@townco/agent 0.1.9 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp-server/adapter.d.ts +10 -14
- package/dist/acp-server/adapter.js +72 -73
- package/dist/acp-server/cli.d.ts +1 -3
- package/dist/acp-server/cli.js +5 -9
- package/dist/acp-server/http.d.ts +1 -3
- package/dist/acp-server/http.js +163 -173
- package/dist/bin.js +0 -0
- package/dist/definition/index.d.ts +4 -1
- package/dist/definition/index.js +8 -1
- package/dist/index.js +13 -12
- package/dist/runner/agent-runner.d.ts +4 -1
- package/dist/runner/agent-runner.js +4 -4
- package/dist/runner/index.d.ts +1 -3
- package/dist/runner/index.js +14 -18
- package/dist/runner/langchain/index.d.ts +8 -19
- package/dist/runner/langchain/index.js +55 -6
- package/dist/runner/langchain/tools/todo.d.ts +32 -48
- package/dist/runner/langchain/tools/todo.js +13 -16
- package/dist/runner/langchain/tools/web_search.d.ts +1 -1
- package/dist/runner/langchain/tools/web_search.js +18 -21
- package/dist/runner/tool-loader.d.ts +14 -0
- package/dist/runner/tool-loader.js +42 -0
- package/dist/runner/tools.d.ts +8 -7
- package/dist/runner/tools.js +12 -4
- package/dist/scaffold/bundle.d.ts +1 -1
- package/dist/scaffold/bundle.js +1 -1
- package/dist/scaffold/copy-gui.js +1 -1
- package/dist/scaffold/index.d.ts +8 -10
- package/dist/scaffold/index.js +82 -90
- package/dist/storage/index.js +24 -23
- package/dist/templates/index.d.ts +4 -1
- package/dist/templates/index.js +7 -3
- package/dist/test-script.js +11 -12
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -2
- package/templates/index.ts +11 -4
- package/dist/definition/mcp.d.ts +0 -0
- package/dist/definition/mcp.js +0 -0
- package/dist/definition/tools/todo.d.ts +0 -49
- package/dist/definition/tools/todo.js +0 -80
- package/dist/definition/tools/web_search.d.ts +0 -4
- package/dist/definition/tools/web_search.js +0 -26
- package/dist/example.d.ts +0 -2
- package/dist/example.js +0 -19
|
@@ -2,18 +2,14 @@ import * as acp from "@agentclientprotocol/sdk";
|
|
|
2
2
|
import type { AgentRunner } from "../runner";
|
|
3
3
|
/** Adapts an Agent to speak the ACP protocol */
|
|
4
4
|
export declare class AgentAcpAdapter implements acp.Agent {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
_params: acp.SetSessionModeRequest,
|
|
16
|
-
): Promise<acp.SetSessionModeResponse>;
|
|
17
|
-
prompt(params: acp.PromptRequest): Promise<acp.PromptResponse>;
|
|
18
|
-
cancel(params: acp.CancelNotification): Promise<void>;
|
|
5
|
+
private connection;
|
|
6
|
+
private sessions;
|
|
7
|
+
private agent;
|
|
8
|
+
constructor(agent: AgentRunner, connection: acp.AgentSideConnection);
|
|
9
|
+
initialize(_params: acp.InitializeRequest): Promise<acp.InitializeResponse>;
|
|
10
|
+
newSession(_params: acp.NewSessionRequest): Promise<acp.NewSessionResponse>;
|
|
11
|
+
authenticate(_params: acp.AuthenticateRequest): Promise<acp.AuthenticateResponse | undefined>;
|
|
12
|
+
setSessionMode(_params: acp.SetSessionModeRequest): Promise<acp.SetSessionModeResponse>;
|
|
13
|
+
prompt(params: acp.PromptRequest): Promise<acp.PromptResponse>;
|
|
14
|
+
cancel(params: acp.CancelNotification): Promise<void>;
|
|
19
15
|
}
|
|
@@ -1,77 +1,76 @@
|
|
|
1
1
|
import * as acp from "@agentclientprotocol/sdk";
|
|
2
2
|
/** Adapts an Agent to speak the ACP protocol */
|
|
3
3
|
export class AgentAcpAdapter {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
4
|
+
connection;
|
|
5
|
+
sessions;
|
|
6
|
+
agent;
|
|
7
|
+
constructor(agent, connection) {
|
|
8
|
+
this.connection = connection;
|
|
9
|
+
this.sessions = new Map();
|
|
10
|
+
this.agent = agent;
|
|
11
|
+
}
|
|
12
|
+
async initialize(_params) {
|
|
13
|
+
return {
|
|
14
|
+
protocolVersion: acp.PROTOCOL_VERSION,
|
|
15
|
+
agentCapabilities: {
|
|
16
|
+
loadSession: false,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async newSession(_params) {
|
|
21
|
+
const sessionId = Math.random().toString(36).substring(2);
|
|
22
|
+
this.sessions.set(sessionId, {
|
|
23
|
+
pendingPrompt: null,
|
|
24
|
+
messages: [],
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
sessionId,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async authenticate(_params) {
|
|
31
|
+
// No auth needed - return empty response
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
async setSessionMode(_params) {
|
|
35
|
+
// Session mode changes are no-op for us (not related to coding)
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
async prompt(params) {
|
|
39
|
+
let session = this.sessions.get(params.sessionId);
|
|
40
|
+
// If session not found (e.g., after server restart), create a new one
|
|
41
|
+
if (!session) {
|
|
42
|
+
console.log(`Session ${params.sessionId} not found, creating new session`);
|
|
43
|
+
session = {
|
|
44
|
+
pendingPrompt: null,
|
|
45
|
+
messages: [],
|
|
46
|
+
};
|
|
47
|
+
this.sessions.set(params.sessionId, session);
|
|
48
|
+
}
|
|
49
|
+
session.pendingPrompt?.abort();
|
|
50
|
+
session.pendingPrompt = new AbortController();
|
|
51
|
+
try {
|
|
52
|
+
for await (const msg of this.agent.invoke({
|
|
53
|
+
prompt: params.prompt,
|
|
54
|
+
sessionId: params.sessionId,
|
|
55
|
+
})) {
|
|
56
|
+
this.connection.sessionUpdate({
|
|
57
|
+
sessionId: params.sessionId,
|
|
58
|
+
update: msg,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
if (session.pendingPrompt.signal.aborted) {
|
|
64
|
+
return { stopReason: "cancelled" };
|
|
65
|
+
}
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
session.pendingPrompt = null;
|
|
69
|
+
return {
|
|
70
|
+
stopReason: "end_turn",
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async cancel(params) {
|
|
74
|
+
this.sessions.get(params.sessionId)?.pendingPrompt?.abort();
|
|
75
|
+
}
|
|
77
76
|
}
|
package/dist/acp-server/cli.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { AgentDefinition } from "../definition";
|
|
2
2
|
import { type AgentRunner } from "../runner";
|
|
3
|
-
export declare function makeStdioTransport(
|
|
4
|
-
agent: AgentRunner | AgentDefinition,
|
|
5
|
-
): void;
|
|
3
|
+
export declare function makeStdioTransport(agent: AgentRunner | AgentDefinition): void;
|
package/dist/acp-server/cli.js
CHANGED
|
@@ -3,13 +3,9 @@ import * as acp from "@agentclientprotocol/sdk";
|
|
|
3
3
|
import { makeRunnerFromDefinition } from "../runner";
|
|
4
4
|
import { AgentAcpAdapter } from "./adapter";
|
|
5
5
|
export function makeStdioTransport(agent) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
new acp.AgentSideConnection(
|
|
12
|
-
(conn) => new AgentAcpAdapter(agentRunner, conn),
|
|
13
|
-
stream,
|
|
14
|
-
);
|
|
6
|
+
const agentRunner = "definition" in agent ? agent : makeRunnerFromDefinition(agent);
|
|
7
|
+
const input = Writable.toWeb(process.stdout);
|
|
8
|
+
const output = Readable.toWeb(process.stdin);
|
|
9
|
+
const stream = acp.ndJsonStream(input, output);
|
|
10
|
+
new acp.AgentSideConnection((conn) => new AgentAcpAdapter(agentRunner, conn), stream);
|
|
15
11
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { AgentDefinition } from "../definition";
|
|
2
2
|
import { type AgentRunner } from "../runner";
|
|
3
|
-
export declare function makeHttpTransport(
|
|
4
|
-
agent: AgentRunner | AgentDefinition,
|
|
5
|
-
): void;
|
|
3
|
+
export declare function makeHttpTransport(agent: AgentRunner | AgentDefinition): void;
|
package/dist/acp-server/http.js
CHANGED
|
@@ -6,183 +6,173 @@ import { cors } from "hono/cors";
|
|
|
6
6
|
import { streamSSE } from "hono/streaming";
|
|
7
7
|
import { makeRunnerFromDefinition } from "../runner";
|
|
8
8
|
import { AgentAcpAdapter } from "./adapter";
|
|
9
|
-
|
|
10
9
|
// Use PGlite in-memory database for LISTEN/NOTIFY
|
|
11
10
|
const pg = new PGlite();
|
|
12
11
|
// Helper to create safe channel names from untrusted IDs
|
|
13
12
|
function safeChannelName(prefix, id) {
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const hash = createHash("sha256").update(id).digest("hex").slice(0, 16);
|
|
14
|
+
return `${prefix}_${hash}`;
|
|
16
15
|
}
|
|
17
16
|
export function makeHttpTransport(agent) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
const port = Number.parseInt(process.env.PORT || "3100", 10);
|
|
182
|
-
console.log(`Starting HTTP server on port ${port}...`);
|
|
183
|
-
Bun.serve({
|
|
184
|
-
fetch: app.fetch,
|
|
185
|
-
port,
|
|
186
|
-
});
|
|
187
|
-
console.log(`HTTP server listening on http://localhost:${port}`);
|
|
17
|
+
const inbound = new TransformStream();
|
|
18
|
+
const outbound = new TransformStream();
|
|
19
|
+
const bridge = acp.ndJsonStream(outbound.writable, inbound.readable);
|
|
20
|
+
const agentRunner = "definition" in agent ? agent : makeRunnerFromDefinition(agent);
|
|
21
|
+
new acp.AgentSideConnection((conn) => new AgentAcpAdapter(agentRunner, conn), bridge);
|
|
22
|
+
const app = new Hono();
|
|
23
|
+
const decoder = new TextDecoder();
|
|
24
|
+
const encoder = new TextEncoder();
|
|
25
|
+
(async () => {
|
|
26
|
+
const reader = outbound.readable.getReader();
|
|
27
|
+
let buf = "";
|
|
28
|
+
for (;;) {
|
|
29
|
+
const { value, done } = await reader.read();
|
|
30
|
+
if (done)
|
|
31
|
+
break;
|
|
32
|
+
buf += decoder.decode(value, { stream: true });
|
|
33
|
+
for (let nl = buf.indexOf("\n"); nl !== -1; nl = buf.indexOf("\n")) {
|
|
34
|
+
const line = buf.slice(0, nl).trim();
|
|
35
|
+
buf = buf.slice(nl + 1);
|
|
36
|
+
if (!line)
|
|
37
|
+
continue;
|
|
38
|
+
let rawMsg;
|
|
39
|
+
try {
|
|
40
|
+
rawMsg = JSON.parse(line);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// ignore malformed lines
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
// Validate the agent message with Zod schema
|
|
47
|
+
const parseResult = acp.agentOutgoingMessageSchema.safeParse(rawMsg);
|
|
48
|
+
if (!parseResult.success) {
|
|
49
|
+
console.error("Invalid agent message:", parseResult.error.issues);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
//const msg = parseResult.data;
|
|
53
|
+
if (rawMsg == null || typeof rawMsg !== "object") {
|
|
54
|
+
console.warn("Malformed message, cannot route:", rawMsg);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if ("id" in rawMsg &&
|
|
58
|
+
typeof rawMsg.id === "string" &&
|
|
59
|
+
rawMsg.id != null) {
|
|
60
|
+
// This is a response to a request - send to response-specific channel
|
|
61
|
+
const channel = safeChannelName("response", rawMsg.id);
|
|
62
|
+
const payload = JSON.stringify(rawMsg).replace(/'/g, "''");
|
|
63
|
+
await pg.query(`NOTIFY ${channel}, '${payload}'`);
|
|
64
|
+
}
|
|
65
|
+
else if ("params" in rawMsg &&
|
|
66
|
+
rawMsg.params != null &&
|
|
67
|
+
typeof rawMsg.params === "object" &&
|
|
68
|
+
"sessionId" in rawMsg.params &&
|
|
69
|
+
typeof rawMsg.params.sessionId === "string") {
|
|
70
|
+
// Other messages (notifications, requests from agent) go to
|
|
71
|
+
// session-specific channel
|
|
72
|
+
const sessionId = rawMsg.params.sessionId;
|
|
73
|
+
const channel = safeChannelName("notifications", sessionId);
|
|
74
|
+
const payload = JSON.stringify(rawMsg).replace(/'/g, "''");
|
|
75
|
+
await pg.query(`NOTIFY ${channel}, '${payload}'`);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
console.warn("Message without sessionId, cannot route:", rawMsg);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
})();
|
|
83
|
+
// TODO: fix this for production
|
|
84
|
+
app.use("*", cors({
|
|
85
|
+
origin: "*",
|
|
86
|
+
allowHeaders: ["content-type", "authorization", "x-session-id"],
|
|
87
|
+
allowMethods: ["GET", "POST", "OPTIONS"],
|
|
88
|
+
}));
|
|
89
|
+
app.get("/health", (c) => c.json({ ok: true }));
|
|
90
|
+
app.get("/events", (c) => {
|
|
91
|
+
const sessionId = c.req.header("X-Session-ID");
|
|
92
|
+
if (!sessionId) {
|
|
93
|
+
return c.json({ error: "X-Session-ID header required" }, 401);
|
|
94
|
+
}
|
|
95
|
+
return streamSSE(c, async (stream) => {
|
|
96
|
+
await stream.writeSSE({ event: "ping", data: "{}" });
|
|
97
|
+
const hb = setInterval(() => {
|
|
98
|
+
// Heartbeat to keep proxies from terminating idle connections
|
|
99
|
+
void stream.writeSSE({ event: "ping", data: "{}" });
|
|
100
|
+
}, 1000);
|
|
101
|
+
const channel = safeChannelName("notifications", sessionId);
|
|
102
|
+
const unsub = await pg.listen(channel, async (payload) => {
|
|
103
|
+
const json = JSON.parse(payload);
|
|
104
|
+
await stream.writeSSE({
|
|
105
|
+
event: "message",
|
|
106
|
+
data: JSON.stringify(json),
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
// Clean up when the client disconnects
|
|
110
|
+
stream.onAbort(() => {
|
|
111
|
+
console.log("/events connection closed");
|
|
112
|
+
clearInterval(hb);
|
|
113
|
+
unsub();
|
|
114
|
+
});
|
|
115
|
+
// Keep the connection open indefinitely
|
|
116
|
+
await stream.sleep(1000 * 60 * 60 * 24);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
app.post("/rpc", async (c) => {
|
|
120
|
+
// Get and validate the request body
|
|
121
|
+
const rawBody = await c.req.json();
|
|
122
|
+
// Validate using Zod schema
|
|
123
|
+
const parseResult = acp.clientOutgoingMessageSchema.safeParse(rawBody);
|
|
124
|
+
if (!parseResult.success) {
|
|
125
|
+
return c.json({
|
|
126
|
+
error: "Invalid ACP message",
|
|
127
|
+
details: parseResult.error.issues,
|
|
128
|
+
}, 400);
|
|
129
|
+
}
|
|
130
|
+
const body = parseResult.data;
|
|
131
|
+
// Ensure the request has an id
|
|
132
|
+
const id = "id" in body ? body.id : null;
|
|
133
|
+
const isRequest = id != null;
|
|
134
|
+
if (isRequest) {
|
|
135
|
+
// For requests, set up a listener before sending the request
|
|
136
|
+
const responseChannel = safeChannelName("response", String(id));
|
|
137
|
+
let responseResolver;
|
|
138
|
+
const responsePromise = new Promise((resolve) => {
|
|
139
|
+
responseResolver = resolve;
|
|
140
|
+
});
|
|
141
|
+
const unsub = await pg.listen(responseChannel, (payload) => {
|
|
142
|
+
const rawResponse = JSON.parse(payload);
|
|
143
|
+
responseResolver(rawResponse);
|
|
144
|
+
});
|
|
145
|
+
// Write NDJSON line into the ACP inbound stream
|
|
146
|
+
const writer = inbound.writable.getWriter();
|
|
147
|
+
await writer.write(encoder.encode(`${JSON.stringify(body)}\n`));
|
|
148
|
+
writer.releaseLock();
|
|
149
|
+
// Wait for response with 30 second timeout
|
|
150
|
+
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error("Request timeout")), 30000));
|
|
151
|
+
try {
|
|
152
|
+
const response = await Promise.race([responsePromise, timeoutPromise]);
|
|
153
|
+
return c.json(response);
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
// Clean up the listener whether we got a response or timed out
|
|
157
|
+
unsub();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
// For notifications, just send and return success
|
|
162
|
+
const writer = inbound.writable.getWriter();
|
|
163
|
+
await writer.write(encoder.encode(`${JSON.stringify(body)}\n`));
|
|
164
|
+
writer.releaseLock();
|
|
165
|
+
return c.json({
|
|
166
|
+
success: true,
|
|
167
|
+
message: "Notification sent to agent",
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
const port = Number.parseInt(process.env.PORT || "3100", 10);
|
|
172
|
+
console.log(`Starting HTTP server on port ${port}...`);
|
|
173
|
+
Bun.serve({
|
|
174
|
+
fetch: app.fetch,
|
|
175
|
+
port,
|
|
176
|
+
});
|
|
177
|
+
console.log(`HTTP server listening on http://localhost:${port}`);
|
|
188
178
|
}
|
package/dist/bin.js
CHANGED
|
File without changes
|
|
@@ -16,7 +16,10 @@ export declare const McpConfigSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
16
16
|
export declare const AgentDefinitionSchema: z.ZodObject<{
|
|
17
17
|
systemPrompt: z.ZodNullable<z.ZodString>;
|
|
18
18
|
model: z.ZodString;
|
|
19
|
-
tools: z.ZodOptional<z.ZodArray<z.ZodString
|
|
19
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
20
|
+
type: z.ZodLiteral<"custom">;
|
|
21
|
+
modulePath: z.ZodString;
|
|
22
|
+
}, z.core.$strip>]>>>;
|
|
20
23
|
mcps: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
21
24
|
name: z.ZodString;
|
|
22
25
|
transport: z.ZodLiteral<"stdio">;
|
package/dist/definition/index.js
CHANGED
|
@@ -24,11 +24,18 @@ export const McpConfigSchema = z.union([
|
|
|
24
24
|
McpStdioConfigSchema,
|
|
25
25
|
McpStreamableHttpConfigSchema,
|
|
26
26
|
]);
|
|
27
|
+
/** Custom tool configuration schema. */
|
|
28
|
+
const CustomToolSchema = z.object({
|
|
29
|
+
type: z.literal("custom"),
|
|
30
|
+
modulePath: z.string(),
|
|
31
|
+
});
|
|
32
|
+
/** Tool schema - can be a string (built-in tool) or custom tool object. */
|
|
33
|
+
const ToolSchema = z.union([z.string(), CustomToolSchema]);
|
|
27
34
|
/** Agent definition schema. */
|
|
28
35
|
export const AgentDefinitionSchema = z.object({
|
|
29
36
|
systemPrompt: z.string().nullable(),
|
|
30
37
|
model: z.string(),
|
|
31
|
-
tools: z.array(
|
|
38
|
+
tools: z.array(ToolSchema).optional(),
|
|
32
39
|
mcps: z.array(McpConfigSchema).optional(),
|
|
33
40
|
harnessImplementation: z.literal("langchain").optional(),
|
|
34
41
|
});
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { makeHttpTransport, makeStdioTransport } from "./acp-server";
|
|
2
|
-
|
|
3
2
|
const exampleAgent = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
model: "claude-sonnet-4-5-20250929",
|
|
4
|
+
systemPrompt: "You are a helpful assistant.",
|
|
5
|
+
tools: ["todo_write", "get_weather", "web_search"],
|
|
6
|
+
mcps: [],
|
|
8
7
|
};
|
|
9
8
|
// Parse transport type from command line argument
|
|
10
9
|
const transport = process.argv[2] || "stdio";
|
|
11
10
|
if (transport === "http") {
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
makeHttpTransport(exampleAgent);
|
|
12
|
+
}
|
|
13
|
+
else if (transport === "stdio") {
|
|
14
|
+
makeStdioTransport(exampleAgent);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
console.error(`Invalid transport: ${transport}`);
|
|
18
|
+
console.error("Usage: bun run index.ts [stdio|http]");
|
|
19
|
+
process.exit(1);
|
|
19
20
|
}
|