@tangle-network/agent-provider-tangle 5.0.9 → 5.0.10

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.
@@ -1,6 +1,7 @@
1
1
  import { AgentInteractiveSessionAttachSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionControlClaimAcknowledgementSchema, AgentInteractiveSessionControlClaimRequestSchema, AgentInteractiveSessionPromptAcknowledgementSchema, AgentInteractiveSessionPromptCommandSchema, AgentInteractiveSessionRefSchema, AgentInteractiveSessionStatusSchema, AgentInteractiveSessionStopAcknowledgementSchema, AgentInteractiveSessionStopCommandSchema, TerminalReplayWindowSchema, TerminalSessionRefSchema, agentInteractiveSessionControlClaimAcknowledgementMatchesRequest, agentInteractiveSessionControlClaimMatchesRef, agentInteractiveSessionPromptAcknowledgementMatchesCommand, agentInteractiveSessionRefMatchesStart, agentInteractiveSessionStatusMatchesRef, agentInteractiveSessionStopAcknowledgementMatchesCommand, canonicalCandidateDigest, exactAgentInteractiveSessionStart, } from "@tangle-network/agent-interface";
2
2
  import { assertOptionKeys } from "./tangle-environment-validation.js";
3
3
  import { transportFailureReason } from "./tangle-failure-reason.js";
4
+ import { notLiveState } from "./tangle-readiness.js";
4
5
  /**
5
6
  * Test the linked SDK surface without accepting any older interactive shape.
6
7
  *
@@ -212,15 +213,15 @@ export function createTangleInteractiveAgentRegistry(box, providerName, environm
212
213
  assertOptionKeys(options, ["signal"], "Tangle interactive agent stop");
213
214
  const exactCommand = AgentInteractiveSessionStopCommandSchema.parse(command);
214
215
  assertRef(ref, exactCommand.ref);
215
- await validateControl(exactCommand.control, options);
216
- let raw;
217
- try {
218
- raw = await mutationHandle(exactCommand.control).stop(exactCommand, options);
219
- }
220
- catch (error) {
221
- options?.signal?.throwIfAborted();
222
- throw new Error(transportFailureReason("interactive stop", error));
223
- }
216
+ const raw = await stopOrNotLive(box, exactCommand, options?.signal, async () => {
217
+ await validateControl(exactCommand.control, options);
218
+ return await mutationHandle(exactCommand.control)
219
+ .stop(exactCommand, options)
220
+ .catch((error) => {
221
+ options?.signal?.throwIfAborted();
222
+ throw new Error(transportFailureReason("interactive stop", error));
223
+ });
224
+ });
224
225
  options?.signal?.throwIfAborted();
225
226
  const acknowledgement = AgentInteractiveSessionStopAcknowledgementSchema.parse(raw);
226
227
  if (!agentInteractiveSessionStopAcknowledgementMatchesCommand(exactCommand, acknowledgement)) {
@@ -232,6 +233,20 @@ export function createTangleInteractiveAgentRegistry(box, providerName, environm
232
233
  },
233
234
  };
234
235
  }
236
+ /** A stop against a failed or deleted sandbox is acknowledged not_live; any other failure stands. */
237
+ async function stopOrNotLive(box, command, signal, attempt) {
238
+ try {
239
+ return await attempt();
240
+ }
241
+ catch (error) {
242
+ signal?.throwIfAborted();
243
+ const gone = await notLiveState(box, signal);
244
+ if (gone === undefined)
245
+ throw error;
246
+ const { operationId, requestDigest, ref, control } = command;
247
+ return { operationId, requestDigest, ref, control, status: "accepted", effect: "not_live", message: `sandbox ${gone}` };
248
+ }
249
+ }
235
250
  function isSandboxInteractiveSession(value) {
236
251
  if (value === null || typeof value !== "object")
237
252
  return false;
@@ -1,5 +1,5 @@
1
1
  import type { AgentEnvironmentProvider } from "@tangle-network/agent-interface/environment-provider";
2
2
  type ProfileValidator = NonNullable<AgentEnvironmentProvider["validateProfile"]>;
3
- /** The provider's validateProfile: the Sandbox mount check, then any caller-supplied validator. */
3
+ /** The provider's validateProfile: the Sandbox mount check and pre-box verdict, then any caller-supplied validator. */
4
4
  export declare function tangleProfileValidator(supplied?: ProfileValidator): ProfileValidator;
5
5
  export {};
@@ -1,9 +1,6 @@
1
+ import * as Sandbox from "@tangle-network/sandbox";
1
2
  import { splitInlineProfileFileMounts, validateDeferredProfileFileMounts } from "@tangle-network/sandbox";
2
- /**
3
- * The Sandbox SDK's own create-time check of a profile's inline file mounts, run before any box
4
- * exists. create() refuses the same input, but only once a caller has already committed to the
5
- * spawn; a coordinator that checks first can return the refusal to whoever asked for the worker.
6
- */
3
+ /** The Sandbox SDK's create-time check of a profile's inline file mounts, run before any box exists. */
7
4
  function profileFileMountIssues(profile) {
8
5
  if (typeof profile === "string")
9
6
  return [];
@@ -24,10 +21,20 @@ function profileFileMountIssues(profile) {
24
21
  }];
25
22
  }
