mirror of
https://github.com/RightNow-AI/openfang.git
synced 2026-04-25 17:25:11 +02:00
fix: resolve remaining clippy warnings blocking CI (ptr_arg, dead_code, map_or, collapsible_if)
This commit is contained in:
@@ -169,7 +169,7 @@ pub async fn agent_ws(
|
||||
let query_auth = uri
|
||||
.query()
|
||||
.and_then(|q| q.split('&').find_map(|pair| pair.strip_prefix("token=")))
|
||||
.map(|raw| crate::percent_decode(raw))
|
||||
.map(crate::percent_decode)
|
||||
.map(|token| ct_eq(&token, api_key))
|
||||
.unwrap_or(false);
|
||||
|
||||
|
||||
@@ -970,13 +970,11 @@ pub fn run() -> InitResult {
|
||||
if matches!(
|
||||
state.copilot_auth_status,
|
||||
CopilotAuthStatus::WaitingForUser
|
||||
) {
|
||||
if !state.copilot_verification_uri.is_empty() {
|
||||
let _ =
|
||||
openfang_runtime::drivers::copilot::open_verification_url(
|
||||
&state.copilot_verification_uri,
|
||||
);
|
||||
}
|
||||
) && !state.copilot_verification_uri.is_empty() {
|
||||
let _ =
|
||||
openfang_runtime::drivers::copilot::open_verification_url(
|
||||
&state.copilot_verification_uri,
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -514,7 +514,7 @@ impl OpenFangKernel {
|
||||
fn fetch_copilot_models(openfang_dir: &Path) -> Result<Vec<String>, String> {
|
||||
use openfang_runtime::drivers::copilot;
|
||||
|
||||
let tokens = copilot::PersistedTokens::load(&openfang_dir.to_path_buf())
|
||||
let tokens = copilot::PersistedTokens::load(openfang_dir)
|
||||
.ok_or("No persisted Copilot tokens found")?;
|
||||
|
||||
let fetch = async {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
//! `config.toml`. The driver handles the rest — device flow, token persistence,
|
||||
//! refresh, and Copilot API token exchange — automatically.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Mutex;
|
||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||
|
||||
@@ -55,6 +55,7 @@ const OAUTH_SCOPES: &str = "copilot";
|
||||
const TOKEN_FILE_NAME: &str = ".copilot-tokens.json";
|
||||
|
||||
/// Device flow polling interval (seconds) — GitHub default is 5.
|
||||
#[allow(dead_code)]
|
||||
const DEVICE_FLOW_POLL_INTERVAL: Duration = Duration::from_secs(5);
|
||||
|
||||
/// Maximum time to wait for user to authorize the device flow.
|
||||
@@ -83,14 +84,14 @@ impl PersistedTokens {
|
||||
}
|
||||
|
||||
/// Load from the OpenFang data directory.
|
||||
pub fn load(openfang_dir: &PathBuf) -> Option<Self> {
|
||||
pub fn load(openfang_dir: &Path) -> Option<Self> {
|
||||
let path = openfang_dir.join(TOKEN_FILE_NAME);
|
||||
let data = std::fs::read_to_string(&path).ok()?;
|
||||
serde_json::from_str(&data).ok()
|
||||
}
|
||||
|
||||
/// Persist to the OpenFang data directory with restricted permissions.
|
||||
pub fn save(&self, openfang_dir: &PathBuf) -> Result<(), String> {
|
||||
pub fn save(&self, openfang_dir: &Path) -> Result<(), String> {
|
||||
let path = openfang_dir.join(TOKEN_FILE_NAME);
|
||||
let json = serde_json::to_string_pretty(self)
|
||||
.map_err(|e| format!("Failed to serialize tokens: {e}"))?;
|
||||
@@ -138,6 +139,7 @@ impl CachedCopilotToken {
|
||||
#[derive(Clone)]
|
||||
struct CachedModels {
|
||||
models: Vec<String>,
|
||||
#[allow(dead_code)]
|
||||
fetched_at: Instant,
|
||||
}
|
||||
|
||||
@@ -358,7 +360,7 @@ pub async fn exchange_copilot_token(
|
||||
.ok_or("Missing 'token' field in Copilot response")?;
|
||||
|
||||
let expires_at_unix = body.get("expires_at").and_then(|v| v.as_i64()).unwrap_or(0);
|
||||
let ttl_secs = (expires_at_unix - unix_now() as i64).max(60) as u64;
|
||||
let ttl_secs = (expires_at_unix - unix_now()).max(60) as u64;
|
||||
|
||||
// Extract base URL from endpoints.api or proxy-ep in the token.
|
||||
let base_url = body
|
||||
@@ -732,7 +734,7 @@ impl crate::llm_driver::LlmDriver for CopilotDriver {
|
||||
///
|
||||
/// Called from `openfang config set-key github-copilot`, `openfang init`,
|
||||
/// `openfang onboard`, and `openfang configure`.
|
||||
pub async fn run_interactive_setup(openfang_dir: &PathBuf) -> Result<PersistedTokens, String> {
|
||||
pub async fn run_interactive_setup(openfang_dir: &Path) -> Result<PersistedTokens, String> {
|
||||
run_device_flow(openfang_dir).await
|
||||
}
|
||||
|
||||
@@ -740,7 +742,7 @@ pub async fn run_interactive_setup(openfang_dir: &PathBuf) -> Result<PersistedTo
|
||||
///
|
||||
/// Prints the user code and verification URL, attempts to open the browser,
|
||||
/// then polls until the user authorizes.
|
||||
pub async fn run_device_flow(openfang_dir: &PathBuf) -> Result<PersistedTokens, String> {
|
||||
pub async fn run_device_flow(openfang_dir: &Path) -> Result<PersistedTokens, String> {
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(30))
|
||||
.build()
|
||||
@@ -817,7 +819,7 @@ pub fn open_verification_url(url: &str) -> bool {
|
||||
}
|
||||
|
||||
/// Check if Copilot OAuth tokens exist on disk.
|
||||
pub fn copilot_auth_available(openfang_dir: &PathBuf) -> bool {
|
||||
pub fn copilot_auth_available(openfang_dir: &Path) -> bool {
|
||||
openfang_dir.join(TOKEN_FILE_NAME).exists()
|
||||
}
|
||||
|
||||
|
||||
@@ -276,7 +276,7 @@ struct OaiUsage {
|
||||
/// Strip trailing empty assistant messages without tool calls.
|
||||
/// Some API proxies reject empty assistant messages as "prefill".
|
||||
fn strip_trailing_empty_assistant(messages: &mut Vec<OaiMessage>) {
|
||||
while messages.last().map_or(false, |m| {
|
||||
while messages.last().is_some_and(|m| {
|
||||
m.role == "assistant"
|
||||
&& m.tool_calls.is_none()
|
||||
&& match &m.content {
|
||||
|
||||
Reference in New Issue
Block a user