@tangle-network/sandbox 0.69.10 → 0.69.12

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.
Files changed (77) hide show
  1. package/dist/agent/index.d.ts +4 -4
  2. package/dist/agent/index.js +5 -5
  3. package/dist/agent/preview.d.ts +1 -1
  4. package/dist/agent/preview.js +3 -3
  5. package/dist/{agent-run-outcome-B5CzWxw4.d.ts → agent-run-outcome-BuebRCWr.d.ts} +2 -2
  6. package/dist/{api-request-D1UVNo16.js → api-request-EseiF9B1.js} +1 -1
  7. package/dist/auth/index.d.ts +2 -2
  8. package/dist/auth/index.js +1 -1
  9. package/dist/browser-interactive-control-controller-Bt1vcu9c.js +4045 -0
  10. package/dist/{browser-interactive-control-controller-SI9hV6r5.d.ts → browser-interactive-control-controller-CVnME80O.d.ts} +5 -7
  11. package/dist/{chunked-upload-l6b9AWFA.js → chunked-upload-Df_5Q2x8.js} +1 -1
  12. package/dist/{chunked-upload-file-CLwAeLrM.js → chunked-upload-file-Dtm1GBkE.js} +2 -2
  13. package/dist/cli-auth-bundle-f2pt7sVA.js +2593 -0
  14. package/dist/{client-qjA1hNOp.js → client-BR_aABY2.js} +11 -11
  15. package/dist/{client-BGm6cw7B.d.ts → client-BWnbrifs.d.ts} +30 -32
  16. package/dist/collaboration/index.d.ts +1 -1
  17. package/dist/collaboration/index.js +1 -1
  18. package/dist/{collaboration-BwLNv6sy.js → collaboration-BTGTf3We.js} +1 -1
  19. package/dist/{core-CG7T2arO.js → core-DeXa_YQ2.js} +5 -4
  20. package/dist/core.d.ts +6 -6
  21. package/dist/core.js +5 -5
  22. package/dist/{direct-http2-Pyj3Rvr1.js → direct-http2-B0ra_xhU.js} +1 -1
  23. package/dist/{errors-Bs5G7JdV.js → errors-ZmDrrk4f.js} +1 -1
  24. package/dist/harness-BD_OISom.js +201 -0
  25. package/dist/harness-DWL2MM4q.js +418 -0
  26. package/dist/{index-nXob5TkM.d.ts → index-DdcCRDq8.d.ts} +14 -16
  27. package/dist/index.d.ts +11 -11
  28. package/dist/index.js +11 -11
  29. package/dist/intelligence/index.js +2 -2
  30. package/dist/interactive-control.d.ts +1 -1
  31. package/dist/interactive-control.js +1 -1
  32. package/dist/{interactive-controller-DSDEfapN.js → interactive-controller-B4bQwRJL.js} +21 -8
  33. package/dist/{interactive-controller-FgmcS8_Y.d.ts → interactive-controller-DlFKGQqu.d.ts} +3 -4
  34. package/dist/lib/prepared-evidence.js +1 -1
  35. package/dist/lib/prepared-process.js +1 -1
  36. package/dist/{lines-D_HDAcVt.js → lines-BqZOl_io.js} +1 -1
  37. package/dist/{lines-BoVYnUCM.d.ts → lines-ptj8SyD4.d.ts} +1 -1
  38. package/dist/lines.d.ts +1 -1
  39. package/dist/lines.js +1 -1
  40. package/dist/{local-cli-auth-YGra1QUA.js → local-cli-auth-Cpi3hT3j.js} +1 -1
  41. package/dist/{mcp-local-Gz1Uygqk.js → mcp-local-BcRLN_Ic.js} +1 -1
  42. package/dist/{prepared-evidence-DUmJSegi.js → prepared-evidence-CuUh_mz6.js} +1 -1
  43. package/dist/{preview-Vu5knAuf.d.ts → preview-ByTCKjiK.d.ts} +3 -3
  44. package/dist/profile-schema-CT3hB1mG.js +1135 -0
  45. package/dist/{public-templates-B6_uwnRZ.d.ts → public-templates-O2mxBX7J.d.ts} +2 -2
  46. package/dist/public-templates.d.ts +1 -1
  47. package/dist/public-templates.js +1 -1
  48. package/dist/{raw-evidence-archive-D60Yg1-5.js → raw-evidence-archive-CqarcYcp.js} +1 -1
  49. package/dist/runtime.d.ts +5 -5
  50. package/dist/runtime.js +5 -5
  51. package/dist/{sandbox-BulsMs3K.js → sandbox-B1ROfJxe.js} +384 -46
  52. package/dist/{secp256k1-DxHlUI6v.js → secp256k1-CZWrpqxW.js} +1 -1
  53. package/dist/select-seat-command.d.ts +1 -1
  54. package/dist/select-seat-command.js +1 -1
  55. package/dist/session-gateway/index.js +3 -3
  56. package/dist/sha2-BUPMvGTk.js +694 -0
  57. package/dist/tangle/index.d.ts +1 -1
  58. package/dist/tangle/index.js +1 -1
  59. package/dist/{tangle-DdzOPPJ9.js → tangle-q-3ualoW.js} +4 -4
  60. package/dist/terminal-stream-types-DwXQzUbH.d.ts +3328 -0
  61. package/dist/{types-CkLWX7i5.d.ts → types-B28t5Sq1.d.ts} +10 -12
  62. package/package.json +6 -6
  63. package/dist/browser-interactive-control-controller-CLHNi8rG.js +0 -292
  64. package/dist/cli-auth-bundle-DmaEJ_qh.js +0 -1590
  65. package/dist/terminal-stream-types-DuzvL1ge.d.ts +0 -676
  66. /package/dist/{abort-signal-BKVZNJul.js → abort-signal-jU-SEjLT.js} +0 -0
  67. /package/dist/{cli-auth-bundle-CeNOYFje.d.ts → cli-auth-bundle-MskLEgtA.d.ts} +0 -0
  68. /package/dist/{index-C0RkLba5.d.ts → index-Dqcr9p97.d.ts} +0 -0
  69. /package/dist/{index-DaIF4c9p.d.ts → index-Dslyq85a.d.ts} +0 -0
  70. /package/dist/{keep-alive-fetch-Bi-zvHpN.js → keep-alive-fetch-C2DX2_rG.js} +0 -0
  71. /package/dist/{prepared-process-Dlk_9JVJ.js → prepared-process-LjBfQnZ5.js} +0 -0
  72. /package/dist/{preview-operations-eTUlPen5.js → preview-operations-BvgwYaoL.js} +0 -0
  73. /package/dist/{response-rewrap-BKkJ5hnn.js → response-rewrap-MBztoTLx.js} +0 -0
  74. /package/dist/{retry-after-header-U_L5Ml9Q.js → retry-after-header-BZbs5rig.js} +0 -0
  75. /package/dist/{sidecar-proxy-error-B2Hxt41g.js → sidecar-proxy-error-Dty4zmN7.js} +0 -0
  76. /package/dist/{sse-parser-CUfurwcm.js → sse-parser-DmO5gP6u.js} +0 -0
  77. /package/dist/{utils-DB8DnUCU.js → utils-vaFoyyiO.js} +0 -0
