@tangle-network/agent-provider-tangle 4.5.7 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -66,12 +66,17 @@ Aggregate limits, credential exclusions, and exact native-session proof remain e
66
66
  Capture lists no directory below a credential directory such as `.opencode` or `.config`: it records the directory as excluded and accounts for its subtree with one complete usage scan, so the workspace totals still reconcile.
67
67
  An unsupported downloader or incomplete transfer fails capture and preserves the source environment.
68
68
 
69
+ ## Profile credentials
70
+
71
+ Declare proxy-held credentials in `profile.proxySecrets` or create input `proxySecrets` using the same `ProxySecretsSchema`. The Provider forwards the full declaration unchanged, including aliases, destinations, methods, paths, presentation and expiry. Trusted Sandbox resolution owns tenant authorization, stored identity and proxy installation. The SDK transport must support the top-level canonical field.
72
+
73
+ Legacy stored names, `"all"` and host objects retain their delivery selection. The API binds known hosts or preserves prior delivery for unbound names; explicit canonical scope governs protected names. Explicit readable requests use the existing `{name, exposeInBox:true}` consent and `metadata.reason` or a retained store reason. A mapper cannot replace authored custody or erase its reason. Source and local HTTP proof do not establish deployed proxy enforcement.
74
+
69
75
  ## Named model credentials at creation
70
76
 
71
77
  `modelCredentials` sends a stored credential reference and explicit endpoint before Sandbox provisions the backend.
72
78
  This uses Sandbox's existing caller-owned model credential path instead of requesting a managed Router credential.
73
- The provider does not create, copy, or renew stored secrets.
74
- The Provider grants the selected reference at create, alongside unrelated caller-requested secrets. Qualified native selectors also grant their selected reference before each fresh turn.
79
+ The provider does not create, copy, or renew stored secrets. The Provider forwards the selected reference at create, alongside unrelated caller-requested secrets. Qualified native selectors also grant their selected reference before each fresh turn.
75
80
 
76
81
  ```ts
77
82
  const provider = createTangleProvider({
@@ -86,8 +91,7 @@ const environment = await provider.create({
86
91
  });
87
92
  ```
88
93
 
89
- The configuration accepts only the reference and endpoint, not credential values or model selection.
90
- The authored profile, selected backend, runtime attachments, and create identity remain unchanged.
94
+ The configuration accepts only the reference and endpoint, not credential values or model selection. The authored profile, selected backend, runtime attachments, and create identity remain unchanged.
91
95
  The provider snapshots this configuration when constructed and refuses combining it with `mapCreateInput`.
92
96
  Omitting it preserves managed creation.
93
97
  The endpoint must use HTTP or HTTPS without credentials, query parameters, or fragments.
@@ -147,20 +151,16 @@ The Provider validates native channels with the maintained CLI Registry before p
147
151
  Each selector must use the exact profile harness.
148
152
  Native execution also requires the selected container to report `cliAuthReferences: true`.
149
153
  A missing or unreadable capability refuses creation or dispatch before inference.
150
- A selector grants its one selected stored secret automatically, alongside unrelated secrets requested by the caller.
154
+ Native selectors retain their existing selected stored name beside unrelated requests; the native owner controls resolution and bundle delivery.
151
155
  Keep pool-wide account credentials out of the create input's `secrets` list.
152
- Static native references grant their selected secret only for subscription profiles.
153
- Static API references grant their selected secret for unmarked legacy profiles and subscription profiles.
154
- Inline environment values cannot shadow the selected stored secret.
155
- Undefined, malformed, unsupported, or failed subscription selections stop before Sandbox creation.
156
+ Static native references select their credential only for subscription profiles. Static API references grant their selected secret for unmarked legacy profiles and subscription profiles.
157
+ Inline environment values cannot shadow the selected stored secret. Undefined, malformed, unsupported, or failed subscription selections stop before Sandbox creation.
156
158
  Subscription failures never fall back to managed Router access.
