@tangle-network/agent-app 0.60.217 → 0.60.219

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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `fetch` that gzips a large string request body before it leaves the app.
3
+ *
4
+ * A Router turn sends its whole system prompt on every model call. From a
5
+ * Worker in another region, a 37k-token prompt (about 150 kB of JSON) spent
6
+ * 118–672 ms uploading before the Router's first step (tangle-router
7
+ * `body_read`), because each round trip of a new connection carries only a
8
+ * slow-start window. Prompt JSON compresses about tenfold, so the upload fits
9
+ * in fewer round trips. The Tangle Router decodes `Content-Encoding: gzip` on
10
+ * /v1/chat/completions, /v1/messages and /v1/responses; another endpoint may not.
11
+ */
12
+ export declare function gzipRequestBodies(base: typeof fetch, minBytes: number): typeof fetch;
@@ -2,7 +2,7 @@ import {
2
2
  ProtectedModelSettlementError,
3
3
  createRouterProtectedModelPort,
4
4
  runProtectedRouterTurn
5
- } from "../chunk-R75P63W5.js";
5
+ } from "../chunk-MAOTZ77B.js";
6
6
  import {
7
7
  DURABLE_HOP_BUDGET_MS,
8
8
  asksForLanguage,
@@ -24,7 +24,7 @@ import {
24
24
  turnKnowledgeInstructions,
25
25
  workspaceKnowledgeForTurn,
26
26
  workspaceTurnCheckpoints
27
- } from "../chunk-7LMHBLFH.js";
27
+ } from "../chunk-NHCS55QI.js";
28
28
  import "../chunk-J63KUZBE.js";
29
29
  import {
30
30
  DEFAULT_TANGLE_BILLING_ENFORCEMENT_ENV_VAR,
@@ -282,6 +282,12 @@ export interface RouterTurnOptions {
282
282
  * chat completions otherwise. A buffered turn (`stream: false`) always uses chat completions.
283
283
  */
284
284
  api?: 'auto' | 'chat' | 'responses';
285
+ /**
286
+ * Gzip a model request body of at least this many bytes (`Content-Encoding: gzip`), so a large system prompt
287
+ * uploads in fewer round trips. The Tangle Router accepts gzip on its model APIs; leave it unset for an
288
+ * endpoint that may not. Default: unset, bodies are sent as they are.
289
+ */
290
+ gzipRequestAboveBytes?: number;
285
291
  }
286
292
  /** OpenAI-compatible function names allow only `[A-Za-z0-9_-]{1,64}`; app tool names often use dots. */
287
293
  export declare function routerFunctionName(name: string): string;
@@ -11,7 +11,7 @@ import {
11
11
  turnKnowledgeInstructions,
12
12
  workspaceKnowledgeForTurn,
13
13
  workspaceTurnCheckpoints
14
- } from "../chunk-7LMHBLFH.js";
14
+ } from "../chunk-NHCS55QI.js";
15
15
  import "../chunk-J63KUZBE.js";
16
16
  import "../chunk-D6UJEOZQ.js";
17
17
  import "../chunk-AMUXRAUO.js";
@@ -7,6 +7,8 @@ import { type TangleExecutionEnvironment } from '../runtime/model';
7
7
  import { type Outcome } from './outcome';
8
8
  import type { TurnSpan, TurnTrace } from '../turn-trace/recorder';
9
9
  export { traceSandboxPromptEvents, type TraceSandboxPromptOptions } from './prompt-trace';
10
+ import { type ReuseStateStore } from './reuse-state';
11
+ export { createCacheReuseStore, type ReuseCacheLike, type ReuseChecks, type ReuseStateStore, type SharedReuseState } from './reuse-state';
10
12
  import { type ProfileFingerprint } from '../profile/fingerprint';
11
13
  import { type ComposeProfileBudget } from '../profile/budget';
12
14
  import { resolveModel, resolveModelSelection, backendModelFields, requireTransportableModel, SandboxModelResolutionError, type ProviderResolutionConfig, type ResolvedModel, type ModelSelection, type ModelSelectionFailure, type ModelSelectionError, type ModelSelectionSource } from './model';
