@blockrun/franklin 3.47.0 → 3.49.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 (59) hide show
  1. package/README.md +31 -15
  2. package/dist/agent/commands.js +11 -9
  3. package/dist/agent/context.js +6 -6
  4. package/dist/agent/intent-prefetch.js +4 -3
  5. package/dist/agent/llm.js +6 -6
  6. package/dist/agent/tokens.js +13 -0
  7. package/dist/agent/types.d.ts +2 -1
  8. package/dist/channel/slack.js +4 -2
  9. package/dist/channel/telegram.js +4 -2
  10. package/dist/commands/balance.js +5 -4
  11. package/dist/commands/doctor.js +3 -2
  12. package/dist/commands/models.js +3 -2
  13. package/dist/commands/proxy.js +4 -4
  14. package/dist/commands/setup.js +6 -5
  15. package/dist/commands/start.js +4 -2
  16. package/dist/config.d.ts +13 -1
  17. package/dist/config.js +28 -8
  18. package/dist/gateway-models.d.ts +11 -5
  19. package/dist/gateway-models.js +11 -5
  20. package/dist/index.js +4 -4
  21. package/dist/model-catalog.d.ts +3 -2
  22. package/dist/model-catalog.js +18 -8
  23. package/dist/onramp/client.js +5 -0
  24. package/dist/panel/html.js +39 -22
  25. package/dist/panel/server.js +8 -7
  26. package/dist/payments/auth-mode.d.ts +11 -1
  27. package/dist/payments/auth-mode.js +13 -1
  28. package/dist/pricing.js +25 -11
  29. package/dist/proxy/server.js +2 -1
  30. package/dist/router/index.js +4 -3
  31. package/dist/router/vision.js +13 -0
  32. package/dist/serve/agent-host.d.ts +2 -1
  33. package/dist/serve/server.js +4 -1
  34. package/dist/session/storage.d.ts +2 -1
  35. package/dist/skills/bootstrap.d.ts +2 -1
  36. package/dist/tools/blockrun.js +2 -2
  37. package/dist/tools/defillama.js +2 -2
  38. package/dist/tools/exa.js +2 -2
  39. package/dist/tools/imagegen.js +2 -2
  40. package/dist/tools/moa.d.ts +2 -1
  41. package/dist/tools/modal.d.ts +2 -1
  42. package/dist/tools/modal.js +2 -2
  43. package/dist/tools/musicgen.js +2 -2
  44. package/dist/tools/phone.js +2 -2
  45. package/dist/tools/prediction.js +2 -2
  46. package/dist/tools/realface.js +2 -2
  47. package/dist/tools/rpc.js +2 -2
  48. package/dist/tools/subagent.d.ts +2 -1
  49. package/dist/tools/surf.js +2 -2
  50. package/dist/tools/videogen.js +2 -2
  51. package/dist/tools/voice.js +2 -2
  52. package/dist/tools/wallet.d.ts +2 -1
  53. package/dist/tools/wallet.js +2 -1
  54. package/dist/trading/providers/blockrun/client.js +5 -4
  55. package/dist/ui/model-picker.js +17 -4
  56. package/dist/wallet/manager.d.ts +15 -0
  57. package/dist/wallet/manager.js +27 -1
  58. package/dist/wallet/reservation.js +4 -2
  59. package/package.json +6 -6
@@ -9,8 +9,10 @@
9
9
  *
10
10
  * Per gateway team (2026-04-22): every model returns `billing_mode` and
11
11
  * a mode-specific `pricing` object. Dispatch on billing_mode to compute
12
- * an estimated charge. x402 adds a fixed 5% margin on top of base price,
13
- * plus a flat $0.001 per-transaction fee on paid calls (Base since
12
+ * an estimated charge. Token-metered chat is billed at the provider's list
13
+ * rate with no margin (since 2026-09-04); media (image/video/music/speech/
14
+ * sfx) and Live Search carry a 5% platform fee. Every paid call adds a flat
15
+ * $0.001 per-transaction fee (Base since
14
16
  * 2026-07-10; Solana instead enforces a $0.001 minimum per call with no
15
17
  * service fee — the flat-fee estimate over-counts there by ≤$0.001, which
16
18
  * is the safe direction for budget tracking).
@@ -113,18 +115,22 @@ export async function findModel(id) {
113
115
  return all.find(m => m.id === id) ?? null;
114
116
  }
115
117
  // ─── Cost estimation ────────────────────────────────────────────────────
116
- /** x402 gateway's fixed margin percentage applied on top of the base price. */
118
+ /**
119
+ * Platform fee multiplier on MEDIA (per_image / per_second / per_track /
120
+ * per_character / per_generation / flat) list prices. Token-metered chat
121
+ * carries no margin — the gateway bills it at the provider's list rate.
122
+ */
117
123
  export const GATEWAY_MARGIN = 1.05;
118
124
  /**
119
125
  * Flat per-transaction fee (USD) the gateway adds on top of the margined
120
- * price on every PAID call (no-op on $0 calls). Introduced upstream
126
+ * (media) or list (chat) price on every PAID call (no-op on $0 calls). Introduced upstream
121
127
  * 2026-07-10, briefly $0.002, back to $0.001 since 2026-07-29
122
128
  * (blockrun src/lib/transaction-fee.ts).
123
129
  */
124
130
  export const GATEWAY_TRANSACTION_FEE_USD = 0.001;
125
131
  /**
126
132
  * Estimated USD charge to generate one response from this model under the
127
- * given context. Includes the 5% gateway margin and the flat $0.001
133
+ * given context. Includes the 5% media platform fee and the flat $0.001
128
134
  * per-transaction fee on paid calls. Returns 0 for free and token-metered
129
135
  * (paid) models where a pre-call estimate isn't meaningful.
130
136
  */
package/dist/index.js CHANGED
@@ -48,13 +48,13 @@ program
48
48
  .name('franklin')
49
49
  .description('Franklin Agent — The AI agent with a wallet.\n\n' +
50
50
  'While others chat, Franklin Agent spends — turning your USDC into real work.\n\n' +
51
- 'Pay per action — a USDC wallet on Solana or Base, or a prepaid API key\n' +
51
+ 'Pay per action — a USDC wallet on Solana, Base or Arc, or a prepaid API key\n' +
52
52
  'from user.blockrun.ai. No subscriptions.')
53
53
  .option('--wallet', 'Pay from the USDC wallet even when an API key is configured')
54
54
  .version(version);
55
55
  program
56
56
  .command('setup [chain]')
57
- .description('Create a new wallet for payments (solana or base)')
57
+ .description('Create a new wallet for payments (solana, base or arc)')
58
58
  .action((chain) => setupCommand(chain));
59
59
  program
60
60
  .command('start')
@@ -368,8 +368,8 @@ function parseStartFlags(argv, startIdx = 0) {
368
368
  }
369
369
  return opts;
370
370
  }