157
159
 
158
- Sandbox metadata records the public selection under `modelCredentials`.
159
- This metadata key is reserved for the Provider selection.
160
+ Sandbox metadata records the public selection under `modelCredentials`. This metadata key is reserved for the Provider selection.
160
161
  Account labels are supplied bindings, not verified native principals.
161
162
  Token values and native credential files never enter that selection or receipt.
162
- A static native reference stays bound to its creation account and harness on every turn.
163
- Reconstructed environments recover that reference from persisted metadata and the observed backend.
163
+ A static native reference stays bound to its creation account and harness on every turn. Reconstructed environments recover that reference from persisted metadata and the observed backend.
164
164
 
165
165
  A resolver selects a bootstrap credential at creation and a durable binding for each fresh turn.
166
166
  Fresh turns require the exact inline subscription profile and a stable `turnId`.
@@ -30,8 +30,11 @@ 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
- /** Validate mapped stored names and bindings without resolving their values. */
34
- export declare function assertMappedSecretNames(options: TangleCreateSandboxOptions): void;
33
+ /** Preserve legacy stored selections while canonical declarations travel separately. */
34
+ export declare function assertMappedSecretNames(options: {
35
+ secrets?: unknown;
36
+ env?: Record<string, string>;
37
+ }): void;
35
38
  export declare function assertCreateInputShape(input: CreateAgentEnvironmentInput, parsedWorkspace?: WorkspaceRequest): WorkspaceRequest | undefined;
36
39
  export declare function assertMappedCreateOptions(options: TangleCreateSandboxOptions): void;
37
40
  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, sandboxSecretBindings } from "./tangle-proxy-secrets.js";
9
+ import { assertProxySecretAliases, captureProxySecrets, mergeProxySecrets, proxySecretsFromInput, sandboxSecretBindingIdentity } 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) {
@@ -99,9 +99,8 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
99
99
  ? parseBackendType(defaultBackend ?? profile.harness ?? "opencode")
100
100
  : input.backend;
101
101
  assertNoInlineSecretValues(input, workspace);
102
- const selectedSecret = modelCredentials === undefined ? undefined
103
- : "cliAuth" in modelCredentials ? modelCredentials.cliAuth?.secretEnv : modelCredentials.apiKeyEnv;
104
102
  const nativeCredentials = modelCredentials !== undefined && "cliAuth" in modelCredentials;
103
+ const selectedSecret = nativeCredentials ? modelCredentials.cliAuth?.secretEnv : modelCredentials?.apiKeyEnv;
105
104
  const proxySecrets = mergeProxySecrets(proxySecretsFromInput(input), modelCredentials?.proxySecrets);
106
105
  assertProxySecretAliases(proxySecrets, input.env, input.secrets);
107
106
  const proxySelected = proxySecrets?.some((binding) => binding.envName === selectedSecret || binding.secretRef.key === selectedSecret) === true ||
@@ -123,13 +122,11 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
123
122
  throw new Error("Tangle modelCredentials cannot shadow a stored secret with inline environment data");
124
123
  }
125
124
  const requestedSecrets = Array.isArray(input.secrets) ? input.secrets : undefined;
126
- const requestedSelection = selectedSecret !== undefined && !proxySelected
125
+ const secrets = input.secrets === "all" ? "all" : selectedSecret !== undefined && !proxySelected
127
126
  ? [...new Set([...(requestedSecrets ?? []), selectedSecret])]
128
127
  : requestedSecrets ?? (proxySecrets === undefined ? undefined : []);
129
- const secrets = sandboxSecretBindings(requestedSelection, proxySecrets, input.env);
130
- if (secrets !== undefined && secrets.length > MAX_ARRAY_LENGTH) {
128
+ if (Array.isArray(secrets) && secrets.length > MAX_ARRAY_LENGTH)
131
129
  throw new Error("Tangle selected credential exceeds the stored-secret grant bound");
132
- }
133
130
  const recordsCredential = nativeCredentials || subscriptionSelection;
