@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.
Files changed (44) hide show
  1. package/dist/acp-server/adapter.d.ts +10 -14
  2. package/dist/acp-server/adapter.js +72 -73
  3. package/dist/acp-server/cli.d.ts +1 -3
  4. package/dist/acp-server/cli.js +5 -9
  5. package/dist/acp-server/http.d.ts +1 -3
  6. package/dist/acp-server/http.js +163 -173
  7. package/dist/bin.js +0 -0
  8. package/dist/definition/index.d.ts +4 -1
  9. package/dist/definition/index.js +8 -1
  10. package/dist/index.js +13 -12
  11. package/dist/runner/agent-runner.d.ts +4 -1
  12. package/dist/runner/agent-runner.js +4 -4
  13. package/dist/runner/index.d.ts +1 -3
  14. package/dist/runner/index.js +14 -18
  15. package/dist/runner/langchain/index.d.ts +8 -19
  16. package/dist/runner/langchain/index.js +55 -6
  17. package/dist/runner/langchain/tools/todo.d.ts +32 -48
  18. package/dist/runner/langchain/tools/todo.js +13 -16
  19. package/dist/runner/langchain/tools/web_search.d.ts +1 -1
  20. package/dist/runner/langchain/tools/web_search.js +18 -21
  21. package/dist/runner/tool-loader.d.ts +14 -0
  22. package/dist/runner/tool-loader.js +42 -0
  23. package/dist/runner/tools.d.ts +8 -7
  24. package/dist/runner/tools.js +12 -4
  25. package/dist/scaffold/bundle.d.ts +1 -1
  26. package/dist/scaffold/bundle.js +1 -1
  27. package/dist/scaffold/copy-gui.js +1 -1
  28. package/dist/scaffold/index.d.ts +8 -10
  29. package/dist/scaffold/index.js +82 -90
  30. package/dist/storage/index.js +24 -23
  31. package/dist/templates/index.d.ts +4 -1
  32. package/dist/templates/index.js +7 -3
  33. package/dist/test-script.js +11 -12
  34. package/dist/tsconfig.tsbuildinfo +1 -1
  35. package/package.json +10 -2
  36. package/templates/index.ts +11 -4
  37. package/dist/definition/mcp.d.ts +0 -0
  38. package/dist/definition/mcp.js +0 -0
  39. package/dist/definition/tools/todo.d.ts +0 -49
  40. package/dist/definition/tools/todo.js +0 -80
  41. package/dist/definition/tools/web_search.d.ts +0 -4
  42. package/dist/definition/tools/web_search.js +0 -26
  43. package/dist/example.d.ts +0 -2
  44. 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
- 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(
12
- _params: acp.AuthenticateRequest,
13
- ): Promise<acp.AuthenticateResponse | undefined>;
14
- setSessionMode(
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
- 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(
43
- `Session ${params.sessionId} not found, creating new session`,
44
- );
45
- session = {
46
- pendingPrompt: null,
47
- messages: [],
48
- };
49
- this.sessions.set(params.sessionId, session);
50
- }
51
- session.pendingPrompt?.abort();
52
- session.pendingPrompt = new AbortController();
53
- try {
54
- for await (const msg of this.agent.invoke({
55
- prompt: params.prompt,
56
- sessionId: params.sessionId,
57
- })) {
58
- this.connection.sessionUpdate({
59
- sessionId: params.sessionId,
60
- update: msg,
61
- });
62
- }
63
- } catch (err) {
64
- if (session.pendingPrompt.signal.aborted) {
65
- return { stopReason: "cancelled" };
66
- }
67
- throw err;
68
- }
69
- session.pendingPrompt = null;
70
- return {
71
- stopReason: "end_turn",
72
- };
73
- }
74
- async cancel(params) {
75
- this.sessions.get(params.sessionId)?.pendingPrompt?.abort();
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
  }
