@tangle-network/agent-provider-tangle 4.5.4 → 4.5.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/dist/tangle-create-options.d.ts +1 -1
- package/dist/tangle-create-options.js +16 -36
- package/dist/tangle-environment.d.ts +0 -1
- package/dist/tangle-environment.js +7 -42
- package/dist/tangle-prompt.js +1 -1
- package/dist/tangle-provider.js +18 -27
- package/dist/tangle-proxy-secrets.d.ts +4 -11
- package/dist/tangle-proxy-secrets.js +37 -80
- package/dist/tangle-types.d.ts +2 -1
- package/package.json +2 -2
|
@@ -30,7 +30,7 @@ export declare function sandboxRestoreFromCheckpoint(checkpoint: WorkspaceReques
|
|
|
30
30
|
} | undefined;
|
|
31
31
|
/** Reject value-bearing secret maps before any custom mapper can drop them. */
|
|
32
32
|
export declare function assertNoInlineSecretValues(input: CreateAgentEnvironmentInput, parsedWorkspace?: WorkspaceRequest): void;
|
|
33
|
-
/**
|
|
33
|
+
/** Validate mapped stored names and bindings without resolving their values. */
|
|
34
34
|
export declare function assertMappedSecretNames(options: CreateSandboxOptions): void;
|
|
35
35
|
export declare function assertCreateInputShape(input: CreateAgentEnvironmentInput, parsedWorkspace?: WorkspaceRequest): WorkspaceRequest | undefined;
|
|
36
36
|
export declare function assertMappedCreateOptions(options: TangleCreateSandboxOptions): void;
|
|
@@ -6,7 +6,7 @@ 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
8
|
import { deepFreeze } from "@tangle-network/agent-interface";
|
|
9
|
-
import { assertProxySecretAliases, captureProxySecrets, mergeProxySecrets, proxySecretsFromInput } from "./tangle-proxy-secrets.js";
|
|
9
|
+
import { assertProxySecretAliases, captureProxySecrets, mergeProxySecrets, proxySecretsFromInput, sandboxSecretBindings } from "./tangle-proxy-secrets.js";
|
|
10
10
|
/** Immutable create evidence used to bind a later native resume to its restored snapshot. */
|
|
11
11
|
export const NATIVE_RESUME_CHECKPOINT_METADATA_KEY = "tangleNativeResumeCheckpointId";
|
|
12
12
|
export function captureModelCredentials(value) {
|
|
@@ -23,8 +23,8 @@ export function captureModelCredentials(value) {
|
|
|
23
23
|
return deepFreeze({ cliAuth: parsed.data, ...(value.proxySecrets === undefined ? {} : { proxySecrets: captureProxySecrets(value.proxySecrets) }) });
|
|
24
24
|
}
|
|
25
25
|
if (!value || typeof value !== "object" || Array.isArray(value) ||
|
|
26
|
-
Object.keys(value).some((key) => key !== "apiKeyEnv" && key !== "baseUrl")) {
|
|
27
|
-
throw new Error("Tangle modelCredentials accepts only apiKeyEnv and
|
|
26
|
+
Object.keys(value).some((key) => key !== "apiKeyEnv" && key !== "baseUrl" && key !== "proxySecrets")) {
|
|
27
|
+
throw new Error("Tangle modelCredentials accepts only apiKeyEnv, baseUrl and proxySecrets");
|
|
28
28
|
}
|
|
29
29
|
const { apiKeyEnv, baseUrl } = value;
|
|
30
30
|
if (typeof apiKeyEnv !== "string" || apiKeyEnv.length > 128 ||
|
|
@@ -43,7 +43,7 @@ export function captureModelCredentials(value) {
|
|
|
43
43
|
url.username || url.password || url.search || url.hash) {
|
|
44
44
|
throw new Error("Tangle modelCredentials baseUrl must be an HTTP(S) endpoint without credentials, query, or fragment");
|
|
45
45
|
}
|
|
46
|
-
return
|
|
46
|
+
return deepFreeze({ apiKeyEnv, baseUrl, ...(value.proxySecrets === undefined ? {} : { proxySecrets: captureProxySecrets(value.proxySecrets) }) });
|
|
47
47
|
}
|
|
48
48
|
const ROUTING_FIELD_LIST = ["only", "allowFallbacks", "requireModel"];
|
|
49
49
|
/**
|
|
@@ -102,9 +102,10 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
|
|
|
102
102
|
const selectedSecret = modelCredentials === undefined ? undefined
|
|
103
103
|
: "cliAuth" in modelCredentials ? modelCredentials.cliAuth?.secretEnv : modelCredentials.apiKeyEnv;
|
|
104
104
|
const nativeCredentials = modelCredentials !== undefined && "cliAuth" in modelCredentials;
|
|
105
|
-
const proxySecrets = mergeProxySecrets(proxySecretsFromInput(input),
|
|
105
|
+
const proxySecrets = mergeProxySecrets(proxySecretsFromInput(input), modelCredentials?.proxySecrets);
|
|
106
106
|
assertProxySecretAliases(proxySecrets, input.env, input.secrets);
|
|
107
|
-
const proxySelected = proxySecrets?.some((binding) => binding.envName === selectedSecret || binding.secretRef.key === selectedSecret) === true
|
|
107
|
+
const proxySelected = proxySecrets?.some((binding) => binding.envName === selectedSecret || binding.secretRef.key === selectedSecret) === true ||
|
|
108
|
+
(Array.isArray(input.secrets) && input.secrets.some((entry) => typeof entry !== "string" && entry.name === selectedSecret)) === true;
|
|
108
109
|
if (modelCredentials !== undefined && selectedSecret === undefined) {
|
|
109
110
|
throw new Error("Tangle modelCredentials must select a stored secret");
|
|
110
111
|
}
|
|
@@ -122,9 +123,10 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
|
|
|
122
123
|
throw new Error("Tangle modelCredentials cannot shadow a stored secret with inline environment data");
|
|
123
124
|
}
|
|
124
125
|
const requestedSecrets = Array.isArray(input.secrets) ? input.secrets : undefined;
|
|
125
|
-
const
|
|
126
|
+
const requestedSelection = selectedSecret !== undefined && !proxySelected
|
|
126
127
|
? [...new Set([...(requestedSecrets ?? []), selectedSecret])]
|
|
127
128
|
: requestedSecrets ?? (proxySecrets === undefined ? undefined : []);
|
|
129
|
+
const secrets = sandboxSecretBindings(requestedSelection, proxySecrets, input.env);
|
|
128
130
|
if (secrets !== undefined && secrets.length > MAX_ARRAY_LENGTH) {
|
|
129
131
|
throw new Error("Tangle selected credential exceeds the stored-secret grant bound");
|
|
130
132
|
}
|
|
@@ -191,7 +193,6 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
|
|
|
191
193
|
...(resources ? { resources } : {}),
|
|
192
194
|
...(restore ?? {}),
|
|
193
195
|
...(input.env ? { env: input.env } : {}),
|
|
194
|
-
...(proxySecrets === undefined ? {} : { proxySecrets }),
|
|
195
196
|
...(Array.isArray(secrets) ? { secrets } : {}),
|
|
196
197
|
...(input.egress === undefined ? {} : { egressPolicy: sandboxEgressPolicy(input.egress) }),
|
|
197
198
|
...(input.billingOwner === undefined ? {} : { billingOwnerId: input.billingOwner }),
|
|
@@ -203,7 +204,7 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
|
|
|
203
204
|
profile,
|
|
204
205
|
...(modelCredentials === undefined ? {} : {
|
|
205
206
|
model: "cliAuth" in modelCredentials
|
|
206
|
-
? { cliAuth: modelCredentials.cliAuth, authMode: "oauth" } : modelCredentials,
|
|
207
|
+
? { cliAuth: modelCredentials.cliAuth, authMode: "oauth" } : { apiKeyEnv: modelCredentials.apiKeyEnv, baseUrl: modelCredentials.baseUrl },
|
|
207
208
|
}),
|
|
208
209
|
...(input.runtimeAttachments === undefined ? {} : {
|
|
209
210
|
runtimeAttachments: tangleRuntimeAttachments(input.runtimeAttachments, profile),
|
|
@@ -266,29 +267,13 @@ export function assertNoInlineSecretValues(input, parsedWorkspace) {
|
|
|
266
267
|
throw new Error("Tangle resource providerOptions are not supported");
|
|
267
268
|
}
|
|
268
269
|
}
|
|
269
|
-
|
|
270
|
-
throw new Error("Tangle secrets must be an array of names created with client.secrets.create(); inline secret values are not accepted");
|
|
271
|
-
}
|
|
272
|
-
if (input.secrets !== undefined) {
|
|
273
|
-
if (input.secrets.length > MAX_ARRAY_LENGTH) {
|
|
274
|
-
throw new Error("Tangle secret names exceed their bound");
|
|
275
|
-
}
|
|
276
|
-
for (const secret of input.secrets)
|
|
277
|
-
boundedIdentifier(secret, "Tangle secret name");
|
|
278
|
-
}
|
|
270
|
+
sandboxSecretBindings(input.secrets, undefined, input.env);
|
|
279
271
|
}
|
|
280
|
-
/**
|
|
272
|
+
/** Validate mapped stored names and bindings without resolving their values. */
|
|
281
273
|
export function assertMappedSecretNames(options) {
|
|
282
|
-
if (options.secrets
|
|
283
|
-
throw new Error("Tangle mapped secrets
|
|
284
|
-
|
|
285
|
-
if (options.secrets !== undefined) {
|
|
286
|
-
if (options.secrets.length > MAX_ARRAY_LENGTH) {
|
|
287
|
-
throw new Error("Tangle mapped secrets exceed their bound");
|
|
288
|
-
}
|
|
289
|
-
for (const secret of options.secrets)
|
|
290
|
-
boundedIdentifier(secret, "Tangle mapped secret name");
|
|
291
|
-
}
|
|
274
|
+
if (options.secrets === "all")
|
|
275
|
+
throw new Error("Tangle mapped secrets require explicit selection");
|
|
276
|
+
sandboxSecretBindings(options.secrets, undefined, options.env);
|
|
292
277
|
}
|
|
293
278
|
export function assertCreateInputShape(input, parsedWorkspace) {
|
|
294
279
|
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
@@ -348,11 +333,6 @@ export function assertMappedCreateOptions(options) {
|
|
|
348
333
|
throw new Error("Tangle mapped create options must be an object");
|
|
349
334
|
}
|
|
350
335
|
assertBoundedJson(options, "Tangle mapped create options", PROFILE_AT_BACKEND_PROFILE);
|
|
351
|
-
const proxySecrets = options.proxySecrets === undefined ? undefined : captureProxySecrets(options.proxySecrets);
|
|
352
|
-
assertProxySecretAliases(proxySecrets, options.env, options.secrets);
|
|
353
|
-
if (proxySecrets !== undefined && !Array.isArray(options.secrets)) {
|
|
354
|
-
throw new Error("Tangle proxy-secret create requires explicit readable secret selection");
|
|
355
|
-
}
|
|
356
336
|
if (options.backend?.model?.cliAuth !== undefined) {
|
|
357
337
|
if (options.backend.type === undefined) {
|
|
358
338
|
throw new Error("Tangle mapped native credentials require the selected backend type");
|
|
@@ -365,7 +345,7 @@ export function assertMappedCreateOptions(options) {
|
|
|
365
345
|
throw new Error("Tangle mapped native credentials must use the exact profile harness");
|
|
366
346
|
}
|
|
367
347
|
const selectedSecret = options.backend.model.cliAuth.secretEnv;
|
|
368
|
-
if (!Array.isArray(options.secrets) || !options.secrets.
|
|
348
|
+
if (!Array.isArray(options.secrets) || !options.secrets.some((entry) => (typeof entry === "string" ? entry : entry.name) === selectedSecret)) {
|
|
369
349
|
throw new Error("Tangle mapped native credential must be explicitly listed in create secrets");
|
|
370
350
|
}
|
|
371
351
|
if (Object.hasOwn(options.env ?? {}, selectedSecret)) {
|
|
@@ -31,7 +31,6 @@ export declare function sandboxInstanceAsEnvironment(box: SandboxInstanceLike, p
|
|
|
31
31
|
}, request?: {
|
|
32
32
|
resources?: ResourceProfile;
|
|
33
33
|
proxySecrets?: ProxySecretBinding[];
|
|
34
|
-
rebindProxySecrets?: boolean;
|
|
35
34
|
confidentialAttestationVerifier?: TangleConfidentialAttestationVerifier;
|
|
36
35
|
requireNativeSessionCapture?: boolean;
|
|
37
36
|
ephemeral?: boolean;
|
|
@@ -1,6 +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
|
|
3
|
+
import { captureProxySecrets, mergeProxySecrets, PROXY_SECRETS_METADATA_KEY } from "./tangle-proxy-secrets.js";
|
|
4
4
|
import { captureModelCredentials, NATIVE_RESUME_CHECKPOINT_METADATA_KEY } from "./tangle-create-options.js";
|
|
5
5
|
import { AgentTurnInputSchema, deepFreeze } from "@tangle-network/agent-interface";
|
|
6
6
|
import { AgentEnvironmentCapabilitiesSchema } from "@tangle-network/agent-interface/environment-provider";
|
|
@@ -61,25 +61,12 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
|
|
|
61
61
|
const deployment = request?.captureCapabilities === undefined
|
|
62
62
|
? await readDeploymentCapabilitySupport(box, operation)
|
|
63
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
64
|
const recordedProxySecrets = box.metadata?.[PROXY_SECRETS_METADATA_KEY];
|
|
75
|
-
const persistedProxySecrets =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
canonicalCandidateDigest(request.proxySecrets) !== canonicalCandidateDigest(recordedBindings)) {
|
|
80
|
-
throw new Error("Tangle live proxy-secret declarations differ from the requested custody");
|
|
65
|
+
const persistedProxySecrets = recordedProxySecrets === undefined ? undefined : captureProxySecrets(recordedProxySecrets);
|
|
66
|
+
if (request?.proxySecrets !== undefined && persistedProxySecrets !== undefined &&
|
|
67
|
+
canonicalCandidateDigest(request.proxySecrets) !== canonicalCandidateDigest(persistedProxySecrets)) {
|
|
68
|
+
throw new Error("Tangle recorded host bindings differ from the requested selection");
|
|
81
69
|
}
|
|
82
|
-
let proxySecretReceipt;
|
|
83
70
|
const recordedCredentials = box.metadata?.modelCredentials;
|
|
84
71
|
const recordedNativeReference = recordedCredentials !== null && typeof recordedCredentials === "object" &&
|
|
85
72
|
Object.hasOwn(recordedCredentials, "cliAuth");
|
|
@@ -89,7 +76,7 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
|
|
|
89
76
|
const persistedNative = recordedNativeReference
|
|
90
77
|
? captureModelCredentials(recordedCredentials)
|
|
91
78
|
: undefined;
|
|
92
|
-
const proxySecrets =
|
|
79
|
+
const proxySecrets = mergeProxySecrets(request?.proxySecrets ?? persistedProxySecrets, persistedNative !== undefined && "cliAuth" in persistedNative ? persistedNative.proxySecrets : undefined);
|
|
93
80
|
const persistedReference = persistedNative !== undefined && "cliAuth" in persistedNative
|
|
94
81
|
? persistedNative.cliAuth : undefined;
|
|
95
82
|
if (request?.nativeAuth !== undefined && persistedReference !== undefined &&
|
|
@@ -98,11 +85,6 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
|
|
|
98
85
|
}
|
|
99
86
|
const nativeReference = request?.nativeAuth?.cliAuth ?? persistedReference;
|
|
100
87
|
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
|
-
}
|
|
106
88
|
const boundCredentialSource = request?.credentialSource ??
|
|
107
89
|
(recordedCredentials !== undefined ? "subscription" : "managed");
|
|
108
90
|
const capabilities = frozenCapabilityDocument(AgentEnvironmentCapabilitiesSchema.parse(capabilitiesForSandbox(declaredCapabilities, support, deployment, confidentialVerifierOption(request?.confidentialAttestationVerifier))));
|
|
@@ -167,11 +149,6 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
|
|
|
167
149
|
throw new Error("Tangle turn proxy-secret declarations differ from its environment");
|
|
168
150
|
}
|
|
169
151
|
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
|
-
}
|
|
175
152
|
if (nativeReference === undefined)
|
|
176
153
|
return input;
|
|
177
154
|
const backend = promptOptionsFromTurnInput(input, { provider: providerName, environmentId }).backend;
|
|
@@ -232,7 +209,6 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
|
|
|
232
209
|
}
|
|
233
210
|
const selectedProxySecrets = mergeProxySecrets(proxySecrets, selected.proxySecrets);
|
|
234
211
|
if (selectedProxySecrets !== undefined) {
|
|
235
|
-
requireProxySecretCapability(await awaitWithSignal(box.capabilities?.(), input.signal), selectedProxySecrets);
|
|
236
212
|
if (canonicalCandidateDigest(selectedProxySecrets) !== canonicalCandidateDigest(proxySecrets)) {
|
|
237
213
|
throw new Error("Tangle retained subscription turn cannot change its proxy-secret declarations");
|
|
238
214
|
}
|
|
@@ -240,14 +216,9 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
|
|
|
240
216
|
selectedReference = selected.cliAuth;
|
|
241
217
|
assertCliAuthReferenceSupported(harness, { ...model, cliAuth: selectedReference });
|
|
242
218
|
input.signal?.throwIfAborted();
|
|
243
|
-
|
|
244
|
-
...(proxySecrets === undefined ? {} : { proxySecrets, expectedProxySecretGeneration: proxySecretReceipt.generation, requireInPlace: true }),
|
|
219
|
+
await awaitWithSignal(box.grantNativeCredential({ harness, cliAuth: selectedReference,
|
|
245
220
|
}, input.signal ? { signal: input.signal } : undefined), input.signal);
|
|
246
221
|
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
|
-
}
|
|
251
222
|
}
|
|
252
223
|
const selectedModel = { ...model, cliAuth: selectedReference };
|
|
253
224
|
assertCliAuthReferenceSupported(harness, selectedModel);
|
|
@@ -519,12 +490,6 @@ export async function sandboxInstanceAsEnvironment(box, providerName, client, de
|
|
|
519
490
|
},
|
|
520
491
|
...(support.destroy ? { destroy: environmentDestruction(box, request?.ephemeral === true) } : {}),
|
|
521
492
|
};
|
|
522
|
-
if (proxySecretReceipt !== undefined) {
|
|
523
|
-
Object.defineProperty(environment, "proxySecretReceipt", {
|
|
524
|
-
enumerable: true,
|
|
525
|
-
get: () => proxySecretReceipt,
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
493
|
bindTangleEvidenceEnvironment(environment, box);
|
|
529
494
|
return environment;
|
|
530
495
|
}
|
package/dist/tangle-prompt.js
CHANGED
|
@@ -84,7 +84,7 @@ export async function preparePromptOptions(box, options, provider) {
|
|
|
84
84
|
metadata: { ...options.backend?.metadata, profileSecretIsolation: true },
|
|
85
85
|
};
|
|
86
86
|
const { runtimeSecrets: _turnOnly, ...persisted } = backend;
|
|
87
|
-
const created = await awaitWithSignal(box.createSession({ sessionId, backend: persisted }), options.signal);
|
|
87
|
+
const created = await awaitWithSignal(box.createSession({ sessionId, retention: "workspace", backend: persisted }), options.signal);
|
|
88
88
|
if (created.session.id !== sessionId || created.info.id !== sessionId) {
|
|
89
89
|
throw new Error("Tangle isolated session creation changed its exact identity");
|
|
90
90
|
}
|
package/dist/tangle-provider.js
CHANGED
|
@@ -6,7 +6,7 @@ import { sandboxInstanceAsEnvironment } from "./tangle-environment.js";
|
|
|
6
6
|
import { tangleProfileValidator } from "./tangle-profile-validation.js";
|
|
7
7
|
import { confidentialVerifierOption, createTangleWorkspaceBranching, } from "./tangle-workspace-branching.js";
|
|
8
8
|
import { assertCreateInputShape, assertMappedCreateOptions, assertMappedSecretNames, assertNoInlineSecretValues, captureModelCredentials, createRoutingFromProviderOptions, NATIVE_RESUME_CHECKPOINT_METADATA_KEY, sandboxOptionsFromCreateInput, sandboxRestoreFromCheckpoint } from "./tangle-create-options.js";
|
|
9
|
-
import { assertProxySecretAliases, captureProxySecrets, mergeProxySecrets, proxySecretsFromInput,
|
|
9
|
+
import { assertProxySecretAliases, captureProxySecrets, mergeProxySecrets, proxySecretsFromInput, sandboxSecretBindings, PROXY_SECRETS_METADATA_KEY } from "./tangle-proxy-secrets.js";
|
|
10
10
|
import { statusFromUnknown } from "./tangle-environment-values.js";
|
|
11
11
|
import { requireNativeCaptureCapability, requireNativeCaptureProof } from "./tangle-native-capture-proof.js";
|
|
12
12
|
import { awaitSandboxRunning, DEFAULT_TANGLE_READY_TIMEOUT_MS, } from "./tangle-readiness.js";
|
|
@@ -68,18 +68,12 @@ export function createTangleProvider(options) {
|
|
|
68
68
|
: options.capabilities
|
|
69
69
|
: defaultTangleSandboxCapabilities(harness.success ? harness.data : undefined);
|
|
70
70
|
configured = ephemeralCapabilityCeiling(configured, options.ephemeral === true);
|
|
71
|
-
const proxyCapability = proxySecretCapabilityFromDocument(await options.client.capabilities?.());
|
|
72
|
-
// Configured adapter ceilings never confer authority that the connected API did not prove.
|
|
73
71
|
configured = { ...configured, profile: { ...configured.profile },
|
|
74
|
-
...(configured.create === undefined
|
|
72
|
+
...(configured.create === undefined ? {} : { create: { ...configured.create } }),
|
|
75
73
|
};
|
|
76
74
|
delete configured.profile.proxySecrets;
|
|
77
75
|
if (configured.create !== undefined)
|
|
78
76
|
delete configured.create.proxySecrets;
|
|
79
|
-
if (proxyCapability !== undefined) {
|
|
80
|
-
configured.profile.proxySecrets = proxyCapability;
|
|
81
|
-
configured.create = { ...configured.create, proxySecrets: proxyCapability };
|
|
82
|
-
}
|
|
83
77
|
if (configured.create?.workspaceSnapshot === true) {
|
|
84
78
|
throw new Error("Tangle provider does not support portable workspace snapshots in this receiver deployment");
|
|
85
79
|
}
|
|
@@ -118,12 +112,6 @@ export function createTangleProvider(options) {
|
|
|
118
112
|
}
|
|
119
113
|
const requestedProxySecrets = proxySecretsFromInput(input);
|
|
120
114
|
assertProxySecretAliases(requestedProxySecrets, input.env, input.secrets);
|
|
121
|
-
// Discovery precedes every reference-only resolver. A resolver can introduce secure
|
|
122
|
-
// intent only in its result; legacy resolvers remain usable on peers without this protocol.
|
|
123
|
-
const peerCapabilities = await awaitWithSignal(options.client.capabilities?.(), input.signal);
|
|
124
|
-
if (requestedProxySecrets !== undefined) {
|
|
125
|
-
requireProxySecretCapability(peerCapabilities, requestedProxySecrets);
|
|
126
|
-
}
|
|
127
115
|
const credentialSource = typeof input.profile === "string" ? "managed" : profileCredentialSource(input.profile);
|
|
128
116
|
const subscription = credentialSource === "subscription";
|
|
129
117
|
if (Object.hasOwn(input.metadata ?? {}, "modelCredentials")) {
|
|
@@ -148,14 +136,21 @@ export function createTangleProvider(options) {
|
|
|
148
136
|
selectedCredentials = captureModelCredentials(selected);
|
|
149
137
|
}
|
|
150
138
|
input.signal?.throwIfAborted();
|
|
151
|
-
const
|
|
139
|
+
const mappedInput = mapCreateInput?.(input) ??
|
|
152
140
|
(subscription && resolveModelCredentials !== undefined ? sandboxOptionsFromCreateInput(input, options.defaultBackend, parsedWorkspace, selectedCredentials, true) : defaultOptions);
|
|
153
|
-
const selectedProxySecrets = mergeProxySecrets(requestedProxySecrets, selectedCredentials
|
|
154
|
-
if (canonicalCandidateDigest(
|
|
141
|
+
const selectedProxySecrets = mergeProxySecrets(requestedProxySecrets, selectedCredentials?.proxySecrets);
|
|
142
|
+
if (mappedInput.proxySecrets !== undefined && canonicalCandidateDigest(mappedInput.proxySecrets) !== canonicalCandidateDigest(selectedProxySecrets)) {
|
|
155
143
|
throw new Error("Tangle mapped proxy-secret declarations differ from the requested bindings");
|
|
156
144
|
}
|
|
157
|
-
|
|
158
|
-
|
|
145
|
+
const { proxySecrets: _legacy, secrets: selection, ...mapped } = mappedInput;
|
|
146
|
+
const secrets = sandboxSecretBindings(selection, selectedProxySecrets, mapped.env);
|
|
147
|
+
const mappedOptions = { ...mapped, ...(secrets === undefined ? {} : { secrets }) };
|
|
148
|
+
for (const entry of sandboxSecretBindings(input.secrets, selectedProxySecrets, input.env) ?? []) {
|
|
149
|
+
if (typeof entry === "string")
|
|
150
|
+
continue;
|
|
151
|
+
if (!Array.isArray(mappedOptions.secrets) || !mappedOptions.secrets.some((selected) => canonicalCandidateDigest(selected) === canonicalCandidateDigest(entry))) {
|
|
152
|
+
throw new Error("Tangle mapped secrets must preserve the requested host bindings");
|
|
153
|
+
}
|
|
159
154
|
}
|
|
160
155
|
assertMappedCreateOptions(mappedOptions);
|
|
161
156
|
// A custom mapper builds its own backend; requested routing must survive it.
|
|
@@ -346,6 +341,7 @@ export function createTangleProvider(options) {
|
|
|
346
341
|
return {
|
|
347
342
|
name: providerName,
|
|
348
343
|
...(exactProcess ? { exactProcess } : {}),
|
|
344
|
+
...(options.client.secrets === undefined ? {} : { secrets: options.client.secrets }),
|
|
349
345
|
...(workspaceBranching === undefined ? {} : { workspaceBranching }),
|
|
350
346
|
capabilities: resolveCapabilities,
|
|
351
347
|
validateProfile: tangleProfileValidator(options.validateProfile),
|
|
@@ -379,11 +375,8 @@ export function createTangleProvider(options) {
|
|
|
379
375
|
if (reconnectBindings === undefined && (operation?.expectedProxySecretGeneration !== undefined || operation?.requireInPlace !== undefined)) {
|
|
380
376
|
throw new Error("Tangle proxy-secret reconnect controls require an explicit declaration");
|
|
381
377
|
}
|
|
382
|
-
if (reconnectBindings !== undefined)
|
|
383
|
-
|
|
384
|
-
throw new Error("Tangle proxy-secret reconnect requires in-place custody");
|
|
385
|
-
requireProxySecretCapability(await awaitWithSignal(options.client.capabilities?.(), operation?.signal), reconnectBindings);
|
|
386
|
-
}
|
|
378
|
+
if (reconnectBindings !== undefined)
|
|
379
|
+
throw new Error("Tangle host bindings are selected at create; reconnect cannot replace them");
|
|
387
380
|
boundedIdentifier(id, "Tangle environment id");
|
|
388
381
|
await resolveCapabilities();
|
|
389
382
|
operation?.signal?.throwIfAborted();
|
|
@@ -420,13 +413,11 @@ export function createTangleProvider(options) {
|
|
|
420
413
|
}
|
|
421
414
|
captureCapabilities = await awaitWithSignal(requireNativeCaptureCapability(box, backendType), operation?.signal);
|
|
422
415
|
}
|
|
423
|
-
if (reconnectBindings !== undefined)
|
|
424
|
-
await rebindProxySecrets(box, reconnectBindings, operation);
|
|
425
416
|
const declaredCapabilities = await resolveDeclaredCapabilities(backendType);
|
|
426
417
|
return await sandboxInstanceAsEnvironment(box, providerName, options.client, declaredCapabilities, operation?.signal ? { signal: operation.signal } : undefined, {
|
|
427
418
|
...confidentialVerifierOption(options.confidentialAttestationVerifier),
|
|
428
419
|
...(options.ephemeral ? { ephemeral: true } : {}),
|
|
429
|
-
...(reconnectBindings === undefined ? {} : { proxySecrets: reconnectBindings
|
|
420
|
+
...(reconnectBindings === undefined ? {} : { proxySecrets: reconnectBindings }),
|
|
430
421
|
...(resolveModelCredentials === undefined ? {} : { resolveModelCredentials }),
|
|
431
422
|
...(options.requireNativeSessionCapture ? { requireNativeSessionCapture: true } : {}),
|
|
432
423
|
...(captureCapabilities === undefined ? {} : { captureCapabilities }),
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type {
|
|
1
|
+
import { type CreateAgentEnvironmentInput, type ProxySecretBinding } from "@tangle-network/agent-interface/environment-provider";
|
|
2
|
+
import type { CreateSandboxOptions } from "@tangle-network/sandbox";
|
|
3
3
|
/** Provider-owned public declarations bind recovery; they contain no authority or values. */
|
|
4
4
|
export declare const PROXY_SECRETS_METADATA_KEY = "tangleProxySecrets";
|
|
5
5
|
export declare function captureProxySecrets(value: unknown): ProxySecretBinding[];
|
|
6
6
|
export declare function proxySecretsFromInput(input: CreateAgentEnvironmentInput): ProxySecretBinding[] | undefined;
|
|
7
7
|
export declare function mergeProxySecrets(requested: ProxySecretBinding[] | undefined, selected: ProxySecretBinding[] | undefined): ProxySecretBinding[] | undefined;
|
|
8
8
|
export declare function assertProxySecretAliases(bindings: ProxySecretBinding[] | undefined, env: Record<string, string> | undefined, secrets: unknown): void;
|
|
9
|
-
|
|
10
|
-
export declare function
|
|
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>;
|
|
9
|
+
/** Lower portable declarations to the single host binding actually served by Sandbox. */
|
|
10
|
+
export declare function sandboxSecretBindings(secrets: CreateAgentEnvironmentInput["secrets"] | "all", bindings?: readonly ProxySecretBinding[], env?: Record<string, string>): Exclude<CreateSandboxOptions["secrets"], "all">;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProxySecretsSchema, mergeProxySecretBindings, } from "@tangle-network/agent-interface/environment-provider";
|
|
2
2
|
import { canonicalCandidateDigest, deepFreeze } from "@tangle-network/agent-interface";
|
|
3
|
-
import {
|
|
3
|
+
import { boundedIdentifier, MAX_ARRAY_LENGTH } from "./tangle-contract-safety.js";
|
|
4
4
|
/** Provider-owned public declarations bind recovery; they contain no authority or values. */
|
|
5
5
|
export const PROXY_SECRETS_METADATA_KEY = "tangleProxySecrets";
|
|
6
6
|
export function captureProxySecrets(value) {
|
|
@@ -28,85 +28,42 @@ export function assertProxySecretAliases(bindings, env, secrets) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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");
|
|
31
|
+
/** Lower portable declarations to the single host binding actually served by Sandbox. */
|
|
32
|
+
export function sandboxSecretBindings(secrets, bindings, env) {
|
|
33
|
+
assertProxySecretAliases(bindings === undefined ? undefined : [...bindings], env, secrets);
|
|
34
|
+
const lowered = (bindings ?? []).map((binding) => {
|
|
35
|
+
if (binding.hosts.length !== 1 || binding.methods !== undefined || binding.paths !== undefined ||
|
|
36
|
+
binding.presentation.type === "query" || binding.placeholderFormat === "jwt" ||
|
|
37
|
+
binding.ttlSeconds !== undefined || binding.envName !== binding.secretRef.key) {
|
|
38
|
+
throw new Error("Tangle host bindings cannot enforce aliases, multiple hosts, methods, paths, query, jwt or expiry");
|
|
70
39
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
40
|
+
return { name: binding.secretRef.key, host: binding.hosts[0],
|
|
41
|
+
header: binding.presentation.type === "header" ? binding.presentation.name : "Authorization" };
|
|
42
|
+
});
|
|
43
|
+
if (secrets === undefined && bindings === undefined)
|
|
44
|
+
return undefined;
|
|
45
|
+
if (secrets !== undefined && !Array.isArray(secrets))
|
|
46
|
+
throw new Error("Tangle secrets must be stored names or host bindings");
|
|
47
|
+
const entries = new Map();
|
|
48
|
+
for (const entry of [...(secrets ?? []), ...lowered]) {
|
|
49
|
+
const name = typeof entry === "string" ? entry : entry.name;
|
|
50
|
+
boundedIdentifier(name, "Tangle stored-secret name");
|
|
51
|
+
if (typeof entry !== "string") {
|
|
52
|
+
if (Object.keys(entry).some((key) => !["name", "host", "header"].includes(key)) ||
|
|
53
|
+
typeof entry.host !== "string" || entry.host.length > 253 ||
|
|
54
|
+
!/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(entry.host) ||
|
|
55
|
+
(entry.header !== undefined && (typeof entry.header !== "string" || !/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(entry.header))) ||
|
|
56
|
+
Object.hasOwn(env ?? {}, name))
|
|
57
|
+
throw new Error("Invalid or shadowed Tangle host binding");
|
|
87
58
|
}
|
|
59
|
+
const previous = entries.get(name);
|
|
60
|
+
const identity = (value) => typeof value === "string" ? value :
|
|
61
|
+
{ name: value.name, host: value.host, header: (value.header ?? "Authorization").toLowerCase() };
|
|
62
|
+
if (previous !== undefined && canonicalCandidateDigest(identity(previous)) !== canonicalCandidateDigest(identity(entry)))
|
|
63
|
+
throw new Error("Conflicting Tangle secret delivery");
|
|
64
|
+
entries.set(name, entry);
|
|
88
65
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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);
|
|
66
|
+
if (entries.size > MAX_ARRAY_LENGTH)
|
|
67
|
+
throw new Error("Tangle stored-secret selection exceeds its bound");
|
|
68
|
+
return [...entries.values()];
|
|
112
69
|
}
|
package/dist/tangle-types.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type TangleCreateSandboxOptions = CreateSandboxOptions & {
|
|
|
28
28
|
proxySecrets?: ProxySecretBinding[];
|
|
29
29
|
};
|
|
30
30
|
export interface SandboxClientLike {
|
|
31
|
-
|
|
31
|
+
readonly secrets?: AgentEnvironmentProvider["secrets"];
|
|
32
32
|
capabilities?(): Promise<{
|
|
33
33
|
proxySecrets?: ProxySecretCapabilities;
|
|
34
34
|
} | null>;
|
|
@@ -819,6 +819,7 @@ export interface SandboxInteractionCommandResultLike {
|
|
|
819
819
|
export type TangleModelCredentials = {
|
|
820
820
|
apiKeyEnv: string;
|
|
821
821
|
baseUrl: string;
|
|
822
|
+
proxySecrets?: ProxySecretBinding[];
|
|
822
823
|
} | {
|
|
823
824
|
cliAuth: CliAuthReference;
|
|
824
825
|
proxySecrets?: ProxySecretBinding[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/agent-provider-tangle",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.6",
|
|
4
4
|
"description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"LICENSE"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@tangle-network/agent-interface": "^5.10.
|
|
36
|
+
"@tangle-network/agent-interface": "^5.10.5"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@tangle-network/sandbox": ">=0.60.88 <2.0.0"
|