@blaxel/core 0.3.20 → 0.3.21-preview.292

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 (47) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/client/sdk.gen.js +95 -2
  3. package/dist/cjs/common/settings.js +2 -2
  4. package/dist/cjs/index.js +1 -0
  5. package/dist/cjs/sandbox/index.js +1 -0
  6. package/dist/cjs/sandbox/sandbox.js +9 -0
  7. package/dist/cjs/sandbox/snapshot.js +77 -0
  8. package/dist/cjs/snapshot/index.js +145 -0
  9. package/dist/cjs/types/client/sdk.gen.d.ts +26 -1
  10. package/dist/cjs/types/client/types.gen.d.ts +277 -11
  11. package/dist/cjs/types/index.d.ts +1 -0
  12. package/dist/cjs/types/sandbox/index.d.ts +1 -0
  13. package/dist/cjs/types/sandbox/sandbox.d.ts +10 -2
  14. package/dist/cjs/types/sandbox/snapshot.d.ts +40 -0
  15. package/dist/cjs/types/snapshot/index.d.ts +103 -0
  16. package/dist/cjs-browser/.tsbuildinfo +1 -1
  17. package/dist/cjs-browser/client/sdk.gen.js +95 -2
  18. package/dist/cjs-browser/common/settings.js +2 -2
  19. package/dist/cjs-browser/index.js +1 -0
  20. package/dist/cjs-browser/sandbox/index.js +1 -0
  21. package/dist/cjs-browser/sandbox/sandbox.js +9 -0
  22. package/dist/cjs-browser/sandbox/snapshot.js +77 -0
  23. package/dist/cjs-browser/snapshot/index.js +145 -0
  24. package/dist/cjs-browser/types/client/sdk.gen.d.ts +26 -1
  25. package/dist/cjs-browser/types/client/types.gen.d.ts +277 -11
  26. package/dist/cjs-browser/types/index.d.ts +1 -0
  27. package/dist/cjs-browser/types/sandbox/index.d.ts +1 -0
  28. package/dist/cjs-browser/types/sandbox/sandbox.d.ts +10 -2
  29. package/dist/cjs-browser/types/sandbox/snapshot.d.ts +40 -0
  30. package/dist/cjs-browser/types/snapshot/index.d.ts +103 -0
  31. package/dist/esm/.tsbuildinfo +1 -1
  32. package/dist/esm/client/sdk.gen.js +88 -0
  33. package/dist/esm/common/settings.js +2 -2
  34. package/dist/esm/index.js +1 -0
  35. package/dist/esm/sandbox/index.js +1 -0
  36. package/dist/esm/sandbox/sandbox.js +9 -0
  37. package/dist/esm/sandbox/snapshot.js +73 -0
  38. package/dist/esm/snapshot/index.js +141 -0
  39. package/dist/esm-browser/.tsbuildinfo +1 -1
  40. package/dist/esm-browser/client/sdk.gen.js +88 -0
  41. package/dist/esm-browser/common/settings.js +2 -2
  42. package/dist/esm-browser/index.js +1 -0
  43. package/dist/esm-browser/sandbox/index.js +1 -0
  44. package/dist/esm-browser/sandbox/sandbox.js +9 -0
  45. package/dist/esm-browser/sandbox/snapshot.js +73 -0
  46. package/dist/esm-browser/snapshot/index.js +141 -0
  47. package/package.json +1 -1
@@ -2168,6 +2168,94 @@ export const deleteApiKeyForServiceAccount = (options) => {
2168
2168
  ...options
2169
2169
  });
2170
2170
  };
