withruntime 0.11.2 → 0.14.0

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 (171) hide show
  1. package/BLAXEL.md +2 -2
  2. package/COMPATIBILITY.md +74 -9
  3. package/DAYTONA.md +33 -5
  4. package/E2B.md +85 -24
  5. package/README.md +11 -10
  6. package/README.src.md +10 -9
  7. package/VERCEL.md +43 -5
  8. package/compatibility-lock.json +58 -49
  9. package/dist/billing-cli.d.ts +1 -1
  10. package/dist/billing-cli.js +85 -5
  11. package/dist/blaxel/errors.d.ts +14 -0
  12. package/dist/blaxel/errors.js +29 -0
  13. package/dist/blaxel/index.d.ts +2 -2
  14. package/dist/blaxel/index.js +4 -4
  15. package/dist/blaxel/interpreter.d.ts +2 -5
  16. package/dist/blaxel/sandbox.d.ts +15 -6
  17. package/dist/blaxel/sandbox.js +64 -8
  18. package/dist/blaxel/snapshot.d.ts +4 -0
  19. package/dist/blaxel/snapshot.js +4 -0
  20. package/dist/cli/logs.d.ts +21 -0
  21. package/dist/cli/logs.js +188 -0
  22. package/dist/cli-extras.d.ts +3 -3
  23. package/dist/cli-extras.js +17 -12
  24. package/dist/cli-words.d.ts +10 -1
  25. package/dist/cli-words.js +18 -0
  26. package/dist/cli.d.ts +22 -3
  27. package/dist/cli.js +647 -273
  28. package/dist/client.d.ts +2 -4
  29. package/dist/client.js +27 -11
  30. package/dist/cloudflare/errors.d.ts +143 -0
  31. package/dist/cloudflare/errors.js +167 -0
  32. package/dist/cloudflare/index.d.ts +175 -6
  33. package/dist/cloudflare/index.js +416 -26
  34. package/dist/cloudflare/interpreter.d.ts +119 -0
  35. package/dist/cloudflare/interpreter.js +223 -0
  36. package/dist/cloudflare/streams.d.ts +38 -0
  37. package/dist/cloudflare/streams.js +145 -0
  38. package/dist/cloudflare/watch.d.ts +9 -0
  39. package/dist/cloudflare/watch.js +24 -0
  40. package/dist/codesandbox/index.d.ts +216 -28
  41. package/dist/codesandbox/index.js +478 -78
  42. package/dist/compat/core.d.ts +18 -0
  43. package/dist/compat/core.js +29 -0
  44. package/dist/compat/files.d.ts +1 -0
  45. package/dist/compat/files.js +25 -5
  46. package/dist/credentials.d.ts +3 -0
  47. package/dist/credentials.js +15 -0
  48. package/dist/daytona/computer-use.d.ts +13 -4
  49. package/dist/daytona/computer-use.js +66 -8
  50. package/dist/daytona/daytona.d.ts +7 -1
  51. package/dist/daytona/daytona.js +31 -4
  52. package/dist/daytona/errors.d.ts +11 -0
  53. package/dist/daytona/errors.js +18 -0
  54. package/dist/daytona/filesystem.js +2 -1
  55. package/dist/daytona/image.d.ts +13 -9
  56. package/dist/daytona/image.js +18 -12
  57. package/dist/daytona/index.d.ts +1 -1
  58. package/dist/daytona/sandbox.d.ts +8 -2
  59. package/dist/daytona/sandbox.js +16 -2
  60. package/dist/domains/index.d.ts +9 -0
  61. package/dist/domains/index.js +10 -0
  62. package/dist/e2b/commands.d.ts +1 -1
  63. package/dist/e2b/commands.js +6 -7
  64. package/dist/e2b/errors.d.ts +17 -0
  65. package/dist/e2b/errors.js +40 -1
  66. package/dist/e2b/index.d.ts +2 -2
  67. package/dist/e2b/index.js +1 -1
  68. package/dist/e2b/sandbox.d.ts +28 -22
  69. package/dist/e2b/sandbox.js +34 -8
  70. package/dist/e2b/unsupported.js +1 -1
  71. package/dist/errors.d.ts +11 -2
  72. package/dist/errors.js +17 -5
  73. package/dist/freestyle/index.d.ts +285 -37
  74. package/dist/freestyle/index.js +656 -144
  75. package/dist/identity.d.ts +3 -0
  76. package/dist/identity.js +27 -0
  77. package/dist/images/index.d.ts +9 -0
  78. package/dist/images/index.js +10 -0
  79. package/dist/index.d.ts +3 -1
  80. package/dist/ips/index.d.ts +9 -0
  81. package/dist/ips/index.js +10 -0
  82. package/dist/jobs/index.d.ts +9 -0
  83. package/dist/jobs/index.js +10 -0
  84. package/dist/keys.js +2 -0
  85. package/dist/login.js +2 -0
  86. package/dist/machine.d.ts +27 -4
  87. package/dist/machine.js +46 -14
  88. package/dist/mcp.js +144 -20
  89. package/dist/modal/index.d.ts +339 -61
  90. package/dist/modal/index.js +781 -121
  91. package/dist/network-cli.d.ts +3 -1
  92. package/dist/network-cli.js +78 -36
  93. package/dist/networks/index.d.ts +11 -0
  94. package/dist/networks/index.js +10 -0
  95. package/dist/ports/index.d.ts +9 -0
  96. package/dist/ports/index.js +10 -0
  97. package/dist/product-names.d.ts +52 -0
  98. package/dist/product-names.js +164 -0
  99. package/dist/product-renames.d.ts +103 -0
  100. package/dist/product-renames.js +189 -0
  101. package/dist/products/api-keys.d.ts +73 -0
  102. package/dist/products/api-keys.js +23 -0
  103. package/dist/products/apps.d.ts +157 -0
  104. package/dist/products/apps.js +60 -0
  105. package/dist/products/balancers.d.ts +87 -0
  106. package/dist/products/balancers.js +8 -0
  107. package/dist/products/billing.d.ts +41 -0
  108. package/dist/products/billing.js +13 -0
  109. package/dist/products/browser.d.ts +10 -0
  110. package/dist/products/browsers.d.ts +71 -0
  111. package/dist/products/browsers.js +102 -0
  112. package/dist/products/builds.d.ts +156 -0
  113. package/dist/products/builds.js +227 -0
  114. package/dist/products/index.d.ts +5 -16
  115. package/dist/products/index.js +5 -14
  116. package/dist/products/jobs.d.ts +19 -2
  117. package/dist/products/jobs.js +28 -11
  118. package/dist/products/logs.d.ts +245 -0
  119. package/dist/products/logs.js +274 -0
  120. package/dist/products/network-products.d.ts +38 -7
  121. package/dist/products/network-products.js +31 -18
  122. package/dist/products/observability.d.ts +8 -2
  123. package/dist/products/private-network.js +1 -1
  124. package/dist/products/queues.d.ts +149 -0
  125. package/dist/products/queues.js +213 -0
  126. package/dist/products/referrals.d.ts +21 -7
  127. package/dist/products/referrals.js +3 -3
  128. package/dist/products/resources.d.ts +54 -0
  129. package/dist/products/resources.js +122 -0
  130. package/dist/products/secrets.d.ts +29 -3
  131. package/dist/products/secrets.js +47 -18
  132. package/dist/products/signed-requests.d.ts +21 -0
  133. package/dist/products/signed-requests.js +11 -0
  134. package/dist/products/streams.d.ts +73 -0
  135. package/dist/products/streams.js +17 -0
  136. package/dist/products/switching.d.ts +35 -7
  137. package/dist/products/switching.js +4 -3
  138. package/dist/products/volumes.d.ts +6 -0
  139. package/dist/record-cli.d.ts +23 -0
  140. package/dist/record-cli.js +308 -0
  141. package/dist/renamed-products.d.ts +38 -0
  142. package/dist/renamed-products.js +34 -0
  143. package/dist/runloop/index.d.ts +9 -2
  144. package/dist/runloop/index.js +29 -8
  145. package/dist/runloop/sdk.d.ts +131 -0
  146. package/dist/runloop/sdk.js +167 -0
  147. package/dist/sandbox.d.ts +7 -2
  148. package/dist/sandbox.js +41 -11
  149. package/dist/sandboxes/index.d.ts +11 -0
  150. package/dist/sandboxes/index.js +12 -0
  151. package/dist/snapshots/index.d.ts +9 -0
  152. package/dist/snapshots/index.js +11 -0
  153. package/dist/snapshots.d.ts +7 -4
  154. package/dist/sprites/index.d.ts +343 -31
  155. package/dist/sprites/index.js +866 -84
  156. package/dist/ssh.d.ts +1 -1
  157. package/dist/ssh.js +11 -11
  158. package/dist/terminal.d.ts +24 -0
  159. package/dist/terminal.js +32 -0
  160. package/dist/transport.d.ts +18 -1
  161. package/dist/transport.js +80 -6
  162. package/dist/tunnel.js +1 -1
  163. package/dist/types.d.ts +71 -4
  164. package/dist/vercel/sandbox.d.ts +1 -1
  165. package/dist/vercel/sandbox.js +6 -4
  166. package/dist/vercel/snapshot.js +10 -2
  167. package/dist/volumes/index.d.ts +9 -0
  168. package/dist/volumes/index.js +10 -0
  169. package/dist/wallet.d.ts +4 -1
  170. package/dist/wallet.js +2 -1
  171. package/package.json +48 -14
