@blockrun/franklin 3.29.2 → 3.29.4

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 CHANGED
@@ -500,6 +500,10 @@ Same wallet. Same tools. From your phone.
500
500
 
501
501
  ## Documentation
502
502
 
503
+ Full BlockRun docs: **https://blockrun.ai/docs**
504
+
505
+ - [Agent developer guide](https://blockrun.ai/docs/getting-started/agent-developers) — building agents on BlockRun
506
+ - [Models, SDKs & APIs](https://blockrun.ai/docs) — the full gateway reference
503
507
  - [Plugin SDK guide](docs/plugin-sdk.md) — build your own workflow vertical
504
508
  - [Changelog](CHANGELOG.md) — every release explained
505
509
  - [Roadmap](docs/ROADMAP.md) — what's coming next
@@ -242,7 +242,7 @@ You run on the BlockRun AI Gateway. When the user asks you to "test the BlockRun
242
242
  - \`GET /.well-known/x402\` — x402 resource list with prices
243
243
 
244
244
  **LLM (POST, x402-paid)**
245
- - \`POST /v1/chat/completions\` — OpenAI-compatible. Body: \`{ model, messages, stream?, tools?, max_tokens?, temperature? }\`. \`model\` MUST come from \`GET /v1/models\` (real frontier examples on the gateway as of 2026-06: \`anthropic/claude-sonnet-4.6\`, \`anthropic/claude-opus-4.8\`, \`deepseek/deepseek-v4-pro\`, \`zai/glm-5.1\`, \`nvidia/llama-4-maverick\`, \`openai/gpt-5-nano\`). Do NOT invent versions like \`openai/gpt-5.1\` or \`xai/grok-5\` — those don't exist; the gateway 400s with the valid list in the error body, so when in doubt fetch \`GET /v1/models\` first.
245
+ - \`POST /v1/chat/completions\` — OpenAI-compatible. Body: \`{ model, messages, stream?, tools?, max_tokens?, temperature? }\`. \`model\` MUST come from \`GET /v1/models\` (real frontier examples on the gateway as of 2026-06: \`anthropic/claude-sonnet-4.6\`, \`anthropic/claude-opus-4.8\`, \`deepseek/deepseek-v4-pro\`, \`zai/glm-5.2\`, \`nvidia/llama-4-maverick\`, \`openai/gpt-5-nano\`). Do NOT invent versions like \`openai/gpt-5.1\` or \`xai/grok-5\` — those don't exist; the gateway 400s with the valid list in the error body, so when in doubt fetch \`GET /v1/models\` first.
246
246
  - \`POST /v1/messages\` — Anthropic-compatible. Body: \`{ model, messages, max_tokens, system?, tools? }\`.
247
247
 
248
248
  **Media (POST, x402-paid; GET to poll async jobs)**
@@ -1384,7 +1384,7 @@ export async function interactiveSession(config, getUserInput, onEvent, onAbortR
1384
1384
  const hasTools = responseParts.some(p => p.type === 'tool_use');
1385
1385
  const hasThinking = responseParts.some(p => p.type === 'thinking');
1386
1386
  if (!hasText && !hasTools && !hasThinking) {
1387
- const EMPTY_FALLBACK_MODELS = ['nvidia/llama-4-maverick', 'nvidia/deepseek-v4-flash', 'zai/glm-5.1'];
1387
+ const EMPTY_FALLBACK_MODELS = ['nvidia/llama-4-maverick', 'nvidia/deepseek-v4-flash', 'zai/glm-5.2'];
1388
1388
  const nextModel = EMPTY_FALLBACK_MODELS.find(m => m !== config.model && !turnFailedModels.has(m));
1389
1389
  if (nextModel && recoveryAttempts < 2) {
1390
1390
  recoveryAttempts++;
@@ -232,6 +232,7 @@ const MODEL_CONTEXT_WINDOWS = {
232
232
  'xai/grok-4-0709': 131_072,
233
233
  'xai/grok-4-1-fast-reasoning': 131_072,
234
234
  // Others
235
+ 'zai/glm-5.2': 1_000_000, // flagship bump 2026-06 — context jumped 200K → 1M
235
236
  'zai/glm-5.1': 200_000,
236
237
  'moonshot/kimi-k2.7': 256_000,
237
238
  'moonshot/kimi-k2.6': 256_000,
package/dist/pricing.js CHANGED
@@ -92,6 +92,7 @@ export const MODEL_PRICING = {
92
92
  // PROMOTION (active ~2026-04): flat $0.001/call for all GLM models
93
93
  'zai/glm-5': { input: 0.6, output: 1.92 }, // flat promo ended 2026-06-06 — per-token now
94
94
  'zai/glm-5.1': { input: 1.40, output: 4.40 }, // launch promo ended 2026-06-05 — per-token now
95
+ 'zai/glm-5.2': { input: 1.40, output: 4.40 }, // new flagship 2026-06 — 1M context, same per-token price as 5.1
95
96
  'zai/glm-5-turbo': { input: 1.2, output: 4.0 }, // flat promo ended 2026-06-06 — per-token now
96
97
  'zai/glm-5.1-turbo': { input: 1.2, output: 4.0 }, // client alias for zai/glm-5-turbo
97
98
  };
@@ -158,9 +158,12 @@ const MODEL_SHORTCUTS = {
158
158
  'm3': 'minimax/minimax-m3',
159
159
  'm2.7': 'minimax/minimax-m2.7',
160
160
  // Others
161
- glm: 'zai/glm-5.1',
161
+ glm: 'zai/glm-5.2',
162
+ 'glm-5.2': 'zai/glm-5.2',
163
+ // glm-5.1 demoted to back-compat pin 2026-06 (flagship is 5.2) — still routes.
164
+ 'glm-5.1': 'zai/glm-5.1',
162
165
  'glm-turbo': 'zai/glm-5-turbo',
163
- 'glm5': 'zai/glm-5.1',
166
+ 'glm5': 'zai/glm-5.2',
164
167
  kimi: 'moonshot/kimi-k2.7',
165
168
  'k2.7': 'moonshot/kimi-k2.7',
166
169
  // K2.6 demoted 2026-06 (flagship is K2.7) but still routes — `k2.6` pins it.
@@ -17,7 +17,11 @@ const NONCE_COOKIE = 'franklin_try_nonce';
17
17
  const SESSION_COOKIE = 'franklin_try_session';
18
18
  const TIMEOUT = 8000;
19
19
  export function isCloudSyncEnabled() {
20
- return process.env.FRANKLIN_CLOUD_SYNC !== 'off';
20
+ // Local-first by default (matches Claude Code / Codex): conversation history
21
+ // stays on disk and is NOT uploaded to franklin.run unless the user opts in
22
+ // with FRANKLIN_CLOUD_SYNC=on. Cross-device sync is a deliberate choice, not
23
+ // the default.
24
+ return process.env.FRANKLIN_CLOUD_SYNC === 'on';
21
25
  }
22
26
  let sessionCookie = null;
23
27
  // Track what we've pushed so save only sends changed/removed conversations.
@@ -7,8 +7,6 @@ import path from 'node:path';
7
7
  import { getOrCreateWallet, getOrCreateSolanaWallet, createPaymentPayload, createSolanaPaymentPayload, parsePaymentRequired, extractPaymentDetails, solanaKeyToBytes, SOLANA_NETWORK, } from '@blockrun/llm';
8
8
  import { loadChain, API_URLS, VERSION } from '../config.js';
9
9
  import { checkImageBudget, recordImageAsset } from '../content/record-image.js';
10
- import { ModelClient } from '../agent/llm.js';
11
- import { analyzeMediaRequest, renderProposalForAskUser } from '../agent/media-router.js';
12
10
  import { recordUsage } from '../stats/tracker.js';
13
11
  import { findModel, estimateCostUsd } from '../gateway-models.js';
14
12
  import { logger } from '../logger.js';
@@ -140,21 +138,8 @@ function buildExecute(deps) {
140
138
  isError: true,
141
139
  };
142
140
  }
143
- // One-shot refinement opt-out: leading `///` tells Franklin "don't
144
- // refine this prompt, I wrote it the way I want it." Strip the prefix
145
- // and pass skipRefine through to the router.
146
- let prompt = rawInput.prompt;
147
- let skipRefine = false;
148
- if (prompt.trimStart().startsWith('///')) {
149
- prompt = prompt.replace(/^\s*\/\/\/\s?/, '');
150
- skipRefine = true;
151
- }
152
- // ── Media router + AskUser flow ────────────────────────────────────
153
- // If the caller explicitly named a model, or the env auto-approves, or
154
- // no AskUser bridge exists (batch / --prompt mode), skip the proposal
155
- // step and use the old default. Otherwise: classifier picks a fitting
156
- // model + rewrites the prompt, the preview goes to AskUser, user
157
- // chooses or cancels.
141
+ // Pure tool: use exactly the prompt the caller gave — no LLM rewriting.
142
+ const prompt = rawInput.prompt;
158
143
  // Reference-image mode forces an edit-capable model. If the caller named
159
144
  // an unsupported one, fail loudly so we don't silently downgrade their
160
145
  // request to text-only generation.
@@ -165,9 +150,9 @@ function buildExecute(deps) {
165
150
  isError: true,
166
151
  };
167
152
  }
168
- let imageModel = model || (editMode ? 'openai/gpt-image-2' : 'openai/gpt-image-1');
153
+ const imageModel = model || (editMode ? 'openai/gpt-image-2' : 'openai/gpt-image-1');
169
154
  let imageSize = size || '1024x1024';
170
- let chosenPrompt = prompt;
155
+ const chosenPrompt = prompt;
171
156
  // ── Edit-mode constraint checks (mirror the gateway, fail before paying) ──
172
157
  if (editMode) {
173
158
  // Mask inpainting is OpenAI-only.
@@ -198,57 +183,6 @@ function buildExecute(deps) {
198
183
  };
199
184
  }
200
185
  }
