@blockrun/franklin 3.45.0 → 3.47.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 (57) hide show
  1. package/README.md +32 -11
  2. package/dist/agent/context.js +58 -10
  3. package/dist/agent/llm.js +14 -6
  4. package/dist/agent/loop.js +34 -6
  5. package/dist/agent/optimize.d.ts +1 -1
  6. package/dist/agent/optimize.js +17 -7
  7. package/dist/agent/secret-redact.d.ts +26 -0
  8. package/dist/agent/secret-redact.js +48 -0
  9. package/dist/agent/streaming-executor.js +15 -0
  10. package/dist/commands/doctor.js +18 -0
  11. package/dist/commands/start.js +4 -0
  12. package/dist/commands/usage.d.ts +14 -0
  13. package/dist/commands/usage.js +86 -0
  14. package/dist/commands/wallet-adopt.d.ts +12 -0
  15. package/dist/commands/wallet-adopt.js +49 -0
  16. package/dist/free-models.js +2 -1
  17. package/dist/gateway-models.js +34 -66
  18. package/dist/index.js +16 -0
  19. package/dist/model-catalog.d.ts +10 -0
  20. package/dist/model-catalog.js +77 -0
  21. package/dist/payments/auth-mode.d.ts +5 -19
  22. package/dist/payments/auth-mode.js +15 -17
  23. package/dist/payments/billing-copy.d.ts +37 -0
  24. package/dist/payments/billing-copy.js +57 -0
  25. package/dist/payments/post-with-payment.js +8 -15
  26. package/dist/payments/price-catalog.d.ts +9 -0
  27. package/dist/payments/price-catalog.js +13 -0
  28. package/dist/payments/usage.d.ts +106 -0
  29. package/dist/payments/usage.js +168 -0
  30. package/dist/pricing.d.ts +2 -6
  31. package/dist/pricing.js +16 -3
  32. package/dist/router/vision.js +9 -1
  33. package/dist/stats/tracker.d.ts +9 -1
  34. package/dist/stats/tracker.js +6 -1
  35. package/dist/tools/bash.js +17 -7
  36. package/dist/tools/blockrun.js +1 -1
  37. package/dist/tools/defillama.js +2 -2
  38. package/dist/tools/imagegen.js +5 -4
  39. package/dist/tools/modal.js +12 -6
  40. package/dist/tools/musicgen.js +4 -3
  41. package/dist/tools/phone.js +16 -15
  42. package/dist/tools/prediction.js +12 -11
  43. package/dist/tools/realface.js +2 -2
  44. package/dist/tools/rpc.js +2 -2
  45. package/dist/tools/sensitive-paths.d.ts +1 -1
  46. package/dist/tools/sensitive-paths.js +13 -4
  47. package/dist/tools/surf.js +2 -2
  48. package/dist/tools/videogen.js +6 -5
  49. package/dist/tools/voice.d.ts +1 -1
  50. package/dist/tools/voice.js +5 -4
  51. package/dist/ui/model-picker.d.ts +1 -2
  52. package/dist/ui/model-picker.js +34 -117
  53. package/dist/wallet/reservation.d.ts +24 -0
  54. package/dist/wallet/reservation.js +50 -4
  55. package/dist/wallet/solana-migration.d.ts +48 -0
  56. package/dist/wallet/solana-migration.js +81 -0
  57. package/package.json +6 -4
@@ -22,6 +22,7 @@ import { logger } from '../logger.js';
22
22
  import { isWalletKeyPath } from './sensitive-paths.js';
23
23
  import { findModel, estimateCostUsd } from '../gateway-models.js';
24
24
  import { recordUsage } from '../stats/tracker.js';
25
+ import { noChargeNote } from '../payments/billing-copy.js';
25
26
  const DEFAULT_MODEL = 'minimax/music-2.5+';
26
27
  // Flat per-track price for the default model — already margin-inclusive
27
28
  // ($0.15/track × 1.05 gateway margin). Fallback when the catalog is unavailable.
