@tangle-network/agent-app 0.47.13 → 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.
@@ -41,7 +41,7 @@ import {
41
41
  flattenHistory,
42
42
  readSandboxBinaryBytes,
43
43
  statSandboxFileSize
44
- } from "../chunk-P6YXUGNA.js";
44
+ } from "../chunk-3G4IUF3D.js";
45
45
  import "../chunk-MCYJON3F.js";
46
46
  import "../chunk-LWSJK546.js";
47
47
  import "../chunk-P5PIAQVS.js";
@@ -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