26
23
  }
27
- /** The provider's validateProfile: the Sandbox mount check, then any caller-supplied validator. */
24
+ /** Sandbox's pre-box verdict where the SDK ships it; oversize only warns: this provider stages a large profile's files. */
25
+ function profileVerdictIssues(profile) {
26
+ const verdict = Sandbox.validateProfileForCreate;
27
+ const harness = typeof profile === "string" ? undefined : profile.harness;
28
+ const result = verdict && harness ? verdict(profile, harness) : undefined;
29
+ if (!result || result.ok || !result.error)
30
+ return [];
31
+ const code = result.error.code ?? "PROFILE_UNSUPPORTED";
32
+ return [{ level: code === "PAYLOAD_TOO_LARGE" ? "warning" : "error", code, message: result.error.message }];
33
+ }
34
+ /** The provider's validateProfile: the Sandbox mount check and pre-box verdict, then any caller-supplied validator. */
28
35
  export function tangleProfileValidator(supplied) {
29
36
  return async (profile) => {
30
- const issues = profileFileMountIssues(profile);
37
+ const issues = [...profileFileMountIssues(profile), ...profileVerdictIssues(profile)];
31
38
  const result = supplied ? await supplied(profile) : undefined;
32
39
  return {
33
40
  ok: !issues.some((issue) => issue.level === "error") && (result?.ok ?? true),
@@ -10,7 +10,7 @@ import { captureProxySecrets, mergeProxySecrets, proxySecretsFromInput, assertPr
10
10
  import { statusFromUnknown } from "./tangle-environment-values.js";
11
11
  import { normalizeTangleBackend } from "./tangle-prompt.js";
12
12
  import { requireNativeCaptureCapability, requireNativeCaptureProof } from "./tangle-native-capture-proof.js";
13
- import { awaitSandboxRunning, DEFAULT_TANGLE_READY_TIMEOUT_MS, } from "./tangle-readiness.js";
13
+ import { awaitSandboxRunning, DEFAULT_TANGLE_READY_TIMEOUT_MS, servedSandbox, } from "./tangle-readiness.js";
14
14
  import { profileCredentialSource } from "./model-credential-source.js";
15
15
  import { requestedResourceProfile } from "./tangle-resources.js";
16
16
  import { assertBoundedJson, attachCleanupHandle, awaitWithSignal, boundedIdentifier, boundedString, MAX_LIST_RESULTS, PROFILE_AT_ROOT, SANDBOX_LIST_PAGE_SIZE, } from "./tangle-contract-safety.js";
@@ -382,7 +382,7 @@ export function createTangleProvider(options) {
382
382
  boundedIdentifier(id, "Tangle environment id");
383
383
  await resolveCapabilities();
384
384
  operation?.signal?.throwIfAborted();
385
- const box = await awaitWithSignal(options.client.get?.(id, operation?.signal ? { signal: operation.signal } : undefined), operation?.signal);
385
+ const box = await awaitWithSignal(servedSandbox(options.client, id, operation?.signal), operation?.signal);
386
386
  operation?.signal?.throwIfAborted();
387
387
  if (!box || boundedIdentifier(box.id, "Tangle environment id") !== id)
388
388
  return null;
@@ -17,21 +17,6 @@ export declare const DEFAULT_TANGLE_READY_TIMEOUT_MS = 120000;
17
17
  * filesystem is still being built until then. An environment composed before
18
18
  * that is an environment that cannot accept a turn.
19
19
  *
20
- * WHAT THIS WAIT IS NOT FOR. An earlier version of this comment claimed the
21
- * wait also closed the platform's "A sandbox lifecycle operation is already in
22
- * progress", and that claim is withdrawn: measured 2026-09-01 (issue #280),
23
- * that refusal comes from `DELETE /v1/sandboxes/:id`, not from a turn. The
24
- * platform guards exactly three routes with the per-sandbox lifecycle lease —
25
- * resume, stop and delete — and the runtime path a prompt takes is not one of
26
- * them, so no readiness wait here can prevent it and none is trying to. The
27
- * collision is answered where it happens, in `destroy()`
28
- * (`tangle-environment.ts`).
29
- *
30
- * Readiness also decides what the environment can claim. Composing an
31
- * environment reads the sandbox's deployment capability document once, and a
32
- * sandbox that is not yet running cannot answer that read, so an environment
33
- * composed during provisioning claims nothing for the rest of its life.
34
- *
35
20
  * The platform owns the wait, and this adapter runs no status loop of its own.
36
21
  * `waitFor` on the created instance is preferred because it refreshes that
37
22
  * instance in place, which keeps the create receipt and gains the runtime
@@ -41,3 +26,12 @@ export declare function awaitSandboxRunning(box: SandboxInstanceLike, client: Sa
41
26
  timeoutMs: number;
42
27
  signal?: AbortSignal;
43
28
  }): Promise<void>;
29
+ /**
30
+ * The state of a box the Sandbox API no longer serves: "deleted" for a 404,
31
+ * or the "failed"/"deleted" status it reports. Runtime replaces such a box,
32
+ * so reconnect and stop answer not-live instead of throwing. Any other
33
+ * refresh error (5xx, network) is not evidence the box is gone: undefined.
34
+ */
35
+ export declare function notLiveState(box: SandboxInstanceLike, signal?: AbortSignal): Promise<"failed" | "deleted" | undefined>;
36
+ /** Reconnect lookup: null for a box the Sandbox API answers 404, failed or deleted. */
37
+ export declare function servedSandbox(client: SandboxClientLike, id: string, signal?: AbortSignal): Promise<SandboxInstanceLike | null>;
@@ -18,21 +18,6 @@ export const DEFAULT_TANGLE_READY_TIMEOUT_MS = 120_000;
18
18
  * filesystem is still being built until then. An environment composed before
19
19
  * that is an environment that cannot accept a turn.
20
20
  *
21
- * WHAT THIS WAIT IS NOT FOR. An earlier version of this comment claimed the
22
- * wait also closed the platform's "A sandbox lifecycle operation is already in
23
- * progress", and that claim is withdrawn: measured 2026-09-01 (issue #280),
24
- * that refusal comes from `DELETE /v1/sandboxes/:id`, not from a turn. The
25
- * platform guards exactly three routes with the per-sandbox lifecycle lease —
26
- * resume, stop and delete — and the runtime path a prompt takes is not one of
27
- * them, so no readiness wait here can prevent it and none is trying to. The
28
- * collision is answered where it happens, in `destroy()`
29
- * (`tangle-environment.ts`).
30
- *
31
- * Readiness also decides what the environment can claim. Composing an
32
- * environment reads the sandbox's deployment capability document once, and a
33
- * sandbox that is not yet running cannot answer that read, so an environment
34
- * composed during provisioning claims nothing for the rest of its life.
35
- *
36
21
  * The platform owns the wait, and this adapter runs no status loop of its own.
37
22
  * `waitFor` on the created instance is preferred because it refreshes that
38
23
  * instance in place, which keeps the create receipt and gains the runtime
@@ -62,11 +47,7 @@ export async function awaitSandboxRunning(box, client, options) {
62
47
  throw error;
63
48
  throw new Error(`Tangle sandbox ${box.id} did not reach running: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
64
49
  }
65
- // A wait that resolves is the platform's answer, and the status it leaves
66
- // behind is that answer in a readable form. Reading it back costs nothing
67
- // and refuses a client whose wait resolves over a sandbox that is not
68
- // running, which is the one way a half-started environment could still
69
- // reach the caller.
50
+ // A client whose wait resolves over a sandbox that is not running is refused here.
70
51
  assertRunning(box, observed, "its wait resolved without reaching running");
71
52
  }
72
53
  function assertRunning(box, status, reason) {
@@ -98,3 +79,30 @@ function waitForRunning(box, client, options) {
98
79
  }
99
80
  return undefined;
100
81
  }
82
+ /**
83
+ * The state of a box the Sandbox API no longer serves: "deleted" for a 404,
84
+ * or the "failed"/"deleted" status it reports. Runtime replaces such a box,
85
+ * so reconnect and stop answer not-live instead of throwing. Any other
86
+ * refresh error (5xx, network) is not evidence the box is gone: undefined.
87
+ */
88
+ export async function notLiveState(box, signal) {
89
+ try {
90
+ await box.refresh?.(signal);
91
+ }
92
+ catch (error) {
93
+ return error?.status === 404 ? "deleted" : undefined;
94
+ }
95
+ return box.status === "failed" || box.status === "deleted" ? box.status : undefined;
96
+ }
97
+ /** Reconnect lookup: null for a box the Sandbox API answers 404, failed or deleted. */
98
+ export async function servedSandbox(client, id, signal) {
99
+ try {
100
+ const box = await client.get?.(id, signal ? { signal } : undefined);
101
+ return box && box.status !== "failed" && box.status !== "deleted" ? box : null;
102
+ }
103
+ catch (error) {
104
+ if (error?.status === 404)
105
+ return null;
106
+ throw error;
107
+ }
108
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-provider-tangle",
3
- "version": "5.0.9",
3
+ "version": "5.0.10",
4
4
  "description": "AgentEnvironmentProvider adapter for Tangle sandboxes",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -46,7 +46,7 @@
46
46
  "devDependencies": {
47
47
  "@tangle-network/agent-provider-testkit": "0.12.4",
48
48
  "@tangle-network/agent-runtime": "0.349.0",
49
- "@tangle-network/sandbox": "1.0.151",
49
+ "@tangle-network/sandbox": "1.0.216",
50
50
  "@types/node": "26.6.5",
51
51
  "typescript": "6.0.3",
52
52
  "vitest": "5.0.5"