@lizard-build/sdk 0.1.6 → 0.1.7

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.mts CHANGED
@@ -156,6 +156,10 @@ declare class SandboxClient {
156
156
  protected static listSandboxes(opts?: ConnectionOpts): Promise<SandboxInfo[]>;
157
157
  protected static getSandboxInfo(sandboxId: string, opts?: ConnectionOpts): Promise<SandboxInfo>;
158
158
  protected static setTimeoutSandbox(sandboxId: string, timeoutMs: number, opts?: ConnectionOpts): Promise<void>;
159
+ protected static exposeSandboxPort(sandboxId: string, port: number, opts?: ConnectionOpts): Promise<{
160
+ hostname: string;
161
+ url: string;
162
+ }>;
159
163
  }
160
164
 
161
165
  /**
@@ -308,7 +312,7 @@ declare class Sandbox extends SandboxClient {
308
312
  * // https://{sandboxId}-3000.sandbox.lizard.run
309
313
  * ```
310
314
  */
311
- getHost(port: number): string;
315
+ getHost(port: number, opts?: ConnectionOpts): Promise<string>;
312
316
  private resolveOpts;
313
317
  }
314
318
 
package/dist/index.d.ts CHANGED
@@ -156,6 +156,10 @@ declare class SandboxClient {
156
156
  protected static listSandboxes(opts?: ConnectionOpts): Promise<SandboxInfo[]>;
157
157
  protected static getSandboxInfo(sandboxId: string, opts?: ConnectionOpts): Promise<SandboxInfo>;
158
158
  protected static setTimeoutSandbox(sandboxId: string, timeoutMs: number, opts?: ConnectionOpts): Promise<void>;
159
+ protected static exposeSandboxPort(sandboxId: string, port: number, opts?: ConnectionOpts): Promise<{
160
+ hostname: string;
161
+ url: string;
162
+ }>;
159
163
  }
160
164
 
161
165
  /**
@@ -308,7 +312,7 @@ declare class Sandbox extends SandboxClient {
308
312
  * // https://{sandboxId}-3000.sandbox.lizard.run
309
313
  * ```
310
314
  */
311
- getHost(port: number): string;
315
+ getHost(port: number, opts?: ConnectionOpts): Promise<string>;
312
316
  private resolveOpts;
313
317
  }
314
318
 
package/dist/index.js CHANGED
@@ -301,6 +301,15 @@ var SandboxClient = class {
301
301
  });
302
302
  if (!res.ok) await handleApiError(res);
303
303
  }
304
+ static async exposeSandboxPort(sandboxId, port, opts) {
305
+ const config = new ConnectionConfig(opts);
306
+ const res = await fetch(`${config.apiUrl}/api/sandboxes/${sandboxId}/expose/${port}`, {
307
+ method: "POST",
308
+ headers: config.headers
309
+ });
310
+ if (!res.ok) await handleApiError(res);
311
+ return res.json();
312
+ }
304
313
  };
305
314
 
306
315
  // src/sandbox/index.ts
@@ -399,10 +408,9 @@ var Sandbox = class extends SandboxClient {
399
408
  * // https://{sandboxId}-3000.sandbox.lizard.run
400
409
  * ```
401
410
  */
402
- getHost(port) {
403
- const apiHost = new URL(this.connectionConfig.apiUrl).host;
404
- const baseHost = apiHost.replace(/^api\./, "");
405
- return `${this.sandboxId}-${port}.sandbox.${baseHost}`;
411
+ async getHost(port, opts) {
412
+ const { hostname } = await SandboxClient.exposeSandboxPort(this.sandboxId, port, this.resolveOpts(opts));
413
+ return hostname;
406
414
  }
407
415
  resolveOpts(opts) {
408
416
  return { ...this.connectionConfig, ...opts };
@@ -442,7 +450,7 @@ var Execution = class {
442
450
  var CODE_INTERPRETER_PORT = 8080;
443
451
  var CodeSandbox = class extends Sandbox {
444
452
  get serverUrl() {
445
- return `https://${this.getHost(CODE_INTERPRETER_PORT)}`;
453
+ return this.getHost(CODE_INTERPRETER_PORT).then((h) => `https://${h}`);
446
454
  }
