@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
@@ -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,14 @@ 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';
71
+ import { zenoBulkBaseUrl } from './zeno-bulk.js';
66
72
 
67
73
  /**
68
74
  * The two write payloads, each widened at `content` so callers can hand us a browser `File` or a
@@ -215,24 +221,8 @@ export class ObjectsApi extends ApiTopic {
215
221
  return this.zenoBulkPost('/export/compose', payload, timeoutMs);
216
222
  }
217
223
 
218
- /**
219
- * Get the zeno-bulk base URL.
220
- * Dev branches: store URL contains "zeno-server" -> replace with "zeno-bulk".
221
- * Production/preview: same domain, LB routes /export to zeno-bulk.
222
- */
223
- private get zenoBulkBaseUrl(): string {
224
- const storeBaseUrl = this.client.baseUrl;
225
- if (storeBaseUrl.includes('localhost:') || storeBaseUrl.includes('127.0.0.1:')) {
226
- return 'https://zeno-bulk-dev-main.api.dev1.vertesia.io';
227
- }
228
- if (storeBaseUrl.includes('zeno-server')) {
229
- return storeBaseUrl.replace(/zeno-server/, 'zeno-bulk');
230
- }
231
- return storeBaseUrl;
232
- }
233
-
234
224
  private zenoBulkPost<T>(path: string, body: object, timeoutMs?: number | false | null): Promise<T> {
235
- return this.client.post(this.zenoBulkBaseUrl + path, { payload: body, timeoutMs });
225
+ return this.client.post(zenoBulkBaseUrl(this.client.baseUrl) + path, { payload: body, timeoutMs });
236
226
  }
237
227
 
