@vertesia/client 1.6.0-dev.20261019.172735Z → 1.6.0-dev.20261120.123957Z

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 (209) hide show
  1. package/lib/AccountApi.d.ts +2 -0
  2. package/lib/AccountApi.d.ts.map +1 -1
  3. package/lib/AccountApi.js +3 -0
  4. package/lib/AccountApi.js.map +1 -1
  5. package/lib/AccountRolesApi.d.ts +11 -0
  6. package/lib/AccountRolesApi.d.ts.map +1 -0
  7. package/lib/AccountRolesApi.js +22 -0
  8. package/lib/AccountRolesApi.js.map +1 -0
  9. package/lib/ApiKeysApi.d.ts +4 -7
  10. package/lib/ApiKeysApi.d.ts.map +1 -1
  11. package/lib/ApiKeysApi.js +5 -4
  12. package/lib/ApiKeysApi.js.map +1 -1
  13. package/lib/AppsApi.d.ts +18 -3
  14. package/lib/AppsApi.d.ts.map +1 -1
  15. package/lib/AppsApi.js +34 -4
  16. package/lib/AppsApi.js.map +1 -1
  17. package/lib/AuditTrailApi.d.ts +6 -1
  18. package/lib/AuditTrailApi.d.ts.map +1 -1
  19. package/lib/AuditTrailApi.js +8 -0
  20. package/lib/AuditTrailApi.js.map +1 -1
  21. package/lib/IamApi.d.ts +1 -1
  22. package/lib/IamApi.js +1 -1
  23. package/lib/InteractionCatalogApi.d.ts +19 -1
  24. package/lib/InteractionCatalogApi.d.ts.map +1 -1
  25. package/lib/InteractionCatalogApi.js +30 -0
  26. package/lib/InteractionCatalogApi.js.map +1 -1
  27. package/lib/InteractionsApi.d.ts +6 -13
  28. package/lib/InteractionsApi.d.ts.map +1 -1
  29. package/lib/InteractionsApi.js +4 -24
  30. package/lib/InteractionsApi.js.map +1 -1
  31. package/lib/OAuthClientsApi.d.ts +3 -1
  32. package/lib/OAuthClientsApi.d.ts.map +1 -1
  33. package/lib/OAuthClientsApi.js +4 -0
  34. package/lib/OAuthClientsApi.js.map +1 -1
  35. package/lib/OAuthProvidersApi.d.ts +6 -2
  36. package/lib/OAuthProvidersApi.d.ts.map +1 -1
  37. package/lib/OAuthProvidersApi.js +6 -2
  38. package/lib/OAuthProvidersApi.js.map +1 -1
  39. package/lib/RunsApi.d.ts +3 -2
  40. package/lib/RunsApi.d.ts.map +1 -1
  41. package/lib/RunsApi.js +3 -2
  42. package/lib/RunsApi.js.map +1 -1
  43. package/lib/StreamSource.d.ts +19 -1
  44. package/lib/StreamSource.d.ts.map +1 -1
  45. package/lib/StreamSource.js +31 -1
  46. package/lib/StreamSource.js.map +1 -1
  47. package/lib/UsersApi.d.ts +7 -1
  48. package/lib/UsersApi.d.ts.map +1 -1
  49. package/lib/UsersApi.js +8 -0
  50. package/lib/UsersApi.js.map +1 -1
  51. package/lib/client.d.ts +14 -2
  52. package/lib/client.d.ts.map +1 -1
  53. package/lib/client.js +55 -8
  54. package/lib/client.js.map +1 -1
  55. package/lib/execute.d.ts +16 -2
  56. package/lib/execute.d.ts.map +1 -1
  57. package/lib/execute.js +16 -3
  58. package/lib/execute.js.map +1 -1
  59. package/lib/idempotency-key.d.ts +19 -0
  60. package/lib/idempotency-key.d.ts.map +1 -0
  61. package/lib/idempotency-key.js +34 -0
  62. package/lib/idempotency-key.js.map +1 -0
  63. package/lib/index.d.ts +1 -0
  64. package/lib/index.d.ts.map +1 -1
  65. package/lib/index.js.map +1 -1
  66. package/lib/nodejs/NodeStreamSource.d.ts +11 -1
  67. package/lib/nodejs/NodeStreamSource.d.ts.map +1 -1
  68. package/lib/nodejs/NodeStreamSource.js +56 -16
  69. package/lib/nodejs/NodeStreamSource.js.map +1 -1
  70. package/lib/store/AgentsApi.d.ts +3 -0
  71. package/lib/store/AgentsApi.d.ts.map +1 -1
  72. package/lib/store/AgentsApi.js +10 -1
  73. package/lib/store/AgentsApi.js.map +1 -1
  74. package/lib/store/ContentSourcesApi.d.ts +52 -0
  75. package/lib/store/ContentSourcesApi.d.ts.map +1 -0
  76. package/lib/store/ContentSourcesApi.js +85 -0
  77. package/lib/store/ContentSourcesApi.js.map +1 -0
  78. package/lib/store/CostApi.d.ts +6 -1
  79. package/lib/store/CostApi.d.ts.map +1 -1
  80. package/lib/store/CostApi.js +7 -0
  81. package/lib/store/CostApi.js.map +1 -1
  82. package/lib/store/DashboardApi.d.ts +61 -19
  83. package/lib/store/DashboardApi.d.ts.map +1 -1
  84. package/lib/store/DashboardApi.js +75 -19
  85. package/lib/store/DashboardApi.js.map +1 -1
  86. package/lib/store/DataApi.d.ts +9 -9
  87. package/lib/store/DataApi.d.ts.map +1 -1
  88. package/lib/store/DataApi.js +14 -10
  89. package/lib/store/DataApi.js.map +1 -1
  90. package/lib/store/FilesApi.d.ts +15 -1
  91. package/lib/store/FilesApi.d.ts.map +1 -1
  92. package/lib/store/FilesApi.js +54 -69
  93. package/lib/store/FilesApi.js.map +1 -1
  94. package/lib/store/IndexingApi.d.ts +0 -6
  95. package/lib/store/IndexingApi.d.ts.map +1 -1
  96. package/lib/store/IndexingApi.js +3 -17
  97. package/lib/store/IndexingApi.js.map +1 -1
  98. package/lib/store/NotificationsApi.d.ts +39 -0
  99. package/lib/store/NotificationsApi.d.ts.map +1 -0
  100. package/lib/store/NotificationsApi.js +68 -0
  101. package/lib/store/NotificationsApi.js.map +1 -0
  102. package/lib/store/ObjectsApi.d.ts +6 -7
  103. package/lib/store/ObjectsApi.d.ts.map +1 -1
  104. package/lib/store/ObjectsApi.js +25 -46
  105. package/lib/store/ObjectsApi.js.map +1 -1
  106. package/lib/store/RenderingApi.d.ts.map +1 -1
  107. package/lib/store/RenderingApi.js +1 -0
  108. package/lib/store/RenderingApi.js.map +1 -1
  109. package/lib/store/WorkflowsApi.d.ts +19 -1
  110. package/lib/store/WorkflowsApi.d.ts.map +1 -1
  111. package/lib/store/WorkflowsApi.js +21 -0
  112. package/lib/store/WorkflowsApi.js.map +1 -1
  113. package/lib/store/chunked-upload.d.ts +71 -0
  114. package/lib/store/chunked-upload.d.ts.map +1 -0
  115. package/lib/store/chunked-upload.js +206 -0
  116. package/lib/store/chunked-upload.js.map +1 -0
  117. package/lib/store/client.d.ts +9 -1
  118. package/lib/store/client.d.ts.map +1 -1
  119. package/lib/store/client.js +15 -1
  120. package/lib/store/client.js.map +1 -1
  121. package/lib/store/index.d.ts +3 -0
  122. package/lib/store/index.d.ts.map +1 -1
  123. package/lib/store/index.js +3 -0
  124. package/lib/store/index.js.map +1 -1
  125. package/lib/store/node-request.browser.d.ts +14 -0
  126. package/lib/store/node-request.browser.d.ts.map +1 -0
  127. package/lib/store/node-request.browser.js +20 -0
  128. package/lib/store/node-request.browser.js.map +1 -0
  129. package/lib/store/node-request.d.ts +20 -0
  130. package/lib/store/node-request.d.ts.map +1 -0
  131. package/lib/store/node-request.js +116 -0
  132. package/lib/store/node-request.js.map +1 -0
  133. package/lib/store/node-sessions.browser.d.ts +3 -0
  134. package/lib/store/node-sessions.browser.d.ts.map +1 -0
  135. package/lib/store/node-sessions.browser.js +15 -0
  136. package/lib/store/node-sessions.browser.js.map +1 -0
  137. package/lib/store/node-sessions.d.ts +14 -0
  138. package/lib/store/node-sessions.d.ts.map +1 -0
  139. package/lib/store/node-sessions.js +88 -0
  140. package/lib/store/node-sessions.js.map +1 -0
  141. package/lib/store/signed-url.d.ts +12 -16
  142. package/lib/store/signed-url.d.ts.map +1 -1
  143. package/lib/store/signed-url.js +111 -71
  144. package/lib/store/signed-url.js.map +1 -1
  145. package/lib/store/stream-bytes.d.ts +16 -0
  146. package/lib/store/stream-bytes.d.ts.map +1 -0
  147. package/lib/store/stream-bytes.js +70 -0
  148. package/lib/store/stream-bytes.js.map +1 -0
  149. package/lib/store/upload-body.d.ts +21 -0
  150. package/lib/store/upload-body.d.ts.map +1 -0
  151. package/lib/store/upload-body.js +32 -0
  152. package/lib/store/upload-body.js.map +1 -0
  153. package/lib/store/upload-content.d.ts +21 -0
  154. package/lib/store/upload-content.d.ts.map +1 -0
  155. package/lib/store/upload-content.js +113 -0
  156. package/lib/store/upload-content.js.map +1 -0
  157. package/lib/store/upload-runtime.d.ts +21 -0
  158. package/lib/store/upload-runtime.d.ts.map +1 -0
  159. package/lib/store/upload-runtime.js +40 -0
  160. package/lib/store/upload-runtime.js.map +1 -0
  161. package/lib/store/zeno-bulk.d.ts +9 -0
  162. package/lib/store/zeno-bulk.d.ts.map +1 -0
  163. package/lib/store/zeno-bulk.js +26 -0
  164. package/lib/store/zeno-bulk.js.map +1 -0
  165. package/lib/vertesia-client.js +10 -9
  166. package/lib/vertesia-client.js.map +1 -1
  167. package/package.json +38 -9
  168. package/src/AccountApi.ts +3 -0
  169. package/src/AccountRolesApi.ts +29 -0
  170. package/src/ApiKeysApi.ts +4 -12
  171. package/src/AppsApi.ts +58 -4
  172. package/src/AuditTrailApi.ts +11 -0
  173. package/src/IamApi.ts +1 -1
  174. package/src/InteractionCatalogApi.ts +44 -1
  175. package/src/InteractionsApi.ts +11 -33
  176. package/src/OAuthClientsApi.ts +6 -0
  177. package/src/OAuthProvidersApi.ts +7 -2
  178. package/src/RunsApi.ts +7 -2
  179. package/src/StreamSource.ts +29 -0
  180. package/src/UsersApi.ts +10 -1
  181. package/src/client.ts +72 -8
  182. package/src/execute.ts +33 -4
  183. package/src/idempotency-key.ts +34 -0
  184. package/src/index.ts +1 -0
  185. package/src/nodejs/NodeStreamSource.ts +63 -24
  186. package/src/store/AgentsApi.ts +13 -1
  187. package/src/store/ContentSourcesApi.ts +126 -0
  188. package/src/store/CostApi.ts +10 -0
  189. package/src/store/DashboardApi.ts +93 -18
  190. package/src/store/DataApi.ts +14 -10
  191. package/src/store/FilesApi.ts +84 -72
  192. package/src/store/IndexingApi.ts +3 -18
  193. package/src/store/NotificationsApi.ts +103 -0
  194. package/src/store/ObjectsApi.ts +32 -51
  195. package/src/store/RenderingApi.ts +1 -0
  196. package/src/store/WorkflowsApi.ts +25 -0
  197. package/src/store/chunked-upload.ts +272 -0
  198. package/src/store/client.ts +21 -1
  199. package/src/store/index.ts +3 -0
  200. package/src/store/node-request.browser.ts +22 -0
  201. package/src/store/node-request.ts +120 -0
  202. package/src/store/node-sessions.browser.ts +16 -0
  203. package/src/store/node-sessions.ts +109 -0
  204. package/src/store/signed-url.ts +126 -72
  205. package/src/store/stream-bytes.ts +79 -0
  206. package/src/store/upload-body.ts +37 -0
  207. package/src/store/upload-content.ts +129 -0
  208. package/src/store/upload-runtime.ts +42 -0
  209. package/src/store/zeno-bulk.ts +30 -0
