mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 22:03:48 +00:00
feat: acp http adapter
This commit is contained in:
parent
2ba630c180
commit
b4c8564cb2
217 changed files with 18785 additions and 17400 deletions
9
examples/mock-acp-agent/README.md
Normal file
9
examples/mock-acp-agent/README.md
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# @sandbox-agent/mock-acp-agent
|
||||
|
||||
Minimal newline-delimited ACP JSON-RPC mock agent.
|
||||
|
||||
Behavior:
|
||||
- Echoes every inbound message as `mock/echo` notification.
|
||||
- For requests (`method` + `id`), returns `result.echoed` payload.
|
||||
- For `mock/ask_client`, emits an agent-initiated `mock/request` before response.
|
||||
- For responses from client (`id` without `method`), emits `mock/client_response` notification.
|
||||
24
examples/mock-acp-agent/package.json
Normal file
24
examples/mock-acp-agent/package.json
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "@sandbox-agent/mock-acp-agent",
|
||||
"version": "0.1.0",
|
||||
"private": false,
|
||||
"type": "module",
|
||||
"description": "Mock ACP agent for adapter integration testing",
|
||||
"license": "Apache-2.0",
|
||||
"main": "./dist/index.js",
|
||||
"exports": {
|
||||
".": "./dist/index.js"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.build.json",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"start": "node ./dist/index.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "latest",
|
||||
"typescript": "latest"
|
||||
}
|
||||
}
|
||||
100
examples/mock-acp-agent/src/index.ts
Normal file
100
examples/mock-acp-agent/src/index.ts
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import { createInterface } from "node:readline";
|
||||
|
||||
interface JsonRpcRequest {
|
||||
jsonrpc?: unknown;
|
||||
id?: unknown;
|
||||
method?: unknown;
|
||||
params?: unknown;
|
||||
result?: unknown;
|
||||
error?: unknown;
|
||||
}
|
||||
|
||||
let outboundRequestSeq = 0;
|
||||
|
||||
function writeMessage(payload: unknown): void {
|
||||
process.stdout.write(`${JSON.stringify(payload)}\n`);
|
||||
}
|
||||
|
||||
function echoNotification(message: unknown): void {
|
||||
writeMessage({
|
||||
jsonrpc: "2.0",
|
||||
method: "mock/echo",
|
||||
params: {
|
||||
message,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function handleMessage(raw: string): void {
|
||||
if (!raw.trim()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let msg: JsonRpcRequest;
|
||||
try {
|
||||
msg = JSON.parse(raw) as JsonRpcRequest;
|
||||
} catch (error) {
|
||||
writeMessage({
|
||||
jsonrpc: "2.0",
|
||||
method: "mock/parse_error",
|
||||
params: {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
raw,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
echoNotification(msg);
|
||||
|
||||
const hasMethod = typeof msg.method === "string";
|
||||
const hasId = msg.id !== undefined;
|
||||
|
||||
if (hasMethod && hasId) {
|
||||
if (msg.method === "mock/ask_client") {
|
||||
outboundRequestSeq += 1;
|
||||
writeMessage({
|
||||
jsonrpc: "2.0",
|
||||
id: `agent-req-${outboundRequestSeq}`,
|
||||
method: "mock/request",
|
||||
params: {
|
||||
prompt: "please respond",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
writeMessage({
|
||||
jsonrpc: "2.0",
|
||||
id: msg.id,
|
||||
result: {
|
||||
echoed: msg,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasMethod && hasId) {
|
||||
writeMessage({
|
||||
jsonrpc: "2.0",
|
||||
method: "mock/client_response",
|
||||
params: {
|
||||
id: msg.id,
|
||||
result: msg.result ?? null,
|
||||
error: msg.error ?? null,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const rl = createInterface({
|
||||
input: process.stdin,
|
||||
crlfDelay: Infinity,
|
||||
});
|
||||
|
||||
rl.on("line", (line) => {
|
||||
handleMessage(line);
|
||||
});
|
||||
|
||||
rl.on("close", () => {
|
||||
process.exit(0);
|
||||
});
|
||||
11
examples/mock-acp-agent/tsconfig.build.json
Normal file
11
examples/mock-acp-agent/tsconfig.build.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowImportingTsExtensions": false,
|
||||
"noEmit": false,
|
||||
"declaration": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
17
examples/mock-acp-agent/tsconfig.json
Normal file
17
examples/mock-acp-agent/tsconfig.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"lib": ["ES2022"],
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "Bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"resolveJsonModule": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue