@tangle-network/agent-provider-tangle 4.5.5 → 4.5.7
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 +3 -3
- 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.d.ts +5 -24
- package/dist/tangle-prompt.js +28 -50
- package/dist/tangle-provider.js +21 -30
- package/dist/tangle-proxy-secrets.d.ts +5 -11
- package/dist/tangle-proxy-secrets.js +39 -83
- package/dist/tangle-types.d.ts +8 -3
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type BackendType, type
|
|
1
|
+
import { type BackendType, type RouterRoutingOptions } from "@tangle-network/sandbox";
|
|
2
2
|
import type { CreateAgentEnvironmentInput, WorkspaceRequest } from "@tangle-network/agent-interface/environment-provider";
|
|
3
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. */
|
|
@@ -30,8 +30,8 @@ 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
|
-
/**
|
|
34
|
-
export declare function assertMappedSecretNames(options:
|
|
33
|
+
/** Validate mapped stored names and bindings without resolving their values. */
|
|
34
|
+
export declare function assertMappedSecretNames(options: TangleCreateSandboxOptions): void;
|
|
35
35
|
export declare function assertCreateInputShape(input: CreateAgentEnvironmentInput, parsedWorkspace?: WorkspaceRequest): WorkspaceRequest | undefined;
|
|
36
36
|
export declare function assertMappedCreateOptions(options: TangleCreateSandboxOptions): void;
|
|
37
37
|
export {};
|
|
@@ -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.d.ts
CHANGED
|
@@ -11,36 +11,16 @@ export declare function promptOptionsFromTurnInput(input: AgentTurnInput, target
|
|
|
11
11
|
}): PromptOptions;
|
|
12
12
|
/** The SDK owns isolated session creation and the executor's private admission receipt. */
|
|
13
13
|
export declare function preparePromptOptions(box: SandboxInstanceLike | undefined, options: PromptOptions, provider: string): Promise<PromptOptions>;
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
* A turn may carry any of them and nothing else. An undeclared field is
|
|
18
|
-
* refused instead of forwarded, because the SDK drops what it does not
|
|
19
|
-
* declare: the turn would then run on different settings with no error
|
|
20
|
-
* anywhere, which is the silent substitution the SDK's own `model` field
|
|
21
|
-
* exists to prevent.
|
|
22
|
-
*/
|
|
23
|
-
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", "routing"];
|
|
24
|
-
/**
|
|
25
|
-
* The `BackendConfig["model"]` fields the Sandbox prompt options declare.
|
|
26
|
-
*
|
|
27
|
-
* This is the block that carries per-turn credentials — `authMode: "oauth"`
|
|
28
|
-
* with `authFiles` for a subscription seat — so it is checked field by field
|
|
29
|
-
* rather than passed through as opaque JSON.
|
|
30
|
-
*/
|
|
14
|
+
/** Canonical backend controls plus the legacy model aliases folded below. */
|
|
15
|
+
declare const SANDBOX_BACKEND_FIELD_LIST: readonly ["runtimeAttachments", "runtimeSecrets", "type", "profile", "model", "server", "interactions", "metadata"];
|
|
31
16
|
declare const SANDBOX_BACKEND_MODEL_FIELD_LIST: readonly ["provider", "model", "apiKey", "baseUrl", "maxThinkingTokens", "mode", "apiKeyEnv", "cliAuth", "authMode", "authFiles", "routing"];
|
|
32
|
-
/**
|
|
33
|
-
* These lists cover the SDK's field sets, restated as values because a
|
|
34
|
-
* TypeScript type cannot be read at run time. This pin keeps them exact in
|
|
35
|
-
* both directions: a field the SDK adds, renames, or removes fails the build
|
|
36
|
-
* here rather than reaching a caller as a wrong refusal or a silent drop.
|
|
37
|
-
*/
|
|
17
|
+
/** SDK canonical fields stay exhaustive; legacy aliases are explicitly projected into model. */
|
|
38
18
|
type Exhaustive<T extends never> = T;
|
|
39
19
|
type SandboxBackendModel = NonNullable<BackendConfig["model"]>;
|
|
40
20
|
declare const SANDBOX_AUTH_FILE_FIELD_LIST: readonly ["path", "content", "mode"];
|
|
41
21
|
type SandboxAuthFile = NonNullable<SandboxBackendModel["authFiles"]>[number];
|
|
42
22
|
type FieldDifference<T, Fields extends readonly PropertyKey[]> = Exclude<keyof T, Fields[number]> | Exclude<Fields[number], keyof T>;
|
|
43
|
-
export type SandboxBackendFieldCoverage = Exhaustive<FieldDifference<BackendConfig, typeof SANDBOX_BACKEND_FIELD_LIST> | FieldDifference<SandboxBackendModel, typeof SANDBOX_BACKEND_MODEL_FIELD_LIST> | FieldDifference<SandboxAuthFile, typeof SANDBOX_AUTH_FILE_FIELD_LIST>>;
|
|
23
|
+
export type SandboxBackendFieldCoverage = Exhaustive<FieldDifference<Omit<BackendConfig, Exclude<(typeof SANDBOX_BACKEND_MODEL_FIELD_LIST)[number], "model"> | "modelId">, typeof SANDBOX_BACKEND_FIELD_LIST> | FieldDifference<SandboxBackendModel, typeof SANDBOX_BACKEND_MODEL_FIELD_LIST> | FieldDifference<SandboxAuthFile, typeof SANDBOX_AUTH_FILE_FIELD_LIST>>;
|
|
44
24
|
type SandboxPromptBackend = NonNullable<PromptOptions["backend"]>;
|
|
45
25
|
/**
|
|
46
26
|
* Read the per-turn backend options a caller sent through `providerOptions`.
|
|
@@ -52,6 +32,7 @@ type SandboxPromptBackend = NonNullable<PromptOptions["backend"]>;
|
|
|
52
32
|
* declare, and the result is bounded JSON the SDK reads once.
|
|
53
33
|
*/
|
|
54
34
|
export declare function backendFromTurnProviderOptions(providerOptions: Record<string, unknown> | undefined): SandboxPromptBackend | undefined;
|
|
35
|
+
export declare function normalizeTangleBackend(value: unknown, allowRouting?: boolean): BackendConfig | undefined;
|
|
55
36
|
/**
|
|
56
37
|
* The part of the backend options that decides which work a turn is.
|
|
57
38
|
*
|
package/dist/tangle-prompt.js
CHANGED
|
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { normalizeRuntimeBackendConfig } from "@tangle-network/sandbox";
|
|
3
3
|
import { projectAgentTerminalRecord } from "@tangle-network/sandbox/runtime";
|
|
4
4
|
import { assertCliAuthReferenceSupported, cliAuthReferenceSchema, } from "@tangle-network/sandbox/auth";
|
|
5
|
-
import { agentProfileSchema, canonicalAgentProfileDigest, boundedEventContentRecordSchema, AgentExactRunControlRefSchema, AgentTurnInputSchema, ContextTransferReceiptSchema, contextTransferResultMatchesRequest, } from "@tangle-network/agent-interface";
|
|
5
|
+
import { agentProfileSchema, canonicalAgentProfileDigest, canonicalCandidateDigest, boundedEventContentRecordSchema, AgentExactRunControlRefSchema, AgentTurnInputSchema, ContextTransferReceiptSchema, contextTransferResultMatchesRequest, } from "@tangle-network/agent-interface";
|
|
6
6
|
import { tokenUsageFromData } from "./tangle-result-values.js";
|
|
7
7
|
import { TangleCredentialCapacityError } from "./model-credential-capacity.js";
|
|
8
8
|
import { assertBoundedJson, awaitWithSignal, boundedString, PROFILE_AT_PROFILE, } from "./tangle-contract-safety.js";
|
|
@@ -96,45 +96,10 @@ export async function preparePromptOptions(box, options, provider) {
|
|
|
96
96
|
options.signal?.throwIfAborted();
|
|
97
97
|
return { ...options, sessionId, backend, expectedPublicProfileRequestDigest, expectedSecretProfileReceipt };
|
|
98
98
|
}
|
|
99
|
-
/**
|
|
100
|
-
* The `BackendConfig` fields this adapter forwards to Sandbox prompt options.
|
|
101
|
-
*
|
|
102
|
-
* A turn may carry any of them and nothing else. An undeclared field is
|
|
103
|
-
* refused instead of forwarded, because the SDK drops what it does not
|
|
104
|
-
* declare: the turn would then run on different settings with no error
|
|
105
|
-
* anywhere, which is the silent substitution the SDK's own `model` field
|
|
106
|
-
* exists to prevent.
|
|
107
|
-
*/
|
|
99
|
+
/** Canonical backend controls plus the legacy model aliases folded below. */
|
|
108
100
|
const SANDBOX_BACKEND_FIELD_LIST = [
|
|
109
|
-
"runtimeAttachments",
|
|
110
|
-
"runtimeSecrets",
|
|
111
|
-
"modelId",
|
|
112
|
-
"provider",
|
|
113
|
-
"apiKey",
|
|
114
|
-
"baseUrl",
|
|
115
|
-
"maxThinkingTokens",
|
|
116
|
-
"mode",
|
|
117
|
-
"apiKeyEnv",
|
|
118
|
-
"cliAuth",
|
|
119
|
-
"authMode",
|
|
120
|
-
"authFiles",
|
|
121
|
-
"type",
|
|
122
|
-
"profile",
|
|
123
|
-
"model",
|
|
124
|
-
"server",
|
|
125
|
-
"interactions",
|
|
126
|
-
"metadata",
|
|
127
|
-
// Creation-only: the SDK normalizer refuses it on a turn.
|
|
128
|
-
"routing",
|
|
101
|
+
"runtimeAttachments", "runtimeSecrets", "type", "profile", "model", "server", "interactions", "metadata",
|
|
129
102
|
];
|
|
130
|
-
const SANDBOX_BACKEND_FIELDS = new Set(SANDBOX_BACKEND_FIELD_LIST);
|
|
131
|
-
/**
|
|
132
|
-
* The `BackendConfig["model"]` fields the Sandbox prompt options declare.
|
|
133
|
-
*
|
|
134
|
-
* This is the block that carries per-turn credentials — `authMode: "oauth"`
|
|
135
|
-
* with `authFiles` for a subscription seat — so it is checked field by field
|
|
136
|
-
* rather than passed through as opaque JSON.
|
|
137
|
-
*/
|
|
138
103
|
const SANDBOX_BACKEND_MODEL_FIELD_LIST = [
|
|
139
104
|
"provider",
|
|
140
105
|
"model",
|
|
@@ -150,6 +115,8 @@ const SANDBOX_BACKEND_MODEL_FIELD_LIST = [
|
|
|
150
115
|
"routing",
|
|
151
116
|
];
|
|
152
117
|
const SANDBOX_BACKEND_MODEL_FIELDS = new Set(SANDBOX_BACKEND_MODEL_FIELD_LIST);
|
|
118
|
+
const SANDBOX_BACKEND_FIELDS = new Set([...SANDBOX_BACKEND_FIELD_LIST,
|
|
119
|
+
...SANDBOX_BACKEND_MODEL_FIELD_LIST.map((field) => field === "model" ? "modelId" : field)]);
|
|
153
120
|
const SANDBOX_AUTH_FILE_FIELD_LIST = ["path", "content", "mode"];
|
|
154
121
|
/**
|
|
155
122
|
* Read the per-turn backend options a caller sent through `providerOptions`.
|
|
@@ -168,19 +135,30 @@ export function backendFromTurnProviderOptions(providerOptions) {
|
|
|
168
135
|
return undefined;
|
|
169
136
|
return sandboxPromptBackend(providerOptions.backend);
|
|
170
137
|
}
|
|
138
|
+
export function normalizeTangleBackend(value, allowRouting = false) {
|
|
139
|
+
if (value === undefined)
|
|
140
|
+
return undefined;
|
|
141
|
+
const source = plainRecord(value, "Tangle backend options"), canonical = { ...source };
|
|
142
|
+
assertDeclaredFields(source, SANDBOX_BACKEND_FIELDS, "Tangle backend options");
|
|
143
|
+
const model = source.model === undefined ? {} : { ...plainRecord(source.model, "Tangle backend model") };
|
|
144
|
+
assertDeclaredFields(model, SANDBOX_BACKEND_MODEL_FIELDS, "Tangle backend model");
|
|
145
|
+
for (const field of SANDBOX_BACKEND_MODEL_FIELD_LIST) {
|
|
146
|
+
const alias = field === "model" ? "modelId" : field, selected = source[alias];
|
|
147
|
+
if (selected === undefined)
|
|
148
|
+
continue;
|
|
149
|
+
if (model[field] !== undefined && canonicalCandidateDigest(model[field]) !== canonicalCandidateDigest(selected))
|
|
150
|
+
throw new Error(`Tangle backend ${alias} conflicts with model.${field}`);
|
|
151
|
+
model[field] = selected;
|
|
152
|
+
delete canonical[alias];
|
|
153
|
+
}
|
|
154
|
+
if (source.model !== undefined || Object.keys(model).length)
|
|
155
|
+
canonical.model = model;
|
|
156
|
+
if (canonical.server !== undefined)
|
|
157
|
+
plainRecord(canonical.server, "Tangle backend server");
|
|
158
|
+
return normalizeRuntimeBackendConfig(canonical, { allowRuntimeSecrets: true, allowRouting });
|
|
159
|
+
}
|
|
171
160
|
function sandboxPromptBackend(value) {
|
|
172
|
-
const
|
|
173
|
-
assertDeclaredFields(source, SANDBOX_BACKEND_FIELDS, "Tangle prompt backend options");
|
|
174
|
-
// Normalization can omit falsy nested values or replace them with flat fields.
|
|
175
|
-
// Reject malformed declarations before that loses the caller's input.
|
|
176
|
-
for (const field of ["model", "server"]) {
|
|
177
|
-
if (source[field] !== undefined) {
|
|
178
|
-
plainRecord(source[field], `Tangle prompt backend ${field} options`);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
const present = normalizeRuntimeBackendConfig(source, {
|
|
182
|
-
allowRuntimeSecrets: true,
|
|
183
|
-
}) ?? {};
|
|
161
|
+
const present = normalizeTangleBackend(value) ?? {};
|
|
184
162
|
const backend = {
|
|
185
163
|
...(present.type === undefined
|
|
186
164
|
? {}
|
package/dist/tangle-provider.js
CHANGED
|
@@ -6,8 +6,9 @@ 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 {
|
|
9
|
+
import { captureProxySecrets, mergeProxySecrets, proxySecretsFromInput, sandboxSecretBindingIdentity, sandboxSecretBindings, PROXY_SECRETS_METADATA_KEY } from "./tangle-proxy-secrets.js";
|
|
10
10
|
import { statusFromUnknown } from "./tangle-environment-values.js";
|
|
11
|
+
import { normalizeTangleBackend } from "./tangle-prompt.js";
|
|
11
12
|
import { requireNativeCaptureCapability, requireNativeCaptureProof } from "./tangle-native-capture-proof.js";
|
|
12
13
|
import { awaitSandboxRunning, DEFAULT_TANGLE_READY_TIMEOUT_MS, } from "./tangle-readiness.js";
|
|
13
14
|
import { profileCredentialSource } from "./model-credential-source.js";
|
|
@@ -68,18 +69,12 @@ export function createTangleProvider(options) {
|
|
|
68
69
|
: options.capabilities
|
|
69
70
|
: defaultTangleSandboxCapabilities(harness.success ? harness.data : undefined);
|
|
70
71
|
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
72
|
configured = { ...configured, profile: { ...configured.profile },
|
|
74
|
-
...(configured.create === undefined
|
|
73
|
+
...(configured.create === undefined ? {} : { create: { ...configured.create } }),
|
|
75
74
|
};
|
|
76
75
|
delete configured.profile.proxySecrets;
|
|
77
76
|
if (configured.create !== undefined)
|
|
78
77
|
delete configured.create.proxySecrets;
|
|
79
|
-
if (proxyCapability !== undefined) {
|
|
80
|
-
configured.profile.proxySecrets = proxyCapability;
|
|
81
|
-
configured.create = { ...configured.create, proxySecrets: proxyCapability };
|
|
82
|
-
}
|
|
83
78
|
if (configured.create?.workspaceSnapshot === true) {
|
|
84
79
|
throw new Error("Tangle provider does not support portable workspace snapshots in this receiver deployment");
|
|
85
80
|
}
|
|
@@ -117,13 +112,7 @@ export function createTangleProvider(options) {
|
|
|
117
112
|
throw new Error("Tangle owns metadata.tangleProxySecrets");
|
|
118
113
|
}
|
|
119
114
|
const requestedProxySecrets = proxySecretsFromInput(input);
|
|
120
|
-
|
|
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
|
-
}
|
|
115
|
+
const requestedSecrets = structuredClone(sandboxSecretBindings(input.secrets, requestedProxySecrets, input.env));
|
|
127
116
|
const credentialSource = typeof input.profile === "string" ? "managed" : profileCredentialSource(input.profile);
|
|
128
117
|
const subscription = credentialSource === "subscription";
|
|
129
118
|
if (Object.hasOwn(input.metadata ?? {}, "modelCredentials")) {
|
|
@@ -148,18 +137,24 @@ export function createTangleProvider(options) {
|
|
|
148
137
|
selectedCredentials = captureModelCredentials(selected);
|
|
149
138
|
}
|
|
150
139
|
input.signal?.throwIfAborted();
|
|
151
|
-
const
|
|
140
|
+
const mappedInput = mapCreateInput?.(input) ??
|
|
152
141
|
(subscription && resolveModelCredentials !== undefined ? sandboxOptionsFromCreateInput(input, options.defaultBackend, parsedWorkspace, selectedCredentials, true) : defaultOptions);
|
|
153
|
-
const selectedProxySecrets = mergeProxySecrets(requestedProxySecrets, selectedCredentials
|
|
154
|
-
if (canonicalCandidateDigest(
|
|
142
|
+
const selectedProxySecrets = mergeProxySecrets(requestedProxySecrets, selectedCredentials?.proxySecrets);
|
|
143
|
+
if (mappedInput.proxySecrets !== undefined && canonicalCandidateDigest(mappedInput.proxySecrets) !== canonicalCandidateDigest(selectedProxySecrets)) {
|
|
155
144
|
throw new Error("Tangle mapped proxy-secret declarations differ from the requested bindings");
|
|
156
145
|
}
|
|
157
|
-
|
|
158
|
-
|
|
146
|
+
const { proxySecrets: _legacy, secrets: selection, ...mapped } = { ...mappedInput, backend: normalizeTangleBackend(mappedInput.backend, true) };
|
|
147
|
+
const secrets = sandboxSecretBindings(selection, selectedProxySecrets, mapped.env);
|
|
148
|
+
const mappedOptions = { ...mapped, ...(secrets === undefined ? {} : { secrets }) };
|
|
149
|
+
for (const entry of requestedSecrets ?? []) {
|
|
150
|
+
if (typeof entry === "string")
|
|
151
|
+
continue;
|
|
152
|
+
if (!Array.isArray(mappedOptions.secrets) || !mappedOptions.secrets.some((selected) => sandboxSecretBindingIdentity(selected) === sandboxSecretBindingIdentity(entry))) {
|
|
153
|
+
throw new Error("Tangle mapped secrets must preserve the requested delivery selection");
|
|
154
|
+
}
|
|
159
155
|
}
|
|
160
156
|
assertMappedCreateOptions(mappedOptions);
|
|
161
|
-
|
|
162
|
-
const mappedRouting = mappedOptions.backend?.routing ?? mappedOptions.backend?.model?.routing;
|
|
157
|
+
const mappedRouting = mappedOptions.backend?.model?.routing;
|
|
163
158
|
if (canonicalCandidateDigest(mappedRouting ?? null) !== canonicalCandidateDigest(requestedRouting ?? null)) {
|
|
164
159
|
throw new Error("Tangle mapped create options must carry exactly the requested providerOptions.routing");
|
|
165
160
|
}
|
|
@@ -346,6 +341,7 @@ export function createTangleProvider(options) {
|
|
|
346
341
|
return {
|
|
347
342
|
name: providerName,
|
|
348
343
|
...(exactProcess ? { exactProcess } : {}),
|
|
344
|
+
...(typeof options.client.secrets?.update !== "function" ? {} : { 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,11 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type {
|
|
1
|
+
import { type CreateAgentEnvironmentInput, type ProxySecretBinding } from "@tangle-network/agent-interface/environment-provider";
|
|
2
|
+
import type { TangleCreateSandboxOptions } from "./tangle-types.js";
|
|
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
|
-
|
|
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<TangleCreateSandboxOptions["secrets"], "all">;
|
|
11
|
+
export declare const sandboxSecretBindingIdentity: (entry: Extract<CreateAgentEnvironmentInput["secrets"], unknown[]>[number]) => string;
|
|
@@ -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) {
|
|
@@ -17,96 +17,52 @@ export function mergeProxySecrets(requested, selected) {
|
|
|
17
17
|
? undefined : deepFreeze(mergeProxySecretBindings(requested, selected));
|
|
18
18
|
}
|
|
19
19
|
export function assertProxySecretAliases(bindings, env, secrets) {
|
|
20
|
-
if (bindings !== undefined && secrets !== undefined && !Array.isArray(secrets))
|
|
20
|
+
if (bindings !== undefined && secrets !== undefined && !Array.isArray(secrets))
|
|
21
21
|
throw new Error("Tangle proxy-secret custody cannot use all or raw readable secret selection");
|
|
22
|
-
}
|
|
23
22
|
for (const binding of bindings ?? []) {
|
|
24
23
|
for (const alias of [binding.envName, binding.secretRef.key]) {
|
|
25
|
-
if (Object.hasOwn(env ?? {}, alias) || (Array.isArray(secrets) && secrets.
|
|
24
|
+
if (Object.hasOwn(env ?? {}, alias) || (Array.isArray(secrets) && secrets.some((entry) => typeof entry === "string" ? entry === alias : entry?.name === alias && "exposeInBox" in entry))) {
|
|
26
25
|
throw new Error("Tangle proxy-secret reference or alias cannot receive raw readable secret delivery");
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
}
|
|
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");
|
|
30
|
+
/** Lower portable declarations to the single host binding actually served by Sandbox. */
|
|
31
|
+
export function sandboxSecretBindings(secrets, bindings, env) {
|
|
32
|
+
assertProxySecretAliases(bindings === undefined ? undefined : [...bindings], env, secrets);
|
|
33
|
+
const lowered = (bindings ?? []).map((binding) => {
|
|
34
|
+
if (binding.hosts.length !== 1 || binding.methods !== undefined || binding.paths !== undefined ||
|
|
35
|
+
binding.presentation.type === "query" || binding.placeholderFormat === "jwt" ||
|
|
36
|
+
binding.ttlSeconds !== undefined || binding.envName !== binding.secretRef.key) {
|
|
37
|
+
throw new Error("Tangle host bindings cannot enforce aliases, multiple hosts, methods, paths, query, jwt or expiry");
|
|
70
38
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
39
|
+
return { name: binding.secretRef.key, host: binding.hosts[0],
|
|
40
|
+
header: binding.presentation.type === "header" ? binding.presentation.name : "Authorization" };
|
|
41
|
+
});
|
|
42
|
+
if (secrets === undefined && bindings === undefined)
|
|
43
|
+
return undefined;
|
|
44
|
+
if (secrets !== undefined && !Array.isArray(secrets))
|
|
45
|
+
throw new Error("Tangle secrets must be stored names or host bindings");
|
|
46
|
+
const entries = new Map();
|
|
47
|
+
for (const entry of [...(secrets ?? []), ...lowered]) {
|
|
48
|
+
const name = typeof entry === "string" ? entry : entry.name;
|
|
49
|
+
boundedIdentifier(name, "Tangle stored-secret name");
|
|
50
|
+
if (typeof entry !== "string") {
|
|
51
|
+
if (("host" in entry ? Object.keys(entry).some((key) => !["name", "host", "header"].includes(key)) ||
|
|
52
|
+
typeof entry.host !== "string" || entry.host.length > 253 ||
|
|
53
|
+
!/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(entry.host) ||
|
|
54
|
+
(entry.header !== undefined && (typeof entry.header !== "string" || !/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(entry.header))) :
|
|
55
|
+
Object.keys(entry).some((key) => !["name", "exposeInBox"].includes(key)) || entry.exposeInBox !== true) ||
|
|
56
|
+
Object.hasOwn(env ?? {}, name))
|
|
57
|
+
throw new Error("Invalid or shadowed Tangle secret selection");
|
|
87
58
|
}
|
|
59
|
+
const previous = entries.get(name);
|
|
60
|
+
if (previous !== undefined && sandboxSecretBindingIdentity(previous) !== sandboxSecretBindingIdentity(entry))
|
|
61
|
+
throw new Error("Conflicting Tangle secret delivery");
|
|
62
|
+
entries.set(name, entry);
|
|
88
63
|
}
|
|
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);
|
|
64
|
+
if (entries.size > MAX_ARRAY_LENGTH)
|
|
65
|
+
throw new Error("Tangle stored-secret selection exceeds its bound");
|
|
66
|
+
return [...entries.values()];
|
|
112
67
|
}
|
|
68
|
+
export const sandboxSecretBindingIdentity = (entry) => canonicalCandidateDigest(typeof entry !== "string" && "host" in entry ? { ...entry, header: (entry.header ?? "Authorization").toLowerCase() } : entry);
|
package/dist/tangle-types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CliAuthReference } from "@tangle-network/sandbox/auth";
|
|
2
|
-
import type { BackendRegistryEntry, BackendRegistryResponse, BackendType, CreateSandboxOptions, ExecResult as SandboxExecResult, PromptOptions, PromptResult, SandboxInstance, SandboxEvent } from "@tangle-network/sandbox";
|
|
2
|
+
import type { BackendConfig, BackendRegistryEntry, BackendRegistryResponse, BackendType, CreateSandboxOptions, ExecResult as SandboxExecResult, PromptOptions, PromptResult, SandboxInstance, 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
4
|
import type { AgentEnvironmentCapabilities, AgentEnvironmentProvider, CreateAgentEnvironmentInput, ProxySecretBinding, ProxySecretCapabilities, ProxySecretReceipt } from "@tangle-network/agent-interface/environment-provider";
|
|
5
5
|
/**
|
|
@@ -24,11 +24,15 @@ export interface SandboxCreateReceiptLike {
|
|
|
24
24
|
export interface TangleExactProcessOptions {
|
|
25
25
|
teamId?: string;
|
|
26
26
|
}
|
|
27
|
-
export type TangleCreateSandboxOptions = CreateSandboxOptions & {
|
|
27
|
+
export type TangleCreateSandboxOptions = Omit<CreateSandboxOptions, "secrets" | "backend"> & {
|
|
28
|
+
backend?: BackendConfig & Omit<NonNullable<BackendConfig["model"]>, "model"> & {
|
|
29
|
+
modelId?: string;
|
|
30
|
+
};
|
|
31
|
+
secrets?: "all" | Extract<CreateAgentEnvironmentInput["secrets"], unknown[]>;
|
|
28
32
|
proxySecrets?: ProxySecretBinding[];
|
|
29
33
|
};
|
|
30
34
|
export interface SandboxClientLike {
|
|
31
|
-
|
|
35
|
+
readonly secrets?: AgentEnvironmentProvider["secrets"];
|
|
32
36
|
capabilities?(): Promise<{
|
|
33
37
|
proxySecrets?: ProxySecretCapabilities;
|
|
34
38
|
} | null>;
|
|
@@ -819,6 +823,7 @@ export interface SandboxInteractionCommandResultLike {
|
|
|
819
823
|
export type TangleModelCredentials = {
|
|
820
824
|
apiKeyEnv: string;
|
|
821
825
|
baseUrl: string;
|
|
826
|
+
proxySecrets?: ProxySecretBinding[];
|
|
822
827
|
} | {
|
|
823
828
|
cliAuth: CliAuthReference;
|
|
824
829
|
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.7",
|
|
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.7"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@tangle-network/sandbox": ">=0.60.88 <2.0.0"
|