2171
+ /**
2172
+ * List snapshots
2173
+ * Returns the snapshots of the workspace, newest first by default, including the ones whose source object has been deleted. Starting with API version 2026-04-28 the response is wrapped in `{data, meta}` and supports cursor pagination via the `cursor` and `limit` query parameters; older versions keep returning a bare array.
2174
+ */
2175
+ export const listSnapshots = (options) => {
2176
+ return (options?.client ?? _heyApiClient).get({
2177
+ security: [
2178
+ {
2179
+ scheme: 'bearer',
2180
+ type: 'http'
2181
+ }
2182
+ ],
2183
+ url: '/snapshots',
2184
+ ...options
2185
+ });
2186
+ };
2187
+ /**
2188
+ * Create snapshot
2189
+ * Captures a snapshot from a source object. The snapshot belongs to the workspace rather than to its source, so it survives the deletion of the object it was captured from, and carries what creating a sandbox or an application from it needs.
2190
+ */
2191
+ export const createSnapshot = (options) => {
2192
+ return (options.client ?? _heyApiClient).post({
2193
+ security: [
2194
+ {
2195
+ scheme: 'bearer',
2196
+ type: 'http'
2197
+ }
2198
+ ],
2199
+ url: '/snapshots',
2200
+ ...options,
2201
+ headers: {
2202
+ 'Content-Type': 'application/json',
2203
+ ...options?.headers
2204
+ }
2205
+ });
2206
+ };
2207
+ /**
2208
+ * Delete snapshot
2209
+ * Deletes a snapshot. There is a single snapshot object, so this removes it for the whole workspace, whether or not the object it was captured from still exists.
2210
+ */
2211
+ export const deleteSnapshot = (options) => {
2212
+ return (options.client ?? _heyApiClient).delete({
2213
+ security: [
2214
+ {
2215
+ scheme: 'bearer',
2216
+ type: 'http'
2217
+ }
2218
+ ],
2219
+ url: '/snapshots/{snapshotName}',
2220
+ ...options
2221
+ });
2222
+ };
2223
+ /**
2224
+ * Get snapshot
2225
+ * Returns a snapshot of the workspace by name.
2226
+ */
2227
+ export const getSnapshot = (options) => {
2228
+ return (options.client ?? _heyApiClient).get({
2229
+ security: [
2230
+ {
2231
+ scheme: 'bearer',
2232
+ type: 'http'
2233
+ }
2234
+ ],
2235
+ url: '/snapshots/{snapshotName}',
2236
+ ...options
2237
+ });
2238
+ };
2239
+ /**
2240
+ * Fork snapshot
2241
+ * Creates a new sandbox or application from a snapshot. The snapshot is enough on its own, so this works after the object it was captured from has been deleted.
2242
+ */
2243
+ export const forkSnapshot = (options) => {
2244
+ return (options.client ?? _heyApiClient).post({
2245
+ security: [
2246
+ {
2247
+ scheme: 'bearer',
2248
+ type: 'http'
2249
+ }
2250
+ ],
2251
+ url: '/snapshots/{snapshotName}/fork',
2252
+ ...options,
2253
+ headers: {
2254
+ 'Content-Type': 'application/json',
2255
+ ...options?.headers
2256
+ }
2257
+ });
2258
+ };
2171
2259
  /**
2172
2260
  * List deployment templates
2173
2261
  * Returns all deployment templates available for creating agents, functions, and other resources with pre-configured settings and code.
@@ -24,8 +24,8 @@ function missingCredentialsMessage() {
24
24
  return "No Blaxel credentials found. Set the BL_API_KEY and BL_WORKSPACE environment variables, or run `bl login`.";
25
25
  }
26
26
  // Build info - these placeholders are replaced at build time by build:replace-imports
27
- const BUILD_VERSION = "0.3.20";
28
- const BUILD_COMMIT = "0be98e0951c3607a16d4c40b7612ad7a8c147703";
27
+ const BUILD_VERSION = "0.3.21-preview.292";
28
+ const BUILD_COMMIT = "3ccc635cd5e9e15a606e3b4c4ae618f992bf4eed";
29
29
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
30
30
  const BLAXEL_API_VERSION = "2026-04-28";
31
31
  // Bun < 1.3.11 never sends connection-level WINDOW_UPDATE: the pooled h2
package/dist/esm/index.js CHANGED
@@ -18,6 +18,7 @@ export * from "./jobs/index.js";
18
18
  export * from "./mcp/index.js";
19
19
  export * from "./models/index.js";
20
20
  export * from "./sandbox/index.js";
21
+ export * from "./snapshot/index.js";
21
22
  export * from "./telemetry/telemetry.js";
22
23
  export * from "./tools/index.js";
23
24
  export * from "./tools/types.js";
@@ -7,6 +7,7 @@ export * from "./codegen/index.js";
7
7
  export { SandboxDrive } from "./drive/index.js";
8
8
  export * from "./preview.js";
9
9
  export * from "./schedule.js";
10
+ export * from "./snapshot.js";
10
11
  export * from "./session.js";
11
12
  export * from "./sandbox.js";
12
13
  export * from "./system.js";
@@ -10,6 +10,7 @@ import { SandboxNetwork } from "./network/index.js";
10
10
  import { SandboxPreviews } from "./preview.js";
11
11
  import { SandboxProcess } from "./process/index.js";
12
12
  import { SandboxSchedules } from "./schedule.js";
13
+ import { SandboxSnapshotsResource } from "./snapshot.js";
13
14
  import { SandboxSessions } from "./session.js";
14
15
  import { SandboxSystem } from "./system.js";
15
16
  import { normalizeEnvs, normalizePorts, normalizeVolumes } from "./types.js";
@@ -74,6 +75,7 @@ export class SandboxInstance {
74
75
  codegen;
75
76
  system;
76
77
  drives;
78
+ snapshots;
77
79
  h2Session;
78
80
  constructor(sandbox) {
79
81
  this.sandbox = sandbox;
@@ -86,6 +88,7 @@ export class SandboxInstance {
86
88
  this.codegen = new SandboxCodegen(sandbox);
87
89
  this.system = new SandboxSystem(sandbox);
88
90
  this.drives = new SandboxDrive(sandbox);
91
+ this.snapshots = new SandboxSnapshotsResource(sandbox);
89
92
  this.h2Session = null;
90
93
  }
91
94
  get metadata() {
@@ -159,6 +162,7 @@ export class SandboxInstance {
159
162
  * sandbox state and can be forked into new sandboxes or applications.
160
163
  *
161
164
  * @param name - Optional human-readable name for the snapshot.
165
+ * @deprecated Use `sandbox.snapshots.create(name)`.
162
166
  */