@@ -0,0 +1,87 @@
1
+ import type { Transport } from "../transport.js";
2
+ import { type ResourceRecord } from "./resources.js";
3
+ /** Private until launch: load balancers and the inbound firewall
4
+ * (packages/cloud/src/api/products/balancers.ts). A change answers
5
+ * `applying`; it is `active` once every router serves it, and `waitingOn`
6
+ * names any router that does not yet. */
7
+ export type AddressState = "applying" | "active" | "failed" | "deleting" | "deleted";
8
+ type Common = ResourceRecord & {
9
+ name: string | null;
10
+ labels: Record<string, string>;
11
+ state: AddressState;
12
+ createdAt: number;
13
+ updatedAt: number;
14
+ deletedAt: number | null;
15
+ /** Routers that do not yet serve the newest change. */
16
+ waitingOn: string[];
17
+ };
18
+ /** A sandbox with the port it serves on, or an App or Function by id. */
19
+ export type BalancerTarget = {
20
+ id: string;
21
+ port?: number;
22
+ };
23
+ export type Balancer = Common & {
24
+ hostname: string;
25
+ targets: BalancerTarget[];
26
+ };
27
+ export type CreateBalancer = {
28
+ name?: string;
29
+ labels?: Record<string, string>;
30
+ /** Up to 1000, all the organization's own. */
31
+ targets?: BalancerTarget[];
32
+ };
33
+ export type UpdateBalancer = {
34
+ name?: string | null;
35
+ labels?: Record<string, string>;
36
+ /** Replaces the whole list. */
37
+ targets?: BalancerTarget[];
38
+ };
39
+ export type FirewallRule = Common & {
40
+ address: string;
41
+ effect: "allow" | "deny" | "limit";
42
+ source?: string;
43
+ ports?: string;
44
+ requests?: number;
45
+ seconds?: number;
46
+ burst?: number;
47
+ priority: number;
48
+ };
49
+ export type CreateFirewallRule = {
50
+ name?: string;
51
+ labels?: Record<string, string>;
52
+ /** The load balancer it guards. */
53
+ address: string;
54
+ priority?: number;
55
+ } & ({
56
+ effect: "allow" | "deny";
57
+ source?: string;
58
+ ports?: string;
59
+ } | {
60
+ effect: "limit";
61
+ requests: number;
62
+ seconds: number;
63
+ burst?: number;
64
+ });
65
+ export type UpdateFirewallRule = {
66
+ name?: string | null;
67
+ labels?: Record<string, string>;
68
+ };
69
+ export declare function balancers(t: Transport): {
70
+ base: string;
71
+ create: (input: CreateBalancer, options?: import("../transport.js").RequestOptions) => Promise<Balancer>;
72
+ get: (id: string, options?: import("./resources.js").ResourceGetOptions<"active" | "deleted" | "failed" | "deleting" | "applying">) => Promise<Balancer>;
73
+ list: (query?: import("./resources.js").ResourceListQuery<"active" | "deleted" | "failed" | "deleting" | "applying">, options?: import("../transport.js").RequestOptions) => Promise<import("../page.js").Page<Balancer>>;
74
+ update: (id: string, input: UpdateBalancer, options?: import("../transport.js").RequestOptions) => Promise<Balancer>;
75
+ wait: (id: string, target: "active" | "deleted" | "failed" | "deleting" | "applying", options?: import("./resources.js").ResourceWaitOptions) => Promise<Balancer>;
76
+ delete: (id: string, options?: import("./resources.js").ResourceDeleteOptions) => Promise<Balancer>;
77
+ };
78
+ export declare function firewall(t: Transport): {
79
+ base: string;
80
+ create: (input: CreateFirewallRule, options?: import("../transport.js").RequestOptions) => Promise<FirewallRule>;
81
+ get: (id: string, options?: import("./resources.js").ResourceGetOptions<"active" | "deleted" | "failed" | "deleting" | "applying">) => Promise<FirewallRule>;
82
+ list: (query?: import("./resources.js").ResourceListQuery<"active" | "deleted" | "failed" | "deleting" | "applying">, options?: import("../transport.js").RequestOptions) => Promise<import("../page.js").Page<FirewallRule>>;
83
+ update: (id: string, input: UpdateFirewallRule, options?: import("../transport.js").RequestOptions) => Promise<FirewallRule>;
84
+ wait: (id: string, target: "active" | "deleted" | "failed" | "deleting" | "applying", options?: import("./resources.js").ResourceWaitOptions) => Promise<FirewallRule>;
85
+ delete: (id: string, options?: import("./resources.js").ResourceDeleteOptions) => Promise<FirewallRule>;
86
+ };
87
+ export {};
@@ -0,0 +1,8 @@
1
+ import { resource } from "./resources.js";
2
+ const SETTLED = ["failed", "deleted"];
3
+ export function balancers(t) {
4
+ return resource(t, "balancers", SETTLED);
5
+ }
6
+ export function firewall(t) {
7
+ return resource(t, "firewall/rules", SETTLED);
8
+ }
@@ -24,6 +24,39 @@ export type Topup = {
24
24
  }[];
