@blockrun/franklin 3.41.0 → 3.42.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/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,45 @@ 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
- 'zai/glm-5.1-turbo': { input: 1.2, output: 4.0 }, // client alias for zai/glm-5-turbo
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
+ 'xai/grok-4-0709': { input: 3.0, output: 15.0 }, // (probed) gateway lists $3/$15 (was mispriced here at $0.2/$1.5)
152
+ 'xai/grok-3-mini': { input: 0.3, output: 0.5 }, // (probed)
153
+ 'xai/grok-2-vision': { input: 2.0, output: 10.0 },
154
+ 'xai/grok-3': { input: 3.0, output: 15.0 }, // (probed)
155
+ 'minimax/minimax-m2.5': { input: 0.3, output: 1.2 },
156
+ // K2.x (probed): the bare `kimi`/`k2.*` shortcuts resolve to K3, the
157
+ // explicit ids still answer.
158
+ 'moonshot/kimi-k2.7': { input: 0.95, output: 4.0 },
159
+ 'moonshot/kimi-k2.6': { input: 0.95, output: 4.0 },
160
+ 'moonshot/kimi-k2.5': { input: 0.6, output: 3.0 },
161
+ 'nvidia/kimi-k2.5': { input: 0.55, output: 2.5 },
162
+ 'zai/glm-5.1-turbo': { input: 1.2, output: 4.0 }, // was a client alias for zai/glm-5-turbo
150
163
  };
151
164
  /** Opus pricing for savings calculations — tracks the current flagship. */
152
165
  export const OPUS_PRICING = MODEL_PRICING['anthropic/claude-opus-5'];
@@ -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
@@ -43,6 +43,81 @@ 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
+ }
46
121
  function normalizeRoutingContext(context) {
47
122
  return typeof context === 'boolean' ? { needsVision: context } : context;
48
123
  }
@@ -83,6 +158,7 @@ const AUTO_TIERS = {
83
158
  'anthropic/claude-opus-4.7',
84
159
  'openai/o3',
85
160
  'deepseek/deepseek-v4-pro',
161
+ // Hidden from /v1/models but still served (probed 2026-08-29).
86
162
  'xai/grok-4-1-fast-reasoning',
87
163
  'deepseek/deepseek-reasoner',
88
164
  ],
@@ -549,6 +625,7 @@ export function routeRequest(prompt, profile = 'auto', context = false) {
549
625
  : {}),
550
626
  hasVision: normalizedContext.needsVision ?? false,
551
627
  requiresStructuredOutput: normalizedContext.requiresStructuredOutput ?? false,
628
+ unavailableModels: getUnavailableModels(normalizedContext.unavailableModels),
552
629
  });
553
630
  const category = detectCategory(prompt, loadLearnedWeights()?.category_keywords).category;
554
631
  return {
@@ -672,7 +749,9 @@ export function getFallbackChain(tier, profile = 'auto') {
672
749
  // third: still DEGRADED at NVIDIA, kept as a genuinely different family for
673
750
  // the case where both Nemotron nano builds are down. The catalog's fifth free
674
751
  // 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.
752
+ // content AND comes back served by nemotron-3-super-120b (re-probed
753
+ // 2026-08-29, unchanged). It is also QUARANTINED for the shared Router above,
754
+ // which would otherwise use it as the free backstop rung of every Auto chain.
676
755
  const OMNI = 'nvidia/nemotron-3-nano-omni-30b-a3b-reasoning';
677
756
  const FREE_MODELS_BY_CATEGORY = {
678
757
  coding: ['nvidia/nemotron-nano-9b-v2', OMNI, 'nvidia/mistral-nemotron'],
@@ -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 Solana flagship; the K2.x compatibility line remains
72
- // routable on both gateways and is also catalogued as multimodal.
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. */
@@ -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 = createSubAgentCapability(this.opts.apiUrl, this.opts.chain, allCapabilities, model);
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
- ...(options.maxSpendUsd != null ? { maxSpendUsd: options.maxSpendUsd } : {}),
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);
@@ -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;