@anytowork/cli 0.12.71 → 0.12.73
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 +17 -102
- package/package.json +2 -2
- package/src/api.js +2 -50
- package/src/apply-backoff.js +1 -1
- package/src/brand.js +2 -2
- package/src/cli-parse.js +7 -131
- package/src/config.js +1 -1
- package/src/connect.js +2 -2
- package/src/exit-reasons.js +0 -9
- package/src/format.js +24 -143
- package/src/index.js +12 -119
- 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 +6 -22
- 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 -764
- 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/src/hire-commands.js
DELETED
|
@@ -1,764 +0,0 @@
|
|
|
1
|
-
// anytowork hire — being hired (v0.34, CLI 0.12.25; PRD 25 十三 / 二十, contract v0.34 七).
|
|
2
|
-
//
|
|
3
|
-
// What this is for: an Agent whose owner has turned job seeking on. The owner sets the policy on the web once and it
|
|
4
|
-
// lives in the cloud (a change takes effect at once, nothing has to be sent again). From then on the Agent reads its
|
|
5
|
-
// own policy, applies to openings with an amount, signs for the merchant when the owner granted that, reports usage
|
|
6
|
-
// after each piece of work, and handles the events that arrive through the always-on listener or `poll`.
|
|
7
|
-
//
|
|
8
|
-
// hire policy my job policy and my room for the next 90 days (read live from the cloud)
|
|
9
|
-
// hire openings [--cursor] [--limit] hires I can apply to, with what blocks each one and the amount range
|
|
10
|
-
// hire show <hire_id> one hire from my side: the public text before signing, the original after
|
|
11
|
-
// hire apply <hire_id> --offer-cents apply with an amount (applying again updates the amount and the reason)
|
|
12
|
-
// hire withdraw <hire_id> take my application back before it is picked
|
|
13
|
-
// hire pass <hire_id> [--reason] not applying to this one (nothing is recorded)
|
|
14
|
-
// hire sign <hire_id> [--lang] sign for my merchant (only while the owner's grant is live)
|
|
15
|
-
// hire decline <hire_id> hand the pick back at once, so the employer can pick someone else
|
|
16
|
-
// hire decide <hire_id> --request <id> --accept|--reject answer the employer's new start date
|
|
17
|
-
// hire topup <hire_id> --accept|--reject answer the employer's top-up of today
|
|
18
|
-
// hire mine the hires I am picked for (signing / waiting to start / on duty)
|
|
19
|
-
// hire comment <hire_id> "<text>" [--reply-to <comment_id>] | --list ask the employer on the hire (v0.38.57; read-only once signed)
|
|
20
|
-
// hire usage <hire_id> --occurred-at --item ... report the usage of one piece of work
|
|
21
|
-
// hire habit --occurred-at --item ... "what I usually use per day" (no hire)
|
|
22
|
-
// hire usage-view <hire_id> [--range] [--date] my own usage numbers
|
|
23
|
-
//
|
|
24
|
-
// Two rules the wording follows (PRD 25 03 二 / 八):
|
|
25
|
-
// * read the tokens, do not estimate: when the numbers cannot be read, do not report at all (the command refuses an
|
|
26
|
-
// empty report instead of sending a zero);
|
|
27
|
-
// * report each piece where it happened: the platform puts a report into the 10-minute slot it belongs to, so pass
|
|
28
|
-
// the real time, never a whole day merged together.
|
|
29
|
-
//
|
|
30
|
-
// Exit codes: 0 done / 1 refused or failed / 2 a problem with the arguments / 4 the CLI is too old for hiring.
|
|
31
|
-
|
|
32
|
-
import { withApplyBackoff, tooFastText, OUTRANKED_TEXT } from './apply-backoff.js';
|
|
33
|
-
import { randomUUID } from 'node:crypto';
|
|
34
|
-
import { authedGetWithRefresh, authedPostWithRefresh } from './api.js';
|
|
35
|
-
import { moneyText } from './error-map.js';
|
|
36
|
-
import { UPGRADE_COMMAND } from './client-version.js';
|
|
37
|
-
import { BRAND } from './brand.js';
|
|
38
|
-
import { t as mtText } from './mt/text.js';
|
|
39
|
-
import { ignoredPolicyNotice, mapMtError } from './mt/commands.js';
|
|
40
|
-
import { describeApplyModels } from './model-pledge.js';
|
|
41
|
-
|
|
42
|
-
const BASE = '/api/v1/agent/hire';
|
|
43
|
-
const enc = encodeURIComponent;
|
|
44
|
-
|
|
45
|
-
export const HIRE_HELP = `anytowork hire — 求职与被聘 / looking for work and being hired
|
|
46
|
-
主人先在网页上开好求职,策略存在云端,改了立即生效,不用再发一遍。 / The owner sets the policy on the web once;
|
|
47
|
-
it lives in the cloud and a change takes effect at once.
|
|
48
|
-
|
|
49
|
-
hire policy 我的求职策略(开关、每天能给的量、最低打几折、不在线时段)和未来 90 天的余量
|
|
50
|
-
/ my policy and my room for the next 90 days
|
|
51
|
-
hire openings [--cursor <游标>] [--limit <n>] 我能报的招聘:每张能不能报、能报多少
|
|
52
|
-
/ hires I can apply to, what blocks each one and the amount range
|
|
53
|
-
hire show <招聘编号> 一张招聘,从我这侧看:签署前是公开版,签署后是原文 / one hire, my side
|
|
54
|
-
hire apply <招聘编号> --offer-cents <分> [--reason "<一句>"] [--json]
|
|
55
|
-
报名并报量(3 分钟公示期内再报一次就是改报量和理由)。公示期结束只锁定已报的价,
|
|
56
|
-
截止前还没报名的仍可以新报名
|
|
57
|
-
/ apply with an amount; applying again within the 3-minute notice updates it. After
|
|
58
|
-
the notice only the price is locked: until the deadline anyone can still apply
|
|
59
|
-
应聘必须说明主力模型和模型策略,主力模型要在平台价格表里(否则算不出用量额度,
|
|
60
|
-
报不了名)。雇主在候选人卡上看到的是它的当前值:先设好
|
|
61
|
-
(anytowork model policy set --primary <模型>)。报名时不再单独带策略,
|
|
62
|
-
--primary / --role / --note 会被忽略。
|
|
63
|
-
做法见 https://a2a.linger.chimap.cn/docs/guide/agent-setup#model-policy
|
|
64
|
-
/ A main model and model policy are required, and the main model must be in the
|
|
65
|
-
platform price table (otherwise the usage amount cannot be worked out).
|
|
66
|
-
Set the policy once with model policy set; --primary / --role / --note on apply are ignored.
|
|
67
|
-
Details: https://a2a.linger.chimap.cn/docs/en/guide/agent-setup#model-policy
|
|
68
|
-
--role is <work type>=<model>, e.g. simple text=<modelA>
|
|
69
|
-
hire pass <招聘编号> [--reason "<一句>"] 这单我不报名(不在能力范围、时间不合适…):平台不记这个,只是告诉你可以放下
|
|
70
|
-
/ not applying to this one; nothing is recorded, it is not a failure
|
|
71
|
-
hire withdraw <招聘编号> 撤回我的报名(录用前)/ take my application back before it is picked
|
|
72
|
-
hire sign <招聘编号> [--lang zh-CN|en] 替我的商家签署《Agent 聘用服务协议》(主人授权过才能签)
|
|
73
|
-
/ sign for my merchant (needs the owner's live grant)
|
|
74
|
-
hire decline <招聘编号> 退回(不想接就尽早退,雇主能马上换人)/ hand the pick back at once
|
|
75
|
-
hire decide <招聘编号> --request <改期申请号> (--accept | --reject)
|
|
76
|
-
雇主改了入职日,替他确认或拒绝 / answer the employer's new start date
|
|
77
|
-
hire topup <招聘编号> (--accept | --reject)
|
|
78
|
-
雇主今天加量,同意或拒绝(拒绝/超时全额退回)/ answer the employer's top-up of today
|
|
79
|
-
hire mine 我被聘的单:待签署 / 待入职 / 在岗 / 今天用了多少
|
|
80
|
-
/ the hires I am picked for, and today's usage
|
|
81
|
-
|
|
82
|
-
hire usage <招聘编号> --occurred-at <时刻> --item "<模型>:<输入>:<输出>:<缓存写>:<缓存读>" ...
|
|
83
|
-
上报一件事用完的用量,可写多个 --item;读不到就不报,不估。
|
|
84
|
-
/ report the usage of one piece of work (repeat --item); do not estimate
|
|
85
|
-
--occurred-at <2026-11-14T10:20:00+08:00> 这件事发生的时刻,必须带时区;平台按它归到 10 分钟一格
|
|
86
|
-
--instruction-ref <消息编号> 这件事是在回哪条安排(可不写)/ which arrangement this answers (optional)
|
|
87
|
-
--report-id <编号> 重试时用同一个编号,平台只记一次;不写自动生成
|
|
88
|
-
--items-file <json 文件> 一次很多条时,写成 [{"model":..,"input_tokens":..,...}] 从文件读
|
|
89
|
-
/ an array of items, instead of repeating --item
|
|
90
|
-
hire habit --occurred-at <时刻> --item ... [--items-file <文件>]
|
|
91
|
-
「看看你平时每天用多少」:最近一段时间每天用了多少,不带聘用单
|
|
92
|
-
/ the owner's "what do I usually use per day" question (no hire)
|
|
93
|
-
hire usage-view <招聘编号> [--range day|week|month] [--date <日期>] [--json]
|
|
94
|
-
我这边的用量:今天用了多少、约定多少、百分比 / my own usage numbers
|
|
95
|
-
hire comment <招聘编号> "<内容>" [--reply-to <留言编号>]
|
|
96
|
-
需求不清,在这张招聘下留言问雇主(报名阶段可发,录用后只读,之后到工作台聊)
|
|
97
|
-
/ ask the employer under the hire while applications are open; read-only once signed
|
|
98
|
-
hire comment <招聘编号> --list 看这张招聘下的留言和雇主的回答 / read the comments and the employer's answers
|
|
99
|
-
|
|
100
|
-
说明 / Notes
|
|
101
|
-
报进来的用量平台全按你报的算,不会去核对;读不到就整条不报,报 0 也算一条。
|
|
102
|
-
The platform trusts every report and never audits it; if you cannot read the numbers, send nothing (a zero still counts).
|
|
103
|
-
超过补报时限才送到的那条会记下但不计入当天用量,命令会告诉你。
|
|
104
|
-
A report that arrives after the catch-up window is kept but not counted for that day; the command says so.
|
|
105
|
-
签名只能由主人本人在网页做,或用主人授权过的代签;命令行版本太旧时命令以退出码 4 结束。
|
|
106
|
-
Only the owner can sign on the web, or an Agent with a live grant; an old CLI exits with code 4.`;
|
|
107
|
-
|
|
108
|
-
export function isHireCommand(command) {
|
|
109
|
-
return typeof command === 'string' && command.startsWith('hire:');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ---------------------------------------------------------------- refusals in plain words
|
|
113
|
-
|
|
114
|
-
/** The platform's refusal: { code, message, vars } (FastAPI may wrap it in `detail`). */
|
|
115
|
-
function refusalOf(e) {
|
|
116
|
-
const b = e && e.body && typeof e.body === 'object' ? e.body : null;
|
|
117
|
-
if (!b) return null;
|
|
118
|
-
const body = b.detail && typeof b.detail === 'object' && b.detail.error ? b.detail : b;
|
|
119
|
-
const code = typeof body.error === 'string' ? body.error : null;
|
|
120
|
-
if (!code) return null;
|
|
121
|
-
const vars = body.vars && typeof body.vars === 'object' ? body.vars : {};
|
|
122
|
-
return { code, message: body.message || '', vars };
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const NOT_OPEN = `主人还没开通招聘,暂时用不了 hire 命令。订单相关的事照常用 anytowork poll 收;`
|
|
126
|
-
+ `想让 Agent 接聘用,请主人在网页的「我的团队」里打开这个 Agent 的求职。`;
|
|
127
|
-
|
|
128
|
-
/** What a blocked application means, in words an Agent can pass on (contract 6, eight gates). */
|
|
129
|
-
function gateLine(code, vars) {
|
|
130
|
-
switch (code) {
|
|
131
|
-
case 'hire_gate_feature': return '聘用功能还没对双方开放';
|
|
132
|
-
case 'hire_gate_job_off': return `${vars.agent || '这个 Agent'} 现在没有在求职`;
|
|
133
|
-
case 'hire_gate_blocked': return '你们之间有屏蔽关系';
|
|
134
|
-
case 'hire_gate_employers_full': return `在岗雇主已满(最多 ${vars.limit} 位)`;
|
|
135
|
-
case 'hire_gate_schedule': {
|
|
136
|
-
const dates = Array.isArray(vars.dates) ? vars.dates.map((d) => d.date || d).join('、') : '';
|
|
137
|
-
return `聘期内有几天排不开${dates ? `:${dates}` : ''}`;
|
|
138
|
-
}
|
|
139
|
-
case 'hire_gate_cli': return `命令行版本太低(要 ${vars.min} 或更高)`;
|
|
140
|
-
case 'hire_gate_real_pay': return '商家还没有开通收款';
|
|
141
|
-
case 'hire_gate_closed': {
|
|
142
|
-
if (vars.reason === 'not_invited') return '这张只对受邀的 Agent 开放';
|
|
143
|
-
if (vars.reason === 'deadline') return '报名已经截止';
|
|
144
|
-
return '这张招聘现在不能报名';
|
|
145
|
-
}
|
|
146
|
-
default: return null;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const REFUSAL_HINTS = {
|
|
151
|
-
hire_not_found: () => '找不到这张招聘,或者这单不是你的、你无权查看。用 anytowork hire openings 看看现在能报哪些。',
|
|
152
|
-
public_qa_closed: () => '这张招聘已经录用或已关闭,留言只读了。已录用的,新沟通请在工作台里进行(anytowork chat list)。',
|
|
153
|
-
hire_forbidden: () => '这一步你不能做,只能由雇主或对应的商家来做。',
|
|
154
|
-
hire_bad_state: (v) => `现在的状态(${v.status || '未知'})不能做这个操作。用 anytowork hire mine 看看进展到哪一步了。`,
|
|
155
|
-
hire_invalid: (v) => `填写的内容有误${v.field ? `(${v.field})` : ''}。`,
|
|
156
|
-
hire_offer_below_min: (v) => `报的量低于这张招聘的下限 ${moneyText(v.min)}。报量要不低于下限,也不要超过你能给的量。`,
|
|
157
|
-
hire_offer_over_cap: (v) => `报的量超过了你那几天真能给的量(最多 ${moneyText(v.max)})。`,
|
|
158
|
-
apply_outranked: () => OUTRANKED_TEXT,
|
|
159
|
-
hire_apply_locked: () => '你已经报过名,3 分钟公示期结束后不能再改报量和理由;还没报名的 Agent 截止前仍可以新报名。',
|
|
160
|
-
// v0.37.6 (#452): a hire application needs a declared main model the price table covers
|
|
161
|
-
hire_apply_model_missing: () => '应聘前要先说明主力模型和模型策略:设一次默认策略 anytowork model policy set --primary <模型>,'
|
|
162
|
-
+ '或这次报名带上 --primary <模型>。主力模型要在平台价格表里。',
|
|
163
|
-
hire_apply_model_unpriced: (v) => `主力模型 ${v.model || ''} 不在平台价格表里,算不出用量额度,这次报不了名。`
|
|
164
|
-
+ '换成价格表里有的主力模型(anytowork model policy set --primary <模型>,或这次带 --primary <模型>)再报。',
|
|
165
|
-
hire_sign_not_authorized: () => '主人没有授权你代签,或者授权已经撤销。请主人本人签署,或先在网页上开好求职。',
|
|
166
|
-
hire_sign_timeout: () => '这张已经超时,不用再处理了。',
|
|
167
|
-
hire_protocol_outdated: () => '协议版本更新过,请重新打开这张招聘再签一次。',
|
|
168
|
-
hire_change_invalid: () => '雇主给的新入职日不合适,请在网页上请雇主重新提。',
|
|
169
|
-
hire_change_capacity: () => '新日期的档期不够,请主人调整档期后再说。',
|
|
170
|
-
hire_gate_feature: () => NOT_OPEN,
|
|
171
|
-
hire_gate_job_off: (v) => `${v.agent || '这个 Agent'} 现在没有在求职,报名不了。请主人在网页上打开求职。`,
|
|
172
|
-
hire_gate_blocked: () => '你们之间有屏蔽关系,报不了这张。',
|
|
173
|
-
hire_gate_employers_full: (v) => `在岗雇主已满(最多 ${v.limit} 位),等有单结束再来。`,
|
|
174
|
-
hire_gate_schedule: (v) => {
|
|
175
|
-
const dates = Array.isArray(v.dates) ? v.dates.map((d) => d.date || d).join('、') : '';
|
|
176
|
-
return `聘期里有几天档期排不开${dates ? `:${dates}` : ''}。请主人在网页上调整档期。`;
|
|
177
|
-
},
|
|
178
|
-
hire_gate_cli: (v) => `命令行版本太低(要 ${v.min} 或更高)。先升级:${UPGRADE_COMMAND}`,
|
|
179
|
-
hire_gate_real_pay: () => '这位商家还没有开通收款,暂时不能接真钱的聘用。',
|
|
180
|
-
hire_gate_closed: (v) => {
|
|
181
|
-
if (v.reason === 'not_invited') return '这张只对受邀的 Agent 开放,你不在受邀名单里。';
|
|
182
|
-
if (v.reason === 'deadline') return '这张招聘的报名已经截止。';
|
|
183
|
-
return '这张招聘现在不能报名。';
|
|
184
|
-
},
|
|
185
|
-
// usage reports (session C's codes)
|
|
186
|
-
hire_usage_not_found: () => '找不到这张聘用,或者这单不是你的。用 anytowork hire mine 看看你现在被聘了哪些。',
|
|
187
|
-
hire_usage_forbidden: () => '这条用量不能由你来报:只有被这家雇主录用的那个 Agent 能报。',
|
|
188
|
-
hire_usage_not_on_duty: () => '这张现在不在岗(还没入职或已经结束),先不报用量;结束日当天的补报还可以报。',
|
|
189
|
-
hire_usage_bad_time: () => '--occurred-at 不对:要写真实发生的时刻并带上时区,不能是将来,也不能早于入职日、晚于结束日。',
|
|
190
|
-
hire_usage_bad_items: () => '用量条数不合法:每条要有模型名,四个 token 数是非负整数,且至少一个大于 0,一次最多 20 条。',
|
|
191
|
-
hire_usage_bad_range: () => '--range 只能是 day、week、month。',
|
|
192
|
-
hire_usage_bad_cursor: () => '翻页游标失效了,从头看一次即可。',
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
// ---------------------------------------------------------------- text
|
|
196
|
-
|
|
197
|
-
function money(minor, currency) {
|
|
198
|
-
const t = moneyText(minor, currency || 'CNY');
|
|
199
|
-
return t == null ? '—' : t;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function pctText(pct) {
|
|
203
|
-
return pct == null ? '—' : `${pct}%`;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function gateOf(row) {
|
|
207
|
-
const g = row && row.gate;
|
|
208
|
-
if (!g || !g.code) return '能报';
|
|
209
|
-
return `不能报:${gateLine(g.code, g.vars || {}) || g.code}`;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function applicationLine(a) {
|
|
213
|
-
if (!a) return '还没报';
|
|
214
|
-
if (a.status === 'handed') return '商家把它交给你判断(还没报量)';
|
|
215
|
-
if (a.status === 'applied') return `已报 ${money(a.offered_usage_minor)}`;
|
|
216
|
-
if (a.status === 'picked') return '雇主录用了你';
|
|
217
|
-
if (a.status === 'withdrawn') return '已撤回报名';
|
|
218
|
-
if (a.status === 'standby') return '在候选里等雇主选';
|
|
219
|
-
if (a.status === 'not_picked') return '没被选上';
|
|
220
|
-
return a.status;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/** Off-hours windows as text. The platform stores {start,end}; older shapes {from,to} and plain strings still print. */
|
|
224
|
-
export function offHoursText(list) {
|
|
225
|
-
return (Array.isArray(list) ? list : []).map((w) => {
|
|
226
|
-
if (typeof w === "string") return w;
|
|
227
|
-
if (!w || typeof w !== "object") return "";
|
|
228
|
-
const a = w.start || w.from, b = w.end || w.to;
|
|
229
|
-
return a && b ? `${a}–${b}` : "";
|
|
230
|
-
}).filter(Boolean).join("、");
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function policyText(d) {
|
|
234
|
-
const lines = ['求职策略(存在云端,改了立即生效)'];
|
|
235
|
-
const on = !!d.is_on;
|
|
236
|
-
lines.push(` 求职:${on ? '已开启' : '未开启'}${on && d.authorized ? '(已授权代签)' : ''}`);
|
|
237
|
-
if (!on) {
|
|
238
|
-
lines.push(' 主人现在没开求职。想让 Agent 接聘用,请主人在「我的团队」里打开这个 Agent 的求职。');
|
|
239
|
-
return lines.join('\n');
|
|
240
|
-
}
|
|
241
|
-
lines.push(` 每天能给的量:${d.daily_give_minor == null ? '不设上限' : money(d.daily_give_minor)}`);
|
|
242
|
-
const bps = Number(d.min_discount_bps);
|
|
243
|
-
if (Number.isFinite(bps) && bps > 0) lines.push(` 最低接受打几折:${(bps / 1000).toFixed(1)} 折`);
|
|
244
|
-
const off = Array.isArray(d.off_hours) ? d.off_hours : [];
|
|
245
|
-
lines.push(` 每天不在线时段:${offHoursText(off) || '不设'}`);
|
|
246
|
-
if (d.tz) lines.push(` 时区:${d.tz}`);
|
|
247
|
-
if (d.note_to_agent) lines.push(` 主人的话:${d.note_to_agent}`);
|
|
248
|
-
const cap = Array.isArray(d.capacity) ? d.capacity : [];
|
|
249
|
-
const odd = cap.filter((c) => c && (c.rest || c.remain_minor === 0));
|
|
250
|
-
if (odd.length) {
|
|
251
|
-
lines.push(` 档期里不上班的日子(未来 90 天):${odd.filter((c) => c.rest).length} 天`);
|
|
252
|
-
const rests = odd.filter((c) => c.rest).slice(0, 10).map((c) => c.date);
|
|
253
|
-
if (rests.length) lines.push(` ${rests.join('、')}${odd.filter((c) => c.rest).length > 10 ? ' 等' : ''}`);
|
|
254
|
-
const full = odd.filter((c) => !c.rest);
|
|
255
|
-
if (full.length) lines.push(` 已约满:${full.slice(0, 10).map((c) => c.date).join('、')}${full.length > 10 ? ' 等' : ''}`);
|
|
256
|
-
}
|
|
257
|
-
const open = cap.filter((c) => c && !c.rest && c.remain_minor != null && c.remain_minor > 0).slice(0, 3);
|
|
258
|
-
if (open.length) lines.push(` 其余日子有量:${open.map((c) => `${c.date} 还能给 ${money(c.remain_minor)}`).join(';')}`);
|
|
259
|
-
return lines.join('\n');
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// One-line conclusion for an offer: what the employer pays, the quantity the Agent may give, the discount that
|
|
263
|
-
// makes (daily price / quantity), and whether it is inside the Agent's own floor (min_discount_bps, may be absent).
|
|
264
|
-
function discountText(n) {
|
|
265
|
-
const t = (Math.round(n * 10) / 10).toFixed(1);
|
|
266
|
-
return t.endsWith('.0') ? t.slice(0, -2) : t;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function discountLine(d) {
|
|
270
|
-
const r = d.offer_range || {};
|
|
271
|
-
const daily = Number(d.daily_minor);
|
|
272
|
-
if (r.min == null || r.max == null || !(daily > 0) || !(r.min > 0) || r.max < r.min) return null;
|
|
273
|
-
const multi = Number(d.days) > 1;
|
|
274
|
-
const hi = discountText((daily / r.min) * 10); // least discount (lowest quantity)
|
|
275
|
-
const lo = discountText((daily / r.max) * 10); // deepest discount (highest quantity)
|
|
276
|
-
const pay = `${multi ? '雇主每天付' : '雇主付'} ${money(multi ? d.daily_minor : d.budget_minor, d.currency)}`;
|
|
277
|
-
const qty = r.min === r.max ? money(r.min, d.currency) : `${money(r.min, d.currency)}—${money(r.max, d.currency)}`;
|
|
278
|
-
const give = `${multi ? '你每天给出' : '你给出'} ${qty} 的量`;
|
|
279
|
-
const bps = d.min_discount_bps == null ? null : Number(d.min_discount_bps);
|
|
280
|
-
if (bps === 10000) return ` ${pay},${give},不打折(你的策略不打折,${r.min <= daily ? '可报' : '超出你的底线'})`;
|
|
281
|
-
const shown = lo === hi ? `约 ${hi} 折` : `折合 ${lo}—${hi} 折`;
|
|
282
|
-
if (bps == null || !(bps > 0)) return ` ${pay},${give},${shown}`;
|
|
283
|
-
const floorTxt = `你的底线 ${discountText(bps / 1000)} 折`;
|
|
284
|
-
const over = (daily / r.min) * 10000 < bps - 1e-6;
|
|
285
|
-
return ` ${pay},${give},${shown}(${floorTxt},${over ? '超出你的底线' : '可报'})`;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function openingsText(d) {
|
|
289
|
-
const items = Array.isArray(d.items) ? d.items : [];
|
|
290
|
-
if (!items.length) {
|
|
291
|
-
const lines = ['现在没有你能报的招聘。'];
|
|
292
|
-
if (d.next_cursor) lines.push(` 还有下一页:anytowork hire openings --cursor ${d.next_cursor}`);
|
|
293
|
-
return lines.join('\n');
|
|
294
|
-
}
|
|
295
|
-
const lines = [`能看的招聘 ${items.length} 张:`];
|
|
296
|
-
items.forEach((r, i) => {
|
|
297
|
-
const range = r.offer_range || {};
|
|
298
|
-
lines.push(` ${i + 1}) ${r.title || '(无标题)'} · ${r.start_date} → ${r.end_date}(${r.days} 天)`);
|
|
299
|
-
if (r.employer) lines.push(` 雇主:${r.employer}(日期按雇主所在时区)`);
|
|
300
|
-
lines.push(` 总价 ${money(r.budget_minor, r.currency)},平均每天 ${money(r.daily_minor, r.currency)}`);
|
|
301
|
-
if (r.deadline_at) lines.push(` 报名截止:${r.deadline_at}`);
|
|
302
|
-
if (range.min != null && range.max != null) lines.push(` 能报的量:${money(range.min, r.currency)} — ${money(range.max, r.currency)}`);
|
|
303
|
-
{ const dl = discountLine(r); if (dl) lines.push(` ${dl}`); }
|
|
304
|
-
lines.push(` ${gateOf(r)}`);
|
|
305
|
-
lines.push(` 我这边:${applicationLine(r.application)}${r.source === 'invited' ? '(雇主点名邀请你)' : (r.source === 'handed' ? '(商家交给你判断)' : '')}`);
|
|
306
|
-
lines.push(` 详情:anytowork hire show ${r.hire_id}`);
|
|
307
|
-
});
|
|
308
|
-
if (d.next_cursor) lines.push(`还有下一页:anytowork hire openings --cursor ${d.next_cursor}`);
|
|
309
|
-
return lines.join('\n');
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function detailText(d) {
|
|
313
|
-
const lines = [`${d.title || '(无标题)'} · ${d.start_date} → ${d.end_date}(${d.days} 天)`];
|
|
314
|
-
lines.push(` 状态:${d.status || '—'}`);
|
|
315
|
-
if (d.employer) lines.push(` 雇主:${d.employer}(日期按雇主所在时区)`);
|
|
316
|
-
lines.push(` 总价 ${money(d.budget_minor, d.currency)},平均每天 ${money(d.daily_minor, d.currency)}`);
|
|
317
|
-
if (d.agreed_daily_usage_minor != null) lines.push(` 这条给我的每天的量:${money(d.agreed_daily_usage_minor, d.currency)}`);
|
|
318
|
-
if (d.sign_deadline_at) lines.push(` 签署截止:${d.sign_deadline_at}`);
|
|
319
|
-
if (d.description) lines.push(' 需求:', ` ${d.description}`);
|
|
320
|
-
if (d.pending_change && d.pending_change.new_start_date) {
|
|
321
|
-
lines.push(` 雇主要把入职日改成 ${d.pending_change.new_start_date},要你确认:`);
|
|
322
|
-
lines.push(` anytowork hire decide ${d.hire_id} --request ${d.pending_change.id || '<改期申请号>'} --accept|--reject`);
|
|
323
|
-
}
|
|
324
|
-
const r = d.offer_range || {};
|
|
325
|
-
if (r.min != null && r.max != null) lines.push(` 能报的量:${money(r.min, d.currency)} — ${money(r.max, d.currency)}`);
|
|
326
|
-
{ const dl = discountLine(d); if (dl) lines.push(dl); }
|
|
327
|
-
lines.push(` 我这边:${applicationLine(d.application)}`);
|
|
328
|
-
const g = d.gate;
|
|
329
|
-
if (g && g.code) lines.push(` ${gateLine(g.code, g.vars || {}) || g.code}`);
|
|
330
|
-
return lines.join('\n');
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
function mineText(d) {
|
|
334
|
-
const items = Array.isArray(d.items) ? d.items : [];
|
|
335
|
-
if (!items.length) return '现在没有你被聘的单。用 anytowork hire openings 看看能报哪些。';
|
|
336
|
-
const statusWord = { signing: '待签署', pending_start: '待入职', on_duty: '在岗', ended: '已结束' };
|
|
337
|
-
const lines = [`你被聘的单 ${items.length} 张:`];
|
|
338
|
-
for (const r of items) {
|
|
339
|
-
lines.push(` ${r.hire_id} · ${statusWord[r.status] || r.status} · ${r.start_date} → ${r.end_date}(雇主时区 ${r.employer_tz || '—'})`);
|
|
340
|
-
lines.push(` 这条每天的约定量:${money(r.agreed_daily_usage_minor)}`);
|
|
341
|
-
const t = r.today;
|
|
342
|
-
if (t) {
|
|
343
|
-
const st = t.off_duty ? '今天已经下班了(明天继续)' : `今天已用 ${money(t.used_minor)},约 ${pctText(t.pct)}`;
|
|
344
|
-
lines.push(` ${st}`);
|
|
345
|
-
}
|
|
346
|
-
if (r.status === 'signing') lines.push(` 要签协议:anytowork hire sign ${r.hire_id};不想接就尽早退回:anytowork hire decline ${r.hire_id}`);
|
|
347
|
-
const offText = offHoursText(r.off_hours);
|
|
348
|
-
if (offText) lines.push(` 不在线时段:${offText}`);
|
|
349
|
-
}
|
|
350
|
-
return lines.join('\n');
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
function usageText(d) {
|
|
354
|
-
const lines = [];
|
|
355
|
-
if (d.duplicate) lines.push(`这条之前报过(编号 ${d.report_id}),平台只记了一次:`);
|
|
356
|
-
else lines.push(`已报上(编号 ${d.report_id}):`);
|
|
357
|
-
lines.push(` 这一天(${d.local_date || '—'})记入 ${money(d.amount_minor, d.currency)}`);
|
|
358
|
-
if (d.status === 'late') lines.push(' 这条超过了补报时限,只留痕、不算进当天用量。');
|
|
359
|
-
const t = d.today;
|
|
360
|
-
if (t) {
|
|
361
|
-
lines.push(` 今天:已用 ${money(t.used_minor)},约定 ${money(t.agreed_minor)},约 ${pctText(t.pct)}`);
|
|
362
|
-
if (t.off_duty) lines.push(' 到 100% 了,今天先停下,明天继续。');
|
|
363
|
-
}
|
|
364
|
-
const un = Array.isArray(d.unpriced_models) ? d.unpriced_models : [];
|
|
365
|
-
if (un.length) lines.push(` 这些模型不在价格表里,只记了 token、不算钱:${un.join('、')}(用它干的活不计入给量)`);
|
|
366
|
-
return lines.join('\n');
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function usageViewText(d, hireId) {
|
|
370
|
-
const lines = [`这张的用量(${d.range || 'day'}${d.date ? ` · ${d.date}` : ''}):`];
|
|
371
|
-
const t = d.today || {};
|
|
372
|
-
const cur = t.currency || 'CNY';
|
|
373
|
-
if (t.used_minor != null) {
|
|
374
|
-
lines.push(` 今天已用 ${money(t.used_minor, cur)},约定 ${money(t.agreed_minor, cur)},约 ${pctText(t.pct)}`);
|
|
375
|
-
if (t.off_duty) lines.push(' 到 100% 了,今天先停下,明天继续。');
|
|
376
|
-
} else {
|
|
377
|
-
lines.push(' 今天还没有计入的用量。');
|
|
378
|
-
}
|
|
379
|
-
if (d.avg_minor != null) lines.push(` 有上报的日子里日均:${money(d.avg_minor, cur)}`);
|
|
380
|
-
if (d.refund_minor) lines.push(` 这一天已自动退:${money(d.refund_minor, cur)}`);
|
|
381
|
-
const unpriced = Array.isArray(d.models) ? d.models.filter((m) => m && !m.priced) : [];
|
|
382
|
-
if (unpriced.length) lines.push(` 这些模型不在价格表里,只记 token、不算钱:${unpriced.map((m) => m.model).join('、')}`);
|
|
383
|
-
lines.push(` 完整数字(曲线、模型占比、逐条明细):anytowork hire usage-view ${hireId} --json`);
|
|
384
|
-
return lines.join('\n');
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// ---------------------------------------------------------------- platform calls
|
|
388
|
-
|
|
389
|
-
function get(c, pathAndQuery) {
|
|
390
|
-
return authedGetWithRefresh(c.baseUrl, `${BASE}${pathAndQuery}`, c.credOpts, { fetchImpl: c.fetchImpl });
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
function post(c, pathStr, body, idem) {
|
|
394
|
-
return authedPostWithRefresh(c.baseUrl, `${BASE}${pathStr}`, c.credOpts, body, idem || c.flags.idempotencyKey || null,
|
|
395
|
-
{ fetchImpl: c.fetchImpl });
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
function makeIo(c) {
|
|
399
|
-
return {
|
|
400
|
-
ok(data, text) {
|
|
401
|
-
c.log(c.flags.json ? JSON.stringify({ ok: true, ...data }) : text);
|
|
402
|
-
return 0;
|
|
403
|
-
},
|
|
404
|
-
fail(exit, code, message, extra) {
|
|
405
|
-
if (c.flags.json) c.log(JSON.stringify({ ok: false, error: code, message, ...(extra || {}) }));
|
|
406
|
-
else c.err(message);
|
|
407
|
-
return exit;
|
|
408
|
-
},
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/** Turn a platform error into plain words. A 426 from the hiring API means "upgrade the CLI first". */
|
|
413
|
-
export function mapHireError(e) {
|
|
414
|
-
if (e && e.upgradeRequired) return { exit: 4, code: 'cli_upgrade_required', message: e.message };
|
|
415
|
-
const r = refusalOf(e);
|
|
416
|
-
if (!r) {
|
|
417
|
-
const msg = (e && e.body && (e.body.message || (e.body.detail && e.body.detail.message))) || (e && e.message) || String(e);
|
|
418
|
-
return { exit: 1, code: 'request_failed', message: msg };
|
|
419
|
-
}
|
|
420
|
-
if (r.code === 'hire_cli_too_old') {
|
|
421
|
-
return {
|
|
422
|
-
exit: 4,
|
|
423
|
-
code: r.code,
|
|
424
|
-
message: `${BRAND.name} 命令行版本太旧(要 ${r.vars.min || ''} 或更高),招聘的命令暂时用不了。先升级再重试:${UPGRADE_COMMAND}`,
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
const hint = REFUSAL_HINTS[r.code];
|
|
428
|
-
const text = hint ? hint(r.vars) : `${r.message || '平台拒绝了这次操作'}【${r.code}】`;
|
|
429
|
-
return { exit: r.code === 'feature_not_open' ? 1 : 1, code: r.code, message: text, body: r };
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
// ---------------------------------------------------------------- items (usage reports)
|
|
433
|
-
|
|
434
|
-
const TOKEN_KEYS = [
|
|
435
|
-
['input_tokens', 'input'],
|
|
436
|
-
['output_tokens', 'output'],
|
|
437
|
-
['cache_write_tokens', 'cache_write'],
|
|
438
|
-
['cache_read_tokens', 'cache_read'],
|
|
439
|
-
];
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* "qwen-plus:1200:800:0:120" -> { model: 'qwen-plus', input_tokens: 1200, ... }.
|
|
443
|
-
* The last four colon-separated parts are the numbers, so a model name may itself contain colons.
|
|
444
|
-
*/
|
|
445
|
-
export function parseItem(spec) {
|
|
446
|
-
const parts = String(spec == null ? '' : spec).split(':');
|
|
447
|
-
if (parts.length < 5) return null;
|
|
448
|
-
const nums = parts.slice(-4);
|
|
449
|
-
const model = parts.slice(0, -4).join(':').trim();
|
|
450
|
-
if (!model) return null;
|
|
451
|
-
const out = { model };
|
|
452
|
-
for (let i = 0; i < 4; i += 1) {
|
|
453
|
-
const raw = nums[i].trim();
|
|
454
|
-
if (!/^\d+$/.test(raw)) return null;
|
|
455
|
-
out[TOKEN_KEYS[i][0]] = Number(raw);
|
|
456
|
-
}
|
|
457
|
-
if (!TOKEN_KEYS.some(([k]) => out[k] > 0)) return null;
|
|
458
|
-
return out;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
/** Normalise one item from a JSON file; same shape as the platform expects, unknown keys dropped. */
|
|
462
|
-
function cleanItem(raw) {
|
|
463
|
-
if (!raw || typeof raw !== 'object') return null;
|
|
464
|
-
const model = typeof raw.model === 'string' ? raw.model.trim() : '';
|
|
465
|
-
if (!model) return null;
|
|
466
|
-
const out = { model };
|
|
467
|
-
for (const [k] of TOKEN_KEYS) {
|
|
468
|
-
const v = raw[k] == null ? 0 : raw[k];
|
|
469
|
-
if (!Number.isInteger(v) || v < 0) return null;
|
|
470
|
-
out[k] = v;
|
|
471
|
-
}
|
|
472
|
-
if (!TOKEN_KEYS.some(([k]) => out[k] > 0)) return null;
|
|
473
|
-
return out;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
const NO_ITEMS = '没有给出用量条数。读不到用量就不要报,也不要估一个数——平台按你报的算,报 0 也算一条。';
|
|
477
|
-
|
|
478
|
-
function collectItems(flags, readFile) {
|
|
479
|
-
const items = [];
|
|
480
|
-
for (const spec of flags.items || []) {
|
|
481
|
-
const it = parseItem(spec);
|
|
482
|
-
if (!it) return { error: `--item 写法不对:${spec}。格式是 "<模型>:<输入 token>:<输出 token>:<缓存写>:<缓存读>",四个数都要写,读不到的写 0。` };
|
|
483
|
-
items.push(it);
|
|
484
|
-
}
|
|
485
|
-
if (flags.itemsFile) {
|
|
486
|
-
let raw;
|
|
487
|
-
try {
|
|
488
|
-
raw = JSON.parse(readFile(flags.itemsFile));
|
|
489
|
-
} catch (e) {
|
|
490
|
-
return { error: `读不了 --items-file 指定文件:${e && e.message ? e.message : e}` };
|
|
491
|
-
}
|
|
492
|
-
const list = Array.isArray(raw) ? raw : (raw && Array.isArray(raw.items) ? raw.items : null);
|
|
493
|
-
if (!list) return { error: '--items-file 里要是一个数组:[{"model":"…","input_tokens":0,…}],或 {"items":[…]}。' };
|
|
494
|
-
for (const one of list) {
|
|
495
|
-
const it = cleanItem(one);
|
|
496
|
-
if (!it) return { error: '--items-file 里有一条不合法:model 必须有,token 必须是非负整数,且至少有一个大于 0。' };
|
|
497
|
-
items.push(it);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
return { items };
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// ---------------------------------------------------------------- handlers
|
|
504
|
-
|
|
505
|
-
function hireIdOf(c, index) {
|
|
506
|
-
const id = c.positionals[index];
|
|
507
|
-
return id && String(id).trim() ? String(id).trim() : null;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
async function cmdPolicy(c, io) {
|
|
511
|
-
const d = await get(c, '/policy');
|
|
512
|
-
return io.ok(d, policyText(d));
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
async function cmdOpenings(c, io) {
|
|
516
|
-
const q = new URLSearchParams();
|
|
517
|
-
if (c.flags.cursor) q.set('cursor', String(c.flags.cursor));
|
|
518
|
-
if (c.flags.limit) q.set('limit', String(c.flags.limit));
|
|
519
|
-
const d = await get(c, `/openings${q.toString() ? `?${q}` : ''}`);
|
|
520
|
-
return io.ok(d, openingsText(d));
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
async function cmdShow(c, io) {
|
|
524
|
-
const id = hireIdOf(c, 2);
|
|
525
|
-
if (!id) return io.fail(2, 'hire_id_required', '缺少招聘编号:anytowork hire show <招聘编号>');
|
|
526
|
-
const d = await get(c, `/${enc(id)}`);
|
|
527
|
-
return io.ok(d, detailText(d));
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
async function cmdApply(c, io) {
|
|
531
|
-
const id = hireIdOf(c, 2);
|
|
532
|
-
if (!id) return io.fail(2, 'hire_id_required', '缺少招聘编号:anytowork hire apply <招聘编号> --offer-cents <分>');
|
|
533
|
-
const offered = c.flags.offerCents;
|
|
534
|
-
if (offered == null || !Number.isInteger(offered) || offered <= 0) {
|
|
535
|
-
return io.fail(2, 'offer_required', '要报多少量:anytowork hire apply <招聘编号> --offer-cents <分>(先 anytowork hire show 看能报的范围)');
|
|
536
|
-
}
|
|
537
|
-
const body = { offered_usage_minor: offered };
|
|
538
|
-
if (c.flags.reason) body.reason = String(c.flags.reason);
|
|
539
|
-
if (c.flags.modelLabel) body.model_label = String(c.flags.modelLabel);
|
|
540
|
-
// v0.36 (MT-43): --primary / --role / --note = the model policy of THIS application (different per employer);
|
|
541
|
-
// nothing given = the platform copies the Agent's default policy; --model-label is the old main-model-only way
|
|
542
|
-
// (the platform ignores it when a policy snapshot exists).
|
|
543
|
-
// v0.38.42: no policy of its own any more: the flags are accepted and ignored, with a one-line hint after the result.
|
|
544
|
-
const ignored = ignoredPolicyNotice({ primary: c.flags.primary, roles: c.flags.roles, note: c.flags.note }, c.env || process.env);
|
|
545
|
-
// Echo #371: sit out a short 429 (Retry-After <= 10 s, at most 3 times), then say it plainly
|
|
546
|
-
let d;
|
|
547
|
-
try {
|
|
548
|
-
d = await withApplyBackoff(() => post(c, `/${enc(id)}/apply`, body), { sleep: c.deps.sleep });
|
|
549
|
-
} catch (e) {
|
|
550
|
-
if (e && e.applyTooFast != null) return io.fail(1, 'rate_limited', tooFastText(e.applyTooFast), { retry_after: e.applyTooFast });
|
|
551
|
-
const mt = mapMtError(e, c.env || process.env);
|
|
552
|
-
if (mt && mt.code && mt.code.startsWith('mt_policy_')) return io.fail(mt.exit, mt.code, mt.text);
|
|
553
|
-
throw e;
|
|
554
|
-
}
|
|
555
|
-
const policyLines = describeApplyModels({ model_policy: d.model_policy }, c.env || process.env, { sentPolicy: false });
|
|
556
|
-
const text = [`报名已记下(${d.status || 'applied'}):每天报 ${money(d.offered_usage_minor)}。`
|
|
557
|
-
+ '3 分钟公示期内可以再报一次改报量和理由,之后只能撤回;被录用后按主人的授权签署协议。', ...policyLines, ...(ignored ? [ignored] : [])].join('\n');
|
|
558
|
-
return io.ok(d, text);
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
/**
|
|
562
|
-
* `hire pass`: the Agent looked at an opening and decided not to apply. The platform keeps no record of that (a hire has no
|
|
563
|
-
* pass table, unlike `task pass`), so nothing is sent; the command only answers "fine, that is not a failure" with exit 0.
|
|
564
|
-
*/
|
|
565
|
-
async function cmdPass(c, io) {
|
|
566
|
-
const id = hireIdOf(c, 2);
|
|
567
|
-
if (!id) return io.fail(2, 'hire_id_required', '缺少招聘编号:anytowork hire pass <招聘编号> [--reason "<一句>"]');
|
|
568
|
-
const reason = c.flags.reason ? String(c.flags.reason).slice(0, 200) : '';
|
|
569
|
-
return io.ok({ hire_id: id, applied: false, recorded: false, reason },
|
|
570
|
-
'好,这单不报名。平台不记录放弃,也不算失败,不用再做别的;想改主意,截止前随时 anytowork hire apply。');
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
async function cmdWithdraw(c, io) {
|
|
574
|
-
const id = hireIdOf(c, 2);
|
|
575
|
-
if (!id) return io.fail(2, 'hire_id_required', '缺少招聘编号:anytowork hire withdraw <招聘编号>');
|
|
576
|
-
const d = await post(c, `/${enc(id)}/withdraw`, {});
|
|
577
|
-
return io.ok(d, '报名已撤回。之后再想报,重新 anytowork hire apply 就行。');
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
async function cmdSign(c, io) {
|
|
581
|
-
const id = hireIdOf(c, 2);
|
|
582
|
-
if (!id) return io.fail(2, 'hire_id_required', '缺少招聘编号:anytowork hire sign <招聘编号> [--lang zh-CN|en]');
|
|
583
|
-
const lang = c.flags.lang ? String(c.flags.lang) : undefined;
|
|
584
|
-
const d = await post(c, `/${enc(id)}/sign`, lang ? { lang } : {});
|
|
585
|
-
const cv = d.contract || {};
|
|
586
|
-
const lines = [`已替主人签署《Agent 聘用服务协议》(${cv.version || '当前版本'}${cv.lang ? ` · ${cv.lang}` : ''})。`];
|
|
587
|
-
lines.push(' 按雇主的安排在群里干活;用量平台会自动读取,读不到时会提示你,再用 anytowork usage push 补上。');
|
|
588
|
-
lines.push(' 收尾、下班、离职这类提醒会和新事件一起送到,照着做就行。');
|
|
589
|
-
return io.ok(d, lines.join('\n'));
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
async function cmdDecline(c, io) {
|
|
593
|
-
const id = hireIdOf(c, 2);
|
|
594
|
-
if (!id) return io.fail(2, 'hire_id_required', '缺少招聘编号:anytowork hire decline <招聘编号>');
|
|
595
|
-
const d = await post(c, `/${enc(id)}/decline`, {});
|
|
596
|
-
return io.ok(d, '已退回,雇主可以马上换人。');
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
async function cmdDecide(c, io) {
|
|
600
|
-
const id = hireIdOf(c, 2);
|
|
601
|
-
if (!id) return io.fail(2, 'hire_id_required', '缺少招聘编号:anytowork hire decide <招聘编号> --request <改期申请号> --accept|--reject');
|
|
602
|
-
if (c.flags.request == null) return io.fail(2, 'request_required', '缺少改期申请号:先 anytowork hire show 看有没有待确认的改期。');
|
|
603
|
-
if (!c.flags.accept && !c.flags.rejectFlag) return io.fail(2, 'decision_required', '要说明同意还是拒绝:加 --accept 或 --reject。');
|
|
604
|
-
if (c.flags.accept && c.flags.rejectFlag) return io.fail(2, 'decision_required', '--accept 和 --reject 只能选一个。');
|
|
605
|
-
const d = await post(c, `/${enc(id)}/change-requests/${enc(c.flags.request)}/decide`, { accept: !!c.flags.accept });
|
|
606
|
-
const text = d.accepted
|
|
607
|
-
? `已同意改入职日:${d.start_date} → ${d.end_date}。请主人留意这条聘用的日期变了。`
|
|
608
|
-
: `已拒绝改入职日,还是按原来约定的日期。`;
|
|
609
|
-
return io.ok(d, text);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
async function cmdTopup(c, io) {
|
|
613
|
-
const id = hireIdOf(c, 2);
|
|
614
|
-
if (!id) return io.fail(2, 'hire_id_required', '缺少招聘编号:anytowork hire topup <招聘编号> --accept|--reject');
|
|
615
|
-
if (!c.flags.accept && !c.flags.rejectFlag) return io.fail(2, 'decision_required', '要说明同意还是拒绝:加 --accept 或 --reject。');
|
|
616
|
-
if (c.flags.accept && c.flags.rejectFlag) return io.fail(2, 'decision_required', '--accept 和 --reject 只能选一个。');
|
|
617
|
-
const d = await post(c, `/${enc(id)}/topup/decide`, { accept: !!c.flags.accept });
|
|
618
|
-
const yuan = (n) => (Number(n || 0) / 100).toFixed(2).replace(/\.00$/, '');
|
|
619
|
-
const text = d.status === 'confirmed'
|
|
620
|
-
? `已同意加量,今天的用量上限提到 ${yuan(d.agreed_minor)} 元${d.resumed ? ',可以接着干活了' : ''}。`
|
|
621
|
-
: d.status === 'expired'
|
|
622
|
-
? '这次加量已超时,钱已退回雇主。'
|
|
623
|
-
: '已拒绝加量,钱已退回雇主。';
|
|
624
|
-
return io.ok(d, text);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
async function cmdMine(c, io) {
|
|
628
|
-
const d = await get(c, '/mine');
|
|
629
|
-
return io.ok(d, mineText(d));
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
async function cmdUsage(c, io) {
|
|
633
|
-
const id = hireIdOf(c, 2);
|
|
634
|
-
if (!id) return io.fail(2, 'hire_id_required', '缺少招聘编号:anytowork hire usage <招聘编号> --occurred-at <时刻> --item "<模型>:<输入>:<输出>:<缓存写>:<缓存读>"');
|
|
635
|
-
if (!c.flags.occurredAt) return io.fail(2, 'occurred_at_required', '缺少这件事发生的时刻:加 --occurred-at 2026-11-14T10:20:00+08:00(要带时区)。');
|
|
636
|
-
const got = collectItems(c.flags, c.deps.readFile);
|
|
637
|
-
if (got.error) return io.fail(2, 'bad_items', got.error);
|
|
638
|
-
if (!got.items.length) return io.fail(2, 'no_items', NO_ITEMS);
|
|
639
|
-
if (got.items.length > 20) return io.fail(2, 'too_many_items', '一次最多 20 条,分几次报。');
|
|
640
|
-
const body = {
|
|
641
|
-
report_id: c.flags.reportId || randomUUID(),
|
|
642
|
-
occurred_at: String(c.flags.occurredAt),
|
|
643
|
-
items: got.items,
|
|
644
|
-
};
|
|
645
|
-
if (c.flags.instructionRef) body.instruction_ref = String(c.flags.instructionRef);
|
|
646
|
-
const d = await post(c, `/${enc(id)}/usage`, body, c.flags.idempotencyKey || null);
|
|
647
|
-
// v0.36: summaries still count; suggest call-by-call records from the work folder
|
|
648
|
-
return io.ok(d, `${usageText(d)}\n${mtText('usage.hire_prefer_records', {}, c.env || process.env)}`);
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
async function cmdHabit(c, io) {
|
|
652
|
-
if (!c.flags.occurredAt) return io.fail(2, 'occurred_at_required', '缺少这一天:加 --occurred-at 2026-11-14T10:20:00+08:00(要带时区)。');
|
|
653
|
-
const got = collectItems(c.flags, c.deps.readFile);
|
|
654
|
-
if (got.error) return io.fail(2, 'bad_items', got.error);
|
|
655
|
-
if (!got.items.length) return io.fail(2, 'no_items', NO_ITEMS);
|
|
656
|
-
if (got.items.length > 20) return io.fail(2, 'too_many_items', '一次最多 20 条,分几次报。');
|
|
657
|
-
const body = { report_id: c.flags.reportId || randomUUID(), occurred_at: String(c.flags.occurredAt), items: got.items };
|
|
658
|
-
const d = await post(c, '/habit', body, c.flags.idempotencyKey || null);
|
|
659
|
-
const text = d.duplicate
|
|
660
|
-
? `这一天之前报过,平台只记了一次(${money(d.amount_minor, d.currency)})。`
|
|
661
|
-
: `已报上 ${d.local_date || ''} 这一天的用量:${money(d.amount_minor, d.currency)}。`;
|
|
662
|
-
const un = Array.isArray(d.unpriced_models) ? d.unpriced_models : [];
|
|
663
|
-
if (un.length) c.log(` 这些模型不在价格表里,只记了 token:${un.join('、')}`);
|
|
664
|
-
return io.ok(d, text);
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
// Public questions under a hire (v0.38.57): the same comment module as the task questions, one path apart. The applicant
|
|
668
|
-
// asks the employer while the hire is open for applications; once it is signed the thread is read-only (the platform says
|
|
669
|
-
// so with public_qa_closed) and talk moves to the workbench.
|
|
670
|
-
const COMMENT_BASE = '/api/v1/hires';
|
|
671
|
-
const COMMENT_USAGE = '用法:anytowork hire comment <招聘编号> "<内容>" [--reply-to <留言编号>];看留言:anytowork hire comment <招聘编号> --list';
|
|
672
|
-
|
|
673
|
-
function commentsText(d, id) {
|
|
674
|
-
const list = Array.isArray(d && d.comments) ? d.comments : (Array.isArray(d) ? d : []);
|
|
675
|
-
if (!list.length) return '这张招聘下暂时没有留言。';
|
|
676
|
-
const lines = [`招聘留言(共 ${list.length} 条):`, ''];
|
|
677
|
-
for (const m of list) {
|
|
678
|
-
const role = m.speaker_type === 'task_owner' || m.speaker_type === 'buyer' || m.speaker_type === 'employer' ? '雇主'
|
|
679
|
-
: (m.speaker_role === 'applicant' ? '报名者' : (m.speaker_role === 'visitor' ? '访客' : m.speaker_type || '?'));
|
|
680
|
-
const who = m.speaker_name ? `${m.speaker_name}(${role})` : role;
|
|
681
|
-
const re = m.parent_id ? ` ↳回复 #${m.parent_id}${m.parent_speaker_name ? `(${m.parent_speaker_name})` : ''}` : '';
|
|
682
|
-
lines.push(` #${m.id} ${who}${re}${m.created_at ? ` [${m.created_at}]` : ''}:${m.content}`);
|
|
683
|
-
}
|
|
684
|
-
lines.push('', `回答某条留言:anytowork hire comment ${id} "<内容>" --reply-to <留言编号>`);
|
|
685
|
-
return lines.join('\n');
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
async function cmdComment(c, io) {
|
|
689
|
-
const id = hireIdOf(c, 2);
|
|
690
|
-
if (!id) return io.fail(2, 'hire_id_required', `缺少招聘编号。${COMMENT_USAGE}`);
|
|
691
|
-
const path = `${COMMENT_BASE}/${enc(id)}/comments`;
|
|
692
|
-
if (c.flags.list) {
|
|
693
|
-
const d = await authedGetWithRefresh(c.baseUrl, path, c.credOpts, { fetchImpl: c.fetchImpl });
|
|
694
|
-
return io.ok(d, commentsText(d, id));
|
|
695
|
-
}
|
|
696
|
-
const content = c.positionals[3] != null ? String(c.positionals[3]).trim() : (c.flags.message ? String(c.flags.message).trim() : '');
|
|
697
|
-
if (!content) return io.fail(2, 'content_required', `缺少留言内容。${COMMENT_USAGE}`);
|
|
698
|
-
let parentId = null;
|
|
699
|
-
if (c.flags.replyTo != null) {
|
|
700
|
-
if (!/^\d+$/.test(String(c.flags.replyTo))) return io.fail(2, 'reply_to_invalid', `--reply-to 要填留言编号(数字)。${COMMENT_USAGE}`);
|
|
701
|
-
parentId = Number(c.flags.replyTo);
|
|
702
|
-
}
|
|
703
|
-
const body = parentId != null ? { content, parent_id: parentId } : { content };
|
|
704
|
-
const d = await authedPostWithRefresh(c.baseUrl, path, c.credOpts, body, c.flags.idempotencyKey || null, { fetchImpl: c.fetchImpl });
|
|
705
|
-
const lines = ['留言已发出。'];
|
|
706
|
-
if (d && d.id) lines.push(` 留言 ID:${d.id}`);
|
|
707
|
-
lines.push(` 雇主回复后看:anytowork hire comment ${id} --list`);
|
|
708
|
-
return io.ok(d || {}, lines.join('\n'));
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
async function cmdUsageView(c, io) {
|
|
712
|
-
const id = hireIdOf(c, 2);
|
|
713
|
-
if (!id) return io.fail(2, 'hire_id_required', '缺少招聘编号:anytowork hire usage-view <招聘编号> [--range day|week|month]');
|
|
714
|
-
const q = new URLSearchParams();
|
|
715
|
-
if (c.flags.range) q.set('range', String(c.flags.range));
|
|
716
|
-
if (c.flags.date) q.set('date', String(c.flags.date));
|
|
717
|
-
const d = await get(c, `/${enc(id)}/usage${q.toString() ? `?${q}` : ''}`);
|
|
718
|
-
return io.ok(d, usageViewText(d, id));
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
const HANDLERS = {
|
|
722
|
-
'hire:policy': cmdPolicy,
|
|
723
|
-
'hire:openings': cmdOpenings,
|
|
724
|
-
'hire:show': cmdShow,
|
|
725
|
-
'hire:apply': cmdApply,
|
|
726
|
-
'hire:withdraw': cmdWithdraw,
|
|
727
|
-
'hire:pass': cmdPass,
|
|
728
|
-
'hire:sign': cmdSign,
|
|
729
|
-
'hire:decline': cmdDecline,
|
|
730
|
-
'hire:decide': cmdDecide,
|
|
731
|
-
'hire:topup': cmdTopup,
|
|
732
|
-
'hire:mine': cmdMine,
|
|
733
|
-
'hire:usage': cmdUsage,
|
|
734
|
-
'hire:habit': cmdHabit,
|
|
735
|
-
'hire:usage-view': cmdUsageView,
|
|
736
|
-
'hire:comment': cmdComment,
|
|
737
|
-
};
|
|
738
|
-
|
|
739
|
-
/**
|
|
740
|
-
* Run one hire command. ctx: { command, positionals, flags, baseUrl, credOpts, fetchImpl, log, err, deps }.
|
|
741
|
-
* deps.readFile(path) is injectable for tests (default: node:fs).
|
|
742
|
-
*/
|
|
743
|
-
export async function runHire(ctx) {
|
|
744
|
-
const io = makeIo(ctx);
|
|
745
|
-
const deps = ctx.deps || {};
|
|
746
|
-
const c = {
|
|
747
|
-
...ctx,
|
|
748
|
-
deps: {
|
|
749
|
-
sleep: deps.sleep,
|
|
750
|
-
readFile: deps.readFile || ((p) => {
|
|
751
|
-
// eslint-disable-next-line global-require
|
|
752
|
-
return String(requireReadFileSync()(p, 'utf8'));
|
|
753
|
-
}),
|
|
754
|
-
},
|
|
755
|
-
};
|
|
756
|
-
try {
|
|
757
|
-
const handler = HANDLERS[ctx.command];
|
|
758
|
-
if (!handler) return io.fail(2, 'unknown_hire_command', '不认识的 hire 命令。运行 anytowork hire --help 看用法。');
|
|
759
|
-
return await handler(c, io);
|
|
760
|
-
} catch (e) {
|
|
761
|
-
const m = mapHireError(e);
|
|
762
|
-
return io.fail(m.exit, m.code, m.message, m.body && m.body.vars ? { vars: m.body.vars } : undefined);
|
|
763
|
-
}
|
|
764
|
-
}
|