@tangle-network/agent-app 0.47.13 → 0.47.15

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-XR5ZXMYL.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,77 @@ 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 = profileModel && (!explicitModel || 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
+ // The materializer compares the profile and transport as provider-qualified
2474
+ // identities. Authored provider evidence has already served preflight above.
2475
+ ...model ? { model: { ...fullProfile.model, provider: model.provider, default: model.model } } : {}
2476
+ };
2477
+ const executionProfile = shell.deferProfileFiles && !options.profile ? splitDeferredProfileFiles(selectedProfile).leanProfile : selectedProfile;
2478
+ const profile = applyPromptTokenLimits(
2479
+ attachReasoningEffort(executionProfile, harness, options.effort),
2448
2480
  {
2449
- maxVisibleOutputTokens: options?.maxOutputTokens,
2450
- maxReasoningTokens: options?.maxReasoningTokens,
2451
- maxTotalOutputTokens: options?.maxTotalOutputTokens
2481
+ maxVisibleOutputTokens: options.maxOutputTokens,
2482
+ maxReasoningTokens: options.maxReasoningTokens,
2483
+ maxTotalOutputTokens: options.maxTotalOutputTokens
2452
2484
  }
2453
2485
  );
2454
2486
  assertProfilePromptWithinBudget(
2455
- profileWithLimits,
2487
+ profile,
2456
2488
  shell.promptBudget ?? {},
2457
- "streamSandboxPrompt profile systemPrompt",
2489
+ `${operation} profile systemPrompt`,
2458
2490
  SHELL_PROMPT_BUDGET_HINT
2459
2491
  );
2460
- if (options?.onProfileResolved) {
2461
- options.onProfileResolved(
2462
- await fingerprintAgentProfile(profileWithLimits, { model: model?.model, harness })
2463
- );
2492
+ if (options.onProfileResolved) {
2493
+ options.onProfileResolved(await fingerprintAgentProfile(profile, { model: model?.model, harness }));
2464
2494
  }
2465
- const backend = {
2495
+ return {
2466
2496
  type: harness,
2467
- profile: profileWithLimits,
2497
+ profile,
2468
2498
  ...model ? { model } : {},
2469
- ...options?.interactions ? { interactions: options.interactions } : {}
2499
+ ...options.interactions ? { interactions: options.interactions } : {}
2470
2500
  };
2501
+ }
2502
+ async function* streamSandboxPrompt(shell, box, message, options) {
2503
+ const backend = await resolveSandboxPromptBackend(shell, options ?? {}, "streamSandboxPrompt");
2504
+ const prompt = typeof message === "string" ? flattenHistory(message, options?.history) : mergeHistoryIntoParts(message, options?.history);
2471
2505
  const stream = options?.detach ? detachedSandboxPromptEvents(box, prompt, options, backend) : box.streamPrompt(prompt, {
2472
2506
  sessionId: options?.sessionId,
2473
2507
  executionId: options?.executionId,
@@ -2625,31 +2659,8 @@ async function mintSandboxScopedToken(box, options) {
2625
2659
  }
2626
2660
  }
2627
2661
  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);
2662
+ const backend = await resolveSandboxPromptBackend(shell, options, "driveSandboxTurn");
2637
2663
  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
2664
  try {
2654
2665
  const drive = await box.driveTurn(prompt, {
2655
2666
  sessionId: options.sessionId,
@@ -2660,12 +2671,7 @@ async function driveSandboxTurn(shell, box, message, options) {
2660
2671
  // Sandbox 0.37 drives through the session message lane, so a gateway
2661
2672
  // consumer can handle these events. Callers without one should omit
2662
2673
  // interactions so the run stays unattended.
2663
- backend: {
2664
- type: harness,
2665
- profile,
2666
- ...model ? { model } : {},
2667
- ...options.interactions ? { interactions: options.interactions } : {}
2668
- }
2674
+ backend
2669
2675
  });
2670
2676
  emitSandboxActivity(options.spend, box);
2671
2677
  return ok(drive);
@@ -2801,6 +2807,7 @@ export {
2801
2807
  attachReasoningEffort,
2802
2808
  applyPromptTokenLimits,
2803
2809
  adaptSandboxStream,
2810
+ resolveSandboxPromptBackend,
2804
2811
  streamSandboxPrompt,
2805
2812
  collectSandboxPromptText,
2806
2813
  runSandboxPrompt,
@@ -2816,4 +2823,4 @@ export {
2816
2823
  isTerminalPromptEvent,
2817
2824
  detectInteractiveQuestion
2818
2825
  };
2819
- //# sourceMappingURL=chunk-P6YXUGNA.js.map
2826
+ //# sourceMappingURL=chunk-XR5ZXMYL.js.map