@blockrun/franklin 3.15.84 → 3.15.86

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.
@@ -133,6 +133,7 @@ export declare class ModelClient {
133
133
  */
134
134
  private resolveVirtualModel;
135
135
  streamCompletion(request: ModelRequest, signal?: AbortSignal): AsyncGenerator<StreamChunk>;
136
+ private parseNonStreamingMessage;
136
137
  /**
137
138
  * Non-streaming completion for simple requests.
138
139
  */
package/dist/agent/llm.js CHANGED
@@ -337,6 +337,8 @@ export class ModelClient {
337
337
  }
338
338
  const isAnthropic = request.model.startsWith('anthropic/');
339
339
  const isGLM = request.model.startsWith('zai/') || request.model.includes('glm');
340
+ const isGeminiThinkingRequired = request.model.startsWith('google/gemini-3.1') ||
341
+ request.model.startsWith('google/gemini-2.5-pro');
340
342
  // Build the request payload, injecting model-specific optimizations
341
343
  let requestPayload = { ...request, stream: true };
342
344
  // Safety: tool_choice without tools causes upstream 400. Strip rather
@@ -368,6 +370,30 @@ export class ModelClient {
368
370
  requestPayload['thinking'] = { type: 'enabled' };
369
371
  }
370
372
  }
373
+ // Gemini Pro reasoning models reject a missing/zero thinking budget. Normalize
374
+ // the gateway default so fallback routing doesn't fail with "Budget 0 is invalid."
375
+ if (isGeminiThinkingRequired) {
376
+ // The gateway's streaming path currently drops Gemini's thinking budget;
377
+ // non-streaming preserves it. We convert the JSON response back into the
378
+ // same internal chunks below so callers keep one code path.
379
+ requestPayload['stream'] = false;
380
+ const maxOut = request.max_tokens ?? 16_384;
381
+ const budgetTokens = Math.min(maxOut, 8_192);
382
+ const thinking = requestPayload['thinking'];
383
+ if (thinking && typeof thinking === 'object' && !Array.isArray(thinking)) {
384
+ requestPayload['thinking'] = {
385
+ ...thinking,
386
+ type: 'enabled',
387
+ budget_tokens: budgetTokens,
388
+ };
389
+ }
390
+ else {
391
+ requestPayload['thinking'] = {
392
+ type: 'enabled',
393
+ budget_tokens: budgetTokens,
394
+ };
395
+ }
396
+ }
371
397
  if (isAnthropic) {
372
398
  // ─ Anthropic extended thinking ──────────────────────────────────────
373
399
  // Enable the `thinking` API block only for models that accept it.
@@ -529,6 +555,10 @@ export class ModelClient {
529
555
  return;
530
556
  }
531
557
  }
558
+ if (requestPayload['stream'] === false) {
559
+ yield* this.parseNonStreamingMessage(response, request.model);
560
+ return;
561
+ }
532
562
  // Parse SSE stream
533
563
  yield* this.parseSSEStream(response, requestController, streamTimeoutMs, request.model);
534
564
  }
@@ -536,6 +566,51 @@ export class ModelClient {
536
566
  unlinkAbort();
537
567
  }
538
568
  }
569
+ async *parseNonStreamingMessage(response, model) {
570
+ const parsed = await response.json();
571
+ yield { kind: 'message_start', payload: { message: parsed } };
572
+ const content = Array.isArray(parsed['content']) ? parsed['content'] : [];
573
+ for (let index = 0; index < content.length; index++) {
574
+ const block = content[index];
575
+ yield { kind: 'content_block_start', payload: { index, content_block: block } };
576
+ if (block.type === 'text' && typeof block.text === 'string') {
577
+ yield {
578
+ kind: 'content_block_delta',
579
+ payload: { index, delta: { type: 'text_delta', text: block.text } },
580
+ };
581
+ }
582
+ else if (block.type === 'thinking' && typeof block.thinking === 'string') {
583
+ yield {
584
+ kind: 'content_block_delta',
585
+ payload: { index, delta: { type: 'thinking_delta', thinking: block.thinking } },
586
+ };
587
+ if (typeof block.signature === 'string') {
588
+ yield {
589
+ kind: 'content_block_delta',
590
+ payload: { index, delta: { type: 'signature_delta', signature: block.signature } },
591
+ };
592
+ }
593
+ }
594
+ else if (block.type === 'tool_use') {
595
+ yield {
596
+ kind: 'content_block_delta',
597
+ payload: { index, delta: { type: 'input_json_delta', partial_json: JSON.stringify(block.input ?? {}) } },
598
+ };
599
+ }
600
+ yield { kind: 'content_block_stop', payload: { index } };
601
+ }
602
+ yield {
603
+ kind: 'message_delta',
604
+ payload: {
605
+ delta: { stop_reason: parsed['stop_reason'] ?? 'end_turn' },
606
+ usage: parsed['usage'] ?? {},
607
+ },
608
+ };
609
+ yield { kind: 'message_stop', payload: {} };
610
+ if (this.debug) {
611
+ console.error(`[franklin] Parsed non-streaming response for ${model}`);
612
+ }
613
+ }
539
614
  /**
540
615
  * Non-streaming completion for simple requests.
541
616
  */