371
- // Handle chain shortcuts: `franklin solana` or `franklin base`
372
- if (firstArg === 'solana' || firstArg === 'base') {
371
+ // Handle chain shortcuts: `franklin solana`, `franklin base` or `franklin arc`
372
+ if (firstArg === 'solana' || firstArg === 'base' || firstArg === 'arc') {
373
373
  if (hasAnyFlag(args, HELP_FLAGS)) {
374
374
  program.parse(['node', 'franklin', 'start', '--help']);
375
375
  }
@@ -1,10 +1,11 @@
1
1
  /** Shared model facts and policy; payment credentials stay in Franklin. */
2
- import { type CatalogState, type Network } from '@blockrun/model-catalog';
2
+ import { type CatalogState } from '@blockrun/model-catalog';
3
+ import { type Chain } from './config.js';
3
4
  export declare function getModelCatalogIdentity(): string;
4
5
  export declare function getModelCatalog(): CatalogState;
5
6
  export declare function onModelCatalogChange(listener: (state: CatalogState) => void): () => void;
6
7
  export declare function refreshModelCatalog(options?: {
7
- network?: Network;
8
+ network?: Chain;
8
9
  force?: boolean;
9
10
  }): Promise<CatalogState>;
10
11
  export declare function clearModelCatalogCache(): void;
@@ -4,8 +4,17 @@ import { API_URLS, loadChain, USER_AGENT } from './config.js';
4
4
  import { gatewayHeaders, resolvePayMode } from './payments/auth-mode.js';
5
5
  const clients = new Map();
6
6
  const bundled = new Map();
7
+ /**
8
+ * Model Core's policy and bundled snapshot know Base and Solana. The Arc
9
+ * gateway is a fork of the Base gateway serving the same catalog, so Arc reads
10
+ * Base's policy and offline snapshot, while its live rows and prices come from
11
+ * arc.blockrun.ai itself (the gateway URL below), cached apart from Base's.
12
+ */
13
+ function catalogNetwork(chain) {
14
+ return chain === 'arc' ? 'base' : chain;
15
+ }
7
16
  function bundledState() {
8
- const network = sessionNetwork ?? loadChain();
17
+ const network = catalogNetwork(sessionChain ?? loadChain());
9
18
  let state = bundled.get(network);
10
19
  if (!state) {
11
20
  state = createCatalogClient({ network }).current();
@@ -14,15 +23,16 @@ function bundledState() {
14
23
  return state;
15
24
  }
16
25
  const listeners = new Set();
17
- let sessionNetwork;
26
+ let sessionChain;
18
27
  function activeClient() {
19
28
  const mode = resolvePayMode();
20
- const network = sessionNetwork ?? loadChain();
21
- const gatewayUrl = `${mode.kind === 'key' ? mode.apiBase : API_URLS[network]}/v1/models?format=json`;
29
+ const chain = sessionChain ?? loadChain();
30
+ const network = catalogNetwork(chain);
31
+ const gatewayUrl = `${mode.kind === 'key' ? mode.apiBase : API_URLS[chain]}/v1/models?format=json`;
22
32
  const catalogUrl = process.env.BLOCKRUN_MODEL_CATALOG_URL
23
33
  ?? 'https://raw.githubusercontent.com/BlockRunAI/model-catalog/main/dist/snapshot.v1.json';
24
34
  // Separate caches for each chain, endpoint and API account; keys never leave memory.
25
- const identity = JSON.stringify([network, gatewayUrl, catalogUrl, mode.kind === 'key' ? mode.key : '']);
35
+ const identity = JSON.stringify([chain, gatewayUrl, catalogUrl, mode.kind === 'key' ? mode.key : '']);
26
36
  let client = clients.get(identity);
27
37
  if (!client) {
28
38
  const headers = { ...gatewayHeaders(mode), 'User-Agent': USER_AGENT };
@@ -43,7 +53,7 @@ export function getModelCatalogIdentity() {
43
53
  return activeClient().identity;
44
54
  }
45
55
  catch {
46
- return `unconfigured:${sessionNetwork ?? loadChain()}`;
56
+ return `unconfigured:${sessionChain ?? loadChain()}`;
47
57
  }
48
58
  }
49
59
  export function getModelCatalog() {
@@ -62,7 +72,7 @@ export function onModelCatalogChange(listener) {
62
72
  }
63
73
  export async function refreshModelCatalog(options = {}) {
64
74
  if (options.network)
65
- sessionNetwork = options.network;
75
+ sessionChain = options.network;
66
76
  const { identity, client } = activeClient();
67
77
  const state = process.env.FRANKLIN_CATALOG_OFFLINE === '1'
68
78
  ? client.current() : await client.refresh({ force: options.force });
@@ -73,5 +83,5 @@ export async function refreshModelCatalog(options = {}) {
73
83
  }
74
84
  export function clearModelCatalogCache() {
75
85
  clients.clear();
76
- sessionNetwork = undefined;
86
+ sessionChain = undefined;
77
87
  }
@@ -25,6 +25,11 @@ import { postWithPayment } from '../payments/post-with-payment.js';
25
25
  */
26
26
  export async function getOnrampUrl(address) {
27
27
  const chain = loadChain();
28
+ // Coinbase Onramp cannot deliver to Arc, and the Arc gateway refuses any
29
+ // network but Base. Fail before the x402 handshake rather than after it.
30
+ if (chain === 'arc') {
31
+ throw new Error('Card purchase is not available on Arc. Send USDC on Arc (chain 5042) to this wallet, or switch to Base or Solana to buy with a card.');
32
+ }
28
33
  const endpoint = `${gatewayBase()}/v1/onramp/token`;
29
34
  const result = await postWithPayment(endpoint, { address, network: chain, asset: 'USDC' }, 'Mint a Coinbase Onramp session link to fund this wallet');
30
35
  if (!result.ok) {
@@ -694,6 +694,7 @@ a:hover { text-decoration:underline; }
694
694
  <div class="chain-switcher" role="tablist" aria-label="Payment chain">
695
695
  <button type="button" data-chain="base" id="chain-btn-base" role="tab">Base</button>
696
696
  <button type="button" data-chain="solana" id="chain-btn-solana" role="tab">Solana</button>
697
+ <button type="button" data-chain="arc" id="chain-btn-arc" role="tab">Arc</button>
697
698
  </div>
698
699
  <span class="chain-switcher-note" id="chain-switcher-note"></span>
699
700
 
@@ -735,7 +736,7 @@ a:hover { text-decoration:underline; }
735
736
  <strong>This overwrites your existing wallet file.</strong>
736
737
  Make sure the current key is backed up first, or you will lose access to any funds still on it.
737
738
  </p>
738
- <textarea id="wallet-import-input" class="wallet-import-input" placeholder="0x… (Base) or base58 key (Solana)"></textarea>
739
+ <textarea id="wallet-import-input" class="wallet-import-input" placeholder="0x… (Base / Arc) or base58 key (Solana)"></textarea>
739
740
  <div class="wallet-actions">
740
741
  <button class="btn btn-danger" id="wallet-import-btn">Import &amp; replace</button>
741
742
  <span class="wallet-import-status" id="wallet-import-status"></span>
@@ -1190,6 +1191,8 @@ async function loadLearnings() {
1190
1191
  }).join('');
1191
1192
  }
1192
1193
 
1194
+ // Payment-chain switcher buttons, in display order.
1195
+ const CHAIN_BUTTON_IDS = ['chain-btn-base', 'chain-btn-solana', 'chain-btn-arc'];
1193
1196
  async function loadWallet() {
1194
1197
  const w = await api('wallet');
1195
1198
  if (!w) return;
@@ -1199,56 +1202,71 @@ async function loadWallet() {
1199
1202
  document.getElementById('wallet-chain-pill').textContent = w.chain || '—';
1200
1203
 
1201
1204
  // Chain switcher — highlight active button
1202
- const baseBtn = document.getElementById('chain-btn-base');
1203
- const solanaBtn = document.getElementById('chain-btn-solana');
1204
- if (baseBtn && solanaBtn) {
1205
- baseBtn.classList.toggle('active', w.chain === 'base');
1206
- solanaBtn.classList.toggle('active', w.chain === 'solana');
1207
- }
1205
+ CHAIN_BUTTON_IDS.forEach((id) => {
1206
+ const b = document.getElementById(id);
1207
+ if (b) b.classList.toggle('active', b.getAttribute('data-chain') === w.chain);
1208
+ });
1208
1209
 
1209
- // Coinbase Onramp works on both chains — the gateway of the active chain
1210
- // mints the link, so the buy button stays visible on Base and Solana alike.
1210
+ // Coinbase Onramp funds Base and Solana — the gateway of the active chain
1211
+ // mints the link. It cannot deliver to Arc (the Arc gateway refuses any
1212
+ // network but Base), so on Arc the card button is replaced by a hint.
1213
+ const onrampActions = document.getElementById('wallet-onramp-actions');
1214
+ const onrampHint = document.getElementById('wallet-onramp-hint');
1215
+ const onrampOk = w.chain !== 'arc';
1216
+ if (onrampActions) onrampActions.style.display = onrampOk ? 'flex' : 'none';
1217
+ if (onrampHint) onrampHint.textContent = onrampOk
1218
+ ? 'Powered by Coinbase Onramp \u00b7 60+ fiat currencies'
1219
+ : 'Card purchase is not available on Arc \u2014 send USDC on Arc (chain 5042) to this address.';
1211
1220
 
1212
1221
  // QR via server — never leak address to third parties.
1213
1222
  // Encode chain + USDC token in the QR payload so wallet apps land
1214
1223
  // directly on the right network/token instead of a bare address:
1215
1224
  // Base → EIP-681: ethereum:<USDC>@8453/transfer?address=<addr>
1225
+ // Arc → EIP-681: ethereum:<USDC>@5042/transfer?address=<addr>
1216
1226
  // Solana → Solana Pay: solana:<addr>?spl-token=<USDC mint>
1217
1227
  const qrBox = document.getElementById('wallet-qr');
1218
1228
  const hint = document.getElementById('wallet-qr-hint');
1219
1229
  if (addr && addr !== 'not set') {
1220
1230
  const USDC_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
1231
+ const USDC_ARC = '0x3600000000000000000000000000000000000000';
1221
1232
  const USDC_SOL_MINT = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
1222
1233
  const payload = w.chain === 'solana'
1223
1234
  ? 'solana:' + addr + '?spl-token=' + USDC_SOL_MINT
1224
- : 'ethereum:' + USDC_BASE + '@8453/transfer?address=' + addr;
1235
+ : w.chain === 'arc'
1236
+ ? 'ethereum:' + USDC_ARC + '@5042/transfer?address=' + addr
1237
+ : 'ethereum:' + USDC_BASE + '@8453/transfer?address=' + addr;
1225
1238
  const svg = await fetch('/api/wallet/qr?data=' + encodeURIComponent(payload)).then(r => r.ok ? r.text() : null);
1226
1239
  qrBox.innerHTML = svg || '';
1227
1240
  hint.textContent = w.chain === 'solana'
1228
1241
  ? 'Scan with a Solana wallet (Phantom, Solflare) to send USDC SPL.'
1229
- : 'Scan with an EVM wallet (MetaMask, Coinbase) to send USDC on Base.';
1242
+ : w.chain === 'arc'
1243
+ ? 'Scan with an EVM wallet to send USDC on Arc (chain 5042). Same address as your Base wallet.'
1244
+ : 'Scan with an EVM wallet (MetaMask, Coinbase) to send USDC on Base.';
1230
1245
  } else {
1231
1246
  qrBox.innerHTML = '';
1232
1247
  hint.textContent = 'No wallet set yet — run: franklin setup';
1233
1248
  }
1234
1249
  }
1235
1250
 
1236
- // Chain switcher — click "Base" or "Solana" to flip payment chain.
1237
- // Creates a wallet on the target chain if one does not exist yet.
1238
- // Note: a currently-running franklin agent reads its chain at startup,
1239
- // so a mid-session switch only affects the next agent invocation.
1240
- ['chain-btn-base', 'chain-btn-solana'].forEach((id) => {
1251
+ // Chain switcher — click "Base", "Solana" or "Arc" to flip payment chain.
1252
+ // Creates a wallet on the target chain if one does not exist yet (Base and
1253
+ // Arc share one EVM wallet). Note: a currently-running franklin agent reads
1254
+ // its chain at startup, so a mid-session switch only affects the next run.
1255
+ function setChainButtonsDisabled(disabled) {
1256
+ CHAIN_BUTTON_IDS.forEach((id) => {
1257
+ const b = document.getElementById(id);
1258
+ if (b) b.disabled = disabled;
1259
+ });
1260
+ }
1261
+ CHAIN_BUTTON_IDS.forEach((id) => {
1241
1262
  const btn = document.getElementById(id);
1242
1263
  if (!btn) return;
1243
1264
  btn.addEventListener('click', async () => {
1244
1265
  const target = btn.getAttribute('data-chain');
1245
1266
  const note = document.getElementById('chain-switcher-note');
1246
- const baseBtn = document.getElementById('chain-btn-base');
1247
- const solanaBtn = document.getElementById('chain-btn-solana');
1248
1267
  // Skip if already active
1249
1268
  if (btn.classList.contains('active')) return;
1250
- baseBtn.disabled = true;
1251
- solanaBtn.disabled = true;
1269
+ setChainButtonsDisabled(true);
1252
1270
  note.textContent = 'Switching to ' + target + '…';
1253
1271
  // The onramp status (e.g. a popup-blocked Coinbase link) belongs to the
1254
1272
  // previous chain's wallet — a stale link would fund the wrong chain.
@@ -1273,8 +1291,7 @@ async function loadWallet() {
1273
1291
  } catch (err) {
1274
1292
  note.textContent = 'Error: ' + (err && err.message ? err.message : 'network error');
1275
1293
  } finally {
1276
- baseBtn.disabled = false;
1277
- solanaBtn.disabled = false;
1294
+ setChainButtonsDisabled(false);
1278
1295
  }
1279
1296
  });
1280
1297
  });
@@ -6,7 +6,7 @@
6
6
  import http from 'node:http';
7
7
  import fs from 'node:fs';
8
8
  import path from 'node:path';
9
- import { loadChain, saveChain } from '../config.js';
9
+ import { loadChain, saveChain, isChain, CHAIN_LABELS } from '../config.js';
10
10
  import { listNumbers as gatewayListNumbers, renewNumber as gatewayRenewNumber, buyNumber as gatewayBuyNumber, releaseNumber as gatewayReleaseNumber, } from '../phone/client.js';
11
11
  import { readCache as readPhoneCache, writeCache as writePhoneCache, clearCache as clearPhoneCache, isFresh as isPhoneCacheFresh, } from '../phone/cache.js';
12
12
  import { getStatsSummary, getStatsFilePath } from '../stats/tracker.js';
@@ -24,6 +24,7 @@ import { isTerminalTaskStatus } from '../tasks/types.js';
24
24
  import { readLiveAgents } from '../session/live-registry.js';
25
25
  import { BLOCKRUN_DIR } from '../config.js';
26
26
  import { getHTML } from './html.js';
27
+ import { readEvmBalance } from '../wallet/manager.js';
27
28
  const sseClients = new Set();
28
29
  function json(res, data, status = 200) {
29
30
  res.writeHead(status, {
@@ -103,7 +104,7 @@ function broadcast(data) {
103
104
  }
104
105
  }
105
106
  /**
106
- * Resolve the current active wallet address (Base or Solana, depending on
107
+ * Resolve the current active wallet address (EVM for Base/Arc, or Solana, depending on
107
108
  * the active chain). Used by phone endpoints that key the cache by wallet,
108
109
  * and that must sign x402 payments out of the wallet the user owns.
109
110
  *
@@ -293,7 +294,7 @@ export function createPanelServer(port) {
293
294
  const { setupAgentWallet } = await import('@blockrun/llm');
294
295
  const client = setupAgentWallet({ silent: true });
295
296
  address = client.getWalletAddress();
296
- balance = await client.getBalance();
297
+ balance = await readEvmBalance(chain, client);
297
298
  }
298
299
  json(res, { address, balance, chain });
299
300
  }
@@ -420,7 +421,7 @@ export function createPanelServer(port) {
420
421
  // Base: 0x + 64 hex chars
421
422
  const normalized = pk.startsWith('0x') ? pk : `0x${pk}`;
422
423
  if (!/^0x[0-9a-fA-F]{64}$/.test(normalized)) {
423
- json(res, { error: 'invalid Base private key — expected 0x + 64 hex chars' }, 400);
424
+ json(res, { error: `invalid ${CHAIN_LABELS[chain]} private key — expected 0x + 64 hex chars` }, 400);
424
425
  return;
425
426
  }
426
427
  saveWallet(normalized);
@@ -454,8 +455,8 @@ export function createPanelServer(port) {
454
455
  const raw = await readBody(req);
455
456
  const body = JSON.parse(raw);
456
457
  const target = body.chain;
457
- if (target !== 'base' && target !== 'solana') {
458
- json(res, { error: 'chain must be "base" or "solana"' }, 400);
458
+ if (!isChain(target)) {
459
+ json(res, { error: 'chain must be "base", "solana" or "arc"' }, 400);
459
460
  return;
460
461
  }
461
462
  saveChain(target);
@@ -472,7 +473,7 @@ export function createPanelServer(port) {
472
473
  const { setupAgentWallet } = await import('@blockrun/llm');
473
474
  const client = setupAgentWallet({ silent: true });
474
475
  address = client.getWalletAddress();
475
- balance = await client.getBalance();
476
+ balance = await readEvmBalance(target, client);
476
477
  }
477
478
  json(res, { ok: true, chain: target, address, balance });
478
479
  }
@@ -3,7 +3,8 @@
3
3
  *
4
4
  * Franklin can reach the BlockRun gateway two ways:
5
5
  *
6
- * wallet — blockrun.ai/api (Base) or sol.blockrun.ai/api (Solana). Every
6
+ * wallet — blockrun.ai/api (Base), sol.blockrun.ai/api (Solana) or
7
+ * arc.blockrun.ai/api (Arc). Every
7
8
  * paid call answers a 402 by signing USDC from the local wallet.
8
9
  * key — api.blockrun.ai with `Authorization: Bearer brk_...`, settled
9
10
  * against a prepaid credit balance. No chain involved.
@@ -74,6 +75,15 @@ export declare function walletBase(chain?: Chain): string;
74
75
  * where payment rides on the PAYMENT-SIGNATURE header instead.
75
76
  */
76
77
  export declare function gatewayHeaders(mode?: PayMode): Record<string, string>;
78
+ /**
79
+ * Whether a 402 on a request sent with these headers may be answered from the
80
+ * wallet. A request that carried an account key gets a credit refusal, not an
81
+ * x402 challenge, and an account failure is never permission to spend from a
82
+ * wallet — the 402 must surface as an error. Branch on the request's own
83
+ * headers rather than re-resolving the mode, so the decision always matches the
84
+ * rail the request actually went out on.
85
+ */
86
+ export declare function walletMayPay(requestHeaders: Record<string, string>): boolean;
77
87
  /**
78
88
  * A key's credit standing, from GET /v1/credits. The authoritative figure for
79
89
  * display — the per-response `x-blockrun-credit-remaining-usd` header can
@@ -3,7 +3,8 @@
3
3
  *
4
4
  * Franklin can reach the BlockRun gateway two ways:
5
5
  *
6
- * wallet — blockrun.ai/api (Base) or sol.blockrun.ai/api (Solana). Every
6
+ * wallet — blockrun.ai/api (Base), sol.blockrun.ai/api (Solana) or
7
+ * arc.blockrun.ai/api (Arc). Every
7
8
  * paid call answers a 402 by signing USDC from the local wallet.
8
9
  * key — api.blockrun.ai with `Authorization: Bearer brk_...`, settled
9
10
  * against a prepaid credit balance. No chain involved.
@@ -140,6 +141,17 @@ export function gatewayHeaders(mode = resolvePayMode()) {
140
141
  headers['Authorization'] = `Bearer ${mode.key}`;
141
142
  return headers;
142
143
  }
144
+ /**
145
+ * Whether a 402 on a request sent with these headers may be answered from the
146
+ * wallet. A request that carried an account key gets a credit refusal, not an
147
+ * x402 challenge, and an account failure is never permission to spend from a
148
+ * wallet — the 402 must surface as an error. Branch on the request's own
149
+ * headers rather than re-resolving the mode, so the decision always matches the
150
+ * rail the request actually went out on.
151
+ */
152
+ export function walletMayPay(requestHeaders) {
153
+ return !requestHeaders['Authorization'];
154
+ }
143
155
  /**
144
156
  * Fetch the key's credit standing. Null when there is no key, the gateway is
145
157
  * unreachable, or it answers with something unexpected — callers show what they
package/dist/pricing.js CHANGED
@@ -48,6 +48,11 @@ const LEGACY_PRICING = {
48
48
  'nvidia/nemotron-3-super-120b': { input: 0, output: 0 },
49
49
  'nvidia/nemotron-super-49b': { input: 0, output: 0 },
50
50
  // Anthropic
51
+ // 2026-10 gateway additions (live /api/v1/models, 2026-10-02). Opus 5.5 and
52
+ // Sonnet 5.5 come in BELOW the 5.0 line; Fable 5.1 holds Fable 5's price.
53
+ 'anthropic/claude-fable-5.1': { input: 10.0, output: 50.0 },
54
+ 'anthropic/claude-opus-5.5': { input: 4.0, output: 20.0 },
55
+ 'anthropic/claude-sonnet-5.5': { input: 2.0, output: 10.0 },
51
56
  'anthropic/claude-fable-5': { input: 10.0, output: 50.0 }, // Mythos-class tier above Opus, 1M ctx
52
57
  // Opus 5 lands at the same $5/$25 as the 4.x Opus line — a straight upgrade
53
58
  // with no cost delta, so nothing downstream needs a pricing carve-out.
@@ -55,7 +60,7 @@ const LEGACY_PRICING = {
55
60
  'anthropic/claude-opus-4.8': { input: 5.0, output: 25.0 },
56
61
  'anthropic/claude-opus-4.7': { input: 5.0, output: 25.0 },
57
62
  'anthropic/claude-opus-4.5': { input: 5.0, output: 25.0 },
58
- 'anthropic/claude-sonnet-5': { input: 3.0, output: 15.0 }, // near-Opus at Sonnet cost, 1M ctx
63
+ 'anthropic/claude-sonnet-5': { input: 2.0, output: 10.0 }, // near-Opus at Sonnet cost, 1M ctx (live list 2026-10-02)
59
64
  'anthropic/claude-sonnet-4.6': { input: 3.0, output: 15.0 },
60
65
  'anthropic/claude-sonnet-4.5': { input: 3.0, output: 15.0 },
61
66
  'anthropic/claude-haiku-4.5': { input: 1.0, output: 5.0 },
@@ -63,6 +68,13 @@ const LEGACY_PRICING = {
63
68
  // Kept for cost lookup on sessions recorded before the switch.
64
69
  'anthropic/claude-haiku-4.5-20251001': { input: 1.0, output: 5.0 },
65
70
  // OpenAI
71
+ // GPT-6 family + GPT-5.1 (live catalog 2026-10-02). Base rates only: GPT-6
72
+ // bills 2x input / 1.5x output above 272K input tokens, which a flat
73
+ // per-1M table cannot express — the catalog's long_context tiers carry that.
74
+ 'openai/gpt-6-astra': { input: 10.0, output: 50.0 },
75
+ 'openai/gpt-6-sol': { input: 2.0, output: 10.0 },
76
+ 'openai/gpt-6-luna': { input: 0.1, output: 0.5 },
77
+ 'openai/gpt-5.1': { input: 1.25, output: 10.0 },
66
78
  'openai/gpt-4.1-nano': { input: 0.1, output: 0.4 },
67
79
  'openai/gpt-4o-mini': { input: 0.15, output: 0.6 },
68
80
  'openai/gpt-5.4-nano': { input: 0.2, output: 1.25 },
@@ -84,12 +96,12 @@ const LEGACY_PRICING = {
84
96
  'openai/o4-mini': { input: 1.1, output: 4.4 },
85
97
  'openai/o1': { input: 15.0, output: 60.0 },
86
98
  'openai/gpt-5.5': { input: 5.0, output: 30.0 },
87
- 'openai/gpt-5.6-sol': { input: 5.0, output: 30.0 }, // GPT-5.6 flagship, deepest reasoning, 1M ctx
99
+ 'openai/gpt-5.6-sol': { input: 4.0, output: 20.0 }, // GPT-5.6 flagship, 1M ctx — cut from $5/$30 on 2026-08-21
88
100
  // GPT-5.6 Pro tiers + 5.5 Pro + chat-latest, added upstream 2026-08-03
89
101
  // (base #329) — priced from the live catalog 2026-08-12.
90
- 'openai/gpt-5.6-luna-pro': { input: 0.1, output: 0.6 },
91
- 'openai/gpt-5.6-terra-pro': { input: 1.0, output: 6.0 },
92
- 'openai/gpt-5.6-sol-pro': { input: 5.0, output: 30.0 },
102
+ 'openai/gpt-5.6-luna-pro': { input: 0.2, output: 1.2 }, // = Luna list (live 2026-10-02)
103
+ 'openai/gpt-5.6-terra-pro': { input: 2.0, output: 12.0 }, // = Terra list (live 2026-10-02)
104
+ 'openai/gpt-5.6-sol-pro': { input: 4.0, output: 20.0 }, // cut from $5/$30 on 2026-08-21
93
105
  'openai/gpt-5.5-pro': { input: 30.0, output: 180.0 },
94
106
  'openai/chat-latest': { input: 5.0, output: 30.0 },
95
107
  'openai/gpt-5.2-pro': { input: 21.0, output: 168.0 },
@@ -103,20 +115,22 @@ const LEGACY_PRICING = {
103
115
  // Google's rate and corrected upstream (base #304) — mirror the real price.
104
116
  'google/gemini-3.5-flash': { input: 1.5, output: 9.0 }, // latest Flash w/ thinking, 1M ctx
105
117
  'google/gemini-3.5-flash-lite': { input: 0.3, output: 2.5 },
106
- 'google/gemini-3.6-flash': { input: 1.5, output: 7.5 }, // added upstream 2026-08-03 (base #329)
118
+ 'google/gemini-3.6-flash': { input: 0.75, output: 3.75 }, // added upstream 2026-08-03 (base #329); live promo rate 2026-10-02
107
119
  'google/gemini-2.5-pro': { input: 1.25, output: 10.0 },
108
120
  'google/gemini-3.1-pro': { input: 2.0, output: 12.0 },
109
121
  // xAI
110
122
  'xai/grok-4.3': { input: 1.25, output: 2.5 }, // 1M ctx; demoted from flagship 2026-07-14
111
- 'xai/grok-4.5': { input: 2.0, output: 6.0 }, // xAI flagship — 500K ctx (note: less than 4.3's 1M)
123
+ 'xai/grok-4.7': { input: 2.0, output: 6.0 }, // newest Grok, 500K ctx (2x at >=200K input)
124
+ 'xai/grok-4.6': { input: 2.0, output: 6.0 }, // 500K ctx (2x at >=200K input)
125
+ 'xai/grok-4.5': { input: 2.0, output: 6.0 }, // 500K ctx (note: less than 4.3's 1M)
112
126
  'xai/grok-build-0.1': { input: 1.0, output: 2.0 }, // agentic coding, OpenRouter resale
113
127
  // DeepSeek (gateway re-aliased these to V4 Flash on 2026-05-03; price cut
114
128
  // again upstream 2026-08-07 to $0.14/$0.28 — mirrored here 2026-08-12).
115
129
  'deepseek/deepseek-chat': { input: 0.14, output: 0.28 },
116
130
  'deepseek/deepseek-reasoner': { input: 0.14, output: 0.28 },
117
- // V4 Pro (1.6T MoE / 49B active, 1M ctx, 65K out). 75% launch promo
118
- // through 2026-05-31 — list is $2.00/$4.00, promo is $0.50/$1.00.
119
- 'deepseek/deepseek-v4-pro': { input: 0.435, output: 0.87 }, // 75% promo became permanent list after 2026-05-31
131
+ // V4 Pro (1.6T MoE / 49B active, 1M ctx, 65K out). Live list 2026-10-02;
132
+ // the old $0.435/$0.87 promo figure no longer matches the gateway.
133
+ 'deepseek/deepseek-v4-pro': { input: 1.32, output: 3.96 },
120
134
  // Minimax
121
135
  'minimax/minimax-m3': { input: 0.3, output: 1.2 },
122
136
  'minimax/minimax-m2.7': { input: 0.3, output: 1.2 },
@@ -125,7 +139,7 @@ const LEGACY_PRICING = {
125
139
  'qwen/qwen3.7-plus': { input: 0.32, output: 1.28 },
126
140
  'qwen/qwen3.7-flash': { input: 0.03, output: 0.13 },
127
141
  // New providers added upstream 2026-08 — priced from the live catalog.
128
- 'tencent/hy3': { input: 0.132, output: 0.528 },
142
+ 'tencent/hy3': { input: 0.132, output: 0.528 }, // retired upstream (hidden) — kept for session-cost records
129
143
  'xiaomi/mimo-v2.5-pro': { input: 0.435, output: 0.87 },
130
144
  // Moonshot — K3 is the gateway flagship (2026-07): 2.8T open MoE, 1M
131
145
  // context, multimodal (image+text), returns reasoning_content. Pricier
@@ -218,7 +218,8 @@ export function createProxy(options) {
218
218
  const effectiveStreamTimeoutMs = options.streamTimeoutMs ?? getProxyStreamTimeoutMs();
219
219
  let baseWallet = null;
220
220
  let solanaWallet = null;
221
- if (chain === 'base') {
221
+ // Base and Arc both pay from the EVM wallet; the 402 names the network.
222
+ if (chain !== 'solana') {
222
223
  const w = getOrCreateWallet();
223
224
  baseWallet = { privateKey: w.privateKey, address: w.address };
224
225
  }
@@ -140,8 +140,9 @@ function normalizeRoutingContext(context) {
140
140
  }
141
141
  // ─── Tier Model Configs ───
142
142
  // Auto-routing strategy (post-DeepSeek-V4-Pro launch promo, 2026-05-03):
143
- // V4 Pro at $0.435/$0.87 with 1M context is the new sweet spot for SIMPLE +
144
- // MEDIUM agent work — Sonnet-quality reasoning at ~1/6 the price. Reserve
143
+ // V4 Pro (launched at $0.435/$0.87; $1.32/$3.96 list as of 2026-10-02) with
144
+ // 1M context is the sweet spot for SIMPLE + MEDIUM agent work — Sonnet-quality
145
+ // reasoning at well under Sonnet's price. Reserve
145
146
  // Opus only for genuinely complex multi-file/multi-decision tasks where
146
147
  // the model's wider context handling and tighter tool-use discipline still
147
148
  // pay for themselves. Sonnet drops to fallback because V4 Pro covers most
@@ -187,7 +188,7 @@ const AUTO_TIERS = {
187
188
  * if none of them have vision, escalates to COMPLEX (Opus is always vision).
188
189
  *
189
190
  * Note: only applied when the caller signals needsVision=true. Without that
190
- * hint the classic per-tier defaults still rule — V4 Pro's $0.435/$0.87 price
191
+ * hint the classic per-tier defaults still rule — V4 Pro's $1.32/$3.96 price
191
192
  * is the right SIMPLE/MEDIUM pick for text-only turns and we don't want to
192
193
  * blanket-upgrade everyone to a vision model.
193
194
  */
@@ -36,6 +36,11 @@ const VISION_MODELS = new Set([
36
36
  'anthropic/claude-sonnet-4.6',
37
37
  'anthropic/claude-sonnet-4.5',
38
38
  'anthropic/claude-haiku-4.5',
39
+ // 2026-10 additions — vision-tagged in the live catalog. Listed after the
40
+ // existing rows so pickVisionSibling's same-family pick is unchanged.
41
+ 'anthropic/claude-fable-5.1',
42
+ 'anthropic/claude-opus-5.5',
43
+ 'anthropic/claude-sonnet-5.5',
39
44
  // OpenAI — multimodal flagships + o3 (Codex 5.3 is text-only, excluded).
40
45
  // GPT-5.6 family + 5.4-mini are vision; 5.4-nano is text-only.
41
46
  'openai/gpt-5.6-sol',
@@ -59,6 +64,11 @@ const VISION_MODELS = new Set([
59
64
  'openai/gpt-4.1',
60
65
  'openai/gpt-4o',
61
66
  'openai/o3',
67
+ // GPT-6 family + GPT-5.1 (2026-10, vision-tagged in the live catalog).
68
+ 'openai/gpt-6-astra',
69
+ 'openai/gpt-6-sol',
70
+ 'openai/gpt-6-luna',
71
+ 'openai/gpt-5.1',
62
72
  // Google — vision baked into every Gemini SKU we surface (flash-lite excepted)
63
73
  'google/gemini-3.1-pro',
64
74
  'google/gemini-3.6-flash',
@@ -75,6 +85,9 @@ const VISION_MODELS = new Set([
75
85
  'xai/grok-4.3',
76
86
  'xai/grok-4-0709',
77
87
  'xai/grok-3',
88
+ // Grok 4.7 / 4.6 (2026-10, vision-tagged in the live catalog).
89
+ 'xai/grok-4.7',
90
+ 'xai/grok-4.6',
78
91
  // Moonshot — K3 is the flagship; the K2.x line is hidden from /v1/models
79
92
  // but still served (probed 2026-08-29) and is catalogued as multimodal.
80
93
  'moonshot/kimi-k3',
@@ -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
+ import type { Chain } from '../config.js';
23
24
  export declare function resolveHostedMaxSpendUsd(requested: number | undefined, ceiling: number | undefined): number | undefined;
24
25
  export interface DispatchOptions {
25
26
  prompt: string;
@@ -43,7 +44,7 @@ export declare class AgentHost {
43
44
  private agents;
44
45
  constructor(opts: {
45
46
  workDir: string;
46
- chain: 'base' | 'solana';
47
+ chain: Chain;
47
48
  apiUrl: string;
48
49
  defaultModel: string;
49
50
  debug?: boolean;
@@ -39,6 +39,7 @@ import { retryFetchBalance } from '../commands/balance-retry.js';
39
39
  import { AgentHost } from './agent-host.js';
40
40
  import { bus } from '../events/bus.js';
41
41
  import { FREE_DEFAULT_MODEL } from '../free-models.js';
42
+ import { readEvmBalance } from '../wallet/manager.js';
42
43
  // Curated Base (chainId 8453) tokens for the wallet "holdings" view. Plain RPC
43
44
  // can't enumerate every token an address holds (no on-chain "list all"), so we
44
45
  // balanceOf a known set and show the non-zero ones. `stable` → USD ≈ amount.
@@ -523,7 +524,9 @@ export async function startServer(opts) {
523
524
  async function fetchBalanceUsd() {
524
525
  try {
525
526
  const client = await getWallet();
526
- return await retryFetchBalance(() => client.getBalance());
527
+ return await retryFetchBalance(() => chain === 'solana'
528
+ ? client.getBalance()
529
+ : readEvmBalance(chain, client));
527
530
  }
528
531
  catch {
529
532
  return undefined;
@@ -2,6 +2,7 @@
2
2
  * Session persistence for Franklin.
3
3
  * Saves conversation history as JSONL for resume capability.
4
4
  */
5
+ import { type Chain } from '../config.js';
5
6
  import type { Dialogue } from '../agent/types.js';
6
7
  export declare function setSessionPersistenceDisabled(disabled: boolean): void;
7
8
  export declare function isSessionPersistenceDisabled(): boolean;
@@ -24,7 +25,7 @@ export interface SessionMeta {
24
25
  * conversation context — switching chains mid-resume is a bug.
25
26
  * Optional for back-compat with pre-3.15.35 sessions.
26
27
  */
27
- chain?: 'base' | 'solana';
28
+ chain?: Chain;
28
29
  inputTokens?: number;
29
30
  outputTokens?: number;
30
31
  costUsd?: number;
@@ -23,6 +23,7 @@
23
23
  */
24
24
  import { Registry } from './registry.js';
25
25
  import type { LoadError } from './types.js';
26
+ import { type Chain } from '../config.js';
26
27
  export interface BundledLoad {
27
28
  registry: Registry;
28
29
  errors: LoadError[];
@@ -45,6 +46,6 @@ export declare function loadAllSkills(workDir: string): AllSkillsLoad;
45
46
  export declare function ensureUserSkillsDir(): string;
46
47
  export declare function ensureLearnedSkillsDir(): string;
47
48
  export interface SkillVarSource {
48
- chain?: 'base' | 'solana';
49
+ chain?: Chain;
49
50
  }
50
51
  export declare function getSkillVars(src: SkillVarSource): Record<string, string>;