@tangle-network/agent-app 3.0.3 → 3.0.5

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.
@@ -46,6 +46,10 @@ export interface ChatTurnDefaultBackend<TContext = unknown, TResource = unknown>
46
46
  }
47
47
  export declare function defaultChatShell(projectId: string, env: ChatTurnEnvironment, config: ChatTurnDefaultBackend): SandboxRuntimeConfig;
48
48
  export declare function createDefaultChatBackend<TContext, TResource>(projectId: string, env: ChatTurnEnvironment, config: ChatTurnDefaultBackend<TContext, TResource>, bindings?: ChatTurnStoreBindings, modelPolicy?: ModelPolicy): {
49
+ prewarm: (scope: {
50
+ workspaceId: string;
51
+ userId: string;
52
+ }) => Promise<void> | Promise<import("../sandbox/prewarm.js").PrewarmResult | undefined>;
49
53
  when: (args: ChatTurnProduceArgs<TContext, TResource>) => boolean;
50
54
  router(args: ChatTurnProduceArgs<TContext, TResource>): Promise<ChatTurnHybridConfiguration>;
51
55
  sandbox: (args: ChatTurnProduceArgs<TContext, TResource>) => Promise<{
@@ -43,7 +43,7 @@ import {
43
43
  } from "../chunk-X2NXWJ6P.js";
44
44
  import {
45
45
  runProtectedRouterTurn
46
- } from "../chunk-4EQWYI53.js";
46
+ } from "../chunk-AFMLLZWU.js";
47
47
  import {
48
48
  DEFAULT_MODEL_FIRST_RESPONSE_TIMEOUT_MS,
49
49
  DEFAULT_MODEL_STREAM_OPEN_TIMEOUT_MS,
@@ -82,13 +82,13 @@ import {
82
82
  turnCarriesFiles,
83
83
  turnPromptText,
84
84
  withProducerStream
85
- } from "../chunk-PO23GWVQ.js";
85
+ } from "../chunk-7YFJ7YCM.js";
86
86
  import "../chunk-SBHFMDR7.js";
87
87
  import "../chunk-H6BRJU5M.js";
88
88
  import "../chunk-4DBHC63F.js";
89
89
  import "../chunk-RN4WPTBH.js";
90
90
  import "../chunk-MM6RLOXF.js";
91
- import "../chunk-B2NN5BIJ.js";
91
+ import "../chunk-FWLVAWKR.js";
92
92
  import "../chunk-F4TUZYMX.js";
93
93
  import {
94
94
  redactErrorMessage
@@ -176,9 +176,9 @@ import "../chunk-S5SRJJQG.js";
176
176
  import "../chunk-O23ED5XC.js";
177
177
  import "../chunk-UGWQLQDS.js";
178
178
  import "../chunk-5V3NHVM3.js";
179
- import "../chunk-3XVGMHCD.js";
179
+ import "../chunk-PISTUUEZ.js";
180
180
  import "../chunk-D6UJEOZQ.js";
181
- import "../chunk-DCPOEDPK.js";
181
+ import "../chunk-YYA2CVOY.js";
182
182
  import "../chunk-KSLTD4FI.js";
183
183
  import {
184
184
  sniffMimeFromName
@@ -1,2 +1,5 @@
1
- import type { CreateChatTurnRoutesOptions } from './turn-route-contracts.js';
2
- export declare function createChatPrewarm<TContext, TResource>(options: CreateChatTurnRoutesOptions<TContext, TResource>): (request: Request) => Promise<Response>;
1
+ import type { ChatTurnRequestContext, CreateChatTurnRoutesOptions } from './turn-route-contracts.js';
2
+ export declare function createChatPrewarm<TContext, TResource>(options: CreateChatTurnRoutesOptions<TContext, TResource>, box?: (scope: {
3
+ workspaceId: string;
4
+ userId: string;
5
+ }) => Promise<unknown>): (request: Request, ctx?: ChatTurnRequestContext) => Promise<Response>;
@@ -566,8 +566,8 @@ export interface ChatTurnTraceOptions<TContext> {
566
566
  export interface CreateChatTurnRoutesOptions<TContext = void, TResource = unknown> {
567
567
  /** Deployment bindings for the template defaults. Custom producers keep their own credentials and policy. */
568
568
  env?: import('./default-backend.js').ChatTurnEnvironment;
569
- /** Disable the inherited prewarm endpoint explicitly. It warms only authenticated thread locks. */
570
- prewarm?: false;
569
+ /** `false` disables the prewarm endpoint; `'box'` also brings up the default backend's box on page open (paid compute). */
570
+ prewarm?: false | 'box';
571
571
  /** Names the product in `deriveExecutionId` so retries land on the same
572
572
  * substrate execution. */
573
573
  projectId: string;
@@ -797,8 +797,8 @@ export declare const INTENT_LINE_HISTORY_MESSAGES = 6;
797
797
  export declare const INTENT_LINE_MAX_CHARS = 240;
798
798
  /** Define routes to run, replay, and list running chat turns with streaming and reconnect support */
799
799
  export interface ChatTurnRoutes {
800
- /** POST — warm the server-authorized workspace lock; verify a named thread before allowing it. Never provisions paid compute. */
801
- prewarm(request: Request): Promise<Response>;
800
+ /** POST — warm the server-authorized workspace lock (and with `prewarm: 'box'` its box, under `ctx.waitUntil`); verify a named thread first. */
801
+ prewarm(request: Request, ctx?: ChatTurnRequestContext): Promise<Response>;
802
802
  /** POST — run one turn, streaming NDJSON. First line is
803
803
  * `{type:'turn', turnId}` (the replay handle); the rest is the engine's
804
804
  * event protocol. Pass the platform's `waitUntil` so the turn keeps
@@ -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-B2NN5BIJ.js";
31
+ } from "./chunk-FWLVAWKR.js";
31
32
  import {
32
33
  redactErrorMessage
33
34
  } from "./chunk-MH74DY2I.js";
@@ -114,13 +115,13 @@ import {
114
115
  import {
115
116
  composeRouterTurnPromptSections,
116
117
  runRouterTurn
117
- } from "./chunk-3XVGMHCD.js";
118
+ } from "./chunk-PISTUUEZ.js";
118
119
  import {
119
120
  createIntelligenceTurnTraceSink,
120
121
  createTurnTrace,
121
122
  formatServerTiming,
122
123
  otlpTraceId
123
- } from "./chunk-DCPOEDPK.js";
124
+ } from "./chunk-YYA2CVOY.js";
124
125
  import {
125
126
  readSandboxBinaryBytes,
126
127
  statSandboxFileSize
@@ -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-PO23GWVQ.js.map
4157
+ //# sourceMappingURL=chunk-7YFJ7YCM.js.map