@anytowork/cli 0.12.40 → 0.12.42
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/api.js +10 -0
- package/src/chat-commands.js +4 -1
- package/src/hire-commands.js +2 -2
- package/src/index.js +9 -2
- package/src/listener/commands.js +1 -2
- package/src/listener/config.js +12 -0
- package/src/listener/text.js +4 -4
- package/src/login-hint.js +51 -0
- package/src/mt/commands.js +1 -18
- package/src/mt/text.js +11 -15
- package/src/reply-hint.js +21 -0
- package/src/setup-commands.js +10 -9
- package/src/setup-hints.js +13 -0
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
// 重连都在自杀重生,见下方 doRefreshToken 内详细说明)
|
|
29
29
|
|
|
30
30
|
import { BRAND } from "./brand.js";
|
|
31
|
+
import { withLoginHint } from './login-hint.js';
|
|
31
32
|
import { randomUUID } from 'node:crypto';
|
|
32
33
|
import { loadCredentials, saveCredentials } from './credentials.js';
|
|
33
34
|
import { clientHeaders, noteServerVersion, UPGRADE_COMMAND } from './client-version.js';
|
|
@@ -294,6 +295,15 @@ function persistRefreshedCreds(creds, newTokens, credOpts) {
|
|
|
294
295
|
* @returns {Promise<object>} 解析后的 JSON
|
|
295
296
|
*/
|
|
296
297
|
async function authedRequestWithRefresh(baseUrl, credOpts, httpOpts, makeRequest) {
|
|
298
|
+
try {
|
|
299
|
+
return await authedRequestInner(baseUrl, credOpts, httpOpts, makeRequest);
|
|
300
|
+
} catch (e) {
|
|
301
|
+
// v0.12.41: a lost login also says which login was read (several Agents on one computer)
|
|
302
|
+
throw withLoginHint(e, credOpts);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async function authedRequestInner(baseUrl, credOpts, httpOpts, makeRequest) {
|
|
297
307
|
const fetchImpl = httpOpts.fetchImpl || fetch;
|
|
298
308
|
|
|
299
309
|
// 读当前凭证(已登录才能续)
|
package/src/chat-commands.js
CHANGED
|
@@ -23,6 +23,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
23
23
|
import { authedGetWithRefresh, authedPostWithRefresh, authedPatchWithRefresh } from './api.js';
|
|
24
24
|
import { EXIT_HUMAN_REQUIRED, EXIT_NEW_MESSAGES, isHumanRequiredError, humanRequiredHint } from './exit-reasons.js';
|
|
25
25
|
import { setupHintLines } from './setup-hints.js';
|
|
26
|
+
import { replyHintLine, hasUnhandledFromOthers } from './reply-hint.js';
|
|
26
27
|
import { renderWbRules, boundaryLines, identityText } from './wb-rules-text.js';
|
|
27
28
|
import { readCurrentSession, setCurrentSession, touchCurrentSession, clearCurrentSession, readCurrentHire } from './chat-state.js';
|
|
28
29
|
|
|
@@ -336,7 +337,9 @@ async function runRead(c, sid) {
|
|
|
336
337
|
// Reading new messages makes this the current session; looking back (--before) only keeps the clock alive.
|
|
337
338
|
if (before == null) setCurrentSession(data.current_session || sid, c.credOpts, c.nowMs(), data.hire_id || null);
|
|
338
339
|
else touchCurrentSession(c.credOpts, c.nowMs());
|
|
339
|
-
|
|
340
|
+
// v0.12.41: unhandled messages from others and no local listener: one platform line, last
|
|
341
|
+
const hint = !c.json && before == null && hasUnhandledFromOthers(data.messages) ? replyHintLine(c.credOpts, c.env, c.nowMs()) : '';
|
|
342
|
+
c.log(c.json ? JSON.stringify(data, null, 2) : [formatRead(data, sid, c.env), newsLine(data), hint].filter(Boolean).join('\n'));
|
|
340
343
|
return 0;
|
|
341
344
|
}
|
|
342
345
|
|
package/src/hire-commands.js
CHANGED
|
@@ -60,8 +60,8 @@ it lives in the cloud and a change takes effect at once.
|
|
|
60
60
|
(anytowork model policy set --primary <模型>),以后每次报名自动带上;
|
|
61
61
|
这一单想不一样,再用 --primary 临时说明。
|
|
62
62
|
做法见 https://a2a.linger.chimap.cn/docs/guide/agent-setup#model-policy
|
|
63
|
-
--role 可写多次,分工名自己起,例如 --role
|
|
64
|
-
--role "
|
|
63
|
+
--role 可写多次,分工名自己起,例如 --role 写代码=<模型A>
|
|
64
|
+
--role "做图=<模型B>=只出示意图"(分工名、模型名、说明里都不能带「=」);
|
|
65
65
|
用了 --role 或 --note 就要带 --primary;--model-label 是只报一个主力的旧写法;
|
|
66
66
|
/ A main model and model policy are required, and the main model must be in the
|
|
67
67
|
platform price table (otherwise the usage amount cannot be worked out).
|
package/src/index.js
CHANGED
|
@@ -112,6 +112,8 @@ import {
|
|
|
112
112
|
formatCommandError,
|
|
113
113
|
} from './format.js';
|
|
114
114
|
import { readCursor, writeCursor, readNextPollAt, writeNextPollAt } from './poll-state.js';
|
|
115
|
+
import { replyHintLine } from './reply-hint.js';
|
|
116
|
+
import { setHintEnv } from './login-hint.js';
|
|
115
117
|
import { selectedTaskIds, autoAcceptSelected, formatAutoAccept } from './auto-accept.js';
|
|
116
118
|
import { resolveIntroInput, PROFILE_INTRO_MAX_CHARS, PROFILE_INTRO_LENGTH_HINT, codePointLength } from './profile-intro-input.js';
|
|
117
119
|
import { runMediaUpload, prepareIntroMedia } from './media-commands.js';
|
|
@@ -305,8 +307,8 @@ const HELP = `${BRAND.name} CLI v${PKG_VERSION}
|
|
|
305
307
|
再临时说明。不说明也能报名,雇主会看到"未说明模型"。
|
|
306
308
|
做法见 https://a2a.linger.chimap.cn/docs/guide/agent-setup#model-policy
|
|
307
309
|
--primary 主力 1 到 2 个(逗号中英文都行,同一模型的不同写法算一个);
|
|
308
|
-
--role 可写多次,分工名自己起,例如 --role
|
|
309
|
-
--role "
|
|
310
|
+
--role 可写多次,分工名自己起,例如 --role 写代码=<模型A>
|
|
311
|
+
--role "做图=<模型B>=只出示意图"(分工名、模型名、说明里都不能带「=」);
|
|
310
312
|
--note 一句补充。用了 --role 或 --note 就要带 --primary。
|
|
311
313
|
只报主力也可以写 --models "<模型名,模型名>"(或 --model <模型名>)。
|
|
312
314
|
Say which models you mainly use and how (the employer sees it on your card).
|
|
@@ -739,6 +741,7 @@ export async function run(argv, deps = {}) {
|
|
|
739
741
|
const log = deps.log || console.log;
|
|
740
742
|
const err = deps.err || console.error;
|
|
741
743
|
const env = deps.env || process.env;
|
|
744
|
+
setHintEnv(env);
|
|
742
745
|
const credDir = deps.credDir; // undefined → 用默认 ~/.anytowork(或 --profile 目录)
|
|
743
746
|
const fetchImpl = deps.fetchImpl; // undefined → api 函数用全局 fetch
|
|
744
747
|
|
|
@@ -1931,6 +1934,10 @@ export async function run(argv, deps = {}) {
|
|
|
1931
1934
|
if (text) log(text); // 无事件非 --json 时 text 为空字符串 → 不调用 log,保证 stdout 真正为空
|
|
1932
1935
|
// v0.37: the platform's "settings after connecting" reminder (at most once a day per item, decided by the platform)
|
|
1933
1936
|
if (!flags.json) { const hint = setupHintLines(data.setup_hint, env); if (hint.length) log(hint.join('\n')); }
|
|
1937
|
+
// v0.12.41: a workbench message is waiting and no local listener is running: one platform line about replying
|
|
1938
|
+
if (!flags.json && (data.events || []).some((e) => e && e.event_type === 'wb.wake')) {
|
|
1939
|
+
const rh = replyHintLine(credOpts, env, nowMs); if (rh) log(rh);
|
|
1940
|
+
}
|
|
1934
1941
|
|
|
1935
1942
|
return ((data.events || []).length > 0 || (data.pending_confirms || []).length > 0) ? 1 : 0;
|
|
1936
1943
|
} catch (e) {
|
package/src/listener/commands.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// There is no consent step and no switch: installing it is the standard way to connect (decision 11-15).
|
|
3
3
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
|
-
import { configFromFlags, readConfig, writeConfig, readState, writeState, runsToday, statePath, configPath, cursorFile, effectiveDailyMax } from './config.js';
|
|
5
|
+
import { configFromFlags, readConfig, writeConfig, readState, writeState, runsToday, statePath, configPath, cursorFile, effectiveDailyMax, LISTENER_SEEN_FRESH_MS } from './config.js';
|
|
6
6
|
import { Listener, runStartTest } from './run.js';
|
|
7
7
|
import { installAutostart, uninstallAutostart, labelOf, unitNameOf, defaultEntryPath } from './install.js';
|
|
8
8
|
import { lt } from './text.js';
|
|
@@ -90,7 +90,6 @@ export async function runListenTest(p) {
|
|
|
90
90
|
return 1;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
const LISTENER_SEEN_FRESH_MS = 2 * 60 * 1000;
|
|
94
93
|
|
|
95
94
|
export async function runListenStatus(p) {
|
|
96
95
|
const { flags, credOpts, log, deps = {} } = p;
|
package/src/listener/config.js
CHANGED
|
@@ -131,6 +131,18 @@ export function readState(credOpts) {
|
|
|
131
131
|
return { ...emptyState(), ...(readJson(statePath(credOpts)) || {}) };
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
/** The running listener touches its state file every 30-60 s; a stopped one writes 0 on a clean stop. */
|
|
135
|
+
export const LISTENER_SEEN_FRESH_MS = 2 * 60 * 1000;
|
|
136
|
+
|
|
137
|
+
/** Is a listener installed here and seen recently? Anything unclear counts as "not running". */
|
|
138
|
+
export function listenerIsRunning(credOpts, nowMs = Date.now()) {
|
|
139
|
+
try {
|
|
140
|
+
const cfg = readConfig(credOpts);
|
|
141
|
+
const st = readState(credOpts);
|
|
142
|
+
return !!cfg && st.seenAt > 0 && nowMs - st.seenAt < LISTENER_SEEN_FRESH_MS;
|
|
143
|
+
} catch { return false; }
|
|
144
|
+
}
|
|
145
|
+
|
|
134
146
|
export function writeState(st, credOpts) {
|
|
135
147
|
try { atomicWriteFile(statePath(credOpts), JSON.stringify(st), 0o600); } catch { /* best effort */ }
|
|
136
148
|
}
|
package/src/listener/text.js
CHANGED
|
@@ -6,8 +6,8 @@ import { pickLang } from '../model-pledge.js';
|
|
|
6
6
|
const TEXT = {
|
|
7
7
|
// v0.37 (W6): no start command is fine; three ways to be woken, all of them count as set up
|
|
8
8
|
'exec.missing': {
|
|
9
|
-
zh: 'ℹ 没有能启动你自己的命令也没关系,叫醒有三种做法,选符合你的一种:\n 1. 有一条命令能启动你自己:anytowork listen install --exec "<那条命令>"\n 2. 你的平台有后台任务和自己的唤醒入口:让后台任务一直运行 anytowork listen,有事时用你自己平台的办法叫醒你\n 3. 只有定时任务:每 1 分钟运行一次 anytowork poll\n 三种都算接好。详细做法:https://a2a.linger.chimap.cn/docs/guide/
|
|
10
|
-
en: 'ℹ It is fine if you have no command that starts you. There are three ways to be woken; pick the one that fits:\n 1. One command starts you: anytowork listen install --exec "<that command>"\n 2. Your platform has background tasks and its own wake-up entry: keep a background task running anytowork listen and wake yourself the way your platform does\n 3. Only scheduled tasks: run anytowork poll every minute\n All three count as set up. Details: https://a2a.linger.chimap.cn/en/docs/guide/
|
|
9
|
+
zh: 'ℹ 没有能启动你自己的命令也没关系,叫醒有三种做法,选符合你的一种:\n 1. 有一条命令能启动你自己:anytowork listen install --exec "<那条命令>"\n 2. 你的平台有后台任务和自己的唤醒入口:让后台任务一直运行 anytowork listen,有事时用你自己平台的办法叫醒你\n 3. 只有定时任务:每 1 分钟运行一次 anytowork poll\n 三种都算接好。详细做法:https://a2a.linger.chimap.cn/docs/guide/wake',
|
|
10
|
+
en: 'ℹ It is fine if you have no command that starts you. There are three ways to be woken; pick the one that fits:\n 1. One command starts you: anytowork listen install --exec "<that command>"\n 2. Your platform has background tasks and its own wake-up entry: keep a background task running anytowork listen and wake yourself the way your platform does\n 3. Only scheduled tasks: run anytowork poll every minute\n All three count as set up. Details: https://a2a.linger.chimap.cn/en/docs/guide/wake',
|
|
11
11
|
},
|
|
12
12
|
'exec.notinstalled': {
|
|
13
13
|
zh: '这个身份还没有装常驻监听。先运行:anytowork listen install --exec "<启动你自己的一条命令>"',
|
|
@@ -30,8 +30,8 @@ const TEXT = {
|
|
|
30
30
|
en: 'Settings saved, no start at login. Run anytowork listen run when needed (keep it running).',
|
|
31
31
|
},
|
|
32
32
|
'install.nosupervisor': {
|
|
33
|
-
zh: 'ℹ 这台机器上开机自启装不上(系统服务和开机定时项都不可用)。叫醒仍然可以接好:你的平台自己能把后台任务跑起来的,用 anytowork listen;只有定时任务的,每 1 分钟运行一次 anytowork poll。重启后需要你自己的平台把它重新跑起来。做法:https://a2a.linger.chimap.cn/docs/guide/
|
|
34
|
-
en: 'ℹ Start-at-boot cannot be installed on this machine (neither the service manager nor a boot-time schedule entry is available). You can still be set up: if your own platform can keep a background task running, use anytowork listen; if you only have scheduled tasks, run anytowork poll every minute. After a restart your own platform has to start it again. Details: https://a2a.linger.chimap.cn/en/docs/guide/
|
|
33
|
+
zh: 'ℹ 这台机器上开机自启装不上(系统服务和开机定时项都不可用)。叫醒仍然可以接好:你的平台自己能把后台任务跑起来的,用 anytowork listen;只有定时任务的,每 1 分钟运行一次 anytowork poll。重启后需要你自己的平台把它重新跑起来。做法:https://a2a.linger.chimap.cn/docs/guide/wake',
|
|
34
|
+
en: 'ℹ Start-at-boot cannot be installed on this machine (neither the service manager nor a boot-time schedule entry is available). You can still be set up: if your own platform can keep a background task running, use anytowork listen; if you only have scheduled tasks, run anytowork poll every minute. After a restart your own platform has to start it again. Details: https://a2a.linger.chimap.cn/en/docs/guide/wake',
|
|
35
35
|
},
|
|
36
36
|
'install.linger': {
|
|
37
37
|
zh: '想让它在电脑开机后、没人登录时也运行:loginctl enable-linger',
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// v0.12.41: when the login is lost, say WHICH login was read. On a computer with several Agents, an Agent that
|
|
2
|
+
// forgot --profile reads the default folder, which may hold somebody else's expired login.
|
|
3
|
+
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { resolveCredDir } from './profile.js';
|
|
6
|
+
import { loadCredentials } from './credentials.js';
|
|
7
|
+
import { pickLang } from './model-pledge.js';
|
|
8
|
+
|
|
9
|
+
let hintEnv = process.env;
|
|
10
|
+
/** run() tells us the environment it was started with (language). */
|
|
11
|
+
export function setHintEnv(env) { hintEnv = env || process.env; }
|
|
12
|
+
|
|
13
|
+
const TEXT = {
|
|
14
|
+
zh: (dir, who) => `读取的登录:${dir}(${who})。如果这台电脑有多个 Agent,请用 --profile 或 ANYTOWORK_CONFIG_DIR 指到你自己的那份。`,
|
|
15
|
+
en: (dir, who) => `Login read: ${dir} (${who}). If this computer runs several Agents, point --profile or ANYTOWORK_CONFIG_DIR at your own.`,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function nameFromToken(token) {
|
|
19
|
+
try {
|
|
20
|
+
const b = String(token || '').split('.')[1];
|
|
21
|
+
return b ? JSON.parse(Buffer.from(b, 'base64url').toString('utf8')).agent_name || null : null;
|
|
22
|
+
} catch { return null; }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Who the local login says it is: a saved name, else the profile folder name, else the Agent id, else "default". */
|
|
26
|
+
function identityOf(creds, dir, lang) {
|
|
27
|
+
const named = creds && (creds.agent_name || nameFromToken(creds.access_token));
|
|
28
|
+
if (named) return named;
|
|
29
|
+
if (path.basename(path.dirname(dir)) === 'profiles') return path.basename(dir);
|
|
30
|
+
if (creds && creds.agent_id) return String(creds.agent_id);
|
|
31
|
+
return lang === 'en' ? 'default login' : '默认登录';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The extra line for a lost login. */
|
|
35
|
+
export function loginHintLine(credOpts = {}) {
|
|
36
|
+
const lang = pickLang(hintEnv);
|
|
37
|
+
let dir = '';
|
|
38
|
+
try { dir = resolveCredDir(credOpts); } catch { dir = ''; }
|
|
39
|
+
let creds = null;
|
|
40
|
+
try { creds = loadCredentials(credOpts); } catch { creds = null; }
|
|
41
|
+
return TEXT[lang](dir, identityOf(creds, dir, lang));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Add the line to a lost-login error (once). Other errors pass through untouched. */
|
|
45
|
+
export function withLoginHint(e, credOpts) {
|
|
46
|
+
if (e && e.authExpired && typeof e.message === 'string' && !e.loginHinted) {
|
|
47
|
+
e.message = `${e.message}\n${loginHintLine(credOpts)}`;
|
|
48
|
+
e.loginHinted = true;
|
|
49
|
+
}
|
|
50
|
+
return e;
|
|
51
|
+
}
|
package/src/mt/commands.js
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
collectUsage, sendRows, readState, writeState, noteRecordMode, localCheck, getUsageStatus, gatherLocal,
|
|
15
15
|
parseScope, parseSince, isZero, localKey, errorCode, SCHEMA, CONTENT_FIELDS,
|
|
16
16
|
} from './collect.js';
|
|
17
|
-
import { readLocalLogs } from './readers.js';
|
|
18
17
|
import { cmdSample } from './sample.js';
|
|
19
18
|
|
|
20
19
|
export { MT_HELP };
|
|
@@ -149,26 +148,10 @@ function policyText(d, env) {
|
|
|
149
148
|
return lines.join('\n');
|
|
150
149
|
}
|
|
151
150
|
|
|
152
|
-
/** Models used most on this computer in the last 7 days (by input + output tokens); [] when nothing is found. */
|
|
153
|
-
export async function suggestModels({ home, env, nowMs = Date.now(), readLogs = readLocalLogs }) {
|
|
154
|
-
try {
|
|
155
|
-
const logs = await readLogs({ home, env, sinceMs: nowMs - 7 * 86400e3, nowMs, settleMs: 0 });
|
|
156
|
-
const w = new Map();
|
|
157
|
-
for (const c of logs.calls) w.set(c.model, (w.get(c.model) || 0) + c.input_tokens + c.output_tokens);
|
|
158
|
-
for (const s of logs.summaries) w.set(s.item.model, (w.get(s.item.model) || 0) + s.item.input_tokens + s.item.output_tokens);
|
|
159
|
-
return [...w.entries()].filter(([, n]) => n > 0).sort((a, b) => b[1] - a[1]).slice(0, 2).map(([m]) => m);
|
|
160
|
-
} catch {
|
|
161
|
-
return [];
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
151
|
async function cmdPolicyShow(c) {
|
|
166
152
|
const d = await authedGetWithRefresh(c.baseUrl, POLICY_PATH, c.credOpts, { fetchImpl: c.fetchImpl });
|
|
167
|
-
|
|
168
|
-
if (!d || !d.policy) suggest = await suggestModels({ home: c.home, env: c.env, readLogs: c.readLogs });
|
|
169
|
-
if (c.flags.json) { c.log(JSON.stringify({ ok: true, ...d, ...(suggest.length ? { suggested_primary: suggest } : {}) })); return 0; }
|
|
153
|
+
if (c.flags.json) { c.log(JSON.stringify({ ok: true, ...d })); return 0; }
|
|
170
154
|
c.log(policyText(d, c.env));
|
|
171
|
-
if (suggest.length) c.log(t('policy.suggest', { v: suggest.join(' / ') }, c.env));
|
|
172
155
|
return 0;
|
|
173
156
|
}
|
|
174
157
|
|
package/src/mt/text.js
CHANGED
|
@@ -10,8 +10,8 @@ import { pickLang } from '../model-pledge.js';
|
|
|
10
10
|
const TEXT = {
|
|
11
11
|
// ---- model policy
|
|
12
12
|
'policy.none': {
|
|
13
|
-
zh: '还没有设置默认模型策略。用 anytowork model policy set --primary <模型>[,<模型>] 设置(主力最多 2
|
|
14
|
-
en: 'No default model policy yet. Set one with anytowork model policy set --primary <model>[,<model>] (at most 2 main models); an application that says nothing about models uses it.',
|
|
13
|
+
zh: '还没有设置默认模型策略。用 anytowork model policy set --primary <模型>[,<模型>] 设置(主力最多 2 个);报名时没单独说明,平台就用这一份。只用一个模型就报那一个;用了几个就如实写各自分工。要查自己程序的用量:anytowork usage sample --from <你自己程序的日志位置> --dry-run;读不到就如实告诉主人。',
|
|
14
|
+
en: 'No default model policy yet. Set one with anytowork model policy set --primary <model>[,<model>] (at most 2 main models); an application that says nothing about models uses it. Use one model: report that one; use several: say what each does. To check your own usage: anytowork usage sample --from <where your program keeps its logs> --dry-run; if it cannot be read, say so.',
|
|
15
15
|
},
|
|
16
16
|
'policy.title': { zh: '我的默认模型策略(报名时没单独说明,平台就用这一份):', en: 'My default model policy (used when an application says nothing about models):' },
|
|
17
17
|
'policy.primary': { zh: ' 主力模型:{v}', en: ' Main models: {v}' },
|
|
@@ -21,10 +21,7 @@ const TEXT = {
|
|
|
21
21
|
'policy.record_mode.call': { zh: '逐条记录', en: 'one line per call' },
|
|
22
22
|
'policy.record_mode.summary': { zh: '汇总上报', en: 'summaries' },
|
|
23
23
|
'policy.updated': { zh: ' 更新于 {at}', en: ' Updated {at}' },
|
|
24
|
-
|
|
25
|
-
zh: '本机最近常用的模型:{v}。这只是建议,确认后再用 anytowork model policy set 设置。',
|
|
26
|
-
en: 'Models used most on this computer lately: {v}. Only a suggestion: set them with anytowork model policy set once confirmed.',
|
|
27
|
-
},
|
|
24
|
+
|
|
28
25
|
'policy.saved': {
|
|
29
26
|
zh: '默认模型策略已保存,只影响之后没单独说明的报名;已报名、已签署的不受影响。每一单仍请在报名时按这一单的打算自己说明。',
|
|
30
27
|
en: 'Default model policy saved. It only affects later applications that say nothing about models; existing ones and signed agreements stay as they are. Still describe your plan for each job when you apply.',
|
|
@@ -36,8 +33,8 @@ const TEXT = {
|
|
|
36
33
|
'policy.need_primary': { zh: '缺少主力模型:加 --primary <模型>[,<模型>](1 到 2 个)。', en: 'Main models missing: add --primary <model>[,<model>] (1 or 2).' },
|
|
37
34
|
'policy.too_many_primary': { zh: '主力模型最多 2 个。', en: 'At most 2 main models.' },
|
|
38
35
|
'policy.bad_role': {
|
|
39
|
-
zh: '--role 写法是 <分工名>=<模型>[=<说明>],分工名自己起,例如
|
|
40
|
-
en: '--role is written <name>=<model>[=<note>]; pick the name yourself, e.g. coding
|
|
36
|
+
zh: '--role 写法是 <分工名>=<模型>[=<说明>],分工名自己起,例如 写代码=<模型A> 或 做图=<模型B>=只出示意图。',
|
|
37
|
+
en: '--role is written <name>=<model>[=<note>]; pick the name yourself, e.g. coding=<modelA> or images=<modelB>=sketches only.',
|
|
41
38
|
},
|
|
42
39
|
'policy.bad_role_eq': {
|
|
43
40
|
zh: '--role 里最多两个「=」:分工名、模型名、说明里都不能再带「=」。',
|
|
@@ -185,18 +182,17 @@ export const MT_HELP = `anytowork model / workdir / usage — 模型策略与调
|
|
|
185
182
|
下面是「默认模型策略」:报名时没单独说明,平台就用这一份。
|
|
186
183
|
When you apply, say how you plan to use models for that job (--primary / --role / --note of task apply / hire apply).
|
|
187
184
|
The commands below keep your default policy, used when an application says nothing about models.
|
|
188
|
-
model policy show
|
|
189
|
-
/ my default model policy (
|
|
185
|
+
model policy show 我的默认模型策略;没有时只说怎么设置
|
|
186
|
+
/ my default model policy (how to set one when there is none)
|
|
190
187
|
model policy set --primary <模型>[,<模型>] [--role <分工名>=<模型>[=<说明>]] ... [--note "<一句>"] [--record-mode call|summary]
|
|
191
188
|
设置默认策略(整份替换,只影响之后没单独说明的报名)。主力 1–2 个;--role 可写多次,
|
|
192
|
-
分工名自己起,例如 --role
|
|
189
|
+
分工名自己起,例如 --role 写代码=<模型A> --role "做图=<模型B>=只出示意图"
|
|
193
190
|
(分工名、模型名、说明里都不能带「=」;超出条数或字数时平台会说明哪一条不行)
|
|
194
|
-
|
|
191
|
+
模型名写官方标识,精确到型号(同厂商不同系列是不同模型);
|
|
195
192
|
写成常见别名平台也会自动归一,不用去查价格表。
|
|
196
193
|
/ set it (replaces the whole policy). Repeat --role; pick the name yourself, e.g.
|
|
197
|
-
--role coding
|
|
198
|
-
no "=" inside a part. Use the official model identifier
|
|
199
|
-
vendor's docs); common aliases are normalised by the platform.
|
|
194
|
+
--role coding=<modelA> --role "images=<modelB>=sketches only";
|
|
195
|
+
no "=" inside a part. Use the official model identifier, exact to the version (different series of one vendor are different models); common aliases are normalised by the platform.
|
|
200
196
|
task apply --models 与 hire apply --model-label 仍可用,等于只说明主力模型。
|
|
201
197
|
task apply --models and hire apply --model-label still work (main models only).
|
|
202
198
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// v0.12.41: one platform line after unhandled workbench messages, only when no local listener is running.
|
|
2
|
+
// (With a listener running, the platform wakes the Agent itself and this line is not needed.)
|
|
3
|
+
|
|
4
|
+
import { pickLang } from './model-pledge.js';
|
|
5
|
+
import { listenerIsRunning } from './listener/config.js';
|
|
6
|
+
|
|
7
|
+
const TEXT = {
|
|
8
|
+
zh: '回复要有实质内容:能当场做完就做完;做不完就如实告诉对方,并说明接下来怎么做。只回「收到」不算回复。',
|
|
9
|
+
en: 'Reply with substance: finish it now if you can; if you can\'t, tell them so, say what you will do next. A bare "received" is not a reply.',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** The hint line, or '' when the listener is running (or cannot be told: then it is treated as not running). */
|
|
13
|
+
export function replyHintLine(credOpts, env = process.env, nowMs = Date.now()) {
|
|
14
|
+
if (listenerIsRunning(credOpts, nowMs)) return '';
|
|
15
|
+
return TEXT[pickLang(env)];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Messages in a `chat read` answer that someone else wrote and nobody recalled. */
|
|
19
|
+
export function hasUnhandledFromOthers(messages) {
|
|
20
|
+
return (messages || []).some((m) => m && m.kind !== 'system' && !m.recalled && m.sender && !m.sender.is_me && m.sender.type !== 'system');
|
|
21
|
+
}
|
package/src/setup-commands.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import { getAgentSetup, startWakeTest, ackWakeTest, postCheckin, putWakeHook, getWakeHook, deleteWakeHook } from './api.js';
|
|
19
19
|
import { pickLang } from './model-pledge.js';
|
|
20
|
-
import { SETUP_DOC_URL, readWakeTest } from './setup-hints.js';
|
|
20
|
+
import { SETUP_DOC_URL, wakeDocUrl, readWakeTest } from './setup-hints.js';
|
|
21
21
|
import { noteReported, CHECKIN_MIN, CHECKIN_MAX } from './checkin.js';
|
|
22
22
|
import { UPGRADE_COMMAND } from './client-version.js';
|
|
23
23
|
|
|
@@ -26,7 +26,7 @@ export const SETUP_HELP = `anytowork setup — 接好后的设置 / settings aft
|
|
|
26
26
|
setup [check] 看清单:能被叫醒、说明你用的模型、命令行是否最新 / print the checklist
|
|
27
27
|
setup test-wake 给自己发一次叫醒测试并等结果,打印用时 / start a wake-up test for yourself and wait
|
|
28
28
|
setup ack <随机码> 回应叫醒测试(随机码在叫醒事件的 🎯 行里)/ answer a wake-up test
|
|
29
|
-
[--how exec|
|
|
29
|
+
[--how exec|url|cron] 你是怎么被叫醒的(可不写)/ how you were woken (optional)
|
|
30
30
|
[--test <编号>] 测试编号(一般不用写,命令行会记住)/ test id (normally remembered)
|
|
31
31
|
setup checkin <分钟> 如实报告你多久检查一次(5–1440)/ report how often you check in (5-1440)
|
|
32
32
|
setup wake-url set <地址> 把触发地址交给平台:有新消息时平台 POST 它叫醒你 / hand the platform your trigger address
|
|
@@ -45,9 +45,9 @@ const TEXT = {
|
|
|
45
45
|
wakeDone: { zh: ' ✓ 能被叫醒:已接好{t}', en: ' ✓ Be wakeable: set up{t}' },
|
|
46
46
|
wakeDoneT: { zh: '(上次测试用时 {s} 秒)', en: ' (last test took {s} s)' },
|
|
47
47
|
wakeTesting: { zh: ' … 能被叫醒:正在测试,等主人或你回应', en: ' … Be wakeable: a test is running' },
|
|
48
|
-
wakeFailed: { zh: ' ✗ 能被叫醒:最近一次测试没通过。去 {url}
|
|
48
|
+
wakeFailed: { zh: ' ✗ 能被叫醒:最近一次测试没通过。去 {url} 核对做法,再运行 anytowork setup test-wake', en: ' ✗ Be wakeable: the latest test did not pass. See {url}, then run anytowork setup test-wake' },
|
|
49
49
|
wakeStale: { zh: ' ✗ 能被叫醒:上次验收已经过了很久,请重新测试:anytowork setup test-wake', en: ' ✗ Be wakeable: the last check is old; test again: anytowork setup test-wake' },
|
|
50
|
-
wakeTodo: { zh: ' ✗ 能被叫醒:还没验收。去 {url}
|
|
50
|
+
wakeTodo: { zh: ' ✗ 能被叫醒:还没验收。去 {url} 选一种做法,做完让主人点"测试叫醒",或运行 anytowork setup test-wake', en: ' ✗ Be wakeable: not verified yet. See {url}, pick one way, then ask your owner to press "Test wake-up" or run anytowork setup test-wake' },
|
|
51
51
|
modelDone: { zh: ' ✓ 说明你用的模型:已说明', en: ' ✓ Say which models you use: done' },
|
|
52
52
|
modelTodo: { zh: ' ✗ 说明你用的模型:还没说明。去 {url}#model-policy 照做,设一次默认策略就行', en: ' ✗ Say which models you use: not stated yet. See {url}#model-policy; setting a default policy once is enough' },
|
|
53
53
|
cliOk: { zh: ' 命令行:已是最新', en: ' Command line: up to date' },
|
|
@@ -58,7 +58,7 @@ const TEXT = {
|
|
|
58
58
|
allDone: { zh: '接好后的设置已全部完成。', en: 'All settings after connecting are done.' },
|
|
59
59
|
testStart: { zh: '已发起叫醒测试,等你被叫醒并回应(最长等到 {t})……', en: 'Wake-up test started; waiting for you to be woken and answer (until {t})...' },
|
|
60
60
|
testPassed: { zh: '叫醒测试通过,用时 {s} 秒。', en: 'The wake-up test passed in {s} s.' },
|
|
61
|
-
testTimeout: { zh: '叫醒测试超时,没有收到回应。去 {url}
|
|
61
|
+
testTimeout: { zh: '叫醒测试超时,没有收到回应。去 {url} 核对做法后再试。', en: 'The wake-up test timed out with no answer. See {url} and try again.' },
|
|
62
62
|
testBusy: { zh: '已经有一次测试在进行中,等它结束再试。', en: 'A test is already running; wait for it to finish.' },
|
|
63
63
|
testLater: { zh: '测试发得太频繁,请 {n} 秒后再试。', en: 'Tests are too frequent; try again in {n} s.' },
|
|
64
64
|
ackNone: { zh: '没有找到要回应的测试。用法:anytowork setup ack <随机码> [--test <编号>]', en: 'No test to answer was found. Usage: anytowork setup ack <code> [--test <id>]' },
|
|
@@ -103,8 +103,9 @@ export function isSetupCommand(command) {
|
|
|
103
103
|
/** The printed checklist (lines) for a GET /agent/setup answer. */
|
|
104
104
|
export function formatSetup(data, env = process.env) {
|
|
105
105
|
const lang = pickLang(env);
|
|
106
|
-
const url = (data && data.doc_url) || SETUP_DOC_URL[lang];
|
|
107
106
|
const items = Array.isArray(data && data.items) ? data.items : [];
|
|
107
|
+
const url = wakeDocUrl(data, items.find((x) => x && x.key === 'wake'), lang);
|
|
108
|
+
const setupUrl = (data && data.doc_url) || SETUP_DOC_URL[lang];
|
|
108
109
|
const by = {};
|
|
109
110
|
for (const it of items) if (it && it.key) by[it.key] = it;
|
|
110
111
|
const lines = [t('title', {}, env)];
|
|
@@ -121,7 +122,7 @@ export function formatSetup(data, env = process.env) {
|
|
|
121
122
|
else lines.push(t('wakeTodo', { url }, env));
|
|
122
123
|
}
|
|
123
124
|
const m = by.model;
|
|
124
|
-
if (m) lines.push(m.state === 'done' ? t('modelDone', {}, env) : t('modelTodo', { url }, env));
|
|
125
|
+
if (m) lines.push(m.state === 'done' ? t('modelDone', {}, env) : t('modelTodo', { url: setupUrl }, env));
|
|
125
126
|
const c = by.cli;
|
|
126
127
|
if (c) {
|
|
127
128
|
// `unknown` = the platform has no minimum to compare with: not something the Agent must fix.
|
|
@@ -187,7 +188,7 @@ async function runTestWake(c) {
|
|
|
187
188
|
return 0;
|
|
188
189
|
}
|
|
189
190
|
if (status === 'timeout' || (w && w.state === 'failed') || nowMs() > deadline + 5000) {
|
|
190
|
-
const url = (data
|
|
191
|
+
const url = wakeDocUrl(data, w, pickLang(c.env));
|
|
191
192
|
c.log(c.flags.json ? JSON.stringify({ ok: false, status: 'timeout' }) : t('testTimeout', { url }, c.env));
|
|
192
193
|
return 0;
|
|
193
194
|
}
|
|
@@ -202,7 +203,7 @@ async function runAck(c, code) {
|
|
|
202
203
|
const testId = c.flags.test || (known ? known.test_id : null);
|
|
203
204
|
if (!nonce || !testId) { c.err(t('ackNone', {}, c.env)); return 2; }
|
|
204
205
|
// How I was woken: started by the always-on listener (its environment says so), else what I say, else not told.
|
|
205
|
-
let how = c.flags.how && ['exec', 'own', 'cron'].includes(c.flags.how) ? c.flags.how : null;
|
|
206
|
+
let how = c.flags.how && ['exec', 'own', 'url', 'cron'].includes(c.flags.how) ? c.flags.how : null;
|
|
206
207
|
if (!how && c.env && c.env.ANYTOWORK_WAKE_REASON === 'wake_test') how = 'exec';
|
|
207
208
|
try {
|
|
208
209
|
const data = await ackWakeTest(c.baseUrl, c.credOpts, testId, how ? { nonce, how } : { nonce }, { fetchImpl: c.fetchImpl });
|
package/src/setup-hints.js
CHANGED
|
@@ -15,6 +15,19 @@ export const SETUP_DOC_URL = {
|
|
|
15
15
|
en: 'https://a2a.linger.chimap.cn/en/docs/guide/agent-setup',
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
const WAKE_BASE = { zh: 'https://a2a.linger.chimap.cn/docs/guide/', en: 'https://a2a.linger.chimap.cn/en/docs/guide/' };
|
|
19
|
+
const WAKE_PAGE = { exec: 'wake-1', listener: 'wake-1', url: 'wake-2', cron: 'wake-3' };
|
|
20
|
+
|
|
21
|
+
/** The wake-up page for what is known about how this Agent is woken (listener -> 1, trigger address -> 2, schedule only -> 3); the choose-a-type page when unknown. */
|
|
22
|
+
export function wakeDocUrl(data, wakeItem, lang) {
|
|
23
|
+
const base = WAKE_BASE[lang] || WAKE_BASE.zh;
|
|
24
|
+
// The platform tells us sched_only / was_listening on the wake item (never a how/type), so those come first.
|
|
25
|
+
if (wakeItem && wakeItem.sched_only) return base + WAKE_PAGE.cron;
|
|
26
|
+
if (wakeItem && wakeItem.was_listening) return base + WAKE_PAGE.listener;
|
|
27
|
+
const how = wakeItem && ((wakeItem.test && wakeItem.test.how) || wakeItem.how || wakeItem.type);
|
|
28
|
+
return base + (WAKE_PAGE[how] || 'wake');
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
const ITEM_LABEL = {
|
|
19
32
|
wake: { zh: '能被叫醒', en: 'be wakeable' },
|
|
20
33
|
model: { zh: '说明你用的模型', en: 'say which models you use' },
|