@tangle-network/sandbox 0.52.1 → 0.52.3

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,7 +1,7 @@
1
1
  import { y as assertCurrentBackendType } from "../runtime-api-DHHveKas.js";
2
2
  import { c as NotFoundError, g as ValidationError, m as StateError } from "../errors-CmYPVl-k.js";
3
- import { n as Sandbox } from "../client-B8i2Ev3O.js";
4
- import { t as SandboxInstance } from "../sandbox-BlKnSETl.js";
3
+ import { n as Sandbox } from "../client-NTRVcsww.js";
4
+ import { t as SandboxInstance } from "../sandbox-DMrjRu5N.js";
5
5
  import { createRequire } from "node:module";
6
6
  import { z } from "zod";
7
7
  //#region src/agent/instances.ts
@@ -1,7 +1,7 @@
1
1
  import { E as backendTypeSchema, _ as parseSSEStream, g as encodeTextForWire, h as encodePromptForWire, p as SANDBOX_PROXY_REQUEST_MAX_BYTES, v as applyRequestedModel, x as normalizeRuntimeBackendConfig, y as assertCurrentBackendType } from "./runtime-api-DHHveKas.js";
2
2
  import { _ as parseErrorResponse, c as NotFoundError, f as SandboxError, g as ValidationError, h as TimeoutError, l as PartialFailureError, p as ServerError, s as NetworkError, t as AuthError } from "./errors-CmYPVl-k.js";
3
3
  import { n as combineAbortSignals } from "./abort-signal-si1WMfJb.js";
4
- import { D as normalizeSandboxShape, E as normalizeConnection, M as exportTraceBundle, O as LinesClient, b as requestInteractiveSessionToken, i as normalizeStartupDiagnostics, n as createSandboxInstanceFromResponse, r as normalizeSandboxCreateReceipt } from "./sandbox-BlKnSETl.js";
4
+ import { D as normalizeSandboxShape, E as normalizeConnection, N as exportTraceBundle, O as LinesClient, b as requestInteractiveSessionToken, i as normalizeStartupDiagnostics, j as rewrapResponse, n as createSandboxInstanceFromResponse, r as normalizeSandboxCreateReceipt } from "./sandbox-DMrjRu5N.js";
5
5
  import { agentProfileSchema } from "@tangle-network/agent-interface";
6
6
  import { z } from "zod";
7
7
  //#region src/backend-registry.ts
@@ -2267,7 +2267,7 @@ var InstancesClient = class {
2267
2267
  await this.failedStart(options, record, error instanceof Error ? error : new Error(String(error)));
2268
2268
  return null;
2269
2269
  }
2270
- box = await this.client.get(sandboxId) ?? box;
2270
+ if (!takesRuntimeCalls(box)) box = await this.client.get(sandboxId) ?? box;
2271
2271
  }
2272
2272
  let current = record;
2273
2273
  if (record.unstartableSince !== null && box.status === "running") {
@@ -2330,6 +2330,10 @@ var InstancesClient = class {
2330
2330
  };
2331
2331
  }
2332
2332
  };
2333
+ /** Whether a box's last applied record lets it take runtime calls. */
2334
+ function takesRuntimeCalls(box) {
2335
+ return box.status === "running" && box.filesystemIncarnationReadiness === "ready";
2336
+ }
2333
2337
  function path(key) {
2334
2338
  return `/v1/instances/${encodeURIComponent(key)}`;
2335
2339
  }
@@ -2943,11 +2947,7 @@ function withRequestContextHeaders(response, path, method) {
2943
2947
  const headers = new Headers(response.headers);
2944
2948
  headers.set("x-tangle-request-path", path);
2945
2949
  if (method) headers.set("x-tangle-request-method", method);
2946
- return new Response(response.body, {
2947
- status: response.status,
2948
- statusText: response.statusText,
2949
- headers
2950
- });
2950
+ return rewrapResponse(response, headers);
2951
2951
  }
