Initial commit

This commit is contained in:
emmettlu
2026-08-02 15:26:10 +08:00
parent fcc5d31137
commit eee7fed161
76 changed files with 10686 additions and 3564 deletions
@@ -0,0 +1,50 @@
use agentos_npu::{LoopbackServerConfig, bridge_chat};
use agentos_protocol::ChatRequest;
use anyhow::{Context, Result, bail};
use clap::Parser;
use std::time::Duration;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
const MAX_REQUEST_BYTES: u64 = 8 * 1024 * 1024;
#[derive(Debug, Parser)]
#[command(name = "agentos-npu-bridge", version)]
struct Args {
#[arg(long, required = true)]
request_json_stdin: bool,
}
#[tokio::main]
async fn main() -> Result<()> {
let _args = Args::parse();
let mut input = Vec::new();
tokio::io::stdin()
.take(MAX_REQUEST_BYTES + 1)
.read_to_end(&mut input)
.await
.context("read request from stdin")?;
if input.len() as u64 > MAX_REQUEST_BYTES {
bail!("request exceeds 8 MiB");
}
let mut request: ChatRequest =
serde_json::from_slice(&input).context("parse agentos.chat.v1 request")?;
request.validate()?;
request.parallel_tool_calls = false;
let config = LoopbackServerConfig {
endpoint: std::env::var("AGENTOS_NPU_SERVER_URL")
.unwrap_or_else(|_| "http://127.0.0.1:8031/v1/chat/completions".into()),
model: std::env::var("AGENTOS_NPU_SERVER_MODEL").unwrap_or_else(|_| "agentos-npu".into()),
timeout: Duration::from_secs(
std::env::var("AGENTOS_NPU_SERVER_TIMEOUT_S")
.ok()
.and_then(|value| value.parse().ok())
.unwrap_or(240),
),
};
let response = bridge_chat(&config, &request).await?;
let output = serde_json::to_vec(&response)?;
let mut stdout = tokio::io::stdout();
stdout.write_all(&output).await?;
stdout.write_all(b"\n").await?;
Ok(())
}