134
131
  if (recordsCredential && Object.hasOwn(input.metadata ?? {}, "modelCredentials")) {
135
132
  throw new Error("Tangle credential selection owns metadata.modelCredentials");
@@ -193,7 +190,8 @@ export function sandboxOptionsFromCreateInput(input, defaultBackend, parsedWorks
193
190
  ...(resources ? { resources } : {}),
194
191
  ...(restore ?? {}),
195
192
  ...(input.env ? { env: input.env } : {}),
196
- ...(Array.isArray(secrets) ? { secrets } : {}),
193
+ ...(secrets === undefined ? {} : { secrets }),
194
+ ...(proxySecrets === undefined ? {} : { proxySecrets }),
197
195
  ...(input.egress === undefined ? {} : { egressPolicy: sandboxEgressPolicy(input.egress) }),
198
196
  ...(input.billingOwner === undefined ? {} : { billingOwnerId: input.billingOwner }),
199
197
  ...(Object.keys(metadata).length > 0 ? { metadata } : {}),
@@ -228,18 +226,7 @@ export function sandboxRestoreFromCheckpoint(checkpoint) {
228
226
  fromSandboxId: boundedIdentifier(checkpoint.source.environmentId, "Tangle workspace checkpoint source"),
229
227
  };
230
228
  }
231
- /**
232
- * Project the portable egress policy onto the Sandbox policy.
233
- *
234
- * The schema is a strict discriminated union, so a domain list outside `strict` is refused rather
235
- * than sent: Sandbox IGNORES `allowDomains` in `open` and `blocked` mode, and a silently ignored
236
- * allowlist is a policy the caller believes is in force and is not.
237
- *
238
- * `includeImplicitDomains` stays unset, which is the Sandbox default of false. A strict policy
239
- * therefore reaches the named domains plus the model endpoints the platform provisioned, matching
240
- * what {@link AgentEnvironmentEgressPolicy} states; opting in would silently add ~40 hosts,
241
- * including public source hosts.
242
- */
229
+ /** Strict allowlists remain exact; implicit domains stay disabled. */
243
230
  function sandboxEgressPolicy(policy) {
244
231
  const parsed = AgentEnvironmentEgressPolicySchema.parse(policy);
245
232
  if (parsed.mode !== "strict")
@@ -267,13 +254,31 @@ export function assertNoInlineSecretValues(input, parsedWorkspace) {
267
254
  throw new Error("Tangle resource providerOptions are not supported");
268
255
  }
269
256
  }
270
- sandboxSecretBindings(input.secrets, undefined, input.env);
257
+ assertMappedSecretNames(input);
271
258
  }
272
- /** Validate mapped stored names and bindings without resolving their values. */
259
+ /** Preserve legacy stored selections while canonical declarations travel separately. */
273
260
  export function assertMappedSecretNames(options) {
274
- if (options.secrets === "all")
275
- throw new Error("Tangle mapped secrets require explicit selection");
276
- sandboxSecretBindings(options.secrets, undefined, options.env);
261
+ const { secrets, env } = options;
262
+ if (secrets === undefined || secrets === "all")
263
+ return;
264
+ if (!Array.isArray(secrets) || secrets.length > MAX_ARRAY_LENGTH)
265
+ throw new Error("Tangle secrets require bounded explicit stored selection");
266
+ const selected = new Map();
267
+ for (const entry of secrets) {
268
+ const name = typeof entry === "string" ? entry : entry?.name;
269
+ boundedIdentifier(name, "Tangle stored-secret name");
270
+ if (typeof entry !== "string" && (!entry || Object.hasOwn(env ?? {}, name) || ("host" in entry
271
+ ? Object.keys(entry).some((key) => !["name", "host", "header"].includes(key)) ||
272
+ typeof entry.host !== "string" || entry.host.length > 253 ||
273
+ !/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(entry.host) ||
274
+ (entry.header !== undefined && (typeof entry.header !== "string" || !/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(entry.header)))
275
+ : Object.keys(entry).some((key) => !["name", "exposeInBox"].includes(key)) || entry.exposeInBox !== true)))
276
+ throw new Error("Invalid or shadowed Tangle secret selection");
277
+ const identity = sandboxSecretBindingIdentity(entry);
278
+ if (selected.has(name) && selected.get(name) !== identity)
279
+ throw new Error("Conflicting Tangle stored-secret selection");
280
+ selected.set(name, identity);
281
+ }
277
282
  }
