aegisone 1.0.5 → 1.0.8
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 +2 -2
- package/bin/aegis.js +28 -3
- package/package.json +1 -1
- package/scripts/predist.mjs +230 -0
- package/src/permissions.js +134 -7
- package/src/release.js +14 -5
- package/vendor/cli/README.md +42 -3
- package/vendor/cli/bin/aegiscode.js +15 -3
- package/vendor/cli/package.json +1 -1
- package/vendor/cli/src/app.js +167 -37
- package/vendor/cli/src/chatflow.js +285 -39
- package/vendor/cli/src/commands.js +251 -30
- package/vendor/cli/src/config.js +41 -11
- package/vendor/cli/src/engine.js +33 -4
- package/vendor/cli/src/entitlement.js +30 -1
- package/vendor/cli/src/format.js +175 -3
- package/vendor/cli/src/overlays.js +13 -9
- package/vendor/cli/src/panels.js +19 -6
- package/vendor/cli/src/render.js +49 -14
- package/vendor/cli/src/screen.js +12 -1
- package/vendor/cli/src/screens.js +118 -25
- package/vendor/cli/src/todos.js +7 -4
- package/vendor/cli/src/tokens.js +31 -1
- package/vendor/cli/vendor/client/aegis.js +22 -0
- package/vendor/cli/vendor/client/byok-catalog.js +43 -8
- package/vendor/cli/vendor/client/user-models.js +378 -0
- package/vendor/cli/vendor/desktop/lib/local/autonomous.js +81 -0
- package/vendor/cli/vendor/desktop/lib/local/engine.js +447 -14
- package/vendor/cli/vendor/desktop/renderer/usage.js +274 -21
- package/vendor/cli/vendor/mcp/tools.js +1 -1
- package/vendor/desktop/README.md +11 -0
- package/vendor/desktop/lib/deep-link.js +35 -1
- package/vendor/desktop/lib/local/autonomous.js +81 -0
- package/vendor/desktop/lib/local/engine.js +447 -14
- package/vendor/desktop/main.js +271 -6
- package/vendor/desktop/package.json +1 -1
- package/vendor/desktop/preload.js +18 -0
- package/vendor/desktop/renderer/app.js +631 -43
- package/vendor/desktop/renderer/index.html +4 -5
- package/vendor/desktop/renderer/stream-policy.js +24 -2
- package/vendor/desktop/renderer/style.css +81 -7
- package/vendor/desktop/renderer/usage.js +274 -21
- package/vendor/desktop/vendor/aegis.js +22 -0
- package/vendor/desktop/vendor/byok-catalog.js +43 -8
- package/vendor/desktop/vendor/user-models.js +378 -0
|
@@ -490,6 +490,22 @@ function rollFor(sessionId) {
|
|
|
490
490
|
* per-turn figure beside the session total (the CLI shows both: the meta row's
|
|
491
491
|
* `1.5k tok` and the status bar's rolling total).
|
|
492
492
|
*/
|
|
493
|
+
/**
|
|
494
|
+
* The account's entitlement snapshot, as the main process last reported it.
|
|
495
|
+
*
|
|
496
|
+
* One reader for the money rule, so the rows that print a charge cannot disagree
|
|
497
|
+
* with each other about which tier they are on — `feeWaived` in usage.js holds
|
|
498
|
+
* the rule itself. `state` is read defensively because this runs on paths that
|
|
499
|
+
* can fire before the first entitlement probe has answered: with no snapshot yet
|
|
500
|
+
* there is no proven tier, and `feeWaived(null)` says "not waived", which is the
|
|
501
|
+
* only safe reading of an unproven account (it is the same reason
|
|
502
|
+
* `entitlement.js` starts at the free boundary rather than at Pro).
|
|
503
|
+
*/
|
|
504
|
+
function entitlement() {
|
|
505
|
+
const s = typeof state !== 'undefined' ? state : null;
|
|
506
|
+
return s && s.entitlement ? s.entitlement : null;
|
|
507
|
+
}
|
|
508
|
+
|
|
493
509
|
function foldRoll(sessionId, usage, opts = {}) {
|
|
494
510
|
const id = sessionId || '';
|
|
495
511
|
const next = rollTurn(rollFor(id), usage, opts);
|
|
@@ -500,7 +516,7 @@ function foldRoll(sessionId, usage, opts = {}) {
|
|
|
500
516
|
|
|
501
517
|
/**
|
|
502
518
|
* Paint the topbar meter. Hidden while a session has accounted for nothing —
|
|
503
|
-
* an unused thread must not display a `0
|
|
519
|
+
* an unused thread must not display a `0 tokens` it never measured — and shown
|
|
504
520
|
* the moment a turn is folded in.
|
|
505
521
|
*
|
|
506
522
|
* `live`, when given, previews the in-flight turn on top of the session's
|
|
@@ -517,6 +533,23 @@ function foldRoll(sessionId, usage, opts = {}) {
|
|
|
517
533
|
*/
|
|
518
534
|
function renderRollMeter(sessionId, live) {
|
|
519
535
|
const el = els.sessionMeter;
|
|
536
|
+
|
|
537
|
+
// The bubble's live figure is painted FIRST, before any of the topbar's own
|
|
538
|
+
// gates can return early. It belongs to the turn in flight — it is the thing
|
|
539
|
+
// the reader is watching while the AI works — and it used to sit at the
|
|
540
|
+
// BOTTOM of this function, behind `if (currentSessionId !== sessionId)
|
|
541
|
+
// return` and behind `if (!el) return`. So a turn whose sessionId did not
|
|
542
|
+
// match the current view, or any window where the topbar element was
|
|
543
|
+
// missing, streamed to completion with a dead counter in the bubble even
|
|
544
|
+
// though the estimate was being recomputed here every frame. That is the
|
|
545
|
+
// "tokens don't work while the AI is working" report.
|
|
546
|
+
const liveCount = live ? liveTokenFig(live) : '';
|
|
547
|
+
const tokensEl = live ? liveTokensEl() : null;
|
|
548
|
+
if (tokensEl) {
|
|
549
|
+
tokensEl.textContent = liveCount;
|
|
550
|
+
tokensEl.hidden = !liveCount;
|
|
551
|
+
}
|
|
552
|
+
|
|
520
553
|
if (!el) return;
|
|
521
554
|
if (currentSessionId !== sessionId) { el.hidden = true; return; }
|
|
522
555
|
let roll = rollsBySession.get(sessionId || '');
|
|
@@ -534,7 +567,115 @@ function renderRollMeter(sessionId, live) {
|
|
|
534
567
|
const line = roll ? fmtRoll(roll) : '';
|
|
535
568
|
el.textContent = line;
|
|
536
569
|
el.hidden = !line;
|
|
570
|
+
// A live figure is an estimate of a turn still in flight; the class is what
|
|
571
|
+
// says so, so a reader is never left comparing a moving number with a settled
|
|
572
|
+
// one and concluding the meter lies.
|
|
573
|
+
el.classList.toggle('live', !!live && !!line);
|
|
537
574
|
if (line) el.title = 'This session, counted the way the CLI counts it — every turn rolled into one running total';
|
|
575
|
+
return roll;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* The bubble's live figure — `↓N tokens`, the CLI's live spinner tail — for a
|
|
580
|
+
* turn still in flight, or '' when there is nothing measured yet.
|
|
581
|
+
*
|
|
582
|
+
* OUTPUT only (the answer plus the thinking trace it was billed with), never
|
|
583
|
+
* input + output: this figure has to be the same quantity the CLI's spinner
|
|
584
|
+
* reports (`cli/src/chatflow.js`: `↓${fmtTokens(state.streamed)} tokens`, fed
|
|
585
|
+
* `streamedCells() / 4`) and the same one aegiscodex-dev climbs with while it
|
|
586
|
+
* works. Adding the prompt in made this surface count a second, much larger
|
|
587
|
+
* quantity that opened high and barely moved.
|
|
588
|
+
*
|
|
589
|
+
* Two ways to fail closed on the same number, because a dead counter is worse
|
|
590
|
+
* than a roughly right one — it tells the reader the turn has stalled:
|
|
591
|
+
*
|
|
592
|
+
* 1. `estimatedBuckets` is the authority. If it is unavailable or its shape
|
|
593
|
+
* is not what this call site expects, the throw used to escape into the
|
|
594
|
+
* painter every frame, so the figure never appeared at all while the
|
|
595
|
+
* answer streamed normally beside it. Caught.
|
|
596
|
+
* 2. Below that, the estimate is taken from the stream itself — the reply's
|
|
597
|
+
* own text at the 4:1 chars:tokens ratio of the same heuristic, i.e. the
|
|
598
|
+
* quantity the CLI's tail is built on. So there is a number to show from
|
|
599
|
+
* the first chunk regardless of what the model reports or bills.
|
|
600
|
+
*/
|
|
601
|
+
function liveTokenFig(live) {
|
|
602
|
+
const reply = typeof live.reply === 'string' ? live.reply : '';
|
|
603
|
+
const reasoning = typeof live.reasoning === 'string' ? live.reasoning : '';
|
|
604
|
+
// A turn in flight that has produced nothing YET. Its figure is zero, and
|
|
605
|
+
// zero is what the other measured surface shows at this moment: the CLI's
|
|
606
|
+
// spinner tail counts the answer's deltas and the thinking trace's, so it too
|
|
607
|
+
// reads `↓0 tokens` only until the turn's first billed token.
|
|
608
|
+
//
|
|
609
|
+
// This is the ONE place the figure deliberately differs from the reference
|
|
610
|
+
// engine's, and the difference is the source of the number rather than its
|
|
611
|
+
// format: `aegiscodex-dev/src/main.js` climbs on ELAPSED TIME
|
|
612
|
+
// (`Math.round(secs * 21 + 7)` with `secs = Math.max(1, …)`, so its floor is
|
|
613
|
+
// 28 and it never prints 0) while this host reports what the turn actually
|
|
614
|
+
// produced. Matching the reference frame-for-frame would mean printing a
|
|
615
|
+
// count no provider ever sent, which this repo refuses everywhere else
|
|
616
|
+
// (`fmtRoll` will not put `0 tokens` on a meter that never took a reading;
|
|
617
|
+
// `fmtUsageSplit` omits an unmeasured half rather than inventing one). The
|
|
618
|
+
// measured zero is honest and self-correcting within the first token.
|
|
619
|
+
//
|
|
620
|
+
// Returning '' here was the start-of-turn lag — the bubble opened with no
|
|
621
|
+
// figure at all and popped one in seconds later, once the reply had grown past
|
|
622
|
+
// a threshold. Safe because the caller only passes `live` for a turn still
|
|
623
|
+
// running: this is a statement about that turn, not a fabricated measurement
|
|
624
|
+
// of a finished one.
|
|
625
|
+
if (!reply && !reasoning) return '↓0 tokens';
|
|
626
|
+
let output = 0;
|
|
627
|
+
try {
|
|
628
|
+
const est = estimatedBuckets(live.prompt, reply, reasoning);
|
|
629
|
+
if (est && typeof est.output === 'number' && est.output > 0) output = est.output;
|
|
630
|
+
} catch (err) {
|
|
631
|
+
/* the stream-text estimate below is the whole point of the fallback */
|
|
632
|
+
}
|
|
633
|
+
if (!output) {
|
|
634
|
+
// Counted, never spread. `[...part].length` is the readable spelling of
|
|
635
|
+
// "how many codepoints", and it is the one this fallback started with — but
|
|
636
|
+
// this function runs inside the painter, so on every frame of every turn
|
|
637
|
+
// that takes this path it built a full codepoint array of the whole reply
|
|
638
|
+
// and threw it away: 100k entries per frame, ~60 frames a second, on the
|
|
639
|
+
// largest replies. The codepoint walk below yields the identical count
|
|
640
|
+
// without the array (a surrogate pair is one codepoint, two UTF-16 units),
|
|
641
|
+
// so the figure is unchanged and the per-frame allocation is gone.
|
|
642
|
+
let cells = 0;
|
|
643
|
+
for (const part of [reply, reasoning]) {
|
|
644
|
+
let i = 0;
|
|
645
|
+
while (i < part.length) {
|
|
646
|
+
const cp = part.codePointAt(i);
|
|
647
|
+
i += cp > 0xffff ? 2 : 1;
|
|
648
|
+
cells += 1;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
output = Math.ceil(cells / 4);
|
|
652
|
+
}
|
|
653
|
+
if (!output) return '';
|
|
654
|
+
return `↓${Math.round(output)} tokens`;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* The live figure's element, CREATED ON DEMAND when the row does not have one.
|
|
659
|
+
*
|
|
660
|
+
* `setBusy` appends it, but not every working row goes through `setBusy`: a
|
|
661
|
+
* turn opened by `ensurePendingRow` (tool activity arriving before any text)
|
|
662
|
+
* had no `.typing-tokens` to find, so the meter had nowhere to paint. Built
|
|
663
|
+
* here, a sibling of `.body` for the same reason as there — `paintStream`
|
|
664
|
+
* assigns the body's `textContent` wholesale and would delete a child.
|
|
665
|
+
*
|
|
666
|
+
* Painted by `renderRollMeter`, the same authority that writes the topbar
|
|
667
|
+
* meter, so the two can never disagree.
|
|
668
|
+
*/
|
|
669
|
+
function liveTokensEl() {
|
|
670
|
+
if (!pendingEl) return null;
|
|
671
|
+
let el = pendingEl.querySelector('.typing-tokens');
|
|
672
|
+
if (!el) {
|
|
673
|
+
el = document.createElement('span');
|
|
674
|
+
el.className = 'typing-tokens';
|
|
675
|
+
el.hidden = true;
|
|
676
|
+
pendingEl.appendChild(el);
|
|
677
|
+
}
|
|
678
|
+
return el;
|
|
538
679
|
}
|
|
539
680
|
|
|
540
681
|
/**
|
|
@@ -833,8 +974,8 @@ function currentBudgetModel() {
|
|
|
833
974
|
*/
|
|
834
975
|
function budgetNote(cls, model) {
|
|
835
976
|
const chosen = effortFor();
|
|
836
|
-
const rung = chosen
|
|
837
|
-
const rungText = chosen
|
|
977
|
+
const rung = chosen;
|
|
978
|
+
const rungText = chosen;
|
|
838
979
|
if (cls === AUTONOMOUS_CLASS) {
|
|
839
980
|
// aegis1 services/pool_brain.py pass_budgets — the total across the worker
|
|
840
981
|
// fan-out + synthesis pass, which is why it is not the local table.
|
|
@@ -864,16 +1005,20 @@ function updateBudgetControls(cls, model) {
|
|
|
864
1005
|
}
|
|
865
1006
|
|
|
866
1007
|
/**
|
|
867
|
-
* The effort to send
|
|
1008
|
+
* The effort rung to send: always 'low' | 'medium' | 'high'.
|
|
868
1009
|
*
|
|
869
|
-
* Sent for EVERY class and model
|
|
870
|
-
*
|
|
871
|
-
*
|
|
872
|
-
*
|
|
1010
|
+
* Sent for EVERY class and model. The three-rung select has no "auto" row any
|
|
1011
|
+
* more, because "no rung pinned" is not a fourth level — it was the DEFAULT,
|
|
1012
|
+
* so a fresh window sent no effort at all and every model ran on whatever the
|
|
1013
|
+
* far end happened to do, which is what "the levels do nothing" was.
|
|
1014
|
+
*
|
|
1015
|
+
* A missing select (or one holding a stale `auto` persisted before this
|
|
1016
|
+
* change) resolves to `high`, the same default the engine and the CLI apply,
|
|
1017
|
+
* so an unreadable control can never silently mean "smallest".
|
|
873
1018
|
*/
|
|
874
1019
|
function effortFor() {
|
|
875
1020
|
const value = els.effortSelect && els.effortSelect.value;
|
|
876
|
-
return value
|
|
1021
|
+
return value === 'low' || value === 'medium' ? value : 'high';
|
|
877
1022
|
}
|
|
878
1023
|
|
|
879
1024
|
// ---------------------------------------------------------------- UI helpers
|
|
@@ -2121,7 +2266,7 @@ function memoryCard(e) {
|
|
|
2121
2266
|
if (rel) bits.push(rel);
|
|
2122
2267
|
else if (e.timestamp) bits.push(e.timestamp);
|
|
2123
2268
|
if (e.session) bits.push(`session ${e.session}`);
|
|
2124
|
-
if (e.tokenCount != null) bits.push(`${e.tokenCount}
|
|
2269
|
+
if (e.tokenCount != null) bits.push(`${e.tokenCount} tokens`);
|
|
2125
2270
|
meta.textContent = bits.join(' · ');
|
|
2126
2271
|
head.appendChild(meta);
|
|
2127
2272
|
li.appendChild(head);
|
|
@@ -2494,7 +2639,27 @@ function hideWelcome() {
|
|
|
2494
2639
|
// window.open (CSP `script-src 'self'` drops nothing here, but the
|
|
2495
2640
|
// main process is what validates the URL).
|
|
2496
2641
|
|
|
2497
|
-
/** Show the connect block
|
|
2642
|
+
/** Show the connect block while EITHER connect route is still untaken, and
|
|
2643
|
+
* retire the individual routes that have been taken.
|
|
2644
|
+
*
|
|
2645
|
+
* This used to hide the whole block — "bring your own key" included — the
|
|
2646
|
+
* moment `keyConfigured` went true, on the reasoning that a panel still
|
|
2647
|
+
* advertising a route the user already took is a nag. It is a nag; but the
|
|
2648
|
+
* two routes are not alternatives, and the user who just redeemed an AEGIS
|
|
2649
|
+
* key is the one most likely to want a provider key of their own (a model the
|
|
2650
|
+
* pool does not carry, a turn that is not relayed). Hiding the BYOK path at
|
|
2651
|
+
* exactly that moment meant the app answered "you have a key" to a question
|
|
2652
|
+
* nobody had asked, and the two-key pop-up below was left to carry the whole
|
|
2653
|
+
* explanation. So the gates are now split, one per route, matching the CLI
|
|
2654
|
+
* welcome screen's `connectRows()`:
|
|
2655
|
+
*
|
|
2656
|
+
* cloud — retired by an AEGIS account key (that is the thing it pitches);
|
|
2657
|
+
* byok — retired by a provider route of the user's own (`providerConfigured`
|
|
2658
|
+
* — a BYOK key or a local base URL, which never touch aegis.apiKey).
|
|
2659
|
+
*
|
|
2660
|
+
* Both states are null/false until status is read, so an unknown state keeps
|
|
2661
|
+
* the block visible: on a cold boot the user has no key far more often than
|
|
2662
|
+
* not, and renderStatus() calls this again the moment the truth arrives. */
|
|
2498
2663
|
function applyWelcomeConnect() {
|
|
2499
2664
|
const box = document.getElementById('welcome-connect');
|
|
2500
2665
|
if (!box) return;
|
|
@@ -2504,15 +2669,22 @@ function applyWelcomeConnect() {
|
|
|
2504
2669
|
} catch {
|
|
2505
2670
|
/* storage disabled — treat as not dismissed */
|
|
2506
2671
|
}
|
|
2507
|
-
//
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
//
|
|
2512
|
-
//
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2672
|
+
// `!== true`, not `=== false`: null is "not read yet" and must read as owed.
|
|
2673
|
+
const cloudOwed = keyConfigured !== true;
|
|
2674
|
+
const byokOwed = providerConfigured !== true;
|
|
2675
|
+
box.hidden = dismissed || (!cloudOwed && !byokOwed);
|
|
2676
|
+
// Each route retires on its own, button AND its note — a note left under a
|
|
2677
|
+
// gone button reads as a dangling fragment.
|
|
2678
|
+
setHidden('welcome-cloud', !cloudOwed);
|
|
2679
|
+
setHidden('welcome-cloud-note', !cloudOwed);
|
|
2680
|
+
setHidden('welcome-byok', !byokOwed);
|
|
2681
|
+
setHidden('welcome-byok-note', !byokOwed);
|
|
2682
|
+
}
|
|
2683
|
+
|
|
2684
|
+
/** Hide/show one cloned panel node by id when it exists. */
|
|
2685
|
+
function setHidden(id, hidden) {
|
|
2686
|
+
const el = document.getElementById(id);
|
|
2687
|
+
if (el) el.hidden = hidden;
|
|
2516
2688
|
}
|
|
2517
2689
|
|
|
2518
2690
|
/**
|
|
@@ -2641,7 +2813,8 @@ function dismissWelcomeConnect() {
|
|
|
2641
2813
|
// ------------------------------------------- boot: the two-key pop-up
|
|
2642
2814
|
//
|
|
2643
2815
|
// The welcome block above pitches the ROUTES ("connect AEGIS Cloud", "bring
|
|
2644
|
-
// your own key") and retires
|
|
2816
|
+
// your own key") and retires each one as it is taken — keyConfigured for the
|
|
2817
|
+
// Cloud row, providerConfigured for the BYOK row. This sheet is the
|
|
2645
2818
|
// other question, and the one nothing on screen used to answer: this app and
|
|
2646
2819
|
// the `aegiscode` CLI on the command line are ONE engine over ONE store, so a
|
|
2647
2820
|
// user who added only one of the two keys gets a surface that refuses turns
|
|
@@ -3042,10 +3215,15 @@ async function spawnPath(card, spec) {
|
|
|
3042
3215
|
// A lane card is a dispatch the same way a turn is, and it was the
|
|
3043
3216
|
// un-costed half of the 3x story: it reported tokens with no charge beside
|
|
3044
3217
|
// them, so the extra calls were the least visible thing on the screen.
|
|
3218
|
+
// The card is also the place the wire's TOTAL was most misleading: a lane
|
|
3219
|
+
// re-sends the request plus a path hint, so its input half is nearly the
|
|
3220
|
+
// whole count and the card read as though the path had produced it all.
|
|
3221
|
+
// The figure is the output, like every other per-dispatch surface here.
|
|
3045
3222
|
const flow = turnAccounting(data && data.usage, spec.model, {
|
|
3046
3223
|
costUsd: data && typeof data.costUsd === 'number' ? data.costUsd : undefined,
|
|
3047
3224
|
});
|
|
3048
|
-
|
|
3225
|
+
const flowProduced = displayTokens(flow);
|
|
3226
|
+
if (flowProduced != null) bits.push(`${flowProduced} tokens`);
|
|
3049
3227
|
if (flow.cost != null) bits.push(fmtCost(flow.cost, flow.real));
|
|
3050
3228
|
// …and roll it into the session, which is the half that was missing. The
|
|
3051
3229
|
// card shows this ONE dispatch; a session total that skipped it would be
|
|
@@ -3164,6 +3342,19 @@ function setBusy(busy, { cancellable } = {}) {
|
|
|
3164
3342
|
dots.className = 'typing-dots';
|
|
3165
3343
|
for (let i = 0; i < 3; i++) dots.appendChild(document.createElement('span'));
|
|
3166
3344
|
pendingEl.querySelector('.body').appendChild(dots);
|
|
3345
|
+
// The live token figure, rendered by `renderRollMeter` — the same authority
|
|
3346
|
+
// that writes the topbar meter, from the same roll, so the two can never
|
|
3347
|
+
// disagree. A SIBLING of `.body`, not a child: `paintStream` assigns the
|
|
3348
|
+
// body's `textContent` on the first chunk, which deletes everything inside
|
|
3349
|
+
// it — the dots go with it deliberately, and this must not.
|
|
3350
|
+
//
|
|
3351
|
+
// Starts hidden and empty. A fresh turn has measured nothing yet, and the
|
|
3352
|
+
// `0 tokens` that would fill this line is the exact fabrication `fmtRoll`
|
|
3353
|
+
// refuses to print.
|
|
3354
|
+
const tokens = document.createElement('span');
|
|
3355
|
+
tokens.className = 'typing-tokens';
|
|
3356
|
+
tokens.hidden = true;
|
|
3357
|
+
pendingEl.appendChild(tokens);
|
|
3167
3358
|
if (cancellable) {
|
|
3168
3359
|
const cancelBtn = document.createElement('button');
|
|
3169
3360
|
cancelBtn.type = 'button';
|
|
@@ -3417,6 +3608,119 @@ function renderApprovalCard(row, approval, beforeSelector) {
|
|
|
3417
3608
|
return card;
|
|
3418
3609
|
}
|
|
3419
3610
|
|
|
3611
|
+
/**
|
|
3612
|
+
* A turn-level note written by the APP, not by the model (`onDelta`'s
|
|
3613
|
+
* `{ note }` chunk). Rendered inside the assistant row it belongs to, above the
|
|
3614
|
+
* text stream, and kept out of `streamedText` for the reason the branch that
|
|
3615
|
+
* calls this states: the row's text is persisted as the assistant's own message
|
|
3616
|
+
* and pushed to the account's cloud memory, so app-authored prose placed there
|
|
3617
|
+
* would come back on the next turn as the model's previous answer.
|
|
3618
|
+
*
|
|
3619
|
+
* It exists because auto mode's silent round continuations have to be VISIBLE:
|
|
3620
|
+
* a turn whose budget quietly grew is the "why is it still running?" report
|
|
3621
|
+
* this app keeps getting, and the CLI announces the same continuation with the
|
|
3622
|
+
* same wording in its transcript.
|
|
3623
|
+
*/
|
|
3624
|
+
function appendTurnNote(row, text, beforeSelector) {
|
|
3625
|
+
if (!row || !text) return null;
|
|
3626
|
+
const note = document.createElement('div');
|
|
3627
|
+
note.className = 'turn-note';
|
|
3628
|
+
note.textContent = text;
|
|
3629
|
+
const before = beforeSelector ? row.querySelector(beforeSelector) : null;
|
|
3630
|
+
if (before) row.insertBefore(note, before);
|
|
3631
|
+
else row.appendChild(note);
|
|
3632
|
+
return note;
|
|
3633
|
+
}
|
|
3634
|
+
|
|
3635
|
+
/**
|
|
3636
|
+
* Render the round-horizon card (`onDelta`'s `{ rounds: { id, spent,
|
|
3637
|
+
* extensions, max, size } }` chunk — see `requestRoundsAsk` in
|
|
3638
|
+
* desktop/lib/local/engine.js).
|
|
3639
|
+
*
|
|
3640
|
+
* This is the desktop half of what the CLI has handled since the ask landed
|
|
3641
|
+
* (`cli/src/app.js` `chunk.rounds` → `confirmRoundsExtension`). Without it the
|
|
3642
|
+
* desktop never opted in (`roundsAsk` was false, because nothing sent it), so a
|
|
3643
|
+
* turn that used its rounds ended with the engine's non-interactive note —
|
|
3644
|
+
* "…or raise AEGIS_CHAT_MAX_ROUNDS for a longer single turn" — naming an
|
|
3645
|
+
* environment variable a packaged Electron app gives its user no way to set.
|
|
3646
|
+
* The engine only says that where nobody could have been asked, so wiring the
|
|
3647
|
+
* ask is what deletes the obsolete line here: with the card on screen the note
|
|
3648
|
+
* drops the knob and keeps the part that is true (the work is held, the next
|
|
3649
|
+
* message resumes it).
|
|
3650
|
+
*
|
|
3651
|
+
* Answers through `models.respondRoundsAsk`; like the approval card it disables
|
|
3652
|
+
* itself on the first click so a double-click cannot send two decisions for one
|
|
3653
|
+
* id. Declining is NOT destructive: the engine falls through to the same
|
|
3654
|
+
* session-hold stop a non-interactive caller gets, so "Stop here" costs the user
|
|
3655
|
+
* nothing they cannot resume.
|
|
3656
|
+
*/
|
|
3657
|
+
function renderRoundsCard(row, ask, beforeSelector) {
|
|
3658
|
+
if (!row || !ask || !ask.id) return null;
|
|
3659
|
+
|
|
3660
|
+
const spent = Number(ask.spent) || 0;
|
|
3661
|
+
const size = Number(ask.size) || spent;
|
|
3662
|
+
const extensions = Number(ask.extensions) || 1;
|
|
3663
|
+
const max = Number(ask.max) || 8;
|
|
3664
|
+
|
|
3665
|
+
const card = document.createElement('div');
|
|
3666
|
+
card.className = 'approval-card rounds-card';
|
|
3667
|
+
card.dataset.roundsAskId = ask.id;
|
|
3668
|
+
|
|
3669
|
+
const title = document.createElement('div');
|
|
3670
|
+
title.className = 'approval-title';
|
|
3671
|
+
title.textContent = `Round limit reached — keep going?`;
|
|
3672
|
+
card.appendChild(title);
|
|
3673
|
+
|
|
3674
|
+
const summary = document.createElement('div');
|
|
3675
|
+
summary.className = 'approval-summary';
|
|
3676
|
+
// Says the three things the user needs to decide: what the limit is, what
|
|
3677
|
+
// "keep going" buys, and that stopping is a pause rather than a loss. No
|
|
3678
|
+
// environment variable is named, because the card IS the lever now.
|
|
3679
|
+
summary.textContent =
|
|
3680
|
+
`This turn has used all ${spent} tool rounds allowed for it. ` +
|
|
3681
|
+
`${size} more continue the SAME turn — no restart, no repeated work. ` +
|
|
3682
|
+
`Stopping holds everything done so far: your next message resumes it automatically. ` +
|
|
3683
|
+
`(${extensions} of ${max} extensions.)`;
|
|
3684
|
+
card.appendChild(summary);
|
|
3685
|
+
|
|
3686
|
+
const actions = document.createElement('div');
|
|
3687
|
+
actions.className = 'approval-actions';
|
|
3688
|
+
|
|
3689
|
+
const decide = (decision) => {
|
|
3690
|
+
for (const btn of actions.querySelectorAll('button')) btn.disabled = true;
|
|
3691
|
+
card.classList.add('resolved');
|
|
3692
|
+
const tag = document.createElement('div');
|
|
3693
|
+
tag.className = 'approval-decision';
|
|
3694
|
+
tag.textContent = decision ? `Continuing — ${size} more rounds` : 'Stopped — the work is held';
|
|
3695
|
+
card.appendChild(tag);
|
|
3696
|
+
models.respondRoundsAsk(ask.id, decision);
|
|
3697
|
+
};
|
|
3698
|
+
|
|
3699
|
+
const mkButton = (label, cls, decision) => {
|
|
3700
|
+
const btn = document.createElement('button');
|
|
3701
|
+
btn.type = 'button';
|
|
3702
|
+
btn.className = `approval-btn ${cls}`;
|
|
3703
|
+
btn.textContent = label;
|
|
3704
|
+
btn.addEventListener('click', () => decide(decision));
|
|
3705
|
+
return btn;
|
|
3706
|
+
};
|
|
3707
|
+
|
|
3708
|
+
actions.appendChild(mkButton(`Keep going (${size} more rounds)`, 'allow', true));
|
|
3709
|
+
actions.appendChild(mkButton('Stop here', 'deny', false));
|
|
3710
|
+
card.appendChild(actions);
|
|
3711
|
+
|
|
3712
|
+
let slot = row.querySelector('.approval-slot');
|
|
3713
|
+
if (!slot) {
|
|
3714
|
+
slot = document.createElement('div');
|
|
3715
|
+
slot.className = 'approval-slot';
|
|
3716
|
+
const before = beforeSelector ? row.querySelector(beforeSelector) : null;
|
|
3717
|
+
if (before) row.insertBefore(slot, before);
|
|
3718
|
+
else row.appendChild(slot);
|
|
3719
|
+
}
|
|
3720
|
+
slot.appendChild(card);
|
|
3721
|
+
return card;
|
|
3722
|
+
}
|
|
3723
|
+
|
|
3420
3724
|
function classLabel(cls) {
|
|
3421
3725
|
const found = classOptions.find((c) => c.class === cls);
|
|
3422
3726
|
return found ? found.label : cls;
|
|
@@ -3880,6 +4184,12 @@ async function saveLocalBase(baseURL) {
|
|
|
3880
4184
|
|
|
3881
4185
|
async function loadSettings() {
|
|
3882
4186
|
els.settingsList.innerHTML = '';
|
|
4187
|
+
// The provider ids the class offers, collected while the byok rows are built.
|
|
4188
|
+
// `/byok`'s own list IS the catalog, so the "add a model" field below can
|
|
4189
|
+
// offer it instead of asking the user to remember a slug — and it can still
|
|
4190
|
+
// accept a typed id, because the very case this row exists for is a provider
|
|
4191
|
+
// whose lineup moved ahead of our catalog.
|
|
4192
|
+
const byokProviderIds = [];
|
|
3883
4193
|
let settings = [];
|
|
3884
4194
|
try {
|
|
3885
4195
|
settings = (await models.settings.get()) || [];
|
|
@@ -3918,6 +4228,7 @@ async function loadSettings() {
|
|
|
3918
4228
|
const byokProviders = Array.isArray(byokData && byokData.providers) ? byokData.providers : [];
|
|
3919
4229
|
for (const p of byokProviders) {
|
|
3920
4230
|
if (!p || !p.id) continue;
|
|
4231
|
+
byokProviderIds.push({ id: p.id, label: p.label || p.id });
|
|
3921
4232
|
const provider = `byok:${p.id}`;
|
|
3922
4233
|
const local = settings.find((s) => s.provider === provider) || {
|
|
3923
4234
|
provider, baseURL: '', configured: false, keyMask: null,
|
|
@@ -3954,6 +4265,195 @@ async function loadSettings() {
|
|
|
3954
4265
|
} catch {
|
|
3955
4266
|
/* catalog unreachable (offline, server down) — no rows, and the hint above says why */
|
|
3956
4267
|
}
|
|
4268
|
+
|
|
4269
|
+
// The user's OWN model declarations (`client/user-models.js`, the file the
|
|
4270
|
+
// CLI's `/model-add` writes). Rendered outside the byok try above so it
|
|
4271
|
+
// survives an unreachable catalog, and it is the ONE way a desktop user can
|
|
4272
|
+
// pin a model the AEGIS catalog does not name — a newly shipped vendor id, a
|
|
4273
|
+
// fine-tune, a preview route — without waiting for a release or hand-editing
|
|
4274
|
+
// a JSON file the app never named. The relay is a pass-through, so anything
|
|
4275
|
+
// the vendor serves for a provider whose key is set is callable.
|
|
4276
|
+
try {
|
|
4277
|
+
await renderUserModelRows(byokProviderIds);
|
|
4278
|
+
} catch (err) {
|
|
4279
|
+
els.settingsHint.textContent =
|
|
4280
|
+
`your own models: ${err && err.message ? err.message : err}`;
|
|
4281
|
+
}
|
|
4282
|
+
}
|
|
4283
|
+
|
|
4284
|
+
/**
|
|
4285
|
+
* The "your own models" block: one add row plus a row per declaration.
|
|
4286
|
+
*
|
|
4287
|
+
* Everything here goes through the engine (`models.userModels.*`), never
|
|
4288
|
+
* through the settings store, because the engine's `listModels('byok')` is what
|
|
4289
|
+
* APPLIES the declarations — one implementation writes the file and one reads
|
|
4290
|
+
* it, so the row a user adds here is the row the picker offers on its next
|
|
4291
|
+
* refresh (loadModels is re-run by the callers below).
|
|
4292
|
+
*
|
|
4293
|
+
* A rejected value does not throw into the console: `add`/`remove` reject with
|
|
4294
|
+
* the validation message (an id the relay would forward to a vendor 404s on the
|
|
4295
|
+
* user's first turn, so refusing it here is the whole value of the check) and it
|
|
4296
|
+
* is printed in the hint line with the file path, which is also the documented
|
|
4297
|
+
* escape hatch for a bulk edit.
|
|
4298
|
+
*/
|
|
4299
|
+
async function renderUserModelRows(byokProviderIds) {
|
|
4300
|
+
if (!els.settingsList || !models.userModels) return;
|
|
4301
|
+
const report = await models.userModels.get();
|
|
4302
|
+
if (!report) return;
|
|
4303
|
+
const map = (report && report.map) || {};
|
|
4304
|
+
const ids = (byokProviderIds || []).map((p) => (p && p.id) || '').filter(Boolean);
|
|
4305
|
+
|
|
4306
|
+
const block = document.createElement('div');
|
|
4307
|
+
block.id = 'user-models-block';
|
|
4308
|
+
|
|
4309
|
+
const title = document.createElement('div');
|
|
4310
|
+
title.className = 'setting-name';
|
|
4311
|
+
title.textContent = 'Your own models (BYOK)';
|
|
4312
|
+
block.appendChild(title);
|
|
4313
|
+
|
|
4314
|
+
// ── add: provider + model id + one button
|
|
4315
|
+
const addRow = document.createElement('div');
|
|
4316
|
+
addRow.className = 'setting-row';
|
|
4317
|
+
addRow.dataset.provider = 'byok:__user-model-add';
|
|
4318
|
+
|
|
4319
|
+
const providerInput = document.createElement('input');
|
|
4320
|
+
providerInput.type = 'text';
|
|
4321
|
+
providerInput.className = 'setting-input';
|
|
4322
|
+
providerInput.id = 'user-model-provider';
|
|
4323
|
+
providerInput.placeholder = 'provider (deepseek)';
|
|
4324
|
+
providerInput.autocomplete = 'off';
|
|
4325
|
+
providerInput.spellcheck = false;
|
|
4326
|
+
// A datalist rather than a select: the catalog's ids are a convenience for the
|
|
4327
|
+
// common case, and a typed slug is still allowed for the case this row exists
|
|
4328
|
+
// for (the catalog has not caught up). A select would have made the second one
|
|
4329
|
+
// impossible without a form of its own.
|
|
4330
|
+
if (ids.length) {
|
|
4331
|
+
const list = document.createElement('datalist');
|
|
4332
|
+
list.id = 'user-model-providers';
|
|
4333
|
+
for (const id of ids) {
|
|
4334
|
+
const opt = document.createElement('option');
|
|
4335
|
+
opt.value = id;
|
|
4336
|
+
list.appendChild(opt);
|
|
4337
|
+
}
|
|
4338
|
+
addRow.appendChild(list);
|
|
4339
|
+
providerInput.setAttribute('list', 'user-model-providers');
|
|
4340
|
+
}
|
|
4341
|
+
addRow.appendChild(providerInput);
|
|
4342
|
+
|
|
4343
|
+
const modelInput = document.createElement('input');
|
|
4344
|
+
modelInput.type = 'text';
|
|
4345
|
+
modelInput.className = 'setting-input';
|
|
4346
|
+
modelInput.id = 'user-model-id';
|
|
4347
|
+
modelInput.placeholder = 'model id (deepseek-v4.2-preview)';
|
|
4348
|
+
modelInput.autocomplete = 'off';
|
|
4349
|
+
modelInput.spellcheck = false;
|
|
4350
|
+
addRow.appendChild(modelInput);
|
|
4351
|
+
|
|
4352
|
+
const actions = document.createElement('div');
|
|
4353
|
+
actions.className = 'setting-actions';
|
|
4354
|
+
const addBtn = document.createElement('button');
|
|
4355
|
+
addBtn.type = 'button';
|
|
4356
|
+
addBtn.className = 'ghost-btn';
|
|
4357
|
+
addBtn.id = 'user-model-add';
|
|
4358
|
+
addBtn.textContent = 'Add model';
|
|
4359
|
+
addBtn.addEventListener('click', async () => {
|
|
4360
|
+
const provider = providerInput.value.trim();
|
|
4361
|
+
const model = modelInput.value.trim();
|
|
4362
|
+
els.settingsHint.textContent = 'adding…';
|
|
4363
|
+
try {
|
|
4364
|
+
const res = await models.userModels.add(provider, model);
|
|
4365
|
+
els.settingsHint.textContent = res && res.added === false
|
|
4366
|
+
? `${res.provider}:${res.model} was already declared.`
|
|
4367
|
+
: `added ${res.provider}:${res.model} — /models and the picker now offer it.`;
|
|
4368
|
+
await loadSettings();
|
|
4369
|
+
await loadModels(els.classSelect.value);
|
|
4370
|
+
} catch (err) {
|
|
4371
|
+
els.settingsHint.textContent = `${err && err.message ? err.message : err}`;
|
|
4372
|
+
}
|
|
4373
|
+
});
|
|
4374
|
+
actions.appendChild(addBtn);
|
|
4375
|
+
addRow.appendChild(actions);
|
|
4376
|
+
|
|
4377
|
+
const hint = document.createElement('div');
|
|
4378
|
+
hint.className = 'setting-status';
|
|
4379
|
+
hint.id = 'user-model-hint';
|
|
4380
|
+
hint.textContent = report.file
|
|
4381
|
+
? `saved in ${report.file} — the CLI reads the same file (/model-add)`
|
|
4382
|
+
: 'saved beside your AEGIS config — the CLI reads the same file (/model-add)';
|
|
4383
|
+
addRow.appendChild(hint);
|
|
4384
|
+
block.appendChild(addRow);
|
|
4385
|
+
|
|
4386
|
+
// ── one removal row per declaration, provider-major and sorted, so the list
|
|
4387
|
+
// is stable between renders (an order that shuffled would make the Remove
|
|
4388
|
+
// button beside a row a guess).
|
|
4389
|
+
const providers = Object.keys(map).sort();
|
|
4390
|
+
for (const provider of providers) {
|
|
4391
|
+
for (const model of map[provider]) {
|
|
4392
|
+
const row = document.createElement('div');
|
|
4393
|
+
row.className = 'setting-row';
|
|
4394
|
+
row.dataset.provider = `byok:${provider}`;
|
|
4395
|
+
|
|
4396
|
+
const name = document.createElement('div');
|
|
4397
|
+
name.className = 'setting-name';
|
|
4398
|
+
name.textContent = `${provider} — ${model}`;
|
|
4399
|
+
row.appendChild(name);
|
|
4400
|
+
|
|
4401
|
+
const status = document.createElement('div');
|
|
4402
|
+
status.className = 'setting-status';
|
|
4403
|
+
// Declared, but not offered: the server's BYOK catalog lists no row for
|
|
4404
|
+
// this provider, so no key could ever be attached to it and the engine
|
|
4405
|
+
// will not paint it. Saying so here is the difference between "my typo is
|
|
4406
|
+
// being ignored" and "this provider cannot take a key".
|
|
4407
|
+
status.textContent = ids.length && !ids.includes(provider)
|
|
4408
|
+
? 'no provider row for this id — /byok lists the ones the relay takes'
|
|
4409
|
+
: 'offered in the picker on this machine';
|
|
4410
|
+
row.appendChild(status);
|
|
4411
|
+
|
|
4412
|
+
const rowActions = document.createElement('div');
|
|
4413
|
+
rowActions.className = 'setting-actions';
|
|
4414
|
+
const rmBtn = document.createElement('button');
|
|
4415
|
+
rmBtn.type = 'button';
|
|
4416
|
+
rmBtn.className = 'ghost-btn danger';
|
|
4417
|
+
rmBtn.textContent = 'Remove';
|
|
4418
|
+
rmBtn.addEventListener('click', async () => {
|
|
4419
|
+
els.settingsHint.textContent = 'removing…';
|
|
4420
|
+
try {
|
|
4421
|
+
const res = await models.userModels.remove(provider, model);
|
|
4422
|
+
els.settingsHint.textContent = res && res.removed === false
|
|
4423
|
+
? `${provider}:${model} was not declared.`
|
|
4424
|
+
: `removed ${provider}:${model}.`;
|
|
4425
|
+
await loadSettings();
|
|
4426
|
+
await loadModels(els.classSelect.value);
|
|
4427
|
+
} catch (err) {
|
|
4428
|
+
els.settingsHint.textContent = `${err && err.message ? err.message : err}`;
|
|
4429
|
+
}
|
|
4430
|
+
});
|
|
4431
|
+
rowActions.appendChild(rmBtn);
|
|
4432
|
+
row.appendChild(rowActions);
|
|
4433
|
+
|
|
4434
|
+
block.appendChild(row);
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
|
|
4438
|
+
// A hand-edited file can carry a row this module refuses (a typo, an id with a
|
|
4439
|
+
// space). It is named rather than dropped in silence: otherwise "my model is
|
|
4440
|
+
// nowhere in the picker" has no explanation anywhere in the UI.
|
|
4441
|
+
const invalid = (report && report.invalid) || [];
|
|
4442
|
+
for (const bad of invalid) {
|
|
4443
|
+
const row = document.createElement('div');
|
|
4444
|
+
row.className = 'setting-row';
|
|
4445
|
+
const name = document.createElement('div');
|
|
4446
|
+
name.className = 'setting-name';
|
|
4447
|
+
name.textContent = `${bad.provider || 'models.json'}: ${bad.model == null ? '' : String(bad.model)}`.trim();
|
|
4448
|
+
row.appendChild(name);
|
|
4449
|
+
const status = document.createElement('div');
|
|
4450
|
+
status.className = 'setting-status';
|
|
4451
|
+
status.textContent = `skipped — ${bad.reason}`;
|
|
4452
|
+
row.appendChild(status);
|
|
4453
|
+
block.appendChild(row);
|
|
4454
|
+
}
|
|
4455
|
+
|
|
4456
|
+
els.settingsList.appendChild(block);
|
|
3957
4457
|
}
|
|
3958
4458
|
|
|
3959
4459
|
async function saveSetting(provider, key) {
|
|
@@ -4283,8 +4783,10 @@ async function send() {
|
|
|
4283
4783
|
// Sent whether or not the fan-out is ticked: the fan-out is enabled by the
|
|
4284
4784
|
// model id the pooled class sends, so a turn that never entered autonomous
|
|
4285
4785
|
// mode still ran pooled and had no way to say how big it should be — and a
|
|
4286
|
-
// DeepSeek reasoning model needs it to size its CoT.
|
|
4287
|
-
//
|
|
4786
|
+
// DeepSeek reasoning model needs it to size its CoT. It is always a rung now
|
|
4787
|
+
// (effortFor floors to `high`), never "state no opinion", because a pooled
|
|
4788
|
+
// call that states nothing is sized by the server's own default instead of
|
|
4789
|
+
// the level shown in the select.
|
|
4288
4790
|
const effort = effortFor();
|
|
4289
4791
|
const maxTokens = budgetFor(model, undefined, effort);
|
|
4290
4792
|
const workers = autonomous ? parseInt(els.autonomousWorkers.value, 10) || undefined : undefined;
|
|
@@ -4310,6 +4812,13 @@ async function send() {
|
|
|
4310
4812
|
threadMessages.push({ role: 'user', content: prompt });
|
|
4311
4813
|
|
|
4312
4814
|
setBusy(true, { cancellable: true });
|
|
4815
|
+
// The counter exists from the frame the turn does, not from its first chunk.
|
|
4816
|
+
// Both live surfaces this one mirrors have a figure on screen from the start
|
|
4817
|
+
// (`cli/src/chatflow.js`'s spinner tail reads `↓0 tokens` on its first render;
|
|
4818
|
+
// the reference engine's count climbs from t=0), and this bubble used to open
|
|
4819
|
+
// with an empty line and pop a number in a second later. Painting here also
|
|
4820
|
+
// means the reader never sees the row without the figure it will carry.
|
|
4821
|
+
if (pendingEl) renderRollMeter(sessionId, { prompt, reply: '', reasoning: '' });
|
|
4313
4822
|
// Sending is an explicit act, so it always returns the view to the tail.
|
|
4314
4823
|
// This is the single moment the auto-scroll overrides the reader's scroll.
|
|
4315
4824
|
stickToBottom({ force: true });
|
|
@@ -4328,7 +4837,16 @@ async function send() {
|
|
|
4328
4837
|
// construction (declared here, not at module scope), so a new turn starts its
|
|
4329
4838
|
// preview fresh — see `liveMeterDue` for why the meter is not recomputed on
|
|
4330
4839
|
// every frame.
|
|
4331
|
-
|
|
4840
|
+
//
|
|
4841
|
+
// Null, NOT 0: unset means "nothing painted for this turn yet", which
|
|
4842
|
+
// `liveMeterDue` reads as due on the first chunk. Seeded at 0 it read as
|
|
4843
|
+
// "measured an empty stream", so the turn's first paint waited out a full
|
|
4844
|
+
// step of the rule — a quarter kilobyte of text, ~64 tokens, seconds into a
|
|
4845
|
+
// slow turn — and the bubble sat with no figure at all and then jumped to it.
|
|
4846
|
+
// The CLI's spinner tail has no such dead zone (it prints `↓0 tokens` from
|
|
4847
|
+
// the first frame), so the two surfaces disagreed about when a count begins
|
|
4848
|
+
// existing.
|
|
4849
|
+
let meterChars = null;
|
|
4332
4850
|
|
|
4333
4851
|
// Text arrives in dozens of small chunks per second; painting each one is
|
|
4334
4852
|
// what made the window feel locked up. One paint per frame, off the latest
|
|
@@ -4365,6 +4883,19 @@ async function send() {
|
|
|
4365
4883
|
paintStream();
|
|
4366
4884
|
return;
|
|
4367
4885
|
}
|
|
4886
|
+
if (chunk && typeof chunk.note === 'string' && chunk.note) {
|
|
4887
|
+
// A turn-level notice that is NOT the model's words — today the only one
|
|
4888
|
+
// is auto mode's "continuing automatically" line (desktop/main.js
|
|
4889
|
+
// chatWithAutoRounds). It is deliberately not folded into
|
|
4890
|
+
// `streamedText`: that string becomes the assistant's message and is
|
|
4891
|
+
// persisted and synced, so an app-authored sentence put there would
|
|
4892
|
+
// re-enter the model's context on the next turn as something it had said.
|
|
4893
|
+
const row = ensurePendingRow();
|
|
4894
|
+
row.classList.remove('pending');
|
|
4895
|
+
appendTurnNote(row, chunk.note, '.body');
|
|
4896
|
+
stickToBottom();
|
|
4897
|
+
return;
|
|
4898
|
+
}
|
|
4368
4899
|
if (chunk && chunk.approval) {
|
|
4369
4900
|
const row = ensurePendingRow();
|
|
4370
4901
|
row.classList.remove('pending');
|
|
@@ -4374,6 +4905,17 @@ async function send() {
|
|
|
4374
4905
|
stickToBottom({ force: true });
|
|
4375
4906
|
return;
|
|
4376
4907
|
}
|
|
4908
|
+
if (chunk && chunk.rounds) {
|
|
4909
|
+
const row = ensurePendingRow();
|
|
4910
|
+
row.classList.remove('pending');
|
|
4911
|
+
renderRoundsCard(row, chunk.rounds, '.body');
|
|
4912
|
+
// Same blocked-until-answered reason as the approval card above. The
|
|
4913
|
+
// engine holds the turn open on this promise, and an unanswered ask
|
|
4914
|
+
// resolves `false` — so a card the user never scrolled to would read as
|
|
4915
|
+
// the turn stopping for no reason.
|
|
4916
|
+
stickToBottom({ force: true });
|
|
4917
|
+
return;
|
|
4918
|
+
}
|
|
4377
4919
|
if (chunk && chunk.tool) {
|
|
4378
4920
|
// See the flow-stream handler above: the run frame is the CLI's live
|
|
4379
4921
|
// row. Ignored here, and ignored *before* `toolLog.push` — a run frame
|
|
@@ -4398,7 +4940,29 @@ async function send() {
|
|
|
4398
4940
|
// All four classes route through the model: surface (the main process
|
|
4399
4941
|
// decides transport — cloud client, ollama, or a direct provider).
|
|
4400
4942
|
const data = await models.chat(
|
|
4401
|
-
{
|
|
4943
|
+
{
|
|
4944
|
+
class: cls,
|
|
4945
|
+
prompt,
|
|
4946
|
+
model,
|
|
4947
|
+
maxTokens,
|
|
4948
|
+
sessionId,
|
|
4949
|
+
autonomous,
|
|
4950
|
+
effort,
|
|
4951
|
+
workers,
|
|
4952
|
+
messages: historyForModel,
|
|
4953
|
+
// Opt in to the round-horizon dialog. A live renderer on the other end
|
|
4954
|
+
// of the delta stream is exactly what this flag asserts, and this call
|
|
4955
|
+
// has one (the `{ rounds }` branch of onDelta above answers it via
|
|
4956
|
+
// renderRoundsCard → models.respondRoundsAsk). It is also what retires
|
|
4957
|
+
// the engine's "raise AEGIS_CHAT_MAX_ROUNDS" advice: that line is
|
|
4958
|
+
// written only for callers nobody could ask (see the `knob` note in
|
|
4959
|
+
// lib/local/engine.js), and a packaged app user has no env to set.
|
|
4960
|
+
// The discovery lane (spawnPath) deliberately does NOT pass this: it is
|
|
4961
|
+
// single-shot with no tools, so it can never reach a round horizon, and
|
|
4962
|
+
// opting in would buy a dialog nobody could answer in a fire-and-forget
|
|
4963
|
+
// card.
|
|
4964
|
+
roundsAsk: true,
|
|
4965
|
+
},
|
|
4402
4966
|
onDelta
|
|
4403
4967
|
);
|
|
4404
4968
|
|
|
@@ -4420,7 +4984,7 @@ async function send() {
|
|
|
4420
4984
|
if (data && data.model) bits.push(`model: ${data.model}`);
|
|
4421
4985
|
else if (model) bits.push(`model: ${model}`);
|
|
4422
4986
|
bits.push(classLabel(cls));
|
|
4423
|
-
if (autonomous) bits.push(`autonomous (${effort
|
|
4987
|
+
if (autonomous) bits.push(`autonomous (${effort}, ${workers || 'auto'}w)`);
|
|
4424
4988
|
// The budget rung is worth showing even without the fan-out: on the pooled
|
|
4425
4989
|
// class it is what sized the call, and a user cannot tell a 16k turn from a
|
|
4426
4990
|
// 64k one by looking at the answer.
|
|
@@ -4431,26 +4995,42 @@ async function send() {
|
|
|
4431
4995
|
// alone left this surface with no comparable meter at all — the desktop
|
|
4432
4996
|
// and the CLI run the same engine, so a gap between them had to be
|
|
4433
4997
|
// measured on the same prompt, and one side was not measuring.
|
|
4998
|
+
//
|
|
4999
|
+
// The figure is the OUTPUT (`displayTokens`), not the wire's total: the
|
|
5000
|
+
// total is input + output, and on a cached turn the input half is the
|
|
5001
|
+
// larger one, so `tokens: 3,145` on a turn that wrote 145 tokens read as a
|
|
5002
|
+
// model emitting twenty times what it did. Same rule as the CLI's
|
|
5003
|
+
// `fmtsUsageSplit`, and the same one `fmtRoll` now uses below — the two
|
|
5004
|
+
// figures on this row are the same quantity for the same reason.
|
|
4434
5005
|
const turn = turnAccounting(data && data.usage, model, {
|
|
4435
5006
|
costUsd: data && typeof data.costUsd === 'number' ? data.costUsd : undefined,
|
|
4436
5007
|
});
|
|
4437
|
-
|
|
5008
|
+
const produced = displayTokens(turn);
|
|
5009
|
+
if (produced != null) bits.push(`tokens: ${produced}`);
|
|
4438
5010
|
// A turn the wire did not report on still gets a figure — the same text
|
|
4439
5011
|
// estimate that goes into the session total, marked `~` so an inferred
|
|
4440
5012
|
// count is never read as a reported one. Printing nothing here while the
|
|
4441
5013
|
// session total moved was the other half of "the counter looks dead".
|
|
5014
|
+
// Output only, like the reported figure beside it: `est.input` is the
|
|
5015
|
+
// prompt, and summing the two is the very reading this change removes.
|
|
4442
5016
|
else {
|
|
4443
5017
|
const est = estimatedBuckets(prompt, text, text === reasoningText ? '' : reasoningText);
|
|
4444
|
-
if (est) bits.push(`~${est.
|
|
5018
|
+
if (est && est.output > 0) bits.push(`~${est.output} tokens`);
|
|
4445
5019
|
}
|
|
4446
|
-
|
|
5020
|
+
// No money on a tier AEGIS bills no fee to, and none from a snapshot that
|
|
5021
|
+
// has not proven a fee is owed — see `feeBillable` in usage.js, which is the
|
|
5022
|
+
// CLI's exact rule. Not a `$0.0000` in its place: a zero states a price, and
|
|
5023
|
+
// this account has no proven price on this turn. The token figure above is
|
|
5024
|
+
// unaffected, so the row keeps its meter either way.
|
|
5025
|
+
const billable = feeBillable(entitlement());
|
|
5026
|
+
if (turn.cost != null && billable) bits.push(fmtCost(turn.cost, turn.real));
|
|
4447
5027
|
// …and on the byok class, whose money that figure is. The relay never
|
|
4448
5028
|
// returns a settled charge (nothing on that route emits one), so this is
|
|
4449
5029
|
// always the rate table's estimate of the caller's OWN provider bill — and
|
|
4450
5030
|
// AEGIS additionally collects a handling fee on the same turn, which this
|
|
4451
5031
|
// response cannot price. One bit, and the number stops reading as the whole
|
|
4452
5032
|
// cost of a BYOK turn.
|
|
4453
|
-
if (cls === 'byok' && turn.cost != null) {
|
|
5033
|
+
if (cls === 'byok' && turn.cost != null && billable) {
|
|
4454
5034
|
bits.push('your provider bill (est.) + AEGIS handling fee');
|
|
4455
5035
|
}
|
|
4456
5036
|
// …AND the running session total beside it, which is the number the CLI
|
|
@@ -4473,7 +5053,7 @@ async function send() {
|
|
|
4473
5053
|
// estimated twice if a turn ever collapses the two into one.
|
|
4474
5054
|
reasoning: text === reasoningText ? '' : reasoningText,
|
|
4475
5055
|
});
|
|
4476
|
-
const rollLine = fmtRoll(roll);
|
|
5056
|
+
const rollLine = fmtRoll(roll, { omitMoney: !billable });
|
|
4477
5057
|
if (rollLine) bits.push(`session: ${rollLine}`);
|
|
4478
5058
|
addMessage('assistant', text, bits.join(' · ') || undefined, sessionId, toolLog);
|
|
4479
5059
|
|
|
@@ -4548,10 +5128,14 @@ async function send() {
|
|
|
4548
5128
|
});
|
|
4549
5129
|
const stopBits = ['stopped by you'];
|
|
4550
5130
|
if (salvage.kind === 'reasoning-only') stopBits.push('reasoning only');
|
|
4551
|
-
|
|
5131
|
+
// The same figure and the same rule as the completed row above, so a
|
|
5132
|
+
// stopped turn and a finished one report one quantity. `displayTokens`
|
|
5133
|
+
// rather than `turn.tokens` — see the note there.
|
|
5134
|
+
const stopProduced = displayTokens(turn);
|
|
5135
|
+
if (stopProduced != null) stopBits.push(`tokens: ${stopProduced}`);
|
|
4552
5136
|
else {
|
|
4553
5137
|
const est = estimatedBuckets(prompt, text, salvageReasoning);
|
|
4554
|
-
if (est) stopBits.push(`~${est.
|
|
5138
|
+
if (est && est.output > 0) stopBits.push(`~${est.output} tokens`);
|
|
4555
5139
|
}
|
|
4556
5140
|
const stopRollLine = fmtRoll(roll);
|
|
4557
5141
|
if (stopRollLine) stopBits.push(`session: ${stopRollLine}`);
|
|
@@ -4650,17 +5234,21 @@ async function init() {
|
|
|
4650
5234
|
updateAutonomousControlsVisibility();
|
|
4651
5235
|
});
|
|
4652
5236
|
|
|
4653
|
-
// The one budget control: which rung sizes the call
|
|
4654
|
-
//
|
|
4655
|
-
//
|
|
4656
|
-
//
|
|
4657
|
-
//
|
|
4658
|
-
//
|
|
4659
|
-
//
|
|
4660
|
-
//
|
|
5237
|
+
// The one budget control: which rung sizes the call (low | medium | high).
|
|
5238
|
+
// Applies to EVERY class now — with the max-tokens dropdown gone there is
|
|
5239
|
+
// nothing else that sizes a call — so it is no longer stored under the
|
|
5240
|
+
// autonomous-mode namespace; an install predating the rename is read from
|
|
5241
|
+
// the old key once, and a stored rung this build's list no longer offers
|
|
5242
|
+
// falls through to the markup's default rather than assigning an option that
|
|
5243
|
+
// does not exist. That fall-through is load-bearing for the retired `auto`
|
|
5244
|
+
// value: a window that had `auto` persisted restores `high`, and the stale
|
|
5245
|
+
// string is rewritten so the next launch reads a rung that is really offered.
|
|
4661
5246
|
const savedEffort = localStorage.getItem(EFFORT_KEY) || localStorage.getItem(LEGACY_EFFORT_KEY);
|
|
4662
|
-
|
|
5247
|
+
const offered = Array.from(els.effortSelect.options).some((o) => o.value === savedEffort);
|
|
5248
|
+
if (savedEffort && offered) {
|
|
4663
5249
|
els.effortSelect.value = savedEffort;
|
|
5250
|
+
} else if (savedEffort) {
|
|
5251
|
+
localStorage.setItem(EFFORT_KEY, els.effortSelect.value);
|
|
4664
5252
|
}
|
|
4665
5253
|
els.effortSelect.addEventListener('change', () => {
|
|
4666
5254
|
localStorage.setItem(EFFORT_KEY, els.effortSelect.value);
|