@anytowork/cli 0.12.63 → 0.12.65
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 +1 -1
- package/src/connect.js +10 -3
- package/src/format.js +2 -2
- package/src/index.js +3 -1
- package/src/listener/hire-wake.js +1 -1
- package/src/network-hint.js +38 -0
- package/src/setup-commands.js +2 -2
package/package.json
CHANGED
package/src/connect.js
CHANGED
|
@@ -61,9 +61,16 @@ export function explainError(kind, ctx = {}) {
|
|
|
61
61
|
next: `请先让主人在 ${BRAND.name} 的「绑定 Agent」页获取接入码,再运行:anytowork auth login --code <接入码> --product "<你是哪款 Agent 产品>"`,
|
|
62
62
|
};
|
|
63
63
|
case 'code_invalid':
|
|
64
|
+
// v0.12.65: a copied code often has two neighbouring letters swapped; compare it with the original before asking for a new one.
|
|
65
|
+
if (ctx.lang === 'en') {
|
|
66
|
+
return {
|
|
67
|
+
message: 'The access code is invalid or expired (it may also have been used once already).',
|
|
68
|
+
next: `First compare the code you used with the message you received, character by character (watch for neighbouring letters in the wrong order), and run again if they differ. If they match, ask your owner for a new access code on the "Bind Agent" page of ${BRAND.name}.`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
64
71
|
return {
|
|
65
72
|
message: '接入码无效或已过期(也可能已经被用过一次)。',
|
|
66
|
-
next:
|
|
73
|
+
next: `请先把你用的码与收到的原文逐字符核对(注意相邻字母的顺序),不一致就改对后重新运行;一致的话,再让主人回到 ${BRAND.name} 的「绑定 Agent」页换一个新的接入码。`,
|
|
67
74
|
};
|
|
68
75
|
case 'pending_exists':
|
|
69
76
|
return {
|
|
@@ -248,11 +255,11 @@ export async function runConnect(opts = {}) {
|
|
|
248
255
|
|
|
249
256
|
/** Print a failure (text or JSON) and return exit code 1/2. */
|
|
250
257
|
const fail = (kind, ctx = {}, exitCode = 1, extra = {}) => {
|
|
251
|
-
const { message, next } = explainError(kind, { baseUrl, profile, ...ctx });
|
|
258
|
+
const { message, next } = explainError(kind, { baseUrl, profile, lang: pickLang(env), ...ctx });
|
|
252
259
|
if (json) {
|
|
253
260
|
log(JSON.stringify({ ok: false, status: ctx.status || kind, error: kind, message, next_step: next, ...extra }));
|
|
254
261
|
} else {
|
|
255
|
-
err(`${message}\n
|
|
262
|
+
err(`${message}\n${kind === 'code_invalid' && pickLang(env) === 'en' ? 'Next: ' : '下一步:'}${next}`);
|
|
256
263
|
}
|
|
257
264
|
return exitCode;
|
|
258
265
|
};
|
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
|
|
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
|
-
|
|
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
|
|
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
|
+
}
|
package/src/setup-commands.js
CHANGED
|
@@ -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: '
|
|
39
|
-
shopWait: { zh: ' 店铺(shop: {stage}
|
|
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)' },
|