feat: Enhance OAuth module and OpenRouter client functionality
- Updated OAuth module to include unused imports for better clarity. - Refactored OpenRouterClient to improve chat functionality and added support for tools in chat requests. - Modified internet tools (Download, Fetch, Search) to use a more flexible internet mode check. - Introduced new Bash tools for managing background jobs (BashOutput, BashKill). - Enhanced workflow tool to parse and execute workflow scripts with arguments. - Updated status and workflow views to reflect new agent and findings counts. - Added IPC protocol definitions for client requests and state payloads.
This commit is contained in:
@@ -5,6 +5,9 @@ pub mod loopback;
|
||||
#[expect(dead_code)]
|
||||
pub mod manager;
|
||||
|
||||
#[expect(unused_imports)]
|
||||
pub use manager::{OAuthManager, OAuthConfig};
|
||||
#[expect(unused_imports)]
|
||||
pub use pkce::CodeVerifier;
|
||||
#[expect(unused_imports)]
|
||||
pub use loopback::LoopbackServer;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use anyhow::Result;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::dto::chat::message::ChatMessage;
|
||||
use crate::dto::openrouter::request::ToolDef;
|
||||
|
||||
pub struct OpenRouterClient {
|
||||
pub client: reqwest::blocking::Client,
|
||||
@@ -18,13 +20,22 @@ impl OpenRouterClient {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn chat(&self, messages: &[crate::dto::chat::message::ChatMessage]) -> Result<String> {
|
||||
pub fn chat(&self, messages: &[ChatMessage]) -> Result<String> {
|
||||
let response = self.chat_with_tools(messages, None)?;
|
||||
Ok(response.content.unwrap_or_default())
|
||||
}
|
||||
|
||||
pub fn chat_with_tools(
|
||||
&self,
|
||||
messages: &[ChatMessage],
|
||||
tools: Option<Vec<ToolDef>>,
|
||||
) -> Result<ChatMessage> {
|
||||
let req = crate::dto::openrouter::request::ChatRequest {
|
||||
model: self.model.clone(),
|
||||
messages: messages.to_vec(),
|
||||
max_tokens: Some(4096),
|
||||
temperature: Some(0.7),
|
||||
tools: None,
|
||||
tools,
|
||||
stream: Some(false),
|
||||
top_p: None,
|
||||
stop: None,
|
||||
@@ -43,11 +54,13 @@ impl OpenRouterClient {
|
||||
anyhow::bail!("OpenRouter API error {}: {}", status, body);
|
||||
}
|
||||
|
||||
let data: Value = resp.json()?;
|
||||
let content = data["choices"][0]["message"]["content"]
|
||||
.as_str()
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
Ok(content)
|
||||
let data: crate::dto::openrouter::response::ChatResponse = resp.json()?;
|
||||
let message = data
|
||||
.choices
|
||||
.into_iter()
|
||||
.next()
|
||||
.map(|c| c.message)
|
||||
.ok_or_else(|| anyhow::anyhow!("OpenRouter response had no choices"))?;
|
||||
Ok(message)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user