@declaw/sdk 1.1.0 → 1.1.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/dist/index.d.cts CHANGED
@@ -75,6 +75,12 @@ declare class ApiClient {
75
75
  streamGet(path: string, opts?: RequestOpts): Promise<Response>;
76
76
  /**
77
77
  * Abort all in-flight requests and release resources.
78
+ *
79
+ * Since 1.1.1 the SDK maintains a process-wide shared ApiClient cache
80
+ * for hot class-method paths (Sandbox.create, Volumes.*, Template.*).
81
+ * Calling `close()` on a shared instance aborts its AbortController,
82
+ * which would cancel any concurrent in-flight call. Prefer
83
+ * `resetSharedClients()` if you want to tear down every cached client.
78
84
  */
79
85
  close(): void;
80
86
  private buildUrl;
@@ -87,6 +93,8 @@ declare class ApiClient {
87
93
  */
88
94
  private delay;
89
95
  }
96
+ declare function getSharedClient(config: ConnectionConfig): ApiClient;
97
+ declare function resetSharedClients(): void;
90
98
 
91
99
  /** CIDR for all traffic. */
92
100
  declare const ALL_TRAFFIC = "0.0.0.0/0";
@@ -1185,7 +1193,11 @@ declare class Sandbox {
1185
1193
  requestTimeout?: number;
1186
1194
  }): Promise<Sandbox>;
1187
1195
  /**
1188
- * Close the underlying HTTP client and release resources.
1196
+ * Historically closed the sandbox's HTTP client; since 1.1.1 the SDK
1197
+ * maintains a process-wide shared ApiClient (see `getSharedClient` in
1198
+ * api/client.ts) so per-sandbox close no longer tears the connection
1199
+ * pool down. Kept as a no-op for backwards compatibility — call
1200
+ * `resetSharedClients()` if you want to force a full teardown.
1189
1201
  */
1190
1202
  close(): void;
