@musistudio/claude-code-router 3.0.0 → 3.0.2

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,5 +1,5 @@
1
- "use strict";var b="2024-11-05",g=k(),J=new Set(g.map(n=>n.name)),r=Buffer.alloc(0);process.stdin.on("data",n=>{r=Buffer.concat([r,Buffer.isBuffer(n)?n:Buffer.from(n)]),R().catch(e=>{c(u(null,-32603,f(e)))})});process.stdin.resume();async function R(){for(;;){let n=r.indexOf(`\r
1
+ "use strict";var y="2024-11-05",d=k(),J=new Set(d.map(n=>n.name)),s=Buffer.alloc(0);process.stdin.on("data",n=>{s=Buffer.concat([s,Buffer.isBuffer(n)?n:Buffer.from(n)]),R().catch(e=>{c(a(null,-32603,p(e)))})});process.stdin.resume();async function R(){for(;;){let n=s.indexOf(`\r
2
2
  \r
3
- `);if(n<0)return;let t=r.subarray(0,n).toString("utf8").match(/content-length:\s*(\d+)/i);if(!t){r=r.subarray(n+4),c(u(null,-32600,"Missing Content-Length header."));continue}let s=Number(t[1]),i=n+4,o=i+s;if(r.length<o)return;let h=r.subarray(i,o).toString("utf8");r=r.subarray(o);let d;try{d=JSON.parse(h)}catch(y){c(u(null,-32700,`Invalid JSON-RPC request: ${f(y)}`));continue}let p=await w(d);p&&c(p)}}async function w(n){if(!l(n))return u(null,-32600,"JSON-RPC request must be an object.");let e=n,t=e.id??null;if(!(e.id===void 0&&e.method?.startsWith("notifications/"))){if(e.jsonrpc!=="2.0"||!e.method)return u(t,-32600,"Invalid JSON-RPC 2.0 request.");try{switch(e.method){case"initialize":return a(t,{capabilities:{tools:{}},protocolVersion:b,serverInfo:{name:"ccr-fusion-tool-fallback",title:"CCR Fusion Tool Fallback",version:"1.0.0"}});case"ping":return a(t,{});case"tools/list":return a(t,{tools:g});case"tools/call":return a(t,S(e.params));default:return u(t,-32601,`Unsupported MCP method: ${e.method}`)}}catch(s){return u(t,-32603,f(s))}}}function S(n){let t=(l(n)&&typeof n.name=="string"?n.name.trim():"")||"unknown",s=J.has(t)?"":" The requested tool was not in the fallback catalog.";return{content:[{text:`Fusion MCP tool "${t}" is temporarily unavailable. CCR registered a fallback definition because the real MCP server did not provide the tool during discovery. Check the Fusion MCP server logs and retry.${s}`,type:"text"}],isError:!0}}function k(){let n=P("FUSION_FALLBACK_TOOLS_JSON");if(!n)return[];let e;try{e=JSON.parse(n)}catch{return[]}if(!Array.isArray(e))return[];let t=new Set,s=[];for(let i of e){if(!l(i))continue;let o=m(i.name);!o||t.has(o)||(t.add(o),s.push({description:m(i.description)||`Fallback registration for Fusion MCP tool "${o}". The real MCP server should handle successful calls.`,inputSchema:l(i.inputSchema)?i.inputSchema:C({}),name:o}))}return s}function C(n,e=[]){return{additionalProperties:!0,properties:n,...e.length?{required:e}:{},type:"object"}}function a(n,e){return{id:n,jsonrpc:"2.0",result:e}}function u(n,e,t){return{error:{code:e,message:t},id:n,jsonrpc:"2.0"}}function c(n){let e=JSON.stringify(n);process.stdout.write(`Content-Length: ${Buffer.byteLength(e,"utf8")}\r
3
+ `);if(n<0)return;let t=s.subarray(0,n).toString("utf8").match(/content-length:\s*(\d+)/i);if(!t){s=s.subarray(n+4),c(a(null,-32600,"Missing Content-Length header."));continue}let i=Number(t[1]),r=n+4,o=r+i;if(s.length<o)return;let h=s.subarray(r,o).toString("utf8");s=s.subarray(o);let g;try{g=JSON.parse(h)}catch(b){c(a(null,-32700,`Invalid JSON-RPC request: ${p(b)}`));continue}let m=await w(g);m&&c(m)}}async function w(n){if(!l(n))return a(null,-32600,"JSON-RPC request must be an object.");let e=n,t=e.id??null;if(!(e.id===void 0&&e.method?.startsWith("notifications/"))){if(e.jsonrpc!=="2.0"||!e.method)return a(t,-32600,"Invalid JSON-RPC 2.0 request.");try{switch(e.method){case"initialize":return u(t,{capabilities:{tools:{}},protocolVersion:y,serverInfo:{name:"ccr-fusion-tool-fallback",title:"CCR Fusion Tool Fallback",version:"1.0.0"}});case"ping":return u(t,{});case"tools/list":return u(t,{tools:d});case"tools/call":return u(t,S(e.params));default:return a(t,-32601,`Unsupported MCP method: ${e.method}`)}}catch(i){return a(t,-32603,p(i))}}}function S(n){let t=(l(n)&&typeof n.name=="string"?n.name.trim():"")||"unknown",i=d.find(o=>o.name===t),r=J.has(t)?"":" The requested tool was not in the fallback catalog.";return{content:[{text:i?.unavailableMessage||`Fusion MCP tool "${t}" is temporarily unavailable. CCR registered a fallback definition because the real MCP server did not provide the tool during discovery. Check the Fusion MCP server logs and retry.${r}`,type:"text"}],isError:!0}}function k(){let n=v("FUSION_FALLBACK_TOOLS_JSON");if(!n)return[];let e;try{e=JSON.parse(n)}catch{return[]}if(!Array.isArray(e))return[];let t=new Set,i=[];for(let r of e){if(!l(r))continue;let o=f(r.name);!o||t.has(o)||(t.add(o),i.push({description:f(r.description)||`Fallback registration for Fusion MCP tool "${o}". The real MCP server should handle successful calls.`,inputSchema:l(r.inputSchema)?r.inputSchema:C({}),name:o,unavailableMessage:f(r.unavailableMessage)}))}return i}function C(n,e=[]){return{additionalProperties:!0,properties:n,...e.length?{required:e}:{},type:"object"}}function u(n,e){return{id:n,jsonrpc:"2.0",result:e}}function a(n,e,t){return{error:{code:e,message:t},id:n,jsonrpc:"2.0"}}function c(n){let e=JSON.stringify(n);process.stdout.write(`Content-Length: ${Buffer.byteLength(e,"utf8")}\r
4
4
  \r
5
- ${e}`)}function P(n){return process.env[n]?.trim()??""}function m(n){return typeof n=="string"&&n.trim()?n.trim():void 0}function l(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function f(n){return n instanceof Error?n.message:String(n)}
5
+ ${e}`)}function v(n){return process.env[n]?.trim()??""}function f(n){return typeof n=="string"&&n.trim()?n.trim():void 0}function l(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function p(n){return n instanceof Error?n.message:String(n)}