201
- // Skip the proposal flow when a reference image is set: the media router
202
- // doesn't know which models support image-to-image, so its suggestions
203
- // would frequently be unusable (text-only models). Default to gpt-image-1
204
- // for now; a future router upgrade can pick between the four edit-capable
205
- // models based on the prompt.
206
- const autoApprove = process.env.FRANKLIN_MEDIA_AUTO_APPROVE_ALL === '1';
207
- if (!model && !autoApprove && ctx.onAskUser && !editMode) {
208
- try {
209
- const chain = loadChain();
210
- const client = new ModelClient({ apiUrl: API_URLS[chain], chain });
211
- const proposal = await analyzeMediaRequest({
212
- kind: 'image',
213
- prompt,
214
- quantity: n,
215
- client,
216
- signal: ctx.abortSignal,
217
- skipRefine,
218
- });
219
- if (proposal) {
220
- const { question, options } = renderProposalForAskUser(proposal, prompt);
221
- const labels = options.map(o => o.label);
222
- const answer = await ctx.onAskUser(question, labels);
223
- // Map the user's returned label back to an option id
224
- const chosen = options.find(o => o.label === answer) ?? { id: 'cancel' };
225
- switch (chosen.id) {
226
- case 'cheaper':
227
- imageModel = proposal.cheaper?.model ?? proposal.recommended.model;
228
- break;
229
- case 'premium':
230
- imageModel = proposal.premium?.model ?? proposal.recommended.model;
231
- break;
232
- case 'cancel':
233
- return {
234
- output: `## Image generation cancelled\n\nNo USDC was spent. Ask again when ready, or pass an explicit \`model\` to skip the confirmation step.`,
235
- };
236
- case 'use-raw':
237
- imageModel = proposal.recommended.model;
238
- // chosenPrompt stays as the raw input
239
- break;
240
- case 'recommended':
241
- default:
242
- imageModel = proposal.recommended.model;
243
- if (proposal.refinedPrompt)
244
- chosenPrompt = proposal.refinedPrompt;
245
- }
246
- }
247
- }
248
- catch {
249
- // Router / AskUser failed — fall back to default model silently.
250
- }
251
- }
252
186
  // gpt-image-2 reliably serves 1024x1024 only — other sizes time out at
