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,103 @@
1
+ /** CLOUD.md section 4: an old product word keeps working for ALIAS_DAYS after
2
+ * its rename ships, with a warning naming the new word, and then fails with
3
+ * `name_retired` and a hint. One implementation for the API's paths, the MCP's
4
+ * tool names, the CLI's commands and the SDK's properties; each reads the table in
5
+ * product-names.ts. This file imports nothing else, so the CLI can carry it. */
6
+ import { type ProductName } from "./product-names.js";
7
+ export type Surface = "api" | "mcp" | "cli" | "sdk";
8
+ export type RetiredName = {
9
+ readonly code: "name_retired";
10
+ readonly status: 410;
11
+ readonly message: string;
12
+ readonly hint: string;
13
+ };
14
+ export type RenamedField = {
15
+ readonly name: "pot" | "potLimits";
16
+ readonly now: "startupIncluded" | "startupLimits";
17
+ readonly where: "GET /v1/usage";
18
+ readonly retires: string | null;
19
+ };
20
+ /** Response fields follow the same 30-day rule as product names. */
21
+ export declare const RENAMED_FIELDS: readonly RenamedField[];
22
+ /** CLOUD.md section 4: warn while a response field's old name works, then
23
+ * fail with the same code, status and hint as a retired product name. */
24
+ export declare function fieldUse(name: RenamedField["name"], now?: Date, table?: readonly RenamedField[]): {
25
+ kind: "renamed";
26
+ warning: string;
27
+ } | {
28
+ kind: "retired";
29
+ error: RetiredName;
30
+ };
31
+ export type NameUse =
32
+ /** The product's own word, or in the CLI its singular shortcut. */
33
+ {
34
+ readonly kind: "current";
35
+ readonly product: ProductName;
36
+ }
37
+ /** An old word, still served: say `warning` to the caller. */
38
+ | {
39
+ readonly kind: "renamed";
40
+ readonly product: ProductName;
41
+ readonly old: string;
42
+ /** The new words, `networks/wireguard` for `tunnel`. */
43
+ readonly to: string;
44
+ readonly retires: string | null;
45
+ readonly warning: string;
46
+ }
47
+ /** An old word past its date. */
48
+ | {
49
+ readonly kind: "retired";
50
+ readonly product: ProductName;
51
+ readonly old: string;
52
+ readonly to: string;
53
+ readonly error: RetiredName;
54
+ };
55
+ /** The new words for an old one: the product, then where inside it. */
56
+ export declare function newWords(product: string, under?: string): string;
57
+ /** The property path of product words in the JavaScript SDK:
58
+ * `networks/wireguard` is `networks.wireguard`, `web-analytics` is
59
+ * `webAnalytics`. */
60
+ export declare function sdkPath(words: string): string[];
61
+ /** Whether `retires` (a UTC date) has come at `now`. */
62
+ export declare function isRetired(retires: string | null, now: Date): boolean;
63
+ /** What one word means on one surface at `now`, or undefined when it names no
64
+ * product. The CLI takes a product's singular silently, unless the word is
65
+ * still another product's live old name (`tunnel` names the private network
66
+ * until it retires, then incoming tunnels). */
67
+ export declare function resolveWord(word: string, surface: Surface, now?: Date, table?: readonly ProductName[]): NameUse | undefined;
68
+ /** An API path under an old word, rewritten to the new one: `/v1/addresses/x`
69
+ * is `/v1/ips/x`. Undefined when the path's first word is not an old name. */
70
+ export declare function renamePath(pathname: string, now?: Date, table?: readonly ProductName[]): {
71
+ readonly path: string;
72
+ readonly use: Exclude<NameUse, {
73
+ kind: "current";
74
+ }>;
75
+ } | undefined;
76
+ /** An MCP tool under an old word, renamed: `runtime_sandbox_exec` is
77
+ * `runtime_sandboxes_exec`. The longest old word wins, so `runtime_web_x`
78
+ * never takes a shorter old name's place. */
79
+ export declare function renameTool(tool: string, now?: Date, table?: readonly ProductName[]): {
80
+ readonly tool: string;
81
+ readonly use: Exclude<NameUse, {
82
+ kind: "current";
83
+ }>;
84
+ } | undefined;
85
+ /** The headers an answer under an old path carries: `Deprecation` (RFC 9745)
86
+ * from the day the rename shipped, `Sunset` (RFC 8594) on the day it stops,
87
+ * a `Link` to the new path, and `Warning` with the sentence the SDK and CLI
88
+ * print. */
89
+ export declare function renamedHeaders(renamed: {
90
+ readonly path: string;
91
+ readonly use: NameUse;
92
+ }): Record<string, string>;
93
+ /** The sentence inside a `Warning: 299` header, for the SDK and CLI to print;
94
+ * undefined for any other header. */
95
+ export declare function warningText(header: string | null): string | undefined;
96
+ /** A CLI command line's product words, in their plural form: `sandbox ls` is
97
+ * `sandboxes ls` silently, and `tunnel create` is `networks wireguard create`
98
+ * with the warning to print. Undefined when the first word names no product,
99
+ * so a top-level command (`login`, `ls`) passes through. */
100
+ export declare function cliWords(args: readonly string[], now?: Date, table?: readonly ProductName[]): {
101
+ readonly args: string[];
102
+ readonly use: NameUse;
103
+ } | undefined;
@@ -0,0 +1,189 @@
1
+ /** CLOUD.md section 4: an old product word keeps working for ALIAS_DAYS after
2
+ * its rename ships, with a warning naming the new word, and then fails with
3
+ * `name_retired` and a hint. One implementation for the API's paths, the MCP's
4
+ * tool names, the CLI's commands and the SDK's properties; each reads the table in
5
+ * product-names.ts. This file imports nothing else, so the CLI can carry it. */
6
+ import { ALIAS_DAYS, PRODUCT_NAMES, wordOf } from "./product-names.js";
7
+ /** CLOUD.md section 4: the deploy shipping this batch sets its retirement
8
+ * date to the deploy day plus ALIAS_DAYS, as product-names.ts does. */
9
+ const RENAME_OF_8_OCTOBER = null;
10
+ /** Response fields follow the same 30-day rule as product names. */
11
+ export const RENAMED_FIELDS = [
12
+ { name: "pot", now: "startupIncluded", where: "GET /v1/usage", retires: RENAME_OF_8_OCTOBER },
13
+ { name: "potLimits", now: "startupLimits", where: "GET /v1/usage", retires: RENAME_OF_8_OCTOBER },
14
+ ];
15
+ /** CLOUD.md section 4: warn while a response field's old name works, then
16
+ * fail with the same code, status and hint as a retired product name. */
17
+ export function fieldUse(name, now = new Date(), table = RENAMED_FIELDS) {
18
+ const field = table.find((field) => field.name === name);
19
+ if (!field)
20
+ throw new Error(`Unknown renamed response field: ${name}`);
21
+ const from = `usage.${field.name}`;
22
+ const to = `usage.${field.now}`;
23
+ if (isRetired(field.retires, now))
24
+ return {
25
+ kind: "retired",
26
+ error: {
27
+ code: RETIRED[0],
28
+ status: RETIRED[1],
29
+ message: `${from} was renamed ${to} and stopped working on ${field.retires}.`,
30
+ hint: `Use ${to}.`,
31
+ },
32
+ };
33
+ const by = field.retires === null ? "" : ` It stops working on ${field.retires}.`;
34
+ return { kind: "renamed", warning: `${from} is now ${to}.${by}` };
35
+ }
36
+ /** The new words for an old one: the product, then where inside it. */
37
+ export function newWords(product, under) {
38
+ return under === undefined ? product : `${product}/${under}`;
39
+ }
40
+ /** How each surface writes product words (`networks/wireguard`), for
41
+ * messages. */
42
+ function spelled(words, surface) {
43
+ if (surface === "api")
44
+ return `/v1/${words}`;
45
+ if (surface === "mcp")
46
+ return `runtime_${words.replaceAll(/[-/]/g, "_")}`;
47
+ if (surface === "sdk")
48
+ return `runtime.${sdkPath(words).join(".")}`;
49
+ return `runtime ${words.replaceAll("/", " ")}`;
50
+ }
51
+ /** The property path of product words in the JavaScript SDK:
52
+ * `networks/wireguard` is `networks.wireguard`, `web-analytics` is
53
+ * `webAnalytics`. */
54
+ export function sdkPath(words) {
55
+ return words
56
+ .split("/")
57
+ .map((word) => word.replaceAll(/[-_]([a-z])/g, (_, c) => c.toUpperCase()));
58
+ }
59
+ /** Whether `retires` (a UTC date) has come at `now`. */
60
+ export function isRetired(retires, now) {
61
+ return retires !== null && now.getTime() >= Date.parse(`${retires}T00:00:00Z`);
62
+ }
63
+ /** The code and status of an old word after its date (api.md's table). */
64
+ const RETIRED = ["name_retired", 410];
65
+ /** What one word means on one surface at `now`, or undefined when it names no
66
+ * product. The CLI takes a product's singular silently, unless the word is
67
+ * still another product's live old name (`tunnel` names the private network
68
+ * until it retires, then incoming tunnels). */
69
+ export function resolveWord(word, surface, now = new Date(), table = PRODUCT_NAMES) {
70
+ const asked = wordOf(word);
71
+ const own = table.find((product) => product.name === asked);
72
+ if (own)
73
+ return { kind: "current", product: own };
74
+ let retired;
75
+ for (const product of table) {
76
+ for (const old of product.old) {
77
+ if (wordOf(old.name) !== asked)
78
+ continue;
79
+ if (surface === "cli" && product.singular === asked)
80
+ return { kind: "current", product };
81
+ const to = newWords(product.name, old.under);
82
+ const target = spelled(to, surface);
83
+ if (!isRetired(old.retires, now)) {
84
+ const by = old.retires === null ? "" : ` It stops working on ${old.retires}.`;
85
+ return {
86
+ kind: "renamed",
87
+ product,
88
+ old: asked,
89
+ to,
90
+ retires: old.retires,
91
+ warning: `${spelled(asked, surface)} is now ${target}.${by}`,
92
+ };
93
+ }
94
+ retired = {
95
+ kind: "retired",
96
+ product,
97
+ old: asked,
98
+ to,
99
+ error: {
100
+ code: RETIRED[0],
101
+ status: RETIRED[1],
102
+ message: `${spelled(asked, surface)} was renamed ${target} and stopped working on ${old.retires}.`,
103
+ hint: `Use ${target}.`,
104
+ },
105
+ };
106
+ }
107
+ }
108
+ if (surface === "cli") {
109
+ const shortcut = table.find((product) => product.singular === asked);
110
+ if (shortcut)
111
+ return { kind: "current", product: shortcut };
112
+ }
113
+ return retired;
114
+ }
115
+ /** An API path under an old word, rewritten to the new one: `/v1/addresses/x`
116
+ * is `/v1/ips/x`. Undefined when the path's first word is not an old name. */
117
+ export function renamePath(pathname, now = new Date(), table = PRODUCT_NAMES) {
118
+ const found = /^\/v1\/([a-z][a-z0-9_-]*)(?=\/|:|$)/.exec(pathname);
119
+ if (!found)
120
+ return undefined;
121
+ const use = resolveWord(found[1], "api", now, table);
122
+ if (!use || use.kind === "current")
123
+ return undefined;
124
+ return { path: `/v1/${use.to}${pathname.slice(found[0].length)}`, use };
125
+ }
126
+ /** An MCP tool under an old word, renamed: `runtime_sandbox_exec` is
127
+ * `runtime_sandboxes_exec`. The longest old word wins, so `runtime_web_x`
128
+ * never takes a shorter old name's place. */
129
+ export function renameTool(tool, now = new Date(), table = PRODUCT_NAMES) {
130
+ if (!tool.startsWith("runtime_"))
131
+ return undefined;
132
+ const rest = tool.slice("runtime_".length);
133
+ let best;
134
+ for (const product of table) {
135
+ for (const old of product.old) {
136
+ const word = wordOf(old.name).replaceAll("-", "_");
137
+ if (rest !== word && !rest.startsWith(`${word}_`))
138
+ continue;
139
+ if (best && best.word.length >= word.length)
140
+ continue;
141
+ const use = resolveWord(word, "mcp", now, table);
142
+ if (use && use.kind !== "current")
143
+ best = { word, use };
144
+ }
145
+ }
146
+ if (!best)
147
+ return undefined;
148
+ const renamed = `${spelled(best.use.to, "mcp")}${rest.slice(best.word.length)}`;
149
+ return { tool: renamed, use: best.use };
150
+ }
151
+ /** The headers an answer under an old path carries: `Deprecation` (RFC 9745)
152
+ * from the day the rename shipped, `Sunset` (RFC 8594) on the day it stops,
153
+ * a `Link` to the new path, and `Warning` with the sentence the SDK and CLI
154
+ * print. */
155
+ export function renamedHeaders(renamed) {
156
+ const { use } = renamed;
157
+ if (use.kind !== "renamed")
158
+ return {};
159
+ const headers = {
160
+ warning: `299 runtime "${use.warning.replaceAll('"', "'")}"`,
161
+ link: `<${renamed.path}>; rel="successor-version"`,
162
+ };
163
+ if (use.retires !== null) {
164
+ const ends = Date.parse(`${use.retires}T00:00:00Z`);
165
+ headers.deprecation = `@${Math.floor((ends - ALIAS_DAYS * 86_400_000) / 1000)}`;
166
+ headers.sunset = new Date(ends).toUTCString();
167
+ }
168
+ return headers;
169
+ }
170
+ /** The sentence inside a `Warning: 299` header, for the SDK and CLI to print;
171
+ * undefined for any other header. */
172
+ export function warningText(header) {
173
+ const found = header === null ? null : /^299 \S+ "(.*)"$/.exec(header);
174
+ return found ? found[1] : undefined;
175
+ }
176
+ /** A CLI command line's product words, in their plural form: `sandbox ls` is
177
+ * `sandboxes ls` silently, and `tunnel create` is `networks wireguard create`
178
+ * with the warning to print. Undefined when the first word names no product,
179
+ * so a top-level command (`login`, `ls`) passes through. */
180
+ export function cliWords(args, now = new Date(), table = PRODUCT_NAMES) {
181
+ const [first, ...rest] = args;
182
+ if (first === undefined)
183
+ return undefined;
184
+ const use = resolveWord(first, "cli", now, table);
185
+ if (!use)
186
+ return undefined;
187
+ const words = use.kind === "current" ? use.product.name : use.to;
188
+ return { args: [...words.split("/"), ...rest], use };
189
+ }
@@ -0,0 +1,73 @@
1
+ import type { RequestOptions, Transport } from "../transport.js";
2
+ export type NewKey = {
3
+ /** The key's name, and its agent's: up to 80 characters. */
4
+ name: string;
5
+ /** full (the default): every action. read: every read, nothing else. */
6
+ access?: "full" | "read";
7
+ /** agent (the default): the key sees and acts on only what it makes.
8
+ * account: everything in the account; only an account-wide key makes one. */
9
+ reach?: "agent" | "account";
10
+ /** The most its agent may commit in any 24 hours, or null for none. Needed
11
+ * when the making key has a limit: the limits of the keys a key made add
12
+ * up to at most its own. */
13
+ dailyLimitMicros?: number | null;
14
+ };
15
+ export type MadeKey = {
16
+ /** The key itself. Shown once: store it now. */
17
+ key: string;
18
+ keyId: string;
19
+ agentId: string;
20
+ orgId: string;
21
+ name: string;
22
+ access: "full" | "read";
23
+ reach: "agent" | "account";
24
+ dailyLimitMicros: number | null;
25
+ /** The making key's expiry, or null for until revoked. */
26
+ expires: string | null;
27
+ /** The id of the key that made it. */
28
+ madeBy: string;
29
+ };
30
+ export type ListedKey = {
31
+ keyId: string;
32
+ agentId: string;
33
+ name: string;
34
+ access: "full" | "read" | "selected";
35
+ reach: "agent" | "account";
36
+ dailyLimitMicros: number | null;
37
+ /** Committed in the last 24 hours: settled plus held, as the limit counts. */
38
+ dailyUsedMicros: number;
39
+ /** The key that made it, or null for one made on the website. */
40
+ madeBy: string | null;
41
+ createdAt: string;
42
+ expiresAt: string | null;
43
+ revokedAt: string | null;
44
+ };
45
+ /** One key's spend, from `GET /v1/usage?key=`. Microdollars as strings. */
46
+ export type KeyUsage = {
47
+ keyId: string;
48
+ agentId: string;
49
+ name: string;
50
+ madeBy: string | null;
51
+ revokedAt: string | null;
52
+ dailyLimitMicros: string | null;
53
+ dailyUsedMicros: string;
54
+ spentMicros: string;
55
+ heldMicros: string;
56
+ runningSandboxes: number;
57
+ resources: number;
58
+ };
59
+ export declare function keys(t: Transport): {
60
+ /** Make a key with this one. It never has more than this key, and is in
61
+ * the audit log as made by it. At most 100 live in an account. */
62
+ create: (input: NewKey, options?: RequestOptions) => Promise<MadeKey>;
63
+ /** This key and the keys it made (every key, for an account-wide key),
64
+ * live first, with what each spent in the last 24 hours. */
65
+ list: (options?: RequestOptions) => Promise<ListedKey[]>;
66
+ /** Revoke this key or one it made: a worker's, when the worker is done. */
67
+ revoke: (keyId: string, options?: RequestOptions) => Promise<{
68
+ keyId: string;
69
+ revokedAt: string;
70
+ }>;
71
+ /** What one key spent: itself, or a key it made. */
72
+ usage: (keyId: string, options?: RequestOptions) => Promise<KeyUsage>;
73
+ };
@@ -0,0 +1,23 @@
1
+ export function keys(t) {
2
+ return {
3
+ /** Make a key with this one. It never has more than this key, and is in
4
+ * the audit log as made by it. At most 100 live in an account. */
5
+ create: (input, options) => t.json({ method: "POST", path: "/v1/keys", body: input, ...options }),
6
+ /** This key and the keys it made (every key, for an account-wide key),
7
+ * live first, with what each spent in the last 24 hours. */
8
+ list: async (options) => (await t.json({ method: "GET", path: "/v1/keys", ...options })).keys,
9
+ /** Revoke this key or one it made: a worker's, when the worker is done. */
10
+ revoke: (keyId, options) => t.json({
11
+ method: "DELETE",
12
+ path: `/v1/keys/${encodeURIComponent(keyId)}`,
13
+ ...options,
14
+ }),
15
+ /** What one key spent: itself, or a key it made. */
16
+ usage: async (keyId, options) => (await t.json({
17
+ method: "GET",
18
+ path: "/v1/usage",
19
+ query: { key: keyId },
20
+ ...options,
21
+ })).key,
22
+ };
23
+ }
@@ -0,0 +1,157 @@
1
+ import type { RequestOptions, Transport } from "../transport.js";
2
+ import { type ResourceDeleteOptions, type ResourceGetOptions, type ResourceListQuery, type ResourceWaitOptions } from "./resources.js";
3
+ /** Private until launch. A deployment's completion follows its own record,
4
+ * not the app's state. */
5
+ export type AppState = "waiting" | "live" | "failed" | "deleting" | "deleted";
6
+ export type AppSettings = {
7
+ minCopies: number;
8
+ maxCopies: number;
9
+ concurrency: number;
10
+ spares: number;
11
+ vcpu: number;
12
+ memoryMiB: number;
13
+ port: number;
14
+ healthPath?: string;
15
+ };
16
+ export type App = AppSettings & {
17
+ id: string;
18
+ name: string | null;
19
+ labels: Record<string, string>;
20
+ state: AppState;
21
+ createdAt: number;
22
+ updatedAt: number;
23
+ deletedAt: number | null;
24
+ error: {
25
+ code: string;
26
+ message: string;
27
+ } | null;
28
+ liveVersion: number | null;
29
+ previousVersion: number | null;
30
+ };
31
+ export type RuntimeFunction = Omit<App, "minCopies"> & {
32
+ minCopies: 0;
33
+ };
34
+ export type CreateFunction = {
35
+ /** Up to 128 letters, digits, dots, dashes or underscores; alphanumeric first. */
36
+ name?: string;
37
+ /** At most 32 entries, each value at most 256 characters. */
38
+ labels?: Record<string, string>;
39
+ /** Required, 1 to 1000. Bounds the number of awake copies. */
40
+ maxCopies: number;
41
+ /** Required, 1 to 16. */
42
+ vcpu: number;
43
+ /** Required, 128 to 65536 MiB. */
44
+ memoryMiB: number;
45
+ /** 1 to 10000; defaults to 100. */
46
+ concurrency?: number;
47
+ /** 0 to 16; defaults to 2. */
48
+ spares?: number;
49
+ /** 1 to 65535; defaults to 8080. */
50
+ port?: number;
51
+ /** Starts with /, no whitespace, at most 256 characters.
52
+ * Omit to check whether the port accepts connections. */
53
+ healthPath?: string;
54
+ /** Only Apps can keep copies awake. Omit this field, including zero. */
55
+ minCopies?: never;
56
+ };
57
+ export type CreateApp = Omit<CreateFunction, "minCopies"> & {
58
+ /** Defaults to 0. No greater than maxCopies. */
59
+ minCopies?: number;
60
+ };
61
+ export type UpdateApp = Partial<AppSettings> & {
62
+ name?: string | null;
63
+ labels?: Record<string, string>;
64
+ };
65
+ export type UpdateFunction = Omit<UpdateApp, "minCopies"> & {
66
+ minCopies?: never;
67
+ };
68
+ export type DeployState = "building" | "warming" | "switching" | "live" | "failed" | "superseded";
69
+ export type AppDeploy = {
70
+ id: string;
71
+ version: number;
72
+ url: string;
73
+ } & ({
74
+ state: "building" | "warming" | "switching" | "live";
75
+ error?: never;
76
+ } | {
77
+ state: "failed" | "superseded";
78
+ error: {
79
+ code: "deploy_build_failed" | "deploy_health_failed" | "deploy_superseded";
80
+ message: string;
81
+ hint: string;
82
+ lastOutput: string;
83
+ };
84
+ });
85
+ export type DeployApp = ({
86
+ image: string;
87
+ build?: never;
88
+ } | {
89
+ build: string;
90
+ image?: never;
91
+ }) & {
92
+ env?: Record<string, string>;
93
+ port?: number;
94
+ healthPath?: string;
95
+ /** Return live, failed or superseded, including its URL/version or failure details. */
96
+ wait?: boolean;
97
+ };
98
+ export type AppVersion = {
99
+ version: number;
100
+ live: boolean;
101
+ previous: boolean;
102
+ saved: boolean;
103
+ };
104
+ export type AppCopy = {
105
+ id: string;
106
+ version: number;
107
+ region: string;
108
+ state: "starting" | "serving" | "draining" | "frozen" | "parked";
109
+ since: number;
110
+ };
111
+ export type DeployGetOptions = RequestOptions & {
112
+ waitFor?: DeployState;
113
+ timeoutSeconds?: number;
114
+ };
115
+ /** Defaults to waiting, live and failed. */
116
+ export type AppListQuery = ResourceListQuery<AppState>;
117
+ export type AppGetOptions = ResourceGetOptions<AppState>;
118
+ export type AppWaitOptions = ResourceWaitOptions;
119
+ export type AppDeleteOptions = ResourceDeleteOptions;
120
+ export declare function apps(t: Transport): {
121
+ /** Create a resource waiting for its first version. Defaults belong to
122
+ * the API, so the SDK does not override them. */
123
+ create: (input: CreateApp, options?: RequestOptions) => Promise<App>;
124
+ get: (id: string, options?: ResourceGetOptions<AppState>) => Promise<App>;
125
+ list: (query?: ResourceListQuery<AppState>, options?: RequestOptions) => Promise<import("../page.js").Page<App>>;
126
+ deploy: (id: string, input: DeployApp, options?: AppWaitOptions) => Promise<AppDeploy>;
127
+ getDeploy: (id: string, deployId: string, options?: DeployGetOptions) => Promise<AppDeploy>;
128
+ /** Resume by deploy id after a process restart, without creating another version. */
129
+ waitDeploy: (id: string, deployId: string, options?: AppWaitOptions) => Promise<AppDeploy>;
130
+ rollback: (id: string, options?: AppDeleteOptions) => Promise<AppDeploy>;
131
+ versions: (id: string, options?: RequestOptions) => Promise<AppVersion[]>;
132
+ copies: (id: string, options?: RequestOptions) => Promise<AppCopy[]>;
133
+ update: (id: string, input: UpdateApp, options?: RequestOptions) => Promise<App>;
134
+ /** Follow resource state, not a deployment: an
135
+ * older live version can survive a failed rollout of a newer version. */
136
+ wait: (id: string, target: "live" | "deleted", options?: AppWaitOptions) => Promise<App>;
137
+ delete: (id: string, options?: ResourceDeleteOptions) => Promise<App>;
138
+ };
139
+ export declare function functions(t: Transport): {
140
+ /** Create a resource waiting for its first version. Defaults belong to
141
+ * the API, so the SDK does not override them. */
142
+ create: (input: CreateFunction, options?: RequestOptions) => Promise<RuntimeFunction>;
143
+ get: (id: string, options?: ResourceGetOptions<AppState>) => Promise<RuntimeFunction>;
144
+ list: (query?: ResourceListQuery<AppState>, options?: RequestOptions) => Promise<import("../page.js").Page<RuntimeFunction>>;
145
+ deploy: (id: string, input: DeployApp, options?: AppWaitOptions) => Promise<AppDeploy>;
146
+ getDeploy: (id: string, deployId: string, options?: DeployGetOptions) => Promise<AppDeploy>;
147
+ /** Resume by deploy id after a process restart, without creating another version. */
148
+ waitDeploy: (id: string, deployId: string, options?: AppWaitOptions) => Promise<AppDeploy>;
149
+ rollback: (id: string, options?: AppDeleteOptions) => Promise<AppDeploy>;
150
+ versions: (id: string, options?: RequestOptions) => Promise<AppVersion[]>;
151
+ copies: (id: string, options?: RequestOptions) => Promise<AppCopy[]>;
152
+ update: (id: string, input: UpdateFunction, options?: RequestOptions) => Promise<RuntimeFunction>;
153
+ /** Follow resource state, not a deployment: an
154
+ * older live version can survive a failed rollout of a newer version. */
155
+ wait: (id: string, target: "live" | "deleted", options?: AppWaitOptions) => Promise<RuntimeFunction>;
156
+ delete: (id: string, options?: ResourceDeleteOptions) => Promise<RuntimeFunction>;
157
+ };
@@ -0,0 +1,60 @@
1
+ import { enc, following, resource, } from "./resources.js";
2
+ function copies(t, plural) {
3
+ const shape = resource(t, plural, ["failed", "deleted", "live"]);
4
+ const { base, get } = shape;
5
+ const getDeploy = (id, deployId, options = {}) => {
6
+ const { waitFor, timeoutSeconds, ...request } = options;
7
+ return t.json({
8
+ method: "GET",
9
+ path: `${base}/${enc(id)}/deploys/${enc(deployId)}`,
10
+ query: { waitFor, timeoutSeconds },
11
+ ...request,
12
+ });
13
+ };
14
+ const followDeploy = async (id, record, request, pause) => {
15
+ while (!["live", "failed", "superseded"].includes(record.state)) {
16
+ record = await getDeploy(id, record.id, { ...request, waitFor: "live", timeoutSeconds: 60 });
17
+ if (!["live", "failed", "superseded"].includes(record.state))
18
+ await pause();
19
+ }
20
+ return record;
21
+ };
22
+ const writeDeploy = (id, verb, body, wait, options) => {
23
+ const { pollMs, ...request } = options;
24
+ const write = (rest) => t.json({ method: "POST", path: `${base}/${enc(id)}/${verb}`, body, ...rest });
25
+ if (!wait)
26
+ return write(request);
27
+ return following({ ...request, pollMs, idempotencyKey: request.idempotencyKey ?? crypto.randomUUID() }, async (rest, pause) => followDeploy(id, await write(rest), rest, pause));
28
+ };
29
+ return {
30
+ /** Create a resource waiting for its first version. Defaults belong to
31
+ * the API, so the SDK does not override them. */
32
+ create: shape.create,
33
+ get,
34
+ list: shape.list,
35
+ deploy: (id, input, options = {}) => {
36
+ const { wait = false, ...body } = input;
37
+ return writeDeploy(id, "deploys", body, wait, options);
38
+ },
39
+ getDeploy,
40
+ /** Resume by deploy id after a process restart, without creating another version. */
41
+ waitDeploy: (id, deployId, options = {}) => following(options, async (request, pause) => followDeploy(id, await getDeploy(id, deployId, request), request, pause)),
42
+ rollback: (id, options = {}) => {
43
+ const { wait = false, ...request } = options;
44
+ return writeDeploy(id, "rollback", {}, wait, request);
45
+ },
46
+ versions: (id, options) => t.json({ method: "GET", path: `${base}/${enc(id)}/versions`, ...options }),
47
+ copies: (id, options) => t.json({ method: "GET", path: `${base}/${enc(id)}/copies`, ...options }),
48
+ update: shape.update,
49
+ /** Follow resource state, not a deployment: an
50
+ * older live version can survive a failed rollout of a newer version. */
51
+ wait: (id, target, options = {}) => shape.wait(id, target, options),
52
+ delete: shape.delete,
53
+ };
54
+ }
55
+ export function apps(t) {
56
+ return copies(t, "apps");
57
+ }
58
+ export function functions(t) {
59
+ return copies(t, "functions");
60
+ }