@tangle-network/agent-provider-tangle 4.1.0 → 4.2.1

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.
@@ -1,10 +1,10 @@
1
1
  import { type BackendType, type CreateSandboxOptions } from "@tangle-network/sandbox";
2
2
  import type { CreateAgentEnvironmentInput, WorkspaceRequest } from "@tangle-network/agent-interface/environment-provider";
3
- import type { TangleModelCredentials } from "./tangle-types.js";
3
+ import type { TangleCreateSandboxOptions, TangleModelCredentials } from "./tangle-types.js";
4
4
  /** Immutable create evidence used to bind a later native resume to its restored snapshot. */
5
5
  export declare const NATIVE_RESUME_CHECKPOINT_METADATA_KEY = "tangleNativeResumeCheckpointId";
6
6
  export declare function captureModelCredentials(value: TangleModelCredentials | undefined): TangleModelCredentials | undefined;
7
- export declare function sandboxOptionsFromCreateInput(input: CreateAgentEnvironmentInput, defaultBackend?: BackendType, parsedWorkspace?: WorkspaceRequest, modelCredentials?: TangleModelCredentials, subscriptionSelection?: boolean): CreateSandboxOptions;
7
+ export declare function sandboxOptionsFromCreateInput(input: CreateAgentEnvironmentInput, defaultBackend?: BackendType, parsedWorkspace?: WorkspaceRequest, modelCredentials?: TangleModelCredentials, subscriptionSelection?: boolean): TangleCreateSandboxOptions;
8
8
  /**
9
9
  * Project a portable workspace checkpoint onto the Sandbox restore fields.
10
10
  *
@@ -20,4 +20,4 @@ export declare function assertNoInlineSecretValues(input: CreateAgentEnvironment
20
20
  /** A custom mapper must not smuggle a value map into the Sandbox request. */
21
21
  export declare function assertMappedSecretNames(options: CreateSandboxOptions): void;
22
22
  export declare function assertCreateInputShape(input: CreateAgentEnvironmentInput, parsedWorkspace?: WorkspaceRequest): WorkspaceRequest | undefined;
