@tangle-network/agent-app 0.60.218 → 0.60.220

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.
@@ -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;
@@ -617,9 +628,10 @@ export type PeekWorkspaceSandboxOutcome = {
617
628
  * costs the caller a cold start it never asked for.
618
629
  *
619
630
  * Matching is on BOTH the box key and the display name, IN THAT ORDER.
620
- * `client.get(id)` keys on the platform's opaque sandbox id, not the
621
- * deterministic key a product derives from a workspace, and is itself a
622
- * `list().find` underneath — so a lookup by identity has to list and match.
631
+ * `client.get(id)` is a direct read by the platform's opaque sandbox id, not by
632
+ * the deterministic key a product derives from a workspace, so a lookup that
633
+ * has not seen the box before has to list and match (`ensureWorkspaceSandbox`
634
+ * reads a box it has seen by id).
623
635
  * Provisioning here always stamps `name` with the box key, so the key is the
624
636
  * authoritative match; the display-name pass exists only to adopt boxes on a
625
637
  * host that predates that convention. The order matters: a single unordered
@@ -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-C7WAGXQN.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.218",
3
+ "version": "0.60.220",
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": [