253
187
  // the gateway. Force the supported size regardless of caller / router
254
188
  // input so we never burn USDC on a request that's going to abort.
@@ -280,6 +214,21 @@ function buildExecute(deps) {
280
214
  };
281
215
  }
282
216
  }
217
+ // Confirm the spend before the paid call (parity with VideoGen). Pure price
218
+ // math — no LLM. Interactive callers (CLI / agent) get a prompt via
219
+ // onAskUser; direct callers (e.g. the desktop media path) pass no onAskUser
220
+ // and generate straight away — the explicit "generate" action is consent.
221
+ const autoApprove = process.env.FRANKLIN_MEDIA_AUTO_APPROVE_ALL === '1';
222
+ if (!autoApprove && ctx.onAskUser) {
223
+ const m = await findModel(imageModel);
224
+ const est = m ? estimateCostUsd(m, { quantity: n }) : 0;
225
+ const priceNote = est > 0 ? ` for ~$${est.toFixed(2)}` : '';
226
+ const countNote = n > 1 ? `${n} images` : 'an image';
227
+ const answer = await ctx.onAskUser(`Generate ${countNote} with ${imageModel}${priceNote}? No USDC is spent if you cancel.`, ['Generate', 'Cancel']);
228
+ if (answer !== 'Generate') {
229
+ return { output: `## Image generation cancelled\n\nNo USDC was spent.` };
230
+ }
231
+ }
283
232
  // Resolve all reference images + the mask into base64 data URIs now, right
