@blockrun/franklin 3.41.0 → 3.42.1
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 +54 -4
- package/dist/agent/context.js +7 -10
- package/dist/agent/error-classifier.d.ts +7 -0
- package/dist/agent/error-classifier.js +11 -2
- package/dist/agent/intent-prefetch.d.ts +3 -1
- package/dist/agent/intent-prefetch.js +25 -21
- package/dist/agent/loop.js +31 -3
- package/dist/agent/permissions.d.ts +3 -1
- package/dist/agent/permissions.js +21 -1
- package/dist/agent/streaming-executor.js +54 -53
- package/dist/agent/tokens.js +9 -1
- package/dist/agent/types.d.ts +13 -0
- package/dist/commands/serve.js +4 -1
- package/dist/pricing.js +40 -20
- package/dist/proxy/server.js +12 -1
- package/dist/router/index.d.ts +17 -0
- package/dist/router/index.js +116 -7
- package/dist/router/vision.js +10 -3
- package/dist/serve/agent-host.d.ts +5 -0
- package/dist/serve/agent-host.js +13 -3
- package/dist/serve/server.d.ts +11 -0
- package/dist/serve/server.js +285 -69
- package/dist/tools/jupiter.js +16 -2
- package/dist/tools/zerox-base.js +15 -2
- package/dist/tools/zerox-gasless.js +14 -4
- package/dist/ui/model-picker.js +13 -3
- package/package.json +10 -3
package/dist/pricing.js
CHANGED
|
@@ -44,7 +44,6 @@ export const MODEL_PRICING = {
|
|
|
44
44
|
'anthropic/claude-opus-5': { input: 5.0, output: 25.0 },
|
|
45
45
|
'anthropic/claude-opus-4.8': { input: 5.0, output: 25.0 },
|
|
46
46
|
'anthropic/claude-opus-4.7': { input: 5.0, output: 25.0 },
|
|
47
|
-
'anthropic/claude-opus-4.6': { input: 5.0, output: 25.0 },
|
|
48
47
|
'anthropic/claude-opus-4.5': { input: 5.0, output: 25.0 },
|
|
49
48
|
'anthropic/claude-sonnet-5': { input: 3.0, output: 15.0 }, // near-Opus at Sonnet cost, 1M ctx
|
|
50
49
|
'anthropic/claude-sonnet-4.6': { input: 3.0, output: 15.0 },
|
|
@@ -54,7 +53,6 @@ export const MODEL_PRICING = {
|
|
|
54
53
|
// Kept for cost lookup on sessions recorded before the switch.
|
|
55
54
|
'anthropic/claude-haiku-4.5-20251001': { input: 1.0, output: 5.0 },
|
|
56
55
|
// OpenAI
|
|
57
|
-
'openai/gpt-5-nano': { input: 0.05, output: 0.4 },
|
|
58
56
|
'openai/gpt-4.1-nano': { input: 0.1, output: 0.4 },
|
|
59
57
|
'openai/gpt-4o-mini': { input: 0.15, output: 0.6 },
|
|
60
58
|
'openai/gpt-5.4-nano': { input: 0.2, output: 1.25 },
|
|
@@ -72,7 +70,6 @@ export const MODEL_PRICING = {
|
|
|
72
70
|
'openai/gpt-4o': { input: 2.5, output: 10.0 },
|
|
73
71
|
'openai/gpt-5.4': { input: 2.5, output: 15.0 },
|
|
74
72
|
'openai/gpt-5.6-terra': { input: 2.0, output: 12.0 }, // balanced GPT-5.6 tier, 1M ctx (2026-07-30 cut)
|
|
75
|
-
'openai/o1-mini': { input: 1.1, output: 4.4 },
|
|
76
73
|
'openai/o3-mini': { input: 1.1, output: 4.4 },
|
|
77
74
|
'openai/o4-mini': { input: 1.1, output: 4.4 },
|
|
78
75
|
'openai/o1': { input: 15.0, output: 60.0 },
|
|
@@ -98,17 +95,8 @@ export const MODEL_PRICING = {
|
|
|
98
95
|
'google/gemini-3.5-flash-lite': { input: 0.3, output: 2.5 },
|
|
99
96
|
'google/gemini-3.6-flash': { input: 1.5, output: 7.5 }, // added upstream 2026-08-03 (base #329)
|
|
100
97
|
'google/gemini-2.5-pro': { input: 1.25, output: 10.0 },
|
|
101
|
-
'google/gemini-3-pro-preview': { input: 2.0, output: 12.0 },
|
|
102
98
|
'google/gemini-3.1-pro': { input: 2.0, output: 12.0 },
|
|
103
99
|
// xAI
|
|
104
|
-
'xai/grok-4-fast': { input: 0.2, output: 0.5 },
|
|
105
|
-
'xai/grok-4-fast-reasoning': { input: 0.2, output: 0.5 },
|
|
106
|
-
'xai/grok-4-1-fast': { input: 0.2, output: 0.5 },
|
|
107
|
-
'xai/grok-4-1-fast-reasoning': { input: 0.2, output: 0.5 },
|
|
108
|
-
'xai/grok-4-0709': { input: 3.0, output: 15.0 }, // gateway lists $3/$15 (was mispriced here at $0.2/$1.5)
|
|
109
|
-
'xai/grok-3-mini': { input: 0.3, output: 0.5 },
|
|
110
|
-
'xai/grok-2-vision': { input: 2.0, output: 10.0 },
|
|
111
|
-
'xai/grok-3': { input: 3.0, output: 15.0 },
|
|
112
100
|
'xai/grok-4.3': { input: 1.5, output: 4.0 }, // 1M ctx; demoted from flagship 2026-07-14
|
|
113
101
|
'xai/grok-4.5': { input: 2.5, output: 9.0 }, // xAI flagship — 500K ctx (note: less than 4.3's 1M)
|
|
114
102
|
'xai/grok-build-0.1': { input: 1.5, output: 3.0 }, // agentic coding, OpenRouter resale
|
|
@@ -122,7 +110,6 @@ export const MODEL_PRICING = {
|
|
|
122
110
|
// Minimax
|
|
123
111
|
'minimax/minimax-m3': { input: 0.3, output: 1.2 },
|
|
124
112
|
'minimax/minimax-m2.7': { input: 0.3, output: 1.2 },
|
|
125
|
-
'minimax/minimax-m2.5': { input: 0.3, output: 1.2 },
|
|
126
113
|
// Qwen — Plus/Flash tiers added upstream 2026-08-03 (base #329).
|
|
127
114
|
'qwen/qwen3.7-max': { input: 1.475, output: 4.425 },
|
|
128
115
|
'qwen/qwen3.7-plus': { input: 0.32, output: 1.28 },
|
|
@@ -134,19 +121,52 @@ export const MODEL_PRICING = {
|
|
|
134
121
|
// context, multimodal (image+text), returns reasoning_content. Pricier
|
|
135
122
|
// than the K2.x line it replaced ($3/$15 vs K2.7's $0.95/$4).
|
|
136
123
|
'moonshot/kimi-k3': { input: 3.0, output: 15.0 },
|
|
137
|
-
// Retired K2.x line (kept for legacy session-cost records; the gateway no
|
|
138
|
-
// longer serves these and the `kimi`/`k2.*` shortcuts now resolve to K3).
|
|
139
|
-
'moonshot/kimi-k2.7': { input: 0.95, output: 4.0 },
|
|
140
|
-
'moonshot/kimi-k2.6': { input: 0.95, output: 4.0 },
|
|
141
|
-
'moonshot/kimi-k2.5': { input: 0.6, output: 3.0 },
|
|
142
|
-
'nvidia/kimi-k2.5': { input: 0.55, output: 2.5 },
|
|
143
124
|
// PROMOTION (active ~2026-04): flat $0.001/call for all GLM models
|
|
144
125
|
'zai/glm-5': { input: 1.0, output: 3.2 }, // flat promo ended 2026-06-06; raised upstream 2026-08-07
|
|
145
126
|
'zai/glm-5.1': { input: 1.40, output: 4.40 }, // launch promo ended 2026-06-05 — per-token now
|
|
146
127
|
'zai/glm-5.2': { input: 1.40, output: 4.40 }, // new flagship 2026-06 — 1M context, same per-token price as 5.1
|
|
147
128
|
'zai/glm-5.3': { input: 1.40, output: 4.40 }, // flagship 2026-08 — 1M context, always-on reasoning, priced at 5.2
|
|
129
|
+
// GLM-5.3 Flash (catalog 2026-08-29): 1M context, vision, reasoning — the
|
|
130
|
+
// only GLM SKU tagged multimodal, at roughly a tenth of the flagship price.
|
|
131
|
+
'zai/glm-5.3-flash': { input: 0.15, output: 0.5 },
|
|
148
132
|
'zai/glm-5-turbo': { input: 1.2, output: 4.0 }, // flat promo ended 2026-06-06 — per-token now
|
|
149
|
-
|
|
133
|
+
// ── Hidden from /v1/models, still served ──
|
|
134
|
+
// None of these appear in GET /v1/models any more, but the gateway still
|
|
135
|
+
// routes and CHARGES for them: on 2026-08-29 every id marked (probed) below
|
|
136
|
+
// was called through the binary and answered. So they stay priced at list
|
|
137
|
+
// — a pinned `/model opus-4.6` or a router chain that still names one must
|
|
138
|
+
// cost correctly — and the picker keeps their shortcuts. The unmarked ids
|
|
139
|
+
// were not re-probed; they are kept so session-cost records written while
|
|
140
|
+
// they were live still price. The router's kill-switch
|
|
141
|
+
// (src/router/index.ts, markModelUnavailable) is what retires an id from
|
|
142
|
+
// routing, and it fires on a real 400/404/410, never on catalog absence.
|
|
143
|
+
'anthropic/claude-opus-4.6': { input: 5.0, output: 25.0 }, // (probed) superseded by 4.7 / 4.8 / 5 at the same price
|
|
144
|
+
'openai/gpt-5-nano': { input: 0.05, output: 0.4 }, // (probed)
|
|
145
|
+
'openai/o1-mini': { input: 1.1, output: 4.4 },
|
|
146
|
+
'google/gemini-3-pro-preview': { input: 2.0, output: 12.0 }, // GA'd as gemini-3.1-pro
|
|
147
|
+
'xai/grok-4-fast': { input: 0.2, output: 0.5 },
|
|
148
|
+
'xai/grok-4-fast-reasoning': { input: 0.2, output: 0.5 }, // (probed)
|
|
149
|
+
'xai/grok-4-1-fast': { input: 0.2, output: 0.5 },
|
|
150
|
+
'xai/grok-4-1-fast-reasoning': { input: 0.2, output: 0.5 }, // (probed)
|
|
151
|
+
// The two non-reasoning ids sit in the shared Router's SIMPLE chains and
|
|
152
|
+
// were charged today, yet had no row here — Franklin reported them as $0
|
|
153
|
+
// and the portfolio scorer, which treats an unpriced id as infinitely
|
|
154
|
+
// expensive, could never pick them over a priced rung. Priced with their
|
|
155
|
+
// reasoning siblings (xAI bills the pair identically).
|
|
156
|
+
'xai/grok-4-1-fast-non-reasoning': { input: 0.2, output: 0.5 }, // (probed)
|
|
157
|
+
'xai/grok-4-fast-non-reasoning': { input: 0.2, output: 0.5 }, // (probed)
|
|
158
|
+
'xai/grok-4-0709': { input: 3.0, output: 15.0 }, // (probed) gateway lists $3/$15 (was mispriced here at $0.2/$1.5)
|
|
159
|
+
'xai/grok-3-mini': { input: 0.3, output: 0.5 }, // (probed)
|
|
160
|
+
'xai/grok-2-vision': { input: 2.0, output: 10.0 },
|
|
161
|
+
'xai/grok-3': { input: 3.0, output: 15.0 }, // (probed)
|
|
162
|
+
'minimax/minimax-m2.5': { input: 0.3, output: 1.2 },
|
|
163
|
+
// K2.x (probed): the bare `kimi`/`k2.*` shortcuts resolve to K3, the
|
|
164
|
+
// explicit ids still answer.
|
|
165
|
+
'moonshot/kimi-k2.7': { input: 0.95, output: 4.0 },
|
|
166
|
+
'moonshot/kimi-k2.6': { input: 0.95, output: 4.0 },
|
|
167
|
+
'moonshot/kimi-k2.5': { input: 0.6, output: 3.0 },
|
|
168
|
+
'nvidia/kimi-k2.5': { input: 0.55, output: 2.5 },
|
|
169
|
+
'zai/glm-5.1-turbo': { input: 1.2, output: 4.0 }, // was a client alias for zai/glm-5-turbo
|
|
150
170
|
};
|
|
151
171
|
/** Opus pricing for savings calculations — tracks the current flagship. */
|
|
152
172
|
export const OPUS_PRICING = MODEL_PRICING['anthropic/claude-opus-5'];
|
package/dist/proxy/server.js
CHANGED
|
@@ -7,7 +7,8 @@ import { MODEL_SHORTCUTS } from '../ui/model-picker.js';
|
|
|
7
7
|
import { appendSettlementRow } from '../stats/cost-log.js';
|
|
8
8
|
import { appendAudit } from '../stats/audit.js';
|
|
9
9
|
import { buildFallbackChain, DEFAULT_FALLBACK_CONFIG, ROUTING_PROFILES, } from './fallback.js';
|
|
10
|
-
import { routeRequest, parseRoutingProfile, isVisionModel, messagesNeedVision, pickVisionSibling, } from '../router/index.js';
|
|
10
|
+
import { routeRequest, parseRoutingProfile, isVisionModel, messagesNeedVision, pickVisionSibling, markModelUnavailable, } from '../router/index.js';
|
|
11
|
+
import { classifyAgentError } from '../agent/error-classifier.js';
|
|
11
12
|
import { estimateCost } from '../pricing.js';
|
|
12
13
|
import { getMaxOutputTokens } from '../agent/optimize.js';
|
|
13
14
|
import { VERSION } from '../config.js';
|
|
@@ -523,6 +524,16 @@ export function createProxy(options) {
|
|
|
523
524
|
else {
|
|
524
525
|
// Wrap in Anthropic error format
|
|
525
526
|
const errorMsg = parsed.error?.message || parsed.message || rawText.slice(0, 500);
|
|
527
|
+
// The proxy's fallback chain only retries 429/5xx, so a routed
|
|
528
|
+
// id the gateway rejects outright (400 "Unknown model", 404,
|
|
529
|
+
// 410) reaches here untouched. Feed the router's dead-rung
|
|
530
|
+
// kill-switch so the next routed request skips it; a client
|
|
531
|
+
// that pinned the id by name is left alone.
|
|
532
|
+
if (routerCandidates.length > 0 && classifyAgentError(String(errorMsg)).modelUnavailable) {
|
|
533
|
+
if (markModelUnavailable(finalModel)) {
|
|
534
|
+
logger.warn(`[franklin] ${finalModel} rejected by the gateway as unavailable — removed from routing for this process`);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
526
537
|
errorBody = JSON.stringify({
|
|
527
538
|
type: 'error',
|
|
528
539
|
error: {
|
package/dist/router/index.d.ts
CHANGED
|
@@ -38,7 +38,24 @@ export interface RoutingContext {
|
|
|
38
38
|
requiresTools?: boolean;
|
|
39
39
|
requiresStructuredOutput?: boolean;
|
|
40
40
|
systemPrompt?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Extra model ids to treat as dead for this call only, on top of the
|
|
43
|
+
* process-wide set (see markModelUnavailable). Tests use this; hosts
|
|
44
|
+
* normally let the runtime observation feed the process-wide set.
|
|
45
|
+
*/
|
|
46
|
+
unavailableModels?: readonly string[];
|
|
41
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Record that the gateway rejected a model id outright (400 "Unknown model",
|
|
50
|
+
* 404, 410). Every later routing decision in this process removes it from
|
|
51
|
+
* the shared Router's chains. Idempotent; returns true the first time.
|
|
52
|
+
*/
|
|
53
|
+
export declare function markModelUnavailable(model: string | undefined | null): boolean;
|
|
54
|
+
/** Ids the shared Router must not select: static, quarantined, and observed. */
|
|
55
|
+
export declare function getUnavailableModels(extra?: readonly string[]): string[];
|
|
56
|
+
export declare function isModelUnavailable(model: string | undefined | null): boolean;
|
|
57
|
+
/** Test hook: forget runtime observations (the static lists stay). */
|
|
58
|
+
export declare function resetUnavailableModels(): void;
|
|
42
59
|
export type TierClassifier = (prompt: string) => Promise<Tier | null>;
|
|
43
60
|
/**
|
|
44
61
|
* Default LLM classifier — lazy-imports the ModelClient to avoid a hard
|
package/dist/router/index.js
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import fs from 'node:fs';
|
|
13
13
|
import path from 'node:path';
|
|
14
|
-
import { DEFAULT_ROUTING_CONFIG as SHARED_ROUTING_CONFIG, route as routeWithSharedCore, } from '@blockrun/router-core';
|
|
14
|
+
import { DEFAULT_MODEL_CAPABILITIES as SHARED_MODEL_CAPABILITIES_BASE, DEFAULT_ROUTING_CONFIG as SHARED_ROUTING_CONFIG, route as routeWithSharedCore, } from '@blockrun/router-core';
|
|
15
15
|
import { MODEL_PRICING, OPUS_PRICING } from '../pricing.js';
|
|
16
16
|
import { BLOCKRUN_DIR } from '../config.js';
|
|
17
17
|
import { detectCategory, mapCategoryToTier } from './categories.js';
|
|
18
18
|
import { selectModel } from './selector.js';
|
|
19
19
|
import { computeLocalElo, blendElo } from './local-elo.js';
|
|
20
|
-
import { isVisionModel } from './vision.js';
|
|
20
|
+
import { isVisionModel, pickVisionSibling } from './vision.js';
|
|
21
21
|
export { isVisionModel, messageNeedsVision, messagesNeedVision, pickVisionSibling } from './vision.js';
|
|
22
22
|
// ─── Learned Weights Loading ───
|
|
23
23
|
const WEIGHTS_FILE = path.join(BLOCKRUN_DIR, 'router-weights.json');
|
|
@@ -43,6 +43,94 @@ const SHARED_MODEL_PRICING = new Map(Object.entries(MODEL_PRICING).map(([model,
|
|
|
43
43
|
...(pricing.perCall !== undefined ? { flatPrice: pricing.perCall } : {}),
|
|
44
44
|
},
|
|
45
45
|
]));
|
|
46
|
+
// ─── Dead-rung kill-switch ───
|
|
47
|
+
//
|
|
48
|
+
// router-core ships its tier chains as committed config, so a model that
|
|
49
|
+
// leaves the gateway keeps its rung until a core release and a consumer
|
|
50
|
+
// repin land — weeks, historically (the free/gpt-oss rungs 400'd for two
|
|
51
|
+
// weeks before d7bc10c retired them). `options.unavailableModels` is the
|
|
52
|
+
// core's answer: ids the host has observed dead are hard-removed from every
|
|
53
|
+
// chain before selection, effective on the next request. Franklin feeds it
|
|
54
|
+
// from three sources:
|
|
55
|
+
//
|
|
56
|
+
// 1. KNOWN_UNAVAILABLE_MODELS — ids the committed core config still
|
|
57
|
+
// references that the gateway has been observed to REJECT. Absence from
|
|
58
|
+
// GET /v1/models is NOT evidence: on 2026-08-29 every catalog-absent id
|
|
59
|
+
// the core config names (Opus 4.6, the K2.x line, the xAI 3.x / 4-0709 /
|
|
60
|
+
// 4-fast family, gpt-5-nano) was probed through the binary and every one
|
|
61
|
+
// answered and was charged — the gateway hides them from the catalog
|
|
62
|
+
// but still serves them. Only add an id here after a real 400/404/410,
|
|
63
|
+
// and drop it once the core config itself stops naming it.
|
|
64
|
+
// 2. QUARANTINED_MODELS — ids the catalog DOES list but Franklin refuses to
|
|
65
|
+
// route to, because the free pool answers for them with a substitute
|
|
66
|
+
// (the response's `model` field names a different model) and leaks
|
|
67
|
+
// thinking prose into content. Same "never promise a model the user
|
|
68
|
+
// doesn't get" rule the picker applies; see FREE_MODELS_BY_CATEGORY.
|
|
69
|
+
// 3. Runtime observations — markModelUnavailable() is called by the agent
|
|
70
|
+
// loop when the gateway rejects a routed model id (400 "Unknown model",
|
|
71
|
+
// 404, 410 — see AgentErrorInfo.modelUnavailable). Process-scoped: the
|
|
72
|
+
// next routing decision in this session never picks that id again.
|
|
73
|
+
//
|
|
74
|
+
// The core treats this as distinct from user-preference exclusion: a chain
|
|
75
|
+
// whose every rung is dead keeps its config (the outage stays visible)
|
|
76
|
+
// instead of fail-opening to something the host said is gone.
|
|
77
|
+
const KNOWN_UNAVAILABLE_MODELS = [
|
|
78
|
+
// Empty as of 2026-08-29 — see the probe note above. The free/gpt-oss and
|
|
79
|
+
// free/deepseek-v4-flash rungs that would have lived here were retired in
|
|
80
|
+
// the core itself (d7bc10c), which is the steady state this list waits for.
|
|
81
|
+
];
|
|
82
|
+
const QUARANTINED_MODELS = [
|
|
83
|
+
// Catalogued free id; live probe 2026-08-29 answered as
|
|
84
|
+
// nvidia/nemotron-3-super-120b with the reasoning trace duplicated into
|
|
85
|
+
// `content`. The core uses it as the free backstop rung of every Auto
|
|
86
|
+
// chain — Franklin's chains end one rung earlier instead.
|
|
87
|
+
'nvidia/step-3.7-flash',
|
|
88
|
+
];
|
|
89
|
+
const observedUnavailable = new Set();
|
|
90
|
+
/**
|
|
91
|
+
* Record that the gateway rejected a model id outright (400 "Unknown model",
|
|
92
|
+
* 404, 410). Every later routing decision in this process removes it from
|
|
93
|
+
* the shared Router's chains. Idempotent; returns true the first time.
|
|
94
|
+
*/
|
|
95
|
+
export function markModelUnavailable(model) {
|
|
96
|
+
if (!model || observedUnavailable.has(model))
|
|
97
|
+
return false;
|
|
98
|
+
observedUnavailable.add(model);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
/** Ids the shared Router must not select: static, quarantined, and observed. */
|
|
102
|
+
export function getUnavailableModels(extra) {
|
|
103
|
+
return [...new Set([
|
|
104
|
+
...KNOWN_UNAVAILABLE_MODELS,
|
|
105
|
+
...QUARANTINED_MODELS,
|
|
106
|
+
...observedUnavailable,
|
|
107
|
+
...(extra ?? []),
|
|
108
|
+
])];
|
|
109
|
+
}
|
|
110
|
+
export function isModelUnavailable(model) {
|
|
111
|
+
if (!model)
|
|
112
|
+
return false;
|
|
113
|
+
return observedUnavailable.has(model)
|
|
114
|
+
|| KNOWN_UNAVAILABLE_MODELS.includes(model)
|
|
115
|
+
|| QUARANTINED_MODELS.includes(model);
|
|
116
|
+
}
|
|
117
|
+
/** Test hook: forget runtime observations (the static lists stay). */
|
|
118
|
+
export function resetUnavailableModels() {
|
|
119
|
+
observedUnavailable.clear();
|
|
120
|
+
}
|
|
121
|
+
// The core's capability snapshot decides vision eligibility inside the
|
|
122
|
+
// portfolio, but it lags the catalog (36 gateway chat ids have no entry as of
|
|
123
|
+
// 2026-08-29, and it disagrees with Franklin's allowlist on gpt-5-mini / o3 /
|
|
124
|
+
// grok-4-0709, all of which accept images). Franklin's allowlist in vision.ts
|
|
125
|
+
// is the maintained source, so its verdict overrides `supportsVision` on
|
|
126
|
+
// every entry the core knows. Ids the core does not know fail OPEN inside
|
|
127
|
+
// the core (`isEligible` returns true) — that gap is closed by the
|
|
128
|
+
// post-selection guard in routeRequest, not by inventing context/output
|
|
129
|
+
// numbers here that would silently change eligibility.
|
|
130
|
+
const SHARED_MODEL_CAPABILITIES = Object.fromEntries(Object.entries(SHARED_MODEL_CAPABILITIES_BASE).map(([id, caps]) => [
|
|
131
|
+
id,
|
|
132
|
+
{ ...caps, supportsVision: isVisionModel(id) },
|
|
133
|
+
]));
|
|
46
134
|
function normalizeRoutingContext(context) {
|
|
47
135
|
return typeof context === 'boolean' ? { needsVision: context } : context;
|
|
48
136
|
}
|
|
@@ -83,6 +171,7 @@ const AUTO_TIERS = {
|
|
|
83
171
|
'anthropic/claude-opus-4.7',
|
|
84
172
|
'openai/o3',
|
|
85
173
|
'deepseek/deepseek-v4-pro',
|
|
174
|
+
// Hidden from /v1/models but still served (probed 2026-08-29).
|
|
86
175
|
'xai/grok-4-1-fast-reasoning',
|
|
87
176
|
'deepseek/deepseek-reasoner',
|
|
88
177
|
],
|
|
@@ -540,6 +629,7 @@ export function routeRequest(prompt, profile = 'auto', context = false) {
|
|
|
540
629
|
strategy: process.env.FRANKLIN_ROUTER_STRATEGY === 'rules' ? 'rules' : 'portfolio',
|
|
541
630
|
},
|
|
542
631
|
modelPricing: SHARED_MODEL_PRICING,
|
|
632
|
+
modelCapabilities: SHARED_MODEL_CAPABILITIES,
|
|
543
633
|
routingProfile: 'auto',
|
|
544
634
|
hasTools: normalizedContext.hasTools ?? toolNames.length > 0,
|
|
545
635
|
toolCount: toolNames.length,
|
|
@@ -549,16 +639,33 @@ export function routeRequest(prompt, profile = 'auto', context = false) {
|
|
|
549
639
|
: {}),
|
|
550
640
|
hasVision: normalizedContext.needsVision ?? false,
|
|
551
641
|
requiresStructuredOutput: normalizedContext.requiresStructuredOutput ?? false,
|
|
642
|
+
unavailableModels: getUnavailableModels(normalizedContext.unavailableModels),
|
|
552
643
|
});
|
|
553
644
|
const category = detectCategory(prompt, loadLearnedWeights()?.category_keywords).category;
|
|
645
|
+
let model = decision.model;
|
|
646
|
+
let candidates = decision.candidates ?? [decision.model];
|
|
647
|
+
const signals = [decision.routerVersion ?? decision.method, ...(decision.taskType ? [decision.taskType] : [])];
|
|
648
|
+
// Vision is a hard requirement, and the core fails open for any id
|
|
649
|
+
// missing from its capability snapshot (see SHARED_MODEL_CAPABILITIES).
|
|
650
|
+
// Before this guard an image turn could land on a text-only model the
|
|
651
|
+
// core simply had no opinion about — zai/glm-5.2 sits in the long-context
|
|
652
|
+
// evidence list, for instance — and the model would then hallucinate
|
|
653
|
+
// from the `Image file: <path>` stub. Walk the core's own recovery chain
|
|
654
|
+
// for the first model that can see; fall back to the family sibling.
|
|
655
|
+
if (normalizedContext.needsVision && !isVisionModel(model)) {
|
|
656
|
+
const sighted = candidates.filter(isVisionModel);
|
|
657
|
+
model = sighted[0] ?? pickVisionSibling(model);
|
|
658
|
+
candidates = sighted.length > 0 ? sighted : [model];
|
|
659
|
+
signals.push('vision-required');
|
|
660
|
+
}
|
|
554
661
|
return {
|
|
555
|
-
model
|
|
662
|
+
model,
|
|
556
663
|
tier: decision.tier,
|
|
557
664
|
confidence: decision.confidence,
|
|
558
|
-
signals
|
|
559
|
-
savings: decision.savings,
|
|
665
|
+
signals,
|
|
666
|
+
savings: model === decision.model ? decision.savings : computeSavings(model),
|
|
560
667
|
category,
|
|
561
|
-
candidates
|
|
668
|
+
candidates,
|
|
562
669
|
taskType: decision.taskType,
|
|
563
670
|
routerVersion: decision.routerVersion,
|
|
564
671
|
reasoning: decision.reasoning,
|
|
@@ -672,7 +779,9 @@ export function getFallbackChain(tier, profile = 'auto') {
|
|
|
672
779
|
// third: still DEGRADED at NVIDIA, kept as a genuinely different family for
|
|
673
780
|
// the case where both Nemotron nano builds are down. The catalog's fifth free
|
|
674
781
|
// id, step-3.7-flash, stays out of every chain — it leaks thinking prose into
|
|
675
|
-
// content AND comes back served by nemotron-3-super-120b
|
|
782
|
+
// content AND comes back served by nemotron-3-super-120b (re-probed
|
|
783
|
+
// 2026-08-29, unchanged). It is also QUARANTINED for the shared Router above,
|
|
784
|
+
// which would otherwise use it as the free backstop rung of every Auto chain.
|
|
676
785
|
const OMNI = 'nvidia/nemotron-3-nano-omni-30b-a3b-reasoning';
|
|
677
786
|
const FREE_MODELS_BY_CATEGORY = {
|
|
678
787
|
coding: ['nvidia/nemotron-nano-9b-v2', OMNI, 'nvidia/mistral-nemotron'],
|
package/dist/router/vision.js
CHANGED
|
@@ -24,6 +24,9 @@ const VISION_MODELS = new Set([
|
|
|
24
24
|
'anthropic/claude-opus-5',
|
|
25
25
|
'anthropic/claude-opus-4.8',
|
|
26
26
|
'anthropic/claude-opus-4.7',
|
|
27
|
+
// Hidden from /v1/models since 2026-08 but still served (probed through
|
|
28
|
+
// the binary 2026-08-29) — a pinned `opus-4.6` image turn must not be
|
|
29
|
+
// rerouted to a sibling the user didn't ask for.
|
|
27
30
|
'anthropic/claude-opus-4.6',
|
|
28
31
|
'anthropic/claude-opus-4.5',
|
|
29
32
|
'anthropic/claude-sonnet-5',
|
|
@@ -63,17 +66,21 @@ const VISION_MODELS = new Set([
|
|
|
63
66
|
// xAI — grok-4-1-fast-reasoning stays out (text-only). Grok 4.5 and 4.3 are
|
|
64
67
|
// both vision-capable in the catalog and were missing here until 2026-08-20:
|
|
65
68
|
// `grok` resolves to 4.5, so every image turn on the xAI flagship was being
|
|
66
|
-
// rerouted to a "vision sibling" the user never asked for.
|
|
69
|
+
// rerouted to a "vision sibling" the user never asked for. grok-4-0709 and
|
|
70
|
+
// grok-3 are hidden from /v1/models but still served (probed 2026-08-29).
|
|
67
71
|
'xai/grok-4.5',
|
|
68
72
|
'xai/grok-4.3',
|
|
69
73
|
'xai/grok-4-0709',
|
|
70
74
|
'xai/grok-3',
|
|
71
|
-
// Moonshot — K3 is the
|
|
72
|
-
//
|
|
75
|
+
// Moonshot — K3 is the flagship; the K2.x line is hidden from /v1/models
|
|
76
|
+
// but still served (probed 2026-08-29) and is catalogued as multimodal.
|
|
73
77
|
'moonshot/kimi-k3',
|
|
74
78
|
'moonshot/kimi-k2.7',
|
|
75
79
|
'moonshot/kimi-k2.6',
|
|
76
80
|
'moonshot/kimi-k2.5',
|
|
81
|
+
// Z.AI — GLM-5.3 Flash is the one GLM SKU the catalog tags as vision
|
|
82
|
+
// (2026-08-29 sync); GLM-5.3 / 5.2 / 5.1 are text + reasoning only.
|
|
83
|
+
'zai/glm-5.3-flash',
|
|
77
84
|
// NVIDIA inference — Nemotron Nano VL is multimodal; deepseek/qwen-coder are
|
|
78
85
|
// not. Llama 4 Maverick dropped 2026-07-14: it left the gateway catalog, and
|
|
79
86
|
// listing it here contradicted routeRequest()'s own "maverick is text-only"
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
import { type ApprovalRequest } from '../agent/approvals.js';
|
|
21
21
|
import { type AgentRunState } from '../events/types.js';
|
|
22
22
|
import type { AgentConfig, StreamEvent } from '../agent/types.js';
|
|
23
|
+
export declare function resolveHostedMaxSpendUsd(requested: number | undefined, ceiling: number | undefined): number | undefined;
|
|
23
24
|
export interface DispatchOptions {
|
|
24
25
|
prompt: string;
|
|
25
26
|
model?: string;
|
|
@@ -46,6 +47,10 @@ export declare class AgentHost {
|
|
|
46
47
|
apiUrl: string;
|
|
47
48
|
defaultModel: string;
|
|
48
49
|
debug?: boolean;
|
|
50
|
+
permissionPolicyFn?: AgentConfig['permissionPolicyFn'];
|
|
51
|
+
allowSubAgents?: boolean;
|
|
52
|
+
allowPaidPrefetch?: boolean;
|
|
53
|
+
defaultMaxSpendUsd?: number;
|
|
49
54
|
});
|
|
50
55
|
private setState;
|
|
51
56
|
/** Start a new hosted agent; resolves with its sessionId once known. */
|
package/dist/serve/agent-host.js
CHANGED
|
@@ -26,6 +26,11 @@ import { bus, } from '../events/bus.js';
|
|
|
26
26
|
import { makeEvent } from '../events/types.js';
|
|
27
27
|
import { writeLiveAgent } from '../session/live-registry.js';
|
|
28
28
|
const RING_BUFFER_SIZE = 200;
|
|
29
|
+
export function resolveHostedMaxSpendUsd(requested, ceiling) {
|
|
30
|
+
if (ceiling == null)
|
|
31
|
+
return requested;
|
|
32
|
+
return requested != null && requested > 0 ? Math.min(requested, ceiling) : ceiling;
|
|
33
|
+
}
|
|
29
34
|
export class AgentHost {
|
|
30
35
|
opts;
|
|
31
36
|
agents = new Map();
|
|
@@ -61,6 +66,7 @@ export class AgentHost {
|
|
|
61
66
|
throw new Error('prompt must not be empty');
|
|
62
67
|
const model = options.model || this.opts.defaultModel;
|
|
63
68
|
const label = options.label?.trim() || prompt.replace(/\s+/g, ' ').slice(0, 60);
|
|
69
|
+
const maxSpendUsd = resolveHostedMaxSpendUsd(options.maxSpendUsd, this.opts.defaultMaxSpendUsd);
|
|
64
70
|
// Per-agent input queue (same contract the loop's own multiplexer wraps).
|
|
65
71
|
const queue = [];
|
|
66
72
|
let resolver = null;
|
|
@@ -134,19 +140,23 @@ export class AgentHost {
|
|
|
134
140
|
}
|
|
135
141
|
};
|
|
136
142
|
const systemInstructions = assembleInstructions(this.opts.workDir, model);
|
|
137
|
-
const subAgent =
|
|
143
|
+
const subAgent = this.opts.allowSubAgents === false
|
|
144
|
+
? null
|
|
145
|
+
: createSubAgentCapability(this.opts.apiUrl, this.opts.chain, allCapabilities, model);
|
|
138
146
|
const config = {
|
|
139
147
|
model,
|
|
140
148
|
apiUrl: this.opts.apiUrl,
|
|
141
149
|
chain: this.opts.chain,
|
|
142
150
|
systemInstructions,
|
|
143
|
-
capabilities: [...allCapabilities, subAgent],
|
|
151
|
+
capabilities: subAgent ? [...allCapabilities, subAgent] : allCapabilities,
|
|
144
152
|
maxTurns: 100,
|
|
145
153
|
workingDir: this.opts.workDir,
|
|
146
154
|
permissionMode: options.permissionMode ?? 'default',
|
|
155
|
+
permissionPolicyFn: this.opts.permissionPolicyFn,
|
|
147
156
|
debug: !!this.opts.debug,
|
|
148
157
|
showPrefetchStatus: false,
|
|
149
|
-
|
|
158
|
+
allowPaidPrefetch: this.opts.allowPaidPrefetch,
|
|
159
|
+
...(maxSpendUsd != null ? { maxSpendUsd } : {}),
|
|
150
160
|
onSessionStart: (sessionId) => {
|
|
151
161
|
agent.sessionId = sessionId;
|
|
152
162
|
this.agents.set(sessionId, agent);
|
package/dist/serve/server.d.ts
CHANGED
|
@@ -16,6 +16,17 @@
|
|
|
16
16
|
* fed by a getUserInput queue. Good enough for the desktop app; multi-session
|
|
17
17
|
* fan-out can come later.
|
|
18
18
|
*/
|
|
19
|
+
import type { AgentConfig } from '../agent/types.js';
|
|
20
|
+
export declare function isOriginAllowed(origin: string | undefined): boolean;
|
|
21
|
+
export declare function tokenOk(url: URL): boolean;
|
|
22
|
+
export declare function localFileUrl(port: number, filePath: string): string;
|
|
23
|
+
export declare function fileTokenOk(url: URL): boolean;
|
|
24
|
+
export declare function resolveServedMediaPath(candidate: string, fileRoots: string[]): {
|
|
25
|
+
realPath: string;
|
|
26
|
+
mediaType: string;
|
|
27
|
+
} | null;
|
|
28
|
+
/** Desktop-only policy: paths outside the workspace require explicit approval. */
|
|
29
|
+
export declare function createDesktopWorkspacePermissionPolicy(workDir: string): NonNullable<AgentConfig['permissionPolicyFn']>;
|
|
19
30
|
interface ServerOptions {
|
|
20
31
|
port: number;
|
|
21
32
|
workDir: string;
|