1191
1203
  /**
@@ -1464,4 +1476,4 @@ declare class Volumes {
1464
1476
  static delete(volumeId: string, opts?: VolumeRequestOpts): Promise<void>;
1465
1477
  }
1466
1478
 
1467
- export { ALL_TRAFFIC, ApiClient, type AuditConfig, type AuditEntry, AuthenticationError, BuildError, type BuildInfo, type CodeSecurityConfig, CommandExitError, CommandHandle, type CommandResult, type CommandWaitOpts, Commands, ConnectionConfig, type ConnectionConfigOptions, type CopyItem, DEFAULT_MASK_PATTERNS, type EntryInfo, type EnvSecurityConfig, FileType, FileUploadError, Filesystem, type FilesystemEvent, FilesystemEventType, type GetBuildStatusOpts, GitAuthError, GitUpstreamError, InjectionAction, type InjectionDefenseConfig, InjectionSensitivity, InvalidArgumentError, type InvisibleTextConfig, type NetworkPolicy, NotEnoughSpaceError, NotFoundError, type PIIConfig, PIIType, type ProcessInfo, Pty, type PtyConnectOpts, type PtyCreateOpts, PtyHandle, type PtyOutput, type PtyResult, type PtySize, RedactionAction, type RequestOpts, type RunOpts, type RunStreamOpts, Sandbox, SandboxError, type SandboxInfo, type SandboxLifecycle, type SandboxMetrics, type SandboxNetworkOpts, type SandboxOpts, SandboxPaginator, type SandboxQuery, SandboxState, type SecureEnvVar, type SecurityPolicy, type Snapshot, type SnapshotInfo, SnapshotPaginator, type SnapshotSource, type Stderr, type Stdout, Template, TemplateBase, type TemplateBuildOpts, type TemplateBuildStatus, TemplateError, TimeoutError, type ToxicityConfig, TransformDirection, type TransformationRule, type VolumeAttachment, type VolumeCreateOpts, type VolumeInfo, type VolumeRequestOpts, Volumes, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, createAuditConfig, createCodeSecurityConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseEntryInfo, parseEnvSecurityConfig, parseFilesystemEvent, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseVolumeInfo, parseWriteInfo, requiresTlsInterception, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry, volumeAttachmentToJSON };
1479
+ export { ALL_TRAFFIC, ApiClient, type AuditConfig, type AuditEntry, AuthenticationError, BuildError, type BuildInfo, type CodeSecurityConfig, CommandExitError, CommandHandle, type CommandResult, type CommandWaitOpts, Commands, ConnectionConfig, type ConnectionConfigOptions, type CopyItem, DEFAULT_MASK_PATTERNS, type EntryInfo, type EnvSecurityConfig, FileType, FileUploadError, Filesystem, type FilesystemEvent, FilesystemEventType, type GetBuildStatusOpts, GitAuthError, GitUpstreamError, InjectionAction, type InjectionDefenseConfig, InjectionSensitivity, InvalidArgumentError, type InvisibleTextConfig, type NetworkPolicy, NotEnoughSpaceError, NotFoundError, type PIIConfig, PIIType, type ProcessInfo, Pty, type PtyConnectOpts, type PtyCreateOpts, PtyHandle, type PtyOutput, type PtyResult, type PtySize, RedactionAction, type RequestOpts, type RunOpts, type RunStreamOpts, Sandbox, SandboxError, type SandboxInfo, type SandboxLifecycle, type SandboxMetrics, type SandboxNetworkOpts, type SandboxOpts, SandboxPaginator, type SandboxQuery, SandboxState, type SecureEnvVar, type SecurityPolicy, type Snapshot, type SnapshotInfo, SnapshotPaginator, type SnapshotSource, type Stderr, type Stdout, Template, TemplateBase, type TemplateBuildOpts, type TemplateBuildStatus, TemplateError, TimeoutError, type ToxicityConfig, TransformDirection, type TransformationRule, type VolumeAttachment, type VolumeCreateOpts, type VolumeInfo, type VolumeRequestOpts, Volumes, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, createAuditConfig, createCodeSecurityConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, getSharedClient, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseEntryInfo, parseEnvSecurityConfig, parseFilesystemEvent, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseVolumeInfo, parseWriteInfo, requiresTlsInterception, resetSharedClients, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry, volumeAttachmentToJSON };
package/dist/index.d.ts CHANGED
@@ -75,6 +75,12 @@ declare class ApiClient {
75
75
  streamGet(path: string, opts?: RequestOpts): Promise<Response>;
76
76
  /**
77
77
  * Abort all in-flight requests and release resources.
78
+ *
79
+ * Since 1.1.1 the SDK maintains a process-wide shared ApiClient cache
80
+ * for hot class-method paths (Sandbox.create, Volumes.*, Template.*).
81
+ * Calling `close()` on a shared instance aborts its AbortController,
82
+ * which would cancel any concurrent in-flight call. Prefer
83
+ * `resetSharedClients()` if you want to tear down every cached client.
78
84
  */
79
85
  close(): void;
80
86
  private buildUrl;
@@ -87,6 +93,8 @@ declare class ApiClient {
87
93
  */
88
94
  private delay;
89
95
  }
96
+ declare function getSharedClient(config: ConnectionConfig): ApiClient;
97
+ declare function resetSharedClients(): void;
90
98
 
91
99
  /** CIDR for all traffic. */
92
100
  declare const ALL_TRAFFIC = "0.0.0.0/0";
@@ -1185,7 +1193,11 @@ declare class Sandbox {
1185
1193
  requestTimeout?: number;
1186
1194
  }): Promise<Sandbox>;
1187
1195
  /**
1188
- * Close the underlying HTTP client and release resources.
1196
+ * Historically closed the sandbox's HTTP client; since 1.1.1 the SDK
1197
+ * maintains a process-wide shared ApiClient (see `getSharedClient` in
1198
+ * api/client.ts) so per-sandbox close no longer tears the connection
1199
+ * pool down. Kept as a no-op for backwards compatibility — call
1200
+ * `resetSharedClients()` if you want to force a full teardown.
1189
1201
  */
1190
1202
  close(): void;
