@alexeiled/claude-router 1.25.0 → 1.26.0
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/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +41 -0
- package/README.md +31 -15
- package/docs/architecture.md +4 -1
- package/docs/configuration.md +1 -1
- package/docs/native-router.md +1 -1
- package/docs/router-band.svg +42 -35
- package/docs/router-pane-classifier.svg +45 -29
- package/docs/router-pane-now.svg +162 -122
- package/docs/router-pane-policy.svg +79 -47
- package/docs/user-guide.md +86 -10
- package/hooks/native-router.mjs +88 -14
- package/lib/display.mjs +2 -0
- package/lib/failover.mjs +55 -0
- package/lib/route.mjs +30 -16
- package/lib/ui/graphical/frame.mjs +11 -7
- package/lib/ui/graphical/now.mjs +7 -3
- package/lib/ui/model/band.mjs +3 -1
- package/lib/ui/model/now.mjs +53 -22
- package/lib/ui/terminal/band.mjs +71 -38
- package/lib/ui/terminal/classifier.mjs +39 -31
- package/lib/ui/terminal/kit.mjs +29 -0
- package/lib/ui/terminal/now.mjs +39 -46
- package/lib/ui/terminal/policy.mjs +31 -28
- package/package.json +2 -1
- package/types/index.d.ts +2 -0
package/docs/user-guide.md
CHANGED
|
@@ -31,6 +31,11 @@ In Claude Code:
|
|
|
31
31
|
|
|
32
32
|
The desktop app, VS Code and mobile cannot open the `/plugin configure` dialog, so their **Set up** and **Credentials → Edit** show a card with a line to run in a terminal: it asks for the key without showing it or keeping it in your shell history and saves it with `claude plugin configure <id> --values-stdin`; **Copy command** copies it, then run `/reload-plugins`. Keys are stored as sensitive plugin options. Do not paste them into a model conversation. The [configuration guide](configuration.md) covers settings and migrations.
|
|
33
33
|
|
|
34
|
+
<picture>
|
|
35
|
+
<source media="(prefers-color-scheme: dark)" srcset="images/desktop-key-card-dark.png">
|
|
36
|
+
<img src="images/desktop-key-card-light.png" alt="The Set up card: a command to run in a terminal that saves the classifier key without showing it, with Copy command and Done buttons." width="560">
|
|
37
|
+
</picture>
|
|
38
|
+
|
|
34
39
|
In this guide, `router.json` means the selected router file. For example, with `CLAUDE_ROUTER_PROVIDER=zai`, edits go to `zai-router.json`.
|
|
35
40
|
The pane shows its provider and file path.
|
|
36
41
|
|
|
@@ -38,20 +43,42 @@ The pane shows its provider and file path.
|
|
|
38
43
|
|
|
39
44
|
### In the desktop app, VS Code and mobile
|
|
40
45
|
|
|
41
|
-
|
|
46
|
+
<picture>
|
|
47
|
+
<source media="(prefers-color-scheme: dark)" srcset="images/desktop-band-routed-dark.png">
|
|
48
|
+
<img src="images/desktop-band-routed-light.png" alt="The desktop band in one row: a tier meter, Opus 5.5 xhigh, the code activity and the reason "clearly stronger" on the left; context and cache readings, the Pin to a tier dropdown and the Router button on the right.">
|
|
49
|
+
</picture>
|
|
50
|
+
|
|
51
|
+
*Rendered from the real component tree with a browser's layout and approximate theme colours; not a screenshot of the Claude app.*
|
|
52
|
+
|
|
53
|
+
|
|
42
54
|
|
|
43
55
|
The band above the prompt is drawn natively as one fixed row. Nothing appears on hover: every control is on the row itself. Colours come from the app's theme, so the band reads in light and dark.
|
|
44
56
|
|
|
45
57
|
- **Left**: a small tier meter icon, then the route (the model and effort for this turn), the activity, the reason, the classifier's support and the switch cost, in the words of the [terminal band](#in-the-terminal). When the window narrows, the left side gives way first.
|
|
46
|
-
- **Right**: the context and cache readings, a **Pin
|
|
58
|
+
- **Right**: the context and cache readings, a **Pin to a tier** dropdown and the **Router** button, which opens the pane. The dropdown lists one entry per tier, not every model; for a model no tier routes to, such as Sonnet on the default routes, turn routing off and use `/model`. With `table` or `shadow` each entry names the route that tier runs, whatever the routing mode; with `auto` it names the tier (`Low tier`), because Auto picks the cheapest capable model when the turn runs. A pin forces that tier for the next turn only. On mobile a pending pin also keeps its own `⏵ next` text and **✕** beside the dropdown, since an app may not draw the dropdown.
|
|
47
59
|
- **One control per state**: **Turn on** when routing is off, **Set up** when the active classifier lacks credentials, **Fix** when routing is unavailable. While routing is on, turn it off from the pane's header (**On** / **Off**) or with `/router off`.
|
|
48
60
|
- **Session row**: the second row (plan windows and the session's cost against no routing) is no longer a band button. Turn it on with **Show session row in band** on the pane's Now tab; Router remembers the choice across sessions.
|
|
49
61
|
|
|
50
62
|
While subagents run, a row of buttons under the band lists them, one per agent with the model, type and task (`agents 2 ▸ ■ Haiku 5.5 Explore · retry usages ●`). Press one to open that agent's transcript in the main view. The row lists three agents and then `+N`, and keeps the first agent and the count when the window narrows. It shows only while an agent runs, and never a teammate. In an agent's transcript the band has a **Back** button (`◂ main` in the terminal, **← Main** on these surfaces) that returns to the main conversation. The agent's model and who picked it are described under the terminal band.
|
|
51
63
|
|
|
64
|
+
<picture>
|
|
65
|
+
<source media="(prefers-color-scheme: dark)" srcset="images/desktop-band-agents-dark.png">
|
|
66
|
+
<img src="images/desktop-band-agents-light.png" alt="The desktop band with a second row listing two running subagents as buttons, one moved to Haiku 5.5 and one on Sonnet 5.5.">
|
|
67
|
+
</picture>
|
|
68
|
+
|
|
69
|
+
<picture>
|
|
70
|
+
<source media="(prefers-color-scheme: dark)" srcset="images/desktop-band-setup-dark.png">
|
|
71
|
+
<img src="images/desktop-band-setup-light.png" alt="The desktop band with a missing classifier key: a warning "Jev: no API key", the model kept, and a Set up button beside Router.">
|
|
72
|
+
</picture>
|
|
73
|
+
|
|
74
|
+
<picture>
|
|
75
|
+
<source media="(prefers-color-scheme: dark)" srcset="images/desktop-band-off-dark.png">
|
|
76
|
+
<img src="images/desktop-band-off-light.png" alt="The desktop band with routing off: Sonnet 5.5, "routing off", and a Turn on button beside Router.">
|
|
77
|
+
</picture>
|
|
78
|
+
|
|
52
79
|
### In the terminal
|
|
53
80
|
|
|
54
|
-
The terminal band is one line above the prompt. Its text, secondary text, accents, success, warning and error colours are your Claude Code theme's own, so a light theme reads as well as a dark one; tiers, models and activities keep their own colours. The line ends with a **Router** button that opens the pane. When the band is narrow, the less important parts drop first: classifier figures and the switch cost, then context and cache, then the activity, then the reason. The meter and the model always stay, except behind a classifier warning: the warning and its **Set up** button come first, and the route gives way to them.
|
|
81
|
+
The terminal band is one line above the prompt. Its text, secondary text, accents, success, warning and error colours are your Claude Code theme's own, so a light theme reads as well as a dark one; tiers, models and activities keep their own colours. The line ends with a **Router** button that opens the pane, drawn as `[ Router ]` when the band has room for the brackets without dropping a reading or a hover control, and as a plain `Router` otherwise. When the band is narrow, the less important parts drop first: classifier figures and the switch cost, then context and cache, then the activity, then the reason. The meter and the model always stay, except behind a classifier warning: the warning and its **Set up** button come first, and the route gives way to them.
|
|
55
82
|
|
|
56
83
|

|
|
57
84
|
|
|
@@ -120,19 +147,53 @@ The pane is drawn natively. From the top it has:
|
|
|
120
147
|
What each tab shows:
|
|
121
148
|
|
|
122
149
|
- **Now**: cards for Next turn (the route, the reason, a pin button per tier, named by route or, with `auto`, by tier), Plan usage (on a Claude plan), Context, This session and, once the session has any, Recent decisions. The Next turn and This session cards carry the same facts as the terminal blocks below. The tab also holds the **Show session row in band** setting.
|
|
150
|
+
|
|
151
|
+
<picture>
|
|
152
|
+
<source media="(prefers-color-scheme: dark)" srcset="images/desktop-pane-now-dark.png">
|
|
153
|
+
<img src="images/desktop-pane-now-light.png" alt="The Now tab of the pane: the next turn route with a pin button per tier, plan usage bars, context and cache, and this session's cost against no routing with a strip of replies by tier." width="560">
|
|
154
|
+
</picture>
|
|
155
|
+
|
|
123
156
|
- **Routes**: a grid of tiers by activities, with an edit card under it for the selected cell.
|
|
157
|
+
|
|
158
|
+
<picture>
|
|
159
|
+
<source media="(prefers-color-scheme: dark)" srcset="images/desktop-pane-routes-dark.png">
|
|
160
|
+
<img src="images/desktop-pane-routes-light.png" alt="The Routes tab: a grid of tiers by activities with the models they run, an editor card for code at High, and an Unsaved changes table with Discard and Save." width="560">
|
|
161
|
+
</picture>
|
|
162
|
+
|
|
124
163
|
- **Policy**: form cards for Routing mode, Switching down, Switching up, Activities and Credits, and a Settings file card with the `router.json` path.
|
|
164
|
+
|
|
165
|
+
<picture>
|
|
166
|
+
<source media="(prefers-color-scheme: dark)" srcset="images/desktop-pane-policy-dark.png">
|
|
167
|
+
<img src="images/desktop-pane-policy-light.png" alt="The Policy tab: cards for routing mode, switching down and up, activities and credits, each with a dropdown and one line of help, and the settings file path." width="560">
|
|
168
|
+
</picture>
|
|
169
|
+
|
|
125
170
|
- **Classifier**: a full card for the active classifier (deadline, wait, health, credentials) and compact rows for the others under **Other classifiers**, then **Across sessions**.
|
|
171
|
+
|
|
172
|
+
<picture>
|
|
173
|
+
<source media="(prefers-color-scheme: dark)" srcset="images/desktop-pane-classifier-dark.png">
|
|
174
|
+
<img src="images/desktop-pane-classifier-light.png" alt="The Classifier tab: a card for the active classifier with its host, deadline and health, a row per other classifier with Set up and Use buttons, and the agreement counts across sessions." width="560">
|
|
175
|
+
</picture>
|
|
176
|
+
|
|
126
177
|
- **Usage**: period buttons, then Summary, Trend, Breakdown, Worth a look, Subagents, About these numbers and **Delete history**.
|
|
127
178
|
|
|
179
|
+
<picture>
|
|
180
|
+
<source media="(prefers-color-scheme: dark)" srcset="images/desktop-pane-usage-dark.png">
|
|
181
|
+
<img src="images/desktop-pane-usage-light.png" alt="The Usage tab: period buttons, a summary of cost against no routing, a breakdown by activity, a worth-a-look note, and a subagents table." width="560">
|
|
182
|
+
</picture>
|
|
183
|
+
|
|
184
|
+
|
|
128
185
|
Unsaved Routes and Policy changes sit in an **Unsaved changes** card at the bottom, a table of each setting before and after with **Discard** and **Save**; the last save and **Undo** follow it. **?** opens an **About the router** card. When the classifier needs attention, the header says so and the warning under the tabs says what to do. Saving, undoing and the numbers behind each card follow the terminal descriptions below.
|
|
129
186
|
|
|
187
|
+
At a phone's width the same trees narrow: the band shortens its route to fit and the cards truncate their notes.
|
|
188
|
+
|
|
189
|
+
<img src="images/mobile-band-and-now-dark.png" alt="The band and the Now tab at a phone width of 390 pixels: the band shortens its route to fit, and the cards stack with shorter text." width="300">
|
|
190
|
+
|
|
130
191
|
### The pane in the terminal
|
|
131
192
|
|
|
132
193
|
|
|
133
194
|
| Tab | What it answers |
|
|
134
195
|
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
135
|
-
| 1 Now | What runs next turn, and why, with a **pin**
|
|
196
|
+
| 1 Now | What runs next turn, and why, with a **pin** dropdown; the plan windows; this session's cost against no routing; context and cache. |
|
|
136
197
|
| 2 Routes | Which model runs: one grid of tiers by activities, the activity routing mode, and an editor for the selected cell. |
|
|
137
198
|
| 3 Policy | How readily the router changes models: the start tier, going down, going up, the activity threshold, the credits cap; the `router.json` path. |
|
|
138
199
|
| 4 Classifier | Which classifier to ask: one row per classifier to compare, the active one's deadline, wait, health and credentials, and the counts kept across sessions. |
|
|
@@ -142,11 +203,11 @@ Under the tab row, one slot shows the warnings on every tab: a project config th
|
|
|
142
203
|
|
|
143
204
|
The top line of every tab, `ROUTER [ ◉ on ] [ ○ off ] Jev ready · 347 ms`, shows the routing mode, switches it, and says whether the classifier is ready. Press `o` or `f` while the pane has focus. The tabs under it carry their digits, `[ 1 Now ] [ 2 Routes ] …`, and **?** shows what the numbers mean above the tab. In a pane too narrow for them, the tabs drop the digits (the keys still work), and then **?** moves to the end of the top line. While the warnings under the tabs name missing classifier credentials, the top line says `see below` instead of repeating them. When routing is unavailable, the top line reads `ROUTER unavailable Claude’s model is kept` with the reason under it, and offers no on or off: see [Troubleshooting](#troubleshooting).
|
|
144
205
|
|
|
145
|
-

|
|
146
207
|
|
|
147
|
-
The **Now** tab has four blocks, each with its name in capitals.
|
|
208
|
+
The **Now** tab has four blocks, each with its name in capitals. From 72 columns wide each block sits in a single-line box with its name as the first line; a narrower pane draws them as plain lines. The Policy controls and the active classifier on the Classifier tab are boxed the same way.
|
|
148
209
|
|
|
149
|
-
**NEXT TURN** answers "what runs next turn, and why". The first line is the tier meter, the model and effort, and the classifier's activity with its share, such as `code 84% debug 8%`. When an activity override runs, a line under it names the tier's own route. **why** gives the reason in the band's words and, beside it, the classifier's support against the bar the policy set and the switch cost: `↑ clearly stronger Jev 88% ≥ 82% · switch ≈ $0.48`. **pin**
|
|
210
|
+
**NEXT TURN** answers "what runs next turn, and why". The first line is the tier meter, the model and effort, and the classifier's activity with its share, such as `code 84% debug 8%`. When an activity override runs, a line under it names the tier's own route. **why** gives the reason in the band's words and, beside it, the classifier's support against the bar the policy set and the switch cost: `↑ clearly stronger Jev 88% ≥ 82% · switch ≈ $0.48`. **pin next turn to a tier** names the model that runs now, and one dropdown under it pins: **Pin to a tier**, then one entry per tier, low to high, each named by what it runs, such as `▂▄ Haiku·high 3%`, with the support the classifier gave it on the last turn; `▶` marks the tier that runs now. Picking a tier forces it for the next turn only, and the dropdown shows the pending pin until it applies; pick **No pin** to drop it. A line under the dropdown points to `/model`, with routing off, for models no tier routes to. With routing off, the block names Claude's model, `routing off · /model choice`, and the pins say they need routing on; nothing from an earlier routed turn stays.
|
|
150
211
|
|
|
151
212
|
**PLAN** appears on a Claude plan: Claude Code's 5-hour and 7-day windows as gauges, with when each resets. They turn yellow at 75% and red at 90%.
|
|
152
213
|
|
|
@@ -351,6 +412,21 @@ These thresholds are starting values. They are not tuned on data yet.
|
|
|
351
412
|
|
|
352
413
|
On Claude Code 2.1.322 an effort that the router changed inside a turn was not sent in the 6 cases found, while a changed model was, so the band and the decision record can name an effort that did not run. Claude Code sends an effort change on a tool-result step only when `CLAUDE_CODE_MODEL_CAPABILITIES=per_turn_effort` is set in its environment; the router does not set it. See [What we do not know yet](activity-routing.md#what-we-do-not-know-yet).
|
|
353
414
|
|
|
415
|
+
### When a model fails
|
|
416
|
+
|
|
417
|
+
When a turn ends on an API error that is the model's fault, the router holds that model out of routing for a while, so the next turns run another model. A toast says so once, such as `Opus 5.5 held out of routing: overloaded, 5 min`.
|
|
418
|
+
|
|
419
|
+
| Error Claude Code reports | Held out for |
|
|
420
|
+
| ------------------------- | ------------ |
|
|
421
|
+
| `rate_limit` | 5 minutes |
|
|
422
|
+
| `overloaded` | 5 minutes |
|
|
423
|
+
| `server_error` | 2 minutes |
|
|
424
|
+
| `model_not_found` | 1 hour |
|
|
425
|
+
|
|
426
|
+
A billing error, a rejected key or request, a cut-off answer and an unknown error hold nothing: another model would not help. Claude Code reports no retry-after, so the times are fixed.
|
|
427
|
+
|
|
428
|
+
While a model is held out, a turn whose route runs it, a pinned turn too, runs the nearest tier's route on another model at the turn's activity; of two tiers as near, the stronger. The switch toast, the band and the route line show `! held out`. The turn's own tool calls do not move it onto a held model either. When the hold ends, the next turn returns to the route it held out without waiting for votes or a checkpoint. A route that is not its tier's configured route, kept from before a routing mode change or a route edit, or your own model when no tier routes to it, is the exception: when the tier's configured route runs another model, that route takes over at once and stays after the hold. The failed request is not sent again: Claude Code reports the error after the turn has ended. A subagent's failure holds nothing. A compaction keeps the holds; a new session starts without them. With `"routingEngine": "auto"` no model is held and no toast shows: that engine does not route around holds.
|
|
429
|
+
|
|
354
430
|
### Read the activity on the pane
|
|
355
431
|
|
|
356
432
|
- **Now**: the first line of **NEXT TURN** names the classifier's activity with its share and the next answer, such as `code 84% debug 8%`. An `uncertain` answer is shown dim: it applies no activity. In `on`, a line under it names the cell when the route is an override, such as `code at low runs on Sonnet 5.5 · high · tier route Haiku 5.5 · high`, and **why** reads `↑ code` or `↓ ops` when the activity moved the route; a refused move, a hold, or a tier change keeps its reason.
|
|
@@ -375,7 +451,7 @@ On the **Classifier** tab, **ACROSS SESSIONS · since the last reset** shows the
|
|
|
375
451
|
| `/router mode default` | Clear the session's mode: the project's or the profile's applies again. |
|
|
376
452
|
| `/router decisions [n]` | Print this session's last `n` routing decisions, 20 by default. See [Routing decisions](#routing-decisions). |
|
|
377
453
|
| `/router line <off\|moves\|all>` | Choose when a turn leaves a [route line](#the-route-line) in the transcript. `moves` is the default. Kept across sessions. |
|
|
378
|
-
| `/model <name>` | Select a model and turn routing off. Use `/router auto` to turn it back on.
|
|
454
|
+
| `/model <name>` | Select a model and turn routing off. Use `/router auto` to turn it back on. The model picker and a model set from the SDK, an IDE or Remote Control do the same. |
|
|
379
455
|
| **Turn on** / **Turn off** on the band | The same as `/router auto` and `/router off`. |
|
|
380
456
|
| **on** / **off** on the pane (`o` / `f`) | The same as `/router auto` and `/router off`. |
|
|
381
457
|
| **pin** on the Now tab | Pin that tier for the next turn. Routing on must already be enabled. |
|
|
@@ -506,7 +582,7 @@ To stop routing for a session, run `/router off`. To keep tier routing but stop
|
|
|
506
582
|
| Status says `no API key` or `no API token` | The active classifier's plugin option is unset or unavailable to this process. | Select **Set up** in the pane, or run `/plugin configure router`. Save the option and start a new turn. |
|
|
507
583
|
| Status says `no account ID` | Clef, Clef Flash or Clef Omni is active without the Cloudflare account ID. | Run `/plugin configure router` and save the Cloudflare account ID. |
|
|
508
584
|
| Route stays on the current model | The classifier timed out, failed, is paused, or network policy refused it. | Read the status band and the pane header. Network policy refusal is not bypassed. |
|
|
509
|
-
| `/model` changed but routing stopped | Choosing a model turns routing off.
|
|
585
|
+
| `/model` changed but routing stopped | Choosing a model (`/model`, the model picker, or the SDK, an IDE or Remote Control) turns routing off. | Run `/router auto` to turn routing back on. |
|
|
510
586
|
| Selected provider file is missing | The provider name selects a file that does not exist. | Create that file in the active Claude Code profile directory. Use `{}` only for built-in profiles. See [Providers](providers.md). |
|
|
511
587
|
| A custom profile containing `{}` fails | No built-in model catalog exists for that provider name. | Define all four routes and their model entries. See the [custom profile example](providers.md#add-another-provider). |
|
|
512
588
|
| Router reports invalid configuration | The selected file is invalid, or project/local settings redirect the profile. | Inspect the file shown in the pane. Remove project/local `HOME`, `CLAUDE_CONFIG_DIR`, or `CLAUDE_ROUTER_PROVIDER` overrides. |
|
|
@@ -520,6 +596,6 @@ To stop routing for a session, run `/router off`. To keep tier routing but stop
|
|
|
520
596
|
| Pane reads `ROUTER unavailable` | Old gateway settings, an old Claude Code, or an invalid `router.json`. The line under it names which. | Fix the cause it names and restart. Until then every turn keeps Claude's model, and `/router auto`, `off`, `pin`, and `activities` reply with the reason and change nothing. |
|
|
521
597
|
| Context reads as unknown | The router lacks a reliable local estimate or current-history measurement. | Keep using the current model, or start a new history with a supported context estimate. |
|
|
522
598
|
|
|
523
|
-
When a session starts with the router unavailable, a toast says why (`Routing off: requires Claude Code 2.1.321 or newer. Claude’s model is kept.`). It shows once a day for each cause (old Claude Code, v0.8 gateway settings, a `router.json` that does not load) and never under `claude -p`. The band and the pane keep saying it.
|
|
599
|
+
When a session starts with the router unavailable, a toast says why (`Routing off: requires Claude Code 2.1.321 or newer. Claude’s model is kept.`). A desktop, VS Code or mobile surface that attaches later gets it once as well. It shows once a day for each cause (old Claude Code, v0.8 gateway settings, a `router.json` that does not load) and never under `claude -p`. The band and the pane keep saying it.
|
|
524
600
|
|
|
525
601
|
For the internal event flow and network deadline behavior, see [Architecture](architecture.md). For what the test traces do and do not show, see [Evaluation](evaluation.md).
|
package/hooks/native-router.mjs
CHANGED
|
@@ -76,6 +76,7 @@ import {
|
|
|
76
76
|
GATEWAY_CLEANUP,
|
|
77
77
|
GATEWAY_SETTINGS,
|
|
78
78
|
missingCredentials,
|
|
79
|
+
modelName,
|
|
79
80
|
NOT_A_TIER_REASON,
|
|
80
81
|
pinCard,
|
|
81
82
|
pluginIdOf,
|
|
@@ -95,6 +96,7 @@ import {
|
|
|
95
96
|
routingBucket,
|
|
96
97
|
stripReminders,
|
|
97
98
|
} from '../lib/facts.mjs';
|
|
99
|
+
import { activeHolds, holdModel, holdMs, holdText } from '../lib/failover.mjs';
|
|
98
100
|
import { applyMode, modeLabel, readProjectMode, resolveRoutingMode } from '../lib/modes.mjs';
|
|
99
101
|
import { renderPanel } from '../lib/panel.mjs';
|
|
100
102
|
import { sameTaskOf } from '../lib/policy.mjs';
|
|
@@ -315,6 +317,8 @@ function createRouter(options) {
|
|
|
315
317
|
turnDecisions: new Map(),
|
|
316
318
|
// The route the last routed turn ran, to tell whether the next one moved it; null at a session's start.
|
|
317
319
|
lastRoute: null,
|
|
320
|
+
// The model of the last main request sent: the one an API error that ends the turn failed on (holdFailedModel).
|
|
321
|
+
lastRequested: /** @type {string | null} */ (null),
|
|
318
322
|
decisionRecord: null,
|
|
319
323
|
trace: /** @type {TraceHold | null} */ (null),
|
|
320
324
|
traceFreshSession: null,
|
|
@@ -322,6 +326,8 @@ function createRouter(options) {
|
|
|
322
326
|
traceStartedSession: null,
|
|
323
327
|
traceFailures: 0,
|
|
324
328
|
traceOperations: new Map(),
|
|
329
|
+
// The surfaces that showed the unavailable toast this session, so an attach never repeats it on the same one.
|
|
330
|
+
noticeSurfaces: new Set(),
|
|
325
331
|
controllers: new Set(),
|
|
326
332
|
turnControllers: new Map(),
|
|
327
333
|
view: /** @type {Record<string, unknown> | null} */ (null),
|
|
@@ -2877,6 +2883,8 @@ async function* sendRouted($, router, e, next, { cfg, loop, loopVersion, session
|
|
|
2877
2883
|
else request.effort = loop.decision.effort;
|
|
2878
2884
|
if (cfg.routingEngine === 'shadow' && !next.signal.aborted && (await $.session.id()) === sessionId)
|
|
2879
2885
|
traceRequest(router, e, router.turnConfigs.get(e.turnId) ?? turn, request, 'auto', loop);
|
|
2886
|
+
// biome-ignore lint/nursery/useAtomicUpdates: the request sent last names the model, whatever ran before it
|
|
2887
|
+
router.lastRequested = request.model;
|
|
2880
2888
|
const response = yield* next(request);
|
|
2881
2889
|
if (!next.signal.aborted && (await $.session.id()) === sessionId)
|
|
2882
2890
|
await observeRouted($, router, { turnId: e.turnId, cfg, loop, loopVersion, request, response, nativeModel });
|
|
@@ -2959,6 +2967,10 @@ async function traceContinuation($, router, cfg, loop, e, traceInput) {
|
|
|
2959
2967
|
async function* stepMain($, router, e, next) {
|
|
2960
2968
|
if (!(await ensureInitialized($, router))) return yield* next(e);
|
|
2961
2969
|
if (e.agentId) return yield* stepAgent($, router, e, next);
|
|
2970
|
+
// A main request goes out as Claude Code built it unless sendRouted routes it, so its model is the one a failure
|
|
2971
|
+
// holds (holdFailedModel) until sendRouted names another.
|
|
2972
|
+
// biome-ignore lint/nursery/useAtomicUpdates: the request sent last names the model, whatever ran before it
|
|
2973
|
+
router.lastRequested = e.model;
|
|
2962
2974
|
const turn = router.turnConfigs.get(e.turnId) ?? (await turnConfigOf($, router));
|
|
2963
2975
|
const cfg = turn.config;
|
|
2964
2976
|
const [sessionId, nativeModel, view] = await Promise.all([$.session.id(), $.session.model(), readView($, router)]);
|
|
@@ -3035,6 +3047,7 @@ async function* stepMain($, router, e, next) {
|
|
|
3035
3047
|
contextKnown: context.known,
|
|
3036
3048
|
availableModels,
|
|
3037
3049
|
effort: e.effort,
|
|
3050
|
+
now: Date.now(),
|
|
3038
3051
|
};
|
|
3039
3052
|
loop =
|
|
3040
3053
|
cfg.routingEngine === 'auto'
|
|
@@ -3125,20 +3138,62 @@ function unavailableCause(error) {
|
|
|
3125
3138
|
|
|
3126
3139
|
// One toast when a session starts with routing unavailable, at most once a day per cause: the band says it too, but not
|
|
3127
3140
|
// once it is collapsed or scrolled away. Not for a headless run, which has no one to read it. The day is recorded before
|
|
3128
|
-
// the toast, so a toast no surface draws is not retried until tomorrow.
|
|
3141
|
+
// the toast, so a toast no surface draws is not retried until tomorrow. A surface that attaches later (desktop, VS Code,
|
|
3142
|
+
// mobile) gets it too, once per surface, once this session has shown it: it was not there to see the first. The day
|
|
3143
|
+
// record still gates the session's first toast, on whichever surface asks first.
|
|
3129
3144
|
async function noticeUnavailable($, router, e) {
|
|
3130
3145
|
const view = router.view;
|
|
3131
3146
|
if (view?.phase !== 'unavailable' || !e.isInteractive || !e.surface) return;
|
|
3147
|
+
if (router.noticeSurfaces.has(e.surface)) return;
|
|
3132
3148
|
try {
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3149
|
+
if (router.noticeSurfaces.size === 0) {
|
|
3150
|
+
const key = `${UNAVAILABLE_NOTICE_PREFIX}${unavailableCause(view.error)}`;
|
|
3151
|
+
const last = await $.store.get(key);
|
|
3152
|
+
const now = Date.now();
|
|
3153
|
+
if (Number.isFinite(last) && now - last >= 0 && now - last < UNAVAILABLE_NOTICE_INTERVAL_MS) return;
|
|
3154
|
+
await $.store.set(key, now);
|
|
3155
|
+
}
|
|
3156
|
+
router.noticeSurfaces.add(e.surface);
|
|
3138
3157
|
$.ui.toast(`Routing off: ${unavailableReason(view)}. Claude’s model is kept.`);
|
|
3139
3158
|
} catch {}
|
|
3140
3159
|
}
|
|
3141
3160
|
|
|
3161
|
+
const MODEL_SELECTED_MANUALLY = 'model selected manually';
|
|
3162
|
+
const MANUAL_SWITCH_SOURCES = new Set(['picker', 'sdk']);
|
|
3163
|
+
|
|
3164
|
+
// A person chose the session's model: routing turns off and keeps it.
|
|
3165
|
+
async function keepChosenModel($, router, reason) {
|
|
3166
|
+
await changeMode($, router, 'manual');
|
|
3167
|
+
await updateView($, router, { nativeModel: await $.session.model(), ...(reason ? { reason } : {}) });
|
|
3168
|
+
}
|
|
3169
|
+
|
|
3170
|
+
// A main turn ended on an API error (`StopFailure`): the request is lost, and Claude Code reports neither the model nor
|
|
3171
|
+
// a retry-after. An error that is the model's holds the model the last request ran out of routing for a while
|
|
3172
|
+
// (lib/failover.mjs), so the next turn runs another; the hold lives in the loop, which the table and shadow engines
|
|
3173
|
+
// read. The `auto` engine routes without holds, so it gets none and no toast claims one.
|
|
3174
|
+
async function holdFailedModel($, router, error) {
|
|
3175
|
+
// A failed hold changes no route; the turn's result stands.
|
|
3176
|
+
try {
|
|
3177
|
+
if (holdMs(error) === null || !(await ensureInitialized($, router))) return;
|
|
3178
|
+
if (router.config.routingEngine === 'auto') return;
|
|
3179
|
+
const model = router.lastRequested ?? (await $.session.model());
|
|
3180
|
+
const ref = { ...LOOP, id: 'main' };
|
|
3181
|
+
// A write that lost to a step's own write reads the loop again.
|
|
3182
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
3183
|
+
const { value: loop, version } = await $.state.get(ref);
|
|
3184
|
+
if (!loop) return;
|
|
3185
|
+
const now = Date.now();
|
|
3186
|
+
const held = holdModel(loop.held, model, error, now);
|
|
3187
|
+
const written = await $.state.set(ref, { ...loop, held }, { ifVersion: version });
|
|
3188
|
+
if (!written.isSet) continue;
|
|
3189
|
+
const hold = activeHolds(held, now)[model];
|
|
3190
|
+
if (hold && (await modeOf($, router)) === 'auto')
|
|
3191
|
+
$.ui.toast(`${modelName(model)} held out of routing: ${holdText(hold, now)}`);
|
|
3192
|
+
return;
|
|
3193
|
+
}
|
|
3194
|
+
} catch {}
|
|
3195
|
+
}
|
|
3196
|
+
|
|
3142
3197
|
async function ensureInitialized($, router) {
|
|
3143
3198
|
if (router.initialized) return true;
|
|
3144
3199
|
router.initializing ??= initializeSession($, router).finally(() => {
|
|
@@ -3158,27 +3213,38 @@ export function register(on, options) {
|
|
|
3158
3213
|
router.trace = null;
|
|
3159
3214
|
router.traceOperations.clear();
|
|
3160
3215
|
router.lastRoute = null;
|
|
3216
|
+
router.lastRequested = null;
|
|
3161
3217
|
router.initialized = false;
|
|
3218
|
+
router.noticeSurfaces.clear();
|
|
3162
3219
|
await ensureInitialized($, router);
|
|
3163
3220
|
await noticeUnavailable($, router, e);
|
|
3164
3221
|
return next(e);
|
|
3165
3222
|
});
|
|
3166
3223
|
|
|
3224
|
+
// The terminal's own attachment raises nothing; a desktop, VS Code or mobile surface attaches after session.start.
|
|
3225
|
+
on('session.attach', async ($, e, next) => {
|
|
3226
|
+
const result = await next(e);
|
|
3227
|
+
await noticeUnavailable($, router, { isInteractive: true, surface: e.surface });
|
|
3228
|
+
return result;
|
|
3229
|
+
});
|
|
3230
|
+
|
|
3167
3231
|
on('command.run', { command: 'model' }, async ($, e, next) => {
|
|
3168
3232
|
const result = await next(e);
|
|
3169
|
-
if (e.origin.kind !== 'plugin')
|
|
3170
|
-
await changeMode($, router, 'manual');
|
|
3171
|
-
await updateView($, router, { nativeModel: await $.session.model(), reason: 'model selected manually' });
|
|
3172
|
-
}
|
|
3233
|
+
if (e.origin.kind !== 'plugin') await keepChosenModel($, router, MODEL_SELECTED_MANUALLY);
|
|
3173
3234
|
return result;
|
|
3174
3235
|
});
|
|
3175
3236
|
|
|
3176
3237
|
on('config.set', { key: 'model' }, async ($, e, next) => {
|
|
3177
3238
|
const result = await next(e);
|
|
3178
|
-
if (!result.deny && e.origin.kind !== 'plugin')
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3239
|
+
if (!result.deny && e.origin.kind !== 'plugin') await keepChosenModel($, router);
|
|
3240
|
+
return result;
|
|
3241
|
+
});
|
|
3242
|
+
|
|
3243
|
+
// A switch the two hooks above never see: the model picker's shortcut, or set_model from the SDK, an IDE or Remote
|
|
3244
|
+
// Control. A 'command' switch is theirs (they know a plugin's own /model); 'auto' and 'resume' are no one's choice.
|
|
3245
|
+
on('classic.PostModelSwitch', async ($, e, next) => {
|
|
3246
|
+
const result = await next(e);
|
|
3247
|
+
if (MANUAL_SWITCH_SOURCES.has(e.source)) await keepChosenModel($, router, MODEL_SELECTED_MANUALLY);
|
|
3182
3248
|
return result;
|
|
3183
3249
|
});
|
|
3184
3250
|
|
|
@@ -3245,6 +3311,14 @@ export function register(on, options) {
|
|
|
3245
3311
|
return next(e);
|
|
3246
3312
|
});
|
|
3247
3313
|
|
|
3314
|
+
// Since 2.1.296 (present at the 2.1.321 floor): a turn that ended on an API error. A subagent's is not routed here.
|
|
3315
|
+
// A hook failure leaves the event to the hooks beneath, as without the router.
|
|
3316
|
+
on('classic.StopFailure', async ($, e, next) => {
|
|
3317
|
+
const result = await next(e);
|
|
3318
|
+
if (e.agent_id === undefined) await holdFailedModel($, router, e.error);
|
|
3319
|
+
return result;
|
|
3320
|
+
}).catch((_$, e, next) => next(e));
|
|
3321
|
+
|
|
3248
3322
|
on('session.compact', async ($, e, next) => {
|
|
3249
3323
|
const result = await next(e);
|
|
3250
3324
|
// Only the main conversation is routed, so an agent compaction changes nothing here.
|
package/lib/display.mjs
CHANGED
|
@@ -121,6 +121,7 @@ export const REASONS = {
|
|
|
121
121
|
'context-unknown': 'context is not measured reliably',
|
|
122
122
|
'context-full': 'the context is too full for any route, so Claude’s model is kept',
|
|
123
123
|
'model-unavailable': 'the requested model is not available',
|
|
124
|
+
'model-held': 'the model failed with an API error and is held out for a while',
|
|
124
125
|
pinned: 'one-turn model pin',
|
|
125
126
|
manual: 'routing did not choose this turn, so Claude’s model is kept',
|
|
126
127
|
'routing off': 'routing is off, so Claude’s model is kept',
|
|
@@ -222,6 +223,7 @@ export const SHORT_REASONS = {
|
|
|
222
223
|
'context-unknown': '= context unknown',
|
|
223
224
|
'context-full': '! context full',
|
|
224
225
|
'model-unavailable': '! model unavailable',
|
|
226
|
+
'model-held': '! held out',
|
|
225
227
|
'native-fallback': '! fallback',
|
|
226
228
|
pinned: '⏵ pinned',
|
|
227
229
|
manual: '= routing skipped',
|
package/lib/failover.mjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// API failover: a model whose request ended a turn on an API error is held out of routing for a while, so the next
|
|
2
|
+
// turn runs another model. Pure: the hook passes the error Claude Code classified (`StopFailure`'s `error`), the model
|
|
3
|
+
// and the clock.
|
|
4
|
+
|
|
5
|
+
const MINUTE = 60_000;
|
|
6
|
+
|
|
7
|
+
// How long each error holds the model out. Only errors that are the model's: busy, limited or failing on the provider's
|
|
8
|
+
// side, or not served at all. Claude Code does not report a retry-after, so the times are fixed. A model that is not
|
|
9
|
+
// found does not come back by itself; an hour bounds the hold in case it was a provider's outage. A billing error, a
|
|
10
|
+
// rejected key or request, a cut-off answer and an unknown error are not the model's, so another model would not help.
|
|
11
|
+
export const HOLD_MS = {
|
|
12
|
+
rate_limit: 5 * MINUTE,
|
|
13
|
+
overloaded: 5 * MINUTE,
|
|
14
|
+
server_error: 2 * MINUTE,
|
|
15
|
+
model_not_found: 60 * MINUTE,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// The words a notice uses for each error.
|
|
19
|
+
const ERROR_WORDS = {
|
|
20
|
+
rate_limit: 'rate limited',
|
|
21
|
+
overloaded: 'overloaded',
|
|
22
|
+
server_error: 'server error',
|
|
23
|
+
model_not_found: 'model not found',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** How long `error` holds the failed model out, in milliseconds, or null when it holds nothing. */
|
|
27
|
+
export const holdMs = (error) => (Object.hasOwn(HOLD_MS, error) ? HOLD_MS[error] : null);
|
|
28
|
+
|
|
29
|
+
/** The holds still running at `now`: a hold ends at its `until`. */
|
|
30
|
+
export function activeHolds(held, now) {
|
|
31
|
+
return Object.fromEntries(Object.entries(held ?? {}).filter(([, hold]) => hold.until > now));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The model ids held out at `now`. */
|
|
35
|
+
export const heldModels = (held, now) => Object.keys(activeHolds(held, now));
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The holds after `model` failed with `error` at `now`: expired holds dropped, and the model held for the error's time.
|
|
39
|
+
* A longer hold already running stays. An error that holds nothing changes no hold.
|
|
40
|
+
* @returns {Record<string, { error: string, until: number }>}
|
|
41
|
+
*/
|
|
42
|
+
export function holdModel(held, model, error, now) {
|
|
43
|
+
const kept = activeHolds(held, now);
|
|
44
|
+
const ms = holdMs(error);
|
|
45
|
+
if (ms === null || typeof model !== 'string' || !model) return kept;
|
|
46
|
+
const running = kept[model];
|
|
47
|
+
if (running && running.until >= now + ms) return kept;
|
|
48
|
+
return { ...kept, [model]: { error, until: now + ms } };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** "overloaded, 5 min": why a model is held out and for how long, rounded up to a minute. */
|
|
52
|
+
export function holdText(hold, now) {
|
|
53
|
+
const minutes = Math.max(1, Math.ceil((hold.until - now) / MINUTE));
|
|
54
|
+
return `${ERROR_WORDS[hold.error] ?? hold.error}, ${minutes} min`;
|
|
55
|
+
}
|
package/lib/route.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { ACTIVITIES, rank, resolveRoute, routeSpec, sameRoute, TIERS } from './config.mjs';
|
|
12
12
|
import * as costs from './cost.mjs';
|
|
13
13
|
import { clip, completedSince, extractFacts, stripReminders } from './facts.mjs';
|
|
14
|
+
import { heldModels } from './failover.mjs';
|
|
14
15
|
import { CONTEXT_FILL, decide, fitTier, initialState, sameTaskOf } from './policy.mjs';
|
|
15
16
|
import { canonicalModel } from './providers.mjs';
|
|
16
17
|
|
|
@@ -189,10 +190,14 @@ export function chooseRoute(config, loop, input) {
|
|
|
189
190
|
sameRoute(applied.route, resolveRoute(config, applied.tier, 'ops'))
|
|
190
191
|
)
|
|
191
192
|
applied.activity = 'ops';
|
|
192
|
-
|
|
193
|
+
// A route standing in for a held-out model serves this turn only, as a pin does: once the hold ends, the next turn
|
|
194
|
+
// runs the route it held out without passing a switching gate. Nor does the turn keep the votes or the escalation
|
|
195
|
+
// `decide` recorded for the held route, which never ran: the same failure still escalates once the hold ends.
|
|
196
|
+
const heldOut = applied.reason === 'model-held';
|
|
197
|
+
const kept = pin || !applied.tier || heldOut;
|
|
193
198
|
return {
|
|
194
199
|
...loop,
|
|
195
|
-
state: applied.state,
|
|
200
|
+
state: heldOut ? { ...loop.state, turn: loop.state.turn + 1 } : applied.state,
|
|
196
201
|
hasRoutedDecision: true,
|
|
197
202
|
lastRoute: kept ? loop.lastRoute : applied.tier,
|
|
198
203
|
lastActivity: kept ? activityOf(config, loop) : applied.activity,
|
|
@@ -236,6 +241,14 @@ function opsFloor(config, activity) {
|
|
|
236
241
|
// the mode changed: `off` is the 1.5 decision.
|
|
237
242
|
const activityOf = (config, loop) => (config.activityRouting === 'on' ? (loop.lastActivity ?? null) : null);
|
|
238
243
|
|
|
244
|
+
// A model an API error held out of routing at `now` (failover.mjs).
|
|
245
|
+
const isHeld = (loop, id, now) => heldModels(loop.held, now).some((model) => isSameModel(model, id));
|
|
246
|
+
// A model this turn cannot send to: one whose context window a request exceeded, or a held-out one.
|
|
247
|
+
const withheld = (loop, id, now) => loop.ineligible.includes(id) || isHeld(loop, id, now);
|
|
248
|
+
// Every tier, nearest to `tier` first; of two as near, the stronger.
|
|
249
|
+
const nearestTiers = (tier) =>
|
|
250
|
+
[...TIERS].sort((a, b) => Math.abs(rank(a) - rank(tier)) - Math.abs(rank(b) - rank(tier)) || rank(b) - rank(a));
|
|
251
|
+
|
|
239
252
|
// One decision (plan §5.2) for the cell `{ tier, activity }` it lands on. Outside `on` the activity is null throughout.
|
|
240
253
|
function routeTurn(config, loop, { facts, advice, pin, nativeModel, contextKnown, availableModels, now }) {
|
|
241
254
|
const last = {
|
|
@@ -249,9 +262,7 @@ function routeTurn(config, loop, { facts, advice, pin, nativeModel, contextKnown
|
|
|
249
262
|
// no longer applies (activity routing turned off).
|
|
250
263
|
const usable = (held) => {
|
|
251
264
|
const model = Object.hasOwn(config.models, held.model) ? config.models[held.model] : null;
|
|
252
|
-
return Boolean(
|
|
253
|
-
model && isModelAllowed(model.id, availableModels, nativeModel) && !loop.ineligible.includes(model.id),
|
|
254
|
-
);
|
|
265
|
+
return Boolean(model && isModelAllowed(model.id, availableModels, nativeModel) && !withheld(loop, model.id, now));
|
|
255
266
|
};
|
|
256
267
|
const inUse = loop.route && usable(loop.route) && (loop.lastActivity ?? null) === last.activity ? loop.route : null;
|
|
257
268
|
const incumbent = {
|
|
@@ -284,9 +295,10 @@ function routeTurn(config, loop, { facts, advice, pin, nativeModel, contextKnown
|
|
|
284
295
|
!shrinksUnmeasured(cell) &&
|
|
285
296
|
(!facts.hasImages || model.imageInput !== false) &&
|
|
286
297
|
isModelAllowed(model.id, availableModels, nativeModel) &&
|
|
287
|
-
!loop
|
|
298
|
+
!withheld(loop, model.id, now)
|
|
288
299
|
);
|
|
289
300
|
};
|
|
301
|
+
const heldOut = (cell) => isHeld(loop, specOf(cell).id, now);
|
|
290
302
|
const roomFor = (cell) =>
|
|
291
303
|
!contextKnown || costs.nextContextTokens(facts) <= specOf(cell).contextWindow * CONTEXT_FILL;
|
|
292
304
|
const fits = (cell) => runs(cell) && roomFor(cell);
|
|
@@ -305,16 +317,16 @@ function routeTurn(config, loop, { facts, advice, pin, nativeModel, contextKnown
|
|
|
305
317
|
// A cell labelled with another activity would run, and stick, a route this turn did not choose.
|
|
306
318
|
const native = cellForModel(config, nativeModel);
|
|
307
319
|
const acceptedActivity = result.floorActivity ?? result.activity;
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
320
|
+
const tierCell = (tier) => ({ tier, activity: acceptedActivity, floorActivity: result.floorActivity });
|
|
321
|
+
// A held-out model is back soon: the nearest tier stands in for it, not the last or the cheapest route.
|
|
322
|
+
const cells = heldOut(result)
|
|
323
|
+
? nearestTiers(result.tier).map(tierCell)
|
|
324
|
+
: [last, native && { ...native, floorActivity: null }, ...TIERS.map(tierCell)];
|
|
313
325
|
const fallback = cells.find(
|
|
314
326
|
(cell) => cell && (cell.activity === null || cell.activity === acceptedActivity) && fits(cell),
|
|
315
327
|
) ?? { tier: null, activity: null, floorActivity: null };
|
|
316
328
|
// Only the window failed: no route is withheld, the conversation is just too full for every one of them.
|
|
317
|
-
const reason = runs(result) ? 'context-full' : 'model-unavailable';
|
|
329
|
+
const reason = runs(result) ? 'context-full' : heldOut(result) ? 'model-held' : 'model-unavailable';
|
|
318
330
|
result = { ...result, ...fallback, reason, lateral: null };
|
|
319
331
|
}
|
|
320
332
|
const route = result.tier ? routeOf(result) : null;
|
|
@@ -484,6 +496,8 @@ export function observedMove(config, loop, { observed, facts, contextKnown, now
|
|
|
484
496
|
const tier = fitTier(config, decision.tier, costs.nextContextTokens(facts), routeFor);
|
|
485
497
|
const to = routeFor(tier);
|
|
486
498
|
if ((compareRoutes(config, to, from, facts.effort) ?? 0) <= 0) return loop;
|
|
499
|
+
// A held-out model stays out for the rest of the turn too: routeTurn already kept the turn off it.
|
|
500
|
+
if (isHeld(loop, routeSpec(config, to).id, now)) return loop;
|
|
487
501
|
// Without a reliable reading of the context, a smaller window might overflow, as in routeTurn.
|
|
488
502
|
const window = (route) => routeSpec(config, route).contextWindow;
|
|
489
503
|
if ((!contextKnown || !loop.historyMeasured) && window(to) < window(from)) return loop;
|
|
@@ -510,11 +524,11 @@ export function observedMove(config, loop, { observed, facts, contextKnown, now
|
|
|
510
524
|
}
|
|
511
525
|
|
|
512
526
|
// A tool continuation keeps the turn's route and activity; only the context, the model list, or the turn's own tool
|
|
513
|
-
// calls (observedMove) can move it.
|
|
527
|
+
// calls (observedMove) can move it. A move never lands on a model held out at `now`.
|
|
514
528
|
export function continueRoute(
|
|
515
529
|
current,
|
|
516
530
|
loop,
|
|
517
|
-
{ nativeModel, contextTokens, contextKnown, availableModels, effort, hasImages = false },
|
|
531
|
+
{ nativeModel, contextTokens, contextKnown, availableModels, effort, hasImages = false, now },
|
|
518
532
|
) {
|
|
519
533
|
if (!loop.decision) return loop;
|
|
520
534
|
// A fit to another tier serves this turn only: `loop.route` stays the route of `lastRoute`, as the tier does.
|
|
@@ -555,7 +569,7 @@ export function continueRoute(
|
|
|
555
569
|
return (
|
|
556
570
|
model.imageInput !== false &&
|
|
557
571
|
isModelAllowed(model.id, availableModels, nativeModel) &&
|
|
558
|
-
!loop
|
|
572
|
+
!withheld(loop, model.id, now) &&
|
|
559
573
|
(contextKnown ? contextTokens <= model.contextWindow * CONTEXT_FILL : model.contextWindow >= runningWindow)
|
|
560
574
|
);
|
|
561
575
|
});
|
|
@@ -571,7 +585,7 @@ export function continueRoute(
|
|
|
571
585
|
reason: 'model-unavailable',
|
|
572
586
|
};
|
|
573
587
|
}
|
|
574
|
-
if (!isModelAllowed(decision.model, availableModels, nativeModel) || loop
|
|
588
|
+
if (!isModelAllowed(decision.model, availableModels, nativeModel) || withheld(loop, decision.model, now)) {
|
|
575
589
|
decision = {
|
|
576
590
|
...decision,
|
|
577
591
|
tier: null,
|
|
@@ -200,15 +200,19 @@ export function graphicalFrame(ui, frame, tabs, tab, actions, content) {
|
|
|
200
200
|
alignItems: 'center',
|
|
201
201
|
gap: 'sm',
|
|
202
202
|
children: [
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
// The kit's segmented control, as the title row's On | Off: the keys stay tab-<id> and the hotkeys the digits.
|
|
204
|
+
ui.choice({
|
|
205
|
+
key: 'tab',
|
|
206
|
+
options: tabs.map(({ id, key, label }) => ({
|
|
207
|
+
value: id,
|
|
205
208
|
key: `tab-${id}`,
|
|
206
|
-
label: `${label}${unsaved[id] ? ' ●' : ''}`,
|
|
207
209
|
hotkey: key,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
label: `${label}${unsaved[id] ? ' ●' : ''}`,
|
|
211
|
+
})),
|
|
212
|
+
selected: tab,
|
|
213
|
+
onPick: actions.tab,
|
|
214
|
+
gap: 'xs',
|
|
215
|
+
}),
|
|
212
216
|
Button({ key: 'help', label: '?', variant: frame.helpOpen ? 'primary' : 'secondary', onPress: actions.help }),
|
|
213
217
|
],
|
|
214
218
|
});
|
package/lib/ui/graphical/now.mjs
CHANGED
|
@@ -127,7 +127,11 @@ function nextCard(ui, next) {
|
|
|
127
127
|
Box({
|
|
128
128
|
flexDirection: 'column',
|
|
129
129
|
gap: 'sm',
|
|
130
|
-
children: [
|
|
130
|
+
children: [
|
|
131
|
+
ui.muted(ui.say(next.pinHead), { size: 'footnote', wrap: 'wrap' }),
|
|
132
|
+
pinRow(ui, next),
|
|
133
|
+
ui.muted(ui.say(next.pinNote), { size: 'footnote' }),
|
|
134
|
+
],
|
|
131
135
|
}),
|
|
132
136
|
]);
|
|
133
137
|
}
|
|
@@ -158,8 +162,8 @@ function pinRow(ui, next) {
|
|
|
158
162
|
Box({ flexShrink: 0, children: [ui.tierMeter(pin.tier, 'lit')] }),
|
|
159
163
|
Button({
|
|
160
164
|
key: `pin-${pin.tier}`,
|
|
161
|
-
label:
|
|
162
|
-
children: [ui.text(
|
|
165
|
+
label: pin.route,
|
|
166
|
+
children: [ui.text(pin.route, { wrap: 'truncate-end' })],
|
|
163
167
|
variant: next.pendingPin === pin.tier ? 'primary' : 'secondary',
|
|
164
168
|
onPress: () => next.pick(pin.tier),
|
|
165
169
|
}),
|