@blockrun/franklin 3.38.0 → 3.40.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/README.md +8 -8
- package/dist/agent/compact.js +1 -1
- package/dist/agent/context.js +17 -8
- package/dist/agent/evaluator.js +1 -1
- package/dist/agent/llm.js +6 -6
- package/dist/agent/loop.js +25 -9
- package/dist/agent/tokens.js +34 -4
- package/dist/agent/turn-analyzer.js +6 -4
- package/dist/agent/verification.js +1 -1
- package/dist/brain/extract.js +6 -1
- package/dist/commands/slack.js +1 -1
- package/dist/commands/social.js +1 -1
- package/dist/commands/telegram.js +1 -1
- package/dist/content/image-pricing.js +23 -0
- package/dist/content/library.d.ts +1 -1
- package/dist/gateway-models.d.ts +14 -4
- package/dist/gateway-models.js +18 -5
- package/dist/learnings/extractor.js +2 -2
- package/dist/plugin-sdk/workflow.d.ts +1 -1
- package/dist/plugin-sdk/workflow.js +2 -2
- package/dist/pricing.js +40 -19
- package/dist/proxy/fallback.js +1 -1
- package/dist/proxy/server.js +52 -5
- package/dist/router/index.d.ts +24 -5
- package/dist/router/index.js +125 -39
- package/dist/router/vision.js +26 -4
- package/dist/serve/server.js +4 -4
- package/dist/tools/content-execute.js +1 -1
- package/dist/tools/moa.js +3 -3
- package/dist/tools/prediction.d.ts +5 -2
- package/dist/tools/prediction.js +21 -44
- package/dist/tools/subagent.js +1 -1
- package/dist/tools/videogen.d.ts +4 -3
- package/dist/tools/videogen.js +10 -6
- package/dist/ui/model-picker.js +158 -53
- package/package.json +4 -2
package/dist/pricing.js
CHANGED
|
@@ -8,21 +8,23 @@ export const MODEL_PRICING = {
|
|
|
8
8
|
// their parser mapping promotes them to Auto upstream of cost estimation.
|
|
9
9
|
'blockrun/auto': { input: 0.8, output: 4.0 },
|
|
10
10
|
'blockrun/free': { input: 0, output: 0 },
|
|
11
|
-
// FREE — BlockRun gateway free tier (refreshed 2026-
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
'nvidia/nemotron-
|
|
11
|
+
// FREE — BlockRun gateway free tier (refreshed 2026-08-12 to match live
|
|
12
|
+
// /api/v1/models). nemotron-nano-9b-v2 is the current free default — the
|
|
13
|
+
// one free model that verifiably serves itself on the streaming path
|
|
14
|
+
// (mistral-nemotron is DEGRADED upstream: stream calls 400, non-stream
|
|
15
|
+
// rides a disclosed gateway fallback).
|
|
16
|
+
'nvidia/nemotron-nano-9b-v2': { input: 0, output: 0 },
|
|
17
17
|
'nvidia/mistral-nemotron': { input: 0, output: 0 },
|
|
18
|
+
'nvidia/nemotron-nano-12b-v2-vl': { input: 0, output: 0 },
|
|
19
|
+
'nvidia/nemotron-3-nano-omni-30b-a3b-reasoning': { input: 0, output: 0 },
|
|
18
20
|
'nvidia/step-3.7-flash': { input: 0, output: 0 },
|
|
21
|
+
// Retired free models (kept at 0 for legacy session-cost records; gateway no
|
|
22
|
+
// longer serves these — do NOT route to them).
|
|
23
|
+
'nvidia/qwen3-next-80b-a3b-instruct': { input: 0, output: 0 }, // NVIDIA EOL 410, 2026-07-27
|
|
24
|
+
'nvidia/qwen3.5-122b-a10b': { input: 0, output: 0 },
|
|
19
25
|
'nvidia/seed-oss-36b': { input: 0, output: 0 },
|
|
20
|
-
'nvidia/nemotron-nano-9b-v2': { input: 0, output: 0 },
|
|
21
|
-
'nvidia/nemotron-nano-12b-v2-vl': { input: 0, output: 0 },
|
|
22
26
|
'nvidia/llama-4-maverick': { input: 0, output: 0 },
|
|
23
27
|
'nvidia/mistral-large-3-675b': { input: 0, output: 0 },
|
|
24
|
-
// Retired free models (kept at 0 for legacy session-cost records; gateway no
|
|
25
|
-
// longer serves these — do NOT route to them).
|
|
26
28
|
'nvidia/deepseek-v4-flash': { input: 0, output: 0 },
|
|
27
29
|
'nvidia/glm-4.7': { input: 0, output: 0 },
|
|
28
30
|
'nvidia/qwen3-next-80b-a3b-thinking': { input: 0, output: 0 },
|
|
@@ -59,7 +61,9 @@ export const MODEL_PRICING = {
|
|
|
59
61
|
'openai/gpt-5-mini': { input: 0.25, output: 2.0 },
|
|
60
62
|
'openai/gpt-4.1-mini': { input: 0.4, output: 1.6 },
|
|
61
63
|
'openai/gpt-5.4-mini': { input: 0.75, output: 4.5 },
|
|
62
|
-
'
|
|
64
|
+
// OpenAI's 2026-07-30 GPT-5.6 price cut, passed through by the gateway
|
|
65
|
+
// (base #326) — mirrored here 2026-08-12.
|
|
66
|
+
'openai/gpt-5.6-luna': { input: 0.2, output: 1.2 }, // cost-efficient GPT-5.6 tier, 1M ctx
|
|
63
67
|
'openai/gpt-5.2': { input: 1.75, output: 14.0 },
|
|
64
68
|
'openai/gpt-5.3': { input: 1.75, output: 14.0 },
|
|
65
69
|
'openai/gpt-5.3-codex': { input: 1.75, output: 14.0 },
|
|
@@ -67,13 +71,20 @@ export const MODEL_PRICING = {
|
|
|
67
71
|
'openai/o3': { input: 2.0, output: 8.0 },
|
|
68
72
|
'openai/gpt-4o': { input: 2.5, output: 10.0 },
|
|
69
73
|
'openai/gpt-5.4': { input: 2.5, output: 15.0 },
|
|
70
|
-
'openai/gpt-5.6-terra': { input: 2.
|
|
74
|
+
'openai/gpt-5.6-terra': { input: 2.0, output: 12.0 }, // balanced GPT-5.6 tier, 1M ctx (2026-07-30 cut)
|
|
71
75
|
'openai/o1-mini': { input: 1.1, output: 4.4 },
|
|
72
76
|
'openai/o3-mini': { input: 1.1, output: 4.4 },
|
|
73
77
|
'openai/o4-mini': { input: 1.1, output: 4.4 },
|
|
74
78
|
'openai/o1': { input: 15.0, output: 60.0 },
|
|
75
79
|
'openai/gpt-5.5': { input: 5.0, output: 30.0 },
|
|
76
80
|
'openai/gpt-5.6-sol': { input: 5.0, output: 30.0 }, // GPT-5.6 flagship, deepest reasoning, 1M ctx
|
|
81
|
+
// GPT-5.6 Pro tiers + 5.5 Pro + chat-latest, added upstream 2026-08-03
|
|
82
|
+
// (base #329) — priced from the live catalog 2026-08-12.
|
|
83
|
+
'openai/gpt-5.6-luna-pro': { input: 0.1, output: 0.6 },
|
|
84
|
+
'openai/gpt-5.6-terra-pro': { input: 1.0, output: 6.0 },
|
|
85
|
+
'openai/gpt-5.6-sol-pro': { input: 5.0, output: 30.0 },
|
|
86
|
+
'openai/gpt-5.5-pro': { input: 30.0, output: 180.0 },
|
|
87
|
+
'openai/chat-latest': { input: 5.0, output: 30.0 },
|
|
77
88
|
'openai/gpt-5.2-pro': { input: 21.0, output: 168.0 },
|
|
78
89
|
'openai/gpt-5.4-pro': { input: 30.0, output: 180.0 },
|
|
79
90
|
// Google
|
|
@@ -81,7 +92,11 @@ export const MODEL_PRICING = {
|
|
|
81
92
|
'google/gemini-3.1-flash-lite': { input: 0.25, output: 1.5 },
|
|
82
93
|
'google/gemini-2.5-flash': { input: 0.3, output: 2.5 },
|
|
83
94
|
'google/gemini-3-flash-preview': { input: 0.5, output: 3.0 },
|
|
84
|
-
|
|
95
|
+
// 2026-08-12 sync: the gateway was billing gemini-3.5-flash at 1/3 of
|
|
96
|
+
// Google's rate and corrected upstream (base #304) — mirror the real price.
|
|
97
|
+
'google/gemini-3.5-flash': { input: 1.5, output: 9.0 }, // latest Flash w/ thinking, 1M ctx
|
|
98
|
+
'google/gemini-3.5-flash-lite': { input: 0.3, output: 2.5 },
|
|
99
|
+
'google/gemini-3.6-flash': { input: 1.5, output: 7.5 }, // added upstream 2026-08-03 (base #329)
|
|
85
100
|
'google/gemini-2.5-pro': { input: 1.25, output: 10.0 },
|
|
86
101
|
'google/gemini-3-pro-preview': { input: 2.0, output: 12.0 },
|
|
87
102
|
'google/gemini-3.1-pro': { input: 2.0, output: 12.0 },
|
|
@@ -97,10 +112,10 @@ export const MODEL_PRICING = {
|
|
|
97
112
|
'xai/grok-4.3': { input: 1.5, output: 4.0 }, // 1M ctx; demoted from flagship 2026-07-14
|
|
98
113
|
'xai/grok-4.5': { input: 2.5, output: 9.0 }, // xAI flagship — 500K ctx (note: less than 4.3's 1M)
|
|
99
114
|
'xai/grok-build-0.1': { input: 1.5, output: 3.0 }, // agentic coding, OpenRouter resale
|
|
100
|
-
// DeepSeek (gateway re-aliased these to V4 Flash on 2026-05-03; price
|
|
101
|
-
//
|
|
102
|
-
'deepseek/deepseek-chat': { input: 0.
|
|
103
|
-
'deepseek/deepseek-reasoner': { input: 0.
|
|
115
|
+
// DeepSeek (gateway re-aliased these to V4 Flash on 2026-05-03; price cut
|
|
116
|
+
// again upstream 2026-08-07 to $0.14/$0.28 — mirrored here 2026-08-12).
|
|
117
|
+
'deepseek/deepseek-chat': { input: 0.14, output: 0.28 },
|
|
118
|
+
'deepseek/deepseek-reasoner': { input: 0.14, output: 0.28 },
|
|
104
119
|
// V4 Pro (1.6T MoE / 49B active, 1M ctx, 65K out). 75% launch promo
|
|
105
120
|
// through 2026-05-31 — list is $2.00/$4.00, promo is $0.50/$1.00.
|
|
106
121
|
'deepseek/deepseek-v4-pro': { input: 0.435, output: 0.87 }, // 75% promo became permanent list after 2026-05-31
|
|
@@ -108,8 +123,13 @@ export const MODEL_PRICING = {
|
|
|
108
123
|
'minimax/minimax-m3': { input: 0.3, output: 1.2 },
|
|
109
124
|
'minimax/minimax-m2.7': { input: 0.3, output: 1.2 },
|
|
110
125
|
'minimax/minimax-m2.5': { input: 0.3, output: 1.2 },
|
|
111
|
-
// Qwen
|
|
126
|
+
// Qwen — Plus/Flash tiers added upstream 2026-08-03 (base #329).
|
|
112
127
|
'qwen/qwen3.7-max': { input: 1.475, output: 4.425 },
|
|
128
|
+
'qwen/qwen3.7-plus': { input: 0.32, output: 1.28 },
|
|
129
|
+
'qwen/qwen3.7-flash': { input: 0.03, output: 0.13 },
|
|
130
|
+
// New providers added upstream 2026-08 — priced from the live catalog.
|
|
131
|
+
'tencent/hy3': { input: 0.132, output: 0.528 },
|
|
132
|
+
'xiaomi/mimo-v2.5-pro': { input: 0.435, output: 0.87 },
|
|
113
133
|
// Moonshot — K3 is the gateway flagship (2026-07): 2.8T open MoE, 1M
|
|
114
134
|
// context, multimodal (image+text), returns reasoning_content. Pricier
|
|
115
135
|
// than the K2.x line it replaced ($3/$15 vs K2.7's $0.95/$4).
|
|
@@ -121,9 +141,10 @@ export const MODEL_PRICING = {
|
|
|
121
141
|
'moonshot/kimi-k2.5': { input: 0.6, output: 3.0 },
|
|
122
142
|
'nvidia/kimi-k2.5': { input: 0.55, output: 2.5 },
|
|
123
143
|
// PROMOTION (active ~2026-04): flat $0.001/call for all GLM models
|
|
124
|
-
'zai/glm-5': { input: 0
|
|
144
|
+
'zai/glm-5': { input: 1.0, output: 3.2 }, // flat promo ended 2026-06-06; raised upstream 2026-08-07
|
|
125
145
|
'zai/glm-5.1': { input: 1.40, output: 4.40 }, // launch promo ended 2026-06-05 — per-token now
|
|
126
146
|
'zai/glm-5.2': { input: 1.40, output: 4.40 }, // new flagship 2026-06 — 1M context, same per-token price as 5.1
|
|
147
|
+
'zai/glm-5.3': { input: 1.40, output: 4.40 }, // flagship 2026-08 — 1M context, always-on reasoning, priced at 5.2
|
|
127
148
|
'zai/glm-5-turbo': { input: 1.2, output: 4.0 }, // flat promo ended 2026-06-06 — per-token now
|
|
128
149
|
'zai/glm-5.1-turbo': { input: 1.2, output: 4.0 }, // client alias for zai/glm-5-turbo
|
|
129
150
|
};
|
package/dist/proxy/fallback.js
CHANGED
|
@@ -7,7 +7,7 @@ export const DEFAULT_FALLBACK_CONFIG = {
|
|
|
7
7
|
chain: [
|
|
8
8
|
'deepseek/deepseek-chat', // Direct fallback — cheap & reliable
|
|
9
9
|
'google/gemini-2.5-flash', // Fast & capable
|
|
10
|
-
'nvidia/
|
|
10
|
+
'nvidia/nemotron-nano-9b-v2', // Free model as ultimate fallback (reliable instruction-follower)
|
|
11
11
|
],
|
|
12
12
|
retryOn: [429, 500, 502, 503, 504, 529],
|
|
13
13
|
maxRetries: 5,
|
package/dist/proxy/server.js
CHANGED
|
@@ -245,6 +245,7 @@ export function createProxy(options) {
|
|
|
245
245
|
req.on('end', async () => {
|
|
246
246
|
let requestModel = currentModel || options.modelOverride || 'unknown';
|
|
247
247
|
let usedFallback = false;
|
|
248
|
+
let routerCandidates = [];
|
|
248
249
|
try {
|
|
249
250
|
if (options.debug)
|
|
250
251
|
logger.debug(`[franklin] request: ${req.method} ${req.url} currentModel=${currentModel || 'none'}`);
|
|
@@ -284,7 +285,7 @@ export function createProxy(options) {
|
|
|
284
285
|
// Model override logic:
|
|
285
286
|
// - Native Anthropic-format IDs (e.g. "claude-sonnet-4-6-20250514")
|
|
286
287
|
// don't contain "/" — these MUST be replaced with currentModel.
|
|
287
|
-
// - BlockRun model IDs always contain "/" (e.g. "blockrun/auto", "nvidia/nemotron
|
|
288
|
+
// - BlockRun model IDs always contain "/" (e.g. "blockrun/auto", "nvidia/mistral-nemotron")
|
|
288
289
|
// — these should be passed through as-is.
|
|
289
290
|
// - If --model CLI flag is set, always override regardless.
|
|
290
291
|
if (options.modelOverride) {
|
|
@@ -319,11 +320,52 @@ export function createProxy(options) {
|
|
|
319
320
|
.join('\n');
|
|
320
321
|
}
|
|
321
322
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
323
|
+
const toolNames = (Array.isArray(parsed.tools) ? parsed.tools : [])
|
|
324
|
+
.map((tool) => tool.name ?? tool.function?.name)
|
|
325
|
+
.filter((name) => typeof name === 'string');
|
|
326
|
+
const toolChoice = parsed.tool_choice;
|
|
327
|
+
const toolChoiceType = typeof toolChoice === 'object' && toolChoice !== null
|
|
328
|
+
? String(toolChoice.type)
|
|
329
|
+
: undefined;
|
|
330
|
+
const forbidsTools = toolChoice === 'none' || toolChoiceType === 'none';
|
|
331
|
+
const requiresTools = !forbidsTools && (toolChoice === 'required'
|
|
332
|
+
|| (toolChoiceType !== undefined
|
|
333
|
+
&& ['any', 'tool', 'function'].includes(toolChoiceType)));
|
|
334
|
+
const explicitToolRequirement = forbidsTools
|
|
335
|
+
? false
|
|
336
|
+
: requiresTools
|
|
337
|
+
? true
|
|
338
|
+
: undefined;
|
|
339
|
+
const responseFormat = parsed.response_format;
|
|
340
|
+
const requiresStructuredOutput = !!responseFormat
|
|
341
|
+
&& responseFormat.type !== undefined
|
|
342
|
+
&& responseFormat.type !== 'text';
|
|
343
|
+
const systemPrompt = typeof parsed.system === 'string'
|
|
344
|
+
? parsed.system
|
|
345
|
+
: Array.isArray(parsed.system)
|
|
346
|
+
? parsed.system
|
|
347
|
+
.filter((part) => part.type === 'text')
|
|
348
|
+
.map((part) => part.text ?? '')
|
|
349
|
+
.join('\n')
|
|
350
|
+
: undefined;
|
|
351
|
+
// Same local Router core as ClawRouter. The proxy supplies
|
|
352
|
+
// concrete request capabilities; no classifier call is added.
|
|
353
|
+
const routing = routeRequest(promptText, routingProfile, {
|
|
354
|
+
needsVision: proxyNeedsVision,
|
|
355
|
+
maxOutputTokens: typeof parsed.max_tokens === 'number'
|
|
356
|
+
? parsed.max_tokens
|
|
357
|
+
: DEFAULT_MAX_TOKENS,
|
|
358
|
+
hasTools: toolNames.length > 0,
|
|
359
|
+
toolNames,
|
|
360
|
+
...(explicitToolRequirement !== undefined
|
|
361
|
+
? { requiresTools: explicitToolRequirement }
|
|
362
|
+
: {}),
|
|
363
|
+
requiresStructuredOutput,
|
|
364
|
+
systemPrompt,
|
|
365
|
+
});
|
|
325
366
|
parsed.model = routing.model;
|
|
326
367
|
requestModel = routing.model;
|
|
368
|
+
routerCandidates = routing.candidates ?? [routing.model];
|
|
327
369
|
logger.info(`[franklin] 🧠 Smart routing: ${routingProfile} → ${routing.tier} → ${routing.model} ` +
|
|
328
370
|
`(${(routing.savings * 100).toFixed(0)}% savings) [${routing.signals.join(', ')}]`);
|
|
329
371
|
}
|
|
@@ -408,7 +450,12 @@ export function createProxy(options) {
|
|
|
408
450
|
if (fallbackEnabled && body && requestPath.includes('messages')) {
|
|
409
451
|
const fallbackConfig = {
|
|
410
452
|
...DEFAULT_FALLBACK_CONFIG,
|
|
411
|
-
chain:
|
|
453
|
+
chain: [
|
|
454
|
+
...new Set([
|
|
455
|
+
...routerCandidates,
|
|
456
|
+
...buildFallbackChain(requestModel),
|
|
457
|
+
]),
|
|
458
|
+
],
|
|
412
459
|
};
|
|
413
460
|
const result = await fetchWithPaymentFallback(targetUrl, requestInit, body, fallbackConfig, {
|
|
414
461
|
method: req.method || 'POST',
|
package/dist/router/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* and picks the model with the best quality-to-cost ratio for that category.
|
|
10
10
|
* Local Elo adjustments personalize routing per user over time.
|
|
11
11
|
*/
|
|
12
|
+
import { type TaskType } from '@blockrun/router-core';
|
|
12
13
|
import { type Category } from './categories.js';
|
|
13
14
|
export { isVisionModel, messageNeedsVision, messagesNeedVision, pickVisionSibling } from './vision.js';
|
|
14
15
|
export type Tier = 'SIMPLE' | 'MEDIUM' | 'COMPLEX' | 'REASONING';
|
|
@@ -20,6 +21,23 @@ export interface RoutingResult {
|
|
|
20
21
|
signals: string[];
|
|
21
22
|
savings: number;
|
|
22
23
|
category?: Category;
|
|
24
|
+
/** Ordered capability-eligible recovery chain. The selected model is first. */
|
|
25
|
+
candidates?: string[];
|
|
26
|
+
/** Explainable task class produced by the shared Router core. */
|
|
27
|
+
taskType?: TaskType;
|
|
28
|
+
/** Shared Router implementation that made this decision. */
|
|
29
|
+
routerVersion?: 'v2-rules' | 'v3-portfolio' | 'franklin-legacy';
|
|
30
|
+
reasoning?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Request capabilities known by the Franklin host at routing time. */
|
|
33
|
+
export interface RoutingContext {
|
|
34
|
+
needsVision?: boolean;
|
|
35
|
+
maxOutputTokens?: number;
|
|
36
|
+
hasTools?: boolean;
|
|
37
|
+
toolNames?: readonly string[];
|
|
38
|
+
requiresTools?: boolean;
|
|
39
|
+
requiresStructuredOutput?: boolean;
|
|
40
|
+
systemPrompt?: string;
|
|
23
41
|
}
|
|
24
42
|
export type TierClassifier = (prompt: string) => Promise<Tier | null>;
|
|
25
43
|
/**
|
|
@@ -30,11 +48,12 @@ export type TierClassifier = (prompt: string) => Promise<Tier | null>;
|
|
|
30
48
|
*/
|
|
31
49
|
export declare function llmClassifyRequest(prompt: string): Promise<Tier | null>;
|
|
32
50
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
51
|
+
* Compatibility async router. Production Auto routing is local and delegates
|
|
52
|
+
* directly to the shared Router core, so it adds no classifier round trip.
|
|
53
|
+
* Tests and third-party integrations may still inject an explicit classifier;
|
|
54
|
+
* that legacy path remains available during the migration window.
|
|
36
55
|
*/
|
|
37
|
-
export declare function routeRequestAsync(prompt: string, profile?: RoutingProfile, classify?: TierClassifier,
|
|
56
|
+
export declare function routeRequestAsync(prompt: string, profile?: RoutingProfile, classify?: TierClassifier, context?: boolean | RoutingContext): Promise<RoutingResult>;
|
|
38
57
|
/**
|
|
39
58
|
* Map a pre-classified tier to a concrete model + savings using the profile's
|
|
40
59
|
* tier table. No classifier call — assumes the caller already decided the
|
|
@@ -45,7 +64,7 @@ export declare function routeRequestAsync(prompt: string, profile?: RoutingProfi
|
|
|
45
64
|
* need the classifier to produce the tier.
|
|
46
65
|
*/
|
|
47
66
|
export declare function resolveTierToModel(tier: Tier, profile?: RoutingProfile, needsVision?: boolean): RoutingResult;
|
|
48
|
-
export declare function routeRequest(prompt: string, profile?: RoutingProfile,
|
|
67
|
+
export declare function routeRequest(prompt: string, profile?: RoutingProfile, context?: boolean | RoutingContext): RoutingResult;
|
|
49
68
|
/**
|
|
50
69
|
* Get fallback models for a tier
|
|
51
70
|
*/
|
package/dist/router/index.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
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
15
|
import { MODEL_PRICING, OPUS_PRICING } from '../pricing.js';
|
|
15
16
|
import { BLOCKRUN_DIR } from '../config.js';
|
|
16
17
|
import { detectCategory, mapCategoryToTier } from './categories.js';
|
|
@@ -34,6 +35,17 @@ function loadLearnedWeights() {
|
|
|
34
35
|
cachedWeights = null;
|
|
35
36
|
return null;
|
|
36
37
|
}
|
|
38
|
+
const SHARED_MODEL_PRICING = new Map(Object.entries(MODEL_PRICING).map(([model, pricing]) => [
|
|
39
|
+
model,
|
|
40
|
+
{
|
|
41
|
+
inputPrice: pricing.input,
|
|
42
|
+
outputPrice: pricing.output,
|
|
43
|
+
...(pricing.perCall !== undefined ? { flatPrice: pricing.perCall } : {}),
|
|
44
|
+
},
|
|
45
|
+
]));
|
|
46
|
+
function normalizeRoutingContext(context) {
|
|
47
|
+
return typeof context === 'boolean' ? { needsVision: context } : context;
|
|
48
|
+
}
|
|
37
49
|
// ─── Tier Model Configs ───
|
|
38
50
|
// Auto-routing strategy (post-DeepSeek-V4-Pro launch promo, 2026-05-03):
|
|
39
51
|
// V4 Pro at $0.435/$0.87 with 1M context is the new sweet spot for SIMPLE +
|
|
@@ -320,10 +332,23 @@ function classicRouteRequest(prompt, profile, needsVision = false) {
|
|
|
320
332
|
// - Exposed via async `routeRequestAsync(prompt, profile, classify?)`. Callers
|
|
321
333
|
// that can't be async (proxy, LLM-client bootstrap) keep using the sync
|
|
322
334
|
// `routeRequest`, which silently does keyword-only routing.
|
|
323
|
-
//
|
|
324
|
-
//
|
|
325
|
-
//
|
|
326
|
-
|
|
335
|
+
// The classifier needs a free model that answers with ONE BARE WORD under a
|
|
336
|
+
// tight max_tokens. That is a narrower requirement than "is a good free chat
|
|
337
|
+
// model", and most of the free pool fails it by streaming chain-of-thought
|
|
338
|
+
// into `content` (glm-4.7 and the qwen-thinking builds emit reasoning and
|
|
339
|
+
// leave text empty; nemotron-nano-9b-v2 opens with "Okay, let's see. The user
|
|
340
|
+
// wants to…" and never reaches a verdict inside the budget).
|
|
341
|
+
//
|
|
342
|
+
// 2026-08-19: the previous default, nvidia/qwen3-next-80b-a3b-instruct, was
|
|
343
|
+
// EOL'd by NVIDIA (410 on 2026-07-27) — the gateway now rides its calls on
|
|
344
|
+
// nemotron-3-super-120b, which leaks prose. Every classification has been
|
|
345
|
+
// failing the strict parse and falling through to keyword-only routing ever
|
|
346
|
+
// since, silently, because the fallback is by design invisible.
|
|
347
|
+
//
|
|
348
|
+
// nemotron-3-nano-omni is the replacement: live-probed on this exact prompt
|
|
349
|
+
// shape it returns "MEDIUM" and nothing else, and it verifiably serves itself
|
|
350
|
+
// rather than riding a pooled substitute.
|
|
351
|
+
const CLASSIFIER_MODEL = process.env.FRANKLIN_ROUTER_MODEL || 'nvidia/nemotron-3-nano-omni-30b-a3b-reasoning';
|
|
327
352
|
const CLASSIFIER_TIMEOUT_MS = 2_500;
|
|
328
353
|
const CLASSIFIER_SYSTEM = `You classify a user's message into ONE routing tier for a CLI agent. Reply with EXACTLY ONE WORD from the allowed set. No explanation, no punctuation, no quotes.
|
|
329
354
|
|
|
@@ -396,25 +421,28 @@ export async function llmClassifyRequest(prompt) {
|
|
|
396
421
|
}
|
|
397
422
|
}
|
|
398
423
|
/**
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
424
|
+
* Compatibility async router. Production Auto routing is local and delegates
|
|
425
|
+
* directly to the shared Router core, so it adds no classifier round trip.
|
|
426
|
+
* Tests and third-party integrations may still inject an explicit classifier;
|
|
427
|
+
* that legacy path remains available during the migration window.
|
|
402
428
|
*/
|
|
403
|
-
export async function routeRequestAsync(prompt, profile = 'auto', classify
|
|
404
|
-
//
|
|
405
|
-
|
|
406
|
-
|
|
429
|
+
export async function routeRequestAsync(prompt, profile = 'auto', classify, context = false) {
|
|
430
|
+
// The production path intentionally has no extra model call. Keeping the
|
|
431
|
+
// function async avoids breaking existing callers while removing router
|
|
432
|
+
// latency and classifier spend.
|
|
433
|
+
if (!classify || profile === 'free')
|
|
434
|
+
return routeRequest(prompt, profile, context);
|
|
435
|
+
const normalizedContext = normalizeRoutingContext(context);
|
|
407
436
|
const tier = await classify(prompt).catch(() => null);
|
|
408
437
|
if (!tier) {
|
|
409
|
-
|
|
410
|
-
return routeRequest(prompt, profile, needsVision);
|
|
438
|
+
return routeRequest(prompt, profile, normalizedContext);
|
|
411
439
|
}
|
|
412
440
|
// Build a RoutingResult from the LLM-picked tier using the same tier
|
|
413
441
|
// tables the keyword path uses. Keeps downstream code path-identical.
|
|
414
442
|
let model;
|
|
415
443
|
let finalTier = tier;
|
|
416
444
|
const signals = ['llm-classified'];
|
|
417
|
-
if (needsVision) {
|
|
445
|
+
if (normalizedContext.needsVision) {
|
|
418
446
|
const v = pickVisionTierModel(tier);
|
|
419
447
|
model = v.model;
|
|
420
448
|
finalTier = v.tier;
|
|
@@ -444,17 +472,15 @@ export async function routeRequestAsync(prompt, profile = 'auto', classify = llm
|
|
|
444
472
|
*/
|
|
445
473
|
export function resolveTierToModel(tier, profile = 'auto', needsVision = false) {
|
|
446
474
|
// Free profile short-circuits — everything routes to a single free model.
|
|
447
|
-
//
|
|
448
|
-
//
|
|
449
|
-
//
|
|
450
|
-
// fail gracefully. (The only vision-capable free model is the Nemotron Omni
|
|
451
|
-
// line; revisit hard-falling to it if a real user hits this path.)
|
|
475
|
+
// Vision turns go to nemotron-nano-12b-v2-vl: the one vision-capable free
|
|
476
|
+
// model that verifiably serves itself (the 30B omni line is pooled onto a
|
|
477
|
+
// text-only substitute upstream, verified live 2026-08-12).
|
|
452
478
|
if (profile === 'free') {
|
|
453
479
|
return {
|
|
454
|
-
model: 'nvidia/
|
|
480
|
+
model: needsVision ? 'nvidia/nemotron-nano-12b-v2-vl' : 'nvidia/nemotron-nano-9b-v2',
|
|
455
481
|
tier: 'SIMPLE',
|
|
456
482
|
confidence: 1.0,
|
|
457
|
-
signals: needsVision ? ['free-profile', 'vision
|
|
483
|
+
signals: needsVision ? ['free-profile', 'free-vision'] : ['free-profile'],
|
|
458
484
|
savings: 1.0,
|
|
459
485
|
};
|
|
460
486
|
}
|
|
@@ -479,23 +505,64 @@ export function resolveTierToModel(tier, profile = 'auto', needsVision = false)
|
|
|
479
505
|
};
|
|
480
506
|
}
|
|
481
507
|
// ─── Main Router ───
|
|
482
|
-
export function routeRequest(prompt, profile = 'auto',
|
|
483
|
-
|
|
508
|
+
export function routeRequest(prompt, profile = 'auto', context = false) {
|
|
509
|
+
const normalizedContext = normalizeRoutingContext(context);
|
|
510
|
+
// Free profile — always use free model (vision turns get the free VL model;
|
|
511
|
+
// see resolveTierToModel for the rationale).
|
|
484
512
|
if (profile === 'free') {
|
|
485
513
|
return {
|
|
486
|
-
model: 'nvidia/
|
|
514
|
+
model: normalizedContext.needsVision ? 'nvidia/nemotron-nano-12b-v2-vl' : 'nvidia/nemotron-nano-9b-v2',
|
|
487
515
|
tier: 'SIMPLE',
|
|
488
516
|
confidence: 1.0,
|
|
489
|
-
signals: needsVision ? ['free-profile', 'vision
|
|
517
|
+
signals: normalizedContext.needsVision ? ['free-profile', 'free-vision'] : ['free-profile'],
|
|
490
518
|
savings: 1.0,
|
|
519
|
+
candidates: FREE_MODELS_BY_CATEGORY.chat,
|
|
491
520
|
};
|
|
492
521
|
}
|
|
493
|
-
//
|
|
494
|
-
//
|
|
495
|
-
//
|
|
496
|
-
|
|
522
|
+
// Emergency rollback for operators. This keeps the former Franklin rules
|
|
523
|
+
// available without making them the default or mixing their Elo state into
|
|
524
|
+
// the shared Router decision.
|
|
525
|
+
if (process.env.FRANKLIN_ROUTER_STRATEGY === 'legacy') {
|
|
526
|
+
return {
|
|
527
|
+
...classicRouteRequest(prompt, profile, normalizedContext.needsVision),
|
|
528
|
+
routerVersion: 'franklin-legacy',
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
// Auto now uses the same local, deterministic Router core as ClawRouter.
|
|
532
|
+
// Hard capability requirements filter candidates before portfolio scoring;
|
|
533
|
+
// no network request, wallet access, benchmark grader or settlement adapter
|
|
534
|
+
// runs in this path.
|
|
497
535
|
if (profile === 'auto') {
|
|
498
|
-
|
|
536
|
+
const toolNames = normalizedContext.toolNames ?? [];
|
|
537
|
+
const decision = routeWithSharedCore(prompt, normalizedContext.systemPrompt, Math.max(1, normalizedContext.maxOutputTokens ?? 4_096), {
|
|
538
|
+
config: {
|
|
539
|
+
...SHARED_ROUTING_CONFIG,
|
|
540
|
+
strategy: process.env.FRANKLIN_ROUTER_STRATEGY === 'rules' ? 'rules' : 'portfolio',
|
|
541
|
+
},
|
|
542
|
+
modelPricing: SHARED_MODEL_PRICING,
|
|
543
|
+
routingProfile: 'auto',
|
|
544
|
+
hasTools: normalizedContext.hasTools ?? toolNames.length > 0,
|
|
545
|
+
toolCount: toolNames.length,
|
|
546
|
+
toolNames,
|
|
547
|
+
...(normalizedContext.requiresTools !== undefined
|
|
548
|
+
? { requiresTools: normalizedContext.requiresTools }
|
|
549
|
+
: {}),
|
|
550
|
+
hasVision: normalizedContext.needsVision ?? false,
|
|
551
|
+
requiresStructuredOutput: normalizedContext.requiresStructuredOutput ?? false,
|
|
552
|
+
});
|
|
553
|
+
const category = detectCategory(prompt, loadLearnedWeights()?.category_keywords).category;
|
|
554
|
+
return {
|
|
555
|
+
model: decision.model,
|
|
556
|
+
tier: decision.tier,
|
|
557
|
+
confidence: decision.confidence,
|
|
558
|
+
signals: [decision.routerVersion ?? decision.method, ...(decision.taskType ? [decision.taskType] : [])],
|
|
559
|
+
savings: decision.savings,
|
|
560
|
+
category,
|
|
561
|
+
candidates: decision.candidates ?? [decision.model],
|
|
562
|
+
taskType: decision.taskType,
|
|
563
|
+
routerVersion: decision.routerVersion,
|
|
564
|
+
reasoning: decision.reasoning,
|
|
565
|
+
};
|
|
499
566
|
}
|
|
500
567
|
// ── Learned routing (if weights available) ──
|
|
501
568
|
const weights = loadLearnedWeights();
|
|
@@ -524,7 +591,7 @@ export function routeRequest(prompt, profile = 'auto', needsVision = false) {
|
|
|
524
591
|
// the turn needs vision, swap to the tier's first vision-capable model.
|
|
525
592
|
// We deliberately don't blend Elo with vision capability — vision is a
|
|
526
593
|
// hard requirement, not a quality dimension.
|
|
527
|
-
if (needsVision && !isVisionModel(selected.model)) {
|
|
594
|
+
if (normalizedContext.needsVision && !isVisionModel(selected.model)) {
|
|
528
595
|
const v = pickVisionTierModel(tier);
|
|
529
596
|
return {
|
|
530
597
|
model: v.model,
|
|
@@ -548,7 +615,7 @@ export function routeRequest(prompt, profile = 'auto', needsVision = false) {
|
|
|
548
615
|
// Fall through to classic if selectModel returns null (no candidates for category)
|
|
549
616
|
}
|
|
550
617
|
// ── Classic routing (keyword-based fallback) ──
|
|
551
|
-
return classicRouteRequest(prompt, profile, needsVision);
|
|
618
|
+
return classicRouteRequest(prompt, profile, normalizedContext.needsVision);
|
|
552
619
|
}
|
|
553
620
|
function computeSavings(model) {
|
|
554
621
|
const opusCostPer1K = (OPUS_PRICING.input + OPUS_PRICING.output) / 2 / 1000;
|
|
@@ -589,16 +656,35 @@ export function getFallbackChain(tier, profile = 'auto') {
|
|
|
589
656
|
// entries backed by the same pooled model is fake resilience: the fallback
|
|
590
657
|
// couldn't rescue a turn the primary had already failed. mistral-nemotron
|
|
591
658
|
// verifiably serves itself, so the chain is genuinely two families again.
|
|
659
|
+
// 2026-08-12: nvidia/qwen3-next-80b-a3b-instruct removed — NVIDIA EOL'd it
|
|
660
|
+
// (410 on 2026-07-27; the gateway hid it and rides its calls on a fallback).
|
|
661
|
+
// nemotron-nano-9b-v2 promoted to lead: it is the only free text model that
|
|
662
|
+
// verifiably serves ITSELF on the streaming path Franklin uses (verified live
|
|
663
|
+
// through the binary today). mistral-nemotron is DEGRADED at NVIDIA — stream
|
|
664
|
+
// calls 400 ("DEGRADED function cannot be invoked") and non-stream calls ride
|
|
665
|
+
// the gateway's disclosed fallback.
|
|
666
|
+
// 2026-08-19: nvidia/nemotron-3-nano-omni-30b-a3b-reasoning promoted to
|
|
667
|
+
// second. When it was last probed it came back served as gpt-oss-120b — the
|
|
668
|
+
// pooled-substitute trap this comment warns about — but NVIDIA has since
|
|
669
|
+
// fixed it: it now answers as ITSELF on both the streaming and non-streaming
|
|
670
|
+
// paths, and it returns clean single-word output under tight max_tokens (it
|
|
671
|
+
// is also the router's classifier for that reason). mistral-nemotron drops to
|
|
672
|
+
// third: still DEGRADED at NVIDIA, kept as a genuinely different family for
|
|
673
|
+
// the case where both Nemotron nano builds are down. The catalog's fifth free
|
|
674
|
+
// 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.
|
|
676
|
+
const OMNI = 'nvidia/nemotron-3-nano-omni-30b-a3b-reasoning';
|
|
592
677
|
const FREE_MODELS_BY_CATEGORY = {
|
|
593
|
-
coding: ['nvidia/
|
|
594
|
-
trading: ['nvidia/
|
|
595
|
-
research: ['nvidia/
|
|
596
|
-
reasoning: ['nvidia/
|
|
597
|
-
chat: ['nvidia/
|
|
598
|
-
creative: ['nvidia/
|
|
678
|
+
coding: ['nvidia/nemotron-nano-9b-v2', OMNI, 'nvidia/mistral-nemotron'],
|
|
679
|
+
trading: ['nvidia/nemotron-nano-9b-v2', OMNI, 'nvidia/mistral-nemotron'],
|
|
680
|
+
research: ['nvidia/nemotron-nano-9b-v2', OMNI, 'nvidia/mistral-nemotron'],
|
|
681
|
+
reasoning: ['nvidia/nemotron-nano-9b-v2', OMNI, 'nvidia/mistral-nemotron'],
|
|
682
|
+
chat: ['nvidia/nemotron-nano-9b-v2', OMNI, 'nvidia/mistral-nemotron'],
|
|
683
|
+
creative: ['nvidia/nemotron-nano-9b-v2', OMNI, 'nvidia/mistral-nemotron'],
|
|
599
684
|
};
|
|
600
685
|
const DEFAULT_FREE_CHAIN = [
|
|
601
|
-
'nvidia/
|
|
686
|
+
'nvidia/nemotron-nano-9b-v2',
|
|
687
|
+
OMNI,
|
|
602
688
|
'nvidia/mistral-nemotron',
|
|
603
689
|
];
|
|
604
690
|
/**
|
package/dist/router/vision.js
CHANGED
|
@@ -35,32 +35,54 @@ const VISION_MODELS = new Set([
|
|
|
35
35
|
'openai/gpt-5.6-sol',
|
|
36
36
|
'openai/gpt-5.6-terra',
|
|
37
37
|
'openai/gpt-5.6-luna',
|
|
38
|
+
// The pro reasoning tier is the same multimodal base with thinking on.
|
|
39
|
+
'openai/gpt-5.6-sol-pro',
|
|
40
|
+
'openai/gpt-5.6-terra-pro',
|
|
41
|
+
'openai/gpt-5.6-luna-pro',
|
|
38
42
|
'openai/gpt-5.5',
|
|
43
|
+
'openai/gpt-5.5-pro',
|
|
44
|
+
// The rolling ChatGPT default — vision-tagged in the catalog.
|
|
45
|
+
'openai/chat-latest',
|
|
39
46
|
'openai/gpt-5.4',
|
|
40
47
|
'openai/gpt-5.4-pro',
|
|
41
48
|
'openai/gpt-5.4-mini',
|
|
42
49
|
'openai/gpt-5.2',
|
|
43
50
|
'openai/gpt-5.2-pro',
|
|
44
51
|
'openai/gpt-5-mini',
|
|
52
|
+
'openai/gpt-5.3',
|
|
45
53
|
'openai/gpt-4.1',
|
|
54
|
+
'openai/gpt-4o',
|
|
46
55
|
'openai/o3',
|
|
47
56
|
// Google — vision baked into every Gemini SKU we surface (flash-lite excepted)
|
|
48
57
|
'google/gemini-3.1-pro',
|
|
58
|
+
'google/gemini-3.6-flash',
|
|
49
59
|
'google/gemini-3.5-flash',
|
|
60
|
+
'google/gemini-3-flash-preview',
|
|
50
61
|
'google/gemini-2.5-pro',
|
|
51
62
|
'google/gemini-2.5-flash',
|
|
52
|
-
// xAI —
|
|
63
|
+
// xAI — grok-4-1-fast-reasoning stays out (text-only). Grok 4.5 and 4.3 are
|
|
64
|
+
// both vision-capable in the catalog and were missing here until 2026-08-20:
|
|
65
|
+
// `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.
|
|
67
|
+
'xai/grok-4.5',
|
|
68
|
+
'xai/grok-4.3',
|
|
53
69
|
'xai/grok-4-0709',
|
|
54
70
|
'xai/grok-3',
|
|
55
|
-
// Moonshot — K3
|
|
56
|
-
//
|
|
57
|
-
// retired K2.7/K2.6 line.
|
|
71
|
+
// Moonshot — K3 is the Solana flagship; the K2.x compatibility line remains
|
|
72
|
+
// routable on both gateways and is also catalogued as multimodal.
|
|
58
73
|
'moonshot/kimi-k3',
|
|
74
|
+
'moonshot/kimi-k2.7',
|
|
75
|
+
'moonshot/kimi-k2.6',
|
|
76
|
+
'moonshot/kimi-k2.5',
|
|
59
77
|
// NVIDIA inference — Nemotron Nano VL is multimodal; deepseek/qwen-coder are
|
|
60
78
|
// not. Llama 4 Maverick dropped 2026-07-14: it left the gateway catalog, and
|
|
61
79
|
// listing it here contradicted routeRequest()'s own "maverick is text-only"
|
|
62
80
|
// note — the free profile would route a vision turn to a text-only model.
|
|
63
81
|
'nvidia/nemotron-nano-12b-v2-vl',
|
|
82
|
+
// Nemotron 3 Nano Omni accepts text, images, video and audio, and now serves
|
|
83
|
+
// itself (2026-08-19 probe) — it is the strongest free vision option in the
|
|
84
|
+
// catalog on ChartQA / DocVQA / MMMU.
|
|
85
|
+
'nvidia/nemotron-3-nano-omni-30b-a3b-reasoning',
|
|
64
86
|
]);
|
|
65
87
|
/** Does this concrete gateway model accept image input? */
|
|
66
88
|
export function isVisionModel(modelId) {
|
package/dist/serve/server.js
CHANGED
|
@@ -36,10 +36,10 @@ import { setupAgentWallet, setupAgentSolanaWallet } from '@blockrun/llm';
|
|
|
36
36
|
import { retryFetchBalance } from '../commands/balance-retry.js';
|
|
37
37
|
import { AgentHost } from './agent-host.js';
|
|
38
38
|
import { bus } from '../events/bus.js';
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
const FREE_DEFAULT_MODEL = 'nvidia/
|
|
39
|
+
// nemotron-nano-9b-v2: the one free model that verifiably serves itself on
|
|
40
|
+
// the STREAMING path (verified live 2026-08-12 — mistral-nemotron is DEGRADED
|
|
41
|
+
// at NVIDIA and 400s on stream; qwen3-next-80b-a3b-instruct hit NVIDIA's EOL).
|
|
42
|
+
const FREE_DEFAULT_MODEL = 'nvidia/nemotron-nano-9b-v2';
|
|
43
43
|
// Curated Base (chainId 8453) tokens for the wallet "holdings" view. Plain RPC
|
|
44
44
|
// can't enumerate every token an address holds (no on-chain "list all"), so we
|
|
45
45
|
// balanceOf a known set and show the non-zero ones. `stable` → USD ≈ amount.
|
|
@@ -112,7 +112,7 @@ export function createContentCapabilities(deps) {
|
|
|
112
112
|
properties: {
|
|
113
113
|
id: { type: 'string', description: 'Content id returned by ContentCreate' },
|
|
114
114
|
kind: { type: 'string', description: 'image, audio, video, or text' },
|
|
115
|
-
source: { type: 'string', description: 'Generator model or "manual" (e.g. "openai/
|
|
115
|
+
source: { type: 'string', description: 'Generator model or "manual" (e.g. "openai/gpt-image-2")' },
|
|
116
116
|
costUsd: { type: 'number', description: 'Actual USD spent producing this asset' },
|
|
117
117
|
data: { type: 'string', description: 'Optional URL or inline text reference to the asset' },
|
|
118
118
|
},
|