@tangle-network/agent-provider-tangle 1.5.0 → 1.7.0

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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { TangleExactProcessOptions } from "./tangle-types.js";
2
- export { JsonBoundError } from "./tangle-contract-safety.js";
2
+ export { JsonBoundError, MAX_INLINE_PAYLOAD_BYTES, MAX_PAYLOAD_STRING_BYTES, MAX_TOTAL_PAYLOAD_BYTES, } from "./tangle-contract-safety.js";
3
3
  export type { JsonBoundRule, JsonBoundViolation } from "./tangle-contract-safety.js";
4
4
  export * from "./tangle-types.js";
5
5
  export { createTangleProvider } from "./tangle-provider.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { JsonBoundError } from "./tangle-contract-safety.js";
1
+ export { JsonBoundError, MAX_INLINE_PAYLOAD_BYTES, MAX_PAYLOAD_STRING_BYTES, MAX_TOTAL_PAYLOAD_BYTES, } from "./tangle-contract-safety.js";
2
2
  export * from "./tangle-types.js";
3
3
  export { createTangleProvider } from "./tangle-provider.js";
4
4
  export { DEFAULT_TANGLE_READY_TIMEOUT_MS } from "./tangle-readiness.js";
@@ -107,10 +107,14 @@ export function defaultTangleSandboxCapabilities(harness) {
107
107
  // Create carries both fields to the Sandbox API unchanged. The API still authorizes the
108
108
  // caller for a delegated billing owner, and it rejects the create when it does not, so this
109
109
  // states only that neither field is dropped on the way.
110
+ // A workspace checkpoint is a Sandbox snapshot. Create restores it into the new box, and the
111
+ // snapshot outlives the box it was taken from (measured 2026-09-24: files byte-identical in
112
+ // a box created 19 s after the source box was deleted).
110
113
  create: {
111
114
  egress: ["open", "strict", "blocked"],
112
115
  billingOwner: true,
113
116
  runtimeAttachments: { mcp: true },
117
+ workspaceCheckpoint: true,
114
118
  },
115
119
  // This is intent only. Narrowing requires both raw TEE evidence and the
116
120
  // caller's external provider-key verifier before the flag survives.
@@ -6,6 +6,50 @@ export declare const MAX_LIST_RESULTS = 100000;
6
6
  export declare const SANDBOX_LIST_PAGE_SIZE = 1000;
7
7
  export declare const MAX_IDENTIFIER_LENGTH = 512;
8
8
  export declare const MAX_STRING_LENGTH = 16384;
9
+ /**
10
+ * MAX_STRING_LENGTH governs CONTROL-PLANE text — names, identifiers, env values, metadata — where
11
+ * 16 KiB is already generous. It must not govern DATA. The contents of file mounts and of inline
12
+ * profile resources are the product's cargo, and one bound for both refused a 17,894-character
13
+ * script AFTER spawn_worker had returned a worker id, so the caller paid for the spawn and got a
14
+ * child it could not equip (agent-sdk#340).
15
+ *
16
+ * Payload is measured in BYTES. `String.length` counts UTF-16 code units, so a CJK file reads a
17
+ * third of its UTF-8 weight and an emoji half of it; every byte budget between here and the
18
+ * sandbox counts UTF-8, so this one does too.
19
+ *
20
+ * 4 MiB is agent-runtime's SPAWN_RESOURCE_PATH_MAX_BYTES (0.239.0) — the largest file the runtime
21
+ * will read off a manager's own disk for a by-path spawn resource. Those resolved bytes arrive
22
+ * here as an inline string, so a smaller number would refuse by-path mounts the runtime had
23
+ * already accepted, and a larger one would advertise what the runtime will not resolve.
24
+ *
25
+ * The transport carries it: @tangle-network/sandbox splits inline `resources.files` out of the
26
+ * create POST and materializes them afterwards, routing any mount that no longer fits a
27
+ * gateway-safe single-shot write — SANDBOX_PROXY_REQUEST_MAX_BYTES (1 MiB) less 8 KiB of request
28
+ * envelope — onto chunked upload, whose session ceiling is 64 MiB. A 4 MiB mount is delivered in
29
+ * parts, so the 1 MiB request budget on `files/write-batch` never bites.
30
+ */
31
+ export declare const MAX_PAYLOAD_STRING_BYTES: number;
32
+ /**
33
+ * Inline `tools`, `agents`, `commands` and `instructions` are NOT split out: they ride the create
34
+ * POST whole, and inline `skills` ride the one-shot profile-priming POST. Both are single request
35
+ * bodies under the gateway's 1 MiB cap, so their TOTAL is the bound that binds, and it is the same
36
+ * budget the sandbox client keeps for a single-shot write: 1 MiB less 8 KiB of envelope. Necessary
37
+ * rather than sufficient — the rest of the create body shares that request and the gateway stays
38
+ * the authority — so a resource too large for it belongs in `resources.files`.
39
+ *
40
+ * `commands` is bounded here as payload although agent-runtime's by-path resolver covers only
41
+ * `tools`, `skills`, `agents` and `files`. The request that carries a command resource is the one
42
+ * that carries the others, and leaving `commands` on the control-plane bound would refuse an 18 KiB
43
+ * command for no transport reason. Anything the resolver gains later needs no change here.
44
+ */
45
+ export declare const MAX_INLINE_PAYLOAD_BYTES: number;
46
+ /**
47
+ * A per-string bound multiplies: MAX_ARRAY_LENGTH mounts at MAX_PAYLOAD_STRING_BYTES is 4 GiB, and
48
+ * `create` structuredClones and deep-freezes the whole input before the client sees it. The
49
+ * aggregate stops at the 64 MiB this module already accepts for one exact-process file, which is
50
+ * also the sandbox's chunked-upload session ceiling.
51
+ */
52
+ export declare const MAX_TOTAL_PAYLOAD_BYTES: number;
9
53
  export declare const MAX_ARRAY_LENGTH = 1024;
10
54
  export declare const MAX_MAP_ENTRIES = 256;
11
55
  export declare const MAX_JSON_DEPTH = 16;
@@ -16,7 +60,7 @@ export declare function boundedString(value: unknown, label: string): string;
16
60
  * The rule a value broke. Only the rules that COUNT something carry a limit; the rest are shape
17
61
  * rejections, where nothing is oversized and saying so misdirects the reader.
18
62
  */
19
- export type JsonBoundRule = "string" | "array" | "entries" | "depth" | "nodes" | "key" | "undefined" | "number" | "type" | "cycle" | "prototype";
63
+ export type JsonBoundRule = "string" | "payload" | "inlinePayload" | "totalPayload" | "array" | "entries" | "depth" | "nodes" | "key" | "undefined" | "number" | "type" | "cycle" | "prototype";
20
64
  export interface JsonBoundViolation {
21
65
  readonly rule: JsonBoundRule;
22
66
  /** Object keys and array indices only. A path locates the value; it never carries one. */
@@ -29,6 +73,20 @@ export interface JsonBoundViolation {
29
73
  /** A JavaScript type or constructor name — program text, not payload. */
30
74
  readonly observedType?: string;
31
75
  }
76
+ /**
77
+ * Where an AgentProfile sits inside the value being walked, as a key path from its root.
78
+ *
79
+ * Payload is classified by POSITION, never by a flag on the call: the same shape reached through
80
+ * `metadata` is control-plane text and keeps MAX_STRING_LENGTH. Omit it and a value has no payload
81
+ * at all, which is what every non-profile call site wants.
82
+ */
83
+ export type ProfileLocation = readonly string[];
84
+ /** The value IS the profile — `assertBoundedJson(input.profile, ...)`. */
85
+ export declare const PROFILE_AT_ROOT: ProfileLocation;
86
+ /** A wrapper whose `profile` key holds it — the per-turn backend override. */
87
+ export declare const PROFILE_AT_PROFILE: ProfileLocation;
88
+ /** The mapped Sandbox create options, where it rides `backend.profile`. */
89
+ export declare const PROFILE_AT_BACKEND_PROFILE: ProfileLocation;
32
90
  /**
33
91
  * The first bound `value` breaks, in document order, or undefined when it breaks none.
34
92
  *
@@ -37,8 +95,8 @@ export interface JsonBoundViolation {
37
95
  * stack happened to hold last would be a new way to mislead. Only the first violation is
38
96
  * reported — later ones may exist.
39
97
  */
40
- export declare function firstJsonBoundViolation(value: unknown): JsonBoundViolation | undefined;
41
- export declare function isBoundedJson(value: unknown): boolean;
98
+ export declare function firstJsonBoundViolation(value: unknown, profileAt?: ProfileLocation): JsonBoundViolation | undefined;
99
+ export declare function isBoundedJson(value: unknown, profileAt?: ProfileLocation): boolean;
42
100
  /**
43
101
  * One line naming the rule, where it broke, what was measured, and the limit — and never the
44
102
  * value. Profile and metadata strings carry prompt text, mounted briefs, and through `env`,
@@ -71,7 +129,7 @@ export declare class JsonBoundError extends Error {
71
129
  readonly violation: JsonBoundViolation;
72
130
  constructor(label: string, violation: JsonBoundViolation, message: string);
73
131
  }
74
- export declare function assertBoundedJson(value: unknown, label?: string): void;
132
+ export declare function assertBoundedJson(value: unknown, label?: string, profileAt?: ProfileLocation): void;
75
133
  /** Keep a late-created provider handle reachable when an abort wins the race. */
76
134
  export declare function attachCleanupHandle(error: unknown, handle: unknown, cleanupError?: unknown): void;
77
135
  export declare function exactProcessRequestDigest(input: CreateAgentExactProcessEnvironmentInput, providerName: string, options: TangleExactProcessOptions): `sha256:${string}`;
@@ -5,6 +5,50 @@ export const MAX_LIST_RESULTS = 100_000;
5
5
  export const SANDBOX_LIST_PAGE_SIZE = 1_000;
6
6
  export const MAX_IDENTIFIER_LENGTH = 512;
7
7
  export const MAX_STRING_LENGTH = 16_384;
8
+ /**
9
+ * MAX_STRING_LENGTH governs CONTROL-PLANE text — names, identifiers, env values, metadata — where
10
+ * 16 KiB is already generous. It must not govern DATA. The contents of file mounts and of inline
11
+ * profile resources are the product's cargo, and one bound for both refused a 17,894-character
12
+ * script AFTER spawn_worker had returned a worker id, so the caller paid for the spawn and got a
13
+ * child it could not equip (agent-sdk#340).
14
+ *
15
+ * Payload is measured in BYTES. `String.length` counts UTF-16 code units, so a CJK file reads a
16
+ * third of its UTF-8 weight and an emoji half of it; every byte budget between here and the
17
+ * sandbox counts UTF-8, so this one does too.
18
+ *
19
+ * 4 MiB is agent-runtime's SPAWN_RESOURCE_PATH_MAX_BYTES (0.239.0) — the largest file the runtime
20
+ * will read off a manager's own disk for a by-path spawn resource. Those resolved bytes arrive
21
+ * here as an inline string, so a smaller number would refuse by-path mounts the runtime had
22
+ * already accepted, and a larger one would advertise what the runtime will not resolve.
23
+ *
24
+ * The transport carries it: @tangle-network/sandbox splits inline `resources.files` out of the
25
+ * create POST and materializes them afterwards, routing any mount that no longer fits a
26
+ * gateway-safe single-shot write — SANDBOX_PROXY_REQUEST_MAX_BYTES (1 MiB) less 8 KiB of request
27
+ * envelope — onto chunked upload, whose session ceiling is 64 MiB. A 4 MiB mount is delivered in
28
+ * parts, so the 1 MiB request budget on `files/write-batch` never bites.
29
+ */
30
+ export const MAX_PAYLOAD_STRING_BYTES = 4 * 1024 * 1024;
31
+ /**
32
+ * Inline `tools`, `agents`, `commands` and `instructions` are NOT split out: they ride the create
33
+ * POST whole, and inline `skills` ride the one-shot profile-priming POST. Both are single request
34
+ * bodies under the gateway's 1 MiB cap, so their TOTAL is the bound that binds, and it is the same
35
+ * budget the sandbox client keeps for a single-shot write: 1 MiB less 8 KiB of envelope. Necessary
36
+ * rather than sufficient — the rest of the create body shares that request and the gateway stays
37
+ * the authority — so a resource too large for it belongs in `resources.files`.
38
+ *
39
+ * `commands` is bounded here as payload although agent-runtime's by-path resolver covers only
40
+ * `tools`, `skills`, `agents` and `files`. The request that carries a command resource is the one
41
+ * that carries the others, and leaving `commands` on the control-plane bound would refuse an 18 KiB
42
+ * command for no transport reason. Anything the resolver gains later needs no change here.
43
+ */
44
+ export const MAX_INLINE_PAYLOAD_BYTES = 1024 * 1024 - 8 * 1024;
45
+ /**
46
+ * A per-string bound multiplies: MAX_ARRAY_LENGTH mounts at MAX_PAYLOAD_STRING_BYTES is 4 GiB, and
47
+ * `create` structuredClones and deep-freezes the whole input before the client sees it. The
48
+ * aggregate stops at the 64 MiB this module already accepts for one exact-process file, which is
49
+ * also the sandbox's chunked-upload session ceiling.
50
+ */
51
+ export const MAX_TOTAL_PAYLOAD_BYTES = 64 * 1024 * 1024;
8
52
  export const MAX_ARRAY_LENGTH = 1_024;
9
53
  export const MAX_MAP_ENTRIES = 256;
10
54
  export const MAX_JSON_DEPTH = 16;
@@ -22,6 +66,57 @@ export function boundedString(value, label) {
22
66
  }
23
67
  return value;
24
68
  }
69
+ /** The value IS the profile — `assertBoundedJson(input.profile, ...)`. */
70
+ export const PROFILE_AT_ROOT = [];
71
+ /** A wrapper whose `profile` key holds it — the per-turn backend override. */
72
+ export const PROFILE_AT_PROFILE = ["profile"];
73
+ /** The mapped Sandbox create options, where it rides `backend.profile`. */
74
+ export const PROFILE_AT_BACKEND_PROFILE = ["backend", "profile"];
75
+ const INLINE_RESOURCE_FIELDS = new Set(["tools", "skills", "agents", "commands"]);
76
+ function childScope(scope, key) {
77
+ if (scope === undefined)
78
+ return undefined;
79
+ switch (scope.kind) {
80
+ case "descend": {
81
+ if (key !== scope.remaining[0])
82
+ return undefined;
83
+ const remaining = scope.remaining.slice(1);
84
+ return remaining.length === 0 ? { kind: "profile" } : { kind: "descend", remaining };
85
+ }
86
+ case "profile":
87
+ return key === "resources" ? { kind: "resources" } : undefined;
88
+ case "resources":
89
+ if (key === "files")
90
+ return { kind: "fileList" };
91
+ if (key === "instructions")
92
+ return { kind: "ref", payload: "inline", bare: true };
93
+ return typeof key === "string" && INLINE_RESOURCE_FIELDS.has(key)
94
+ ? { kind: "inlineList" }
95
+ : undefined;
96
+ case "fileList":
97
+ return typeof key === "number" ? { kind: "fileMount" } : undefined;
98
+ case "fileMount":
99
+ return key === "resource" ? { kind: "ref", payload: "file", bare: false } : undefined;
100
+ case "inlineList":
101
+ return typeof key === "number" ? { kind: "ref", payload: "inline", bare: false } : undefined;
102
+ case "ref":
103
+ return key === "content" ? { kind: "payload", payload: scope.payload } : undefined;
104
+ case "payload":
105
+ return undefined;
106
+ }
107
+ }
108
+ function payloadClassOf(scope) {
109
+ if (scope === undefined)
110
+ return undefined;
111
+ if (scope.kind === "payload")
112
+ return scope.payload;
113
+ return scope.kind === "ref" && scope.bare ? scope.payload : undefined;
114
+ }
115
+ function rootScope(profileAt) {
116
+ if (profileAt === undefined)
117
+ return undefined;
118
+ return profileAt.length === 0 ? { kind: "profile" } : { kind: "descend", remaining: profileAt };
119
+ }
25
120
  /** A key or constructor name is author-chosen program text, so echoing it discloses nothing. It
26
121
  * can still be long enough to turn a one-line reason into a dump, or carry a control character
27
122
  * that breaks the line a journal writes it on. */
@@ -51,12 +146,12 @@ function safeTypeName(value) {
51
146
  * stack happened to hold last would be a new way to mislead. Only the first violation is
52
147
  * reported — later ones may exist.
53
148
  */
54
- export function firstJsonBoundViolation(value) {
55
- const pending = [
56
- { value, depth: 0, path: "" },
57
- ];
149
+ export function firstJsonBoundViolation(value, profileAt) {
150
+ const pending = [{ value, depth: 0, path: "", scope: rootScope(profileAt) }];
58
151
  const ancestors = new Set();
59
152
  let nodes = 0;
153
+ let payloadBytes = 0;
154
+ let inlineBytes = 0;
60
155
  while (pending.length > 0) {
61
156
  const item = pending.pop();
62
157
  if (!item)
@@ -75,8 +170,28 @@ export function firstJsonBoundViolation(value) {
75
170
  if (current === null || typeof current === "boolean")
76
171
  continue;
77
172
  if (typeof current === "string") {
78
- if (current.length > MAX_STRING_LENGTH) {
79
- return { rule: "string", path: item.path, observed: current.length, limit: MAX_STRING_LENGTH, limitName: "MAX_STRING_LENGTH" };
173
+ const payload = payloadClassOf(item.scope);
174
+ if (payload === undefined) {
175
+ if (current.length > MAX_STRING_LENGTH) {
176
+ return { rule: "string", path: item.path, observed: current.length, limit: MAX_STRING_LENGTH, limitName: "MAX_STRING_LENGTH" };
177
+ }
178
+ continue;
179
+ }
180
+ const bytes = Buffer.byteLength(current, "utf8");
181
+ if (bytes > MAX_PAYLOAD_STRING_BYTES) {
182
+ return { rule: "payload", path: item.path, observed: bytes, limit: MAX_PAYLOAD_STRING_BYTES, limitName: "MAX_PAYLOAD_STRING_BYTES" };
183
+ }
184
+ // Totals accumulate in document order and are checked as they cross, so an oversized value
185
+ // is refused at the string that crossed the line rather than after the whole walk.
186
+ if (payload === "inline") {
187
+ inlineBytes += bytes;
188
+ if (inlineBytes > MAX_INLINE_PAYLOAD_BYTES) {
189
+ return { rule: "inlinePayload", path: item.path, observed: inlineBytes, limit: MAX_INLINE_PAYLOAD_BYTES, limitName: "MAX_INLINE_PAYLOAD_BYTES" };
190
+ }
191
+ }
192
+ payloadBytes += bytes;
193
+ if (payloadBytes > MAX_TOTAL_PAYLOAD_BYTES) {
194
+ return { rule: "totalPayload", path: item.path, observed: payloadBytes, limit: MAX_TOTAL_PAYLOAD_BYTES, limitName: "MAX_TOTAL_PAYLOAD_BYTES" };
80
195
  }
81
196
  continue;
82
197
  }
@@ -94,13 +209,18 @@ export function firstJsonBoundViolation(value) {
94
209
  if (ancestors.has(current))
95
210
  return { rule: "cycle", path: item.path };
96
211
  ancestors.add(current);
97
- pending.push({ value: current, depth: item.depth, path: item.path, leave: true });
212
+ pending.push({ value: current, depth: item.depth, path: item.path, scope: item.scope, leave: true });
98
213
  if (Array.isArray(current)) {
99
214
  if (current.length > MAX_ARRAY_LENGTH) {
100
215
  return { rule: "array", path: item.path, observed: current.length, limit: MAX_ARRAY_LENGTH, limitName: "MAX_ARRAY_LENGTH" };
101
216
  }
102
217
  for (let index = current.length - 1; index >= 0; index -= 1) {
103
- pending.push({ value: current[index], depth: item.depth + 1, path: `${item.path}[${index}]` });
218
+ pending.push({
219
+ value: current[index],
220
+ depth: item.depth + 1,
221
+ path: `${item.path}[${index}]`,
222
+ scope: childScope(item.scope, index),
223
+ });
104
224
  }
105
225
  continue;
106
226
  }
@@ -129,13 +249,14 @@ export function firstJsonBoundViolation(value) {
129
249
  value: current[keys[index]],
130
250
  depth: item.depth + 1,
131
251
  path: appendKeyToPath(item.path, keys[index]),
252
+ scope: childScope(item.scope, keys[index]),
132
253
  });
133
254
  }
134
255
  }
135
256
  return undefined;
136
257
  }
137
- export function isBoundedJson(value) {
138
- return firstJsonBoundViolation(value) === undefined;
258
+ export function isBoundedJson(value, profileAt) {
259
+ return firstJsonBoundViolation(value, profileAt) === undefined;
139
260
  }
140
261
  /**
141
262
  * One line naming the rule, where it broke, what was measured, and the limit — and never the
@@ -154,6 +275,12 @@ export function describeJsonBoundViolation(violation) {
154
275
  switch (violation.rule) {
155
276
  case "string":
156
277
  return `string at ${at} is ${violation.observed} characters, ${limit}`;
278
+ case "payload":
279
+ return `payload at ${at} is ${violation.observed} bytes, ${limit}; split it or fetch it from inside the environment`;
280
+ case "inlinePayload":
281
+ return `inline profile resources total ${violation.observed} bytes at ${at}, ${limit}; they ride one create request, so move the large ones to resources.files`;
282
+ case "totalPayload":
283
+ return `profile payload totals ${violation.observed} bytes at ${at}, ${limit}; split it across turns`;
157
284
  case "array":
158
285
  return `array at ${at} has ${violation.observed} entries, ${limit}`;
159
286
  case "entries":
@@ -210,8 +337,8 @@ export class JsonBoundError extends Error {
210
337
  this.violation = violation;
211
338
  }
212
339
  }
213
- export function assertBoundedJson(value, label = "value") {
214
- const violation = firstJsonBoundViolation(value);
340
+ export function assertBoundedJson(value, label = "value", profileAt) {
341
+ const violation = firstJsonBoundViolation(value, profileAt);
215
342
  if (violation === undefined)
216
343
  return;
217
344
  // A rule with no limit counted nothing: a Date, a cycle, a NaN and an absent value are not
@@ -3,6 +3,16 @@ import type { CreateAgentEnvironmentInput, WorkspaceRequest } from "@tangle-netw
3
3
  import type { TangleProviderOptions } from "./tangle-types.js";
4
4
  export declare function captureModelCredentials(value: TangleProviderOptions["modelCredentials"]): TangleProviderOptions["modelCredentials"];
5
5
  export declare function sandboxOptionsFromCreateInput(input: CreateAgentEnvironmentInput, defaultBackend?: BackendType, parsedWorkspace?: WorkspaceRequest, modelCredentials?: TangleProviderOptions["modelCredentials"]): CreateSandboxOptions;
6
+ /**
7
+ * Project a portable workspace checkpoint onto the Sandbox restore fields.
8
+ *
9
+ * A Tangle checkpoint is a snapshot of its source box, and Sandbox names a snapshot by the pair
10
+ * (snapshot id, source box id). The source box may already be deleted.
11
+ */
12
+ export declare function sandboxRestoreFromCheckpoint(checkpoint: WorkspaceRequest["checkpoint"]): {
13
+ fromSnapshot: string;
14
+ fromSandboxId: string;
15
+ } | undefined;
6
16
  /** Reject value-bearing secret maps before any custom mapper can drop them. */
7
17
  export declare function assertNoInlineSecretValues(input: CreateAgentEnvironmentInput, parsedWorkspace?: WorkspaceRequest): void;
8
18
  /** A custom mapper must not smuggle a value map into the Sandbox request. */
@@ -1,6 +1,6 @@
1
1
  import { parseBackendType, } from "@tangle-network/sandbox";
2
2
  import { AgentEnvironmentEgressPolicySchema, WorkspaceRequestSchema, workspaceCwdPathForBase, } from "@tangle-network/agent-interface/environment-provider";
3
- import { assertBoundedJson, boundedIdentifier, boundedString, MAX_ARRAY_LENGTH, MAX_MAP_ENTRIES, } from "./tangle-contract-safety.js";
3
+ import { assertBoundedJson, boundedIdentifier, boundedString, MAX_ARRAY_LENGTH, MAX_MAP_ENTRIES, PROFILE_AT_BACKEND_PROFILE, PROFILE_AT_ROOT, } from "./tangle-contract-safety.js";
4
4
  import { sandboxResourcesFromResourceRequest } from "./tangle-resources.js";
5
5
  import { tangleRuntimeAttachments } from "./tangle-runtime-attachments.js";
6
6
  export function captureModelCredentials(value) {
@@ -61,6 +61,7 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
61
61
  throw new Error("Tangle workspace providerOptions are not supported");
62
62
  }
63
63
  const workspaceCwd = workspaceCwdPathForBase(workspace.cwd, "repository", "Tangle");
64
+ const restore = sandboxRestoreFromCheckpoint(workspace.checkpoint);
64
65
  if (input.resources?.providerOptions && Object.keys(input.resources.providerOptions).length > 0) {
65
66
  throw new Error("Tangle resource providerOptions are not supported");
66
67
  }
@@ -91,6 +92,7 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
91
92
  }
92
93
  : {}),
93
94
  ...(resources ? { resources } : {}),
95
+ ...(restore ?? {}),
94
96
  ...(input.env ? { env: input.env } : {}),
95
97
  ...(Array.isArray(input.secrets) ? { secrets: input.secrets } : {}),
96
98
  ...(input.egress === undefined ? {} : { egressPolicy: sandboxEgressPolicy(input.egress) }),
@@ -110,6 +112,20 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
110
112
  };
111
113
  return mapped;
112
114
  }
115
+ /**
116
+ * Project a portable workspace checkpoint onto the Sandbox restore fields.
117
+ *
118
+ * A Tangle checkpoint is a snapshot of its source box, and Sandbox names a snapshot by the pair
119
+ * (snapshot id, source box id). The source box may already be deleted.
120
+ */
121
+ export function sandboxRestoreFromCheckpoint(checkpoint) {
122
+ if (checkpoint === undefined)
123
+ return undefined;
124
+ return {
125
+ fromSnapshot: boundedIdentifier(checkpoint.checkpointId, "Tangle workspace checkpoint id"),
126
+ fromSandboxId: boundedIdentifier(checkpoint.source.environmentId, "Tangle workspace checkpoint source"),
127
+ };
128
+ }
113
129
  /**
114
130
  * Project the portable egress policy onto the Sandbox policy.
115
131
  *
@@ -215,7 +231,7 @@ export function assertCreateInputShape(input, parsedWorkspace) {
215
231
  if (!input.profile || typeof input.profile !== "object" || Array.isArray(input.profile)) {
216
232
  throw new Error("Tangle profile must be an object or bounded reference");
217
233
  }
218
- assertBoundedJson(input.profile, "Tangle create profile");
234
+ assertBoundedJson(input.profile, "Tangle create profile", PROFILE_AT_ROOT);
219
235
  }
220
236
  if (input.resources !== undefined) {
221
237
  if (!input.resources || typeof input.resources !== "object" || Array.isArray(input.resources)) {
@@ -237,7 +253,7 @@ export function assertMappedCreateOptions(options) {
237
253
  if (!options || typeof options !== "object" || Array.isArray(options)) {
238
254
  throw new Error("Tangle mapped create options must be an object");
239
255
  }
240
- assertBoundedJson(options, "Tangle mapped create options");
256
+ assertBoundedJson(options, "Tangle mapped create options", PROFILE_AT_BACKEND_PROFILE);
241
257
  if (options.backend?.runtimeAttachments !== undefined) {
242
258
  tangleRuntimeAttachments(options.backend.runtimeAttachments, options.backend.profile);
243
259
  }
@@ -289,7 +305,7 @@ function inlineAgentProfile(profile) {
289
305
  if (!profile || typeof profile !== "object" || Array.isArray(profile)) {
290
306
  throw new Error("Tangle inline AgentProfile must be an object");
291
307
  }
292
- assertBoundedJson(profile, "Tangle inline AgentProfile");
308
+ assertBoundedJson(profile, "Tangle inline AgentProfile", PROFILE_AT_ROOT);
293
309
  return profile;
294
310
  }
295
311
  function assertBoundedRecord(value, label) {
@@ -1,6 +1,6 @@
1
1
  import { agentProfileSchema, CONTRACT_MAX_JSON_BYTES, boundedEventContentRecordSchema, isBoundedEventContentJson, AgentExactRunControlRefSchema, AgentTurnInputSchema, ContextTransferReceiptSchema, contextTransferResultMatchesRequest, } from "@tangle-network/agent-interface";
2
2
  import { tokenUsageFromData } from "./tangle-result-values.js";
3
- import { assertBoundedJson, boundedString } from "./tangle-contract-safety.js";
3
+ import { assertBoundedJson, boundedString, PROFILE_AT_PROFILE, } from "./tangle-contract-safety.js";
4
4
  import { tangleRuntimeAttachments } from "./tangle-runtime-attachments.js";
5
5
  export function promptFromTurnInput(input) {
6
6
  AgentTurnInputSchema.parse(input);
@@ -145,7 +145,7 @@ function sandboxPromptBackend(value) {
145
145
  runtimeAttachments: tangleRuntimeAttachments(present.runtimeAttachments, backend.profile),
146
146
  });
147
147
  }
148
- assertBoundedJson(backend, "Tangle prompt backend");
148
+ assertBoundedJson(backend, "Tangle prompt backend", PROFILE_AT_PROFILE);
149
149
  return backend;
150
150
  }
151
151
  function sandboxPromptBackendModel(value) {
@@ -4,11 +4,11 @@ import { createTangleExactProcessProvider, } from "./exact-process.js";
4
4
  import { capabilitiesForClient, defaultTangleSandboxCapabilities, narrowTangleCapabilitiesToBackend, } from "./tangle-capabilities.js";
5
5
  import { sandboxInstanceAsEnvironment } from "./tangle-environment.js";
6
6
  import { confidentialVerifierOption, createTangleWorkspaceBranching, } from "./tangle-workspace-branching.js";
7
- import { assertCreateInputShape, assertMappedCreateOptions, assertMappedSecretNames, assertNoInlineSecretValues, captureModelCredentials, sandboxOptionsFromCreateInput } from "./tangle-create-options.js";
7
+ import { assertCreateInputShape, assertMappedCreateOptions, assertMappedSecretNames, assertNoInlineSecretValues, captureModelCredentials, sandboxOptionsFromCreateInput, sandboxRestoreFromCheckpoint } from "./tangle-create-options.js";
8
8
  import { statusFromUnknown } from "./tangle-environment-values.js";
9
9
  import { awaitSandboxRunning, DEFAULT_TANGLE_READY_TIMEOUT_MS, } from "./tangle-readiness.js";
10
10
  import { requestedResourceProfile } from "./tangle-resources.js";
11
- import { assertBoundedJson, attachCleanupHandle, awaitWithSignal, boundedIdentifier, boundedString, MAX_LIST_RESULTS, SANDBOX_LIST_PAGE_SIZE, } from "./tangle-contract-safety.js";
11
+ import { assertBoundedJson, attachCleanupHandle, awaitWithSignal, boundedIdentifier, boundedString, MAX_LIST_RESULTS, PROFILE_AT_ROOT, SANDBOX_LIST_PAGE_SIZE, } from "./tangle-contract-safety.js";
12
12
  export function createTangleProvider(options) {
13
13
  const modelCredentials = captureModelCredentials(options.modelCredentials);
14
14
  const mapCreateInput = options.mapCreateInput;
@@ -71,6 +71,22 @@ export function createTangleProvider(options) {
71
71
  throw new Error("Tangle mapped create options must preserve input idempotencyKey");
72
72
  }
73
73
  assertMappedSecretNames(createOptions);
74
+ const checkpoint = parsedWorkspace?.checkpoint;
75
+ if (checkpoint !== undefined) {
76
+ // A checkpoint names a snapshot this provider took. Another provider's id means nothing to
77
+ // Sandbox, and a mapper that drops the restore would return an empty workspace as if full.
78
+ if (checkpoint.provider !== providerName) {
79
+ throw new Error(`Tangle cannot restore a workspace checkpoint taken by provider "${checkpoint.provider}"`);
80
+ }
81
+ const restore = sandboxRestoreFromCheckpoint(checkpoint);
82
+ if (createOptions.fromSnapshot !== restore?.fromSnapshot ||
83
+ createOptions.fromSandboxId !== restore?.fromSandboxId) {
84
+ throw new Error("Tangle mapped create options must preserve the workspace checkpoint");
85
+ }
86
+ }
87
+ else if (createOptions.fromSnapshot !== undefined || createOptions.fromSandboxId !== undefined) {
88
+ throw new Error("Tangle mapped create options restore a snapshot the create input did not name");
89
+ }
74
90
  if (input.runtimeAttachments !== undefined &&
75
91
  (createOptions.backend?.runtimeAttachments === undefined ||
76
92
  canonicalCandidateDigest(input.runtimeAttachments) !== canonicalCandidateDigest(createOptions.backend.runtimeAttachments))) {
@@ -80,6 +96,9 @@ export function createTangleProvider(options) {
80
96
  // default cannot describe a sandbox that this projection routes elsewhere.
81
97
  const declaredCapabilities = await resolveDeclaredCapabilities(createOptions.backend?.type);
82
98
  narrowedProviderCapabilities(declaredCapabilities);
99
+ if (checkpoint !== undefined && declaredCapabilities.create?.workspaceCheckpoint !== true) {
100
+ throw new Error("Tangle workspace checkpoint restore is not supported by the declared capabilities");
101
+ }
83
102
  if (createOptions.backend?.runtimeAttachments !== undefined) {
84
103
  if (createOptions.backend.type === undefined || declaredCapabilities.create?.runtimeAttachments?.mcp !== true) {
85
104
  throw new Error("Tangle runtime attachments are not supported by the selected backend deployment");
@@ -178,8 +197,11 @@ export function createTangleProvider(options) {
178
197
  assertCreateInputShape(input);
179
198
  assertNoInlineSecretValues(input);
180
199
  for (const [field, value] of Object.entries(material)) {
181
- if (value !== undefined)
182
- assertBoundedJson(value, `Tangle create ${field}`);
200
+ if (value === undefined)
201
+ continue;
202
+ // Only `profile` carries payload. Every other create field is control-plane text, and a
203
+ // profile-shaped value smuggled through one of them stays on MAX_STRING_LENGTH.
204
+ assertBoundedJson(value, `Tangle create ${field}`, field === "profile" ? PROFILE_AT_ROOT : undefined);
183
205
  }
184
206
  const acceptedInput = Object.freeze({
185
207
  ...deepFreeze(structuredClone(material)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-tangle",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -99,7 +99,7 @@
99
99
  "LICENSE"
100
100
  ],
101
101
  "dependencies": {
102
- "@tangle-network/agent-interface": "^2.8.0"
102
+ "@tangle-network/agent-interface": "^2.13.0"
103
103
  },
104
104
  "peerDependencies": {
105
105
  "@tangle-network/sandbox": ">=0.39.0 <1.0.0"
@@ -110,8 +110,8 @@
110
110
  }
111
111
  },
112
112
  "devDependencies": {
113
- "@tangle-network/agent-eval": "0.173.1",
114
- "@tangle-network/agent-runtime": "0.192.2",
113
+ "@tangle-network/agent-eval": "0.182.0",
114
+ "@tangle-network/agent-runtime": "0.231.1",
115
115
  "@tangle-network/sandbox": "0.39.0",
116
116
  "@types/node": "26.4.1",
117
117
  "typescript": "7.0.2",