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:
+59
-17
@@ -1,42 +1,84 @@
|
||||
use std::net::TcpListener;
|
||||
use std::os::unix::net::UnixListener;
|
||||
use std::thread;
|
||||
use anyhow::Result;
|
||||
use super::conn::Connection;
|
||||
|
||||
enum ListenerKind {
|
||||
Tcp(TcpListener),
|
||||
Unix(UnixListener),
|
||||
}
|
||||
|
||||
pub struct IpcServer {
|
||||
listener: TcpListener,
|
||||
listener: ListenerKind,
|
||||
}
|
||||
|
||||
impl IpcServer {
|
||||
pub fn bind(addr: &str) -> Result<Self> {
|
||||
let listener = TcpListener::bind(addr)?;
|
||||
Ok(IpcServer { listener })
|
||||
Ok(IpcServer { listener: ListenerKind::Tcp(listener) })
|
||||
}
|
||||
|
||||
pub fn bind_unix(path: &str) -> Result<Self> {
|
||||
let _ = std::fs::remove_file(path);
|
||||
let listener = UnixListener::bind(path)?;
|
||||
Ok(IpcServer { listener: ListenerKind::Unix(listener) })
|
||||
}
|
||||
|
||||
pub fn accept(&self) -> Result<Connection> {
|
||||
let (stream, _addr) = self.listener.accept()?;
|
||||
stream.set_nodelay(true)?;
|
||||
Ok(Connection::Tcp(stream))
|
||||
match &self.listener {
|
||||
ListenerKind::Tcp(l) => {
|
||||
let (stream, _addr) = l.accept()?;
|
||||
stream.set_nodelay(true)?;
|
||||
Ok(Connection::Tcp(stream))
|
||||
}
|
||||
ListenerKind::Unix(l) => {
|
||||
let (stream, _addr) = l.accept()?;
|
||||
Ok(Connection::Unix(stream))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn accept_with_handler<F>(self, handler: F) -> thread::JoinHandle<()>
|
||||
where
|
||||
F: Fn(Connection) -> Result<()> + Send + 'static,
|
||||
{
|
||||
thread::spawn(move || {
|
||||
for stream in self.listener.incoming() {
|
||||
match stream {
|
||||
Ok(stream) => {
|
||||
if let Err(e) = handler(Connection::Tcp(stream)) {
|
||||
eprintln!("ipc handler error: {}", e);
|
||||
match self.listener {
|
||||
ListenerKind::Tcp(l) => {
|
||||
thread::spawn(move || {
|
||||
for stream in l.incoming() {
|
||||
match stream {
|
||||
Ok(s) => {
|
||||
let _ = s.set_nodelay(true);
|
||||
if let Err(e) = handler(Connection::Tcp(s)) {
|
||||
eprintln!("ipc handler error: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("ipc accept error: {}", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("ipc accept error: {}", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
ListenerKind::Unix(l) => {
|
||||
thread::spawn(move || {
|
||||
for stream in l.incoming() {
|
||||
match stream {
|
||||
Ok(s) => {
|
||||
if let Err(e) = handler(Connection::Unix(s)) {
|
||||
eprintln!("ipc handler error: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("ipc accept error: {}", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user