@stdiobus/workers-registry 1.3.11 → 1.3.14
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/launcher/index.cjs +4 -0
- package/launcher/index.cjs.map +7 -0
- package/launcher/index.js +11 -3
- package/launcher/index.js.map +1 -1
- package/out/dist/workers/acp-registry/registry-launcher-client.cjs +52 -0
- package/out/dist/workers/acp-registry/{registry-launcher-client.js.map → registry-launcher-client.cjs.map} +2 -2
- package/out/dist/workers/acp-registry/registry-launcher-client.js +9 -49
- package/out/dist/workers/acp-worker/index.cjs +46 -0
- package/out/dist/workers/acp-worker/{index.js.map → index.cjs.map} +2 -2
- package/out/dist/workers/acp-worker/index.js +10 -45
- package/out/dist/workers/echo-worker/echo-worker.cjs +3 -0
- package/out/dist/workers/echo-worker/{echo-worker.js.map → echo-worker.cjs.map} +2 -2
- package/out/dist/workers/echo-worker/echo-worker.js +11 -2
- package/out/dist/workers/mcp-echo-server/index.cjs +45 -0
- package/out/dist/workers/mcp-echo-server/{index.js.map → index.cjs.map} +2 -2
- package/out/dist/workers/mcp-echo-server/index.js +10 -43
- package/out/dist/workers/mcp-to-acp-proxy/proxy.cjs +3 -0
- package/out/dist/workers/mcp-to-acp-proxy/{proxy.js.map → proxy.cjs.map} +2 -2
- package/out/dist/workers/mcp-to-acp-proxy/proxy.js +11 -2
- package/package.json +1 -1
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";var import_url=require("url");var import_path=require("path");var import_promises=require("fs/promises");var import_meta={};var __filename=(0,import_url.fileURLToPath)(import_meta.url);var __dirname=(0,import_path.dirname)(__filename);var WORKERS={"acp-worker":{path:"../out/dist/workers/acp-worker/index.js",description:"Full ACP protocol implementation with MCP integration"},"acp-registry":{path:"../out/dist/workers/acp-registry/registry-launcher-client.js",description:"Registry Launcher for ACP Registry agents"},"echo-worker":{path:"../out/dist/workers/echo-worker/echo-worker.js",description:"Simple echo worker for testing NDJSON protocol"},"mcp-echo-server":{path:"../out/dist/workers/mcp-echo-server/index.js",description:"MCP server example for testing"},"mcp-to-acp-proxy":{path:"../out/dist/workers/mcp-to-acp-proxy/proxy.js",description:"MCP-to-ACP protocol bridge"}};function showUsage(){console.error("Usage: node index.js <worker-name>");console.error("");console.error("Available workers:");for(const[name,config]of Object.entries(WORKERS)){console.error(` - ${name.padEnd(20)} ${config.description}`)}console.error("");console.error("Examples:");console.error(" node index.js acp-worker");console.error(" node index.js echo-worker");console.error(" node index.js mcp-echo-server")}function isValidWorkerName(name){return name in WORKERS}async function main(){const workerName=process.argv[2];if(!workerName){console.error("Error: Worker name is required\n");showUsage();process.exit(1)}if(!isValidWorkerName(workerName)){console.error(`Error: Unknown worker "${workerName}"
|
|
3
|
+
`);showUsage();process.exit(1)}const workerConfig=WORKERS[workerName];const workerPath=workerConfig.path;const absolutePath=(0,import_path.join)(__dirname,workerPath);try{await(0,import_promises.readFile)(absolutePath);console.error(`[launcher] Starting worker: ${workerName}`);console.error(`[launcher] Description: ${workerConfig.description}`);console.error(`[launcher] Path: ${absolutePath}`);await import(absolutePath)}catch(error){if(error&&typeof error==="object"&&"code"in error&&error.code==="ENOENT"){console.error(`Error: Worker file not found: ${absolutePath}`);console.error("");console.error('Please run "npm run build" first to compile the workers.');process.exit(1)}const errorMessage=error instanceof Error?error.message:String(error);const errorStack=error instanceof Error?error.stack:void 0;console.error(`Error loading worker "${workerName}":`,errorMessage);if(errorStack){console.error(errorStack)}process.exit(1)}}main().catch(error=>{console.error("Fatal error:",error);process.exit(1)});
|
|
4
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../workers-registry/launcher/index.ts"],
|
|
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 * Universal worker launcher for stdio Bus Workers Registry\n * \n * Usage:\n * node index.js <worker-name>\n * node index.js acp-worker\n * node index.js echo-worker\n * node index.js mcp-echo-server\n * \n * This script dynamically imports and runs the specified worker from the compiled output.\n */\n\nimport { fileURLToPath } from 'url';\nimport { dirname, join } from 'path';\nimport { readFile } from 'fs/promises';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\n/**\n * Worker configuration mapping worker names to their entry points\n */\ninterface WorkerConfig {\n readonly path: string;\n readonly description: string;\n}\n\n/**\n * Available workers mapping\n */\nconst WORKERS: Readonly<Record<string, WorkerConfig>> = {\n 'acp-worker': {\n path: '../out/dist/workers/acp-worker/index.js',\n description: 'Full ACP protocol implementation with MCP integration'\n },\n 'acp-registry': {\n path: '../out/dist/workers/acp-registry/registry-launcher-client.js',\n description: 'Registry Launcher for ACP Registry agents'\n },\n 'echo-worker': {\n path: '../out/dist/workers/echo-worker/echo-worker.js',\n description: 'Simple echo worker for testing NDJSON protocol'\n },\n 'mcp-echo-server': {\n path: '../out/dist/workers/mcp-echo-server/index.js',\n description: 'MCP server example for testing'\n },\n 'mcp-to-acp-proxy': {\n path: '../out/dist/workers/mcp-to-acp-proxy/proxy.js',\n description: 'MCP-to-ACP protocol bridge'\n }\n} as const;\n\n/**\n * Worker name type\n */\ntype WorkerName = keyof typeof WORKERS;\n\n/**\n * Display usage information\n */\nfunction showUsage(): void {\n console.error('Usage: node index.js <worker-name>');\n console.error('');\n console.error('Available workers:');\n\n for (const [name, config] of Object.entries(WORKERS)) {\n console.error(` - ${name.padEnd(20)} ${config.description}`);\n }\n\n console.error('');\n console.error('Examples:');\n console.error(' node index.js acp-worker');\n console.error(' node index.js echo-worker');\n console.error(' node index.js mcp-echo-server');\n}\n\n/**\n * Validate worker name\n */\nfunction isValidWorkerName(name: string): name is WorkerName {\n return name in WORKERS;\n}\n\n/**\n * Main entry point\n */\nasync function main(): Promise<void> {\n const workerName = process.argv[2];\n\n // Check if worker name is provided\n if (!workerName) {\n console.error('Error: Worker name is required\\n');\n showUsage();\n process.exit(1);\n }\n\n // Check if worker exists\n if (!isValidWorkerName(workerName)) {\n console.error(`Error: Unknown worker \"${workerName}\"\\n`);\n showUsage();\n process.exit(1);\n }\n\n const workerConfig = WORKERS[workerName];\n const workerPath = workerConfig.path;\n\n // Resolve absolute path\n const absolutePath = join(__dirname, workerPath);\n\n try {\n // Verify the worker file exists\n await readFile(absolutePath);\n\n // Import and run the worker\n console.error(`[launcher] Starting worker: ${workerName}`);\n console.error(`[launcher] Description: ${workerConfig.description}`);\n console.error(`[launcher] Path: ${absolutePath}`);\n\n await import(absolutePath);\n } catch (error) {\n if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {\n console.error(`Error: Worker file not found: ${absolutePath}`);\n console.error('');\n console.error('Please run \"npm run build\" first to compile the workers.');\n process.exit(1);\n }\n\n const errorMessage = error instanceof Error ? error.message : String(error);\n const errorStack = error instanceof Error ? error.stack : undefined;\n\n console.error(`Error loading worker \"${workerName}\":`, errorMessage);\n if (errorStack) {\n console.error(errorStack);\n }\n process.exit(1);\n }\n}\n\n// Run main function\nmain().catch((error) => {\n console.error('Fatal error:', error);\n process.exit(1);\n});\n"],
|
|
5
|
+
"mappings": ";aAqCA,eAA8B,eAC9B,gBAA8B,gBAC9B,oBAAyB,uBAvCzB,mBAyCA,IAAM,cAAa,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,MAAM,oBAAoB,YAAY,EAAE,EAEhD,MAAM,OAAO,aACf,OAAS,MAAO,CACd,GAAI,OAAS,OAAO,QAAU,UAAY,SAAU,OAAS,MAAM,OAAS,SAAU,CACpF,QAAQ,MAAM,iCAAiC,YAAY,EAAE,EAC7D,QAAQ,MAAM,EAAE,EAChB,QAAQ,MAAM,0DAA0D,EACxE,QAAQ,KAAK,CAAC,CAChB,CAEA,MAAM,aAAe,iBAAiB,MAAQ,MAAM,QAAU,OAAO,KAAK,EAC1E,MAAM,WAAa,iBAAiB,MAAQ,MAAM,MAAQ,OAE1D,QAAQ,MAAM,yBAAyB,UAAU,KAAM,YAAY,EACnE,GAAI,WAAY,CACd,QAAQ,MAAM,UAAU,CAC1B,CACA,QAAQ,KAAK,CAAC,CAChB,CACF,CAGA,KAAK,EAAE,MAAO,OAAU,CACtB,QAAQ,MAAM,eAAgB,KAAK,EACnC,QAAQ,KAAK,CAAC,CAChB,CAAC",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/launcher/index.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
// ESM wrapper for CommonJS bundle
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { dirname, join } from 'path';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
|
|
11
|
+
// Import the CommonJS bundle
|
|
12
|
+
require('./index.cjs');
|
package/launcher/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../workers-registry/launcher/index.ts"],
|
|
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 * Universal worker launcher for stdio Bus Workers Registry\n * \n * Usage:\n * node index.js <worker-name>\n * node index.js acp-worker\n * node index.js echo-worker\n * node index.js mcp-echo-server\n * \n * This script dynamically imports and runs the specified worker from the compiled output.\n */\n\nimport { fileURLToPath } from 'url';\nimport { dirname, join } from 'path';\nimport { readFile } from 'fs/promises';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\n/**\n * Worker configuration mapping worker names to their entry points\n */\ninterface WorkerConfig {\n readonly path: string;\n readonly description: string;\n}\n\n/**\n * Available workers mapping\n */\nconst WORKERS: Readonly<Record<string, WorkerConfig>> = {\n 'acp-worker': {\n path: '../out/dist/workers/acp-worker/index.js',\n description: 'Full ACP protocol implementation with MCP integration'\n },\n 'acp-registry': {\n path: '../out/dist/workers/acp-registry/registry-launcher-client.js',\n description: 'Registry Launcher for ACP Registry agents'\n },\n 'echo-worker': {\n path: '../out/dist/workers/echo-worker/echo-worker.js',\n description: 'Simple echo worker for testing NDJSON protocol'\n },\n 'mcp-echo-server': {\n path: '../out/dist/workers/mcp-echo-server/index.js',\n description: 'MCP server example for testing'\n },\n 'mcp-to-acp-proxy': {\n path: '../out/dist/workers/mcp-to-acp-proxy/proxy.js',\n description: 'MCP-to-ACP protocol bridge'\n }\n} as const;\n\n/**\n * Worker name type\n */\ntype WorkerName = keyof typeof WORKERS;\n\n/**\n * Display usage information\n */\nfunction showUsage(): void {\n console.error('Usage: node index.js <worker-name>');\n console.error('');\n console.error('Available workers:');\n\n for (const [name, config] of Object.entries(WORKERS)) {\n console.error(` - ${name.padEnd(20)} ${config.description}`);\n }\n\n console.error('');\n console.error('Examples:');\n console.error(' node index.js acp-worker');\n console.error(' node index.js echo-worker');\n console.error(' node index.js mcp-echo-server');\n}\n\n/**\n * Validate worker name\n */\nfunction isValidWorkerName(name: string): name is WorkerName {\n return name in WORKERS;\n}\n\n/**\n * Main entry point\n */\nasync function main(): Promise<void> {\n const workerName = process.argv[2];\n\n // Check if worker name is provided\n if (!workerName) {\n console.error('Error: Worker name is required\\n');\n showUsage();\n process.exit(1);\n }\n\n // Check if worker exists\n if (!isValidWorkerName(workerName)) {\n console.error(`Error: Unknown worker \"${workerName}\"\\n`);\n showUsage();\n process.exit(1);\n }\n\n const workerConfig = WORKERS[workerName];\n const workerPath = workerConfig.path;\n\n // Resolve absolute path\n const absolutePath = join(__dirname, workerPath);\n\n try {\n // Verify the worker file exists\n await readFile(absolutePath);\n\n // Import and run the worker\n console.error(`[launcher] Starting worker: ${workerName}`);\n console.error(`[launcher] Description: ${workerConfig.description}`);\n console.error(`[launcher] Path: ${absolutePath}`);\n\n await import(absolutePath);\n } catch (error) {\n if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {\n console.error(`Error: Worker file not found: ${absolutePath}`);\n console.error('');\n console.error('Please run \"npm run build\" first to compile the workers.');\n process.exit(1);\n }\n\n const errorMessage = error instanceof Error ? error.message : String(error);\n const errorStack = error instanceof Error ? error.stack : undefined;\n\n console.error(`Error loading worker \"${workerName}\":`, errorMessage);\n if (errorStack) {\n console.error(errorStack);\n }\n process.exit(1);\n }\n}\n\n// Run main function\nmain().catch((error) => {\n console.error('Fatal error:', error);\n process.exit(1);\n});\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;AAqCA,OAAS,kBAAqB,MAC9B,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QAAQ,MAAM,2BAA2B,aAAa,WAAW,EAAE,EACnE,QAAQ,MAAM,oBAAoB,YAAY,EAAE,EAEhD,MAAM,OAAO,aACf,OAAS,MAAO,CACd,GAAI,OAAS,OAAO,QAAU,UAAY,SAAU,OAAS,MAAM,OAAS,SAAU,CACpF,QAAQ,MAAM,iCAAiC,YAAY,EAAE,EAC7D,QAAQ,MAAM,EAAE,EAChB,QAAQ,MAAM,0DAA0D,EACxE,QAAQ,KAAK,CAAC,CAChB,CAEA,MAAM,aAAe,iBAAiB,MAAQ,MAAM,QAAU,OAAO,KAAK,EAC1E,MAAM,WAAa,iBAAiB,MAAQ,MAAM,MAAQ,OAE1D,QAAQ,MAAM,yBAAyB,UAAU,KAAM,YAAY,EACnE,GAAI,WAAY,CACd,QAAQ,MAAM,UAAU,CAC1B,CACA,QAAQ,KAAK,CAAC,CAChB,CACF,CAGA,KAAK,EAAE,MAAO,OAAU,CACtB,QAAQ,MAAM,eAAgB,KAAK,EACnC,QAAQ,KAAK,CAAC,CAChB,CAAC",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../workers-registry/acp-registry/registry-launcher-client.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 * @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();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Q,KAAM,CACvB,cAAc,OAAO,CACvB,KAAO,CAEL,QAAQ,KAAO,OACf,cAAc,OAAO,CACvB,CACF,CAGA,QAAQ,GAAG,oBAAsB,KAAQ,CACvC,QAAQ,MAAM,uBAAuB,IAAI,OAAO,EAAE,EAClD,QAAQ,KAAK,CAAC,CAChB,CAAC,EAGD,QAAQ,GAAG,qBAAuB,QAAW,CAC3C,QAAQ,MAAM,wBAAwB,MAAM,EAAE,EAC9C,QAAQ,KAAK,CAAC,CAChB,CAAC,EAED,KAAK",
|
|
6
|
+
"names": ["crypto", "net", "readline"]
|
|
7
7
|
}
|
|
@@ -1,52 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
// ESM wrapper for CommonJS bundle
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { dirname, join } from 'path';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
11
|
+
// Import the CommonJS bundle
|
|
12
|
+
require('./registry-launcher-client.cjs');
|