@anytowork/cli 0.12.73 → 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 +2 -0
- package/package.json +1 -1
- package/src/api.js +15 -0
- package/src/apply-backoff.js +4 -1
- package/src/cli-parse.js +5 -0
- package/src/config.js +34 -5
- package/src/connect.js +20 -1
- package/src/error-map.js +56 -0
- package/src/format.js +53 -1
- package/src/index.js +57 -15
package/README.md
CHANGED
|
@@ -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 新增)
|
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -629,6 +629,21 @@ export async function passTask(baseUrl, credOpts = {}, taskId, body, idempotency
|
|
|
629
629
|
return authedPostWithRefresh(baseUrl, `/api/v1/tasks/${encodeURIComponent(taskId)}/pass`, credOpts, body, idempotencyKey, opts);
|
|
630
630
|
}
|
|
631
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
|
+
|
|
632
647
|
/**
|
|
633
648
|
* 买方选中某申请人。
|
|
634
649
|
* @param {object} credOpts 凭证目录选项 { dir? }
|
package/src/apply-backoff.js
CHANGED
|
@@ -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
|
@@ -635,6 +635,10 @@ export function parseArgs(argv) {
|
|
|
635
635
|
command = 'ping';
|
|
636
636
|
} else if (c0 === 'task') {
|
|
637
637
|
switch (c1) {
|
|
638
|
+
case undefined:
|
|
639
|
+
case 'help':
|
|
640
|
+
command = flags.help || c1 === 'help' ? 'task:help' : 'unknown';
|
|
641
|
+
break;
|
|
638
642
|
// M7 新增:任务信息查询 + 文件能力
|
|
639
643
|
case 'show': command = 'task:show'; break;
|
|
640
644
|
case 'files': command = 'task:files'; break;
|
|
@@ -648,6 +652,7 @@ export function parseArgs(argv) {
|
|
|
648
652
|
case 'continue': command = 'task:continue'; break; // v0.24.0: continue from accepted work
|
|
649
653
|
case 'apply': command = 'task:apply'; break;
|
|
650
654
|
case 'pass': command = 'task:pass'; break;
|
|
655
|
+
case 'withdraw': command = 'task:withdraw'; break; // withdraw pending application before poster selects anyone
|
|
651
656
|
case 'select': command = 'task:select'; break;
|
|
652
657
|
case 'accept': command = 'task:accept'; break;
|
|
653
658
|
case 'start': command = 'task:start'; break;
|
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
|
}
|
package/src/connect.js
CHANGED
|
@@ -17,6 +17,7 @@ import path from 'node:path';
|
|
|
17
17
|
import fs from 'node:fs';
|
|
18
18
|
|
|
19
19
|
import { saveCredentials, loadCredentials } from './credentials.js';
|
|
20
|
+
import { normalizeSavedBaseUrl } from './config.js';
|
|
20
21
|
import { resolveCredDir } from './profile.js';
|
|
21
22
|
import { atomicWriteFile } from './atomic-write.js';
|
|
22
23
|
import { clientHeaders, CLI_VERSION, UPGRADE_COMMAND } from './client-version.js';
|
|
@@ -119,6 +120,13 @@ export function explainError(kind, ctx = {}) {
|
|
|
119
120
|
next: `同一台电脑上接另一个 Agent,请单独建一个空间:anytowork ${flag} auth login --code <接入码> --product "<你是哪款 Agent 产品>"(也可以用环境变量 ANYTOWORK_CONFIG_DIR 指向另一个目录)。这个接入码还没有被使用。`,
|
|
120
121
|
};
|
|
121
122
|
}
|
|
123
|
+
case 'cross_env_profile': {
|
|
124
|
+
const slug = ctx.profile ? `test-${ctx.profile.replace(/^test-/, '')}` : 'test-<名字>';
|
|
125
|
+
return {
|
|
126
|
+
message: `当前档案已绑定在另一个环境(${ctx.existingBaseUrl || '其他环境'}),不能直接覆盖成 ${ctx.baseUrl || '当前环境'}。`,
|
|
127
|
+
next: `测试环境与正式环境必须分档案隔离,请换独立档案重新运行:ANYTOWORK_BASE_URL=${ctx.baseUrl || '<环境地址>'} anytowork --profile ${slug} auth login --code <接入码> --product "<你是哪款 Agent 产品>"。这个接入码还没有被使用。`,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
122
130
|
case 'no_pending':
|
|
123
131
|
return {
|
|
124
132
|
message: '这个空间里没有正在等待确认的接入请求。',
|
|
@@ -231,7 +239,7 @@ function clearPending(credOpts) {
|
|
|
231
239
|
* @returns {Promise<number>}
|
|
232
240
|
*/
|
|
233
241
|
export async function runConnect(opts = {}) {
|
|
234
|
-
|
|
242
|
+
let {
|
|
235
243
|
baseUrl, code, product, noWait = false, resume = false, json = false, profile = null, credDir,
|
|
236
244
|
env = process.env, log = console.log, err = console.error,
|
|
237
245
|
fetchImpl = fetch,
|
|
@@ -243,6 +251,12 @@ export async function runConnect(opts = {}) {
|
|
|
243
251
|
} = opts;
|
|
244
252
|
|
|
245
253
|
const credOpts = credDir ? { dir: credDir } : { profile };
|
|
254
|
+
if (resume) {
|
|
255
|
+
const prePending = loadPending(credOpts);
|
|
256
|
+
if (!(env && (env.ANYTOWORK_BASE_URL || env.A2A_BASE_URL)) && prePending && prePending.base_url) {
|
|
257
|
+
baseUrl = String(prePending.base_url).replace(/\/+$/, '');
|
|
258
|
+
}
|
|
259
|
+
}
|
|
246
260
|
// Notes for a human or an Agent reading the output. In --json mode they move to stderr so stdout stays one JSON object.
|
|
247
261
|
const say = (line) => (json ? err(line) : log(line));
|
|
248
262
|
const docsUrl = `${baseUrl}/docs/guide/auto-accept`;
|
|
@@ -303,6 +317,11 @@ export async function runConnect(opts = {}) {
|
|
|
303
317
|
const existing = loadCredentials(credOpts);
|
|
304
318
|
let existingAgentId = null;
|
|
305
319
|
if (existing && existing.access_token) {
|
|
320
|
+
const existingBase = normalizeSavedBaseUrl(existing.base_url) || '';
|
|
321
|
+
const targetBase = normalizeSavedBaseUrl(baseUrl) || String(baseUrl).trim().replace(/\/+$/, '');
|
|
322
|
+
if (existingBase && existingBase !== targetBase) {
|
|
323
|
+
return fail('cross_env_profile', { existingBaseUrl: existingBase, baseUrl: targetBase }, 1);
|
|
324
|
+
}
|
|
306
325
|
existingAgentId = existing.agent_id || decodeAgentId(existing.access_token) || null;
|
|
307
326
|
let alive = false;
|
|
308
327
|
try {
|
package/src/error-map.js
CHANGED
|
@@ -130,6 +130,62 @@ export function mapApiError(e, { json = false, webBase = '' } = {}) {
|
|
|
130
130
|
return { exit: 1, text: OUTRANKED_TEXT, toStdout: false };
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
// Pending application slots are full (HTTP 409): list occupying tasks and suggest waiting or `task withdraw`.
|
|
134
|
+
if (code === 'apply_slots_full') {
|
|
135
|
+
const s = body.apply_slots && typeof body.apply_slots === 'object' ? body.apply_slots : null;
|
|
136
|
+
const slotText = s && s.used != null && s.limit != null ? `(${s.used}/${s.limit})` : '';
|
|
137
|
+
const occ = Array.isArray(body.occupying_tasks) ? body.occupying_tasks : [];
|
|
138
|
+
const ids = occ.map((t) => (typeof t === 'string' ? t : t && t.task_id)).filter(Boolean);
|
|
139
|
+
const head = `待选名额已满${slotText}。${ids.length ? `当前占名额的待选单:${ids.join('、')}。` : ''}`;
|
|
140
|
+
if (json) {
|
|
141
|
+
return { exit: 1, text: JSON.stringify({ ok: false, ...body, error: code, message: body.message || head }), toStdout: true };
|
|
142
|
+
}
|
|
143
|
+
const stageWords = { collecting: '收集窗内', shortlisted: '候选名单内', published: '候选名单内' };
|
|
144
|
+
const lines = [head];
|
|
145
|
+
for (const t of occ) {
|
|
146
|
+
if (t && typeof t === 'object' && t.task_id && (t.title || t.stage)) {
|
|
147
|
+
const st = t.stage ? `(${stageWords[t.stage] || t.stage})` : '';
|
|
148
|
+
lines.push(` • ${t.task_id}${t.title ? ` 《${t.title}》` : ''}${st}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
lines.push(' 可等待发起方选人,或运行 anytowork task withdraw <task_id> 撤回把握较小的一笔后再申请。');
|
|
152
|
+
return { exit: 1, text: lines.join('\n'), toStdout: false };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Re-applying to a task previously withdrawn by the same seller (HTTP 409).
|
|
156
|
+
if (code === 'apply_withdrawn') {
|
|
157
|
+
const msg = body.message || '你之前已主动撤回过这一单的报名,同一任务撤回后不能再次报名。';
|
|
158
|
+
if (json) return { exit: 1, text: JSON.stringify({ ok: false, ...body, error: code, message: msg }), toStdout: true };
|
|
159
|
+
return { exit: 1, text: `${msg}【${code}】\n 同一任务撤回后不可再次报名,请跳过本单,不要重试。`, toStdout: false };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Rolling 24h cap on applying or withdrawing: wait for Retry-After / recover_at, do not loop retry.
|
|
163
|
+
if (code === 'apply_daily_limit' || code === 'withdraw_daily_limit') {
|
|
164
|
+
const fallback = code === 'apply_daily_limit' ? '已达到 24 小时滚动报名上限' : '已达到 24 小时主动撤回报名上限';
|
|
165
|
+
const msg = body.message || fallback;
|
|
166
|
+
const ra = e && Number.isFinite(Number(e.retryAfter)) && Number(e.retryAfter) > 0 ? Math.ceil(Number(e.retryAfter)) : null;
|
|
167
|
+
if (json) {
|
|
168
|
+
const out = { ok: false, ...body, error: code, message: msg };
|
|
169
|
+
if (ra != null && out.retry_after == null) out.retry_after = ra;
|
|
170
|
+
return { exit: 1, text: JSON.stringify(out), toStdout: true };
|
|
171
|
+
}
|
|
172
|
+
const waitHint = body.recover_at
|
|
173
|
+
? `请等待至 ${body.recover_at} 恢复后再操作,不要反复重试。`
|
|
174
|
+
: (ra != null ? `请等待约 ${ra} 秒恢复后再操作,不要反复重试。` : '请等待额度滚动恢复后再操作,不要反复重试。');
|
|
175
|
+
return { exit: 1, text: `${msg}【${code}】\n ${waitHint}`, toStdout: false };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Trying to `task withdraw` an application that is no longer `pending` (e.g. already picked / started).
|
|
179
|
+
if (code === 'withdraw_not_pending' || code === 'already_selected' || code === 'withdraw_already_picked') {
|
|
180
|
+
const msg = body.message || '当前报名已不在选人前待选状态,不能撤回报名';
|
|
181
|
+
if (json) return { exit: 1, text: JSON.stringify({ ok: false, ...body, error: code, message: msg }), toStdout: true };
|
|
182
|
+
return {
|
|
183
|
+
exit: 1,
|
|
184
|
+
text: `${msg}【${code}】\n 若已被选中、尚未确认接单,请改用 anytowork task decline-pick <task_id> --reason <理由键> --note "<一句话说明>";若已接单开工,请改用 anytowork task abandon。`,
|
|
185
|
+
toStdout: false,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
133
189
|
if (code === 'deliverable_refunded') {
|
|
134
190
|
const note = '这单已全额退款,交付物已归还接单方;这是规则,不是网络问题,不用重试。';
|
|
135
191
|
if (json) return { exit: 1, text: JSON.stringify({ ok: false, error: code, message: body.message || note }), toStdout: true };
|
package/src/format.js
CHANGED
|
@@ -275,12 +275,34 @@ export function formatTaskApply(data, { json = false, env, sentPolicy = true } =
|
|
|
275
275
|
if (data.quote_cents != null) lines.push(` 我的报价(整单成交价):${moneyText(data.quote_cents, data.currency)}`);
|
|
276
276
|
if (data.status) lines.push(` 申请状态:${applicationStatusText(data.status)}`);
|
|
277
277
|
if (data.task_status) lines.push(` 任务当前状态:${data.task_status}`);
|
|
278
|
+
const s = data && data.apply_slots && typeof data.apply_slots === 'object' ? data.apply_slots : null;
|
|
279
|
+
if (s && s.used != null && s.limit != null) {
|
|
280
|
+
const rem = s.available != null ? `,剩余 ${s.available}` : '';
|
|
281
|
+
lines.push(` 当前待选名额:${s.used}/${s.limit}${rem}(公布后若转入候补将自动释放名额)`);
|
|
282
|
+
}
|
|
278
283
|
if (data.sim_notice) lines.push(` ⚠ ${simNoticeText(data.sim_notice)}`);
|
|
279
284
|
// v0.27.25: the models the platform stored (normalised names), the notes, and the promise reminder
|
|
280
285
|
lines.push(...describeApplyModels(data, env, { sentPolicy }));
|
|
281
286
|
return lines.join('\n');
|
|
282
287
|
}
|
|
283
288
|
|
|
289
|
+
/**
|
|
290
|
+
* 格式化选人前撤回报名结果(`anytowork task withdraw <task_id>`)。
|
|
291
|
+
* @param {object} data { withdrawn, task_id, apply_slots?, slot_released? }
|
|
292
|
+
*/
|
|
293
|
+
export function formatTaskWithdraw(data, { json = false } = {}) {
|
|
294
|
+
if (json) return asJson(data);
|
|
295
|
+
const s = data && data.apply_slots && typeof data.apply_slots === 'object' ? data.apply_slots : null;
|
|
296
|
+
if (s && s.used != null && s.limit != null) {
|
|
297
|
+
const rem = s.available != null ? `,剩余 ${s.available}` : '';
|
|
298
|
+
if (data && data.slot_released === false) {
|
|
299
|
+
return `已撤回报名(当前已用 ${s.used}/${s.limit}${rem};本单不可再次报名)`;
|
|
300
|
+
}
|
|
301
|
+
return `已撤回报名,释放 1 个待选名额(当前已用 ${s.used}/${s.limit}${rem};本单不可再次报名)`;
|
|
302
|
+
}
|
|
303
|
+
return '已撤回报名(本单不可再次报名)';
|
|
304
|
+
}
|
|
305
|
+
|
|
284
306
|
/**
|
|
285
307
|
* 格式化买方选人结果。
|
|
286
308
|
* @param {object} data { task_id, status, selected_application_id }
|
|
@@ -461,6 +483,17 @@ export function formatCruise(data, { json = false } = {}) {
|
|
|
461
483
|
for (const t of sellerTasks) lines.push(...cruiseTaskLines(t));
|
|
462
484
|
}
|
|
463
485
|
|
|
486
|
+
if (data.apply_slots && typeof data.apply_slots === 'object' && data.apply_slots.limit != null) {
|
|
487
|
+
const s = data.apply_slots;
|
|
488
|
+
const occ = Array.isArray(data.pending_applications) ? data.pending_applications : [];
|
|
489
|
+
lines.push('');
|
|
490
|
+
lines.push(`我待选的报名(占名额 ${s.used ?? 0}/${s.limit},剩余 ${s.available ?? Math.max(0, s.limit - (s.used ?? 0))}):${occ.length === 0 ? '无' : ''}`);
|
|
491
|
+
for (const p of occ) {
|
|
492
|
+
const stageTxt = p.stage === 'collecting' ? '收集窗内' : '已入围待选';
|
|
493
|
+
lines.push(` • 任务 ${p.task_id}${p.title ? `「${p.title}」` : ''}(${stageTxt})`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
464
497
|
// ── 待处理事件(最多展示 10 条,全量用 --json)──
|
|
465
498
|
lines.push('');
|
|
466
499
|
if (events.length === 0) {
|
|
@@ -1085,7 +1118,23 @@ export function formatPoll(data, { json = false, isFirstRun = false, activeTasks
|
|
|
1085
1118
|
const noteRef = e.event_type === 'task_revision_extension_requested' ? '' : revisionNoteRef(e.payload);
|
|
1086
1119
|
// v0.23.31: the platform marks events about a task my own user published
|
|
1087
1120
|
const ownRef = e.own_task === true ? '(你发布的任务)' : '';
|
|
1088
|
-
|
|
1121
|
+
let slotsRef = '';
|
|
1122
|
+
if (e.event_type === 'new_task_matched' && e.own_task !== true) {
|
|
1123
|
+
const slots = (e && e.apply_slots) || (e && e.payload && e.payload.apply_slots) || data.apply_slots || null;
|
|
1124
|
+
if (slots && typeof slots === 'object' && slots.limit != null) {
|
|
1125
|
+
const limit = Number(slots.limit);
|
|
1126
|
+
const used = slots.used != null ? Number(slots.used) : (slots.available != null ? limit - Number(slots.available) : null);
|
|
1127
|
+
const avail = slots.available != null ? Number(slots.available) : (used != null ? Math.max(0, limit - used) : null);
|
|
1128
|
+
if (avail === 0) {
|
|
1129
|
+
const occ = Array.isArray(data.occupying_tasks) ? data.occupying_tasks : [];
|
|
1130
|
+
const occTxt = occ.length > 0 ? `;当前占名额单:${occ.slice(0, 3).map((o) => o.task_id).join('、')}${occ.length > 3 ? ' 等' : ''}` : '';
|
|
1131
|
+
slotsRef = ` [待选名额已满 ${used != null ? used : limit}/${limit}${occTxt};如需申请本单,可先运行 anytowork task withdraw <task_id> 撤回一笔旧待选单]`;
|
|
1132
|
+
} else if (avail != null) {
|
|
1133
|
+
slotsRef = ` [待选名额剩余 ${avail}/${limit}]`;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
lines.push(` • ${isUrgentEvent(e) ? '⏰ 优先 ' : ''}#${e.id} ${e.event_type}${taskRef}${ownRef}${noteRef}${slotsRef}`);
|
|
1089
1138
|
// a new comment on a task: say who wrote it and whom it answers (the text itself: `anytowork qa <task_id> --list`)
|
|
1090
1139
|
if (e.event_type === 'comment_posted' && e.payload) {
|
|
1091
1140
|
const p = e.payload;
|
|
@@ -1261,6 +1310,9 @@ function safetyEventDetailLines(e) {
|
|
|
1261
1310
|
if (t === 'application_closed') {
|
|
1262
1311
|
return [`${ind}你在任务 ${p.task_id || ''} 的报名已关闭,该任务不再向你开放。`];
|
|
1263
1312
|
}
|
|
1313
|
+
if (t === 'application_waitlisted') {
|
|
1314
|
+
return [`${ind}你的报名已转入候补(不占用待选名额,无需撤回;前面空出位置或发起方展开更多候选时会再通知你)`];
|
|
1315
|
+
}
|
|
1264
1316
|
if (t === 'contact_block_changed') {
|
|
1265
1317
|
return [`${ind}${p.action === 'unblock' ? '已取消屏蔽' : '已屏蔽'}用户 ${p.user_id || ''}${p.via ? `(来源:${p.via})` : ''}`];
|
|
1266
1318
|
}
|
package/src/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { BRAND } from './brand.js';
|
|
|
11
11
|
import { parseArgs } from './cli-parse.js';
|
|
12
12
|
import { buildAskQuestions, buildAnswers } from './collab-input.js';
|
|
13
13
|
import { RETIRED_COMMANDS } from './retired-commands.js';
|
|
14
|
-
import { resolveBaseUrl } from './config.js';
|
|
14
|
+
import { resolveBaseUrl, envTagOfUrl, normalizeSavedBaseUrl } from './config.js';
|
|
15
15
|
import { configRootFromEnv, defaultRootDir, isValidProfileName, profileRootFromEnv, profileDir, resolveCredDir } from './profile.js';
|
|
16
16
|
import { loadCredentials } from './credentials.js';
|
|
17
17
|
import { runAuthLogin } from './oauth.js';
|
|
@@ -63,6 +63,7 @@ import {
|
|
|
63
63
|
getRestrictions,
|
|
64
64
|
// P19: review tags come from the platform
|
|
65
65
|
getReviewsConfig,
|
|
66
|
+
withdrawTaskApplication,
|
|
66
67
|
} from './api.js';
|
|
67
68
|
import { REASON_CODES, reasonHelpLine } from './exit-reasons.js';
|
|
68
69
|
import { checkTaskText, checkAttachment, limitError } from './input-limits.js';
|
|
@@ -71,6 +72,7 @@ import {
|
|
|
71
72
|
formatTaskCreate,
|
|
72
73
|
formatPrecheckReview,
|
|
73
74
|
formatTaskApply,
|
|
75
|
+
formatTaskWithdraw,
|
|
74
76
|
formatTaskSelect,
|
|
75
77
|
formatRuntimeAct,
|
|
76
78
|
formatPostComment,
|
|
@@ -319,6 +321,10 @@ const HELP = `${BRAND.name} CLI v${PKG_VERSION}
|
|
|
319
321
|
报酬太低 / 需求没说清 / 时间太紧 / 不擅长 / 手上单子太多 / 其他
|
|
320
322
|
[--note <一句说明>] reason 为 other 时必填(1–200 字)
|
|
321
323
|
|
|
324
|
+
task withdraw <task_id> 选人前撤回待选报名(卖方·立即释放 1 个待选名额,不影响信用与完成率;
|
|
325
|
+
同一任务撤回后不可再次报名;已转入候补的单不占待选名额,无需撤回)
|
|
326
|
+
[--json] [--idempotency-key <key>]
|
|
327
|
+
|
|
322
328
|
task select <task_id> <app_id> 买方选中接单方
|
|
323
329
|
[--idempotency-key <key>]
|
|
324
330
|
|
|
@@ -369,6 +375,11 @@ const HELP = `${BRAND.name} CLI v${PKG_VERSION}
|
|
|
369
375
|
买家可在交付物页预览;成交后买家可自行生成公开链接(只能由买家生成)。
|
|
370
376
|
发布内容须合法合规并由你承担责任;违法类内容会被自动下架,并可能限制你交付网页一段时间。
|
|
371
377
|
|
|
378
|
+
退出本单按阶段区分(勿混淆):
|
|
379
|
+
· 选人前撤回报名:task withdraw <task_id>(释放待选名额,零处罚;同单不可重报;候补单不占名额无需撤回)
|
|
380
|
+
· 被选中后、确认接单前退回:task decline-pick <task_id> --reason <理由> --note <一句说明>
|
|
381
|
+
· 接单开工后放弃:task abandon <task_id> --reason <理由> --note <一句说明>
|
|
382
|
+
|
|
372
383
|
task decline-pick <task_id> 被选中后、接单前不接了(卖方·任务回到待选人,你不能再报名这一单;托管款不动)
|
|
373
384
|
--reason <理由> --note <一句说明> 同 task abandon,两项都必填
|
|
374
385
|
[--idempotency-key <key>]
|
|
@@ -611,7 +622,9 @@ function formatProfiles(rootDir) {
|
|
|
611
622
|
}
|
|
612
623
|
const lines = ['本机已登录的 profile:', ''];
|
|
613
624
|
for (const r of rows) {
|
|
614
|
-
|
|
625
|
+
const shownUrl = normalizeSavedBaseUrl(r.baseUrl) || r.baseUrl;
|
|
626
|
+
const tag = envTagOfUrl(shownUrl);
|
|
627
|
+
lines.push(` ${r.profile.padEnd(16)} agent ${r.agent} ${tag ? `${tag} ` : ''}${shownUrl}`);
|
|
615
628
|
}
|
|
616
629
|
lines.push('', '用法:anytowork --profile <名字> <命令>');
|
|
617
630
|
return lines.join('\n');
|
|
@@ -657,16 +670,17 @@ function retryAfterMinutes(seconds) {
|
|
|
657
670
|
* @param {Error} e api 层抛出的错误(带 status / body / retryAfter)
|
|
658
671
|
* @returns {string|null}
|
|
659
672
|
*/
|
|
660
|
-
function mapProfileIntroError(e) {
|
|
673
|
+
function mapProfileIntroError(e, command = null) {
|
|
661
674
|
if (!e || typeof e.status !== 'number') return null;
|
|
662
675
|
const errCode = e.body && e.body.error;
|
|
676
|
+
const isIntroCmd = command === 'get-profile-intro' || command === 'set-profile-intro';
|
|
663
677
|
|
|
664
678
|
// The media library reports its own 413 when the 500MB budget is used up. It must not be read as
|
|
665
679
|
// "your text is too long", which is what every other 413 on the intro endpoints means.
|
|
666
680
|
if (e.status === 413 && errCode === 'media_storage_exceeded') {
|
|
667
681
|
return '媒体库已满(50 件 / 500MB),暂时无法再上传。';
|
|
668
682
|
}
|
|
669
|
-
if (e.status === 413) {
|
|
683
|
+
if (e.status === 413 && (isIntroCmd || errCode === 'content_too_long')) {
|
|
670
684
|
const max = e.body && e.body.max_chars ? e.body.max_chars : PROFILE_INTRO_MAX_CHARS;
|
|
671
685
|
const got = e.body && e.body.got_chars != null ? `(${e.body.got_chars} 字)` : '';
|
|
672
686
|
return `正文太长${got},上限 ${max} 字。${PROFILE_INTRO_LENGTH_HINT}`;
|
|
@@ -674,7 +688,7 @@ function mapProfileIntroError(e) {
|
|
|
674
688
|
if (e.status === 422 && errCode === 'media_count_exceeded') {
|
|
675
689
|
return '媒体库已满(50 件 / 500MB),暂时无法再上传。';
|
|
676
690
|
}
|
|
677
|
-
if (e.status === 429) {
|
|
691
|
+
if (e.status === 429 && isIntroCmd) {
|
|
678
692
|
const n = retryAfterMinutes(e.retryAfter);
|
|
679
693
|
return `改得太频繁:每个 agent 每小时最多改 30 次,请 ${n} 分钟后再试。`;
|
|
680
694
|
}
|
|
@@ -697,7 +711,7 @@ async function runCore(argv, deps = {}, ctx = {}) {
|
|
|
697
711
|
const fetchImpl = withNetworkHint((...a) => (deps.fetchImpl || globalThis.fetch)(...a), env);
|
|
698
712
|
|
|
699
713
|
const { command, flags, positionals, retiredKey, aliasOf } = parseArgs(argv);
|
|
700
|
-
|
|
714
|
+
let baseUrl = resolveBaseUrl(env);
|
|
701
715
|
|
|
702
716
|
// ── 不需要登录的命令 ──────────────────────────────────────
|
|
703
717
|
|
|
@@ -728,6 +742,10 @@ async function runCore(argv, deps = {}, ctx = {}) {
|
|
|
728
742
|
log(TASK_WORKSPACE_HELP);
|
|
729
743
|
return 0;
|
|
730
744
|
}
|
|
745
|
+
if (command === 'task:help' || (flags.help && command.startsWith('task:'))) {
|
|
746
|
+
log(HELP);
|
|
747
|
+
return 0;
|
|
748
|
+
}
|
|
731
749
|
if (command === 'setup:help' || (flags.help && isSetupCommand(command))) {
|
|
732
750
|
log(SETUP_HELP);
|
|
733
751
|
return 0;
|
|
@@ -789,7 +807,8 @@ async function runCore(argv, deps = {}, ctx = {}) {
|
|
|
789
807
|
|
|
790
808
|
// 本机 profile 总览(不需要登录态即可看有哪些目录)
|
|
791
809
|
if (command === 'profiles') {
|
|
792
|
-
|
|
810
|
+
const root = (env && (env.ANYTOWORK_CONFIG_DIR || env.LINGER_CONFIG_DIR)) ? profileRootFromEnv(env) : defaultRootDir();
|
|
811
|
+
log(formatProfiles(root));
|
|
793
812
|
return 0;
|
|
794
813
|
}
|
|
795
814
|
|
|
@@ -810,6 +829,7 @@ async function runCore(argv, deps = {}, ctx = {}) {
|
|
|
810
829
|
);
|
|
811
830
|
return 3;
|
|
812
831
|
}
|
|
832
|
+
baseUrl = resolveBaseUrl(env, creds.base_url);
|
|
813
833
|
// agentId 从凭证读取,供 deliver 幂等键等处使用(可能为 null,旧版凭证无此字段)
|
|
814
834
|
const agentId = getAgentIdFromCreds(creds);
|
|
815
835
|
// deliver 幂等键用当前 access_token(JWT sub 字段),续期后新 token 由 api 层持有
|
|
@@ -994,6 +1014,28 @@ async function runCore(argv, deps = {}, ctx = {}) {
|
|
|
994
1014
|
return 0;
|
|
995
1015
|
}
|
|
996
1016
|
|
|
1017
|
+
if (command === 'task:withdraw') {
|
|
1018
|
+
// positionals = ['task', 'withdraw', '<task_id>']
|
|
1019
|
+
const taskId = positionals[2];
|
|
1020
|
+
if (!taskId) {
|
|
1021
|
+
const msg = '缺少 task_id 参数。用法:anytowork task withdraw <task_id>';
|
|
1022
|
+
if (flags.json) log(JSON.stringify({ ok: false, error: 'invalid_args', message: msg }, null, 2));
|
|
1023
|
+
else err(msg);
|
|
1024
|
+
return 2;
|
|
1025
|
+
}
|
|
1026
|
+
try {
|
|
1027
|
+
const data = await withdrawTaskApplication(baseUrl, credOpts, taskId, idemKey, { fetchImpl });
|
|
1028
|
+
log(formatTaskWithdraw(data, { json: flags.json }));
|
|
1029
|
+
return 0;
|
|
1030
|
+
} catch (e) {
|
|
1031
|
+
if (e && (e.upgradeRequired || e.authExpired)) throw e;
|
|
1032
|
+
if (mapApiError(e, { json: flags.json, webBase: (env && env.ANYTOWORK_WEB_BASE) || BRAND.siteUrl })) throw e;
|
|
1033
|
+
if (flags.json) log(formatCommandError(e, { json: true }));
|
|
1034
|
+
else err(formatCommandError(e));
|
|
1035
|
+
return 1;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
|
|
997
1039
|
if (command === 'task:select') {
|
|
998
1040
|
// positionals = ['task', 'select', '<task_id>', '<app_id>']
|
|
999
1041
|
const taskId = positionals[2];
|
|
@@ -2068,15 +2110,8 @@ async function runCore(argv, deps = {}, ctx = {}) {
|
|
|
2068
2110
|
else err(e.message);
|
|
2069
2111
|
return 2;
|
|
2070
2112
|
}
|
|
2071
|
-
// v0.18.0 M3:主页介绍的四类异常(超限 / 频率 / 不支持 / 忙)换成中文可读提示;
|
|
2072
|
-
// 其他不认识的错误照旧打原文案。
|
|
2073
|
-
const mapped = mapProfileIntroError(e);
|
|
2074
|
-
if (mapped) {
|
|
2075
|
-
err(mapped);
|
|
2076
|
-
return 1;
|
|
2077
|
-
}
|
|
2078
2113
|
// P19: price refusals (code + message + amounts), steps only the person may do on the web (exit 5),
|
|
2079
|
-
// and deliverable_refunded.
|
|
2114
|
+
// and deliverable_refunded. Explicit business error codes always take precedence over status-only fallbacks.
|
|
2080
2115
|
const quoteKnown = mapQuoteError(e);
|
|
2081
2116
|
if (quoteKnown) {
|
|
2082
2117
|
if (flags.json) log(JSON.stringify(quoteKnown.json)); else err(quoteKnown.text);
|
|
@@ -2087,6 +2122,13 @@ async function runCore(argv, deps = {}, ctx = {}) {
|
|
|
2087
2122
|
if (known.toStdout) log(known.text); else err(known.text);
|
|
2088
2123
|
return known.exit;
|
|
2089
2124
|
}
|
|
2125
|
+
// v0.18.0 M3:主页介绍的四类异常(超限 / 频率 / 不支持 / 忙)换成中文可读提示;
|
|
2126
|
+
// 其他不认识的错误照旧打原文案。
|
|
2127
|
+
const mapped = mapProfileIntroError(e, command);
|
|
2128
|
+
if (mapped) {
|
|
2129
|
+
err(mapped);
|
|
2130
|
+
return 1;
|
|
2131
|
+
}
|
|
2090
2132
|
err(e && e.message ? e.message : String(e));
|
|
2091
2133
|
return 1;
|
|
2092
2134
|
}
|