23
- export declare function assertMappedCreateOptions(options: CreateSandboxOptions): void;
23
+ export declare function assertMappedCreateOptions(options: TangleCreateSandboxOptions): void;
@@ -5,6 +5,8 @@ import { assertBoundedJson, boundedIdentifier, boundedString, MAX_ARRAY_LENGTH,
5
5
  import { profileCredentialSource } from "./model-credential-source.js";
6
6
  import { sandboxResourcesFromResourceRequest } from "./tangle-resources.js";
7
7
  import { tangleRuntimeAttachments } from "./tangle-runtime-attachments.js";
8
+ import { deepFreeze } from "@tangle-network/agent-interface";
9
+ import { assertProxySecretAliases, captureProxySecrets, mergeProxySecrets, proxySecretsFromInput } from "./tangle-proxy-secrets.js";
8
10
  /** Immutable create evidence used to bind a later native resume to its restored snapshot. */
9
11
  export const NATIVE_RESUME_CHECKPOINT_METADATA_KEY = "tangleNativeResumeCheckpointId";
10
12
  export function captureModelCredentials(value) {
@@ -12,13 +14,13 @@ export function captureModelCredentials(value) {
12
14
  return undefined;
13
15
  assertBoundedJson(value, "Tangle modelCredentials");
14
16
  if (value && typeof value === "object" && !Array.isArray(value) && "cliAuth" in value) {
15
- if (Object.keys(value).some((key) => key !== "cliAuth")) {
16
- throw new Error("Tangle native modelCredentials accepts only cliAuth");
17
+ if (Object.keys(value).some((key) => key !== "cliAuth" && key !== "proxySecrets")) {
18
+ throw new Error("Tangle native modelCredentials accepts only cliAuth and proxySecrets");
17
19
  }
18
20
  const parsed = cliAuthReferenceSchema.safeParse(value.cliAuth);
19
21
  if (!parsed.success)
20
22
  throw new Error("Tangle modelCredentials cliAuth must be a valid stored-secret reference");
21
- return Object.freeze({ cliAuth: Object.freeze(parsed.data) });
23
+ return deepFreeze({ cliAuth: parsed.data, ...(value.proxySecrets === undefined ? {} : { proxySecrets: captureProxySecrets(value.proxySecrets) }) });
22
24
  }
23
25
  if (!value || typeof value !== "object" || Array.isArray(value) ||
24
26
  Object.keys(value).some((key) => key !== "apiKeyEnv" && key !== "baseUrl")) {
@@ -53,6 +55,9 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
53
55
  const selectedSecret = modelCredentials === undefined ? undefined
54
56
  : "cliAuth" in modelCredentials ? modelCredentials.cliAuth?.secretEnv : modelCredentials.apiKeyEnv;
55
57
  const nativeCredentials = modelCredentials !== undefined && "cliAuth" in modelCredentials;
58
+ const proxySecrets = mergeProxySecrets(proxySecretsFromInput(input), nativeCredentials ? modelCredentials.proxySecrets : undefined);
59
+ assertProxySecretAliases(proxySecrets, input.env, input.secrets);
60
+ const proxySelected = proxySecrets?.some((binding) => binding.envName === selectedSecret || binding.secretRef.key === selectedSecret) === true;
56
61
  if (modelCredentials !== undefined && selectedSecret === undefined) {
57
62
  throw new Error("Tangle modelCredentials must select a stored secret");
58
63
  }
@@ -70,9 +75,9 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
70
75
  throw new Error("Tangle modelCredentials cannot shadow a stored secret with inline environment data");
71
76
  }
72
77
  const requestedSecrets = Array.isArray(input.secrets) ? input.secrets : undefined;
73
- const secrets = selectedSecret !== undefined
78
+ const secrets = selectedSecret !== undefined && !proxySelected
74
79
  ? [...new Set([...(requestedSecrets ?? []), selectedSecret])]
75
- : requestedSecrets;
80
+ : requestedSecrets ?? (proxySecrets === undefined ? undefined : []);
76
81
  if (secrets !== undefined && secrets.length > MAX_ARRAY_LENGTH) {
77
82
  throw new Error("Tangle selected credential exceeds the stored-secret grant bound");
78
83
  }
@@ -143,6 +148,7 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
143
148
  ...(resources ? { resources } : {}),
144
149
  ...(restore ?? {}),
145
150
  ...(input.env ? { env: input.env } : {}),
151
+ ...(proxySecrets === undefined ? {} : { proxySecrets }),
146
152
  ...(Array.isArray(secrets) ? { secrets } : {}),
147
153
  ...(input.egress === undefined ? {} : { egressPolicy: sandboxEgressPolicy(input.egress) }),
148
154
  ...(input.billingOwner === undefined ? {} : { billingOwnerId: input.billingOwner }),
@@ -155,7 +161,7 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
155
161
  profile,
156
162
  ...(modelCredentials === undefined ? {} : {
157
163
  model: "cliAuth" in modelCredentials
158
- ? { ...modelCredentials, authMode: "oauth" } : modelCredentials,
164
+ ? { cliAuth: modelCredentials.cliAuth, authMode: "oauth" } : modelCredentials,
159
165
  }),
160
166
  ...(input.runtimeAttachments === undefined ? {} : {
161
167
  runtimeAttachments: tangleRuntimeAttachments(input.runtimeAttachments, profile),
@@ -269,6 +275,7 @@ export function assertCreateInputShape(input, parsedWorkspace) {
269
275
  "signal",
270
276
  "providerOptions",
271
277
  "runtimeAttachments",
278
+ "proxySecrets",
272
279
  ])
273
280
  keys.delete(key);
274
281
  if (keys.size > 0)
@@ -306,6 +313,11 @@ export function assertMappedCreateOptions(options) {
306
313
  throw new Error("Tangle mapped create options must be an object");
307
314
  }
308
315
  assertBoundedJson(options, "Tangle mapped create options", PROFILE_AT_BACKEND_PROFILE);
316
+ const proxySecrets = options.proxySecrets === undefined ? undefined : captureProxySecrets(options.proxySecrets);
317
+ assertProxySecretAliases(proxySecrets, options.env, options.secrets);
318
+ if (proxySecrets !== undefined && !Array.isArray(options.secrets)) {
319
+ throw new Error("Tangle proxy-secret create requires explicit readable secret selection");
320
+ }
309
321
  if (options.backend?.model?.cliAuth !== undefined) {
310
322
  if (options.backend.type === undefined) {
311
323
  throw new Error("Tangle mapped native credentials require the selected backend type");
@@ -1,5 +1,5 @@
1
1
  import { type CliAuthReference } from "@tangle-network/sandbox/auth";
2
- import type { AgentEnvironment, AgentEnvironmentCapabilities, ResourceProfile } from "@tangle-network/agent-interface/environment-provider";
2
+ import type { AgentEnvironment, AgentEnvironmentCapabilities, ResourceProfile, ProxySecretBinding } from "@tangle-network/agent-interface/environment-provider";
3
3
  import type { SandboxClientLike, SandboxInstanceLike, SandboxRuntimeCapabilityDocument, TangleModelCredentialResolver } from "./tangle-types.js";
4
4
  import { type ProfileCredentialSource } from "./model-credential-source.js";
5
5
  import type { TangleConfidentialAttestationVerifier } from "./tangle-types.js";
@@ -30,6 +30,8 @@ export declare function sandboxInstanceAsEnvironment(box: SandboxInstanceLike, p
30
30
  signal?: AbortSignal;
31
31
  }, request?: {
32
32
  resources?: ResourceProfile;
33
+ proxySecrets?: ProxySecretBinding[];
34
+ rebindProxySecrets?: boolean;
33
35
  confidentialAttestationVerifier?: TangleConfidentialAttestationVerifier;
34
36
  requireNativeSessionCapture?: boolean;
35
37
  requireCliAuthReferences?: boolean;
@@ -1,5 +1,6 @@
1
1
  import { assertCliAuthReferenceSupported } from "@tangle-network/sandbox/auth";
2
2
  import { canonicalCandidateDigest } from "@tangle-network/agent-interface";
3
+ import { captureProxySecrets, mergeProxySecrets, PROXY_SECRETS_METADATA_KEY, readProxySecretReceipt, requireProxySecretCapability, validateProxySecretReceipt } from "./tangle-proxy-secrets.js";
3
4
  import { captureModelCredentials, NATIVE_RESUME_CHECKPOINT_METADATA_KEY } from "./tangle-create-options.js";
4
5
  import { AgentTurnInputSchema, deepFreeze } from "@tangle-network/agent-interface";
5
6
  import { AgentEnvironmentCapabilitiesSchema } from "@tangle-network/agent-interface/environment-provider";
@@ -60,6 +61,25 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
60
61
  const deployment = request?.captureCapabilities === undefined
61
62
  ? await readDeploymentCapabilitySupport(box, operation)
62
63
  : deploymentCapabilitySupport(request.captureCapabilities);
64
+ const modelRecord = box.metadata?.modelCredentials;
65
+ const readLiveProxyState = request?.proxySecrets !== undefined ||
66
+ box.metadata?.[PROXY_SECRETS_METADATA_KEY] !== undefined ||
67
+ (modelRecord !== null && typeof modelRecord === "object" && "proxySecrets" in modelRecord) ||
68
+ typeof client.capabilities === "function";
69
+ const liveEgress = !readLiveProxyState || box.egress === undefined ? undefined
70
+ : await awaitWithSignal(box.egress.get(operation), operation?.signal);
71
+ const authoritativeProxySecrets = liveEgress !== null && typeof liveEgress === "object" &&
72
+ "proxySecrets" in liveEgress && liveEgress.proxySecrets !== undefined
73
+ ? captureProxySecrets(liveEgress.proxySecrets) : undefined;
74
+ const recordedProxySecrets = box.metadata?.[PROXY_SECRETS_METADATA_KEY];
75
+ const persistedProxySecrets = authoritativeProxySecrets !== undefined || recordedProxySecrets === undefined
76
+ ? undefined : captureProxySecrets(recordedProxySecrets);
77
+ const recordedBindings = authoritativeProxySecrets ?? persistedProxySecrets;
78
+ if (request?.proxySecrets !== undefined && recordedBindings !== undefined &&
79
+ canonicalCandidateDigest(request.proxySecrets) !== canonicalCandidateDigest(recordedBindings)) {
80
+ throw new Error("Tangle live proxy-secret declarations differ from the requested custody");
81
+ }
82
+ let proxySecretReceipt;
63
83
  const recordedCredentials = box.metadata?.modelCredentials;
64
84
  const recordedNativeReference = recordedCredentials !== null && typeof recordedCredentials === "object" &&
65
85
  Object.hasOwn(recordedCredentials, "cliAuth");
@@ -69,6 +89,7 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
69
89
  const persistedNative = recordedNativeReference
70
90
  ? captureModelCredentials(recordedCredentials)
71
91
  : undefined;
92
+ const proxySecrets = authoritativeProxySecrets ?? (request?.rebindProxySecrets ? request.proxySecrets : mergeProxySecrets(request?.proxySecrets ?? persistedProxySecrets, persistedNative !== undefined && "cliAuth" in persistedNative ? persistedNative.proxySecrets : undefined));
72
93
  const persistedReference = persistedNative !== undefined && "cliAuth" in persistedNative
73
94
  ? persistedNative.cliAuth : undefined;
74
95
  if (request?.nativeAuth !== undefined && persistedReference !== undefined &&
@@ -77,6 +98,11 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
77
98
  }
78
99
  const nativeReference = request?.nativeAuth?.cliAuth ?? persistedReference;
79
100
  const credentialHarness = request?.nativeAuth?.harness ?? request?.credentialHarness;
101
+ // Recovery may obtain an expired reference-only receipt only when the trusted native
102
+ // owner can renew it. prepareTurn requires an installed, fresh acknowledgement before use.
103
+ if (proxySecrets !== undefined) {
104
+ proxySecretReceipt = await readProxySecretReceipt(box, proxySecrets, operation, undefined, nativeReference !== undefined && request?.resolveModelCredentials !== undefined);
105
+ }
80
106
  const boundCredentialSource = request?.credentialSource ??
81
107
  (recordedCredentials !== undefined ? "subscription" : "managed");
82
108
  const capabilities = frozenCapabilityDocument(AgentEnvironmentCapabilitiesSchema.parse(capabilitiesForSandbox(declaredCapabilities, support, deployment, confidentialVerifierOption(request?.confidentialAttestationVerifier))));
@@ -135,9 +161,19 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
135
161
  AgentTurnInputSchema.parse(input);
136
162
  input.signal?.throwIfAborted();
137
163
  assertCaptureInput(input);
164
+ const requestedTurnProfile = input.profile ?? promptOptionsFromTurnInput(input, { provider: providerName, environmentId }).backend?.profile;
165
+ if (requestedTurnProfile?.proxySecrets !== undefined &&
166
+ canonicalCandidateDigest(mergeProxySecrets(proxySecrets, captureProxySecrets(requestedTurnProfile.proxySecrets))) !== canonicalCandidateDigest(proxySecrets ?? [])) {
167
+ throw new Error("Tangle turn proxy-secret declarations differ from its environment");
168
+ }
169
+ const replay = input.lastEventId !== undefined || input.controlRef !== undefined;
170
+ if (proxySecrets !== undefined) {
171
+ // An expired lease can be renewed by the trusted owner, but never dispatched as-is.
172
+ const canRenew = !replay && nativeReference !== undefined && request?.resolveModelCredentials !== undefined;
173
+ proxySecretReceipt = await readProxySecretReceipt(box, proxySecrets, input.signal ? { signal: input.signal } : undefined, proxySecretReceipt, canRenew);
174
+ }
138
175
  if (nativeReference === undefined)
139
176
  return input;
140
- const replay = input.lastEventId !== undefined || input.controlRef !== undefined;
141
177
  const backend = promptOptionsFromTurnInput(input, { provider: providerName, environmentId }).backend;
142
178
  // A plain exact read supplies no backend override and keeps its admitted request unchanged.
143
179
  if (replay && backend === undefined)
@@ -194,11 +230,24 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
194
230
  : selected.cliAuth.format !== "bundle" && selected.cliAuth.format !== "files")) {
195
231
  throw new Error(`Tangle subscription turn resolver must select a stored ${harness} native reference`);
196
232
  }
233
+ const selectedProxySecrets = mergeProxySecrets(proxySecrets, selected.proxySecrets);
234
+ if (selectedProxySecrets !== undefined) {
235
+ requireProxySecretCapability(await awaitWithSignal(box.capabilities?.(), input.signal), selectedProxySecrets);
236
+ if (canonicalCandidateDigest(selectedProxySecrets) !== canonicalCandidateDigest(proxySecrets)) {
237
+ throw new Error("Tangle retained subscription turn cannot change its proxy-secret declarations");
238
+ }
239
+ }
197
240
  selectedReference = selected.cliAuth;
198
241
  assertCliAuthReferenceSupported(harness, { ...model, cliAuth: selectedReference });
199
242
  input.signal?.throwIfAborted();
200
- await awaitWithSignal(box.grantNativeCredential({ harness, cliAuth: selectedReference }, input.signal ? { signal: input.signal } : undefined), input.signal);
243
+ const granted = await awaitWithSignal(box.grantNativeCredential({ harness, cliAuth: selectedReference,
244
+ ...(proxySecrets === undefined ? {} : { proxySecrets, expectedProxySecretGeneration: proxySecretReceipt.generation, requireInPlace: true }),
245
+ }, input.signal ? { signal: input.signal } : undefined), input.signal);
201
246
  input.signal?.throwIfAborted();
247
+ if (proxySecrets !== undefined) {
248
+ proxySecretReceipt = validateProxySecretReceipt(granted !== null && typeof granted === "object" && "proxySecretReceipt" in granted ? granted.proxySecretReceipt : undefined, environmentId, proxySecrets, proxySecretReceipt);
249
+ proxySecretReceipt = await readProxySecretReceipt(box, proxySecrets, input.signal ? { signal: input.signal } : undefined, proxySecretReceipt);
250
+ }
202
251
  }
203
252
  const selectedModel = { ...model, cliAuth: selectedReference };
204
253
  assertCliAuthReferenceSupported(harness, selectedModel);
@@ -508,6 +557,12 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
508
557
  }
509
558
  : {}),
510
559
  };
560
+ if (proxySecretReceipt !== undefined) {
561
+ Object.defineProperty(environment, "proxySecretReceipt", {
562
+ enumerable: true,
563
+ get: () => proxySecretReceipt,
564
+ });
565
+ }
511
566
  bindTangleEvidenceEnvironment(environment, box);
512
567
  return environment;
513
568
  }
@@ -1,10 +1,11 @@
1
- import { AgentEnvironmentCapabilitiesSchema, createAgentEnvironmentWithIdempotency, } from "@tangle-network/agent-interface/environment-provider";
1
+ import { AgentEnvironmentCapabilitiesSchema, AgentEnvironmentGetOptionsSchema, createAgentEnvironmentWithIdempotency, } from "@tangle-network/agent-interface/environment-provider";
2
2
  import { canonicalCandidateDigest, deepFreeze, harnessTypeSchema } from "@tangle-network/agent-interface";
3
3
  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
7
  import { assertCreateInputShape, assertMappedCreateOptions, assertMappedSecretNames, assertNoInlineSecretValues, captureModelCredentials, NATIVE_RESUME_CHECKPOINT_METADATA_KEY, sandboxOptionsFromCreateInput, sandboxRestoreFromCheckpoint } from "./tangle-create-options.js";
8
+ import { assertProxySecretAliases, captureProxySecrets, mergeProxySecrets, proxySecretsFromInput, proxySecretCapabilityFromDocument, PROXY_SECRETS_METADATA_KEY, rebindProxySecrets, requireProxySecretCapability } from "./tangle-proxy-secrets.js";
8
9
  import { statusFromUnknown } from "./tangle-environment-values.js";
9
10
  import { requireNativeCaptureCapability, requireNativeCaptureProof } from "./tangle-native-capture-proof.js";
10
11
  import { awaitSandboxRunning, DEFAULT_TANGLE_READY_TIMEOUT_MS, } from "./tangle-readiness.js";
@@ -41,11 +42,23 @@ export function createTangleProvider(options) {
41
42
  : undefined;
42
43
  const resolveDeclaredCapabilities = async (backendType) => {
43
44
  const harness = harnessTypeSchema.safeParse(backendType);
44
- const configured = options.capabilities
45
+ let configured = options.capabilities
45
46
  ? typeof options.capabilities === "function"
46
47
  ? await options.capabilities()
47
48
  : options.capabilities
48
49
  : defaultTangleSandboxCapabilities(harness.success ? harness.data : undefined);
50
+ const proxyCapability = proxySecretCapabilityFromDocument(await options.client.capabilities?.());
51
+ // Configured adapter ceilings never confer authority that the connected API did not prove.
52
+ configured = { ...configured, profile: { ...configured.profile },
53
+ ...(configured.create === undefined && proxyCapability === undefined ? {} : { create: { ...configured.create } }),
54
+ };
55
+ delete configured.profile.proxySecrets;
56
+ if (configured.create !== undefined)
57
+ delete configured.create.proxySecrets;
58
+ if (proxyCapability !== undefined) {
59
+ configured.profile.proxySecrets = proxyCapability;
60
+ configured.create = { ...configured.create, proxySecrets: proxyCapability };
61
+ }
49
62
  if (configured.create?.workspaceSnapshot === true) {
50
63
  throw new Error("Tangle provider does not support portable workspace snapshots in this receiver deployment");
51
64
  }
@@ -81,6 +94,17 @@ export function createTangleProvider(options) {
81
94
  if (input.providerOptions && Object.keys(input.providerOptions).length > 0) {
82
95
  throw new Error("Tangle create providerOptions are not supported");
83
96
  }
97
+ if (Object.hasOwn(input.metadata ?? {}, PROXY_SECRETS_METADATA_KEY)) {
98
+ throw new Error("Tangle owns metadata.tangleProxySecrets");
99
+ }
100
+ const requestedProxySecrets = proxySecretsFromInput(input);
101
+ assertProxySecretAliases(requestedProxySecrets, input.env, input.secrets);
102
+ // Discovery precedes every reference-only resolver. A resolver can introduce secure
103
+ // intent only in its result; legacy resolvers remain usable on peers without this protocol.
104
+ const peerCapabilities = await awaitWithSignal(options.client.capabilities?.(), input.signal);
105
+ if (requestedProxySecrets !== undefined) {
106
+ requireProxySecretCapability(peerCapabilities, requestedProxySecrets);
107
+ }
84
108
  const credentialSource = typeof input.profile === "string" ? "managed" : profileCredentialSource(input.profile);
85
109
  const subscription = credentialSource === "subscription";
86
110
  if (Object.hasOwn(input.metadata ?? {}, "modelCredentials")) {
@@ -107,6 +131,13 @@ export function createTangleProvider(options) {
107
131
  input.signal?.throwIfAborted();
108
132
  const mappedOptions = mapCreateInput?.(input) ??
109
133
  (subscription && resolveModelCredentials !== undefined ? sandboxOptionsFromCreateInput(input, options.defaultBackend, parsedWorkspace, selectedCredentials, true) : defaultOptions);
134
+ const selectedProxySecrets = mergeProxySecrets(requestedProxySecrets, selectedCredentials !== undefined && "cliAuth" in selectedCredentials ? selectedCredentials.proxySecrets : undefined);
135
+ if (canonicalCandidateDigest(mappedOptions.proxySecrets ?? null) !== canonicalCandidateDigest(selectedProxySecrets ?? null)) {
136
+ throw new Error("Tangle mapped proxy-secret declarations differ from the requested bindings");
137
+ }
138
+ if (selectedProxySecrets !== undefined) {
139
+ requireProxySecretCapability(peerCapabilities, selectedProxySecrets);
140
+ }
110
141
  assertMappedCreateOptions(mappedOptions);
111
142
  if (Object.hasOwn(mappedOptions.metadata ?? {}, "modelCredentials") &&
112
143
  (!subscription || selectedCredentials === undefined ||
@@ -121,6 +152,9 @@ export function createTangleProvider(options) {
121
152
  }
122
153
  const createOptions = deepFreeze(structuredClone({
123
154
  ...mappedOptions,
155
+ ...(selectedProxySecrets === undefined ? {} : {
156
+ metadata: { ...mappedOptions.metadata, [PROXY_SECRETS_METADATA_KEY]: selectedProxySecrets },
157
+ }),
124
158
  ...(options.requireNativeSessionCapture ? { requireNativeSessionCapture: true } : {}),
125
159
  }));
126
160
  if (input.idempotencyKey !== undefined &&
@@ -223,6 +257,7 @@ export function createTangleProvider(options) {
223
257
  ? {}
224
258
  : { resources: requestedResources }),
225
259
  credentialSource,
260
+ ...(selectedProxySecrets === undefined ? {} : { proxySecrets: selectedProxySecrets }),
226
261
  ...(resolveModelCredentials === undefined ? {} : { resolveModelCredentials }),
227
262
  ...(createOptions.backend?.model?.cliAuth === undefined ? {} : {
228
263
  nativeAuth: { harness: createOptions.backend.type, cliAuth: createOptions.backend.model.cliAuth },
@@ -309,11 +344,21 @@ export function createTangleProvider(options) {
309
344
  if (operation?.contextTransfer !== undefined) {
310
345
  throw new Error("Tangle context transfer attachment is not qualified by this receiver deployment");
311
346
  }
312
- assertProviderOperationOptions(operation, "Tangle get");
347
+ if (operation !== undefined)
348
+ AgentEnvironmentGetOptionsSchema.parse(operation);
349
+ const reconnectBindings = operation?.proxySecrets === undefined ? undefined : captureProxySecrets(operation.proxySecrets);
350
+ if (reconnectBindings === undefined && (operation?.expectedProxySecretGeneration !== undefined || operation?.requireInPlace !== undefined)) {
351
+ throw new Error("Tangle proxy-secret reconnect controls require an explicit declaration");
352
+ }
353
+ if (reconnectBindings !== undefined) {
354
+ if (operation?.requireInPlace === false)
355
+ throw new Error("Tangle proxy-secret reconnect requires in-place custody");
356
+ requireProxySecretCapability(await awaitWithSignal(options.client.capabilities?.(), operation?.signal), reconnectBindings);
357
+ }
313
358
  boundedIdentifier(id, "Tangle environment id");
314
359
  await resolveCapabilities();
315
360
  operation?.signal?.throwIfAborted();
316
- const box = await awaitWithSignal(options.client.get?.(id, operation), operation?.signal);
361
+ const box = await awaitWithSignal(options.client.get?.(id, operation?.signal ? { signal: operation.signal } : undefined), operation?.signal);
317
362
  operation?.signal?.throwIfAborted();
318
363
  if (!box || boundedIdentifier(box.id, "Tangle environment id") !== id)
319
364
  return null;
@@ -346,9 +391,12 @@ export function createTangleProvider(options) {
346
391
  }
347
392
  captureCapabilities = await awaitWithSignal(requireNativeCaptureCapability(box, backendType), operation?.signal);
348
393
  }
394
+ if (reconnectBindings !== undefined)
395
+ await rebindProxySecrets(box, reconnectBindings, operation);
349
396
  const declaredCapabilities = await resolveDeclaredCapabilities(backendType);
350
397
  return await sandboxInstanceAsEnvironment(box, providerName, options.client, declaredCapabilities, operation?.signal ? { signal: operation.signal } : undefined, {
351
398
  ...confidentialVerifierOption(options.confidentialAttestationVerifier),
399
+ ...(reconnectBindings === undefined ? {} : { proxySecrets: reconnectBindings, rebindProxySecrets: true }),
352
400
  ...(resolveModelCredentials === undefined ? {} : { resolveModelCredentials }),
353
401
  ...(options.requireNativeSessionCapture ? { requireNativeSessionCapture: true } : {}),
354
402
  ...(captureCapabilities === undefined ? {} : { captureCapabilities }),
@@ -0,0 +1,17 @@
1
+ import { type AgentEnvironmentGetOptions, type CreateAgentEnvironmentInput, type ProxySecretBinding, type ProxySecretCapabilities, type ProxySecretReceipt } from "@tangle-network/agent-interface/environment-provider";
2
+ import type { SandboxInstanceLike } from "./tangle-types.js";
3
+ /** Provider-owned public declarations bind recovery; they contain no authority or values. */
4
+ export declare const PROXY_SECRETS_METADATA_KEY = "tangleProxySecrets";
5
+ export declare function captureProxySecrets(value: unknown): ProxySecretBinding[];
6
+ export declare function proxySecretsFromInput(input: CreateAgentEnvironmentInput): ProxySecretBinding[] | undefined;
7
+ export declare function mergeProxySecrets(requested: ProxySecretBinding[] | undefined, selected: ProxySecretBinding[] | undefined): ProxySecretBinding[] | undefined;
8
+ export declare function assertProxySecretAliases(bindings: ProxySecretBinding[] | undefined, env: Record<string, string> | undefined, secrets: unknown): void;
9
+ export declare function proxySecretCapabilityFromDocument(document: unknown): ProxySecretCapabilities | undefined;
10
+ export declare function requireProxySecretCapability(document: unknown, bindings: ProxySecretBinding[]): void;
11
+ /** Read live custody rather than trusting metadata, a cached declaration, or a caller option. */
12
+ export declare function readProxySecretReceipt(box: SandboxInstanceLike, bindings: ProxySecretBinding[], operation?: {
13
+ signal?: AbortSignal;
14
+ }, previous?: ProxySecretReceipt, allowExpired?: boolean): Promise<ProxySecretReceipt>;
15
+ export declare function validateProxySecretReceipt(value: unknown, sandboxId: string, bindings: ProxySecretBinding[], previous?: ProxySecretReceipt, allowExpired?: boolean): ProxySecretReceipt;
16
+ /** Explicit reconnect attachment reauthorizes through the existing trusted lifecycle owner. */
17
+ export declare function rebindProxySecrets(box: SandboxInstanceLike, bindings: ProxySecretBinding[], options: AgentEnvironmentGetOptions): Promise<ProxySecretReceipt>;
@@ -0,0 +1,112 @@
1
+ import { ProxySecretCapabilitiesSchema, ProxySecretReceiptSchema, ProxySecretsSchema, isProxySecretScopeAttenuation, proxySecretPresentationsEqual, mergeProxySecretBindings, } from "@tangle-network/agent-interface/environment-provider";
2
+ import { canonicalCandidateDigest, deepFreeze } from "@tangle-network/agent-interface";
3
+ import { awaitWithSignal } from "./tangle-contract-safety.js";
4
+ /** Provider-owned public declarations bind recovery; they contain no authority or values. */
5
+ export const PROXY_SECRETS_METADATA_KEY = "tangleProxySecrets";
6
+ export function captureProxySecrets(value) {
7
+ return deepFreeze(ProxySecretsSchema.parse(value));
8
+ }
9
+ export function proxySecretsFromInput(input) {
10
+ const profile = typeof input.profile === "string" ? undefined : input.profile.proxySecrets;
11
+ const direct = input.proxySecrets === undefined ? undefined : captureProxySecrets(input.proxySecrets);
12
+ const declared = profile === undefined ? undefined : captureProxySecrets(profile);
13
+ return mergeProxySecrets(declared, direct);
14
+ }
15
+ export function mergeProxySecrets(requested, selected) {
16
+ return requested === undefined && selected === undefined
17
+ ? undefined : deepFreeze(mergeProxySecretBindings(requested, selected));
18
+ }
19
+ export function assertProxySecretAliases(bindings, env, secrets) {
20
+ if (bindings !== undefined && secrets !== undefined && !Array.isArray(secrets)) {
21
+ throw new Error("Tangle proxy-secret custody cannot use all or raw readable secret selection");
22
+ }
23
+ for (const binding of bindings ?? []) {
24
+ for (const alias of [binding.envName, binding.secretRef.key]) {
25
+ if (Object.hasOwn(env ?? {}, alias) || (Array.isArray(secrets) && secrets.includes(alias))) {
26
+ throw new Error("Tangle proxy-secret reference or alias cannot receive raw readable secret delivery");
27
+ }
28
+ }
29
+ }
30
+ }
31
+ export function proxySecretCapabilityFromDocument(document) {
32
+ const value = document !== null && typeof document === "object" && "proxySecrets" in document
33
+ ? document.proxySecrets : undefined;
34
+ const parsed = ProxySecretCapabilitiesSchema.safeParse(value);
35
+ return parsed.success ? parsed.data : undefined;
36
+ }
37
+ export function requireProxySecretCapability(document, bindings) {
38
+ const capability = proxySecretCapabilityFromDocument(document);
39
+ if (capability === undefined || bindings.some((binding) => !capability.presentations.includes(binding.presentation.type) ||
40
+ !capability.placeholderFormats.includes(binding.placeholderFormat ?? "opaque"))) {
41
+ throw new Error("Tangle peer does not prove the requested proxy-secret capability");
42
+ }
43
+ }
44
+ /** Read live custody rather than trusting metadata, a cached declaration, or a caller option. */
45
+ export async function readProxySecretReceipt(box, bindings, operation, previous, allowExpired = false) {
46
+ const document = await awaitWithSignal(box.capabilities?.(), operation?.signal);
47
+ requireProxySecretCapability(document, bindings);
48
+ if (box.egress === undefined)
49
+ throw new Error("Tangle proxy-secret receipt readback is unavailable");
50
+ const state = await awaitWithSignal(box.egress.get(operation), operation?.signal);
51
+ return validateProxySecretReceipt(state !== null && typeof state === "object" && "proxySecretReceipt" in state ? state.proxySecretReceipt : undefined, box.id, bindings, previous, allowExpired);
52
+ }
53
+ export function validateProxySecretReceipt(value, sandboxId, bindings, previous, allowExpired = false) {
54
+ const receipt = ProxySecretReceiptSchema.parse(value);
55
+ if (receipt.sandboxId !== sandboxId ||
56
+ (receipt.status !== "installed" && !(receipt.status === "revoked" && bindings.length === 0)) ||
57
+ receipt.bindings.length !== bindings.length ||
58
+ (previous !== undefined && (receipt.generation < previous.generation ||
59
+ (receipt.generation === previous.generation && canonicalCandidateDigest(receipt) !== canonicalCandidateDigest(previous))))) {
60
+ throw new Error("Tangle proxy-secret receipt does not prove current sandbox custody");
61
+ }
62
+ const now = Date.now();
63
+ for (const binding of bindings) {
64
+ const installed = receipt.bindings.find((entry) => entry.envName === binding.envName);
65
+ const prior = previous?.bindings.find((entry) => entry.envName === binding.envName);
66
+ if (installed === undefined)
67
+ throw new Error("Tangle proxy-secret receipt dropped a declaration");
68
+ if (canonicalCandidateDigest(installed.secretRef) !== canonicalCandidateDigest(binding.secretRef)) {
69
+ throw new Error("Tangle proxy-secret receipt changes its requested reference");
70
+ }
71
+ const grant = installed.grant;
72
+ const issuedAt = Date.parse(grant.issuedAt);
73
+ const expiresAt = Date.parse(grant.expiresAt);
74
+ if (grant.sandboxId !== sandboxId || issuedAt > now || (!allowExpired && expiresAt <= now) ||
75
+ (binding.ttlSeconds !== undefined && expiresAt - issuedAt > binding.ttlSeconds * 1000) ||
76
+ !proxySecretPresentationsEqual(binding.presentation, grant.presentation) ||
77
+ grant.placeholderFormat !== (binding.placeholderFormat ?? "opaque") ||
78
+ !isProxySecretScopeAttenuation(binding, grant.scope) ||
79
+ (prior !== undefined && (prior.grant.identity.tenantId !== grant.identity.tenantId ||
80
+ prior.grant.identity.issuerId !== grant.identity.issuerId ||
81
+ prior.grant.identity.secretId !== grant.identity.secretId ||
82
+ (prior.grant.identity.revision !== grant.identity.revision && receipt.generation <= previous.generation) ||
83
+ (prior.grant.identity.revision === grant.identity.revision && prior.grant.sourceExpiresAt !== undefined &&
84
+ (grant.sourceExpiresAt === undefined || Date.parse(grant.sourceExpiresAt) > Date.parse(prior.grant.sourceExpiresAt) ||
85
+ expiresAt > Date.parse(prior.grant.sourceExpiresAt)))))) {
86
+ throw new Error("Tangle proxy-secret receipt is expired, widened, or changes its resolved identity");
87
+ }
88
+ }
89
+ return deepFreeze(receipt);
90
+ }
91
+ /** Explicit reconnect attachment reauthorizes through the existing trusted lifecycle owner. */
92
+ export async function rebindProxySecrets(box, bindings, options) {
93
+ requireProxySecretCapability(await awaitWithSignal(box.capabilities?.(), options.signal), bindings);
94
+ if (box.egress?.update === undefined)
95
+ throw new Error("Tangle proxy-secret reconnect requires in-place egress update support");
96
+ const state = await awaitWithSignal(box.egress.get(options), options.signal);
97
+ const current = ProxySecretReceiptSchema.parse(state !== null && typeof state === "object" && "proxySecretReceipt" in state ? state.proxySecretReceipt : undefined);
98
+ if (current.sandboxId !== box.id || (options.expectedProxySecretGeneration !== undefined &&
99
+ current.generation !== options.expectedProxySecretGeneration)) {
100
+ throw new Error("Tangle proxy-secret reconnect generation or sandbox conflicts with current custody");
101
+ }
102
+ const updated = await awaitWithSignal(box.egress.update({
103
+ proxySecrets: bindings, expectedProxySecretGeneration: current.generation, requireInPlace: true,
104
+ }, options.signal ? { signal: options.signal } : undefined), options.signal);
105
+ const receipt = validateProxySecretReceipt(updated !== null && typeof updated === "object" && "proxySecretReceipt" in updated ? updated.proxySecretReceipt : undefined, box.id, bindings);
106
+ if (bindings.length === 0 && receipt.status !== "revoked") {
107
+ throw new Error("Tangle proxy-secret reconnect requires confirmed revocation for an empty selection");
108
+ }
109
+ if (receipt.generation < current.generation)
110
+ throw new Error("Tangle proxy-secret reconnect returned stale custody");
111
+ return readProxySecretReceipt(box, bindings, options, receipt);
112
+ }
@@ -1,7 +1,7 @@
1
1
  import type { CliAuthReference } from "@tangle-network/sandbox/auth";
2
2
  import type { BackendRegistryEntry, BackendRegistryResponse, BackendType, CreateSandboxOptions, ExecResult as SandboxExecResult, PromptOptions, PromptResult, SandboxEvent } from "@tangle-network/sandbox";
3
3
  import type { AgentRunCancellationAcknowledgement, AgentRunCancellationRequest, AgentInteractiveSessionControlClaim, AgentInteractiveSessionControlClaimAcknowledgement, AgentInteractiveSessionControlClaimRequest, AgentInteractiveSessionAttach, AgentInteractiveSessionPromptAcknowledgement, AgentInteractiveSessionPromptCommand, AgentInteractiveSessionRef, AgentInteractiveSessionStart, AgentInteractiveSessionStatus, AgentInteractiveSessionStopAcknowledgement, AgentInteractiveSessionStopCommand, AgentInteractiveTerminalSession, ConfidentialAttestation, ConfidentialExecutionEnvironment, InputPart, InteractionRequest, InteractionResponseCommand } from "@tangle-network/agent-interface";
4
- import type { AgentEnvironmentCapabilities, AgentEnvironmentProvider, CreateAgentEnvironmentInput } from "@tangle-network/agent-interface/environment-provider";
4
+ import type { AgentEnvironmentCapabilities, AgentEnvironmentProvider, CreateAgentEnvironmentInput, ProxySecretBinding, ProxySecretCapabilities, ProxySecretReceipt } from "@tangle-network/agent-interface/environment-provider";
5
5
  /**
6
6
  * The platform verdict for the create call that returned a sandbox.
7
7
  * `created` means the call allocated the sandbox; `idempotent_replay` means an
@@ -19,12 +19,20 @@ export interface SandboxCreateReceiptLike {
19
19
  outcome: "created" | "idempotent_replay" | "unknown";
20
20
  idempotencyKeyApplied: boolean;
21
21
  captureProof?: NativeCaptureProofLike;
22
+ proxySecretReceipt?: ProxySecretReceipt;
22
23
  }
23
24
  export interface TangleExactProcessOptions {
24
25
  teamId?: string;
25
26
  }
27
+ export type TangleCreateSandboxOptions = CreateSandboxOptions & {
28
+ proxySecrets?: ProxySecretBinding[];
29
+ };
26
30
  export interface SandboxClientLike {
27
- create(options?: CreateSandboxOptions, requestOptions?: {
31
+ /** Authenticated control-plane capability discovery before resolution or allocation. */
32
+ capabilities?(): Promise<{
33
+ proxySecrets?: ProxySecretCapabilities;
34
+ } | null>;
35
+ create(options?: TangleCreateSandboxOptions, requestOptions?: {
28
36
  signal?: AbortSignal;
29
37
  timeoutMs?: number;
30
38
  }): Promise<SandboxInstanceLike>;
@@ -104,6 +112,7 @@ export interface SandboxRuntimeCapabilityDocument {
104
112
  schema?: number;
105
113
  /** The selected runtime resolves stored-secret native authentication references. */
106
114
  cliAuthReferences?: boolean;
115
+ proxySecrets?: ProxySecretCapabilities;
107
116
  claudeTokenContinuations?: boolean;
108
117
  codexCredentialContinuations?: boolean;
109
118
  nativeSessionCaptureVersion?: number;
@@ -430,9 +439,24 @@ export interface SandboxInstanceLike {
430
439
  grantNativeCredential?(grant: {
431
440
  harness: "claude-code" | "codex";
432
441
  cliAuth: CliAuthReference;
442
+ proxySecrets?: ProxySecretBinding[];
443
+ expectedProxySecretGeneration?: number;
444
+ requireInPlace?: boolean;
433
445
  }, options?: {
434
446
  signal?: AbortSignal;
435
- }): Promise<void>;
447
+ }): Promise<unknown>;
448
+ egress?: {
449
+ get(options?: {
450
+ signal?: AbortSignal;
451
+ }): Promise<unknown>;
452
+ update?(update: NonNullable<CreateSandboxOptions["egressPolicy"]> | {
453
+ proxySecrets: ProxySecretBinding[];
454
+ expectedProxySecretGeneration: number;
455
+ requireInPlace: true;
456
+ }, options?: {
457
+ signal?: AbortSignal;
458
+ }): Promise<unknown>;
459
+ };
436
460
  read?(path: string, options?: {
437
461
  sessionId?: string;
438
462
  signal?: AbortSignal;
@@ -788,6 +812,7 @@ export type TangleModelCredentials = {
788
812
  baseUrl: string;
789
813
  } | {
790
814
  cliAuth: CliAuthReference;
815
+ proxySecrets?: ProxySecretBinding[];
791
816
  };
792
817
  /** Select one public stored-secret reference for a stable create or fresh-turn identity. */
793
818
  export type TangleModelCredentialResolver = (input: Readonly<CreateAgentEnvironmentInput>) => TangleModelCredentials | undefined | Promise<TangleModelCredentials | undefined>;
@@ -812,7 +837,7 @@ export interface TangleProviderOptions {
812
837
  capabilities?: AgentEnvironmentCapabilities | (() => AgentEnvironmentCapabilities | Promise<AgentEnvironmentCapabilities>);
813
838
  validateProfile?: AgentEnvironmentProvider["validateProfile"];
814
839
  /** Replaces the default mapping, including its backend and profile selection. */
815
- mapCreateInput?: (input: CreateAgentEnvironmentInput) => CreateSandboxOptions;
840
+ mapCreateInput?: (input: CreateAgentEnvironmentInput) => TangleCreateSandboxOptions;
816
841
  exactProcess?: TangleExactProcessOptions;
817
842
  /**
818
843
  * Passed to the HTTP Sandbox creation request and the subsequent wait for
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-tangle",
3
- "version": "4.1.0",
3
+ "version": "4.2.1",
4
4
  "description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -92,6 +92,8 @@
92
92
  "dist/tangle-usage-log.js",
93
93
  "dist/tangle-prompt.d.ts",
94
94
  "dist/tangle-prompt.js",
95
+ "dist/tangle-proxy-secrets.d.ts",
96
+ "dist/tangle-proxy-secrets.js",
95
97
  "dist/tangle-provider.d.ts",
96
98
  "dist/tangle-provider.js",
97
99
  "dist/tangle-readiness.d.ts",
@@ -128,7 +130,7 @@
128
130
  "dist/model-credential-capacity.d.ts"
129
131
  ],
130
132
  "dependencies": {
131
- "@tangle-network/agent-interface": "^5.0.0"
133
+ "@tangle-network/agent-interface": "^5.3.0"
132
134
  },
133
135
  "peerDependencies": {
134
136
  "@tangle-network/sandbox": ">=0.60.27 <1.0.0"