@@ -6,12 +6,16 @@ import {
6
6
  type DashboardArchiveResult,
7
7
  type DashboardBulkArchiveResult,
8
8
  type DashboardBulkDeleteResult,
9
+ type DashboardExport,
10
+ DashboardExportStatus,
9
11
  type DashboardItem,
10
12
  type DashboardStatus,
11
13
  type DashboardVersion,
12
14
  type DashboardVersionItem,
13
15
  type DashboardVersioningStatusResponse,
14
16
  DataStoreApiHeaders,
17
+ type ExportDashboardPayload,
18
+ type ExportDashboardPreviewPayload,
15
19
  type PromoteDashboardVersionPayload,
16
20
  type UpdateDashboardPayload,
17
21
  } from '@vertesia/common';
@@ -23,7 +27,9 @@ import {
23
27
  * - Multi-panel Vega/Vega-Lite visualizations
24
28
  * - SQL-backed data sources via named queries
25
29
  *
26
- * Note: Rendering is handled by the tools (data_preview_dashboard, data_render_dashboard).
30
+ * - PNG export of a saved dashboard ({@link DashboardApi.export}) or of an unsaved one
31
+ * ({@link DashboardApi.exportPreview}). Exports run in the background: poll them with
32
+ * {@link DashboardApi.getExport}, or wait for them with {@link DashboardApi.waitForExport}.
27
33
  */
28
34
  export class DashboardApi extends ApiTopic {
29
35
  private readonly storeId: string;
@@ -58,30 +64,24 @@ export class DashboardApi extends ApiTopic {
58
64
  /**
59
65
  * Create a new dashboard.
60
66
  *
61
- * @param payload - Dashboard configuration with queries and panels
67
+ * @param payload - Dashboard name, SQL data source and Vega-Lite spec
62
68
  * @returns The created dashboard
63
69
  *
64
70
  * @example
65
71
  * ```typescript
66
72
  * const dashboard = await client.data.dashboards(storeId).create({
67
73
  * name: 'Sales Overview',
68
- * queries: [
69
- * { name: 'revenue', sql: 'SELECT month, SUM(amount) FROM sales GROUP BY month' }
70
- * ],
71
- * panels: [
72
- * {
73
- * title: 'Monthly Revenue',
74
- * dataSources: ['revenue'],
75
- * position: { row: 0, col: 0 },
76
- * spec: {
77
- * mark: 'bar',
78
- * encoding: {
79
- * x: { field: 'month', type: 'ordinal' },
80
- * y: { field: 'sum_amount', type: 'quantitative' }
81
- * }
82
- * }
74
+ * dataSource: {
75
+ * kind: 'data_sql',
76
+ * query: 'SELECT month, SUM(amount) AS revenue FROM sales GROUP BY month',
77
+ * },
78
+ * spec: {
79
+ * mark: 'bar',
80
+ * encoding: {
81
+ * x: { field: 'month', type: 'ordinal' },
82
+ * y: { field: 'revenue', type: 'quantitative' }
83
83
  * }
84
- * ]
84
+ * }
85
85
  * });
86
86
  * ```
87
87
  */
@@ -110,6 +110,67 @@ export class DashboardApi extends ApiTopic {
110
110
  return this.put(`/${id}`, { payload, headers: this.storeHeaders() });
111
111
  }
112
112
 
113
+ /**
114
+ * Start rendering a saved dashboard as an image.
115
+ *
116
+ * Every call renders a new image from the current data. The export starts `running`: poll it
117
+ * with {@link getExport} or wait for it with {@link waitForExport}.
118
+ *
119
+ * @param id - Dashboard ID
120
+ * @param payload - Parameter values and render options
121
+ * @returns The started export
122
+ */
123
+ export(id: string, payload: ExportDashboardPayload = {}): Promise<DashboardExport> {
124
+ return this.post(`/${id}/export`, { payload, headers: this.storeHeaders() });
125
+ }
126
+
127
+ /**
128
+ * Start rendering an unsaved dashboard (SQL query and Vega-Lite spec) as an image, without saving it.
129
+ *
130
+ * Use it to check a spec before creating or updating a dashboard: an invalid spec or query makes
131
+ * the export fail with the list of problems.
132
+ *
133
+ * @param payload - The query, spec and render options
134
+ * @returns The started export
135
+ */
136
+ exportPreview(payload: ExportDashboardPreviewPayload): Promise<DashboardExport> {
137
+ return this.post('/export', { payload, headers: this.storeHeaders() });
138
+ }
139
+
140
+ /**
141
+ * Get the status of an export. Once it is `completed`, each call returns a fresh download URL.
142
+ *
143
+ * @param exportId - The `export_id` returned when the export was started
144
+ * @returns The export
145
+ */
146
+ getExport(exportId: string): Promise<DashboardExport> {
147
+ return this.get(`/exports/${exportId}`, { headers: this.storeHeaders() });
148
+ }
149
+
150
+ /**
151
+ * Poll an export until it is `completed` or `failed`.
152
+ *
153
+ * @param exportId - The `export_id` returned when the export was started
154
+ * @param options - Poll interval (default: 1s) and timeout (default: 5 minutes)
155
+ * @returns The completed or failed export
156
+ * @throws Error when the export is still running after `timeoutMs`
157
+ */
158
+ async waitForExport(exportId: string, options: DashboardExportWaitOptions = {}): Promise<DashboardExport> {
159
+ const pollIntervalMs = options.pollIntervalMs ?? 1000;
160
+ const timeoutMs = options.timeoutMs ?? 5 * 60 * 1000;
161
+ const deadline = Date.now() + timeoutMs;
162
+ while (true) {
163
+ const current = await this.getExport(exportId);
164
+ if (current.status !== DashboardExportStatus.RUNNING) {
165
+ return current;
166
+ }
167
+ if (Date.now() >= deadline) {
168
+ throw new Error(`Dashboard export ${exportId} is still running after ${timeoutMs}ms`);
169
+ }
170
+ await sleep(pollIntervalMs);
171
+ }
172
+ }
173
+
113
174
  /**
114
175
  * Archive (soft delete) a dashboard.
115
176
  *
@@ -215,3 +276,17 @@ export class DashboardApi extends ApiTopic {
215
276
  return this.put(`/${dashboardId}/versioning`, { payload: { enabled }, headers: this.storeHeaders() });
216
277
  }
217
278
  }
279
+
280
+ /**
281
+ * Options for {@link DashboardApi.waitForExport}.
282
+ */
283
+ export interface DashboardExportWaitOptions {
284
+ /** Delay between status checks, in milliseconds (default: 1000) */
285
+ pollIntervalMs?: number;
286
+ /** How long to wait before giving up, in milliseconds (default: 5 minutes) */
287
+ timeoutMs?: number;
288
+ }
289
+
290
+ function sleep(ms: number): Promise<void> {
291
+ return new Promise((resolve) => setTimeout(resolve, ms));
292
+ }
@@ -26,6 +26,7 @@ import {
26
26
  type QueryValidationResult,
27
27
  type UpdateSchemaPayload,
28
28
  } from '@vertesia/common';
29
+ import { withImportId } from '../idempotency-key.js';
29
30
  import { DashboardApi } from './DashboardApi.js';
30
31
 
31
32
  /**
@@ -279,7 +280,10 @@ export class DataApi extends ApiTopic {
279
280
  * the moment 1.5 is deployed, not at their next upgrade.
280
281
  */
281
282
  import(id: string, payload: ImportDataPayload): Promise<ImportJob> {
282
- return this.post(`/${id}/import`, { payload, headers: this.storeHeaders(id) });
283
+ return this.post(`/${id}/import`, {
284
+ payload: withImportId(this.client, payload),
285
+ headers: this.storeHeaders(id),
286
+ });
283
287
  }
284
288
 
285
289
  /**
@@ -315,7 +319,7 @@ export class DataApi extends ApiTopic {
315
319
  * Named snapshots are kept indefinitely (not subject to 30-day cleanup).
316
320
  *
317
321
  * @param id - Data store ID
318
- * @param payload - Snapshot name and optional message
322
+ * @param payload - Snapshot name and message, both non-empty
319
323
  * @returns The created version/snapshot
320
324
  *
321
325
  * @example
@@ -487,21 +491,21 @@ export class DataApi extends ApiTopic {
487
491
  * // List dashboards
488
492
  * const dashboards = await client.data.dashboards(storeId).list();
489
493
  *
490
- * // Preview a dashboard before creating
491
- * const preview = await client.data.dashboards(storeId).preview({
492
- * queries: [{ name: 'sales', sql: 'SELECT * FROM sales' }],
493
- * panels: [{ title: 'Sales', dataSources: ['sales'], ... }]
494
+ * // Preview a dashboard before creating it
495
+ * const preview = await client.data.dashboards(storeId).exportPreview({
496
+ * query: 'SELECT region, SUM(amount) AS total FROM sales GROUP BY region',
497
+ * spec: { mark: 'bar', encoding: { ... } },
494
498
  * });
495
499
  *
496
500
  * // Create a dashboard
497
501
  * const dashboard = await client.data.dashboards(storeId).create({
498
502
  * name: 'Sales Overview',
499
- * queries: [...],
500
- * panels: [...]
503
+ * query: 'SELECT region, SUM(amount) AS total FROM sales GROUP BY region',
504
+ * spec: { mark: 'bar', encoding: { ... } },
501
505
  * });
502
506
  *
503
- * // Render dashboard to PNG
504
- * const result = await client.data.dashboards(storeId).render(dashboardId);
507
+ * // Export the dashboard as a PNG (signed download URL)
508
+ * const { url } = await client.data.dashboards(storeId).export(dashboard.id);
505
509
  * ```
506
510
  */
507
511
  dashboards(storeId: string): DashboardApi {
@@ -1,9 +1,14 @@
1
1
  import { ApiTopic, type ClientBase, type IRequestRetryPolicy } from '@vertesia/api-fetch-client';
2
2
  import type {
3
+ AbortUploadSessionPayload,
4
+ AbortUploadSessionResponse,
3
5
  BucketCreateAccessStatusResponse,
4
6
  BucketReadAccessStatusResponse,
5
7
  BulkUploadUrlsPayload,
6
8
  BulkUploadUrlsResponse,
9
+ CompleteUploadSessionPayload,
10
+ CompleteUploadSessionResponse,
11
+ CreateUploadSessionPayload,
7
12
  DeleteFileResult,
8
13
  EnsureBucketCreateAccessPayload,
9
14
  EnsureBucketCreateAccessResponse,
@@ -15,12 +20,16 @@ import type {
15
20
  FileMetadataUpdateResult,
16
21
  GetFileUrlPayload,
17
22
  GetFileUrlResponse,
23
+ GetUploadPartUrlsPayload,
18
24
  GetUploadUrlPayload,
19
25
  SetFileMetadataPayload,
26
+ UploadPartUrlsResponse,
27
+ UploadSession,
20
28
  } from '@vertesia/common';
21
29
  import { StreamSource } from '../StreamSource.js';
22
30
  import { fetchSignedUrl } from './signed-url.js';
23
- import { getUploadMimeTypeHint, resolveUploadMimeType } from './uploadMimeType.js';
31
+ import { fileLocationForError, sanitizedErrorCause, uploadContent } from './upload-content.js';
32
+ import { getUploadMimeTypeHint } from './uploadMimeType.js';
24
33
 
25
34
  export const MEMORIES_PREFIX = 'memories';
26
35
  export const ARTIFACTS_PREFIX = 'agents';
@@ -31,25 +40,6 @@ const FILE_SIGNING_RETRY_POLICY: IRequestRetryPolicy = {
31
40
  statuses: [502, 503, 504],
32
41
  };
33
42
 
34
- function fileLocationForError(location: string): string {
35
- try {
36
- const url = new URL(location);
37
- return `${url.protocol}//${url.host}${url.pathname}`;
38
- } catch {
39
- return location.split(/[?#]/, 1)[0] || 'unknown file';
40
- }
41
- }
42
-
43
- function sanitizedErrorCause(error: unknown): Error | undefined {
44
- if (!(error instanceof Error)) {
45
- return undefined;
46
- }
47
- const message = error.message.replace(/https?:\/\/[^\s)\]}>"']+/g, (url) => fileLocationForError(url));
48
- const cause = new Error(message);
49
- cause.name = error.name;
50
- return cause;
51
- }
52
-
53
43
  function fileDownloadFailureReason(status?: number, statusText?: string): string {
54
44
  if (status === 404) return 'not found';
55
45
  if (status === 403) return 'forbidden';
@@ -156,6 +146,31 @@ export class FilesApi extends ApiTopic {
156
146
  });
157
147
  }
158
148
 
149
+ /**
150
+ * Start an upload in parts, for content too large for one signed PUT. The upload methods of this API use it
151
+ * for stream sources longer than one part; call it directly only to drive the store's protocol yourself.
152
+ */
153
+ createUploadSession(payload: CreateUploadSessionPayload): Promise<UploadSession> {
154
+ return this.post('/upload-sessions', { payload, retryPolicy: FILE_SIGNING_RETRY_POLICY });
155
+ }
156
+
157
+ /** Signed URLs for parts of an `s3_multipart` upload session. */
158
+ getUploadPartUrls(payload: GetUploadPartUrlsPayload): Promise<UploadPartUrlsResponse> {
159
+ return this.post('/upload-sessions/parts', { payload, retryPolicy: FILE_SIGNING_RETRY_POLICY });
160
+ }
161
+
162
+ /** Assemble the uploaded parts of an `s3_multipart` upload session into the file. */
163
+ completeUploadSession(payload: CompleteUploadSessionPayload): Promise<CompleteUploadSessionResponse> {
164
+ // Retried like the other calls: aborting all the uploaded parts for one gateway error costs far more than a
165
+ // retry of a completion that already went through, which S3 answers or refuses without harm.
166
+ return this.post('/upload-sessions/complete', { payload, retryPolicy: FILE_SIGNING_RETRY_POLICY });
167
+ }
168
+
169
+ /** Discard an unfinished `s3_multipart` upload session and its parts. */
170
+ abortUploadSession(payload: AbortUploadSessionPayload): Promise<AbortUploadSessionResponse> {
171
+ return this.post('/upload-sessions/abort', { payload, retryPolicy: FILE_SIGNING_RETRY_POLICY });
172
+ }
173
+
159
174
  // Strictly typed: provide either simple args or a full payload via a separate method
160
175
  getDownloadUrl(file: string, name?: string, disposition?: 'inline' | 'attachment'): Promise<GetFileUrlResponse> {
161
176
  const payload: GetFileUrlPayload = { file, name, disposition };
@@ -202,22 +217,13 @@ export class FilesApi extends ApiTopic {
202
217
  await Promise.all(
203
218
  batch.map(async (source, j) => {
204
219
  const idx = i + j;
205
- const { url, id, mime_type } = files[idx];
206
- const isStream = source instanceof StreamSource;
207
- const sourceMimeType = resolveUploadMimeType(source.type, mime_type);
208
-
209
- const res = await fetchSignedUrl(url, {
210
- method: 'PUT',
211
- body: isStream ? source.stream : source,
212
- headers: sourceMimeType ? { 'Content-Type': sourceMimeType } : undefined,
213
- });
214
-
215
- if (!res.ok) {
216
- throw new Error(`Failed to upload file ${source.name}: ${res.statusText}`);
217
- }
218
-
219
- const etag = res.headers.get('etag')?.replace(/^"(.*)"$/, '$1');
220
- results[idx] = { source: id, name: source.name, type: sourceMimeType, etag };
220
+ const { id, mime_type, etag } = await uploadContent(
221
+ this,
222
+ source,
223
+ fileDescriptors[idx],
224
+ async () => files[idx],
225
+ );
226
+ results[idx] = { source: id, name: source.name, type: mime_type, etag };
221
227
  }),
222
228
  );
223
229
  }
@@ -243,29 +249,22 @@ export class FilesApi extends ApiTopic {
243
249
  * @returns the uploaded file id and storage path
244
250
  */
245
251
  async uploadFileWithPath(source: StreamSource | File): Promise<{ id: string; path: string }> {
246
- const isStream = source instanceof StreamSource;
247
- const { url, id, path, mime_type } = await this.getUploadUrl({
248
- id: isStream ? source.id : undefined,
249
- name: source.name,
250
- mime_type: getUploadMimeTypeHint(source.type),
251
- });
252
- const sourceMimeType = resolveUploadMimeType(source.type, mime_type) || 'application/gzip';
253
-
254
- const res = await fetchSignedUrl(url, {
255
- method: 'PUT',
256
- body: isStream ? source.stream : source,
257
- headers: {
258
- 'Content-Type': sourceMimeType,
259
- },
260
- }).catch((err) => {
261
- console.error('Failed to upload file', { err, url, id, path });
262
- throw err;
263
- });
264
- if (!res.ok) {
265
- console.log(res);
266
- throw new Error(`Failed to upload file: ${res.statusText}`);
267
- }
252
+ return this.uploadSource(source, source instanceof StreamSource ? source.id : undefined, source.name);
253
+ }
268
254
 
255
+ /** Upload a source under a file id and name that may differ from its own. */
256
+ private async uploadSource(
257
+ source: StreamSource | File,
258
+ fileId: string | undefined,
259
+ name: string,
260
+ ): Promise<{ id: string; path: string }> {
261
+ const { id, path } = await uploadContent(
262
+ this,
263
+ source,
264
+ { id: fileId, name, mime_type: getUploadMimeTypeHint(source.type) },
265
+ undefined,
266
+ 'application/gzip',
267
+ );
269
268
  return { id, path };
270
269
  }
271
270
 
@@ -274,14 +273,37 @@ export class FilesApi extends ApiTopic {
274
273
  * @param location can be a relative path in the project, a reference to a cloud storage, or a accessible HTTPS URL (typically signed URL)
275
274
  * @returns ReadableStream
276
275
  */
276
+ async fetchDownloadUrl(url: string): Promise<Response> {
277
+ const endpoint = new URL(this.getUrl('/source-download'));
278
+ const target = new URL(url);
279
+ const ticket = target.pathname.slice(endpoint.pathname.length + 1);
280
+ if (
281
+ target.origin === endpoint.origin &&
282
+ target.pathname.startsWith(`${endpoint.pathname}/`) &&
283
+ /^[A-Za-z0-9_-]{32}$/.test(ticket) &&
284
+ !target.search &&
285
+ !target.hash &&
286
+ !target.username &&
287
+ !target.password
288
+ ) {
289
+ const request = await this.createRequest(target.href, {
290
+ method: 'GET',
291
+ headers: { ...this.headers },
292
+ redirect: 'error',
293
+ });
294
+ return this.fetch(request);
295
+ }
296
+ return fetchSignedUrl(url, { method: 'GET' });
297
+ }
298
+
277
299
  async downloadFile(location: string): Promise<ReadableStream<Uint8Array<ArrayBuffer>>> {
278
- //if start with HTTPS, no download url needed - assume it's signed already
300
+ // A supplied HTTPS URL can already be signed.
279
301
  const needSign = !location.startsWith('https:');
280
302
  const { url } = needSign ? await this.getDownloadUrl(location) : { url: location };
281
303
 
282
304
  let res: Response;
283
305
  try {
284
- res = await fetchSignedUrl(url, { method: 'GET' });
306
+ res = await this.fetchDownloadUrl(url);
285
307
  } catch (error: unknown) {
286
308
  throw new FileDownloadError(location, undefined, undefined, error);
287
309
  }
@@ -313,12 +335,7 @@ export class FilesApi extends ApiTopic {
313
335
  async uploadMemoryPack(source: StreamSource | File): Promise<string> {
314
336
  const fileId = getMemoryFilePath(source.name);
315
337
  const nameWithExt = source.name.endsWith('.tar.gz') ? source.name : `${source.name}.tar.gz`;
316
- if (source instanceof File) {
317
- const file = source as File;
318
- return this.uploadFile(new StreamSource(file.stream(), nameWithExt, file.type, fileId));
319
- } else {
320
- return this.uploadFile(new StreamSource(source.stream, nameWithExt, source.type, fileId));
321
- }
338
+ return (await this.uploadSource(source, fileId, nameWithExt)).id;
322
339
  }
323
340
 
324
341
  async downloadMemoryPack(name: string, gunzip: boolean = false): Promise<ReadableStream<Uint8Array>> {
@@ -350,12 +367,7 @@ export class FilesApi extends ApiTopic {
350
367
  */
351
368
  async uploadArtifact(runId: string, name: string, source: StreamSource | File): Promise<string> {
352
369
  const artifactPath = getAgentArtifactPath(runId, name);
353
- if (source instanceof File) {
354
- const file = source as File;
355
- return this.uploadFile(new StreamSource(file.stream(), name, file.type, artifactPath));
356
- } else {
357
- return this.uploadFile(new StreamSource(source.stream, name, source.type, artifactPath));
358
- }
370
+ return (await this.uploadSource(source, artifactPath, name)).id;
359
371
  }
360
372
 
361
373
  /**
@@ -27,6 +27,7 @@ import type {
27
27
  SwapAliasResult,
28
28
  TriggerReindexResult,
29
29
  } from '@vertesia/common';
30
+ import { zenoBulkBaseUrl } from './zeno-bulk.js';
30
31
 
31
32
  /**
32
33
  * API for indexing operations on content objects.
@@ -274,30 +275,14 @@ export class IndexingApi extends ApiTopic {
274
275
 
275
276
  // ========================================================================
276
277
  // Zeno Bulk endpoints (Go migration service)
277
- // Routes via LB path rules in prod, or derived URL in dev.
278
+ // Routes via LB path rules in prod, or derived URL in dev (see zenoBulkBaseUrl).
278
279
  // ========================================================================
279
280
 
280
- /**
281
- * Get the zeno-bulk base URL.
282
- * Dev branches: store URL contains "zeno-server" -> replace with "zeno-bulk".
283
- * Production/preview: same domain, LB routes /reindex/* to zeno-bulk.
284
- */
285
- private get zenoBulkBaseUrl(): string {
286
- const storeBaseUrl = this.client.baseUrl;
287
- if (storeBaseUrl.includes('localhost:') || storeBaseUrl.includes('127.0.0.1:')) {
288
- return 'https://zeno-bulk-dev-main.api.dev1.vertesia.io';
289
- }
290
- if (storeBaseUrl.includes('zeno-server')) {
291
- return storeBaseUrl.replace(/zeno-server/, 'zeno-bulk');
292
- }
293
- return storeBaseUrl;
294
- }
295
-
296
281
  /**
297
282
  * POST to a zeno-bulk endpoint. Resolves the path against the zeno-bulk base URL.
298
283
  */
299
284
  private zenoBulkPost<T>(path: string, body: object): Promise<T> {
300
- return this.client.post(this.zenoBulkBaseUrl + path, { payload: body });
285
+ return this.client.post(zenoBulkBaseUrl(this.client.baseUrl) + path, { payload: body });
301
286
  }
302
287
 
303
288
  /**
@@ -0,0 +1,103 @@
1
+ import { ApiTopic, type ClientBase } from '@vertesia/api-fetch-client';
2
+ import type {
3
+ ArchiveNotificationsPayload,
4
+ ListNotificationsQuery,
5
+ ListNotificationsResponse,
6
+ MarkAllNotificationsReadPayload,
7
+ MarkNotificationsReadPayload,
8
+ Notification,
9
+ NotificationCounts,
10
+ NotificationPreferences,
11
+ NotificationStreamEvent,
12
+ NotificationUpdateResult,
13
+ } from '@vertesia/common';
14
+ import {
15
+ type ManagedEventSourceConnection,
16
+ type ManagedEventSourceStatus,
17
+ openManagedEventSource,
18
+ } from '../managed-sse.js';
19
+
20
+ export interface SubscribeNotificationsOptions {
21
+ signal?: AbortSignal;
22
+ max_reconnect_attempts?: number;
23
+ /** Called when the inbox changed: fetch the counts and the newest page again. */
24
+ on_changed: (event: NotificationStreamEvent) => void;
25
+ /** Called once the stream is connected, after every reconnect, so the caller can fetch a snapshot. */
26
+ on_open?: () => void;
27
+ on_error?: (error: unknown) => void;
28
+ on_status?: (status: ManagedEventSourceStatus) => void;
29
+ }
30
+
31
+ /**
32
+ * The current user's notification inbox in the current project. Every method is scoped by the
33
+ * caller's authentication: there is no way to read or change another user's notifications.
34
+ */
35
+ export class NotificationsApi extends ApiTopic {
36
+ constructor(parent: ClientBase) {
37
+ super(parent, '/api/v1/notifications');
38
+ }
39
+
40
+ list(query: ListNotificationsQuery = {}): Promise<ListNotificationsResponse> {
41
+ return this.get('/', { query });
42
+ }
43
+
44
+ retrieve(id: string): Promise<Notification> {
45
+ return this.get(`/${id}`);
46
+ }
47
+
48
+ counts(): Promise<NotificationCounts> {
49
+ return this.get('/counts');
50
+ }
51
+
52
+ /**
53
+ * Marks notifications read, by id or by the exact occurrence the client rendered. An occurrence with
54
+ * no notification yet is held and applied when its notification is written.
55
+ */
56
+ markRead(payload: MarkNotificationsReadPayload): Promise<NotificationUpdateResult> {
57
+ return this.post('/read', { payload });
58
+ }
59
+
60
+ /** Marks read every notification written up to `before`, the `read_all_before` of a list. */
61
+ markAllRead(payload: MarkAllNotificationsReadPayload): Promise<NotificationUpdateResult> {
62
+ return this.post('/read-all', { payload });
63
+ }
64
+
65
+ archive(payload: ArchiveNotificationsPayload): Promise<NotificationUpdateResult> {
66
+ return this.post('/archive', { payload });
67
+ }
68
+
69
+ getPreferences(): Promise<NotificationPreferences> {
70
+ return this.get('/preferences');
71
+ }
72
+
73
+ updatePreferences(payload: NotificationPreferences): Promise<NotificationPreferences> {
74
+ return this.put('/preferences', { payload });
75
+ }
76
+
77
+ /**
78
+ * Opens the change stream. The stream carries no notification content: on every `changed` event
79
+ * (and on `on_open`, after a reconnect) fetch the counts and the newest page again.
80
+ */
81
+ subscribe(options: SubscribeNotificationsOptions): ManagedEventSourceConnection {
82
+ const { signal, max_reconnect_attempts, on_changed, on_open, on_error, on_status } = options;
83
+ return openManagedEventSource<NotificationStreamEvent>({
84
+ url: () => new URL(`${this.baseUrl}/stream`),
85
+ event_types: ['changed', 'ready'],
86
+ signal,
87
+ max_reconnect_attempts,
88
+ get_access_token: async () => {
89
+ const client = this.client as ClientBase & { _auth?: () => Promise<string> };
90
+ return client._auth ? await client._auth() : undefined;
91
+ },
92
+ on_error,
93
+ on_status,
94
+ on_event: ({ data, event_type }) => {
95
+ if (event_type === 'ready') {
96
+ on_open?.();
97
+ } else if (data.type === 'changed') {
98
+ on_changed(data);
99
+ }
100
+ },
101
+ });
102
+ }
103
+ }