@anytowork/cli 0.12.63 → 0.12.64

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anytowork/cli",
3
- "version": "0.12.63",
3
+ "version": "0.12.64",
4
4
  "description": "AnytoWork 平台命令行工具——让任何能执行 shell 命令的 Agent 用一条命令接入 AnytoWork:登录、发单接单、管理能力。",
5
5
  "type": "module",
6
6
  "bin": {
package/src/format.js CHANGED
@@ -1126,8 +1126,8 @@ export function formatPoll(data, { json = false, isFirstRun = false, activeTasks
1126
1126
  /** Lines under a hire.* event (empty for every other event). */
1127
1127
  export function hireEventLines(e) {
1128
1128
  const t = e && e.event_type;
1129
- // v0.38.57: the owner's shop opened (shop.opened): orders and job seeking take effect now, tell the owner
1130
- if (t === 'shop.opened') return [' 主人的店已开张,接单和求职已生效,请告诉主人'];
1129
+ // v0.38.57: the owner's shop opened (shop.opened): orders and job seeking can be turned on now, tell the owner
1130
+ if (t === 'shop.opened') return [' 主人的店铺开张了,接单和求职现在可以开启,请告诉主人'];
1131
1131
  if (!t || !String(t).startsWith('hire.')) return [];
1132
1132
  const p = (e && e.payload) || {};
1133
1133
  const ind = ' ';
package/src/index.js CHANGED
@@ -126,6 +126,7 @@ import { runRefund, isRefundCommand } from './refund-commands.js';
126
126
  import { runDiscover, isDiscoverCommand } from './discover-commands.js';
127
127
  import { runExtension } from './extension-commands.js';
128
128
  import { mapApiError } from './error-map.js';
129
+ import { withNetworkHint } from './network-hint.js';
129
130
  import { runContinue } from './cont-commands.js';
130
131
  import { runSpace, runTaskWorkspace, isSpaceCommand, isTaskWorkspaceCommand, SPACE_HELP, TASK_WORKSPACE_HELP } from './space-commands.js';
131
132
  import { runListen, LISTEN_HELP } from './listen-command.js';
@@ -735,7 +736,8 @@ async function runCore(argv, deps = {}, ctx = {}) {
735
736
  const env = deps.env || process.env;
736
737
  setHintEnv(env);
737
738
  const credDir = deps.credDir; // undefined → 用默认 ~/.anytowork(或 --profile 目录)
738
- const fetchImpl = deps.fetchImpl; // undefined → api 函数用全局 fetch
739
+ // v0.12.64: one wrapper for every command: a failed network request gets the same general hint (see network-hint.js)
740
+ const fetchImpl = withNetworkHint((...a) => (deps.fetchImpl || globalThis.fetch)(...a), env);
739
741
 
740
742
  const { command, flags, positionals, retiredKey, aliasOf } = parseArgs(argv);
741
743
  const baseUrl = resolveBaseUrl(env);
@@ -27,7 +27,7 @@ export function hireEventExpired(e, nowMs) {
27
27
  }
28
28
 
29
29
  const EN_LINE = {
30
- 'shop.opened': () => '- Your owner\'s shop is open: orders and job seeking are in effect now, tell your owner',
30
+ 'shop.opened': () => '- Your owner\'s shop is open: orders and job seeking can be turned on now, tell your owner',
31
31
  'hire.to_sign': (p) => `- You were picked for a hire${p.title ? ` "${p.title}"` : ''}${p.deadline_at ? `, sign before ${p.deadline_at}` : ''}: anytowork hire sign ${p.hire_id || '<hire id>'} (or hire decline)`,
32
32
  'hire.topup': (p) => `- ${p.reminder ? 'Reminder: ' : ''}the employer paid a top-up for today${p.deadline_at ? `, answer before ${p.deadline_at}` : ''}; no answer in time = a full refund: anytowork hire topup ${p.hire_id || '<hire id>'} --accept | --reject`,
33
33
  'hire.reschedule': (p) => `- The employer asks to move the start date to ${p.new_start_date || 'a new date'}: anytowork hire decide ${p.hire_id || '<hire id>'} --request ${p.request_id || '<request id>'} --accept | --reject`,
@@ -0,0 +1,38 @@
1
+ // v0.12.64: one general hint for a failed network request. Sandboxed environments often block outgoing connections, and
2
+ // then every command ends in the bare "fetch failed"; the Agent cannot tell that this is something to ask for.
3
+ // runCore wraps its fetch once with this, so every command (also --json) gets the same line and nothing else changes.
4
+
5
+ import { pickLang } from "./model-pledge.js";
6
+
7
+ const NETWORK_CODES = new Set([
8
+ "ENOTFOUND", "ECONNREFUSED", "ECONNRESET", "ETIMEDOUT", "EAI_AGAIN", "EHOSTUNREACH", "ENETUNREACH", "ENETDOWN",
9
+ "UND_ERR_CONNECT_TIMEOUT", "UND_ERR_SOCKET",
10
+ ]);
11
+
12
+ const HINT = {
13
+ zh: "提示:多半是当前环境禁止联网(比如沙箱)。请申请放行网络访问后重试。",
14
+ en: "Hint: this usually means the current environment blocks network access (a sandbox, for example). Ask to allow network access, then try again.",
15
+ };
16
+
17
+ /** True for a request that never got an HTTP answer: Node's "fetch failed" or a socket error code. */
18
+ export function isNetworkError(e) {
19
+ if (!e || typeof e !== "object" || e.status) return false;
20
+ const code = e.code || (e.cause && e.cause.code);
21
+ if (code && NETWORK_CODES.has(code)) return true;
22
+ return /fetch failed/i.test(String(e.message || ""));
23
+ }
24
+
25
+ /** Wrap a fetch function: a network failure gets the hint as a second line of its message (once); all else passes. */
26
+ export function withNetworkHint(fetchFn, env = process.env) {
27
+ return async (...args) => {
28
+ try {
29
+ return await fetchFn(...args);
30
+ } catch (e) {
31
+ if (isNetworkError(e) && !e.networkHinted) {
32
+ e.message = `${e.message}\n${HINT[pickLang(env)]}`;
33
+ e.networkHinted = true;
34
+ }
35
+ throw e;
36
+ }
37
+ };
38
+ }
@@ -35,8 +35,8 @@ const TEXT = {
35
35
  wakeTodo: { zh: ' ✗ 能被叫醒:还没验收。不用问主人,自己按 {url} 配好(方案 A 常驻监听;A 不可用时方案 B 每分钟 poll),再运行 anytowork setup test-wake', en: ' ✗ Be wakeable: not verified yet. Do not ask your owner: set it up following {url} (Plan A, the always-on listener; Plan B, a poll every minute, when A is unavailable), then run anytowork setup test-wake' },
36
36
  modelDone: { zh: ' ✓ 说明你用的模型:已说明', en: ' ✓ Say which models you use: done' },
37
37
  modelTodo: { zh: ' ✗ 说明你用的模型:还没说明。自己判断用的模型(读自己的配置或日志,必要时 anytowork usage sample --from <目录> --dry-run,读不到如实说),去 {url}#model-policy 照做,设一次默认策略就行', en: ' ✗ Say which models you use: not stated yet. Work out your models yourself (read your own config or logs, and if needed anytowork usage sample --from <dir> --dry-run; say so if you cannot tell), then follow {url}#model-policy; one default policy is enough' },
38
- shopOpen: { zh: ' 店铺(shop):已开张,接单和求职已生效', en: ' Shop: open, orders and jobs are in effect' },
39
- shopWait: { zh: ' 店铺(shop: {stage}):主人的店还没开张,接单和求职已保存但还不生效。{hint}', en: ' Shop ({stage}): your owner\'s shop is not open yet, order and job settings are saved but not in effect. {hint}' },
38
+ shopOpen: { zh: ' 接单和求职:现在可以开启,由主人在「我的团队」里决定、配置;你只转述,不替主人开启', en: ' Orders and jobs: can be turned on now. Your owner decides and sets them up in My Team; only pass this on, do not turn them on for your owner' },
39
+ shopWait: { zh: ' 店铺(shop: {stage}):主人的店还没开张,开张前接单和求职都开始不了。{hint}', en: ' Shop ({stage}): your owner\'s shop is not open yet; orders and jobs cannot start before it opens. {hint}' },
40
40
  cliOk: { zh: ' 命令行:已是最新', en: ' Command line: up to date' },
41
41
  cliTodo: { zh: ' ✗ 命令行:需要升级(现在 {cur},至少 {min})。自己运行 {cmd},用 anytowork --version 确认', en: ' ✗ Command line: upgrade needed (now {cur}, at least {min}). Run {cmd} yourself and confirm with anytowork --version' },
42
42
  checkinDone: { zh: ' ✓ 检查间隔:已报告(每 {n} 分钟)', en: ' ✓ Check-in interval: reported (every {n} minutes)' },