@vertesia/client 1.6.0-dev.20261022.120426Z → 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 (183) 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/AppsApi.d.ts +18 -3
  10. package/lib/AppsApi.d.ts.map +1 -1
  11. package/lib/AppsApi.js +34 -4
  12. package/lib/AppsApi.js.map +1 -1
  13. package/lib/AuditTrailApi.d.ts +6 -1
  14. package/lib/AuditTrailApi.d.ts.map +1 -1
  15. package/lib/AuditTrailApi.js +8 -0
  16. package/lib/AuditTrailApi.js.map +1 -1
  17. package/lib/IamApi.d.ts +1 -1
  18. package/lib/IamApi.js +1 -1
  19. package/lib/InteractionCatalogApi.d.ts +19 -1
  20. package/lib/InteractionCatalogApi.d.ts.map +1 -1
  21. package/lib/InteractionCatalogApi.js +30 -0
  22. package/lib/InteractionCatalogApi.js.map +1 -1
  23. package/lib/InteractionsApi.d.ts +3 -12
  24. package/lib/InteractionsApi.d.ts.map +1 -1
  25. package/lib/InteractionsApi.js +2 -23
  26. package/lib/InteractionsApi.js.map +1 -1
  27. package/lib/OAuthClientsApi.d.ts +3 -1
  28. package/lib/OAuthClientsApi.d.ts.map +1 -1
  29. package/lib/OAuthClientsApi.js +4 -0
  30. package/lib/OAuthClientsApi.js.map +1 -1
  31. package/lib/OAuthProvidersApi.d.ts +6 -2
  32. package/lib/OAuthProvidersApi.d.ts.map +1 -1
  33. package/lib/OAuthProvidersApi.js +6 -2
  34. package/lib/OAuthProvidersApi.js.map +1 -1
  35. package/lib/StreamSource.d.ts +19 -1
  36. package/lib/StreamSource.d.ts.map +1 -1
  37. package/lib/StreamSource.js +31 -1
  38. package/lib/StreamSource.js.map +1 -1
  39. package/lib/UsersApi.d.ts +7 -1
  40. package/lib/UsersApi.d.ts.map +1 -1
  41. package/lib/UsersApi.js +8 -0
  42. package/lib/UsersApi.js.map +1 -1
  43. package/lib/client.d.ts +14 -2
  44. package/lib/client.d.ts.map +1 -1
  45. package/lib/client.js +55 -8
  46. package/lib/client.js.map +1 -1
  47. package/lib/execute.d.ts.map +1 -1
  48. package/lib/execute.js +4 -2
  49. package/lib/execute.js.map +1 -1
  50. package/lib/idempotency-key.d.ts +19 -0
  51. package/lib/idempotency-key.d.ts.map +1 -0
  52. package/lib/idempotency-key.js +34 -0
  53. package/lib/idempotency-key.js.map +1 -0
  54. package/lib/nodejs/NodeStreamSource.d.ts +10 -1
  55. package/lib/nodejs/NodeStreamSource.d.ts.map +1 -1
  56. package/lib/nodejs/NodeStreamSource.js +40 -2
  57. package/lib/nodejs/NodeStreamSource.js.map +1 -1
  58. package/lib/store/AgentsApi.d.ts.map +1 -1
  59. package/lib/store/AgentsApi.js +5 -2
  60. package/lib/store/AgentsApi.js.map +1 -1
  61. package/lib/store/ContentSourcesApi.d.ts +52 -0
  62. package/lib/store/ContentSourcesApi.d.ts.map +1 -0
  63. package/lib/store/ContentSourcesApi.js +85 -0
  64. package/lib/store/ContentSourcesApi.js.map +1 -0
  65. package/lib/store/CostApi.d.ts +6 -1
  66. package/lib/store/CostApi.d.ts.map +1 -1
  67. package/lib/store/CostApi.js +7 -0
  68. package/lib/store/CostApi.js.map +1 -1
  69. package/lib/store/DashboardApi.d.ts +61 -19
  70. package/lib/store/DashboardApi.d.ts.map +1 -1
  71. package/lib/store/DashboardApi.js +75 -19
  72. package/lib/store/DashboardApi.js.map +1 -1
  73. package/lib/store/DataApi.d.ts +9 -9
  74. package/lib/store/DataApi.d.ts.map +1 -1
  75. package/lib/store/DataApi.js +14 -10
  76. package/lib/store/DataApi.js.map +1 -1
  77. package/lib/store/FilesApi.d.ts +15 -1
  78. package/lib/store/FilesApi.d.ts.map +1 -1
  79. package/lib/store/FilesApi.js +54 -75
  80. package/lib/store/FilesApi.js.map +1 -1
  81. package/lib/store/NotificationsApi.d.ts +39 -0
  82. package/lib/store/NotificationsApi.d.ts.map +1 -0
  83. package/lib/store/NotificationsApi.js +68 -0
  84. package/lib/store/NotificationsApi.js.map +1 -0
  85. package/lib/store/ObjectsApi.d.ts +6 -1
  86. package/lib/store/ObjectsApi.d.ts.map +1 -1
  87. package/lib/store/ObjectsApi.js +23 -30
  88. package/lib/store/ObjectsApi.js.map +1 -1
  89. package/lib/store/RenderingApi.d.ts.map +1 -1
  90. package/lib/store/RenderingApi.js +1 -0
  91. package/lib/store/RenderingApi.js.map +1 -1
  92. package/lib/store/WorkflowsApi.d.ts +19 -1
  93. package/lib/store/WorkflowsApi.d.ts.map +1 -1
  94. package/lib/store/WorkflowsApi.js +21 -0
  95. package/lib/store/WorkflowsApi.js.map +1 -1
  96. package/lib/store/chunked-upload.d.ts +71 -0
  97. package/lib/store/chunked-upload.d.ts.map +1 -0
  98. package/lib/store/chunked-upload.js +206 -0
  99. package/lib/store/chunked-upload.js.map +1 -0
  100. package/lib/store/client.d.ts +9 -1
  101. package/lib/store/client.d.ts.map +1 -1
  102. package/lib/store/client.js +15 -1
  103. package/lib/store/client.js.map +1 -1
  104. package/lib/store/index.d.ts +3 -0
  105. package/lib/store/index.d.ts.map +1 -1
  106. package/lib/store/index.js +3 -0
  107. package/lib/store/index.js.map +1 -1
  108. package/lib/store/node-request.browser.d.ts +14 -0
  109. package/lib/store/node-request.browser.d.ts.map +1 -0
  110. package/lib/store/node-request.browser.js +20 -0
  111. package/lib/store/node-request.browser.js.map +1 -0
  112. package/lib/store/node-request.d.ts +20 -0
  113. package/lib/store/node-request.d.ts.map +1 -0
  114. package/lib/store/node-request.js +116 -0
  115. package/lib/store/node-request.js.map +1 -0
  116. package/lib/store/node-sessions.browser.d.ts +3 -0
  117. package/lib/store/node-sessions.browser.d.ts.map +1 -0
  118. package/lib/store/node-sessions.browser.js +15 -0
  119. package/lib/store/node-sessions.browser.js.map +1 -0
  120. package/lib/store/node-sessions.d.ts +14 -0
  121. package/lib/store/node-sessions.d.ts.map +1 -0
  122. package/lib/store/node-sessions.js +88 -0
  123. package/lib/store/node-sessions.js.map +1 -0
  124. package/lib/store/signed-url.d.ts +12 -16
  125. package/lib/store/signed-url.d.ts.map +1 -1
  126. package/lib/store/signed-url.js +111 -71
  127. package/lib/store/signed-url.js.map +1 -1
  128. package/lib/store/stream-bytes.d.ts +16 -0
  129. package/lib/store/stream-bytes.d.ts.map +1 -0
  130. package/lib/store/stream-bytes.js +70 -0
  131. package/lib/store/stream-bytes.js.map +1 -0
  132. package/lib/store/upload-body.d.ts +21 -0
  133. package/lib/store/upload-body.d.ts.map +1 -0
  134. package/lib/store/upload-body.js +32 -0
  135. package/lib/store/upload-body.js.map +1 -0
  136. package/lib/store/upload-content.d.ts +21 -0
  137. package/lib/store/upload-content.d.ts.map +1 -0
  138. package/lib/store/upload-content.js +113 -0
  139. package/lib/store/upload-content.js.map +1 -0
  140. package/lib/store/upload-runtime.d.ts +21 -0
  141. package/lib/store/upload-runtime.d.ts.map +1 -0
  142. package/lib/store/upload-runtime.js +40 -0
  143. package/lib/store/upload-runtime.js.map +1 -0
  144. package/lib/vertesia-client.js +10 -9
  145. package/lib/vertesia-client.js.map +1 -1
  146. package/package.json +35 -11
  147. package/src/AccountApi.ts +3 -0
  148. package/src/AccountRolesApi.ts +29 -0
  149. package/src/AppsApi.ts +58 -4
  150. package/src/AuditTrailApi.ts +11 -0
  151. package/src/IamApi.ts +1 -1
  152. package/src/InteractionCatalogApi.ts +44 -1
  153. package/src/InteractionsApi.ts +2 -31
  154. package/src/OAuthClientsApi.ts +6 -0
  155. package/src/OAuthProvidersApi.ts +7 -2
  156. package/src/StreamSource.ts +29 -0
  157. package/src/UsersApi.ts +10 -1
  158. package/src/client.ts +72 -8
  159. package/src/execute.ts +4 -2
  160. package/src/idempotency-key.ts +34 -0
  161. package/src/nodejs/NodeStreamSource.ts +37 -2
  162. package/src/store/AgentsApi.ts +5 -2
  163. package/src/store/ContentSourcesApi.ts +126 -0
  164. package/src/store/CostApi.ts +10 -0
  165. package/src/store/DashboardApi.ts +93 -18
  166. package/src/store/DataApi.ts +14 -10
  167. package/src/store/FilesApi.ts +84 -78
  168. package/src/store/NotificationsApi.ts +103 -0
  169. package/src/store/ObjectsApi.ts +30 -34
  170. package/src/store/RenderingApi.ts +1 -0
  171. package/src/store/WorkflowsApi.ts +25 -0
  172. package/src/store/chunked-upload.ts +272 -0
  173. package/src/store/client.ts +21 -1
  174. package/src/store/index.ts +3 -0
  175. package/src/store/node-request.browser.ts +22 -0
  176. package/src/store/node-request.ts +120 -0
  177. package/src/store/node-sessions.browser.ts +16 -0
  178. package/src/store/node-sessions.ts +109 -0
  179. package/src/store/signed-url.ts +126 -72
  180. package/src/store/stream-bytes.ts +79 -0
  181. package/src/store/upload-body.ts +37 -0
  182. package/src/store/upload-content.ts +129 -0
  183. package/src/store/upload-runtime.ts +42 -0