@@ -1,8 +1,6 @@
1
- import { K as SandboxCreateReceipt, a as TerminalStreamOptions, g as TerminalReadyInfo, i as TerminalStreamHandlers, s as TerminalStreamToken, t as TerminalAttachTimings } from "./terminal-stream-types-DuzvL1ge.js";
2
- import { t as CliAuthReference } from "./cli-auth-bundle-CeNOYFje.js";
1
+ import { $ as PlanContinuation, F as AgentProfileCapabilities, I as AgentProfileConfidential, M as InteractionRequest, O as AgentExactRunControlRef, P as AgentProfile$1, Y as AgentProfileValidationResult, Z as ReasoningEffort, a as TerminalStreamOptions, ct as TerminalReadyInfo, d as SandboxSizePreset, dt as AgentProfile, f as AgentRuntimeAttachments, i as TerminalStreamHandlers, s as TerminalStreamToken, t as TerminalAttachTimings, zt as SandboxCreateReceipt } from "./terminal-stream-types-DwXQzUbH.js";
2
+ import { t as CliAuthReference } from "./cli-auth-bundle-MskLEgtA.js";
3
3
  import { z } from "zod";
4
- import * as _$_tangle_network_agent_interface0 from "@tangle-network/agent-interface";
5
- import { AgentExactRunControlRef, AgentProfile, AgentProfileCapabilities, AgentProfileConfidential, AgentProfileValidationResult, AgentRuntimeAttachments, PlanContinuation, ReasoningEffort, SandboxSizePreset } from "@tangle-network/agent-interface";
6
4
  //#region ../../../packages/runtime-contracts/dist/backend-types.d.ts
