@blockrun/franklin 3.37.0 → 3.39.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.
Files changed (54) hide show
  1. package/README.md +8 -8
  2. package/dist/agent/compact.js +1 -1
  3. package/dist/agent/context.js +3 -3
  4. package/dist/agent/evaluator.js +1 -1
  5. package/dist/agent/llm.js +6 -6
  6. package/dist/agent/loop.js +25 -9
  7. package/dist/agent/tokens.js +17 -3
  8. package/dist/agent/turn-analyzer.js +6 -4
  9. package/dist/agent/verification.js +1 -1
  10. package/dist/commands/slack.js +1 -1
  11. package/dist/commands/social.js +1 -1
  12. package/dist/commands/telegram.js +1 -1
  13. package/dist/content/image-pricing.js +23 -0
  14. package/dist/content/library.d.ts +1 -1
  15. package/dist/gateway-models.d.ts +14 -4
  16. package/dist/gateway-models.js +18 -5
  17. package/dist/learnings/extractor.js +2 -2
  18. package/dist/plugin-sdk/workflow.d.ts +1 -1
  19. package/dist/plugin-sdk/workflow.js +2 -2
  20. package/dist/pricing.js +39 -19
  21. package/dist/proxy/fallback.js +1 -1
  22. package/dist/proxy/server.js +52 -5
  23. package/dist/router/index.d.ts +24 -5
  24. package/dist/router/index.js +100 -35
  25. package/dist/router/vision.js +5 -3
  26. package/dist/serve/server.js +4 -4
  27. package/dist/tools/content-execute.js +1 -1
  28. package/dist/tools/moa.js +3 -3
  29. package/dist/tools/polymarket/client.d.ts +5 -5
  30. package/dist/tools/polymarket/client.js +26 -11
  31. package/dist/tools/polymarket/constants.d.ts +25 -26
  32. package/dist/tools/polymarket/constants.js +65 -31
  33. package/dist/tools/polymarket/creds.d.ts +10 -0
  34. package/dist/tools/polymarket/creds.js +7 -1
  35. package/dist/tools/polymarket/fund.js +15 -3
  36. package/dist/tools/polymarket/orders.js +14 -7
  37. package/dist/tools/polymarket/positions.js +1 -1
  38. package/dist/tools/polymarket/redeem.d.ts +26 -0
  39. package/dist/tools/polymarket/redeem.js +180 -33
  40. package/dist/tools/polymarket/relayer.d.ts +20 -10
  41. package/dist/tools/polymarket/relayer.js +57 -37
  42. package/dist/tools/polymarket/setup.d.ts +20 -0
  43. package/dist/tools/polymarket/setup.js +135 -53
  44. package/dist/tools/polymarket/transactions.d.ts +9 -0
  45. package/dist/tools/polymarket/transactions.js +22 -0
  46. package/dist/tools/polymarket/withdraw.d.ts +15 -0
  47. package/dist/tools/polymarket/withdraw.js +173 -23
  48. package/dist/tools/prediction.d.ts +5 -2
  49. package/dist/tools/prediction.js +21 -44
  50. package/dist/tools/subagent.js +1 -1
  51. package/dist/tools/videogen.d.ts +4 -3
  52. package/dist/tools/videogen.js +9 -6
  53. package/dist/ui/model-picker.js +48 -39
  54. package/package.json +8 -5
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-07-11 to match live /v1/models).
12
- // qwen3-next-80b-a3b-instruct is the current free default (cleanest instruction-
13
- // following — verified live: no thinking leak, no markdown fences, reliable).
14
- 'nvidia/qwen3-next-80b-a3b-instruct': { input: 0, output: 0 },
15
- 'nvidia/qwen3.5-122b-a10b': { input: 0, output: 0 },
16
- 'nvidia/nemotron-3-nano-omni-30b-a3b-reasoning': { input: 0, output: 0 },
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
- 'openai/gpt-5.6-luna': { input: 1.0, output: 6.0 }, // cost-efficient GPT-5.6 tier, 1M ctx
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.5, output: 15.0 }, // balanced GPT-5.6 tier, 1M ctx
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
- 'google/gemini-3.5-flash': { input: 0.5, output: 3.0 }, // latest Flash w/ thinking, 1M ctx
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
- // dropped from $0.28/$0.42 to $0.20/$0.40, context bumped 128K→1M).
102
- 'deepseek/deepseek-chat': { input: 0.20, output: 0.40 },
103
- 'deepseek/deepseek-reasoner': { input: 0.20, output: 0.40 },
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,7 +141,7 @@ 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.6, output: 1.92 }, // flat promo ended 2026-06-06 — per-token now
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
127
147
  'zai/glm-5-turbo': { input: 1.2, output: 4.0 }, // flat promo ended 2026-06-06 — per-token now