1191
1203
  /**
@@ -1464,4 +1476,4 @@ declare class Volumes {
1464
1476
  static delete(volumeId: string, opts?: VolumeRequestOpts): Promise<void>;
1465
1477
  }
1466
1478
 
1467
- export { ALL_TRAFFIC, ApiClient, type AuditConfig, type AuditEntry, AuthenticationError, BuildError, type BuildInfo, type CodeSecurityConfig, CommandExitError, CommandHandle, type CommandResult, type CommandWaitOpts, Commands, ConnectionConfig, type ConnectionConfigOptions, type CopyItem, DEFAULT_MASK_PATTERNS, type EntryInfo, type EnvSecurityConfig, FileType, FileUploadError, Filesystem, type FilesystemEvent, FilesystemEventType, type GetBuildStatusOpts, GitAuthError, GitUpstreamError, InjectionAction, type InjectionDefenseConfig, InjectionSensitivity, InvalidArgumentError, type InvisibleTextConfig, type NetworkPolicy, NotEnoughSpaceError, NotFoundError, type PIIConfig, PIIType, type ProcessInfo, Pty, type PtyConnectOpts, type PtyCreateOpts, PtyHandle, type PtyOutput, type PtyResult, type PtySize, RedactionAction, type RequestOpts, type RunOpts, type RunStreamOpts, Sandbox, SandboxError, type SandboxInfo, type SandboxLifecycle, type SandboxMetrics, type SandboxNetworkOpts, type SandboxOpts, SandboxPaginator, type SandboxQuery, SandboxState, type SecureEnvVar, type SecurityPolicy, type Snapshot, type SnapshotInfo, SnapshotPaginator, type SnapshotSource, type Stderr, type Stdout, Template, TemplateBase, type TemplateBuildOpts, type TemplateBuildStatus, TemplateError, TimeoutError, type ToxicityConfig, TransformDirection, type TransformationRule, type VolumeAttachment, type VolumeCreateOpts, type VolumeInfo, type VolumeRequestOpts, Volumes, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, createAuditConfig, createCodeSecurityConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseEntryInfo, parseEnvSecurityConfig, parseFilesystemEvent, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseVolumeInfo, parseWriteInfo, requiresTlsInterception, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry, volumeAttachmentToJSON };
1479
+ export { ALL_TRAFFIC, ApiClient, type AuditConfig, type AuditEntry, AuthenticationError, BuildError, type BuildInfo, type CodeSecurityConfig, CommandExitError, CommandHandle, type CommandResult, type CommandWaitOpts, Commands, ConnectionConfig, type ConnectionConfigOptions, type CopyItem, DEFAULT_MASK_PATTERNS, type EntryInfo, type EnvSecurityConfig, FileType, FileUploadError, Filesystem, type FilesystemEvent, FilesystemEventType, type GetBuildStatusOpts, GitAuthError, GitUpstreamError, InjectionAction, type InjectionDefenseConfig, InjectionSensitivity, InvalidArgumentError, type InvisibleTextConfig, type NetworkPolicy, NotEnoughSpaceError, NotFoundError, type PIIConfig, PIIType, type ProcessInfo, Pty, type PtyConnectOpts, type PtyCreateOpts, PtyHandle, type PtyOutput, type PtyResult, type PtySize, RedactionAction, type RequestOpts, type RunOpts, type RunStreamOpts, Sandbox, SandboxError, type SandboxInfo, type SandboxLifecycle, type SandboxMetrics, type SandboxNetworkOpts, type SandboxOpts, SandboxPaginator, type SandboxQuery, SandboxState, type SecureEnvVar, type SecurityPolicy, type Snapshot, type SnapshotInfo, SnapshotPaginator, type SnapshotSource, type Stderr, type Stdout, Template, TemplateBase, type TemplateBuildOpts, type TemplateBuildStatus, TemplateError, TimeoutError, type ToxicityConfig, TransformDirection, type TransformationRule, type VolumeAttachment, type VolumeCreateOpts, type VolumeInfo, type VolumeRequestOpts, Volumes, WatchHandle, type WriteEntry, type WriteInfo, applyTransformation, codeSecurityConfigToJSON, createAuditConfig, createCodeSecurityConfig, createEnvSecurityConfig, createInjectionDefenseConfig, createInvisibleTextConfig, createNetworkPolicy, createPIIConfig, createSecurityPolicy, createToxicityConfig, createTransformationRule, domainMatches, getSharedClient, invisibleTextConfigToJSON, isSensitive, networkPolicyToOpts, parseAuditConfig, parseAuditEntry, parseBuildInfo, parseCodeSecurityConfig, parseCommandResult, parseEntryInfo, parseEnvSecurityConfig, parseFilesystemEvent, parseInjectionDefenseConfig, parseInvisibleTextConfig, parseNetworkPolicy, parsePIIConfig, parseProcessInfo, parseSandboxInfo, parseSandboxLifecycle, parseSandboxMetrics, parseSecurityPolicy, parseSnapshot, parseSnapshotInfo, parseTemplateBuildStatus, parseToxicityConfig, parseVolumeInfo, parseWriteInfo, requiresTlsInterception, resetSharedClients, securityPolicyToJSON, toxicityConfigToJSON, validateNetworkEntry, volumeAttachmentToJSON };
package/dist/index.js CHANGED
@@ -171,6 +171,12 @@ var ApiClient = class {
171
171
  }
172
172
  /**
173
173
  * Abort all in-flight requests and release resources.
174
+ *
175
+ * Since 1.1.1 the SDK maintains a process-wide shared ApiClient cache
176
+ * for hot class-method paths (Sandbox.create, Volumes.*, Template.*).
177
+ * Calling `close()` on a shared instance aborts its AbortController,
178
+ * which would cancel any concurrent in-flight call. Prefer
179
+ * `resetSharedClients()` if you want to tear down every cached client.
174
180
  */
