tensorlake 0.5.131 → 0.5.133

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 (50) hide show
  1. package/README.md +27 -0
  2. package/dist/applications/index.cjs +492 -708
  3. package/dist/applications/index.cjs.map +1 -1
  4. package/dist/applications/index.d.cts +3 -3
  5. package/dist/applications/index.d.ts +3 -3
  6. package/dist/applications/index.js +493 -713
  7. package/dist/applications/index.js.map +1 -1
  8. package/dist/function-agent/main.cjs +5 -2
  9. package/dist/function-agent/main.cjs.map +1 -1
  10. package/dist/function-agent/main.js +6 -3
  11. package/dist/function-agent/main.js.map +1 -1
  12. package/dist/function-executor/main.cjs +6 -3
  13. package/dist/function-executor/main.cjs.map +1 -1
  14. package/dist/function-executor/main.js +7 -4
  15. package/dist/function-executor/main.js.map +1 -1
  16. package/dist/index.cjs +121 -418
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +8 -22
  19. package/dist/index.d.ts +8 -22
  20. package/dist/index.js +122 -423
  21. package/dist/index.js.map +1 -1
  22. package/dist/native-worker.cjs +1 -0
  23. package/dist/native-worker.cjs.map +1 -1
  24. package/dist/native-worker.js +1 -0
  25. package/dist/native-worker.js.map +1 -1
  26. package/dist/{remote-DRCCuRth.d.cts → remote-D95Y6Czr.d.cts} +1 -1
  27. package/dist/{remote-0dzBqScB.d.ts → remote-omwTzbfj.d.ts} +1 -1
  28. package/dist/{sandbox-image-Bf5bcxtO.d.cts → sandbox-image-ChzWDeZy.d.cts} +2 -0
  29. package/dist/{sandbox-image-Bf5bcxtO.d.ts → sandbox-image-ChzWDeZy.d.ts} +2 -0
  30. package/dist/sandbox-image.cjs +476 -453
  31. package/dist/sandbox-image.cjs.map +1 -1
  32. package/dist/sandbox-image.d.cts +1 -1
  33. package/dist/sandbox-image.d.ts +1 -1
  34. package/dist/sandbox-image.js +475 -456
  35. package/dist/sandbox-image.js.map +1 -1
  36. package/package.json +8 -8
  37. package/runtime/function-executor/manifest.json +14 -14
  38. package/runtime/function-executor/package/dist/function-executor/main.js +7 -4
  39. package/runtime/function-executor/package/dist/function-executor/main.js.map +1 -1
  40. package/runtime/function-executor/package/dist/native-worker.cjs +1 -0
  41. package/runtime/function-executor/package/dist/native-worker.cjs.map +1 -1
  42. package/runtime/function-executor/package/npm-shrinkwrap.json +2 -12
  43. package/runtime/function-executor/package/package.json +1 -2
  44. package/runtime/typescript-function-runner/manifest.json +13 -13
  45. package/runtime/typescript-function-runner/package/dist/function-agent/main.js +6 -3
  46. package/runtime/typescript-function-runner/package/dist/function-agent/main.js.map +1 -1
  47. package/runtime/typescript-function-runner/package/dist/native-worker.cjs +1 -0
  48. package/runtime/typescript-function-runner/package/dist/native-worker.cjs.map +1 -1
  49. package/runtime/typescript-function-runner/package/npm-shrinkwrap.json +20 -29
  50. package/runtime/typescript-function-runner/package/package.json +7 -7
@@ -41,12 +41,12 @@ var init_esm_shims = __esm({
41
41
  });
42
42
 
43
43
  // src/defaults.ts
44
- var SDK_VERSION, API_URL, API_KEY, NAMESPACE, SANDBOX_PROXY_URL, DEFAULT_HTTP_TIMEOUT_MS, MAX_RETRIES, RETRY_BACKOFF_MS, RETRYABLE_STATUS_CODES;
44
+ var SDK_VERSION, API_URL, API_KEY, NAMESPACE, SANDBOX_PROXY_URL, DEFAULT_HTTP_TIMEOUT_MS, MAX_RETRIES, RETRY_BACKOFF_MS;
45
45
  var init_defaults = __esm({
46
46
  "src/defaults.ts"() {
47
47
  "use strict";
48
48
  init_esm_shims();
49
- SDK_VERSION = "0.5.131";
49
+ SDK_VERSION = "0.5.133";
50
50
  API_URL = process.env.TENSORLAKE_API_URL ?? "https://api.tensorlake.ai";
51
51
  API_KEY = process.env.TENSORLAKE_API_KEY ?? void 0;
52
52
  NAMESPACE = process.env.INDEXIFY_NAMESPACE ?? "default";
@@ -54,33 +54,10 @@ var init_defaults = __esm({
54
54
  DEFAULT_HTTP_TIMEOUT_MS = 3e5;
55
55
  MAX_RETRIES = 3;
56
56
  RETRY_BACKOFF_MS = 500;
57
- RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429, 502, 503, 504]);
58
57
  }
59
58
  });
60
59
 
61
60
  // src/errors.ts
