@tangle-network/agent-runtime 0.131.0 → 0.131.1

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 (29) hide show
  1. package/dist/agent.js +1 -1
  2. package/dist/{authoring-CvHwo1oW.js → authoring-Dv3t6SXe.js} +2 -2
  3. package/dist/{authoring-CvHwo1oW.js.map → authoring-Dv3t6SXe.js.map} +1 -1
  4. package/dist/{graph-BJTxGOFB.js → graph-xWdv53Le.js} +2 -2
  5. package/dist/{graph-BJTxGOFB.js.map → graph-xWdv53Le.js.map} +1 -1
  6. package/dist/index.js +4 -4
  7. package/dist/kernel.js +4 -4
  8. package/dist/{knowledge-ce0_uKCl.js → knowledge-DPEu4f-0.js} +2 -2
  9. package/dist/{knowledge-ce0_uKCl.js.map → knowledge-DPEu4f-0.js.map} +1 -1
  10. package/dist/knowledge.js +1 -1
  11. package/dist/{loop-runner-bin-DSbuDDqM.js → loop-runner-bin-dg6li2-b.js} +2 -2
  12. package/dist/{loop-runner-bin-DSbuDDqM.js.map → loop-runner-bin-dg6li2-b.js.map} +1 -1
  13. package/dist/loop-runner-bin.js +1 -1
  14. package/dist/mcp/bin.js +2 -2
  15. package/dist/mcp/index.js +5 -5
  16. package/dist/mcp/memory-bin.js +1 -1
  17. package/dist/{memory-server-5HEJH672.js → memory-server-eD2baiRO.js} +2 -2
  18. package/dist/{memory-server-5HEJH672.js.map → memory-server-eD2baiRO.js.map} +1 -1
  19. package/dist/{openai-tools-ru75mLjq.js → openai-tools-zRphjXS4.js} +2 -2
  20. package/dist/{openai-tools-ru75mLjq.js.map → openai-tools-zRphjXS4.js.map} +1 -1
  21. package/dist/{runtime-hiAABiTk.js → runtime-cOzDOOHr.js} +4 -4
  22. package/dist/{runtime-hiAABiTk.js.map → runtime-cOzDOOHr.js.map} +1 -1
  23. package/dist/{supervise-iPN27pO0.js → supervise-DHYX8gO2.js} +4 -4
  24. package/dist/{supervise-iPN27pO0.js.map → supervise-DHYX8gO2.js.map} +1 -1
  25. package/dist/testing.js +10 -10
  26. package/dist/{tool-server-RcWgLIsL.js → tool-server-Gs3VvfSK.js} +22 -9
  27. package/dist/tool-server-Gs3VvfSK.js.map +1 -0
  28. package/package.json +2 -1
  29. package/dist/tool-server-RcWgLIsL.js.map +0 -1
package/dist/testing.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { $ as parseExactAgentProfile, K as applyExactAgentProfileDiff, rt as canonicalCandidateDigest$1, st as immutableCandidateValue } from "./prepare-DYWjVcPx.js";
2
2
  import { f as verifyAgentImprovementProposal } from "./improvement-cycle-Csp38cWg.js";
3
- import { c as supervisorAgentWithTestBrain, dt as driverAgent, r as superviseWithTestBrain } from "./supervise-iPN27pO0.js";
4
- import { i as runGraphWithTestBrain } from "./graph-BJTxGOFB.js";
3
+ import { c as supervisorAgentWithTestBrain, dt as driverAgent, r as superviseWithTestBrain } from "./supervise-DHYX8gO2.js";
4
+ import { i as runGraphWithTestBrain } from "./graph-xWdv53Le.js";
5
5
  import { SANDBOX_SIZE_PRESET_NAMES } from "@tangle-network/agent-interface";
6
6
  //#region src/testing/fixtures/agent-improvement-proposal.json
