@weave-os/router 0.2.29 → 0.2.31
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 +20 -16
- package/bin.js +54 -11
- package/cc-statusline.sh +269 -56
- package/codex-skills/force-parent/SKILL.md +23 -0
- package/codex-skills/force-parent/scripts/emit.sh +7 -0
- package/codex-skills/router-models/SKILL.md +1 -1
- package/codex-status.sh +312 -48
- package/codex-toggle.sh +1 -1
- package/commands/force-parent.md +6 -0
- package/commands/models.md +1 -1
- package/commands/router-models.md +1 -1
- package/directives.tsv +1 -0
- package/install.sh +1572 -221
- package/package.json +8 -2
- package/pi-router/README.md +5 -3
- package/pi-router/package.json +2 -1
- package/pi-router/src/force-model.ts +109 -38
- package/pi-router/src/pricing.generated.ts +8 -3
- package/pi-router/src/routed-model.ts +51 -7
- package/pi-router/src/ui.ts +3 -3
- package/uninstall.sh +172 -12
- package/windows.js +546 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weave-os/router",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.31",
|
|
4
4
|
"description": "One-command installer that points Claude Code, Codex, opencode, or pi at the Weave Router. For pi it also ships the routing extension, loaded via pi.extensions.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"weave-router": "bin.js",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"bin.js",
|
|
19
|
+
"windows.js",
|
|
19
20
|
"install.sh",
|
|
20
21
|
"uninstall.sh",
|
|
21
22
|
"cc-statusline.sh",
|
|
@@ -76,5 +77,10 @@
|
|
|
76
77
|
"llm-router",
|
|
77
78
|
"pi",
|
|
78
79
|
"pi-package"
|
|
79
|
-
]
|
|
80
|
+
],
|
|
81
|
+
"dependencies": {
|
|
82
|
+
"@decimalturn/toml-patch": "3.3.0",
|
|
83
|
+
"isomorphic-git": "1.43.1",
|
|
84
|
+
"smol-toml": "1.9.0"
|
|
85
|
+
}
|
|
80
86
|
}
|
package/pi-router/README.md
CHANGED
|
@@ -19,7 +19,7 @@ That writes `~/.pi/agent/models.json` (the `weave` provider), adds
|
|
|
19
19
|
the key in `~/.pi/agent/.weave_router_key`. pi auto-installs `@weave-os/router`
|
|
20
20
|
from npm on next start and loads this extension via its `pi.extensions` field.
|
|
21
21
|
Plain `pi` then connects to the installed endpoint, normally
|
|
22
|
-
`https://router.
|
|
22
|
+
`https://router.weaveos.com`; it does not start a local Python proxy.
|
|
23
23
|
|
|
24
24
|
## What it does
|
|
25
25
|
|
|
@@ -32,8 +32,10 @@ Plain `pi` then connects to the installed endpoint, normally
|
|
|
32
32
|
selects the model per request. You don't pick a model — the router does.
|
|
33
33
|
- **Force-model commands.** `/fm <model>` and `/force-model <model>` pin the
|
|
34
34
|
current router session; `/ufm` and `/unforce-model` resume automatic routing.
|
|
35
|
-
The
|
|
36
|
-
|
|
35
|
+
The status records `last pin: <model>` alongside response attribution after
|
|
36
|
+
a completed acknowledgment. This is reachable branch history, not a query
|
|
37
|
+
of the router's current pin. Structured response headers drive new history;
|
|
38
|
+
older transcripts retain explicit force/clear command acknowledgment support.
|
|
37
39
|
- **Beta routing toggle.** `/beta` toggles the router's beta HMM strategy for
|
|
38
40
|
the current session. The router confirms whether beta routing is enabled or
|
|
39
41
|
disabled; run `/beta` again to switch back.
|
package/pi-router/package.json
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* directives as extension commands and forward one canonical user turn.
|
|
4
4
|
*
|
|
5
5
|
* The router remains authoritative for aliases, validation, canonical model
|
|
6
|
-
* ids, and pin persistence. UI
|
|
7
|
-
* pairs on the reachable Pi branch
|
|
6
|
+
* ids, and pin persistence. UI history uses structured outcomes and legacy
|
|
7
|
+
* command/response pairs on the reachable Pi branch because Pi records the
|
|
8
8
|
* selected model handle on assistant messages rather than the response model.
|
|
9
9
|
*/
|
|
10
10
|
|
|
@@ -14,6 +14,26 @@ import type {
|
|
|
14
14
|
SessionEntry,
|
|
15
15
|
} from "@mariozechner/pi-coding-agent";
|
|
16
16
|
|
|
17
|
+
export const ROUTER_COMMAND_HEADER = "x-weave-router-command";
|
|
18
|
+
export const ROUTER_COMMAND_ENTRY_TYPE = "weave-router-command";
|
|
19
|
+
|
|
20
|
+
const COMMAND_ID = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i;
|
|
21
|
+
const ROUTER_COMMANDS = ["force_model", "router_session", "router_models", "router_feedback", "loop_stop"] as const;
|
|
22
|
+
type RouterCommand = (typeof ROUTER_COMMANDS)[number];
|
|
23
|
+
type CommandDisposition = "accepted" | "rejected";
|
|
24
|
+
|
|
25
|
+
export type RouterPinTransition =
|
|
26
|
+
| { transition: "applied"; model: string; provider: string; effort?: string }
|
|
27
|
+
| { transition: "cleared" | "unchanged" };
|
|
28
|
+
|
|
29
|
+
export interface RouterCommandOutcome {
|
|
30
|
+
version: 1;
|
|
31
|
+
id: string;
|
|
32
|
+
command: RouterCommand;
|
|
33
|
+
disposition: CommandDisposition;
|
|
34
|
+
pin: RouterPinTransition;
|
|
35
|
+
}
|
|
36
|
+
|
|
17
37
|
export type ForceModelTransition =
|
|
18
38
|
| { kind: "applied"; model: string }
|
|
19
39
|
| { kind: "cleared" }
|
|
@@ -21,77 +41,118 @@ export type ForceModelTransition =
|
|
|
21
41
|
|
|
22
42
|
type ForceModelDirective = "force" | "clear";
|
|
23
43
|
|
|
44
|
+
function record(value: unknown): value is Record<string, unknown> {
|
|
45
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function displayToken(value: unknown): value is string {
|
|
49
|
+
return typeof value === "string" && /^[A-Za-z0-9._:/-]{1,128}$/.test(value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isRouterCommandOutcome(value: unknown): value is RouterCommandOutcome {
|
|
53
|
+
if (!record(value) || value.version !== 1 || typeof value.id !== "string" ||
|
|
54
|
+
!COMMAND_ID.test(value.id) ||
|
|
55
|
+
!ROUTER_COMMANDS.some((command) => command === value.command) ||
|
|
56
|
+
(value.disposition !== "accepted" && value.disposition !== "rejected") || !record(value.pin)) return false;
|
|
57
|
+
const pin = value.pin;
|
|
58
|
+
if (value.disposition === "rejected" && pin.transition !== "unchanged") return false;
|
|
59
|
+
if (pin.transition === "applied") {
|
|
60
|
+
return value.command === "force_model" && displayToken(pin.model) && displayToken(pin.provider) &&
|
|
61
|
+
(pin.effort === undefined || (typeof pin.effort === "string" && /^[A-Za-z0-9_-]{1,32}$/.test(pin.effort)));
|
|
62
|
+
}
|
|
63
|
+
return (pin.transition === "unchanged" ||
|
|
64
|
+
(pin.transition === "cleared" && value.command === "force_model")) &&
|
|
65
|
+
pin.model === undefined && pin.provider === undefined && pin.effort === undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function parseRouterCommandHeader(header: string): RouterCommandOutcome | undefined {
|
|
69
|
+
if (header.length === 0 || header.length > 4096 || !/^[A-Za-z0-9_-]+$/.test(header)) return undefined;
|
|
70
|
+
try {
|
|
71
|
+
const decoded = Buffer.from(header, "base64url");
|
|
72
|
+
if (decoded.toString("base64url") !== header) return undefined;
|
|
73
|
+
const outcome: unknown = JSON.parse(decoded.toString("utf8"));
|
|
74
|
+
return isRouterCommandOutcome(outcome) ? outcome : undefined;
|
|
75
|
+
} catch {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
24
80
|
function messageText(message: unknown): string | undefined {
|
|
25
|
-
if (!
|
|
81
|
+
if (!record(message)) return undefined;
|
|
26
82
|
const content = message.content;
|
|
27
83
|
if (typeof content === "string") return content;
|
|
28
84
|
if (!Array.isArray(content)) return undefined;
|
|
29
85
|
return content
|
|
30
|
-
.filter(
|
|
31
|
-
(block)
|
|
32
|
-
Boolean(
|
|
33
|
-
block &&
|
|
34
|
-
typeof block === "object" &&
|
|
35
|
-
"type" in block &&
|
|
36
|
-
block.type === "text" &&
|
|
37
|
-
"text" in block &&
|
|
38
|
-
typeof block.text === "string",
|
|
39
|
-
),
|
|
40
|
-
)
|
|
86
|
+
.filter((block): block is { type: "text"; text: string } =>
|
|
87
|
+
record(block) && block.type === "text" && typeof block.text === "string")
|
|
41
88
|
.map((block) => block.text)
|
|
42
89
|
.join("\n");
|
|
43
90
|
}
|
|
44
91
|
|
|
45
92
|
export function parseForceModelDirective(text: string): ForceModelDirective | undefined {
|
|
46
93
|
const command = text.trim();
|
|
47
|
-
if (/^\/(?:force-model|fm)\s+\S+/i.test(command)) return "force";
|
|
94
|
+
if (/^\/(?:force-model|force-parent|fm)\s+\S+/i.test(command)) return "force";
|
|
48
95
|
if (/^\/(?:unforce-model|ufm)$/i.test(command)) return "clear";
|
|
49
96
|
return undefined;
|
|
50
97
|
}
|
|
51
98
|
|
|
52
99
|
export function parseForceModelAcknowledgement(text: string): ForceModelTransition | undefined {
|
|
53
|
-
const applied =
|
|
100
|
+
const applied = /^(?:(?:✦ \*\*Weave Router\*\* →|Weave Router:)\s+)?force-(?:model|parent) applied:\s+([^\s()]+)/i.exec(text.trim());
|
|
54
101
|
if (applied) return { kind: "applied", model: applied[1] };
|
|
55
|
-
if (
|
|
102
|
+
if (/^(?:(?:✦ \*\*Weave Router\*\* →|Weave Router:)\s+)?force-model cleared\b/i.test(text.trim())) return { kind: "cleared" };
|
|
56
103
|
if (/is(?:n't| not) a recognized model/i.test(text)) return { kind: "noop" };
|
|
57
104
|
return undefined;
|
|
58
105
|
}
|
|
59
106
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Reconstruct the effective router pin on the currently reachable branch. */
|
|
67
|
-
export function forcedModelFromBranch(entries: readonly SessionEntry[]): string | undefined {
|
|
68
|
-
let forcedModel: string | undefined;
|
|
107
|
+
/** Reconstruct acknowledged pin history on the reachable branch, never current server state. */
|
|
108
|
+
export function lastPinFromBranch(entries: readonly SessionEntry[]): string | undefined {
|
|
109
|
+
let lastPin: string | undefined;
|
|
69
110
|
let pendingDirective: ForceModelDirective | undefined;
|
|
70
|
-
|
|
111
|
+
const appliedOutcomes = new Set<string>();
|
|
112
|
+
const structuredResponses = new Set<string>();
|
|
71
113
|
for (const entry of entries) {
|
|
114
|
+
if (entry.type !== "custom" || entry.customType !== ROUTER_COMMAND_ENTRY_TYPE) continue;
|
|
115
|
+
if (isRouterCommandOutcome(entry.data)) structuredResponses.add(`msg_router_cmd_${entry.data.id}`);
|
|
116
|
+
else if (record(entry.data) && typeof entry.data.responseId === "string") structuredResponses.add(entry.data.responseId);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
for (const [index, entry] of entries.entries()) {
|
|
120
|
+
if (entry.type === "custom" && entry.customType === ROUTER_COMMAND_ENTRY_TYPE) {
|
|
121
|
+
pendingDirective = undefined;
|
|
122
|
+
if (!isRouterCommandOutcome(entry.data) || appliedOutcomes.has(entry.data.id)) continue;
|
|
123
|
+
appliedOutcomes.add(entry.data.id);
|
|
124
|
+
if (entry.data.pin.transition === "applied") {
|
|
125
|
+
lastPin = entry.data.pin.model + (entry.data.pin.effort ? `:${entry.data.pin.effort}` : "");
|
|
126
|
+
} else if (entry.data.pin.transition === "cleared") lastPin = undefined;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
72
129
|
if (entry.type !== "message") continue;
|
|
73
130
|
if (entry.message.role === "user") {
|
|
74
131
|
pendingDirective = parseForceModelDirective(messageText(entry.message) ?? "");
|
|
75
132
|
continue;
|
|
76
133
|
}
|
|
77
134
|
if (entry.message.role !== "assistant") continue;
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
135
|
+
const annotation = entries[index + 1];
|
|
136
|
+
const responseId = entry.message.responseId;
|
|
137
|
+
const structuredResponse = responseId?.startsWith("msg_router_cmd_") &&
|
|
138
|
+
COMMAND_ID.test(responseId.slice("msg_router_cmd_".length));
|
|
139
|
+
if (structuredResponse || (responseId && structuredResponses.has(responseId)) ||
|
|
140
|
+
(annotation?.type === "custom" && annotation.customType === ROUTER_COMMAND_ENTRY_TYPE)) {
|
|
141
|
+
// Structured responses never fall back to acknowledgment prose.
|
|
142
|
+
pendingDirective = undefined;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (entry.message.stopReason !== "stop") {
|
|
82
146
|
pendingDirective = undefined;
|
|
83
147
|
continue;
|
|
84
148
|
}
|
|
85
149
|
if (!pendingDirective) continue;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (transition?.kind === "
|
|
89
|
-
else if (transition?.kind === "cleared" && pendingDirective === "clear") forcedModel = undefined;
|
|
90
|
-
// Rejected force-model commands intentionally retain the previous pin.
|
|
150
|
+
const transition = parseForceModelAcknowledgement(messageText(entry.message) ?? "");
|
|
151
|
+
if (transition?.kind === "applied" && pendingDirective === "force") lastPin = transition.model;
|
|
152
|
+
else if (transition?.kind === "cleared" && pendingDirective === "clear") lastPin = undefined;
|
|
91
153
|
pendingDirective = undefined;
|
|
92
154
|
}
|
|
93
|
-
|
|
94
|
-
return forcedModel;
|
|
155
|
+
return lastPin;
|
|
95
156
|
}
|
|
96
157
|
|
|
97
158
|
function sendRouterCommand(pi: ExtensionAPI, command: string, ctx: ExtensionCommandContext): void {
|
|
@@ -117,6 +178,16 @@ export function registerForceModelCommands(pi: ExtensionAPI): void {
|
|
|
117
178
|
handler: forceModel,
|
|
118
179
|
});
|
|
119
180
|
}
|
|
181
|
+
pi.registerCommand("force-parent", {
|
|
182
|
+
description: "Pin only this parent thread while subagents route automatically",
|
|
183
|
+
handler: async (args, ctx) => {
|
|
184
|
+
if (!args.trim()) {
|
|
185
|
+
ctx.ui.notify("Usage: /force-parent <model-id>", "warning");
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
sendRouterCommand(pi, `/force-parent ${args.trim()}`, ctx);
|
|
189
|
+
},
|
|
190
|
+
});
|
|
120
191
|
for (const name of ["ufm", "unforce-model"]) {
|
|
121
192
|
pi.registerCommand(name, {
|
|
122
193
|
description: "Clear this session's forced Weave Router model",
|
|
@@ -7,12 +7,13 @@ export interface ModelPricing {
|
|
|
7
7
|
cacheReadMultiplier: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const PRICING_VERSION = "catalog-sha256:
|
|
10
|
+
export const PRICING_VERSION = "catalog-sha256:3b753718c0db1fdc";
|
|
11
11
|
|
|
12
12
|
export const MODEL_PRICING: Readonly<Record<string, ModelPricing>> = Object.freeze({
|
|
13
13
|
"claude-fable-5": { inputUsdPerMillion: 10, outputUsdPerMillion: 50, cacheReadMultiplier: 0.1 },
|
|
14
14
|
"claude-fable-5-1": { inputUsdPerMillion: 10, outputUsdPerMillion: 50, cacheReadMultiplier: 0.025 },
|
|
15
15
|
"claude-haiku-4-5": { inputUsdPerMillion: 1, outputUsdPerMillion: 5, cacheReadMultiplier: 0.1 },
|
|
16
|
+
"claude-haiku-5-5": { inputUsdPerMillion: 0.1, outputUsdPerMillion: 0.5, cacheReadMultiplier: 0.1 },
|
|
16
17
|
"claude-opus-4-0": { inputUsdPerMillion: 15, outputUsdPerMillion: 75, cacheReadMultiplier: 0.1 },
|
|
17
18
|
"claude-opus-4-1": { inputUsdPerMillion: 15, outputUsdPerMillion: 75, cacheReadMultiplier: 0.1 },
|
|
18
19
|
"claude-opus-4-5": { inputUsdPerMillion: 5, outputUsdPerMillion: 25, cacheReadMultiplier: 0.1 },
|
|
@@ -23,7 +24,7 @@ export const MODEL_PRICING: Readonly<Record<string, ModelPricing>> = Object.free
|
|
|
23
24
|
"claude-opus-5-5": { inputUsdPerMillion: 4, outputUsdPerMillion: 20, cacheReadMultiplier: 0.05 },
|
|
24
25
|
"claude-sonnet-4-5": { inputUsdPerMillion: 3, outputUsdPerMillion: 15, cacheReadMultiplier: 0.1 },
|
|
25
26
|
"claude-sonnet-4-6": { inputUsdPerMillion: 3, outputUsdPerMillion: 15, cacheReadMultiplier: 0.1 },
|
|
26
|
-
"claude-sonnet-5": { inputUsdPerMillion:
|
|
27
|
+
"claude-sonnet-5": { inputUsdPerMillion: 2, outputUsdPerMillion: 10, cacheReadMultiplier: 0.1 },
|
|
27
28
|
"claude-sonnet-5-5": { inputUsdPerMillion: 2, outputUsdPerMillion: 10, cacheReadMultiplier: 0.1 },
|
|
28
29
|
"deepseek/deepseek-v4-flash": { inputUsdPerMillion: 0.14, outputUsdPerMillion: 0.28, cacheReadMultiplier: 0.1 },
|
|
29
30
|
"deepseek/deepseek-v4-pro": { inputUsdPerMillion: 1.74, outputUsdPerMillion: 3.48, cacheReadMultiplier: 0.0862 },
|
|
@@ -43,6 +44,7 @@ export const MODEL_PRICING: Readonly<Record<string, ModelPricing>> = Object.free
|
|
|
43
44
|
"gemini-3.6-flash": { inputUsdPerMillion: 1.5, outputUsdPerMillion: 7.5, cacheReadMultiplier: 0.1 },
|
|
44
45
|
"gemini-3.7-flash": { inputUsdPerMillion: 1.5, outputUsdPerMillion: 7.5, cacheReadMultiplier: 0.1 },
|
|
45
46
|
"gemini-3.8-flash": { inputUsdPerMillion: 1.5, outputUsdPerMillion: 7.5, cacheReadMultiplier: 0.1 },
|
|
47
|
+
"gemini-4-argon": { inputUsdPerMillion: 2, outputUsdPerMillion: 10, cacheReadMultiplier: 0.1 },
|
|
46
48
|
"google/gemma-4-26b-a4b-it": { inputUsdPerMillion: 0.15, outputUsdPerMillion: 0.6, cacheReadMultiplier: 0.1 },
|
|
47
49
|
"gpt-4.1": { inputUsdPerMillion: 2, outputUsdPerMillion: 8, cacheReadMultiplier: 0.25 },
|
|
48
50
|
"gpt-4.1-mini": { inputUsdPerMillion: 0.4, outputUsdPerMillion: 1.6, cacheReadMultiplier: 0.25 },
|
|
@@ -70,17 +72,20 @@ export const MODEL_PRICING: Readonly<Record<string, ModelPricing>> = Object.free
|
|
|
70
72
|
"gpt-6-luna": { inputUsdPerMillion: 0.1, outputUsdPerMillion: 0.5, cacheReadMultiplier: 0.1 },
|
|
71
73
|
"gpt-6-sol": { inputUsdPerMillion: 2, outputUsdPerMillion: 10, cacheReadMultiplier: 0.1 },
|
|
72
74
|
"gpt-6.1-sol": { inputUsdPerMillion: 2, outputUsdPerMillion: 10, cacheReadMultiplier: 0.05 },
|
|
75
|
+
"gpt-6.1-terra": { inputUsdPerMillion: 1, outputUsdPerMillion: 5, cacheReadMultiplier: 0.05 },
|
|
73
76
|
"grok-4.5": { inputUsdPerMillion: 2, outputUsdPerMillion: 6, cacheReadMultiplier: 0.25 },
|
|
74
77
|
"grok-4.6": { inputUsdPerMillion: 2, outputUsdPerMillion: 6, cacheReadMultiplier: 0.25 },
|
|
75
78
|
"grok-4.7": { inputUsdPerMillion: 2, outputUsdPerMillion: 6, cacheReadMultiplier: 0.25 },
|
|
76
79
|
"inclusionai/ling-3.0-flash": { inputUsdPerMillion: 0.06, outputUsdPerMillion: 0.18, cacheReadMultiplier: 0.2 },
|
|
77
80
|
"minimax/minimax-m2.7": { inputUsdPerMillion: 0.3, outputUsdPerMillion: 1.2, cacheReadMultiplier: 0.2 },
|
|
78
81
|
"minimax/minimax-m3": { inputUsdPerMillion: 0.3, outputUsdPerMillion: 1.2, cacheReadMultiplier: 0.2 },
|
|
82
|
+
"minimax/minimax-m3.1-flash": { inputUsdPerMillion: 0.15, outputUsdPerMillion: 0.6, cacheReadMultiplier: 0.1 },
|
|
79
83
|
"mistralai/mistral-small-2603": { inputUsdPerMillion: 0.2, outputUsdPerMillion: 0.6, cacheReadMultiplier: 0.1 },
|
|
80
84
|
"moonshotai/kimi-k2.5": { inputUsdPerMillion: 0.6, outputUsdPerMillion: 3, cacheReadMultiplier: 0.5 },
|
|
81
85
|
"moonshotai/kimi-k2.6": { inputUsdPerMillion: 0.95, outputUsdPerMillion: 4, cacheReadMultiplier: 0.1684 },
|
|
82
86
|
"moonshotai/kimi-k2.7": { inputUsdPerMillion: 0.95, outputUsdPerMillion: 4, cacheReadMultiplier: 0.2 },
|
|
83
87
|
"moonshotai/kimi-k3": { inputUsdPerMillion: 3, outputUsdPerMillion: 15, cacheReadMultiplier: 0.1 },
|
|
88
|
+
"moonshotai/kimi-k3.1": { inputUsdPerMillion: 2, outputUsdPerMillion: 10, cacheReadMultiplier: 0.1 },
|
|
84
89
|
"muse-spark-1.3": { inputUsdPerMillion: 1.25, outputUsdPerMillion: 4.25, cacheReadMultiplier: 0.12 },
|
|
85
90
|
"qwen/qwen3-235b-a22b-2507": { inputUsdPerMillion: 0.2266, outputUsdPerMillion: 0.9064, cacheReadMultiplier: 0.5 },
|
|
86
91
|
"qwen/qwen3-30b-a3b-instruct-2507": { inputUsdPerMillion: 0.15, outputUsdPerMillion: 0.6, cacheReadMultiplier: 0.1684 },
|
|
@@ -92,7 +97,7 @@ export const MODEL_PRICING: Readonly<Record<string, ModelPricing>> = Object.free
|
|
|
92
97
|
"qwen/qwen3.7-plus": { inputUsdPerMillion: 0.4, outputUsdPerMillion: 1.6, cacheReadMultiplier: 0.2 },
|
|
93
98
|
"qwen/qwen3.8-max": { inputUsdPerMillion: 2, outputUsdPerMillion: 6, cacheReadMultiplier: 0.125 },
|
|
94
99
|
"xiaomi/mimo-v2.5-pro": { inputUsdPerMillion: 1, outputUsdPerMillion: 3, cacheReadMultiplier: 0.1 },
|
|
95
|
-
"xiaomi/mimo-v2.6-flash": { inputUsdPerMillion: 0.
|
|
100
|
+
"xiaomi/mimo-v2.6-flash": { inputUsdPerMillion: 0.13, outputUsdPerMillion: 0.28, cacheReadMultiplier: 0.015384615384615385 },
|
|
96
101
|
"xiaomi/mimo-v2.6-pro": { inputUsdPerMillion: 0.435, outputUsdPerMillion: 0.87, cacheReadMultiplier: 0.00827586 },
|
|
97
102
|
"z-ai/glm-5": { inputUsdPerMillion: 1, outputUsdPerMillion: 3.2, cacheReadMultiplier: 0.2 },
|
|
98
103
|
"z-ai/glm-5.1": { inputUsdPerMillion: 1.4, outputUsdPerMillion: 4.4, cacheReadMultiplier: 0.18571428571428572 },
|
|
@@ -19,7 +19,13 @@ import {
|
|
|
19
19
|
PROVIDER_NAME,
|
|
20
20
|
} from "./config.js";
|
|
21
21
|
import { parseRoutedContextWindow } from "./context-window.js";
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
lastPinFromBranch,
|
|
24
|
+
parseRouterCommandHeader,
|
|
25
|
+
ROUTER_COMMAND_ENTRY_TYPE,
|
|
26
|
+
ROUTER_COMMAND_HEADER,
|
|
27
|
+
type RouterCommandOutcome,
|
|
28
|
+
} from "./force-model.js";
|
|
23
29
|
import { registerWeave } from "./provider.js";
|
|
24
30
|
import {
|
|
25
31
|
aggregateSavings,
|
|
@@ -40,6 +46,12 @@ interface PendingRoute {
|
|
|
40
46
|
decision?: string;
|
|
41
47
|
}
|
|
42
48
|
|
|
49
|
+
interface PendingCommand {
|
|
50
|
+
turnIndex: number;
|
|
51
|
+
sessionId: string;
|
|
52
|
+
outcome?: RouterCommandOutcome;
|
|
53
|
+
}
|
|
54
|
+
|
|
43
55
|
function savingsFromBranch(ctx: ExtensionContext): { entries: SavingsEntryData[]; aggregate: SavingsAggregate } {
|
|
44
56
|
const entries: SavingsEntryData[] = [];
|
|
45
57
|
for (const entry of ctx.sessionManager.getBranch()) {
|
|
@@ -64,12 +76,14 @@ export function registerRoutedModel(pi: ExtensionAPI): void {
|
|
|
64
76
|
let savings = aggregateSavings(entries);
|
|
65
77
|
let requestedModel: string | undefined;
|
|
66
78
|
let routedModel: string | undefined;
|
|
67
|
-
let
|
|
79
|
+
let lastPinModel: string | undefined;
|
|
68
80
|
let lastNotifiedModel: string | undefined;
|
|
81
|
+
let activeTurnIndex: number | undefined;
|
|
82
|
+
let pendingCommand: PendingCommand | undefined;
|
|
69
83
|
|
|
70
84
|
const refresh = (ctx: ExtensionContext) => {
|
|
71
85
|
if (isSubagent()) return;
|
|
72
|
-
updateRouterStatus(ctx, { requestedModel, routedModel,
|
|
86
|
+
updateRouterStatus(ctx, { requestedModel, routedModel, lastPinModel, savings });
|
|
73
87
|
};
|
|
74
88
|
|
|
75
89
|
const restore = (ctx: ExtensionContext) => {
|
|
@@ -82,8 +96,10 @@ export function registerRoutedModel(pi: ExtensionAPI): void {
|
|
|
82
96
|
lastEntry && requestedModel && normalizeModelId(requestedModel) === lastEntry.requestedModel
|
|
83
97
|
? lastEntry.routedModel
|
|
84
98
|
: undefined;
|
|
85
|
-
|
|
99
|
+
lastPinModel = lastPinFromBranch(ctx.sessionManager.getBranch());
|
|
86
100
|
pendingRoutes = [];
|
|
101
|
+
pendingCommand = undefined;
|
|
102
|
+
activeTurnIndex = undefined;
|
|
87
103
|
lastNotifiedModel = undefined;
|
|
88
104
|
};
|
|
89
105
|
|
|
@@ -93,6 +109,11 @@ export function registerRoutedModel(pi: ExtensionAPI): void {
|
|
|
93
109
|
refresh(ctx);
|
|
94
110
|
});
|
|
95
111
|
|
|
112
|
+
pi.on("turn_start", (event) => {
|
|
113
|
+
activeTurnIndex = event.turnIndex;
|
|
114
|
+
pendingCommand = undefined;
|
|
115
|
+
});
|
|
116
|
+
|
|
96
117
|
pi.on("model_select", (event, ctx: ExtensionContext) => {
|
|
97
118
|
// A new requested model has not yet received a router-confirmed window.
|
|
98
119
|
// Restore the conservative virtual-model default until its first response.
|
|
@@ -104,7 +125,16 @@ export function registerRoutedModel(pi: ExtensionAPI): void {
|
|
|
104
125
|
});
|
|
105
126
|
|
|
106
127
|
pi.on("after_provider_response", (event, ctx: ExtensionContext) => {
|
|
128
|
+
pendingCommand = undefined;
|
|
107
129
|
if (event.status < 200 || event.status >= 300) return;
|
|
130
|
+
const commandHeader = event.headers?.[ROUTER_COMMAND_HEADER];
|
|
131
|
+
if (commandHeader !== undefined && activeTurnIndex !== undefined && ctx.model?.provider === PROVIDER_NAME) {
|
|
132
|
+
pendingCommand = {
|
|
133
|
+
turnIndex: activeTurnIndex,
|
|
134
|
+
sessionId: ctx.sessionManager.getSessionId(),
|
|
135
|
+
outcome: parseRouterCommandHeader(commandHeader),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
108
138
|
const model = event.headers?.[ROUTED_MODEL_HEADER];
|
|
109
139
|
if (!model) return;
|
|
110
140
|
const contextWindow = parseRoutedContextWindow(event.headers?.[ROUTED_CONTEXT_WINDOW_HEADER]);
|
|
@@ -138,9 +168,16 @@ export function registerRoutedModel(pi: ExtensionAPI): void {
|
|
|
138
168
|
|
|
139
169
|
pi.on("turn_end", (event, ctx: ExtensionContext) => {
|
|
140
170
|
if (isSubagent() || event.message.role !== "assistant") return;
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
171
|
+
const command = pendingCommand;
|
|
172
|
+
pendingCommand = undefined;
|
|
173
|
+
if (command && command.turnIndex === event.turnIndex && command.sessionId === ctx.sessionManager.getSessionId() && event.message.stopReason === "stop") {
|
|
174
|
+
const outcome = command.outcome;
|
|
175
|
+
const matchingResponse = outcome && event.message.responseId === `msg_router_cmd_${outcome.id}`;
|
|
176
|
+
pi.appendEntry(ROUTER_COMMAND_ENTRY_TYPE, matchingResponse ? outcome : { responseId: event.message.responseId, outcome: null });
|
|
177
|
+
}
|
|
178
|
+
const restoredLastPin = lastPinFromBranch(ctx.sessionManager.getBranch());
|
|
179
|
+
if (restoredLastPin !== lastPinModel) {
|
|
180
|
+
lastPinModel = restoredLastPin;
|
|
144
181
|
// Force-model directives take effect between responses, before the next
|
|
145
182
|
// served-window header can arrive. Fall back to the conservative value.
|
|
146
183
|
registerWeave(pi);
|
|
@@ -177,6 +214,13 @@ export function registerRoutedModel(pi: ExtensionAPI): void {
|
|
|
177
214
|
|
|
178
215
|
pi.on("session_shutdown", (_event, ctx: ExtensionContext) => {
|
|
179
216
|
pendingRoutes = [];
|
|
217
|
+
pendingCommand = undefined;
|
|
218
|
+
activeTurnIndex = undefined;
|
|
180
219
|
if (!isSubagent()) clearLoomUi(ctx);
|
|
181
220
|
});
|
|
221
|
+
|
|
222
|
+
pi.on("agent_end", () => {
|
|
223
|
+
pendingCommand = undefined;
|
|
224
|
+
activeTurnIndex = undefined;
|
|
225
|
+
});
|
|
182
226
|
}
|
package/pi-router/src/ui.ts
CHANGED
|
@@ -22,7 +22,7 @@ const LOOM_WORDMARK = [
|
|
|
22
22
|
export interface RouterUiSnapshot {
|
|
23
23
|
requestedModel?: string;
|
|
24
24
|
routedModel?: string;
|
|
25
|
-
|
|
25
|
+
lastPinModel?: string;
|
|
26
26
|
savings: SavingsAggregate;
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -89,7 +89,7 @@ export function clearLoomUi(ctx: ExtensionContext): void {
|
|
|
89
89
|
|
|
90
90
|
export function updateRouterStatus(ctx: ExtensionContext, snapshot: RouterUiSnapshot): void {
|
|
91
91
|
if (!ctx.hasUI) return;
|
|
92
|
-
const { requestedModel, routedModel,
|
|
92
|
+
const { requestedModel, routedModel, lastPinModel, savings } = snapshot;
|
|
93
93
|
let route: string;
|
|
94
94
|
if (routedModel && requestedModel) route = `${routedModel} ← ${requestedModel}`;
|
|
95
95
|
else if (routedModel) route = routedModel;
|
|
@@ -98,6 +98,6 @@ export function updateRouterStatus(ctx: ExtensionContext, snapshot: RouterUiSnap
|
|
|
98
98
|
|
|
99
99
|
const tui = isTuiContext(ctx);
|
|
100
100
|
const label = tui ? ctx.ui.theme.bold(brand("WEAVE ROUTER")) : "WEAVE ROUTER";
|
|
101
|
-
const detail =
|
|
101
|
+
const detail = `${route} · ${formatSavings(savings)}${lastPinModel ? ` · last pin: ${lastPinModel}` : ""}`;
|
|
102
102
|
ctx.ui.setStatus(STATUS_KEY, `${label} — ${tui ? ctx.ui.theme.fg("dim", detail) : detail}`);
|
|
103
103
|
}
|