@sleep2agi/agent-node 2.1.0-preview.1 → 2.1.0
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 -1
- package/package.json +8 -3
package/dist/cli.js
CHANGED
|
@@ -33,7 +33,7 @@ Runtime:
|
|
|
33
33
|
${z}
|
|
34
34
|
|
|
35
35
|
执行完后简要汇报结果。`,Y={model:P||void 0,tools:x.length?x:void 0,maxTurns:yz,permissionMode:"bypassPermissions",allowDangerouslySkipPermissions:!0,settingSources:[],env:process.env,cwd:process.cwd(),stderr:(X)=>{if(X.trim())v(`[stderr] ${X.trim().slice(0,200)}`)},hooks:{PreToolUse:[{hooks:[async(X)=>{return V(`[tool] ${X.tool_name}(${JSON.stringify(X.tool_input).slice(0,80)})`),{continue:!0}}]}]}};if(t>0)Y.maxBudgetUsd=t;if(d)Y.systemPrompt=d;if(I)Y.resume=I;let W="",K=Date.now();for await(let X of $({prompt:Q,options:Y})){let B=X;if(B.type==="system"&&B.subtype==="init")I=B.session_id,V(`[claude] session=${B.session_id?.slice(0,8)} model=${P||"default"}`),Vz(B.session_id);if(B.type==="result"){let G=Date.now()-K,J=B.usage||{};V(`[claude] ${B.subtype} | ${G}ms | $${B.total_cost_usd?.toFixed(4)||"?"} | in=${J.input_tokens||0} out=${J.output_tokens||0} | turns=${B.num_turns}`),W=B.subtype==="success"?B.result||"任务完成":`执行出错: ${B.error||B.result||"未知错误"}`}}return W}var D=null,hz=d||[`你是 ${F},一个 AI Agent 节点,工作目录:${process.cwd()}。`,"你通过通信网络接收任务。收到任务后执行并返回结果。","规则:","1. 只回复有实质内容的结果。",'2. 绝对不要回复"收到""好的""ok""在线""待命""等待任务"等确认消息。',"3. 没有新任务时保持完全沉默,不要主动发任何消息。","4. 不要调用任何通信工具(send_task/send_message 等)。","5. 你的回复会被系统自动发送给任务发送者。"].join(`
|
|
36
|
-
`),e={model_auto_compact_token_limit:200000,developer_instructions:hz};async function fz(z,Z,$){let{Codex:Q}=await import("@openai/codex-sdk")
|
|
36
|
+
`),e={model_auto_compact_token_limit:200000,developer_instructions:hz};async function fz(z,Z,$){let Q;try{({Codex:Q}=await import("@openai/codex-sdk"))}catch{throw Error("@openai/codex-sdk not installed. Run: npm install -g @openai/codex-sdk @openai/codex")}if(!D){let B=new Q({config:e}),J={skipGitRepoCheck:!0,approvalPolicy:"never",model:P||"gpt-5.4",sandboxMode:"danger-full-access",modelReasoningEffort:"low"};if(R)D=B.resumeThread(R,J),V(`codex resumed thread: ${R}`);else D=B.startThread(J)}V(`[codex] model=${P||"gpt-5.4"} thread=${D?.id||"new"}`);let W=z,K=$?.length?[{type:"text",text:W},...$.map((B)=>({type:"local_image",path:B}))]:W,X=Date.now();try{let{events:B}=await D.runStreamed(K),G="",J=null,H=0;for await(let k of B)if(k.type==="item.started"){let w=k.item;v(`[codex] ${w.type}${w.command?`: ${w.command.slice(0,60)}`:w.tool?`: ${w.server}/${w.tool}`:""}`)}else if(k.type==="item.completed"){H++;let w=k.item;if(w.type==="agent_message")G=w.text||"";if(w.type==="command_execution")v(`[codex] cmd exit=${w.exit_code} | ${w.aggregated_output?.slice(0,80)}`);if(w.type==="reasoning")v(`[codex] thinking: ${w.text?.slice(0,80)}`);if(w.type==="mcp_tool_call")v(`[codex] mcp: ${w.server}/${w.tool} → ${w.status}`)}else if(k.type==="turn.completed")J=k.usage;let p=Date.now()-X,bz=J?.input_tokens||0;if(V(`[codex] done | ${p}ms | in=${bz} out=${J?.output_tokens||0} | items=${H}`),D?.id)Vz(D.id);return G||"(无回复)"}catch(B){V(`codex thread error: ${B.message}, 重建`),D=new Q({config:e}).startThread({skipGitRepoCheck:!0,approvalPolicy:"never",model:P||"gpt-5.4",sandboxMode:"danger-full-access",modelReasoningEffort:"low"});let J=await D.run(K),H=Date.now()-X;return V(`[codex] retry done | ${H}ms`),J.finalResponse||"(无回复)"}}var zz=Promise.resolve();function Gz(z,Z,$){let Q=async()=>{if(y==="codex")return fz(z,Z,$);return Sz(z,Z)},Y=zz.then(Q,Q);return zz=Y.then(()=>{},()=>{}),Y}async function cz(z,Z){V(`→ processing [${y}]: ${z.slice(0,80)}`),await h("working",z.slice(0,200));let $;try{$=await Gz(z,Z)}catch(Q){$=`${y} 错误: ${Q.message}`,C(`✗ ${Q.message}`)}return await h("idle"),$}var m={},pz=5000,dz=new Set(["收到","好的","ok","嗯","是的","了解","明白","确认","done","ack","roger","yes","no","在线","待命","正常","保持在线","通信正常","已收到","收到了","好","行","noted","copy","received","understood","等待任务","等待中","等待指令","无新任务","idle","waiting"]);function jz(z,Z=!1){if(!z)return!0;if(!Z){if(z.replace(/[\s\p{P}\p{S}\p{Emoji}]/gu,"").length<3)return!0}let Q=z.trim().replace(/^[\[【].+?[\]】]\s*/,"").trim().toLowerCase().replace(/[\s。!?.!?✅❌👀⏳,,]+$/g,"").trim();if(dz.has(Q))return!0;if(/^[\p{Emoji}\s]+$/u.test(z.trim())&&!/[0-9a-zA-Z#*]/.test(z))return!0;return!1}function mz(z,Z){if(z===F)return"self";if(Z.startsWith(`[${F}]`))return"own-prefix";let $=Date.now();if(m[z]&&$-m[z]<pz)return"cooldown";if(jz(Z))return"low-value-inbound";return null}async function rz(){let z=await Ez();if(!z.length)return;for(let Z of z){let $=Z.from_session||"hub",Q=Z.content,Y=Z.type||"task";if(V(`← [${$}] (${Y}/${Z.priority||"normal"}) ${Q.slice(0,100)}`),await Iz(Z.id),Y!=="task"&&Y!=="broadcast"){v(`skip non-task message: type=${Y}`);continue}let W=mz($,Q);if(W){v(`skip message from ${$}: ${W}`);continue}let K=await cz(Q,$);if(V(`processTask returned: "${K.slice(0,80)}" (${K.length} chars)`),jz(K,!0)){V(`skip reply: low-value (${K.slice(0,30)})`);continue}try{V(`sending reply to ${$} (task ${Z.id.slice(0,8)})...`),await uz($,`[${F}] ${K.slice(0,2000)}`,Z.id),m[$]=Date.now(),V(`→ [${$}] ${K.slice(0,100)}`)}catch(X){O(`reply failed: ${X.message}`)}}}function Fz(z){return String(z.from?.id||z.chat?.id||"")}function wz(z){return z.from?.username||z.from?.first_name||Fz(z)||"telegram"}function nz(z,Z){if(z.allowFrom.length===0)return!0;let $=Fz(Z),Q=Z.from?.username?String(Z.from.username):"";return z.allowFrom.includes($)||!!Q&&z.allowFrom.includes(Q)}async function f(z,Z,$){let Q=await fetch(`${z.apiBase}/${Z}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify($)}),Y=await Q.json();if(!Y.ok)throw Error(`telegram ${Z} failed: ${Y.description||Q.statusText}`);return Y.result}async function Zz(z,Z,$,Q){let Y=$.match(/[\s\S]{1,4096}/g)||["(无回复)"];for(let W=0;W<Y.length;W++)await f(z,"sendMessage",{chat_id:Z,text:Y[W],...Q&&W===0?{reply_to_message_id:Q}:{}})}async function $z(z,Z,$){let Q=await f(z,"getFile",{file_id:Z}),Y=String(Q.file_path||""),W=await fetch(`${z.fileBase}/${Y}`);if(!W.ok)throw Error(`telegram file download failed: ${W.status} ${W.statusText}`);let K=Y.split(".").pop(),X=($||Y.split("/").pop()||Z).replace(/[^a-zA-Z0-9._-]/g,"_"),B=X.includes(".")||!K?X:`${X}.${K}`,G=b(z.channel.inboxDir,`${Date.now()}_${B}`);return n(G,Buffer.from(await W.arrayBuffer())),G}async function lz(z,Z){let $=Z.text||Z.caption||"",Q=[];if(Array.isArray(Z.photo)&&Z.photo.length>0){let W=Z.photo[Z.photo.length-1],K=await $z(z,W.file_id,`photo_${Z.message_id}.jpg`);Q.push(K)}let Y=String(Z.document?.mime_type||"");if(Z.document&&Y.startsWith("image/")){let W=await $z(z,Z.document.file_id,Z.document.file_name||`image_${Z.message_id}`);Q.push(W)}if(Q.length)$+=`
|
|
37
37
|
|
|
38
38
|
[Telegram 附件已下载]
|
|
39
39
|
${Q.map((W)=>`- 图片: ${W}`).join(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleep2agi/agent-node",
|
|
3
|
-
"version": "2.1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "One-command AI Agent node for CommHub networks. Claude + Codex dual runtime.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"agent-node": "./dist/cli.js"
|
|
@@ -36,7 +36,12 @@
|
|
|
36
36
|
"node": ">=18.0.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@anthropic-ai/claude-agent-sdk": "^0.2.96"
|
|
40
|
-
|
|
39
|
+
"@anthropic-ai/claude-agent-sdk": "^0.2.96"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@openai/codex-sdk": ">=0.118.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"@openai/codex-sdk": { "optional": true }
|
|
41
46
|
}
|
|
42
47
|
}
|