@tangle-network/agent-app 0.47.12 → 0.47.14

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.
@@ -18,6 +18,14 @@
18
18
  * session — including its `step-finish` usage, which must never be billed) and
19
19
  * lets `runWithModelFailover` walk to the next model.
20
20
  *
21
+ * `liveLifecycleEvents` relaxes the buffer for progress only. `start`,
22
+ * `status`, `model-processing`, and session lifecycle carry no answer and no
23
+ * receipt, so a product may take them the moment they arrive and show what
24
+ * the turn is waiting on. Measured 2026-09-11 on a warm production box:
25
+ * OpenCode reports whole parts, so the buffer held every event for 16 s and
26
+ * the product could show nothing through provisioning and agent startup. Off
27
+ * by default: with it on, an abandoned model's progress stays in the stream.
28
+ *
21
29
  * The classification itself is `isUpstreamUnavailable` verbatim, so this path
22
30
  * inherits the measured facts from the 2026-07-25 outage — above all that an
23
31
  * outage is NOT always a thrown error: the sandbox RESOLVES a terminal `error`
@@ -81,6 +89,13 @@ interface TerminalFailure {
81
89
  * never by throwing. Both `data` and the whole record are offered to
82
90
  * `isUpstreamUnavailable` so a payload nested either way is caught.
83
91
  */
92
+ /**
93
+ * Progress the consumer may see before the commit point: it names no model
94
+ * output and carries no billing receipt, so streaming it live cannot duplicate
95
+ * an answer or bill an abandoned attempt. `warning` and every
96
+ * `message.part.updated` (including `step-start`/`step-finish`) stay buffered.
97
+ */
98
+ export declare function isLiveLifecycleEvent(event: unknown): boolean;
84
99
  export declare function classifyTerminalFailure(event: unknown): TerminalFailure | null;
85
100
  /** Open the raw turn stream for one specific model. */
86
101
  export type OpenModelStream = (args: {
@@ -118,6 +133,14 @@ export interface ModelFailoverStreamOptions {
118
133
  firstResponseTimeoutMs?: number;
119
134
  /** Override the commit-point rule. Default {@link isCommittingSandboxEvent}. */
120
135
  isCommitting?: (event: unknown) => boolean;
136
+ /**
137
+ * Stream {@link isLiveLifecycleEvent} progress to the consumer as it arrives
138
+ * instead of holding it until the attempt commits. Default `false`, which
139
+ * keeps an abandoned model's events entirely off the wire. With it on, such
140
+ * an event is never replayed from the buffer, and one from an abandoned
141
+ * attempt stays in the stream — it describes the sandbox, not the answer.
142
+ */
143
+ liveLifecycleEvents?: boolean;
121
144
  onFallback?: (info: ModelFallbackInfo) => void;
122
145
  /**
123
146
  * How many times to RE-RUN THE SAME MODEL when a turn completes having
@@ -87,6 +87,11 @@ export interface SandboxChatProducerOptions {
87
87
  * answer-bearing event. Default 60 seconds. Processing/lifecycle events do
88
88
  * not extend it. */
89
89
  firstResponseTimeoutMs?: number;
90
+ /** Forward `start`/`status`/`model-processing`/session lifecycle to the
91
+ * client as it arrives instead of after the commit point, so a product can
92
+ * show what a turn is waiting on. Default `false`. An abandoned model's
93
+ * progress then stays on the wire; its answer and receipt never do. */
94
+ liveLifecycleEvents?: boolean;
90
95
  /** Fired when a model is abandoned mid-chain (telemetry/alerting). The user
91
96
  * already sees a transcript notice; this is for the operator. */
92
97
  onModelFallback?: (info: ModelFallbackInfo) => void;
@@ -1,5 +1,7 @@
1
1
  import {
2
- assertHarnessModelCompatible
2
+ DEFAULT_HARNESS,
3
+ assertHarnessModelCompatible,
4
+ isHarness
3
5
  } from "./chunk-MCYJON3F.js";
4
6
  import {
5
7
  assertProfilePromptWithinBudget,
@@ -18,6 +20,7 @@ import {
18
20
  Sandbox
19
21
  } from "@tangle-network/sandbox/core";
20
22
  import { createHash } from "crypto";
23
+ import { mergeAgentProfiles } from "@tangle-network/agent-interface";
21
24
 
22
25
  // src/sandbox/outcome.ts
23
26
  var ok = (value) => ({ succeeded: true, value });
@@ -2428,46 +2431,75 @@ function adaptSandboxStream(events) {
2428
2431
  }
2429
2432
  })();
2430
2433
  }
2431
- async function* streamSandboxPrompt(shell, box, message, options) {
2432
- const harness = options?.harness ?? "opencode";
2434
+ async function resolveSandboxPromptBackend(shell, options, operation = "sandbox prompt") {
2435
+ const initialHarness = options.harness ?? options.profile?.harness ?? DEFAULT_HARNESS;
2436
+ if (!isHarness(initialHarness)) throw new Error(`Unsupported sandbox harness: ${initialHarness}`);
2437
+ const extraMcp = mergeExtraMcp(
2438
+ options.appToolMcp ?? {},
2439
+ options.profile?.mcp ?? options.baseProfileMcp ?? {},
2440
+ options.extraMcp
2441
+ );
2442
+ const compose = (harness2) => {
2443
+ if (!shell.profile) throw new Error(`${operation}: supply a profile or a shell profile composer`);
2444
+ return shell.profile({ systemPrompt: options.systemPrompt, extraMcp, harness: harness2 });
2445
+ };
2446
+ let fullProfile = options.profile ? mergeAgentProfiles(options.profile, {
2447
+ ...options.systemPrompt !== void 0 ? { prompt: { systemPrompt: options.systemPrompt } } : {},
2448
+ ...Object.keys(extraMcp).length > 0 ? { mcp: extraMcp } : {}
2449
+ }) : compose(initialHarness);
2450
+ const harness = options.harness ?? fullProfile.harness ?? DEFAULT_HARNESS;
2451
+ if (!isHarness(harness)) throw new Error(`Unsupported sandbox harness: ${harness}`);
2452
+ if (!options.profile && harness !== initialHarness) fullProfile = compose(harness);
2453
+ const explicitModel = trimOrNull(options.model);
2454
+ const profileModel = trimOrNull(fullProfile.model?.default);
2455
+ const profileProvider = !explicitModel && profileModel ? trimOrNull(fullProfile.model?.provider) : null;
2433
2456
  const model = requireTransportableModel(
2434
- resolveModelSelection(shell.provider, {
2435
- model: options?.model,
2436
- modelApiKey: options?.modelApiKey
2457
+ resolveModelSelection({
2458
+ ...shell.provider,
2459
+ providerName: trimOrNull(shell.provider?.providerName) ?? profileProvider ?? void 0
2460
+ }, {
2461
+ model: explicitModel ?? profileModel ?? void 0,
2462
+ modelApiKey: options.modelApiKey
2437
2463
  }),
2438
- "streamSandboxPrompt"
2464
+ operation
2439
2465
  );
2440
- if (model?.model) assertHarnessModelCompatible(harness, model);
2441
- const prompt = typeof message === "string" ? flattenHistory(message, options?.history) : mergeHistoryIntoParts(message, options?.history);
2442
- const appToolMcp = options?.appToolMcp ?? {};
2443
- const extraMcp = mergeExtraMcp(appToolMcp, options?.baseProfileMcp ?? {}, options?.extraMcp);
2444
- const fullProfile = shell.profile({ systemPrompt: options?.systemPrompt, extraMcp, harness });
2445
- const profile = shell.deferProfileFiles ? splitDeferredProfileFiles(fullProfile).leanProfile : fullProfile;
2446
- const profileWithLimits = applyPromptTokenLimits(
2447
- attachReasoningEffort(profile, harness, options?.effort),
2466
+ if (model) assertHarnessModelCompatible(harness, {
2467
+ ...model,
2468
+ provider: profileProvider ?? model.provider
2469
+ });
2470
+ const selectedProfile = {
2471
+ ...fullProfile,
2472
+ harness,
2473
+ ...model ? { model: { ...fullProfile.model, default: model.model } } : {}
2474
+ };
2475
+ const executionProfile = shell.deferProfileFiles && !options.profile ? splitDeferredProfileFiles(selectedProfile).leanProfile : selectedProfile;
2476
+ const profile = applyPromptTokenLimits(
2477
+ attachReasoningEffort(executionProfile, harness, options.effort),
2448
2478
  {
2449
- maxVisibleOutputTokens: options?.maxOutputTokens,
2450
- maxReasoningTokens: options?.maxReasoningTokens,
2451
- maxTotalOutputTokens: options?.maxTotalOutputTokens
2479
+ maxVisibleOutputTokens: options.maxOutputTokens,
2480
+ maxReasoningTokens: options.maxReasoningTokens,
2481
+ maxTotalOutputTokens: options.maxTotalOutputTokens
2452
2482
  }
2453
2483
  );
2454
2484
  assertProfilePromptWithinBudget(
2455
- profileWithLimits,
2485
+ profile,
2456
2486
  shell.promptBudget ?? {},
2457
- "streamSandboxPrompt profile systemPrompt",
2487
+ `${operation} profile systemPrompt`,
2458
2488
  SHELL_PROMPT_BUDGET_HINT
2459
2489
  );
2460
- if (options?.onProfileResolved) {
2461
- options.onProfileResolved(
2462
- await fingerprintAgentProfile(profileWithLimits, { model: model?.model, harness })
2463
- );
2490
+ if (options.onProfileResolved) {
2491
+ options.onProfileResolved(await fingerprintAgentProfile(profile, { model: model?.model, harness }));
2464
2492
  }
2465
- const backend = {
2493
+ return {
2466
2494
  type: harness,
2467
- profile: profileWithLimits,
2495
+ profile,
2468
2496
  ...model ? { model } : {},
2469
- ...options?.interactions ? { interactions: options.interactions } : {}
2497
+ ...options.interactions ? { interactions: options.interactions } : {}
2470
2498
  };
2499
+ }
2500
+ async function* streamSandboxPrompt(shell, box, message, options) {
2501
+ const backend = await resolveSandboxPromptBackend(shell, options ?? {}, "streamSandboxPrompt");
2502
+ const prompt = typeof message === "string" ? flattenHistory(message, options?.history) : mergeHistoryIntoParts(message, options?.history);
2471
2503
  const stream = options?.detach ? detachedSandboxPromptEvents(box, prompt, options, backend) : box.streamPrompt(prompt, {
2472
2504
  sessionId: options?.sessionId,
2473
2505
  executionId: options?.executionId,
@@ -2625,31 +2657,8 @@ async function mintSandboxScopedToken(box, options) {
2625
2657
  }
2626
2658
  }
2627
2659
  async function driveSandboxTurn(shell, box, message, options) {
2628
- const harness = options.harness ?? "opencode";
2629
- const model = requireTransportableModel(
2630
- resolveModelSelection(shell.provider, {
2631
- model: options.model,
2632
- modelApiKey: options.modelApiKey
2633
- }),
2634
- "driveSandboxTurn"
2635
- );
2636
- if (model?.model) assertHarnessModelCompatible(harness, model);
2660
+ const backend = await resolveSandboxPromptBackend(shell, options, "driveSandboxTurn");
2637
2661
  const prompt = typeof message === "string" ? flattenHistory(message, options.history) : mergeHistoryIntoParts(message, options.history);
2638
- const appToolMcp = options.appToolMcp ?? {};
2639
- const extraMcp = mergeExtraMcp(appToolMcp, options.baseProfileMcp ?? {}, options.extraMcp);
2640
- const fullProfile = shell.profile({ systemPrompt: options.systemPrompt, extraMcp, harness });
2641
- const executionProfile = shell.deferProfileFiles ? splitDeferredProfileFiles(fullProfile).leanProfile : fullProfile;
2642
- const profile = attachReasoningEffort(
2643
- executionProfile,
2644
- harness,
2645
- options.effort
2646
- );
2647
- assertProfilePromptWithinBudget(
2648
- profile,
2649
- shell.promptBudget ?? {},
2650
- "driveSandboxTurn profile systemPrompt",
2651
- SHELL_PROMPT_BUDGET_HINT
2652
- );
2653
2662
  try {
2654
2663
  const drive = await box.driveTurn(prompt, {
2655
2664
  sessionId: options.sessionId,
@@ -2660,12 +2669,7 @@ async function driveSandboxTurn(shell, box, message, options) {
2660
2669
  // Sandbox 0.37 drives through the session message lane, so a gateway
2661
2670
  // consumer can handle these events. Callers without one should omit
2662
2671
  // interactions so the run stays unattended.
2663
- backend: {
2664
- type: harness,
2665
- profile,
2666
- ...model ? { model } : {},
2667
- ...options.interactions ? { interactions: options.interactions } : {}
2668
- }
2672
+ backend
2669
2673
  });
2670
2674
  emitSandboxActivity(options.spend, box);
2671
2675
  return ok(drive);
@@ -2801,6 +2805,7 @@ export {
2801
2805
  attachReasoningEffort,
2802
2806
  applyPromptTokenLimits,
2803
2807
  adaptSandboxStream,
2808
+ resolveSandboxPromptBackend,
2804
2809
  streamSandboxPrompt,
2805
2810
  collectSandboxPromptText,
2806
2811
  runSandboxPrompt,
@@ -2816,4 +2821,4 @@ export {
2816
2821
  isTerminalPromptEvent,
2817
2822
  detectInteractiveQuestion
2818
2823
  };
2819
- //# sourceMappingURL=chunk-P6YXUGNA.js.map
2824
+ //# sourceMappingURL=chunk-3G4IUF3D.js.map