@@ -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/qwen3-next-80b-a3b-instruct', // Free model as ultimate fallback (reliable instruction-follower)
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,
@@ -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-ultra-253b")
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
- // Route the request — propagate vision-need so AUTO_TIERS' V4
323
- // Pro default doesn't get picked for an image-bearing turn.
324
- const routing = routeRequest(promptText, routingProfile, proxyNeedsVision);
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: buildFallbackChain(requestModel),
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',
@@ -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
- * Async router — LLM classifier first, keyword classifier as fallback.
34
- * Profile-specific tier tables (AUTO / ECO / PREMIUM / FREE) still pick
35
- * the concrete model; the classifier only picks the TIER.
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, needsVision?: boolean): Promise<RoutingResult>;
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, needsVision?: boolean): RoutingResult;
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
  */
@@ -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 +
@@ -396,25 +408,28 @@ export async function llmClassifyRequest(prompt) {
396
408
  }
397
409
  }
398
410
  /**
399
- * Async router — LLM classifier first, keyword classifier as fallback.
400
- * Profile-specific tier tables (AUTO / ECO / PREMIUM / FREE) still pick
401
- * the concrete model; the classifier only picks the TIER.
411
+ * Compatibility async router. Production Auto routing is local and delegates
412
+ * directly to the shared Router core, so it adds no classifier round trip.
413
+ * Tests and third-party integrations may still inject an explicit classifier;
414
+ * that legacy path remains available during the migration window.
402
415
  */