7
5
  /**
8
6
  * This distribution's backend vocabulary, declared positively. The shared
@@ -1894,7 +1892,7 @@ interface BackendConfig {
1894
1892
  * Use an `AgentProfile` object for an inline provider-neutral profile
1895
1893
  * definition.
1896
1894
  */
1897
- profile?: AgentProfile;
1895
+ profile?: AgentProfile$1;
1898
1896
  /**
1899
1897
  * Which model this backend runs. The model id has exactly one home per
1900
1898
  * config: `modelId` here, or the `model` shorthand on per-turn options
@@ -2152,7 +2150,7 @@ interface BackendManager {
2152
2150
  *
2153
2151
  * Optional while backends adopt the public `AgentProfile` contract.
2154
2152
  */
2155
- validateProfile?(profile: AgentProfile): Promise<AgentProfileValidationResult>;
2153
+ validateProfile?(profile: AgentProfile$1): Promise<AgentProfileValidationResult>;
2156
2154
  /** Restart the backend agent */
2157
2155
  restart(): Promise<void>;
2158
2156
  }
@@ -2338,7 +2336,7 @@ interface PromptResult {
2338
2336
  /** Set when `status === "awaiting_question"`. */
2339
2337
  question?: AgentQuestionRequest;
2340
2338
  /** Canonical request for any interaction that still needs a response. */
2341
- interaction?: _$_tangle_network_agent_interface0.InteractionRequest;
2339
+ interaction?: InteractionRequest;
2342
2340
  /** Set when `status === "awaiting_plan_decision"`. */
2343
2341
  plan?: DurablePlanSnapshot;
2344
2342
  /**
@@ -6068,7 +6066,7 @@ interface SandboxFleetAgentSpec {
6068
6066
  * skills, instructions, MCP servers and files into the agent's own harness
6069
6067
  * session. Defaults to `defaults.backend.profile`.
6070
6068
  */
6071
- profile?: AgentProfile | SandboxFleetProfileRef;
6069
+ profile?: AgentProfile$1 | SandboxFleetProfileRef;
6072
6070
  /** Runtime MCP bindings for this agent, separate from its profile. */
6073
6071
  runtimeAttachments?: AgentRuntimeAttachments;
6074
6072
  /** The agent's own task. `run()` sends it when called without a message. */
@@ -6924,7 +6922,7 @@ interface SentSessionMessage {
6924
6922
  runControlRef?: AgentExactRunControlRef;
6925
6923
  }
6926
6924
  /** Canonical portable profile attached to a task session. */
6927
- type TaskSessionProfile = AgentProfile & {
6925
+ type TaskSessionProfile = AgentProfile$1 & {
6928
6926
  name: string;
6929
6927
  };
6930
6928
  /** Options for creating an isolated background task session. */
@@ -7204,7 +7202,7 @@ type ConversationTurnResult = ((TurnDriveResult & {
7204
7202
  } | {
7205
7203
  state: "awaiting_input";
7206
7204
  executionId: string;
7207
- requests: _$_tangle_network_agent_interface0.InteractionRequest[];
7205
+ requests: InteractionRequest[];
7208
7206
  }) & {
7209
7207
  /** Trace id this pass sent as `x-tangle-trace-id`. */traceId?: string;
7210
7208
  };
@@ -7292,11 +7290,11 @@ type TurnDriveResult = {
7292
7290
  } | {
7293
7291
  state: "awaiting_question";
7294
7292
  question: AgentQuestionRequest;
7295
- interaction?: _$_tangle_network_agent_interface0.InteractionRequest;
7293
+ interaction?: InteractionRequest;
7296
7294
  result: Record<string, unknown>;
7297
7295
  } | {
7298
7296
  state: "awaiting_interaction";
7299
- interaction: _$_tangle_network_agent_interface0.InteractionRequest;
7297
+ interaction: InteractionRequest;
7300
7298
  result: Record<string, unknown>;
7301
7299
  } | {
7302
7300
  state: "running"; /** When the session began executing, if the runtime reported it. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/sandbox",
3
- "version": "0.69.10",
3
+ "version": "0.69.12",
4
4
  "description": "Client SDK for the Tangle Sandbox platform - build AI agent applications with dev containers",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -153,15 +153,15 @@
153
153
  "ws": "^8.22.0",
154
154
  "yjs": "13.6.30",
155
155
  "@products/sandbox-test-utils": "0.0.0",
156
- "@repo/shared": "0.0.0",
157
156
  "@tangle-network/agent-profile-materialize": "0.26.0",
158
- "@tangle-network/runtime-contracts": "0.19.0",
157
+ "@tangle-network/cli-agent-registry": "0.10.2",
158
+ "@repo/shared": "0.0.0",
159
159
  "@tangle-network/sse-core": "0.0.0",
160
- "@tangle-network/cli-agent-registry": "0.10.2"
160
+ "@tangle-network/runtime-contracts": "0.19.0"
161
161
  },
162
162
  "tangleRelease": {
163
- "sourceSha": "cfc5cbbea7aab2c33247cf8c1a561fea783d6d6e",
164
- "mergedAt": "2026-10-26T12:45:28-06:00"
163
+ "sourceSha": "02fcaa7cdd12f1cea201a8e929a7772232549e3e",
164
+ "mergedAt": "2026-10-26T14:54:59-06:00"
165
165
  },
166
166
  "scripts": {
167
167
  "build": "node scripts/build-dist.mjs",
@@ -1,292 +0,0 @@
1
- import { t as awaitWithAbort } from "./abort-signal-BKVZNJul.js";
2
- import { z } from "zod";
3
- import { AgentInteractiveSessionControlClaimAcknowledgementSchema, AgentInteractiveSessionControlClaimRequestSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionRefSchema, AgentInteractiveSessionStatusSchema, agentInteractiveSessionControlClaimAcknowledgementMatchesRequest, agentInteractiveSessionControlClaimMatchesRef, agentInteractiveSessionControlClaimRequestDigest } from "@tangle-network/agent-interface/environment-interactive-control";
4
- //#region ../../../packages/runtime-contracts/dist/interactive-session-control-http.js
5
- const interactiveSessionStatusResponseSchema = z.object({
6
- success: z.literal(true),
7
- data: z.object({ status: AgentInteractiveSessionStatusSchema }).strict()
8
- }).strict();
9
- const interactiveSessionControlClaimResponseSchema = z.object({
10
- success: z.literal(true),
11
- data: AgentInteractiveSessionControlClaimAcknowledgementSchema
12
- }).strict();
13
- const interactiveSessionControlReleaseBodySchema = z.object({
14
- ref: AgentInteractiveSessionRefSchema,
15
- control: AgentInteractiveSessionControlClaimSchema
16
- }).strict();
17
- const interactiveSessionControlReleaseResponseSchema = z.object({
18
- success: z.literal(true),
19
- data: z.object({ status: z.enum([
20
- "released",
21
- "already-released",
22
- "absent"
23
- ]) }).strict()
24
- }).strict();
25
- z.object({
26
- ref: AgentInteractiveSessionRefSchema,
27
- control: AgentInteractiveSessionControlClaimSchema
28
- }).strict();
29
- const interactiveSessionControlValidationResponseSchema = z.object({
30
- success: z.literal(true),
31
- data: z.object({ valid: z.literal(true) }).strict()
32
- }).strict();
33
- //#endregion
34
- //#region src/interactive-control-controller.ts
35
- /** A status response that cannot admit a terminal control claim. */
36
- var InteractiveSessionNotRunningError = class extends Error {
37
- constructor(status) {
38
- super("Interactive session is not running or has stale identity");
39
- this.status = status;
40
- this.name = "InteractiveSessionNotRunningError";
41
- }
42
- };
43
- /** Maximum time spent on bounded claim recovery and release cleanup. */
44
- const INTERACTIVE_CONTROL_CLEANUP_TIMEOUT_MS = 5e3;
45
- function randomId(prefix) {
46
- const cryptoApi = globalThis.crypto;
47
- if (cryptoApi && typeof cryptoApi.randomUUID === "function") return `${prefix}-${cryptoApi.randomUUID()}`;
48
- return `${prefix}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
49
- }
50
- /** Create a holder id for one in-memory interactive controller. */
51
- function createInteractiveControlHolderId(prefix = "interactive") {
52
- return randomId(prefix);
53
- }
54
- function assertInteractiveSessionRef(ref, options) {
55
- if (ref.run.sessionId !== options.sessionId || ref.incarnationId !== options.incarnationId || options.environmentId !== void 0 && ref.run.environmentId !== options.environmentId) throw new Error("Interactive session identity does not match this sandbox");
56
- }
57
- function assertActiveControlClaim(control) {
58
- const expiresAt = Date.parse(control.expiresAt);
59
- if (!Number.isFinite(expiresAt) || expiresAt <= Date.now()) throw new Error("Interactive control claim is stale");
60
- }
61
- function createCleanupScope(timeoutMs) {
62
- const controller = new AbortController();
63
- const timer = setTimeout(() => {
64
- controller.abort(new DOMException(`Interactive control cleanup timed out after ${timeoutMs}ms`, "TimeoutError"));
65
- }, timeoutMs);
66
- return {
67
- signal: controller.signal,
68
- dispose: () => clearTimeout(timer)
69
- };
70
- }
71
- function claimAcknowledgementMatchesRequest(ref, request, acknowledgement) {
72
- if (!agentInteractiveSessionControlClaimAcknowledgementMatchesRequest(request, acknowledgement)) return false;
73
- if (acknowledgement.status !== "accepted" && acknowledgement.status !== "replayed") return true;
74
- return acknowledgement.control !== void 0 && agentInteractiveSessionControlClaimMatchesRef(ref, acknowledgement.control) && acknowledgement.control.holderId === request.holderId;
75
- }
76
- /**
77
- * Own the one status → claim → release sequence shared by browser and SDK callers.
78
- *
79
- * This module deliberately has no terminal or WebSocket dependency. Attach-capable
80
- * callers extend it with the stream operation after a claim has been resolved.
81
- */
82
- var InteractiveSessionControlController = class {
83
- operationIdFactory;
84
- cleanupTimeoutMs;
85
- resolveInFlight;
86
- constructor(transport, options) {
87
- this.transport = transport;
88
- this.options = options;
89
- this.operationIdFactory = options.operationIdFactory ?? (() => randomId("interactive-claim"));
90
- this.cleanupTimeoutMs = options.cleanupTimeoutMs ?? 5e3;
91
- if (!Number.isFinite(this.cleanupTimeoutMs) || this.cleanupTimeoutMs <= 0) throw new RangeError("Interactive control cleanup timeout must be greater than zero");
92
- }
93
- async safelyReleaseClaim(identity) {
94
- const cleanupScope = createCleanupScope(this.cleanupTimeoutMs);
95
- try {
96
- await awaitWithAbort(this.release(identity, { signal: cleanupScope.signal }), cleanupScope.signal);
97
- } catch {} finally {
98
- cleanupScope.dispose();
99
- }
100
- }
101
- /**
102
- * Recover a claim whose response or commit may have been lost or corrupted.
103
- *
104
- * The same operation id and digest make this replay idempotent. Recovery uses
105
- * an independent bounded signal so caller abort cannot strand an invisible claim.
106
- */
107
- async recoverAmbiguousClaim(ref, request) {
108
- const cleanupScope = createCleanupScope(this.cleanupTimeoutMs);
109
- try {
110
- const acknowledgement = AgentInteractiveSessionControlClaimAcknowledgementSchema.parse(await awaitWithAbort(this.transport.claimControl(this.options.sessionId, request, { signal: cleanupScope.signal }), cleanupScope.signal));
111
- if ((acknowledgement.status === "accepted" || acknowledgement.status === "replayed") && acknowledgement.control !== void 0 && claimAcknowledgementMatchesRequest(ref, request, acknowledgement) && agentInteractiveSessionControlClaimMatchesRef(ref, acknowledgement.control)) await this.safelyReleaseClaim({
112
- ref,
113
- control: acknowledgement.control
114
- });
115
- } catch {} finally {
116
- cleanupScope.dispose();
117
- }
118
- }
119
- /** Release one claim that this controller resolved. */
120
- async release(identity, requestOptions) {
121
- requestOptions?.signal?.throwIfAborted();
122
- const exactRef = AgentInteractiveSessionRefSchema.parse(identity.ref);
123
- assertInteractiveSessionRef(exactRef, this.options);
124
- if (!agentInteractiveSessionControlClaimMatchesRef(exactRef, identity.control)) throw new Error("Interactive control claim is not bound to the session");
125
- await this.transport.releaseControl(this.options.sessionId, exactRef, identity.control, requestOptions);
126
- }
127
- /** Observe and claim the current exact process incarnation. */
128
- async resolve(requestOptions) {
129
- requestOptions?.signal?.throwIfAborted();
130
- if (this.resolveInFlight !== void 0) return await awaitWithAbort(this.resolveInFlight, requestOptions?.signal);
131
- const operation = this.resolveInternal(requestOptions);
132
- let tracked;
133
- tracked = operation.finally(() => {
134
- if (this.resolveInFlight === tracked) this.resolveInFlight = void 0;
135
- });
136
- this.resolveInFlight = tracked;
137
- return await tracked;
138
- }
139
- async resolveInternal(requestOptions) {
140
- let claimedIdentity;
141
- try {
142
- requestOptions?.signal?.throwIfAborted();
143
- const status = await this.transport.status(this.options.sessionId, this.options.incarnationId, requestOptions);
144
- requestOptions?.signal?.throwIfAborted();
145
- if (status?.state !== "running") throw new InteractiveSessionNotRunningError(status);
146
- const ref = AgentInteractiveSessionRefSchema.parse(status.ref);
147
- assertInteractiveSessionRef(ref, this.options);
148
- let expectedGeneration = 1;
149
- for (let attempt = 0; attempt < 2; attempt += 1) {
150
- requestOptions?.signal?.throwIfAborted();
151
- const material = {
152
- operationId: this.operationIdFactory(),
153
- ref,
154
- holderId: this.options.holderId,
155
- expectedGeneration
156
- };
157
- const request = AgentInteractiveSessionControlClaimRequestSchema.parse({
158
- ...material,
159
- requestDigest: agentInteractiveSessionControlClaimRequestDigest(material)
160
- });
161
- let acknowledgement;
162
- try {
163
- acknowledgement = AgentInteractiveSessionControlClaimAcknowledgementSchema.parse(await this.transport.claimControl(this.options.sessionId, request, requestOptions));
164
- } catch (error) {
165
- await this.recoverAmbiguousClaim(ref, request);
166
- throw error;
167
- }
168
- if (!claimAcknowledgementMatchesRequest(ref, request, acknowledgement)) {
169
- await this.recoverAmbiguousClaim(ref, request);
170
- throw new Error("Interactive control claim acknowledgement does not match the request");
171
- }
172
- if ((acknowledgement.status === "accepted" || acknowledgement.status === "replayed") && acknowledgement.control) {
173
- if (!agentInteractiveSessionControlClaimMatchesRef(ref, acknowledgement.control)) throw new Error("Interactive control claim is not bound to the session");
174
- claimedIdentity = {
175
- ref,
176
- control: acknowledgement.control
177
- };
178
- requestOptions?.signal?.throwIfAborted();
179
- assertActiveControlClaim(acknowledgement.control);
180
- return claimedIdentity;
181
- }
182
- requestOptions?.signal?.throwIfAborted();
183
- if (acknowledgement.status === "conflict" && acknowledgement.conflictReason === "generation_mismatch" && acknowledgement.currentGeneration !== void 0 && acknowledgement.currentGeneration > expectedGeneration) {
184
- expectedGeneration = acknowledgement.currentGeneration;
185
- continue;
186
- }
187
- throw new Error(acknowledgement.message ?? "Interactive control is held by another client");
188
- }
189
- throw new Error("Interactive control claim became stale during attach");
190
- } catch (error) {
191
- if (claimedIdentity !== void 0) await this.safelyReleaseClaim(claimedIdentity);
192
- throw error;
193
- }
194
- }
195
- /** Expose the canonical ref digest used by persisted control identities. */
196
- static identityDigest(identity) {
197
- const ref = AgentInteractiveSessionRefSchema.parse(identity.ref);
198
- const control = AgentInteractiveSessionControlClaimSchema.parse(identity.control);
199
- if (!agentInteractiveSessionControlClaimMatchesRef(ref, control)) throw new Error("Interactive control claim is not bound to the session");
200
- return control.refDigest;
201
- }
202
- };
203
- /** Expose the same digest used to bind persistence and control identities. */
204
- function interactiveSessionIdentityDigest(identity) {
205
- return InteractiveSessionControlController.identityDigest(identity);
206
- }
207
- //#endregion
208
- //#region src/browser-interactive-control-controller.ts
209
- function browserInteractiveSessionEndpoint(baseUrl, sessionId, suffix = "") {
210
- return `${baseUrl.replace(/\/+$/, "")}/agents/sessions/${encodeURIComponent(sessionId)}/interactive${suffix}`;
211
- }
212
- function browserInteractiveTerminalEndpoint(baseUrl, sessionId) {
213
- return `${baseUrl.replace(/\/+$/, "")}/terminals/${encodeURIComponent(sessionId)}/ws`;
214
- }
215
- function authHeaders(token, includeContentType = false) {
216
- return {
217
- Authorization: `Bearer ${token}`,
218
- ...includeContentType ? { "Content-Type": "application/json" } : {}
219
- };
220
- }
221
- async function readError(response) {
222
- if (response.status === 404) return /* @__PURE__ */ new Error("Interactive session identity is stale or no longer exists");
223
- return /* @__PURE__ */ new Error(`Interactive session request failed (${response.status})`);
224
- }
225
- function createBrowserInteractiveSessionControlTransport(options) {
226
- const fetchImpl = options.fetchImpl ?? globalThis.fetch;
227
- if (typeof fetchImpl !== "function") throw new Error("Interactive browser controller requires fetch");
228
- return {
229
- async status(sessionId, incarnationId, requestOptions) {
230
- const response = await fetchImpl(`${browserInteractiveSessionEndpoint(options.sessionApiUrl, sessionId)}?incarnationId=${encodeURIComponent(incarnationId)}`, {
231
- headers: authHeaders(options.token),
232
- ...requestOptions?.signal === void 0 ? {} : { signal: requestOptions.signal }
233
- });
234
- if (response.status === 404) return null;
235
- if (!response.ok) throw await readError(response);
236
- const parsed = interactiveSessionStatusResponseSchema.safeParse(await response.json());
237
- if (!parsed.success) throw new Error("Interactive session is not running or has stale identity");
238
- return parsed.data.data.status;
239
- },
240
- async claimControl(sessionId, request, requestOptions) {
241
- const response = await fetchImpl(browserInteractiveSessionEndpoint(options.sessionApiUrl, sessionId, "/control"), {
242
- method: "POST",
243
- headers: authHeaders(options.token, true),
244
- body: JSON.stringify(request),
245
- ...requestOptions?.signal === void 0 ? {} : { signal: requestOptions.signal }
246
- });
247
- if (!response.ok) throw await readError(response);
248
- const parsed = interactiveSessionControlClaimResponseSchema.safeParse(await response.json());
249
- if (!parsed.success) throw new Error("Interactive control claim response is invalid");
250
- return parsed.data.data;
251
- },
252
- async releaseControl(sessionId, ref, control, requestOptions) {
253
- const body = interactiveSessionControlReleaseBodySchema.parse({
254
- ref,
255
- control
256
- });
257
- const response = await fetchImpl(browserInteractiveSessionEndpoint(options.sessionApiUrl, sessionId, "/control/release"), {
258
- method: "POST",
259
- headers: authHeaders(options.token, true),
260
- body: JSON.stringify(body),
261
- ...requestOptions?.signal === void 0 ? {} : { signal: requestOptions.signal }
262
- });
263
- if (!response.ok) throw await readError(response);
264
- if (!interactiveSessionControlReleaseResponseSchema.safeParse(await response.json()).success) throw new Error("Interactive control release response is invalid");
265
- }
266
- };
267
- }
268
- /** Browser controller for status, claim, and release without terminal attach. */
269
- var BrowserInteractiveSessionControlController = class extends InteractiveSessionControlController {
270
- constructor(options) {
271
- super(createBrowserInteractiveSessionControlTransport(options), options);
272
- }
273
- };
274
- /**
275
- * Return one stable browser holder per exact sandbox process incarnation.
276
- * Storage failures produce a new holder and never reuse persisted authority.
277
- */
278
- function browserInteractiveControlHolderId(environmentId, sessionId, incarnationId) {
279
- const key = `tangle.interactive.control-holder:${environmentId}:${sessionId}:${incarnationId}`;
280
- try {
281
- const storage = globalThis.sessionStorage;
282
- const existing = storage.getItem(key);
283
- if (existing) return existing;
284
- const holderId = createInteractiveControlHolderId("browser");
285
- storage.setItem(key, holderId);
286
- return holderId;
287
- } catch {
288
- return createInteractiveControlHolderId("browser");
289
- }
290
- }
291
- //#endregion
292
- export { INTERACTIVE_CONTROL_CLEANUP_TIMEOUT_MS as a, assertInteractiveSessionRef as c, interactiveSessionControlClaimResponseSchema as d, interactiveSessionControlReleaseResponseSchema as f, createBrowserInteractiveSessionControlTransport as i, createInteractiveControlHolderId as l, interactiveSessionStatusResponseSchema as m, browserInteractiveControlHolderId as n, InteractiveSessionControlController as o, interactiveSessionControlValidationResponseSchema as p, browserInteractiveTerminalEndpoint as r, InteractiveSessionNotRunningError as s, BrowserInteractiveSessionControlController as t, interactiveSessionIdentityDigest as u };