284
233
  // before the paid call. Done after the cheap validations so bad paths /
285
234
  // oversize attachments / unsupported combinations fail without any network
@@ -24,8 +24,6 @@ import { getOrCreateWallet, getOrCreateSolanaWallet, createPaymentPayload, creat
24
24
  import { loadChain, API_URLS, VERSION } from '../config.js';
25
25
  import { logger } from '../logger.js';
26
26
  import { resolveReferenceImage } from './imagegen.js';
27
- import { ModelClient } from '../agent/llm.js';
28
- import { analyzeMediaRequest, renderProposalForAskUser } from '../agent/media-router.js';
29
27
  import { recordUsage } from '../stats/tracker.js';
30
28
  import { findModel, estimateCostUsd } from '../gateway-models.js';
31
29
  // BytePlus RealFace asset IDs from the RealFace tool (after H5 liveness +
@@ -100,65 +98,27 @@ function buildExecute(deps) {
100
98
  };
101
99
  }
102
100
  }
103
- // One-shot refinement opt-out: leading `///` tells Franklin "don't
104
- // refine this prompt." Strip the prefix and pass skipRefine through.
105
- let prompt = rawInput.prompt;
106
- let skipRefine = false;
107
- if (prompt.trimStart().startsWith('///')) {
108
- prompt = prompt.replace(/^\s*\/\/\/\s?/, '');
109
- skipRefine = true;
110
- }
111
- let videoModel = model || DEFAULT_MODEL;
112
- let duration = duration_seconds ?? DEFAULT_DURATION;
113
- let chosenPrompt = prompt;
114
- // ── Media router + AskUser flow (video bills per second, always ask) ──
101
+ // Pure tool: use exactly the model + prompt + duration the caller gave.
102
+ // No LLM prompt-rewriting or model "routing" — the UI / agent decides those
103
+ // upstream. (This removes a second, flaky free-model call that used to time
104
+ // out and made "video generation" appear broken.)
105
+ const prompt = rawInput.prompt;
106
+ const videoModel = model || DEFAULT_MODEL;
107
+ const duration = duration_seconds ?? DEFAULT_DURATION;
108
+ const chosenPrompt = prompt;
109
+ // Video bills per second — confirm the cost before spending. This is pure
110
+ // price math (no LLM). Interactive callers (CLI / agent) get a prompt via
111
+ // onAskUser; direct callers (e.g. the desktop media path) pass no onAskUser
112
+ // and generate straight away — the explicit "generate" action is consent.
115
113
  const autoApprove = process.env.FRANKLIN_MEDIA_AUTO_APPROVE_ALL === '1';
