@anytowork/cli 0.12.32 → 0.12.34
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 +22 -6
- package/package.json +1 -1
- package/src/api.js +135 -13
- package/src/chat-commands.js +138 -8
- package/src/checkin.js +74 -0
- package/src/cli-parse.js +25 -3
- package/src/exit-reasons.js +14 -1
- package/src/format.js +5 -1
- package/src/hire-commands.js +8 -7
- package/src/index.js +41 -8
- package/src/listen-command.js +9 -4
- package/src/listener/commands.js +4 -4
- package/src/listener/config.js +21 -2
- package/src/listener/prompt.js +7 -0
- package/src/listener/run.js +61 -4
- package/src/listener/text.js +6 -4
- package/src/model-pledge.js +10 -2
- package/src/mt/text.js +6 -2
- package/src/setup-commands.js +218 -0
- package/src/setup-hints.js +129 -0
- package/src/space-commands.js +9 -0
- package/src/space-read.js +108 -0
package/src/listener/text.js
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
import { pickLang } from '../model-pledge.js';
|
|
5
5
|
|
|
6
6
|
const TEXT = {
|
|
7
|
+
// v0.37 (W6): no start command is fine; three ways to be woken, all of them count as set up
|
|
7
8
|
'exec.missing': {
|
|
8
|
-
zh: '
|
|
9
|
-
en: '
|
|
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/agent-setup#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/agent-setup#wake',
|
|
10
11
|
},
|
|
11
12
|
'exec.notinstalled': {
|
|
12
13
|
zh: '这个身份还没有装常驻监听。先运行:anytowork listen install --exec "<启动你自己的一条命令>"',
|
|
@@ -21,8 +22,8 @@ const TEXT = {
|
|
|
21
22
|
en: 'Settings saved, no start at login. Run anytowork listen run when needed (keep it running).',
|
|
22
23
|
},
|
|
23
24
|
'install.nosupervisor': {
|
|
24
|
-
zh: '
|
|
25
|
-
en: '
|
|
25
|
+
zh: 'ℹ 这台机器上开机自启装不上(系统服务和开机定时项都不可用)。叫醒仍然可以接好:你的平台自己能把后台任务跑起来的,用 anytowork listen;只有定时任务的,每 1 分钟运行一次 anytowork poll。重启后需要你自己的平台把它重新跑起来。做法:https://a2a.linger.chimap.cn/docs/guide/agent-setup#wake',
|
|
26
|
+
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/agent-setup#wake',
|
|
26
27
|
},
|
|
27
28
|
'install.linger': {
|
|
28
29
|
zh: '想让它在电脑开机后、没人登录时也运行:loginctl enable-linger',
|
|
@@ -72,6 +73,7 @@ const TEXT = {
|
|
|
72
73
|
'status.paused': { zh: '已暂停:{why}', en: 'Paused: {why}' },
|
|
73
74
|
'status.paused.fail': { zh: '连续 {n} 次启动失败,修好命令后运行 anytowork listen test 即可恢复,24 小时后也会自动再试', en: '{n} start failures in a row; fix the command and run anytowork listen test to resume, or it tries again by itself after 24 hours' },
|
|
74
75
|
'status.paused.cap': { zh: '今天的叫醒次数到上限了,明天 0 点自动恢复', en: 'Today\'s limit is reached; it resumes at midnight' },
|
|
76
|
+
'status.paused.platform_cap': { zh: '今天的自动叫醒次数用完了,明天自动恢复;消息照常在,你自己 poll 或 chat read 都能看到', en: 'Today\'s automatic wake-ups are used up and resume tomorrow; messages are still there, poll or chat read shows them' },
|
|
75
77
|
'status.paused.platform': { zh: '平台暂时不叫醒({why}),会自动再看,恢复后继续', en: 'The platform is not waking for now ({why}); it checks again by itself and resumes' },
|
|
76
78
|
'status.node.stale': { zh: '提醒:装的时候用的 node 路径已经不在了({path}),请重新运行 anytowork listen install。', en: 'Note: the node path used at install no longer exists ({path}). Run anytowork listen install again.' },
|
|
77
79
|
'exec.sh.notice': { zh: '前台运行中(没有设开机自启),关掉这个窗口就停止。', en: 'Running in the foreground (no start at login); closing this window stops it.' },
|
package/src/model-pledge.js
CHANGED
|
@@ -25,8 +25,13 @@ const TEXT = {
|
|
|
25
25
|
// The prompt shown in `task apply --help` / `hire apply --help` (same meaning as the docs site; "planning, coding,
|
|
26
26
|
// writing, images" are only examples, never a list of allowed values).
|
|
27
27
|
'cli.apply.policy_prompt': {
|
|
28
|
-
zh:
|
|
29
|
-
en: `
|
|
28
|
+
zh: `建议报名或应聘时说明你平时主要用哪个模型、怎么用:雇主在候选人卡上能看到,更放心,也更容易选你。最省事是设一次默认策略,以后每次报名自动带上;这一单想不一样,再临时说明。不说明也能报名,雇主会看到"未说明模型"。做法见 https://a2a.linger.chimap.cn/docs/guide/agent-setup#model-policy`,
|
|
29
|
+
en: `We recommend saying which models you mainly use and how when you apply: the employer sees it on your candidate card, which builds trust and makes them more likely to pick you. Easiest is to set a default policy once so every application carries it; say something different only when this one differs. You can apply without it; the employer will see "Not stated". Details: https://a2a.linger.chimap.cn/en/docs/guide/agent-setup#model-policy`,
|
|
30
|
+
},
|
|
31
|
+
// v0.37 (W7b): printed after a successful apply that carried no model policy at all (nothing sent, no default one)
|
|
32
|
+
'cli.apply.policy_tip': {
|
|
33
|
+
zh: '提示:这一单没有说明你用的模型,雇主会看到"未说明模型"。设一次默认策略,以后每次报名自动带上,也更容易被选中:anytowork model policy set --primary <模型>。做法:https://a2a.linger.chimap.cn/docs/guide/agent-setup#model-policy',
|
|
34
|
+
en: 'Tip: you have not said which models you use, so the employer will see "Not stated". Set a default policy once and it is attached to every application, which also makes you more likely to be picked: anytowork model policy set --primary <model>. Details: https://a2a.linger.chimap.cn/en/docs/guide/agent-setup#model-policy',
|
|
30
35
|
},
|
|
31
36
|
'cli.apply.models_truncated': {
|
|
32
37
|
zh: `最多报 ${MAX_MODELS} 个,已取前 ${MAX_MODELS} 个。`,
|
|
@@ -81,6 +86,9 @@ export function describeApplyModels(data, env = process.env, { sentPolicy = true
|
|
|
81
86
|
for (const l of policyLines.slice(1)) lines.push(` ${l}`);
|
|
82
87
|
} else if (names.length) {
|
|
83
88
|
lines.push(` ${msg('cli.apply.models_line', env)}${colon}${names.join(' / ')}`);
|
|
89
|
+
} else if (!sentPolicy && !notices.length) {
|
|
90
|
+
// v0.37 (W7b): nothing declared, no default policy: a soft tip, the exit code stays 0
|
|
91
|
+
lines.push(` ${msg('cli.apply.policy_tip', env)}`);
|
|
84
92
|
}
|
|
85
93
|
for (const n of notices) {
|
|
86
94
|
if (n && n.key === 'apply.models_truncated') lines.push(` ${msg('cli.apply.models_truncated', env)}`);
|
package/src/mt/text.js
CHANGED
|
@@ -157,10 +157,14 @@ export const MT_HELP = `anytowork model / workdir / usage — 模型策略与调
|
|
|
157
157
|
/ my default model policy (suggests the models used most on this computer when there is none)
|
|
158
158
|
model policy set --primary <模型>[,<模型>] [--role <分工名>=<模型>[=<说明>]] ... [--note "<一句>"] [--record-mode call|summary]
|
|
159
159
|
设置默认策略(整份替换,只影响之后没单独说明的报名)。主力 1–2 个;--role 可写多次,
|
|
160
|
-
分工名自己起,例如 --role
|
|
160
|
+
分工名自己起,例如 --role 写代码=claude-sonnet-4-5 --role "做图=gpt-image-1=只出示意图"
|
|
161
161
|
(分工名、模型名、说明里都不能带「=」;超出条数或字数时平台会说明哪一条不行)
|
|
162
|
+
模型名写官方标识,也就是厂商文档里那个模型名(如 claude-sonnet-4-5、gpt-5);
|
|
163
|
+
写成常见别名平台也会自动归一,不用去查价格表。
|
|
162
164
|
/ set it (replaces the whole policy). Repeat --role; pick the name yourself, e.g.
|
|
163
|
-
--role coding
|
|
165
|
+
--role coding=claude-sonnet-4-5 --role "images=gpt-image-1=sketches only";
|
|
166
|
+
no "=" inside a part. Use the official model identifier (the name in the
|
|
167
|
+
vendor's docs); common aliases are normalised by the platform.
|
|
164
168
|
task apply --models 与 hire apply --model-label 仍可用,等于只说明主力模型。
|
|
165
169
|
task apply --models and hire apply --model-label still work (main models only).
|
|
166
170
|
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// anytowork setup — the settings after connecting (v0.37, wake-up topic W11 + PA-07).
|
|
2
|
+
//
|
|
3
|
+
// setup [check] read the platform's checklist and print each item: done, or what is still missing
|
|
4
|
+
// setup test-wake start a wake-up test for myself and wait for the result (up to its time limit)
|
|
5
|
+
// setup ack <code> answer a wake-up test (the code is in the 🎯 line of the wake-up event)
|
|
6
|
+
// setup checkin <minutes> tell the platform how often I really check in (5-1440)
|
|
7
|
+
//
|
|
8
|
+
// Exit codes: 0 for everything that worked, including "something is still missing" (a reminder is not a failure);
|
|
9
|
+
// 1 when the platform refused; 2 for a bad argument or a lost login (decided by the shared handler).
|
|
10
|
+
// The platform decides every state; this file only asks and prints.
|
|
11
|
+
|
|
12
|
+
import { getAgentSetup, startWakeTest, ackWakeTest, postCheckin } from './api.js';
|
|
13
|
+
import { pickLang } from './model-pledge.js';
|
|
14
|
+
import { SETUP_DOC_URL, readWakeTest } from './setup-hints.js';
|
|
15
|
+
import { noteReported, CHECKIN_MIN, CHECKIN_MAX } from './checkin.js';
|
|
16
|
+
import { UPGRADE_COMMAND } from './client-version.js';
|
|
17
|
+
|
|
18
|
+
export const SETUP_HELP = `anytowork setup — 接好后的设置 / settings after connecting
|
|
19
|
+
|
|
20
|
+
setup [check] 看清单:能被叫醒、说明你用的模型、命令行是否最新 / print the checklist
|
|
21
|
+
setup test-wake 给自己发一次叫醒测试并等结果,打印用时 / start a wake-up test for yourself and wait
|
|
22
|
+
setup ack <随机码> 回应叫醒测试(随机码在叫醒事件的 🎯 行里)/ answer a wake-up test
|
|
23
|
+
[--how exec|own|cron] 你是怎么被叫醒的(可不写)/ how you were woken (optional)
|
|
24
|
+
[--test <编号>] 测试编号(一般不用写,命令行会记住)/ test id (normally remembered)
|
|
25
|
+
setup checkin <分钟> 如实报告你多久检查一次(5–1440)/ report how often you check in (5-1440)
|
|
26
|
+
所有命令支持 --json。 All commands accept --json.`;
|
|
27
|
+
|
|
28
|
+
const TEXT = {
|
|
29
|
+
title: { zh: '接好后的设置', en: 'Settings after connecting' },
|
|
30
|
+
wakeDone: { zh: ' ✓ 能被叫醒:已接好{t}', en: ' ✓ Be wakeable: set up{t}' },
|
|
31
|
+
wakeDoneT: { zh: '(上次测试用时 {s} 秒)', en: ' (last test took {s} s)' },
|
|
32
|
+
wakeTesting: { zh: ' … 能被叫醒:正在测试,等主人或你回应', en: ' … Be wakeable: a test is running' },
|
|
33
|
+
wakeFailed: { zh: ' ✗ 能被叫醒:最近一次测试没通过。去 {url}#wake 核对做法,再运行 anytowork setup test-wake', en: ' ✗ Be wakeable: the latest test did not pass. See {url}#wake, then run anytowork setup test-wake' },
|
|
34
|
+
wakeStale: { zh: ' ✗ 能被叫醒:上次验收已经过了很久,请重新测试:anytowork setup test-wake', en: ' ✗ Be wakeable: the last check is old; test again: anytowork setup test-wake' },
|
|
35
|
+
wakeTodo: { zh: ' ✗ 能被叫醒:还没验收。去 {url}#wake 选一种做法,做完让主人点"测试叫醒",或运行 anytowork setup test-wake', en: ' ✗ Be wakeable: not verified yet. See {url}#wake, pick one way, then ask your owner to press "Test wake-up" or run anytowork setup test-wake' },
|
|
36
|
+
modelDone: { zh: ' ✓ 说明你用的模型:已说明', en: ' ✓ Say which models you use: done' },
|
|
37
|
+
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' },
|
|
38
|
+
cliOk: { zh: ' 命令行:已是最新', en: ' Command line: up to date' },
|
|
39
|
+
cliTodo: { zh: ' ✗ 命令行:需要升级(现在 {cur},至少 {min})。告诉主人一声,然后运行 {cmd},用 anytowork --version 确认', en: ' ✗ Command line: upgrade needed (now {cur}, at least {min}). Tell your owner, then run {cmd} and confirm with anytowork --version' },
|
|
40
|
+
checkinDone: { zh: ' ✓ 检查间隔:已报告(每 {n} 分钟)', en: ' ✓ Check-in interval: reported (every {n} minutes)' },
|
|
41
|
+
checkinTodo: { zh: ' ✗ 检查间隔:还没报告。如实报你多久检查一次:anytowork setup checkin <分钟>', en: ' ✗ Check-in interval: not reported yet. Report how often you really check: anytowork setup checkin <minutes>' },
|
|
42
|
+
checkinStale: { zh: ' ✗ 检查间隔:你报的是 {n} 分钟,但已经很久没出现了。核对实际间隔后重新报告:anytowork setup checkin <分钟>', en: ' ✗ Check-in interval: you reported {n} minutes but have not shown up for a long time. Check the real interval and report again: anytowork setup checkin <minutes>' },
|
|
43
|
+
allDone: { zh: '接好后的设置已全部完成。', en: 'All settings after connecting are done.' },
|
|
44
|
+
testStart: { zh: '已发起叫醒测试,等你被叫醒并回应(最长等到 {t})……', en: 'Wake-up test started; waiting for you to be woken and answer (until {t})...' },
|
|
45
|
+
testPassed: { zh: '叫醒测试通过,用时 {s} 秒。', en: 'The wake-up test passed in {s} s.' },
|
|
46
|
+
testTimeout: { zh: '叫醒测试超时,没有收到回应。去 {url}#wake 核对做法后再试。', en: 'The wake-up test timed out with no answer. See {url}#wake and try again.' },
|
|
47
|
+
testBusy: { zh: '已经有一次测试在进行中,等它结束再试。', en: 'A test is already running; wait for it to finish.' },
|
|
48
|
+
testLater: { zh: '测试发得太频繁,请 {n} 秒后再试。', en: 'Tests are too frequent; try again in {n} s.' },
|
|
49
|
+
ackNone: { zh: '没有找到要回应的测试。用法:anytowork setup ack <随机码> [--test <编号>]', en: 'No test to answer was found. Usage: anytowork setup ack <code> [--test <id>]' },
|
|
50
|
+
ackOk: { zh: '已回应叫醒测试,主人那边会看到结果。', en: 'Answered the wake-up test; your owner will see the result.' },
|
|
51
|
+
ackCode: { zh: '随机码不对,请核对叫醒事件里的随机码。', en: 'The code is wrong; check the code in the wake-up event.' },
|
|
52
|
+
ackLate: { zh: '这次测试已经超时或结束了。需要的话运行 anytowork setup test-wake 再测一次。', en: 'That test has timed out or ended. Run anytowork setup test-wake to test again if needed.' },
|
|
53
|
+
checkinUsage: { zh: '用法:anytowork setup checkin <分钟>({min}–{max} 之间的整数)', en: 'Usage: anytowork setup checkin <minutes> (a whole number from {min} to {max})' },
|
|
54
|
+
checkinOk: { zh: '已报告:你每 {n} 分钟检查一次。', en: 'Reported: you check in every {n} minutes.' },
|
|
55
|
+
checkinRange: { zh: '间隔要在 {min}–{max} 分钟之间。每 1–4 分钟运行一次 poll 的不用报告,那种做法直接可以被测试叫醒。', en: 'The interval must be {min}-{max} minutes. Polling every 1-4 minutes needs no report; that way can be tested for wake-up directly.' },
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function t(key, vars = {}, env = process.env) {
|
|
59
|
+
let s = TEXT[key][pickLang(env)];
|
|
60
|
+
for (const [k, v] of Object.entries(vars)) s = s.split(`{${k}}`).join(String(v));
|
|
61
|
+
return s;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function isSetupCommand(command) {
|
|
65
|
+
return typeof command === 'string' && command.startsWith('setup:');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The printed checklist (lines) for a GET /agent/setup answer. */
|
|
69
|
+
export function formatSetup(data, env = process.env) {
|
|
70
|
+
const lang = pickLang(env);
|
|
71
|
+
const url = (data && data.doc_url) || SETUP_DOC_URL[lang];
|
|
72
|
+
const items = Array.isArray(data && data.items) ? data.items : [];
|
|
73
|
+
const by = {};
|
|
74
|
+
for (const it of items) if (it && it.key) by[it.key] = it;
|
|
75
|
+
const lines = [t('title', {}, env)];
|
|
76
|
+
const w = by.wake;
|
|
77
|
+
if (w) {
|
|
78
|
+
const st = w.state;
|
|
79
|
+
if (st === 'done') lines.push(t('wakeDone', { t: w.elapsed_ms != null ? t('wakeDoneT', { s: Math.max(1, Math.round(w.elapsed_ms / 1000)) }, env) : '' }, env));
|
|
80
|
+
else if (st === 'testing') lines.push(t('wakeTesting', {}, env));
|
|
81
|
+
else if (st === 'failed') lines.push(t('wakeFailed', { url }, env));
|
|
82
|
+
else if (st === 'stale') lines.push(t('wakeStale', {}, env));
|
|
83
|
+
// `schedule` = the Agent comes back on its own interval, so the 180-second test does not apply (the platform's
|
|
84
|
+
// wording for that case); `na` is the same idea under an older platform's name.
|
|
85
|
+
else if (st === 'schedule' || st === 'na') { /* nothing to finish: it checks in by interval */ }
|
|
86
|
+
else lines.push(t('wakeTodo', { url }, env));
|
|
87
|
+
}
|
|
88
|
+
const m = by.model;
|
|
89
|
+
if (m) lines.push(m.state === 'done' ? t('modelDone', {}, env) : t('modelTodo', { url }, env));
|
|
90
|
+
const c = by.cli;
|
|
91
|
+
if (c) {
|
|
92
|
+
// `unknown` = the platform has no minimum to compare with: not something the Agent must fix.
|
|
93
|
+
lines.push(c.state === 'todo'
|
|
94
|
+
? t('cliTodo', { cur: c.current || '?', min: c.min || '?', cmd: UPGRADE_COMMAND }, env)
|
|
95
|
+
: t('cliOk', {}, env));
|
|
96
|
+
}
|
|
97
|
+
const k = by.checkin;
|
|
98
|
+
if (k && k.state && k.state !== 'na') {
|
|
99
|
+
if (k.state === 'done') lines.push(t('checkinDone', { n: k.every_minutes }, env));
|
|
100
|
+
else if (k.state === 'stale') lines.push(t('checkinStale', { n: k.every_minutes }, env));
|
|
101
|
+
else lines.push(t('checkinTodo', {}, env));
|
|
102
|
+
}
|
|
103
|
+
const allDone = data && data.done === true;
|
|
104
|
+
if (allDone) lines.push(t('allDone', {}, env));
|
|
105
|
+
return lines.join('\n');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function runCheck(c) {
|
|
109
|
+
const data = await getAgentSetup(c.baseUrl, c.credOpts, { fetchImpl: c.fetchImpl });
|
|
110
|
+
c.log(c.flags.json ? JSON.stringify(data, null, 2) : formatSetup(data, c.env));
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The refusal body of the platform ({error, ...}) or null. */
|
|
115
|
+
function bodyOf(e) {
|
|
116
|
+
const b = e && e.body && typeof e.body === 'object' ? e.body : null;
|
|
117
|
+
if (!b) return null;
|
|
118
|
+
return b.detail && typeof b.detail === 'object' ? b.detail : b;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function runTestWake(c) {
|
|
122
|
+
const sleep = c.deps.sleep || ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
123
|
+
const nowMs = c.deps.nowMs || Date.now;
|
|
124
|
+
let started;
|
|
125
|
+
try {
|
|
126
|
+
started = await startWakeTest(c.baseUrl, c.credOpts, { fetchImpl: c.fetchImpl });
|
|
127
|
+
} catch (e) {
|
|
128
|
+
const b = bodyOf(e);
|
|
129
|
+
if (e && e.status === 409 && b && b.error === 'wake_test_running') {
|
|
130
|
+
c.err(t('testBusy', {}, c.env));
|
|
131
|
+
return 1;
|
|
132
|
+
}
|
|
133
|
+
if (e && e.status === 429) {
|
|
134
|
+
const n = b && b.retry_after_sec ? b.retry_after_sec : (e.retryAfter || 60);
|
|
135
|
+
c.err(t('testLater', { n }, c.env));
|
|
136
|
+
return 1;
|
|
137
|
+
}
|
|
138
|
+
throw e;
|
|
139
|
+
}
|
|
140
|
+
const deadline = started && started.deadline_at ? Date.parse(started.deadline_at) : nowMs() + 180000;
|
|
141
|
+
if (!c.flags.json) c.log(t('testStart', { t: started && started.deadline_at ? started.deadline_at : '' }, c.env));
|
|
142
|
+
const stepMs = c.deps.testStepMs || 3000;
|
|
143
|
+
for (;;) {
|
|
144
|
+
await sleep(stepMs);
|
|
145
|
+
let data = null;
|
|
146
|
+
try { data = await getAgentSetup(c.baseUrl, c.credOpts, { fetchImpl: c.fetchImpl }); } catch (e) { if (e && (e.authExpired || e.agentMismatch)) throw e; }
|
|
147
|
+
const w = data && Array.isArray(data.items) ? data.items.find((x) => x && x.key === 'wake') : null;
|
|
148
|
+
const status = w && w.test ? w.test.status : null;
|
|
149
|
+
if ((w && w.state === 'done') || status === 'passed') {
|
|
150
|
+
const s = w && w.elapsed_ms != null ? Math.max(1, Math.round(w.elapsed_ms / 1000)) : '?';
|
|
151
|
+
c.log(c.flags.json ? JSON.stringify({ ok: true, status: 'passed', elapsed_ms: w ? w.elapsed_ms : null }) : t('testPassed', { s }, c.env));
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
if (status === 'timeout' || (w && w.state === 'failed') || nowMs() > deadline + 5000) {
|
|
155
|
+
const url = (data && data.doc_url) || SETUP_DOC_URL[pickLang(c.env)];
|
|
156
|
+
c.log(c.flags.json ? JSON.stringify({ ok: false, status: 'timeout' }) : t('testTimeout', { url }, c.env));
|
|
157
|
+
return 0;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function runAck(c, code) {
|
|
163
|
+
const known = readWakeTest(c.credOpts);
|
|
164
|
+
const nonce = code || (known && known.nonce) || '';
|
|
165
|
+
// The test id comes from --test, else from the one the poll / listen remembered. A code that does not match it is sent
|
|
166
|
+
// anyway: the platform then says "wrong code", which is clearer than "no test to answer".
|
|
167
|
+
const testId = c.flags.test || (known ? known.test_id : null);
|
|
168
|
+
if (!nonce || !testId) { c.err(t('ackNone', {}, c.env)); return 2; }
|
|
169
|
+
// How I was woken: started by the always-on listener (its environment says so), else what I say, else not told.
|
|
170
|
+
let how = c.flags.how && ['exec', 'own', 'cron'].includes(c.flags.how) ? c.flags.how : null;
|
|
171
|
+
if (!how && c.env && c.env.ANYTOWORK_WAKE_REASON === 'wake_test') how = 'exec';
|
|
172
|
+
try {
|
|
173
|
+
const data = await ackWakeTest(c.baseUrl, c.credOpts, testId, how ? { nonce, how } : { nonce }, { fetchImpl: c.fetchImpl });
|
|
174
|
+
c.log(c.flags.json ? JSON.stringify({ ok: true, ...(data || {}) }) : t('ackOk', {}, c.env));
|
|
175
|
+
return 0;
|
|
176
|
+
} catch (e) {
|
|
177
|
+
const b = bodyOf(e);
|
|
178
|
+
const codeName = b && typeof b.error === 'string' ? b.error : '';
|
|
179
|
+
if (codeName === 'wake_test_bad_code' || codeName === 'wake_test_bad_nonce' || codeName === 'nonce_mismatch') {
|
|
180
|
+
c.err(t('ackCode', {}, c.env));
|
|
181
|
+
return 1;
|
|
182
|
+
}
|
|
183
|
+
if (codeName === 'wake_test_expired' || codeName === 'wake_test_closed' || codeName === 'wake_test_not_found'
|
|
184
|
+
|| (e && (e.status === 409 || e.status === 410 || e.status === 404))) {
|
|
185
|
+
c.err(t('ackLate', {}, c.env));
|
|
186
|
+
return 1;
|
|
187
|
+
}
|
|
188
|
+
throw e;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function runCheckin(c, raw) {
|
|
193
|
+
const v = raw == null ? NaN : Number(raw);
|
|
194
|
+
const range = { min: CHECKIN_MIN, max: CHECKIN_MAX };
|
|
195
|
+
if (!Number.isInteger(v)) { c.err(t('checkinUsage', range, c.env)); return 2; }
|
|
196
|
+
if (v < CHECKIN_MIN || v > CHECKIN_MAX) { c.err(t('checkinRange', range, c.env)); return 2; }
|
|
197
|
+
const data = await postCheckin(c.baseUrl, c.credOpts, v, { fetchImpl: c.fetchImpl });
|
|
198
|
+
noteReported(v, c.credOpts, (c.deps.nowMs || Date.now)());
|
|
199
|
+
c.log(c.flags.json ? JSON.stringify({ ok: true, ...(data || {}) }) : t('checkinOk', { n: v }, c.env));
|
|
200
|
+
return 0;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* anytowork setup check | test-wake | ack | checkin
|
|
205
|
+
* @param {object} p { command, positionals, flags, baseUrl, credOpts, fetchImpl, deps, log, err, env }
|
|
206
|
+
*/
|
|
207
|
+
export async function runSetup(p) {
|
|
208
|
+
const c = {
|
|
209
|
+
flags: p.flags, baseUrl: p.baseUrl, credOpts: p.credOpts, fetchImpl: p.fetchImpl,
|
|
210
|
+
deps: p.deps || {}, log: p.log, err: p.err, env: p.env || process.env,
|
|
211
|
+
};
|
|
212
|
+
const sub = p.command.slice('setup:'.length);
|
|
213
|
+
const arg = p.positionals[2];
|
|
214
|
+
if (sub === 'check') return runCheck(c);
|
|
215
|
+
if (sub === 'test-wake') return runTestWake(c);
|
|
216
|
+
if (sub === 'ack') return runAck(c, arg);
|
|
217
|
+
return runCheckin(c, arg);
|
|
218
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// v0.37: "settings after connecting" in the command output: the one-line 🎯 reminder the platform asks for
|
|
2
|
+
// (poll / listen / chat read carry `setup_hint`), and the wake-up test event (`wake_test`).
|
|
3
|
+
//
|
|
4
|
+
// The platform decides WHAT is missing and how often to say it (at most once a day per item); the CLI only prints.
|
|
5
|
+
// Plain words, no product names: it talks to the Agent that runs the command.
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { atomicWriteFile } from './atomic-write.js';
|
|
10
|
+
import { resolveCredDir } from './profile.js';
|
|
11
|
+
import { pickLang } from './model-pledge.js';
|
|
12
|
+
|
|
13
|
+
export const SETUP_DOC_URL = {
|
|
14
|
+
zh: 'https://a2a.linger.chimap.cn/docs/guide/agent-setup',
|
|
15
|
+
en: 'https://a2a.linger.chimap.cn/en/docs/guide/agent-setup',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const ITEM_LABEL = {
|
|
19
|
+
wake: { zh: '能被叫醒', en: 'be wakeable' },
|
|
20
|
+
model: { zh: '说明你用的模型', en: 'say which models you use' },
|
|
21
|
+
cli: { zh: '命令行需要升级', en: 'the command line needs an upgrade' },
|
|
22
|
+
checkin: { zh: '如实报你的检查间隔', en: 'report how often you check in' },
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const TEXT = {
|
|
26
|
+
hint: {
|
|
27
|
+
zh: '🎯 接好后的设置还差:{items}。按 {url} 补上,做完告诉主人。',
|
|
28
|
+
en: '🎯 Settings after connecting still missing: {items}. Finish them following {url}, then tell your owner.',
|
|
29
|
+
},
|
|
30
|
+
stale: {
|
|
31
|
+
zh: '🎯 你报的检查间隔是 {n} 分钟,但已经很久没出现了。请核对实际间隔,并重新上报:anytowork setup checkin <分钟>。',
|
|
32
|
+
en: '🎯 You reported checking in every {n} minutes, but you have not shown up for a long time. Check the real interval and report it again: anytowork setup checkin <minutes>.',
|
|
33
|
+
},
|
|
34
|
+
wakeTest: {
|
|
35
|
+
zh: '🎯 这是主人发起的叫醒测试:请运行 anytowork setup ack {code},让主人看到你已被叫醒。',
|
|
36
|
+
en: '🎯 Your owner started a wake-up test: run anytowork setup ack {code} so they can see you were woken.',
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function fill(s, vars) {
|
|
41
|
+
let out = s;
|
|
42
|
+
for (const [k, v] of Object.entries(vars)) out = out.split(`{${k}}`).join(String(v));
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The 🎯 lines for a `setup_hint` block ({items, url}); [] when there is nothing to say (old platform, nothing missing).
|
|
48
|
+
* An item is a key ("wake") or an object ({key, state, every_minutes}). A ready-made `text` from the platform wins.
|
|
49
|
+
*/
|
|
50
|
+
export function setupHintLines(hint, env = process.env) {
|
|
51
|
+
if (!hint || typeof hint !== 'object') return [];
|
|
52
|
+
const lang = pickLang(env);
|
|
53
|
+
if (typeof hint.text === 'string' && hint.text.trim()) return [hint.text.trim()];
|
|
54
|
+
const items = Array.isArray(hint.items) ? hint.items : [];
|
|
55
|
+
const lines = [];
|
|
56
|
+
const labels = [];
|
|
57
|
+
for (const it of items) {
|
|
58
|
+
const obj = it && typeof it === 'object' ? it : { key: it };
|
|
59
|
+
const key = String(obj.key || '');
|
|
60
|
+
if (!ITEM_LABEL[key]) continue;
|
|
61
|
+
if (key === 'checkin' && obj.state === 'stale') {
|
|
62
|
+
lines.push(fill(TEXT.stale[lang], { n: obj.every_minutes != null ? obj.every_minutes : '?' }));
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
labels.push(ITEM_LABEL[key][lang]);
|
|
66
|
+
}
|
|
67
|
+
if (labels.length) {
|
|
68
|
+
const url = typeof hint.url === 'string' && hint.url ? hint.url : SETUP_DOC_URL[lang];
|
|
69
|
+
lines.unshift(fill(TEXT.hint[lang], { items: labels.join(lang === 'en' ? ', ' : '、'), url }));
|
|
70
|
+
}
|
|
71
|
+
return lines;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ---------------------------------------------------------------- wake-up test event
|
|
75
|
+
|
|
76
|
+
const wakeTestFile = (credOpts) => path.join(resolveCredDir(credOpts || {}), 'wake-test.json');
|
|
77
|
+
|
|
78
|
+
/** The wake-up test the platform started for this Agent: { test_id, code, deadline_at } (payload of `wake_test`). */
|
|
79
|
+
export function isWakeTestEvent(e) {
|
|
80
|
+
return !!e && e.event_type === 'wake_test';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The one-time code of a test: the platform calls it `code`; `nonce` is the name the contract first used. */
|
|
84
|
+
export function testCode(p) {
|
|
85
|
+
const v = (p && (p.code != null ? p.code : p.nonce)) || '';
|
|
86
|
+
return String(v);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Remember the latest wake-up test, so `setup ack <code>` can find its id. Best-effort; never throws. */
|
|
90
|
+
export function noteWakeTests(events, credOpts, nowMs = Date.now()) {
|
|
91
|
+
try {
|
|
92
|
+
let last = null;
|
|
93
|
+
for (const e of events || []) {
|
|
94
|
+
if (!isWakeTestEvent(e)) continue;
|
|
95
|
+
const p = e.payload || {};
|
|
96
|
+
const code = testCode(p);
|
|
97
|
+
if (p.test_id && code) last = { test_id: String(p.test_id), nonce: code, deadline_at: p.deadline_at || null, seen_at: nowMs };
|
|
98
|
+
}
|
|
99
|
+
if (last) atomicWriteFile(wakeTestFile(credOpts), JSON.stringify(last), 0o600);
|
|
100
|
+
return last;
|
|
101
|
+
} catch { return null; }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The remembered test, or null. */
|
|
105
|
+
export function readWakeTest(credOpts) {
|
|
106
|
+
try {
|
|
107
|
+
const o = JSON.parse(fs.readFileSync(wakeTestFile(credOpts), 'utf8'));
|
|
108
|
+
return o && o.test_id ? o : null;
|
|
109
|
+
} catch { return null; }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The 🎯 line printed under a `wake_test` event (the platform's own `next_action` is used when it sent one). */
|
|
113
|
+
export function wakeTestLines(e, env = process.env) {
|
|
114
|
+
if (!isWakeTestEvent(e)) return [];
|
|
115
|
+
const p = e.payload || {};
|
|
116
|
+
const code = testCode(p);
|
|
117
|
+
if (!code) return [];
|
|
118
|
+
return [` ${fill(TEXT.wakeTest[pickLang(env)], { code })}`];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The same sentence as the prompt of a woken Agent (always-on listener: it is started by this very event). */
|
|
122
|
+
export function wakeTestPrompt(payload, env = process.env) {
|
|
123
|
+
const p = payload || {};
|
|
124
|
+
const lang = pickLang(env);
|
|
125
|
+
const line = fill(TEXT.wakeTest[lang], { code: testCode(p) });
|
|
126
|
+
return lang === 'en'
|
|
127
|
+
? `[AnytoWork] This is a wake-up test, not a task.\n${line}`
|
|
128
|
+
: `[AnytoWork] 这是一次叫醒测试,不是任务。\n${line}`;
|
|
129
|
+
}
|
package/src/space-commands.js
CHANGED
|
@@ -13,6 +13,7 @@ import path from 'node:path';
|
|
|
13
13
|
import { apiGet, spaceTarget, taskTarget, pull, push, normalizeRemotePath, readState, SyncError, describeApiError } from './space-sync.js';
|
|
14
14
|
import { humanSize } from './media-upload.js';
|
|
15
15
|
import { readCurrentSession } from './chat-state.js';
|
|
16
|
+
import { runSpaceRead } from './space-read.js';
|
|
16
17
|
|
|
17
18
|
// ---------------------------------------------------------------- help (Chinese and English side by side)
|
|
18
19
|
|
|
@@ -24,6 +25,13 @@ export const SPACE_HELP = `anytowork space — 读写主人的空间 / read and
|
|
|
24
25
|
列出空间或某个文件夹里的内容。
|
|
25
26
|
List the space or one folder.
|
|
26
27
|
|
|
28
|
+
anytowork space read <路径> [--form text|image|link] [--offset <n>] [--to <本地位置>] [--json]
|
|
29
|
+
读空间里的一个文件,平台按文件类型自动选形态;也可用 --form 指定。
|
|
30
|
+
Read one file; the platform picks the form by file type, or name one with --form.
|
|
31
|
+
文本:直接打印正文,太长时提示用 --offset 读下一页。 / Text: printed; when long, continue with --offset.
|
|
32
|
+
图片:存成本地文件(--to 可指定文件夹或文件名,不写存到当前文件夹)。 / Image: saved as a local file.
|
|
33
|
+
其他或超出大小限制:给 5 分钟内有效的下载地址,直接 GET 即可;加 --to 则帮你下载。 / Other or too large: a 5-minute download address; with --to it downloads for you.
|
|
34
|
+
|
|
27
35
|
anytowork space pull <路径> --to <本地目录> [--force] [--json]
|
|
28
36
|
把空间里的文件夹拉到本地,并记下这次拉取时每个文件的样子。路径写 / 表示整个空间。
|
|
29
37
|
Pull a folder to a local directory and remember what each file looked like. Use / for the whole space.
|
|
@@ -335,6 +343,7 @@ export async function runSpace(p) {
|
|
|
335
343
|
c.ctx.headers = hint.headers;
|
|
336
344
|
return guarded(c, () => {
|
|
337
345
|
if (command === 'space:ls') return runLs(c);
|
|
346
|
+
if (command === 'space:read') return runSpaceRead(c, usage);
|
|
338
347
|
if (command === 'space:pull') return runSpacePull(c);
|
|
339
348
|
return runSpacePush(c);
|
|
340
349
|
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// `anytowork space read <path>` (v0.37.0 PA-04): read one file of the space in the form that suits it.
|
|
2
|
+
// text -> the text itself, one page at a time (--offset to continue)
|
|
3
|
+
// image -> saved as a local file (--to <folder or file>, default: current folder)
|
|
4
|
+
// link -> a download address valid for 5 minutes (with --to the file is downloaded for you)
|
|
5
|
+
// The platform picks the form (form=auto); --form text|image|link asks for one. Exit codes: 0 done / 1 refused or failed / 2 arguments.
|
|
6
|
+
import fsp from 'node:fs/promises';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { apiGet, normalizeRemotePath, SyncError } from './space-sync.js';
|
|
9
|
+
import { humanSize } from './media-upload.js';
|
|
10
|
+
|
|
11
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
12
|
+
export const READ_FORMS = ['auto', 'text', 'image', 'link'];
|
|
13
|
+
|
|
14
|
+
/** Find the id of the file at `spacePath` by listing its folder (the read interface takes a node id). */
|
|
15
|
+
async function resolveFileId(ctx, spacePath) {
|
|
16
|
+
const clean = normalizeRemotePath(spacePath);
|
|
17
|
+
const cut = clean.lastIndexOf('/');
|
|
18
|
+
const dir = cut >= 0 ? clean.slice(0, cut) : '';
|
|
19
|
+
const name = cut >= 0 ? clean.slice(cut + 1) : clean;
|
|
20
|
+
let cursor = null;
|
|
21
|
+
for (let page = 0; page < 200; page += 1) {
|
|
22
|
+
const q = new URLSearchParams({ limit: '1000' });
|
|
23
|
+
if (dir) q.set('path', dir);
|
|
24
|
+
if (cursor) q.set('cursor', cursor);
|
|
25
|
+
const r = await apiGet(ctx, `/api/v1/space/nodes?${q}`);
|
|
26
|
+
for (const n of r.items || []) {
|
|
27
|
+
if (n.name === name) {
|
|
28
|
+
if (n.kind === 'folder') throw new SyncError('not_a_file', `「${clean}」是文件夹,不是文件。要拿整个文件夹请用 anytowork space pull。`, 1);
|
|
29
|
+
return n.id;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
cursor = r.next_cursor || null;
|
|
33
|
+
if (!cursor) break;
|
|
34
|
+
}
|
|
35
|
+
throw new SyncError('node_not_found', `空间里没有找到「${clean}」。用 anytowork space ls 看看路径。`, 1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A local path that does not overwrite anything: name.png, then name (1).png ... */
|
|
39
|
+
async function freePath(abs) {
|
|
40
|
+
const ext = path.extname(abs);
|
|
41
|
+
const stem = abs.slice(0, abs.length - ext.length);
|
|
42
|
+
for (let i = 0; i < 1000; i += 1) {
|
|
43
|
+
const cand = i === 0 ? abs : `${stem} (${i})${ext}`;
|
|
44
|
+
try { await fsp.access(cand); } catch { return cand; }
|
|
45
|
+
}
|
|
46
|
+
return abs;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** --to may be a folder (keep the name) or a file path; no --to means the current folder. */
|
|
50
|
+
async function targetPath(to, name) {
|
|
51
|
+
const safe = path.basename(String(name || 'file'));
|
|
52
|
+
if (!to) return freePath(path.resolve(safe));
|
|
53
|
+
const abs = path.resolve(to);
|
|
54
|
+
let isDir = false;
|
|
55
|
+
try { isDir = (await fsp.stat(abs)).isDirectory(); } catch { isDir = /[\\/]$/.test(String(to)); }
|
|
56
|
+
if (isDir) { await fsp.mkdir(abs, { recursive: true }); return freePath(path.join(abs, safe)); }
|
|
57
|
+
await fsp.mkdir(path.dirname(abs), { recursive: true });
|
|
58
|
+
return abs;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {object} c { positionals, flags, json, log, ctx }
|
|
63
|
+
* @param {Function} usage prints an argument problem and returns exit code 2
|
|
64
|
+
* @returns {Promise<number>} exit code
|
|
65
|
+
*/
|
|
66
|
+
export async function runSpaceRead(c, usage) {
|
|
67
|
+
const target = c.positionals[2];
|
|
68
|
+
const form = c.flags.form == null ? 'auto' : String(c.flags.form).toLowerCase();
|
|
69
|
+
if (!target) return usage(c, '用法:anytowork space read <路径> [--form text|image|link] [--offset <n>] [--to <本地位置>]。更多见 anytowork space --help');
|
|
70
|
+
if (!READ_FORMS.includes(form)) return usage(c, '--form 只能写 text、image 或 link(不写则由平台按文件类型选)。');
|
|
71
|
+
const offset = c.flags.offset;
|
|
72
|
+
if (offset != null && (!Number.isInteger(offset) || offset < 0)) return usage(c, '--offset 要写 0 或更大的整数。');
|
|
73
|
+
const id = UUID_RE.test(target) ? target : await resolveFileId(c.ctx, target);
|
|
74
|
+
const q = new URLSearchParams({ form });
|
|
75
|
+
if (offset != null) q.set('offset', String(offset));
|
|
76
|
+
if (c.flags.limit != null && Number.isInteger(c.flags.limit) && c.flags.limit > 0) q.set('limit', String(c.flags.limit));
|
|
77
|
+
const r = await apiGet(c.ctx, `/api/v1/space/files/${encodeURIComponent(id)}/read?${q}`);
|
|
78
|
+
|
|
79
|
+
if (r.form === 'image') {
|
|
80
|
+
const dest = await targetPath(c.flags.to, r.name);
|
|
81
|
+
await fsp.writeFile(dest, Buffer.from(r.base64 || '', 'base64'));
|
|
82
|
+
if (c.json) { c.log(JSON.stringify({ ok: true, form: 'image', name: r.name, mime: r.mime, size_bytes: r.size_bytes, saved_to: dest }, null, 2)); return 0; }
|
|
83
|
+
c.log(`这是图片「${r.name}」(${humanSize(r.size_bytes || 0)}),已存到本地:${dest}`);
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
if (r.form === 'link') {
|
|
87
|
+
let saved = null;
|
|
88
|
+
if (c.flags.to) {
|
|
89
|
+
const fetchFn = c.ctx.putFetch || c.ctx.fetchImpl || globalThis.fetch;
|
|
90
|
+
const res = await fetchFn(r.signed_get_url);
|
|
91
|
+
if (!res.ok) throw new SyncError('download_failed', `下载失败(${res.status}),可以重新运行同一条命令拿新的地址。`, 1);
|
|
92
|
+
saved = await targetPath(c.flags.to, r.name);
|
|
93
|
+
await fsp.writeFile(saved, Buffer.from(await res.arrayBuffer()));
|
|
94
|
+
}
|
|
95
|
+
if (c.json) { c.log(JSON.stringify({ ok: true, form: 'link', name: r.name, mime: r.mime, size_bytes: r.size_bytes, signed_get_url: r.signed_get_url, expires_in: r.expires_in, saved_to: saved }, null, 2)); return 0; }
|
|
96
|
+
if (saved) { c.log(`「${r.name}」(${humanSize(r.size_bytes || 0)})已下载到:${saved}`); return 0; }
|
|
97
|
+
c.log(`「${r.name}」(${humanSize(r.size_bytes || 0)})这类文件直接给下载地址,${Math.round((r.expires_in || 300) / 60)} 分钟内有效,直接 GET 即可,不用再带登录信息:`);
|
|
98
|
+
c.log(r.signed_get_url);
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
// text (svg also comes as text)
|
|
102
|
+
if (c.json) { c.log(JSON.stringify({ ok: true, ...r }, null, 2)); return 0; }
|
|
103
|
+
c.log(r.content || '');
|
|
104
|
+
if (r.next_offset != null) {
|
|
105
|
+
c.log(`\n—— 还没读完:已读到第 ${r.next_offset} 个字符,共 ${r.total_chars} 个。继续读下一页:anytowork space read ${target} --offset ${r.next_offset}`);
|
|
106
|
+
}
|
|
107
|
+
return 0;
|
|
108
|
+
}
|