@@ -214,6 +216,15 @@ export interface SandboxRuntimeConfig {
214
216
  * the box is returned. It never deletes the box.
215
217
  */
216
218
  migrateEgressPolicy?: boolean;
219
+ /**
220
+ * Where Worker isolates share what a reuse last checked on a box (its id, the
221
+ * exec probe, the egress read, the runtime environment delivered). A request is
222
+ * not promised the isolate that served the last one, so without a shared store
223
+ * a reuse often finds nothing to trust. Default: the runtime's Cache API when
224
+ * it has one; `null` keeps the state in the isolate. Holds ids, times and
225
+ * digests only.
226
+ */
227
+ reuseState?: ReuseStateStore | null;
217
228
  storage?: (ctx: SandboxBuildContext) => StorageConfig | undefined;
218
229
  restore?: (ctx: SandboxBuildContext) => SandboxRestoreSpec | undefined | Promise<SandboxRestoreSpec | undefined>;
219
230
  boxKey?: (scope: SandboxScope) => string;
@@ -41,6 +41,7 @@ import {
41
41
  buildSandboxToolPathSetupScript,
42
42
  classifySeveredStream,
43
43
  collectSandboxPromptText,
44
+ createCacheReuseStore,
44
45
  createD1PrewarmClaimStore,
45
46
  createD1WarmLeaseStore,
46
47
  createEscalationSpeculator,
@@ -100,7 +101,7 @@ import {
100
101
  warmBinOf,
101
102
  warmWeekdayOf,
102
103
  writeProfileFilesToBox
103
- } from "../chunk-4QUOPWIG.js";
104
+ } from "../chunk-RDLOC7BJ.js";
104
105
  import {
105
106
  EGRESS_PROXY_RECOVERY_PHASE,
106
107
  EGRESS_PROXY_RECOVERY_REQUIRED,
@@ -209,6 +210,7 @@ export {
209
210
  classifySandboxTransientFailure,
210
211
  classifySeveredStream,
211
212
  collectSandboxPromptText,
213
+ createCacheReuseStore,
212
214
  createD1PrewarmClaimStore,
213
215
  createD1WarmLeaseStore,
214
216
  createEscalationSpeculator,
@@ -0,0 +1,55 @@
1
+ /**
2
+ * What isolates share about a running box: its id and the checks a reuse may
3
+ * trust (see `ReuseChecks` in `./index`).
4
+ *
5
+ * A Worker request is not promised the isolate that served the last one. Legal's
6
+ * sandbox lane, 8 consecutive turns on 2026-10-20, found no check from the turn
7
+ * before in any of them, so a trust held only in isolate memory never opened. The
8
+ * state is small and best effort, so it rides the Workers Cache API (one read at
9
+ * the start of a reuse, a write only when a check changed); a miss costs the full
10
+ * verification, as before.
11
+ *
12
+ * Nothing secret is stored: ids, times, and digests of the policy and the
13
+ * runtime environment.
14
+ */
15
+ export interface ReuseChecks {
16
+ /** What tells one run of the box from the next (see `boxIdentity`). */
17
+ identity: string;
18
+ /** When the exec probe last passed. */
19
+ alive?: number;
20
+ /** The egress policy (normalized) the box was last read at or migrated to. */
21
+ egress?: {
22
+ key: string;
23
+ at: number;
24
+ };
25
+ /** The digest of the runtime environment last delivered to the box. */
26
+ env?: {
27
+ digest: string;
28
+ at: number;
29
+ };
30
+ /** The deferred corpus the box was last found to hold, by its hash. */
31
+ corpus?: {
32
+ hash: string;
33
+ at: number;
34
+ };
35
+ }
36
+ export interface SharedReuseState {
37
+ boxId: string;
38
+ checks: ReuseChecks;
39
+ }
40
+ /** Where isolates keep {@link SharedReuseState}, by box name. Failures are the caller's to swallow. */
41
+ export interface ReuseStateStore {
42
+ load(name: string): Promise<SharedReuseState | null>;
43
+ save(name: string, state: SharedReuseState): Promise<void>;
44
+ drop(name: string): Promise<void>;
45
+ }
46
+ /** The slice of a Workers `Cache` this store uses. */
47
+ export interface ReuseCacheLike {
48
+ match(request: Request): Promise<Response | undefined>;
49
+ put(request: Request, response: Response): Promise<void>;
50
+ delete(request: Request): Promise<boolean>;
51
+ }
52
+ /** A store over a Workers-style cache. The cache is opened on first use. */
53
+ export declare function createCacheReuseStore(open: () => Promise<ReuseCacheLike>): ReuseStateStore;
54
+ /** The runtime's own cache when it has one (a Worker does), else null. */
55
+ export declare function workersReuseStore(): ReuseStateStore | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-app",
3
- "version": "0.60.217",
3
+ "version": "0.60.219",
4
4
  "packageManager": "pnpm@11.24.0",
5
5
  "description": "Build agent applications with typed chat, tools, sandboxes, integrations, billing, and evaluation.",
6
6
  "keywords": [