175
181
  close() {
176
182
  this.abortController.abort();
@@ -290,6 +296,28 @@ var ApiClient = class {
290
296
  await new Promise((resolve) => setTimeout(resolve, ms));
291
297
  }
292
298
  };
299
+ var _sharedClients = /* @__PURE__ */ new Map();
300
+ function sharedKey(config) {
301
+ return [config.apiKey ?? "", config.apiUrl, config.requestTimeout ?? ""].join("|");
302
+ }
303
+ function getSharedClient(config) {
304
+ const key = sharedKey(config);
305
+ let client = _sharedClients.get(key);
306
+ if (!client) {
307
+ client = new ApiClient(config);
308
+ _sharedClients.set(key, client);
309
+ }
310
+ return client;
311
+ }
312
+ function resetSharedClients() {
313
+ for (const client of _sharedClients.values()) {
314
+ try {
315
+ client.close();
316
+ } catch {
317
+ }
318
+ }
319
+ _sharedClients.clear();
320
+ }
293
321
 
294
322
  // src/sandbox/network.ts
295
323
  var ALL_TRAFFIC = "0.0.0.0/0";
@@ -1839,54 +1867,49 @@ var Sandbox = class _Sandbox {
1839
1867
  apiUrl: opts?.apiUrl,
1840
1868
  requestTimeout: opts?.requestTimeout
1841
1869
  });