@@ -65,14 +66,14 @@ function buildExecute(deps) {
65
66
  if (contentId && deps.library) {
66
67
  const content = deps.library.get(contentId);
67
68
  if (!content) {
68
- return { output: `Content ${contentId} not found. No USDC was spent.` };
69
+ return { output: `Content ${contentId} not found. ${noChargeNote()}` };
69
70
  }
70
71
  if (content.spentUsd + trackCostUsd > content.budgetUsd + 1e-9) {
71
72
  return {
72
73
  output: `## Music generation skipped\n` +
73
74
  `- Would exceed budget: spent $${content.spentUsd.toFixed(2)} + fixed ` +
74
75
  `$${trackCostUsd.toFixed(2)} > cap $${content.budgetUsd.toFixed(2)}\n\n` +
75
- `No USDC was spent.`,
76
+ noChargeNote(),
76
77
  };
77
78
  }
78
79
  }
@@ -263,7 +264,7 @@ export function createMusicGenCapability(deps = {}) {
263
264
  name: 'MusicGen',
264
265
  description: "Generate a ~3-minute MP3 track from a text prompt (plus optional " +
265
266
  "lyrics or instrumental flag). Calls BlockRun's /v1/audio/generations. " +
266
- "Costs $0.1575 USDC per call — bills a flat rate, MiniMax ignores " +
267
+ "Costs $0.1575 per call — bills a flat rate, MiniMax ignores " +
267
268
  "duration hints and always returns ~3 min. Generation takes 1–3 " +
268
269
  "minutes. ALWAYS confirm with the user before calling — music is " +
269
270
  "expensive and slow. Pass contentId to attach to a Content piece " +
@@ -16,6 +16,7 @@ import { loadChain, VERSION } from '../config.js';
16
16
  import { gatewayBase, gatewayHeaders } from '../payments/auth-mode.js';
17
17
  import { logger } from '../logger.js';
18
18
  import { recordUsage } from '../stats/tracker.js';
19
+ import { chargedNote, noChargeNote, cancelHint } from '../payments/billing-copy.js';
19
20
  const PHONE_TIMEOUT_MS = 30_000;
20
21
  async function postWithPayment(path, body, ctx, meta) {
21
22
  const startMs = Date.now();
@@ -119,7 +120,7 @@ export const listPhoneNumbersCapability = {
119
120
  name: 'ListPhoneNumbers',
120
121
  description: 'List the phone numbers your wallet currently owns (US/CA, leased 30 days at a time). ' +
121
122
  'Use this before any phone-related action to remind the agent what numbers are available. ' +
122
- 'Costs $0.001 USDC. Returns each number with country, area code, expiration timestamp, ' +
123
+ 'Costs $0.001 per call. Returns each number with country, area code, expiration timestamp, ' +
123
124
  'and current status (active/expiring/expired).',
124
125
  input_schema: { type: 'object', properties: {} },
125
126
  },
@@ -127,7 +128,7 @@ export const listPhoneNumbersCapability = {
127
128
  try {
128
129
  const res = await postWithPayment('/v1/phone/numbers/list', {}, ctx, { tool: 'ListPhoneNumbers', priceUsd: 0.001 });
129
130
  return {
130
- output: `## Phone numbers (wallet-owned)\n\n` +
131
+ output: `## Phone numbers (provisioned to this account)\n\n` +
131
132
  '```json\n' + JSON.stringify(res, null, 2) + '\n```',
132
133
  };
133
134
  }
@@ -139,7 +140,7 @@ export const listPhoneNumbersCapability = {
139
140
  export const buyPhoneNumberCapability = {
140
141
  spec: {
141
142
  name: 'BuyPhoneNumber',
142
- description: 'Provision a new US or CA phone number for the wallet for 30 days. Costs $5 USDC. ' +
143
+ description: 'Provision a new US or CA phone number for 30 days. Costs $5.00 per number. ' +
143
144
  'Optionally pin a 3-digit area code (best effort). The provisioned number is auto-registered ' +
144
145
  'as a valid caller ID for outbound VoiceCall. A wallet can hold multiple numbers; this adds ' +
145
146
  'one, never replaces. To pick the country: country="US" (default) or country="CA".',
@@ -162,15 +163,15 @@ export const buyPhoneNumberCapability = {
162
163
  // callers (FRANKLIN_MEDIA_AUTO_APPROVE_ALL=1 or no onAskUser bridge) proceed.
163
164
  const autoApprove = process.env.FRANKLIN_MEDIA_AUTO_APPROVE_ALL === '1';
164
165
  if (!autoApprove && ctx.onAskUser) {
165
- const answer = await ctx.onAskUser(`Buy a new ${body.country || 'US'} phone number for $5.00 USDC? No USDC is spent if you cancel.`, ['Buy', 'Cancel']);
166
+ const answer = await ctx.onAskUser(`Buy a new ${body.country || 'US'} phone number for $5.00? ${cancelHint()}`, ['Buy', 'Cancel']);
166
167
  if (answer !== 'Buy') {
167
- return { output: `## Phone number purchase cancelled\n\nNo USDC was spent.` };
168
+ return { output: `## Phone number purchase cancelled\n\n${noChargeNote()}` };
168
169
  }
169
170
  }
170
171
  try {
171
172
  const res = await postWithPayment('/v1/phone/numbers/buy', body, ctx, { tool: 'BuyPhoneNumber', priceUsd: 5.0 });
172
173
  return {
173
- output: `## Number provisioned ($5 USDC charged)\n\n` +
174
+ output: `## Number provisioned (${chargedNote(5)})\n\n` +
174
175
  '```json\n' + JSON.stringify(res, null, 2) + '\n```',
175
176
  };
176
177
  }
@@ -182,7 +183,7 @@ export const buyPhoneNumberCapability = {
182
183
  export const renewPhoneNumberCapability = {
183
184
  spec: {
184
185
  name: 'RenewPhoneNumber',
185
- description: 'Extend the 30-day lease on a wallet-owned phone number. Costs $5 USDC. Use ListPhoneNumbers ' +
186
+ description: 'Extend the 30-day lease on a BlockRun-provisioned phone number. Costs $5.00. Use ListPhoneNumbers ' +
186
187
  'first to confirm the number is yours. Released or expired numbers cannot be renewed — buy a ' +
187
188
  'new one with BuyPhoneNumber instead.',
188
189
  input_schema: {
@@ -200,15 +201,15 @@ export const renewPhoneNumberCapability = {
200
201
  // Confirm the $5 spend before charging (parity with BuyPhoneNumber / ModalCreate).
201
202
  const autoApprove = process.env.FRANKLIN_MEDIA_AUTO_APPROVE_ALL === '1';
202
203
  if (!autoApprove && ctx.onAskUser) {
203
- const answer = await ctx.onAskUser(`Renew ${input.phone_number} for 30 days at $5.00 USDC? No USDC is spent if you cancel.`, ['Renew', 'Cancel']);
204
+ const answer = await ctx.onAskUser(`Renew ${input.phone_number} for 30 days at $5.00? ${cancelHint()}`, ['Renew', 'Cancel']);
204
205
  if (answer !== 'Renew') {
205
- return { output: `## Renewal cancelled\n\nNo USDC was spent.` };
206
+ return { output: `## Renewal cancelled\n\n${noChargeNote()}` };
206
207
  }
207
208
  }
208
209
  try {
209
210
  const res = await postWithPayment('/v1/phone/numbers/renew', { phoneNumber: input.phone_number }, ctx, { tool: 'RenewPhoneNumber', priceUsd: 5.0 });
210
211
  return {
211
- output: `## Lease renewed (+30 days, $5 USDC charged)\n\n` +
212
+ output: `## Lease renewed (+30 days, ${chargedNote(5)})\n\n` +
212
213
  '```json\n' + JSON.stringify(res, null, 2) + '\n```',
213
214
  };
214
215
  }
@@ -220,7 +221,7 @@ export const renewPhoneNumberCapability = {
220
221
  export const releasePhoneNumberCapability = {
221
222
  spec: {
222
223
  name: 'ReleasePhoneNumber',
223
- description: 'Release a wallet-owned phone number back to the BlockRun pool before its lease expires. ' +
224
+ description: 'Release a BlockRun-provisioned phone number back to the pool before its lease expires. ' +
224
225
  'Free. The number is gone after this — it may be picked up by another wallet. Use when you ' +
225
226
  "no longer need a test number and want it out of your ListPhoneNumbers result.",
226
227
  input_schema: {
@@ -251,8 +252,8 @@ export const phoneLookupCapability = {
251
252
  spec: {
252
253
  name: 'PhoneLookup',
253
254
  description: 'Look up carrier and line type information for ANY phone number (does not need to be ' +
254
- 'wallet-owned). Returns carrier name, line type (mobile/landline/voip), country, and ' +
255
- 'portability info. Costs $0.01 USDC. Use to validate a number before texting/calling or ' +
255
+ 'BlockRun-provisioned). Returns carrier name, line type (mobile/landline/voip), country, and ' +
256
+ 'portability info. Costs $0.01 per lookup. Use to validate a number before texting/calling or ' +
256
257
  'to figure out whether a contact number is a real mobile.',
257
258
  input_schema: {
258
259
  type: 'object',
@@ -269,7 +270,7 @@ export const phoneLookupCapability = {
269
270
  try {
270
271
  const res = await postWithPayment('/v1/phone/lookup', { phoneNumber: input.phone_number }, ctx, { tool: 'PhoneLookup', priceUsd: 0.01 });
271
272
  return {
272
- output: `## Phone lookup ($0.01 USDC charged)\n\n` +
273
+ output: `## Phone lookup (${chargedNote(0.01)})\n\n` +
273
274
  '```json\n' + JSON.stringify(res, null, 2) + '\n```',
274
275
  };
275
276
  }
@@ -299,7 +300,7 @@ export const phoneFraudCheckCapability = {
299
300
  try {
300
301
  const res = await postWithPayment('/v1/phone/lookup/fraud', { phoneNumber: input.phone_number }, ctx, { tool: 'PhoneFraudCheck', priceUsd: 0.05 });
301
302
  return {
302
- output: `## Fraud check ($0.05 USDC charged)\n\n` +
303
+ output: `## Fraud check (${chargedNote(0.05)})\n\n` +
303
304
  '```json\n' + JSON.stringify(res, null, 2) + '\n```',
304
305
  };
305
306
  }
@@ -37,12 +37,13 @@
37
37
  */
38
38
  import { getOrCreateWallet, getOrCreateSolanaWallet, createPaymentPayload, createSolanaPaymentPayload, parsePaymentRequired, extractPaymentDetails, solanaKeyToBytes, SOLANA_NETWORK, } from '@blockrun/llm';
39
39
  import { loadChain, VERSION } from '../config.js';
40
- import { chargeFromResponse, resolveCharge } from '../payments/price-catalog.js';
40
+ import { chargeFromResponse, requestIdFromResponse, resolveCharge } from '../payments/price-catalog.js';
41
41
  import { gatewayBase, gatewayHeaders } from '../payments/auth-mode.js';
42
42
  import { logger } from '../logger.js';
43
43
  import { recordFetch } from '../trading/providers/telemetry.js';
44
44
  import { recordUsage } from '../stats/tracker.js';
45
45
  import { frameUntrusted } from './untrusted.js';
46
+ import { receiptLine } from '../payments/billing-copy.js';
46
47
  const TIMEOUT_MS = 30_000;
47
48
  const DEFAULT_LIMIT = 20;
48
49
  const MAX_LIMIT = 50;
@@ -131,7 +132,7 @@ async function getWithPayment(path, query, ctx) {
131
132
  // restart). Without this, Predexon spend is absent from `franklin stats`
132
133
  // and invisible to the --max-spend ceiling (parity with surf.ts).
133
134
  try {
134
- recordUsage(`PredictionMarket:${path}`, 0, 0, charge.usd, Date.now() - startedAt, false, charge.estimated);
135
+ recordUsage(`PredictionMarket:${path}`, 0, 0, charge.usd, Date.now() - startedAt, false, charge.estimated, requestIdFromResponse(response));
135
136
  }
136
137
  catch { /* best-effort */ }
137
138
  return (await response.json());
@@ -409,7 +410,7 @@ async function execute(input, ctx) {
409
410
  lines.push(`${i + 1}. **[${platform}]** ${title}`);
410
411
  });
411
412
  }
412
- lines.push(`_$0.005 paid via x402._`);
413
+ lines.push(receiptLine(0.005));
413
414
  return { output: frameUntrusted('Prediction-market data (untrusted)', lines.join('\n')) };
414
415
  }
415
416
  case 'leaderboard': {
@@ -457,7 +458,7 @@ async function execute(input, ctx) {
457
458
  parts.push(`win ${formatPct(winRate, 0)}`);
458
459
  lines.push(`${i + 1}. \`${w}\`${handle}` + (parts.length > 0 ? ` — ${parts.join(' · ')}` : ''));
459
460
  });
460
- lines.push('', `_$0.001 paid via x402._`);
461
+ lines.push('', receiptLine(0.001));
461
462
  return { output: frameUntrusted('Prediction-market data (untrusted)', lines.join('\n')) };
462
463
  }
463
464
  case 'walletProfile': {
@@ -572,7 +573,7 @@ async function execute(input, ctx) {
572
573
  if (recent.length > 0)
573
574
  lines.push(` ${recent.join(' · ')}`);
574
575
  });
575
- lines.push('', `_$0.005 paid via x402._`);
576
+ lines.push('', receiptLine(0.005));
576
577
  return { output: frameUntrusted('Prediction-market data (untrusted)', lines.join('\n')) };
577
578
  }
578
579
  case 'walletPnl': {
@@ -648,7 +649,7 @@ async function execute(input, ctx) {
648
649
  });
649
650
  }
650
651
  }
651
- lines.push('', `_$0.005 paid via x402._`);
652
+ lines.push('', receiptLine(0.005));
652
653
  return { output: frameUntrusted('Prediction-market data (untrusted)', lines.join('\n')) };
653
654
  }
654
655
  case 'walletPositions': {
@@ -714,7 +715,7 @@ async function execute(input, ctx) {
714
715
  }
715
716
  lines.push(`${i + 1}. **${title}** — ${parts.join(' · ')}`);
716
717
  });
717
- lines.push('', `_$0.005 paid via x402._`);
718
+ lines.push('', receiptLine(0.005));
718
719
  return { output: frameUntrusted('Prediction-market data (untrusted)', lines.join('\n')) };
719
720
  }
720
721
  case 'smartActivity': {
@@ -755,7 +756,7 @@ async function execute(input, ctx) {
755
756
  stats.push(`${formatPct(netBuyersPct, 0)} net buyers`);
756
757
  lines.push(`${i + 1}. **${title}**${cidTag}` + (stats.length > 0 ? `\n ${stats.join(' · ')}` : ''));
757
758
  });
758
- lines.push('', `_$0.005 paid via x402._`);
759
+ lines.push('', receiptLine(0.005));
759
760
  return { output: frameUntrusted('Prediction-market data (untrusted)', lines.join('\n')) };
760
761
  }
761
762
  case 'smartMoney': {
@@ -810,7 +811,7 @@ async function execute(input, ctx) {
810
811
  perf.push(`win ${formatPct(pos.avg_smart_win_rate, 0)}`);
811
812
  lines.push(`**Smart performance:** ${perf.join(' · ')}`);
812
813
  }
813
- lines.push('', `_$0.005 paid via x402._`);
814
+ lines.push('', receiptLine(0.005));
814
815
  return { output: frameUntrusted('Prediction-market data (untrusted)', lines.join('\n')) };
815
816
  }
816
817
  case 'searchPolymarket': {
@@ -857,7 +858,7 @@ async function execute(input, ctx) {
857
858
  ` prices: ${yesPx} · vol: ${formatUsd(vol)} · liq: ${formatUsd(liq)}` +
858
859
  (end ? ` · ends ${String(end).slice(0, 10)}` : ''));
859
860
  });
860
- lines.push('', `_$0.001 paid via x402._`);
861
+ lines.push('', receiptLine(0.001));
861
862
  return { output: frameUntrusted('Prediction-market data (untrusted)', lines.join('\n')) };
862
863
  }
863
864
  case 'searchKalshi': {
@@ -893,7 +894,7 @@ async function execute(input, ctx) {
893
894
  ` yes ${yes} · vol: ${m.volume?.toLocaleString() ?? 'n/a'} · OI: ${m.open_interest?.toLocaleString() ?? 'n/a'}` +
894
895
  (m.close_time ? ` · closes ${String(m.close_time).slice(0, 10)}` : ''));
895
896
  });
896
- lines.push('', `_$0.001 paid via x402._`);
897
+ lines.push('', receiptLine(0.001));
897
898
  return { output: frameUntrusted('Prediction-market data (untrusted)', lines.join('\n')) };
898
899
  }
899
900
  case 'crossPlatform': {
@@ -27,7 +27,7 @@
27
27
  */
28
28
  import { getOrCreateWallet, getOrCreateSolanaWallet, createPaymentPayload, createSolanaPaymentPayload, parsePaymentRequired, extractPaymentDetails, solanaKeyToBytes, SOLANA_NETWORK, } from '@blockrun/llm';
29
29
  import { loadChain, USER_AGENT } from '../config.js';
30
- import { chargeFromResponse, resolveCharge } from '../payments/price-catalog.js';
30
+ import { chargeFromResponse, requestIdFromResponse, resolveCharge } from '../payments/price-catalog.js';
31
31
  import { gatewayBase, gatewayHeaders } from '../payments/auth-mode.js';
32
32
  import { recordUsage } from '../stats/tracker.js';
33
33
  import { logger } from '../logger.js';
@@ -194,7 +194,7 @@ async function actionEnroll(base, chain, input, ctx) {
194
194
  ? resolveCharge({ apiPath: url, chargedUsd: chargeFromResponse(res), settledUsd: paidUsd })
195
195
  : { usd: 0, estimated: false };
196
196
  try {
197
- recordUsage('RealFace:enroll', 0, 0, charge.usd, Date.now() - start, false, charge.estimated);
197
+ recordUsage('RealFace:enroll', 0, 0, charge.usd, Date.now() - start, false, charge.estimated, requestIdFromResponse(res));
198
198
  }
199
199
  catch { /* best-effort */ }
200
200
  if (res.status === 425) {
package/dist/tools/rpc.js CHANGED
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import { getOrCreateWallet, getOrCreateSolanaWallet, createPaymentPayload, createSolanaPaymentPayload, parsePaymentRequired, extractPaymentDetails, solanaKeyToBytes, SOLANA_NETWORK, } from '@blockrun/llm';
20
20
  import { loadChain, VERSION } from '../config.js';
21
- import { chargeFromResponse, resolveCharge } from '../payments/price-catalog.js';
21
+ import { chargeFromResponse, requestIdFromResponse, resolveCharge } from '../payments/price-catalog.js';
22
22
  import { gatewayBase, gatewayHeaders } from '../payments/auth-mode.js';
23
23
  import { logger } from '../logger.js';
24
24
  import { recordUsage } from '../stats/tracker.js';
@@ -94,7 +94,7 @@ async function postRpcWithPayment(network, jsonRpcBody, ctx) {
94
94
  // call from the published catalog instead of recording a free call.
95
95
  const charge = resolveCharge({ apiPath: endpoint, chargedUsd: chargeFromResponse(response), settledUsd: paidUsd });
96
96
  try {
97
- recordUsage(`MultiChainRPC:${network}`, 0, 0, charge.usd, Date.now() - startedAt, false, charge.estimated);
97
+ recordUsage(`MultiChainRPC:${network}`, 0, 0, charge.usd, Date.now() - startedAt, false, charge.estimated, requestIdFromResponse(response));
98
98
  }
99
99
  catch { /* best-effort */ }
100
100
  return {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Wallet secret-material guard for the model-facing file tools.
2
+ * Secret-material guard for the model-facing file tools.
3
3
  *
4
4
  * Franklin IS the wallet: a steered model (prompt injection via a fetched page,
5
5
  * MCP result, file contents, etc.) that can Read/Write/Edit arbitrary paths
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Wallet secret-material guard for the model-facing file tools.
2
+ * Secret-material guard for the model-facing file tools.
3
3
  *
4
4
  * Franklin IS the wallet: a steered model (prompt injection via a fetched page,
5
5
  * MCP result, file contents, etc.) that can Read/Write/Edit arbitrary paths
@@ -11,13 +11,22 @@
11
11
  */
12
12
  import fs from 'node:fs';
13
13
  import path from 'node:path';
14
- import { BLOCKRUN_DIR } from '../config.js';
15
- /** Private-key / wallet-secret files under ~/.blockrun. */
14
+ import { API_KEY_FILE, BLOCKRUN_DIR } from '../config.js';
15
+ /**
16
+ * Secret-material files under ~/.blockrun.
17
+ *
18
+ * Appended to, never reordered: test/local.mjs indexes this list positionally.
19
+ */
16
20
  const WALLET_KEY_FILES = [
17
21
  path.join(BLOCKRUN_DIR, '.session'), // EVM private key (0x hex)
18
22
  path.join(BLOCKRUN_DIR, '.solana-session'), // Solana secret key (base58)
19
23
  path.join(BLOCKRUN_DIR, '.solana-session-key2'),
20
- path.join(BLOCKRUN_DIR, 'solana-wallet.json'), // legacy { address, private_key }
24
+ path.join(BLOCKRUN_DIR, 'solana-wallet.json'), // legacy { address, privateKey }
25
+ // Account bearer key (brk_...). Not a private key, but it spends: it draws
26
+ // on a prepaid balance with no per-call signature and no chain-level
27
+ // ceiling, so `cat ~/.blockrun/api-key` is exfiltration in one Read. It
28
+ // belongs behind the same guard as the wallet keys above.
29
+ API_KEY_FILE,
21
30
  ];
22
31
  // macOS (APFS) and Windows are case-INSENSITIVE by default, and fs.realpathSync
23
32
  // does NOT canonicalize case — so `.SOLANA-SESSION` opens the real
@@ -17,7 +17,7 @@
17
17
  */
18
18
  import { getOrCreateWallet, getOrCreateSolanaWallet, createPaymentPayload, createSolanaPaymentPayload, parsePaymentRequired, extractPaymentDetails, solanaKeyToBytes, SOLANA_NETWORK, } from '@blockrun/llm';
19
19
  import { loadChain, USER_AGENT } from '../config.js';
20
- import { basePriceForPath, chargeFromResponse, resolveCharge } from '../payments/price-catalog.js';
20
+ import { basePriceForPath, chargeFromResponse, requestIdFromResponse, resolveCharge } from '../payments/price-catalog.js';
21
21
  import { GATEWAY_TRANSACTION_FEE_USD } from '../gateway-models.js';
22
22
  import { gatewayBase, gatewayHeaders } from '../payments/auth-mode.js';
23
23
  import { frameUntrusted } from './untrusted.js';
@@ -218,7 +218,7 @@ async function callSurf(toolName, table, input, ctx) {
218
218
  ? resolveCharge({ apiPath: url, chargedUsd: chargeFromResponse(response), settledUsd: paidUsd })
219
219
  : { usd: 0, estimated: false };
220
220
  try {
221
- recordUsage(`${toolName}:${entry.path}`, 0, 0, charge.usd, Date.now() - start, false, charge.estimated);
221
+ recordUsage(`${toolName}:${entry.path}`, 0, 0, charge.usd, Date.now() - start, false, charge.estimated, requestIdFromResponse(response));
222
222
  }
223
223
  catch { /* best-effort */ }
224
224
  if (!response.ok) {
@@ -29,6 +29,7 @@ import { resolveReferenceImage } from './imagegen.js';
29
29
  import { isWalletKeyPath } from './sensitive-paths.js';
30
30
  import { recordUsage } from '../stats/tracker.js';
31
31
  import { findModel, estimateCostUsd, GATEWAY_MARGIN } from '../gateway-models.js';
32
+ import { noChargeNote, cancelHint } from '../payments/billing-copy.js';
32
33
  // BytePlus RealFace asset IDs from the RealFace tool (after H5 liveness +
33
34
  // enrollment). Format: `ta_` + alphanumeric.
34
35
  const REAL_FACE_ASSET_ID_REGEX = /^ta_[A-Za-z0-9]+$/;
@@ -141,23 +142,23 @@ function buildExecute(deps) {
141
142
  // Model-aware estimate so the quoted price matches the model we name in
142
143
  // the prompt (flat per-second fallback only when the model is unknown).
143
144
  const est = resolveVideoUnitCost(videoCatalogModel, duration);
144
- 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']);
145
+ const answer = await ctx.onAskUser(`Generate a ${duration}s video with ${videoModel} for ~$${est.toFixed(2)}? ${cancelHint()}`, ['Generate', 'Cancel']);
145
146
  if (answer !== 'Generate') {
146
- return { output: `## Video generation cancelled\n\nNo USDC was spent.` };
147
+ return { output: `## Video generation cancelled\n\n${noChargeNote()}` };
147
148
  }
148
149
  }
149
150
  const estCost = resolveVideoUnitCost(videoCatalogModel, duration);
150
151
  if (contentId && deps.library) {
151
152
  const content = deps.library.get(contentId);
152
153
  if (!content) {
153
- return { output: `Content ${contentId} not found. No USDC was spent.` };
154
+ return { output: `Content ${contentId} not found. ${noChargeNote()}` };
154
155
  }
155
156
  if (content.spentUsd + estCost > content.budgetUsd + 1e-9) {
156
157
  return {
157
158
  output: `## Video generation skipped\n` +
158
159
  `- Would exceed budget: spent $${content.spentUsd.toFixed(2)} + estimated ` +
159
160
  `$${estCost.toFixed(2)} > cap $${content.budgetUsd.toFixed(2)}\n\n` +
160
- `No USDC was spent.`,
161
+ noChargeNote(),
161
162
  };
162
163
  }
163
164
  }
@@ -486,7 +487,7 @@ export function createVideoGenCapability(deps = {}) {
486
487
  spec: {
487
488
  name: 'VideoGen',
488
489
  description: "Generate a short MP4 video from a text prompt (optional seed image). " +
489
- "Calls BlockRun's /v1/videos/generations. Costs USDC — default model " +
490
+ "Calls BlockRun's /v1/videos/generations. Billed per generation — default model " +
490
491
  "xai/grok-imagine-video bills $0.05/s (8s default ≈ $0.42). Generation " +
491
492
  "takes ~20–60s. ALWAYS confirm with the user before calling — videos " +
492
493
  "are expensive and slow. Pass contentId to attach to a Content piece " +
@@ -7,7 +7,7 @@
7
7
  * - VoiceStatus — GET /v1/voice/call/{call_id} (free). Polls for transcript
8
8
  * + recording + final disposition.
9
9
  *
10
- * Voice calls require a wallet-owned BlockRun phone number as caller ID —
10
+ * Voice calls require a BlockRun-provisioned phone number as caller ID —
11
11
  * use BuyPhoneNumber (or ListPhoneNumbers if one already exists) before
12
12
  * calling VoiceCall, otherwise the gateway returns 400 with the buy
13
13
  * instructions inline.
@@ -7,7 +7,7 @@
7
7
  * - VoiceStatus — GET /v1/voice/call/{call_id} (free). Polls for transcript
8
8
  * + recording + final disposition.
9
9
  *
10
- * Voice calls require a wallet-owned BlockRun phone number as caller ID —
10
+ * Voice calls require a BlockRun-provisioned phone number as caller ID —
11
11
  * use BuyPhoneNumber (or ListPhoneNumbers if one already exists) before
12
12
  * calling VoiceCall, otherwise the gateway returns 400 with the buy
13
13
  * instructions inline.
@@ -21,6 +21,7 @@ import { logger } from '../logger.js';
21
21
  import { recordUsage } from '../stats/tracker.js';
22
22
  import { frameUntrusted } from './untrusted.js';
23
23
  import { CallLog } from '../phone/call-log.js';
24
+ import { chargedNote } from '../payments/billing-copy.js';
24
25
  /** Singleton, lazy — paths are computed at first use so tests can stub homedir. */
25
26
  let _callLog = null;
26
27
  function callLog() {
@@ -228,7 +229,7 @@ export const voiceCallCapability = {
228
229
  'Common use cases: appointment reminders, verification callbacks, voice surveys, customer ' +
229
230
  'outreach, OTP retrieval, two-party verification calls.\n\n' +
230
231
  'Requirements:\n' +
231
- ' - `from` MUST be a wallet-owned BlockRun phone number — use ListPhoneNumbers to find ' +
232
+ ' - `from` MUST be a BlockRun-provisioned phone number — use ListPhoneNumbers to find ' +
232
233
  'one or BuyPhoneNumber to provision one ($5, 30-day lease).\n' +
233
234
  ' - `to` and `from` must be E.164 format (+ country code prefix, e.g. +14155552671).\n' +
234
235
  ' - `task` must be ≥10 chars, ≤4000 chars.\n' +
@@ -306,7 +307,7 @@ export const voiceCallCapability = {
306
307
  if (typeof input.to !== 'string')
307
308
  return { output: 'to (E.164) required', isError: true };
308
309
  if (typeof input.from !== 'string')
309
- return { output: 'from (wallet-owned E.164) required — use ListPhoneNumbers / BuyPhoneNumber', isError: true };
310
+ return { output: 'from (BlockRun-provisioned E.164) required — use ListPhoneNumbers / BuyPhoneNumber', isError: true };
310
311
  if (typeof input.task !== 'string' || input.task.length < 10) {
311
312
  return { output: 'task required (10–4000 chars natural-language description)', isError: true };
312
313
  }
@@ -345,7 +346,7 @@ export const voiceCallCapability = {
345
346
  }
346
347
  catch { /* best-effort */ }
347
348
  return {
348
- output: `## Voice call initiated ($0.54 USDC charged)\n\n` +
349
+ output: `## Voice call initiated (${chargedNote(0.54)})\n\n` +
349
350
  `**call_id:** \`${callId}\`\n\nPoll with VoiceStatus call_id="${callId}" to get the ` +
350
351
  `transcript and disposition. The call typically completes in 1–6 minutes.\n\n` +
351
352
  '```json\n' + JSON.stringify(res, null, 2) + '\n```',
@@ -3,7 +3,6 @@
3
3
  * Shows categorized model list, supports shortcuts and arrow-key selection.
4
4
  */
5
5
  import { type GatewayModel } from '../gateway-models.js';
6
- export declare const MODEL_SHORTCUTS: Record<string, string>;
7
6
  /**
8
7
  * Resolve a model name — supports shortcuts. Returns the canonical model id.
9
8
  *
@@ -53,8 +52,8 @@ export interface ModelCategory {
53
52
  * (pickModel() below) import from this array. To add or remove models,
54
53
  * edit this one place.
55
54
  */
55
+ export declare const MODEL_SHORTCUTS: Record<string, string>;
56
56
  export declare const PICKER_CATEGORIES: ModelCategory[];
57
- /** Flat list of all picker models (for index-based navigation). */
58
57
  export declare const PICKER_MODELS_FLAT: ModelEntry[];
59
58
  export interface HydratedPicker {
60
59
  categories: ModelCategory[];