25
25
  }[];
26
26
  };
27
+ /** Auto top-up: when credit falls below `below`, the saved card is charged
28
+ * `amount` plus tax, within `monthlyLimit` a calendar month (UTC). Each
29
+ * automatic top-up adds 5% more as credit, and while it is on the account
30
+ * may run 200 sandboxes at once. Dollars are numbers in whole cents. */
31
+ export type AutoTopUp = {
32
+ /** Charging now. */
33
+ enabled: boolean;
34
+ /** Asked to turn on; turns on once a person saves a card at `saveCardAt`. */
35
+ waitingForCard: boolean;
36
+ below: number | null;
37
+ amount: number | null;
38
+ monthlyLimit: number | null;
39
+ /** Dollars added this month, a charge in flight included. */
40
+ thisMonth: number;
41
+ card: boolean;
42
+ /** Why it turned itself off; null while on. */
43
+ offReason: "declined" | "authentication_required" | "card_removed" | "no_address" | "blocked" | "failed" | null;
44
+ offAt: string | null;
45
+ /** Where a person saves the card, while none is saved. */
46
+ saveCardAt: string | null;
47
+ };
48
+ /** A figure left out keeps the one saved, or takes its default. */
49
+ export type AutoTopUpInput = {
50
+ enabled: boolean;
51
+ /** Charge when credit falls below this: $10 at least, and the default. */
52
+ below?: number;
53
+ /** Each time, before tax: $20 (the default) to $10,000, and at most $500
54
+ * in an account's first week. */
55
+ amount?: number;
56
+ /** The most a calendar month (UTC): $100 at least and at least `amount`;
57
+ * $500 by default. */
58
+ monthlyLimit?: number;
59
+ };
27
60
  export declare function billing(t: Transport): {
28
61
  /** Open a stablecoin top-up of `usd` dollars ($10 to $10,000). Pass the
29
62
  * same `idempotencyKey` when retrying to get the same top-up back. */
@@ -32,4 +65,12 @@ export declare function billing(t: Transport): {
32
65
  }, options?: RequestOptions) => Promise<Topup>;
