@blaxel/core 0.2.89-preview.179 → 0.2.90-dev.181

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 (80) hide show
  1. package/README.md +37 -2
  2. package/dist/cjs/.tsbuildinfo +1 -1
  3. package/dist/cjs/client/sdk.gen.js +63 -12
  4. package/dist/cjs/common/h2fetch.js +1 -1
  5. package/dist/cjs/common/pagination.js +87 -0
  6. package/dist/cjs/common/pagination.test.js +62 -0
  7. package/dist/cjs/common/settings.js +3 -3
  8. package/dist/cjs/common/settings.test.js +3 -3
  9. package/dist/cjs/drive/index.js +39 -3
  10. package/dist/cjs/index.js +1 -0
  11. package/dist/cjs/jobs/jobs.js +42 -9
  12. package/dist/cjs/sandbox/client/sdk.gen.js +1 -1
  13. package/dist/cjs/sandbox/preview.js +8 -3
  14. package/dist/cjs/sandbox/sandbox.js +41 -4
  15. package/dist/cjs/types/client/sdk.gen.d.ts +34 -19
  16. package/dist/cjs/types/client/types.gen.d.ts +704 -22
  17. package/dist/cjs/types/common/pagination.d.ts +35 -0
  18. package/dist/cjs/types/common/pagination.test.d.ts +1 -0
  19. package/dist/cjs/types/drive/index.d.ts +35 -4
  20. package/dist/cjs/types/index.d.ts +1 -0
  21. package/dist/cjs/types/jobs/jobs.d.ts +33 -3
  22. package/dist/cjs/types/sandbox/client/sdk.gen.d.ts +1 -1
  23. package/dist/cjs/types/sandbox/client/types.gen.d.ts +24 -0
  24. package/dist/cjs/types/sandbox/preview.d.ts +2 -2
  25. package/dist/cjs/types/sandbox/sandbox.d.ts +36 -2
  26. package/dist/cjs/types/volume/index.d.ts +37 -4
  27. package/dist/cjs/volume/index.js +41 -3
  28. package/dist/cjs-browser/.tsbuildinfo +1 -1
  29. package/dist/cjs-browser/client/sdk.gen.js +63 -12
  30. package/dist/cjs-browser/common/pagination.js +87 -0
  31. package/dist/cjs-browser/common/pagination.test.js +62 -0
  32. package/dist/cjs-browser/common/settings.js +3 -3
  33. package/dist/cjs-browser/common/settings.test.js +3 -3
  34. package/dist/cjs-browser/drive/index.js +39 -3
  35. package/dist/cjs-browser/index.js +1 -0
  36. package/dist/cjs-browser/jobs/jobs.js +42 -9
  37. package/dist/cjs-browser/sandbox/client/sdk.gen.js +1 -1
  38. package/dist/cjs-browser/sandbox/preview.js +8 -3
  39. package/dist/cjs-browser/sandbox/sandbox.js +41 -4
  40. package/dist/cjs-browser/types/client/sdk.gen.d.ts +34 -19
  41. package/dist/cjs-browser/types/client/types.gen.d.ts +704 -22
  42. package/dist/cjs-browser/types/common/pagination.d.ts +35 -0
  43. package/dist/cjs-browser/types/common/pagination.test.d.ts +1 -0
  44. package/dist/cjs-browser/types/drive/index.d.ts +35 -4
  45. package/dist/cjs-browser/types/index.d.ts +1 -0
  46. package/dist/cjs-browser/types/jobs/jobs.d.ts +33 -3
  47. package/dist/cjs-browser/types/sandbox/client/sdk.gen.d.ts +1 -1
  48. package/dist/cjs-browser/types/sandbox/client/types.gen.d.ts +24 -0
  49. package/dist/cjs-browser/types/sandbox/preview.d.ts +2 -2
  50. package/dist/cjs-browser/types/sandbox/sandbox.d.ts +36 -2
  51. package/dist/cjs-browser/types/volume/index.d.ts +37 -4
  52. package/dist/cjs-browser/volume/index.js +41 -3
  53. package/dist/esm/.tsbuildinfo +1 -1
  54. package/dist/esm/client/sdk.gen.js +57 -9
  55. package/dist/esm/common/h2fetch.js +1 -1
  56. package/dist/esm/common/pagination.js +83 -0
  57. package/dist/esm/common/pagination.test.js +60 -0
  58. package/dist/esm/common/settings.js +3 -3
  59. package/dist/esm/common/settings.test.js +3 -3
  60. package/dist/esm/drive/index.js +39 -3
  61. package/dist/esm/index.js +1 -0
  62. package/dist/esm/jobs/jobs.js +42 -9
  63. package/dist/esm/sandbox/client/sdk.gen.js +1 -1
  64. package/dist/esm/sandbox/preview.js +8 -3
  65. package/dist/esm/sandbox/sandbox.js +41 -4
  66. package/dist/esm/volume/index.js +41 -3
  67. package/dist/esm-browser/.tsbuildinfo +1 -1
  68. package/dist/esm-browser/client/sdk.gen.js +57 -9
  69. package/dist/esm-browser/common/pagination.js +83 -0
  70. package/dist/esm-browser/common/pagination.test.js +60 -0
  71. package/dist/esm-browser/common/settings.js +3 -3
  72. package/dist/esm-browser/common/settings.test.js +3 -3
  73. package/dist/esm-browser/drive/index.js +39 -3
  74. package/dist/esm-browser/index.js +1 -0
  75. package/dist/esm-browser/jobs/jobs.js +42 -9
  76. package/dist/esm-browser/sandbox/client/sdk.gen.js +1 -1
  77. package/dist/esm-browser/sandbox/preview.js +8 -3
  78. package/dist/esm-browser/sandbox/sandbox.js +41 -4
  79. package/dist/esm-browser/volume/index.js +41 -3
  80. package/package.json +1 -1