62
- function describeError(err) {
63
- const parts = [];
64
- const seen = /* @__PURE__ */ new Set();
65
- let current = err;
66
- for (let depth = 0; depth < 6; depth++) {
67
- if (current == null || typeof current !== "object" || seen.has(current)) {
68
- break;
69
- }
70
- seen.add(current);
71
- const e = current;
72
- const message = typeof e.message === "string" ? e.message.trim() : "";
73
- const code = typeof e.code === "string" ? e.code : void 0;
74
- let segment = message;
75
- if (code && (!message || !message.includes(code))) {
76
- segment = segment ? `${segment} (${code})` : code;
77
- }
78
- if (segment && !parts.includes(segment)) parts.push(segment);
79
- current = e.cause;
80
- }
81
- if (parts.length > 0) return parts.join(": ");
82
- return err instanceof Error ? err.message : String(err);
83
- }
84
61
  function formatErrorDetails(errorDetails) {
85
62
  if (errorDetails == null) return void 0;
86
63
  if (typeof errorDetails === "string") {
@@ -194,364 +171,464 @@ var init_errors = __esm({
194
171
  }
195
172
  });
196
173
 
197
- // src/sdk-timings.ts
198
- function sdkTimingsEnabled() {
199
- const value = process.env[SDK_TIMINGS_ENV_VAR];
200
- return value === "1" || value === "true" || value === "yes";
201
- }
202
- function sdkTimingPayloadsEnabled() {
203
- const value = process.env[SDK_TIMING_PAYLOADS_ENV_VAR];
204
- return value === "1" || value === "true" || value === "yes";
205
- }
206
- function nowMs() {
207
- return performance.now();
208
- }
209
- function logSdkTiming(op, phase, startedAt, fields = {}) {
210
- if (!sdkTimingsEnabled()) return;
211
- logSdkTimingEvent(op, phase, {
212
- ...fields,
213
- duration_ms: Math.round((nowMs() - startedAt) * 100) / 100
214
- });
215
- }
216
- function logSdkTimingEvent(op, phase, fields = {}) {
217
- if (!sdkTimingsEnabled()) return;
218
- const parts = [
219
- "[tensorlake:sdk-timing]",
220
- `op=${op}`,
221
- `phase=${phase}`
222
- ];
223
- for (const [key, value] of Object.entries(fields)) {
224
- if (value == null) continue;
225
- parts.push(`${key}=${formatSdkTimingValue(value)}`);
226
- }
227
- console.error(parts.join(" "));
228
- }
229
- function formatSdkTimingValue(value) {
230
- if (typeof value === "number" || typeof value === "boolean") {
231
- return String(value);
174
+ // src/native-worker-protocol.ts
175
+ var cancelNativeCall, closeNativeHandle;
176
+ var init_native_worker_protocol = __esm({
177
+ "src/native-worker-protocol.ts"() {
178
+ "use strict";
179
+ init_esm_shims();
180
+ cancelNativeCall = /* @__PURE__ */ Symbol.for("tensorlake.native.cancel.v1");
181
+ closeNativeHandle = /* @__PURE__ */ Symbol.for("tensorlake.native.close.v1");
232
182
  }
233
- if (/^[A-Za-z0-9_./:@-]+$/.test(value)) {
234
- return value;
183
+ });
184
+
185
+ // src/url.ts
186
+ function trimTrailingSlashes(url) {
187
+ return url.endsWith("/") ? url.slice(0, -1) : url;
188
+ }
189
+ function resolveProxyTarget(proxyUrl, sandboxId) {
190
+ try {
191
+ const parsed = new URL(proxyUrl);
192
+ const host = parsed.hostname;
193
+ if (host === "localhost" || host === "127.0.0.1") {
194
+ return {
195
+ baseUrl: trimTrailingSlashes(proxyUrl),
196
+ hostHeader: `${sandboxId}.local`,
197
+ sandboxIdHeader: void 0
198
+ };
199
+ }
200
+ const port = parsed.port ? `:${parsed.port}` : "";
201
+ return {
202
+ baseUrl: `${parsed.protocol}//${host}${port}`,
203
+ hostHeader: void 0,
204
+ sandboxIdHeader: sandboxId
205
+ };
206
+ } catch {
207
+ return {
208
+ baseUrl: `${trimTrailingSlashes(proxyUrl)}/${sandboxId}`,
209
+ hostHeader: void 0,
210
+ sandboxIdHeader: void 0
211
+ };
235
212
  }
236
- return JSON.stringify(value);
237
213
  }
238
- var SDK_TIMINGS_ENV_VAR, SDK_TIMING_PAYLOADS_ENV_VAR;
239
- var init_sdk_timings = __esm({
240
- "src/sdk-timings.ts"() {
214
+ var init_url = __esm({
215
+ "src/url.ts"() {
241
216
  "use strict";
242
217
  init_esm_shims();
243
- SDK_TIMINGS_ENV_VAR = "TENSORLAKE_SDK_TIMINGS";
244
- SDK_TIMING_PAYLOADS_ENV_VAR = "TENSORLAKE_SDK_TIMING_PAYLOADS";
218
+ init_defaults();
245
219
  }
246
220
  });
247
221
 
248
- // src/http.ts
249
- import {
250
- Agent,
251
- fetch as undiciFetch,
252
- setGlobalDispatcher
253
- } from "undici";
254
- function withTraceId(value, traceId) {
255
- if (value == null) {
256
- return { traceId };
257
- }
258
- return Object.assign(value, { traceId });
222
+ // src/native-worker-client.ts
223
+ import { createRequire } from "module";
224
+ import { Worker } from "worker_threads";
225
+ function createWorkerBinding(runtime) {
226
+ return {
227
+ NativeCloudClient: class {
228
+ constructor(...args) {
229
+ return runtime.handle("NativeCloudClient", args);
230
+ }
231
+ },
232
+ NativeSandboxClient: class {
233
+ constructor(...args) {
234
+ return runtime.handle("NativeSandboxClient", args);
235
+ }
236
+ },
237
+ NativeSandboxProxyClient: class {
238
+ constructor(...args) {
239
+ return runtime.handle("NativeSandboxProxyClient", args);
240
+ }
241
+ },
242
+ NativeRepositoryClient: class {
243
+ constructor(...args) {
244
+ return runtime.handle("NativeRepositoryClient", args);
245
+ }
246
+ },
247
+ validateManagedName: (name) => runtime.call(void 0, "validateManagedName", [name])
248
+ };
259
249
  }
260
- function hasHeader(headers, name) {
261
- const lowered = name.toLowerCase();
262
- return Object.keys(headers).some((key) => key.toLowerCase() === lowered);
250
+ function workerBinding() {
251
+ return createWorkerBinding(
252
+ runtimes[runtimeKey] ??= new NativeWorkerClient()
253
+ );
263
254
  }
264
- function normalizeRequestBody(body) {
265
- if (body == null) {
266
- return void 0;
267
- }
268
- if (body instanceof Uint8Array) {
269
- return Uint8Array.from(body).buffer;
270
- }
271
- return body;
255
+ function releaseNativeHandle(handle) {
256
+ handle?.[closeNativeHandle]?.();
272
257
  }
273
- function stripPathPayload(path4) {
274
- const queryStart = path4.search(/[?#]/);
275
- return queryStart === -1 ? path4 : path4.slice(0, queryStart);
258
+ var NativeWorkerClient, runtimeKey, runtimes;
259
+ var init_native_worker_client = __esm({
260
+ "src/native-worker-client.ts"() {
261
+ "use strict";
262
+ init_esm_shims();
263
+ init_native_worker_protocol();
264
+ init_url();
265
+ NativeWorkerClient = class {
266
+ constructor(workerPath = () => createRequire(import.meta.url).resolve(
267
+ "tensorlake/internal/native-worker"
268
+ )) {
269
+ this.workerPath = workerPath;
270
+ }
271
+ worker;
272
+ nextId = 1;
273
+ registered = /* @__PURE__ */ new Set();
274
+ pending = /* @__PURE__ */ new Map();
275
+ finalizers = new FinalizationRegistry(
276
+ (id) => this.release(id)
277
+ );
278
+ handle(kind, args, parent) {
279
+ const handle = { id: this.nextId++, kind, args, parent };
280
+ this.finalizers.register(handle, handle.id);
281
+ let closed = false;
282
+ return new Proxy(
283
+ {},
284
+ {
285
+ get: (_target, method) => {
286
+ if (method === "then") return void 0;
287
+ if (method === closeNativeHandle)
288
+ return () => {
289
+ closed = true;
290
+ this.release(handle.id);
291
+ };
292
+ if (method === "connectProxy")
293
+ return (...proxyArgs) => {
294
+ if (closed) throw new Error("Tensorlake native client is closed");
295
+ return this.handle("NativeSandboxProxyClient", proxyArgs, handle);
296
+ };
297
+ if (method === "baseUrl")
298
+ return () => resolveProxyTarget(String(args[0]), String(args[1])).baseUrl;
299
+ if (typeof method !== "string") return void 0;
300
+ return (...callArgs) => {
301
+ if (closed)
302
+ return Promise.reject(
303
+ new Error("Tensorlake native client is closed")
304
+ );
305
+ const emit = typeof callArgs.at(-1) === "function" ? callArgs.pop() : void 0;
306
+ return this.call(handle, method, callArgs, emit);
307
+ };
308
+ }
309
+ }
310
+ );
311
+ }
312
+ call(handle, method, args, emit) {
313
+ const id = this.nextId++;
314
+ let worker;
315
+ const promise = new Promise((resolve, reject) => {
316
+ try {
317
+ worker = this.getWorker();
318
+ this.pending.set(id, { resolve, reject, emit, handle });
319
+ worker.ref();
320
+ if (handle) this.register(handle, worker);
321
+ this.send(worker, {
322
+ type: "call",
323
+ id,
324
+ handleId: handle?.id,
325
+ method,
326
+ args,
327
+ stream: !!emit
328
+ });
329
+ } catch (error) {
330
+ this.pending.delete(id);
331
+ this.unrefIfIdle();
332
+ reject(error);
333
+ }
334
+ });
335
+ promise[cancelNativeCall] = () => {
336
+ const pending = this.pending.get(id);
337
+ if (pending && worker) {
338
+ pending.emit = void 0;
339
+ this.send(worker, { type: "cancel", id });
340
+ }
341
+ };
342
+ return promise;
343
+ }
344
+ getWorker() {
345
+ if (this.worker) return this.worker;
346
+ const worker = new Worker(this.workerPath(), {
347
+ // The bundled worker needs no application loaders or telemetry preloads.
348
+ // NODE_OPTIONS is parsed independently of execArgv by Node.
349
+ execArgv: [],
350
+ env: { ...process.env, NODE_OPTIONS: "" },
351
+ name: "tensorlake-native"
352
+ });
353
+ this.worker = worker;
354
+ worker.on("message", (message) => {
355
+ const pending = this.pending.get(message.id);
356
+ if (!pending || this.worker !== worker) return;
357
+ if (message.type === "event") {
358
+ Promise.resolve().then(() => pending.emit?.(message.value)).then(
359
+ () => {
360
+ if (this.worker === worker)
361
+ this.send(worker, { type: "ack", id: message.id });
362
+ },
363
+ (error) => {
364
+ this.send(worker, { type: "cancel", id: message.id });
365
+ pending.reject(error);
366
+ }
367
+ );
368
+ return;
369
+ }
370
+ this.pending.delete(message.id);
371
+ if (message.type === "error") {
372
+ const error = new Error(message.error.message);
373
+ error.name = message.error.name;
374
+ error.stack = message.error.stack ?? error.stack;
375
+ pending.reject(error);
376
+ } else {
377
+ pending.resolve(message.value);
378
+ }
379
+ this.unrefIfIdle();
380
+ });
381
+ const fail = (error) => {
382
+ if (this.worker !== worker) return;
383
+ this.worker = void 0;
384
+ this.registered.clear();
385
+ for (const pending of this.pending.values()) pending.reject(error);
386
+ this.pending.clear();
387
+ void worker.terminate();
388
+ };
389
+ worker.on("error", fail);
390
+ worker.on("messageerror", fail);
391
+ worker.on(
392
+ "exit",
393
+ (code) => fail(
394
+ new Error(
395
+ `Tensorlake native worker exited (${code}); in-flight operations were not retried`
396
+ )
397
+ )
398
+ );
399
+ worker.unref();
400
+ return worker;
401
+ }
402
+ register(handle, worker) {
403
+ if (this.registered.has(handle.id)) return;
404
+ if (handle.parent) this.register(handle.parent, worker);
405
+ this.send(worker, {
406
+ type: "create",
407
+ handle: { id: handle.id, kind: handle.kind, args: handle.args },
408
+ parentId: handle.parent?.id
409
+ });
410
+ this.registered.add(handle.id);
411
+ }
412
+ release(handleId) {
413
+ if (this.worker && this.registered.delete(handleId))
414
+ this.send(this.worker, { type: "release", handleId });
415
+ }
416
+ send(worker, message) {
417
+ worker.postMessage(message);
418
+ }
419
+ unrefIfIdle() {
420
+ if (this.pending.size === 0) this.worker?.unref();
421
+ }
422
+ };
423
+ runtimeKey = /* @__PURE__ */ Symbol.for(
424
+ `tensorlake.native.worker.${false ? "source" : "0.5.133"}.v1`
425
+ );
426
+ runtimes = globalThis;
427
+ }
428
+ });
429
+
430
+ // src/native-sandbox.ts
431
+ function loadNativeSandboxBinding() {
432
+ return cachedBinding ??= workerBinding();
276
433
  }
277
- function throwMappedError(status, body, path4) {
278
- let message = body;
434
+ function parseNativeError(error) {
435
+ const message = error instanceof Error ? error.message : typeof error === "string" ? error : "";
436
+ if (!message) return null;
279
437
  try {
280
- const parsed = JSON.parse(body);
281
- if (parsed.message) message = parsed.message;
282
- else if (parsed.error) message = parsed.error;
438
+ const parsed = JSON.parse(message);
439
+ if (parsed && typeof parsed.category === "string") {
440
+ return {
441
+ category: parsed.category,
442
+ status: typeof parsed.status === "number" ? parsed.status : null,
443
+ message: typeof parsed.message === "string" ? parsed.message : message
444
+ };
445
+ }
283
446
  } catch {
284
447
  }
448
+ return null;
449
+ }
450
+ function translateNativeError(error, context) {
451
+ const payload = parseNativeError(error);
452
+ if (!payload) {
453
+ if (error instanceof Error) return error;
454
+ return new SandboxError(String(error));
455
+ }
456
+ const { category, status, message } = payload;
457
+ if (category === "connection") {
458
+ return new SandboxConnectionError(message, { cause: error });
459
+ }
285
460
  if (status === 404) {
286
- if (path4.includes("sandbox-pools") || path4.includes("pools")) {
287
- const match = path4.match(/sandbox-pools\/([^/]+)/);
288
- if (match) throw new PoolNotFoundError(match[1]);
461
+ if (context?.notFoundKind === "pool" && context.poolId) {
462
+ return new PoolNotFoundError(context.poolId);
289
463
  }
290
- if (path4.includes("sandboxes")) {
291
- const match = path4.match(/sandboxes\/([^/]+)/);
292
- if (match) throw new SandboxNotFoundError(match[1]);
464
+ if (context?.notFoundKind === "sandbox" && context.sandboxId) {
465
+ return new SandboxNotFoundError(context.sandboxId);
293
466
  }
294
- throw new RemoteAPIError(404, message);
467
+ return new RemoteAPIError(404, message);
295
468
  }
296
- if (status === 409) {
297
- if (path4.includes("sandbox-pools") || path4.includes("pools")) {
298
- const match = path4.match(/sandbox-pools\/([^/]+)/);
299
- if (match) throw new PoolInUseError(match[1], message);
300
- }
469
+ if (status === 409 && context?.poolId) {
470
+ return new PoolInUseError(context.poolId, message);
471
+ }
472
+ if (typeof status === "number") {
473
+ return new RemoteAPIError(status, message);
301
474
  }
302
- throw new RemoteAPIError(status, message);
475
+ return new SandboxError(message);
303
476
  }
304
- function anySignal(signals) {
305
- const controller = new AbortController();
306
- for (const signal of signals) {
307
- if (signal.aborted) {
308
- controller.abort(signal.reason);
309
- return controller.signal;
310
- }
311
- signal.addEventListener("abort", () => controller.abort(signal.reason), {
312
- once: true
313
- });
477
+ async function callNative(fn, context) {
478
+ try {
479
+ return await fn();
480
+ } catch (error) {
481
+ throw translateNativeError(error, context);
314
482
  }
315
- return controller.signal;
316
483
  }
317
- function sleep(ms) {
318
- return new Promise((resolve) => setTimeout(resolve, ms));
484
+ async function* nativeEventStream(start, context, signal) {
485
+ if (signal?.aborted) return;
486
+ const queue = [];
487
+ let wake;
488
+ let finished = false;
489
+ let stopped = false;
490
+ let failure;
491
+ const notify = () => {
492
+ const resolve = wake;
493
+ wake = void 0;
494
+ resolve?.();
495
+ };
496
+ const emit = (value) => {
497
+ if (stopped) return Promise.resolve();
498
+ return new Promise((consumed) => {
499
+ queue.push({ value, consumed });
500
+ notify();
501
+ });
502
+ };
503
+ let call;
504
+ const onAbort = () => {
505
+ stopped = true;
506
+ call?.[cancelNativeCall]?.();
507
+ notify();
508
+ };
509
+ signal?.addEventListener("abort", onAbort, { once: true });
510
+ try {
511
+ call = start(emit);
512
+ void call.catch((error) => {
513
+ failure = error;
514
+ }).finally(() => {
515
+ finished = true;
516
+ notify();
517
+ });
518
+ while (!stopped) {
519
+ const event = queue.shift();
520
+ if (event) {
521
+ try {
522
+ yield JSON.parse(event.value);
523
+ } finally {
524
+ event.consumed();
525
+ }
526
+ } else if (finished) {
527
+ break;
528
+ } else {
529
+ await new Promise((resolve) => {
530
+ wake = resolve;
531
+ });
532
+ }
533
+ }
534
+ if (!stopped && failure !== void 0) throw translateNativeError(failure, context);
535
+ } finally {
536
+ stopped = true;
537
+ signal?.removeEventListener("abort", onAbort);
538
+ call?.[cancelNativeCall]?.();
539
+ for (const event of queue) event.consumed();
540
+ }
319
541
  }
320
- var REQUEST_TIMEOUT_HEADER, HttpClient;
321
- var init_http = __esm({
322
- "src/http.ts"() {
542
+ var cachedBinding;
543
+ var init_native_sandbox = __esm({
544
+ "src/native-sandbox.ts"() {
323
545
  "use strict";
324
546
  init_esm_shims();
325
- init_defaults();
326
547
  init_errors();
327
- init_sdk_timings();
328
- REQUEST_TIMEOUT_HEADER = "X-Tensorlake-Request-Timeout-Ms";
329
- setGlobalDispatcher(
330
- new Agent({
331
- keepAliveTimeout: 6e4,
332
- allowH2: true
333
- })
334
- );
335
- HttpClient = class _HttpClient {
336
- baseUrl;
337
- headers;
338
- maxRetries;
339
- retryBackoffMs;
340
- timeoutMs;
341
- abortController = null;
548
+ init_native_worker_client();
549
+ init_native_worker_protocol();
550
+ }
551
+ });
552
+
553
+ // src/native-cloud.ts
554
+ async function serializeRequest(method, path4, options) {
555
+ const headers = { ...options?.headers };
556
+ let body = options?.body;
557
+ if (options?.json !== void 0) {
558
+ body = JSON.stringify(options.json);
559
+ if (!Object.keys(headers).some((key) => key.toLowerCase() === "content-type")) {
560
+ headers["Content-Type"] = "application/json";
561
+ }
562
+ }
563
+ const request = {
564
+ method,
565
+ path: path4,
566
+ headersJson: JSON.stringify(headers),
567
+ statusOnlyCodes: [...options?.statusOnlyCodes ?? []]
568
+ };
569
+ if (body instanceof FormData) {
570
+ request.parts = [];
571
+ for (const [name, value] of body.entries()) {
572
+ request.parts.push(typeof value === "string" ? { name, data: Buffer.from(value) } : { name, data: Buffer.from(await value.arrayBuffer()), filename: value.name, contentType: value.type || "application/octet-stream" });
573
+ }
574
+ } else if (body !== void 0) {
575
+ if (body instanceof Blob) request.body = Buffer.from(await body.arrayBuffer());
576
+ else if (typeof body === "string") request.body = Buffer.from(body);
577
+ else if (body instanceof ArrayBuffer) request.body = Buffer.from(new Uint8Array(body));
578
+ else request.body = Buffer.from(body);
579
+ }
580
+ return request;
581
+ }
582
+ var NativeCloudTransport;
583
+ var init_native_cloud = __esm({
584
+ "src/native-cloud.ts"() {
585
+ "use strict";
586
+ init_esm_shims();
587
+ init_native_sandbox();
588
+ init_native_worker_client();
589
+ NativeCloudTransport = class {
342
590
  constructor(options) {
343
- const url = options.baseUrl;
344
- this.baseUrl = url.endsWith("/") ? url.slice(0, -1) : url;
345
- this.maxRetries = options.maxRetries ?? MAX_RETRIES;
346
- this.retryBackoffMs = options.retryBackoffMs ?? RETRY_BACKOFF_MS;
347
- this.timeoutMs = options.timeoutMs === void 0 ? DEFAULT_HTTP_TIMEOUT_MS : options.timeoutMs;
348
- this.headers = {
349
- "User-Agent": `tensorlake-typescript-sdk/${SDK_VERSION}`
350
- };
351
- if (this.timeoutMs != null) {
352
- this.headers[REQUEST_TIMEOUT_HEADER] = String(this.timeoutMs);
353
- }
354
- if (options.apiKey) {
355
- this.headers["Authorization"] = `Bearer ${options.apiKey}`;
591
+ this.options = options;
592
+ if (!Number.isSafeInteger(options.maxRetries) || options.maxRetries < 0 || options.maxRetries > 4294967295) {
593
+ throw new RangeError("maxRetries must be a non-negative 32-bit integer");
356
594
  }
357
- if (options.organizationId) {
358
- this.headers["X-Forwarded-Organization-Id"] = options.organizationId;
359
- }
360
- if (options.projectId) {
361
- this.headers["X-Forwarded-Project-Id"] = options.projectId;
362
- }
363
- if (options.hostHeader) {
364
- this.headers["Host"] = options.hostHeader;
365
- }
366
- if (options.sandboxIdHeader) {
367
- this.headers["X-Tensorlake-Sandbox-Id"] = options.sandboxIdHeader;
368
- }
369
- if (options.routingHint) {
370
- this.headers["X-Tensorlake-Route-Hint"] = options.routingHint;
595
+ if (!Number.isFinite(options.retryBackoffMs) || options.retryBackoffMs < 0) {
596
+ throw new RangeError("retryBackoffMs must be a non-negative finite number");
371
597
  }
372
598
  }
599
+ native;
600
+ closed = false;
601
+ client() {
602
+ if (this.closed) throw new Error("Tensorlake native client is closed");
603
+ if (this.native) return this.native;
604
+ const ctor = loadNativeSandboxBinding().NativeCloudClient;
605
+ if (!ctor) throw new Error("Native binding does not export NativeCloudClient; rebuild with 'npm run build:native'");
606
+ return this.native = new ctor(JSON.stringify(this.options));
607
+ }
373
608
  close() {
374
- this.abortController?.abort();
375
- this.abortController = null;
376
- }
377
- /** Make a JSON request, returning the parsed response body. */
378
- async requestJson(method, path4, options) {
379
- const response = await this.requestResponse(method, path4, {
380
- json: options?.body,
381
- headers: options?.headers,
382
- signal: options?.signal,
383
- retryableStatusCodes: options?.retryableStatusCodes,
384
- allowedErrorStatusCodes: options?.allowedErrorStatusCodes,
385
- allowHttpErrors: options?.allowHttpErrors
386
- });
387
- const text = await response.text();
388
- const data = text ? JSON.parse(text) : void 0;
389
- return withTraceId(data, response.traceId);
390
- }
391
- /** Make a request returning raw bytes. */
392
- async requestBytes(method, path4, options) {
393
- const headers = { ...options?.headers ?? {} };
394
- if (options?.contentType) {
395
- headers["Content-Type"] = options.contentType;
396
- }
397
- const response = await this.requestResponse(method, path4, {
398
- body: options?.body,
399
- headers,
400
- signal: options?.signal
401
- });
402
- const buffer = await response.arrayBuffer();
403
- return withTraceId(new Uint8Array(buffer), response.traceId);
404
- }
405
- /** Make a request and return the response body as an SSE stream. */
406
- async requestStream(method, path4, options) {
407
- const response = await this.requestResponse(method, path4, {
408
- json: options?.json,
409
- headers: { Accept: "text/event-stream" },
410
- signal: options?.signal
411
- });
412
- if (!response.body) {
413
- throw new RemoteAPIError(
414
- response.status,
415
- "No response body for SSE stream"
416
- );
417
- }
418
- return withTraceId(response.body, response.traceId);
609
+ this.closed = true;
610
+ releaseNativeHandle(this.native ?? null);
611
+ this.native = void 0;
419
612
  }
420
- /** Make a request and return the raw Response. */
421
613
  async requestResponse(method, path4, options) {
422
- const headers = {
423
- ...this.headers,
424
- ...options?.headers ?? {}
425
- };
426
- const hasJsonBody = options?.json !== void 0;
427
- if (hasJsonBody && !hasHeader(headers, "Content-Type")) {
428
- headers["Content-Type"] = "application/json";
429
- }
430
- const body = hasJsonBody ? JSON.stringify(options?.json) : normalizeRequestBody(options?.body);
431
- const { response, traceId } = await this.doFetch(
432
- method,
433
- path4,
434
- body,
435
- headers,
436
- options?.signal,
437
- options?.allowHttpErrors ?? false,
438
- options?.retryableStatusCodes ?? RETRYABLE_STATUS_CODES,
439
- options?.allowedErrorStatusCodes ?? /* @__PURE__ */ new Set()
440
- );
441
- return withTraceId(response, traceId);
442
- }
443
- static makeTraceparent() {
444
- const randomHex = (bytes) => Array.from(crypto.getRandomValues(new Uint8Array(bytes))).map((b) => b.toString(16).padStart(2, "0")).join("");
445
- const traceId = randomHex(16);
446
- const spanId = randomHex(8);
447
- return { traceparent: `00-${traceId}-${spanId}-01`, traceId };
448
- }
449
- async doFetch(method, path4, body, headers, signal, allowHttpErrors = false, retryableStatusCodes = RETRYABLE_STATUS_CODES, allowedErrorStatusCodes = /* @__PURE__ */ new Set()) {
450
- const url = `${this.baseUrl}${path4}`;
451
- const { traceparent, traceId } = _HttpClient.makeTraceparent();
452
- headers["traceparent"] = traceparent;
453
- let lastError;
454
- const operationStart = nowMs();
455
- const timingPath = sdkTimingPayloadsEnabled() ? path4 : stripPathPayload(path4);
456
- for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
457
- if (attempt > 0) {
458
- const delay = this.retryBackoffMs * Math.pow(2, attempt - 1);
459
- logSdkTimingEvent("http.request", "retry_sleep_start", {
460
- method,
461
- path: timingPath,
462
- attempt,
463
- delay_ms: delay,
464
- server_trace_id: traceId
465
- });
466
- await sleep(delay);
467
- }
468
- this.abortController = new AbortController();
469
- let timedOut = false;
470
- const timeoutId = this.timeoutMs == null ? null : setTimeout(() => {
471
- timedOut = true;
472
- this.abortController?.abort();
473
- }, this.timeoutMs);
474
- const combinedSignal = signal ? anySignal([signal, this.abortController.signal]) : this.abortController.signal;
475
- const attemptStart = nowMs();
476
- try {
477
- const response = await undiciFetch(url, {
478
- method,
479
- headers,
480
- body,
481
- signal: combinedSignal
482
- });
483
- if (timeoutId != null) clearTimeout(timeoutId);
484
- logSdkTiming("http.request", "headers", attemptStart, {
485
- method,
486
- path: timingPath,
487
- status: response.status,
488
- attempt,
489
- server_trace_id: traceId
490
- });
491
- if (response.ok) {
492
- logSdkTiming("http.request", "complete", operationStart, {
493
- method,
494
- path: timingPath,
495
- status: response.status,
496
- attempts: attempt + 1,
497
- server_trace_id: traceId
498
- });
499
- return { response, traceId };
500
- }
501
- if (retryableStatusCodes.has(response.status) && attempt < this.maxRetries) {
502
- lastError = new RemoteAPIError(
503
- response.status,
504
- await response.text().catch(() => "")
505
- );
506
- logSdkTimingEvent("http.request", "retryable_status", {
507
- method,
508
- path: timingPath,
509
- status: response.status,
510
- attempt,
511
- server_trace_id: traceId
512
- });
513
- continue;
514
- }
515
- if (allowHttpErrors || allowedErrorStatusCodes.has(response.status)) {
516
- logSdkTiming("http.request", "complete", operationStart, {
517
- method,
518
- path: timingPath,
519
- status: response.status,
520
- attempts: attempt + 1,
521
- server_trace_id: traceId
522
- });
523
- return { response, traceId };
524
- }
525
- const errorBody = await response.text().catch(() => "");
526
- throwMappedError(response.status, errorBody, path4);
527
- } catch (err) {
528
- if (timeoutId != null) clearTimeout(timeoutId);
529
- if (err instanceof RemoteAPIError || err instanceof SandboxNotFoundError || err instanceof PoolNotFoundError || err instanceof PoolInUseError) {
530
- throw err;
531
- }
532
- if (signal?.aborted && !timedOut) {
533
- throw new SandboxConnectionError("request aborted by caller", {
534
- cause: err
535
- });
536
- }
537
- lastError = err instanceof Error ? err : new Error(String(err));
538
- logSdkTiming("http.request", "error", attemptStart, {
539
- method,
540
- path: timingPath,
541
- attempt,
542
- server_trace_id: traceId,
543
- error: timedOut ? `request timed out after ${this.timeoutMs}ms` : describeError(err)
544
- });
545
- if (attempt >= this.maxRetries) {
546
- const detail = timedOut ? `request timed out after ${this.timeoutMs}ms` : describeError(err);
547
- throw new SandboxConnectionError(detail, { cause: err });
548
- }
549
- }
550
- }
551
- throw new SandboxConnectionError(
552
- lastError ? describeError(lastError) : "request failed",
553
- { cause: lastError }
614
+ const request = await serializeRequest(method, path4, options);
615
+ const raw = await callNative(() => this.client().request(request));
616
+ const response = new Response(
617
+ [204, 205, 304].includes(raw.status) ? null : Uint8Array.from(raw.data).buffer,
618
+ { status: raw.status, headers: JSON.parse(raw.headersJson) }
554
619
  );
620
+ return Object.assign(response, { traceId: raw.traceId });
621
+ }
622
+ async requestJson(method, path4) {
623
+ const response = await this.requestResponse(method, path4);
624
+ const text = await response.text();
625
+ const value = text ? JSON.parse(text) : null;
626
+ return Object.assign(value ?? {}, { traceId: response.traceId });
627
+ }
628
+ async *stream(method, path4, signal) {
629
+ if (signal?.aborted) return;
630
+ const request = await serializeRequest(method, path4, { headers: { Accept: "text/event-stream" } });
631
+ yield* nativeEventStream((emit) => this.client().stream(request, emit), void 0, signal);
555
632
  }
556
633
  };
557
634
  }
@@ -607,65 +684,6 @@ var init_models = __esm({
607
684
  }
608
685
  });
609
686
 
610
- // src/sse.ts
611
- async function* parseSSEMessages(stream, signal) {
612
- const reader = stream.getReader();
613
- const decoder = new TextDecoder();
614
- let buffer = "";
615
- try {
616
- while (true) {
617
- if (signal?.aborted) break;
618
- const { done, value } = await reader.read();
619
- if (done) break;
620
- buffer += decoder.decode(value, { stream: true });
621
- const parts = buffer.split(/\r?\n\r?\n/);
622
- buffer = parts.pop() ?? "";
623
- for (const part of parts) {
624
- const lines = part.split(/\r?\n/);
625
- const dataLines = [];
626
- let event;
627
- let id;
628
- for (const line of lines) {
629
- if (!line || line.startsWith(":")) continue;
630
- const separator = line.indexOf(":");
631
- const field = separator === -1 ? line : line.slice(0, separator);
632
- let value2 = separator === -1 ? "" : line.slice(separator + 1);
633
- if (value2.startsWith(" ")) {
634
- value2 = value2.slice(1);
635
- }
636
- if (field === "data") {
637
- dataLines.push(value2);
638
- } else if (field === "event") {
639
- event = value2;
640
- } else if (field === "id") {
641
- id = value2;
642
- }
643
- }
644
- if (dataLines.length > 0 || event || id) {
645
- yield { data: dataLines.join("\n"), event, id };
646
- }
647
- }
648
- }
649
- } finally {
650
- reader.releaseLock();
651
- }
652
- }
653
- async function* parseSSEStream(stream, signal) {
654
- for await (const message of parseSSEMessages(stream, signal)) {
655
- if (!message.data) continue;
656
- try {
657
- yield JSON.parse(message.data);
658
- } catch {
659
- }
660
- }
661
- }
662
- var init_sse = __esm({
663
- "src/sse.ts"() {
664
- "use strict";
665
- init_esm_shims();
666
- }
667
- });
668
-
669
687
  // src/cloud-client.ts
670
688
  import { nanoid } from "nanoid";
671
689
  function secretFromMetadata(metadata) {
@@ -728,7 +746,7 @@ function createApplicationBuildForm(request, imageContexts) {
728
746
  }
729
747
  return form;
730
748
  }
731
- function trimTrailingSlashes(value) {
749
+ function trimTrailingSlashes2(value) {
732
750
  return value.endsWith("/") ? value.slice(0, -1) : value;
733
751
  }
734
752
  function nextRequestPath(next) {
@@ -765,11 +783,10 @@ var init_cloud_client = __esm({
765
783
  "use strict";
766
784
  init_esm_shims();
767
785
  init_defaults();
768
- init_http();
786
+ init_native_cloud();
769
787
  init_models();
770
- init_sse();
771
788
  CloudClient = class _CloudClient {
772
- http;
789
+ transport;
773
790
  organizationId;
774
791
  projectId;
775
792
  namespace;
@@ -777,20 +794,22 @@ var init_cloud_client = __esm({
777
794
  this.organizationId = options?.organizationId;
778
795
  this.projectId = options?.projectId;
779
796
  this.namespace = options?.namespace ?? NAMESPACE;
780
- this.http = new HttpClient({
797
+ this.transport = new NativeCloudTransport({
781
798
  baseUrl: options?.apiUrl ?? API_URL,
782
799
  apiKey: options?.apiKey ?? API_KEY,
783
800
  organizationId: this.organizationId,
784
801
  projectId: this.projectId,
785
802
  maxRetries: options?.maxRetries ?? MAX_RETRIES,
786
- retryBackoffMs: options?.retryBackoffMs ?? RETRY_BACKOFF_MS
803
+ retryBackoffMs: options?.retryBackoffMs ?? RETRY_BACKOFF_MS,
804
+ timeoutMs: DEFAULT_HTTP_TIMEOUT_MS,
805
+ userAgent: `tensorlake-typescript-sdk/${SDK_VERSION}`
787
806
  });
788
807
  }
789
808
  static forCloud(options) {
790
809
  return new _CloudClient(options);
791
810
  }
792
811
  close() {
793
- this.http.close();
812
+ this.transport.close();
794
813
  }
795
814
  async upsertApplication(manifest, codeZip, upgradeRunningRequests = false) {
796
815
  const applicationManifest = { ...manifest };
@@ -818,18 +837,18 @@ var init_cloud_client = __esm({
818
837
  "upgrade_requests_to_latest_code",
819
838
  String(upgradeRunningRequests)
820
839
  );
821
- await this.http.requestResponse("POST", this.namespacePath("applications"), {
840
+ await this.transport.requestResponse("POST", this.namespacePath("applications"), {
822
841
  body: form
823
842
  });
824
843
  }
825
844
  async deleteApplication(applicationName) {
826
- await this.http.requestResponse(
845
+ await this.transport.requestResponse(
827
846
  "DELETE",
828
847
  this.namespacePath(`applications/${encodeURIComponent(applicationName)}`)
829
848
  );
830
849
  }
831
850
  async deleteSandboxImage(imageName) {
832
- await this.http.requestResponse(
851
+ await this.transport.requestResponse(
833
852
  "DELETE",
834
853
  this.namespacePath(`sandbox-images/${encodeURIComponent(imageName)}`)
835
854
  );
@@ -848,10 +867,10 @@ var init_cloud_client = __esm({
848
867
  options?.organizationId,
849
868
  options?.projectId
850
869
  );
851
- const response = await this.http.requestResponse(
870
+ const response = await this.transport.requestResponse(
852
871
  "GET",
853
872
  `${base}/by-name/${encodeURIComponent(imageName)}`,
854
- { allowedErrorStatusCodes: /* @__PURE__ */ new Set([404]) }
873
+ { statusOnlyCodes: /* @__PURE__ */ new Set([404]) }
855
874
  );
856
875
  if (response.status === 404) {
857
876
  return null;
@@ -873,7 +892,7 @@ var init_cloud_client = __esm({
873
892
  let path4 = `${base}?pageSize=100`;
874
893
  const templates = [];
875
894
  while (path4 !== null) {
876
- const page = await this.http.requestJson(
895
+ const page = await this.transport.requestJson(
877
896
  "GET",
878
897
  path4
879
898
  );
@@ -886,7 +905,7 @@ var init_cloud_client = __esm({
886
905
  return templates;
887
906
  }
888
907
  async applications() {
889
- const raw = await this.http.requestJson(
908
+ const raw = await this.transport.requestJson(
890
909
  "GET",
891
910
  this.namespacePath("applications")
892
911
  );
@@ -895,7 +914,7 @@ var init_cloud_client = __esm({
895
914
  );
896
915
  }
897
916
  async applicationManifest(applicationName) {
898
- const raw = await this.http.requestJson(
917
+ const raw = await this.transport.requestJson(
899
918
  "GET",
900
919
  this.namespacePath(`applications/${encodeURIComponent(applicationName)}`)
901
920
  );
@@ -905,10 +924,10 @@ var init_cloud_client = __esm({
905
924
  const path4 = this.namespacePath(
906
925
  `applications/${encodeURIComponent(applicationName)}`
907
926
  );
908
- const response = inputs.length === 0 ? await this.http.requestResponse("POST", path4, {
927
+ const response = inputs.length === 0 ? await this.transport.requestResponse("POST", path4, {
909
928
  body: new Uint8Array(),
910
929
  headers: { Accept: "application/json" }
911
- }) : inputs.length === 1 && inputs[0].name === "0" ? await this.http.requestResponse("POST", path4, {
930
+ }) : inputs.length === 1 && inputs[0].name === "0" ? await this.transport.requestResponse("POST", path4, {
912
931
  body: toRequestBody(inputs[0].data),
913
932
  headers: {
914
933
  Accept: "application/json",
@@ -923,13 +942,13 @@ var init_cloud_client = __esm({
923
942
  return requestId;
924
943
  }
925
944
  async waitOnRequestCompletion(applicationName, requestId) {
926
- const stream = await this.http.requestStream(
945
+ const stream = this.transport.stream(
927
946
  "GET",
928
947
  this.namespacePath(
929
948
  `applications/${encodeURIComponent(applicationName)}/requests/${encodeURIComponent(requestId)}/progress`
930
949
  )
931
950
  );
932
- for await (const event of parseSSEStream(stream)) {
951
+ for await (const event of stream) {
933
952
  if (Object.prototype.hasOwnProperty.call(event, "RequestFinished")) {
934
953
  return;
935
954
  }
@@ -937,7 +956,7 @@ var init_cloud_client = __esm({
937
956
  throw new Error("progress stream ended before request completion");
938
957
  }
939
958
  async requestMetadata(applicationName, requestId) {
940
- const raw = await this.http.requestJson(
959
+ const raw = await this.transport.requestJson(
941
960
  "GET",
942
961
  this.namespacePath(
943
962
  `applications/${encodeURIComponent(applicationName)}/requests/${encodeURIComponent(requestId)}`
@@ -946,7 +965,7 @@ var init_cloud_client = __esm({
946
965
  return fromSnakeKeys(raw);
947
966
  }
948
967
  async requestOutput(applicationName, requestId) {
949
- const response = await this.http.requestResponse(
968
+ const response = await this.transport.requestResponse(
950
969
  "GET",
951
970
  this.namespacePath(
952
971
  `applications/${encodeURIComponent(applicationName)}/requests/${encodeURIComponent(requestId)}/output`
@@ -964,7 +983,7 @@ var init_cloud_client = __esm({
964
983
  options?.organizationId,
965
984
  options?.projectId
966
985
  );
967
- const raw = await this.http.requestJson("GET", base);
986
+ const raw = await this.transport.requestJson("GET", base);
968
987
  const pageSize = Math.max(0, options?.pageSize ?? 100);
969
988
  return Object.assign(
970
989
  {
@@ -979,7 +998,7 @@ var init_cloud_client = __esm({
979
998
  options?.organizationId,
980
999
  options?.projectId
981
1000
  );
982
- const raw = await this.http.requestJson(
1001
+ const raw = await this.transport.requestJson(
983
1002
  "GET",
984
1003
  `${base}/${encodeURIComponent(secretId)}`
985
1004
  );
@@ -1004,24 +1023,24 @@ var init_cloud_client = __esm({
1004
1023
  options?.organizationId,
1005
1024
  options?.projectId
1006
1025
  );
1007
- await this.http.requestResponse(
1026
+ await this.transport.requestResponse(
1008
1027
  "DELETE",
1009
1028
  `${base}/${encodeURIComponent(secretId)}`
1010
1029
  );
1011
1030
  }
1012
1031
  async upsertSecret(base, secret) {
1013
- let response = await this.http.requestResponse("POST", base, {
1032
+ let response = await this.transport.requestResponse("POST", base, {
1014
1033
  json: secret,
1015
1034
  headers: { "Idempotency-Key": nanoid() },
1016
- allowedErrorStatusCodes: /* @__PURE__ */ new Set([409])
1035
+ statusOnlyCodes: /* @__PURE__ */ new Set([409])
1017
1036
  });
1018
1037
  if (response.status === 409) {
1019
1038
  const prefix = base.slice(0, -"/secrets".length);
1020
- const existing = await this.http.requestJson(
1039
+ const existing = await this.transport.requestJson(
1021
1040
  "GET",
1022
1041
  `${prefix}/secret-names/${encodeURIComponent(secret.name)}`
1023
1042
  );
1024
- response = await this.http.requestResponse(
1043
+ response = await this.transport.requestResponse(
1025
1044
  "POST",
1026
1045
  `${base}/${encodeURIComponent(existing.id)}/versions`,
1027
1046
  {
@@ -1047,9 +1066,9 @@ var init_cloud_client = __esm({
1047
1066
  new Blob([toBlobPart(request.buildContext)]),
1048
1067
  "context.tar.gz"
1049
1068
  );
1050
- const response = await this.http.requestResponse(
1069
+ const response = await this.transport.requestResponse(
1051
1070
  "PUT",
1052
- `${trimTrailingSlashes(buildServicePath)}/builds`,
1071
+ `${trimTrailingSlashes2(buildServicePath)}/builds`,
1053
1072
  { body: form }
1054
1073
  );
1055
1074
  const raw = await parseJsonResponse(response);
@@ -1057,48 +1076,48 @@ var init_cloud_client = __esm({
1057
1076
  }
1058
1077
  async createApplicationBuild(buildServicePath, request, imageContexts) {
1059
1078
  const form = createApplicationBuildForm(request, imageContexts);
1060
- const response = await this.http.requestResponse(
1079
+ const response = await this.transport.requestResponse(
1061
1080
  "POST",
1062
- trimTrailingSlashes(buildServicePath),
1081
+ trimTrailingSlashes2(buildServicePath),
1063
1082
  { body: form }
1064
1083
  );
1065
1084
  const raw = await parseJsonResponse(response);
1066
1085
  return fromSnakeKeys(raw);
1067
1086
  }
1068
1087
  async applicationBuildInfo(buildServicePath, applicationBuildId) {
1069
- const raw = await this.http.requestJson(
1088
+ const raw = await this.transport.requestJson(
1070
1089
  "GET",
1071
- `${trimTrailingSlashes(buildServicePath)}/${encodeURIComponent(applicationBuildId)}`
1090
+ `${trimTrailingSlashes2(buildServicePath)}/${encodeURIComponent(applicationBuildId)}`
1072
1091
  );
1073
1092
  return fromSnakeKeys(raw);
1074
1093
  }
1075
1094
  async cancelApplicationBuild(buildServicePath, applicationBuildId) {
1076
- const raw = await this.http.requestJson(
1095
+ const raw = await this.transport.requestJson(
1077
1096
  "POST",
1078
- `${trimTrailingSlashes(buildServicePath)}/${encodeURIComponent(applicationBuildId)}/cancel`
1097
+ `${trimTrailingSlashes2(buildServicePath)}/${encodeURIComponent(applicationBuildId)}/cancel`
1079
1098
  );
1080
1099
  return fromSnakeKeys(raw);
1081
1100
  }
1082
1101
  async buildInfo(buildServicePath, buildId) {
1083
- const raw = await this.http.requestJson(
1102
+ const raw = await this.transport.requestJson(
1084
1103
  "GET",
1085
- `${trimTrailingSlashes(buildServicePath)}/builds/${encodeURIComponent(buildId)}`
1104
+ `${trimTrailingSlashes2(buildServicePath)}/builds/${encodeURIComponent(buildId)}`
1086
1105
  );
1087
1106
  return fromSnakeKeys(raw);
1088
1107
  }
1089
1108
  async cancelBuild(buildServicePath, buildId) {
1090
- await this.http.requestResponse(
1109
+ await this.transport.requestResponse(
1091
1110
  "POST",
1092
- `${trimTrailingSlashes(buildServicePath)}/builds/${encodeURIComponent(buildId)}/cancel`
1111
+ `${trimTrailingSlashes2(buildServicePath)}/builds/${encodeURIComponent(buildId)}/cancel`
1093
1112
  );
1094
1113
  }
1095
1114
  async *streamBuildLogs(buildServicePath, buildId, signal) {
1096
- const stream = await this.http.requestStream(
1115
+ const stream = this.transport.stream(
1097
1116
  "GET",
1098
- `${trimTrailingSlashes(buildServicePath)}/builds/${encodeURIComponent(buildId)}/logs`,
1099
- { signal }
1117
+ `${trimTrailingSlashes2(buildServicePath)}/builds/${encodeURIComponent(buildId)}/logs`,
1118
+ signal
1100
1119
  );
1101
- for await (const event of parseSSEStream(stream, signal)) {
1120
+ for await (const event of stream) {
1102
1121
  yield fromSnakeKeys(event);
1103
1122
  }
1104
1123
  }
@@ -1111,7 +1130,7 @@ var init_cloud_client = __esm({
1111
1130
  input.name
1112
1131
  );
1113
1132
  }
1114
- return this.http.requestResponse("POST", path4, {
1133
+ return this.transport.requestResponse("POST", path4, {
1115
1134
  body: form,
1116
1135
  headers: { Accept: "application/json" }
1117
1136
  });
@@ -1120,10 +1139,10 @@ var init_cloud_client = __esm({
1120
1139
  return `/v1/namespaces/${encodeURIComponent(this.namespace)}/${subpath.replace(/^\/+/, "")}`;
1121
1140
  }
1122
1141
  async existingApplicationPublicEndpointId(applicationName) {
1123
- const response = await this.http.requestResponse(
1142
+ const response = await this.transport.requestResponse(
1124
1143
  "GET",
1125
1144
  this.namespacePath(`applications/${encodeURIComponent(applicationName)}`),
1126
- { allowedErrorStatusCodes: /* @__PURE__ */ new Set([404]) }
1145
+ { statusOnlyCodes: /* @__PURE__ */ new Set([404]) }
1127
1146
  );
1128
1147
  if (response.status === 404) {
1129
1148
  return void 0;
@@ -1351,7 +1370,7 @@ var require_libc = __commonJS({
1351
1370
 
1352
1371
  // src/native-binding.ts
1353
1372
  import * as fs from "fs";
1354
- import { createRequire } from "module";
1373
+ import { createRequire as createRequire2 } from "module";
1355
1374
  import path2 from "path";
1356
1375
  import { fileURLToPath as fileURLToPath2 } from "url";
1357
1376
  function packageRoot() {
@@ -1395,7 +1414,7 @@ function nativePackageName(platform = process.platform, arch = process.arch, opt
1395
1414
  function loadNative() {
1396
1415
  const target = nativeTargetId();
1397
1416
  const bindingPath = nativeBindingPath();
1398
- const require2 = createRequire(import.meta.url);
1417
+ const require2 = createRequire2(import.meta.url);
1399
1418
  if (fs.existsSync(bindingPath)) return require2(bindingPath);
1400
1419
  const packageName = nativePackageName();
1401
1420
  if (!packageName) {