@stdiobus/workers-registry 1.3.18 → 1.3.20
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/README.md +89 -43
- package/launch/.gitkeep +1 -0
- package/launch/index.js +1 -1
- package/launch/index.js.map +2 -2
- package/out/dist/workers-registry/acp-registry/acp-registry-config.json +10 -0
- package/out/dist/workers-registry/acp-registry/index.js +5 -0
- package/out/dist/workers-registry/acp-registry/index.js.map +7 -0
- package/out/dist/workers-registry/acp-worker/index.js +3 -3
- package/out/dist/workers-registry/acp-worker/index.js.map +3 -3
- package/out/dist/workers-registry/index.js +2 -2
- package/out/dist/workers-registry/mcp-to-acp-proxy/proxy.js.map +1 -1
- package/out/tsc/workers-registry/acp-worker/src/mcp-proxy/converter.d.ts +3 -0
- package/out/tsc/workers-registry/acp-worker/src/stdio/index.d.ts +1 -0
- package/out/tsc/workers-registry/acp-worker/src/stdio/session-id-router.d.ts +21 -0
- package/out/tsc/workers-registry/acp-worker/src/stdio/session-id-router.test.d.ts +1 -0
- package/package.json +1 -1
- package/out/dist/workers-registry/acp-registry/registry-launcher-client.js +0 -52
- package/out/dist/workers-registry/acp-registry/registry-launcher-client.js.map +0 -7
- package/out/dist/workers-registry/acp-registry/registry-launcher-config.json +0 -30
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Auto-generated by build script
|
|
2
2
|
export const workers = {
|
|
3
3
|
"acp-registry": {
|
|
4
|
-
"entrypoint": "./acp-registry/
|
|
4
|
+
"entrypoint": "./acp-registry/index.js",
|
|
5
5
|
"types": null,
|
|
6
|
-
"config": "./acp-registry/registry-
|
|
6
|
+
"config": "./acp-registry/acp-registry-config.json",
|
|
7
7
|
"type": "javascript"
|
|
8
8
|
},
|
|
9
9
|
"acp-worker": {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../workers-registry/mcp-to-acp-proxy/proxy.js"],
|
|
4
|
-
"sourcesContent": ["#!/usr/bin/env node\n\n/*\n * Apache License 2.0\n * Copyright (c) 2025\u2013present Raman Marozau, Target Insight Function.\n * Contact: raman@worktif.com\n *\n * This file is part of the stdio bus protocol reference implementation:\n * stdio_bus_kernel_workers (target: <target_stdio_bus_kernel_workers>).\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * MCP-to-ACP Protocol Proxy\n *\n * Converts MCP protocol (from Kiro) to ACP protocol (for stdio Bus)\n * Runs as MCP server for Kiro, forwards to ACP via TCP\n */\n\nimport net from 'net';\nimport { createInterface } from 'readline';\n\nconst ACP_HOST = process.env.ACP_HOST || '127.0.0.1';\nconst ACP_PORT = process.env.ACP_PORT || 9000;\nconst AGENT_ID = process.env.AGENT_ID || 'default-agent';\n\nconsole.error(`[MCP-APC][proxy] Starting proxy...`);\nconsole.error(`[MCP-APC][proxy] Target: ${ACP_HOST}:${ACP_PORT}`);\nconsole.error(`[MCP-APC][proxy] Agent ID: ${AGENT_ID}`);\n\n// State\nconst acpSocket = net.connect(ACP_PORT, ACP_HOST);\nlet acpConnected = false;\nlet proxySessionId = null; // For stdio Bus routing\nlet acpSessionId = null; // From ACP agent\nlet pendingRequests = new Map(); // id -> {method, params, ...}\nlet accumulatedText = new Map(); // requestId -> accumulated text\n\nacpSocket.on('connect', () => {\n console.error('[MCP-APC][proxy] Connected to ACP stdio Bus');\n acpConnected = true;\n});\n\nacpSocket.on('error', (err) => {\n console.error(`[MCP-APC][proxy] ACP connection error: ${err.message}`);\n process.exit(1);\n});\n\n// Handle ACP messages\nlet acpBuffer = '';\nacpSocket.on('data', (data) => {\n acpBuffer += data.toString();\n\n let newlineIndex;\n while ((newlineIndex = acpBuffer.indexOf('\\n')) !== -1) {\n const line = acpBuffer.slice(0, newlineIndex);\n acpBuffer = acpBuffer.slice(newlineIndex + 1);\n\n if (line.trim()) {\n try {\n const acpMsg = JSON.parse(line);\n console.error(`[MCP-APC][proxy] \u2190 ACP: ${JSON.stringify(acpMsg)}`);\n\n // Check if notification or response\n if (acpMsg.id === undefined || acpMsg.id === null) {\n // Notification\n console.error(`[MCP-APC][proxy] Processing notification: ${acpMsg.method}`);\n handleACPNotification(acpMsg);\n } else {\n // Response\n console.error(`[MCP-APC][proxy] Processing response id=${acpMsg.id}`);\n console.error(`[MCP-APC][proxy] Pending: ${JSON.stringify([...pendingRequests.keys()])}`);\n const mcpResponse = convertACPtoMCP(acpMsg);\n if (mcpResponse) {\n console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(mcpResponse)}`);\n process.stdout.write(JSON.stringify(mcpResponse) + '\\n');\n } else {\n console.error(`[MCP-APC][proxy] WARNING: No MCP response for id=${acpMsg.id}`);\n }\n }\n } catch (err) {\n console.error(`[MCP-APC][proxy] Error parsing ACP: ${err.message}`);\n }\n }\n }\n});\n\n// Handle MCP requests\nconst rl = createInterface({\n input: process.stdin,\n terminal: false\n});\n\nrl.on('line', (line) => {\n if (!line.trim()) return;\n\n try {\n const mcpReq = JSON.parse(line);\n console.error(`[MCP-APC][proxy] \u2190 MCP: ${JSON.stringify(mcpReq)}`);\n\n const acpReq = convertMCPtoACP(mcpReq);\n if (acpReq) {\n console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(acpReq)}`);\n if (acpConnected) {\n acpSocket.write(JSON.stringify(acpReq) + '\\n');\n }\n }\n } catch (err) {\n console.error(`[MCP-APC][proxy] Error parsing MCP: ${err.message}`);\n }\n});\n\nfunction handleACPNotification(msg) {\n const { method, params } = msg;\n\n if (method === 'session/update' && params?.update) {\n const update = params.update;\n\n // Find pending session/prompt request\n for (const [reqId, pending] of pendingRequests.entries()) {\n if (pending.method === 'session/prompt') {\n if (update.sessionUpdate === 'agent_message_chunk' && update.content?.text) {\n if (!accumulatedText.has(reqId)) {\n accumulatedText.set(reqId, '');\n }\n accumulatedText.set(reqId, accumulatedText.get(reqId) + update.content.text);\n }\n break;\n }\n }\n }\n}\n\nfunction convertMCPtoACP(mcpReq) {\n const { id, method, params } = mcpReq;\n\n if (id === undefined || id === null) {\n return null; // Ignore notifications\n }\n\n pendingRequests.set(id, { method, params });\n\n if (!proxySessionId) {\n proxySessionId = `proxy-${Date.now()}`;\n }\n\n switch (method) {\n case 'initialize':\n return {\n jsonrpc: '2.0',\n id,\n method: 'initialize',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: {\n protocolVersion: 1,\n clientCapabilities: params?.capabilities || {},\n clientInfo: params?.clientInfo || { name: 'mcp-proxy', version: '1.0.0' }\n }\n };\n\n case 'tools/list':\n sendMCP({\n jsonrpc: '2.0',\n id,\n result: {\n tools: [{\n name: 'acp_prompt',\n description: `Send prompt to ${AGENT_ID}`,\n inputSchema: {\n type: 'object',\n properties: {\n prompt: { type: 'string', description: 'Prompt text' }\n },\n required: ['prompt']\n }\n }]\n }\n });\n pendingRequests.delete(id);\n return null;\n\n case 'tools/call':\n const promptText = params?.arguments?.prompt || '';\n\n if (!acpSessionId) {\n // Need to create session first\n const sessionReqId = `sess-${id}`;\n pendingRequests.set(sessionReqId, {\n method: 'session/new',\n originalId: id,\n promptText\n });\n return {\n jsonrpc: '2.0',\n id: sessionReqId,\n method: 'session/new',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: { cwd: process.cwd(), mcpServers: [] }\n };\n }\n\n // Session exists, send prompt\n // IMPORTANT: Update pending to session/prompt since that's what we're sending\n pendingRequests.set(id, { method: 'session/prompt', params });\n return {\n jsonrpc: '2.0',\n id,\n method: 'session/prompt',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: {\n sessionId: acpSessionId,\n prompt: [{ type: 'text', text: promptText }]\n }\n };\n\n case 'resources/list':\n sendMCP({ jsonrpc: '2.0', id, result: { resources: [] } });\n pendingRequests.delete(id);\n return null;\n\n case 'resources/templates/list':\n sendMCP({ jsonrpc: '2.0', id, result: { resourceTemplates: [] } });\n pendingRequests.delete(id);\n return null;\n\n case 'prompts/list':\n sendMCP({ jsonrpc: '2.0', id, result: { prompts: [] } });\n pendingRequests.delete(id);\n return null;\n\n default:\n sendMCP({ jsonrpc: '2.0', id, error: { code: -32601, message: `Unknown method: ${method}` } });\n pendingRequests.delete(id);\n return null;\n }\n}\n\nfunction convertACPtoMCP(acpResp) {\n const { id, result, error } = acpResp;\n\n const pending = pendingRequests.get(id);\n if (!pending) {\n console.error(`[MCP-APC][proxy] ERROR: No pending request for id=${id}`);\n return null;\n }\n\n console.error(`[MCP-APC][proxy] Converting ACP->MCP for method: ${pending.method}`);\n pendingRequests.delete(id);\n\n if (error) {\n accumulatedText.delete(id);\n return {\n jsonrpc: '2.0',\n id,\n error: { code: error.code || -32603, message: error.message || 'ACP error' }\n };\n }\n\n switch (pending.method) {\n case 'initialize':\n return {\n jsonrpc: '2.0',\n id,\n result: {\n protocolVersion: '2024-11-05',\n capabilities: { tools: {}, resources: {} },\n serverInfo: result?.agentInfo || { name: 'acp-agent', version: '1.0.0' }\n }\n };\n\n case 'session/new':\n acpSessionId = result?.sessionId;\n console.error(`[MCP-APC][proxy] ACP session: ${acpSessionId}`);\n\n if (pending.originalId && pending.promptText) {\n // Send queued prompt\n const promptReq = {\n jsonrpc: '2.0',\n id: pending.originalId,\n method: 'session/prompt',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: {\n sessionId: acpSessionId,\n prompt: [{ type: 'text', text: pending.promptText }]\n }\n };\n\n pendingRequests.set(pending.originalId, { method: 'session/prompt' });\n\n console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(promptReq)}`);\n if (acpConnected) {\n acpSocket.write(JSON.stringify(promptReq) + '\\n');\n }\n }\n return null;\n\n case 'session/prompt':\n const text = accumulatedText.get(id) || '';\n accumulatedText.delete(id);\n console.error(`[MCP-APC][proxy] Returning accumulated text (${text.length} chars): \"${text.substring(0, 50)}...\"`);\n return {\n jsonrpc: '2.0',\n id,\n result: {\n content: [{ type: 'text', text: text || 'No response' }]\n }\n };\n\n default:\n console.error(`[MCP-APC][proxy] WARNING: Unhandled method ${pending.method}, returning raw result`);\n return { jsonrpc: '2.0', id, result: result || {} };\n }\n}\n\nfunction sendMCP(msg) {\n console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(msg)}`);\n process.stdout.write(JSON.stringify(msg) + '\\n');\n}\n\nprocess.on('SIGTERM', () => {\n acpSocket.end();\n process.exit(0);\n});\n\nprocess.on('SIGINT', () => {\n acpSocket.end();\n process.exit(0);\n});\n"],
|
|
4
|
+
"sourcesContent": ["#!/usr/bin/env node\n\n/*\n * Apache License 2.0\n * Copyright (c) 2025\u2013present Raman Marozau, Target Insight Function.\n * Contact: raman@worktif.com\n *\n * This file is part of the stdio bus protocol reference implementation:\n * stdio_bus_kernel_workers (target: <target_stdio_bus_kernel_workers>).\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * MCP-to-ACP Protocol Proxy\n *\n * Converts MCP protocol (from Kiro) to ACP protocol (for stdio Bus)\n * Runs as MCP server for Kiro, forwards to ACP via TCP\n */\n\nimport net from 'net';\nimport { createInterface } from 'readline';\n\nconst ACP_HOST = process.env.ACP_HOST || '127.0.0.1';\nconst ACP_PORT = process.env.ACP_PORT || 9000;\nconst AGENT_ID = process.env.AGENT_ID || 'default-agent';\n\nconsole.error(`[MCP-APC][proxy] Starting proxy...`);\nconsole.error(`[MCP-APC][proxy] Target: ${ACP_HOST}:${ACP_PORT}`);\nconsole.error(`[MCP-APC][proxy] Agent ID: ${AGENT_ID}`);\n\n// State\nconst acpSocket = net.connect(ACP_PORT, ACP_HOST);\nlet acpConnected = false;\nlet proxySessionId = null; // For stdio Bus routing\nlet acpSessionId = null; // From ACP agent\nlet pendingRequests = new Map(); // id -> {method, params, ...}\nlet accumulatedText = new Map(); // requestId -> accumulated text\n\nacpSocket.on('connect', () => {\n console.error('[MCP-APC][proxy] Connected to ACP stdio Bus');\n acpConnected = true;\n});\n\nacpSocket.on('error', (err) => {\n console.error(`[MCP-APC][proxy] ACP connection error: ${err.message}`);\n process.exit(1);\n});\n\n// Handle ACP messages\nlet acpBuffer = '';\nacpSocket.on('data', (data) => {\n acpBuffer += data.toString();\n\n let newlineIndex;\n while ((newlineIndex = acpBuffer.indexOf('\\n')) !== -1) {\n const line = acpBuffer.slice(0, newlineIndex);\n acpBuffer = acpBuffer.slice(newlineIndex + 1);\n\n if (line.trim()) {\n try {\n const acpMsg = JSON.parse(line);\n console.error(`[MCP-APC][proxy] \u2190 ACP: ${JSON.stringify(acpMsg)}`);\n\n // Check if notification or response\n if (acpMsg.id === undefined || acpMsg.id === null) {\n // Notification from ACP worker - rewrite sessionId and send back to stdio Bus\n console.error(`[MCP-APC][proxy] Processing notification: ${acpMsg.method}`);\n handleACPNotification(acpMsg);\n } else {\n // Response\n console.error(`[MCP-APC][proxy] Processing response id=${acpMsg.id}`);\n console.error(`[MCP-APC][proxy] Pending: ${JSON.stringify([...pendingRequests.keys()])}`);\n const mcpResponse = convertACPtoMCP(acpMsg);\n if (mcpResponse) {\n console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(mcpResponse)}`);\n process.stdout.write(JSON.stringify(mcpResponse) + '\\n');\n } else {\n console.error(`[MCP-APC][proxy] WARNING: No MCP response for id=${acpMsg.id}`);\n }\n }\n } catch (err) {\n console.error(`[MCP-APC][proxy] Error parsing ACP: ${err.message}`);\n }\n }\n }\n});\n\n// Handle MCP requests\nconst rl = createInterface({\n input: process.stdin,\n terminal: false\n});\n\nrl.on('line', (line) => {\n if (!line.trim()) return;\n\n try {\n const mcpReq = JSON.parse(line);\n console.error(`[MCP-APC][proxy] \u2190 MCP: ${JSON.stringify(mcpReq)}`);\n\n const acpReq = convertMCPtoACP(mcpReq);\n if (acpReq) {\n console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(acpReq)}`);\n if (acpConnected) {\n acpSocket.write(JSON.stringify(acpReq) + '\\n');\n }\n }\n } catch (err) {\n console.error(`[MCP-APC][proxy] Error parsing MCP: ${err.message}`);\n }\n});\n\nfunction handleACPNotification(msg) {\n const { method, params } = msg;\n\n if (method === 'session/update' && params?.update) {\n const update = params.update;\n\n // Find pending session/prompt request\n for (const [reqId, pending] of pendingRequests.entries()) {\n if (pending.method === 'session/prompt') {\n if (update.sessionUpdate === 'agent_message_chunk' && update.content?.text) {\n if (!accumulatedText.has(reqId)) {\n accumulatedText.set(reqId, '');\n }\n accumulatedText.set(reqId, accumulatedText.get(reqId) + update.content.text);\n }\n break;\n }\n }\n }\n}\n\nfunction convertMCPtoACP(mcpReq) {\n const { id, method, params } = mcpReq;\n\n if (id === undefined || id === null) {\n return null; // Ignore notifications\n }\n\n pendingRequests.set(id, { method, params });\n\n if (!proxySessionId) {\n proxySessionId = `proxy-${Date.now()}`;\n }\n\n switch (method) {\n case 'initialize':\n return {\n jsonrpc: '2.0',\n id,\n method: 'initialize',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: {\n protocolVersion: 1,\n clientCapabilities: params?.capabilities || {},\n clientInfo: params?.clientInfo || { name: 'mcp-proxy', version: '1.0.0' }\n }\n };\n\n case 'tools/list':\n sendMCP({\n jsonrpc: '2.0',\n id,\n result: {\n tools: [{\n name: 'acp_prompt',\n description: `Send prompt to ${AGENT_ID}`,\n inputSchema: {\n type: 'object',\n properties: {\n prompt: { type: 'string', description: 'Prompt text' }\n },\n required: ['prompt']\n }\n }]\n }\n });\n pendingRequests.delete(id);\n return null;\n\n case 'tools/call':\n const promptText = params?.arguments?.prompt || '';\n\n if (!acpSessionId) {\n // Need to create session first\n const sessionReqId = `sess-${id}`;\n pendingRequests.set(sessionReqId, {\n method: 'session/new',\n originalId: id,\n promptText\n });\n return {\n jsonrpc: '2.0',\n id: sessionReqId,\n method: 'session/new',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: { cwd: process.cwd(), mcpServers: [] }\n };\n }\n\n // Session exists, send prompt\n // IMPORTANT: Update pending to session/prompt since that's what we're sending\n pendingRequests.set(id, { method: 'session/prompt', params });\n return {\n jsonrpc: '2.0',\n id,\n method: 'session/prompt',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: {\n sessionId: acpSessionId,\n prompt: [{ type: 'text', text: promptText }]\n }\n };\n\n case 'resources/list':\n sendMCP({ jsonrpc: '2.0', id, result: { resources: [] } });\n pendingRequests.delete(id);\n return null;\n\n case 'resources/templates/list':\n sendMCP({ jsonrpc: '2.0', id, result: { resourceTemplates: [] } });\n pendingRequests.delete(id);\n return null;\n\n case 'prompts/list':\n sendMCP({ jsonrpc: '2.0', id, result: { prompts: [] } });\n pendingRequests.delete(id);\n return null;\n\n default:\n sendMCP({ jsonrpc: '2.0', id, error: { code: -32601, message: `Unknown method: ${method}` } });\n pendingRequests.delete(id);\n return null;\n }\n}\n\nfunction convertACPtoMCP(acpResp) {\n const { id, result, error } = acpResp;\n\n const pending = pendingRequests.get(id);\n if (!pending) {\n console.error(`[MCP-APC][proxy] ERROR: No pending request for id=${id}`);\n return null;\n }\n\n console.error(`[MCP-APC][proxy] Converting ACP->MCP for method: ${pending.method}`);\n pendingRequests.delete(id);\n\n if (error) {\n accumulatedText.delete(id);\n return {\n jsonrpc: '2.0',\n id,\n error: { code: error.code || -32603, message: error.message || 'ACP error' }\n };\n }\n\n switch (pending.method) {\n case 'initialize':\n return {\n jsonrpc: '2.0',\n id,\n result: {\n protocolVersion: '2024-11-05',\n capabilities: { tools: {}, resources: {} },\n serverInfo: result?.agentInfo || { name: 'acp-agent', version: '1.0.0' }\n }\n };\n\n case 'session/new':\n acpSessionId = result?.sessionId;\n console.error(`[MCP-APC][proxy] ACP session: ${acpSessionId}`);\n\n if (pending.originalId && pending.promptText) {\n // Send queued prompt\n const promptReq = {\n jsonrpc: '2.0',\n id: pending.originalId,\n method: 'session/prompt',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: {\n sessionId: acpSessionId,\n prompt: [{ type: 'text', text: pending.promptText }]\n }\n };\n\n pendingRequests.set(pending.originalId, { method: 'session/prompt' });\n\n console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(promptReq)}`);\n if (acpConnected) {\n acpSocket.write(JSON.stringify(promptReq) + '\\n');\n }\n }\n return null;\n\n case 'session/prompt':\n const text = accumulatedText.get(id) || '';\n accumulatedText.delete(id);\n console.error(`[MCP-APC][proxy] Returning accumulated text (${text.length} chars): \"${text.substring(0, 50)}...\"`);\n return {\n jsonrpc: '2.0',\n id,\n result: {\n content: [{ type: 'text', text: text || 'No response' }]\n }\n };\n\n default:\n console.error(`[MCP-APC][proxy] WARNING: Unhandled method ${pending.method}, returning raw result`);\n return { jsonrpc: '2.0', id, result: result || {} };\n }\n}\n\nfunction sendMCP(msg) {\n console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(msg)}`);\n process.stdout.write(JSON.stringify(msg) + '\\n');\n}\n\nprocess.on('SIGTERM', () => {\n acpSocket.end();\n process.exit(0);\n});\n\nprocess.on('SIGINT', () => {\n acpSocket.end();\n process.exit(0);\n});\n"],
|
|
5
5
|
"mappings": ";AAgCA,OAAO,QAAS,MAChB,OAAS,oBAAuB,WAEhC,IAAM,SAAW,QAAQ,IAAI,UAAY,YACzC,IAAM,SAAW,QAAQ,IAAI,UAAY,I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ProtocolConverter {
|
|
|
138
138
|
* Returns accumulated text from streaming notifications.
|
|
139
139
|
*/
|
|
140
140
|
private convertSessionPromptResponse;
|
|
141
|
+
private extractTextFromResult;
|
|
142
|
+
private extractTextFromContentBlocks;
|
|
143
|
+
private readText;
|
|
141
144
|
/**
|
|
142
145
|
* Handle session/update notification.
|
|
143
146
|
* Accumulates text chunks for agent_message_chunk updates.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './session-id-router.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class SessionIdRouter {
|
|
2
|
+
private readonly requestSessionIdMap;
|
|
3
|
+
private readonly acpSessionIdMap;
|
|
4
|
+
/**
|
|
5
|
+
* Process a single inbound (stdin) line.
|
|
6
|
+
*
|
|
7
|
+
* - Saves stdio Bus sessionId for request/response correlation
|
|
8
|
+
* - Tracks ACP sessionId ↔ stdio Bus sessionId mapping when available
|
|
9
|
+
* - Strips stdio Bus sessionId before passing to ACP SDK
|
|
10
|
+
*/
|
|
11
|
+
processIncomingLine(line: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Process a single outbound (stdout) line.
|
|
14
|
+
*
|
|
15
|
+
* - Restores stdio Bus sessionId on responses using request mapping
|
|
16
|
+
* - Maps ACP sessionId to stdio Bus sessionId for notifications
|
|
17
|
+
*/
|
|
18
|
+
processOutgoingLine(line: string): string;
|
|
19
|
+
private readSessionId;
|
|
20
|
+
private setAcpSessionMapping;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import net from"net";import readline from"readline";import crypto from"crypto";function parseArgs(){const args=process.argv.slice(2);const options={tcp:null,unix:null,agentId:null,flow:null,sessionId:null,prompt:"Hello, agent!",interactive:false,timeout:3e4,help:false};for(let i=0;i<args.length;i++){const arg=args[i];switch(arg){case"--tcp":options.tcp=args[++i];break;case"--unix":options.unix=args[++i];break;case"--agent":options.agentId=args[++i];break;case"--flow":options.flow=args[++i];break;case"--session":options.sessionId=args[++i];break;case"--prompt":options.prompt=args[++i];break;case"--interactive":options.interactive=true;break;case"--timeout":options.timeout=parseInt(args[++i],10);break;case"--help":case"-h":options.help=true;break;default:console.error(`Unknown option: ${arg}`);process.exit(1)}}return options}function showHelp(){console.log(`
|
|
3
|
-
ACP Registry Transit Test Client
|
|
4
|
-
|
|
5
|
-
This client demonstrates sending ACP messages through the Registry Launcher
|
|
6
|
-
transit chain: Client \u2192 stdio Bus \u2192 Registry Launcher \u2192 ACP Agent \u2192 back
|
|
7
|
-
|
|
8
|
-
Usage:
|
|
9
|
-
node registry-launcher-client.js --tcp <host:port> --agent <id> [options]
|
|
10
|
-
node registry-launcher-client.js --unix <path> --agent <id> [options]
|
|
11
|
-
|
|
12
|
-
Connection (one required):
|
|
13
|
-
--tcp <host:port> Connect via TCP (e.g., localhost:9000)
|
|
14
|
-
--unix <path> Connect via Unix socket (e.g., /tmp/stdio_bus.sock)
|
|
15
|
-
|
|
16
|
-
Required:
|
|
17
|
-
--agent <id> Agent ID from ACP Registry to route messages to
|
|
18
|
-
|
|
19
|
-
ACP Flow Options:
|
|
20
|
-
--flow <type> ACP flow to execute:
|
|
21
|
-
initialize - Send initialize request
|
|
22
|
-
session-new - Create new session
|
|
23
|
-
session-prompt - Send prompt to session
|
|
24
|
-
full - Run full flow (init \u2192 new \u2192 prompt)
|
|
25
|
-
--session <id> Session ID for session/prompt (auto-generated if not set)
|
|
26
|
-
--prompt <text> Prompt text for session/prompt (default: "Hello, agent!")
|
|
27
|
-
|
|
28
|
-
Modes:
|
|
29
|
-
--interactive Read JSON from stdin, auto-add agentId to messages
|
|
30
|
-
--timeout <ms> Response timeout in ms (default: 30000)
|
|
31
|
-
|
|
32
|
-
Other:
|
|
33
|
-
--help, -h Show this help message
|
|
34
|
-
|
|
35
|
-
Examples:
|
|
36
|
-
# Run full ACP flow with an agent
|
|
37
|
-
node registry-launcher-client.js --tcp localhost:9000 --agent my-agent --flow full
|
|
38
|
-
|
|
39
|
-
# Send just an initialize request
|
|
40
|
-
node registry-launcher-client.js --tcp localhost:9000 --agent my-agent --flow initialize
|
|
41
|
-
|
|
42
|
-
# Create a new session
|
|
43
|
-
node registry-launcher-client.js --tcp localhost:9000 --agent my-agent --flow session-new
|
|
44
|
-
|
|
45
|
-
# Send a prompt to an existing session
|
|
46
|
-
node registry-launcher-client.js --tcp localhost:9000 --agent my-agent --flow session-prompt --session sess-123
|
|
47
|
-
|
|
48
|
-
# Interactive mode - type JSON messages, agentId added automatically
|
|
49
|
-
node registry-launcher-client.js --tcp localhost:9000 --agent my-agent --interactive
|
|
50
|
-
`)}function generateId(prefix="req"){return`${prefix}-${crypto.randomUUID().slice(0,8)}`}function generateSessionId(){return`sess-${crypto.randomUUID().slice(0,8)}`}function buildInitializeRequest(agentId){return{jsonrpc:"2.0",id:generateId("init"),method:"initialize",agentId,params:{protocolVersion:1,clientCapabilities:{},clientInfo:{name:"registry-launcher-test-client",version:"1.0.0"}}}}function buildAuthenticateRequest(agentId,methodId){return{jsonrpc:"2.0",id:generateId("auth"),method:"authenticate",agentId,params:{methodId}}}function buildSessionNewRequest(agentId){return{jsonrpc:"2.0",id:generateId("session-new"),method:"session/new",agentId,params:{cwd:process.cwd(),mcpServers:[]}}}function buildSessionPromptRequest(agentId,sessionId,promptText){return{jsonrpc:"2.0",id:generateId("prompt"),method:"session/prompt",agentId,params:{sessionId,prompt:[{type:"text",text:promptText}]}}}function createConnection(options){if(options.tcp){const[host,portStr]=options.tcp.split(":");const port=parseInt(portStr,10);if(!host||isNaN(port)){console.error("Invalid TCP address. Use format: host:port");process.exit(1)}console.error(`Connecting to TCP ${host}:${port}...`);return net.createConnection({host,port})}else if(options.unix){console.error(`Connecting to Unix socket ${options.unix}...`);return net.createConnection({path:options.unix})}else{console.error("Error: Must specify --tcp or --unix");process.exit(1)}}function sendRequest(socket,request,timeout){return new Promise((resolve,reject)=>{let buffer="";let timeoutId;const cleanup=()=>{clearTimeout(timeoutId);socket.removeListener("data",onData);socket.removeListener("error",onError);socket.removeListener("close",onClose)};const onData=data=>{buffer+=data.toString();let newlineIndex;while((newlineIndex=buffer.indexOf("\n"))!==-1){const line=buffer.slice(0,newlineIndex);buffer=buffer.slice(newlineIndex+1);if(line.trim()){try{const response=JSON.parse(line);if(response.id===request.id){cleanup();resolve(response);return}else{console.error(`\u2190 Received (other): ${JSON.stringify(response)}`)}}catch(err){console.error(`Error parsing response: ${err.message}`)}}}};const onError=err=>{cleanup();reject(new Error(`Connection error: ${err.message}`))};const onClose=()=>{cleanup();reject(new Error("Connection closed before response received"))};timeoutId=setTimeout(()=>{cleanup();reject(new Error(`Timeout: No response within ${timeout}ms`))},timeout);socket.on("data",onData);socket.on("error",onError);socket.on("close",onClose);console.error(`\u2192 Sending: ${JSON.stringify(request)}`);socket.write(JSON.stringify(request)+"\n")})}async function runInitializeFlow(socket,options){console.error("\n=== Initialize Flow ===");const request=buildInitializeRequest(options.agentId);const response=await sendRequest(socket,request,options.timeout);console.log("\nInitialize Response:");console.log(JSON.stringify(response,null,2));if(response.error){console.error(`\u2717 Initialize failed: ${response.error.message}`)}else{console.error("\u2713 Initialize successful");if(response.result?.protocolVersion){console.error(` Protocol version: ${response.result.protocolVersion}`)}if(response.result?.serverInfo){console.error(` Server: ${response.result.serverInfo.name} v${response.result.serverInfo.version}`)}}return response}async function runAuthenticateFlow(socket,options,methodId){console.error("\n=== Authenticate Flow ===");console.error(` Method: ${methodId}`);const request=buildAuthenticateRequest(options.agentId,methodId);const response=await sendRequest(socket,request,options.timeout);console.log("\nAuthenticate Response:");console.log(JSON.stringify(response,null,2));if(response.error){console.error(`\u2717 Authentication failed: ${response.error.message}`)}else{console.error("\u2713 Authentication successful")}return response}async function runSessionNewFlow(socket,options){console.error("\n=== Session/New Flow ===");const request=buildSessionNewRequest(options.agentId);const response=await sendRequest(socket,request,options.timeout);console.log("\nSession/New Response:");console.log(JSON.stringify(response,null,2));if(response.error){console.error(`\u2717 Session creation failed: ${response.error.message}`)}else{console.error("\u2713 Session created successfully");if(response.result?.sessionId){console.error(` Session ID: ${response.result.sessionId}`)}}return response}async function runSessionPromptFlow(socket,options,sessionId){console.error("\n=== Session/Prompt Flow ===");const request=buildSessionPromptRequest(options.agentId,sessionId,options.prompt);const response=await sendRequest(socket,request,options.timeout);console.log("\nSession/Prompt Response:");console.log(JSON.stringify(response,null,2));if(response.error){console.error(`\u2717 Prompt failed: ${response.error.message}`)}else{console.error("\u2713 Prompt successful");if(response.result?.messages){console.error(` Response messages: ${response.result.messages.length}`)}}return response}async function runFullFlow(socket,options){console.error("\n========================================");console.error("Running Full ACP Flow");console.error(`Agent: ${options.agentId}`);console.error("========================================");const initResponse=await runInitializeFlow(socket,options);if(initResponse.error){console.error("\nFull flow aborted due to initialize failure.");return}const authMethods=initResponse.result?.authMethods||[];if(authMethods.length>0){const openaiMethod=authMethods.find(m=>m.id==="openai-api-key");const apiKeyMethod=authMethods.find(m=>m.id.includes("api-key")||m.id.includes("apikey"));const methodId=openaiMethod?.id||apiKeyMethod?.id||authMethods[0].id;const authResponse=await runAuthenticateFlow(socket,options,methodId);if(authResponse.error){console.error("\nFull flow aborted due to authentication failure.");return}}const sessionResponse=await runSessionNewFlow(socket,options);if(sessionResponse.error){console.error("\nFull flow aborted due to session creation failure.");return}const sessionId=sessionResponse.result?.sessionId||options.sessionId||generateSessionId();await runSessionPromptFlow(socket,options,sessionId);console.error("\n========================================");console.error("Full ACP Flow Complete");console.error("========================================")}async function runSingleFlow(options){const socket=createConnection(options);socket.on("connect",async()=>{console.error("Connected.");try{switch(options.flow){case"initialize":await runInitializeFlow(socket,options);break;case"session-new":await runSessionNewFlow(socket,options);break;case"session-prompt":const sessionId=options.sessionId||generateSessionId();if(!options.sessionId){console.error(`Note: Using generated session ID: ${sessionId}`)}await runSessionPromptFlow(socket,options,sessionId);break;case"full":await runFullFlow(socket,options);break;default:console.error(`Unknown flow: ${options.flow}`);console.error("Valid flows: initialize, session-new, session-prompt, full")}}catch(err){console.error(`
|
|
51
|
-
Error: ${err.message}`)}finally{socket.end()}});socket.on("error",err=>{console.error(`Connection error: ${err.message}`);process.exit(1)});socket.on("close",()=>{console.error("\nConnection closed.");process.exit(0)})}function runInteractive(options){const socket=createConnection(options);let buffer="";const rl=readline.createInterface({input:process.stdin,output:process.stderr,terminal:false});socket.on("connect",()=>{console.error("Connected in interactive mode.");console.error(`Agent ID: ${options.agentId} (will be added to all messages)`);console.error("\nEnter JSON-RPC messages (one per line). agentId will be added automatically.");console.error('Example: {"jsonrpc":"2.0","id":"1","method":"initialize","params":{}}');console.error("Press Ctrl+D to exit.\n")});socket.on("data",data=>{buffer+=data.toString();let newlineIndex;while((newlineIndex=buffer.indexOf("\n"))!==-1){const line=buffer.slice(0,newlineIndex);buffer=buffer.slice(newlineIndex+1);if(line.trim()){try{const response=JSON.parse(line);console.log("\n\u2190 Response:");console.log(JSON.stringify(response,null,2));console.error("")}catch(err){console.error(`Error parsing response: ${err.message}`)}}}});rl.on("line",line=>{if(!line.trim())return;try{const msg=JSON.parse(line);msg.agentId=options.agentId;console.error(`\u2192 Sending (with agentId=${options.agentId}): ${JSON.stringify(msg)}`);socket.write(JSON.stringify(msg)+"\n")}catch(err){console.error(`Invalid JSON: ${err.message}`);console.error("Please enter a valid JSON object.")}});rl.on("close",()=>{console.error("\nClosing connection...");socket.end()});socket.on("error",err=>{console.error(`Connection error: ${err.message}`);rl.close();process.exit(1)});socket.on("close",()=>{console.error("Connection closed.");process.exit(0)})}function main(){const options=parseArgs();if(options.help){showHelp();process.exit(0)}if(!options.tcp&&!options.unix){console.error("Error: Must specify --tcp or --unix connection");console.error("Use --help for usage information.");process.exit(1)}if(!options.agentId){console.error("Error: Must specify --agent <id> for routing");console.error("Use --help for usage information.");process.exit(1)}if(options.interactive){runInteractive(options)}else if(options.flow){runSingleFlow(options)}else{options.flow="full";runSingleFlow(options)}}process.on("uncaughtException",err=>{console.error(`Uncaught exception: ${err.message}`);process.exit(1)});process.on("unhandledRejection",reason=>{console.error(`Unhandled rejection: ${reason}`);process.exit(1)});main();
|
|
52
|
-
//# sourceMappingURL=registry-launcher-client.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../workers-registry/acp-registry/registry-launcher-client.js"],
|
|
4
|
-
"sourcesContent": ["#!/usr/bin/env node\n\n/*\n * Apache License 2.0\n * Copyright (c) 2025\u2013present Raman Marozau, Target Insight Function.\n * Contact: raman@worktif.com\n *\n * This file is part of the stdio bus protocol reference implementation:\n * stdio_bus_kernel_workers (target: <target_stdio_bus_kernel_workers>).\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * @file registry-launcher-client.js\n * @brief Test client for ACP Registry Transit via stdio Bus\n *\n * This test client demonstrates sending ACP messages through the Registry Launcher\n * transit chain. It shows how to use the agentId field for routing messages to\n * specific agents registered in the ACP Registry.\n *\n * ## Transit Chain\n *\n * ```\n * This Client \u2192 stdio Bus \u2192 Registry Launcher \u2192 ACP Agent \u2192 back\n * ```\n *\n * ## Connection Modes\n *\n * The client supports TCP and Unix socket connections to stdio Bus:\n *\n * - **TCP**: Connect to `--tcp <host:port>` mode\n * ```bash\n * node workers-registry/acp-registry/registry-launcher-client.js --tcp localhost:9000 --agent my-agent\n * ```\n *\n * - **Unix Socket**: Connect to `--unix <path>` mode\n * ```bash\n * node workers-registry/acp-registry/registry-launcher-client.js --unix /tmp/stdio_bus.sock --agent my-agent\n * ```\n *\n * ## Usage\n *\n * ```bash\n * # Start stdio Bus with Registry Launcher configuration. stdio Bus kernel repo: https://github.com/stdiobus/stdiobus\n * ./stdio_bus --config workers-registry/acp-registry/registry-launcher-config.json --tcp localhost:9000\n *\n * # In another terminal, run the test client\n * node workers-registry/acp-registry/registry-launcher-client.js --tcp localhost:9000 --agent my-agent\n *\n * # Run specific ACP flow\n * node workers-registry/acp-registry/registry-launcher-client.js --tcp localhost:9000 --agent my-agent --flow initialize\n * node workers-registry/acp-registry/registry-launcher-client.js --tcp localhost:9000 --agent my-agent --flow session-new\n * node workers-registry/acp-registry/registry-launcher-client.js --tcp localhost:9000 --agent my-agent --flow session-prompt\n *\n * # Run full ACP flow (initialize \u2192 session/new \u2192 session/prompt)\n * node workers-registry/acp-registry/registry-launcher-client.js --tcp localhost:9000 --agent my-agent --flow full\n *\n * # Interactive mode - send custom messages with agentId\n * node workers-registry/acp-registry/registry-launcher-client.js --tcp localhost:9000 --agent my-agent --interactive\n * ```\n *\n * ## Command Line Options\n *\n * | Option | Description |\n * |--------|-------------|\n * | `--tcp <host:port>` | Connect via TCP to specified host and port |\n * | `--unix <path>` | Connect via Unix domain socket |\n * | `--agent <id>` | Agent ID from ACP Registry (required) |\n * | `--flow <type>` | ACP flow to execute: initialize, session-new, session-prompt, full |\n * | `--session <id>` | Session ID for session-based requests (auto-generated if not provided) |\n * | `--prompt <text>` | Prompt text for session/prompt request (default: \"Hello, agent!\") |\n * | `--interactive` | Interactive mode: read JSON from stdin, auto-add agentId |\n * | `--timeout <ms>` | Response timeout in milliseconds (default: 30000) |\n * | `--help` | Show usage information |\n *\n * ## ACP Message Flows\n *\n * ### Initialize Flow\n *\n * Sends an `initialize` request to establish protocol version and capabilities:\n *\n * ```json\n * {\n * \"jsonrpc\": \"2.0\",\n * \"id\": \"init-1\",\n * \"method\": \"initialize\",\n * \"agentId\": \"my-agent\",\n * \"params\": {\n * \"protocolVersion\": 1,\n * \"capabilities\": {},\n * \"clientInfo\": {\n * \"name\": \"registry-launcher-test-client\",\n * \"version\": \"1.0.0\"\n * }\n * }\n * }\n * ```\n *\n * ### Session/New Flow\n *\n * Creates a new session with the agent:\n *\n * ```json\n * {\n * \"jsonrpc\": \"2.0\",\n * \"id\": \"session-new-1\",\n * \"method\": \"session/new\",\n * \"agentId\": \"my-agent\",\n * \"params\": {}\n * }\n * ```\n *\n * ### Session/Prompt Flow\n *\n * Sends a prompt to an existing session:\n *\n * ```json\n * {\n * \"jsonrpc\": \"2.0\",\n * \"id\": \"prompt-1\",\n * \"method\": \"session/prompt\",\n * \"agentId\": \"my-agent\",\n * \"params\": {\n * \"sessionId\": \"sess-123\",\n * \"prompt\": {\n * \"messages\": [\n * {\n * \"role\": \"user\",\n * \"content\": { \"type\": \"text\", \"text\": \"Hello, agent!\" }\n * }\n * ]\n * }\n * }\n * }\n * ```\n *\n * ## Important Notes\n *\n * - The `agentId` field is required for all messages and is used by the Registry\n * Launcher to route messages to the correct agent process\n * - The Registry Launcher removes the `agentId` field before forwarding to the agent\n * - Responses from agents are forwarded unchanged (no agentId added)\n * - Session IDs returned by session/new should be used in subsequent session/prompt calls\n */\n\nimport net from 'net';\nimport readline from 'readline';\nimport crypto from 'crypto';\n\n/**\n * Parse command line arguments.\n * @returns {Object} Parsed options\n */\nfunction parseArgs() {\n const args = process.argv.slice(2);\n const options = {\n tcp: null,\n unix: null,\n agentId: null,\n flow: null,\n sessionId: null,\n prompt: 'Hello, agent!',\n interactive: false,\n timeout: 30000,\n help: false\n };\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n switch (arg) {\n case '--tcp':\n options.tcp = args[++i];\n break;\n case '--unix':\n options.unix = args[++i];\n break;\n case '--agent':\n options.agentId = args[++i];\n break;\n case '--flow':\n options.flow = args[++i];\n break;\n case '--session':\n options.sessionId = args[++i];\n break;\n case '--prompt':\n options.prompt = args[++i];\n break;\n case '--interactive':\n options.interactive = true;\n break;\n case '--timeout':\n options.timeout = parseInt(args[++i], 10);\n break;\n case '--help':\n case '-h':\n options.help = true;\n break;\n default:\n console.error(`Unknown option: ${arg}`);\n process.exit(1);\n }\n }\n\n return options;\n}\n\n/**\n * Display usage information.\n */\nfunction showHelp() {\n console.log(`\nACP Registry Transit Test Client\n\nThis client demonstrates sending ACP messages through the Registry Launcher\ntransit chain: Client \u2192 stdio Bus \u2192 Registry Launcher \u2192 ACP Agent \u2192 back\n\nUsage:\n node registry-launcher-client.js --tcp <host:port> --agent <id> [options]\n node registry-launcher-client.js --unix <path> --agent <id> [options]\n\nConnection (one required):\n --tcp <host:port> Connect via TCP (e.g., localhost:9000)\n --unix <path> Connect via Unix socket (e.g., /tmp/stdio_bus.sock)\n\nRequired:\n --agent <id> Agent ID from ACP Registry to route messages to\n\nACP Flow Options:\n --flow <type> ACP flow to execute:\n initialize - Send initialize request\n session-new - Create new session\n session-prompt - Send prompt to session\n full - Run full flow (init \u2192 new \u2192 prompt)\n --session <id> Session ID for session/prompt (auto-generated if not set)\n --prompt <text> Prompt text for session/prompt (default: \"Hello, agent!\")\n\nModes:\n --interactive Read JSON from stdin, auto-add agentId to messages\n --timeout <ms> Response timeout in ms (default: 30000)\n\nOther:\n --help, -h Show this help message\n\nExamples:\n # Run full ACP flow with an agent\n node registry-launcher-client.js --tcp localhost:9000 --agent my-agent --flow full\n\n # Send just an initialize request\n node registry-launcher-client.js --tcp localhost:9000 --agent my-agent --flow initialize\n\n # Create a new session\n node registry-launcher-client.js --tcp localhost:9000 --agent my-agent --flow session-new\n\n # Send a prompt to an existing session\n node registry-launcher-client.js --tcp localhost:9000 --agent my-agent --flow session-prompt --session sess-123\n\n # Interactive mode - type JSON messages, agentId added automatically\n node registry-launcher-client.js --tcp localhost:9000 --agent my-agent --interactive\n`);\n}\n\n/**\n * Generate a unique request ID.\n * @param {string} prefix - Prefix for the ID\n * @returns {string} Unique ID\n */\nfunction generateId(prefix = 'req') {\n return `${prefix}-${crypto.randomUUID().slice(0, 8)}`;\n}\n\n/**\n * Generate a unique session ID.\n * @returns {string} Session ID\n */\nfunction generateSessionId() {\n return `sess-${crypto.randomUUID().slice(0, 8)}`;\n}\n\n/**\n * Build an ACP initialize request.\n * @param {string} agentId - Agent ID for routing\n * @returns {Object} JSON-RPC initialize request\n */\nfunction buildInitializeRequest(agentId) {\n return {\n jsonrpc: '2.0',\n id: generateId('init'),\n method: 'initialize',\n agentId,\n params: {\n protocolVersion: 1,\n clientCapabilities: {},\n clientInfo: {\n name: 'registry-launcher-test-client',\n version: '1.0.0'\n }\n }\n };\n}\n\n/**\n * Build an ACP authenticate request.\n * @param {string} agentId - Agent ID for routing\n * @param {string} methodId - Authentication method ID\n * @returns {Object} JSON-RPC authenticate request\n */\nfunction buildAuthenticateRequest(agentId, methodId) {\n return {\n jsonrpc: '2.0',\n id: generateId('auth'),\n method: 'authenticate',\n agentId,\n params: {\n methodId\n }\n };\n}\n\n/**\n * Build an ACP session/new request.\n * @param {string} agentId - Agent ID for routing\n * @returns {Object} JSON-RPC session/new request\n */\nfunction buildSessionNewRequest(agentId) {\n return {\n jsonrpc: '2.0',\n id: generateId('session-new'),\n method: 'session/new',\n agentId,\n params: {\n cwd: process.cwd(),\n mcpServers: []\n }\n };\n}\n\n/**\n * Build an ACP session/prompt request.\n * @param {string} agentId - Agent ID for routing\n * @param {string} sessionId - Session ID\n * @param {string} promptText - Prompt text\n * @returns {Object} JSON-RPC session/prompt request\n */\nfunction buildSessionPromptRequest(agentId, sessionId, promptText) {\n return {\n jsonrpc: '2.0',\n id: generateId('prompt'),\n method: 'session/prompt',\n agentId,\n params: {\n sessionId,\n prompt: [\n {\n type: 'text',\n text: promptText\n }\n ]\n }\n };\n}\n\n/**\n * Create a socket connection to stdio Bus.\n * @param {Object} options - Connection options\n * @returns {net.Socket} Connected socket\n */\nfunction createConnection(options) {\n if (options.tcp) {\n const [host, portStr] = options.tcp.split(':');\n const port = parseInt(portStr, 10);\n if (!host || isNaN(port)) {\n console.error('Invalid TCP address. Use format: host:port');\n process.exit(1);\n }\n console.error(`Connecting to TCP ${host}:${port}...`);\n return net.createConnection({ host, port });\n } else if (options.unix) {\n console.error(`Connecting to Unix socket ${options.unix}...`);\n return net.createConnection({ path: options.unix });\n } else {\n console.error('Error: Must specify --tcp or --unix');\n process.exit(1);\n }\n}\n\n/**\n * Send a request and wait for response.\n * @param {net.Socket} socket - Connected socket\n * @param {Object} request - Request to send\n * @param {number} timeout - Timeout in ms\n * @returns {Promise<Object>} Response object\n */\nfunction sendRequest(socket, request, timeout) {\n return new Promise((resolve, reject) => {\n let buffer = '';\n let timeoutId;\n\n const cleanup = () => {\n clearTimeout(timeoutId);\n socket.removeListener('data', onData);\n socket.removeListener('error', onError);\n socket.removeListener('close', onClose);\n };\n\n const onData = (data) => {\n buffer += data.toString();\n\n let newlineIndex;\n while ((newlineIndex = buffer.indexOf('\\n')) !== -1) {\n const line = buffer.slice(0, newlineIndex);\n buffer = buffer.slice(newlineIndex + 1);\n\n if (line.trim()) {\n try {\n const response = JSON.parse(line);\n // Check if this response matches our request ID\n if (response.id === request.id) {\n cleanup();\n resolve(response);\n return;\n } else {\n // Log other responses (notifications, etc.)\n console.error(`\u2190 Received (other): ${JSON.stringify(response)}`);\n }\n } catch (err) {\n console.error(`Error parsing response: ${err.message}`);\n }\n }\n }\n };\n\n const onError = (err) => {\n cleanup();\n reject(new Error(`Connection error: ${err.message}`));\n };\n\n const onClose = () => {\n cleanup();\n reject(new Error('Connection closed before response received'));\n };\n\n timeoutId = setTimeout(() => {\n cleanup();\n reject(new Error(`Timeout: No response within ${timeout}ms`));\n }, timeout);\n\n socket.on('data', onData);\n socket.on('error', onError);\n socket.on('close', onClose);\n\n // Send the request\n console.error(`\u2192 Sending: ${JSON.stringify(request)}`);\n socket.write(JSON.stringify(request) + '\\n');\n });\n}\n\n/**\n * Run the initialize flow.\n * @param {net.Socket} socket - Connected socket\n * @param {Object} options - Options\n * @returns {Promise<Object>} Initialize response\n */\nasync function runInitializeFlow(socket, options) {\n console.error('\\n=== Initialize Flow ===');\n const request = buildInitializeRequest(options.agentId);\n const response = await sendRequest(socket, request, options.timeout);\n\n console.log('\\nInitialize Response:');\n console.log(JSON.stringify(response, null, 2));\n\n if (response.error) {\n console.error(`\u2717 Initialize failed: ${response.error.message}`);\n } else {\n console.error('\u2713 Initialize successful');\n if (response.result?.protocolVersion) {\n console.error(` Protocol version: ${response.result.protocolVersion}`);\n }\n if (response.result?.serverInfo) {\n console.error(` Server: ${response.result.serverInfo.name} v${response.result.serverInfo.version}`);\n }\n }\n\n return response;\n}\n\n/**\n * Run the authenticate flow.\n * @param {net.Socket} socket - Connected socket\n * @param {Object} options - Options\n * @param {string} methodId - Authentication method ID\n * @returns {Promise<Object>} Authenticate response\n */\nasync function runAuthenticateFlow(socket, options, methodId) {\n console.error('\\n=== Authenticate Flow ===');\n console.error(` Method: ${methodId}`);\n const request = buildAuthenticateRequest(options.agentId, methodId);\n const response = await sendRequest(socket, request, options.timeout);\n\n console.log('\\nAuthenticate Response:');\n console.log(JSON.stringify(response, null, 2));\n\n if (response.error) {\n console.error(`\u2717 Authentication failed: ${response.error.message}`);\n } else {\n console.error('\u2713 Authentication successful');\n }\n\n return response;\n}\n\n/**\n * Run the session/new flow.\n * @param {net.Socket} socket - Connected socket\n * @param {Object} options - Options\n * @returns {Promise<Object>} Session/new response\n */\nasync function runSessionNewFlow(socket, options) {\n console.error('\\n=== Session/New Flow ===');\n const request = buildSessionNewRequest(options.agentId);\n const response = await sendRequest(socket, request, options.timeout);\n\n console.log('\\nSession/New Response:');\n console.log(JSON.stringify(response, null, 2));\n\n if (response.error) {\n console.error(`\u2717 Session creation failed: ${response.error.message}`);\n } else {\n console.error('\u2713 Session created successfully');\n if (response.result?.sessionId) {\n console.error(` Session ID: ${response.result.sessionId}`);\n }\n }\n\n return response;\n}\n\n/**\n * Run the session/prompt flow.\n * @param {net.Socket} socket - Connected socket\n * @param {Object} options - Options\n * @param {string} sessionId - Session ID to use\n * @returns {Promise<Object>} Session/prompt response\n */\nasync function runSessionPromptFlow(socket, options, sessionId) {\n console.error('\\n=== Session/Prompt Flow ===');\n const request = buildSessionPromptRequest(options.agentId, sessionId, options.prompt);\n const response = await sendRequest(socket, request, options.timeout);\n\n console.log('\\nSession/Prompt Response:');\n console.log(JSON.stringify(response, null, 2));\n\n if (response.error) {\n console.error(`\u2717 Prompt failed: ${response.error.message}`);\n } else {\n console.error('\u2713 Prompt successful');\n if (response.result?.messages) {\n console.error(` Response messages: ${response.result.messages.length}`);\n }\n }\n\n return response;\n}\n\n/**\n * Run the full ACP flow (initialize \u2192 session/new \u2192 session/prompt).\n * @param {net.Socket} socket - Connected socket\n * @param {Object} options - Options\n */\nasync function runFullFlow(socket, options) {\n console.error('\\n========================================');\n console.error('Running Full ACP Flow');\n console.error(`Agent: ${options.agentId}`);\n console.error('========================================');\n\n // Step 1: Initialize\n const initResponse = await runInitializeFlow(socket, options);\n if (initResponse.error) {\n console.error('\\nFull flow aborted due to initialize failure.');\n return;\n }\n\n // Step 2: Authenticate if required\n const authMethods = initResponse.result?.authMethods || [];\n if (authMethods.length > 0) {\n // Prefer openai-api-key, then any api-key method, then first available\n const openaiMethod = authMethods.find(m => m.id === 'openai-api-key');\n const apiKeyMethod = authMethods.find(m =>\n m.id.includes('api-key') || m.id.includes('apikey')\n );\n const methodId = openaiMethod?.id || apiKeyMethod?.id || authMethods[0].id;\n\n const authResponse = await runAuthenticateFlow(socket, options, methodId);\n if (authResponse.error) {\n console.error('\\nFull flow aborted due to authentication failure.');\n return;\n }\n }\n\n // Step 3: Create session\n const sessionResponse = await runSessionNewFlow(socket, options);\n if (sessionResponse.error) {\n console.error('\\nFull flow aborted due to session creation failure.');\n return;\n }\n\n // Extract session ID from response\n const sessionId = sessionResponse.result?.sessionId || options.sessionId || generateSessionId();\n\n // Step 4: Send prompt\n await runSessionPromptFlow(socket, options, sessionId);\n\n console.error('\\n========================================');\n console.error('Full ACP Flow Complete');\n console.error('========================================');\n}\n\n/**\n * Run a single flow based on options.\n * @param {Object} options - Parsed options\n */\nasync function runSingleFlow(options) {\n const socket = createConnection(options);\n\n socket.on('connect', async () => {\n console.error('Connected.');\n\n try {\n switch (options.flow) {\n case 'initialize':\n await runInitializeFlow(socket, options);\n break;\n case 'session-new':\n await runSessionNewFlow(socket, options);\n break;\n case 'session-prompt':\n const sessionId = options.sessionId || generateSessionId();\n if (!options.sessionId) {\n console.error(`Note: Using generated session ID: ${sessionId}`);\n }\n await runSessionPromptFlow(socket, options, sessionId);\n break;\n case 'full':\n await runFullFlow(socket, options);\n break;\n default:\n console.error(`Unknown flow: ${options.flow}`);\n console.error('Valid flows: initialize, session-new, session-prompt, full');\n }\n } catch (err) {\n console.error(`\\nError: ${err.message}`);\n } finally {\n socket.end();\n }\n });\n\n socket.on('error', (err) => {\n console.error(`Connection error: ${err.message}`);\n process.exit(1);\n });\n\n socket.on('close', () => {\n console.error('\\nConnection closed.');\n process.exit(0);\n });\n}\n\n/**\n * Run in interactive mode.\n * Reads JSON messages from stdin and adds agentId before sending.\n * @param {Object} options - Parsed options\n */\nfunction runInteractive(options) {\n const socket = createConnection(options);\n let buffer = '';\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stderr,\n terminal: false\n });\n\n socket.on('connect', () => {\n console.error('Connected in interactive mode.');\n console.error(`Agent ID: ${options.agentId} (will be added to all messages)`);\n console.error('\\nEnter JSON-RPC messages (one per line). agentId will be added automatically.');\n console.error('Example: {\"jsonrpc\":\"2.0\",\"id\":\"1\",\"method\":\"initialize\",\"params\":{}}');\n console.error('Press Ctrl+D to exit.\\n');\n });\n\n // Handle incoming responses\n socket.on('data', (data) => {\n buffer += data.toString();\n\n let newlineIndex;\n while ((newlineIndex = buffer.indexOf('\\n')) !== -1) {\n const line = buffer.slice(0, newlineIndex);\n buffer = buffer.slice(newlineIndex + 1);\n\n if (line.trim()) {\n try {\n const response = JSON.parse(line);\n console.log('\\n\u2190 Response:');\n console.log(JSON.stringify(response, null, 2));\n console.error('');\n } catch (err) {\n console.error(`Error parsing response: ${err.message}`);\n }\n }\n }\n });\n\n // Handle user input\n rl.on('line', (line) => {\n if (!line.trim()) return;\n\n try {\n // Parse the user's JSON\n const msg = JSON.parse(line);\n\n // Add agentId for routing\n msg.agentId = options.agentId;\n\n console.error(`\u2192 Sending (with agentId=${options.agentId}): ${JSON.stringify(msg)}`);\n socket.write(JSON.stringify(msg) + '\\n');\n } catch (err) {\n console.error(`Invalid JSON: ${err.message}`);\n console.error('Please enter a valid JSON object.');\n }\n });\n\n rl.on('close', () => {\n console.error('\\nClosing connection...');\n socket.end();\n });\n\n socket.on('error', (err) => {\n console.error(`Connection error: ${err.message}`);\n rl.close();\n process.exit(1);\n });\n\n socket.on('close', () => {\n console.error('Connection closed.');\n process.exit(0);\n });\n}\n\n/**\n * Main entry point.\n */\nfunction main() {\n const options = parseArgs();\n\n if (options.help) {\n showHelp();\n process.exit(0);\n }\n\n // Validate required options\n if (!options.tcp && !options.unix) {\n console.error('Error: Must specify --tcp or --unix connection');\n console.error('Use --help for usage information.');\n process.exit(1);\n }\n\n if (!options.agentId) {\n console.error('Error: Must specify --agent <id> for routing');\n console.error('Use --help for usage information.');\n process.exit(1);\n }\n\n // Determine mode\n if (options.interactive) {\n runInteractive(options);\n } else if (options.flow) {\n runSingleFlow(options);\n } else {\n // Default to full flow if no specific flow or interactive mode\n options.flow = 'full';\n runSingleFlow(options);\n }\n}\n\n// Handle uncaught exceptions\nprocess.on('uncaughtException', (err) => {\n console.error(`Uncaught exception: ${err.message}`);\n process.exit(1);\n});\n\n// Handle unhandled promise rejections\nprocess.on('unhandledRejection', (reason) => {\n console.error(`Unhandled rejection: ${reason}`);\n process.exit(1);\n});\n\nmain();\n"],
|
|
5
|
-
"mappings": ";AA8JA,OAAO,QAAS,MAChB,OAAO,aAAc,WACrB,OAAO,WAAY,SAMnB,SAAS,WAAY,CACnB,MAAM,KAAO,QAAQ,KAAK,MAAM,CAAC,EACjC,MAAM,QAAU,CACd,IAAK,KACL,KAAM,KACN,QAAS,KACT,KAAM,KAC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EAC9C,QAAQ,KAAK,CAAC,CAChB,CAAC,EAED,KAAK",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"_comment": "stdio Bus configuration for running the Registry Launcher as a worker pool",
|
|
3
|
-
"_description": "This configuration demonstrates how to use the Registry Launcher to connect ACP clients to any agent in the ACP Registry through stdio Bus",
|
|
4
|
-
"pools": [
|
|
5
|
-
{
|
|
6
|
-
"_comment": "Registry Launcher worker pool - routes messages to ACP Registry agents",
|
|
7
|
-
"id": "registry-launcher",
|
|
8
|
-
"command": "node",
|
|
9
|
-
"args": [
|
|
10
|
-
"/workers-registry/launch/index.js",
|
|
11
|
-
"acp-registry"
|
|
12
|
-
],
|
|
13
|
-
"instances": 1
|
|
14
|
-
}
|
|
15
|
-
],
|
|
16
|
-
"limits": {
|
|
17
|
-
"_comment_max_input_buffer": "Maximum size of input buffer per connection (1MB default)",
|
|
18
|
-
"max_input_buffer": 1048576,
|
|
19
|
-
"_comment_max_output_queue": "Maximum size of output queue per connection (4MB default)",
|
|
20
|
-
"max_output_queue": 4194304,
|
|
21
|
-
"_comment_max_restarts": "Maximum number of worker restarts within restart_window_sec",
|
|
22
|
-
"max_restarts": 5,
|
|
23
|
-
"_comment_restart_window_sec": "Time window for counting restarts (60 seconds)",
|
|
24
|
-
"restart_window_sec": 60,
|
|
25
|
-
"_comment_drain_timeout_sec": "Timeout for draining connections during graceful shutdown",
|
|
26
|
-
"drain_timeout_sec": 30,
|
|
27
|
-
"_comment_backpressure_timeout_sec": "Timeout for backpressure before dropping messages",
|
|
28
|
-
"backpressure_timeout_sec": 60
|
|
29
|
-
}
|
|
30
|
-
}
|