238
228
  listFolders(_path: string = '/') {
@@ -294,39 +284,19 @@ export class ObjectsApi extends ApiTopic {
294
284
  }
295
285
 
296
286
  async upload(source: StreamSource | File) {
297
- const isStream = source instanceof StreamSource;
298
- // get a signed URL to upload the file a computed mimeType and the file object id.
299
- const { url, id, mime_type } = await this.getUploadUrl({
300
- id: isStream ? source.id : undefined,
287
+ const request = {
288
+ id: source instanceof StreamSource ? source.id : undefined,
301
289
  name: source.name,
302
290
  mime_type: getUploadMimeTypeHint(source.type),
303
- });
304
- const sourceMimeType = resolveUploadMimeType(source.type, mime_type);
305
-
306
- // upload the file content to the signed URL
307
- const res = await fetchSignedUrl(url, {
308
- method: 'PUT',
309
- body: isStream ? source.stream : source,
310
- headers: sourceMimeType ? { 'Content-Type': sourceMimeType } : undefined,
311
- }).catch((err) => {
312
- console.error('Failed to upload file', err);
313
- throw err;
314
- });
315
- if (!res.ok) {
316
- console.error('Failed to upload file', { status: res.status, statusText: res.statusText, url });
317
- throw new Error(`Failed to upload file: ${res.statusText}`);
318
- }
319
-
320
- //Etag need to be unquoted
321
- //When a server returns an ETag header, it includes the quotes around the actual hash value.
322
- //This is part of the HTTP specification (RFC 7232), which states that ETags should be
323
- //enclosed in double quotes.
324
- const etag = res.headers.get('etag')?.replace(/^"(.*)"$/, '$1');
325
-
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
+ );
326
296
  return {
327
297
  source: id,
328
298
  name: source.name,
329
- type: sourceMimeType,
299
+ type: mime_type,
330
300
  etag,
331
301
  };
332
302
  }
@@ -339,9 +309,10 @@ export class ObjectsApi extends ApiTopic {
339
309
  },
340
310
  ): Promise<ContentObject> {
341
311
  const { content, ...payloadWithoutContent } = payload;
342
- const createPayload: CreateContentObjectPayload = {
312
+ // One key per call, reused by every retry of the POST below.
313
+ const createPayload: CreateContentObjectPayload = withIdempotencyKey(this.client, {
343
314
  ...payloadWithoutContent,
344
- };
315
+ });
345
316
  if (content instanceof StreamSource || content instanceof File) {
346
317
  createPayload.content = await this.upload(content);
347
318
  } else {
@@ -380,7 +351,7 @@ export class ObjectsApi extends ApiTopic {
380
351
  },
381
352
  ): Promise<ContentObject> {
382
353
  const metadata = await this.client.files.getMetadata(uri);
383
- const createPayload: CreateContentObjectPayload = {
354
+ const createPayload: CreateContentObjectPayload = withIdempotencyKey(this.client, {
384
355
  ...payload,
385
356
  content: {
386
357
  source: uri,
@@ -388,7 +359,7 @@ export class ObjectsApi extends ApiTopic {
388
359
  type: metadata.contentType,
389
360
  etag: metadata.etag,
390
361
  },
391
- };
362
+ });
392
363
 
393
364
  const headers: Record<string, string> = {};
394
365
  if (options?.processing_priority) {
@@ -518,7 +489,9 @@ export class ObjectsApi extends ApiTopic {
518
489
  return this.client.runOperation({
519
490
  name: 'create',
520
491
  ids: [],
521
- 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'],
522
495
  }) as Promise<BulkObjectCreateResult>;
523
496
  }
524
497
 
@@ -526,6 +499,14 @@ export class ObjectsApi extends ApiTopic {
526
499
  return this.get(`/${documentId}/workflow-runs`);
527
500
  }
528
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
+
529
510
  listRenditions(documentId: string): Promise<ContentObjectItem[]> {
530
511
  return this.get(`/${documentId}/renditions`);
531
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
  }
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Uploads in parts, for stream sources longer than one part (Node.js only).
3
+ *
4
+ * A single signed PUT is capped by the store (5 GB on S3, about 5,000 MiB on Azure) and cannot resume. A source
5
+ * longer than {@link UPLOAD_PART_SIZE} therefore goes through an upload session, sent with the store's own protocol:
6
+ *
7
+ * - Google Cloud Storage: a resumable upload, written by `@google-cloud/storage`, which retries a failed chunk from
8
+ * the offset the service persisted.
9
+ * - Azure Blob Storage: Put Block for each part then Put Block List, written by `@azure/storage-blob`.
10
+ * - Amazon S3: a multipart upload. Each part is a `PUT` to a URL the server signs, retried like any signed-URL
11
+ * transfer, and the server completes the upload, or aborts it when a part cannot be sent.
12
+ *
13
+ * Memory stays about one part per upload, and nothing is written to disk. Parts are 16 MiB, or larger for content
14
+ * whose length would need more parts than the store allows: S3 takes 10,000 and Azure 50,000.
15
+ *
16
+ * The two SDKs are optional peer dependencies, loaded only on this path. Without the one a session needs, the
17
+ * upload falls back to a single signed PUT.
18
+ */
19
+ import type { CompletedUploadPart, S3MultipartUploadSession, UploadSession } from '@vertesia/common';
20
+ import { StreamSource } from '../StreamSource.js';
21
+ // hasNodeHttp from node-request, whose browser build answers false: a bundle without the Node transport never
22
+ // opens a session.
23
+ import { hasNodeHttp } from './node-request.js';
24
+ import { uploadAzureBlocks, uploadGcsResumable } from './node-sessions.js';
25
+ import { fetchSignedUrl, MAX_BUFFERED_STREAM_BYTES } from './signed-url.js';
26
+ import { chunkToBlobPart, continueStream } from './stream-bytes.js';
27
+ import { getUploadBody, type UploadBody, unquoteEtag } from './upload-body.js';
28
+ import { ContentLengthMismatchError, UploadSessionUnavailableError } from './upload-runtime.js';
29
+
30
+ export { UploadSessionUnavailableError } from './upload-runtime.js';
31
+
32
+ /** Sources longer than this are sent in parts: the most of a stream that is held in memory at once. */
33
+ export const UPLOAD_PART_SIZE = MAX_BUFFERED_STREAM_BYTES;
34
+
35
+ const MiB = 1024 * 1024;
36
+ /** S3 numbers parts from 1 to 10,000 and takes objects up to 5 TiB. */
37
+ const S3_MAX_PARTS = 10_000;
38
+ const S3_MAX_OBJECT_SIZE = 5 * 1024 * 1024 * MiB;
39
+ /** For a stream of unknown length, S3 parts double in size every this many parts: 16 MiB parts reach 968 GiB. */
40
+ const S3_PARTS_PER_SIZE = 2_000;
41
+ /** Azure commits at most 50,000 blocks. */
42
+ const AZURE_MAX_BLOCKS = 50_000;
43
+ /**
44
+ * Part URLs are signed this many at a time, and signed again once this old, since they expire (S3 default, one hour,
45
+ * or sooner with the signer's credentials) while a slow source fills the parts before them.
46
+ */
47
+ const PART_URL_BATCH = 100;
48
+ const PART_URL_MAX_AGE_MS = 15 * 60_000;
49
+
50
+ /** Content to send in parts, with its declared length when it is a stream whose length is known. */
51
+ export interface PartsBody {
52
+ body: Blob | ReadableStream<Uint8Array>;
53
+ size?: number;
54
+ }
55
+
56
+ export type UploadPlan = { kind: 'single'; upload: UploadBody } | { kind: 'parts'; parts: PartsBody };
57
+
58
+ /** The operations an S3 multipart upload needs from the API. */
59
+ export interface MultipartUploadApi {
60
+ getUploadPartUrls(payload: {
61
+ id: string;
62
+ upload_id: string;
63
+ part_numbers: number[];
64
+ }): Promise<{ parts: { part_number: number; url: string }[] }>;
65
+ completeUploadSession(payload: {
66
+ id: string;
67
+ upload_id: string;
68
+ parts: CompletedUploadPart[];
69
+ }): Promise<{ etag?: string }>;
70
+ abortUploadSession(payload: { id: string; upload_id: string }): Promise<unknown>;
71
+ }
72
+
73
+ /**
74
+ * How to upload a source. A `File`, and anything in a browser, is sent in one PUT as before. In Node.js, a stream
75
+ * source longer than one part is sent in parts. A plain stream is read up to one part to find out: one that ends
76
+ * first is sent whole, from memory, so it keeps its retries.
77
+ */
78
+ export async function planUpload(source: StreamSource | File): Promise<UploadPlan> {
79
+ const upload = await getUploadBody(source);
80
+ if (!(source instanceof StreamSource) || !hasNodeHttp()) return { kind: 'single', upload };
81
+ const { body, contentLength } = upload;
82
+ if (body instanceof Blob) {
83
+ return body.size > UPLOAD_PART_SIZE ? { kind: 'parts', parts: { body } } : { kind: 'single', upload };
84
+ }
85
+ if (contentLength !== undefined && contentLength <= UPLOAD_PART_SIZE) return { kind: 'single', upload };
86
+
87
+ const reader = (body as ReadableStream<unknown>).getReader();
88
+ const head: BlobPart[] = [];
89
+ let read = 0;
90
+ try {
91
+ while (read <= UPLOAD_PART_SIZE) {
92
+ const { done, value } = await reader.read();
93
+ if (done) {
94
+ reader.releaseLock();
95
+ // a declared length is over one part here, so a stream that ended is short of it
96
+ if (contentLength !== undefined) throw new ContentLengthMismatchError(contentLength, read, 'short');
97
+ return { kind: 'single', upload: { body: new Blob(head) } };
98
+ }
99
+ const part = chunkToBlobPart(value);
100
+ head.push(part);
101
+ read += part instanceof Blob ? part.size : (part as Uint8Array).byteLength;
102
+ }
103
+ } catch (err) {
104
+ await reader.cancel(err).catch(() => undefined);
105
+ throw err;
106
+ }
107
+ return { kind: 'parts', parts: { body: continueStream(head, reader), size: contentLength } };
108
+ }
109
+
110
+ /** The same content as one stream, for a single PUT when no session can be used. */
111
+ export function partsAsUploadBody(parts: PartsBody): UploadBody {
112
+ return parts.body instanceof Blob ? { body: parts.body } : { body: parts.body, contentLength: parts.size };
113
+ }
114
+
115
+ /** Sends the content through the session. Returns the stored object's ETag, unquoted, when the store gives one. */
116
+ export async function uploadInParts(
117
+ api: MultipartUploadApi,
118
+ session: UploadSession,
119
+ parts: PartsBody,
120
+ ): Promise<string | undefined> {
121
+ switch (session.protocol) {
122
+ case 's3_multipart':
123
+ return uploadS3Parts(api, session, parts);
124
+ case 'gcs_resumable':
125
+ return uploadGcsResumable(session, parts);
126
+ case 'azure_block_blob':
127
+ return unquoteEtag(
128
+ await uploadAzureBlocks(
129
+ session.url,
130
+ fitParts(session.part_size, knownSize(parts), AZURE_MAX_BLOCKS),
131
+ session.mime_type,
132
+ parts,
133
+ ),
134
+ );
135
+ default:
136
+ // A protocol from a newer server: upload in one request instead, before reading anything.
137
+ throw new UploadSessionUnavailableError(
138
+ `support for the ${(session as { protocol: unknown }).protocol} protocol`,
139
+ );
140
+ }
141
+ }
142
+
143
+ function knownSize(parts: PartsBody): number | undefined {
144
+ return parts.body instanceof Blob ? parts.body.size : parts.size;
145
+ }
146
+
147
+ /** `base`, or when `size` bytes would need more than `maxParts` parts of it, the whole number of MiB that fits. */
148
+ function fitParts(base: number, size: number | undefined, maxParts: number): number {
149
+ const needed = size === undefined ? 0 : Math.ceil(size / maxParts);
150
+ return needed <= base ? base : Math.ceil(needed / MiB) * MiB;
151
+ }
152
+
153
+ /**
154
+ * The size of each S3 part. With the length known, one size that fits it in 10,000 parts. Without, parts grow as the
155
+ * upload does, so a stream of unknown length can reach 968 GiB while short uploads keep small parts.
156
+ */
157
+ function s3PartSizes(base: number, size: number | undefined): (partNumber: number) => number {
158
+ if (size !== undefined) {
159
+ if (size > S3_MAX_OBJECT_SIZE) {
160
+ throw new Error(`S3 takes objects up to 5 TiB; this upload is declared at ${size} bytes`);
161
+ }
162
+ const fixed = fitParts(base, size, S3_MAX_PARTS);
163
+ return () => fixed;
164
+ }
165
+ return (partNumber) => base * 2 ** Math.floor((partNumber - 1) / S3_PARTS_PER_SIZE);
166
+ }
167
+
168
+ /** Splits the content into parts, part `n` of `partSize(n)` bytes; the last may be shorter. */
169
+ async function* blobParts(
170
+ body: Blob | ReadableStream<Uint8Array>,
171
+ partSize: (partNumber: number) => number,
172
+ ): AsyncGenerator<Blob> {
173
+ let partNumber = 1;
174
+ if (body instanceof Blob) {
175
+ for (let offset = 0; offset < body.size; partNumber++) {
176
+ const end = Math.min(offset + partSize(partNumber), body.size);
177
+ yield body.slice(offset, end);
178
+ offset = end;
179
+ }
180
+ return;
181
+ }
182
+ const reader = body.getReader();
183
+ let pending: Uint8Array[] = [];
184
+ let pendingBytes = 0;
185
+ let finished = false;
186
+ try {
187
+ for (;;) {
188
+ const { done, value } = await reader.read();
189
+ if (done) break;
190
+ let chunk = value;
191
+ while (pendingBytes + chunk.byteLength >= partSize(partNumber)) {
192
+ const take = partSize(partNumber) - pendingBytes;
193
+ pending.push(chunk.subarray(0, take));
194
+ yield new Blob(pending as BlobPart[]);
195
+ partNumber++;
196
+ pending = [];
197
+ pendingBytes = 0;
198
+ chunk = chunk.subarray(take);
199
+ }
200
+ if (chunk.byteLength > 0) {
201
+ pending.push(chunk);
202
+ pendingBytes += chunk.byteLength;
203
+ }
204
+ }
205
+ finished = true;
206
+ if (pendingBytes > 0) yield new Blob(pending as BlobPart[]);
207
+ } finally {
208
+ if (!finished) await reader.cancel().catch(() => undefined);
209
+ reader.releaseLock();
210
+ }
211
+ }
212
+
213
+ async function uploadS3Parts(
214
+ api: MultipartUploadApi,
215
+ session: S3MultipartUploadSession,
216
+ parts: PartsBody,
217
+ ): Promise<string | undefined> {
218
+ const { id, upload_id } = session;
219
+ const uploaded: CompletedUploadPart[] = [];
220
+ let urls = new Map<number, string>();
221
+ let signedAt = 0;
222
+ let sent = 0;
223
+
224
+ async function partUrl(partNumber: number, renew: boolean): Promise<string> {
225
+ if (renew || !urls.has(partNumber) || Date.now() - signedAt > PART_URL_MAX_AGE_MS) {
226
+ const last = Math.min(partNumber + PART_URL_BATCH - 1, S3_MAX_PARTS);
227
+ const part_numbers = Array.from({ length: last - partNumber + 1 }, (_, i) => partNumber + i);
228
+ const signed = await api.getUploadPartUrls({ id, upload_id, part_numbers });
229
+ urls = new Map(signed.parts.map((p) => [p.part_number, p.url]));
230
+ signedAt = Date.now();
231
+ }
232
+ const url = urls.get(partNumber);
233
+ if (!url) throw new Error(`No upload URL was signed for part ${partNumber}`);
234
+ return url;
235
+ }
236
+
237
+ try {
238
+ for await (const part of blobParts(parts.body, s3PartSizes(session.part_size, knownSize(parts)))) {
239
+ const partNumber = uploaded.length + 1;
240
+ if (partNumber > S3_MAX_PARTS) {
241
+ throw new Error(`Upload needs more than ${S3_MAX_PARTS} parts`);
242
+ }
243
+ sent += part.size;
244
+ if (parts.size !== undefined && sent > parts.size) {
245
+ throw new ContentLengthMismatchError(parts.size, sent, 'long');
246
+ }
247
+ let res = await fetchSignedUrl(await partUrl(partNumber, false), { method: 'PUT', body: part });
248
+ if (res.status === 403) {
249
+ // An expired URL, or one whose signing credentials expired: sign it again, once.
250
+ await res.body?.cancel().catch(() => undefined);
251
+ res = await fetchSignedUrl(await partUrl(partNumber, true), { method: 'PUT', body: part });
252
+ }
253
+ const detail = res.ok ? '' : await res.text().catch(() => '');
254
+ if (res.ok) await res.body?.cancel().catch(() => undefined);
255
+ const etag = res.headers.get('etag');
256
+ if (!res.ok || !etag) {
257
+ throw new Error(
258
+ `Failed to upload part ${partNumber}: ${res.status} ${res.statusText}${detail ? ` ${detail}` : ''}`,
259
+ );
260
+ }
261
+ uploaded.push({ part_number: partNumber, etag });
262
+ }
263
+ if (parts.size !== undefined && sent < parts.size) {
264
+ throw new ContentLengthMismatchError(parts.size, sent, 'short');
265
+ }
266
+ const completed = await api.completeUploadSession({ id, upload_id, parts: uploaded });
267
+ return unquoteEtag(completed.etag);
268
+ } catch (err) {
269
+ await api.abortUploadSession({ id, upload_id }).catch(() => undefined);
270
+ throw err;
271
+ }
272
+ }
@@ -1,14 +1,17 @@
1
1
  import {
2
2
  AbstractFetchClient,
3
3
  type FETCH_FN,
4
+ type IPacingRetryPolicy,
4
5
  type IRequestRetryPolicy,
5
6
  type RequestError,
7
+ type RequestIdentityProvider,
6
8
  } from '@vertesia/api-fetch-client';
7
9
  import { APP_VERSION_HEADER, type BulkOperationPayload, type BulkOperationResponse } from '@vertesia/common';
8
10
  import { warnUnknownOptions } from '../unknown-options.js';
9
11
  import { AgentsApi } from './AgentsApi.js';
10
12
  import { CollectionsApi } from './CollectionsApi.js';
11
13
  import { ContentApi } from './ContentApi.js';
14
+ import { ContentSourcesApi } from './ContentSourcesApi.js';
12
15
  import { CostApi } from './CostApi.js';
13
16
  import { DataApi } from './DataApi.js';
14
17
  import { EmailApi } from './EmailApi.js';
@@ -17,6 +20,7 @@ import { EventsApi } from './EventsApi.js';
17
20
  import { ZenoClientNotFoundError } from './errors.js';
18
21
  import { FilesApi } from './FilesApi.js';
19
22
  import { IndexingApi } from './IndexingApi.js';
23
+ import { NotificationsApi } from './NotificationsApi.js';
20
24
  import { ObjectsApi } from './ObjectsApi.js';
21
25
  import { PendingAsksApi } from './PendingAsksApi.js';
22
26
  import { ProcessApi } from './ProcessApi.js';
@@ -34,9 +38,13 @@ export interface ZenoClientProps {
34
38
  serverUrl?: string;
35
39
  tokenServerUrl?: string;
36
40
  apikey?: string;
41
+ /** Supplies the complete Authorization header; takes precedence over apikey. */
42
+ authCallback?: () => Promise<string>;
43
+ requestIdentity?: RequestIdentityProvider;
37
44
  onRequest?: (request: Request) => void;
38
45
  onResponse?: (response: Response) => void;
39
46
  retryPolicy?: IRequestRetryPolicy;
47
+ pacingRetry?: IPacingRetryPolicy | false;
40
48
  timeout?: number | false | null;
41
49
  fetch?: FETCH_FN | Promise<FETCH_FN>;
42
50
  }
@@ -46,9 +54,12 @@ const KNOWN_STORE_OPTIONS: Record<keyof Required<ZenoClientProps>, true> = {
46
54
  serverUrl: true,
47
55
  tokenServerUrl: true,
48
56
  apikey: true,
57
+ authCallback: true,
58
+ requestIdentity: true,
49
59
  onRequest: true,
50
60
  onResponse: true,
51
61
  retryPolicy: true,
62
+ pacingRetry: true,
52
63
  timeout: true,
53
64
  fetch: true,
54
65
  };
@@ -64,15 +75,22 @@ export class ZenoClient extends AbstractFetchClient<ZenoClient> {
64
75
  constructor(opts: ZenoClientProps = {}) {
65
76
  warnUnknownOptions('ZenoClient', opts, KNOWN_STORE_OPTIONS);
66
77
  super(ensureDefined(opts.serverUrl), opts.fetch);
67
- if (opts.apikey) {
78
+ if (opts.authCallback) {
79
+ this.withAuthCallback(opts.authCallback);
80
+ } else if (opts.apikey) {
68
81
  this.withApiKey(opts.apikey);
69
82
  }
70
83
  if (opts.retryPolicy) {
71
84
  this.withRetryPolicy(opts.retryPolicy);
72
85
  }
86
+ if (opts.pacingRetry !== undefined) {
87
+ this.withPacingRetry(opts.pacingRetry);
88
+ }
89
+
73
90
  if (opts.timeout !== undefined) {
74
91
  this.withTimeout(opts.timeout);
75
92
  }
93
+ this.requestIdentity = opts.requestIdentity;
76
94
  this.onRequest = opts.onRequest;
77
95
  this.onResponse = opts.onResponse;
78
96
  this.errorFactory = (err: RequestError) => {
@@ -127,6 +145,7 @@ export class ZenoClient extends AbstractFetchClient<ZenoClient> {
127
145
  types = new TypesApi(this);
128
146
  workflows = new WorkflowsApi(this);
129
147
  schedules = new SchedulesApi(this);
148
+ contentSources = new ContentSourcesApi(this);
130
149
  processes = new ProcessApi(this);
131
150
  processTestRuns = new ProcessTestRunApi(this);
132
151
  tasks = new TaskApi(this);
@@ -138,6 +157,7 @@ export class ZenoClient extends AbstractFetchClient<ZenoClient> {
138
157
  /** @deprecated Use events.subscriptions. */
139
158
  eventSubscriptions = this.events.subscriptions;
140
159
  pendingAsks = new PendingAsksApi(this);
160
+ notifications = new NotificationsApi(this);
141
161
  data = new DataApi(this);
142
162
  indexing = new IndexingApi(this);
143
163
  query = new QueryApi(this);
@@ -1,6 +1,8 @@
1
1
  export * from './AgentsApi.js';
2
2
  export * from './ContentApi.js';
3
+ export * from './ContentSourcesApi.js';
3
4
  export * from './client.js';
5
+ export * from './DashboardApi.js';
4
6
  export * from './DataApi.js';
5
7
  export * from './EmailApi.js';
6
8
  export * from './EmbeddingsApi.js';
@@ -10,6 +12,7 @@ export * from './EventsApi.js';
10
12
  export * from './errors.js';
11
13
  export * from './FilesApi.js';
12
14
  export * from './IndexingApi.js';
15
+ export * from './NotificationsApi.js';
13
16
  export * from './ObjectsApi.js';
14
17
  export * from './PendingAsksApi.js';
15
18
  export * from './ProcessApi.js';