403
- export async function routeRequestAsync(prompt, profile = 'auto', classify = llmClassifyRequest, needsVision = false) {
404
- // Free / short-circuit profiles — no classifier needed.
405
- if (profile === 'free')
406
- return routeRequest(prompt, profile, needsVision);
416
+ export async function routeRequestAsync(prompt, profile = 'auto', classify, context = false) {
417
+ // The production path intentionally has no extra model call. Keeping the
418
+ // function async avoids breaking existing callers while removing router
419
+ // latency and classifier spend.
420
+ if (!classify || profile === 'free')
421
+ return routeRequest(prompt, profile, context);
422
+ const normalizedContext = normalizeRoutingContext(context);
407
423
  const tier = await classify(prompt).catch(() => null);
408
424
  if (!tier) {
409
- // Classifier miss or disabled — fall through to the sync keyword router.
410
- return routeRequest(prompt, profile, needsVision);
425
+ return routeRequest(prompt, profile, normalizedContext);
411
426
  }
412
427
  // Build a RoutingResult from the LLM-picked tier using the same tier
413
428
  // tables the keyword path uses. Keeps downstream code path-identical.
414
429
  let model;
415
430
  let finalTier = tier;
416
431
  const signals = ['llm-classified'];
417
- if (needsVision) {
432
+ if (normalizedContext.needsVision) {
418
433
  const v = pickVisionTierModel(tier);
419
434
  model = v.model;
420
435
  finalTier = v.tier;
@@ -444,17 +459,15 @@ export async function routeRequestAsync(prompt, profile = 'auto', classify = llm
444
459
  */
445
460
  export function resolveTierToModel(tier, profile = 'auto', needsVision = false) {
446
461
  // Free profile short-circuits — everything routes to a single free model.
447
- // llama-4-maverick is text-only; on a vision turn the free profile can't
448
- // help us. Caller should detect this and warn the user that Free won't
449
- // handle images — for now we just return the free pick and let the model
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.)
462
+ // Vision turns go to nemotron-nano-12b-v2-vl: the one vision-capable free
463
+ // model that verifiably serves itself (the 30B omni line is pooled onto a
464
+ // text-only substitute upstream, verified live 2026-08-12).
452
465
  if (profile === 'free') {
453
466
  return {
454
- model: 'nvidia/qwen3-next-80b-a3b-instruct',
467
+ model: needsVision ? 'nvidia/nemotron-nano-12b-v2-vl' : 'nvidia/nemotron-nano-9b-v2',
455
468
  tier: 'SIMPLE',
456
469
  confidence: 1.0,
457
- signals: needsVision ? ['free-profile', 'vision-unsupported'] : ['free-profile'],
470
+ signals: needsVision ? ['free-profile', 'free-vision'] : ['free-profile'],
458
471
  savings: 1.0,
459
472
  };
460
473
  }
@@ -479,23 +492,64 @@ export function resolveTierToModel(tier, profile = 'auto', needsVision = false)
479
492
  };
480
493
  }
481
494
  // ─── Main Router ───
482
- export function routeRequest(prompt, profile = 'auto', needsVision = false) {
483
- // Free profile — always use free model
495
+ export function routeRequest(prompt, profile = 'auto', context = false) {
496
+ const normalizedContext = normalizeRoutingContext(context);
497
+ // Free profile — always use free model (vision turns get the free VL model;
498
+ // see resolveTierToModel for the rationale).
484
499
  if (profile === 'free') {
485
500
  return {
486
- model: 'nvidia/qwen3-next-80b-a3b-instruct',
501
+ model: normalizedContext.needsVision ? 'nvidia/nemotron-nano-12b-v2-vl' : 'nvidia/nemotron-nano-9b-v2',
487
502
  tier: 'SIMPLE',
488
503
  confidence: 1.0,
489
- signals: needsVision ? ['free-profile', 'vision-unsupported'] : ['free-profile'],
504
+ signals: normalizedContext.needsVision ? ['free-profile', 'free-vision'] : ['free-profile'],
490
505
  savings: 1.0,
506
+ candidates: FREE_MODELS_BY_CATEGORY.chat,
491
507
  };
492
508
  }
493
- // Auto profile bypasses learned routing. The learned Elo scores grow with
494
- // usage volume rather than pure quality, which biased the router toward
495
- // cheap/weak models on agentic work. Classic AUTO_TIERS defaults are
496
- // agent-tuned (Sonnet-tier backbone) and more predictable for users.
509
+ // Emergency rollback for operators. This keeps the former Franklin rules
510
+ // available without making them the default or mixing their Elo state into
511
+ // the shared Router decision.
512
+ if (process.env.FRANKLIN_ROUTER_STRATEGY === 'legacy') {
513
+ return {
514
+ ...classicRouteRequest(prompt, profile, normalizedContext.needsVision),
515
+ routerVersion: 'franklin-legacy',
516
+ };
517
+ }
518
+ // Auto now uses the same local, deterministic Router core as ClawRouter.
519
+ // Hard capability requirements filter candidates before portfolio scoring;
520
+ // no network request, wallet access, benchmark grader or settlement adapter
521
+ // runs in this path.
497
522
  if (profile === 'auto') {
498
- return classicRouteRequest(prompt, profile, needsVision);
523
+ const toolNames = normalizedContext.toolNames ?? [];
524
+ const decision = routeWithSharedCore(prompt, normalizedContext.systemPrompt, Math.max(1, normalizedContext.maxOutputTokens ?? 4_096), {
525
+ config: {
526
+ ...SHARED_ROUTING_CONFIG,
527
+ strategy: process.env.FRANKLIN_ROUTER_STRATEGY === 'rules' ? 'rules' : 'portfolio',
528
+ },
529
+ modelPricing: SHARED_MODEL_PRICING,
530
+ routingProfile: 'auto',
531
+ hasTools: normalizedContext.hasTools ?? toolNames.length > 0,
532
+ toolCount: toolNames.length,
533
+ toolNames,
534
+ ...(normalizedContext.requiresTools !== undefined
535
+ ? { requiresTools: normalizedContext.requiresTools }
536
+ : {}),
537
+ hasVision: normalizedContext.needsVision ?? false,
538
+ requiresStructuredOutput: normalizedContext.requiresStructuredOutput ?? false,
539
+ });
540
+ const category = detectCategory(prompt, loadLearnedWeights()?.category_keywords).category;
541
+ return {
542
+ model: decision.model,
543
+ tier: decision.tier,
544
+ confidence: decision.confidence,
545
+ signals: [decision.routerVersion ?? decision.method, ...(decision.taskType ? [decision.taskType] : [])],
546
+ savings: decision.savings,
547
+ category,
548
+ candidates: decision.candidates ?? [decision.model],
549
+ taskType: decision.taskType,
550
+ routerVersion: decision.routerVersion,
551
+ reasoning: decision.reasoning,
552
+ };
499
553
  }
500
554
  // ── Learned routing (if weights available) ──
501
555
  const weights = loadLearnedWeights();
@@ -524,7 +578,7 @@ export function routeRequest(prompt, profile = 'auto', needsVision = false) {
524
578
  // the turn needs vision, swap to the tier's first vision-capable model.
525
579
  // We deliberately don't blend Elo with vision capability — vision is a
526
580
  // hard requirement, not a quality dimension.
527
- if (needsVision && !isVisionModel(selected.model)) {
581
+ if (normalizedContext.needsVision && !isVisionModel(selected.model)) {
528
582
  const v = pickVisionTierModel(tier);
529
583
  return {
530
584
  model: v.model,
@@ -548,7 +602,7 @@ export function routeRequest(prompt, profile = 'auto', needsVision = false) {
548
602
  // Fall through to classic if selectModel returns null (no candidates for category)
549
603
  }
550
604
  // ── Classic routing (keyword-based fallback) ──
551
- return classicRouteRequest(prompt, profile, needsVision);
605
+ return classicRouteRequest(prompt, profile, normalizedContext.needsVision);
552
606
  }
553
607
  function computeSavings(model) {
554
608
  const opusCostPer1K = (OPUS_PRICING.input + OPUS_PRICING.output) / 2 / 1000;
@@ -589,16 +643,27 @@ export function getFallbackChain(tier, profile = 'auto') {
589
643
  // entries backed by the same pooled model is fake resilience: the fallback
590
644
  // couldn't rescue a turn the primary had already failed. mistral-nemotron
591
645
  // verifiably serves itself, so the chain is genuinely two families again.
646
+ // 2026-08-12: nvidia/qwen3-next-80b-a3b-instruct removed — NVIDIA EOL'd it
647
+ // (410 on 2026-07-27; the gateway hid it and rides its calls on a fallback).
648
+ // nemotron-nano-9b-v2 promoted to lead: it is the only free text model that
649
+ // verifiably serves ITSELF on the streaming path Franklin uses (verified live
650
+ // through the binary today). mistral-nemotron is DEGRADED at NVIDIA — stream
651
+ // calls 400 ("DEGRADED function cannot be invoked") and non-stream calls ride
652
+ // the gateway's disclosed fallback — so it sits second: it still answers
653
+ // non-streaming turns, and it upgrades the chain automatically if NVIDIA
654
+ // restores it. step-3.7-flash leaks thinking prose into content, and the 30B
655
+ // omni model came back served as nvidia/gpt-oss-120b (the pooled-substitute
656
+ // trap this comment already warns about).
592
657
  const FREE_MODELS_BY_CATEGORY = {
593
- coding: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/mistral-nemotron'],
594
- trading: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/mistral-nemotron'],
595
- research: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/mistral-nemotron'],
596
- reasoning: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/mistral-nemotron'],
597
- chat: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/mistral-nemotron'],
598
- creative: ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/mistral-nemotron'],
658
+ coding: ['nvidia/nemotron-nano-9b-v2', 'nvidia/mistral-nemotron'],
659
+ trading: ['nvidia/nemotron-nano-9b-v2', 'nvidia/mistral-nemotron'],
660
+ research: ['nvidia/nemotron-nano-9b-v2', 'nvidia/mistral-nemotron'],
661
+ reasoning: ['nvidia/nemotron-nano-9b-v2', 'nvidia/mistral-nemotron'],
662
+ chat: ['nvidia/nemotron-nano-9b-v2', 'nvidia/mistral-nemotron'],
663
+ creative: ['nvidia/nemotron-nano-9b-v2', 'nvidia/mistral-nemotron'],
599
664
  };
600
665
  const DEFAULT_FREE_CHAIN = [
601
- 'nvidia/qwen3-next-80b-a3b-instruct',
666
+ 'nvidia/nemotron-nano-9b-v2',
602
667
  'nvidia/mistral-nemotron',
603
668
  ];
604
669
  /**
@@ -52,10 +52,12 @@ const VISION_MODELS = new Set([
52
52
  // xAI — only Grok 4 base supports vision; grok-4-1-fast-reasoning is text-only
53
53
  'xai/grok-4-0709',
54
54
  'xai/grok-3',
55
- // Moonshot — K3 (flagship, 2026-07) is multimodal (image + text input);
56
- // gateway catalog lists it under the "vision" category. Replaced the
57
- // retired K2.7/K2.6 line.
55
+ // Moonshot — K3 is the Solana flagship; the K2.x compatibility line remains
56
+ // routable on both gateways and is also catalogued as multimodal.
58
57
  'moonshot/kimi-k3',
58
+ 'moonshot/kimi-k2.7',
59
+ 'moonshot/kimi-k2.6',
60
+ 'moonshot/kimi-k2.5',
59
61
  // NVIDIA inference — Nemotron Nano VL is multimodal; deepseek/qwen-coder are
60
62
  // not. Llama 4 Maverick dropped 2026-07-14: it left the gateway catalog, and
61
63
  // listing it here contradicted routeRequest()'s own "maverick is text-only"
@@ -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
- // qwen3-next-80b-a3b-instruct: cleanest free instruction-follower (no thinking
40
- // leak / markdown fences — verified live 2026-07-11). Replaces the EOL'd
41
- // nvidia/deepseek-v4-flash the gateway no longer serves.
42
- const FREE_DEFAULT_MODEL = 'nvidia/qwen3-next-80b-a3b-instruct';
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/dall-e-3")' },
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
  },
package/dist/tools/moa.js CHANGED
@@ -14,13 +14,13 @@ import { ModelClient } from '../agent/llm.js';
14
14
  // ─── Configuration ────────────────────────────────────────────────────────
15
15
  /** Reference models — diverse, cheap/free models for parallel queries. */
16
16
  const REFERENCE_MODELS = [
17
- 'nvidia/qwen3-next-80b-a3b-instruct', // Free, clean instruction-follower
18
- 'nvidia/mistral-nemotron', // Free, diverse family (maverick left the catalog 2026-07-14)
17
+ 'nvidia/nemotron-nano-9b-v2', // Free, serves itself on every path (qwen3-next EOL'd 2026-08-12)
18
+ 'nvidia/mistral-nemotron', // Free second voice (DEGRADED upstream; non-stream rides gateway fallback)
19
19
  'google/gemini-2.5-flash', // Fast, cheap
20
20
  'deepseek/deepseek-chat', // Cheap, good reasoning
21
21
  ];
22
22
  /** Aggregator model — free by default. Users explicitly pass `aggregator` to upgrade. */
23
- const AGGREGATOR_MODEL = 'nvidia/qwen3-next-80b-a3b-instruct';
23
+ const AGGREGATOR_MODEL = 'nvidia/nemotron-nano-9b-v2';
24
24
  /** Max tokens per reference response. */
25
25
  const REFERENCE_MAX_TOKENS = 4096;
26
26
  /** Max tokens for aggregator. */
@@ -52,10 +52,10 @@ export interface GeoblockStatus {
52
52
  * routes through POLYMARKET_CLOB_HOST, i.e. the exact egress real orders use.
53
53
  *
54
54
  * We deliberately do NOT trust polymarket.com/api/geoblock's boolean: it
55
- * reflects FRONTEND blocking (it returns blocked=true for Japan even though the
56
- * Japanese API accepts orders — verified: POST /order from a Tokyo egress
57
- * returns 401, not 403). The /api/geoblock call is kept only for country/ip
58
- * context. Cached 10 min; fail-open (unknown) on network error so a hiccup never
59
- * blocks a call that might succeed.
55
+ * reflects FRONTEND blocking, which can diverge from what the order API accepts
56
+ * (e.g. Japan returns blocked=true on the frontend while its API still accepts
57
+ * orders — POST /order there returns 401, not 403). The /api/geoblock call is
58
+ * kept only for country/ip context. Cached 10 min; fail-open (unknown) on
59
+ * network error so a hiccup never blocks a call that might succeed.
60
60
  */
61
61
  export declare function checkGeoblock(): Promise<GeoblockStatus>;