@@ -311,6 +311,7 @@ export async function startCommand(options) {
311
311
  }
312
312
  // Resolve resume target, if requested.
313
313
  let resumeSessionId;
314
+ let resumeTranscript;
314
315
  if (options.resume || options.continue) {
315
316
  const { pickSession } = await import('../ui/session-picker.js');
316
317
  const { loadSessionMeta, loadSessionHistory } = await import('../session/storage.js');
@@ -338,10 +339,11 @@ export async function startCommand(options) {
338
339
  }
339
340
  if (resumeSessionId) {
340
341
  const meta = loadSessionMeta(resumeSessionId);
341
- const msgs = loadSessionHistory(resumeSessionId).length;
342
+ const history = loadSessionHistory(resumeSessionId);
342
343
  const when = meta ? new Date(meta.updatedAt).toLocaleString() : 'unknown';
343
344
  console.log(chalk.green(` Resuming session ${resumeSessionId.slice(0, 24)}…`));
344
- console.log(chalk.dim(` ${msgs} messages · last active ${when}\n`));
345
+ console.log(chalk.dim(` ${history.length} messages · last active ${when}\n`));
346
+ resumeTranscript = buildResumeTranscript(history);
345
347
  }
346
348
  }
347
349
  // Agent config
@@ -376,7 +378,7 @@ export async function startCommand(options) {
376
378
  if (process.stdin.isTTY) {
377
379
  await runWithInkUI(agentConfig, model, workDir, version, walletInfo, (cb) => {
378
380
  onBalanceFetched = cb;
379
- }, fetchBalance, importedKickoffPrompt);
381
+ }, fetchBalance, importedKickoffPrompt, resumeTranscript);
380
382
  }
381
383
  else {
382
384
  await runWithBasicUI(agentConfig, model, workDir, importedKickoffPrompt);
@@ -409,8 +411,40 @@ async function runOneShot(agentConfig, prompt) {
409
411
  });
410
412
  return exitCode;
411
413
  }
414
+ function buildResumeTranscript(history) {
415
+ const entries = history
416
+ .map((msg) => {
417
+ const text = extractVisibleText(msg).replace(/\s+/g, ' ').trim();
418
+ if (!text)
419
+ return null;
420
+ return { role: msg.role, text: text.length > 180 ? `${text.slice(0, 177)}...` : text };
421
+ })
422
+ .filter((entry) => entry !== null);
423
+ if (entries.length === 0)
424
+ return [];
425
+ const started = entries.slice(0, 4);
426
+ const recentStart = entries.length > 10 ? -6 : 4;
427
+ const recent = entries.slice(recentStart);
428
+ return entries.length > 10
429
+ ? [...started, { role: 'assistant', text: '...' }, ...recent]
430
+ : [...started, ...recent];
431
+ }
432
+ function extractVisibleText(msg) {
433
+ if (typeof msg.content === 'string')
434
+ return msg.content;
435
+ if (!Array.isArray(msg.content))
436
+ return '';
437
+ return msg.content
438
+ .map((part) => {
439
+ if ('type' in part && part.type === 'text')
440
+ return part.text;
441
+ return '';
442
+ })
443
+ .filter(Boolean)
444
+ .join('\n');
445
+ }
412
446
  // ─── Ink UI (interactive terminal) ─────────────────────────────────────────