447
455
  /**
448
456
  * Execute code in a persistent kernel.
@@ -477,7 +485,7 @@ var CodeSandbox = class extends Sandbox {
477
485
  const controller = new AbortController();
478
486
  const timer = opts?.timeoutMs ? setTimeout(() => controller.abort(), opts.timeoutMs) : void 0;
479
487
  try {
480
- const res = await fetch(`${this.serverUrl}/execute`, {
488
+ const res = await fetch(`${await this.serverUrl}/execute`, {
481
489
  method: "POST",
482
490
  headers: { "Content-Type": "application/json" },
483
491
  body: JSON.stringify(body),
@@ -537,7 +545,7 @@ var CodeSandbox = class extends Sandbox {
537
545
  * ```
538
546
  */
539
547
  async createContext(opts) {
540
- const res = await fetch(`${this.serverUrl}/contexts`, {
548
+ const res = await fetch(`${await this.serverUrl}/contexts`, {
541
549
  method: "POST",
542
550
  headers: { "Content-Type": "application/json" },
543
551
  body: JSON.stringify({
@@ -552,7 +560,7 @@ var CodeSandbox = class extends Sandbox {
552
560
  * List all active execution contexts in this sandbox.
553
561
  */
554
562
  async listContexts() {
555
- const res = await fetch(`${this.serverUrl}/contexts`);
563
+ const res = await fetch(`${await this.serverUrl}/contexts`);
556
564
  if (!res.ok) throw new Error(`Failed to list contexts: ${await res.text()}`);
557
565
  return res.json();
558
566
  }
@@ -561,7 +569,7 @@ var CodeSandbox = class extends Sandbox {
561
569
  */
562
570
  async deleteContext(context) {
563
571
  const id = typeof context === "string" ? context : context.id;
564
- const res = await fetch(`${this.serverUrl}/contexts/${id}`, { method: "DELETE" });
572
+ const res = await fetch(`${await this.serverUrl}/contexts/${id}`, { method: "DELETE" });
565
573
  if (!res.ok) throw new Error(`Failed to delete context: ${await res.text()}`);
566
574
  }
567
575
  /**
@@ -569,7 +577,7 @@ var CodeSandbox = class extends Sandbox {
569
577
  */
570
578
  async restartContext(context) {
571
579
  const id = typeof context === "string" ? context : context.id;
572
- const res = await fetch(`${this.serverUrl}/contexts/${id}/restart`, { method: "POST" });
580
+ const res = await fetch(`${await this.serverUrl}/contexts/${id}/restart`, { method: "POST" });
573
581
  if (!res.ok) throw new Error(`Failed to restart context: ${await res.text()}`);
574
582
  }
575
583
  static async create(templateOrOpts, opts) {
package/dist/index.mjs CHANGED
@@ -270,6 +270,15 @@ var SandboxClient = class {
270
270
  });
271
271
  if (!res.ok) await handleApiError(res);
272
272
  }
273
+ static async exposeSandboxPort(sandboxId, port, opts) {
274
+ const config = new ConnectionConfig(opts);
275
+ const res = await fetch(`${config.apiUrl}/api/sandboxes/${sandboxId}/expose/${port}`, {
276
+ method: "POST",
277
+ headers: config.headers
278
+ });
279
+ if (!res.ok) await handleApiError(res);
280
+ return res.json();
281
+ }
273
282
  };
274
283
 
275
284
  // src/sandbox/index.ts
@@ -368,10 +377,9 @@ var Sandbox = class extends SandboxClient {
368
377
  * // https://{sandboxId}-3000.sandbox.lizard.run
369
378
  * ```
370
379
  */
371
- getHost(port) {
372
- const apiHost = new URL(this.connectionConfig.apiUrl).host;
373
- const baseHost = apiHost.replace(/^api\./, "");
374
- return `${this.sandboxId}-${port}.sandbox.${baseHost}`;
380
+ async getHost(port, opts) {
381
+ const { hostname } = await SandboxClient.exposeSandboxPort(this.sandboxId, port, this.resolveOpts(opts));
382
+ return hostname;
375
383
  }
376
384
  resolveOpts(opts) {
377
385
  return { ...this.connectionConfig, ...opts };
@@ -411,7 +419,7 @@ var Execution = class {
411
419
  var CODE_INTERPRETER_PORT = 8080;
412
420
  var CodeSandbox = class extends Sandbox {
413
421
  get serverUrl() {
414
- return `https://${this.getHost(CODE_INTERPRETER_PORT)}`;
422
+ return this.getHost(CODE_INTERPRETER_PORT).then((h) => `https://${h}`);
415
423
  }
416
424
  /**
417
425
  * Execute code in a persistent kernel.
@@ -446,7 +454,7 @@ var CodeSandbox = class extends Sandbox {
446
454
  const controller = new AbortController();
447
455
  const timer = opts?.timeoutMs ? setTimeout(() => controller.abort(), opts.timeoutMs) : void 0;
448
456
  try {
449
- const res = await fetch(`${this.serverUrl}/execute`, {
457
+ const res = await fetch(`${await this.serverUrl}/execute`, {
450
458
  method: "POST",
451
459
  headers: { "Content-Type": "application/json" },
452
460
  body: JSON.stringify(body),
@@ -506,7 +514,7 @@ var CodeSandbox = class extends Sandbox {
506
514
  * ```
507
515
  */
508
516
  async createContext(opts) {
509
- const res = await fetch(`${this.serverUrl}/contexts`, {
517
+ const res = await fetch(`${await this.serverUrl}/contexts`, {
510
518
  method: "POST",
511
519
  headers: { "Content-Type": "application/json" },
512
520
  body: JSON.stringify({
@@ -521,7 +529,7 @@ var CodeSandbox = class extends Sandbox {
521
529
  * List all active execution contexts in this sandbox.
522
530
  */
523
531
  async listContexts() {
524
- const res = await fetch(`${this.serverUrl}/contexts`);
532
+ const res = await fetch(`${await this.serverUrl}/contexts`);
525
533
  if (!res.ok) throw new Error(`Failed to list contexts: ${await res.text()}`);
526
534
  return res.json();
527
535
  }
@@ -530,7 +538,7 @@ var CodeSandbox = class extends Sandbox {
530
538
  */
531
539
  async deleteContext(context) {
532
540
  const id = typeof context === "string" ? context : context.id;
533
- const res = await fetch(`${this.serverUrl}/contexts/${id}`, { method: "DELETE" });
541
+ const res = await fetch(`${await this.serverUrl}/contexts/${id}`, { method: "DELETE" });
534
542
  if (!res.ok) throw new Error(`Failed to delete context: ${await res.text()}`);
535
543
  }
536
544
  /**
@@ -538,7 +546,7 @@ var CodeSandbox = class extends Sandbox {
538
546
  */
539
547
  async restartContext(context) {
540
548
  const id = typeof context === "string" ? context : context.id;
541
- const res = await fetch(`${this.serverUrl}/contexts/${id}/restart`, { method: "POST" });
549
+ const res = await fetch(`${await this.serverUrl}/contexts/${id}/restart`, { method: "POST" });
542
550
  if (!res.ok) throw new Error(`Failed to restart context: ${await res.text()}`);
543
551
  }
544
552
  static async create(templateOrOpts, opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lizard-build/sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Lizard SDK — cloud sandboxes for AI agents",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",