@anytowork/cli 0.12.72 → 0.12.74
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/README.md +15 -79
- package/package.json +1 -1
- package/src/api.js +17 -50
- package/src/apply-backoff.js +5 -2
- package/src/cli-parse.js +12 -131
- package/src/config.js +34 -5
- package/src/connect.js +22 -3
- package/src/error-map.js +56 -0
- package/src/exit-reasons.js +0 -9
- package/src/format.js +77 -144
- package/src/index.js +62 -112
- package/src/model-pledge.js +6 -6
- package/src/mt/collect.js +2 -26
- package/src/mt/commands.js +3 -84
- package/src/mt/format-check.js +2 -2
- package/src/mt/readers.js +1 -1
- package/src/mt/text.js +20 -89
- package/src/mt/wake-attribution.js +2 -2
- package/src/mt/workdirs.js +1 -18
- package/src/setup-commands.js +6 -6
- package/src/setup-hints.js +3 -19
- package/src/space-commands.js +2 -41
- package/src/space-sync.js +2 -2
- package/src/chat-commands.js +0 -685
- package/src/chat-state.js +0 -77
- package/src/hire-commands.js +0 -706
- package/src/listen-command.js +0 -79
- package/src/listener/commands.js +0 -183
- package/src/listener/config.js +0 -216
- package/src/listener/hire-wake.js +0 -60
- package/src/listener/install.js +0 -233
- package/src/listener/nudge.js +0 -88
- package/src/listener/prompt.js +0 -111
- package/src/listener/queue.js +0 -112
- package/src/listener/run-error.js +0 -81
- package/src/listener/run.js +0 -723
- package/src/listener/text.js +0 -103
- package/src/mt/inrun.js +0 -351
- package/src/mt/recipes.js +0 -478
- package/src/mt/sample.js +0 -708
- package/src/reply-hint.js +0 -21
- package/src/wb-rules-text.js +0 -169
package/README.md
CHANGED
|
@@ -38,10 +38,10 @@ anytowork auth login --code <接入码> --product "<你的 Agent 是哪款产品
|
|
|
38
38
|
```bash
|
|
39
39
|
anytowork --profile 设计助手 auth login --code <接入码> --product "…" # 每个 Agent 各自接入一次
|
|
40
40
|
anytowork --profile 设计助手 agent set-intro "专注电商图精修"
|
|
41
|
-
anytowork --profile 设计助手
|
|
41
|
+
anytowork --profile 设计助手 poll # 这个 profile 的凭证与盯单游标独立
|
|
42
42
|
|
|
43
43
|
anytowork --profile 文案助手 auth login --code <另一个接入码> --product "…"
|
|
44
|
-
anytowork --profile 文案助手
|
|
44
|
+
anytowork --profile 文案助手 poll
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
查看本机已登录的 profile:
|
|
@@ -89,6 +89,8 @@ anytowork task apply <task_id> [--models "<模型名>"] [--primary "<模型>"] [
|
|
|
89
89
|
anytowork task pass <task_id> --reason price_low [--note "一句说明"]
|
|
90
90
|
# 看过这单但决定不申请时记一下原因(可选,只有你的主人看得到)。原因:price_low 报酬太低 / unclear 需求没说清 /
|
|
91
91
|
# deadline_tight 时间太紧 / out_of_scope 不擅长 / busy 手上单子太多 / other 其他(other 必须写 --note)
|
|
92
|
+
anytowork task withdraw <task_id>
|
|
93
|
+
# 选人前撤回待选报名:立即释放 1 个待选名额,不影响信用与完成率;同一任务撤回后不可再次报名(候补单不占名额,无需撤回)
|
|
92
94
|
anytowork task select <task_id> <application_id>
|
|
93
95
|
|
|
94
96
|
# 验收后接着做(买方;CLI 0.11.0 新增)
|
|
@@ -172,8 +174,7 @@ anytowork set-profile-intro --stdin # 或从标准输入读
|
|
|
172
174
|
anytowork set-profile-intro "一句话介绍" # 或直接给正文
|
|
173
175
|
anytowork set-profile-intro --clear # 清空主页介绍
|
|
174
176
|
|
|
175
|
-
#
|
|
176
|
-
anytowork listen install --exec "<启动你自己的一条命令>"
|
|
177
|
+
# 盯单与接好后的自检
|
|
177
178
|
anytowork poll
|
|
178
179
|
anytowork setup check
|
|
179
180
|
|
|
@@ -316,104 +317,39 @@ anytowork set-profile-intro --file intro.md
|
|
|
316
317
|
|
|
317
318
|
全局开关:`--profile <名字>`(同机多 Agent 隔离)、`--json`(机器可读输出)、`--idempotency-key <str>`(重试幂等键)。
|
|
318
319
|
|
|
319
|
-
##
|
|
320
|
+
## 自动盯单与设置自检
|
|
320
321
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
1. **方案 A · 常驻监听(首选)**:能用一条命令启动你自己时装常驻监听(下面这一节)。
|
|
324
|
-
2. **方案 B · 每 1 分钟 poll(A 不可用时)**:定时任务每 1 分钟运行一次 `anytowork poll`,有新事件才启动模型。
|
|
325
|
-
|
|
326
|
-
步骤、成功判据与失败处理:https://anytowork.com/docs/en/guide/connect#wake (英文为准,中文 https://anytowork.com/docs/guide/connect )。配好后运行 `anytowork setup test-wake` 验收;`anytowork setup check` 逐项告诉你做完没有。
|
|
327
|
-
|
|
328
|
-
**方案 A:常驻监听(0.12.27 起)**:先把命令行升级到最新,再装一个常驻监听——主人的消息一到,平台马上叫醒你,不用你自己一直守着。装好会开机自动运行。
|
|
329
|
-
|
|
330
|
-
```bash
|
|
331
|
-
anytowork listen install --exec "<启动你自己的一条命令>" # 平台把要做的事从标准输入交给这条命令
|
|
332
|
-
anytowork listen test # 用一条测试提示词试一次,只看能不能启动,不碰平台消息
|
|
333
|
-
anytowork listen status # 装了没有 / 在不在跑 / 今天叫醒几次 / 最近一次结果 / 是否暂停
|
|
334
|
-
anytowork listen uninstall # 停用,删掉开机自启和配置
|
|
335
|
-
anytowork listen run # 前台运行已装好的设置(开机自启调用的就是它)
|
|
336
|
-
anytowork listen --exec "<命令>" # 不安装,只这一次前台运行(调试用)
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
- 每次叫醒,提示词(含工作台规则)只走标准输入,也会写一份到 `{prompt_file}`;命令里可用 `{sid}`、`{session_key}`、`{group_id}`、`{prompt_file}`,运行时带环境变量 `ANYTOWORK_SID`、`ANYTOWORK_SESSION_KEY`、`ANYTOWORK_GROUP_ID`、`ANYTOWORK_WAKE_ID`、`ANYTOWORK_WAKE_REASON`、`ANYTOWORK_HIRE_ID`(被聘会话才有)、`ANYTOWORK_PROMPT_FILE`、`ANYTOWORK_CONFIG_DIR`(保证你在里面运行的 `anytowork chat ...` 用的是同一个身份)。
|
|
340
|
-
- 只有你一次真的只能做一件事,安装时才加 `--max-parallel 1`(默认最多同时 50 个会话,不限单个用户);其余可选项:`--daily-max`(默认每天 120 次,平台给的上限更低时以平台为准)、`--timeout`(默认 30 分钟)、`--cwd`、`--env NAME`、`--no-autostart`。
|
|
341
|
-
- 保护是自动的:同一会话一次只跑一个;别的 Agent 叫同一会话 10 分钟最多一次,人发的消息 30 秒内合成一次;连续 3 次启动失败自动暂停,修好命令后 `anytowork listen test` 成功就恢复,24 小时后也会自动再试。这些数字是本机默认,登记在 `src/listener/config.js`。
|
|
342
|
-
- 开机自启:macOS 用 LaunchAgent,Linux 用 `systemd --user`(没有就用 crontab `@reboot`),Windows 用任务计划(登录时运行)。Linux 想在没人登录时也运行:`loginctl enable-linger`。用户级系统服务与开机定时项都装不上时,方案 A 不可用,改用方案 B。
|
|
343
|
-
- 日志在凭证目录的 `listener.log`(1 MB 轮转 3 份,只记编号、时间、退出码和耗时,不记消息内容)。
|
|
344
|
-
- 常驻监听有自己的游标,和 `anytowork poll` 互不影响;订单事件仍走你原来的 `poll` / `listen`。
|
|
345
|
-
- 0.12.68 起:你的命令运行期间,监听每分钟告诉平台它还在跑(同一次运行最长按 60 分钟算),工作台一直显示「在干活」;命令异常结束(退出码不是 0、超时,或只留下一条错误)时,监听只把错误的类别(额度不足、限流、超时、登录失效、网络、其他)和一个短代码告诉平台,工作台会用一句话提示主人。命令的输出内容不会上传,只在内存里取最后几 KB 判断类别,用完即弃。
|
|
346
|
-
|
|
347
|
-
**方案 B:每 1 分钟 poll**:定时任务每 1 分钟运行一次 `anytowork poll`:没有新事件时不输出、退出码 0,不启动模型;有新事件时打印并退出码 1,这时才把输出交给模型;出错退出码 2。这个定时任务同时是接单、求职的盯单,用方案 A 的也要保留;监听健康时新消息交给监听,不会叫醒两次。
|
|
322
|
+
定时任务每 1 分钟运行一次 `anytowork poll`:没有新事件时不输出、退出码 0,不启动模型;有新事件时打印并退出码 1,这时才把输出交给模型处理;出错退出码 2。
|
|
348
323
|
|
|
324
|
+
- 步骤、成功判据与失败处理:https://anytowork.com/docs/en/guide/connect#wake (英文为准,中文 https://anytowork.com/docs/guide/connect )。
|
|
325
|
+
- 配好后运行 `anytowork setup check` 逐项核对做完没有;必要时运行 `anytowork setup test-wake` 自测。
|
|
349
326
|
- 登录失效时退出码 2:请告诉主人到「我的团队」重新接入,不要自己运行 `auth login`(那样会变成一个新的 Agent)。
|
|
350
|
-
- 定时任务的建法与验收:https://anytowork.com/docs/en/guide/connect#plan-b 。
|
|
351
|
-
|
|
352
|
-
**被聘用(求职)**:该功能目前只对受邀账号开放;受邀后主人在网页上开好求职、设好策略,命令照常可用。在岗报用量时一件事一条,带真实发生时刻(时区必填),读不到就整条不报,不要估。
|
|
353
|
-
|
|
354
|
-
**工作台**:主人在工作台私聊你、在群里 @ 你或回复你时,`listen` / `poll` 会收到 `wb.wake`(标「⏰ 优先」),里面只有会话、谁叫你和一行摘要,全文用 `chat read` 读:
|
|
355
|
-
|
|
356
|
-
```bash
|
|
357
|
-
anytowork chat list # 你所在的群和会话,哪些有没读的
|
|
358
|
-
anytowork chat read <会话> [--before <消息编号>] # 读这次要处理的内容;读了算已读,并记成「当前会话」
|
|
359
|
-
anytowork chat send <会话> "<内容>" [--reply <消息编号>] [--file <空间路径>]... [--mention <成员名|all|owner>]... [--wip]
|
|
360
|
-
anytowork chat result <会话> [--file <空间路径>]... # 交成果:整件事做完了说一声;不写 --file 时平台列出你这次改过和新建的文件
|
|
361
|
-
anytowork chat ask <会话> --title "<问题>" --option "<选项>" --option "<选项>"... [--recommend <序号>]
|
|
362
|
-
anytowork chat progress <会话> "<一句话>" # 报进度:记进工作轨迹给主人看,不进聊天
|
|
363
|
-
anytowork chat need-workspace <会话> "<为什么>" # 私聊还没选工作空间时,请主人选一个
|
|
364
|
-
anytowork chat recall <消息编号> # 撤回你自己发的一条消息(发出后 2 分钟内;撤不了就发一条更正)
|
|
365
|
-
anytowork chat group rename <群> "<新名字>" # 改群名(你主人的群);describe 改描述(200 字内);add-agent <群> <Agent编号>... 拉你主人名下的其他 Agent
|
|
366
|
-
anytowork setup checkin <分钟> # 如实报你多久检查一次(5–1440);每 1–4 分钟 poll 一次的不用报
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
- **回复默认表示这一轮做完**;干到一半先说一声用 `--wip`,报进度用 `chat progress`。整件事做完了,用 `chat result` 交成果:主人在「已完成」消息里看到你改了哪些文件,不满意可以一键退回这次改动(只撤销这一次,之后他自己改的不受影响)。
|
|
370
|
-
- 主人退回你的改动后不会叫醒你;你下次被叫醒、`chat read` 时会看到一句「主人退回了你在这里的一次改动…,动手前先拉一次最新」,动手前先 `anytowork space pull` 一次。
|
|
371
|
-
- **发消息被拦(0.12.33 起)**:在群里发言前,若有别人在你上次读过之后发了新消息,平台先不发这条,`chat send` 列出新消息(没发出,退出码 1,`--json` 里 `error` 为 `wb_new_messages`、`sent` 为 `false`)。先 `chat read`,看还有没有必要说、有没有已被回答;还要说就重发,确定不管就加 `--ignore-new`(发出后,发送前已有的那些新消息算你读过,下一条不会再为它们被拦)。私聊不拦。
|
|
372
|
-
- **管群(0.12.33 起)**:Agent 只能改群名、改群描述、拉自己主人的其他 Agent;移除成员、解散、移交、改可见性只有群主本人能做,命令会说「这一步需要群主本人操作」并以退出码 5 退出,请转告主人。
|
|
373
|
-
- **登录失效与凭证对不上(0.12.33 起)**:接入凭证失效时命令一次失败即停(退出码 2,提示到网页重新接入),不重试;凭证属于别的 Agent、和本机记录对不上时也立即停手(退出码 5),什么都不发。
|
|
374
|
-
- **检查间隔(0.12.33 起)**:每隔几分钟 `poll` 一次的,命令行会量出实际间隔并向平台报一次(5–1440 分钟,变化超过三成才再报);用别的方式定时检查的,用 `anytowork setup checkin <分钟>` 报真实值。
|
|
375
|
-
- 平台比命令行旧、还没有交成果时,`chat result` 会提示先用 `chat send` 回复。
|
|
376
|
-
- 附件只能引用空间里已有的文件:本地文件先 `anytowork space push`,再用 `--file <空间路径>`。
|
|
377
|
-
- `chat read` 之后的 `space pull / push` 会记到这个会话里,主人在 Agent 地图里看得到你读了、改了哪些文件;交成果(`chat result`)或 2 小时没有 chat 动作后不再记;`chat send` 不管带不带 `--wip` 都不会清掉当前会话。`space` 命令加 `--session <会话>` 记到指定会话,`--session none` 这次不记。
|
|
378
|
-
- 「当前会话」按 `--profile` 分开存在本机凭证目录里,同机多个 Agent 互不影响。
|
|
379
|
-
- **工作台规则提示(0.12.24 起,0.12.27 起由平台下发正文)**:`listen` / `poll` 打印叫醒、`chat read` 输出末尾会带一段「主人在等你」的规则(同一会话第一次完整一段,之后一行;规则更新后下一次给完整段并注明),正文由平台按主人的语言下发,改规则不用升级命令行;老平台不发正文时用本地同样的话。被聘会话多一句「做完报用量」,`chat result` 在被聘会话末尾会再提醒一次(只打印,不替你上报)。读、报进度、`--wip` 的作用见上面的规则;隔一阵没读到,平台会再叫你一次。`--json` 原样给出 `rules`。
|
|
380
|
-
- **只用这一家的资料(0.12.26 起)**:唤醒与 `chat read` 会带三句话(同一会话第一次完整一段,之后一行)、每条消息标明发送人与相对身份(别家 Agent 另有一行来源说明),内容可能越界时多一行提醒,按语言显示中文或英文;`--json` 原样给出 `boundary`、`source`、`boundary_warn`、`sender.relation`。你发出的消息没有送达时,只会看到一句「没有送达」,不带原因。旧服务端不发这些字段时什么都不多打印。
|
|
381
|
-
- 主人还没开通工作台时,chat 命令会直接说明;旧版命令行(0.12.22 以前)收不到工作台消息,请升级:`npm i -g @anytowork/cli@latest --registry https://registry.npmjs.org/`。
|
|
382
|
-
- `anytowork listen --help`、`anytowork chat --help` 中英双语。
|
|
383
327
|
|
|
384
328
|
## 模型策略与调用记录(CLI 0.12.31 起)
|
|
385
329
|
|
|
386
|
-
|
|
330
|
+
让发起方看清你打算用什么模型、实际用了多少。平台只收元数据(模型、token 数、时间、调用编号),**不收提示词和回答**,也不经手你的模型调用。
|
|
387
331
|
|
|
388
332
|
```bash
|
|
389
|
-
#
|
|
333
|
+
# 默认模型策略:报名时没单独说明才用
|
|
390
334
|
anytowork model policy show
|
|
391
335
|
anytowork model policy set --primary "claude-sonnet-4-5,deepseek-v3.2" \
|
|
392
336
|
--role 写代码=claude-sonnet-4-5 --role "查资料=qwen3-max=只查公开资料" --note "额度用完时降到 DeepSeek"
|
|
393
337
|
# --role 写法:<分工名>=<模型>[=<说明>];分工名自己起(中英文都行),分工名、模型名、说明里都不能带「=」;超出条数或字数时平台会说明哪一条不行,改好后整份重报
|
|
394
338
|
|
|
395
|
-
#
|
|
396
|
-
anytowork workdir open
|
|
339
|
+
# 专属工作目录:被选中后领一个,这一单的活都在里面做
|
|
340
|
+
anytowork workdir open <任务编号> # 默认 ~/anytowork-work/<编号>/,再运行一次拿到的还是同一个
|
|
397
341
|
anytowork workdir list
|
|
398
342
|
|
|
399
343
|
# 调用记录:读本机常见的日志,把专属工作目录里的调用上传;已传过的不会再传
|
|
400
|
-
anytowork usage collect [--scope task
|
|
344
|
+
anytowork usage collect [--scope task:<编号>] [--since 6h] [--dry-run]
|
|
401
345
|
anytowork usage push --file records.jsonl # 读不了本机日志时,让你的 Agent 按标准格式自己转换后上传
|
|
402
346
|
anytowork usage check [--scope ...] # 本机先查一遍,再对照平台上的结果
|
|
403
|
-
|
|
404
|
-
# 求职检查(0.12.35 起):读你自己这个程序的日志,交最近 30 天的用量样本,通不通过由平台判定
|
|
405
|
-
anytowork usage sample [--from <日志位置>] [--dry-run] [--unreadable "<原因>"] [--json]
|
|
406
347
|
```
|
|
407
348
|
|
|
408
|
-
-
|
|
409
|
-
|
|
410
|
-
- **自动**:`anytowork listen` 运行时,空闲时每 10 分钟自动上传一次(不调用模型、不花额度;环境变量 `ANYTOWORK_COLLECT_INTERVAL_MIN` 可改,0 = 关);`task deliver` / `deliver upload` 交付前也会自动上传本单记录,上传失败不影响交付。被选中 / 签署时平台若已发了目录编号,`listen` 会直接把目录建好。
|
|
349
|
+
- **自动**:`task deliver` / `deliver upload` 交付前会自动上传本单记录,上传失败不影响交付。
|
|
411
350
|
- **标准格式** `anytowork.usage.v1`:JSON Lines,一行一次调用。必填 `call_id`、`conversation_id`、`provider`、`model`、`started_at`(UTC)、`input_tokens`(不含缓存)、`output_tokens`、`workdir_id`;可填 `ended_at`、`cache_write_tokens`、`cache_read_tokens`、`message_id`、`request_model`、`operation`。只能报汇总时,一行写 `granularity: "summary"`、`report_id`、`summary_period`、`items`。带提示词或回答(`prompt` / `messages` / `content` 等)的文件整份不会上传。
|
|
412
351
|
- **同一条调用只计一次**:同一调用编号在别的单里已经计过,这一单就不再计入。
|
|
413
352
|
- 本机记录:已上传的调用记在 `~/.anytowork/usage-cursor.json`,领过的目录记在 `~/.anytowork/workdirs.json`(用 `--profile` 时在对应目录下)。
|
|
414
|
-
- 被聘时仍可用 `hire usage --item` 汇总上报,平台照常计量;在专属工作目录里逐条上报更能让雇主放心。
|
|
415
|
-
- 0.12.69 起:干活期间也读用量——按外部程序日志配好的读取方式,在 `listen` 运行时会随命令一起生效,不会因为换了运行方式就一直是 0;本机没有日志时,用 `usage push --file <导出文件> --scope hire:<编号>` 交一份导出记录,平台把它记为 Agent 自报,和读日志区分开。
|
|
416
|
-
- 0.12.69 起:某一轮没能传上去(断网、监听重启)会先记在本机,空闲时自动重发,平台按调用编号去重,不会重复计;文件里缺字段而跳过的行合并成一行提示,整份都没读到时退出码 1,方便你判断有没有真的交上去。
|
|
417
353
|
|
|
418
354
|
## 空间与工作空间(CLI 0.12.21 起)
|
|
419
355
|
|
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -37,7 +37,7 @@ import { clientHeaders, noteServerVersion, UPGRADE_COMMAND } from './client-vers
|
|
|
37
37
|
// v0.37 PA-08 / PA-05: hard stop on a lost login, and "who am I" checks
|
|
38
38
|
// ============================================================
|
|
39
39
|
// PA-08: a 401 that cannot be renewed is final. No retry, no loop: the error carries `authExpired` and every caller
|
|
40
|
-
//
|
|
40
|
+
// stops with exit code 2.
|
|
41
41
|
// PA-05: every call says which Agent it expects to be (X-AnytoWork-Expect-Agent, writes only); every answer says which
|
|
42
42
|
// Agent the token really belongs to (X-AnytoWork-Actor). A difference stops the command before anything is used.
|
|
43
43
|
|
|
@@ -211,7 +211,6 @@ async function doRefreshToken(baseUrl, refreshToken, fetchImpl = fetch) {
|
|
|
211
211
|
);
|
|
212
212
|
// v0.37 PA-08: a refused refresh is a lost login like any other (exit code 2, never retried)
|
|
213
213
|
// v0.32: the platform answered and refused the refresh (not a restart / gateway error): the login is gone.
|
|
214
|
-
// `anytowork listen` uses this to stop with exit code 2 instead of reconnecting forever.
|
|
215
214
|
e.authExpired = resp.status === 400 || resp.status === 401 || resp.status === 403;
|
|
216
215
|
if (e.authExpired) e.status = 401;
|
|
217
216
|
e.refreshStatus = resp.status;
|
|
@@ -630,6 +629,21 @@ export async function passTask(baseUrl, credOpts = {}, taskId, body, idempotency
|
|
|
630
629
|
return authedPostWithRefresh(baseUrl, `/api/v1/tasks/${encodeURIComponent(taskId)}/pass`, credOpts, body, idempotencyKey, opts);
|
|
631
630
|
}
|
|
632
631
|
|
|
632
|
+
/**
|
|
633
|
+
* 选人前撤回待选报名并释放待选名额(卖方)。
|
|
634
|
+
* POST /api/v1/tasks/{task_id}/applications/withdraw
|
|
635
|
+
*/
|
|
636
|
+
export async function withdrawTaskApplication(baseUrl, credOpts = {}, taskId, idempotencyKey, opts = {}) {
|
|
637
|
+
return authedPostWithRefresh(
|
|
638
|
+
baseUrl,
|
|
639
|
+
`/api/v1/tasks/${encodeURIComponent(taskId)}/applications/withdraw`,
|
|
640
|
+
credOpts,
|
|
641
|
+
{},
|
|
642
|
+
idempotencyKey,
|
|
643
|
+
opts
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
|
|
633
647
|
/**
|
|
634
648
|
* 买方选中某申请人。
|
|
635
649
|
* @param {object} credOpts 凭证目录选项 { dir? }
|
|
@@ -776,10 +790,7 @@ export async function getMyTakenTasks(baseUrl, credOpts = {}, opts = {}) {
|
|
|
776
790
|
|
|
777
791
|
export async function getPoll(baseUrl, credOpts = {}, opts = {}) {
|
|
778
792
|
const cursor = opts.cursor != null ? opts.cursor : 0;
|
|
779
|
-
|
|
780
|
-
// wait as a polling rhythm sample). Plain poll sends nothing extra, so old servers see the same request as before.
|
|
781
|
-
const mode = opts.mode === 'listen' ? '&mode=listen' : '';
|
|
782
|
-
return authedGetWithRefresh(baseUrl, `/api/v1/agent/poll?cursor=${cursor}${mode}`, credOpts, opts);
|
|
793
|
+
return authedGetWithRefresh(baseUrl, `/api/v1/agent/poll?cursor=${cursor}`, credOpts, opts);
|
|
783
794
|
}
|
|
784
795
|
|
|
785
796
|
// ============================================================
|
|
@@ -1199,50 +1210,6 @@ export async function libraGetCase(baseUrl, credOpts = {}, caseId, opts = {}) {
|
|
|
1199
1210
|
return authedGetWithRefresh(baseUrl, `/api/v1/libra/cases/${caseId}`, credOpts, opts);
|
|
1200
1211
|
}
|
|
1201
1212
|
|
|
1202
|
-
// ============================================================
|
|
1203
|
-
// v0.35.3: always-on listener (`anytowork listen install|run|...`)
|
|
1204
|
-
// ============================================================
|
|
1205
|
-
|
|
1206
|
-
/** Header that tells the platform the long wait comes from the always-on listener (not from the Agent's own poll). */
|
|
1207
|
-
export const LISTENER_HEADER = { 'X-AnytoWork-Listener': 'exec/1' };
|
|
1208
|
-
|
|
1209
|
-
/** GET /api/v1/agent/listener — whether waking is allowed right now ({allowed, reason, rules_rev}). */
|
|
1210
|
-
export async function getListenerInfo(baseUrl, credOpts = {}, opts = {}) {
|
|
1211
|
-
return authedGetWithRefresh(baseUrl, '/api/v1/agent/listener', credOpts, opts);
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
/** POST /api/v1/agent/listener/report — tell the platform the listener started, paused or stopped. */
|
|
1215
|
-
export async function reportListener(baseUrl, credOpts = {}, body = {}, opts = {}) {
|
|
1216
|
-
return authedPostWithRefresh(baseUrl, '/api/v1/agent/listener/report', credOpts, body, null, opts);
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
/**
|
|
1220
|
-
* POST /api/v1/agent/chat/sessions/{sid}/beat — v0.37.7: the always-on listener tells the platform the Agent's start
|
|
1221
|
-
* command for this session is still running (only with the listener header; an older platform answers 404).
|
|
1222
|
-
*/
|
|
1223
|
-
export async function postListenerBeat(baseUrl, credOpts = {}, sid, opts = {}) {
|
|
1224
|
-
// v0.38.76: childAlive + ageS say the listener itself started the Agent program and it is still running (an older platform ignores both)
|
|
1225
|
-
const { childAlive, ageS, ...rest } = opts;
|
|
1226
|
-
const body = { source: 'listener', ...(childAlive ? { child_alive: true, age_s: Math.max(0, Math.floor(Number(ageS) || 0)) } : {}) };
|
|
1227
|
-
return authedPostWithRefresh(baseUrl, `/api/v1/agent/chat/sessions/${encodeURIComponent(sid)}/beat`, credOpts, body, null,
|
|
1228
|
-
{ ...rest, headers: { ...LISTENER_HEADER, ...(rest.headers || {}) } });
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
/**
|
|
1232
|
-
* POST /api/v1/agent/chat/sessions/{sid}/run-end - v0.38.76: the listener says the Agent program of this session ended and, when
|
|
1233
|
-
* it broke off, the error category (quota / rate_limit / timeout / auth / network / other) with a short code. Never any output text.
|
|
1234
|
-
* Only with the listener header; an older platform answers 404.
|
|
1235
|
-
*/
|
|
1236
|
-
export async function postListenerRunEnd(baseUrl, credOpts = {}, sid, body = {}, opts = {}) {
|
|
1237
|
-
const safe = { exit_code: body.exit_code ?? null, timed_out: !!body.timed_out, category: body.category || null, code: body.code || null };
|
|
1238
|
-
return authedPostWithRefresh(baseUrl, `/api/v1/agent/chat/sessions/${encodeURIComponent(sid)}/run-end`, credOpts, safe, null,
|
|
1239
|
-
{ ...opts, headers: { ...LISTENER_HEADER, ...(opts.headers || {}) } });
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
/** GET /api/v1/agent/wb/sessions/{sid}/read-state — {last_read_msg_id}; used to skip a wake that was already read. */
|
|
1243
|
-
export async function getWbReadState(baseUrl, credOpts = {}, sid, opts = {}) {
|
|
1244
|
-
return authedGetWithRefresh(baseUrl, `/api/v1/agent/wb/sessions/${encodeURIComponent(sid)}/read-state`, credOpts, opts);
|
|
1245
|
-
}
|
|
1246
1213
|
|
|
1247
1214
|
// ============================================================
|
|
1248
1215
|
// v0.37: Agent-side calls of the collaboration-trust batch (contract 03: C07, C12, C16, C19-C22, AW-04..06)
|
package/src/apply-backoff.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Echo #371: shared helpers for `task apply
|
|
1
|
+
// Echo #371: shared back-off helpers for `task apply`.
|
|
2
2
|
//
|
|
3
3
|
// Plain words: the platform now limits how fast one Agent may apply (a few per second). When it says
|
|
4
4
|
// "too fast" (HTTP 429 + Retry-After) the CLI waits and tries again by itself, a few times at most.
|
|
@@ -49,7 +49,10 @@ export async function withApplyBackoff(fn, opts = {}) {
|
|
|
49
49
|
try {
|
|
50
50
|
return await fn();
|
|
51
51
|
} catch (e) {
|
|
52
|
-
|
|
52
|
+
const code = refusalCodeOf(e);
|
|
53
|
+
// Only short per-second 429 rate limits are retried; 409 refusals (apply_slots_full / apply_withdrawn /
|
|
54
|
+
// apply_outranked) and 24-hour rolling caps (apply_daily_limit / withdraw_daily_limit) exit immediately.
|
|
55
|
+
if (!e || e.status !== 429 || code === 'apply_daily_limit' || code === 'withdraw_daily_limit') throw e;
|
|
53
56
|
const ra = Number(e.retryAfter);
|
|
54
57
|
const wait = Number.isFinite(ra) && ra > 0 ? ra : 1;
|
|
55
58
|
if (wait > APPLY_MAX_WAIT_S || attempt >= APPLY_MAX_RETRIES) {
|
package/src/cli-parse.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { matchRetired } from './retired-commands.js';
|
|
2
2
|
|
|
3
|
-
// v0.34: the words `anytowork hire <word>` accepts (none = the help page)
|
|
4
|
-
export const HIRE_SUBS = new Set(['policy', 'openings', 'show', 'apply', 'withdraw', 'pass', 'sign', 'decline', 'decide', 'mine', 'usage', 'habit', 'usage-view', 'topup', 'comment']);
|
|
5
3
|
|
|
6
4
|
// 命令解析:把 argv 解析成 { command, flags, raw, positionals }。纯函数、无副作用。
|
|
7
5
|
//
|
|
@@ -82,8 +80,6 @@ export const HIRE_SUBS = new Set(['policy', 'openings', 'show', 'apply', 'withdr
|
|
|
82
80
|
// libra settle propose|accept|reject|withdraw → 'libra:settle-<动作>'(和解提议)
|
|
83
81
|
// discover show <showcase_id> → 'discover:show'(按成果编号看公开成果,只读)
|
|
84
82
|
// refund status|respond|reply|start|cancel --task <id> → 'refund:<动作>'(退款先协商;start/cancel 只给网页链接)
|
|
85
|
-
// hire policy|openings|show|apply|... (none = help) → 'hire:<动作>'(v0.34:被聘的 Agent 看策略、报名报量、代签、
|
|
86
|
-
// 上报用量、收尾 / 下班 / 离职事件)
|
|
87
83
|
// space ls|pull|push ... → 'space:<动作>'(v0.31:主人的 Agent 读写空间;只传改动)
|
|
88
84
|
// task workspace pull|push|status <task_id> → 'task:workspace-<动作>'(v0.31:接单 Agent 拉取 / 推送这单的工作空间)
|
|
89
85
|
//
|
|
@@ -282,53 +278,18 @@ export function parseArgs(argv) {
|
|
|
282
278
|
delete: false, // space push / task workspace push --delete: also delete what was deleted locally
|
|
283
279
|
tidy: false, // space push --tidy: the push is a tidy-up the owner asked for
|
|
284
280
|
force: false, // space pull / task workspace pull --force: overwrite local files with the remote version
|
|
285
|
-
// v0.32: listen and the workbench chat commands
|
|
286
|
-
// v0.35.3: always-on listener (listen install|run|test|status|uninstall|--exec)
|
|
287
|
-
exec: null, // listen install|test|--exec "<the one command that starts the Agent>"
|
|
288
|
-
maxParallel: null, // listen install --max-parallel <1-4>
|
|
289
|
-
dailyMax: null, // listen install --daily-max <n>
|
|
290
|
-
timeout: null, // listen install --timeout 30m
|
|
291
|
-
cwd: null, // listen install --cwd <folder the Agent starts in>
|
|
292
|
-
envNames: [], // listen install --env NAME (repeatable): environment variables to pass on
|
|
293
|
-
noAutostart: false, // listen install --no-autostart: save settings only
|
|
294
|
-
session: null, // space ls|pull|push --session <session> | none: which workbench session to record the files under
|
|
295
|
-
reply: null, // chat send --reply <message id>
|
|
296
|
-
mentions: [], // chat send --mention <member> (repeatable; all = every Agent, owner = the owner)
|
|
297
|
-
wip: false, // chat send --wip: still working, the round stays open
|
|
298
|
-
options: [], // chat ask --option "<choice>" (repeatable; "label::note")
|
|
299
|
-
recommend: null, // chat ask --recommend <n> (1-based)
|
|
300
|
-
before: null, // chat read --before <message id>
|
|
301
|
-
done: null, // chat plan --done 1,2: steps that are finished (comma list)
|
|
302
|
-
doing: null, // chat plan --doing 3: steps in progress, parallel allowed (comma list)
|
|
303
281
|
how: null, // v0.37 setup ack --how exec|own|cron
|
|
304
282
|
test: null, // v0.37 setup ack --test <test id> (normally remembered from the wake-up event)
|
|
305
|
-
|
|
306
|
-
cursor: null, // chat list --cursor <next_cursor>
|
|
307
|
-
// v0.34: hire (being hired) — amounts are in the smallest unit (cents), times must carry a time zone
|
|
308
|
-
offerCents: null, // hire apply --offer-cents <分>: the daily usage I offer
|
|
309
|
-
modelLabel: null, // hire apply --model-label "<模型>": the model I mostly use (shown to the employer)
|
|
310
|
-
request: null, // hire decide --request <change request id>
|
|
311
|
-
accept: false, // hire decide --accept
|
|
312
|
-
rejectFlag: false, // hire decide --reject (not the same flag as --rejected-text)
|
|
313
|
-
lang: null, // hire sign --lang zh-CN|en: which language version of the agreement
|
|
314
|
-
occurredAt: null, // hire usage / habit --occurred-at <ISO time with zone>
|
|
315
|
-
items: [], // hire usage / habit --item "<model>:<in>:<out>:<cache write>:<cache read>" (repeatable)
|
|
316
|
-
itemsFile: null, // hire usage / habit --items-file <json>: an array of the same shape
|
|
317
|
-
instructionRef: null, // hire usage --instruction-ref <message id>: which arrangement this report answers
|
|
318
|
-
reportId: null, // hire usage / habit --report-id <id>: reuse on a retry so the platform counts it once
|
|
319
|
-
limit: null, // hire openings --limit <n>; space read --limit <chars per page>
|
|
283
|
+
limit: null, // space read --limit <chars per page>
|
|
320
284
|
form: null, // space read --form text|image|link (default: the platform picks)
|
|
321
285
|
offset: null, // space read --offset <chars>: next page of a long text
|
|
322
|
-
range: null, // hire usage-view --range day|week|month
|
|
323
|
-
date: null, // hire usage-view --date <date>
|
|
324
286
|
// v0.36: model policy / work folder / call records
|
|
325
|
-
primary: null, // model policy set / task apply
|
|
326
|
-
roles: [], // model policy set / task apply
|
|
287
|
+
primary: null, // model policy set / task apply --primary "<model>,<model>"
|
|
288
|
+
roles: [], // model policy set / task apply --role <work type>=<model> (repeatable; the work type is the Agent own wording)
|
|
327
289
|
recordMode: null, // model policy set --record-mode call|summary
|
|
328
|
-
scope: null, // usage collect / check --scope task:<id
|
|
290
|
+
scope: null, // usage collect / check --scope task:<id>
|
|
329
291
|
since: null, // usage collect / check --since <time | 30m / 6h / 3d>
|
|
330
|
-
dryRun: false, // usage collect --dry-run (count only, send nothing)
|
|
331
|
-
unreadable: null, // usage sample --unreadable "<reason>": no local log, send this reason instead (v0.37.4)
|
|
292
|
+
dryRun: false, // usage collect --dry-run (count only, send nothing)
|
|
332
293
|
path: null, // workdir open --path <dir>
|
|
333
294
|
};
|
|
334
295
|
const positionals = [];
|
|
@@ -612,76 +573,10 @@ export function parseArgs(argv) {
|
|
|
612
573
|
flags.tidy = true;
|
|
613
574
|
} else if (a === '--force') {
|
|
614
575
|
flags.force = true;
|
|
615
|
-
} else if (a === '--exec') {
|
|
616
|
-
flags.exec = args.shift() ?? null;
|
|
617
|
-
} else if (a === '--max-parallel') {
|
|
618
|
-
flags.maxParallel = args.shift() ?? null;
|
|
619
|
-
} else if (a === '--daily-max') {
|
|
620
|
-
flags.dailyMax = args.shift() ?? null;
|
|
621
|
-
} else if (a === '--timeout') {
|
|
622
|
-
flags.timeout = args.shift() ?? null;
|
|
623
|
-
} else if (a === '--cwd') {
|
|
624
|
-
flags.cwd = args.shift() ?? null;
|
|
625
|
-
} else if (a === '--env') {
|
|
626
|
-
const v = args.shift();
|
|
627
|
-
if (v != null && v !== '') flags.envNames.push(v);
|
|
628
|
-
} else if (a === '--no-autostart') {
|
|
629
|
-
flags.noAutostart = true;
|
|
630
|
-
} else if (a === '--session') {
|
|
631
|
-
flags.session = args.shift() ?? null;
|
|
632
|
-
} else if (a === '--reply') {
|
|
633
|
-
flags.reply = args.shift() ?? null;
|
|
634
|
-
} else if (a === '--mention') {
|
|
635
|
-
const v = args.shift();
|
|
636
|
-
if (v != null && v !== '') flags.mentions.push(v);
|
|
637
|
-
} else if (a === '--wip') {
|
|
638
|
-
flags.wip = true;
|
|
639
|
-
} else if (a === '--done') {
|
|
640
|
-
flags.done = args.shift() ?? null;
|
|
641
|
-
} else if (a === '--doing') {
|
|
642
|
-
flags.doing = args.shift() ?? null;
|
|
643
|
-
} else if (a === '--option') {
|
|
644
|
-
const v = args.shift();
|
|
645
|
-
if (v != null) flags.options.push(v);
|
|
646
|
-
} else if (a === '--recommend') {
|
|
647
|
-
flags.recommend = args.shift() ?? null;
|
|
648
|
-
} else if (a === '--before') {
|
|
649
|
-
flags.before = args.shift() ?? null;
|
|
650
576
|
} else if (a === '--how') {
|
|
651
577
|
flags.how = args.shift() ?? null;
|
|
652
578
|
} else if (a === '--test') {
|
|
653
579
|
flags.test = args.shift() ?? null;
|
|
654
|
-
} else if (a === '--ignore-new') {
|
|
655
|
-
flags.ignoreNew = true;
|
|
656
|
-
|
|
657
|
-
} else if (a === '--cursor') {
|
|
658
|
-
flags.cursor = args.shift() ?? null;
|
|
659
|
-
} else if (a === '--offer-cents') {
|
|
660
|
-
// v0.34: hire apply --offer-cents <分>(金额一律最小单位整数,非数字 -> NaN,由命令报参数错)
|
|
661
|
-
const v = args.shift();
|
|
662
|
-
flags.offerCents = v != null ? parseInt(v, 10) : null;
|
|
663
|
-
} else if (a === '--model-label') {
|
|
664
|
-
flags.modelLabel = args.shift() ?? null;
|
|
665
|
-
} else if (a === '--request') {
|
|
666
|
-
flags.request = args.shift() ?? null;
|
|
667
|
-
} else if (a === '--accept') {
|
|
668
|
-
flags.accept = true;
|
|
669
|
-
} else if (a === '--reject') {
|
|
670
|
-
// 注意:--rejected-text 是 task mark 的另一个开关,这里只认完整的 --reject
|
|
671
|
-
flags.rejectFlag = true;
|
|
672
|
-
} else if (a === '--lang') {
|
|
673
|
-
flags.lang = args.shift() ?? null;
|
|
674
|
-
} else if (a === '--occurred-at') {
|
|
675
|
-
flags.occurredAt = args.shift() ?? null;
|
|
676
|
-
} else if (a === '--item') {
|
|
677
|
-
const v = args.shift();
|
|
678
|
-
if (v != null && v !== '') flags.items.push(v);
|
|
679
|
-
} else if (a === '--items-file') {
|
|
680
|
-
flags.itemsFile = args.shift() ?? null;
|
|
681
|
-
} else if (a === '--instruction-ref') {
|
|
682
|
-
flags.instructionRef = args.shift() ?? null;
|
|
683
|
-
} else if (a === '--report-id') {
|
|
684
|
-
flags.reportId = args.shift() ?? null;
|
|
685
580
|
} else if (a === '--limit') {
|
|
686
581
|
const v = args.shift();
|
|
687
582
|
flags.limit = v != null ? parseInt(v, 10) : null;
|
|
@@ -690,10 +585,6 @@ export function parseArgs(argv) {
|
|
|
690
585
|
} else if (a === '--offset') {
|
|
691
586
|
const v = args.shift();
|
|
692
587
|
flags.offset = v != null ? Number(v) : null;
|
|
693
|
-
} else if (a === '--range') {
|
|
694
|
-
flags.range = args.shift() ?? null;
|
|
695
|
-
} else if (a === '--date') {
|
|
696
|
-
flags.date = args.shift() ?? null;
|
|
697
588
|
} else if (a === '--primary') {
|
|
698
589
|
flags.primary = args.shift() ?? null;
|
|
699
590
|
} else if (a === '--role') {
|
|
@@ -707,8 +598,6 @@ export function parseArgs(argv) {
|
|
|
707
598
|
flags.since = args.shift() ?? null;
|
|
708
599
|
} else if (a === '--dry-run') {
|
|
709
600
|
flags.dryRun = true;
|
|
710
|
-
} else if (a === '--unreadable') {
|
|
711
|
-
flags.unreadable = args.shift() ?? '';
|
|
712
601
|
} else if (a === '--path') {
|
|
713
602
|
flags.path = args.shift() ?? null;
|
|
714
603
|
} else if (a.startsWith('--')) {
|
|
@@ -719,7 +608,6 @@ export function parseArgs(argv) {
|
|
|
719
608
|
}
|
|
720
609
|
|
|
721
610
|
const [c0, c1, c2, c3] = positionals;
|
|
722
|
-
const SUBS = HIRE_SUBS;
|
|
723
611
|
let command;
|
|
724
612
|
let aliasOf = null; // set when the typed command is an old name of a renamed one
|
|
725
613
|
|
|
@@ -738,13 +626,6 @@ export function parseArgs(argv) {
|
|
|
738
626
|
} else if ((c0 === 'hall' || c0 === 'market') && (c1 === 'browse' || c1 === undefined)) {
|
|
739
627
|
// v0.32: the hall is called the market now; `market` is the new name, `hall browse` keeps working
|
|
740
628
|
command = 'hall:browse';
|
|
741
|
-
} else if (c0 === 'listen') {
|
|
742
|
-
// v0.32: stay connected (long waits on the poll event stream)
|
|
743
|
-
command = 'listen';
|
|
744
|
-
} else if (c0 === 'chat') {
|
|
745
|
-
// v0.32: anytowork chat list|read|send|ask|progress|need-workspace (none = show the help); v0.33 adds result
|
|
746
|
-
command = c1 === undefined ? 'chat:help'
|
|
747
|
-
: (['list', 'read', 'send', 'result', 'ask', 'progress', 'need-workspace', 'recall', 'group', 'plan'].includes(c1) ? `chat:${c1}` : 'unknown');
|
|
748
629
|
} else if (c0 === 'setup') {
|
|
749
630
|
// v0.37: settings after connecting: setup [check] | test-wake | ack <code> | checkin <minutes>
|
|
750
631
|
command = c1 === undefined ? 'setup:check'
|
|
@@ -754,6 +635,10 @@ export function parseArgs(argv) {
|
|
|
754
635
|
command = 'ping';
|
|
755
636
|
} else if (c0 === 'task') {
|
|
756
637
|
switch (c1) {
|
|
638
|
+
case undefined:
|
|
639
|
+
case 'help':
|
|
640
|
+
command = flags.help || c1 === 'help' ? 'task:help' : 'unknown';
|
|
641
|
+
break;
|
|
757
642
|
// M7 新增:任务信息查询 + 文件能力
|
|
758
643
|
case 'show': command = 'task:show'; break;
|
|
759
644
|
case 'files': command = 'task:files'; break;
|
|
@@ -767,6 +652,7 @@ export function parseArgs(argv) {
|
|
|
767
652
|
case 'continue': command = 'task:continue'; break; // v0.24.0: continue from accepted work
|
|
768
653
|
case 'apply': command = 'task:apply'; break;
|
|
769
654
|
case 'pass': command = 'task:pass'; break;
|
|
655
|
+
case 'withdraw': command = 'task:withdraw'; break; // withdraw pending application before poster selects anyone
|
|
770
656
|
case 'select': command = 'task:select'; break;
|
|
771
657
|
case 'accept': command = 'task:accept'; break;
|
|
772
658
|
case 'start': command = 'task:start'; break;
|
|
@@ -836,11 +722,6 @@ export function parseArgs(argv) {
|
|
|
836
722
|
} else if (c0 === 'discover') {
|
|
837
723
|
// v0.26.60: anytowork discover show <showcase_id>
|
|
838
724
|
command = c1 === 'show' ? 'discover:show' : 'unknown';
|
|
839
|
-
} else if (c0 === 'hire') {
|
|
840
|
-
// v0.34: anytowork hire policy|openings|show|apply|withdraw|pass|sign|decline|decide|mine|usage|habit|usage-view
|
|
841
|
-
// (none = show the help). `hire usage-view` is spelled as two words so it never collides with `hire usage`.
|
|
842
|
-
command = c1 === undefined ? 'hire:help'
|
|
843
|
-
: (SUBS.has(c1) ? `hire:${c1}` : 'unknown');
|
|
844
725
|
} else if (c0 === 'model') {
|
|
845
726
|
// v0.36: anytowork model policy show|set (none = show the help)
|
|
846
727
|
command = c1 === undefined ? 'model:help'
|
|
@@ -849,8 +730,8 @@ export function parseArgs(argv) {
|
|
|
849
730
|
// v0.36: anytowork workdir open|list
|
|
850
731
|
command = c1 === undefined ? 'workdir:help' : (['open', 'list'].includes(c1) ? `workdir:${c1}` : 'unknown');
|
|
851
732
|
} else if (c0 === 'usage') {
|
|
852
|
-
// v0.36: anytowork usage collect|push|check
|
|
853
|
-
command = c1 === undefined ? 'usage:help' : (['collect', 'push', 'check'
|
|
733
|
+
// v0.36: anytowork usage collect|push|check
|
|
734
|
+
command = c1 === undefined ? 'usage:help' : (['collect', 'push', 'check'].includes(c1) ? `usage:${c1}` : 'unknown');
|
|
854
735
|
} else if (c0 === 'space') {
|
|
855
736
|
// v0.31: anytowork space ls|pull|push (none = show the help)
|
|
856
737
|
command = c1 === undefined ? 'space:help' : (['ls', 'read', 'pull', 'push'].includes(c1) ? `space:${c1}` : 'unknown');
|
package/src/config.js
CHANGED
|
@@ -1,17 +1,46 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 平台地址解析。默认连官方平台,环境变量可覆盖指向本地或测试环境;
|
|
2
|
+
// 若未显式传环境变量,则沿用该 profile 登录时落盘的 base_url,最后回退官方默认地址。
|
|
2
3
|
//
|
|
3
|
-
// 优先级:ANYTOWORK_BASE_URL > A2A_BASE_URL > 官方默认。
|
|
4
|
+
// 优先级:ANYTOWORK_BASE_URL > A2A_BASE_URL > savedBaseUrl(凭证记录) > 官方默认。
|
|
4
5
|
// (A2A_BASE_URL 与后端 oauth.py 同名,运维同一变量即可统一切换。)
|
|
5
6
|
|
|
6
7
|
/** 官方默认平台地址(CTO 拍板·M3 前提)。 */
|
|
7
8
|
export const DEFAULT_BASE_URL = 'https://anytowork.com';
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* 归一历史旧正式域名到当前官方默认地址,避免早期登录的正式档案被误判为测试环境或打向退役域名。
|
|
12
|
+
* @param {string|null|undefined} url
|
|
13
|
+
* @returns {string|null}
|
|
14
|
+
*/
|
|
15
|
+
export function normalizeSavedBaseUrl(url) {
|
|
16
|
+
if (!url || url === '(未记录)') return null;
|
|
17
|
+
const clean = String(url).trim().replace(/\/+$/, '');
|
|
18
|
+
if (!clean) return null;
|
|
19
|
+
if (/^https?:\/\/a2a\.[^/]+\.chimap\.cn$/i.test(clean)) return DEFAULT_BASE_URL;
|
|
20
|
+
return clean;
|
|
21
|
+
}
|
|
22
|
+
|
|
9
23
|
/**
|
|
10
24
|
* 解析平台基础地址。
|
|
11
25
|
* @param {Record<string,string>} env 环境变量字典(默认 process.env,传入便于单测)
|
|
26
|
+
* @param {string|null} [savedBaseUrl] 当前 profile 凭证中已记录的 base_url
|
|
12
27
|
* @returns {string} 去掉末尾斜杠的平台地址
|
|
13
28
|
*/
|
|
14
|
-
export function resolveBaseUrl(env = process.env) {
|
|
15
|
-
const
|
|
16
|
-
|
|
29
|
+
export function resolveBaseUrl(env = process.env, savedBaseUrl = null) {
|
|
30
|
+
const fromEnv = env && (env.ANYTOWORK_BASE_URL || env.A2A_BASE_URL);
|
|
31
|
+
const raw = fromEnv || normalizeSavedBaseUrl(savedBaseUrl) || DEFAULT_BASE_URL;
|
|
32
|
+
return String(raw).replace(/\/+$/, '');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 将凭证中记录的 base_url 映射为可读中文环境标签(不写死任何内部测试服域名)。
|
|
37
|
+
* @param {string|null|undefined} url
|
|
38
|
+
* @returns {string} '[正式环境]' | '[测试环境]' | '[本地开发]' | ''
|
|
39
|
+
*/
|
|
40
|
+
export function envTagOfUrl(url) {
|
|
41
|
+
const clean = normalizeSavedBaseUrl(url);
|
|
42
|
+
if (!clean) return '';
|
|
43
|
+
if (clean === DEFAULT_BASE_URL) return '[正式环境]';
|
|
44
|
+
if (/^https?:\/\/(?:localhost|127\.0\.0\.1)(?::\d+)?$/i.test(clean)) return '[本地开发]';
|
|
45
|
+
return '[测试环境]';
|
|
17
46
|
}
|