7
7
  var agent_improvement_proposal_default = {
8
8
  changedSurfaces: ["prompt"],
9
- digest: "sha256:01a9d56883f0e99ee43e54a1ec921ee80542e1b67b78659ca6335aee267609d5",
9
+ digest: "sha256:0100ae51aacfe8f3dc6a09364f5ea6ecfc42e220207584eaef33b1c43d46ffe0",
10
10
  evaluation: {
11
11
  "decision": {
12
12
  "contributingChecks": [
@@ -4565,7 +4565,7 @@ var agent_improvement_proposal_default = {
4565
4565
  ],
4566
4566
  "metadata": {
4567
4567
  "fixture": "agent-improvement-proposal",
4568
- "runtimeVersion": "0.131.0"
4568
+ "runtimeVersion": "0.131.1"
4569
4569
  },
4570
4570
  "objectives": [
4571
4571
  {
@@ -4676,8 +4676,8 @@ var agent_improvement_proposal_default = {
4676
4676
  "baselineContentHash": "sha256:5c21ee53e513fc604cb09754e21c392b24a424da0ef37dbf8f1ee4a8a0b08f09",
4677
4677
  "candidateContentHash": "sha256:60fcbb1c728194bd51d7d19cb732d1c3f1881dce7e0a6266b41c8b98cfd65693",
4678
4678
  "kind": "agent-eval-loop",
4679
- "recordDigest": "sha256:1be3dab07f5e01c97fb437eec6772825ac7b32a78e875419ecdceb32af1a198d",
4680
- "runId": "agent-runtime-0.131.0-proposal-fixture",
4679
+ "recordDigest": "sha256:cbe02e0772200d6d63b5d8993f0edc1691d911b0dec4f83ab78756c0c77d0719",
4680
+ "runId": "agent-runtime-0.131.1-proposal-fixture",
4681
4681
  "schema": "agent-candidate-experiment"
4682
4682
  }
4683
4683
  },
@@ -4700,13 +4700,13 @@ var agent_improvement_proposal_default = {
4700
4700
  }],
4701
4701
  kind: "agent-improvement-proposal",
4702
4702
  proposedAt: "2026-07-10T01:00:00.000Z",
4703
- runId: "agent-runtime-0.131.0-proposal-fixture"
4703
+ runId: "agent-runtime-0.131.1-proposal-fixture"
4704
4704
  };
4705
4705
  //#endregion
4706
4706
  //#region src/testing/fixtures/agent-profile-improvement-proposal.json
4707
4707
  var agent_profile_improvement_proposal_default = {
4708
4708
  changedSurfaces: ["prompt", "skills"],
4709
- digest: "sha256:97ab9bd1ba910859a42954c9b0dc85a377db2dd454516ac4e76bd118c15e69ca",
4709
+ digest: "sha256:84bcbcf898fdcea174da9fcca59f49018c998eef794b3b5b3778986f598d2271",
4710
4710
  evaluation: {
4711
4711
  "decision": {
4712
4712
  "contributingChecks": [
@@ -6340,7 +6340,7 @@ var agent_profile_improvement_proposal_default = {
6340
6340
  ],
6341
6341
  "metadata": {
6342
6342
  "fixture": "agent-profile-improvement-proposal",
6343
- "runtimeVersion": "0.131.0"
6343
+ "runtimeVersion": "0.131.1"
6344
6344
  },
6345
6345
  "objectives": [
6346
6346
  {
@@ -6451,7 +6451,7 @@ var agent_profile_improvement_proposal_default = {
6451
6451
  "baselineContentHash": "sha256:21c495a37c418c10bde64fbaa188beddeed31f1f051ea60a6a6582a9ee0db704",
6452
6452
  "candidateContentHash": "sha256:103f77bc8481601eef1ad5fe6ba84a40dffabc3a44f421f8c8559121edab84e9",
6453
6453
  "kind": "agent-eval-loop",
6454
- "recordDigest": "sha256:30fa9b74d5682ada3d9c40eb90298cda4c3e17c0a45aaf8f821fd422e3bafbf8",
6454
+ "recordDigest": "sha256:c981ecdfd07a3135792dae473a4430515aad326d88eb4fd1f8844ce9439289dc",
6455
6455
  "runId": "profile-improvement-1",
6456
6456
  "schema": "agent-profile-improvement-experiment"
6457
6457
  }
@@ -47,14 +47,7 @@ function createStdioToolServer(options) {
47
47
  if (!tool) return rpcError(message.id ?? null, -32601, `unknown tool: ${name}`);
48
48
  try {
49
49
  const output = await tool.handler(params.arguments ?? {});
50
- return rpcResult(message.id ?? null, {
51
- content: [{
52
- type: "text",
53
- text: JSON.stringify(output)
54
- }],
55
- structuredContent: output,
56
- isError: false
57
- });
50
+ return rpcResult(message.id ?? null, toolCallResult(output));
58
51
  } catch (err) {
59
52
  const reason = err instanceof Error ? err.message : String(err);
60
53
  const code = err instanceof TypeError || err instanceof RangeError ? -32602 : -32e3;
@@ -111,6 +104,26 @@ function createStdioToolServer(options) {
111
104
  stop
112
105
  };
113
106
  }
107
+ function toolCallResult(output) {
108
+ let json;
109
+ try {
110
+ json = JSON.stringify(output);
111
+ } catch (err) {
112
+ const reason = err instanceof Error ? `: ${err.message}` : "";
113
+ throw new TypeError(`MCP tool result must be JSON-serializable${reason}`, { cause: err });
114
+ }
115
+ if (json === void 0) throw new TypeError("MCP tool result must be JSON-serializable");
116
+ const serialized = JSON.parse(json);
117
+ const result = {
118
+ content: [{
119
+ type: "text",
120
+ text: typeof serialized === "string" ? serialized : json
121
+ }],
122
+ isError: false
123
+ };
124
+ if (serialized !== null && typeof serialized === "object" && !Array.isArray(serialized)) result.structuredContent = serialized;
125
+ return result;
126
+ }
114
127
  function rpcResult(id, result) {
115
128
  return {
116
129
  jsonrpc: "2.0",
@@ -138,4 +151,4 @@ function writeResponse(output, response) {
138
151
  //#endregion
139
152
  export { createStdioToolServer as t };
140
153
 
141
- //# sourceMappingURL=tool-server-RcWgLIsL.js.map
154
+ //# sourceMappingURL=tool-server-Gs3VvfSK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-server-Gs3VvfSK.js","names":[],"sources":["../src/mcp/tool-server.ts"],"sourcesContent":["/**\n * `createStdioToolServer` — the generic newline-delimited JSON-RPC 2.0 MCP\n * server core: `initialize` / `notifications/initialized` / `tools/list` /\n * `tools/call` over a stdio-shaped transport, protocol 2024-11-05.\n *\n * Extracted from `createMcpServer` (server.ts) so every in-repo MCP server —\n * the delegation server, the memory server — serves the ONE wire protocol the\n * same-host client (`connectStdioMcp`, runtime/stdio-mcp-client.ts) speaks.\n * A second hand-rolled serve loop could drift from what the client expects;\n * this core makes that impossible by construction.\n *\n * @experimental\n */\n\nimport { createInterface, type Interface as ReadlineInterface } from 'node:readline'\nimport { ValidationError } from '../errors'\nimport type { JsonRpcMessage, JsonRpcResponse, McpToolDescriptor, McpTransport } from './protocol'\n\nexport type { JsonRpcMessage, JsonRpcResponse, McpToolDescriptor, McpTransport } from './protocol'\n\nconst PROTOCOL_VERSION = '2024-11-05'\n\n/** @experimental */\nexport interface StdioToolServerOptions {\n /** Server display name surfaced via `initialize`. */\n serverName: string\n /** Server version surfaced via `initialize`. */\n serverVersion: string\n /** The tools to serve. Duplicate names throw — a silent shadow would hide a tool. */\n tools: readonly McpToolDescriptor[]\n}\n\n/** @experimental */\nexport interface StdioToolServer {\n /** Tools currently registered, keyed by name. */\n readonly tools: ReadonlyMap<string, McpToolDescriptor>\n /** Handle a single parsed JSON-RPC message. Returns the response object (or `null` for notifications). */\n handle(message: JsonRpcMessage): Promise<JsonRpcResponse | null>\n /** Drive the server on a stdio-shaped transport until `stop()` is called. */\n serve(transport?: McpTransport): Promise<void>\n /** Stop a `serve` call. Subsequent requests are rejected. */\n stop(): void\n}\n\n/** Build the generic stdio JSON-RPC tool server. */\nexport function createStdioToolServer(options: StdioToolServerOptions): StdioToolServer {\n const tools = new Map<string, McpToolDescriptor>()\n for (const tool of options.tools) {\n if (tools.has(tool.name)) {\n throw new ValidationError(`createStdioToolServer: duplicate tool name \"${tool.name}\"`)\n }\n tools.set(tool.name, tool)\n }\n\n let stopped = false\n let activeReadline: ReadlineInterface | undefined\n\n async function handle(message: JsonRpcMessage): Promise<JsonRpcResponse | null> {\n if (stopped) {\n return rpcError(message.id ?? null, -32099, 'server stopped')\n }\n if (message.method === 'initialize') {\n return rpcResult(message.id ?? null, {\n protocolVersion: PROTOCOL_VERSION,\n capabilities: { tools: {} },\n serverInfo: { name: options.serverName, version: options.serverVersion },\n })\n }\n if (message.method === 'notifications/initialized') {\n // MCP clients send this after the handshake; it has no id and expects\n // no response.\n return null\n }\n if (message.method === 'tools/list') {\n return rpcResult(message.id ?? null, {\n tools: [...tools.values()].map((tool) => ({\n name: tool.name,\n description: tool.description,\n inputSchema: tool.inputSchema,\n })),\n })\n }\n if (message.method === 'tools/call') {\n const params = (message.params ?? {}) as { name?: unknown; arguments?: unknown }\n const name = typeof params.name === 'string' ? params.name : ''\n const tool = tools.get(name)\n if (!tool) {\n return rpcError(message.id ?? null, -32601, `unknown tool: ${name}`)\n }\n try {\n const output = await tool.handler(params.arguments ?? {})\n return rpcResult(message.id ?? null, toolCallResult(output))\n } catch (err) {\n const reason = err instanceof Error ? err.message : String(err)\n const code = err instanceof TypeError || err instanceof RangeError ? -32602 : -32000\n return rpcError(message.id ?? null, code, reason)\n }\n }\n if (message.id === undefined || message.id === null) return null\n return rpcError(message.id, -32601, `unknown method: ${message.method}`)\n }\n\n async function serve(transport?: McpTransport): Promise<void> {\n const input = transport?.input ?? process.stdin\n const output = transport?.output ?? process.stdout\n const rl = createInterface({ input, crlfDelay: Number.POSITIVE_INFINITY })\n activeReadline = rl\n return new Promise<void>((resolve, reject) => {\n rl.on('line', (line) => {\n const trimmed = line.trim()\n if (!trimmed) return\n let parsed: JsonRpcMessage | undefined\n try {\n parsed = JSON.parse(trimmed) as JsonRpcMessage\n } catch (err) {\n writeResponse(output, rpcError(null, -32700, `parse error: ${(err as Error).message}`))\n return\n }\n if (parsed?.jsonrpc !== '2.0' || typeof parsed.method !== 'string') {\n writeResponse(output, rpcError(parsed?.id ?? null, -32600, 'invalid request'))\n return\n }\n void handle(parsed).then((response) => {\n if (response) writeResponse(output, response)\n })\n })\n rl.on('close', () => resolve())\n rl.on('error', (err) => reject(err))\n if (stopped) {\n rl.close()\n resolve()\n }\n })\n }\n\n function stop(): void {\n stopped = true\n activeReadline?.close()\n activeReadline = undefined\n }\n\n return { tools, handle, serve, stop }\n}\n\nfunction toolCallResult(output: unknown): {\n content: [{ type: 'text'; text: string }]\n structuredContent?: Record<string, unknown>\n isError: false\n} {\n let json: string | undefined\n try {\n json = JSON.stringify(output)\n } catch (err) {\n const reason = err instanceof Error ? `: ${err.message}` : ''\n throw new TypeError(`MCP tool result must be JSON-serializable${reason}`, { cause: err })\n }\n if (json === undefined) {\n throw new TypeError('MCP tool result must be JSON-serializable')\n }\n\n const serialized = JSON.parse(json) as unknown\n // Preserve string content verbatim. MCP clients pass this text directly to the calling agent.\n const result: {\n content: [{ type: 'text'; text: string }]\n structuredContent?: Record<string, unknown>\n isError: false\n } = {\n content: [{ type: 'text', text: typeof serialized === 'string' ? serialized : json }],\n isError: false,\n }\n if (serialized !== null && typeof serialized === 'object' && !Array.isArray(serialized)) {\n result.structuredContent = serialized as Record<string, unknown>\n }\n return result\n}\n\nfunction rpcResult(id: number | string | null, result: unknown): JsonRpcResponse {\n return { jsonrpc: '2.0', id, result }\n}\n\nfunction rpcError(\n id: number | string | null,\n code: number,\n message: string,\n data?: unknown,\n): JsonRpcResponse {\n return {\n jsonrpc: '2.0',\n id,\n error: data === undefined ? { code, message } : { code, message, data },\n }\n}\n\nfunction writeResponse(output: NodeJS.WritableStream, response: JsonRpcResponse): void {\n output.write(`${JSON.stringify(response)}\\n`)\n}\n"],"mappings":";;;;;;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tC;AAEA,SAAS,eAAe,QAItB;CACA,IAAI;CACJ,IAAI;EACF,OAAO,KAAK,UAAU,MAAM;CAC9B,SAAS,KAAK;EACZ,MAAM,SAAS,eAAe,QAAQ,KAAK,IAAI,YAAY;EAC3D,MAAM,IAAI,UAAU,4CAA4C,UAAU,EAAE,OAAO,IAAI,CAAC;CAC1F;CACA,IAAI,SAAS,KAAA,GACX,MAAM,IAAI,UAAU,2CAA2C;CAGjE,MAAM,aAAa,KAAK,MAAM,IAAI;CAElC,MAAM,SAIF;EACF,SAAS,CAAC;GAAE,MAAM;GAAQ,MAAM,OAAO,eAAe,WAAW,aAAa;EAAK,CAAC;EACpF,SAAS;CACX;CACA,IAAI,eAAe,QAAQ,OAAO,eAAe,YAAY,CAAC,MAAM,QAAQ,UAAU,GACpF,OAAO,oBAAoB;CAE7B,OAAO;AACT;AAEA,SAAS,UAAU,IAA4B,QAAkC;CAC/E,OAAO;EAAE,SAAS;EAAO;EAAI;CAAO;AACtC;AAEA,SAAS,SACP,IACA,MACA,SACA,MACiB;CACjB,OAAO;EACL,SAAS;EACT;EACA,OAAO,SAAS,KAAA,IAAY;GAAE;GAAM;EAAQ,IAAI;GAAE;GAAM;GAAS;EAAK;CACxE;AACF;AAEA,SAAS,cAAc,QAA+B,UAAiC;CACrF,OAAO,MAAM,GAAG,KAAK,UAAU,QAAQ,EAAE,GAAG;AAC9C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-runtime",
3
- "version": "0.131.0",
3
+ "version": "0.131.1",
4
4
  "description": "Shared task-lifecycle skeleton for agents: a recursive loop kernel for chat turns, one-shot tasks, and multi-attempt loops, with trace capture and eval-gated self-improvement. Domain behavior lives in adapters; scoring and ship-gates in @tangle-network/agent-eval.",
5
5
  "homepage": "https://github.com/tangle-network/agent-runtime#readme",
6
6
  "repository": {
@@ -116,6 +116,7 @@
116
116
  },
117
117
  "devDependencies": {
118
118
  "@arethetypeswrong/cli": "0.18.5",
119
+ "@modelcontextprotocol/sdk": "1.30.0",
119
120
  "@biomejs/biome": "^2.5.5",
120
121
  "@tangle-network/agent-eval": "0.144.6",
121
122
  "@tangle-network/agent-interface": "0.46.1",
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-server-RcWgLIsL.js","names":[],"sources":["../src/mcp/tool-server.ts"],"sourcesContent":["/**\n * `createStdioToolServer` — the generic newline-delimited JSON-RPC 2.0 MCP\n * server core: `initialize` / `notifications/initialized` / `tools/list` /\n * `tools/call` over a stdio-shaped transport, protocol 2024-11-05.\n *\n * Extracted from `createMcpServer` (server.ts) so every in-repo MCP server —\n * the delegation server, the memory server — serves the ONE wire protocol the\n * same-host client (`connectStdioMcp`, runtime/stdio-mcp-client.ts) speaks.\n * A second hand-rolled serve loop could drift from what the client expects;\n * this core makes that impossible by construction.\n *\n * @experimental\n */\n\nimport { createInterface, type Interface as ReadlineInterface } from 'node:readline'\nimport { ValidationError } from '../errors'\nimport type { JsonRpcMessage, JsonRpcResponse, McpToolDescriptor, McpTransport } from './protocol'\n\nexport type { JsonRpcMessage, JsonRpcResponse, McpToolDescriptor, McpTransport } from './protocol'\n\nconst PROTOCOL_VERSION = '2024-11-05'\n\n/** @experimental */\nexport interface StdioToolServerOptions {\n /** Server display name surfaced via `initialize`. */\n serverName: string\n /** Server version surfaced via `initialize`. */\n serverVersion: string\n /** The tools to serve. Duplicate names throw — a silent shadow would hide a tool. */\n tools: readonly McpToolDescriptor[]\n}\n\n/** @experimental */\nexport interface StdioToolServer {\n /** Tools currently registered, keyed by name. */\n readonly tools: ReadonlyMap<string, McpToolDescriptor>\n /** Handle a single parsed JSON-RPC message. Returns the response object (or `null` for notifications). */\n handle(message: JsonRpcMessage): Promise<JsonRpcResponse | null>\n /** Drive the server on a stdio-shaped transport until `stop()` is called. */\n serve(transport?: McpTransport): Promise<void>\n /** Stop a `serve` call. Subsequent requests are rejected. */\n stop(): void\n}\n\n/** Build the generic stdio JSON-RPC tool server. */\nexport function createStdioToolServer(options: StdioToolServerOptions): StdioToolServer {\n const tools = new Map<string, McpToolDescriptor>()\n for (const tool of options.tools) {\n if (tools.has(tool.name)) {\n throw new ValidationError(`createStdioToolServer: duplicate tool name \"${tool.name}\"`)\n }\n tools.set(tool.name, tool)\n }\n\n let stopped = false\n let activeReadline: ReadlineInterface | undefined\n\n async function handle(message: JsonRpcMessage): Promise<JsonRpcResponse | null> {\n if (stopped) {\n return rpcError(message.id ?? null, -32099, 'server stopped')\n }\n if (message.method === 'initialize') {\n return rpcResult(message.id ?? null, {\n protocolVersion: PROTOCOL_VERSION,\n capabilities: { tools: {} },\n serverInfo: { name: options.serverName, version: options.serverVersion },\n })\n }\n if (message.method === 'notifications/initialized') {\n // MCP clients send this after the handshake; it has no id and expects\n // no response.\n return null\n }\n if (message.method === 'tools/list') {\n return rpcResult(message.id ?? null, {\n tools: [...tools.values()].map((tool) => ({\n name: tool.name,\n description: tool.description,\n inputSchema: tool.inputSchema,\n })),\n })\n }\n if (message.method === 'tools/call') {\n const params = (message.params ?? {}) as { name?: unknown; arguments?: unknown }\n const name = typeof params.name === 'string' ? params.name : ''\n const tool = tools.get(name)\n if (!tool) {\n return rpcError(message.id ?? null, -32601, `unknown tool: ${name}`)\n }\n try {\n const output = await tool.handler(params.arguments ?? {})\n return rpcResult(message.id ?? null, {\n content: [{ type: 'text', text: JSON.stringify(output) }],\n structuredContent: output,\n isError: false,\n })\n } catch (err) {\n const reason = err instanceof Error ? err.message : String(err)\n const code = err instanceof TypeError || err instanceof RangeError ? -32602 : -32000\n return rpcError(message.id ?? null, code, reason)\n }\n }\n if (message.id === undefined || message.id === null) return null\n return rpcError(message.id, -32601, `unknown method: ${message.method}`)\n }\n\n async function serve(transport?: McpTransport): Promise<void> {\n const input = transport?.input ?? process.stdin\n const output = transport?.output ?? process.stdout\n const rl = createInterface({ input, crlfDelay: Number.POSITIVE_INFINITY })\n activeReadline = rl\n return new Promise<void>((resolve, reject) => {\n rl.on('line', (line) => {\n const trimmed = line.trim()\n if (!trimmed) return\n let parsed: JsonRpcMessage | undefined\n try {\n parsed = JSON.parse(trimmed) as JsonRpcMessage\n } catch (err) {\n writeResponse(output, rpcError(null, -32700, `parse error: ${(err as Error).message}`))\n return\n }\n if (parsed?.jsonrpc !== '2.0' || typeof parsed.method !== 'string') {\n writeResponse(output, rpcError(parsed?.id ?? null, -32600, 'invalid request'))\n return\n }\n void handle(parsed).then((response) => {\n if (response) writeResponse(output, response)\n })\n })\n rl.on('close', () => resolve())\n rl.on('error', (err) => reject(err))\n if (stopped) {\n rl.close()\n resolve()\n }\n })\n }\n\n function stop(): void {\n stopped = true\n activeReadline?.close()\n activeReadline = undefined\n }\n\n return { tools, handle, serve, stop }\n}\n\nfunction rpcResult(id: number | string | null, result: unknown): JsonRpcResponse {\n return { jsonrpc: '2.0', id, result }\n}\n\nfunction rpcError(\n id: number | string | null,\n code: number,\n message: string,\n data?: unknown,\n): JsonRpcResponse {\n return {\n jsonrpc: '2.0',\n id,\n error: data === undefined ? { code, message } : { code, message, data },\n }\n}\n\nfunction writeResponse(output: NodeJS.WritableStream, response: JsonRpcResponse): void {\n output.write(`${JSON.stringify(response)}\\n`)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAoBA,MAAM,mBAAmB;;AAyBzB,SAAgB,sBAAsB,SAAkD;CACtF,MAAM,wBAAQ,IAAI,IAA+B;CACjD,KAAK,MAAM,QAAQ,QAAQ,OAAO;EAChC,IAAI,MAAM,IAAI,KAAK,IAAI,GACrB,MAAM,IAAI,gBAAgB,+CAA+C,KAAK,KAAK,EAAE;EAEvF,MAAM,IAAI,KAAK,MAAM,IAAI;CAC3B;CAEA,IAAI,UAAU;CACd,IAAI;CAEJ,eAAe,OAAO,SAA0D;EAC9E,IAAI,SACF,OAAO,SAAS,QAAQ,MAAM,MAAM,QAAQ,gBAAgB;EAE9D,IAAI,QAAQ,WAAW,cACrB,OAAO,UAAU,QAAQ,MAAM,MAAM;GACnC,iBAAiB;GACjB,cAAc,EA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