- 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.
85 lines
2.7 KiB
Rust
85 lines
2.7 KiB
Rust
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: ListenerKind,
|
|
}
|
|
|
|
impl IpcServer {
|
|
pub fn bind(addr: &str) -> Result<Self> {
|
|
let listener = TcpListener::bind(addr)?;
|
|
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> {
|
|
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,
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|