@blockrun/franklin 3.34.0 → 3.34.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -260,6 +260,11 @@ export async function startServer(opts) {
260
260
  // The socket + correlation id for the in-flight turn (single-window).
261
261
  let activeWs = null;
262
262
  let activeTurnId = null;
263
+ // Pending approval asks for the legacy desktop session (trade plans).
264
+ // Keyed by askId — the wire contract the desktop UI already declares
265
+ // (agent.permissionAsk / agent.permissionResponse with askId + decision).
266
+ let askSeq = 0;
267
+ const legacyAsks = new Map();
263
268
  // We sometimes inject helper commands (`/model …`, `/clear`) as their own
264
269
  // turns ahead of the real prompt. Each ends with its own turn_done — which
265
270
  // would emit agent.done and clear activeTurnId, killing the real prompt's
@@ -443,10 +448,38 @@ export async function startServer(opts) {
443
448
  capabilities,
444
449
  maxTurns: 100,
445
450
  workingDir: workDir,
446
- permissionMode: 'trust', // the desktop UI has no permission prompt yet
451
+ permissionMode: 'trust', // tools auto-run; money still gates via approvalPromptFn below
447
452
  debug: !!debug,
448
453
  showPrefetchStatus: false,
449
454
  costSaver,
455
+ // Structured approvals (trade plans): surfaced to the desktop over the
456
+ // in-flight turn stream as agent.permissionAsk; the UI answers with
457
+ // agent.permissionResponse {askId, decision}. Without a connected
458
+ // client — or unanswered past the TTL — the approval fails closed,
459
+ // matching the trade-plan gate's deny-by-default posture.
460
+ approvalPromptFn: (req) => new Promise((resolve) => {
461
+ if (!activeWs || !activeTurnId) {
462
+ resolve({ choice: 'deny', message: 'no client connected to approve' });
463
+ return;
464
+ }
465
+ const askId = `ask_${++askSeq}_${Date.now().toString(36)}`;
466
+ const timer = setTimeout(() => {
467
+ if (legacyAsks.delete(askId)) {
468
+ resolve({ choice: 'deny', message: 'approval timed out' });
469
+ }
470
+ }, req.timeoutMs ?? 15 * 60 * 1000);
471
+ timer.unref?.();
472
+ legacyAsks.set(askId, (decision) => {
473
+ clearTimeout(timer);
474
+ resolve(decision);
475
+ });
476
+ emit('agent.permissionAsk', {
477
+ sessionId: '',
478
+ toolName: req.kind === 'trade-plan' ? 'TradePlan' : req.title,
479
+ description: `${req.title}\n\n${req.description}`,
480
+ askId,
481
+ });
482
+ }),
450
483
  };
451
484
  agentConfig = config;
452
485
  interactiveSession(config, getUserInput, onEvent, (abort) => { abortFn = abort; })
@@ -692,14 +725,35 @@ export async function startServer(opts) {
692
725
  abortFn();
693
726
  break;
694
727
  case 'agent.permissionResponse': {
695
- // Hosted agents: resolve the parked approval by (sessionId, requestId).
696
- // Legacy desktop path runs in trust mode — nothing to unblock there,
697
- // so a payload without ids stays a no-op (byte-compatible).
728
+ // Two resolution paths:
729
+ // - Hosted agents: (sessionId, requestId) → AgentHost broker.
730
+ // - Legacy desktop session: (askId, decision y/n/always) → the parked
731
+ // approvalPromptFn promise (trade-plan approvals).
732
+ // A payload with neither stays a no-op (byte-compatible with clients
733
+ // that predate both).
698
734
  const sid = p.sessionId ? String(p.sessionId) : '';
699
735
  const rid = p.requestId ? String(p.requestId) : '';
700
736
  if (sid && rid) {
701
737
  const ok = host.respond(sid, rid, String(p.choice ?? p.decision ?? 'no'), p.message ? String(p.message) : undefined);
702
738
  send(ws, id, 'response', { ok });
739
+ break;
740
+ }
741
+ const askId = p.askId ? String(p.askId) : '';
742
+ if (askId) {
743
+ const resolver = legacyAsks.get(askId);
744
+ if (resolver) {
745
+ legacyAsks.delete(askId);
746
+ const decision = String(p.decision ?? p.choice ?? 'n').toLowerCase();
747
+ const approve = decision === 'y' || decision === 'yes' || decision === 'always' || decision === 'approve';
748
+ resolver({
749
+ choice: approve ? 'approve' : 'deny',
750
+ message: p.message ? String(p.message) : undefined,
751
+ });
752
+ send(ws, id, 'response', { ok: true });
753
+ }
754
+ else {
755
+ send(ws, id, 'response', { ok: false });
756
+ }
703
757
  }
704
758
  break;
705
759
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/franklin",
3
- "version": "3.34.0",
3
+ "version": "3.34.1",
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": {