@sleep2agi/agent-node 2.1.0 → 2.1.2-preview.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.
Files changed (3) hide show
  1. package/README.md +101 -200
  2. package/dist/cli.js +18 -16
  3. package/package.json +11 -6
package/README.md CHANGED
@@ -1,247 +1,148 @@
1
- # 🤖 @sleep2agi/agent-node
1
+ # @sleep2agi/agent-node
2
2
 
3
- 一行命令启动 AI Agent,加入 CommHub 通信网络。
3
+ Agent runtime for Agent Network. Connects to a CommHub server, registers under an alias, and processes incoming tasks with one of three runtimes.
4
4
 
5
- 基于 [Claude Agent SDK](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk) + [Codex SDK](https://www.npmjs.com/package/@openai/codex-sdk) 双引擎实现。
5
+ **v2.1.1 stable.** The supported entry point is the `anet` CLI from `@sleep2agi/agent-network@2.0.0`, which writes the right `config.json` and environment variables for you.
6
6
 
7
- ```bash
8
- npx @sleep2agi/agent-node --alias "我的Agent" --hub http://YOUR_HUB:9200 --tools all
9
- ```
10
-
11
- ---
7
+ ## Install
12
8
 
13
- ## 🏗️ 技术实现
9
+ You usually don't install this package directly — `anet node create` and `anet node start` use it via `npx`. To pin it:
14
10
 
15
- ### 双引擎架构
11
+ ```bash
12
+ npm install -g @sleep2agi/agent-node
13
+ ```
16
14
 
17
- agent-node 内部根据 `--runtime` 参数选择不同的 AI 引擎:
15
+ ## Verified flow
18
16
 
19
- ```
20
- agent-node
21
- ├── runtime: claude ──→ @anthropic-ai/claude-agent-sdk
22
- │ └── query() spawn claude CLI → AI 处理 + 工具调用
23
-
24
- └── runtime: codex ───→ @openai/codex-sdk
25
- └── exec() spawn codex CLI AI 处理 + 工具调用
17
+ ```bash
18
+ npm install -g @sleep2agi/agent-network
19
+ anet hub start # local hub (terminal 1)
20
+ anet hub dashboard # web UI (terminal 2)
21
+ anet login --username admin --password anethub
22
+ anet node create my-bot # two-step picker: runtime, then provider
23
+ anet node start my-bot #SSE connected
26
24
  ```
27
25
 
28
- ### Claude Agent SDK(`--runtime claude`,默认)
29
-
30
- 基于 Anthropic 的 [Claude Agent SDK](https://github.com/anthropics/claude-agent-sdk-typescript),底层 spawn `claude` CLI 进程。
31
-
32
- **核心调用**:
33
- ```typescript
34
- import { query } from "@anthropic-ai/claude-agent-sdk";
35
-
36
- for await (const message of query({
37
- prompt: "任务内容",
38
- options: {
39
- model: "MiniMax-M2.7", // 支持任意 Anthropic API 兼容模型
40
- tools: ["Read", "Bash", "Grep"],
41
- maxTurns: 5,
42
- permissionMode: "bypassPermissions",
43
- settingSources: [], // 隔离全局配置,防止串网
44
- }
45
- })) {
46
- if (message.type === "result") console.log(message.result);
47
- }
48
- ```
26
+ The picker writes `.anet/nodes/<name>/config.json`. `anet node start` reads it and runs this package under the hood.
49
27
 
50
- **MiniMax / 书生模型怎么跑在 Claude SDK 上?**
28
+ ## Direct invocation
51
29
 
52
- Claude Agent SDK 底层走 Anthropic API。通过设置环境变量将请求重定向到兼容端点,零代码修改:
30
+ For scripts and CI:
53
31
 
54
32
  ```bash
55
- # MiniMax M2.7
56
- ANTHROPIC_BASE_URL=https://api.minimax.io/anthropic
57
- ANTHROPIC_AUTH_TOKEN=your-minimax-key
58
-
59
- # 书生 Intern-S1-Pro
60
- ANTHROPIC_BASE_URL=https://chat.intern-ai.org.cn
61
- ANTHROPIC_AUTH_TOKEN=your-intern-key
33
+ npx @sleep2agi/agent-node --alias my-bot --hub http://127.0.0.1:9200 --tools all
62
34
  ```
63
35
 
64
- SDK 不校验模型名,`--model MiniMax-M2.7` 原样传给 API。
65
-
66
- **已验证功能**:
67
- - ✅ 单轮/多轮对话
68
- - ✅ tool_use(Read/Write/Edit/Bash/Glob/Grep/WebSearch/WebFetch)
69
- - ✅ Extended Thinking(`<think>` 标签)
70
- - ✅ Session Resume(跨 query 保持上下文)
71
- - ✅ SSE streaming
72
- - ✅ Hooks(PreToolUse/PostToolUse)
73
- - ✅ maxBudgetUsd 预算控制
74
- - ✅ settingSources 隔离(防止读全局 MCP 配置串网)
75
-
76
- ### Codex SDK(`--runtime codex`)
36
+ CLI flags:
77
37
 
78
- 基于 OpenAI [Codex SDK](https://www.npmjs.com/package/@openai/codex-sdk),复用 Codex CLI 登录态。
38
+ | Flag | Default | Notes |
39
+ |---|---|---|
40
+ | `--alias` | required | unique name in the hub |
41
+ | `--hub` | `http://127.0.0.1:9200` | CommHub URL |
42
+ | `--runtime` | `claude-agent-sdk` | `claude-agent-sdk` / `codex-sdk` / `claude-code-cli` |
43
+ | `--model` | runtime default | passed through to the SDK |
44
+ | `--tools` | (none) | `all` or comma-separated list |
45
+ | `--max-turns` | `50` | upper bound per task |
46
+ | `--session` | (none) | resume a prior session / thread |
79
47
 
80
- **核心调用**:
81
- ```typescript
82
- import Codex from "@openai/codex-sdk";
48
+ ## Runtimes
83
49
 
84
- const client = new Codex();
85
- const thread = await client.threads.create();
50
+ | Runtime | Backend | Status | Notes |
51
+ |---|---|---|---|
52
+ | `claude-agent-sdk` | [@anthropic-ai/claude-agent-sdk](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk) | verified | Anthropic Messages API; works with any compatible endpoint |
53
+ | `codex-sdk` | [@openai/codex-sdk](https://www.npmjs.com/package/@openai/codex-sdk) | unverified end-to-end | unit tests pass, no full E2E with real codex auth |
54
+ | `claude-code-cli` | local `claude` CLI | unverified end-to-end | runs locally for Claude Pro subscribers |
86
55
 
87
- const response = await client.responses.create({
88
- model: "gpt-5.4",
89
- thread_id: thread.id,
90
- input: "任务内容",
91
- tools: [{ type: "code_interpreter" }, { type: "file_search" }],
92
- });
56
+ Runtimes are loaded lazily — picking one doesn't pull the others' dependencies. `claude-code-cli` adds zero extra SDK weight.
93
57
 
94
- console.log(response.output_text);
95
- ```
58
+ ## Provider presets (claude-agent-sdk)
96
59
 
97
- **特点**:
98
- - 不需要额外 API key(复用 `codex` CLI 登录态)
99
- - 支持 gpt-5.4(默认)/ o3 / o4-mini
100
- - Thread 保持上下文(多轮对话)
101
- - Thread 过期自动重建
60
+ `anet node create` step 2 picks one of these and writes `ANTHROPIC_BASE_URL` + a default model. All Anthropic-compatible HTTP API; `--model` is passed through verbatim.
102
61
 
103
- ---
62
+ | Provider | Base URL | Default model | Status |
63
+ |---|---|---|---|
64
+ | Anthropic | `https://api.anthropic.com` | `claude-sonnet-4-5` | verified |
65
+ | MiniMax (国际) | `https://api.minimax.io/anthropic` | `MiniMax-M2.7` | verified |
66
+ | MiniMax (国内) | `https://api.minimaxi.com/anthropic` | `MiniMax-M2.7` | verified |
67
+ | DeepSeek | `https://api.deepseek.com/anthropic` | `deepseek-chat` | verified |
68
+ | GLM (智谱) | `https://open.bigmodel.cn/api/anthropic` | `glm-4-plus` | verified |
69
+ | Kimi (Moonshot) | `https://api.moonshot.cn/anthropic` | `moonshot-v1-32k` | verified |
70
+ | OpenRouter | `https://openrouter.ai/api/v1` | (user-chosen) | unverified end-to-end |
71
+ | Custom | user-supplied | user-supplied | unverified end-to-end |
104
72
 
105
- ## 🔄 Agent 主循环
73
+ ## Manual env-var examples
106
74
 
107
- 无论哪种 runtime,agent-node 的主循环都一样:
75
+ ```bash
76
+ # DeepSeek
77
+ ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic \
78
+ ANTHROPIC_AUTH_TOKEN=sk-... \
79
+ npx @sleep2agi/agent-node --alias deep --hub http://127.0.0.1:9200 --tools all
108
80
 
109
- ```
110
- 启动
111
-
112
- 注册到 CommHub(report_status: idle)
113
-
114
- SSE 长连接 /events/:alias
115
-
116
- ┌─→ 收到 new_task 事件
117
- │ ↓
118
- │ get_inbox → 拿任务内容
119
- │ ↓
120
- │ ack_inbox → 确认收到
121
- │ ↓
122
- │ report_status: working
123
- │ ↓
124
- │ AI 处理(claude query() 或 codex exec())
125
- │ ↓
126
- │ send_task → 回报结果给发送者
127
- │ ↓
128
- │ report_status: idle
129
- │ ↓
130
- └─── 等待下一个任务
131
- ↓ (每 3 分钟)
132
- heartbeat → report_status: idle
81
+ # MiniMax
82
+ ANTHROPIC_BASE_URL=https://api.minimax.io/anthropic \
83
+ ANTHROPIC_AUTH_TOKEN=your-key \
84
+ npx @sleep2agi/agent-node --alias mini --model MiniMax-M2.7 --hub http://127.0.0.1:9200 --tools all
133
85
  ```
134
86
 
135
- **CommHub 通信层**(agent-node 自己的代码,不经过 AI 子进程):
136
-
137
- ```typescript
138
- // 直接 HTTP POST 到 CommHub MCP 端点
139
- async function callCommHub(method: string, params: object) {
140
- const res = await fetch(`${HUB_URL}/mcp`, {
141
- method: "POST",
142
- headers: { "Content-Type": "application/json", "Accept": "application/json, text/event-stream" },
143
- body: JSON.stringify({
144
- jsonrpc: "2.0",
145
- method: "tools/call",
146
- params: { name: method, arguments: params },
147
- }),
148
- });
149
- // ...
87
+ ## Configuration file
88
+
89
+ Typical output of `anet node create` at `.anet/nodes/<name>/config.json`:
90
+
91
+ ```json
92
+ {
93
+ "alias": "my-bot",
94
+ "hub": "http://127.0.0.1:9200",
95
+ "runtime": "claude-agent-sdk",
96
+ "model": "MiniMax-M2.7",
97
+ "anthropic_base_url": "https://api.minimax.io/anthropic",
98
+ "anthropic_auth_token": "sk-...",
99
+ "tools": "all",
100
+ "maxTurns": 50,
101
+ "dangerouslySkipPermissions": true,
102
+ "teammateMode": true
150
103
  }
151
104
  ```
152
105
 
153
- ---
106
+ Per-node config wins over `~/.anet/config.json`; missing fields fall back to global, then defaults.
154
107
 
155
- ## 🛡️ 隔离策略
108
+ ## Main loop
156
109
 
157
- `settingSources: []` 阻止 claude 子进程读全局 `~/.claude.json`:
110
+ Same shape across runtimes:
158
111
 
159
112
  ```
160
- ❌ 没有隔离时:
161
- agent-node query() → spawn claude
162
- claude ~/.claude.json → 加载全局 commhub MCP
163
- AI send_task消息发到主网络(串网!)
164
-
165
- 有隔离时:
166
- agent-node query({ settingSources: [] }) → spawn claude
167
- claude 不读任何全局配置
168
- → AI 只能用 agent-node 显式传的工具
113
+ start
114
+ report_status: idle
115
+ SSE long-poll /events/:alias
116
+ on new_task: get_inboxack_inbox
117
+ → report_status: working
118
+ run the LLM (with commhub MCP tools injected)
119
+ send_reply
120
+ report_status: idle
169
121
  ```
170
122
 
171
- ---
172
-
173
- ## 📊 模型对照表
174
-
175
- | 模型 | runtime | 环境变量 | 默认 |
176
- |------|---------|---------|------|
177
- | MiniMax M2.7(国际) | claude | `ANTHROPIC_BASE_URL=https://api.minimax.io/anthropic` | |
178
- | MiniMax M2.7(国内) | claude | `ANTHROPIC_BASE_URL=https://api.minimaxi.com/anthropic` | |
179
- | 书生 Intern-S1-Pro | claude | `ANTHROPIC_BASE_URL=https://chat.intern-ai.org.cn` | |
180
- | Claude Sonnet 4.6 | claude | `ANTHROPIC_API_KEY=key` | ✅ |
181
- | GPT-5.4 | codex | 不需要(复用 codex 登录) | ✅ |
182
- | o3 | codex | 不需要 | |
183
- | o4-mini | codex | 不需要 | |
184
-
185
- ---
186
-
187
- ## 🚀 快速启动
188
-
189
- ```bash
190
- # MiniMax(低成本)
191
- ANTHROPIC_BASE_URL=https://api.minimax.io/anthropic \
192
- ANTHROPIC_AUTH_TOKEN=your-key \
193
- npx @sleep2agi/agent-node --alias 小明 --model MiniMax-M2.7 --hub http://IP:9200 --tools all
194
-
195
- # 书生(国产)
196
- ANTHROPIC_BASE_URL=https://chat.intern-ai.org.cn \
197
- ANTHROPIC_AUTH_TOKEN=your-key \
198
- npx @sleep2agi/agent-node --alias 书生 --model intern-s1-pro --hub http://IP:9200 --tools all
199
-
200
- # Codex GPT-5.4(OpenAI)
201
- npx @sleep2agi/agent-node --alias Codex马 --runtime codex --hub http://IP:9200 --tools all
202
-
203
- # Claude
204
- ANTHROPIC_API_KEY=your-key \
205
- npx @sleep2agi/agent-node --alias Claude马 --hub http://IP:9200 --tools all
206
- ```
207
-
208
- ---
209
-
210
- ## ⚙️ CLI 参数
211
-
212
- | 参数 | 默认值 | 说明 |
213
- |------|--------|------|
214
- | `--alias` | 必填 | Agent 名称 |
215
- | `--hub` | `http://127.0.0.1:9200` | CommHub URL |
216
- | `--runtime` | `claude` | `claude` 或 `codex` |
217
- | `--model` | claude: `claude-sonnet-4-6` / codex: `gpt-5.4` | 模型名 |
218
- | `--tools` | 无 | `all` 或逗号分隔 |
219
- | `--max-turns` | `5` | 每任务最大轮次 |
220
- | `--max-budget` | 无 | 每任务预算(美元) |
221
- | `--session` | 无 | 恢复指定 session/thread |
222
- | `--prompt` | 无 | 自定义 system prompt |
123
+ ## Peer coordination (verified)
223
124
 
224
- ---
125
+ When the agent runs, the commhub MCP tools are auto-injected. The model can call:
225
126
 
226
- ## 📦 依赖
127
+ - `commhub_get_all_status()` — see who else is online
128
+ - `commhub_send_task(alias, task)` — dispatch a sub-task to a peer
129
+ - `commhub_get_task(task_id)` — poll for the peer's reply
130
+ - `commhub_send_message(alias, message)` — chat without a task lifecycle
131
+ - `commhub_report_status(status, task)` — push status update
227
132
 
228
- | | 什么时候需要 |
229
- |---|------------|
230
- | `@anthropic-ai/claude-agent-sdk` | `--runtime claude` 时(动态 import) |
231
- | `@openai/codex-sdk` | `--runtime codex` 时(动态 import) |
133
+ This is what powers the multi-agent flow demonstrated in `anet hub dashboard` (e.g. ask one bot to consult another — the Tasks and Messages pages show the full handshake live).
232
134
 
233
- 未使用的 runtime 不会加载依赖。
135
+ ## Isolation
234
136
 
235
- ---
137
+ When the runtime is `claude-code-cli`, the spawned subprocess gets `settingSources: []` so it doesn't read the host's `~/.claude.json` and accidentally cross networks.
236
138
 
237
- ## 🔗 相关
139
+ ## Companion packages
238
140
 
239
- | | |
141
+ | Package | Version |
240
142
  |---|---|
241
- | **npm** | [@sleep2agi/agent-node](https://www.npmjs.com/package/@sleep2agi/agent-node) |
242
- | **CLI 管理工具** | [@sleep2agi/agent-network](https://www.npmjs.com/package/@sleep2agi/agent-network) |
243
- | **通信服务器** | [@sleep2agi/commhub-server](https://www.npmjs.com/package/@sleep2agi/commhub-server) |
244
- | **Dashboard** | [agent-network-dashboard.vercel.app](https://agent-network-dashboard.vercel.app) |
143
+ | [@sleep2agi/agent-network](https://www.npmjs.com/package/@sleep2agi/agent-network) | 2.0.0 |
144
+ | [@sleep2agi/commhub-server](https://www.npmjs.com/package/@sleep2agi/commhub-server) | 0.5.0 |
145
+ | [@sleep2agi/agent-network-dashboard](https://www.npmjs.com/package/@sleep2agi/agent-network-dashboard) | 0.1.0 |
245
146
 
246
147
  ## License
247
148
 
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as Uz}from"node:module";var i=Uz(import.meta.url);import{readFileSync as L,existsSync as r,writeFileSync as n,chmodSync as vz}from"fs";import{join as b}from"path";import{hostname as a,homedir as Dz}from"os";import{mkdirSync as qz,appendFileSync as Lz}from"fs";var Qz=Dz(),U=process.argv.slice(2),j={},Yz=[],Wz="2.1.0";try{let z=new URL(".",import.meta.url).pathname;for(let Z of["../package.json","../../package.json"])try{let $=JSON.parse(L(b(z,Z),"utf-8"));if($.version){Wz=$.version;break}}catch{}}catch{}for(let z=0;z<U.length;z++){if(U[z]==="--version"||U[z]==="-v")console.log(`agent-node v${Wz}`),process.exit(0);if(U[z]==="-h"||U[z]==="--help")console.log(`
2
+ import{createRequire as Rz}from"node:module";var P=Rz(import.meta.url);import{readFileSync as f,existsSync as a,writeFileSync as t,chmodSync as Pz}from"fs";import{join as M}from"path";import{hostname as zz,homedir as xz}from"os";import{mkdirSync as wz,appendFileSync as Sz}from"fs";var qz=xz(),b=process.argv.slice(2),H={},Wz=[],Gz="2.1.0";try{let z=new URL(".",import.meta.url).pathname;for(let Z of["../package.json","../../package.json"])try{let $=JSON.parse(f(M(z,Z),"utf-8"));if($.version){Gz=$.version;break}}catch{}}catch{}for(let z=0;z<b.length;z++){if(b[z]==="--version"||b[z]==="-v")console.log(`agent-node v${Gz}`),process.exit(0);if(b[z]==="-h"||b[z]==="--help")console.log(`
3
3
  @sleep2agi/agent-node — AI Agent 节点,一行命令加入 CommHub 网络
4
4
 
5
5
  用法:
@@ -8,11 +8,11 @@ import{createRequire as Uz}from"node:module";var i=Uz(import.meta.url);import{re
8
8
  选项:
9
9
  --config <path> 配置文件 (.anet/nodes/<name>/config.json)
10
10
  --alias <name> Agent 别名 / CommHub alias (必需)
11
- --runtime <type> claude-agent-sdk (default) | codex-sdk
12
- --model <name> AI 模型 (claude-agent-sdk: claude-sonnet-4-6, codex-sdk: gpt-5.4)
11
+ --runtime <type> claude-agent-sdk (default) | codex-sdk | http-api | minimax
12
+ --model <name> AI 模型 (codex: gpt-5.4, http-api: gpt-4o-mini, minimax: MiniMax-M1)
13
13
  --hub <url> CommHub URL
14
14
  --tools <list> 工具列表,逗号分隔 ("all" = 全部)
15
- --max-turns <n> 每任务最大轮次 (default: 5)
15
+ --max-turns <n> 每任务最大轮次 (default: 50)
16
16
  --max-budget <usd> 每任务预算上限
17
17
  --session <id> 恢复 session / thread ID
18
18
  --channel <spec> Channel (telegram 或 telegram:/path)
@@ -24,19 +24,21 @@ import{createRequire as Uz}from"node:module";var i=Uz(import.meta.url);import{re
24
24
  Runtime:
25
25
  claude-agent-sdk Claude Agent SDK — Claude/MiniMax/Anthropic 兼容 API
26
26
  codex-sdk Codex SDK — GPT-5.4,复用 codex 登录态
27
- `),process.exit(0);if(U[z]==="--new-session"){j["new-session"]="true";continue}if(U[z]==="--channel"&&z+1<U.length){Yz.push(U[++z]);continue}if(U[z].startsWith("--")&&z+1<U.length)j[U[z].slice(2)]=U[++z]}function Xz(z){return z.replace(/^~(?=\/|$)/,Qz)}function Mz(z){let Z=z.indexOf(":");if(Z<0)return{type:z,raw:z};if(Z===0||Z===z.length-1)throw Error(`invalid channel spec "${z}" (expected type or type:path)`);return{type:z.slice(0,Z),path:Xz(z.slice(Z+1)),raw:z}}function T(z){if(!r(z))return null;try{return JSON.parse(L(z,"utf-8"))}catch{return null}}var q={},M="";if(j.config){let z=j.config.startsWith("/")?j.config:b(process.cwd(),j.config),Z=T(z);if(Z)q=Z,M=z,console.log(`[agent-node] Config: ${z}`)}var F=j.alias||process.env.COMMHUB_ALIAS||process.env.ALIAS||q.alias;if(!j.config&&F){let z=b(process.cwd(),".anet","nodes",F,"config.json"),Z=b(process.cwd(),".anet","profiles",`${F}.json`),$=r(z)?z:Z,Q=T($);if(Q){if(q={...Q,...q},M=$,console.log(`[agent-node] Config: ${$}`),Q.env&&typeof Q.env==="object"){for(let[Y,W]of Object.entries(Q.env))if(!process.env[Y]&&typeof W==="string")process.env[Y]=Xz(W)}}}var _=T(b(Qz,".anet","config.json"))||{};if(_.hub&&!q.hub)q.hub=_.hub;if(_.token&&!q.token)q.token=_.token;if(!j.config&&!Object.keys(q).length){let z=T(b(process.cwd(),".agent-node.json"));if(z)q=z,console.log("[agent-node] 配置: .agent-node.json")}if(!F)console.error(`错误: 必须指定 --alias
28
- 用法: npx @sleep2agi/agent-node --alias "我的Agent"`),process.exit(1);var Bz=j.runtime||process.env.RUNTIME||q.runtime||"claude-agent-sdk",Pz={"claude-agent-sdk":"claude","claude-sdk":"claude","agent-sdk":"claude",claude:"claude","codex-sdk":"codex",codex:"codex"},y=Pz[Bz]||"claude",Rz=Bz,l=j.url||j.hub||process.env.COMMHUB_URL||q.hub||"http://127.0.0.1:9200",P=j.model||process.env.MODEL||q.model,kz=["Read","Write","Edit","Bash","Glob","Grep","WebSearch","WebFetch"],o=j.tools||(Array.isArray(q.tools)?q.tools.join(","):q.tools)||"",x=o==="all"?kz:o.split(",").filter(Boolean),yz=parseInt(j["max-turns"]||q.flags?.maxTurns||q.maxTurns||"5"),t=parseFloat(j["max-budget"]||q.flags?.maxBudgetUsd||q.maxBudgetUsd||"0"),xz=j["new-session"]==="true",R=xz?"":j.session||q.session||q.resume||q.sessionId||"",d=j.prompt||q.systemPrompt||"",N=process.env.COMMHUB_TOKEN||q.token||_.token||"",g=j["log-dir"]||b(process.cwd(),".anet","nodes",F,"logs"),_z={debug:0,info:1,warn:2,error:3},Nz=_z[j["log-level"]||process.env.LOG_LEVEL||q.logLevel||"info"]??1,A=[...(Array.isArray(q.channels)?q.channels:[]).filter((z)=>!z.startsWith("server:")&&!z.startsWith("plugin:")),...Yz],Kz=A.map((z)=>{try{return Mz(z)}catch(Z){console.error(`[agent-node] ${Z.message}`),process.exit(1)}});function Vz(z){if(!M||!z)return;try{let Z=JSON.parse(L(M,"utf-8"));if(Z.session===z)return;Z.session=z,n(M,JSON.stringify(Z,null,2)+`
29
- `),v(`session 写回: ${M} → ${z.slice(0,8)}...`)}catch(Z){O(`writebackSession failed: ${Z.message}`)}}function Az(z){if(!r(z))return;for(let Z of L(z,"utf-8").split(`
30
- `)){let $=Z.trim();if(!$||$.startsWith("#"))continue;let Q=$.indexOf("=");if(Q<=0)continue;let Y=$.slice(0,Q).trim(),W=$.slice(Q+1).trim().replace(/^['"]|['"]$/g,"");if(!process.env[Y])process.env[Y]=W}}function Oz(z){return b(process.cwd(),".anet","nodes",F,"channels",z)}function Cz(z){let Z=z.path||Oz("telegram");Az(b(Z,".env"));let $=process.env.TELEGRAM_BOT_TOKEN||"";if(!$)console.error(`[agent-node] telegram channel needs TELEGRAM_BOT_TOKEN in ${b(Z,".env")}`),process.exit(1);try{vz(b(Z,".env"),384)}catch{}let Q=T(b(Z,"access.json"))||{},Y=b(Z,"inbox");try{qz(Y,{recursive:!0})}catch{}return{type:"telegram",dir:Z,inboxDir:Y,token:$,allowFrom:Array.isArray(Q.allowFrom)?Q.allowFrom.map(String):[]}}var u=Kz.filter((z)=>z.type==="telegram").map(Cz),s=Kz.find((z)=>z.type!=="telegram");if(s)console.error(`[agent-node] unsupported channel: ${s.raw}`),process.exit(1);if(u.length>0&&y!=="codex"&&!x.includes("Read"))x.push("Read");try{qz(g,{recursive:!0})}catch{}function c(z,Z,$){if(Z<Nz)return;let Q=new Date().toTimeString().slice(0,8),Y=z.toUpperCase().padEnd(5),W=`[${Q}] [${Y}] [${F}] ${$}`;console.log(W);try{let K=new Date().toISOString().slice(0,10);Lz(b(g,`${K}.log`),W+`
31
- `)}catch{}}var V=(z)=>c("info",1,z),v=(z)=>c("debug",0,z),O=(z)=>c("warn",2,z),C=(z)=>c("error",3,z);async function E(z,Z,$=3){let Q={"Content-Type":"application/json",Accept:"application/json, text/event-stream"};if(N)Q.Authorization=`Bearer ${N}`;let Y;for(let W=0;W<=$;W++)try{let K=await fetch(`${l}/mcp`,{method:"POST",headers:Q,body:JSON.stringify({jsonrpc:"2.0",id:Date.now(),method:"tools/call",params:{name:z,arguments:Z}})});if(!K.ok&&W<$){Y=Error(`HTTP ${K.status}`),await new Promise((H)=>setTimeout(H,1000*Math.pow(2,W)));continue}let X=await K.text(),B=X.match(/data: (.+)/),G=B?JSON.parse(B[1]):JSON.parse(X),J=G?.result?.content?.[0]?.text;return J?JSON.parse(J):G}catch(K){if(Y=K,W<$)v(`callCommHub(${z}) attempt ${W+1} failed: ${K.message}, retrying...`),await new Promise((X)=>setTimeout(X,1000*Math.pow(2,W)))}throw Y||Error(`callCommHub(${z}) failed after ${$} retries`)}var S=q.node_id||"",Jz=S?`sdk-${S}`:`sdk-${F}-${Date.now().toString(36)}`,Tz=()=>E("report_status",{resume_id:Jz,alias:F,status:"idle",server:a(),hostname:a(),agent:`agent-node:${y}`,project_dir:process.cwd(),node_id:S||void 0,session_id:R||void 0,config_path:M||void 0,channels:A.length?JSON.stringify(A):void 0}),h=(z,Z)=>E("report_status",{resume_id:Jz,alias:F,status:z,task:Z,node_id:S||void 0,session_id:I||R||void 0,config_path:M||void 0,channels:A.length?JSON.stringify(A):void 0}),Ez=async()=>(await E("get_inbox",{alias:F,limit:20}))?.messages||[],Iz=(z)=>E("ack_inbox",{alias:F,message_id:z}),uz=(z,Z,$)=>E("send_reply",{alias:z,text:Z,from_session:F,in_reply_to:$||void 0,status:"replied"}),I=R||void 0;async function Sz(z,Z){let{query:$}=await import("@anthropic-ai/claude-agent-sdk"),Q=`你是 ${F},收到来自 ${Z} 的任务:
27
+ `),process.exit(0);if(b[z]==="--new-session"){H["new-session"]="true";continue}if(b[z]==="--channel"&&z+1<b.length){Wz.push(b[++z]);continue}if(b[z].startsWith("--")&&z+1<b.length)H[b[z].slice(2)]=b[++z]}function jz(z){return z.replace(/^~(?=\/|$)/,qz)}function yz(z){let Z=z.indexOf(":");if(Z<0)return{type:z,raw:z};if(Z===0||Z===z.length-1)throw Error(`invalid channel spec "${z}" (expected type or type:path)`);return{type:z.slice(0,Z),path:jz(z.slice(Z+1)),raw:z}}function p(z){if(!a(z))return null;try{return JSON.parse(f(z,"utf-8"))}catch{return null}}var G={},N="";if(H.config){let z=H.config.startsWith("/")?H.config:M(process.cwd(),H.config),Z=p(z);if(Z)G=Z,N=z,console.log(`[agent-node] Config: ${z}`)}var w=H.alias||process.env.COMMHUB_ALIAS||process.env.ALIAS||G.alias;if(!H.config&&w){let z=M(process.cwd(),".anet","nodes",w,"config.json"),Z=M(process.cwd(),".anet","profiles",`${w}.json`),$=a(z)?z:Z,Q=p($);if(Q){if(G={...Q,...G},N=$,console.log(`[agent-node] Config: ${$}`),Q.env&&typeof Q.env==="object"){for(let[Y,X]of Object.entries(Q.env))if(!process.env[Y]&&typeof X==="string")process.env[Y]=jz(X)}}}var T=p(M(qz,".anet","config.json"))||{};if(T.hub&&!G.hub)G.hub=T.hub;if(T.token&&!G.token)G.token=T.token;if(!H.config&&!Object.keys(G).length){let z=p(M(process.cwd(),".agent-node.json"));if(z)G=z,console.log("[agent-node] 配置: .agent-node.json")}if(!w)console.error(`错误: 必须指定 --alias
28
+ 用法: npx @sleep2agi/agent-node --alias "我的Agent"`),process.exit(1);var Bz=H.runtime||process.env.RUNTIME||G.runtime||"claude-agent-sdk",Nz={"claude-agent-sdk":"claude","claude-sdk":"claude","agent-sdk":"claude",claude:"claude","codex-sdk":"codex",codex:"codex","http-api":"http","openai-api":"http",minimax:"http"},A=Nz[Bz]||"claude",Lz=Bz,d=H.url||H.hub||process.env.COMMHUB_URL||G.hub||"http://127.0.0.1:9200",y=H.model||process.env.MODEL||G.model,_z=["Read","Write","Edit","Bash","Glob","Grep","WebSearch","WebFetch"],Zz=H.tools||(Array.isArray(G.tools)?G.tools.join(","):G.tools)||"",I=Zz==="all"?_z:Zz.split(",").filter(Boolean),Az=parseInt(H["max-turns"]||G.flags?.maxTurns||G.maxTurns||"50"),$z=parseFloat(H["max-budget"]||G.flags?.maxBudgetUsd||G.maxBudgetUsd||"0"),Cz=H["new-session"]==="true",_=Cz?"":H.session||G.session||G.resume||G.sessionId||"",E=H.prompt||G.systemPrompt||"",L=G.token||T.token||process.env.COMMHUB_TOKEN||"";if(process.env.COMMHUB_TOKEN&&G.token&&process.env.COMMHUB_TOKEN!==G.token)console.warn(`[${w}] ⚠ COMMHUB_TOKEN env override ignored (using node config token). Unset COMMHUB_TOKEN to silence this warning.`);var s=H["log-dir"]||M(process.cwd(),".anet","nodes",w,"logs"),Oz={debug:0,info:1,warn:2,error:3},Ez=Oz[H["log-level"]||process.env.LOG_LEVEL||G.logLevel||"info"]??1,S=[...(Array.isArray(G.channels)?G.channels:[]).filter((z)=>!z.startsWith("server:")&&!z.startsWith("plugin:")),...Wz],Kz=S.map((z)=>{try{return yz(z)}catch(Z){console.error(`[agent-node] ${Z.message}`),process.exit(1)}});function Fz(z){if(!N||!z)return;try{let Z=JSON.parse(f(N,"utf-8"));if(Z.session===z)return;Z.session=z,t(N,JSON.stringify(Z,null,2)+`
29
+ `),R(`session 写回: ${N} → ${z.slice(0,8)}...`)}catch(Z){C(`writebackSession failed: ${Z.message}`)}}function Tz(z){if(!a(z))return;for(let Z of f(z,"utf-8").split(`
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 Iz(z){return M(process.cwd(),".anet","nodes",w,"channels",z)}function uz(z){let Z=z.path||Iz("telegram");Tz(M(Z,".env"));let $=process.env.TELEGRAM_BOT_TOKEN||"";if(!$)console.error(`[agent-node] telegram channel needs TELEGRAM_BOT_TOKEN in ${M(Z,".env")}`),process.exit(1);try{Pz(M(Z,".env"),384)}catch{}let Q=p(M(Z,"access.json"))||{},Y=M(Z,"inbox");try{wz(Y,{recursive:!0})}catch{}return{type:"telegram",dir:Z,inboxDir:Y,token:$,allowFrom:Array.isArray(Q.allowFrom)?Q.allowFrom.map(String):[]}}var n=Kz.filter((z)=>z.type==="telegram").map(uz),Qz=Kz.find((z)=>z.type!=="telegram");if(Qz)console.error(`[agent-node] unsupported channel: ${Qz.raw}`),process.exit(1);if(n.length>0&&A!=="codex"&&!I.includes("Read"))I.push("Read");try{wz(s,{recursive:!0})}catch{}function i(z,Z,$){if(Z<Ez)return;let Q=new Date().toTimeString().slice(0,8),Y=z.toUpperCase().padEnd(5),X=`[${Q}] [${Y}] [${w}] ${$}`;console.log(X);try{let W=new Date().toISOString().slice(0,10);Sz(M(s,`${W}.log`),X+`
31
+ `)}catch{}}var V=(z)=>i("info",1,z),R=(z)=>i("debug",0,z),C=(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((F)=>setTimeout(F,1000*Math.pow(2,X)));continue}let J=await W.text(),B=J.match(/data: (.+)/),K=B?JSON.parse(B[1]):JSON.parse(J),j=K?.result?.content?.[0]?.text;return j?JSON.parse(j):K}catch(W){if(Y=W,X<$)R(`callCommHub(${z}) attempt ${X+1} failed: ${W.message}, retrying...`),await new Promise((J)=>setTimeout(J,1000*Math.pow(2,X)))}throw Y||Error(`callCommHub(${z}) failed after ${$} retries`)}var r=G.node_id||"",hz=G.node_name||"",u=G.network_id||process.env.ANET_NETWORK_ID||T.network_id||"",Hz=r?`sdk-${r}`:`sdk-${w}-${Date.now().toString(36)}`,fz=()=>c("report_status",{resume_id:Hz,alias:w,status:"idle",server:zz(),hostname:zz(),agent:`agent-node:${A}`,project_dir:process.cwd(),node_id:r||void 0,node_name:hz||void 0,session_id:_||void 0,config_path:N||void 0,channels:S.length?JSON.stringify(S):void 0,model:y||void 0,network_id:u||void 0}),l=(z,Z)=>c("report_status",{resume_id:Hz,alias:w,status:z,task:Z,node_id:r||void 0,session_id:m||_||void 0,config_path:N||void 0,channels:S.length?JSON.stringify(S):void 0,network_id:u||void 0}),pz=async()=>(await c("get_inbox",{alias:w,limit:20}))?.messages||[],dz=(z)=>c("ack_inbox",{alias:w,message_id:z}),cz=(z,Z,$,Q=!1)=>c("send_reply",{alias:z,text:Z,from_session:w,in_reply_to:$||void 0,status:Q?"failed":"replied"}),m=_||void 0;async function mz(z,Z){let{existsSync:$}=await import("fs"),Q=!1;try{let q=P.resolve("@anthropic-ai/claude-agent-sdk-linux-x64/claude");if($(q))Q=!0}catch{}if(!Q)try{let{execSync:q}=await import("child_process");q("which claude",{stdio:"pipe"}),Q=!0}catch{}let Y=!!(process.env.ANTHROPIC_BASE_URL&&(process.env.ANTHROPIC_AUTH_TOKEN||process.env.ANTHROPIC_API_KEY));if(!Q&&Y)return V(`[claude] no Claude Code binary; falling back to http runtime against ${process.env.ANTHROPIC_BASE_URL}`),vz(z,Z);let{query:X}=await import("@anthropic-ai/claude-agent-sdk"),W=[`你是 ${w},一个 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} 的最终汇报里。`,"","【禁止】",`- 不要给自己(${w})发任务(死循环)。`,'- 不要回复"收到""ok""明白了"等无内容确认。',"- 不要在无新任务时主动调用通信工具。","","执行完后简要汇报结果。"].join(`
32
+ `),J=E?`${E}
32
33
 
33
- ${z}
34
+ 收到来自 ${Z} 的任务:
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 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)$+=`
36
+ ${z}`:W,B=process.env.COMMHUB_URL||d,K=process.env.COMMHUB_TOKEN||L,j={};if(B)j.commhub={type:"http",url:`${B}/mcp`,headers:K?{Authorization:`Bearer ${K}`}:void 0};let F=(()=>{try{let{execSync:q}=P("child_process"),v=P("fs");try{let D=P.resolve("@anthropic-ai/claude-agent-sdk-linux-x64/claude");if(v.existsSync(D))return q(`${D} --version`,{stdio:"pipe"}),V(`[claude] using glibc binary: ${D}`),D}catch{}try{let D=q("which claude",{encoding:"utf-8"}).trim();if(D)return V(`[claude] using global binary: ${D}`),D}catch{}V("[claude] no binary resolved, falling back to SDK default");return}catch{return}})(),k={model:y||void 0,tools:I.length?I:void 0,maxTurns:Az,permissionMode:"bypassPermissions",allowDangerouslySkipPermissions:!0,settingSources:[],mcpServers:Object.keys(j).length?j:void 0,pathToClaudeCodeExecutable:F,env:process.env,cwd:process.cwd(),stderr:(q)=>{if(q.trim())V(`[stderr] ${q.trim().slice(0,300)}`)},hooks:{PreToolUse:[{hooks:[async(q)=>{return V(`[tool] ${q.tool_name}(${JSON.stringify(q.tool_input).slice(0,80)})`),{continue:!0}}]}]}};if($z>0)k.maxBudgetUsd=$z;if(E)k.systemPrompt=E;if(m)k.resume=m;let O="",U=Date.now();V(`[claude] claudePath=${F||"SDK default"}, mcpServers=${Object.keys(j).join(",")||"none"}`);for await(let q of X({prompt:J,options:k})){let v=q;if(v.type==="system"&&v.subtype==="init")m=v.session_id,V(`[claude] session=${v.session_id?.slice(0,8)} model=${y||"default"}`),Fz(v.session_id);if(v.type==="result"){let D=Date.now()-U,e=v.usage||{};V(`[claude] ${v.subtype} | ${D}ms | $${v.total_cost_usd?.toFixed(4)||"?"} | in=${e.input_tokens||0} out=${e.output_tokens||0} | turns=${v.num_turns}`),O=v.subtype==="success"?v.result||"任务完成":`执行出错: ${v.error||v.result||"未知错误"}`}}return O}var x=null,nz=E||[`你是 ${w},一个 AI Agent 节点,工作目录:${process.cwd()}。`,"你通过通信网络(CommHub)接收任务并和其他 agent 协作。","","【可用通信工具】","- mcp_commhub__send_task(alias, task):派任务给指定 agent,等其 LLM 处理完返回 reply(同步语义)。","- mcp_commhub__send_message(alias, message):发聊天消息(不要求对方回复)。","- mcp_commhub__get_task(task_id):查询某任务的当前状态/reply。","- mcp_commhub__get_all_status():查看网络上所有在线 agent。","","【协作模式】","当你的任务需要其他 agent 的能力时:","1. 先 get_all_status 看哪些 agent 在线。","2. 用 send_task 派给合适的 agent。","3. **必须** 用 get_task 轮询那个 task_id 直到 status=replied,拿到对方的 reply 内容。","4. 把 reply 整合进你给原始任务发起者的最终汇报。","","【禁止】",'- 不要回复"收到""好的""ok""在线""待命"等无内容确认。',"- 不要给自己发任务(会死循环)。","- 收到的若是 reply 类型,不要再 send_task 给原方(会乒乓回复)。","- 没有新任务时保持沉默,不主动发消息。","","你的最终回复会被系统自动 send_reply 给任务发起者。"].join(`
37
+ `),Xz={model_auto_compact_token_limit:200000,developer_instructions:nz};async function rz(z,Z,$){try{let{execSync:B}=await import("child_process"),K=B("which codex 2>/dev/null",{encoding:"utf-8"}).trim();if(K){let j=K.replace(/\/codex$/,"");if(!process.env.PATH?.includes(j))process.env.PATH=`${j}:${process.env.PATH}`}}catch{}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(!x){let B=new Q({config:Xz}),j={skipGitRepoCheck:!0,approvalPolicy:"never",model:y||"gpt-5.4",sandboxMode:"danger-full-access",modelReasoningEffort:"low"};if(_)x=B.resumeThread(_,j),V(`codex resumed thread: ${_}`);else x=B.startThread(j)}V(`[codex] model=${y||"gpt-5.4"} thread=${x?.id||"new"}`);let X=z,W=$?.length?[{type:"text",text:X},...$.map((B)=>({type:"local_image",path:B}))]:X,J=Date.now();try{let{events:B}=await x.runStreamed(W),K="",j=null,F=0;for await(let U of B)if(U.type==="item.started"){let q=U.item;R(`[codex] ${q.type}${q.command?`: ${q.command.slice(0,60)}`:q.tool?`: ${q.server}/${q.tool}`:""}`)}else if(U.type==="item.completed"){F++;let q=U.item;if(q.type==="agent_message")K=q.text||"";if(q.type==="command_execution")R(`[codex] cmd exit=${q.exit_code} | ${q.aggregated_output?.slice(0,80)}`);if(q.type==="reasoning")R(`[codex] thinking: ${q.text?.slice(0,80)}`);if(q.type==="mcp_tool_call")R(`[codex] mcp: ${q.server}/${q.tool} → ${q.status}`)}else if(U.type==="turn.completed")j=U.usage;let k=Date.now()-J,O=j?.input_tokens||0;if(V(`[codex] done | ${k}ms | in=${O} out=${j?.output_tokens||0} | items=${F}`),x?.id)Fz(x.id);return K||"(无回复)"}catch(B){V(`codex thread error: ${B.message}, 重建`),x=new Q({config:Xz}).startThread({skipGitRepoCheck:!0,approvalPolicy:"never",model:y||"gpt-5.4",sandboxMode:"danger-full-access",modelReasoningEffort:"low"});let j=await x.run(W),F=Date.now()-J;return V(`[codex] retry done | ${F}ms`),j.finalResponse||"(无回复)"}}async function vz(z,Z){let $=process.env.ANTHROPIC_API_KEY||process.env.OPENAI_API_KEY||process.env.MINIMAX_CODING_API_KEY||G.apiKey||"",Q=process.env.ANTHROPIC_BASE_URL||G.anthropicBaseUrl||"",Y=process.env.OPENAI_BASE_URL||G.apiBaseUrl||"https://api.openai.com/v1",X=y||"gpt-4o-mini",W=!!Q,B=(Q||Y).replace(/\/v1\/?$/,"");if(!$)return"错误: 需要设置 ANTHROPIC_API_KEY, OPENAI_API_KEY, 或 MINIMAX_CODING_API_KEY";let K=E||`你是 ${w},一个 AI 助手。收到来自 ${Z} 的任务后简要执行并汇报。`,j=Date.now();V(`[http-api] model=${X} format=${W?"anthropic":"openai"} base=${B.replace(/\/v1$/,"")}`);let F="",k=null;if(W){let U=await fetch(`${B}/v1/messages`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":$,"anthropic-version":"2023-06-01"},body:JSON.stringify({model:X,system:K,messages:[{role:"user",content:z}],max_tokens:2000})});if(!U.ok){let D=await U.text();return`Anthropic API 错误 ${U.status}: ${D.slice(0,200)}`}let q=await U.json();F=(Array.isArray(q.content)?q.content:[]).filter((D)=>D.type==="text").map((D)=>D.text).join(`
38
+ `)||"",k=q.usage}else{let U=await fetch(`${B}/chat/completions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${$}`},body:JSON.stringify({model:X,messages:[{role:"system",content:K},{role:"user",content:z}],max_tokens:2000})});if(!U.ok){let v=await U.text();return`OpenAI API 错误 ${U.status}: ${v.slice(0,200)}`}let q=await U.json();F=q.choices?.[0]?.message?.content||"",k=q.usage}let O=Date.now()-j;return V(`[http-api] done | ${O}ms | in=${k?.input_tokens||k?.prompt_tokens||0} out=${k?.output_tokens||k?.completion_tokens||0}`),F||"(无回复)"}var Yz=Promise.resolve();function Uz(z,Z,$){let Q=async()=>{if(A==="codex")return rz(z,Z,$);if(A==="http")return vz(z,Z);return mz(z,Z)},Y=Yz.then(Q,Q);return Yz=Y.then(()=>{},()=>{}),Y}async function lz(z,Z){V(`→ processing [${A}]: ${z.slice(0,80)}`),await l("working",z.slice(0,200)).catch(()=>{});let $,Q=!1;try{$=await Uz(z,Z)}catch(Y){$=`${A} 错误: ${Y.message}`,Q=!0,h(`✗ ${Y.message}`)}finally{await l("idle").catch(()=>{})}if(!Q&&/(API 错误|API error|需要设置.*KEY|missing.*key|issue with the selected model|may not have access|may not exist|model.+not.+(found|available))/i.test($))Q=!0;return{text:$,failed:Q}}var o={},gz=5000,iz=new Set(["收到","好的","ok","嗯","是的","了解","明白","确认","done","ack","roger","yes","no","在线","待命","正常","保持在线","通信正常","已收到","收到了","好","行","noted","copy","received","understood","等待任务","等待中","等待指令","无新任务","idle","waiting"]);function Dz(z,Z=!1){if(!z)return!0;let Q=z.trim().replace(/^[\[【].+?[\]】]\s*/,"").trim().toLowerCase().replace(/[\s。!?.!?✅❌👀⏳,,]+$/g,"").trim();if(iz.has(Q))return!0;if(/^[\p{Emoji}\s]+$/u.test(z.trim())&&!/[0-9a-zA-Z#*]/.test(z))return!0;return!1}function oz(z,Z,$){if(z===w)return"self";if(Z.startsWith(`[${w}]`))return"own-prefix";if(z!=="hub"&&z!=="api"){let Q=Date.now();if(o[z]&&Q-o[z]<gz)return"cooldown"}if($!=="task"&&$!=="broadcast"&&Dz(Z))return"low-value-inbound";return null}async function az(){let z=await pz();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 dz(Z.id),Y!=="task"&&Y!=="broadcast"){R(`skip non-task message: type=${Y}`);continue}let X=oz($,Q,Y);if(X){R(`skip message from ${$}: ${X}`);continue}let{text:W,failed:J}=await lz(Q,$);if(V(`processTask returned: "${W.slice(0,80)}" (${W.length} chars, failed=${J})`),!J&&Dz(W,!0)){V(`skip reply: low-value (${W.slice(0,30)})`);continue}try{V(`sending reply to ${$} (task ${Z.id.slice(0,8)}, status=${J?"failed":"replied"})...`),await cz($,`[${w}] ${W.slice(0,2000)}`,Z.id,J),o[$]=Date.now(),V(`→ [${$}] ${W.slice(0,100)}`)}catch(B){C(`reply failed: ${B.message}`)}}}function Mz(z){return String(z.from?.id||z.chat?.id||"")}function kz(z){return z.from?.username||z.from?.first_name||Mz(z)||"telegram"}function tz(z,Z){if(z.allowFrom.length===0)return!0;let $=Mz(Z),Q=Z.from?.username?String(Z.from.username):"";return z.allowFrom.includes($)||!!Q&&z.allowFrom.includes(Q)}async function g(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 Vz(z,Z,$,Q){let Y=$.match(/[\s\S]{1,4096}/g)||["(无回复)"];for(let X=0;X<Y.length;X++)await g(z,"sendMessage",{chat_id:Z,text:Y[X],...Q&&X===0?{reply_to_message_id:Q}:{}})}async function Jz(z,Z,$){let Q=await g(z,"getFile",{file_id:Z}),Y=String(Q.file_path||""),X=await fetch(`${z.fileBase}/${Y}`);if(!X.ok)throw Error(`telegram file download failed: ${X.status} ${X.statusText}`);let W=Y.split(".").pop(),J=($||Y.split("/").pop()||Z).replace(/[^a-zA-Z0-9._-]/g,"_"),B=J.includes(".")||!W?J:`${J}.${W}`,K=M(z.channel.inboxDir,`${Date.now()}_${B}`);return t(K,Buffer.from(await X.arrayBuffer())),K}async function sz(z,Z){let $=Z.text||Z.caption||"",Q=[];if(Array.isArray(Z.photo)&&Z.photo.length>0){let X=Z.photo[Z.photo.length-1],W=await Jz(z,X.file_id,`photo_${Z.message_id}.jpg`);Q.push(W)}let Y=String(Z.document?.mime_type||"");if(Z.document&&Y.startsWith("image/")){let X=await Jz(z,Z.document.file_id,Z.document.file_name||`image_${Z.message_id}`);Q.push(X)}if(Q.length)$+=`
37
39
 
38
40
  [Telegram 附件已下载]
39
- ${Q.map((W)=>`- 图片: ${W}`).join(`
40
- `)}`;return{text:$.trim(),images:Q}}async function gz(z,Z){if(!nz(z.channel,Z))return;let $=Z.chat?.id,Q=Z.message_id,Y=`telegram:${wz(Z)}`,{text:W,images:K}=await lz(z,Z);if(!$||!Q||!W)return;v(`[TG] processing: ${W.slice(0,80)}`);try{let X=await Gz(W,Y,K);await Zz(z,$,X,Q),V(`→ [${Y}] ${X.slice(0,100)}`)}catch(X){C(`telegram task failed: ${X.message}`),await Zz(z,$,`处理出错: ${X.message}`,Q).catch(()=>{})}}async function iz(z){let Z={channel:z,apiBase:`https://api.telegram.org/bot${z.token}`,fileBase:`https://api.telegram.org/file/bot${z.token}`,offset:0};try{let X=await f(Z,"getMe",{});V(`Telegram bot: @${X.username} (${X.first_name})`)}catch(X){C(`Telegram token 无效: ${X.message}`),process.exit(1)}let $=b(z.dir,"state.json");try{let X=JSON.parse(L($,"utf-8"));if(X.offset)Z.offset=X.offset,v(`Telegram offset restored: ${Z.offset}`)}catch{}let Q=()=>{try{n($,JSON.stringify({offset:Z.offset})+`
41
- `)}catch{}},Y=!1,W=[];async function K(){if(Y)return;Y=!0;while(W.length){let{msg:X,updateId:B}=W.shift();try{await gz(Z,X),Z.offset=B+1,Q()}catch(G){C(`TG handle: ${G.message}`)}}Y=!1}V(`Telegram polling: ${z.dir}`);while(!0)try{let B=await(await fetch(`${Z.apiBase}/getUpdates?offset=${Z.offset}&timeout=30`)).json();if(!B.ok)throw Error(B.description||"getUpdates failed");for(let G of B.result||[])if(Z.offset=G.update_id+1,G.message){let J=G.message,H=wz(J),p=J.text||J.caption||"";if(V(`← TG [${H}] ${p.slice(0,80)}${J.photo?" +img":""}${J.document?" +file":""}`),J.chat?.id&&J.message_id)f(Z,"setMessageReaction",{chat_id:J.chat.id,message_id:J.message_id,reaction:[{type:"emoji",emoji:W.length>0?"⏳":"\uD83D\uDC40"}]}).catch(()=>{});W.push({msg:J,updateId:G.update_id}),K()}}catch(X){O(`Telegram polling error: ${X.message}`),await new Promise((B)=>setTimeout(B,3000))}}async function az(){let z=`${l}/events/${encodeURIComponent(F)}`,Z=3000;while(!0){v(`SSE connecting: ${z}`);try{let $={Accept:"text/event-stream","Cache-Control":"no-cache"};if(N)$.Authorization=`Bearer ${N}`;let Q=await fetch(z,{headers:$});if(!Q.ok||!Q.body){if(Q.status===401)C("SSE 401: token 无效或未配置。检查 ~/.anet/config.json 的 token 字段");else O(`SSE failed: ${Q.status}`);await new Promise((X)=>setTimeout(X,Z)),Z=Math.min(Z*1.5,60000);continue}Z=3000;let Y=Q.body.getReader(),W=new TextDecoder,K="";while(!0){let{done:X,value:B}=await Y.read();if(X)break;K+=W.decode(B,{stream:!0});let G=K.split(`
42
- `);K=G.pop()||"";for(let J of G){if(!J.startsWith("data: "))continue;try{let H=JSON.parse(J.slice(6));if(H.type==="connected"){V("SSE connected");continue}if(["new_task","broadcast"].includes(H.type))V(`← SSE ${H.type}`),await rz();if(H.type==="new_reply")V(`← SSE reply from ${H.from||"?"}${H.in_reply_to?` (task ${H.in_reply_to.slice(0,8)})`:""}`)}catch{}}}}catch($){O(`SSE error: ${$.message}`)}v(`SSE reconnecting (${Z/1000}s)...`),await new Promise(($)=>setTimeout($,Z)),Z=Math.min(Z*1.5,60000)}}V("启动");V(` runtime: ${Rz}`);V(` model: ${P||(y==="codex"?"gpt-5.4":"claude-sonnet-4-6")} ${P?"":"(default)"}`);V(` hub: ${l}${N?" (auth)":" (no auth!)"}`);V(` tools: ${x.length?`[${x.join(",")}]`:"(none)"}`);V(` channels:${u.length?` telegram(${u.map((z)=>z.dir).join(",")})`:" (none)"}`);V(` session: ${R||"(new)"}`);V(` log-dir: ${g}`);await Tz();V("已注册到 CommHub");setInterval(()=>h("idle").catch(()=>{}),180000);var Hz=async()=>{V("shutting down..."),await h("offline").catch(()=>{}),process.exit(0)};process.on("SIGINT",Hz);process.on("SIGTERM",Hz);for(let z of u)iz(z);az();
41
+ ${Q.map((X)=>`- 图片: ${X}`).join(`
42
+ `)}`;return{text:$.trim(),images:Q}}async function ez(z,Z){if(!tz(z.channel,Z))return;let $=Z.chat?.id,Q=Z.message_id,Y=`telegram:${kz(Z)}`,{text:X,images:W}=await sz(z,Z);if(!$||!Q||!X)return;R(`[TG] processing: ${X.slice(0,80)}`);try{let J=await Uz(X,Y,W);await Vz(z,$,J,Q),V(`→ [${Y}] ${J.slice(0,100)}`)}catch(J){h(`telegram task failed: ${J.message}`),await Vz(z,$,`处理出错: ${J.message}`,Q).catch(()=>{})}}async function zZ(z){let Z={channel:z,apiBase:`https://api.telegram.org/bot${z.token}`,fileBase:`https://api.telegram.org/file/bot${z.token}`,offset:0};try{let J=await g(Z,"getMe",{});V(`Telegram bot: @${J.username} (${J.first_name})`)}catch(J){h(`Telegram token 无效: ${J.message}`),process.exit(1)}let $=M(z.dir,"state.json");try{let J=JSON.parse(f($,"utf-8"));if(J.offset)Z.offset=J.offset,R(`Telegram offset restored: ${Z.offset}`)}catch{}let Q=()=>{try{t($,JSON.stringify({offset:Z.offset})+`
43
+ `)}catch{}},Y=!1,X=[];async function W(){if(Y)return;Y=!0;while(X.length){let{msg:J,updateId:B}=X.shift();try{await ez(Z,J),Z.offset=B+1,Q()}catch(K){h(`TG handle: ${K.message}`)}}Y=!1}V(`Telegram polling: ${z.dir}`);while(!0)try{let B=await(await fetch(`${Z.apiBase}/getUpdates?offset=${Z.offset}&timeout=30`)).json();if(!B.ok)throw Error(B.description||"getUpdates failed");for(let K of B.result||[])if(Z.offset=K.update_id+1,K.message){let j=K.message,F=kz(j),k=j.text||j.caption||"";if(V(`← TG [${F}] ${k.slice(0,80)}${j.photo?" +img":""}${j.document?" +file":""}`),j.chat?.id&&j.message_id)g(Z,"setMessageReaction",{chat_id:j.chat.id,message_id:j.message_id,reaction:[{type:"emoji",emoji:X.length>0?"⏳":"\uD83D\uDC40"}]}).catch(()=>{});X.push({msg:j,updateId:K.update_id}),W()}}catch(J){C(`Telegram polling error: ${J.message}`),await new Promise((B)=>setTimeout(B,3000))}}async function ZZ(){let z=`${d}/events/${encodeURIComponent(w)}`,Z=3000;while(!0){R(`SSE connecting: ${z}`);try{let $={Accept:"text/event-stream","Cache-Control":"no-cache"};if(L)$.Authorization=`Bearer ${L}`;let Q=await fetch(z,{headers:$});if(!Q.ok||!Q.body){if(Q.status===401)h("SSE 401: token 无效或未配置。检查 ~/.anet/config.json 的 token 字段");else C(`SSE failed: ${Q.status}`);await new Promise((J)=>setTimeout(J,Z)),Z=Math.min(Z*1.5,60000);continue}Z=3000;let Y=Q.body.getReader(),X=new TextDecoder,W="";while(!0){let{done:J,value:B}=await Y.read();if(J)break;W+=X.decode(B,{stream:!0});let K=W.split(`
44
+ `);W=K.pop()||"";for(let j of K){if(!j.startsWith("data: "))continue;try{let F=JSON.parse(j.slice(6));if(F.type==="connected"){V("SSE connected");continue}if(["new_task","broadcast"].includes(F.type))V(`← SSE ${F.type}`),await az();if(F.type==="new_reply")V(`← SSE reply from ${F.from||"?"}${F.in_reply_to?` (task ${F.in_reply_to.slice(0,8)})`:""}`)}catch{}}}}catch($){C(`SSE error: ${$.message}`)}R(`SSE reconnecting (${Z/1000}s)...`),await new Promise(($)=>setTimeout($,Z)),Z=Math.min(Z*1.5,60000)}}V("启动");V(` runtime: ${Lz}`);V(` model: ${y||(A==="codex"?"gpt-5.4":"claude-sonnet-4-6")} ${y?"":"(default)"}`);V(` hub: ${d}${L?" (auth)":" (no auth!)"}`);if(L)try{let z=await fetch(`${d}/api/auth/me`,{headers:{Authorization:`Bearer ${L}`}}).then((Z)=>Z.json()).catch(()=>null);if(z?.ok&&z.user)if(V(` user: ${z.user.username} (${z.user.role})`),z.current_network){let Z=z.networks?.find(($)=>$.network_id===z.current_network)?.network_name;V(` network: ${Z||z.current_network}`)}else V(` network: ${u||"(global)"}`);else if(z?.ok===!1)V(` network: ${u||"(global)"}`);else C(" token 验证失败 — 检查 token 是否有效。运行: anet login")}catch{V(` network: ${u||"(global)"}`)}else C(" 未配置 token — agent 数据不隔离。运行: anet login");V(` tools: ${I.length?`[${I.join(",")}]`:"(none)"}`);V(` channels:${n.length?` telegram(${n.map((z)=>z.dir).join(",")})`:" (none)"}`);V(` session: ${_||"(new)"}`);V(` log-dir: ${s}`);await fz();V("已注册到 CommHub");setInterval(()=>l("idle").catch(()=>{}),180000);var bz=async()=>{V("shutting down..."),await l("offline").catch(()=>{}),process.exit(0)};process.on("SIGINT",bz);process.on("SIGTERM",bz);for(let z of n)zZ(z);ZZ();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sleep2agi/agent-node",
3
- "version": "2.1.0",
4
- "description": "One-command AI Agent node for CommHub networks. Claude + Codex dual runtime.",
3
+ "version": "2.1.2-preview.0",
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"
7
7
  },
@@ -23,13 +23,16 @@
23
23
  "gpt5",
24
24
  "sdk",
25
25
  "minimax",
26
- "swarm"
26
+ "runtime",
27
+ "node",
28
+ "anthropic"
27
29
  ],
28
30
  "author": "sleep2agi",
29
31
  "license": "MIT",
32
+ "homepage": "https://anet.vansin.me",
30
33
  "repository": {
31
34
  "type": "git",
32
- "url": "https://github.com/sleep2agi/agent-comm-hub",
35
+ "url": "https://github.com/sleep2agi/agent-network",
33
36
  "directory": "agent-node"
34
37
  },
35
38
  "engines": {
@@ -42,6 +45,8 @@
42
45
  "@openai/codex-sdk": ">=0.118.0"
43
46
  },
44
47
  "peerDependenciesMeta": {
45
- "@openai/codex-sdk": { "optional": true }
48
+ "@openai/codex-sdk": {
49
+ "optional": true
50
+ }
46
51
  }
47
- }
52
+ }