@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.
@@ -1,3 +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=require("readline");var ACP_HOST=process.env.ACP_HOST||"127.0.0.1";var ACP_PORT=process.env.ACP_PORT||9e3;var AGENT_ID=process.env.AGENT_ID||"default-agent";console.error(`[MCP-APC][proxy] Starting proxy...`);console.error(`[MCP-APC][proxy] Target: ${ACP_HOST}:${ACP_PORT}`);console.error(`[MCP-APC][proxy] Agent ID: ${AGENT_ID}`);var acpSocket=import_net.default.connect(ACP_PORT,ACP_HOST);var acpConnected=false;var proxySessionId=null;var acpSessionId=null;var pendingRequests=new Map;var accumulatedText=new Map;acpSocket.on("connect",()=>{console.error("[MCP-APC][proxy] Connected to ACP stdio Bus");acpConnected=true});acpSocket.on("error",err=>{console.error(`[MCP-APC][proxy] ACP connection error: ${err.message}`);process.exit(1)});var acpBuffer="";acpSocket.on("data",data=>{acpBuffer+=data.toString();let newlineIndex;while((newlineIndex=acpBuffer.indexOf("\n"))!==-1){const line=acpBuffer.slice(0,newlineIndex);acpBuffer=acpBuffer.slice(newlineIndex+1);if(line.trim()){try{const acpMsg=JSON.parse(line);console.error(`[MCP-APC][proxy] \u2190 ACP: ${JSON.stringify(acpMsg)}`);if(acpMsg.id===void 0||acpMsg.id===null){console.error(`[MCP-APC][proxy] Processing notification: ${acpMsg.method}`);handleACPNotification(acpMsg)}else{console.error(`[MCP-APC][proxy] Processing response id=${acpMsg.id}`);console.error(`[MCP-APC][proxy] Pending: ${JSON.stringify([...pendingRequests.keys()])}`);const mcpResponse=convertACPtoMCP(acpMsg);if(mcpResponse){console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(mcpResponse)}`);process.stdout.write(JSON.stringify(mcpResponse)+"\n")}else{console.error(`[MCP-APC][proxy] WARNING: No MCP response for id=${acpMsg.id}`)}}}catch(err){console.error(`[MCP-APC][proxy] Error parsing ACP: ${err.message}`)}}}});var rl=(0,import_readline.createInterface)({input:process.stdin,terminal:false});rl.on("line",line=>{if(!line.trim())return;try{const mcpReq=JSON.parse(line);console.error(`[MCP-APC][proxy] \u2190 MCP: ${JSON.stringify(mcpReq)}`);const acpReq=convertMCPtoACP(mcpReq);if(acpReq){console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(acpReq)}`);if(acpConnected){acpSocket.write(JSON.stringify(acpReq)+"\n")}}}catch(err){console.error(`[MCP-APC][proxy] Error parsing MCP: ${err.message}`)}});function handleACPNotification(msg){const{method,params}=msg;if(method==="session/update"&&params?.update){const update=params.update;for(const[reqId,pending]of pendingRequests.entries()){if(pending.method==="session/prompt"){if(update.sessionUpdate==="agent_message_chunk"&&update.content?.text){if(!accumulatedText.has(reqId)){accumulatedText.set(reqId,"")}accumulatedText.set(reqId,accumulatedText.get(reqId)+update.content.text)}break}}}}function convertMCPtoACP(mcpReq){const{id,method,params}=mcpReq;if(id===void 0||id===null){return null}pendingRequests.set(id,{method,params});if(!proxySessionId){proxySessionId=`proxy-${Date.now()}`}switch(method){case"initialize":return{jsonrpc:"2.0",id,method:"initialize",agentId:AGENT_ID,sessionId:proxySessionId,params:{protocolVersion:1,clientCapabilities:params?.capabilities||{},clientInfo:params?.clientInfo||{name:"mcp-proxy",version:"1.0.0"}}};case"tools/list":sendMCP({jsonrpc:"2.0",id,result:{tools:[{name:"acp_prompt",description:`Send prompt to ${AGENT_ID}`,inputSchema:{type:"object",properties:{prompt:{type:"string",description:"Prompt text"}},required:["prompt"]}}]}});pendingRequests.delete(id);return null;case"tools/call":const promptText=params?.arguments?.prompt||"";if(!acpSessionId){const sessionReqId=`sess-${id}`;pendingRequests.set(sessionReqId,{method:"session/new",originalId:id,promptText});return{jsonrpc:"2.0",id:sessionReqId,method:"session/new",agentId:AGENT_ID,sessionId:proxySessionId,params:{cwd:process.cwd(),mcpServers:[]}}}pendingRequests.set(id,{method:"session/prompt",params});return{jsonrpc:"2.0",id,method:"session/prompt",agentId:AGENT_ID,sessionId:proxySessionId,params:{sessionId:acpSessionId,prompt:[{type:"text",text:promptText}]}};case"resources/list":sendMCP({jsonrpc:"2.0",id,result:{resources:[]}});pendingRequests.delete(id);return null;case"resources/templates/list":sendMCP({jsonrpc:"2.0",id,result:{resourceTemplates:[]}});pendingRequests.delete(id);return null;case"prompts/list":sendMCP({jsonrpc:"2.0",id,result:{prompts:[]}});pendingRequests.delete(id);return null;default:sendMCP({jsonrpc:"2.0",id,error:{code:-32601,message:`Unknown method: ${method}`}});pendingRequests.delete(id);return null}}function convertACPtoMCP(acpResp){const{id,result,error}=acpResp;const pending=pendingRequests.get(id);if(!pending){console.error(`[MCP-APC][proxy] ERROR: No pending request for id=${id}`);return null}console.error(`[MCP-APC][proxy] Converting ACP->MCP for method: ${pending.method}`);pendingRequests.delete(id);if(error){accumulatedText.delete(id);return{jsonrpc:"2.0",id,error:{code:error.code||-32603,message:error.message||"ACP error"}}}switch(pending.method){case"initialize":return{jsonrpc:"2.0",id,result:{protocolVersion:"2024-11-05",capabilities:{tools:{},resources:{}},serverInfo:result?.agentInfo||{name:"acp-agent",version:"1.0.0"}}};case"session/new":acpSessionId=result?.sessionId;console.error(`[MCP-APC][proxy] ACP session: ${acpSessionId}`);if(pending.originalId&&pending.promptText){const promptReq={jsonrpc:"2.0",id:pending.originalId,method:"session/prompt",agentId:AGENT_ID,sessionId:proxySessionId,params:{sessionId:acpSessionId,prompt:[{type:"text",text:pending.promptText}]}};pendingRequests.set(pending.originalId,{method:"session/prompt"});console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(promptReq)}`);if(acpConnected){acpSocket.write(JSON.stringify(promptReq)+"\n")}}return null;case"session/prompt":const text=accumulatedText.get(id)||"";accumulatedText.delete(id);console.error(`[MCP-APC][proxy] Returning accumulated text (${text.length} chars): "${text.substring(0,50)}..."`);return{jsonrpc:"2.0",id,result:{content:[{type:"text",text:text||"No response"}]}};default:console.error(`[MCP-APC][proxy] WARNING: Unhandled method ${pending.method}, returning raw result`);return{jsonrpc:"2.0",id,result:result||{}}}}function sendMCP(msg){console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(msg)}`);process.stdout.write(JSON.stringify(msg)+"\n")}process.on("SIGTERM",()=>{acpSocket.end();process.exit(0)});process.on("SIGINT",()=>{acpSocket.end();process.exit(0)});
3
- //# sourceMappingURL=proxy.cjs.map