@sleep2agi/agent-node 2.1.2-preview.1 → 2.1.2-preview.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.
- package/dist/cli.js +1 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -29,6 +29,7 @@ Runtime:
|
|
|
29
29
|
`),R(`session 写回: ${N} → ${z.slice(0,8)}...`)}catch(Z){_(`writebackSession failed: ${Z.message}`)}}function Oz(z){if(!a(z))return;for(let Z of f(z,"utf-8").split(`
|
|
30
30
|
`)){let $=Z.trim();if(!$||$.startsWith("#"))continue;let Q=$.indexOf("=");if(Q<=0)continue;let Y=$.slice(0,Q).trim(),X=$.slice(Q+1).trim().replace(/^['"]|['"]$/g,"");if(!process.env[Y])process.env[Y]=X}}function Ez(z){return U(process.cwd(),".anet","nodes",H,"channels",z)}function Tz(z){let Z=z.path||Ez("telegram");Oz(U(Z,".env"));let $=process.env.TELEGRAM_BOT_TOKEN||"";if(!$)console.error(`[agent-node] telegram channel needs TELEGRAM_BOT_TOKEN in ${U(Z,".env")}`),process.exit(1);try{bz(U(Z,".env"),384)}catch{}let Q=p(U(Z,"access.json"))||{},Y=U(Z,"inbox");try{Fz(Y,{recursive:!0})}catch{}return{type:"telegram",dir:Z,inboxDir:Y,token:$,allowFrom:Array.isArray(Q.allowFrom)?Q.allowFrom.map(String):[]}}var n=Bz.filter((z)=>z.type==="telegram").map(Tz),$z=Bz.find((z)=>z.type!=="telegram");if($z)console.error(`[agent-node] unsupported channel: ${$z.raw}`),process.exit(1);if(n.length>0&&C!=="codex"&&!T.includes("Read"))T.push("Read");try{Fz(s,{recursive:!0})}catch{}function i(z,Z,$){if(Z<_z)return;let Q=new Date().toTimeString().slice(0,8),Y=z.toUpperCase().padEnd(5),X=`[${Q}] [${Y}] [${H}] ${$}`;console.log(X);try{let W=new Date().toISOString().slice(0,10);Iz(U(s,`${W}.log`),X+`
|
|
31
31
|
`)}catch{}}var V=(z)=>i("info",1,z),R=(z)=>i("debug",0,z),_=(z)=>i("warn",2,z),h=(z)=>i("error",3,z);async function c(z,Z,$=3){let Q={"Content-Type":"application/json",Accept:"application/json, text/event-stream"};if(L)Q.Authorization=`Bearer ${L}`;let Y;for(let X=0;X<=$;X++)try{let W=await fetch(`${d}/mcp`,{method:"POST",headers:Q,body:JSON.stringify({jsonrpc:"2.0",id:Date.now(),method:"tools/call",params:{name:z,arguments:Z}})});if(!W.ok&&X<$){Y=Error(`HTTP ${W.status}`),await new Promise((w)=>setTimeout(w,1000*Math.pow(2,X)));continue}let q=await W.text(),B=q.match(/data: (.+)/),F=B?JSON.parse(B[1]):JSON.parse(q),K=F?.result?.content?.[0]?.text;return K?JSON.parse(K):F}catch(W){if(Y=W,X<$)R(`callCommHub(${z}) attempt ${X+1} failed: ${W.message}, retrying...`),await new Promise((q)=>setTimeout(q,1000*Math.pow(2,X)))}throw Y||Error(`callCommHub(${z}) failed after ${$} retries`)}var r=j.node_id||"",uz=j.node_name||"",u=j.network_id||process.env.ANET_NETWORK_ID||E.network_id||"",wz=r?`sdk-${r}`:`sdk-${H}-${Date.now().toString(36)}`,Sz=()=>c("report_status",{resume_id:wz,alias:H,status:"idle",server:e(),hostname:e(),agent:`agent-node:${C}`,project_dir:process.cwd(),node_id:r||void 0,node_name:uz||void 0,session_id:A||void 0,config_path:N||void 0,channels:S.length?JSON.stringify(S):void 0,model:x||void 0,network_id:u||void 0}),l=(z,Z)=>c("report_status",{resume_id:wz,alias:H,status:z,task:Z,node_id:r||void 0,session_id:m||A||void 0,config_path:N||void 0,channels:S.length?JSON.stringify(S):void 0,network_id:u||void 0}),hz=async()=>(await c("get_inbox",{alias:H,limit:20}))?.messages||[],fz=(z)=>c("ack_inbox",{alias:H,message_id:z}),pz=(z,Z,$,Q=!1)=>c("send_reply",{alias:z,text:Z,from_session:H,in_reply_to:$||void 0,status:Q?"failed":"replied"}),m=A||void 0;async function dz(z,Z){let{existsSync:$}=await import("fs"),Q=!1;try{let G=b.resolve("@anthropic-ai/claude-agent-sdk-linux-x64/claude");if($(G))Q=!0}catch{}if(!Q)try{let{execSync:G}=await import("child_process");G("which claude",{stdio:"pipe"}),Q=!0}catch{}if(!Q&&process.platform==="linux")try{let{execSync:G}=await import("child_process");V("[claude] no Claude binary found — installing @anthropic-ai/claude-agent-sdk-linux-x64 (glibc) ..."),G("npm install --no-save --prefix "+JSON.stringify(__dirname+"/../")+" @anthropic-ai/claude-agent-sdk-linux-x64",{stdio:"pipe",timeout:60000});try{let J=b.resolve("@anthropic-ai/claude-agent-sdk-linux-x64/claude");if($(J))Q=!0,V(`[claude] glibc binary installed: ${J}`)}catch{}}catch(G){V(`[claude] auto-install of glibc binary failed: ${G?.message||G}`)}if(!Q)return["claude 错误: Claude Code 二进制未找到。","agent-node 默认运行 claude-agent-sdk runtime 需要 Claude Code 本地二进制。","解决方案:"," 1. 全局安装 Claude Code: npm i -g @anthropic-ai/claude-code"," 2. 或者切换到 codex-sdk runtime: anet node create <name> --runtime codex-sdk (需 codex auth login)"," 3. 或者在 node config.json 里设 pathToClaudeCodeExecutable 指向已安装的 claude 二进制"].join(`
|
|
32
|
+
`);if(typeof process.getuid==="function"&&process.getuid()===0)return["claude 错误: 当前以 root 用户运行,Claude Code 拒绝 --dangerously-skip-permissions。","解决方案 (推荐 1):"," 1. 建非 root 用户后再启动:"," useradd -m anet-agent"," su - anet-agent"," anet login --hub <URL> --username <user> --password <pass>"," anet node start <name>"," 2. 或切换 runtime 为 codex-sdk (root 下可运行,需 codex auth login):"," anet node delete <name> && anet node create <name> --runtime codex-sdk"].join(`
|
|
32
33
|
`);let{query:Y}=await import("@anthropic-ai/claude-agent-sdk"),X=[`你是 ${H},一个 AI Agent 节点。收到来自 ${Z} 的任务:`,"",z,"","【若任务需要其他 agent 协助】","1. 先用 mcp_commhub__get_all_status 看哪些 agent 在线。","2. 用 mcp_commhub__send_task(alias, task) 派给合适的 agent,记下 task_id。","3. 用 mcp_commhub__get_task(task_id) 轮询直到 status 是 replied 或 failed,拿到 reply 内容。",`4. 把对方的 reply 整合到你给 ${Z} 的最终汇报里。`,"","【禁止】",`- 不要给自己(${H})发任务(死循环)。`,'- 不要回复"收到""ok""明白了"等无内容确认。',"- 不要在无新任务时主动调用通信工具。","","执行完后简要汇报结果。"].join(`
|
|
33
34
|
`),W=O?`${O}
|
|
34
35
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleep2agi/agent-node",
|
|
3
|
-
"version": "2.1.2-preview.
|
|
3
|
+
"version": "2.1.2-preview.2",
|
|
4
4
|
"description": "AI Agent runtime for CommHub networks. Supports Claude Agent SDK, Codex SDK, and OpenAI/Anthropic-compatible HTTP API.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"agent-node": "./dist/cli.js"
|