413
- async function runWithInkUI(agentConfig, model, workDir, version, walletInfo, onBalanceReady, fetchBalance, initialInput) {
447
+ async function runWithInkUI(agentConfig, model, workDir, version, walletInfo, onBalanceReady, fetchBalance, initialInput, initialTranscript) {
414
448
  const startSnapshot = snapshotStats();
415
449
  const ui = launchInkUI({
416
450
  model,
@@ -418,6 +452,7 @@ async function runWithInkUI(agentConfig, model, workDir, version, walletInfo, on
418
452
  version,
419
453
  walletAddress: walletInfo?.address,
420
454
  walletBalance: walletInfo?.balance,
455
+ initialTranscript,
421
456
  chain: walletInfo?.chain,
422
457
  onModelChange: (newModel, reason) => {
423
458
  agentConfig.model = newModel;
package/dist/ui/app.d.ts CHANGED
@@ -20,6 +20,10 @@ export declare function launchInkUI(opts: {
20
20
  version: string;
21
21
  walletAddress?: string;
22
22
  walletBalance?: string;
23
+ initialTranscript?: Array<{
24
+ role: 'user' | 'assistant';
25
+ text: string;
26
+ }>;
23
27
  chain?: string;
24
28
  showPicker?: boolean;
25
29
  onModelChange?: (model: string, reason?: 'user' | 'system') => void;
package/dist/ui/app.js CHANGED
@@ -345,7 +345,7 @@ function formatAgentErrorForDisplay(error) {
345
345
  out.push(`- Tip: ${tip}`);
346
346
  return out.join('\n');
347
347
  }
348
- function RunCodeApp({ initialModel, workDir, walletAddress, walletBalance, chain, startWithPicker, onSubmit, onModelChange, onAbort, onExit, }) {
348
+ function RunCodeApp({ initialModel, workDir, walletAddress, walletBalance, chain, initialTranscript, startWithPicker, onSubmit, onModelChange, onAbort, onExit, }) {
349
349
  const { exit } = useApp();
350
350
  // Track terminal rows so we can cap the dynamic-region height. Ink wipes the
351
351
  // terminal scrollback (via ansiEscapes.clearTerminal → \x1b[3J) whenever the
@@ -362,7 +362,14 @@ function RunCodeApp({ initialModel, workDir, walletAddress, walletBalance, chain
362
362
  // Last completed tool — shown in dynamic area so it can be expanded/collapsed with Tab
363
363
  const [expandableTool, setExpandableTool] = useState(null);
364
364
  // Full responses committed to Static immediately — goes into terminal scrollback
365
- const [committedResponses, setCommittedResponses] = useState([]);
365
+ const [committedResponses, setCommittedResponses] = useState(() => (initialTranscript ?? []).map((entry, idx) => ({
366
+ key: `${entry.role === 'user' ? 'user' : 'resume'}-${idx}`,
367
+ text: entry.role === 'user'
368
+ ? chalk.hex('#FFD700').bold('❯ ') + chalk.hex('#FFD700').bold(entry.text)
369
+ : entry.text,
370
+ tokens: { input: 0, output: 0, calls: 0 },
371
+ cost: 0,
372
+ })));
366
373
  // Short preview of latest response shown in dynamic area (last ~5 lines, cleared on next turn)
367
374
  const [responsePreview, setResponsePreview] = useState('');
368
375
  const [currentModel, setCurrentModel] = useState(initialModel || PICKER_MODELS_FLAT[0].id);
@@ -1138,7 +1145,7 @@ export function launchInkUI(opts) {
1138
1145
  restoreTerminalAutoWrap?.();
1139
1146
  instance?.unmount();
1140
1147
  };
1141
- instance = render(_jsx(RunCodeApp, { initialModel: opts.model, workDir: opts.workDir, walletAddress: opts.walletAddress || 'not set — run: franklin setup', walletBalance: opts.walletBalance || 'unknown', chain: opts.chain || 'base', startWithPicker: opts.showPicker, onSubmit: (value) => {
1148
+ instance = render(_jsx(RunCodeApp, { initialModel: opts.model, workDir: opts.workDir, walletAddress: opts.walletAddress || 'not set — run: franklin setup', walletBalance: opts.walletBalance || 'unknown', initialTranscript: opts.initialTranscript, chain: opts.chain || 'base', startWithPicker: opts.showPicker, onSubmit: (value) => {
1142
1149
  if (resolveInput) {
1143
1150
  resolveInput(value);
1144
1151
  resolveInput = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/franklin",
3
- "version": "3.15.84",
3
+ "version": "3.15.86",
4
4
  "description": "Franklin — 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": {