@tangle-network/agent-provider-tangle 4.3.1 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -1
- package/dist/tangle-create-options.d.ts +15 -1
- package/dist/tangle-create-options.js +50 -14
- package/dist/tangle-prompt.d.ts +2 -2
- package/dist/tangle-prompt.js +4 -0
- package/dist/tangle-provider.js +7 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @tangle-network/agent-provider-tangle
|
|
2
2
|
|
|
3
3
|
Wraps `@tangle-network/sandbox` as an `AgentEnvironmentProvider`.
|
|
4
|
-
The Sandbox peer range is `>=0.60.
|
|
4
|
+
The Sandbox peer range is `>=0.60.88 <1.0.0`; the minimum version declares create-time `backend.routing`.
|
|
5
5
|
|
|
6
6
|
Terminal `result` and `done` events use the Sandbox SDK's `projectAgentTerminalRecord` summary. Cumulative tool history stays in native evidence; bounded approval identity survives projection, and malformed or conflicting approval sources fail closed. Terminal events omit the duplicate raw `providerEvent` payload.
|
|
7
7
|
|
|
@@ -232,6 +232,31 @@ The account owner retains authority over registration, namespace verification, h
|
|
|
232
232
|
Updating a stored secret does not refresh credentials already injected into a live Sandbox.
|
|
233
233
|
Creation-time validity and the selected host's native credential lifecycle still bound long-running work.
|
|
234
234
|
|
|
235
|
+
## Router routing at creation
|
|
236
|
+
|
|
237
|
+
`CreateAgentEnvironmentInput.providerOptions.routing` sets the Tangle Router provider routing for every model call the environment makes.
|
|
238
|
+
It reaches the Sandbox create call as `backend.routing`.
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
const environment = await provider.create({
|
|
242
|
+
profile,
|
|
243
|
+
providerOptions: {
|
|
244
|
+
routing: { only: ["zai"], allowFallbacks: false, requireModel: true },
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
`only` lists the Router provider ids the calls may use.
|
|
250
|
+
`allowFallbacks: false` stops the Router from falling back to another provider.
|
|
251
|
+
`requireModel: true` fails the call rather than substituting another model.
|
|
252
|
+
Routing is set at creation: the Sandbox SDK refuses `backend.routing` on a turn.
|
|
253
|
+
A workspace fork sends no backend, so a forked environment's routing is whatever the platform copies from its parent.
|
|
254
|
+
The Sandbox platform accepts it only for Router-backed OpenCode.
|
|
255
|
+
|
|
256
|
+
`routing` is the only create `providerOptions` field; any other field is refused.
|
|
257
|
+
Unknown routing fields are refused too; the accepted set is pinned to the SDK's `RouterRoutingOptions` at compile time.
|
|
258
|
+
A custom `mapCreateInput` must carry exactly the requested routing, on `backend.routing` or `backend.model.routing`, and none when none was requested; otherwise creation is refused before any request.
|
|
259
|
+
|
|
235
260
|
## `create()` returns a ready environment
|
|
236
261
|
|
|
237
262
|
`provider.create()` does not return until the sandbox reports `running`.
|
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
import { type BackendType, type CreateSandboxOptions } from "@tangle-network/sandbox";
|
|
1
|
+
import { type BackendType, type CreateSandboxOptions, 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. */
|
|
5
5
|
export declare const NATIVE_RESUME_CHECKPOINT_METADATA_KEY = "tangleNativeResumeCheckpointId";
|
|
6
6
|
export declare function captureModelCredentials(value: TangleModelCredentials | undefined): TangleModelCredentials | undefined;
|
|
7
|
+
declare const ROUTING_FIELD_LIST: readonly ["only", "allowFallbacks", "requireModel"];
|
|
8
|
+
type Exhaustive<T extends never> = T;
|
|
9
|
+
type UncoveredRoutingField = Exhaustive<Exclude<keyof RouterRoutingOptions, (typeof ROUTING_FIELD_LIST)[number]>>;
|
|
10
|
+
type StaleRoutingField = Exhaustive<Exclude<(typeof ROUTING_FIELD_LIST)[number], keyof RouterRoutingOptions>>;
|
|
11
|
+
export type RoutingFieldCoverage = [UncoveredRoutingField, StaleRoutingField];
|
|
12
|
+
/**
|
|
13
|
+
* Read create `providerOptions`, whose only field is `routing`: the Tangle
|
|
14
|
+
* Router provider routing every model call in the environment uses.
|
|
15
|
+
*
|
|
16
|
+
* Routing is fixed when the sandbox is created; the Sandbox SDK refuses it on
|
|
17
|
+
* a turn. Any other field is refused rather than dropped.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createRoutingFromProviderOptions(providerOptions: Record<string, unknown> | undefined): RouterRoutingOptions | undefined;
|
|
7
20
|
export declare function sandboxOptionsFromCreateInput(input: CreateAgentEnvironmentInput, defaultBackend?: BackendType, parsedWorkspace?: WorkspaceRequest, modelCredentials?: TangleModelCredentials, subscriptionSelection?: boolean): TangleCreateSandboxOptions;
|
|
8
21
|
/**
|
|
9
22
|
* Project a portable workspace checkpoint onto the Sandbox restore fields.
|
|
@@ -21,3 +34,4 @@ export declare function assertNoInlineSecretValues(input: CreateAgentEnvironment
|
|
|
21
34
|
export declare function assertMappedSecretNames(options: CreateSandboxOptions): void;
|
|
22
35
|
export declare function assertCreateInputShape(input: CreateAgentEnvironmentInput, parsedWorkspace?: WorkspaceRequest): WorkspaceRequest | undefined;
|
|
23
36
|
export declare function assertMappedCreateOptions(options: TangleCreateSandboxOptions): void;
|
|
37
|
+
export {};
|
|
@@ -45,6 +45,53 @@ export function captureModelCredentials(value) {
|
|
|
45
45
|
}
|
|
46
46
|
return Object.freeze({ apiKeyEnv, baseUrl });
|
|
47
47
|
}
|
|
48
|
+
const ROUTING_FIELD_LIST = ["only", "allowFallbacks", "requireModel"];
|
|
49
|
+
/**
|
|
50
|
+
* Read create `providerOptions`, whose only field is `routing`: the Tangle
|
|
51
|
+
* Router provider routing every model call in the environment uses.
|
|
52
|
+
*
|
|
53
|
+
* Routing is fixed when the sandbox is created; the Sandbox SDK refuses it on
|
|
54
|
+
* a turn. Any other field is refused rather than dropped.
|
|
55
|
+
*/
|
|
56
|
+
export function createRoutingFromProviderOptions(providerOptions) {
|
|
57
|
+
if (providerOptions === undefined)
|
|
58
|
+
return undefined;
|
|
59
|
+
if (!providerOptions || typeof providerOptions !== "object" || Array.isArray(providerOptions)) {
|
|
60
|
+
throw new Error("Tangle create providerOptions must be a JSON object");
|
|
61
|
+
}
|
|
62
|
+
assertBoundedJson(providerOptions, "Tangle create providerOptions");
|
|
63
|
+
if (Object.keys(providerOptions).some((key) => key !== "routing")) {
|
|
64
|
+
throw new Error("Tangle create providerOptions accept only routing");
|
|
65
|
+
}
|
|
66
|
+
const routing = providerOptions.routing;
|
|
67
|
+
if (routing === undefined)
|
|
68
|
+
return undefined;
|
|
69
|
+
if (!routing || typeof routing !== "object" || Array.isArray(routing)) {
|
|
70
|
+
throw new Error("Tangle create providerOptions.routing must be an object");
|
|
71
|
+
}
|
|
72
|
+
const fields = routing;
|
|
73
|
+
if (Object.keys(fields).some((key) => !ROUTING_FIELD_LIST.includes(key))) {
|
|
74
|
+
throw new Error(`Tangle create providerOptions.routing accepts only ${ROUTING_FIELD_LIST.join(", ")}`);
|
|
75
|
+
}
|
|
76
|
+
const { only, allowFallbacks, requireModel } = fields;
|
|
77
|
+
if (only !== undefined) {
|
|
78
|
+
if (!Array.isArray(only) || only.length === 0 || only.length > MAX_ARRAY_LENGTH) {
|
|
79
|
+
throw new Error("Tangle create providerOptions.routing.only must be a non-empty list of Router provider ids");
|
|
80
|
+
}
|
|
81
|
+
for (const provider of only)
|
|
82
|
+
boundedIdentifier(provider, "Tangle routing provider id");
|
|
83
|
+
}
|
|
84
|
+
for (const [name, value] of [["allowFallbacks", allowFallbacks], ["requireModel", requireModel]]) {
|
|
85
|
+
if (value !== undefined && typeof value !== "boolean") {
|
|
86
|
+
throw new Error(`Tangle create providerOptions.routing.${name} must be a boolean`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
...(only === undefined ? {} : { only: [...only] }),
|
|
91
|
+
...(allowFallbacks === undefined ? {} : { allowFallbacks: allowFallbacks }),
|
|
92
|
+
...(requireModel === undefined ? {} : { requireModel: requireModel }),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
48
95
|
export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorkspace, modelCredentials, subscriptionSelection = false) {
|
|
49
96
|
const workspace = assertCreateInputShape(input, parsedWorkspace) ?? {};
|
|
50
97
|
const profile = inlineAgentProfile(input.profile);
|
|
@@ -95,11 +142,7 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
|
|
|
95
142
|
[NATIVE_RESUME_CHECKPOINT_METADATA_KEY]: boundedIdentifier(workspace.checkpoint.checkpointId, "Tangle native resume checkpoint id"),
|
|
96
143
|
}),
|
|
97
144
|
};
|
|
98
|
-
|
|
99
|
-
throw new Error("Tangle create providerOptions are not supported");
|
|
100
|
-
}
|
|
101
|
-
if (input.providerOptions)
|
|
102
|
-
assertBoundedRecord(input.providerOptions, "Tangle create providerOptions");
|
|
145
|
+
const routing = createRoutingFromProviderOptions(input.providerOptions);
|
|
103
146
|
if (input.metadata)
|
|
104
147
|
assertBoundedRecord(input.metadata, "Tangle metadata");
|
|
105
148
|
if (input.name !== undefined) {
|
|
@@ -166,6 +209,7 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
|
|
|
166
209
|
...(input.runtimeAttachments === undefined ? {} : {
|
|
167
210
|
runtimeAttachments: tangleRuntimeAttachments(input.runtimeAttachments, profile),
|
|
168
211
|
}),
|
|
212
|
+
...(routing === undefined ? {} : { routing }),
|
|
169
213
|
},
|
|
170
214
|
};
|
|
171
215
|
return mapped;
|
|
@@ -207,15 +251,7 @@ function sandboxEgressPolicy(policy) {
|
|
|
207
251
|
}
|
|
208
252
|
/** Reject value-bearing secret maps before any custom mapper can drop them. */
|
|
209
253
|
export function assertNoInlineSecretValues(input, parsedWorkspace) {
|
|
210
|
-
|
|
211
|
-
if (!input.providerOptions || typeof input.providerOptions !== "object" || Array.isArray(input.providerOptions)) {
|
|
212
|
-
throw new Error("Tangle create providerOptions must be a JSON object");
|
|
213
|
-
}
|
|
214
|
-
assertBoundedJson(input.providerOptions, "Tangle create providerOptions");
|
|
215
|
-
if (Object.keys(input.providerOptions).length > 0) {
|
|
216
|
-
throw new Error("Tangle create providerOptions are not supported");
|
|
217
|
-
}
|
|
218
|
-
}
|
|
254
|
+
createRoutingFromProviderOptions(input.providerOptions);
|
|
219
255
|
if (input.workspace?.providerOptions !== undefined) {
|
|
220
256
|
const workspace = parsedWorkspace ?? WorkspaceRequestSchema.parse(input.workspace);
|
|
221
257
|
if (workspace.providerOptions && Object.keys(workspace.providerOptions).length > 0) {
|
package/dist/tangle-prompt.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare function promptOptionsFromTurnInput(input: AgentTurnInput, target
|
|
|
17
17
|
* anywhere, which is the silent substitution the SDK's own `model` field
|
|
18
18
|
* exists to prevent.
|
|
19
19
|
*/
|
|
20
|
-
declare const SANDBOX_BACKEND_FIELD_LIST: readonly ["runtimeAttachments", "runtimeSecrets", "modelId", "provider", "apiKey", "baseUrl", "maxThinkingTokens", "mode", "apiKeyEnv", "cliAuth", "authMode", "authFiles", "type", "profile", "model", "server", "interactions", "metadata"];
|
|
20
|
+
declare const SANDBOX_BACKEND_FIELD_LIST: readonly ["runtimeAttachments", "runtimeSecrets", "modelId", "provider", "apiKey", "baseUrl", "maxThinkingTokens", "mode", "apiKeyEnv", "cliAuth", "authMode", "authFiles", "type", "profile", "model", "server", "interactions", "metadata", "routing"];
|
|
21
21
|
/**
|
|
22
22
|
* The `BackendConfig["model"]` fields the Sandbox prompt options declare.
|
|
23
23
|
*
|
|
@@ -25,7 +25,7 @@ declare const SANDBOX_BACKEND_FIELD_LIST: readonly ["runtimeAttachments", "runti
|
|
|
25
25
|
* with `authFiles` for a subscription seat — so it is checked field by field
|
|
26
26
|
* rather than passed through as opaque JSON.
|
|
27
27
|
*/
|
|
28
|
-
declare const SANDBOX_BACKEND_MODEL_FIELD_LIST: readonly ["provider", "model", "apiKey", "baseUrl", "maxThinkingTokens", "mode", "apiKeyEnv", "cliAuth", "authMode", "authFiles"];
|
|
28
|
+
declare const SANDBOX_BACKEND_MODEL_FIELD_LIST: readonly ["provider", "model", "apiKey", "baseUrl", "maxThinkingTokens", "mode", "apiKeyEnv", "cliAuth", "authMode", "authFiles", "routing"];
|
|
29
29
|
/**
|
|
30
30
|
* These lists cover the SDK's field sets, restated as values because a
|
|
31
31
|
* TypeScript type cannot be read at run time. This pin keeps them exact in
|
package/dist/tangle-prompt.js
CHANGED
|
@@ -91,6 +91,8 @@ const SANDBOX_BACKEND_FIELD_LIST = [
|
|
|
91
91
|
"server",
|
|
92
92
|
"interactions",
|
|
93
93
|
"metadata",
|
|
94
|
+
// Creation-only: the SDK normalizer refuses it on a turn.
|
|
95
|
+
"routing",
|
|
94
96
|
];
|
|
95
97
|
const SANDBOX_BACKEND_FIELDS = new Set(SANDBOX_BACKEND_FIELD_LIST);
|
|
96
98
|
/**
|
|
@@ -111,6 +113,8 @@ const SANDBOX_BACKEND_MODEL_FIELD_LIST = [
|
|
|
111
113
|
"cliAuth",
|
|
112
114
|
"authMode",
|
|
113
115
|
"authFiles",
|
|
116
|
+
// Creation-only: the SDK normalizer refuses it on a turn.
|
|
117
|
+
"routing",
|
|
114
118
|
];
|
|
115
119
|
const SANDBOX_BACKEND_MODEL_FIELDS = new Set(SANDBOX_BACKEND_MODEL_FIELD_LIST);
|
|
116
120
|
const SANDBOX_AUTH_FILE_FIELD_LIST = ["path", "content", "mode"];
|
package/dist/tangle-provider.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createTangleExactProcessProvider, } from "./exact-process.js";
|
|
|
4
4
|
import { capabilitiesForClient, defaultTangleSandboxCapabilities, narrowTangleCapabilitiesToBackend, } from "./tangle-capabilities.js";
|
|
5
5
|
import { sandboxInstanceAsEnvironment } from "./tangle-environment.js";
|
|
6
6
|
import { confidentialVerifierOption, createTangleWorkspaceBranching, } from "./tangle-workspace-branching.js";
|
|
7
|
-
import { assertCreateInputShape, assertMappedCreateOptions, assertMappedSecretNames, assertNoInlineSecretValues, captureModelCredentials, NATIVE_RESUME_CHECKPOINT_METADATA_KEY, sandboxOptionsFromCreateInput, sandboxRestoreFromCheckpoint } from "./tangle-create-options.js";
|
|
7
|
+
import { assertCreateInputShape, assertMappedCreateOptions, assertMappedSecretNames, assertNoInlineSecretValues, captureModelCredentials, createRoutingFromProviderOptions, NATIVE_RESUME_CHECKPOINT_METADATA_KEY, sandboxOptionsFromCreateInput, sandboxRestoreFromCheckpoint } from "./tangle-create-options.js";
|
|
8
8
|
import { assertProxySecretAliases, captureProxySecrets, mergeProxySecrets, proxySecretsFromInput, proxySecretCapabilityFromDocument, PROXY_SECRETS_METADATA_KEY, rebindProxySecrets, requireProxySecretCapability } from "./tangle-proxy-secrets.js";
|
|
9
9
|
import { statusFromUnknown } from "./tangle-environment-values.js";
|
|
10
10
|
import { requireNativeCaptureCapability, requireNativeCaptureProof } from "./tangle-native-capture-proof.js";
|
|
@@ -91,9 +91,7 @@ export function createTangleProvider(options) {
|
|
|
91
91
|
const parsedWorkspace = assertCreateInputShape(input);
|
|
92
92
|
input.signal?.throwIfAborted();
|
|
93
93
|
assertNoInlineSecretValues(input, parsedWorkspace);
|
|
94
|
-
|
|
95
|
-
throw new Error("Tangle create providerOptions are not supported");
|
|
96
|
-
}
|
|
94
|
+
const requestedRouting = createRoutingFromProviderOptions(input.providerOptions);
|
|
97
95
|
if (Object.hasOwn(input.metadata ?? {}, PROXY_SECRETS_METADATA_KEY)) {
|
|
98
96
|
throw new Error("Tangle owns metadata.tangleProxySecrets");
|
|
99
97
|
}
|
|
@@ -139,6 +137,11 @@ export function createTangleProvider(options) {
|
|
|
139
137
|
requireProxySecretCapability(peerCapabilities, selectedProxySecrets);
|
|
140
138
|
}
|
|
141
139
|
assertMappedCreateOptions(mappedOptions);
|
|
140
|
+
// A custom mapper builds its own backend; requested routing must survive it.
|
|
141
|
+
const mappedRouting = mappedOptions.backend?.routing ?? mappedOptions.backend?.model?.routing;
|
|
142
|
+
if (canonicalCandidateDigest(mappedRouting ?? null) !== canonicalCandidateDigest(requestedRouting ?? null)) {
|
|
143
|
+
throw new Error("Tangle mapped create options must carry exactly the requested providerOptions.routing");
|
|
144
|
+
}
|
|
142
145
|
if (Object.hasOwn(mappedOptions.metadata ?? {}, "modelCredentials") &&
|
|
143
146
|
(!subscription || selectedCredentials === undefined ||
|
|
144
147
|
canonicalCandidateDigest(mappedOptions.metadata?.modelCredentials) !== canonicalCandidateDigest(selectedCredentials))) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/agent-provider-tangle",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@tangle-network/agent-interface": "^5.6.1"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@tangle-network/sandbox": ">=0.60.
|
|
39
|
+
"@tangle-network/sandbox": ">=0.60.88 <1.0.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependenciesMeta": {
|
|
42
42
|
"@tangle-network/sandbox": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@tangle-network/agent-provider-testkit": "0.12.0",
|
|
48
48
|
"@tangle-network/agent-runtime": "0.292.3",
|
|
49
|
-
"@tangle-network/sandbox": "0.60.
|
|
49
|
+
"@tangle-network/sandbox": "0.60.88",
|
|
50
50
|
"@types/node": "26.6.3",
|
|
51
51
|
"typescript": "7.0.2",
|
|
52
52
|
"vitest": "5.0.2"
|