@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.
- 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/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/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 +55 -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 +52 -0
- package/lib/store/ContentSourcesApi.d.ts.map +1 -0
- package/lib/store/ContentSourcesApi.js +85 -0
- package/lib/store/ContentSourcesApi.js.map +1 -0
- package/lib/store/CostApi.d.ts +6 -1
- package/lib/store/CostApi.d.ts.map +1 -1
- package/lib/store/CostApi.js +7 -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 +15 -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/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/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/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/StreamSource.ts +29 -0
- package/src/UsersApi.ts +10 -1
- package/src/client.ts +72 -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 +126 -0
- package/src/store/CostApi.ts +10 -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 +21 -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/upload-body.ts +37 -0
- package/src/store/upload-content.ts +129 -0
- package/src/store/upload-runtime.ts +42 -0
package/src/execute.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type RateLimitRequestResponse,
|
|
12
12
|
} from '@vertesia/common';
|
|
13
13
|
import type { VertesiaClient } from './client.js';
|
|
14
|
+
import { withIdempotencyKey } from './idempotency-key.js';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Client-side timeout for a synchronous (non-streaming) interaction execution. The request blocks on
|
|
@@ -192,9 +193,10 @@ export async function executeInteractionAsync(
|
|
|
192
193
|
// A conversation starts an agent run: without `idempotency_key` a replay could start a second one,
|
|
193
194
|
// so opt out of any client-level retry policy (see `AgentsApi.start`). With a key, a replay
|
|
194
195
|
// returns the run the first request started.
|
|
195
|
-
const
|
|
196
|
+
const keyedPayload = payload.type === 'conversation' ? withIdempotencyKey(client, payload) : payload;
|
|
197
|
+
const unkeyedConversation = keyedPayload.type === 'conversation' && !keyedPayload.idempotency_key;
|
|
196
198
|
return await client.post('/api/v1/execute/async', {
|
|
197
|
-
payload,
|
|
199
|
+
payload: keyedPayload,
|
|
198
200
|
retryPolicy: unkeyedConversation ? false : undefined,
|
|
199
201
|
});
|
|
200
202
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ClientBase, generateIdempotencyKey } from '@vertesia/api-fetch-client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Give a create request its own `idempotency_key` when the client's retry policy asks for idempotency
|
|
5
|
+
* keys and the caller set none, so a retried attempt returns what the first one created instead of
|
|
6
|
+
* creating it again. The server stores the key with the resource it creates. A caller's key, or a
|
|
7
|
+
* client without the opt-in, leaves the payload unchanged.
|
|
8
|
+
*/
|
|
9
|
+
export function withIdempotencyKey<T extends { idempotency_key?: string }>(client: ClientBase, payload: T): T {
|
|
10
|
+
if (payload.idempotency_key || !client.getRetryPolicy()?.idempotencyKeys) {
|
|
11
|
+
return payload;
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
...payload,
|
|
15
|
+
idempotency_key: client.getRetryPolicy()?.idempotencyKey?.(payload) ?? generateIdempotencyKey(),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Give a data-store import its own `import_id` under the same opt-in as {@link withIdempotencyKey}. The server
|
|
21
|
+
* takes the ID as the import job's ObjectId and refuses an unknown one older than 24 hours, so it is a fresh
|
|
22
|
+
* ObjectId: the current time in seconds, then random bytes.
|
|
23
|
+
*/
|
|
24
|
+
export function withImportId<T extends { import_id?: string }>(client: ClientBase, payload: T): T {
|
|
25
|
+
if (payload.import_id || !client.getRetryPolicy()?.idempotencyKeys) {
|
|
26
|
+
return payload;
|
|
27
|
+
}
|
|
28
|
+
const durableId = client.getRetryPolicy()?.importId?.(payload);
|
|
29
|
+
if (durableId) return { ...payload, import_id: durableId };
|
|
30
|
+
const seconds = Math.floor(Date.now() / 1000)
|
|
31
|
+
.toString(16)
|
|
32
|
+
.padStart(8, '0');
|
|
33
|
+
return { ...payload, import_id: seconds + generateIdempotencyKey().replaceAll('-', '').slice(0, 16) };
|
|
34
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
1
2
|
import type { Readable } from 'node:stream';
|
|
2
3
|
import { finished } from 'node:stream/promises';
|
|
3
4
|
import { StreamSource } from '../StreamSource.js';
|
|
@@ -6,13 +7,47 @@ import { StreamSource } from '../StreamSource.js';
|
|
|
6
7
|
* A stream source that wraps a Node.js Readable stream.
|
|
7
8
|
* This class is only works in Node.js environments.
|
|
8
9
|
* Cancelling the web stream destroys the Node.js stream, releasing its underlying resource (e.g. a file descriptor).
|
|
10
|
+
*
|
|
11
|
+
* When the stream reads a whole local file (`fs.createReadStream(path)`), uploads send a file-backed `Blob`
|
|
12
|
+
* instead of the stream (see {@link replayableBody}): it can be retried without holding the file in memory.
|
|
9
13
|
*/
|
|
10
14
|
export class NodeStreamSource extends StreamSource {
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
private readonly filePath: string | undefined;
|
|
16
|
+
|
|
17
|
+
constructor(stream: Readable, name: string, type?: string, id?: string, size?: number) {
|
|
18
|
+
// read before wrapping: the web stream may start reading the Node.js stream
|
|
19
|
+
const filePath = wholeFilePath(stream);
|
|
20
|
+
super(readableToWebStream(stream) as ReadableStream, name, type, id, size);
|
|
21
|
+
this.filePath = filePath;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A `Blob` backed by the file the stream reads, from Node's `fs.openAsBlob`. Reading it reads the file from
|
|
26
|
+
* disk on demand, so each upload attempt streams the file again instead of buffering it.
|
|
27
|
+
*/
|
|
28
|
+
override async replayableBody(): Promise<Blob | undefined> {
|
|
29
|
+
if (!this.filePath || typeof fs.openAsBlob !== 'function') return undefined;
|
|
30
|
+
return (await fs.openAsBlob(this.filePath, { type: this.type })) as Blob;
|
|
13
31
|
}
|
|
14
32
|
}
|
|
15
33
|
|
|
34
|
+
/**
|
|
35
|
+
* The path of the file a stream reads, when it reads all of it from the start: an `fs.ReadStream` opened by
|
|
36
|
+
* path with no range or encoding that nothing has read yet. Any other stream (a range, a descriptor, one that
|
|
37
|
+
* decodes the file to text, a stream already consumed, or one that is not a file) has no path, and is uploaded as
|
|
38
|
+
* a stream.
|
|
39
|
+
*/
|
|
40
|
+
function wholeFilePath(stream: Readable): string | undefined {
|
|
41
|
+
if (!(stream instanceof fs.ReadStream)) return undefined;
|
|
42
|
+
const { path, start, end } = stream as fs.ReadStream & { start?: number; end?: number };
|
|
43
|
+
if (typeof path !== 'string') return undefined;
|
|
44
|
+
if ((start ?? 0) !== 0 || end !== Infinity) return undefined;
|
|
45
|
+
// an encoding uploads the decoded text (e.g. base64), not the file's bytes
|
|
46
|
+
if (stream.readableEncoding) return undefined;
|
|
47
|
+
if (stream.bytesRead > 0 || stream.readableDidRead) return undefined;
|
|
48
|
+
return path;
|
|
49
|
+
}
|
|
50
|
+
|
|
16
51
|
/**
|
|
17
52
|
* Not ReadableStream.from: it cancels by calling return() on the Node.js async iterator, which is a no-op
|
|
18
53
|
* when nothing was read yet, so the Node.js stream would stay open. Also covers Bun, which lacks ReadableStream.from.
|
package/src/store/AgentsApi.ts
CHANGED
|
@@ -57,6 +57,7 @@ import {
|
|
|
57
57
|
} from '@vertesia/common';
|
|
58
58
|
import type { VertesiaClient } from '../client.js';
|
|
59
59
|
import { EventSourceProvider } from '../execute.js';
|
|
60
|
+
import { withIdempotencyKey } from '../idempotency-key.js';
|
|
60
61
|
import { fetchSignedUrl } from './signed-url.js';
|
|
61
62
|
import { shouldCloseAgentRunStream, shouldCloseCompactRunStream } from './stream-termination.js';
|
|
62
63
|
|
|
@@ -101,8 +102,10 @@ export class AgentsApi extends ApiTopic {
|
|
|
101
102
|
// retry policy explicitly rather than relying on POST being absent from its method list.
|
|
102
103
|
// Rate-limiter pacing retries are unaffected: those happen before the request reaches the
|
|
103
104
|
// handler. Process starts take no key and keep the client's policy.
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
// A client whose policy sends idempotency keys gives the run a generated key instead.
|
|
106
|
+
const keyedPayload = 'interaction' in payload ? withIdempotencyKey(this.client, payload) : payload;
|
|
107
|
+
const unkeyedAgentStart = 'interaction' in keyedPayload && !keyedPayload.idempotency_key;
|
|
108
|
+
return this.post('/', { payload: keyedPayload, retryPolicy: unkeyedAgentStart ? false : undefined });
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
/**
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ApiTopic, type ClientBase } from '@vertesia/api-fetch-client';
|
|
2
|
+
import type {
|
|
3
|
+
ContentSourceFoldersDiscovery,
|
|
4
|
+
ContentSourceReport,
|
|
5
|
+
ContentSourceReportQuery,
|
|
6
|
+
ContentSourceRootsDiscovery,
|
|
7
|
+
ContentSourceSampleDiscovery,
|
|
8
|
+
ContentSourceSchemaDiscovery,
|
|
9
|
+
ContentSourceSiteDiscovery,
|
|
10
|
+
ContentSourceStatus,
|
|
11
|
+
CreateContentSourcePayload,
|
|
12
|
+
DeleteCountResult,
|
|
13
|
+
DiscoverContentSourceFoldersPayload,
|
|
14
|
+
DiscoverContentSourceSamplePayload,
|
|
15
|
+
DiscoverContentSourceSchemaPayload,
|
|
16
|
+
DiscoverContentSourceSitePayload,
|
|
17
|
+
ExternalContentSource,
|
|
18
|
+
InspectContentSourceFoldersPayload,
|
|
19
|
+
InspectContentSourceSamplePayload,
|
|
20
|
+
InspectContentSourceSchemaPayload,
|
|
21
|
+
SyncContentSourcePayload,
|
|
22
|
+
UpdateContentSourcePayload,
|
|
23
|
+
} from '@vertesia/common';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Folders of external content systems (SharePoint, Box) synced into the project without copies. Each source has
|
|
27
|
+
* a sync that imports the folder, then reads its changes on a schedule or on request.
|
|
28
|
+
*/
|
|
29
|
+
export class ContentSourcesApi extends ApiTopic {
|
|
30
|
+
constructor(parent: ClientBase) {
|
|
31
|
+
super(parent, '/api/v1/content-sources');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
list(): Promise<ExternalContentSource[]> {
|
|
35
|
+
return this.get('/');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
retrieve(id: string): Promise<ExternalContentSource> {
|
|
39
|
+
return this.get(`/${id}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Checks the folder with the system and registers the source. Nothing is imported until `sync` is called. */
|
|
43
|
+
create(payload: CreateContentSourcePayload): Promise<ExternalContentSource> {
|
|
44
|
+
return this.post('/', { payload });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Changes the name, description or sync settings, and, before the first sync, the root and folder. */
|
|
48
|
+
update(id: string, payload: UpdateContentSourcePayload): Promise<ExternalContentSource> {
|
|
49
|
+
return this.put(`/${id}`, { payload });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Stops the sync and removes the source. Synced documents are kept. */
|
|
53
|
+
delete(id: string): Promise<DeleteCountResult> {
|
|
54
|
+
return this.del(`/${id}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Syncs now: reads the changes, or, with `full`, lists the whole folder and removes deleted files. */
|
|
58
|
+
sync(id: string, payload: SyncContentSourcePayload = {}): Promise<ContentSourceStatus> {
|
|
59
|
+
return this.post(`/${id}/sync`, { payload });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The sync's state: the current and last rounds, and when the next one starts. */
|
|
63
|
+
status(id: string): Promise<ContentSourceStatus> {
|
|
64
|
+
return this.get(`/${id}/status`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A page of what a sync round did with each file: created, updated, deleted, skipped or failed. Round IDs are in
|
|
69
|
+
* the status's `recent_rounds`. Pass the `next_cursor` of a page to read the next one.
|
|
70
|
+
*/
|
|
71
|
+
report(id: string, roundId: string, query: ContentSourceReportQuery = {}): Promise<ContentSourceReport> {
|
|
72
|
+
return this.get(`/${id}/rounds/${encodeURIComponent(roundId)}/report`, { query: { ...query } });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Resolves a site through an OAuth provider and lists its document libraries. Works before a source exists,
|
|
77
|
+
* so it also tells whether the connection is set up correctly.
|
|
78
|
+
*/
|
|
79
|
+
discoverSite(payload: DiscoverContentSourceSitePayload): Promise<ContentSourceSiteDiscovery> {
|
|
80
|
+
return this.post('/discover/site', { payload });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The direct subfolders of a folder of a document library, to browse to the folder to sync. */
|
|
84
|
+
discoverFolders(payload: DiscoverContentSourceFoldersPayload): Promise<ContentSourceFoldersDiscovery> {
|
|
85
|
+
return this.post('/discover/folders', { payload });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The content types of a document library with their columns, and the library's own columns. */
|
|
89
|
+
discoverSchema(payload: DiscoverContentSourceSchemaPayload): Promise<ContentSourceSchemaDiscovery> {
|
|
90
|
+
return this.post('/discover/schema', { payload });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* A bounded sample of the files under a folder, with each file's content type and column values. The sample is
|
|
95
|
+
* spread over subfolders; `truncated` says whether the folder holds more than was read.
|
|
96
|
+
*/
|
|
97
|
+
discoverSample(payload: DiscoverContentSourceSamplePayload): Promise<ContentSourceSampleDiscovery> {
|
|
98
|
+
return this.post('/discover/sample', { payload });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* What a source's connection reaches: the document libraries of its SharePoint site, or the Box folders shared
|
|
103
|
+
* with its app. The caller names no OAuth provider or address: the source holds them.
|
|
104
|
+
*/
|
|
105
|
+
inspectRoots(id: string): Promise<ContentSourceRootsDiscovery> {
|
|
106
|
+
return this.post(`/${id}/discover/roots`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The direct subfolders of a folder the source reaches, at the top of its root by default. */
|
|
110
|
+
inspectFolders(
|
|
111
|
+
id: string,
|
|
112
|
+
payload: InspectContentSourceFoldersPayload = {},
|
|
113
|
+
): Promise<ContentSourceFoldersDiscovery> {
|
|
114
|
+
return this.post(`/${id}/discover/folders`, { payload });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The content types (SharePoint) or metadata templates (Box) and their columns. */
|
|
118
|
+
inspectSchema(id: string, payload: InspectContentSourceSchemaPayload = {}): Promise<ContentSourceSchemaDiscovery> {
|
|
119
|
+
return this.post(`/${id}/discover/schema`, { payload });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A bounded sample of the files under a folder the source reaches, its own folder by default. */
|
|
123
|
+
inspectSample(id: string, payload: InspectContentSourceSamplePayload = {}): Promise<ContentSourceSampleDiscovery> {
|
|
124
|
+
return this.post(`/${id}/discover/sample`, { payload });
|
|
125
|
+
}
|
|
126
|
+
}
|
package/src/store/CostApi.ts
CHANGED
|
@@ -6,6 +6,8 @@ import type {
|
|
|
6
6
|
CostModelPricesQuery,
|
|
7
7
|
CostRunPriceQuery,
|
|
8
8
|
CostRunPriceResponse,
|
|
9
|
+
IntakeCostSummaryQuery,
|
|
10
|
+
IntakeCostSummaryResponse,
|
|
9
11
|
ModelPriceComparisonResponse,
|
|
10
12
|
} from '@vertesia/common';
|
|
11
13
|
|
|
@@ -30,6 +32,14 @@ export class CostApi extends ApiTopic {
|
|
|
30
32
|
return this.get('/model-prices', { query: { ...query } });
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
/**
|
|
36
|
+
* The LLM and embedding cost of the current project's intake runs over a window: totals, a time series, and
|
|
37
|
+
* breakdowns by content type, outcome and document. Requires a billing read permission.
|
|
38
|
+
*/
|
|
39
|
+
getIntakeCostSummary(query: IntakeCostSummaryQuery = {}): Promise<IntakeCostSummaryResponse> {
|
|
40
|
+
return this.get('/intake', { query: { ...query } });
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
/**
|
|
34
44
|
* Price a single interaction run or agent run.
|
|
35
45
|
*/
|
|
@@ -6,12 +6,16 @@ import {
|
|
|
6
6
|
type DashboardArchiveResult,
|
|
7
7
|
type DashboardBulkArchiveResult,
|
|
8
8
|
type DashboardBulkDeleteResult,
|
|
9
|
+
type DashboardExport,
|
|
10
|
+
DashboardExportStatus,
|
|
9
11
|
type DashboardItem,
|
|
10
12
|
type DashboardStatus,
|
|
11
13
|
type DashboardVersion,
|
|
12
14
|
type DashboardVersionItem,
|
|
13
15
|
type DashboardVersioningStatusResponse,
|
|
14
16
|
DataStoreApiHeaders,
|
|
17
|
+
type ExportDashboardPayload,
|
|
18
|
+
type ExportDashboardPreviewPayload,
|
|
15
19
|
type PromoteDashboardVersionPayload,
|
|
16
20
|
type UpdateDashboardPayload,
|
|
17
21
|
} from '@vertesia/common';
|
|
@@ -23,7 +27,9 @@ import {
|
|
|
23
27
|
* - Multi-panel Vega/Vega-Lite visualizations
|
|
24
28
|
* - SQL-backed data sources via named queries
|
|
25
29
|
*
|
|
26
|
-
*
|
|
30
|
+
* - PNG export of a saved dashboard ({@link DashboardApi.export}) or of an unsaved one
|
|
31
|
+
* ({@link DashboardApi.exportPreview}). Exports run in the background: poll them with
|
|
32
|
+
* {@link DashboardApi.getExport}, or wait for them with {@link DashboardApi.waitForExport}.
|
|
27
33
|
*/
|
|
28
34
|
export class DashboardApi extends ApiTopic {
|
|
29
35
|
private readonly storeId: string;
|
|
@@ -58,30 +64,24 @@ export class DashboardApi extends ApiTopic {
|
|
|
58
64
|
/**
|
|
59
65
|
* Create a new dashboard.
|
|
60
66
|
*
|
|
61
|
-
* @param payload - Dashboard
|
|
67
|
+
* @param payload - Dashboard name, SQL data source and Vega-Lite spec
|
|
62
68
|
* @returns The created dashboard
|
|
63
69
|
*
|
|
64
70
|
* @example
|
|
65
71
|
* ```typescript
|
|
66
72
|
* const dashboard = await client.data.dashboards(storeId).create({
|
|
67
73
|
* name: 'Sales Overview',
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* mark: 'bar',
|
|
78
|
-
* encoding: {
|
|
79
|
-
* x: { field: 'month', type: 'ordinal' },
|
|
80
|
-
* y: { field: 'sum_amount', type: 'quantitative' }
|
|
81
|
-
* }
|
|
82
|
-
* }
|
|
74
|
+
* dataSource: {
|
|
75
|
+
* kind: 'data_sql',
|
|
76
|
+
* query: 'SELECT month, SUM(amount) AS revenue FROM sales GROUP BY month',
|
|
77
|
+
* },
|
|
78
|
+
* spec: {
|
|
79
|
+
* mark: 'bar',
|
|
80
|
+
* encoding: {
|
|
81
|
+
* x: { field: 'month', type: 'ordinal' },
|
|
82
|
+
* y: { field: 'revenue', type: 'quantitative' }
|
|
83
83
|
* }
|
|
84
|
-
*
|
|
84
|
+
* }
|
|
85
85
|
* });
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
@@ -110,6 +110,67 @@ export class DashboardApi extends ApiTopic {
|
|
|
110
110
|
return this.put(`/${id}`, { payload, headers: this.storeHeaders() });
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Start rendering a saved dashboard as an image.
|
|
115
|
+
*
|
|
116
|
+
* Every call renders a new image from the current data. The export starts `running`: poll it
|
|
117
|
+
* with {@link getExport} or wait for it with {@link waitForExport}.
|
|
118
|
+
*
|
|
119
|
+
* @param id - Dashboard ID
|
|
120
|
+
* @param payload - Parameter values and render options
|
|
121
|
+
* @returns The started export
|
|
122
|
+
*/
|
|
123
|
+
export(id: string, payload: ExportDashboardPayload = {}): Promise<DashboardExport> {
|
|
124
|
+
return this.post(`/${id}/export`, { payload, headers: this.storeHeaders() });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Start rendering an unsaved dashboard (SQL query and Vega-Lite spec) as an image, without saving it.
|
|
129
|
+
*
|
|
130
|
+
* Use it to check a spec before creating or updating a dashboard: an invalid spec or query makes
|
|
131
|
+
* the export fail with the list of problems.
|
|
132
|
+
*
|
|
133
|
+
* @param payload - The query, spec and render options
|
|
134
|
+
* @returns The started export
|
|
135
|
+
*/
|
|
136
|
+
exportPreview(payload: ExportDashboardPreviewPayload): Promise<DashboardExport> {
|
|
137
|
+
return this.post('/export', { payload, headers: this.storeHeaders() });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Get the status of an export. Once it is `completed`, each call returns a fresh download URL.
|
|
142
|
+
*
|
|
143
|
+
* @param exportId - The `export_id` returned when the export was started
|
|
144
|
+
* @returns The export
|
|
145
|
+
*/
|
|
146
|
+
getExport(exportId: string): Promise<DashboardExport> {
|
|
147
|
+
return this.get(`/exports/${exportId}`, { headers: this.storeHeaders() });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Poll an export until it is `completed` or `failed`.
|
|
152
|
+
*
|
|
153
|
+
* @param exportId - The `export_id` returned when the export was started
|
|
154
|
+
* @param options - Poll interval (default: 1s) and timeout (default: 5 minutes)
|
|
155
|
+
* @returns The completed or failed export
|
|
156
|
+
* @throws Error when the export is still running after `timeoutMs`
|
|
157
|
+
*/
|
|
158
|
+
async waitForExport(exportId: string, options: DashboardExportWaitOptions = {}): Promise<DashboardExport> {
|
|
159
|
+
const pollIntervalMs = options.pollIntervalMs ?? 1000;
|
|
160
|
+
const timeoutMs = options.timeoutMs ?? 5 * 60 * 1000;
|
|
161
|
+
const deadline = Date.now() + timeoutMs;
|
|
162
|
+
while (true) {
|
|
163
|
+
const current = await this.getExport(exportId);
|
|
164
|
+
if (current.status !== DashboardExportStatus.RUNNING) {
|
|
165
|
+
return current;
|
|
166
|
+
}
|
|
167
|
+
if (Date.now() >= deadline) {
|
|
168
|
+
throw new Error(`Dashboard export ${exportId} is still running after ${timeoutMs}ms`);
|
|
169
|
+
}
|
|
170
|
+
await sleep(pollIntervalMs);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
113
174
|
/**
|
|
114
175
|
* Archive (soft delete) a dashboard.
|
|
115
176
|
*
|
|
@@ -215,3 +276,17 @@ export class DashboardApi extends ApiTopic {
|
|
|
215
276
|
return this.put(`/${dashboardId}/versioning`, { payload: { enabled }, headers: this.storeHeaders() });
|
|
216
277
|
}
|
|
217
278
|
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Options for {@link DashboardApi.waitForExport}.
|
|
282
|
+
*/
|
|
283
|
+
export interface DashboardExportWaitOptions {
|
|
284
|
+
/** Delay between status checks, in milliseconds (default: 1000) */
|
|
285
|
+
pollIntervalMs?: number;
|
|
286
|
+
/** How long to wait before giving up, in milliseconds (default: 5 minutes) */
|
|
287
|
+
timeoutMs?: number;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function sleep(ms: number): Promise<void> {
|
|
291
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
292
|
+
}
|
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 {
|