@@ -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,35 +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, location: fileLocationForError(url), id, path });
262
- throw err;
263
- });
264
- if (!res.ok) {
265
- console.error('Failed to upload file', {
266
- status: res.status,
267
- statusText: res.statusText,
268
- location: fileLocationForError(url),
269
- id,
270
- path,
271
- });
272
- throw new Error(`Failed to upload file: ${res.statusText}`);
273
- }
252
+ return this.uploadSource(source, source instanceof StreamSource ? source.id : undefined, source.name);
253
+ }
274
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
+ );
275
268
  return { id, path };
276
269
  }
277
270
 
@@ -280,14 +273,37 @@ export class FilesApi extends ApiTopic {
280
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)
281
274
  * @returns ReadableStream
282
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
+
283
299
  async downloadFile(location: string): Promise<ReadableStream<Uint8Array<ArrayBuffer>>> {
284
- //if start with HTTPS, no download url needed - assume it's signed already
300
+ // A supplied HTTPS URL can already be signed.
285
301
  const needSign = !location.startsWith('https:');
286
302
  const { url } = needSign ? await this.getDownloadUrl(location) : { url: location };
287
303
 
288
304
  let res: Response;
289
305
  try {
290
- res = await fetchSignedUrl(url, { method: 'GET' });
306
+ res = await this.fetchDownloadUrl(url);
291
307
  } catch (error: unknown) {
292
308
  throw new FileDownloadError(location, undefined, undefined, error);
293
309
  }
@@ -319,12 +335,7 @@ export class FilesApi extends ApiTopic {
319
335
  async uploadMemoryPack(source: StreamSource | File): Promise<string> {
320
336
  const fileId = getMemoryFilePath(source.name);
321
337
  const nameWithExt = source.name.endsWith('.tar.gz') ? source.name : `${source.name}.tar.gz`;
322
- if (source instanceof File) {
323
- const file = source as File;
324
- return this.uploadFile(new StreamSource(file.stream(), nameWithExt, file.type, fileId));
325
- } else {
326
- return this.uploadFile(new StreamSource(source.stream, nameWithExt, source.type, fileId));
327
- }
338
+ return (await this.uploadSource(source, fileId, nameWithExt)).id;
328
339
  }
329
340
 
330
341
  async downloadMemoryPack(name: string, gunzip: boolean = false): Promise<ReadableStream<Uint8Array>> {
@@ -356,12 +367,7 @@ export class FilesApi extends ApiTopic {
356
367
  */
357
368
  async uploadArtifact(runId: string, name: string, source: StreamSource | File): Promise<string> {
358
369
  const artifactPath = getAgentArtifactPath(runId, name);
359
- if (source instanceof File) {
360
- const file = source as File;
361
- return this.uploadFile(new StreamSource(file.stream(), name, file.type, artifactPath));
362
- } else {
363
- return this.uploadFile(new StreamSource(source.stream, name, source.type, artifactPath));
364
- }
370
+ return (await this.uploadSource(source, artifactPath, name)).id;
365
371
  }
366
372
 
367
373
  /**
@@ -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
+ }
@@ -5,6 +5,7 @@ import {
5
5
  type BulkObjectDeleteResult,
6
6
  type BulkObjectUpdateOptions,
7
7
  type BulkObjectUpdateResult,
8
+ type BulkOperationPayload,
8
9
  type Collection,
9
10
  type ComplexSearchPayload,
10
11
  type ComputedFacetResponse,
@@ -34,6 +35,8 @@ import {
34
35
  type GetUploadUrlPayload,
35
36
  type ListContentObjectExportsResponse,
36
37
  type ListWorkflowRunsResponse,
38
+ type ObjectIntakeCostQuery,
39
+ type ObjectIntakeCostResponse,
37
40
  type ObjectSearchPayload,
38
41
  type ObjectSearchQuery,
39
42
  type ObjectSearchResponse,
@@ -58,11 +61,13 @@ export { getSupportedRenditionFormats, supportsVisualRendition } from '@vertesia
58
61
  // Re-export rendition utilities for consumers
59
62
  export { canGenerateRendition };
60
63
 
64
+ import { withIdempotencyKey } from '../idempotency-key.js';
61
65
  import { StreamSource } from '../StreamSource.js';
62
66
  import { AnalyzeDocApi } from './AnalyzeDocApi.js';
63
67
  import type { ZenoClient } from './client.js';
64
68
  import { fetchSignedUrl } from './signed-url.js';
65
- import { getUploadMimeTypeHint, resolveUploadMimeType } from './uploadMimeType.js';
69
+ import { uploadContent } from './upload-content.js';
70
+ import { getUploadMimeTypeHint } from './uploadMimeType.js';
66
71
  import { zenoBulkBaseUrl } from './zeno-bulk.js';
67
72
 
68
73
  /**
@@ -279,39 +284,19 @@ export class ObjectsApi extends ApiTopic {
279
284
  }
280
285
 
281
286
  async upload(source: StreamSource | File) {
282
- const isStream = source instanceof StreamSource;
283
- // get a signed URL to upload the file a computed mimeType and the file object id.
284
- const { url, id, mime_type } = await this.getUploadUrl({
285
- id: isStream ? source.id : undefined,
287
+ const request = {
288
+ id: source instanceof StreamSource ? source.id : undefined,
286
289
  name: source.name,
287
290
  mime_type: getUploadMimeTypeHint(source.type),
288
- });
289
- const sourceMimeType = resolveUploadMimeType(source.type, mime_type);
290
-
291
- // upload the file content to the signed URL
292
- const res = await fetchSignedUrl(url, {
293
- method: 'PUT',
294
- body: isStream ? source.stream : source,
295
- headers: sourceMimeType ? { 'Content-Type': sourceMimeType } : undefined,
296
- }).catch((err) => {
297
- console.error('Failed to upload file', err);
298
- throw err;
299
- });
300
- if (!res.ok) {
301
- console.error('Failed to upload file', { status: res.status, statusText: res.statusText, url });
302
- throw new Error(`Failed to upload file: ${res.statusText}`);
303
- }
304
-
305
- //Etag need to be unquoted
306
- //When a server returns an ETag header, it includes the quotes around the actual hash value.
307
- //This is part of the HTTP specification (RFC 7232), which states that ETags should be
308
- //enclosed in double quotes.
309
- const etag = res.headers.get('etag')?.replace(/^"(.*)"$/, '$1');
310
-
291
+ };
292
+ // A signed URL for the object's content file, or an upload session for a long stream.
293
+ const { id, mime_type, etag } = await uploadContent(this.client.files, source, request, () =>
294
+ this.getUploadUrl(request),
295
+ );
311
296
  return {
312
297
  source: id,
313
298
  name: source.name,
314
- type: sourceMimeType,
299
+ type: mime_type,
315
300
  etag,
316
301
  };
317
302
  }
@@ -324,9 +309,10 @@ export class ObjectsApi extends ApiTopic {
324
309
  },
325
310
  ): Promise<ContentObject> {
326
311
  const { content, ...payloadWithoutContent } = payload;
327
- const createPayload: CreateContentObjectPayload = {
312
+ // One key per call, reused by every retry of the POST below.
313
+ const createPayload: CreateContentObjectPayload = withIdempotencyKey(this.client, {
328
314
  ...payloadWithoutContent,
329
- };
315
+ });
330
316
  if (content instanceof StreamSource || content instanceof File) {
331
317
  createPayload.content = await this.upload(content);
332
318
  } else {
@@ -365,7 +351,7 @@ export class ObjectsApi extends ApiTopic {
365
351
  },
366
352
  ): Promise<ContentObject> {
367
353
  const metadata = await this.client.files.getMetadata(uri);
368
- const createPayload: CreateContentObjectPayload = {
354
+ const createPayload: CreateContentObjectPayload = withIdempotencyKey(this.client, {
369
355
  ...payload,
370
356
  content: {
371
357
  source: uri,
@@ -373,7 +359,7 @@ export class ObjectsApi extends ApiTopic {
373
359
  type: metadata.contentType,
374
360
  etag: metadata.etag,
375
361
  },
376
- };
362
+ });
377
363
 
378
364
  const headers: Record<string, string> = {};
379
365
  if (options?.processing_priority) {
@@ -503,7 +489,9 @@ export class ObjectsApi extends ApiTopic {
503
489
  return this.client.runOperation({
504
490
  name: 'create',
505
491
  ids: [],
506
- params: { objects, ...options },
492
+ // `CreateContentObjectPayload` keeps the known metadata interfaces assignable, so it is wider than the
493
+ // wire type the bulk payload names; the server checks each object against the single-create contract.
494
+ params: { objects, ...options } as BulkOperationPayload['params'],
507
495
  }) as Promise<BulkObjectCreateResult>;
508
496
  }
509
497
 
@@ -511,6 +499,14 @@ export class ObjectsApi extends ApiTopic {
511
499
  return this.get(`/${documentId}/workflow-runs`);
512
500
  }
513
501
 
502
+ /**
503
+ * The LLM and embedding cost of the intake workflows that processed a content object, per run and in total.
504
+ * Requires read access to the object and a billing read permission.
505
+ */
506
+ getIntakeCost(documentId: string, query?: ObjectIntakeCostQuery): Promise<ObjectIntakeCostResponse> {
507
+ return this.get(`/${documentId}/intake-cost`, { query });
508
+ }
509
+
514
510
  listRenditions(documentId: string): Promise<ContentObjectItem[]> {
515
511
  return this.get(`/${documentId}/renditions`);
516
512
  }
@@ -80,6 +80,7 @@ export class RenderingApi extends ApiTopic {
80
80
  format: payload.format,
81
81
  download_url: status.download_url,
82
82
  file_uri: status.file_uri,
83
+ warnings: status.warnings,
83
84
  };
84
85
  }
85
86
 
@@ -1,4 +1,5 @@
1
1
  import { ApiTopic, type ClientBase, type IRequestParams } from '@vertesia/api-fetch-client';
2
+ import type { WorkflowUsageQuery, WorkflowUsageStanding } from '@vertesia/common';
2
3
  import {
3
4
  type ActivityCatalog,
4
5
  type AgentEvent,
@@ -20,6 +21,7 @@ import {
20
21
  type RunsByAgentAnalyticsResponse,
21
22
  type SignalAgentPayload,
22
23
  type SignalAgentResponse,
24
+ type SubscriptionWorkflowCatalog,
23
25
  type TimeToFirstResponseAnalyticsResponse,
24
26
  type TokenUsageAnalyticsResponse,
25
27
  type ToolAnalyticsResponse,
@@ -55,6 +57,14 @@ export class WorkflowsApi extends ApiTopic {
55
57
  super(parent, '/api/v1/workflows');
56
58
  }
57
59
 
60
+ usage(query?: WorkflowUsageQuery): Promise<WorkflowUsageStanding> {
61
+ return this.get('/usage', { query });
62
+ }
63
+
64
+ getSubscriptionWorkflowCatalog(): Promise<SubscriptionWorkflowCatalog> {
65
+ return this.get('/subscription-catalog');
66
+ }
67
+
58
68
  getActivityCatalog(): Promise<ActivityCatalog> {
59
69
  return this.get('/activity-catalog');
60
70
  }
@@ -729,39 +739,48 @@ export class WorkflowsApi extends ApiTopic {
729
739
  return this.post('/analytics/first-response-behavior', { payload: query });
730
740
  }
731
741
 
742
+ /** @deprecated Workflow rules are deprecated; use event subscriptions instead. */
732
743
  rules = new WorkflowsRulesApi(this);
744
+ /** @deprecated Workflow definitions are deprecated. */
733
745
  definitions = new WorkflowsDefinitionApi(this);
734
746
  }
735
747
 
748
+ /** @deprecated Workflow rules are deprecated; use event subscriptions instead. */
736
749
  export class WorkflowsRulesApi extends ApiTopic {
737
750
  constructor(parent: WorkflowsApi) {
738
751
  super(parent, '/rules');
739
752
  }
740
753
 
754
+ /** @deprecated Workflow rules are deprecated; use event subscriptions instead. */
741
755
  list(): Promise<WorkflowRuleItem[]> {
742
756
  return this.get('/');
743
757
  }
744
758
 
759
+ /** @deprecated Workflow rules are deprecated; use event subscriptions instead. */
745
760
  retrieve(id: string): Promise<WorkflowRule> {
746
761
  return this.get(`/${id}`);
747
762
  }
748
763
 
764
+ /** @deprecated Workflow rules are deprecated; use event subscriptions instead. */
749
765
  update(id: string, payload: UpdateWorkflowRulePayload): Promise<WorkflowRule> {
750
766
  return this.put(`/${id}`, {
751
767
  payload,
752
768
  });
753
769
  }
754
770
 
771
+ /** @deprecated Workflow rules are deprecated; use event subscriptions instead. */
755
772
  create(payload: CreateWorkflowRulePayload): Promise<WorkflowRule> {
756
773
  return this.post('/', {
757
774
  payload,
758
775
  });
759
776
  }
760
777
 
778
+ /** @deprecated Workflow rules are deprecated; use event subscriptions instead. */
761
779
  delete(id: string) {
762
780
  return this.del(`/${id}`);
763
781
  }
764
782
 
783
+ /** @deprecated Workflow rules are deprecated; use event subscriptions instead. */
765
784
  execute(
766
785
  id: string,
767
786
  objectIds?: string[],
@@ -775,6 +794,7 @@ export class WorkflowsRulesApi extends ApiTopic {
775
794
  }
776
795
  }
777
796
 
797
+ /** @deprecated Workflow definitions are deprecated. */
778
798
  export class WorkflowsDefinitionApi extends ApiTopic {
779
799
  //model: DSLWorkflowDefinition;
780
800
 
@@ -782,26 +802,31 @@ export class WorkflowsDefinitionApi extends ApiTopic {
782
802
  super(parent, '/definitions');
783
803
  }
784
804
 
805
+ /** @deprecated Workflow definitions are deprecated. */
785
806
  list(): Promise<WorkflowDefinitionRef[]> {
786
807
  return this.get('/');
787
808
  }
788
809
 
810
+ /** @deprecated Workflow definitions are deprecated. */
789
811
  retrieve(id: string): Promise<DSLWorkflowDefinition> {
790
812
  return this.get(`/${id}`);
791
813
  }
792
814
 
815
+ /** @deprecated Workflow definitions are deprecated. */
793
816
  update(id: string, payload: UpdateWorkflowDefinitionPayload): Promise<DSLWorkflowDefinition> {
794
817
  return this.put(`/${id}`, {
795
818
  payload,
796
819
  });
797
820
  }
798
821
 
822
+ /** @deprecated Workflow definitions are deprecated. */
799
823
  create(payload: DSLWorkflowSpec): Promise<DSLWorkflowDefinition> {
800
824
  return this.post('/', {
801
825
  payload,
802
826
  });
803
827
  }
804
828
 
829
+ /** @deprecated Workflow definitions are deprecated. */
805
830
  delete(id: string) {
806
831
  return this.del(`/${id}`);
807
832
  }