@evolvingmachines/sdk 0.0.13 → 0.0.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/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
`)].filter(r=>r.length>0);await c.files.write(s,l.join(`
|
|
4
4
|
|
|
5
5
|
`)+`
|
|
6
|
-
`);}async function Ce(c,e,n,s){if(!(!s||Object.keys(s).length===0))switch(c){case "claude":await Q(e,n,s);break;case "codex":await te(e,s);break;case "gemini":await X(e,s);break;case "qwen":await ee(e,s);break;default:throw new Error(`Unknown agent type for MCP config: ${c}`)}}function ne(){let c={};return function(p){let t;try{t=JSON.parse(p);}catch{return null}if(t._meta||t._prompt)return null;let u=t.session_id;switch(t.type){case "system":return null;case "assistant":return e(t.message?.content,"assistant",u);case "user":{let d=t.message?.content;return typeof d=="string"||Array.isArray(d)&&d.length===1&&d[0].type==="text"?null:e(d,"user",u)}case "result":return null;default:return null}};function e(r,p,t){if(typeof r=="string")return p==="user"?null:[{sessionId:t,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:r}}}];if(!r||!Array.isArray(r))return null;let u=[];for(let d of r){let m=null;switch(d.type){case "text":case "text_delta":if(p==="user")break;m={sessionUpdate:"agent_message_chunk",content:{type:"text",text:d.text}};break;case "image":if(p==="user")break;m={sessionUpdate:"agent_message_chunk",content:{type:"image",data:d.source?.type==="base64"?d.source.data:"",mimeType:d.source?.type==="base64"?d.source.media_type:"",uri:d.source?.type==="url"?d.source.url:void 0}};break;case "thinking":case "thinking_delta":m={sessionUpdate:"agent_thought_chunk",content:{type:"text",text:d.thinking}};break;case "tool_use":case "server_tool_use":case "mcp_tool_use":{if(c[d.id]=d,d.name==="TodoWrite")Array.isArray(d.input?.todos)&&(m={sessionUpdate:"plan",entries:o(d.input)});else {let f=n(d);m={sessionUpdate:"tool_call",toolCallId:d.id,status:"pending",...f};}break}case "tool_result":case "tool_search_tool_result":case "web_fetch_tool_result":case "web_search_tool_result":case "code_execution_tool_result":case "bash_code_execution_tool_result":case "text_editor_code_execution_tool_result":case "mcp_tool_result":{let f=c[d.tool_use_id];if(!f||(delete c[d.tool_use_id],f.name==="TodoWrite"))break;m={sessionUpdate:"tool_call_update",toolCallId:d.tool_use_id,status:"is_error"in d&&d.is_error?"failed":"completed",...s(d,f)};break}}m&&u.push({sessionId:t,update:m});}return u.length>0?u:null}function n(r){let p=r.name,t=r.input||{};switch(p){case "Task":return {title:t.description||"Task",kind:"think",content:t.prompt?[{type:"content",content:{type:"text",text:t.prompt}}]:[],rawInput:t};case "NotebookRead":return {title:t.notebook_path?`Read Notebook ${t.notebook_path}`:"Read Notebook",kind:"read",content:[],locations:t.notebook_path?[{path:t.notebook_path}]:[],rawInput:t};case "NotebookEdit":return {title:t.notebook_path?`Edit Notebook ${t.notebook_path}`:"Edit Notebook",kind:"edit",content:t.new_source?[{type:"content",content:{type:"text",text:t.new_source}}]:[],locations:t.notebook_path?[{path:t.notebook_path}]:[],rawInput:t};case "Bash":return {title:t.command?"`"+t.command.replaceAll("`","\\`")+"`":"Terminal",kind:"execute",content:t.description?[{type:"content",content:{type:"text",text:t.description}}]:[],rawInput:t};case "BashOutput":return {title:"Tail Logs",kind:"execute",content:[],rawInput:t};case "KillShell":return {title:"Kill Process",kind:"execute",content:[],rawInput:t};case "Read":{let u="";return t.limit?u=" ("+((t.offset??0)+1)+" - "+((t.offset??0)+t.limit)+")":t.offset&&(u=" (from line "+(t.offset+1)+")"),{title:"Read "+(t.file_path??"File")+u,kind:"read",content:[],locations:t.file_path?[{path:t.file_path,line:t.offset??0}]:[],rawInput:t}}case "LS":return {title:t.path?`List \`${t.path}\` directory`:"List current directory",kind:"search",content:[],locations:[],rawInput:t};case "Edit":{let u=t.file_path;return {title:u?`Edit \`${u}\``:"Edit",kind:"edit",content:u?[{type:"diff",path:u,oldText:t.old_string??null,newText:t.new_string??""}]:[],locations:u?[{path:u}]:[],rawInput:t}}case "Write":return {title:t.file_path?`Write ${t.file_path}`:"Write",kind:"edit",content:t.file_path?[{type:"diff",path:t.file_path,oldText:null,newText:t.content??""}]:[],locations:t.file_path?[{path:t.file_path}]:[],rawInput:t};case "Glob":{let u="Find";return t.path&&(u+=` \`${t.path}\``),t.pattern&&(u+=` \`${t.pattern}\``),{title:u,kind:"search",content:[],locations:t.path?[{path:t.path}]:[],rawInput:t}}case "Grep":{let u="grep";return t["-i"]&&(u+=" -i"),t["-n"]&&(u+=" -n"),t["-A"]!==void 0&&(u+=` -A ${t["-A"]}`),t["-B"]!==void 0&&(u+=` -B ${t["-B"]}`),t["-C"]!==void 0&&(u+=` -C ${t["-C"]}`),t.output_mode==="files_with_matches"?u+=" -l":t.output_mode==="count"&&(u+=" -c"),t.head_limit!==void 0&&(u+=` | head -${t.head_limit}`),t.glob&&(u+=` --include="${t.glob}"`),t.type&&(u+=` --type=${t.type}`),t.multiline&&(u+=" -P"),u+=` "${t.pattern??""}"`,t.path&&(u+=` ${t.path}`),{title:u,kind:"search",content:[],rawInput:t}}case "WebFetch":return {title:t.url?`Fetch ${t.url}`:"Fetch",kind:"fetch",content:t.prompt?[{type:"content",content:{type:"text",text:t.prompt}}]:[],rawInput:t};case "WebSearch":{let u=`"${t.query??""}"`;return t.allowed_domains?.length>0&&(u+=` (allowed: ${t.allowed_domains.join(", ")})`),t.blocked_domains?.length>0&&(u+=` (blocked: ${t.blocked_domains.join(", ")})`),{title:u,kind:"fetch",content:[],rawInput:t}}case "TodoWrite":return {title:Array.isArray(t.todos)?`Update TODOs: ${t.todos.map(u=>u.content).join(", ")}`:"Update TODOs",kind:"think",content:[],rawInput:t};case "ExitPlanMode":return {title:"Ready to code?",kind:"switch_mode",content:t.plan?[{type:"content",content:{type:"text",text:t.plan}}]:[],rawInput:t};default:if(p?.startsWith("mcp__")){let u=p.split("__"),d=u[1]||"mcp",m=u.slice(2).join("__")||p;return {title:`${d}: ${m}`,kind:"other",content:[],rawInput:t}}return {title:p||"Unknown Tool",kind:"other",content:[],rawInput:t}}}function s(r,p){let t=r.content;switch(p?.name){case "Read":return Array.isArray(t)&&t.length>0?{content:t.map(u=>({type:"content",content:u.type==="text"?{type:"text",text:l(u.text)}:i(u,false)}))}:typeof t=="string"&&t.length>0?{content:[{type:"content",content:{type:"text",text:l(t)}}]}:{};case "Edit":case "Write":case "Bash":return
|
|
6
|
+
`);}async function Ce(c,e,n,s){if(!(!s||Object.keys(s).length===0))switch(c){case "claude":await Q(e,n,s);break;case "codex":await te(e,s);break;case "gemini":await X(e,s);break;case "qwen":await ee(e,s);break;default:throw new Error(`Unknown agent type for MCP config: ${c}`)}}function ne(){let c={};return function(p){let t;try{t=JSON.parse(p);}catch{return null}if(t._meta||t._prompt)return null;let u=t.session_id;switch(t.type){case "system":return null;case "assistant":return e(t.message?.content,"assistant",u);case "user":{let d=t.message?.content;return typeof d=="string"||Array.isArray(d)&&d.length===1&&d[0].type==="text"?null:e(d,"user",u)}case "result":return null;default:return null}};function e(r,p,t){if(typeof r=="string")return p==="user"?null:[{sessionId:t,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:r}}}];if(!r||!Array.isArray(r))return null;let u=[];for(let d of r){let m=null;switch(d.type){case "text":case "text_delta":if(p==="user")break;m={sessionUpdate:"agent_message_chunk",content:{type:"text",text:d.text}};break;case "image":if(p==="user")break;m={sessionUpdate:"agent_message_chunk",content:{type:"image",data:d.source?.type==="base64"?d.source.data:"",mimeType:d.source?.type==="base64"?d.source.media_type:"",uri:d.source?.type==="url"?d.source.url:void 0}};break;case "thinking":case "thinking_delta":m={sessionUpdate:"agent_thought_chunk",content:{type:"text",text:d.thinking}};break;case "tool_use":case "server_tool_use":case "mcp_tool_use":{if(c[d.id]=d,d.name==="TodoWrite")Array.isArray(d.input?.todos)&&(m={sessionUpdate:"plan",entries:o(d.input)});else {let f=n(d);m={sessionUpdate:"tool_call",toolCallId:d.id,status:"pending",...f};}break}case "tool_result":case "tool_search_tool_result":case "web_fetch_tool_result":case "web_search_tool_result":case "code_execution_tool_result":case "bash_code_execution_tool_result":case "text_editor_code_execution_tool_result":case "mcp_tool_result":{let f=c[d.tool_use_id];if(!f||(delete c[d.tool_use_id],f.name==="TodoWrite"))break;m={sessionUpdate:"tool_call_update",toolCallId:d.tool_use_id,status:"is_error"in d&&d.is_error?"failed":"completed",...s(d,f)};break}}m&&u.push({sessionId:t,update:m});}return u.length>0?u:null}function n(r){let p=r.name,t=r.input||{};switch(p){case "Task":return {title:t.description||"Task",kind:"think",content:t.prompt?[{type:"content",content:{type:"text",text:t.prompt}}]:[],rawInput:t};case "NotebookRead":return {title:t.notebook_path?`Read Notebook ${t.notebook_path}`:"Read Notebook",kind:"read",content:[],locations:t.notebook_path?[{path:t.notebook_path}]:[],rawInput:t};case "NotebookEdit":return {title:t.notebook_path?`Edit Notebook ${t.notebook_path}`:"Edit Notebook",kind:"edit",content:t.new_source?[{type:"content",content:{type:"text",text:t.new_source}}]:[],locations:t.notebook_path?[{path:t.notebook_path}]:[],rawInput:t};case "Bash":return {title:t.command?"`"+t.command.replaceAll("`","\\`")+"`":"Terminal",kind:"execute",content:t.description?[{type:"content",content:{type:"text",text:t.description}}]:[],rawInput:t};case "BashOutput":return {title:"Tail Logs",kind:"execute",content:[],rawInput:t};case "KillShell":return {title:"Kill Process",kind:"execute",content:[],rawInput:t};case "Read":{let u="";return t.limit?u=" ("+((t.offset??0)+1)+" - "+((t.offset??0)+t.limit)+")":t.offset&&(u=" (from line "+(t.offset+1)+")"),{title:"Read "+(t.file_path??"File")+u,kind:"read",content:[],locations:t.file_path?[{path:t.file_path,line:t.offset??0}]:[],rawInput:t}}case "LS":return {title:t.path?`List \`${t.path}\` directory`:"List current directory",kind:"search",content:[],locations:[],rawInput:t};case "Edit":{let u=t.file_path;return {title:u?`Edit \`${u}\``:"Edit",kind:"edit",content:u?[{type:"diff",path:u,oldText:t.old_string??null,newText:t.new_string??""}]:[],locations:u?[{path:u}]:[],rawInput:t}}case "Write":return {title:t.file_path?`Write ${t.file_path}`:"Write",kind:"edit",content:t.file_path?[{type:"diff",path:t.file_path,oldText:null,newText:t.content??""}]:[],locations:t.file_path?[{path:t.file_path}]:[],rawInput:t};case "Glob":{let u="Find";return t.path&&(u+=` \`${t.path}\``),t.pattern&&(u+=` \`${t.pattern}\``),{title:u,kind:"search",content:[],locations:t.path?[{path:t.path}]:[],rawInput:t}}case "Grep":{let u="grep";return t["-i"]&&(u+=" -i"),t["-n"]&&(u+=" -n"),t["-A"]!==void 0&&(u+=` -A ${t["-A"]}`),t["-B"]!==void 0&&(u+=` -B ${t["-B"]}`),t["-C"]!==void 0&&(u+=` -C ${t["-C"]}`),t.output_mode==="files_with_matches"?u+=" -l":t.output_mode==="count"&&(u+=" -c"),t.head_limit!==void 0&&(u+=` | head -${t.head_limit}`),t.glob&&(u+=` --include="${t.glob}"`),t.type&&(u+=` --type=${t.type}`),t.multiline&&(u+=" -P"),u+=` "${t.pattern??""}"`,t.path&&(u+=` ${t.path}`),{title:u,kind:"search",content:[],rawInput:t}}case "WebFetch":return {title:t.url?`Fetch ${t.url}`:"Fetch",kind:"fetch",content:t.prompt?[{type:"content",content:{type:"text",text:t.prompt}}]:[],rawInput:t};case "WebSearch":{let u=`"${t.query??""}"`;return t.allowed_domains?.length>0&&(u+=` (allowed: ${t.allowed_domains.join(", ")})`),t.blocked_domains?.length>0&&(u+=` (blocked: ${t.blocked_domains.join(", ")})`),{title:u,kind:"fetch",content:[],rawInput:t}}case "TodoWrite":return {title:Array.isArray(t.todos)?`Update TODOs: ${t.todos.map(u=>u.content).join(", ")}`:"Update TODOs",kind:"think",content:[],rawInput:t};case "ExitPlanMode":return {title:"Ready to code?",kind:"switch_mode",content:t.plan?[{type:"content",content:{type:"text",text:t.plan}}]:[],rawInput:t};default:if(p?.startsWith("mcp__")){let u=p.split("__"),d=u[1]||"mcp",m=u.slice(2).join("__")||p;return {title:`${d}: ${m}`,kind:"other",content:[],rawInput:t}}return {title:p||"Unknown Tool",kind:"other",content:[],rawInput:t}}}function s(r,p){let t=r.content;switch(p?.name){case "Read":return Array.isArray(t)&&t.length>0?{content:t.map(u=>({type:"content",content:u.type==="text"?{type:"text",text:l(u.text)}:i(u,false)}))}:typeof t=="string"&&t.length>0?{content:[{type:"content",content:{type:"text",text:l(t)}}]}:{};case "Edit":case "Write":case "Bash":return a(t,r.is_error||false);case "ExitPlanMode":return {title:"Exited Plan Mode"};default:return a(t,"is_error"in r?r.is_error:false)}}function a(r,p=false){return Array.isArray(r)&&r.length>0?{content:r.map(t=>({type:"content",content:i(t,p)}))}:typeof r=="string"&&r.length>0?{content:[{type:"content",content:{type:"text",text:p?"```\n"+r+"\n```":r}}]}:{}}function i(r,p){if(r.type==="text")return p?{type:"text",text:"```\n"+r.text+"\n```"}:{type:"text",text:r.text};if(r.type==="image"){if(r.data&&r.mimeType)return {type:"image",data:r.data,mimeType:r.mimeType};if(r.source?.type==="base64")return {type:"image",data:r.source.data||"",mimeType:r.source.media_type||""};if(r.source?.type==="url")return {type:"image",data:"",mimeType:"",uri:r.source.url}}return r}function o(r){return r.todos.map(p=>({content:p.content,status:p.status||"pending",priority:"medium"}))}function l(r){let p="```",t=Array.from(r.matchAll(/^```+/gm));for(let[u]of t)for(;u.length>=p.length;)p+="`";return p+`
|
|
7
7
|
`+r+(r.endsWith(`
|
|
8
8
|
`)?"":`
|
|
9
9
|
`)+p}}function se(){return function(r){let p;try{p=JSON.parse(r);}catch{return null}if(p._meta||p._prompt)return null;let t=[];switch(p.type){case "thread.started":case "turn.started":case "turn.completed":return null;case "item.started":{let u=p.item;if(!u)return null;let d=e(u);d&&t.push({update:d});break}case "item.updated":{let u=p.item;if(!u)return null;let d=n(u);d&&t.push({update:d});break}case "item.completed":{let u=p.item;if(!u)return null;let d=s(u);d&&t.push({update:d});break}default:return null}return t.length>0?t:null};function e(l){let r=l.id;switch(l.type){case "mcp_tool_call":return {type:"mcp_tool_call",name:`${l.server}:${l.tool}`},{sessionUpdate:"tool_call",toolCallId:r,title:`${l.server}: ${l.tool}`,kind:"other",status:"in_progress",rawInput:l.arguments,content:[]};case "command_execution":return {type:"command_execution",name:l.command},{sessionUpdate:"tool_call",toolCallId:r,title:l.command?`\`${l.command}\``:"Execute Command",kind:"execute",status:"in_progress",rawInput:{command:l.command},content:[]};case "web_search":return {type:"web_search",name:l.query},{sessionUpdate:"tool_call",toolCallId:r,title:`Search: ${l.query??""}`,kind:"fetch",status:"in_progress",content:[]};case "todo_list":return {sessionUpdate:"plan",entries:o(l.items)};default:return null}}function n(l){return l.type==="todo_list"?{sessionUpdate:"plan",entries:o(l.items)}:null}function s(l){let r=l.id;switch(l.type){case "reasoning":return {sessionUpdate:"agent_thought_chunk",content:{type:"text",text:l.text??l.summary?.join(`
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import {EventEmitter}from'events';import tn from'ajv';import At from'zod-to-json
|
|
|
3
3
|
`)].filter(r=>r.length>0);await c.files.write(s,l.join(`
|
|
4
4
|
|
|
5
5
|
`)+`
|
|
6
|
-
`);}async function Ce(c,e,n,s){if(!(!s||Object.keys(s).length===0))switch(c){case "claude":await Q(e,n,s);break;case "codex":await te(e,s);break;case "gemini":await X(e,s);break;case "qwen":await ee(e,s);break;default:throw new Error(`Unknown agent type for MCP config: ${c}`)}}function ne(){let c={};return function(p){let t;try{t=JSON.parse(p);}catch{return null}if(t._meta||t._prompt)return null;let u=t.session_id;switch(t.type){case "system":return null;case "assistant":return e(t.message?.content,"assistant",u);case "user":{let d=t.message?.content;return typeof d=="string"||Array.isArray(d)&&d.length===1&&d[0].type==="text"?null:e(d,"user",u)}case "result":return null;default:return null}};function e(r,p,t){if(typeof r=="string")return p==="user"?null:[{sessionId:t,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:r}}}];if(!r||!Array.isArray(r))return null;let u=[];for(let d of r){let m=null;switch(d.type){case "text":case "text_delta":if(p==="user")break;m={sessionUpdate:"agent_message_chunk",content:{type:"text",text:d.text}};break;case "image":if(p==="user")break;m={sessionUpdate:"agent_message_chunk",content:{type:"image",data:d.source?.type==="base64"?d.source.data:"",mimeType:d.source?.type==="base64"?d.source.media_type:"",uri:d.source?.type==="url"?d.source.url:void 0}};break;case "thinking":case "thinking_delta":m={sessionUpdate:"agent_thought_chunk",content:{type:"text",text:d.thinking}};break;case "tool_use":case "server_tool_use":case "mcp_tool_use":{if(c[d.id]=d,d.name==="TodoWrite")Array.isArray(d.input?.todos)&&(m={sessionUpdate:"plan",entries:o(d.input)});else {let f=n(d);m={sessionUpdate:"tool_call",toolCallId:d.id,status:"pending",...f};}break}case "tool_result":case "tool_search_tool_result":case "web_fetch_tool_result":case "web_search_tool_result":case "code_execution_tool_result":case "bash_code_execution_tool_result":case "text_editor_code_execution_tool_result":case "mcp_tool_result":{let f=c[d.tool_use_id];if(!f||(delete c[d.tool_use_id],f.name==="TodoWrite"))break;m={sessionUpdate:"tool_call_update",toolCallId:d.tool_use_id,status:"is_error"in d&&d.is_error?"failed":"completed",...s(d,f)};break}}m&&u.push({sessionId:t,update:m});}return u.length>0?u:null}function n(r){let p=r.name,t=r.input||{};switch(p){case "Task":return {title:t.description||"Task",kind:"think",content:t.prompt?[{type:"content",content:{type:"text",text:t.prompt}}]:[],rawInput:t};case "NotebookRead":return {title:t.notebook_path?`Read Notebook ${t.notebook_path}`:"Read Notebook",kind:"read",content:[],locations:t.notebook_path?[{path:t.notebook_path}]:[],rawInput:t};case "NotebookEdit":return {title:t.notebook_path?`Edit Notebook ${t.notebook_path}`:"Edit Notebook",kind:"edit",content:t.new_source?[{type:"content",content:{type:"text",text:t.new_source}}]:[],locations:t.notebook_path?[{path:t.notebook_path}]:[],rawInput:t};case "Bash":return {title:t.command?"`"+t.command.replaceAll("`","\\`")+"`":"Terminal",kind:"execute",content:t.description?[{type:"content",content:{type:"text",text:t.description}}]:[],rawInput:t};case "BashOutput":return {title:"Tail Logs",kind:"execute",content:[],rawInput:t};case "KillShell":return {title:"Kill Process",kind:"execute",content:[],rawInput:t};case "Read":{let u="";return t.limit?u=" ("+((t.offset??0)+1)+" - "+((t.offset??0)+t.limit)+")":t.offset&&(u=" (from line "+(t.offset+1)+")"),{title:"Read "+(t.file_path??"File")+u,kind:"read",content:[],locations:t.file_path?[{path:t.file_path,line:t.offset??0}]:[],rawInput:t}}case "LS":return {title:t.path?`List \`${t.path}\` directory`:"List current directory",kind:"search",content:[],locations:[],rawInput:t};case "Edit":{let u=t.file_path;return {title:u?`Edit \`${u}\``:"Edit",kind:"edit",content:u?[{type:"diff",path:u,oldText:t.old_string??null,newText:t.new_string??""}]:[],locations:u?[{path:u}]:[],rawInput:t}}case "Write":return {title:t.file_path?`Write ${t.file_path}`:"Write",kind:"edit",content:t.file_path?[{type:"diff",path:t.file_path,oldText:null,newText:t.content??""}]:[],locations:t.file_path?[{path:t.file_path}]:[],rawInput:t};case "Glob":{let u="Find";return t.path&&(u+=` \`${t.path}\``),t.pattern&&(u+=` \`${t.pattern}\``),{title:u,kind:"search",content:[],locations:t.path?[{path:t.path}]:[],rawInput:t}}case "Grep":{let u="grep";return t["-i"]&&(u+=" -i"),t["-n"]&&(u+=" -n"),t["-A"]!==void 0&&(u+=` -A ${t["-A"]}`),t["-B"]!==void 0&&(u+=` -B ${t["-B"]}`),t["-C"]!==void 0&&(u+=` -C ${t["-C"]}`),t.output_mode==="files_with_matches"?u+=" -l":t.output_mode==="count"&&(u+=" -c"),t.head_limit!==void 0&&(u+=` | head -${t.head_limit}`),t.glob&&(u+=` --include="${t.glob}"`),t.type&&(u+=` --type=${t.type}`),t.multiline&&(u+=" -P"),u+=` "${t.pattern??""}"`,t.path&&(u+=` ${t.path}`),{title:u,kind:"search",content:[],rawInput:t}}case "WebFetch":return {title:t.url?`Fetch ${t.url}`:"Fetch",kind:"fetch",content:t.prompt?[{type:"content",content:{type:"text",text:t.prompt}}]:[],rawInput:t};case "WebSearch":{let u=`"${t.query??""}"`;return t.allowed_domains?.length>0&&(u+=` (allowed: ${t.allowed_domains.join(", ")})`),t.blocked_domains?.length>0&&(u+=` (blocked: ${t.blocked_domains.join(", ")})`),{title:u,kind:"fetch",content:[],rawInput:t}}case "TodoWrite":return {title:Array.isArray(t.todos)?`Update TODOs: ${t.todos.map(u=>u.content).join(", ")}`:"Update TODOs",kind:"think",content:[],rawInput:t};case "ExitPlanMode":return {title:"Ready to code?",kind:"switch_mode",content:t.plan?[{type:"content",content:{type:"text",text:t.plan}}]:[],rawInput:t};default:if(p?.startsWith("mcp__")){let u=p.split("__"),d=u[1]||"mcp",m=u.slice(2).join("__")||p;return {title:`${d}: ${m}`,kind:"other",content:[],rawInput:t}}return {title:p||"Unknown Tool",kind:"other",content:[],rawInput:t}}}function s(r,p){let t=r.content;switch(p?.name){case "Read":return Array.isArray(t)&&t.length>0?{content:t.map(u=>({type:"content",content:u.type==="text"?{type:"text",text:l(u.text)}:i(u,false)}))}:typeof t=="string"&&t.length>0?{content:[{type:"content",content:{type:"text",text:l(t)}}]}:{};case "Edit":case "Write":case "Bash":return
|
|
6
|
+
`);}async function Ce(c,e,n,s){if(!(!s||Object.keys(s).length===0))switch(c){case "claude":await Q(e,n,s);break;case "codex":await te(e,s);break;case "gemini":await X(e,s);break;case "qwen":await ee(e,s);break;default:throw new Error(`Unknown agent type for MCP config: ${c}`)}}function ne(){let c={};return function(p){let t;try{t=JSON.parse(p);}catch{return null}if(t._meta||t._prompt)return null;let u=t.session_id;switch(t.type){case "system":return null;case "assistant":return e(t.message?.content,"assistant",u);case "user":{let d=t.message?.content;return typeof d=="string"||Array.isArray(d)&&d.length===1&&d[0].type==="text"?null:e(d,"user",u)}case "result":return null;default:return null}};function e(r,p,t){if(typeof r=="string")return p==="user"?null:[{sessionId:t,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:r}}}];if(!r||!Array.isArray(r))return null;let u=[];for(let d of r){let m=null;switch(d.type){case "text":case "text_delta":if(p==="user")break;m={sessionUpdate:"agent_message_chunk",content:{type:"text",text:d.text}};break;case "image":if(p==="user")break;m={sessionUpdate:"agent_message_chunk",content:{type:"image",data:d.source?.type==="base64"?d.source.data:"",mimeType:d.source?.type==="base64"?d.source.media_type:"",uri:d.source?.type==="url"?d.source.url:void 0}};break;case "thinking":case "thinking_delta":m={sessionUpdate:"agent_thought_chunk",content:{type:"text",text:d.thinking}};break;case "tool_use":case "server_tool_use":case "mcp_tool_use":{if(c[d.id]=d,d.name==="TodoWrite")Array.isArray(d.input?.todos)&&(m={sessionUpdate:"plan",entries:o(d.input)});else {let f=n(d);m={sessionUpdate:"tool_call",toolCallId:d.id,status:"pending",...f};}break}case "tool_result":case "tool_search_tool_result":case "web_fetch_tool_result":case "web_search_tool_result":case "code_execution_tool_result":case "bash_code_execution_tool_result":case "text_editor_code_execution_tool_result":case "mcp_tool_result":{let f=c[d.tool_use_id];if(!f||(delete c[d.tool_use_id],f.name==="TodoWrite"))break;m={sessionUpdate:"tool_call_update",toolCallId:d.tool_use_id,status:"is_error"in d&&d.is_error?"failed":"completed",...s(d,f)};break}}m&&u.push({sessionId:t,update:m});}return u.length>0?u:null}function n(r){let p=r.name,t=r.input||{};switch(p){case "Task":return {title:t.description||"Task",kind:"think",content:t.prompt?[{type:"content",content:{type:"text",text:t.prompt}}]:[],rawInput:t};case "NotebookRead":return {title:t.notebook_path?`Read Notebook ${t.notebook_path}`:"Read Notebook",kind:"read",content:[],locations:t.notebook_path?[{path:t.notebook_path}]:[],rawInput:t};case "NotebookEdit":return {title:t.notebook_path?`Edit Notebook ${t.notebook_path}`:"Edit Notebook",kind:"edit",content:t.new_source?[{type:"content",content:{type:"text",text:t.new_source}}]:[],locations:t.notebook_path?[{path:t.notebook_path}]:[],rawInput:t};case "Bash":return {title:t.command?"`"+t.command.replaceAll("`","\\`")+"`":"Terminal",kind:"execute",content:t.description?[{type:"content",content:{type:"text",text:t.description}}]:[],rawInput:t};case "BashOutput":return {title:"Tail Logs",kind:"execute",content:[],rawInput:t};case "KillShell":return {title:"Kill Process",kind:"execute",content:[],rawInput:t};case "Read":{let u="";return t.limit?u=" ("+((t.offset??0)+1)+" - "+((t.offset??0)+t.limit)+")":t.offset&&(u=" (from line "+(t.offset+1)+")"),{title:"Read "+(t.file_path??"File")+u,kind:"read",content:[],locations:t.file_path?[{path:t.file_path,line:t.offset??0}]:[],rawInput:t}}case "LS":return {title:t.path?`List \`${t.path}\` directory`:"List current directory",kind:"search",content:[],locations:[],rawInput:t};case "Edit":{let u=t.file_path;return {title:u?`Edit \`${u}\``:"Edit",kind:"edit",content:u?[{type:"diff",path:u,oldText:t.old_string??null,newText:t.new_string??""}]:[],locations:u?[{path:u}]:[],rawInput:t}}case "Write":return {title:t.file_path?`Write ${t.file_path}`:"Write",kind:"edit",content:t.file_path?[{type:"diff",path:t.file_path,oldText:null,newText:t.content??""}]:[],locations:t.file_path?[{path:t.file_path}]:[],rawInput:t};case "Glob":{let u="Find";return t.path&&(u+=` \`${t.path}\``),t.pattern&&(u+=` \`${t.pattern}\``),{title:u,kind:"search",content:[],locations:t.path?[{path:t.path}]:[],rawInput:t}}case "Grep":{let u="grep";return t["-i"]&&(u+=" -i"),t["-n"]&&(u+=" -n"),t["-A"]!==void 0&&(u+=` -A ${t["-A"]}`),t["-B"]!==void 0&&(u+=` -B ${t["-B"]}`),t["-C"]!==void 0&&(u+=` -C ${t["-C"]}`),t.output_mode==="files_with_matches"?u+=" -l":t.output_mode==="count"&&(u+=" -c"),t.head_limit!==void 0&&(u+=` | head -${t.head_limit}`),t.glob&&(u+=` --include="${t.glob}"`),t.type&&(u+=` --type=${t.type}`),t.multiline&&(u+=" -P"),u+=` "${t.pattern??""}"`,t.path&&(u+=` ${t.path}`),{title:u,kind:"search",content:[],rawInput:t}}case "WebFetch":return {title:t.url?`Fetch ${t.url}`:"Fetch",kind:"fetch",content:t.prompt?[{type:"content",content:{type:"text",text:t.prompt}}]:[],rawInput:t};case "WebSearch":{let u=`"${t.query??""}"`;return t.allowed_domains?.length>0&&(u+=` (allowed: ${t.allowed_domains.join(", ")})`),t.blocked_domains?.length>0&&(u+=` (blocked: ${t.blocked_domains.join(", ")})`),{title:u,kind:"fetch",content:[],rawInput:t}}case "TodoWrite":return {title:Array.isArray(t.todos)?`Update TODOs: ${t.todos.map(u=>u.content).join(", ")}`:"Update TODOs",kind:"think",content:[],rawInput:t};case "ExitPlanMode":return {title:"Ready to code?",kind:"switch_mode",content:t.plan?[{type:"content",content:{type:"text",text:t.plan}}]:[],rawInput:t};default:if(p?.startsWith("mcp__")){let u=p.split("__"),d=u[1]||"mcp",m=u.slice(2).join("__")||p;return {title:`${d}: ${m}`,kind:"other",content:[],rawInput:t}}return {title:p||"Unknown Tool",kind:"other",content:[],rawInput:t}}}function s(r,p){let t=r.content;switch(p?.name){case "Read":return Array.isArray(t)&&t.length>0?{content:t.map(u=>({type:"content",content:u.type==="text"?{type:"text",text:l(u.text)}:i(u,false)}))}:typeof t=="string"&&t.length>0?{content:[{type:"content",content:{type:"text",text:l(t)}}]}:{};case "Edit":case "Write":case "Bash":return a(t,r.is_error||false);case "ExitPlanMode":return {title:"Exited Plan Mode"};default:return a(t,"is_error"in r?r.is_error:false)}}function a(r,p=false){return Array.isArray(r)&&r.length>0?{content:r.map(t=>({type:"content",content:i(t,p)}))}:typeof r=="string"&&r.length>0?{content:[{type:"content",content:{type:"text",text:p?"```\n"+r+"\n```":r}}]}:{}}function i(r,p){if(r.type==="text")return p?{type:"text",text:"```\n"+r.text+"\n```"}:{type:"text",text:r.text};if(r.type==="image"){if(r.data&&r.mimeType)return {type:"image",data:r.data,mimeType:r.mimeType};if(r.source?.type==="base64")return {type:"image",data:r.source.data||"",mimeType:r.source.media_type||""};if(r.source?.type==="url")return {type:"image",data:"",mimeType:"",uri:r.source.url}}return r}function o(r){return r.todos.map(p=>({content:p.content,status:p.status||"pending",priority:"medium"}))}function l(r){let p="```",t=Array.from(r.matchAll(/^```+/gm));for(let[u]of t)for(;u.length>=p.length;)p+="`";return p+`
|
|
7
7
|
`+r+(r.endsWith(`
|
|
8
8
|
`)?"":`
|
|
9
9
|
`)+p}}function se(){return function(r){let p;try{p=JSON.parse(r);}catch{return null}if(p._meta||p._prompt)return null;let t=[];switch(p.type){case "thread.started":case "turn.started":case "turn.completed":return null;case "item.started":{let u=p.item;if(!u)return null;let d=e(u);d&&t.push({update:d});break}case "item.updated":{let u=p.item;if(!u)return null;let d=n(u);d&&t.push({update:d});break}case "item.completed":{let u=p.item;if(!u)return null;let d=s(u);d&&t.push({update:d});break}default:return null}return t.length>0?t:null};function e(l){let r=l.id;switch(l.type){case "mcp_tool_call":return {type:"mcp_tool_call",name:`${l.server}:${l.tool}`},{sessionUpdate:"tool_call",toolCallId:r,title:`${l.server}: ${l.tool}`,kind:"other",status:"in_progress",rawInput:l.arguments,content:[]};case "command_execution":return {type:"command_execution",name:l.command},{sessionUpdate:"tool_call",toolCallId:r,title:l.command?`\`${l.command}\``:"Execute Command",kind:"execute",status:"in_progress",rawInput:{command:l.command},content:[]};case "web_search":return {type:"web_search",name:l.query},{sessionUpdate:"tool_call",toolCallId:r,title:`Search: ${l.query??""}`,kind:"fetch",status:"in_progress",content:[]};case "todo_list":return {sessionUpdate:"plan",entries:o(l.items)};default:return null}}function n(l){return l.type==="todo_list"?{sessionUpdate:"plan",entries:o(l.items)}:null}function s(l){let r=l.id;switch(l.type){case "reasoning":return {sessionUpdate:"agent_thought_chunk",content:{type:"text",text:l.text??l.summary?.join(`
|