@stdiobus/workers-registry 1.3.14 → 1.3.15

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.
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../workers-registry/mcp-to-acp-proxy/proxy.js"],
4
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"],
5
- "mappings": ";yvBAgCA,eAAgB,0BAChB,oBAAgC,oBAEhC,IAAM,SAAW,QAAQ,IAAI,UAAY,YACzC,IAAM,SAAW,QAAQ,IAAI,UAAY,IACzC,IAAM,SAAW,QAAQ,IAAI,UAAY,gBAEzC,QAAQ,MAAM,oCAAoC,EAClD,QAAQ,MAAM,4BAA4B,QAAQ,IAAI,QAAQ,EAAE,EAChE,QAAQ,MAAM,8BAA8B,QAAQ,EAAE,EAGtD,IAAM,UAAY,WAAAA,QAAI,QAAQ,SAAU,QAAQ,EAChD,IAAI,aAAe,MACnB,IAAI,eAAiB,KACrB,IAAI,aAAe,KACnB,IAAI,gBAAkB,IAAI,IAC1B,IAAI,gBAAkB,IAAI,IAE1B,UAAU,GAAG,UAAW,IAAM,CAC5B,QAAQ,MAAM,6CAA6C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AAiB,CAAC,EAEpE,QAAQ,MAAM,gCAA2B,KAAK,UAAU,SAAS,CAAC,EAAE,EACpE,GAAI,aAAc,CAChB,UAAU,MAAM,KAAK,UAAU,SAAS,EAAI,IAAI,CAClD,CACF,CACA,OAAO,KAET,IAAK,iBACH,MAAM,KAAO,gBAAgB,IAAI,EAAE,GAAK,GACxC,gBAAgB,OAAO,EAAE,EACzB,QAAQ,MAAM,gDAAgD,KAAK,MAAM,aAAa,KAAK,UAAU,EAAG,EAAE,CAAC,MAAM,EACjH,MAAO,CACL,QAAS,MACT,GACA,OAAQ,CACN,QAAS,CAAC,CAAE,KAAM,OAAQ,KAAM,MAAQ,aAAc,CAAC,CACzD,CACF,EAEF,QACE,QAAQ,MAAM,8CAA8C,QAAQ,MAAM,wBAAwB,EAClG,MAAO,CAAE,QAAS,MAAO,GAAI,OAAQ,QAAU,CAAC,CAAE,CACtD,CACF,CAEA,SAAS,QAAQ,IAAK,CACpB,QAAQ,MAAM,gCAA2B,KAAK,UAAU,GAAG,CAAC,EAAE,EAC9D,QAAQ,OAAO,MAAM,KAAK,UAAU,GAAG,EAAI,IAAI,CACjD,CAEA,QAAQ,GAAG,UAAW,IAAM,CAC1B,UAAU,IAAI,EACd,QAAQ,KAAK,CAAC,CAChB,CAAC,EAED,QAAQ,GAAG,SAAU,IAAM,CACzB,UAAU,IAAI,EACd,QAAQ,KAAK,CAAC,CAChB,CAAC",
6
+ "names": []
7
7
  }
@@ -1,2 +1,16 @@
1
1
  export type { Platform, BinaryTarget, BinaryDistribution, NpxDistribution, UvxDistribution, Distribution, RegistryAgent, Registry, SpawnCommand, } from './registry-launcher/registry/types.js';
2
2
  export type { RegistryIndex, IRegistryIndex, } from './registry-launcher/registry/index.js';