33
66
  /** Read a top-up: whether its payment has arrived. */
34
67
  topupStatus: (purchaseId: string, options?: RequestOptions) => Promise<Topup>;
68
+ /** Auto top-up's settings. A person saves its card on the website. */
69
+ autoTopUp: {
70
+ get: (options?: RequestOptions) => Promise<AutoTopUp>;
71
+ /** Set the three figures, and turn it on (once a card is saved) or keep it off. */
72
+ set: (input: AutoTopUpInput, options?: RequestOptions) => Promise<AutoTopUp>;
73
+ /** Turn it off. The figures and the card are kept; running sandboxes are never stopped. */
74
+ off: (options?: RequestOptions) => Promise<AutoTopUp>;
75
+ };
35
76
  };
@@ -9,5 +9,18 @@ export function billing(t) {
9
9
  path: `/v1/billing/topups/${encodeURIComponent(purchaseId)}`,
10
10
  ...options,
11
11
  }),
12
+ /** Auto top-up's settings. A person saves its card on the website. */
13
+ autoTopUp: {
14
+ get: (options) => t.json({ method: "GET", path: "/v1/billing/auto-top-up", ...options }),
15
+ /** Set the three figures, and turn it on (once a card is saved) or keep it off. */
16
+ set: (input, options) => t.json({
17
+ method: "PUT",
18
+ path: "/v1/billing/auto-top-up",
19
+ body: input,
20
+ ...options,
21
+ }),
22
+ /** Turn it off. The figures and the card are kept; running sandboxes are never stopped. */
23
+ off: (options) => t.json({ method: "DELETE", path: "/v1/billing/auto-top-up", ...options }),
24
+ },
12
25
  };
