@tangle-network/agent-provider-tangle 5.0.0 → 5.0.2

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.
@@ -182,10 +182,6 @@ function exactSandboxOptions(input, defaults, providerName, identityDigest) {
182
182
  input.provisionTimeoutMs < 1)) {
183
183
  throw new Error("exact process provisionTimeoutMs must be a positive integer");
184
184
  }
185
- if (input.egress.mode === "strict" &&
186
- input.egress.allowDomains.length === 0) {
187
- throw new Error("strict exact process egress requires at least one domain");
188
- }
189
185
  const resources = sandboxResourcesFromRequest(input.resources);
190
186
  return {
191
187
  environment: input.image,
@@ -200,7 +196,7 @@ function exactSandboxOptions(input, defaults, providerName, identityDigest) {
200
196
  ? { mode: "blocked" }
201
197
  : {
202
198
  mode: "strict",
203
- allowDomains: [...input.egress.allowDomains],
199
+ allowDomains: input.egress.allowDomains.map((e) => typeof e === "string" ? e : { ...e, allowPrivateIps: [...e.allowPrivateIps] }),
204
200
  includeImplicitDomains: false,
205
201
  },
206
202
  maxLifetimeSeconds: input.maxLifetimeMs / 1_000,
@@ -1,4 +1,4 @@
1
- import { canonicalCandidateDigest } from "@tangle-network/agent-interface";
1
+ import { AgentEnvironmentEgressAllowDomainSchema, canonicalCandidateDigest } from "@tangle-network/agent-interface";
2
2
  export const MAX_EXACT_FILE_BYTES = 64 * 1024 * 1024;
3
3
  export const MAX_LIST_RESULTS = 100_000;
4
4
  /** Sandbox caps list responses at 1,000 resources. */
@@ -50,6 +50,8 @@ export const MAX_INLINE_PAYLOAD_BYTES = 1024 * 1024 - 8 * 1024;
50
50
  */
51
51
  export const MAX_TOTAL_PAYLOAD_BYTES = 64 * 1024 * 1024;
52
52
  export const MAX_ARRAY_LENGTH = 1_024;
53
+ /** Strict exact-process egress: the interface entry shape, one to {@link MAX_ARRAY_LENGTH} entries. */
54
+ const EXACT_PROCESS_ALLOW_DOMAINS = AgentEnvironmentEgressAllowDomainSchema.array().min(1).max(MAX_ARRAY_LENGTH);
53
55
  export const MAX_MAP_ENTRIES = 256;
54
56
  export const MAX_JSON_DEPTH = 16;
55
57
  export const MAX_JSON_NODES = 8_192;
@@ -438,17 +440,9 @@ export function validateExactProcessCreateInput(input, providerName, options) {
438
440
  throw new Error("strict exact process egress has unsupported fields");
439
441
  }
440
442
  if (input.egress.mode === "strict") {
441
- if (!Array.isArray(input.egress.allowDomains)) {
442
- throw new Error("exact process egress allowDomains must be an array");
443
- }
444
- if (input.egress.allowDomains.length > MAX_ARRAY_LENGTH) {
445
- throw new Error("exact process egress allowDomains has too many entries");
446
- }
447
- if (input.egress.allowDomains.length === 0) {
448
- throw new Error("strict exact process egress requires at least one domain");
449
- }
450
- for (const domain of input.egress.allowDomains) {
451
- boundedIdentifier(domain, "exact process egress domain");
443
+ // The interface schema owns the entry shape; strict exact egress also needs one entry.
444
+ if (!EXACT_PROCESS_ALLOW_DOMAINS.safeParse(input.egress.allowDomains).success) {
445
+ throw new Error("strict exact process egress requires one to 1024 valid allowDomains entries");
452
446
  }
453
447
  }
454
448
  if (!Number.isSafeInteger(input.maxLifetimeMs) ||
@@ -1,6 +1,6 @@
1
1
  import { assertCliAuthReferenceSupported, cliAuthReferenceSchema, } from "@tangle-network/sandbox/auth";
2
2
  import { parseBackendType, } from "@tangle-network/sandbox";
3
- import { AgentEnvironmentEgressPolicySchema, WorkspaceRequestSchema, workspaceCwdPathForBase, } from "@tangle-network/agent-interface/environment-provider";
3
+ import { AgentEnvironmentEgressAllowDomainSchema, AgentEnvironmentEgressPolicySchema, WorkspaceRequestSchema, workspaceCwdPathForBase, } from "@tangle-network/agent-interface/environment-provider";
4
4
  import { assertBoundedJson, boundedIdentifier, boundedString, MAX_ARRAY_LENGTH, MAX_MAP_ENTRIES, PROFILE_AT_BACKEND_PROFILE, PROFILE_AT_ROOT, } from "./tangle-contract-safety.js";
5
5
  import { profileCredentialSource } from "./model-credential-source.js";
6
6
  import { sandboxResourcesFromResourceRequest } from "./tangle-resources.js";
@@ -383,18 +383,11 @@ export function assertMappedCreateOptions(options) {
383
383
  throw new Error("Tangle mapped egress policy allows domains only in strict mode");
384
384
  }
385
385
  // The default path is schema-checked, so this gate holds a custom mapper to the same shape.
386
- // A non-string or padded host reaches the platform, matches nothing, and leaves the caller
386
+ // A malformed or padded host reaches the platform, matches nothing, and leaves the caller
387
387
  // believing an allowlist is in force that is not.
388
- if (options.egressPolicy.allowDomains !== undefined) {
389
- if (!Array.isArray(options.egressPolicy.allowDomains)) {
390
- throw new Error("Tangle mapped egress allowed domains must be an array");
391
- }
392
- if (options.egressPolicy.allowDomains.length > MAX_ARRAY_LENGTH) {
393
- throw new Error("Tangle mapped egress allowed domains exceed their bound");
394
- }
395
- for (const domain of options.egressPolicy.allowDomains) {
396
- boundedIdentifier(domain, "Tangle mapped egress allowed domain");
397
- }
388
+ if (options.egressPolicy.allowDomains !== undefined &&
389
+ !AgentEnvironmentEgressAllowDomainSchema.array().max(MAX_ARRAY_LENGTH).safeParse(options.egressPolicy.allowDomains).success) {
390
+ throw new Error("Tangle mapped egress allowed domain is invalid");
398
391
  }
399
392
  }
400
393
  if (options.env !== undefined)
@@ -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 {};