@tangle-network/agent-app 3.0.4 → 3.0.6

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.
@@ -14,6 +14,7 @@ import {
14
14
  createComputerStep,
15
15
  createD1PrewarmClaimStore,
16
16
  createEscalationSpeculator,
17
+ createSandboxPrewarmer,
17
18
  createSandboxRunTool,
18
19
  createWorkspacePrewarmRoute,
19
20
  ensureWorkspaceSandbox,
@@ -27,7 +28,7 @@ import {
27
28
  sandboxRunFailureDetail,
28
29
  streamSandboxPrompt,
29
30
  turnStorageBindings
30
- } from "./chunk-FWLVAWKR.js";
31
+ } from "./chunk-FDPQ67MN.js";
31
32
  import {
32
33
  redactErrorMessage
33
34
  } from "./chunk-MH74DY2I.js";
@@ -3593,7 +3594,9 @@ function createDefaultChatBackend(projectId, env, config, bindings, modelPolicy)
3593
3594
  trace: args.trace,
3594
3595
  signal: args.admissionSignal
3595
3596
  });
3597
+ const warmer = bindings && createSandboxPrewarmer(shell, { claim: createD1PrewarmClaimStore(bindings.db), mode: "create-or-resume", claimTtlSeconds: 45 });
3596
3598
  return {
3599
+ prewarm: (scope) => warmer ? warmer.prewarm({ ...scope, harness }).then((warm) => warm.completion) : Promise.resolve(),
3597
3600
  when: (args) => config.router !== false && (Boolean(config.funding) || Boolean(env.TANGLE_API_KEY?.trim())) && !turnCarriesFiles(args.prompt) && !args.executionLimits?.maxReasoningTokens,
3598
3601
  async router(args) {
3599
3602
  const model = modelFor(args);
@@ -3645,12 +3648,12 @@ function createDefaultChatBackend(projectId, env, config, bindings, modelPolicy)
3645
3648
  }
3646
3649
 
3647
3650
  // src/chat-routes/route-prewarm.ts
3648
- function createChatPrewarm(options) {
3651
+ function createChatPrewarm(options, box) {
3649
3652
  if (options.prewarm === false) return async () => new Response(null, { status: 405 });
3650
3653
  const bindings = options.turnLock === false ? void 0 : turnStorageBindings(options);
3651
3654
  const route = createWorkspacePrewarmRoute({
3652
3655
  turnStore: bindings,
3653
- authorize: async ({ request, threadId }) => {
3656
+ authorize: async ({ request, context, threadId }) => {
3654
3657
  const auth = await options.authorize({ request, intent: "running", threadId });
3655
3658
  if (!auth.ok) return { status: "denied", response: auth.response };
3656
3659
  if (auth.intent !== void 0 && auth.intent !== "running") return {
@@ -3658,10 +3661,11 @@ function createChatPrewarm(options) {
3658
3661
  response: Response.json({ error: "Authorization did not allow this read.", code: "chat_authorization_intent_mismatch" }, { status: 403 })
3659
3662
  };
3660
3663
  if (!bindings) return { status: "declined", reason: "lock_not_configured" };
3664
+ if (options.prewarm === "box" && box) context?.waitUntil?.(box({ workspaceId: auth.tenantId, userId: auth.userId }));
3661
3665
  return { status: "allowed", workspaceId: auth.tenantId, steps: [] };
3662
3666
  }
3663
3667
  });
3664
- return (request) => route(request, void 0);
3668
+ return (request, ctx) => route(request, ctx);
3665
3669
  }
3666
3670
 
3667
3671
  // src/chat-routes/turn-routes.ts
@@ -3696,10 +3700,11 @@ async function admitTurn(request, trace, options, waitUntil) {
3696
3700
  }
3697
3701
  function createChatTurnRoutes(input) {
3698
3702
  const produce = input.produce;
3703
+ const backend = typeof produce === "function" || produce && "router" in produce && typeof produce.router === "function" ? void 0 : createDefaultChatBackend(input.projectId, input.env ?? {}, produce ?? {}, turnStorageBindings(input), input.modelPolicy);
3699
3704
  const options = {
3700
3705
  ...input,
3701
3706
  ...resolveTurnStorage(input),
3702
- produce: typeof produce === "function" || produce && "router" in produce && typeof produce.router === "function" ? produce : createDefaultChatBackend(input.projectId, input.env ?? {}, produce ?? {}, turnStorageBindings(input), input.modelPolicy)
3707
+ produce: backend ?? produce
3703
3708
  };
3704
3709
  const log = options.log ?? ((message, meta) => console.error(message, meta ?? ""));
3705
3710
  const draftStore = options.store;
@@ -3919,7 +3924,7 @@ function createChatTurnRoutes(input) {
3919
3924
  return Response.json({ running: ids });
3920
3925
  }
3921
3926
  return {
3922
- prewarm: createChatPrewarm(input),
3927
+ prewarm: createChatPrewarm(input, backend?.prewarm),
3923
3928
  turn: (request, ctx) => withD1QueryCount(() => turn(request, ctx)),
3924
3929
  cancel: (request) => cancelChatTurn(request, { authorize: options.authorize, cancel: options.cancel, log }),
3925
3930
  replay,
@@ -4149,4 +4154,4 @@ export {
4149
4154
  createChatTurnRoutes,
4150
4155
  streamChatRouteAsSandboxEvents
4151
4156
  };
4152
- //# sourceMappingURL=chunk-JDNGAX4C.js.map
4157
+ //# sourceMappingURL=chunk-VGGSCEI6.js.map