2952
2952
  async function resolveLocalCliAuthFiles(backendType) {
2953
2953
  const { discoverLocalCliAuthFiles } = await import("./local-cli-auth-BAJuMBZU.js");
package/dist/core.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as FileWriteConflictError, c as NotFoundError, f as SandboxError, g as ValidationError, h as TimeoutError, l as PartialFailureError, m as StateError, n as CapabilityError, p as ServerError, s as NetworkError, t as AuthError, u as QuotaError } from "./errors-CmYPVl-k.js";
2
- import { _ as backendRegistryInteractionKindSchema, b as parseBackendRegistryResponse, c as InstanceRestartingError, g as backendRegistryEntrySchema, h as backendRegistryCapabilitiesSchema, l as InstancesClient, n as Sandbox, s as HostedInstance, v as backendRegistryResponseSchema, x as parseBackendRegistryResponseBody, y as isBackendRegistryInteractionKind } from "./client-B8i2Ev3O.js";
3
- import { A as lineInstanceKey, O as LinesClient, a as WorkspaceImages, t as SandboxInstance } from "./sandbox-BlKnSETl.js";
2
+ import { _ as backendRegistryInteractionKindSchema, b as parseBackendRegistryResponse, c as InstanceRestartingError, g as backendRegistryEntrySchema, h as backendRegistryCapabilitiesSchema, l as InstancesClient, n as Sandbox, s as HostedInstance, v as backendRegistryResponseSchema, x as parseBackendRegistryResponseBody, y as isBackendRegistryInteractionKind } from "./client-NTRVcsww.js";
3
+ import { A as lineInstanceKey, O as LinesClient, a as WorkspaceImages, t as SandboxInstance } from "./sandbox-DMrjRu5N.js";
4
4
  //#region src/core.ts
