@0perator/operator 0.1.351 → 0.1.353
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/dist/acp/agent.js +2 -2
- package/dist/acp/tool-map.js +5 -4
- package/dist/autonomy/delegate.js +54 -1
- package/dist/autonomy/headless.js +2 -0
- package/dist/autonomy/session-factory.js +1 -0
- package/dist/background/index.js +86 -10
- package/dist/background/notices.js +16 -4
- package/dist/cli.js +1073 -177
- package/dist/config/home.js +6 -0
- package/dist/config/memory-sections.js +92 -0
- package/dist/config/persona.js +144 -26
- package/dist/config/settings.js +15 -4
- package/dist/consolidation/scheduler.js +9 -2
- package/dist/consolidation/sleep.js +39 -278
- package/dist/engine/agent.js +444 -76
- package/dist/engine/anthropic-chat.js +13 -2
- package/dist/engine/aurora.js +66 -19
- package/dist/engine/batch-scheduler.js +27 -3
- package/dist/engine/compaction.js +12 -5
- package/dist/engine/continuation.js +14 -12
- package/dist/engine/contract.js +1 -1
- package/dist/engine/decision-points.js +7 -1
- package/dist/engine/front-door.js +59 -0
- package/dist/engine/grandmaster.js +13 -1
- package/dist/engine/loop-guard.js +694 -0
- package/dist/engine/owner-act.js +52 -0
- package/dist/engine/verify-gate.js +52 -0
- package/dist/flywheel/processor.js +3 -1
- package/dist/flywheel/srft.js +8 -4
- package/dist/hooks/index.js +12 -8
- package/dist/mcp/index.js +9 -4
- package/dist/permissions/index.js +32 -11
- package/dist/permissions/modes.js +42 -0
- package/dist/permissions/plan-review.js +100 -0
- package/dist/permissions/policy.js +16 -5
- package/dist/permissions/signature.js +8 -3
- package/dist/remote/safe-commands.js +1 -1
- package/dist/router/read-rates.js +152 -0
- package/dist/selfimprove/backfill.js +174 -0
- package/dist/selfimprove/index.js +146 -57
- package/dist/selfimprove/lessons.js +429 -0
- package/dist/selfimprove/sync.js +58 -0
- package/dist/session.js +362 -33
- package/dist/skills/finder.js +219 -0
- package/dist/toolchain/toolchain.py +528 -112
- package/dist/tools/deferred.js +28 -18
- package/dist/tools/executor.js +7 -3
- package/dist/tools/registry.js +68 -7
- package/dist/tools/result-cap.js +1 -1
- package/dist/ui/ActivitySpinner.js +21 -12
- package/dist/ui/App.js +107 -30
- package/dist/ui/ApprovalPrompt.js +5 -3
- package/dist/ui/ArtifactPicker.js +3 -3
- package/dist/ui/BgPanel.js +105 -5
- package/dist/ui/Composer.js +85 -9
- package/dist/ui/PlanPane.js +72 -8
- package/dist/ui/QuestionPrompt.js +6 -4
- package/dist/ui/SecretPrompt.js +8 -3
- package/dist/ui/SessionPicker.js +2 -2
- package/dist/ui/SkillFinder.js +153 -0
- package/dist/ui/StatusRule.js +5 -2
- package/dist/ui/SummaryCard.js +3 -1
- package/dist/ui/ThinkingSpinner.js +11 -2
- package/dist/ui/ToolBatch.js +11 -2
- package/dist/ui/ToolStep.js +36 -13
- package/dist/ui/Transcript.js +13 -2
- package/dist/ui/actNow.js +61 -0
- package/dist/ui/batchLine.js +165 -0
- package/dist/ui/conversations.js +154 -0
- package/dist/ui/decodeHealth.js +77 -0
- package/dist/ui/expand.js +17 -0
- package/dist/ui/fit.js +40 -0
- package/dist/ui/fitTail.js +14 -0
- package/dist/ui/fold.js +149 -0
- package/dist/ui/format.js +46 -2
- package/dist/ui/liveTools.js +163 -13
- package/dist/ui/modelPicker.js +78 -6
- package/dist/ui/nextStep.js +103 -0
- package/dist/ui/pending.js +57 -0
- package/dist/ui/phase.js +105 -0
- package/dist/ui/planExit.js +0 -5
- package/dist/ui/progressbar.js +4 -26
- package/dist/ui/readForecast.js +44 -0
- package/dist/ui/readProgress.js +119 -0
- package/dist/ui/reportLine.js +62 -0
- package/dist/ui/slashCommands.js +1 -1
- package/dist/ui/theme.js +1 -0
- package/dist/ui/turnFlow.js +72 -0
- package/dist/ui/turnLedger.js +121 -0
- package/dist/ui/turnScope.js +11 -0
- package/dist/util/slash.js +18 -0
- package/package.json +1 -1
package/dist/ui/liveTools.js
CHANGED
|
@@ -1,20 +1,170 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { settledFields } from "./fold.js";
|
|
2
|
+
// Bulky payloads — never dumped (they'd bury the path and blow up the line); shown as a size instead.
|
|
3
|
+
export const BULK_ARGS = ["content", "text", "body", "data", "new_string", "old_string", "diff", "message"];
|
|
4
|
+
const BULK = new Set(BULK_ARGS);
|
|
5
|
+
/** The partial arguments of a call still being written, for DISPLAY only: every key whose string value has closed
|
|
6
|
+
* (path, command, url…), and the running length of each bulk string so far. Nothing is repaired or run — the same
|
|
7
|
+
* string/escape state machine as json-repair's looksTruncated walks the text, and stops at the first unfinished token. */
|
|
8
|
+
export function draftArgs(raw) {
|
|
9
|
+
const args = {};
|
|
10
|
+
const sizes = {};
|
|
11
|
+
const n = raw.length;
|
|
12
|
+
let i = 0;
|
|
13
|
+
const ws = () => { while (i < n && /\s/.test(raw[i]))
|
|
14
|
+
i++; };
|
|
15
|
+
// A JSON string from raw[i] (the opening quote): its decoded text so far and whether it closed.
|
|
16
|
+
const str = () => {
|
|
17
|
+
let out = "";
|
|
18
|
+
i++;
|
|
19
|
+
while (i < n) {
|
|
20
|
+
const ch = raw[i];
|
|
21
|
+
if (ch === '"') {
|
|
22
|
+
i++;
|
|
23
|
+
return { value: out, done: true };
|
|
24
|
+
}
|
|
25
|
+
if (ch !== "\\") {
|
|
26
|
+
out += ch;
|
|
27
|
+
i++;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (i + 1 >= n)
|
|
31
|
+
return { value: out, done: false };
|
|
32
|
+
const e = raw[i + 1];
|
|
33
|
+
if (e === "u") {
|
|
34
|
+
if (i + 6 > n)
|
|
35
|
+
return { value: out, done: false };
|
|
36
|
+
out += String.fromCharCode(parseInt(raw.slice(i + 2, i + 6), 16) || 0xfffd);
|
|
37
|
+
i += 6;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
out += e === "n" ? "\n" : e === "t" ? "\t" : e === "r" ? "\r" : e === "b" ? "\b" : e === "f" ? "\f" : e;
|
|
41
|
+
i += 2;
|
|
42
|
+
}
|
|
43
|
+
return { value: out, done: false };
|
|
44
|
+
};
|
|
45
|
+
// Skip one nested object/array (or scalar); false when it runs off the end of what has streamed.
|
|
46
|
+
const skip = () => {
|
|
47
|
+
let depth = 0;
|
|
48
|
+
while (i < n) {
|
|
49
|
+
const ch = raw[i];
|
|
50
|
+
if (ch === '"') {
|
|
51
|
+
if (!str().done)
|
|
52
|
+
return false;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (ch === "{" || ch === "[")
|
|
56
|
+
depth++;
|
|
57
|
+
else if (ch === "}" || ch === "]") {
|
|
58
|
+
if (depth === 0)
|
|
59
|
+
return true;
|
|
60
|
+
depth--;
|
|
61
|
+
if (depth === 0) {
|
|
62
|
+
i++;
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (ch === "," && depth === 0)
|
|
67
|
+
return true;
|
|
68
|
+
i++;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
};
|
|
72
|
+
ws();
|
|
73
|
+
if (raw[i] !== "{")
|
|
74
|
+
return { args, sizes };
|
|
75
|
+
i++;
|
|
76
|
+
for (;;) {
|
|
77
|
+
ws();
|
|
78
|
+
if (i >= n || raw[i] === "}")
|
|
79
|
+
break;
|
|
80
|
+
if (raw[i] === ",") {
|
|
81
|
+
i++;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (raw[i] !== '"')
|
|
85
|
+
break;
|
|
86
|
+
const key = str();
|
|
87
|
+
if (!key.done)
|
|
88
|
+
break;
|
|
89
|
+
ws();
|
|
90
|
+
if (raw[i] !== ":")
|
|
91
|
+
break;
|
|
92
|
+
i++;
|
|
93
|
+
ws();
|
|
94
|
+
if (i >= n)
|
|
95
|
+
break;
|
|
96
|
+
if (raw[i] === '"') {
|
|
97
|
+
const v = str();
|
|
98
|
+
if (BULK.has(key.value))
|
|
99
|
+
sizes[key.value] = v.value.length;
|
|
100
|
+
else if (v.done)
|
|
101
|
+
args[key.value] = v.value;
|
|
102
|
+
if (!v.done)
|
|
103
|
+
break;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const start = i;
|
|
107
|
+
if (!skip())
|
|
108
|
+
break;
|
|
109
|
+
const token = raw.slice(start, i).trim();
|
|
110
|
+
try {
|
|
111
|
+
const v = JSON.parse(token);
|
|
112
|
+
if (typeof v === "number" || typeof v === "boolean")
|
|
113
|
+
args[key.value] = v;
|
|
114
|
+
}
|
|
115
|
+
catch { /* nested: not shown */ }
|
|
116
|
+
}
|
|
117
|
+
return { args, sizes };
|
|
118
|
+
}
|
|
119
|
+
/** Upsert one draft row: a call the model is still writing. Its startedAt is when the draft began ("drafting 1m 12s"). */
|
|
120
|
+
export function draftLiveTool(rows, d, now = Date.now()) {
|
|
121
|
+
const { args, sizes } = draftArgs(d.args);
|
|
122
|
+
const i = rows.findIndex((r) => r.id === d.id);
|
|
123
|
+
if (i < 0)
|
|
124
|
+
return [...rows, { id: d.id, name: d.name, args, sizes, status: "selected", drafting: true, startedAt: now }];
|
|
125
|
+
const next = rows.slice();
|
|
126
|
+
next[i] = { ...rows[i], name: d.name, args, sizes };
|
|
127
|
+
return next;
|
|
128
|
+
}
|
|
129
|
+
export function bufferDraft(pending, d, now = Date.now()) {
|
|
130
|
+
pending.set(d.id, { id: d.id, name: d.name, args: d.args, at: pending.get(d.id)?.at ?? now });
|
|
131
|
+
}
|
|
132
|
+
/** Fold the buffered drafts into the rows — draftLiveTool once per call, a new row's clock from its first piece — and
|
|
133
|
+
* empty the buffer. */
|
|
134
|
+
export function applyDrafts(rows, pending) {
|
|
135
|
+
let next = rows;
|
|
136
|
+
for (const d of pending.values())
|
|
137
|
+
next = draftLiveTool(next, d, d.at);
|
|
138
|
+
pending.clear();
|
|
139
|
+
return next;
|
|
140
|
+
}
|
|
141
|
+
/** The batch was dispatched (onToolStart): one row per call, in call order, each WAITING its turn — not running.
|
|
142
|
+
* A drafted row keeps its id, so it flips in place; its final, parsed args replace the draft's. */
|
|
143
|
+
export function seedLiveTools(calls, rows = []) {
|
|
144
|
+
return calls.map((c) => ({ ...rows.find((r) => r.id === c.id), id: c.id, name: c.name, args: c.args, status: "selected", drafting: false, sizes: undefined, startedAt: undefined }));
|
|
145
|
+
}
|
|
146
|
+
/** The call was really released to run (onToolCallStart): its timer starts now. */
|
|
147
|
+
export function startLiveTool(rows, id, now = Date.now()) {
|
|
148
|
+
let changed = false;
|
|
149
|
+
const next = rows.map((r) => {
|
|
150
|
+
if (r.id !== id || r.status !== "selected")
|
|
151
|
+
return r;
|
|
152
|
+
changed = true;
|
|
153
|
+
return { ...r, status: "running", drafting: false, startedAt: now };
|
|
154
|
+
});
|
|
155
|
+
return changed ? next : rows;
|
|
156
|
+
}
|
|
157
|
+
/** Flip the ONE row matching `id` to its settled state with its real result, live — called from onToolResult as each
|
|
158
|
+
* call in the batch settles (`refused`: the engine's report that a layer answered for it). A row that never got a start
|
|
159
|
+
* signal (a host that doesn't wire onToolCallStart) settles from waiting; an id with no matching row is a no-op (a
|
|
160
|
+
* stale/duplicate settle should never throw). */
|
|
161
|
+
export function settleLiveTool(rows, id, result, now = Date.now(), refused) {
|
|
12
162
|
let changed = false;
|
|
13
163
|
const next = rows.map((r) => {
|
|
14
|
-
if (r.id !== id || r.status !== "running")
|
|
164
|
+
if (r.id !== id || (r.status !== "running" && r.status !== "selected"))
|
|
15
165
|
return r;
|
|
16
166
|
changed = true;
|
|
17
|
-
return { ...r,
|
|
167
|
+
return { ...r, ...settledFields(result, refused), drafting: false, endedAt: now };
|
|
18
168
|
});
|
|
19
169
|
return changed ? next : rows;
|
|
20
170
|
}
|
package/dist/ui/modelPicker.js
CHANGED
|
@@ -5,6 +5,9 @@ import { BYO_PRESETS, fmtCtx, pickerRow, shortName } from "../router/models.js";
|
|
|
5
5
|
import { markPickerOptions, portalIdFor } from "../router/portal.js";
|
|
6
6
|
import { CONTEXT_PRESETS } from "../config/settings.js";
|
|
7
7
|
import { DISCUSS } from "./QuestionPrompt.js";
|
|
8
|
+
import { fitSegments, seg } from "./fit.js";
|
|
9
|
+
import { cellWidth, truncateToWidth } from "./StatusRule.js";
|
|
10
|
+
import { approxTokens, fmtWait, fmtWhen, readSeconds } from "../router/read-rates.js";
|
|
8
11
|
/** The last /model row: an action, never a ModelProfile — so the lists fed from the registry (the ACP dropdown, a
|
|
9
12
|
* follower's model list) can never offer it. */
|
|
10
13
|
export const CONNECT_ROW = "+ Connect a provider key (Anthropic, Google, Nous, OpenAI, …)";
|
|
@@ -18,14 +21,44 @@ const group = (m) => (m.kind === "orchestrated" ? 3 : m.tier === "free" ? 2 : m.
|
|
|
18
21
|
export function pickerOrder(models) {
|
|
19
22
|
return models.map((m, i) => ({ m, i })).sort((a, b) => group(a.m) - group(b.m) || a.i - b.i).map(({ m }) => m);
|
|
20
23
|
}
|
|
24
|
+
/** A row's cost tail as fit parts: the source of the rate gives way first, then the time; the size always stays. Over
|
|
25
|
+
* the model's window it says so instead. No measured rate → the size and "read speed not measured yet", never a guess.
|
|
26
|
+
* "up to": the model may still hold part of this prefix from an earlier turn. */
|
|
27
|
+
export function costParts(c, now = Date.now()) {
|
|
28
|
+
if (!c)
|
|
29
|
+
return [];
|
|
30
|
+
if (c.window && c.tokens > c.window)
|
|
31
|
+
return [seg(` · this conversation (${approxTokens(c.tokens)}) is over its window`)];
|
|
32
|
+
const secs = readSeconds(c.tokens, c.rate);
|
|
33
|
+
if (secs === undefined)
|
|
34
|
+
return [seg(` · re-reads up to ${approxTokens(c.tokens)}`), seg(" (read speed not measured yet)", 2)];
|
|
35
|
+
return [seg(` · re-reads up to ${approxTokens(c.tokens)}`), seg(` ≈ ${fmtWait(secs)}`, 1), seg(` (${Math.round(c.rate.tokPerSec)} tok/s, ${fmtWhen(c.rate.at, now)})`, 2)];
|
|
36
|
+
}
|
|
37
|
+
// The QuestionPrompt box spends ~16 cells around a row (border, padding, "❯ [12] ", a portal marker): rows are fitted to
|
|
38
|
+
// what is left so a cost tail never wraps a row (click anchoring counts one line per row).
|
|
39
|
+
const ROW_CHROME = 16;
|
|
21
40
|
/** The /model rows in picker order — pickerRow for each (the active single model shows its served window), " · cached"
|
|
22
|
-
* on free rows served from the disk cache — closed by the connect
|
|
41
|
+
* on free rows served from the disk cache, and with `cost` the re-read each switch would cost — closed by the connect
|
|
42
|
+
* row. With `cols`, a row with a cost is fitted to one line. */
|
|
23
43
|
export function modelPickerView(models, o) {
|
|
24
44
|
const ordered = pickerOrder(models);
|
|
25
45
|
const rows = ordered.map((m) => {
|
|
26
46
|
const active = m.id === o.active;
|
|
27
47
|
const row = pickerRow(m, { servedCtx: active && m.kind === "single" ? o.servedCtx : undefined });
|
|
28
|
-
|
|
48
|
+
const cost = active ? [] : costParts(o.cost?.(m), o.now);
|
|
49
|
+
const tail = `${o.staleFree && m.tier === "free" ? " · cached" : ""}${active ? " (active)" : ""}`;
|
|
50
|
+
if (!cost.length)
|
|
51
|
+
return `${row}${tail}`;
|
|
52
|
+
const segs = [seg(row), ...cost, ...(tail ? [seg(tail)] : [])];
|
|
53
|
+
if (!o.cols)
|
|
54
|
+
return segs.map((x) => x.forms[0]).join("");
|
|
55
|
+
const width = Math.max(20, o.cols - ROW_CHROME);
|
|
56
|
+
const fitted = fitSegments(segs, width, { sep: "" });
|
|
57
|
+
if (cellWidth(segs.map((x) => x.forms[0]).join("")) <= width - 1 || !fitted.endsWith("…"))
|
|
58
|
+
return fitted;
|
|
59
|
+
// Still too wide once the rate's parts gave way: the name gives way, the size stays ("re-reads up to ~61K").
|
|
60
|
+
const keep = `${cost[0].forms[0]}${tail}`;
|
|
61
|
+
return `${truncateToWidth(row, Math.max(8, width - 1 - cellWidth(keep)))}${keep}`;
|
|
29
62
|
});
|
|
30
63
|
return {
|
|
31
64
|
rows: [...rows, CONNECT_ROW],
|
|
@@ -88,11 +121,50 @@ export function pickerAnswer(entries, answer, index) {
|
|
|
88
121
|
const typed = answer.trim();
|
|
89
122
|
return !typed || answer === DISCUSS ? null : { typed };
|
|
90
123
|
}
|
|
91
|
-
/** The /model line after a pick: `model → <id> · ctx N% · turns N`; a free row repeats its caveat instead.
|
|
92
|
-
|
|
124
|
+
/** The /model line after a pick: `model → <id> · ctx N% · turns N`; a free row repeats its caveat instead. With the
|
|
125
|
+
* switch's measured cost it adds what the next message will re-read (TUI A3.6). */
|
|
126
|
+
export function modelLine(id, chosen, ctxPct, turns, cost, now = Date.now()) {
|
|
127
|
+
const reread = cost && cost.tokens > 0 && !(cost.window && cost.tokens > cost.window)
|
|
128
|
+
? ` · re-reads up to ${approxTokens(cost.tokens)} on your next message${(() => { const secs = readSeconds(cost.tokens, cost.rate); return secs === undefined ? "" : ` (≈ ${fmtWait(secs)} at ${Math.round(cost.rate.tokPerSec)} tok/s, measured ${fmtWhen(cost.rate.at, now)})`; })()}`
|
|
129
|
+
: cost?.window && cost.tokens > cost.window ? ` · this conversation (${approxTokens(cost.tokens)}) is over its window — the first turn compacts it` : "";
|
|
93
130
|
if (chosen?.tier === "free")
|
|
94
|
-
return `model → ${id} · ${chosen.desc ?? "free tier"}`;
|
|
95
|
-
return `model → ${id} · ctx ${ctxPct}% · turns ${turns}`;
|
|
131
|
+
return `model → ${id} · ${chosen.desc ?? "free tier"}${reread}`;
|
|
132
|
+
return `model → ${id} · ctx ${ctxPct}% · turns ${turns}${reread}`;
|
|
133
|
+
}
|
|
134
|
+
/** Whether a pick earns the re-read confirm step: 16K tokens or more to re-read, unless a measured read says it takes
|
|
135
|
+
* under 30 s — or a conversation that is over the model's window. */
|
|
136
|
+
export function wantsRereadConfirm(c) {
|
|
137
|
+
if (!c)
|
|
138
|
+
return false;
|
|
139
|
+
if (c.window && c.tokens > c.window)
|
|
140
|
+
return true;
|
|
141
|
+
if (c.tokens < 16_000)
|
|
142
|
+
return false;
|
|
143
|
+
const secs = readSeconds(c.tokens, c.rate);
|
|
144
|
+
return secs === undefined || secs >= 30;
|
|
145
|
+
}
|
|
146
|
+
/** The confirm step: switch now (the next turn starts with that read), compact on the current, cache-warm model first
|
|
147
|
+
* (priced as its summary cap at its measured decode rate, then the bounded re-read at the target's rate), or stay.
|
|
148
|
+
* Every time shown comes from a measured rate; an unmeasured one shows sizes only. */
|
|
149
|
+
export function rereadConfirmView(o) {
|
|
150
|
+
const { target, current, cost } = o;
|
|
151
|
+
const over = !!(cost.window && cost.tokens > cost.window);
|
|
152
|
+
const secs = readSeconds(cost.tokens, cost.rate);
|
|
153
|
+
const measured = secs === undefined ? "" : ` ≈ ${fmtWait(secs)} (${Math.round(cost.rate.tokPerSec)} tok/s, measured ${fmtWhen(cost.rate.at, o.now)})`;
|
|
154
|
+
const question = over
|
|
155
|
+
? `${target} can't hold this conversation (${approxTokens(cost.tokens)} > its ${approxTokens(cost.window).slice(1)} window): its first turn compacts it`
|
|
156
|
+
: `${target} may have none of this cached: it re-reads up to ${approxTokens(cost.tokens)} tok${measured}`;
|
|
157
|
+
const rows = [over ? "Switch now · the first turn compacts the conversation" : "Switch now · the next turn starts with that read"];
|
|
158
|
+
const choices = ["switch"];
|
|
159
|
+
if (o.compact) {
|
|
160
|
+
const sum = readSeconds(o.compact.summaryMax, o.compact.decode);
|
|
161
|
+
const after = readSeconds(o.compact.afterMax, cost.rate);
|
|
162
|
+
rows.push(`Compact on ${current} first (cache-warm${sum === undefined ? "" : `, ≈${fmtWait(sum)}`}), then switch · re-read ≤${approxTokens(o.compact.afterMax).slice(1)}${after === undefined ? "" : ` ≈ ${fmtWait(after)}`}`);
|
|
163
|
+
choices.push("compact");
|
|
164
|
+
}
|
|
165
|
+
rows.push(`Stay on ${current}`);
|
|
166
|
+
choices.push("stay");
|
|
167
|
+
return { question, rows, choices };
|
|
96
168
|
}
|
|
97
169
|
/** After a key is stored: the rows it unlocked, by name — or why none show yet. */
|
|
98
170
|
export function keyStoredLine(account, rows, preset, free = false) {
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { fitSegments, seg } from "./fit.js";
|
|
2
|
+
import { approxTokens } from "../router/read-rates.js";
|
|
3
|
+
/** The bound /compact can promise, as the strip shows it: "61K → ≤18K". */
|
|
4
|
+
export function compactCost(est) {
|
|
5
|
+
if (!est || est.afterMax >= est.before)
|
|
6
|
+
return undefined;
|
|
7
|
+
return `${approxTokens(est.before).slice(1)} → ≤${approxTokens(est.afterMax).slice(1)}`;
|
|
8
|
+
}
|
|
9
|
+
const REASONING_TAIL = 2400; // chars of the kept reasoning handed back with "continue from that reasoning"
|
|
10
|
+
/** The steps after an Esc. With reasoning on screen, "continue from that reasoning" hands its tail back to the model —
|
|
11
|
+
* it never reached the model's context (the interrupted round is dropped). "think off" changes enable_thinking for that
|
|
12
|
+
* one turn only, so the system prompt — and the cached prefix — stay as they are. */
|
|
13
|
+
export function interruptSteps(o) {
|
|
14
|
+
const r = (o.reasoning ?? "").trim();
|
|
15
|
+
const tail = r.length > REASONING_TAIL ? `…${r.slice(-REASONING_TAIL)}` : r;
|
|
16
|
+
const cont = r
|
|
17
|
+
? { label: "continue from that reasoning", short: "continue", action: { kind: "send", display: "continue from that reasoning",
|
|
18
|
+
text: `Continue from where you were when I stopped you. Your reasoning up to that point never reached you; here is how it ended:\n\n${tail}` } }
|
|
19
|
+
: { label: "continue", short: "continue", action: { kind: "send", display: "continue", text: "Continue from where you were when I stopped you." } };
|
|
20
|
+
const steps = [
|
|
21
|
+
cont,
|
|
22
|
+
{ label: "continue, think off", short: "no-think", action: { kind: "send", display: "continue, think off", text: "Continue from where you were when I stopped you.", thinkOff: true } },
|
|
23
|
+
];
|
|
24
|
+
const cost = compactCost(o.compact);
|
|
25
|
+
if (cost)
|
|
26
|
+
steps.push({ label: "compact, then continue", short: "compact", cost, action: { kind: "compact-send", display: "compact, then continue", text: "Continue from where you were when I stopped you." } });
|
|
27
|
+
steps.push({ label: "model…", short: "model", action: { kind: "model" } });
|
|
28
|
+
return steps;
|
|
29
|
+
}
|
|
30
|
+
/** The steps after an engine stop: the stop's own options, sent verbatim, so the model's behavior does not change —
|
|
31
|
+
* plus "show what it had" when a cut reply was kept on screen, and "think off" where reasoning is the likely cause.
|
|
32
|
+
* Null when there is nothing to offer: no strip, never an empty one that eats the next Esc (review F13). */
|
|
33
|
+
export function engineStopSteps(kind, o = {}) {
|
|
34
|
+
const steps = stopSteps(kind, o);
|
|
35
|
+
return steps.length ? steps : null;
|
|
36
|
+
}
|
|
37
|
+
function stopSteps(kind, o) {
|
|
38
|
+
const send = (label, short, text, thinkOff = false) => ({ label, short, action: { kind: "send", display: label, text, thinkOff: thinkOff || undefined } });
|
|
39
|
+
const cost = compactCost(o.compact);
|
|
40
|
+
const compactStep = (label, text) => (cost ? [{ label, short: "compact", cost, action: { kind: "compact-send", display: label, text } }] : []);
|
|
41
|
+
switch (kind) {
|
|
42
|
+
case "repetition": return [
|
|
43
|
+
send("another pass, different approach", "retry", "Take another pass with a different approach."),
|
|
44
|
+
...(o.partialChars ? [{ label: "show what it had", short: "show", cost: `${approxTokens(o.partialChars).slice(1)} chars, cut`, action: { kind: "show" } }] : []),
|
|
45
|
+
send("another pass, think off", "no-think", "Take another pass with a different approach.", true),
|
|
46
|
+
];
|
|
47
|
+
case "reasoning_budget": return [
|
|
48
|
+
send("go ahead with the next step", "go", "Go ahead with the next concrete step."),
|
|
49
|
+
send("go ahead, think off", "no-think", "Go ahead with the next concrete step.", true),
|
|
50
|
+
];
|
|
51
|
+
case "paused": return [send("keep going", "go", "Keep going from here."), ...compactStep("compact, then keep going", "Keep going from here.")];
|
|
52
|
+
case "window": return compactStep("compact, then carry on", "Carry on from here.");
|
|
53
|
+
case "rounds": return [send("continue", "continue", "Continue from here."), send("continue, think off", "no-think", "Continue from here.", true)];
|
|
54
|
+
case "empty": return [send("try again", "retry", "Try again."), send("try again, think off", "no-think", "Try again.", true)];
|
|
55
|
+
case "length": return [send("continue", "continue", "Continue exactly where you stopped.")];
|
|
56
|
+
case "yield": return [
|
|
57
|
+
send("keep going meanwhile", "go", "Keep going on the next step meanwhile."),
|
|
58
|
+
send("take a step over yourself", "take over", "Take the delegated step over yourself."),
|
|
59
|
+
];
|
|
60
|
+
case "owner": return [
|
|
61
|
+
send("answer from what you have", "answer", "Answer now from what you have — no more tool calls.", true),
|
|
62
|
+
send("keep working on it", "go", "Keep working on it."),
|
|
63
|
+
];
|
|
64
|
+
case "stopped": return [send("try a different way", "retry", "Try a different way."), send("try a different way, think off", "no-think", "Try a different way.", true)];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** The strip, one line fitted to cols−1: " 1 continue 2 continue, think off 3 compact, then continue (61K → ≤18K)
|
|
68
|
+
* 4 model… or type". The cost parentheses go first, then the labels shorten; under 50 columns it reads
|
|
69
|
+
* "1·2·3·4 or type". */
|
|
70
|
+
export function nextStepLine(steps, cols) {
|
|
71
|
+
if (!steps.length)
|
|
72
|
+
return "";
|
|
73
|
+
if (cols < 50)
|
|
74
|
+
return fitSegments([seg(`${steps.map((_, i) => i + 1).join("·")} or type`)], cols, { lead: " " });
|
|
75
|
+
const segs = [];
|
|
76
|
+
steps.forEach((s, i) => {
|
|
77
|
+
segs.push(seg(`${i + 1} `), seg([s.label, s.short], 1, true));
|
|
78
|
+
if (s.cost)
|
|
79
|
+
segs.push(seg(` (${s.cost})`, 2));
|
|
80
|
+
segs.push(seg(" "));
|
|
81
|
+
});
|
|
82
|
+
segs.push(seg("or type"));
|
|
83
|
+
return fitSegments(segs, cols, { lead: " ", sep: "" });
|
|
84
|
+
}
|
|
85
|
+
/** The step a key picks: a digit within range, on an EMPTY draft (any other key types normally and hides the strip). */
|
|
86
|
+
export function pickStep(input, steps, draftEmpty) {
|
|
87
|
+
if (!draftEmpty || !/^[1-9]$/.test(input))
|
|
88
|
+
return undefined;
|
|
89
|
+
return steps[Number(input) - 1];
|
|
90
|
+
}
|
|
91
|
+
/** The partial on screen at an Esc, settled as an entry (so "output above kept" is true for what the owner was
|
|
92
|
+
* watching), and the line after it saying it is screen-only. Null when nothing had streamed. */
|
|
93
|
+
export function settledPartial(text, reasoning) {
|
|
94
|
+
const t = text.trim();
|
|
95
|
+
const r = reasoning.trim();
|
|
96
|
+
if (!t && !r)
|
|
97
|
+
return null;
|
|
98
|
+
const chars = t.length + r.length;
|
|
99
|
+
return {
|
|
100
|
+
entry: { content: t, reasoning: r || undefined },
|
|
101
|
+
note: ` ${approxTokens(chars).slice(1)} chars of that reply kept above, on screen only — never sent to the model`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// What the owner has typed while a turn runs (TUI A3.1 / A3.2). A steer goes in before the next model call; an after-turn
|
|
2
|
+
// item waits for the turn to end; a staged command runs alone when the turn ends, never joined into a text turn (a
|
|
3
|
+
// "/model cortana" joined with other queued text used to reach the MODEL as plain text). Pure, so the order rules and the
|
|
4
|
+
// hint widths are unit-tested without a TTY.
|
|
5
|
+
import { seg } from "./fit.js";
|
|
6
|
+
import { fitWithTail } from "./fitTail.js";
|
|
7
|
+
const PREVIEW_MIN = 24; // cells a preview keeps before the key hints give way (fitTail.ts)
|
|
8
|
+
const preview = (texts) => texts.join("\n").replace(/\s*\n\s*/g, " / ");
|
|
9
|
+
/** ↑ / ⌫ act on the most recent pending item, whichever kind it is. */
|
|
10
|
+
export function popLatest(items) {
|
|
11
|
+
if (!items.length)
|
|
12
|
+
return { rest: [] };
|
|
13
|
+
return { item: items[items.length - 1], rest: items.slice(0, -1) };
|
|
14
|
+
}
|
|
15
|
+
/** Every steer, oldest first, out of the list — the engine folds them in as one owner message at the next round. */
|
|
16
|
+
export function takeSteers(items) {
|
|
17
|
+
return { steers: items.filter((i) => i.kind === "steer").map((i) => i.text), rest: items.filter((i) => i.kind !== "steer") };
|
|
18
|
+
}
|
|
19
|
+
/** What runs when the turn ends: staged commands one by one, then one text turn — steers the turn never reached first
|
|
20
|
+
* (nothing typed is lost), then the after-turn messages in the order they were typed. */
|
|
21
|
+
export function drainPlan(items) {
|
|
22
|
+
const commands = items.filter((i) => i.kind === "command").map((i) => i.text);
|
|
23
|
+
const steers = items.filter((i) => i.kind === "steer").map((i) => i.text);
|
|
24
|
+
const after = items.filter((i) => i.kind === "after").map((i) => i.text);
|
|
25
|
+
return { commands, text: [...steers, ...after].join("\n") };
|
|
26
|
+
}
|
|
27
|
+
/** The pending hint above the composer: one line for steers, one for after-turn items, each fitted to cols−1. The ↑/⌫
|
|
28
|
+
* keys ride on the line that holds the most recent item. `phase` is what the turn is doing now ("reasoning",
|
|
29
|
+
* "running bash"). Drop order as the window narrows: the phase, then the keys, then the long head. */
|
|
30
|
+
export function pendingLines(items, cols, phase) {
|
|
31
|
+
const steers = items.filter((i) => i.kind === "steer").map((i) => i.text);
|
|
32
|
+
const after = items.filter((i) => i.kind !== "steer").map((i) => i.text);
|
|
33
|
+
const latest = items[items.length - 1]?.kind;
|
|
34
|
+
const keys = (n) => seg(n > 1 ? " · ↑ edit last · ⌫ cancel last" : " · ↑ edit · ⌫ cancel", 2);
|
|
35
|
+
const out = [];
|
|
36
|
+
if (steers.length) {
|
|
37
|
+
const segs = [
|
|
38
|
+
seg([steers.length > 1 ? `↳ ${steers.length} steers · go in before the next model call` : "↳ steer · goes in before the next model call", "↳ steer"], 1, true),
|
|
39
|
+
...(phase ? [seg(` (now: ${phase})`, 3)] : []),
|
|
40
|
+
...(latest === "steer" ? [keys(steers.length)] : []),
|
|
41
|
+
];
|
|
42
|
+
out.push(fitWithTail(segs, preview(steers), cols, { sep: "", join: ": ", tailMin: PREVIEW_MIN }));
|
|
43
|
+
}
|
|
44
|
+
if (after.length) {
|
|
45
|
+
const segs = [
|
|
46
|
+
seg([after.length > 1 ? `⏎ after this turn (${after.length})` : "⏎ after this turn", "⏎ after turn"], 1, true),
|
|
47
|
+
...(latest && latest !== "steer" ? [keys(after.length)] : []),
|
|
48
|
+
];
|
|
49
|
+
out.push(fitWithTail(segs, preview(after), cols, { sep: "", join: ": ", tailMin: PREVIEW_MIN }));
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/** The keys a running turn takes, for the phase line's tail (ui/phase.ts puts "esc to interrupt" after them): Enter
|
|
54
|
+
* steers, Tab queues for after the turn. "tab after turn" gives way first on a narrow window, then "⏎ steer". */
|
|
55
|
+
export function turnKeySegs() {
|
|
56
|
+
return [seg("⏎ steer", 5), seg("tab after turn", 6)];
|
|
57
|
+
}
|
package/dist/ui/phase.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// The honest phase line (TUI plan #2): the dim line under the spinner names only what the engine measured. It used to
|
|
2
|
+
// fall back to "reasoning" whenever no prefill label was set, so a request parked behind a sub-agent, a server still
|
|
3
|
+
// loading the model and a mid-turn compaction all read as "reasoning" under a rotating "Untangling…". Each phase here is
|
|
4
|
+
// set by a real signal (cli.tsx): waiting at the turn start and after every tool round, loading from the on-demand
|
|
5
|
+
// Aurora notice, reading from prompt_progress, thinking from a reasoning chunk, writing from a content chunk, tools from
|
|
6
|
+
// onToolStart, recovering from onSelfHeal, compacting from the compaction start. Always one row: the cause drops first.
|
|
7
|
+
import { fitSegments, seg } from "./fit.js";
|
|
8
|
+
import { fmtElapsed, fmtTok } from "./format.js";
|
|
9
|
+
import { readLine } from "./readProgress.js";
|
|
10
|
+
import { decodeSegs } from "./decodeHealth.js";
|
|
11
|
+
const VERB = {
|
|
12
|
+
waiting: "Waiting", queued: "Waiting", sent: "Waiting", loading: "Loading", reading: "Reading", thinking: "Thinking", writing: "Writing",
|
|
13
|
+
drafting: "Drafting", tools: "Running", recovering: "Recovering", compacting: "Compacting",
|
|
14
|
+
};
|
|
15
|
+
const WORD = {
|
|
16
|
+
waiting: "waiting for the model", queued: "waiting for a slot", sent: "request sent", loading: "loading the model", reading: "reading",
|
|
17
|
+
thinking: "thinking", writing: "writing", drafting: "drafting", tools: "running tools", recovering: "recovering", compacting: "compacting",
|
|
18
|
+
};
|
|
19
|
+
/** The phase in a few words, for the main lane (BgPanel lanes). */
|
|
20
|
+
export function phaseWord(phase) {
|
|
21
|
+
return WORD[phase];
|
|
22
|
+
}
|
|
23
|
+
/** The spinner verb for a measured phase; undefined when nothing is known (the spinner then rotates its pool). A read
|
|
24
|
+
* the server has finished is waiting for its first token, not reading. */
|
|
25
|
+
export function phaseVerb(phase, read) {
|
|
26
|
+
if (phase === "reading" && read?.complete)
|
|
27
|
+
return "Waiting";
|
|
28
|
+
return phase ? VERB[phase] : undefined;
|
|
29
|
+
}
|
|
30
|
+
const ESC = seg(["esc to interrupt", "esc"], 1, true);
|
|
31
|
+
/** A gate owner label as the owner reads it: "main" → the main turn, a sub-agent's name → "Iris (sub-agent)". */
|
|
32
|
+
export function holderLabel(owner) {
|
|
33
|
+
if (!owner)
|
|
34
|
+
return undefined;
|
|
35
|
+
if (owner === "main")
|
|
36
|
+
return "the main turn";
|
|
37
|
+
if (owner === "compaction")
|
|
38
|
+
return "a compaction";
|
|
39
|
+
if (owner === "sub-agent")
|
|
40
|
+
return "a sub-agent";
|
|
41
|
+
return `${owner} (sub-agent)`;
|
|
42
|
+
}
|
|
43
|
+
function tokSeg(tokens) {
|
|
44
|
+
return tokens ? [seg([`${fmtTok(tokens)} tok this turn`, `${fmtTok(tokens)} tok`], 2, true)] : [];
|
|
45
|
+
}
|
|
46
|
+
/** The phase line: `meter` (reading only, ≥100 cols) is drawn in its own color before `text`. */
|
|
47
|
+
export function phaseLine(v, cols, frame = 0) {
|
|
48
|
+
const tail = [...(v.hint ? [seg(v.hint, 2)] : []), ...(v.keys ?? []), ESC];
|
|
49
|
+
const fit = (segs) => ({ text: fitSegments([...segs, ...tail], cols, { lead: " " }).slice(2) });
|
|
50
|
+
const model = v.model ?? "the model";
|
|
51
|
+
switch (v.phase) {
|
|
52
|
+
case "reading":
|
|
53
|
+
if (v.read)
|
|
54
|
+
return readLine(v.read, cols, { model: v.model, frame, tail });
|
|
55
|
+
return fit([seg("reading the prompt")]);
|
|
56
|
+
case "queued": {
|
|
57
|
+
const who = holderLabel(v.queue?.holder);
|
|
58
|
+
const line = fitSegments([
|
|
59
|
+
seg(`waiting for ${model}`),
|
|
60
|
+
...(who ? [seg([`${who} holds its slot`, `${who.replace(/ \(sub-agent\)$/, "")} holds it`], 4)] : []),
|
|
61
|
+
seg(v.queue?.ahead ? `${v.queue.ahead} ahead` : "next in line", 3),
|
|
62
|
+
...tail,
|
|
63
|
+
], cols, { lead: " ◌ " });
|
|
64
|
+
return { text: line.slice(2) };
|
|
65
|
+
}
|
|
66
|
+
case "sent":
|
|
67
|
+
return fit([seg(`request sent to ${model}`), v.expect ? seg(v.expect, 3, true) : seg("no reply yet", 4)]);
|
|
68
|
+
case "loading":
|
|
69
|
+
return fit([seg([`loading ${model} (it was unloaded)`, `loading ${model}`], 3, true), seg("your turn starts the moment it is up", 4)]);
|
|
70
|
+
case "thinking":
|
|
71
|
+
return fit([seg("thinking"), ...tokSeg(v.tokens), ...(v.decode ? decodeSegs(v.decode) : [])]);
|
|
72
|
+
case "writing":
|
|
73
|
+
return fit([seg("writing"), ...tokSeg(v.tokens), ...(v.decode ? decodeSegs(v.decode) : [])]);
|
|
74
|
+
case "drafting":
|
|
75
|
+
return fit([seg("drafting"), ...tokSeg(v.tokens), ...(v.decode ? decodeSegs(v.decode) : [])]);
|
|
76
|
+
case "tools":
|
|
77
|
+
return fit([seg("running tools")]);
|
|
78
|
+
case "recovering":
|
|
79
|
+
return fit([seg(v.label || "recovering")]);
|
|
80
|
+
case "compacting": {
|
|
81
|
+
const c = v.compaction;
|
|
82
|
+
if (!c)
|
|
83
|
+
return fit([seg(v.label || "compacting context")]);
|
|
84
|
+
const r = c.read;
|
|
85
|
+
// The span is cached, so the summarizer reads a few thousand new tokens and then writes for most of the
|
|
86
|
+
// compaction: once its read is done, or its first delta lands, the line says so (review F2).
|
|
87
|
+
const wrote = c.wrote ? `${c.approx ? "≈" : ""}${fmtTok(c.wrote)} tok` : undefined;
|
|
88
|
+
const phase = wrote ? [seg([`writing the summary · ${wrote}`, `writing · ${wrote}`], 3, true)]
|
|
89
|
+
: r && r.done >= r.fresh ? [seg(`summarizer read ${fmtTok(r.fresh)} new`, 4), seg(["writing the summary", "writing"], 3, true)]
|
|
90
|
+
: r ? [seg([r.cache > 0 ? `summarizer reading ${fmtTok(r.done)} new (${fmtTok(r.cache)} reused)` : `summarizer reading ${fmtTok(r.done)} of ${fmtTok(r.fresh)} new`, `summarizer ${Math.round(r.fraction * 100)}%`], 3)]
|
|
91
|
+
: [];
|
|
92
|
+
return fit([seg(`compacting ${fmtTok(c.before)} tokens`), ...phase]);
|
|
93
|
+
}
|
|
94
|
+
default: // waiting
|
|
95
|
+
return fit([seg("waiting for the model"), v.expect ? seg(v.expect, 3, true) : seg("nothing back yet", 4)]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** The receipt when a server held a request ≥5 s before it began reading: busy with another client, or loading. */
|
|
99
|
+
export function holdReceipt(model, heldMs, cols) {
|
|
100
|
+
return fitSegments([seg(`${model} began reading ${fmtElapsed(heldMs)} after the request was sent`), seg("(the server was busy, or loading the model)", 2)], cols, { lead: " ▸ ", sep: " " });
|
|
101
|
+
}
|
|
102
|
+
/** The receipt when a compaction finished and freed something: before → after, and how long it took. */
|
|
103
|
+
export function compactReceipt(before, after, ms, cols, tail) {
|
|
104
|
+
return fitSegments([seg(`compacted ${fmtTok(before)} → ${fmtTok(after)} in ${fmtElapsed(ms)}`), ...(tail ? [seg(tail, 2)] : [])], cols, { lead: " ▸ " });
|
|
105
|
+
}
|
package/dist/ui/planExit.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
// Plan-mode "Approve & run": exiting plan mode after the model has actually proposed a plan
|
|
2
|
-
// shouldn't silently flip modes and leave the owner to shift+tab out AND re-type "go" — it should
|
|
3
|
-
// offer the choice inline. These are pure decision functions (no React, no Session), mirroring
|
|
4
|
-
// questionKey in QuestionPrompt.tsx, so the whole gate + answer-mapping is testable without a TTY.
|
|
5
|
-
// cli.tsx's applyMode is the one place that wires them to the real mode switch + turn submission.
|
|
6
1
|
export const PLAN_EXIT_OPTIONS = ["Approve & run", "Keep planning", "Cancel"];
|
|
7
2
|
export const APPROVED_PLAN_MESSAGE = "Proceed with the approved plan.";
|
|
8
3
|
/** Should exiting plan mode surface the picker instead of switching modes silently? Only when the
|
package/dist/ui/progressbar.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Pure, testable progress-bar primitives shared by the media-gen
|
|
2
|
-
//
|
|
1
|
+
// Pure, testable progress-bar primitives shared by the media-gen sweep (ToolStep.tsx) and the compaction
|
|
2
|
+
// bar (ActivitySpinner.tsx). Font-safe per toolicons.ts's rule: only ▰ (U+25B0 filled) and
|
|
3
3
|
// ▱ (U+25B1 empty), both Geometric Shapes — no new Unicode blocks introduced.
|
|
4
4
|
const FILLED = "▰";
|
|
5
5
|
const EMPTY = "▱";
|
|
@@ -11,8 +11,8 @@ export function renderBar(fraction, width = 10) {
|
|
|
11
11
|
return FILLED.repeat(filled) + EMPTY.repeat(width - filled);
|
|
12
12
|
}
|
|
13
13
|
/** An indeterminate "sweep" bar: a `litWidth`-cell bright window that starts at `frame % width` and wraps
|
|
14
|
-
* around the track — for a process with no knowable percentage (
|
|
15
|
-
* media
|
|
14
|
+
* around the track — for a process with no knowable percentage (a compaction that reports no read progress,
|
|
15
|
+
* a media render). It never fills. `frame` is the shared ticker's frame index (see tick.ts). */
|
|
16
16
|
export function renderSweepBar(frame, width = 10, litWidth = 3) {
|
|
17
17
|
const start = ((frame % width) + width) % width; // frame is always >=0 from useTick, but stay safe
|
|
18
18
|
let out = "";
|
|
@@ -22,25 +22,3 @@ export function renderSweepBar(frame, width = 10, litWidth = 3) {
|
|
|
22
22
|
}
|
|
23
23
|
return out;
|
|
24
24
|
}
|
|
25
|
-
// ETA heuristics for media-gen tools (image_generate / video_generate): the flux/video brokers report no
|
|
26
|
-
// percentage, so progress is derived from elapsed-time-vs-estimate instead. video scales with frame count —
|
|
27
|
-
// LTX on the flux/video workers runs ~210s at the 97-frame default, roughly linear below that.
|
|
28
|
-
const IMAGE_ETA_MS = 40_000;
|
|
29
|
-
const VIDEO_BASE_FRAMES = 97;
|
|
30
|
-
const VIDEO_BASE_ETA_MS = 210_000;
|
|
31
|
-
const VIDEO_MIN_ETA_MS = 60_000;
|
|
32
|
-
/** Estimated total duration for a media-gen tool call, from its own args when available. */
|
|
33
|
-
export function mediaEtaMs(toolName, args) {
|
|
34
|
-
if (/video_generate/i.test(toolName)) {
|
|
35
|
-
const frames = typeof args?.num_frames === "number" ? args.num_frames : VIDEO_BASE_FRAMES;
|
|
36
|
-
return Math.max(VIDEO_MIN_ETA_MS, (frames / VIDEO_BASE_FRAMES) * VIDEO_BASE_ETA_MS);
|
|
37
|
-
}
|
|
38
|
-
return IMAGE_ETA_MS; // image_generate (and any other media-kind tool) — flat-rate estimate
|
|
39
|
-
}
|
|
40
|
-
/** elapsed/ETA as a progress fraction, capped at 95% — a job can legitimately run past its estimate, and
|
|
41
|
-
* reading 100% before the real result arrives would make the bar lie while the user keeps waiting. */
|
|
42
|
-
export function mediaProgressFraction(elapsedMs, etaMs) {
|
|
43
|
-
if (etaMs <= 0)
|
|
44
|
-
return 0.95;
|
|
45
|
-
return Math.min(0.95, elapsedMs / etaMs);
|
|
46
|
-
}
|