163
167
  async snapshot(name) {
164
168
  const { data } = await createSandboxSnapshot({
@@ -170,6 +174,8 @@ export class SandboxInstance {
170
174
  }
171
175
  /**
172
176
  * List the snapshots of this sandbox.
177
+ *
178
+ * @deprecated Use `sandbox.snapshots.list()`.
173
179
  */
174
180
  async listSnapshots() {
175
181
  const { data } = await listSandboxSnapshots({
@@ -180,6 +186,8 @@ export class SandboxInstance {
180
186
  }
181
187
  /**
182
188
  * Delete a snapshot of this sandbox by its ID.
189
+ *
190
+ * @deprecated Use `sandbox.snapshots.delete(name)`.
183
191
  */
184
192
  async deleteSnapshot(snapshotId) {
185
193
  await deleteSandboxSnapshot({
@@ -197,6 +205,7 @@ export class SandboxInstance {
197
205
  * is: connections to a sandbox still resuming are retried by the gateway.
198
206
  *
199
207
  * @param snapshotId - ID of the snapshot to restore this sandbox to.
208
+ * @deprecated Use `sandbox.snapshots.restore(name)`.
200
209
  */
201
210
  async restore(snapshotId) {
202
211
  const { data } = await restoreSandboxSnapshot({
@@ -0,0 +1,73 @@
1
+ import { deleteSandboxSnapshot, listSandboxSnapshots, restoreSandboxSnapshot } from "../client/index.js";
2
+ import { Snapshot } from "../snapshot/index.js";
3
+ /**
4
+ * SandboxSnapshotsResource is the sandbox's view of the workspace's snapshots: the
5
+ * ones captured from it. A snapshot itself belongs to the workspace, so
6
+ * deleting one here deletes it everywhere, and it stays after this sandbox is
7
+ * deleted.
8
+ */
9
+ export class SandboxSnapshotsResource {
10
+ sandbox;
11
+ constructor(sandbox) {
12
+ this.sandbox = sandbox;
13
+ }
14
+ get sandboxName() {
15
+ return this.sandbox.metadata.name;
16
+ }
17
+ /**
18
+ * Capture a snapshot of the sandbox.
19
+ *
20
+ * @param name - Name of the snapshot, unique among this sandbox's
21
+ * snapshots. Generated when omitted.
22
+ */
23
+ async create(name) {
24
+ return await Snapshot.create({
25
+ ...(name !== undefined ? { name } : {}),
26
+ source: { name: this.sandboxName, kind: "sandbox" },
27
+ });
28
+ }
29
+ /** List the snapshots captured from this sandbox. */
30
+ async list() {
31
+ const { data } = await listSandboxSnapshots({
32
+ path: { sandboxName: this.sandboxName },
33
+ throwOnError: true,
34
+ });
35
+ return data.map((snapshot) => new Snapshot(snapshot));
36
+ }
37
+ /**
38
+ * Find a snapshot captured from this sandbox by its name, or by its
39
+ * identifier. Names are only unique within the sandbox, which is why the
40
+ * workspace-level `Snapshot.get` takes the identifier instead.
41
+ */
42
+ async get(snapshotName) {
43
+ const snapshots = await this.list();
44
+ const found = snapshots.find((s) => s.name === snapshotName || s.id === snapshotName);
45
+ if (!found) {
46
+ throw new Error(`Snapshot ${snapshotName} not found on sandbox ${this.sandboxName}`);
47
+ }
48
+ return found;
49
+ }
50
+ /**
51
+ * Delete a snapshot captured from this sandbox. The snapshot is a workspace
52
+ * object, so it is removed for the whole workspace.
53
+ */
54
+ async delete(snapshotName) {
55
+ await deleteSandboxSnapshot({
56
+ path: { sandboxName: this.sandboxName, snapshotId: snapshotName },
57
+ throwOnError: true,
58
+ });
59
+ }
60
+ /**
61
+ * Restore the sandbox to one of its snapshots. The sandbox keeps its name,
62
+ * its URLs and its previews: the running instance is torn down and rebuilt
63
+ * from the snapshot, so everything written since it was taken is lost unless
64
+ * it was snapshotted too.
65
+ */
66
+ async restore(snapshotName) {
67
+ const { data } = await restoreSandboxSnapshot({
68
+ path: { sandboxName: this.sandboxName, snapshotId: snapshotName },
69
+ throwOnError: true,
70
+ });
71
+ return data;
72
+ }
73
+ }
@@ -0,0 +1,141 @@
1
+ import { createSnapshot, deleteSnapshot, forkSnapshot, getSnapshot, listSnapshots } from "../client/index.js";
2
+ import { createPaginatedList } from "../common/pagination.js";
3
+ /**
4
+ * A snapshot is a workspace resource: it is captured from a sandbox, but it
5
+ * outlives it. Deleting the sandbox it came from leaves the snapshot in place,
6
+ * with `source.deleted` set, and it still carries what a fork needs to run.
7
+ */
8
+ export class Snapshot {
9
+ snapshot;
10
+ constructor(snapshot) {
11
+ this.snapshot = snapshot;
12
+ }
13
+ get name() {
14
+ return this.snapshot.name;
15
+ }
16
+ /** Identifier of the snapshot on the compute plane. */
17
+ get id() {
18
+ return this.snapshot.id;
19
+ }
20
+ get status() {
21
+ return this.snapshot.status;
22
+ }
23
+ get workspace() {
24
+ return this.snapshot.workspace;
25
+ }
26
+ get createdAt() {
27
+ return this.snapshot.createdAt;
28
+ }
29
+ /** The object the snapshot was captured from, and whether it still exists. */
30
+ get source() {
31
+ return this.snapshot.source;
32
+ }
33
+ /** The configuration a fork of this snapshot runs with. */
34
+ get spec() {
35
+ return this.snapshot.spec;
36
+ }
37
+ /**
38
+ * Capture a snapshot of a source object.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const snapshot = await Snapshot.create({
43
+ * name: "my-snapshot",
44
+ * source: { name: "my-sandbox" },
45
+ * });
46
+ * ```
47
+ */
48
+ static async create(config) {
49
+ const { data } = await createSnapshot({
50
+ body: {
51
+ ...(config.name !== undefined ? { name: config.name } : {}),
52
+ source: {
53
+ name: config.source.name,
54
+ ...(config.source.kind !== undefined ? { kind: config.source.kind } : {}),
55
+ },
56
+ },
57
+ throwOnError: true,
58
+ });
59
+ return new Snapshot(data);
60
+ }
61
+ /**
62
+ * Fetch a snapshot by its identifier (`snapshot.id`). Names are only unique
63
+ * within the sandbox they were captured from, so the workspace-level routes
64
+ * take the identifier; use `sandbox.snapshots.get(name)` to address one by
65
+ * name.
66
+ */
67
+ static async get(snapshotId) {
68
+ const { data } = await getSnapshot({
69
+ path: { snapshotName: snapshotId },
70
+ throwOnError: true,
71
+ });
72
+ return new Snapshot(data);
73
+ }
74
+ /**
75
+ * List one page of the workspace's snapshots.
76
+ *
77
+ * The returned page exposes `data` for the current page, `meta` for cursor
78
+ * metadata, and `nextPage()` / `autoPagingEach()` / `autoPagingToArray()`
79
+ * helpers. Iterate it directly with `for await` to walk every page.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const page = await Snapshot.list({ limit: 50 });
84
+ * for await (const snapshot of page) {
85
+ * console.log(snapshot.name);
86
+ * }
87
+ * ```
88
+ */
89
+ static async list(query) {
90
+ const fetchPage = async (pageQuery) => {
91
+ const { data } = await listSnapshots({
92
+ query: pageQuery,
93
+ throwOnError: true,
94
+ });
95
+ return data;
96
+ };
97
+ return createPaginatedList({
98
+ response: await fetchPage(query),
99
+ fetchPage,
100
+ mapItem: (snapshot) => new Snapshot(snapshot),
101
+ query,
102
+ });
103
+ }
104
+ /**
105
+ * Delete a snapshot. There is one snapshot object, so this removes it for
106
+ * the whole workspace, whether or not the sandbox it came from still exists.
107
+ */
108
+ static async delete(snapshotId) {
109
+ const { data } = await deleteSnapshot({
110
+ path: { snapshotName: snapshotId },
111
+ throwOnError: true,
112
+ });
113
+ return data;
114
+ }
115
+ async delete() {
116
+ return await Snapshot.delete(this.id);
117
+ }
118
+ /**
119
+ * Create a sandbox or an application from this snapshot. This works after
120
+ * the sandbox the snapshot was captured from has been deleted.
121
+ *
122
+ * @param targetName - Name of the sandbox/application to create.
123
+ * @param options - Fork options (target type, port, traffic, ...).
124
+ */
125
+ async fork(targetName, options = {}) {
126
+ const { data } = await forkSnapshot({
127
+ path: { snapshotName: this.id },
128
+ body: {
129
+ targetName,
130
+ targetType: options.targetType ?? "sandbox",
131
+ ...(options.port !== undefined ? { port: options.port } : {}),
132
+ ...(options.traffic !== undefined ? { traffic: options.traffic } : {}),
133
+ ...(options.customDomain !== undefined ? { customDomain: options.customDomain } : {}),
134
+ ...(options.prefix !== undefined ? { prefix: options.prefix } : {}),
135
+ ...(options.envs !== undefined ? { envs: options.envs } : {}),
136
+ },
137
+ throwOnError: true,
138
+ });
139
+ return data;
140
+ }
141
+ }