5
5
  /** Local SDK protocol support only, not a deployed-host readiness assertion.
6
6
  * Version 1 refuses unconfirmed isolated receipts before materializing any
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { C as deriveAgentResultOutcome, D as parseBackendType, E as backendTypeSchema, S as createAgentRunOutcomeTracker, T as ALL_BACKEND_TYPES, _ as parseSSEStream, w as deriveAgentRunOutcome, x as normalizeRuntimeBackendConfig } from "./runtime-api-DHHveKas.js";
2
2
  import { a as FileWriteConflictError, c as NotFoundError, d as ResumeEnvRequiredError, f as SandboxError, g as ValidationError, h as TimeoutError, i as EgressProxyRecoveryError, l as PartialFailureError, m as StateError, n as CapabilityError, o as KeyBudgetExhaustedError, p as ServerError, r as EdgeNotReadyError, s as NetworkError, t as AuthError, u as QuotaError } from "./errors-CmYPVl-k.js";
3
- import { _ as backendRegistryInteractionKindSchema, a as splitInlineProfileSkills, b as parseBackendRegistryResponse, c as InstanceRestartingError, d as SandboxFleetClient, f as runtimeWorkspaceCwdSchema, g as backendRegistryEntrySchema, h as backendRegistryCapabilitiesSchema, i as splitInlineProfileFileMounts, l as InstancesClient, m as validateBatchRunRequest, n as Sandbox, o as validateDeferredProfileFileMounts, p as createBatchResultAccumulator, r as materializeProfileFileMounts, s as HostedInstance, t as IntelligenceClient, u as SandboxFleet, v as backendRegistryResponseSchema, x as parseBackendRegistryResponseBody, y as isBackendRegistryInteractionKind } from "./client-B8i2Ev3O.js";
3
+ import { _ as backendRegistryInteractionKindSchema, a as splitInlineProfileSkills, b as parseBackendRegistryResponse, c as InstanceRestartingError, d as SandboxFleetClient, f as runtimeWorkspaceCwdSchema, g as backendRegistryEntrySchema, h as backendRegistryCapabilitiesSchema, i as splitInlineProfileFileMounts, l as InstancesClient, m as validateBatchRunRequest, n as Sandbox, o as validateDeferredProfileFileMounts, p as createBatchResultAccumulator, r as materializeProfileFileMounts, s as HostedInstance, t as IntelligenceClient, u as SandboxFleet, v as backendRegistryResponseSchema, x as parseBackendRegistryResponseBody, y as isBackendRegistryInteractionKind } from "./client-NTRVcsww.js";
4
4
  import { a as INTERACTIVE_CONTROL_CLEANUP_TIMEOUT_MS, c as createInteractiveControlHolderId, l as interactiveSessionIdentityDigest, n as browserInteractiveControlHolderId, o as InteractiveSessionControlController, t as BrowserInteractiveSessionControlController } from "./browser-interactive-control-controller-Dv0gbFMu.js";
5
- import { A as lineInstanceKey, C as collectAgentResponseText, M as exportTraceBundle, N as otelTraceIdForTangleTrace, O as LinesClient, P as toOtelJson, S as collectAgentFinalMessageText, T as isToolBearingEvent, _ as TerminalStream, a as WorkspaceImages, c as SandboxTaskSession, d as agentInteractiveSessionPromptRequestDigest, f as InteractiveTerminalFrameLog, g as InteractiveSessionController, h as BrowserInteractiveSessionController, j as buildTraceExportPayload, k as SandboxLines, l as SandboxSession, m as createInteractiveTerminalSession, o as GPU_LEASE_PROVIDER_NAMES, p as createInteractiveTerminalCapture, s as MAX_EGRESS_DENIALS_LIMIT, t as SandboxInstance, u as InteractiveSessionHandle, v as TerminalStreamError, w as getSandboxEventText, x as applySandboxEventText, y as TERMINAL_WS_ECHO_SUBPROTOCOL } from "./sandbox-BlKnSETl.js";
5
+ import { A as lineInstanceKey, C as collectAgentResponseText, F as toOtelJson, M as buildTraceExportPayload, N as exportTraceBundle, O as LinesClient, P as otelTraceIdForTangleTrace, S as collectAgentFinalMessageText, T as isToolBearingEvent, _ as TerminalStream, a as WorkspaceImages, c as SandboxTaskSession, d as agentInteractiveSessionPromptRequestDigest, f as InteractiveTerminalFrameLog, g as InteractiveSessionController, h as BrowserInteractiveSessionController, k as SandboxLines, l as SandboxSession, m as createInteractiveTerminalSession, o as GPU_LEASE_PROVIDER_NAMES, p as createInteractiveTerminalCapture, s as MAX_EGRESS_DENIALS_LIMIT, t as SandboxInstance, u as InteractiveSessionHandle, v as TerminalStreamError, w as getSandboxEventText, x as applySandboxEventText, y as TERMINAL_WS_ECHO_SUBPROTOCOL } from "./sandbox-DMrjRu5N.js";
6
6
  import { a as CollaborationClient, i as parseCollaborationDocumentId, n as buildCollaborationDocumentId, r as normalizeCollaborationPath, t as CollaborationFileBridge } from "./collaboration-DLPFc9-W.js";
7
- import { t as TangleSandboxClient } from "./tangle-D_9VIKn9.js";
7
+ import { t as TangleSandboxClient } from "./tangle-HORVNS5w.js";
8
8
  import { SANDBOX_SIZE_PRESET_NAMES, agentProfileConfidentialSchema, agentProfileSchema } from "@tangle-network/agent-interface";
9
9
  import { z } from "zod";
10
10
  //#region src/confidential.ts
@@ -202,6 +202,33 @@ function snakeCase(value) {
202
202
  return value.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
203
203
  }
204
204
  //#endregion
205
+ //#region src/lib/response-rewrap.ts
206
+ /**
207
+ * Response wrappers that must outlive the fetch Response they wrap.
208
+ *
209
+ * Node's fetch (undici) cancels a response body when the Response object that
210
+ * fetch returned is garbage collected while its body is still unread. A
211
+ * wrapper built with `new Response(original.body, …)` shares that body stream
212
+ * but not that lifetime: once the original is collected, the wrapper's body is
213
+ * already cancelled and every read throws `TypeError: Body is unusable: Body
214
+ * has already been read`. It depends on when the collector runs, so it shows
215
+ * up as a rare failure on any call whose body is read after a longer await.
216
+ *
217
+ * The map holds each original for as long as its wrapper is reachable, so the
218
+ * body stays readable. When both are unreachable, undici's own cleanup runs.
219
+ */
220
+ const originals = /* @__PURE__ */ new WeakMap();
221
+ /** A Response with `original`'s status and body and the given headers. */
222
+ function rewrapResponse(original, headers) {
223
+ const wrapper = new Response(original.body, {
224
+ status: original.status,
225
+ statusText: original.statusText,
226
+ headers
227
+ });
228
+ originals.set(wrapper, original);
229
+ return wrapper;
230
+ }
231
+ //#endregion
205
232
  //#region src/lines.ts
