@tangle-network/agent-provider-tangle 3.6.4 → 3.6.6

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/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # @tangle-network/agent-provider-tangle
2
2
 
3
3
  Wraps `@tangle-network/sandbox` as an `AgentEnvironmentProvider`.
4
- The Sandbox peer range is `>=0.58.7 <1.0.0`.
5
- The floor includes native credential reference validation, per-container capability parsing, and runtime MCP transport.
4
+ The Sandbox peer range is `>=0.60.27 <1.0.0`; the minimum version exports the shared terminal projection.
5
+
6
+ Terminal `result` and `done` events use the Sandbox SDK's `projectAgentTerminalRecord` summary. Cumulative tool history stays in native evidence; bounded approval identity survives projection, and malformed or conflicting approval sources fail closed. Terminal events omit the duplicate raw `providerEvent` payload.
7
+
8
+ Per-turn backend options use the SDK's `normalizeRuntimeBackendConfig` for current model/auth fields and turn-scoped `runtimeSecrets`. Unknown options remain rejected, and native credentials still require the exact profile's subscription intent. Retained request identity excludes credential values, matching Sandbox message admission; Sandbox separately keys the executing backend by secret values so rotation cannot reuse stale authority.
6
9
 
7
10
  Runtime MCP bindings travel through `CreateAgentEnvironmentInput.runtimeAttachments` to Sandbox's `backend.runtimeAttachments`.
8
11
  They remain separate from the authored profile and its digest.
