tensorlake 0.4.46 → 0.4.48

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.
@@ -76,6 +76,7 @@ interface UpdateSandboxOptions {
76
76
  interface CreateSandboxResponse {
77
77
  sandboxId: string;
78
78
  status: SandboxStatus;
79
+ routingHint?: string;
79
80
  }
80
81
  interface SandboxInfo {
81
82
  sandboxId: string;
@@ -96,6 +97,7 @@ interface SandboxInfo {
96
97
  allowUnauthenticatedAccess?: boolean;
97
98
  exposedPorts?: number[];
98
99
  sandboxUrl?: string;
100
+ routingHint?: string;
99
101
  }
100
102
  interface SandboxPortAccess {
101
103
  allowUnauthenticatedAccess: boolean;
@@ -267,6 +269,7 @@ interface SandboxOptions {
267
269
  apiKey?: string;
268
270
  organizationId?: string;
269
271
  projectId?: string;
272
+ routingHint?: string;
270
273
  }
271
274
  interface CreateAndConnectOptions extends CreateSandboxOptions {
272
275
  poolId?: string;
@@ -76,6 +76,7 @@ interface UpdateSandboxOptions {
76
76
  interface CreateSandboxResponse {
77
77
  sandboxId: string;
78
78
  status: SandboxStatus;
79
+ routingHint?: string;
79
80
  }
80
81
  interface SandboxInfo {
81
82
  sandboxId: string;
@@ -96,6 +97,7 @@ interface SandboxInfo {
96
97
  allowUnauthenticatedAccess?: boolean;
97
98
  exposedPorts?: number[];
98
99
  sandboxUrl?: string;
100
+ routingHint?: string;
99
101
  }
100
102
  interface SandboxPortAccess {
101
103
  allowUnauthenticatedAccess: boolean;
@@ -267,6 +269,7 @@ interface SandboxOptions {
267
269
  apiKey?: string;
268
270
  organizationId?: string;
269
271
  projectId?: string;
272
+ routingHint?: string;
270
273
  }
271
274
  interface CreateAndConnectOptions extends CreateSandboxOptions {
272
275
  poolId?: string;
@@ -151,6 +151,13 @@ var RemoteAPIError = class extends SandboxError {
151
151
  };
152
152
 
153
153
  // src/http.ts
154
+ var import_undici = require("undici");
155
+ (0, import_undici.setGlobalDispatcher)(
156
+ new import_undici.Agent({
157
+ keepAliveTimeout: 6e4,
158
+ allowH2: true
159
+ })
160
+ );
154
161
  var HttpClient = class {
155
162
  baseUrl;
156
163
  headers;
@@ -177,6 +184,9 @@ var HttpClient = class {
177
184
  if (options.hostHeader) {
178
185
  this.headers["Host"] = options.hostHeader;
179
186
  }
187
+ if (options.routingHint) {
188
+ this.headers["X-Tensorlake-Route-Hint"] = options.routingHint;
189
+ }
180
190
  }
181
191
  close() {
182
192
  this.abortController?.abort();
@@ -199,31 +209,26 @@ var HttpClient = class {
199
209
  if (options?.contentType) {
200
210
  headers["Content-Type"] = options.contentType;
201
211
  }
202
- const response = await this.requestResponse(
203
- method,
204
- path2,
205
- {
206
- body: options?.body,
207
- headers,
208
- signal: options?.signal
209
- }
210
- );
212
+ const response = await this.requestResponse(method, path2, {
213
+ body: options?.body,
214
+ headers,
215
+ signal: options?.signal
216
+ });
211
217
  const buffer = await response.arrayBuffer();
212
218
  return new Uint8Array(buffer);
213
219
  }
214
220
  /** Make a request and return the response body as an SSE stream. */
215
221
  async requestStream(method, path2, options) {
216
- const response = await this.requestResponse(
217
- method,
218
- path2,
219
- {
220
- json: options?.json,
221
- headers: { Accept: "text/event-stream" },
222
- signal: options?.signal
223
- }
224
- );
222
+ const response = await this.requestResponse(method, path2, {
223
+ json: options?.json,
224
+ headers: { Accept: "text/event-stream" },
225
+ signal: options?.signal
226
+ });
225
227
  if (!response.body) {
226
- throw new RemoteAPIError(response.status, "No response body for SSE stream");
228
+ throw new RemoteAPIError(
229
+ response.status,
230
+ "No response body for SSE stream"
231
+ );
227
232
  }
228
233
  return response.body;
229
234
  }
@@ -262,7 +267,7 @@ var HttpClient = class {
262
267
  );
263
268
  const combinedSignal = signal ? anySignal([signal, this.abortController.signal]) : this.abortController.signal;
264
269
  try {
265
- const response = await fetch(url, {
270
+ const response = await (0, import_undici.fetch)(url, {
266
271
  method,
267
272
  headers,
268
273
  body,
@@ -3071,7 +3076,8 @@ var Sandbox = class {
3071
3076
  apiKey: options.apiKey,
3072
3077
  organizationId: options.organizationId,
3073
3078
  projectId: options.projectId,
3074
- hostHeader
3079
+ hostHeader,
3080
+ routingHint: options.routingHint
3075
3081
  });
3076
3082
  }
3077
3083
  /** @internal Used by SandboxClient.createAndConnect to set ownership. */
@@ -3666,14 +3672,15 @@ var SandboxClient = class _SandboxClient {
3666
3672
  );
3667
3673
  }
3668
3674
  // --- Connect ---
3669
- connect(identifier, proxyUrl) {
3675
+ connect(identifier, proxyUrl, routingHint) {
3670
3676
  const resolvedProxy = proxyUrl ?? resolveProxyUrl(this.apiUrl);
3671
3677
  return new Sandbox({
3672
3678
  sandboxId: identifier,
3673
3679
  proxyUrl: resolvedProxy,
3674
3680
  apiKey: this.apiKey,
3675
3681
  organizationId: this.organizationId,
3676
- projectId: this.projectId
3682
+ projectId: this.projectId,
3683
+ routingHint
3677
3684
  });
3678
3685
  }
3679
3686
  async createAndConnect(options) {
@@ -3684,11 +3691,16 @@ var SandboxClient = class _SandboxClient {
3684
3691
  } else {
3685
3692
  result = await this.create(options);
3686
3693
  }
3694
+ if (result.status === "running" /* RUNNING */) {
3695
+ const sandbox = this.connect(result.sandboxId, options?.proxyUrl, result.routingHint);
3696
+ sandbox._setOwner(this);
3697
+ return sandbox;
3698
+ }
3687
3699
  const deadline = Date.now() + startupTimeout * 1e3;
3688
3700
  while (Date.now() < deadline) {
3689
3701
  const info = await this.get(result.sandboxId);
3690
3702
  if (info.status === "running" /* RUNNING */) {
3691
- const sandbox = this.connect(result.sandboxId, options?.proxyUrl);
3703
+ const sandbox = this.connect(result.sandboxId, options?.proxyUrl, info.routingHint);
3692
3704
  sandbox._setOwner(this);
3693
3705
  return sandbox;
3694
3706
  }