@tangle-network/agent-provider-tangle 1.4.0 → 1.6.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,4 +1,6 @@
1
1
  export type { TangleExactProcessOptions } from "./tangle-types.js";
2
+ export { JsonBoundError, MAX_INLINE_PAYLOAD_BYTES, MAX_PAYLOAD_STRING_BYTES, MAX_TOTAL_PAYLOAD_BYTES, } from "./tangle-contract-safety.js";
3
+ export type { JsonBoundRule, JsonBoundViolation } from "./tangle-contract-safety.js";
2
4
  export * from "./tangle-types.js";
3
5
  export { createTangleProvider } from "./tangle-provider.js";
4
6
  export { DEFAULT_TANGLE_READY_TIMEOUT_MS } from "./tangle-readiness.js";
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { JsonBoundError, MAX_INLINE_PAYLOAD_BYTES, MAX_PAYLOAD_STRING_BYTES, MAX_TOTAL_PAYLOAD_BYTES, } from "./tangle-contract-safety.js";
1
2
  export * from "./tangle-types.js";
2
3
  export { createTangleProvider } from "./tangle-provider.js";
3
4
  export { DEFAULT_TANGLE_READY_TIMEOUT_MS } from "./tangle-readiness.js";
@@ -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`,
@@ -52,7 +110,26 @@ export declare function describeJsonBoundViolation(violation: JsonBoundViolation
52
110
  * profile, the metadata, or a providerOptions map — which is how three children settled on five
53
111
  * words that identified nothing.
54
112
  */
55
- export declare function assertBoundedJson(value: unknown, label?: string): void;
113
+ /**
114
+ * A value refused by a JSON bound, as an error a consumer can classify without reading text.
115
+ *
116
+ * Every refusal in this package was a plain `Error` with a message, and the runtime that
117
+ * supervises these environments classifies a failed retained execution from the error's
118
+ * STRUCTURE — class name, `code`, status — never its message, because this package's messages
119
+ * are not a contract. So a bound refusal reached its journal under the one name reserved for an
120
+ * execution nobody can observe, telling the operator to reconcile before retrying when nothing
121
+ * had run and nothing needed reconciling (agent-runtime#1204, exhibit 6).
122
+ *
123
+ * `name` and `code` are stable; `message` stays the operator-facing line and may change. The
124
+ * violation is carried whole so a reader can act on the rule and the path without parsing.
125
+ */
126
+ export declare class JsonBoundError extends Error {
127
+ readonly code: "JSON_BOUND_VIOLATION";
128
+ readonly label: string;
129
+ readonly violation: JsonBoundViolation;
130
+ constructor(label: string, violation: JsonBoundViolation, message: string);
131
+ }
132
+ export declare function assertBoundedJson(value: unknown, label?: string, profileAt?: ProfileLocation): void;
56
133
  /** Keep a late-created provider handle reachable when an abort wins the race. */
57
134
  export declare function attachCleanupHandle(error: unknown, handle: unknown, cleanupError?: unknown): void;
58
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":
@@ -186,15 +313,39 @@ export function describeJsonBoundViolation(violation) {
186
313
  * profile, the metadata, or a providerOptions map — which is how three children settled on five
187
314
  * words that identified nothing.
188
315
  */
189
- export function assertBoundedJson(value, label = "value") {
190
- const violation = firstJsonBoundViolation(value);
316
+ /**
317
+ * A value refused by a JSON bound, as an error a consumer can classify without reading text.
318
+ *
319
+ * Every refusal in this package was a plain `Error` with a message, and the runtime that
320
+ * supervises these environments classifies a failed retained execution from the error's
321
+ * STRUCTURE — class name, `code`, status — never its message, because this package's messages
322
+ * are not a contract. So a bound refusal reached its journal under the one name reserved for an
323
+ * execution nobody can observe, telling the operator to reconcile before retrying when nothing
324
+ * had run and nothing needed reconciling (agent-runtime#1204, exhibit 6).
325
+ *
326
+ * `name` and `code` are stable; `message` stays the operator-facing line and may change. The
327
+ * violation is carried whole so a reader can act on the rule and the path without parsing.
328
+ */
329
+ export class JsonBoundError extends Error {
330
+ code = "JSON_BOUND_VIOLATION";
331
+ label;
332
+ violation;
333
+ constructor(label, violation, message) {
334
+ super(message);
335
+ this.name = "JsonBoundError";
336
+ this.label = label;
337
+ this.violation = violation;
338
+ }
339
+ }
340
+ export function assertBoundedJson(value, label = "value", profileAt) {
341
+ const violation = firstJsonBoundViolation(value, profileAt);
191
342
  if (violation === undefined)
192
343
  return;
193
344
  // A rule with no limit counted nothing: a Date, a cycle, a NaN and an absent value are not
194
345
  // oversized, and "exceeds" sends the reader after a size problem that does not exist.
195
346
  const verdict = violation.limit === undefined ? "violates" : "exceeds";
196
347
  const message = `${label} ${verdict} its JSON bound: ${describeJsonBoundViolation(violation)}`;
197
- throw new Error(message.length > MAX_BOUND_MESSAGE_LENGTH
348
+ throw new JsonBoundError(label, violation, message.length > MAX_BOUND_MESSAGE_LENGTH
198
349
  ? `${message.slice(0, MAX_BOUND_MESSAGE_LENGTH - 3)}...`
199
350
  : message);
200
351
  }
@@ -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) {
@@ -215,7 +215,7 @@ export function assertCreateInputShape(input, parsedWorkspace) {
215
215
  if (!input.profile || typeof input.profile !== "object" || Array.isArray(input.profile)) {
216
216
  throw new Error("Tangle profile must be an object or bounded reference");
217
217
  }
218
- assertBoundedJson(input.profile, "Tangle create profile");
218
+ assertBoundedJson(input.profile, "Tangle create profile", PROFILE_AT_ROOT);
219
219
  }
220
220
  if (input.resources !== undefined) {
221
221
  if (!input.resources || typeof input.resources !== "object" || Array.isArray(input.resources)) {
@@ -237,7 +237,7 @@ export function assertMappedCreateOptions(options) {
237
237
  if (!options || typeof options !== "object" || Array.isArray(options)) {
238
238
  throw new Error("Tangle mapped create options must be an object");
239
239
  }
240
- assertBoundedJson(options, "Tangle mapped create options");
240
+ assertBoundedJson(options, "Tangle mapped create options", PROFILE_AT_BACKEND_PROFILE);
241
241
  if (options.backend?.runtimeAttachments !== undefined) {
242
242
  tangleRuntimeAttachments(options.backend.runtimeAttachments, options.backend.profile);
243
243
  }
@@ -289,7 +289,7 @@ function inlineAgentProfile(profile) {
289
289
  if (!profile || typeof profile !== "object" || Array.isArray(profile)) {
290
290
  throw new Error("Tangle inline AgentProfile must be an object");
291
291
  }
292
- assertBoundedJson(profile, "Tangle inline AgentProfile");
292
+ assertBoundedJson(profile, "Tangle inline AgentProfile", PROFILE_AT_ROOT);
293
293
  return profile;
294
294
  }
295
295
  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) {
@@ -8,7 +8,7 @@ import { assertCreateInputShape, assertMappedCreateOptions, assertMappedSecretNa
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;
@@ -178,8 +178,11 @@ export function createTangleProvider(options) {
178
178
  assertCreateInputShape(input);
179
179
  assertNoInlineSecretValues(input);
180
180
  for (const [field, value] of Object.entries(material)) {
181
- if (value !== undefined)
182
- assertBoundedJson(value, `Tangle create ${field}`);
181
+ if (value === undefined)
182
+ continue;
183
+ // Only `profile` carries payload. Every other create field is control-plane text, and a
184
+ // profile-shaped value smuggled through one of them stays on MAX_STRING_LENGTH.
185
+ assertBoundedJson(value, `Tangle create ${field}`, field === "profile" ? PROFILE_AT_ROOT : undefined);
183
186
  }
184
187
  const acceptedInput = Object.freeze({
185
188
  ...deepFreeze(structuredClone(material)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-tangle",
3
- "version": "1.4.0",
3
+ "version": "1.6.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.10.0"
103
103
  },
104
104
  "peerDependencies": {
105
105
  "@tangle-network/sandbox": ">=0.39.0 <1.0.0"