@@ -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;
@@ -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
- const agentRunner =
7
- "definition" in agent ? agent : makeRunnerFromDefinition(agent);
8
- const input = Writable.toWeb(process.stdout);
9
- const output = Readable.toWeb(process.stdin);
10
- const stream = acp.ndJsonStream(input, output);
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;
@@ -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
- const hash = createHash("sha256").update(id).digest("hex").slice(0, 16);
15
- return `${prefix}_${hash}`;
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
- const inbound = new TransformStream();
19
- const outbound = new TransformStream();
20
- const bridge = acp.ndJsonStream(outbound.writable, inbound.readable);
21
- const agentRunner =
22
- "definition" in agent ? agent : makeRunnerFromDefinition(agent);
23
- new acp.AgentSideConnection(
24
- (conn) => new AgentAcpAdapter(agentRunner, conn),
25
- bridge,
26
- );
27
- const app = new Hono();
28
- const decoder = new TextDecoder();
29
- const encoder = new TextEncoder();
30
- (async () => {
31
- const reader = outbound.readable.getReader();
32
- let buf = "";
33
- for (;;) {
34
- const { value, done } = await reader.read();
35
- if (done) break;
36
- buf += decoder.decode(value, { stream: true });
37
- for (let nl = buf.indexOf("\n"); nl !== -1; nl = buf.indexOf("\n")) {
38
- const line = buf.slice(0, nl).trim();
39
- buf = buf.slice(nl + 1);
40
- if (!line) continue;
41
- let rawMsg;
42
- try {
43
- rawMsg = JSON.parse(line);
44
- } catch {
45
- // ignore malformed lines
46
- continue;
47
- }
48
- // Validate the agent message with Zod schema
49
- const parseResult = acp.agentOutgoingMessageSchema.safeParse(rawMsg);
50
- if (!parseResult.success) {
51
- console.error("Invalid agent message:", parseResult.error.issues);
52
- continue;
53
- }
54
- //const msg = parseResult.data;
55
- if (rawMsg == null || typeof rawMsg !== "object") {
56
- console.warn("Malformed message, cannot route:", rawMsg);
57
- continue;
58
- }
59
- if (
60
- "id" in rawMsg &&
61
- typeof rawMsg.id === "string" &&
62
- rawMsg.id != null
63
- ) {
64
- // This is a response to a request - send to response-specific channel
65
- const channel = safeChannelName("response", rawMsg.id);
66
- const payload = JSON.stringify(rawMsg).replace(/'/g, "''");
67
- await pg.query(`NOTIFY ${channel}, '${payload}'`);
68
- } else if (
69
- "params" in rawMsg &&
70
- rawMsg.params != null &&
71
- typeof rawMsg.params === "object" &&
72
- "sessionId" in rawMsg.params &&
73
- typeof rawMsg.params.sessionId === "string"
74
- ) {
75
- // Other messages (notifications, requests from agent) go to
76
- // session-specific channel
77
- const sessionId = rawMsg.params.sessionId;
78
- const channel = safeChannelName("notifications", sessionId);
79
- const payload = JSON.stringify(rawMsg).replace(/'/g, "''");
80
- await pg.query(`NOTIFY ${channel}, '${payload}'`);
81
- } else {
82
- console.warn("Message without sessionId, cannot route:", rawMsg);
83
- }
84
- }
85
- }
86
- })();
87
- // TODO: fix this for production
88
- app.use(
89
- "*",
90
- cors({
91
- origin: "*",
92
- allowHeaders: ["content-type", "authorization", "x-session-id"],
93
- allowMethods: ["GET", "POST", "OPTIONS"],
94
- }),
95
- );
96
- app.get("/health", (c) => c.json({ ok: true }));
97
- app.get("/events", (c) => {
98
- const sessionId = c.req.header("X-Session-ID");
99
- if (!sessionId) {
100
- return c.json({ error: "X-Session-ID header required" }, 401);
101
- }
102
- return streamSSE(c, async (stream) => {
103
- await stream.writeSSE({ event: "ping", data: "{}" });
104
- const hb = setInterval(() => {
105
- // Heartbeat to keep proxies from terminating idle connections
106
- void stream.writeSSE({ event: "ping", data: "{}" });
107
- }, 1000);
108
- const channel = safeChannelName("notifications", sessionId);
109
- const unsub = await pg.listen(channel, async (payload) => {
110
- const json = JSON.parse(payload);
111
- await stream.writeSSE({
112
- event: "message",
113
- data: JSON.stringify(json),
114
- });
115
- });
116
- // Clean up when the client disconnects
117
- stream.onAbort(() => {
118
- console.log("/events connection closed");
119
- clearInterval(hb);
120
- unsub();
121
- });
122
- // Keep the connection open indefinitely
123
- await stream.sleep(1000 * 60 * 60 * 24);
124
- });
125
- });
126
- app.post("/rpc", async (c) => {
127
- // Get and validate the request body
128
- const rawBody = await c.req.json();
129
- // Validate using Zod schema
130
- const parseResult = acp.clientOutgoingMessageSchema.safeParse(rawBody);
131
- if (!parseResult.success) {
132
- return c.json(
133
- {
134
- error: "Invalid ACP message",
135
- details: parseResult.error.issues,
136
- },
137
- 400,
138
- );
139
- }
140
- const body = parseResult.data;
141
- // Ensure the request has an id
142
- const id = "id" in body ? body.id : null;
143
- const isRequest = id != null;
144
- if (isRequest) {
145
- // For requests, set up a listener before sending the request
146
- const responseChannel = safeChannelName("response", String(id));
147
- let responseResolver;
148
- const responsePromise = new Promise((resolve) => {
149
- responseResolver = resolve;
150
- });
151
- const unsub = await pg.listen(responseChannel, (payload) => {
152
- const rawResponse = JSON.parse(payload);
153
- responseResolver(rawResponse);
154
- });
155
- // Write NDJSON line into the ACP inbound stream
156
- const writer = inbound.writable.getWriter();
157
- await writer.write(encoder.encode(`${JSON.stringify(body)}\n`));
158
- writer.releaseLock();
159
- // Wait for response with 30 second timeout
160
- const timeoutPromise = new Promise((_, reject) =>
161
- setTimeout(() => reject(new Error("Request timeout")), 30000),
162
- );
163
- try {
164
- const response = await Promise.race([responsePromise, timeoutPromise]);
165
- return c.json(response);
166
- } finally {
167
- // Clean up the listener whether we got a response or timed out
168
- unsub();
169
- }
170
- } else {
171
- // For notifications, just send and return success
172
- const writer = inbound.writable.getWriter();
173
- await writer.write(encoder.encode(`${JSON.stringify(body)}\n`));
174
- writer.releaseLock();
175
- return c.json({
176
- success: true,
177
- message: "Notification sent to agent",
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">;
@@ -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(z.string()).optional(),
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
- model: "claude-sonnet-4-5-20250929",
5
- systemPrompt: "You are a helpful assistant.",
6
- tools: ["todo_write", "get_weather", "web_search"],
7
- mcps: [],
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
- makeHttpTransport(exampleAgent);
13
- } else if (transport === "stdio") {
14
- makeStdioTransport(exampleAgent);
15
- } else {
16
- console.error(`Invalid transport: ${transport}`);
17
- console.error("Usage: bun run index.ts [stdio|http]");
18
- process.exit(1);
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
  }