3
+ export { ACPAgent } from './agent.js';
4
+ export { PlatformNotSupportedError, NoDistributionError, getCurrentPlatform, resolve, resolveBinary, resolveNpx, resolveUvx, } from './registry-launcher/registry/resolver.js';
5
+ export { AgentRuntimeManager } from './registry-launcher/runtime/manager.js';
6
+ export { AgentRuntimeImpl } from './registry-launcher/runtime/agent-runtime.js';
7
+ export type { RuntimeState, AgentRuntime } from './registry-launcher/runtime/types.js';
8
+ export { NDJSONHandler, INDJSONHandler, ErrorCallback, MessageCallback, } from './registry-launcher/stream/ndjson-handler.js';
9
+ export { MessageRouter, createErrorResponse, ErrorResponse, RoutingErrorCodes, transformMessage, extractAgentId, extractId, WriteCallback, } from './registry-launcher/router/message-router.js';
10
+ export { loadConfig } from './registry-launcher/config/config.js';
11
+ export type { DEFAULT_CONFIG, LauncherConfig, } from './registry-launcher/config/types.js';
12
+ export { MCPManager, MCPConnection, MCPFactories } from './mcp/manager.js';
13
+ export type { MCPServerConfig, MCPContent, MCPImageContent, MCPBlobResourceContents, MCPEmbeddedResource, MCPResource, MCPTextContent, MCPResourceContents, MCPTextResourceContents, MCPTool, MCPToolCallResult, MCPResourceReadResult, } from './mcp/types.js';
14
+ export { canReadFile, canWriteFile, FileReadResult, FileWriteResult, readFile, canUseTerminal, TerminalResult, writeFile, executeCommand, startCommand, } from './acp/client-capabilities.js';
15
+ export { createErrorToolCallContent, mapMCPContentToACPContentBlock, mapMCPResourceContentsToACPContentBlock, isResourceLink, extractResourceLinkUri, mapMCPResultToACPToolCallContent, ResourceLink, mapToolResultToACPContent, } from './acp/content-mapper.js';
16
+ export { determineToolKind, executeToolCall, generateToolCallId, executeToolCallWithPermission, requestToolPermission, PermissionResult, ToolCallStatus, ToolKind, sendToolCallInitiation, sendToolCallUpdate, } from './acp/tools.js';
@@ -1,2 +1,30 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ /**
3
+ * Worker configuration mapping worker names to their entry points
4
+ */
5
+ interface WorkerConfig {
6
+ readonly path: string;
7
+ readonly description: string;
8
+ }
9
+ /**
10
+ * Available workers mapping
11
+ */
12
+ declare const STDIO_BUS_WORKERS: Readonly<Record<string, WorkerConfig>>;
13
+ /**
14
+ * Worker name type
15
+ */
16
+ type WorkerName = keyof typeof STDIO_BUS_WORKERS;
17
+ /**
18
+ * Display usage information
19
+ */
20
+ declare function showUsage(): void;
21
+ /**
22
+ * Validate worker name
23
+ */
24
+ declare function isValidWorkerName(name: string): name is WorkerName;
25
+ /**
26
+ * Main entry point
27
+ */
28
+ declare function main(): Promise<void>;
29
+ export { STDIO_BUS_WORKERS, showUsage, isValidWorkerName, main as launch };
30
+ export type { WorkerConfig, WorkerName };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdiobus/workers-registry",
3
- "version": "1.3.14",
3
+ "version": "1.3.15",
4
4
  "description": "Worker implementations for stdio Bus kernel - ACP, MCP, and protocol bridges",
5
5
  "type": "module",
6
6
  "main": "./out/dist/workers/acp-worker/index.js",
@@ -18,6 +18,26 @@
18
18
  "import": "./out/dist/workers/acp-worker/index.js",
19
19
  "types": "./out/tsc/workers-registry/acp-worker/src/index.d.ts"
20
20
  },
21
+ "./workers/acp-worker/agent": {
22
+ "import": "./out/dist/workers/acp-worker/agent.js",
23
+ "types": "./out/tsc/workers-registry/acp-worker/src/agent.d.ts"
24
+ },
25
+ "./workers/acp-worker/registry": {
26
+ "import": "./out/dist/workers/acp-worker/registry-launcher/registry/index.js",
27
+ "types": "./out/tsc/workers-registry/acp-worker/src/registry-launcher/registry/index.d.ts"
28
+ },
29
+ "./workers/acp-worker/runtime": {
30
+ "import": "./out/dist/workers/acp-worker/registry-launcher/runtime/manager.js",
31
+ "types": "./out/tsc/workers-registry/acp-worker/src/registry-launcher/runtime/manager.d.ts"
32
+ },
33
+ "./workers/acp-worker/config": {
34
+ "import": "./out/dist/workers/acp-worker/registry-launcher/config/config.js",
35
+ "types": "./out/tsc/workers-registry/acp-worker/src/registry-launcher/config/config.d.ts"
36
+ },
37
+ "./workers/acp-worker/mcp": {
38
+ "import": "./out/dist/workers/acp-worker/mcp/manager.js",
39
+ "types": "./out/tsc/workers-registry/acp-worker/src/mcp/manager.d.ts"
40
+ },
21
41
  "./workers/echo-worker": "./out/dist/workers/echo-worker/echo-worker.js",
22
42
  "./workers/mcp-echo-server": {
23
43
  "import": "./out/dist/workers/mcp-echo-server/index.js",
@@ -1,52 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf;var __hasOwnProp=Object.prototype.hasOwnProperty;var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:true}):target,mod));var import_net=__toESM(require("net"),1);var import_readline=__toESM(require("readline"),1);var import_crypto=__toESM(require("crypto"),1);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}-${import_crypto.default.randomUUID().slice(0,8)}`}function generateSessionId(){return`sess-${import_crypto.default.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 import_net.default.createConnection({host,port})}else if(options.unix){console.error(`Connecting to Unix socket ${options.unix}...`);return import_net.default.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=import_readline.default.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.cjs.map