@@ -0,0 +1,35 @@
1
+ export type PaginatedListMeta = {
2
+ hasMore?: boolean;
3
+ nextCursor?: string;
4
+ total?: number;
5
+ };
6
+ export type CursorPaginationQuery = {
7
+ cursor?: string;
8
+ };
9
+ export type ListResponse<T> = T[] | {
10
+ data?: T[] | null;
11
+ meta?: PaginatedListMeta | null;
12
+ } | null | undefined;
13
+ export type AutoPagingEachCallback<T> = (item: T) => boolean | void | Promise<boolean | void>;
14
+ export type AutoPagingToArrayOptions = {
15
+ limit: number;
16
+ };
17
+ export type PaginatedList<T, TQuery extends CursorPaginationQuery = CursorPaginationQuery> = AsyncIterable<T> & {
18
+ data: T[];
19
+ meta: PaginatedListMeta;
20
+ hasMore: boolean;
21
+ nextCursor?: string;
22
+ nextPage(): Promise<PaginatedList<T, TQuery> | null>;
23
+ autoPagingEach(onItem: AutoPagingEachCallback<T>): Promise<void>;
24
+ autoPagingToArray(options: AutoPagingToArrayOptions): Promise<T[]>;
25
+ };
26
+ type CreatePaginatedListOptions<TRaw, TItem, TQuery extends CursorPaginationQuery> = {
27
+ response: ListResponse<TRaw>;
28
+ fetchPage: (query?: TQuery) => Promise<ListResponse<TRaw>>;
29
+ mapItem: (item: TRaw) => TItem | Promise<TItem>;
30
+ query?: TQuery;
31
+ seenCursors?: Set<string>;
32
+ };
33
+ export declare function unwrapListData<T>(response: ListResponse<T>): T[];
34
+ export declare function createPaginatedList<TRaw, TItem, TQuery extends CursorPaginationQuery = CursorPaginationQuery>({ response, fetchPage, mapItem, query, seenCursors, }: CreatePaginatedListOptions<TRaw, TItem, TQuery>): Promise<PaginatedList<TItem, TQuery>>;
35
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,11 +1,12 @@
1
- import { Drive } from "../client/index.js";
2
- export interface DriveCreateConfiguration {
1
+ import { type Drive, type ListDrivesData } from "../client/index.js";
2
+ export type DriveListQuery = NonNullable<ListDrivesData["query"]>;
3
+ export type DriveCreateConfiguration = {
3
4
  name?: string;
4
5
  displayName?: string;
5
6
  labels?: Record<string, string>;
6
7
  size?: number;
7
8
  region?: string;
8
- }
9
+ };
9
10
  export declare class DriveInstance {
10
11
  private drive;
11
12
  constructor(drive: Drive);
@@ -19,7 +20,37 @@ export declare class DriveInstance {
19
20
  get region(): string | undefined;
20
21
  static create(config: DriveCreateConfiguration | Drive): Promise<DriveInstance>;
21
22
  static get(driveName: string): Promise<DriveInstance>;
22
- static list(): Promise<DriveInstance[]>;
23
+ /**
24
+ * List one page of drives.
25
+ *
26
+ * The returned page exposes `data` for the current page, `meta` for cursor
27
+ * metadata, and helpers to fetch more pages only when you need them.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const page = await DriveInstance.list({ limit: 50 });
32
+ *
33
+ * for (const drive of page.data) {
34
+ * console.log(drive.name);
35
+ * }
36
+ *
37
+ * const nextPage = await page.nextPage();
38
+ * ```
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const allDrives = await (await DriveInstance.list()).autoPagingToArray({
43
+ * limit: 1000,
44
+ * });
45
+ * ```
46
+ */
47
+ static list(query?: DriveListQuery): Promise<import("../common/pagination.js").PaginatedList<DriveInstance, {
48
+ cursor?: string;
49
+ limit?: number;
50
+ sort?: "createdAt:desc" | "createdAt:asc" | "name:asc" | "name:desc";
51
+ q?: string;
52
+ anchor?: "end";
53
+ }>>;
23
54
  static delete(driveName: string): Promise<{
24
55
  message?: string;
25
56
  name?: string;
@@ -7,6 +7,7 @@ export * from "./common/node.js";
7
7
  export * from "./common/errors.js";
8
8
  export * from "./common/internal.js";
9
9
  export * from "./common/logger.js";
10
+ export * from "./common/pagination.js";
10
11
  export * from "./common/settings.js";
11
12
  export * from "./common/webhook.js";
12
13
  export * from "./drive/index.js";
@@ -1,4 +1,5 @@
1
- import { CreateJobExecutionRequest, JobExecution } from "../client/index.js";
1
+ import { type CreateJobExecutionRequest, type JobExecution, type ListJobExecutionsData } from "../client/index.js";
2
+ export type JobExecutionListQuery = NonNullable<ListJobExecutionsData["query"]>;
2
3
  declare class BlJob {
3
4
  jobName: string;
4
5
  constructor(jobName: string);
@@ -16,9 +17,38 @@ declare class BlJob {
16
17
  */
17
18
  getExecution(executionId: string): Promise<JobExecution>;
18
19
  /**
19
- * List all executions for this job
20
+ * List one page of executions for this job.
21
+ *
22
+ * The returned page exposes `data` for the current page, `meta` for cursor
23
+ * metadata, and helpers to fetch more pages only when you need them.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const job = blJob("daily-import");
28
+ * const page = await job.listExecutions({ limit: 50 });
29
+ *
30
+ * for (const execution of page.data) {
31
+ * console.log(execution.status);
32
+ * }
33
+ *
34
+ * const nextPage = await page.nextPage();
35
+ * ```
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const job = blJob("daily-import");
40
+ * const executions = await (await job.listExecutions()).autoPagingToArray({
41
+ * limit: 1000,
42
+ * });
43
+ * ```
20
44
  */
21
- listExecutions(): Promise<JobExecution[]>;
45
+ listExecutions(query?: JobExecutionListQuery): Promise<import("../common/pagination.js").PaginatedList<JobExecution, {
46
+ limit?: number;
47
+ offset?: number;
48
+ cursor?: string;
49
+ sort?: "createdAt:desc" | "createdAt:asc" | "name:asc" | "name:desc";
50
+ q?: string;
51
+ }>>;
22
52
  /**
23
53
  * Get the status of a specific execution
24
54
  */
@@ -61,7 +61,7 @@ export declare const getCodegenRerankingByPath: <ThrowOnError extends boolean =
61
61
  export declare const getDrivesMount: <ThrowOnError extends boolean = false>(options?: Options<GetDrivesMountData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen").DriveListResponse, import("./types.gen").ErrorResponse, ThrowOnError>;
62
62
  /**
63
63
  * Attach a drive to a local path
64
- * Mounts an agent drive using the blfs binary to a local path, optionally mounting a subpath within the drive
64
+ * Mounts an agent drive using the blfs binary to a local path, optionally mounting a subpath within the drive. Supports optional UID/GID mapping to remap file ownership between the local sandbox and the filer (always mapped to filer UID/GID 0). Mapping values can be set per-request via uidMap/gidMap fields, or globally via BLFS_UID_MAP/BLFS_GID_MAP environment variables (request values take precedence).
65
65
  */
66
66
  export declare const postDrivesMount: <ThrowOnError extends boolean = false>(options: Options<PostDrivesMountData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen").DriveMountResponse, import("./types.gen").ErrorResponse, ThrowOnError>;
67
67
  /**
@@ -37,8 +37,16 @@ export type DriveListResponse = {
37
37
  export type DriveMountInfo = {
38
38
  driveName?: string;
39
39
  drivePath?: string;
40
+ /**
41
+ * The local GID used for this mount
42
+ */
43
+ gidMap?: string;
40
44
  mountPath?: string;
41
45
  readOnly?: boolean;
46
+ /**
47
+ * The local UID used for this mount
48
+ */
49
+ uidMap?: string;
42
50
  };
43
51
  export type DriveMountRequest = {
44
52
  driveName: string;
@@ -46,19 +54,35 @@ export type DriveMountRequest = {
46
54
  * Optional, defaults to "/"
47
55
  */
48
56
  drivePath?: string;
57
+ /**
58
+ * Optional, local GID to map (filer GID is always 0)
59
+ */
60
+ gidMap?: string;
49
61
  mountPath: string;
50
62
  /**
51
63
  * Optional, defaults to false
52
64
  */
53
65
  readOnly?: boolean;
66
+ /**
67
+ * Optional, local UID to map (filer UID is always 0)
68
+ */
69
+ uidMap?: string;
54
70
  };
55
71
  export type DriveMountResponse = {
56
72
  driveName?: string;
57
73
  drivePath?: string;
74
+ /**
75
+ * The local GID used for this mount
76
+ */
77
+ gidMap?: string;
58
78
  message?: string;
59
79
  mountPath?: string;
60
80
  readOnly?: boolean;
61
81
  success?: boolean;
82
+ /**
83
+ * The local UID used for this mount
84
+ */
85
+ uidMap?: string;
62
86
  };
63
87
  export type DriveUnmountResponse = {
64
88
  message?: string;
@@ -30,8 +30,8 @@ export declare class SandboxPreviews {
30
30
  constructor(sandbox: Sandbox);
31
31
  get sandboxName(): string;
32
32
  list(): Promise<SandboxPreview[]>;
33
- create(preview: Preview): Promise<SandboxPreview>;
34
- createIfNotExists(preview: Preview): Promise<SandboxPreview>;
33
+ create(preview: Preview, force?: boolean): Promise<SandboxPreview>;
34
+ createIfNotExists(preview: Preview, force?: boolean): Promise<SandboxPreview>;
35
35
  get(previewName: string): Promise<SandboxPreview>;
36
36
  delete(previewName: string): Promise<Preview>;
37
37
  private waitForDeletion;
@@ -1,5 +1,5 @@
1
1
  import type http2 from "http2";
2
- import { SandboxLifecycle, Sandbox as SandboxModel } from "../client/index.js";
2
+ import { type ListSandboxesData, type SandboxLifecycle, type Sandbox as SandboxModel } from "../client/index.js";
3
3
  import { SandboxCodegen } from "./codegen/index.js";
4
4
  import { SandboxDrive } from "./drive/index.js";
5
5
  import { SandboxFileSystem } from "./filesystem/index.js";
@@ -9,6 +9,7 @@ import { SandboxProcess } from "./process/index.js";
9
9
  import { SandboxSessions } from "./session.js";
10
10
  import { SandboxSystem } from "./system.js";
11
11
  import { SandboxConfiguration, SandboxCreateConfiguration, SandboxUpdateMetadata, SandboxUpdateNetwork, SessionWithToken } from "./types.js";
12
+ export type SandboxListQuery = NonNullable<ListSandboxesData["query"]>;
12
13
  export declare class SandboxInstance {
13
14
  private sandbox;
14
15
  fs: SandboxFileSystem;
@@ -51,7 +52,40 @@ export declare class SandboxInstance {
51
52
  createIfNotExist?: boolean;
52
53
  }): Promise<SandboxInstance>;
53
54
  static get(sandboxName: string): Promise<SandboxInstance>;
54
- static list(): Promise<SandboxInstance[]>;
55
+ /**
56
+ * List one page of sandboxes.
57
+ *
58
+ * The returned page exposes `data` for the current page, `meta` for cursor
59
+ * metadata, and helpers to fetch more pages only when you need them.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const page = await SandboxInstance.list({ limit: 50 });
64
+ *
65
+ * for (const sandbox of page.data) {
66
+ * console.log(sandbox.metadata.name);
67
+ * }
68
+ *
69
+ * const nextPage = await page.nextPage();
70
+ * ```
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * const page = await SandboxInstance.list({ limit: 100 });
75
+ *
76
+ * for await (const sandbox of page) {
77
+ * console.log(sandbox.metadata.name);
78
+ * }
79
+ * ```
80
+ */
81
+ static list(query?: SandboxListQuery): Promise<import("../common/pagination.js").PaginatedList<SandboxInstance, {
82
+ showTerminated?: boolean;
83
+ cursor?: string;
84
+ limit?: number;
85
+ sort?: "createdAt:desc" | "createdAt:asc" | "name:asc" | "name:desc";
86
+ q?: string;
87
+ anchor?: "end";
88
+ }>>;
55
89
  static delete(sandboxName: string): Promise<SandboxModel>;
56
90
  delete(): Promise<SandboxModel>;
57
91
  static updateMetadata(sandboxName: string, metadata: SandboxUpdateMetadata): Promise<SandboxInstance>;
@@ -1,12 +1,13 @@
1
- import { Volume } from "../client/index.js";
2
- export interface VolumeCreateConfiguration {
1
+ import { type ListVolumesData, type Volume } from "../client/index.js";
2
+ export type VolumeListQuery = NonNullable<ListVolumesData["query"]>;
3
+ export type VolumeCreateConfiguration = {
3
4
  name?: string;
4
5
  displayName?: string;
5
6
  labels?: Record<string, string>;
6
7
  size?: number;
7
8
  region?: string;
8
9
  template?: string;
9
- }
10
+ };
10
11
  export declare class VolumeInstance {
11
12
  private volume;
12
13
  constructor(volume: Volume);
@@ -19,7 +20,39 @@ export declare class VolumeInstance {
19
20
  get region(): string | undefined;
20
21
  static create(config: VolumeCreateConfiguration | Volume): Promise<VolumeInstance>;
21
22
  static get(volumeName: string): Promise<VolumeInstance>;
22
- static list(): Promise<VolumeInstance[]>;
23
+ /**
24
+ * List one page of volumes.
25
+ *
26
+ * The returned page exposes `data` for the current page, `meta` for cursor
27
+ * metadata, and helpers to fetch more pages only when you need them.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const page = await VolumeInstance.list({ limit: 50 });
32
+ *
33
+ * for (const volume of page.data) {
34
+ * console.log(volume.name);
35
+ * }
36
+ *
37
+ * const nextPage = await page.nextPage();
38
+ * ```
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const page = await VolumeInstance.list({ limit: 100 });
43
+ *
44
+ * for await (const volume of page) {
45
+ * console.log(volume.name);
46
+ * }
47
+ * ```
48
+ */
49
+ static list(query?: VolumeListQuery): Promise<import("../common/pagination.js").PaginatedList<VolumeInstance, {
50
+ cursor?: string;
51
+ limit?: number;
52
+ sort?: "createdAt:desc" | "createdAt:asc" | "name:asc" | "name:desc";
53
+ q?: string;
54
+ anchor?: "end";
55
+ }>>;
23
56
  static delete(volumeName: string): Promise<Volume>;
24
57
  delete(): Promise<Volume>;
25
58
  static update(volumeName: string, updates: VolumeCreateConfiguration | Volume): Promise<VolumeInstance>;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VolumeInstance = void 0;
4
4
  const uuid_1 = require("uuid");
5
5
  const index_js_1 = require("../client/index.js");
6
+ const pagination_js_1 = require("../common/pagination.js");
6
7
  const settings_js_1 = require("../common/settings.js");
7
8
  class VolumeInstance {
8
9
  volume;
@@ -88,9 +89,46 @@ class VolumeInstance {
88
89
  });
89
90
  return new VolumeInstance(data);
90
91
  }
91
- static async list() {
92
- const { data } = await (0, index_js_1.listVolumes)({ throwOnError: true });
93
- return data.map((volume) => new VolumeInstance(volume));
92
+ /**
93
+ * List one page of volumes.
94
+ *
95
+ * The returned page exposes `data` for the current page, `meta` for cursor
96
+ * metadata, and helpers to fetch more pages only when you need them.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * const page = await VolumeInstance.list({ limit: 50 });
101
+ *
102
+ * for (const volume of page.data) {
103
+ * console.log(volume.name);
104
+ * }
105
+ *
106
+ * const nextPage = await page.nextPage();
107
+ * ```
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * const page = await VolumeInstance.list({ limit: 100 });
112
+ *
113
+ * for await (const volume of page) {
114
+ * console.log(volume.name);
115
+ * }
116
+ * ```
117
+ */
118
+ static async list(query) {
119
+ const fetchPage = async (pageQuery) => {
120
+ const { data } = await (0, index_js_1.listVolumes)({
121
+ query: pageQuery,
122
+ throwOnError: true,
123
+ });
124
+ return data;
125
+ };
126
+ return (0, pagination_js_1.createPaginatedList)({
127
+ response: await fetchPage(query),
128
+ fetchPage,
129
+ mapItem: (volume) => new VolumeInstance(volume),
130
+ query,
131
+ });
94
132
  }
95
133
  static async delete(volumeName) {
96
134
  const { data } = await (0, index_js_1.deleteVolume)({