@blockrun/franklin 3.43.0 → 3.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,4 +44,4 @@ export declare const ROUTING_PROFILES: Set<string>;
44
44
  * nothing more than provider overload. `blockrun/free` was already handled;
45
45
  * a concrete free id was not.
46
46
  */
47
- export declare function buildFallbackChain(startModel: string, config?: FallbackConfig): string[];
47
+ export declare function buildFallbackChain(startModel: string, config?: FallbackConfig, needsVision?: boolean): string[];
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { logger } from '../logger.js';
6
6
  import { FREE_DEFAULT_MODEL, isFreeModelId } from '../free-models.js';
7
+ import { isVisionModel } from '../router/vision.js';
7
8
  export const DEFAULT_FALLBACK_CONFIG = {
8
9
  chain: [
9
10
  'deepseek/deepseek-chat', // Direct fallback — cheap & reliable
@@ -124,9 +125,27 @@ export const ROUTING_PROFILES = new Set([
124
125
  * nothing more than provider overload. `blockrun/free` was already handled;
125
126
  * a concrete free id was not.
126
127
  */
127
- export function buildFallbackChain(startModel, config = DEFAULT_FALLBACK_CONFIG) {
128
+ export function buildFallbackChain(startModel, config = DEFAULT_FALLBACK_CONFIG, needsVision = false) {
128
129
  // Never include routing profiles in the chain — they'd cause 400s
129
- const safeChain = config.chain.filter(m => !ROUTING_PROFILES.has(m));
130
+ let safeChain = config.chain.filter(m => !ROUTING_PROFILES.has(m));
131
+ // A request carrying images must not fall back onto a text-only model.
132
+ //
133
+ // The pre-request guard in proxy/server.ts swaps a text-only pick for a
134
+ // vision sibling, but it runs ONCE, before the call. This chain is walked
135
+ // AFTER a failure, so the guard was bypassed on every retry: an image sent
136
+ // to claude-sonnet-4.6 that hit a 429 fell straight to
137
+ // deepseek/deepseek-chat, which cannot read images at all.
138
+ //
139
+ // That costs real money. The gateway does not always refuse these before
140
+ // payment — probed 2026-08-31, Base returns 402 (a payment quote) for an
141
+ // image request to deepseek/deepseek-chat and the whole zai/glm-5.x line,
142
+ // while Solana correctly 400s them pre-payment. So on Base the retry is
143
+ // quoted, signed, settled, and THEN rejected upstream — or worse, answered
144
+ // without the image. Same shape as the free-tier guard above: the chain has
145
+ // to know what the request needs, not just what it costs.
146
+ if (needsVision) {
147
+ safeChain = safeChain.filter(m => isVisionModel(m));
148
+ }
130
149
  // Free start model → free-only chain. Ends the walk rather than reaching for
131
150
  // a paid rung; the caller gets the failure instead of a surprise charge.
132
151
  if (isFreeModelId(startModel)) {
@@ -180,6 +180,28 @@ function withinRateLimit() {
180
180
  rateWindow.push(now);
181
181
  return true;
182
182
  }
183
+ /**
184
+ * Does this raw request body carry image content?
185
+ *
186
+ * The pre-request vision guard computes this from the already-parsed body, but
187
+ * that binding is out of scope by the time the FALLBACK chain is built — and
188
+ * the fallback walk is exactly where an unguarded retry drops an image onto a
189
+ * text-only model the gateway will still charge for. Re-derived from the raw
190
+ * body so the retry path cannot silently lose the requirement.
191
+ */
192
+ function bodyNeedsVision(body) {
193
+ if (!body)
194
+ return false;
195
+ try {
196
+ const parsed = JSON.parse(body);
197
+ return messagesNeedVision((parsed.messages ?? []));
198
+ }
199
+ catch {
200
+ // Unparseable body: assume no images rather than filtering the chain down
201
+ // on a guess. The pre-request guard already ran on the parsed copy.
202
+ return false;
203
+ }
204
+ }
183
205
  export function createProxy(options) {
184
206
  // Wire stderr-mirroring of unified logger output to the proxy's debug
185
207
  // flag — same pattern as interactiveSession in agent/loop. File writes
@@ -467,7 +489,11 @@ export function createProxy(options) {
467
489
  chain: [
468
490
  ...new Set([
469
491
  ...routerCandidates,
470
- ...buildFallbackChain(requestModel),
492
+ // Recomputed here rather than reused from the pre-request
493
+ // guard above: that const is out of scope by this point, and
494
+ // without it the RETRY path drops images onto a text-only
495
+ // model that the gateway will happily charge for.
496
+ ...buildFallbackChain(requestModel, DEFAULT_FALLBACK_CONFIG, bodyNeedsVision(body)),
471
497
  ]),
472
498
  ],
473
499
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/franklin",
3
- "version": "3.43.0",
3
+ "version": "3.43.1",
4
4
  "description": "Franklin Agent \u2014 The AI agent with a wallet. Spends USDC autonomously to get real work done. Pay per action, no subscriptions.",
5
5
  "type": "module",
6
6
  "exports": {