1842
- const client = new ApiClient(config);
1843
- try {
1844
- const body = {
1845
- template: opts?.template ?? DEFAULT_TEMPLATE,
1846
- timeout: opts?.timeout ?? DEFAULT_TIMEOUT,
1847
- secure: opts?.secure ?? true
1848
- };
1849
- if (opts?.metadata) {
1850
- body.metadata = opts.metadata;
1851
- }
1852
- if (opts?.envs) {
1853
- body.envs = opts.envs;
1854
- }
1855
- if (opts?.network) {
1856
- body.network = networkOptsToJSON(opts.network);
1857
- } else if (opts?.allowInternetAccess === false) {
1858
- body.network = { deny_out: [ALL_TRAFFIC] };
1859
- }
1860
- if (opts?.security) {
1861
- body.security = { policy_json: JSON.stringify(securityPolicyToJSON(opts.security)) };
1862
- if (opts.security.network && !body.network) {
1863
- body.network = typeof opts.security.network === "object" && "allowOut" in opts.security.network ? networkOptsToJSON(opts.security.network) : opts.security.network;
1864
- }
1865
- }
1866
- if (opts?.lifecycle) {
1867
- body.lifecycle = lifecycleToJSON(opts.lifecycle);
1868
- }
1869
- if (opts?.volumes && opts.volumes.length > 0) {
1870
- body.volumes = opts.volumes.map(volumeAttachmentToJSON);
1870
+ const client = getSharedClient(config);
1871
+ const body = {
1872
+ template: opts?.template ?? DEFAULT_TEMPLATE,
1873
+ timeout: opts?.timeout ?? DEFAULT_TIMEOUT,
1874
+ secure: opts?.secure ?? true
1875
+ };
1876
+ if (opts?.metadata) {
1877
+ body.metadata = opts.metadata;
1878
+ }
1879
+ if (opts?.envs) {
1880
+ body.envs = opts.envs;
1881
+ }
1882
+ if (opts?.network) {
1883
+ body.network = networkOptsToJSON(opts.network);
1884
+ } else if (opts?.allowInternetAccess === false) {
1885
+ body.network = { deny_out: [ALL_TRAFFIC] };
1886
+ }
1887
+ if (opts?.security) {
1888
+ body.security = { policy_json: JSON.stringify(securityPolicyToJSON(opts.security)) };
1889
+ if (opts.security.network && !body.network) {
1890
+ body.network = typeof opts.security.network === "object" && "allowOut" in opts.security.network ? networkOptsToJSON(opts.security.network) : opts.security.network;
1871
1891
  }
1872
- const data = await client.post("/sandboxes", {
1873
- json: body,
1874
- timeout: opts?.requestTimeout
1875
- });
1876
- const sandboxId = data.sandbox_id;
1877
- assertValidId(sandboxId, "sandbox ID (from server)");
1878
- return new _Sandbox(
1879
- sandboxId,
1880
- config,
1881
- client,
1882
- data.envd_access_token,
1883
- data.sandbox_domain,
1884
- data.traffic_access_token
1885
- );
1886
- } catch (error) {
1887
- client.close();
1888
- throw error;
1889
1892
  }
1893
+ if (opts?.lifecycle) {
1894
+ body.lifecycle = lifecycleToJSON(opts.lifecycle);
1895
+ }
1896
+ if (opts?.volumes && opts.volumes.length > 0) {
1897
+ body.volumes = opts.volumes.map(volumeAttachmentToJSON);
1898
+ }
1899
+ const data = await client.post("/sandboxes", {
1900
+ json: body,
1901
+ timeout: opts?.requestTimeout
1902
+ });
1903
+ const sandboxId = data.sandbox_id;
1904
+ assertValidId(sandboxId, "sandbox ID (from server)");
1905
+ return new _Sandbox(
1906
+ sandboxId,
1907
+ config,
1908
+ client,
1909
+ data.envd_access_token,
1910
+ data.sandbox_domain,
1911
+ data.traffic_access_token
1912
+ );
1890
1913
  }
1891
1914
  /**
1892
1915
  * Connect to an existing sandbox.
@@ -1903,23 +1926,18 @@ var Sandbox = class _Sandbox {
1903
1926
  apiUrl: opts?.apiUrl,
1904
1927
  requestTimeout: opts?.requestTimeout
1905
1928
  });
1906
- const client = new ApiClient(config);
1907
- try {
1908
- const data = await client.get(`/sandboxes/${sandboxId}`, {
1909
- timeout: opts?.requestTimeout
1910
- });
1911
- return new _Sandbox(
1912
- data.sandbox_id,
1913
- config,
1914
- client,
1915
- data.envd_access_token,
1916
- data.sandbox_domain,
1917
- data.traffic_access_token
1918
- );
1919
- } catch (error) {
1920
- client.close();
1921
- throw error;
1922
- }
1929
+ const client = getSharedClient(config);
1930
+ const data = await client.get(`/sandboxes/${sandboxId}`, {
1931
+ timeout: opts?.requestTimeout
1932
+ });
1933
+ return new _Sandbox(
1934
+ data.sandbox_id,
1935
+ config,
1936
+ client,
1937
+ data.envd_access_token,
1938
+ data.sandbox_domain,
1939
+ data.traffic_access_token
1940
+ );
1923
1941
  }
1924
1942
  /**
1925
1943
  * List sandboxes.
@@ -1936,35 +1954,31 @@ var Sandbox = class _Sandbox {
1936
1954
  apiUrl: opts?.apiUrl,
1937
1955
  requestTimeout: opts?.requestTimeout
1938
1956
  });
1939
- const client = new ApiClient(config);
1940
- try {
1941
- const params = {};
1942
- if (opts?.query) {
1943
- for (const [key, value] of Object.entries(opts.query)) {
1944
- params[key] = value;
1945
- }
1946
- }
1947
- if (opts?.limit !== void 0) {
1948
- params.limit = String(opts.limit);
1949
- }
1950
- if (opts?.nextToken) {
1951
- params.next_token = opts.nextToken;
1957
+ const client = getSharedClient(config);
1958
+ const params = {};
1959
+ if (opts?.query) {
1960
+ for (const [key, value] of Object.entries(opts.query)) {
1961
+ params[key] = value;
1952
1962
  }
1953
- const data = await client.get("/sandboxes", {
1954
- params,
1955
- timeout: opts?.requestTimeout
1956
- });
1957
- const rawSandboxes = data.sandboxes ?? [];
1958
- const sandboxes = rawSandboxes.map(
1959
- (s) => parseSandboxInfo(s)
1960
- );
1961
- return {
1962
- sandboxes,
1963
- nextToken: data.next_token ?? void 0
1964
- };
1965
- } finally {
1966
- client.close();
1967
1963
  }
1964
+ if (opts?.limit !== void 0) {
1965
+ params.limit = String(opts.limit);
1966
+ }
1967
+ if (opts?.nextToken) {
1968
+ params.next_token = opts.nextToken;
1969
+ }
1970
+ const data = await client.get("/sandboxes", {
1971
+ params,
1972
+ timeout: opts?.requestTimeout
1973
+ });
1974
+ const rawSandboxes = data.sandboxes ?? [];
1975
+ const sandboxes = rawSandboxes.map(
1976
+ (s) => parseSandboxInfo(s)
1977
+ );
1978
+ return {
1979
+ sandboxes,
1980
+ nextToken: data.next_token ?? void 0
1981
+ };
1968
1982
  }
1969
1983
  /**
1970
1984
  * Kill this sandbox.
@@ -2116,33 +2130,31 @@ var Sandbox = class _Sandbox {
2116
2130
  apiUrl: options.apiUrl,
2117
2131
  requestTimeout: options.requestTimeout
2118
2132
  });
2119
- const client = new ApiClient(config);
2120
- try {
2121
- const query = options.snapshotId ? `?snapshot_id=${encodeURIComponent(options.snapshotId)}` : "";
2122
- await client.post(`/sandboxes/${sandboxId}/restore${query}`, {
2123
- timeout: options.requestTimeout
2124
- });
2125
- const data = await client.get(`/sandboxes/${sandboxId}`, {
2126
- timeout: options.requestTimeout
2127
- });
2128
- return new _Sandbox(
2129
- data.sandbox_id,
2130
- config,
2131
- client,
2132
- data.envd_access_token,
2133
- data.sandbox_domain,
2134
- data.traffic_access_token
2135
- );
2136
- } catch (error) {
2137
- client.close();
2138
- throw error;
2139
- }
2133
+ const client = getSharedClient(config);
2134
+ const query = options.snapshotId ? `?snapshot_id=${encodeURIComponent(options.snapshotId)}` : "";
2135
+ await client.post(`/sandboxes/${sandboxId}/restore${query}`, {
2136
+ timeout: options.requestTimeout
2137
+ });
2138
+ const data = await client.get(`/sandboxes/${sandboxId}`, {
2139
+ timeout: options.requestTimeout
2140
+ });
2141
+ return new _Sandbox(
2142
+ data.sandbox_id,
2143
+ config,
2144
+ client,
2145
+ data.envd_access_token,
2146
+ data.sandbox_domain,
2147
+ data.traffic_access_token
2148
+ );
2140
2149
  }
2141
2150
  /**
2142
- * Close the underlying HTTP client and release resources.
2151
+ * Historically closed the sandbox's HTTP client; since 1.1.1 the SDK
2152
+ * maintains a process-wide shared ApiClient (see `getSharedClient` in
2153
+ * api/client.ts) so per-sandbox close no longer tears the connection
2154
+ * pool down. Kept as a no-op for backwards compatibility — call
2155
+ * `resetSharedClients()` if you want to force a full teardown.
2143
2156
  */
2144
2157
  close() {
2145
- this._client.close();
2146
2158
  }
2147
2159
  /**
2148
2160
  * Support `await using sandbox = await Sandbox.create(...)` for automatic cleanup.
@@ -2372,36 +2384,32 @@ var Template = class {
2372
2384
  domain: opts?.domain,
2373
2385
  requestTimeout: opts?.requestTimeout
2374
2386
  });
2375
- const client = new ApiClient(config);
2376
- try {
2377
- const body = {
2378
- template: template.toJSON(),
2379
- alias
2380
- };
2381
- if (opts?.cpuCount !== void 0) {
2382
- body.cpu_count = opts.cpuCount;
2383
- }
2384
- if (opts?.memoryMb !== void 0) {
2385
- body.memory_mb = opts.memoryMb;
2386
- }
2387
- if (opts?.diskMb !== void 0) {
2388
- body.disk_mb = opts.diskMb;
2389
- }
2390
- const data = await client.post("/templates/build", {
2391
- json: body,
2392
- timeout: opts?.requestTimeout
2393
- });
2394
- const response = data;
2395
- const result = parseBuildInfo(response);
2396
- if (opts?.onBuildLogs && Array.isArray(response.logs)) {
2397
- for (const log of response.logs) {
2398
- opts.onBuildLogs(log);
2399
- }
2387
+ const client = getSharedClient(config);
2388
+ const body = {
2389
+ template: template.toJSON(),
2390
+ alias
2391
+ };
2392
+ if (opts?.cpuCount !== void 0) {
2393
+ body.cpu_count = opts.cpuCount;
2394
+ }
2395
+ if (opts?.memoryMb !== void 0) {
2396
+ body.memory_mb = opts.memoryMb;
2397
+ }
2398
+ if (opts?.diskMb !== void 0) {
2399
+ body.disk_mb = opts.diskMb;
2400
+ }
2401
+ const data = await client.post("/templates/build", {
2402
+ json: body,
2403
+ timeout: opts?.requestTimeout
2404
+ });
2405
+ const response = data;
2406
+ const result = parseBuildInfo(response);
2407
+ if (opts?.onBuildLogs && Array.isArray(response.logs)) {
2408
+ for (const log of response.logs) {
2409
+ opts.onBuildLogs(log);
2400
2410
  }
2401
- return result;
2402
- } finally {
2403
- client.close();
2404
2411
  }
2412
+ return result;
2405
2413
  }
2406
2414
  /**
2407
2415
  * Start a template build in the background.
@@ -2414,30 +2422,26 @@ var Template = class {
2414
2422
  domain: opts?.domain,
2415
2423
  requestTimeout: opts?.requestTimeout
2416
2424
  });
2417
- const client = new ApiClient(config);
2418
- try {
2419
- const body = {
2420
- template: template.toJSON(),
2421
- alias,
2422
- background: true
2423
- };
2424
- if (opts?.cpuCount !== void 0) {
2425
- body.cpu_count = opts.cpuCount;
2426
- }
2427
- if (opts?.memoryMb !== void 0) {
2428
- body.memory_mb = opts.memoryMb;
2429
- }
2430
- if (opts?.diskMb !== void 0) {
2431
- body.disk_mb = opts.diskMb;
2432
- }
2433
- const data = await client.post("/templates/build", {
2434
- json: body,
2435
- timeout: opts?.requestTimeout
2436
- });
2437
- return parseBuildInfo(data);
2438
- } finally {
2439
- client.close();
2425
+ const client = getSharedClient(config);
2426
+ const body = {
2427
+ template: template.toJSON(),
2428
+ alias,
2429
+ background: true
2430
+ };
2431
+ if (opts?.cpuCount !== void 0) {
2432
+ body.cpu_count = opts.cpuCount;
2440
2433
  }
2434
+ if (opts?.memoryMb !== void 0) {
2435
+ body.memory_mb = opts.memoryMb;
2436
+ }
2437
+ if (opts?.diskMb !== void 0) {
2438
+ body.disk_mb = opts.diskMb;
2439
+ }
2440
+ const data = await client.post("/templates/build", {
2441
+ json: body,
2442
+ timeout: opts?.requestTimeout
2443
+ });
2444
+ return parseBuildInfo(data);
2441
2445
  }
2442
2446
  /**
2443
2447
  * Get the status of a template build.
@@ -2451,15 +2455,11 @@ var Template = class {
2451
2455
  domain: opts?.domain,
2452
2456
  requestTimeout: opts?.requestTimeout
2453
2457
  });
2454
- const client = new ApiClient(config);
2455
- try {
2456
- const data = await client.get(`/templates/builds/${buildId}`, {
2457
- timeout: opts?.requestTimeout
2458
- });
2459
- return parseTemplateBuildStatus(data);
2460
- } finally {
2461
- client.close();
2462
- }
2458
+ const client = getSharedClient(config);
2459
+ const data = await client.get(`/templates/builds/${buildId}`, {
2460
+ timeout: opts?.requestTimeout
2461
+ });
2462
+ return parseTemplateBuildStatus(data);
2463
2463
  }
2464
2464
  };
2465
2465
 
@@ -2484,19 +2484,15 @@ var Volumes = class {
2484
2484
  apiUrl: opts?.apiUrl,
2485
2485
  requestTimeout: opts?.requestTimeout
2486
2486
  });
2487
- const client = new ApiClient(config);
2488
- try {
2489
- const body = data instanceof Uint8Array ? data : new Uint8Array(data);
2490
- const resp = await client.post("/volumes", {
2491
- params: { name },
2492
- body,
2493
- headers: { "Content-Type": opts?.contentType ?? "application/gzip" },
2494
- timeout: opts?.requestTimeout
2495
- });
2496
- return parseVolumeInfo(resp);
2497
- } finally {
2498
- client.close();
2499
- }
2487
+ const client = getSharedClient(config);
2488
+ const body = data instanceof Uint8Array ? data : new Uint8Array(data);
2489
+ const resp = await client.post("/volumes", {
2490
+ params: { name },
2491
+ body,
2492
+ headers: { "Content-Type": opts?.contentType ?? "application/gzip" },
2493
+ timeout: opts?.requestTimeout
2494
+ });
2495
+ return parseVolumeInfo(resp);
2500
2496
  }
2501
2497
  /** Fetch metadata for a single volume. */
2502
2498
  static async get(volumeId, opts) {
@@ -2507,15 +2503,11 @@ var Volumes = class {
2507
2503
  apiUrl: opts?.apiUrl,
2508
2504
  requestTimeout: opts?.requestTimeout
2509
2505
  });
2510
- const client = new ApiClient(config);
2511
- try {
2512
- const resp = await client.get(`/volumes/${volumeId}`, {
2513
- timeout: opts?.requestTimeout
2514
- });
2515
- return parseVolumeInfo(resp);
2516
- } finally {
2517
- client.close();
2518
- }
2506
+ const client = getSharedClient(config);
2507
+ const resp = await client.get(`/volumes/${volumeId}`, {
2508
+ timeout: opts?.requestTimeout
2509
+ });
2510
+ return parseVolumeInfo(resp);
2519
2511
  }
