@vertesia/client 1.6.0-dev.20261022.120426Z → 1.7.0-dev.20261120.100641Z
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.
- package/lib/AccountApi.d.ts +2 -0
- package/lib/AccountApi.d.ts.map +1 -1
- package/lib/AccountApi.js +3 -0
- package/lib/AccountApi.js.map +1 -1
- package/lib/AccountRolesApi.d.ts +11 -0
- package/lib/AccountRolesApi.d.ts.map +1 -0
- package/lib/AccountRolesApi.js +22 -0
- package/lib/AccountRolesApi.js.map +1 -0
- package/lib/AppsApi.d.ts +18 -3
- package/lib/AppsApi.d.ts.map +1 -1
- package/lib/AppsApi.js +34 -4
- package/lib/AppsApi.js.map +1 -1
- package/lib/AuditTrailApi.d.ts +6 -1
- package/lib/AuditTrailApi.d.ts.map +1 -1
- package/lib/AuditTrailApi.js +8 -0
- package/lib/AuditTrailApi.js.map +1 -1
- package/lib/EnvironmentsApi.d.ts +2 -2
- package/lib/EnvironmentsApi.d.ts.map +1 -1
- package/lib/IamApi.d.ts +1 -1
- package/lib/IamApi.js +1 -1
- package/lib/InteractionCatalogApi.d.ts +19 -1
- package/lib/InteractionCatalogApi.d.ts.map +1 -1
- package/lib/InteractionCatalogApi.js +30 -0
- package/lib/InteractionCatalogApi.js.map +1 -1
- package/lib/InteractionsApi.d.ts +3 -12
- package/lib/InteractionsApi.d.ts.map +1 -1
- package/lib/InteractionsApi.js +2 -23
- package/lib/InteractionsApi.js.map +1 -1
- package/lib/OAuthClientsApi.d.ts +3 -1
- package/lib/OAuthClientsApi.d.ts.map +1 -1
- package/lib/OAuthClientsApi.js +4 -0
- package/lib/OAuthClientsApi.js.map +1 -1
- package/lib/OAuthProvidersApi.d.ts +6 -2
- package/lib/OAuthProvidersApi.d.ts.map +1 -1
- package/lib/OAuthProvidersApi.js +6 -2
- package/lib/OAuthProvidersApi.js.map +1 -1
- package/lib/RemoteMcpConnectionsApi.d.ts +5 -1
- package/lib/RemoteMcpConnectionsApi.d.ts.map +1 -1
- package/lib/RemoteMcpConnectionsApi.js +6 -2
- package/lib/RemoteMcpConnectionsApi.js.map +1 -1
- package/lib/StreamSource.d.ts +19 -1
- package/lib/StreamSource.d.ts.map +1 -1
- package/lib/StreamSource.js +31 -1
- package/lib/StreamSource.js.map +1 -1
- package/lib/UsersApi.d.ts +7 -1
- package/lib/UsersApi.d.ts.map +1 -1
- package/lib/UsersApi.js +8 -0
- package/lib/UsersApi.js.map +1 -1
- package/lib/client.d.ts +14 -2
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +57 -8
- package/lib/client.js.map +1 -1
- package/lib/execute.d.ts.map +1 -1
- package/lib/execute.js +4 -2
- package/lib/execute.js.map +1 -1
- package/lib/idempotency-key.d.ts +19 -0
- package/lib/idempotency-key.d.ts.map +1 -0
- package/lib/idempotency-key.js +34 -0
- package/lib/idempotency-key.js.map +1 -0
- package/lib/nodejs/NodeStreamSource.d.ts +10 -1
- package/lib/nodejs/NodeStreamSource.d.ts.map +1 -1
- package/lib/nodejs/NodeStreamSource.js +40 -2
- package/lib/nodejs/NodeStreamSource.js.map +1 -1
- package/lib/store/AgentsApi.d.ts.map +1 -1
- package/lib/store/AgentsApi.js +5 -2
- package/lib/store/AgentsApi.js.map +1 -1
- package/lib/store/ContentSourcesApi.d.ts +57 -0
- package/lib/store/ContentSourcesApi.d.ts.map +1 -0
- package/lib/store/ContentSourcesApi.js +92 -0
- package/lib/store/ContentSourcesApi.js.map +1 -0
- package/lib/store/CostApi.d.ts +9 -1
- package/lib/store/CostApi.d.ts.map +1 -1
- package/lib/store/CostApi.js +16 -0
- package/lib/store/CostApi.js.map +1 -1
- package/lib/store/DashboardApi.d.ts +61 -19
- package/lib/store/DashboardApi.d.ts.map +1 -1
- package/lib/store/DashboardApi.js +75 -19
- package/lib/store/DashboardApi.js.map +1 -1
- package/lib/store/DataApi.d.ts +9 -9
- package/lib/store/DataApi.d.ts.map +1 -1
- package/lib/store/DataApi.js +14 -10
- package/lib/store/DataApi.js.map +1 -1
- package/lib/store/FilesApi.d.ts +15 -1
- package/lib/store/FilesApi.d.ts.map +1 -1
- package/lib/store/FilesApi.js +54 -75
- package/lib/store/FilesApi.js.map +1 -1
- package/lib/store/NotificationsApi.d.ts +39 -0
- package/lib/store/NotificationsApi.d.ts.map +1 -0
- package/lib/store/NotificationsApi.js +68 -0
- package/lib/store/NotificationsApi.js.map +1 -0
- package/lib/store/ObjectsApi.d.ts +6 -1
- package/lib/store/ObjectsApi.d.ts.map +1 -1
- package/lib/store/ObjectsApi.js +23 -30
- package/lib/store/ObjectsApi.js.map +1 -1
- package/lib/store/RenderingApi.d.ts.map +1 -1
- package/lib/store/RenderingApi.js +1 -0
- package/lib/store/RenderingApi.js.map +1 -1
- package/lib/store/WorkflowsApi.d.ts +19 -1
- package/lib/store/WorkflowsApi.d.ts.map +1 -1
- package/lib/store/WorkflowsApi.js +21 -0
- package/lib/store/WorkflowsApi.js.map +1 -1
- package/lib/store/chunked-upload.d.ts +71 -0
- package/lib/store/chunked-upload.d.ts.map +1 -0
- package/lib/store/chunked-upload.js +206 -0
- package/lib/store/chunked-upload.js.map +1 -0
- package/lib/store/client.d.ts +9 -1
- package/lib/store/client.d.ts.map +1 -1
- package/lib/store/client.js +17 -1
- package/lib/store/client.js.map +1 -1
- package/lib/store/index.d.ts +3 -0
- package/lib/store/index.d.ts.map +1 -1
- package/lib/store/index.js +3 -0
- package/lib/store/index.js.map +1 -1
- package/lib/store/node-request.browser.d.ts +14 -0
- package/lib/store/node-request.browser.d.ts.map +1 -0
- package/lib/store/node-request.browser.js +20 -0
- package/lib/store/node-request.browser.js.map +1 -0
- package/lib/store/node-request.d.ts +20 -0
- package/lib/store/node-request.d.ts.map +1 -0
- package/lib/store/node-request.js +116 -0
- package/lib/store/node-request.js.map +1 -0
- package/lib/store/node-sessions.browser.d.ts +3 -0
- package/lib/store/node-sessions.browser.d.ts.map +1 -0
- package/lib/store/node-sessions.browser.js +15 -0
- package/lib/store/node-sessions.browser.js.map +1 -0
- package/lib/store/node-sessions.d.ts +14 -0
- package/lib/store/node-sessions.d.ts.map +1 -0
- package/lib/store/node-sessions.js +88 -0
- package/lib/store/node-sessions.js.map +1 -0
- package/lib/store/signed-url.d.ts +12 -16
- package/lib/store/signed-url.d.ts.map +1 -1
- package/lib/store/signed-url.js +111 -71
- package/lib/store/signed-url.js.map +1 -1
- package/lib/store/stream-bytes.d.ts +16 -0
- package/lib/store/stream-bytes.d.ts.map +1 -0
- package/lib/store/stream-bytes.js +70 -0
- package/lib/store/stream-bytes.js.map +1 -0
- package/lib/store/stream-termination.d.ts.map +1 -1
- package/lib/store/stream-termination.js +17 -16
- package/lib/store/stream-termination.js.map +1 -1
- package/lib/store/upload-body.d.ts +21 -0
- package/lib/store/upload-body.d.ts.map +1 -0
- package/lib/store/upload-body.js +32 -0
- package/lib/store/upload-body.js.map +1 -0
- package/lib/store/upload-content.d.ts +21 -0
- package/lib/store/upload-content.d.ts.map +1 -0
- package/lib/store/upload-content.js +113 -0
- package/lib/store/upload-content.js.map +1 -0
- package/lib/store/upload-runtime.d.ts +21 -0
- package/lib/store/upload-runtime.d.ts.map +1 -0
- package/lib/store/upload-runtime.js +40 -0
- package/lib/store/upload-runtime.js.map +1 -0
- package/lib/user-agent.d.ts +11 -0
- package/lib/user-agent.d.ts.map +1 -0
- package/lib/user-agent.js +35 -0
- package/lib/user-agent.js.map +1 -0
- package/lib/vertesia-client.js +10 -9
- package/lib/vertesia-client.js.map +1 -1
- package/package.json +35 -11
- package/src/AccountApi.ts +3 -0
- package/src/AccountRolesApi.ts +29 -0
- package/src/AppsApi.ts +58 -4
- package/src/AuditTrailApi.ts +11 -0
- package/src/EnvironmentsApi.ts +2 -2
- package/src/IamApi.ts +1 -1
- package/src/InteractionCatalogApi.ts +44 -1
- package/src/InteractionsApi.ts +2 -31
- package/src/OAuthClientsApi.ts +6 -0
- package/src/OAuthProvidersApi.ts +7 -2
- package/src/RemoteMcpConnectionsApi.ts +7 -3
- package/src/StreamSource.ts +29 -0
- package/src/UsersApi.ts +10 -1
- package/src/client.ts +74 -8
- package/src/execute.ts +4 -2
- package/src/idempotency-key.ts +34 -0
- package/src/nodejs/NodeStreamSource.ts +37 -2
- package/src/store/AgentsApi.ts +5 -2
- package/src/store/ContentSourcesApi.ts +135 -0
- package/src/store/CostApi.ts +24 -0
- package/src/store/DashboardApi.ts +93 -18
- package/src/store/DataApi.ts +14 -10
- package/src/store/FilesApi.ts +84 -78
- package/src/store/NotificationsApi.ts +103 -0
- package/src/store/ObjectsApi.ts +30 -34
- package/src/store/RenderingApi.ts +1 -0
- package/src/store/WorkflowsApi.ts +25 -0
- package/src/store/chunked-upload.ts +272 -0
- package/src/store/client.ts +23 -1
- package/src/store/index.ts +3 -0
- package/src/store/node-request.browser.ts +22 -0
- package/src/store/node-request.ts +120 -0
- package/src/store/node-sessions.browser.ts +16 -0
- package/src/store/node-sessions.ts +109 -0
- package/src/store/signed-url.ts +126 -72
- package/src/store/stream-bytes.ts +79 -0
- package/src/store/stream-termination.ts +24 -24
- package/src/store/upload-body.ts +37 -0
- package/src/store/upload-content.ts +129 -0
- package/src/store/upload-runtime.ts +42 -0
- package/src/user-agent.ts +41 -0
package/src/store/DataApi.ts
CHANGED
|
@@ -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`, {
|
|
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
|
|
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).
|
|
492
|
-
*
|
|
493
|
-
*
|
|
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
|
-
*
|
|
500
|
-
*
|
|
503
|
+
* query: 'SELECT region, SUM(amount) AS total FROM sales GROUP BY region',
|
|
504
|
+
* spec: { mark: 'bar', encoding: { ... } },
|
|
501
505
|
* });
|
|
502
506
|
*
|
|
503
|
-
* //
|
|
504
|
-
* const
|
|
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 {
|
package/src/store/FilesApi.ts
CHANGED
|
@@ -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 {
|
|
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 {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
247
|
-
|
|
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
|
-
//
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
}
|
package/src/store/ObjectsApi.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
283
|
-
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -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
|
}
|