dsh-dot-life 0.23.0 → 0.23.2
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.en.md +3 -2
- package/README.md +5 -4
- package/cordis.patch.yml +3 -2
- package/docs/DESIGN.md +12 -0
- package/docs/SETTINGS.md +21 -3
- package/docs/computer.md +3 -3
- package/docs/phone.md +5 -4
- package/package.json +2 -2
- package/scripts/prompts.mjs +0 -1
- package/src/computer/backends/docker.js +5 -0
- package/src/computer/backends/microsandbox.js +6 -0
- package/src/computer/backends/proxy.js +2 -2
- package/src/computer/docker.js +1 -1
- package/src/computer/key.js +0 -1
- package/src/computer/subprocess.js +2 -1
- package/src/computer/vm.js +64 -12
- package/src/dot/core.js +11 -5
- package/src/interlude/core.js +11 -6
- package/src/llm-gate.js +420 -0
- package/src/memory/memory.js +3 -1
- package/src/memory/recall.js +1 -1
- package/src/memory/store.js +0 -16
- package/src/page/api.js +7 -1
- package/src/page/page.js +27 -3
- package/src/phone/mcp-entry.cjs +31 -0
- package/src/phone/phone.js +39 -9
- package/src/qq/qq.js +4 -1
- package/src/settings-schema.js +8 -2
- package/src/settings.js +0 -2
- package/scripts/check-mac-aio.sh +0 -73
- package/scripts/check-mac.sh +0 -116
- package/scripts/check-windows.ps1 +0 -226
package/src/interlude/core.js
CHANGED
|
@@ -23,6 +23,7 @@ import { homedir } from 'node:os';
|
|
|
23
23
|
import { join, relative, isAbsolute } from 'node:path';
|
|
24
24
|
import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
25
25
|
import { sectionOf, setValues } from '../settings.js';
|
|
26
|
+
import { background, installLlmGate } from '../llm-gate.js';
|
|
26
27
|
import { prompt, table } from '../prompts.js';
|
|
27
28
|
import { describeNow, stamp } from '../clock.js';
|
|
28
29
|
import { createDoings, tokensOf } from './doings.js';
|
|
@@ -117,7 +118,6 @@ export const defaults = {
|
|
|
117
118
|
imTarget: '',
|
|
118
119
|
};
|
|
119
120
|
|
|
120
|
-
const dshHome = () => process.env.DSH_HOME || join(homedir(), '.dsh');
|
|
121
121
|
/** dsh-im tags messages it relays with an rpcId of `<channel>-<uuid>`; the desktop UI does not. */
|
|
122
122
|
export const IM_RPC = /^(weixin|wechat|qq|feishu|lark|dingtalk|wecom|wework|telegram|discord|slack|whatsapp|email|office)-/i;
|
|
123
123
|
export const isImMessage = (m) => IM_RPC.test(String(m?.source?.rpcId ?? ''));
|
|
@@ -801,8 +801,8 @@ export function apply(ctx, config = {}) {
|
|
|
801
801
|
doings: view, trying: tryOpen(),
|
|
802
802
|
upcoming: intents.filter((i) => i.id !== intent?.id).map((i) => ({ at: describeNow(new Date(i.at)), kind: i.kind, text: i.text })),
|
|
803
803
|
});
|
|
804
|
-
const options = { provider: sel.provider, model: sel.model, ...(sel.reasoningEffort ? { reasoningEffort: sel.reasoningEffort } : {}), system, tools, maxTokens: cfg.maxTokens,
|
|
805
|
-
messages: [createUserMessage({ content: [{ type: 'text', text: user }], source: { kind: 'dsh-interlude' } })] };
|
|
804
|
+
const options = background({ provider: sel.provider, model: sel.model, ...(sel.reasoningEffort ? { reasoningEffort: sel.reasoningEffort } : {}), system, tools, maxTokens: cfg.maxTokens,
|
|
805
|
+
messages: [createUserMessage({ content: [{ type: 'text', text: user }], source: { kind: 'dsh-interlude' } })] });
|
|
806
806
|
const r1 = await collectReply(ctx.llm.stream(options));
|
|
807
807
|
const spent = [usageOf(r1.usage)];
|
|
808
808
|
// The `interval` tool call carries the fields; a bare JSON reply is accepted too.
|
|
@@ -814,11 +814,11 @@ export function apply(ctx, config = {}) {
|
|
|
814
814
|
// call over the script just written fills every other field — the post-commit continuity
|
|
815
815
|
// refresh, widened so nothing the round should have produced is lost.
|
|
816
816
|
if (!parsed?.state) {
|
|
817
|
-
const r2 = await collectReply(ctx.llm.stream({
|
|
817
|
+
const r2 = await collectReply(ctx.llm.stream(background({
|
|
818
818
|
...options, maxTokens: 2000,
|
|
819
819
|
system: prompt('interlude.round.refresh'),
|
|
820
820
|
messages: [createUserMessage({ content: [{ type: 'text', text: JSON.stringify({ interval: { nowLocal: describeNow(now) }, previousContinuity: state ?? null, script }, null, 1) }], source: { kind: 'dsh-interlude' } })],
|
|
821
|
-
})).catch((error) => { logger.warn(`continuity refresh failed: ${error.message}`); return { text: '', args: '', usage: null }; });
|
|
821
|
+
}))).catch((error) => { logger.warn(`continuity refresh failed: ${error.message}`); return { text: '', args: '', usage: null }; });
|
|
822
822
|
spent.push(usageOf(r2.usage));
|
|
823
823
|
const refresh = r2.args || r2.text;
|
|
824
824
|
const p2 = parseReply(refresh.includes('"script"') ? refresh : `{"script":"x",${refresh.replace(/^[^{]*\{/, '')}`, now);
|
|
@@ -1010,7 +1010,7 @@ export function apply(ctx, config = {}) {
|
|
|
1010
1010
|
const system = prompt('interlude.growth.system', { name: canon?.storyDefaults?.characterName ?? 'dot', maxChars: cfg.portraitMaxChars, change: `${Math.round(cfg.portraitMaxChange * 100)}%` });
|
|
1011
1011
|
const messages = [createUserMessage({ content: [{ type: 'text', text: JSON.stringify(input, null, 1) }], source: { kind: 'dsh-interlude' } })];
|
|
1012
1012
|
const call = async (msgs) => {
|
|
1013
|
-
const r = await collectReply(ctx.llm.stream({ provider: sel.provider, model: sel.model, ...(sel.reasoningEffort ? { reasoningEffort: sel.reasoningEffort } : {}), system, tools: [growthTool()], maxTokens: cfg.maxTokens, messages: msgs }));
|
|
1013
|
+
const r = await collectReply(ctx.llm.stream(background({ provider: sel.provider, model: sel.model, ...(sel.reasoningEffort ? { reasoningEffort: sel.reasoningEffort } : {}), system, tools: [growthTool()], maxTokens: cfg.maxTokens, messages: msgs })));
|
|
1014
1014
|
const u = usageOf(r.usage);
|
|
1015
1015
|
if (u) { meta.dayTokensIn = (meta.dayTokensIn ?? 0) + u.in + u.cached; meta.dayTokensCached = (meta.dayTokensCached ?? 0) + u.cached; meta.dayTokensOut = (meta.dayTokensOut ?? 0) + u.out; saveMeta(); }
|
|
1016
1016
|
try { appendFileSync(files.calls, `${JSON.stringify({ ts: new Date().toISOString(), phase: 'growth', usage: u, reply: clip(r.args || r.text, 3000) })}\n`); } catch (error) { void error; }
|
|
@@ -1222,6 +1222,11 @@ export function apply(ctx, config = {}) {
|
|
|
1222
1222
|
}
|
|
1223
1223
|
}
|
|
1224
1224
|
ctx.effect(() => { const timer = setInterval(tick, 60000); return () => clearInterval(timer); }, 'dsh-interlude: scheduler');
|
|
1225
|
+
// Model requests (src/llm-gate.js): rounds and the growth review are marked above. With dsh-dot her
|
|
1226
|
+
// looks, plays, tries and free time run in its errand (dot registers that); without it, the session
|
|
1227
|
+
// set aside in vmSession and a look / try / free-time session that is not her conversation.
|
|
1228
|
+
const herConversation = (id) => { const d = dshDot(); return d ? id === d.session?.() : id === lastActSession && id !== cfg.vmSession; };
|
|
1229
|
+
installLlmGate(ctx, { name: 'dot-interlude', backgroundSessions: (id) => ((Boolean(cfg.vmSession) && id === cfg.vmSession) || observing.has(id) || trying.has(id) || free.has(id)) && !herConversation(id) });
|
|
1225
1230
|
|
|
1226
1231
|
// 4. 幕前: the Canon is a system-prompt section (right after the deployment persona, static per
|
|
1227
1232
|
// session so the cached prefix holds); the continuity is a dynamic context after the history.
|
package/src/llm-gate.js
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
// One gate in front of every model request in this dsh, so her life in the background does not use
|
|
2
|
+
// up the requests-per-minute budget the owner's conversation needs (users hit
|
|
3
|
+
// `429 rate_limit_rpm_exceeded` in a normal chat). Built on dsh-llm's `llm/stream` waterfall, which
|
|
4
|
+
// every model call goes through — the agent loop's steps and direct `ctx.llm.stream(...)` alike.
|
|
5
|
+
// After LangChain's InMemoryRateLimiter (a bucket in front of model calls), LiteLLM's request
|
|
6
|
+
// priorities and cooldowns, promptfoo's scheduler (AIMD per provider, honour retry-after) and the
|
|
7
|
+
// OpenAI SDKs' backoff with jitter — at the scale of one person's desktop: no dependency, process memory only.
|
|
8
|
+
//
|
|
9
|
+
// Which requests are ours in the background (only these are ever paced; anything unknown is foreground):
|
|
10
|
+
//
|
|
11
|
+
// request where class
|
|
12
|
+
// ───────────────────────────────────────────── ──────────────────────────── ──────────
|
|
13
|
+
// interlude round, its continuity refresh, interlude/core.js (marked) background
|
|
14
|
+
// the weekly growth review
|
|
15
|
+
// memory consolidation, diary memory/memory.js complete() background
|
|
16
|
+
// QQ group scoring (groupPolicy 'score') qq/qq.js (marked) background
|
|
17
|
+
// howto reflection after a phone run dot/core.js reflectOnce() background
|
|
18
|
+
// her errand session (current and retired): dot/core.js isErrand background
|
|
19
|
+
// non-conversation app notifications, phone
|
|
20
|
+
// checks, interlude look / play / try / free
|
|
21
|
+
// time (dshDot.task)
|
|
22
|
+
// interlude without dsh-dot: interlude.vmSession interlude/core.js background
|
|
23
|
+
// (a session set aside for looks / plays /
|
|
24
|
+
// tries), and a look / try / free-time session
|
|
25
|
+
// that is not her conversation
|
|
26
|
+
// her conversation (lastSession): the owner's — foreground
|
|
27
|
+
// dsh / IM chat, QQ messages (private and
|
|
28
|
+
// group) and conversation-app notifications
|
|
29
|
+
// (QQ, WeChat) — these wake her there
|
|
30
|
+
// a phone check or look when there is no errand — foreground
|
|
31
|
+
// (it falls back to her conversation)
|
|
32
|
+
// anything else (other plugins, sessions we do — foreground
|
|
33
|
+
// not know, compaction, titles)
|
|
34
|
+
//
|
|
35
|
+
// What the gate does, per provider (a limit on one provider never slows another):
|
|
36
|
+
// - counts every request started in the last 60 s (both classes);
|
|
37
|
+
// - a background request starts only when the window holds fewer than `backgroundRpm` requests,
|
|
38
|
+
// at least 60 s / cap after the previous background one (bucket refill: no bursts), one at a
|
|
39
|
+
// time, and not while a foreground request is in flight (one open for 10 min is taken as
|
|
40
|
+
// abandoned) or within `foregroundQuietSeconds` after one ended (the owner's turn has several steps);
|
|
41
|
+
// - a RATE_LIMIT finish (any class) starts a cooldown for background requests — at least the 60 s
|
|
42
|
+
// 60 s after the latest refusal, doubling with jitter when a fresh window is refused again
|
|
43
|
+
// (≤ 10 min), or the provider's retry-after — and halves the background cap (≥ 1) once per
|
|
44
|
+
// incident (refusals within 60 s of the counted one, e.g. dsh's retries, are the same incident);
|
|
45
|
+
// after 3 min without a 429 the cap grows back by 1 a minute (AIMD);
|
|
46
|
+
// - a background request never waits longer than `maxBackgroundWaitSeconds` (≤ 270 s, below dot's
|
|
47
|
+
// turnStallMs, so an errand step is never taken for a stalled turn), and stops waiting at once
|
|
48
|
+
// when its signal aborts (the adapter then ends it with dsh's own aborted finish);
|
|
49
|
+
// - `holdRetries`: see holdFor() — the one case a foreground request is touched;
|
|
50
|
+
// - nothing in here may break a model call: any error in the bookkeeping lets the request through.
|
|
51
|
+
import { sectionOf } from './settings.js';
|
|
52
|
+
|
|
53
|
+
export const defaults = {
|
|
54
|
+
backgroundRpm: 20, // see DEFAULT_RPM_WHY; 0 = no pacing at all (the gate only counts)
|
|
55
|
+
foregroundQuietSeconds: 15, // background waits this long after her conversation's last request ended
|
|
56
|
+
maxBackgroundWaitSeconds: 180, // a background request never waits longer; capped at MAX_WAIT_CAP_SECONDS
|
|
57
|
+
holdRetries: true, // hold dsh's fast retry of a rate-limited request until the window has room
|
|
58
|
+
retryHoldMaxSeconds: 30, // …but never longer than this
|
|
59
|
+
};
|
|
60
|
+
// Why 20: one background request every 3 s at most. The measured burst (one "like a post" act) was
|
|
61
|
+
// dozens of requests in under a minute; 20 leaves most of a typical entry-tier RPM limit (tens per
|
|
62
|
+
// minute) to the owner, while a single errand loop, whose steps already take seconds each (tools,
|
|
63
|
+
// the phone), barely slows down. Below that, AIMD halves the cap on the first 429 anyway.
|
|
64
|
+
|
|
65
|
+
const WINDOW_MS = 60000;
|
|
66
|
+
const RETRY_WINDOW_MS = 12000; // dsh's retry waits ≤ 10 s (+10% jitter) after a failure: a start this soon is a retry
|
|
67
|
+
const COOLDOWN_MAX_MS = 600000;
|
|
68
|
+
const RECOVER_AFTER_MS = 180000; // no 429 for this long: the cap grows again, repeated-hit count resets
|
|
69
|
+
const RAISE_EVERY_MS = 60000;
|
|
70
|
+
const FG_STALE_MS = 600000; // a foreground request "in flight" this long is taken as abandoned (never iterated / dropped)
|
|
71
|
+
// dot's turnStallMs is 300 s: a background agent step held longer would make her errand look stalled.
|
|
72
|
+
export const MAX_WAIT_CAP_SECONDS = 270;
|
|
73
|
+
const JITTER = 0.25;
|
|
74
|
+
|
|
75
|
+
// Hand-built requests the plugin makes for background work. A WeakSet of the options objects:
|
|
76
|
+
// the waterfall hands every listener the very object passed to ctx.llm.stream.
|
|
77
|
+
const BACKGROUND = new WeakSet();
|
|
78
|
+
/** Mark one hand-built request as background work; returns the same options object. */
|
|
79
|
+
export function background(options) {
|
|
80
|
+
try { if (options && typeof options === 'object') BACKGROUND.add(options); } catch { /* never in the way */ }
|
|
81
|
+
return options;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const num = (v, d, min = 0) => (Number.isFinite(Number(v)) && Number(v) >= min ? Number(v) : d);
|
|
85
|
+
function normalize(c = {}) {
|
|
86
|
+
return {
|
|
87
|
+
backgroundRpm: Math.floor(num(c.backgroundRpm, defaults.backgroundRpm)),
|
|
88
|
+
quietMs: num(c.foregroundQuietSeconds, defaults.foregroundQuietSeconds) * 1000,
|
|
89
|
+
maxWaitMs: Math.min(MAX_WAIT_CAP_SECONDS, num(c.maxBackgroundWaitSeconds, defaults.maxBackgroundWaitSeconds)) * 1000,
|
|
90
|
+
holdRetries: c.holdRetries === undefined ? defaults.holdRetries : c.holdRetries !== false,
|
|
91
|
+
retryHoldMaxMs: num(c.retryHoldMaxSeconds, defaults.retryHoldMaxSeconds) * 1000,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The gate's logic, clock-injectable. `config`: the `llm` settings section; `now`/`setTimer`/
|
|
97
|
+
* `clearTimer`/`random` for tests; `logger` ({ info, debug }); `audit(event, data)`.
|
|
98
|
+
*/
|
|
99
|
+
export function createGate({ config = {}, now = Date.now, setTimer = setTimeout, clearTimer = clearTimeout, random = Math.random, logger = {}, audit = () => {} } = {}) {
|
|
100
|
+
const cfg = normalize(config);
|
|
101
|
+
const pacing = cfg.backgroundRpm > 0;
|
|
102
|
+
const providers = new Map();
|
|
103
|
+
const sessionTests = new Map(); // name → (sessionId) => boolean
|
|
104
|
+
const limits = new Map(); // provider \0 session → { at, retryAfterMs, inWindow }: its last RATE_LIMIT
|
|
105
|
+
const debug = (m) => { try { logger.debug?.(m); } catch { /* ignore */ } };
|
|
106
|
+
const info = (m) => { try { logger.info?.(m); } catch { /* ignore */ } };
|
|
107
|
+
const note = (event, data) => { try { audit(event, data); } catch { /* ignore */ } };
|
|
108
|
+
const timer = (fn, ms) => { const h = setTimer(fn, Math.max(0, ms)); h?.unref?.(); return h; };
|
|
109
|
+
const stamp = (t) => new Date(t).toTimeString().slice(0, 8);
|
|
110
|
+
|
|
111
|
+
const P = (name) => {
|
|
112
|
+
let p = providers.get(name);
|
|
113
|
+
if (!p) {
|
|
114
|
+
p = { name, starts: [], bgStarts: [], fg: new Map(), fgLastEnd: -Infinity, lastBgStart: -Infinity, cap: cfg.backgroundRpm, raiseAt: Infinity, hits: 0, lastHitAt: -Infinity, lastAnyHitAt: -Infinity, coolingUntil: 0, coolTimer: null, queue: [], timer: null, timerAt: Infinity, delayed: 0, rateLimited: 0, heldRetries: 0 };
|
|
115
|
+
providers.set(name, p);
|
|
116
|
+
}
|
|
117
|
+
return p;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
function refresh(p, t) {
|
|
121
|
+
while (p.starts.length && p.starts[0] <= t - WINDOW_MS) p.starts.shift();
|
|
122
|
+
while (p.bgStarts.length && p.bgStarts[0] <= t - WINDOW_MS) p.bgStarts.shift();
|
|
123
|
+
while (p.cap < cfg.backgroundRpm && t >= p.raiseAt) { p.cap++; p.raiseAt += RAISE_EVERY_MS; } // additive increase
|
|
124
|
+
if (p.cap >= cfg.backgroundRpm) p.raiseAt = Infinity;
|
|
125
|
+
if (p.hits && t - p.lastAnyHitAt >= RECOVER_AFTER_MS) p.hits = 0;
|
|
126
|
+
for (const [rec, at] of p.fg) if (at <= t - FG_STALE_MS) p.fg.delete(rec); // abandoned: never held the background for ever
|
|
127
|
+
for (const [k, l] of limits) if (t - l.at > RETRY_WINDOW_MS) limits.delete(k); // only ever read within RETRY_WINDOW_MS
|
|
128
|
+
if (p.coolingUntil && t >= p.coolingUntil) {
|
|
129
|
+
p.coolingUntil = 0;
|
|
130
|
+
info(`${p.name}: cooldown over, background requests resume (cap ${p.cap}/min)`);
|
|
131
|
+
note('cooldown-end', { provider: p.name, cap: p.cap });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The earliest time the head of the background queue may start (Infinity: wait for an event). */
|
|
136
|
+
function readyAt(p, t) {
|
|
137
|
+
// While his request is in flight: not before it ends (an event pumps then) or is taken as abandoned.
|
|
138
|
+
const fgOpen = p.fg.size ? Math.min(...p.fg.values()) + FG_STALE_MS : -Infinity;
|
|
139
|
+
let at = Math.max(t, fgOpen, p.fgLastEnd + cfg.quietMs, p.coolingUntil, p.lastBgStart + WINDOW_MS / p.cap);
|
|
140
|
+
if (p.starts.length >= p.cap) at = Math.max(at, p.starts[p.starts.length - p.cap] + WINDOW_MS);
|
|
141
|
+
return at;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Count one request as started now. */
|
|
145
|
+
function start(rec, t) {
|
|
146
|
+
const p = rec.p;
|
|
147
|
+
rec.started = true;
|
|
148
|
+
p.starts.push(t);
|
|
149
|
+
if (rec.cls === 'foreground') p.fg.set(rec, t);
|
|
150
|
+
else { p.bgStarts.push(t); p.lastBgStart = t; }
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function admit(p, w, t) {
|
|
154
|
+
p.queue.splice(p.queue.indexOf(w), 1);
|
|
155
|
+
w.off();
|
|
156
|
+
start(w.rec, t);
|
|
157
|
+
if (t > w.since) p.delayed++;
|
|
158
|
+
w.resolve();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function pump(p) {
|
|
162
|
+
try {
|
|
163
|
+
const t = now();
|
|
164
|
+
refresh(p, t);
|
|
165
|
+
for (const w of [...p.queue]) if (t >= w.deadline) admit(p, w, t); // the bound outranks every rule
|
|
166
|
+
if (p.queue.length && readyAt(p, t) <= t) admit(p, p.queue[0], t); // one at a time
|
|
167
|
+
schedule(p, t);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
debug(`llm gate: pump failed (${err.message}); releasing ${p.queue.length} waiting`);
|
|
170
|
+
for (const w of p.queue.splice(0)) { try { w.off(); } catch { /* ignore */ } w.resolve(); }
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function schedule(p, t) {
|
|
175
|
+
if (!p.queue.length) { if (p.timer) clearTimer(p.timer); p.timer = null; p.timerAt = Infinity; return; }
|
|
176
|
+
const next = Math.min(readyAt(p, t), ...p.queue.map((w) => w.deadline));
|
|
177
|
+
if (next === p.timerAt && p.timer) return;
|
|
178
|
+
if (p.timer) clearTimer(p.timer);
|
|
179
|
+
p.timerAt = next;
|
|
180
|
+
p.timer = Number.isFinite(next) ? timer(() => { p.timer = null; p.timerAt = Infinity; pump(p); }, next - t) : null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Wait until `until` (or the signal aborts); resolves either way. */
|
|
184
|
+
const sleep = (ms, signal) => new Promise((resolve) => {
|
|
185
|
+
if (signal?.aborted || ms <= 0) { resolve(); return; }
|
|
186
|
+
let h = null;
|
|
187
|
+
const done = () => { if (h) clearTimer(h); signal?.removeEventListener?.('abort', done); resolve(); };
|
|
188
|
+
h = timer(done, ms);
|
|
189
|
+
signal?.addEventListener?.('abort', done, { once: true });
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* dsh's own retry after a RATE_LIMIT (500 ms, 1 s, 2 s … ≤ 10 s) lands inside the same 60 s window
|
|
194
|
+
* and is refused again. A foreground request of the same session and provider starting within
|
|
195
|
+
* RETRY_WINDOW_MS of that finish is taken for the retry and held until the provider's retry-after,
|
|
196
|
+
* else until enough of the last minute's requests have aged out: the hit came at the L-th request
|
|
197
|
+
* in the window, so the limit is taken as L - 1 and the retry waits for the window to hold fewer.
|
|
198
|
+
* A rough estimate, and always capped at retryHoldMaxSeconds (and the request's own abort).
|
|
199
|
+
*/
|
|
200
|
+
function holdFor(p, rec, t) {
|
|
201
|
+
if (!cfg.holdRetries || !rec.session) return 0;
|
|
202
|
+
const l = limits.get(`${p.name}\0${rec.session}`);
|
|
203
|
+
if (!l || t - l.at > RETRY_WINDOW_MS) return 0;
|
|
204
|
+
let until;
|
|
205
|
+
if (l.retryAfterMs > 0) until = l.at + l.retryAfterMs;
|
|
206
|
+
else {
|
|
207
|
+
const allowed = Math.max(1, l.inWindow - 1);
|
|
208
|
+
const i = p.starts.length - allowed;
|
|
209
|
+
until = i >= 0 ? p.starts[i] + WINDOW_MS : 0;
|
|
210
|
+
}
|
|
211
|
+
return Math.max(0, Math.min(until, t + cfg.retryHoldMaxMs) - t);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function classify(options) {
|
|
215
|
+
if (BACKGROUND.has(options)) return 'background';
|
|
216
|
+
const id = options?.sessionId;
|
|
217
|
+
if (id) {
|
|
218
|
+
for (const test of sessionTests.values()) {
|
|
219
|
+
try { if (test(String(id))) return 'background'; } catch (err) { debug(`llm gate: session test failed (${err.message})`); }
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return 'foreground';
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Book one request in: { rec, wait } (wait: a promise, or null when it may start now). */
|
|
226
|
+
function begin(options) {
|
|
227
|
+
const t = now();
|
|
228
|
+
const p = P(String(options?.provider ?? '?'));
|
|
229
|
+
refresh(p, t);
|
|
230
|
+
const rec = { p, cls: classify(options), session: options?.sessionId ? String(options.sessionId) : '', started: false, signal: options?.signal };
|
|
231
|
+
// An already aborted request is not counted: the adapter ends it at once without a provider call.
|
|
232
|
+
if (rec.signal?.aborted) return { rec, wait: null };
|
|
233
|
+
if (rec.cls === 'foreground') {
|
|
234
|
+
const hold = holdFor(p, rec, t);
|
|
235
|
+
if (!hold) { start(rec, t); return { rec, wait: null }; }
|
|
236
|
+
p.heldRetries++;
|
|
237
|
+
debug(`llm gate: holding a retry in ${rec.session} on ${p.name} for ${Math.round(hold / 1000)} s`);
|
|
238
|
+
return { rec, wait: sleep(hold, rec.signal).then(() => { if (!rec.signal?.aborted) { const s = now(); refresh(p, s); start(rec, s); } }) };
|
|
239
|
+
}
|
|
240
|
+
if (!pacing) { start(rec, t); return { rec, wait: null }; }
|
|
241
|
+
const wait = new Promise((resolve) => {
|
|
242
|
+
const w = { rec, since: t, deadline: t + cfg.maxWaitMs, resolve, off: () => {} };
|
|
243
|
+
if (rec.signal?.addEventListener) {
|
|
244
|
+
const onAbort = () => { const i = p.queue.indexOf(w); if (i < 0) return; p.queue.splice(i, 1); resolve(); pump(p); };
|
|
245
|
+
rec.signal.addEventListener('abort', onAbort, { once: true });
|
|
246
|
+
w.off = () => rec.signal.removeEventListener?.('abort', onAbort);
|
|
247
|
+
}
|
|
248
|
+
p.queue.push(w);
|
|
249
|
+
});
|
|
250
|
+
pump(p);
|
|
251
|
+
return { rec, wait };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function hit(p, rec, failure, t) {
|
|
255
|
+
p.rateLimited++;
|
|
256
|
+
const retryAfterMs = Number(failure?.providerRetryAfterMs) > 0 ? Number(failure.providerRetryAfterMs) : 0;
|
|
257
|
+
if (rec.session) limits.set(`${p.name}\0${rec.session}`, { at: t, retryAfterMs, inWindow: p.starts.length });
|
|
258
|
+
if (!pacing) return;
|
|
259
|
+
// One incident, one hit: refusals within WINDOW_MS of the last counted hit (a burst refused
|
|
260
|
+
// together, dsh's five fast retries) are the same incident. Only a fresh window refused again is a
|
|
261
|
+
// repeat (halves the cap again, doubles the cooldown); every hit still extends the cooldown below.
|
|
262
|
+
const repeat = t - p.lastHitAt >= WINDOW_MS;
|
|
263
|
+
if (repeat) {
|
|
264
|
+
p.hits++; p.lastHitAt = t;
|
|
265
|
+
p.cap = Math.max(1, Math.floor(p.cap / 2)); // multiplicative decrease
|
|
266
|
+
}
|
|
267
|
+
p.lastAnyHitAt = t;
|
|
268
|
+
p.raiseAt = t + RECOVER_AFTER_MS; // recovery counts from the latest refusal
|
|
269
|
+
const backoff = repeat ? Math.min(COOLDOWN_MAX_MS, WINDOW_MS * 2 ** (p.hits - 1) * (1 + JITTER * random())) : WINDOW_MS;
|
|
270
|
+
const until = t + Math.min(COOLDOWN_MAX_MS, Math.max(backoff, retryAfterMs));
|
|
271
|
+
if (until <= p.coolingUntil) return;
|
|
272
|
+
const was = p.coolingUntil;
|
|
273
|
+
p.coolingUntil = until;
|
|
274
|
+
if (p.coolTimer) clearTimer(p.coolTimer);
|
|
275
|
+
p.coolTimer = timer(() => { p.coolTimer = null; pump(p); }, until - t);
|
|
276
|
+
if (!was) {
|
|
277
|
+
info(`${p.name}: rate limited (${rec.cls}${rec.session ? ` in ${rec.session}` : ''}); background requests wait until ${stamp(until)}, cap ${p.cap}/min`);
|
|
278
|
+
note('cooldown-start', { provider: p.name, until: new Date(until).toISOString(), cap: p.cap, hits: p.hits, retryAfterMs: retryAfterMs || undefined, class: rec.cls });
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** The request ended: `reason` is its finish chunk's reason, or null (stopped early, thrown). */
|
|
283
|
+
function finish(rec, reason) {
|
|
284
|
+
const p = rec.p, t = now();
|
|
285
|
+
refresh(p, t);
|
|
286
|
+
if (rec.cls === 'foreground' && rec.started) { p.fg.delete(rec); p.fgLastEnd = t; }
|
|
287
|
+
rec.started = false;
|
|
288
|
+
if (reason?.kind === 'error' && reason.failure?.code === 'RATE_LIMIT') hit(p, rec, reason.failure, t);
|
|
289
|
+
else if (rec.session && reason) limits.delete(`${p.name}\0${rec.session}`);
|
|
290
|
+
pump(p);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Pass the chunks through unchanged, noting the terminal finish (or that the stream ended without one). */
|
|
294
|
+
async function* observe(source, rec) {
|
|
295
|
+
let done = false;
|
|
296
|
+
const end = (reason) => { if (done) return; done = true; try { finish(rec, reason); } catch (err) { debug(`llm gate: finish failed (${err.message})`); } };
|
|
297
|
+
try {
|
|
298
|
+
for await (const chunk of source) {
|
|
299
|
+
if (chunk?.type === 'finish') end(chunk.reason ?? null);
|
|
300
|
+
yield chunk;
|
|
301
|
+
}
|
|
302
|
+
} finally { end(null); }
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return {
|
|
306
|
+
config: cfg,
|
|
307
|
+
/** The `llm/stream` listener body: delays (when it must) and observes one request. */
|
|
308
|
+
wrap(options, next) {
|
|
309
|
+
let booked;
|
|
310
|
+
try { booked = begin(options); } catch (err) { debug(`llm gate: ${err.message}; request let through`); return next(); }
|
|
311
|
+
const { rec, wait } = booked;
|
|
312
|
+
if (!wait) {
|
|
313
|
+
let source;
|
|
314
|
+
try { source = next(); } catch (err) { try { finish(rec, null); } catch { /* ignore */ } throw err; }
|
|
315
|
+
return observe(source, rec);
|
|
316
|
+
}
|
|
317
|
+
return (async function* gated() {
|
|
318
|
+
try { await wait; } catch (err) { debug(`llm gate: wait failed (${err.message})`); }
|
|
319
|
+
let source;
|
|
320
|
+
try { source = next(); } catch (err) { try { finish(rec, null); } catch { /* ignore */ } throw err; }
|
|
321
|
+
yield* observe(source, rec);
|
|
322
|
+
})();
|
|
323
|
+
},
|
|
324
|
+
classify,
|
|
325
|
+
/** Register which sessions are background (a predicate on the session id); returns the remover. */
|
|
326
|
+
backgroundSessions(name, test) {
|
|
327
|
+
sessionTests.set(name, test);
|
|
328
|
+
return () => { if (sessionTests.get(name) === test) sessionTests.delete(name); };
|
|
329
|
+
},
|
|
330
|
+
/** Per provider: requests in the last minute, background cap, cooldown, waiting, totals. */
|
|
331
|
+
status() {
|
|
332
|
+
const t = now();
|
|
333
|
+
return {
|
|
334
|
+
pacing, backgroundRpm: cfg.backgroundRpm, quietSeconds: cfg.quietMs / 1000, maxWaitSeconds: cfg.maxWaitMs / 1000, holdRetries: cfg.holdRetries,
|
|
335
|
+
providers: [...providers.values()].map((p) => {
|
|
336
|
+
try { refresh(p, t); } catch { /* status only */ }
|
|
337
|
+
return { provider: p.name, lastMinute: p.starts.length, backgroundLastMinute: p.bgStarts.length, cap: p.cap, coolingUntil: p.coolingUntil || null, waiting: p.queue.length, foregroundInFlight: p.fg.size, delayed: p.delayed, rateLimited: p.rateLimited, heldRetries: p.heldRetries };
|
|
338
|
+
}),
|
|
339
|
+
};
|
|
340
|
+
},
|
|
341
|
+
/** Let everything waiting go and drop the timers (dispose). */
|
|
342
|
+
stop() {
|
|
343
|
+
for (const p of providers.values()) {
|
|
344
|
+
for (const w of p.queue.splice(0)) { try { w.off(); } catch { /* ignore */ } w.resolve(); }
|
|
345
|
+
if (p.timer) clearTimer(p.timer);
|
|
346
|
+
if (p.coolTimer) clearTimer(p.coolTimer);
|
|
347
|
+
p.timer = p.coolTimer = null; p.timerAt = Infinity;
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** One line for /dot. */
|
|
354
|
+
export function statusLine(st) {
|
|
355
|
+
if (!st) return 'model requests: gate not installed';
|
|
356
|
+
const head = st.pacing ? `background ≤${st.backgroundRpm}/min, waits ${st.quietSeconds} s after yours, ≤${st.maxWaitSeconds} s` : 'pacing off (llm.backgroundRpm 0)';
|
|
357
|
+
const per = st.providers.map((p) => `${p.provider} ${p.lastMinute}/min (bg cap ${p.cap}${p.coolingUntil ? `, cooling until ${new Date(p.coolingUntil).toTimeString().slice(0, 8)}` : ''}${p.waiting ? `, ${p.waiting} waiting` : ''}, ${p.delayed} delayed, ${p.rateLimited}×429${p.heldRetries ? `, ${p.heldRetries} retries held` : ''})`);
|
|
358
|
+
return `model requests: ${per.join(' · ') || 'none yet'} — ${head}`;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// One gate per dsh (per Cordis root), whichever components are on. Each component that makes model
|
|
362
|
+
// calls installs it; the listener lives on one of their contexts and moves to another if that one is
|
|
363
|
+
// disposed, so turning one component off never takes the gate away from the others.
|
|
364
|
+
const installs = new WeakMap();
|
|
365
|
+
const rootOf = (ctx) => { try { return ctx?.root ?? ctx; } catch { return ctx; } };
|
|
366
|
+
|
|
367
|
+
/** The gate installed for this dsh, if any (the dot page's status). */
|
|
368
|
+
export function gateFor(ctx) { return installs.get(rootOf(ctx))?.gate; }
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Install the gate once per dsh (idempotent) and, with `backgroundSessions`, register which of this
|
|
372
|
+
* component's sessions are background for as long as the component lives. Returns the gate, or null
|
|
373
|
+
* when it could not be installed (the plugin then works exactly as before).
|
|
374
|
+
*/
|
|
375
|
+
export function installLlmGate(ctx, { name = 'dsh-dot', backgroundSessions = null, deps = {} } = {}) {
|
|
376
|
+
try {
|
|
377
|
+
const root = rootOf(ctx);
|
|
378
|
+
let inst = installs.get(root);
|
|
379
|
+
if (!inst) {
|
|
380
|
+
const logger = (() => { try { return ctx.logger?.('dsh-dot/llm-gate') ?? {}; } catch { return {}; } })();
|
|
381
|
+
inst = { holders: new Set(), owner: null, off: null, gate: null };
|
|
382
|
+
const audit = (event, data) => {
|
|
383
|
+
const c = inst.owner ?? ctx;
|
|
384
|
+
const a = (() => { try { return c.get?.('dshComputer')?.audit ?? c.get?.('dshPhone')?.audit; } catch { return undefined; } })();
|
|
385
|
+
a?.({ kind: 'llm-gate', event, ...data });
|
|
386
|
+
};
|
|
387
|
+
inst.gate = createGate({ config: deps.config ?? sectionOf('llm', (m) => logger.warn?.(m)), logger, audit, ...deps });
|
|
388
|
+
installs.set(root, inst);
|
|
389
|
+
}
|
|
390
|
+
const { gate } = inst;
|
|
391
|
+
const attach = () => {
|
|
392
|
+
if (inst.owner) return;
|
|
393
|
+
for (const h of inst.holders) {
|
|
394
|
+
try {
|
|
395
|
+
// `global`: dsh-llm dispatches with the LlmRuntime as `this`; never filtered out by scope.
|
|
396
|
+
inst.off = h.on('llm/stream', (options, next) => gate.wrap(options, next), { global: true });
|
|
397
|
+
inst.owner = h;
|
|
398
|
+
return;
|
|
399
|
+
} catch { /* try the next holder */ }
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
const setup = () => {
|
|
403
|
+
inst.holders.add(ctx);
|
|
404
|
+
const removeTest = backgroundSessions ? gate.backgroundSessions(name, backgroundSessions) : () => {};
|
|
405
|
+
attach();
|
|
406
|
+
return () => {
|
|
407
|
+
removeTest();
|
|
408
|
+
inst.holders.delete(ctx);
|
|
409
|
+
if (inst.owner === ctx) { try { inst.off?.(); } catch { /* disposed with its fiber anyway */ } inst.owner = null; inst.off = null; attach(); }
|
|
410
|
+
if (!inst.holders.size) { gate.stop(); installs.delete(root); }
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
if (typeof ctx.effect === 'function') ctx.effect(setup, `${name}: llm request gate`);
|
|
414
|
+
else setup();
|
|
415
|
+
return gate;
|
|
416
|
+
} catch (err) {
|
|
417
|
+
try { ctx?.logger?.('dsh-dot/llm-gate')?.debug?.(`llm gate not installed: ${err.message}`); } catch { /* ignore */ }
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
}
|
package/src/memory/memory.js
CHANGED
|
@@ -28,6 +28,7 @@ import { createRecall } from './recall.js';
|
|
|
28
28
|
import { annotate } from './when.js';
|
|
29
29
|
import { dayMark, unstamp } from '../clock.js';
|
|
30
30
|
import { sectionOf, setValues } from '../settings.js';
|
|
31
|
+
import { background, installLlmGate } from '../llm-gate.js';
|
|
31
32
|
import { configure as configurePrompts, prompt, table } from '../prompts.js';
|
|
32
33
|
|
|
33
34
|
export const name = 'dot-memory';
|
|
@@ -265,6 +266,7 @@ export function apply(ctx, config = {}) {
|
|
|
265
266
|
const files = { memory: join(dir, 'memory.json'), md: join(dir, 'memory.md'), transcript: join(dir, 'transcript.jsonl'), handoffs: join(dir, 'handoffs.jsonl'), calls: join(dir, 'calls.jsonl'), diary: join(dir, 'diary.md'), archive: join(dir, 'memory.v019.json'), migration: join(dir, 'memory-migration.md') };
|
|
266
267
|
mkdirSync(dir, { recursive: true });
|
|
267
268
|
const dot = () => ctx.get('dshDot');
|
|
269
|
+
installLlmGate(ctx, { name: 'dsh-dot/memory' }); // her consolidation and diary wait behind his requests (complete() below)
|
|
268
270
|
// Checked when used, not once at boot: the other plugin may start after this one.
|
|
269
271
|
let coexistLogged = false;
|
|
270
272
|
const peopleOnly = () => {
|
|
@@ -467,7 +469,7 @@ export function apply(ctx, config = {}) {
|
|
|
467
469
|
let usage = null;
|
|
468
470
|
try {
|
|
469
471
|
let finish = null;
|
|
470
|
-
for await (const chunk of ctx.llm.stream({ provider: sel.provider, model: sel.model, ...(sel.reasoningEffort ? { reasoningEffort: sel.reasoningEffort } : {}), maxTokens: cfg.maxTokens, messages: [createUserMessage({ content: [{ type: 'text', text }], source: { kind: 'dsh-dot-memory' } })] })) {
|
|
472
|
+
for await (const chunk of ctx.llm.stream(background({ provider: sel.provider, model: sel.model, ...(sel.reasoningEffort ? { reasoningEffort: sel.reasoningEffort } : {}), maxTokens: cfg.maxTokens, messages: [createUserMessage({ content: [{ type: 'text', text }], source: { kind: 'dsh-dot-memory' } })] }))) {
|
|
471
473
|
if (chunk.type === 'text-delta') raw += chunk.text;
|
|
472
474
|
if (chunk.type === 'usage') usage = chunk.usage ?? null;
|
|
473
475
|
if (chunk.type === 'finish') finish = chunk.reason;
|
package/src/memory/recall.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
// off.
|
|
26
26
|
// Passwords and keys never reach the index, the cloud, or her prompt (store.js's filter).
|
|
27
27
|
import { spawn } from 'node:child_process';
|
|
28
|
-
import { appendFileSync, chmodSync, existsSync, mkdirSync, readFileSync, rmSync,
|
|
28
|
+
import { appendFileSync, chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
29
29
|
import { createRequire } from 'node:module';
|
|
30
30
|
import { homedir } from 'node:os';
|
|
31
31
|
import { dirname, join } from 'node:path';
|
package/src/memory/store.js
CHANGED
|
@@ -46,19 +46,6 @@ export function jaccard(a, b) {
|
|
|
46
46
|
return inter / (A.size + B.size - inter);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
/**
|
|
50
|
-
* Character-bigram Jaccard: looser than the 3-gram one, for "is this the same fact said again"
|
|
51
|
-
* about one person (Chinese paraphrases share bigrams far more than trigrams).
|
|
52
|
-
*/
|
|
53
|
-
export function similar2(a, b) {
|
|
54
|
-
const grams = (t) => { const s = normText(t); const out = new Set(); for (let i = 0; i + 2 <= s.length; i++) out.add(s.slice(i, i + 2)); if (s.length < 2 && s) out.add(s); return out; };
|
|
55
|
-
const A = grams(a), B = grams(b);
|
|
56
|
-
if (!A.size || !B.size) return 0;
|
|
57
|
-
let inter = 0;
|
|
58
|
-
for (const g of A) if (B.has(g)) inter++;
|
|
59
|
-
return inter / (A.size + B.size - inter);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
49
|
/** Chinese runs ~1.4–1.6 characters per token; estimate conservatively. */
|
|
63
50
|
export const estimateTokens = (text) => Math.ceil(String(text ?? '').length / 1.5);
|
|
64
51
|
|
|
@@ -146,9 +133,6 @@ export function handleOf(platform, { uid = '', name = '' } = {}) {
|
|
|
146
133
|
const n = String(name ?? '').trim();
|
|
147
134
|
return n ? `${p}:name:${n}` : '';
|
|
148
135
|
}
|
|
149
|
-
/** Kept for callers that still build "<platform>:name:<x>" handles directly. */
|
|
150
|
-
export const personId = (platform, handle) => `${String(platform ?? '').trim().toLowerCase() || 'unknown'}:${String(handle ?? '').trim()}`;
|
|
151
|
-
|
|
152
136
|
const platformOf = (handle) => String(handle).split(':')[0];
|
|
153
137
|
const nameOfHandle = (handle) => { const m = /^[^:]+:name:(.+)$/.exec(String(handle)); return m ? m[1] : ''; };
|
|
154
138
|
|
package/src/page/api.js
CHANGED
|
@@ -9,6 +9,7 @@ import { homedir } from 'node:os';
|
|
|
9
9
|
import { rejectUnlessOwner } from '../web-auth.js';
|
|
10
10
|
import { dshHome, fileError, readAll, writeSections } from '../settings.js';
|
|
11
11
|
import { describe, validatePatch } from '../settings-schema.js';
|
|
12
|
+
import { gateFor } from '../llm-gate.js';
|
|
12
13
|
import { doctorFor, FIXES } from '../doctor.js';
|
|
13
14
|
import { bundle, summary, versions } from './diag.js';
|
|
14
15
|
import { PAGE_PATH, pageHtml } from './page.js';
|
|
@@ -39,7 +40,9 @@ function services(ctx) {
|
|
|
39
40
|
export function statusOf(ctx) {
|
|
40
41
|
const s = services(ctx);
|
|
41
42
|
const st = (svc) => { try { return svc?.status?.() ?? (svc ? {} : null); } catch (err) { return { state: 'error', error: err.message }; } };
|
|
42
|
-
|
|
43
|
+
// The model-request gate (src/llm-gate.js) is listed only when a component installed it.
|
|
44
|
+
const llm = (() => { try { const g = gateFor(ctx)?.status(); return g ? { state: g.providers.some((p) => p.coolingUntil) ? 'cooling' : 'on', ...g } : undefined; } catch { return undefined; } })();
|
|
45
|
+
return { phone: st(s.phone), computer: st(s.computer), qq: st(s.qq), dot: s.dot ? { state: 'on' } : null, interlude: s.interlude ? { state: 'on' } : null, compat: s.compat ? { state: 'on', qqBridge: (() => { try { const b = s.compat.bridge(); return b ? { root: b.root, mode: b.mode, bots: b.botUins } : null; } catch { return null; } })() } : null, ...(llm ? { llm } : {}) };
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
const need = (svc, what) => { if (!svc) throw new Error(`${what}组件没开(在 dsh 的插件页打开)`); return svc; };
|
|
@@ -63,6 +66,8 @@ const ACTIONS = {
|
|
|
63
66
|
return `已导入:${r.name}(${r.title},作者 @${r.author},${r.license})`;
|
|
64
67
|
},
|
|
65
68
|
'phone-accept': async ({ phone }, body) => { need(phone, '手机'); if (body?.gb) phone.setStorage(String(body.gb)); phone.accept(); return '已接受许可,开始安装'; },
|
|
69
|
+
'phone-power': async ({ phone }, body) => { await need(phone, '手机').power(body?.on === true); return body?.on === true ? '手机开机中' : '手机已关机(重启 dsh 也保持关着)'; },
|
|
70
|
+
'computer-power': async ({ computer }, body) => { await need(computer, '电脑').power(body?.on === true); return body?.on === true ? '电脑开机中' : '电脑已关机(重启 dsh 也保持关着)'; },
|
|
66
71
|
'phone-restart': async ({ phone }) => { await need(phone, '手机').restart(); return '手机重启中'; },
|
|
67
72
|
'phone-retry': async ({ phone }) => { await need(phone, '手机').restart(); return '重试中'; },
|
|
68
73
|
};
|
|
@@ -77,6 +82,7 @@ export function setupSteps(ctx, stored = readSetup()) {
|
|
|
77
82
|
const dev = (svc, x, okStates) => !svc ? { state: 'skip', detail: '组件没开' }
|
|
78
83
|
: okStates.includes(x?.state) ? { state: 'done', detail: '就绪' }
|
|
79
84
|
: x?.state === 'error' ? { state: 'blocked', detail: x.error ?? '出错' }
|
|
85
|
+
: x?.state === 'off' ? { state: 'skip', detail: '已关机(页面顶部可以开机)' }
|
|
80
86
|
: x?.state === 'needs-license' ? { state: 'todo', detail: '还没装' }
|
|
81
87
|
: { state: 'working', detail: x?.progress?.text ?? x?.stage ?? x?.state ?? '' };
|
|
82
88
|
const canon = (() => { try { return s.interlude?.canon?.(); } catch { return null; } })();
|