278
283
  export function assertCreateInputShape(input, parsedWorkspace) {
279
284
  if (!input || typeof input !== "object" || Array.isArray(input)) {
@@ -345,9 +350,9 @@ export function assertMappedCreateOptions(options) {
345
350
  throw new Error("Tangle mapped native credentials must use the exact profile harness");
346
351
  }
347
352
  const selectedSecret = options.backend.model.cliAuth.secretEnv;
348
- if (!Array.isArray(options.secrets) || !options.secrets.some((entry) => (typeof entry === "string" ? entry : entry.name) === selectedSecret)) {
349
- throw new Error("Tangle mapped native credential must be explicitly listed in create secrets");
350
- }
353
+ if (options.secrets !== "all" && !(Array.isArray(options.secrets) && options.secrets.some((entry) => (typeof entry === "string" ? entry : entry.name) === selectedSecret)) &&
354
+ !options.proxySecrets?.some((binding) => binding.envName === selectedSecret || binding.secretRef.key === selectedSecret))
355
+ throw new Error("Tangle mapped native credential must retain its stored selection");
351
356
  if (Object.hasOwn(options.env ?? {}, selectedSecret)) {
352
357
  throw new Error("Tangle mapped native credential cannot shadow a stored secret with inline environment data");
353
358
  }
@@ -1,3 +1,4 @@
1
1
  import type { AgentSessionRef, AgentTurnInput } from "@tangle-network/agent-interface/environment-provider";
2
+ import type { PromptOptions } from "@tangle-network/sandbox";
2
3
  import type { SandboxInstanceLike } from "./tangle-types.js";
3
- export declare function dispatchEnvironmentRun(box: SandboxInstanceLike, provider: string, environmentId: string): (input: AgentTurnInput) => Promise<AgentSessionRef>;
4
+ export declare function dispatchEnvironmentRun(box: SandboxInstanceLike, provider: string, environmentId: string, prepare: (options: PromptOptions) => Promise<PromptOptions>): (input: AgentTurnInput) => Promise<AgentSessionRef>;
@@ -1,8 +1,8 @@
1
- import { promptFromTurnInput, promptOptionsFromTurnInput, preparePromptOptions, } from "./tangle-prompt.js";
1
+ import { promptFromTurnInput, promptOptionsFromTurnInput, } from "./tangle-prompt.js";
2
2
  import { retainedSessionControlRef, sessionPromptExecutionId, sessionPromptSessionId, sessionRefFromSandboxDispatch, } from "./tangle-session-control.js";
3
3
  import { awaitWithSignal } from "./tangle-contract-safety.js";
4
4
  import { interruptAfterAbort, sessionPromptRequestDigest, } from "./tangle-environment-control.js";
5
- export function dispatchEnvironmentRun(box, provider, environmentId) {
5
+ export function dispatchEnvironmentRun(box, provider, environmentId, prepare) {
6
6
  return async (input) => {
7
7
  input.signal?.throwIfAborted();
8
8
  const options = promptOptionsFromTurnInput(input, { provider, environmentId });
@@ -23,12 +23,12 @@ export function dispatchEnvironmentRun(box, provider, environmentId) {
23
23
  }
24
24
  }
25
25
  const runControlRef = retainedSessionControlRef(expectedSessionId, expectedExecutionId, provider, environmentId, requestDigest, callerControlRef?.runId);
26
- const promise = box.dispatchPrompt?.(promptFromTurnInput(input), await preparePromptOptions(box, {
26
+ const promise = box.dispatchPrompt?.(promptFromTurnInput(input), await prepare({
27
27
  ...options,
28
28
  sessionId: expectedSessionId,
29
29
  executionId: expectedExecutionId,
30
30
  runControlRef,
31
- }, provider));
31
+ }));
32
32
  let dispatched;
33
33
  try {
34
34
  dispatched = await awaitWithSignal(promise, input.signal);
@@ -1,7 +1,7 @@
1
1
  import type { AgentSession, AgentSessionRef, AgentTurnInput } from "@tangle-network/agent-interface/environment-provider";
2
2
  import type { AgentExactRunControlRef, AgentRunControlRef } from "@tangle-network/agent-interface";
3
- import type { SandboxEvent } from "@tangle-network/sandbox";
4
- import type { SandboxInstanceLike, SandboxSessionLike } from "./tangle-types.js";
3
+ import type { SandboxEvent, PromptOptions } from "@tangle-network/sandbox";
4
+ import type { SandboxSessionLike } from "./tangle-types.js";
5
5
  import type { ExecutionUsageLog } from "./tangle-usage-log.js";
6
6
  type ExactExecutionEventStream = (options: {
7
7
  sessionId: string;
@@ -10,18 +10,6 @@ type ExactExecutionEventStream = (options: {
10
10
  signal?: AbortSignal;
11
11
  controlRef?: AgentExactRunControlRef;
12
12
  }) => AsyncIterable<SandboxEvent>;
13
- /**
14
- * @param retainedControl Whether the environment's narrowed capability
15
- * document grants retained control. Canonical cancellation is offered only
16
- * under that grant: a `cancelRun` method the deployment does not honor is an
17
- * action the caller selects and finds rejected on the wire.
18
- * @param interactionResponses Whether the environment's narrowed capability
19
- * document claims interaction responses. The method is offered only under
20
- * that claim, so a caller never selects an answer the deployment cannot
21
- * record.
22
- * @param usageLog Sink for the token usage each execution measured. The
23
- * environment observation reads it, because Sandbox reports usage per
24
- * execution result and never for the environment.
25
- */
26
- export declare function sandboxSessionAsAgentSession(session: SandboxSessionLike, controlRef: AgentRunControlRef | undefined, provider: string, environmentId: string, dispatch: ((input: AgentTurnInput) => Promise<AgentSessionRef>) | undefined, exactExecutionEvents: ExactExecutionEventStream | undefined, retainedControl: boolean, interactionResponses: boolean, usageLog?: ExecutionUsageLog, nativeContinuation?: boolean, beforePrompt?: (input: AgentTurnInput) => AgentTurnInput | void | Promise<AgentTurnInput | void>, onExecution?: (executionId: string) => void, box?: SandboxInstanceLike): AgentSession;
13
+ /** Compose exact session control, replay, prompt preparation and usage. */
14
+ export declare function sandboxSessionAsAgentSession(session: SandboxSessionLike, controlRef: AgentRunControlRef | undefined, provider: string, environmentId: string, dispatch: ((input: AgentTurnInput) => Promise<AgentSessionRef>) | undefined, exactExecutionEvents: ExactExecutionEventStream | undefined, retainedControl: boolean, interactionResponses: boolean, usageLog?: ExecutionUsageLog, nativeContinuation?: boolean, beforePrompt?: (input: AgentTurnInput) => AgentTurnInput | void | Promise<AgentTurnInput | void>, onExecution?: (executionId: string) => void, prepareOptions?: (options: PromptOptions) => Promise<PromptOptions>): AgentSession;
27
15
  export {};