2520
2512
  /** List all volumes owned by the caller, newest first. */
2521
2513
  static async list(opts) {
@@ -2525,16 +2517,12 @@ var Volumes = class {
2525
2517
  apiUrl: opts?.apiUrl,
2526
2518
  requestTimeout: opts?.requestTimeout
2527
2519
  });
2528
- const client = new ApiClient(config);
2529
- try {
2530
- const resp = await client.get("/volumes", {
2531
- timeout: opts?.requestTimeout
2532
- });
2533
- const rows = resp.volumes ?? [];
2534
- return rows.map(parseVolumeInfo);
2535
- } finally {
2536
- client.close();
2537
- }
2520
+ const client = getSharedClient(config);
2521
+ const resp = await client.get("/volumes", {
2522
+ timeout: opts?.requestTimeout
2523
+ });
2524
+ const rows = resp.volumes ?? [];
2525
+ return rows.map(parseVolumeInfo);
2538
2526
  }
2539
2527
  /** Delete a volume and its blob. Idempotent on the wire. */
2540
2528
  static async delete(volumeId, opts) {
@@ -2545,12 +2533,8 @@ var Volumes = class {
2545
2533
  apiUrl: opts?.apiUrl,
2546
2534
  requestTimeout: opts?.requestTimeout
2547
2535
  });
2548
- const client = new ApiClient(config);
2549
- try {
2550
- await client.delete(`/volumes/${volumeId}`, { timeout: opts?.requestTimeout });
2551
- } finally {
2552
- client.close();
2553
- }
2536
+ const client = getSharedClient(config);
2537
+ await client.delete(`/volumes/${volumeId}`, { timeout: opts?.requestTimeout });
2554
2538
  }
2555
2539
  };
2556
2540
  export {
@@ -2603,6 +2587,7 @@ export {
2603
2587
  createToxicityConfig,
2604
2588
  createTransformationRule,
2605
2589
  domainMatches,
2590
+ getSharedClient,
2606
2591
  invisibleTextConfigToJSON,
2607
2592
  isSensitive,
2608
2593
  networkPolicyToOpts,
@@ -2630,6 +2615,7 @@ export {
2630
2615
  parseVolumeInfo,
2631
2616
  parseWriteInfo,
2632
2617
  requiresTlsInterception,
2618
+ resetSharedClients,
2633
2619
  securityPolicyToJSON,
2634
2620
  toxicityConfigToJSON,
2635
2621
  validateNetworkEntry,