@@ -12,6 +12,7 @@ export interface DeploymentCapabilitySupport {
12
12
  /** The selected runtime explicitly supports named native credential references. */
13
13
  readonly cliAuthReferences: boolean;
14
14
  readonly claudeTokenContinuations: boolean;
15
+ readonly codexCredentialContinuations: boolean;
15
16
  /**
16
17
  * Run requests carry the caller's exact `runControlRef`, and admission
17
18
  * echoes the executionId. Detached dispatch needs both: it sends the
@@ -11,6 +11,7 @@ import { awaitWithSignal } from "./tangle-contract-safety.js";
11
11
  export const UNPROVEN_DEPLOYMENT = {
12
12
  cliAuthReferences: false,
13
13
  claudeTokenContinuations: false,
14
+ codexCredentialContinuations: false,
14
15
  exactDispatch: false,
15
16
  canonicalCancellation: false,
16
17
  eventReplay: false,
@@ -36,6 +37,7 @@ export const UNPROVEN_DEPLOYMENT = {
36
37
  export const ADAPTER_CEILING_DEPLOYMENT = {
37
38
  cliAuthReferences: true,
38
39
  claudeTokenContinuations: true,
40
+ codexCredentialContinuations: true,
39
41
  exactDispatch: true,
40
42
  canonicalCancellation: true,
41
43
  eventReplay: true,
@@ -53,6 +55,7 @@ export function deploymentCapabilitySupport(document) {
53
55
  return {
54
56
  cliAuthReferences: document.cliAuthReferences === true,
55
57
  claudeTokenContinuations: document.claudeTokenContinuations === true,
58
+ codexCredentialContinuations: document.codexCredentialContinuations === true,
56
59
  exactDispatch: document.dispatch?.runControlRef === true &&
57
60
  document.dispatch?.executionIdOnAdmission === true,
58
61
  canonicalCancellation: document.cancel?.canonicalRunCancellation === true &&
@@ -146,13 +146,18 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
146
146
  let selectedReference = nativeReference;
147
147
  // Exact reads retain the admitted execution. A new operation obtains a new durable
148
148
  // account-owner binding; retries of that operation present the same key after restart.
149
- // Per-turn account selection exists for Claude setup tokens, whose named-grant continuation
150
- // Sandbox proves. Other harnesses keep the account selected at creation, whose admission
151
- // already covered the run deadline.
152
- if (!replay && request?.resolveModelCredentials !== undefined && harness === "claude-code") {
153
- if (!deployment.claudeTokenContinuations || box.grantNativeCredential === undefined ||
154
- nativeReference.format !== "token") {
155
- throw new Error("Tangle fresh subscription turns require proven Claude token continuation and named-grant support");
149
+ // Native subscription turns can change accounts only when the serving image proves
150
+ // a named grant that preserves this harness's private session HOME.
151
+ if (!replay && request?.resolveModelCredentials !== undefined &&
152
+ (harness === "claude-code" || harness === "codex")) {
153
+ const supported = harness === "claude-code"
154
+ ? deployment.claudeTokenContinuations && nativeReference.format === "token"
155
+ : deployment.codexCredentialContinuations &&
156
+ (nativeReference.format === "bundle" || nativeReference.format === "files");
157
+ if (!supported || box.grantNativeCredential === undefined) {
158
+ throw new Error(harness === "claude-code"
159
+ ? "Tangle fresh subscription turns require proven Claude token continuation and named-grant support"
160
+ : "Tangle fresh subscription turns require proven Codex credential continuation and named-grant support");
156
161
  }
157
162
  const profile = backend?.profile;
158
163
  if (profile === undefined || profileCredentialSource(profile) !== "subscription") {
@@ -173,8 +178,11 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
173
178
  }),
174
179
  ...(input.signal ? { signal: input.signal } : {}),
175
180
  }))), input.signal));
176
- if (selected === undefined || !("cliAuth" in selected) || selected.cliAuth.format !== "token") {
177
- throw new Error("Tangle subscription turn resolver must select a stored Claude token reference");
181
+ if (selected === undefined || !("cliAuth" in selected) ||
182
+ (harness === "claude-code"
183
+ ? selected.cliAuth.format !== "token"
184
+ : selected.cliAuth.format !== "bundle" && selected.cliAuth.format !== "files")) {
185
+ throw new Error(`Tangle subscription turn resolver must select a stored ${harness} native reference`);
178
186
  }
179
187
  selectedReference = selected.cliAuth;
180
188
  assertCliAuthReferenceSupported(harness, { ...model, cliAuth: selectedReference });
@@ -1,7 +1,7 @@
1
1
  import { CanonicalStreamEventSchema, boundedEventContentRecordSchema, } from "@tangle-network/agent-interface";
2
2
  import { optionalNonEmptyString } from "./tangle-environment-values.js";
3
3
  import { tokenUsageFromData } from "./tangle-result-values.js";
4
- import { sandboxTerminalProjection } from "./tangle-prompt.js";
4
+ import { projectAgentTerminalRecord } from "@tangle-network/sandbox/runtime";
5
5
  /** The sidecar sends this envelope when an SSE connection is ready. */
6
6
  export function isSandboxConnectionMarker(event) {
7
7
  if (!event || typeof event !== "object")
@@ -136,9 +136,8 @@ export function environmentEventFromSandboxEvent(event, expected = {}) {
136
136
  }
137
137
  const terminal = record.type === "result" || record.type === "done";
138
138
  const sourceData = record.data;
139
- const projected = terminal && Object.hasOwn(sourceData, "toolInvocations");
140
- const data = projected ? sandboxTerminalProjection(sourceData) : sourceData;
141
- assertBoundedRecord(projected ? { ...record, data } : record);
139
+ const data = terminal ? projectAgentTerminalRecord(sourceData) : sourceData;
140
+ assertBoundedRecord(terminal ? { ...record, data } : record);
142
141
  if (Object.prototype.hasOwnProperty.call(data, "contextTransferReceipt")) {
143
142
  throw new Error("Tangle Sandbox emitted an unsolicited context transfer receipt");
144
143
  }
@@ -195,7 +194,7 @@ export function environmentEventFromSandboxEvent(event, expected = {}) {
195
194
  ...(usageMode === undefined ? {} : { usageMode }),
196
195
  // A terminal projection is not the complete native event. The source is
197
196
  // available through exact session/execution evidence, including tool history.
198
- ...(!projected ? { providerEvent: event } : {}),
197
+ ...(!terminal ? { providerEvent: event } : {}),
199
198
  };
200
199
  }
201
200
  function normalizeSandboxEvent(type, data, identity) {
@@ -20,6 +20,8 @@ export interface PreparedNativeEvidence {
20
20
  directory?: string;
21
21
  remove(): Promise<void>;
22
22
  }
23
+ export declare const MAX_METADATA_BYTES: number;
24
+ export declare const MAX_RECORD_BYTES: number;
23
25
  /** Exact receipt validation is repeated while consuming, so a later local mutation fails capture. */
24
26
  export declare function nativePayloadChunks(directory: string, ref: NativePayloadFile, signal?: AbortSignal): AsyncIterable<Uint8Array>;
25
27
  /** The new route must never fall back to the legacy aggregate JSON request. */
@@ -5,8 +5,10 @@ import { tmpdir } from "node:os";
5
5
  import { join } from "node:path";
6
6
  import { EvidenceJsonArray } from "./tangle-evidence-json.js";
7
7
  const MAX_ENTRIES = 100_000;
8
- const MAX_METADATA_BYTES = 32 * 1024 * 1024;
9
- const MAX_RECORD_BYTES = 16 * 1024 * 1024;
8
+ // Match the shipped Sandbox archive reader: a valid producer manifest or NDJSON
9
+ // record must not be rejected after capture solely by this consumer's bound.
10
+ export const MAX_METADATA_BYTES = 64 * 1024 * 1024;
11
+ export const MAX_RECORD_BYTES = 16 * 1024 * 1024;
10
12
  function record(value) {
11
13
  if (!value || typeof value !== "object" || Array.isArray(value))
12
14
  throw new Error("Tangle native export metadata is malformed");
@@ -9,7 +9,7 @@ export declare function promptOptionsFromTurnInput(input: AgentTurnInput, target
9
9
  sessionId?: string;
10
10
  }): PromptOptions;
11
11
  /**
12
- * The `BackendConfig` fields the Sandbox prompt options declare.
12
+ * The `BackendConfig` fields this adapter forwards to Sandbox prompt options.
13
13
  *
14
14
  * A turn may carry any of them and nothing else. An undeclared field is
15
15
  * refused instead of forwarded, because the SDK drops what it does not
@@ -17,7 +17,7 @@ export declare function promptOptionsFromTurnInput(input: AgentTurnInput, target
17
17
  * anywhere, which is the silent substitution the SDK's own `model` field
18
18
  * exists to prevent.
19
19
  */
20
- declare const SANDBOX_BACKEND_FIELD_LIST: readonly ["runtimeAttachments", "type", "profile", "model", "server", "interactions", "metadata"];
20
+ declare const SANDBOX_BACKEND_FIELD_LIST: readonly ["runtimeAttachments", "runtimeSecrets", "modelId", "provider", "apiKey", "baseUrl", "maxThinkingTokens", "mode", "apiKeyEnv", "cliAuth", "authMode", "authFiles", "type", "profile", "model", "server", "interactions", "metadata"];
21
21
  /**
22
22
  * The `BackendConfig["model"]` fields the Sandbox prompt options declare.
23
23
  *
@@ -27,7 +27,7 @@ declare const SANDBOX_BACKEND_FIELD_LIST: readonly ["runtimeAttachments", "type"
27
27
  */
28
28
  declare const SANDBOX_BACKEND_MODEL_FIELD_LIST: readonly ["provider", "model", "apiKey", "baseUrl", "maxThinkingTokens", "mode", "apiKeyEnv", "cliAuth", "authMode", "authFiles"];
29
29
  /**
30
- * The two lists above are the SDK's field sets, restated as values because a
30
+ * These lists cover the SDK's field sets, restated as values because a
31
31
  * TypeScript type cannot be read at run time. This pin keeps them exact in
32
32
  * both directions: a field the SDK adds, renames, or removes fails the build
33
33
  * here rather than reaching a caller as a wrong refusal or a silent drop.
@@ -82,12 +82,6 @@ type ValidatedSandboxPromptResult = Record<string, unknown> & {
82
82
  durationMs: number;
83
83
  executionId?: string;
84
84
  };
85
- /**
86
- * Completion is a bounded summary; cumulative tool history is retained separately.
87
- * The native session evidence owns the original arguments and outputs. Never
88
- * truncate that history or require the whole conversation to fit one event.
89
- */
90
- export declare function sandboxTerminalProjection(record: Record<string, unknown>): Record<string, unknown>;
91
85
  export declare function validatedSandboxPromptResult(result: PromptResult): ValidatedSandboxPromptResult;
92
86
  export declare function agentTurnResultFromPromptRecord(record: ValidatedSandboxPromptResult, options?: {
93
87
  contextTransferRequested?: boolean;
@@ -1,3 +1,5 @@
1
+ import { normalizeRuntimeBackendConfig } from "@tangle-network/sandbox";
2
+ import { projectAgentTerminalRecord } from "@tangle-network/sandbox/runtime";
1
3
  import { assertCliAuthReferenceSupported, cliAuthReferenceSchema, } from "@tangle-network/sandbox/auth";
2
4
  import { agentProfileSchema, canonicalAgentProfileDigest, boundedEventContentRecordSchema, AgentExactRunControlRefSchema, AgentTurnInputSchema, ContextTransferReceiptSchema, contextTransferResultMatchesRequest, } from "@tangle-network/agent-interface";
3
5
  import { tokenUsageFromData } from "./tangle-result-values.js";
@@ -61,7 +63,7 @@ export function promptOptionsFromTurnInput(input, target) {
61
63
  };
62
64
  }
63
65
  /**
64
- * The `BackendConfig` fields the Sandbox prompt options declare.
66
+ * The `BackendConfig` fields this adapter forwards to Sandbox prompt options.
65
67
  *
66
68
  * A turn may carry any of them and nothing else. An undeclared field is
67
69
  * refused instead of forwarded, because the SDK drops what it does not
@@ -71,6 +73,17 @@ export function promptOptionsFromTurnInput(input, target) {
71
73
  */
72
74
  const SANDBOX_BACKEND_FIELD_LIST = [
73
75
  "runtimeAttachments",
76
+ "runtimeSecrets",
77
+ "modelId",
78
+ "provider",
79
+ "apiKey",
80
+ "baseUrl",
81
+ "maxThinkingTokens",
82
+ "mode",
83
+ "apiKeyEnv",
84
+ "cliAuth",
85
+ "authMode",
86
+ "authFiles",
74
87
  "type",
75
88
  "profile",
76
89
  "model",
@@ -118,8 +131,18 @@ export function backendFromTurnProviderOptions(providerOptions) {
118
131
  return sandboxPromptBackend(providerOptions.backend);
119
132
  }
120
133
  function sandboxPromptBackend(value) {
121
- const present = plainRecord(value, "Tangle prompt backend options");
122
- assertDeclaredFields(present, SANDBOX_BACKEND_FIELDS, "Tangle prompt backend options");
134
+ const source = plainRecord(value, "Tangle prompt backend options");
135
+ assertDeclaredFields(source, SANDBOX_BACKEND_FIELDS, "Tangle prompt backend options");
136
+ // Normalization can omit falsy nested values or replace them with flat fields.
137
+ // Reject malformed declarations before that loses the caller's input.
138
+ for (const field of ["model", "server"]) {
139
+ if (source[field] !== undefined) {
140
+ plainRecord(source[field], `Tangle prompt backend ${field} options`);
141
+ }
142
+ }
143
+ const present = normalizeRuntimeBackendConfig(source, {
144
+ allowRuntimeSecrets: true,
145
+ }) ?? {};
123
146
  const backend = {
124
147
  ...(present.type === undefined
125
148
  ? {}
@@ -161,6 +184,9 @@ function sandboxPromptBackend(value) {
161
184
  }
162
185
  assertCliAuthReferenceSupported(backend.type, backend.model);
163
186
  }
187
+ if (present.runtimeSecrets !== undefined) {
188
+ Object.assign(backend, { runtimeSecrets: present.runtimeSecrets });
189
+ }
164
190
  if (present.runtimeAttachments !== undefined) {
165
191
  Object.assign(backend, {
166
192
  runtimeAttachments: tangleRuntimeAttachments(present.runtimeAttachments, backend.profile),
@@ -330,12 +356,16 @@ function plainRecord(value, label) {
330
356
  export function backendRequestIdentity(backend) {
331
357
  if (backend === undefined)
332
358
  return undefined;
333
- const model = backend.model;
359
+ const normalized = (normalizeRuntimeBackendConfig(backend, { allowRuntimeSecrets: true }) ?? {});
360
+ // Sandbox message admission omits turn-only credentials from request identity;
361
+ // the SDK/sidecar independently keys the executing backend by their values.
362
+ const { runtimeSecrets: _runtimeSecrets, ...identity } = normalized;
363
+ const model = normalized.model;
334
364
  if (model === undefined)
335
- return { ...backend };
365
+ return identity;
336
366
  const { apiKey: _apiKey, authFiles, ...rest } = model;
337
367
  return {
338
- ...backend,
368
+ ...identity,
339
369
  model: {
340
370
  ...rest,
341
371
  ...(authFiles === undefined
@@ -411,15 +441,6 @@ const SANDBOX_OPTIONAL_RESULT_FIELDS = new Set([
411
441
  "usage",
412
442
  "costUsd",
413
443
  ]);
414
- /**
415
- * Completion is a bounded summary; cumulative tool history is retained separately.
416
- * The native session evidence owns the original arguments and outputs. Never
417
- * truncate that history or require the whole conversation to fit one event.
418
- */
419
- export function sandboxTerminalProjection(record) {
420
- const { toolInvocations: _toolInvocations, ...terminal } = record;
421
- return terminal;
422
- }
423
444
  export function validatedSandboxPromptResult(result) {
424
445
  if (!result || typeof result !== "object" || Array.isArray(result)) {
425
446
  throw new Error("Tangle prompt returned no result object");
@@ -432,7 +453,7 @@ export function validatedSandboxPromptResult(result) {
432
453
  // The Sandbox SDK materializes absent optional response fields as
433
454
  // `undefined`. They were absent on the JSON wire and must stay absent in the
434
455
  // provider-neutral result before the strict JSON check runs.
435
- const record = sandboxTerminalProjection(Object.fromEntries(Object.entries(source).filter(([field, value]) => value !== undefined || !SANDBOX_OPTIONAL_RESULT_FIELDS.has(field))));
456
+ const record = projectAgentTerminalRecord(Object.fromEntries(Object.entries(source).filter(([field, value]) => value !== undefined || !SANDBOX_OPTIONAL_RESULT_FIELDS.has(field))));
436
457
  const content = boundedEventContentRecordSchema.safeParse(record);
437
458
  if (!content.success) {
438
459
  throw new Error("Tangle prompt result exceeded its JSON bound", { cause: content.error });
@@ -105,6 +105,7 @@ export interface SandboxRuntimeCapabilityDocument {
105
105
  /** The selected runtime resolves stored-secret native authentication references. */
106
106
  cliAuthReferences?: boolean;
107
107
  claudeTokenContinuations?: boolean;
108
+ codexCredentialContinuations?: boolean;
108
109
  nativeSessionCaptureVersion?: number;
109
110
  nativeSessionCaptureHarnesses?: readonly string[];
110
111
  agentInterface?: string;
@@ -427,7 +428,7 @@ export interface SandboxInstanceLike {
427
428
  }): SandboxSessionLike;
428
429
  /** Owner-authorized named grant; material never crosses this consumer boundary. */
429
430
  grantNativeCredential?(grant: {
430
- harness: "claude-code";
431
+ harness: "claude-code" | "codex";
431
432
  cliAuth: CliAuthReference;
432
433
  }, options?: {
433
434
  signal?: AbortSignal;
@@ -74,6 +74,17 @@ export function createTangleWorkspaceBranching(options) {
74
74
  return recovered;
75
75
  };
76
76
  /** The fork equivalent of {@link resolveCheckpoint}. */
77
+ const resolveLocalFork = (request) => {
78
+ const local = forks.get(request.idempotencyKey);
79
+ if (!local)
80
+ return { state: "absent" };
81
+ return local.request.requestDigest === request.requestDigest
82
+ ? { state: "known", record: local }
83
+ : {
84
+ state: "conflict",
85
+ existingRequestDigest: local.request.requestDigest,
86
+ };
87
+ };
77
88
  const resolveFork = async (request, signal) => {
78
89
  const local = forks.get(request.idempotencyKey);
79
90
  if (local) {
@@ -280,7 +291,15 @@ export function createTangleWorkspaceBranching(options) {
280
291
  typeof box.getTeeAttestation !== "function")) {
281
292
  return forkUnknown(request, "Confidential fork requires a trusted verifier and Sandbox attestation support", false);
282
293
  }
283
- const known = await resolveFork(request, operation?.signal);
294
+ // A key this handle has not recorded is created again with the same key: Sandbox applies the
295
+ // key and replays the child it already created for it. Searching the account for the key's
296
+ // child first paged every sandbox in the account, which timed out or repeated rows on an
297
+ // account with thousands of them, so a fork answered unknown (agent-sdk#439 removed the same
298
+ // scan from deleteCheckpoint). This provider cannot create a confidential fork, only recover
299
+ // one, so that request still searches; lookupFork does too, for a key it must recover.
300
+ const known = request.confidential?.requested === true
301
+ ? await resolveFork(request, operation?.signal)
302
+ : resolveLocalFork(request);
284
303
  if (known.state === "conflict") {
285
304
  return forkConflict(request, known.existingRequestDigest);
286
305
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-tangle",
3
- "version": "3.6.4",
3
+ "version": "3.6.6",
4
4
  "description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -131,7 +131,7 @@
131
131
  "@tangle-network/agent-interface": "^3.0.0"
132
132
  },
133
133
  "peerDependencies": {
134
- "@tangle-network/sandbox": ">=0.58.7 <1.0.0"
134
+ "@tangle-network/sandbox": ">=0.60.27 <1.0.0"
135
135
  },
136
136
  "peerDependenciesMeta": {
137
137
  "@tangle-network/sandbox": {
@@ -141,7 +141,7 @@
141
141
  "devDependencies": {
142
142
  "@tangle-network/agent-provider-testkit": "0.10.2",
143
143
  "@tangle-network/agent-runtime": "0.292.3",
144
- "@tangle-network/sandbox": "0.58.7",
144
+ "@tangle-network/sandbox": "0.60.27",
145
145
  "@types/node": "26.6.3",
146
146
  "typescript": "7.0.2",
147
147
  "vitest": "5.0.2"