116
- if (!model && !autoApprove && ctx.onAskUser) {
117
- try {
118
- const chain = loadChain();
119
- const client = new ModelClient({ apiUrl: API_URLS[chain], chain });
120
- const proposal = await analyzeMediaRequest({
121
- kind: 'video',
122
- prompt,
123
- durationSeconds: duration_seconds,
124
- client,
125
- signal: ctx.abortSignal,
126
- skipRefine,
127
- });
128
- if (proposal) {
129
- const { question, options } = renderProposalForAskUser(proposal, prompt);
130
- const labels = options.map(o => o.label);
131
- const answer = await ctx.onAskUser(question, labels);
132
- const chosen = options.find(o => o.label === answer) ?? { id: 'cancel' };
133
- switch (chosen.id) {
134
- case 'cheaper':
135
- videoModel = proposal.cheaper?.model ?? proposal.recommended.model;
136
- break;
137
- case 'premium':
138
- videoModel = proposal.premium?.model ?? proposal.recommended.model;
139
- break;
140
- case 'cancel':
141
- return {
142
- output: `## Video generation cancelled\n\nNo USDC was spent.`,
143
- };
144
- case 'use-raw':
145
- videoModel = proposal.recommended.model;
146
- // chosenPrompt stays as the raw input
147
- break;
148
- case 'recommended':
149
- default:
150
- videoModel = proposal.recommended.model;
151
- if (proposal.refinedPrompt)
152
- chosenPrompt = proposal.refinedPrompt;
153
- }
154
- // Use the proposal's duration — the router honored the user's
155
- // duration_seconds or filled in the model's default.
156
- if (proposal.durationSeconds)
157
- duration = proposal.durationSeconds;
158
- }
159
- }
160
- catch {
161
- // Router / AskUser failed — fall through to legacy default.
114
+ if (!autoApprove && ctx.onAskUser) {
115
+ // Model-aware estimate so the quoted price matches the model we name in
116
+ // the prompt (flat per-second fallback only when the model is unknown).
117
+ const m = await findModel(videoModel);
118
+ const est = m ? estimateCostUsd(m, { duration_seconds: duration }) : estimateVideoCostUsd(duration);
119
+ const answer = await ctx.onAskUser(`Generate a ${duration}s video with ${videoModel} for ~$${est.toFixed(2)}? No USDC is spent if you cancel.`, ['Generate', 'Cancel']);
120
+ if (answer !== 'Generate') {
121
+ return { output: `## Video generation cancelled\n\nNo USDC was spent.` };
162
122
  }
163
123
  }
164
124
  const estCost = estimateVideoCostUsd(duration);
@@ -97,10 +97,14 @@ export const MODEL_SHORTCUTS = {
97
97
  minimax: 'minimax/minimax-m3',
98
98
  'm3': 'minimax/minimax-m3',
99
99
  'm2.7': 'minimax/minimax-m2.7',
100
- glm: 'zai/glm-5.1',
100
+ glm: 'zai/glm-5.2',
101
101
  'glm-5': 'zai/glm-5',
102
+ 'glm-5.2': 'zai/glm-5.2',
103
+ // GLM-5.1 demoted to a back-compat pin 2026-06 (flagship is 5.2) — still
104
+ // routes for anyone who wants the 200K-context build explicitly.
105
+ 'glm-5.1': 'zai/glm-5.1',
102
106
  'glm-turbo': 'zai/glm-5-turbo',
103
- 'glm5': 'zai/glm-5.1',
107
+ 'glm5': 'zai/glm-5.2',
104
108
  kimi: 'moonshot/kimi-k2.7',
105
109
  'k2.7': 'moonshot/kimi-k2.7',
106
110
  // K2.6 demoted 2026-06 (gateway flagship is K2.7) but still routes — the
@@ -169,6 +173,9 @@ export const PICKER_CATEGORIES = [
169
173
  { id: 'deepseek/deepseek-v4-pro', shortcut: 'deepseek-v4-pro', label: 'DeepSeek V4 Pro', price: '$0.435/$0.87', highlight: true },
170
174
  { id: 'deepseek/deepseek-reasoner', shortcut: 'r1', label: 'DeepSeek V4 Flash R.', price: '$0.2/$0.4' },
171
175
  { id: 'xai/grok-4-1-fast-reasoning', shortcut: 'grok-fast', label: 'Grok 4.1 Fast R.', price: '$0.2/$0.5' },
176
+ // GLM-5.2: Z.AI's new flagship — 1M context, top open-source on
177
+ // long-horizon coding. `glm`/`glm5` shortcuts pin it.
178
+ { id: 'zai/glm-5.2', shortcut: 'glm', label: 'GLM-5.2', price: '$1.4/$4.4' },
172
179
  ],
173
180
  },
174
181
  {
@@ -181,7 +188,8 @@ export const PICKER_CATEGORIES = [
181
188
  { id: 'deepseek/deepseek-chat', shortcut: 'deepseek', label: 'DeepSeek V4 Flash Chat', price: '$0.2/$0.4' },
182
189
  { id: 'moonshot/kimi-k2.7', shortcut: 'kimi', label: 'Kimi K2.7', price: '$0.95/$4' },
183
190
  // GLM flat-rate promos fully ended 2026-06-06 — whole family per-token
184
- // now (glm-5 $0.60/$1.92; `glm` shortcut still pins flagship glm-5.1).
191
+ // now (glm-5 $0.60/$1.92; `glm` shortcut pins flagship glm-5.2, listed
192
+ // in Reasoning above).
185
193
  { id: 'zai/glm-5', shortcut: 'glm-5', label: 'GLM-5', price: '$0.6/$1.92' },
186
194
  // Minimax M2.7 hidden to make room for V4 Pro in Reasoning + V4 Flash
187
195
  // (free) without exceeding the picker's 24-entry cap. Shortcut `minimax`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/franklin",
3
- "version": "3.29.2",
3
+ "version": "3.29.4",
4
4
  "description": "Franklin Agent — 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": {