13
26
  }
@@ -18,6 +18,11 @@ export type SandboxBrowser = {
18
18
  expiresAt: string | null;
19
19
  /** headless: false only: the desktop's live view. */
20
20
  streamUrl?: string;
21
+ /** start() only: the sandbox's memory, which is the browser's. */
22
+ memoryMiB?: number;
23
+ /** start() only, under 2 GiB: heavy apps such as Google Sheets, YouTube
24
+ * and StackBlitz need a 2 GiB sandbox; 1 GiB suits light pages. */
25
+ hint?: string;
21
26
  };
22
27
  export type BrowserStartOptions = {
23
28
  /** true (the default): no window. false: on the sandbox's desktop, with a live view. */
@@ -52,6 +57,11 @@ export declare function sandboxBrowser(t: Transport, sandbox: Sandbox): {
52
57
  expiresAt: string | null;
53
58
  /** headless: false only: the desktop's live view. */
54
59
  streamUrl?: string;
60
+ /** start() only: the sandbox's memory, which is the browser's. */
61
+ memoryMiB?: number;
62
+ /** start() only, under 2 GiB: heavy apps such as Google Sheets, YouTube
63
+ * and StackBlitz need a 2 GiB sandbox; 1 GiB suits light pages. */
64
+ hint?: string;
55
65
  }>;
56
66
  /** Whether it runs, and a fresh cdpUrl when it does. */
57
67
  get: (options?: RequestOptions) => Promise<SandboxBrowser>;
@@ -0,0 +1,71 @@
1
+ import { Page } from "../page.js";
2
+ import type { RequestOptions, Transport } from "../transport.js";
3
+ export type CreateBrowser = {
4
+ /** 1024–16384 MiB; the server defaults to 2048. */
5
+ memoryMiB?: number;
6
+ /** The server defaults to 1 vCPU. */
7
+ vcpu?: number;
8
+ /** Defaults to true; false requests a visible browser. */
9
+ headless?: boolean;
10
+ width?: number;
11
+ height?: number;
12
+ timeoutSeconds?: number;
13
+ idlePauseSeconds?: number;
14
+ name?: string;
15
+ labels?: Record<string, string>;
16
+ };
17
+ export type UpdateBrowser = {
18
+ name?: string | null;
19
+ labels?: Record<string, string>;
20
+ };
21
+ export type ListBrowsers = {
22
+ limit?: number;
23
+ cursor?: string;
24
+ };
25
+ /** A browser resource and its current connection credentials. */
26
+ export type BrowserInfo = {
27
+ id: string;
28
+ name: string | null;
29
+ labels: Record<string, string>;
30
+ state: string;
31
+ sandboxId: string;
32
+ memoryMiB: number;
33
+ vcpu: number;
34
+ headless: boolean;
35
+ version: string;
36
+ cdpUrl: string;
37
+ httpUrl: string;
38
+ headers: Record<string, string>;
39
+ expiresAt: string | null;
40
+ liveViewUrl?: string;
41
+ hint?: string;
42
+ };
43
+ export type BrowserConnectOptions = {
44
+ playwright: [endpointURL: string, options: {
45
+ headers: Record<string, string>;
46
+ }];
47
+ puppeteer: {
48
+ browserWSEndpoint: string;
49
+ headers: Record<string, string>;
50
+ };
51
+ };
52
+ export type Browser = BrowserInfo & {
53
+ /** End this browser; concurrent calls share one request, and failures can be retried. */
54
+ delete(options?: RequestOptions): Promise<void>;
55
+ /** Get Playwright's argument tuple and Puppeteer's options, including authentication headers. */
56
+ connectOptions(): BrowserConnectOptions;
57
+ /** End this browser on scope exit; an already missing browser counts as cleaned up. */
58
+ [Symbol.asyncDispose](): Promise<void>;
59
+ };
60
+ /** Browsers follow the shared resource interface: id, name, labels, state. */
61
+ export declare function browsers(t: Transport): {
62
+ /** Create a browser ready to connect; omitted fields use the server's defaults. */
63
+ create(input?: CreateBrowser, options?: RequestOptions): Promise<Browser>;
64
+ /** Fetch a browser by id with fresh CDP connection credentials. */
65
+ get(id: string, options?: RequestOptions): Promise<Browser>;
66
+ list: (query?: ListBrowsers, options?: RequestOptions) => Promise<Page<Browser>>;
67
+ /** Change a browser's name or labels without changing its compute settings. */
68
+ update(id: string, input: UpdateBrowser, options?: RequestOptions): Promise<Browser>;
69
+ /** End a browser by id; pass RequestOptions to bound or deduplicate the request. */
70
+ delete: (id: string, options?: RequestOptions) => Promise<void>;
71
+ };
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Managed Chromium browsers with authenticated Chrome DevTools Protocol (CDP) connections.
3
+ *
4
+ * await using browser = await runtime.browsers.create();
5
+ * const playwrightBrowser = await chromium.connectOverCDP(...browser.connectOptions().playwright);
6
+ * const puppeteerBrowser = await puppeteer.connect(browser.connectOptions().puppeteer);
7
+ *
8
+ * Use `get(browser.id)` for fresh connection credentials after `expiresAt`.
9
+ */
10
+ import { RuntimeError } from "../errors.js";
11
+ import { Page } from "../page.js";
12
+ /** Browsers follow the shared resource interface: id, name, labels, state. */
13
+ export function browsers(t) {
14
+ const path = (id) => `/v1/browsers/${encodeURIComponent(id)}`;
15
+ /** End a browser by id; API errors retain their code and recovery hint. */
16
+ const remove = async (id, options) => {
17
+ await t.json({ method: "DELETE", path: path(id), ...options });
18
+ };
19
+ const wrap = (info) => {
20
+ let deleted = false;
21
+ let deleting;
22
+ const browser = {
23
+ ...info,
24
+ delete(options) {
25
+ if (deleted)
26
+ return Promise.resolve();
27
+ if (!deleting) {
28
+ deleting = remove(info.id, options)
29
+ .then(() => {
30
+ deleted = true;
31
+ })
32
+ .catch((error) => {
33
+ if (error instanceof RuntimeError && error.status === 404)
34
+ deleted = true;
35
+ throw error;
36
+ })
37
+ .finally(() => {
38
+ deleting = undefined;
39
+ });
40
+ }
41
+ return deleting;
42
+ },
43
+ connectOptions() {
44
+ return {
45
+ playwright: [browser.cdpUrl, { headers: { ...browser.headers } }],
46
+ puppeteer: {
47
+ browserWSEndpoint: browser.cdpUrl,
48
+ headers: { ...browser.headers },
49
+ },
50
+ };
51
+ },
52
+ async [Symbol.asyncDispose]() {
53
+ // Creation's signal/key belong to creation: an aborted task must still clean up.
54
+ try {
55
+ await browser.delete();
56
+ }
57
+ catch (error) {
58
+ if (!(error instanceof RuntimeError && error.status === 404))
59
+ throw error;
60
+ }
61
+ },
62
+ };
63
+ return browser;
64
+ };
65
+ /** Fetch one page; `for await (const browser of await list())` follows every cursor. */
66
+ const list = async (query = {}, options) => {
67
+ const page = await t.json({
68
+ method: "GET",
69
+ path: "/v1/browsers",
70
+ query,
71
+ ...options,
72
+ });
73
+ return new Page(page.data.map(wrap), page.nextCursor, (cursor) => list({ ...query, cursor }, options));
74
+ };
75
+ return {
76
+ /** Create a browser ready to connect; omitted fields use the server's defaults. */
77
+ async create(input = {}, options) {
78
+ return wrap(await t.json({
79
+ method: "POST",
80
+ path: "/v1/browsers",
81
+ body: input,
82
+ ...options,
83
+ }));
84
+ },
85
+ /** Fetch a browser by id with fresh CDP connection credentials. */
86
+ async get(id, options) {
87
+ return wrap(await t.json({ method: "GET", path: path(id), ...options }));
88
+ },
89
+ list,
90
+ /** Change a browser's name or labels without changing its compute settings. */
91
+ async update(id, input, options) {
92
+ return wrap(await t.json({
93
+ method: "POST",
94
+ path: `${path(id)}:update`,
95
+ body: input,
96
+ ...options,
97
+ }));
98
+ },
99
+ /** End a browser by id; pass RequestOptions to bound or deduplicate the request. */
100
+ delete: remove,
101
+ };
102
+ }
@@ -0,0 +1,156 @@
1
+ import { Page } from "../page.js";
2
+ import { type RequestOptions, type Transport } from "../transport.js";
3
+ export type BuildState = "queued" | "fetching" | "building" | "deploying" | "succeeded" | "failed" | "cancelled" | "superseded";
4
+ type Resource = {
5
+ id: string;
6
+ name: string | null;
7
+ labels: Record<string, string>;
8
+ createdAt: number;
9
+ updatedAt: number;
10
+ deletedAt: number | null;
11
+ error: {
12
+ code: string;
13
+ message: string;
14
+ } | null;
15
+ };
16
+ export type Build = Resource & {
17
+ repositoryId: string;
18
+ ref: string;
19
+ /** The branch whose move asked for it, when the caller said. */
20
+ branch: string | null;
21
+ commit: string | null;
22
+ state: BuildState;
23
+ reason: string | null;
24
+ /** Milliseconds per step once the runner is done (install, build, mirror,
25
+ * fork, snapshot, total, ...); null until then. */
26
+ timings: Record<string, number> | null;
27
+ /** The saved server an App deploys, once a build of a repository with a
28
+ * start command succeeded; null otherwise. */
29
+ outputSnapshotId: string | null;
30
+ };
31
+ export type CreateBuild = {
32
+ repositoryId: string;
33
+ ref: string;
34
+ /** The same branch and commit is one build; a newer build of the branch
35
+ * supersedes older ones not yet ended. */
36
+ branch?: string;
37
+ name?: string;
38
+ labels?: Record<string, string>;
39
+ };
40
+ /** A connected repository's settings changed in place; its id and builds
41
+ * stay. A field left out stays as it is; a null name clears it. */
42
+ export type ChangeRepository = Partial<Omit<ConnectRepository, "provider" | "name" | "labels">> & {
43
+ name?: string | null;
44
+ labels?: Record<string, string>;
45
+ };
46
+ export type ConnectRepository = {
47
+ provider: "github" | "git";
48
+ repository: string;
49
+ deploy: `app:${string}` | `function:${string}` | `container:${string}`;
50
+ productionBranch?: string;
51
+ previews?: boolean;
52
+ /** The folder the build runs in; the repository's root by default. */
53
+ rootDirectory?: string;
54
+ /** Leave out to choose by the lockfile (bun, pnpm, Yarn or npm). */
55
+ installCommand?: string | null;
56
+ buildCommand?: string | null;
57
+ /** Run after the build with PORT set; the build ends as this server,
58
+ * answering healthPath with 200 and saved with its memory. */
59
+ startCommand?: string | null;
60
+ port?: number;
61
+ healthPath?: string | null;
62
+ /** Settings install and build are given. Never a secret: anyone who reads
63
+ * the repository sees them. */
64
+ buildEnv?: Record<string, string>;
65
+ name?: string;
66
+ labels?: Record<string, string>;
67
+ };
68
+ export type Repository = Resource & {
69
+ provider: "github" | "git";
70
+ repository: string;
71
+ deploy: ConnectRepository["deploy"];
72
+ productionBranch: string;
73
+ previews: boolean;
74
+ rootDirectory: string;
75
+ installCommand: string | null;
76
+ buildCommand: string | null;
77
+ startCommand: string | null;
78
+ port: number;
79
+ healthPath: string | null;
80
+ buildEnv: Record<string, string>;
81
+ state: "connected" | "disconnected";
82
+ };
83
+ export type ListBuilds = {
84
+ limit?: number;
85
+ cursor?: string;
86
+ name?: string;
87
+ label?: string[];
88
+ state?: BuildState[];
89
+ };
90
+ export type ListRepositories = Omit<ListBuilds, "state"> & {
91
+ state?: Repository["state"][];
92
+ };
93
+ export type BuildLine = {
94
+ cursor: string | null;
95
+ at: number;
96
+ step: string | null;
97
+ text: string;
98
+ stream: "stdout" | "stderr";
99
+ };
100
+ export type FailingStep = {
101
+ name: string;
102
+ exitCode: number | null;
103
+ lastLines: string[];
104
+ };
105
+ export type BuildLog = {
106
+ lines: BuildLine[];
107
+ cursor: string | null;
108
+ state: BuildState;
109
+ reason: string | null;
110
+ failingStep: FailingStep | null;
111
+ hasMore: boolean;
112
+ nextCursor: string | null;
113
+ };
114
+ export type BuildLogEvent = ({
115
+ type: "line";
116
+ } & BuildLine & {
117
+ cursor: string;
118
+ }) | {
119
+ type: "gap";
120
+ cursor: string | null;
121
+ earliestCursor: string;
122
+ } | {
123
+ type: "terminal";
124
+ cursor: string | null;
125
+ state: "succeeded" | "failed" | "cancelled" | "superseded";
126
+ reason: string;
127
+ failingStep: FailingStep | null;
128
+ };
129
+ /** cursor resumes a follow; pageCursor pages older search results. */
130
+ export type LogOptions = {
131
+ follow?: boolean;
132
+ cursor?: string;
133
+ pageCursor?: string;
134
+ };
135
+ export declare function builds(t: Transport): {
136
+ create: (input: CreateBuild, options?: RequestOptions) => Promise<Build>;
137
+ get: (id: string, options?: RequestOptions) => Promise<Build>;
138
+ list: (query?: ListBuilds, options?: RequestOptions) => Promise<Page<Build>>;
139
+ logs: {
140
+ (id: string, query: LogOptions & {
141
+ follow: true;
142
+ }, options?: RequestOptions): AsyncGenerator<BuildLogEvent>;
143
+ (id: string, query?: LogOptions & {
144
+ follow?: false;
145
+ }, options?: RequestOptions): Promise<BuildLog>;
146
+ (id: string, query: LogOptions, options?: RequestOptions): Promise<BuildLog> | AsyncGenerator<BuildLogEvent>;
147
+ };
148
+ cancel: (id: string, options?: RequestOptions) => Promise<Build>;
149
+ repositories: {
150
+ connect: (input: ConnectRepository, options?: RequestOptions) => Promise<Repository>;
151
+ list: (query?: ListRepositories, options?: RequestOptions) => Promise<Page<Repository>>;
152
+ update: (id: string, change: ChangeRepository, options?: RequestOptions) => Promise<Repository>;
153
+ disconnect: (id: string, options?: RequestOptions) => Promise<Repository>;
154
+ };
155
+ };
156
+ export {};