206
233
  /**
207
234
  * Lines: give a sandbox a phone number or messaging address.
@@ -8853,11 +8880,7 @@ var DirectRuntimeHttpClient = class {
8853
8880
  const responseHeaders = new Headers(response.headers);
8854
8881
  responseHeaders.set("x-tangle-request-path", path);
8855
8882
  if (options?.method) responseHeaders.set("x-tangle-request-method", options.method);
8856
- return new Response(response.body, {
8857
- status: response.status,
8858
- statusText: response.statusText,
8859
- headers: responseHeaders
8860
- });
8883
+ return rewrapResponse(response, responseHeaders);
8861
8884
  }
8862
8885
  };
8863
8886
  function quoteForShell(value) {
@@ -8865,4 +8888,4 @@ function quoteForShell(value) {
8865
8888
  return `'${value.replace(/'/g, "'\\''")}'`;
8866
8889
  }
8867
8890
  //#endregion
8868
- export { lineInstanceKey as A, collectAgentResponseText as C, normalizeSandboxShape as D, normalizeConnection as E, exportTraceBundle as M, otelTraceIdForTangleTrace as N, LinesClient as O, toOtelJson as P, collectAgentFinalMessageText as S, isToolBearingEvent as T, TerminalStream as _, WorkspaceImages as a, requestInteractiveSessionToken as b, SandboxTaskSession as c, agentInteractiveSessionPromptRequestDigest as d, InteractiveTerminalFrameLog as f, InteractiveSessionController as g, BrowserInteractiveSessionController as h, normalizeStartupDiagnostics as i, buildTraceExportPayload as j, SandboxLines as k, SandboxSession as l, createInteractiveTerminalSession as m, createSandboxInstanceFromResponse as n, GPU_LEASE_PROVIDER_NAMES as o, createInteractiveTerminalCapture as p, normalizeSandboxCreateReceipt as r, MAX_EGRESS_DENIALS_LIMIT as s, SandboxInstance as t, InteractiveSessionHandle as u, TerminalStreamError as v, getSandboxEventText as w, applySandboxEventText as x, TERMINAL_WS_ECHO_SUBPROTOCOL as y };
8891
+ export { lineInstanceKey as A, collectAgentResponseText as C, normalizeSandboxShape as D, normalizeConnection as E, toOtelJson as F, buildTraceExportPayload as M, exportTraceBundle as N, LinesClient as O, otelTraceIdForTangleTrace as P, collectAgentFinalMessageText as S, isToolBearingEvent as T, TerminalStream as _, WorkspaceImages as a, requestInteractiveSessionToken as b, SandboxTaskSession as c, agentInteractiveSessionPromptRequestDigest as d, InteractiveTerminalFrameLog as f, InteractiveSessionController as g, BrowserInteractiveSessionController as h, normalizeStartupDiagnostics as i, rewrapResponse as j, SandboxLines as k, SandboxSession as l, createInteractiveTerminalSession as m, createSandboxInstanceFromResponse as n, GPU_LEASE_PROVIDER_NAMES as o, createInteractiveTerminalCapture as p, normalizeSandboxCreateReceipt as r, MAX_EGRESS_DENIALS_LIMIT as s, SandboxInstance as t, InteractiveSessionHandle as u, TerminalStreamError as v, getSandboxEventText as w, applySandboxEventText as x, TERMINAL_WS_ECHO_SUBPROTOCOL as y };
@@ -1,2 +1,2 @@
1
- import { a as TANGLE_JOBS_CONTRACT, c as JsonResponseParamTypes, d as SandboxIdParamTypes, i as TANGLE_CHAIN_ID, l as SandboxCreateParamTypes, n as JOB_SANDBOX_CREATE, o as AgentSandboxBlueprintAbi, r as JOB_SANDBOX_DELETE, s as ITangleJobsAbi, t as TangleSandboxClient, u as SandboxCreateResponseParamTypes } from "../tangle-D_9VIKn9.js";
1
+ import { a as TANGLE_JOBS_CONTRACT, c as JsonResponseParamTypes, d as SandboxIdParamTypes, i as TANGLE_CHAIN_ID, l as SandboxCreateParamTypes, n as JOB_SANDBOX_CREATE, o as AgentSandboxBlueprintAbi, r as JOB_SANDBOX_DELETE, s as ITangleJobsAbi, t as TangleSandboxClient, u as SandboxCreateResponseParamTypes } from "../tangle-HORVNS5w.js";
2
2
  export { AgentSandboxBlueprintAbi, ITangleJobsAbi, JOB_SANDBOX_CREATE, JOB_SANDBOX_DELETE, JsonResponseParamTypes, SandboxCreateParamTypes, SandboxCreateResponseParamTypes, SandboxIdParamTypes, TANGLE_CHAIN_ID, TANGLE_JOBS_CONTRACT, TangleSandboxClient };
@@ -1,5 +1,5 @@
1
1
  import { _ as parseErrorResponse } from "./errors-CmYPVl-k.js";
2
- import { n as createSandboxInstanceFromResponse } from "./sandbox-BlKnSETl.js";
2
+ import { n as createSandboxInstanceFromResponse } from "./sandbox-DMrjRu5N.js";
3
3
  //#region src/tangle/abi.ts
4
4
  /**
5
5
  * Tangle Contract ABI Definitions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/sandbox",
3
- "version": "0.52.1",
3
+ "version": "0.52.3",
4
4
  "description": "Client SDK for the Tangle Sandbox platform - build AI agent applications with dev containers",
5
5
  "type": "module",
6
6
  "sideEffects": [