@vertesia/client 0.51.0 → 0.53.0
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/cjs/AccountApi.js +11 -1
- package/lib/cjs/AccountApi.js.map +1 -1
- package/lib/cjs/AccountsApi.js +3 -0
- package/lib/cjs/AccountsApi.js.map +1 -1
- package/lib/cjs/InteractionsApi.js +17 -0
- package/lib/cjs/InteractionsApi.js.map +1 -1
- package/lib/cjs/RunsApi.js +33 -8
- package/lib/cjs/RunsApi.js.map +1 -1
- package/lib/cjs/client.js +65 -10
- package/lib/cjs/client.js.map +1 -1
- package/lib/cjs/execute.js +6 -0
- package/lib/cjs/execute.js.map +1 -1
- package/lib/cjs/index.js +0 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/nodejs/NodeStreamSource.js +45 -0
- package/lib/cjs/nodejs/NodeStreamSource.js.map +1 -0
- package/lib/cjs/nodejs/index.js +18 -0
- package/lib/cjs/nodejs/index.js.map +1 -0
- package/lib/cjs/store/AnalyzeDocApi.js +25 -6
- package/lib/cjs/store/AnalyzeDocApi.js.map +1 -1
- package/lib/cjs/store/CommandsApi.js +7 -23
- package/lib/cjs/store/CommandsApi.js.map +1 -1
- package/lib/cjs/store/EmbeddingsApi.js +29 -0
- package/lib/cjs/store/EmbeddingsApi.js.map +1 -0
- package/lib/cjs/store/FilesApi.js +6 -0
- package/lib/cjs/store/FilesApi.js.map +1 -1
- package/lib/cjs/store/TypesApi.js +1 -0
- package/lib/cjs/store/TypesApi.js.map +1 -1
- package/lib/cjs/store/WorkflowsApi.js +90 -8
- package/lib/cjs/store/WorkflowsApi.js.map +1 -1
- package/lib/cjs/store/client.js +2 -0
- package/lib/cjs/store/client.js.map +1 -1
- package/lib/esm/AccountApi.js +11 -1
- package/lib/esm/AccountApi.js.map +1 -1
- package/lib/esm/AccountsApi.js +3 -0
- package/lib/esm/AccountsApi.js.map +1 -1
- package/lib/esm/InteractionsApi.js +18 -1
- package/lib/esm/InteractionsApi.js.map +1 -1
- package/lib/esm/RunsApi.js +33 -8
- package/lib/esm/RunsApi.js.map +1 -1
- package/lib/esm/client.js +65 -10
- package/lib/esm/client.js.map +1 -1
- package/lib/esm/execute.js +5 -0
- package/lib/esm/execute.js.map +1 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/nodejs/NodeStreamSource.js +41 -0
- package/lib/esm/nodejs/NodeStreamSource.js.map +1 -0
- package/lib/esm/nodejs/index.js +2 -0
- package/lib/esm/nodejs/index.js.map +1 -0
- package/lib/esm/store/AnalyzeDocApi.js +25 -6
- package/lib/esm/store/AnalyzeDocApi.js.map +1 -1
- package/lib/esm/store/CommandsApi.js +6 -21
- package/lib/esm/store/CommandsApi.js.map +1 -1
- package/lib/esm/store/EmbeddingsApi.js +25 -0
- package/lib/esm/store/EmbeddingsApi.js.map +1 -0
- package/lib/esm/store/FilesApi.js +6 -0
- package/lib/esm/store/FilesApi.js.map +1 -1
- package/lib/esm/store/TypesApi.js +1 -0
- package/lib/esm/store/TypesApi.js.map +1 -1
- package/lib/esm/store/WorkflowsApi.js +91 -9
- package/lib/esm/store/WorkflowsApi.js.map +1 -1
- package/lib/esm/store/client.js +2 -0
- package/lib/esm/store/client.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/AccountApi.d.ts +8 -3
- package/lib/types/AccountApi.d.ts.map +1 -1
- package/lib/types/AccountsApi.d.ts +1 -1
- package/lib/types/AccountsApi.d.ts.map +1 -1
- package/lib/types/AnalyticsApi.d.ts +0 -1
- package/lib/types/ApiKeysApi.d.ts +0 -1
- package/lib/types/CommandsApi.d.ts +0 -1
- package/lib/types/EnvironmentsApi.d.ts +0 -1
- package/lib/types/IamApi.d.ts +0 -1
- package/lib/types/InteractionBase.d.ts +0 -1
- package/lib/types/InteractionsApi.d.ts +17 -3
- package/lib/types/InteractionsApi.d.ts.map +1 -1
- package/lib/types/ProjectsApi.d.ts +0 -1
- package/lib/types/PromptsApi.d.ts +0 -1
- package/lib/types/RefsApi.d.ts +0 -1
- package/lib/types/RunsApi.d.ts +15 -2
- package/lib/types/RunsApi.d.ts.map +1 -1
- package/lib/types/StreamSource.d.ts +0 -1
- package/lib/types/TrainingApi.d.ts +0 -1
- package/lib/types/UsersApi.d.ts +0 -1
- package/lib/types/client.d.ts +20 -5
- package/lib/types/client.d.ts.map +1 -1
- package/lib/types/execute.d.ts +7 -4
- package/lib/types/execute.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -4
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/nodejs/NodeStreamSource.d.ts +9 -0
- package/lib/types/nodejs/NodeStreamSource.d.ts.map +1 -0
- package/lib/types/nodejs/index.d.ts +1 -0
- package/lib/types/nodejs/index.d.ts.map +1 -0
- package/lib/types/store/AgentsApi.d.ts +0 -1
- package/lib/types/store/AnalyzeDocApi.d.ts +4 -4
- package/lib/types/store/AnalyzeDocApi.d.ts.map +1 -1
- package/lib/types/store/CollectionsApi.d.ts +0 -1
- package/lib/types/store/CommandsApi.d.ts +5 -9
- package/lib/types/store/CommandsApi.d.ts.map +1 -1
- package/lib/types/store/EmbeddingsApi.d.ts +12 -0
- package/lib/types/store/EmbeddingsApi.d.ts.map +1 -0
- package/lib/types/store/FilesApi.d.ts +0 -1
- package/lib/types/store/FilesApi.d.ts.map +1 -1
- package/lib/types/store/ObjectsApi.d.ts +0 -1
- package/lib/types/store/TypesApi.d.ts +2 -2
- package/lib/types/store/TypesApi.d.ts.map +1 -1
- package/lib/types/store/WorkflowsApi.d.ts +16 -9
- package/lib/types/store/WorkflowsApi.d.ts.map +1 -1
- package/lib/types/store/client.d.ts +2 -1
- package/lib/types/store/client.d.ts.map +1 -1
- package/lib/types/store/errors.d.ts +0 -1
- package/lib/types/store/index.d.ts +0 -1
- package/package.json +25 -10
- package/src/AccountApi.ts +14 -2
- package/src/AccountsApi.ts +4 -0
- package/src/InteractionsApi.ts +25 -3
- package/src/RunsApi.ts +67 -30
- package/src/client.test.ts +94 -0
- package/src/client.ts +84 -13
- package/src/execute.ts +9 -3
- package/src/index.ts +2 -3
- package/src/nodejs/NodeStreamSource.ts +43 -0
- package/src/nodejs/index.ts +1 -0
- package/src/store/AnalyzeDocApi.ts +29 -9
- package/src/store/CommandsApi.ts +6 -33
- package/src/store/EmbeddingsApi.ts +39 -0
- package/src/store/FilesApi.ts +4 -0
- package/src/store/TypesApi.ts +2 -1
- package/src/store/WorkflowsApi.ts +127 -25
- package/src/store/client.ts +2 -0
package/src/RunsApi.ts
CHANGED
|
@@ -1,26 +1,38 @@
|
|
|
1
1
|
import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
CheckpointConversationPayload,
|
|
4
|
+
ComputeRunFacetPayload,
|
|
5
|
+
ExecutionRun,
|
|
6
|
+
ExecutionRunRef,
|
|
7
|
+
FindPayload,
|
|
8
|
+
RunCreatePayload,
|
|
9
|
+
RunListingFilters,
|
|
10
|
+
RunListingQueryOptions,
|
|
11
|
+
RunSearchPayload,
|
|
12
|
+
ToolResultsPayload,
|
|
13
|
+
UserMessagePayload,
|
|
14
|
+
} from "@vertesia/common";
|
|
3
15
|
import { VertesiaClient } from "./client.js";
|
|
16
|
+
import { ExecutionResponse } from "@llumiverse/core";
|
|
4
17
|
|
|
5
18
|
export interface FilterOption {
|
|
6
|
-
id: string
|
|
7
|
-
name: string
|
|
8
|
-
count: number
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
count: number;
|
|
9
22
|
}
|
|
10
23
|
|
|
11
24
|
export interface ComputeRunFacetsResponse {
|
|
12
|
-
environments?: { _id: string
|
|
13
|
-
interactions?: { _id: string
|
|
14
|
-
models?: { _id: string
|
|
15
|
-
tags?: { _id: string
|
|
16
|
-
status?: { _id: string
|
|
25
|
+
environments?: { _id: string; count: number }[];
|
|
26
|
+
interactions?: { _id: string; count: number }[];
|
|
27
|
+
models?: { _id: string; count: number }[];
|
|
28
|
+
tags?: { _id: string; count: number }[];
|
|
29
|
+
status?: { _id: string; count: number }[];
|
|
17
30
|
total?: { count: number }[];
|
|
18
31
|
}
|
|
19
32
|
|
|
20
33
|
export class RunsApi extends ApiTopic {
|
|
21
|
-
|
|
22
34
|
constructor(parent: ClientBase) {
|
|
23
|
-
super(parent, "/api/v1/runs")
|
|
35
|
+
super(parent, "/api/v1/runs");
|
|
24
36
|
}
|
|
25
37
|
|
|
26
38
|
/**
|
|
@@ -30,30 +42,29 @@ export class RunsApi extends ApiTopic {
|
|
|
30
42
|
* @returns InteractionResult[]
|
|
31
43
|
**/
|
|
32
44
|
list({ limit, offset, filters }: RunListingQueryOptions): Promise<ExecutionRunRef[]> {
|
|
33
|
-
|
|
34
45
|
const query = {
|
|
35
46
|
limit,
|
|
36
47
|
offset,
|
|
37
|
-
...filters
|
|
38
|
-
}
|
|
48
|
+
...filters,
|
|
49
|
+
};
|
|
39
50
|
|
|
40
|
-
return this.get(
|
|
51
|
+
return this.get("/", { query: query });
|
|
41
52
|
}
|
|
42
53
|
|
|
43
54
|
find(payload: FindPayload): Promise<ExecutionRun[]> {
|
|
44
55
|
return this.post("/find", {
|
|
45
|
-
payload
|
|
56
|
+
payload,
|
|
46
57
|
});
|
|
47
58
|
}
|
|
48
59
|
|
|
49
60
|
/**
|
|
50
61
|
* Get a run by id
|
|
51
|
-
*
|
|
62
|
+
*
|
|
52
63
|
* @param id
|
|
53
64
|
* @returns InteractionResult
|
|
54
65
|
**/
|
|
55
|
-
retrieve<P=any, R=any>(id: string): Promise<ExecutionRun<P, R>> {
|
|
56
|
-
return this.get(
|
|
66
|
+
retrieve<P = any, R = any>(id: string): Promise<ExecutionRun<P, R>> {
|
|
67
|
+
return this.get("/" + id);
|
|
57
68
|
}
|
|
58
69
|
|
|
59
70
|
/**
|
|
@@ -62,10 +73,9 @@ export class RunsApi extends ApiTopic {
|
|
|
62
73
|
*/
|
|
63
74
|
filterOptions(field: string, filters: RunListingFilters): Promise<FilterOption[]> {
|
|
64
75
|
const query = {
|
|
65
|
-
...filters
|
|
66
|
-
}
|
|
76
|
+
...filters,
|
|
77
|
+
};
|
|
67
78
|
return this.get(`/filter-options/${field}`, { query });
|
|
68
|
-
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
create(payload: RunCreatePayload): Promise<ExecutionRun> {
|
|
@@ -73,14 +83,42 @@ export class RunsApi extends ApiTopic {
|
|
|
73
83
|
if (sessionTags) {
|
|
74
84
|
let tags = Array.isArray(sessionTags) ? sessionTags : [sessionTags];
|
|
75
85
|
if (Array.isArray(payload.tags)) {
|
|
76
|
-
tags = tags.concat(payload.tags)
|
|
86
|
+
tags = tags.concat(payload.tags);
|
|
77
87
|
} else if (payload.tags) {
|
|
78
|
-
tags = tags.concat([payload.tags])
|
|
88
|
+
tags = tags.concat([payload.tags]);
|
|
79
89
|
}
|
|
80
|
-
payload = { ...payload, tags }
|
|
90
|
+
payload = { ...payload, tags };
|
|
81
91
|
}
|
|
82
92
|
return this.post("/", {
|
|
83
|
-
payload
|
|
93
|
+
payload,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Send tool results and continues the conversation
|
|
99
|
+
* @param payload
|
|
100
|
+
* @returns
|
|
101
|
+
*/
|
|
102
|
+
sendToolResults(payload: ToolResultsPayload): Promise<ExecutionResponse> {
|
|
103
|
+
return this.post(`/tool-results`, {
|
|
104
|
+
payload,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
*
|
|
110
|
+
* @param payload
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
sendUserMessage(payload: UserMessagePayload): Promise<ExecutionResponse> {
|
|
114
|
+
return this.post(`/user-message`, {
|
|
115
|
+
payload,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
createCheckpoint(payload: CheckpointConversationPayload): Promise<ExecutionResponse> {
|
|
120
|
+
return this.post(`/checkpoint`, {
|
|
121
|
+
payload,
|
|
84
122
|
});
|
|
85
123
|
}
|
|
86
124
|
|
|
@@ -91,14 +129,13 @@ export class RunsApi extends ApiTopic {
|
|
|
91
129
|
**/
|
|
92
130
|
computeFacets(query: ComputeRunFacetPayload): Promise<ComputeRunFacetsResponse> {
|
|
93
131
|
return this.post("/facets", {
|
|
94
|
-
payload: query
|
|
132
|
+
payload: query,
|
|
95
133
|
});
|
|
96
134
|
}
|
|
97
135
|
|
|
98
136
|
search(payload: RunSearchPayload): Promise<ExecutionRunRef[]> {
|
|
99
137
|
return this.post("/search", {
|
|
100
|
-
payload
|
|
138
|
+
payload,
|
|
101
139
|
});
|
|
102
140
|
}
|
|
103
|
-
|
|
104
|
-
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { VertesiaClient } from "./client";
|
|
3
|
+
|
|
4
|
+
describe('Test Vertesia Client', () => {
|
|
5
|
+
test('Initialization with studio and zeno URLs', () => {
|
|
6
|
+
const client = new VertesiaClient({
|
|
7
|
+
serverUrl: 'https://api.vertesia.io',
|
|
8
|
+
storeUrl: 'https://api.vertesia.io',
|
|
9
|
+
apikey: '1234',
|
|
10
|
+
});
|
|
11
|
+
expect(client).toBeDefined();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('Initialization with studio URL only', () => {
|
|
15
|
+
expect(() => {
|
|
16
|
+
new VertesiaClient({
|
|
17
|
+
serverUrl: 'https://api.vertesia.io',
|
|
18
|
+
storeUrl: '',
|
|
19
|
+
});
|
|
20
|
+
}).toThrowError("Parameter 'site' or 'storeUrl' is required for VertesiaClient");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('Initialization with zeno URL only', () => {
|
|
24
|
+
expect(() => {
|
|
25
|
+
new VertesiaClient({
|
|
26
|
+
serverUrl: '',
|
|
27
|
+
storeUrl: 'https://api.vertesia.io',
|
|
28
|
+
});
|
|
29
|
+
}).toThrowError("Parameter 'site' or 'serverUrl' is required for VertesiaClient");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('Initialization with same site', () => {
|
|
33
|
+
const client = new VertesiaClient({
|
|
34
|
+
serverUrl: 'https://api.vertesia.io',
|
|
35
|
+
storeUrl: 'https://api.vertesia.io',
|
|
36
|
+
site: 'api.vertesia.io',
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
expect(client).toBeDefined();
|
|
40
|
+
expect(client.baseUrl).toBe('https://api.vertesia.io');
|
|
41
|
+
expect(client.storeUrl).toBe('https://api.vertesia.io');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('Initialization with default parameters', () => {
|
|
45
|
+
const client = new VertesiaClient();
|
|
46
|
+
|
|
47
|
+
expect(client).toBeDefined();
|
|
48
|
+
expect(client.baseUrl).toBe('https://api.vertesia.io');
|
|
49
|
+
expect(client.storeUrl).toBe('https://api.vertesia.io');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('Initialization with site api-preview.vertesia.io', () => {
|
|
53
|
+
const client = new VertesiaClient({
|
|
54
|
+
site: 'api-preview.vertesia.io',
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(client).toBeDefined();
|
|
58
|
+
expect(client.baseUrl).toBe('https://api-preview.vertesia.io');
|
|
59
|
+
expect(client.storeUrl).toBe('https://api-preview.vertesia.io');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('Initialization with site api-staging.vertesia.io', () => {
|
|
63
|
+
const client = new VertesiaClient({
|
|
64
|
+
site: 'api-staging.vertesia.io',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(client).toBeDefined();
|
|
68
|
+
expect(client.baseUrl).toBe('https://api-staging.vertesia.io');
|
|
69
|
+
expect(client.storeUrl).toBe('https://api-staging.vertesia.io');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('Initialization with site localhost', () => {
|
|
73
|
+
const client = new VertesiaClient({
|
|
74
|
+
serverUrl: 'http://localhost:8091',
|
|
75
|
+
storeUrl: 'http://localhost:8092',
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(client).toBeDefined();
|
|
79
|
+
expect(client.baseUrl).toBe('http://localhost:8091');
|
|
80
|
+
expect(client.storeUrl).toBe('http://localhost:8092');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('Initialization with overrides', () => {
|
|
84
|
+
const client = new VertesiaClient({
|
|
85
|
+
serverUrl: 'https://studio-server-production.api.becomposable.com',
|
|
86
|
+
storeUrl: 'https://zeno-server-production.api.becomposable.com',
|
|
87
|
+
site: 'api.vertesia.io',
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(client).toBeDefined();
|
|
91
|
+
expect(client.baseUrl).toBe('https://studio-server-production.api.becomposable.com');
|
|
92
|
+
expect(client.storeUrl).toBe('https://zeno-server-production.api.becomposable.com');
|
|
93
|
+
});
|
|
94
|
+
});
|
package/src/client.ts
CHANGED
|
@@ -21,9 +21,22 @@ import UsersApi from "./UsersApi.js";
|
|
|
21
21
|
*/
|
|
22
22
|
const EXPIRATION_THRESHOLD = 60000;
|
|
23
23
|
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
export type VertesiaClientProps = {
|
|
25
|
+
/**
|
|
26
|
+
* The site name of Vertesia.
|
|
27
|
+
*
|
|
28
|
+
* This is used to determine the API backend. It should not include the protocol. For more
|
|
29
|
+
* advanced configurations, use `serverUrl` and `storeUrl` instead.
|
|
30
|
+
*
|
|
31
|
+
* @example api.vertesia.io
|
|
32
|
+
* @example api-preview.vertesia.io
|
|
33
|
+
* @example api-staging.vertesia.io
|
|
34
|
+
* @default api.vertesia.io
|
|
35
|
+
* @since 0.52.0
|
|
36
|
+
*/
|
|
37
|
+
site?: 'api.vertesia.io' | 'api-preview.vertesia.io' | 'api-staging.vertesia.io';
|
|
38
|
+
serverUrl?: string;
|
|
39
|
+
storeUrl?: string;
|
|
27
40
|
apikey?: string;
|
|
28
41
|
projectId?: string;
|
|
29
42
|
sessionTags?: string | string[];
|
|
@@ -49,17 +62,33 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
49
62
|
sessionTags?: string | string[];
|
|
50
63
|
|
|
51
64
|
constructor(
|
|
52
|
-
opts: VertesiaClientProps = {
|
|
65
|
+
opts: VertesiaClientProps = {
|
|
66
|
+
site: 'api.vertesia.io',
|
|
67
|
+
}
|
|
53
68
|
) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
let studioServerUrl: string;
|
|
70
|
+
let zenoServerUrl: string;
|
|
71
|
+
|
|
72
|
+
if (opts.serverUrl) {
|
|
73
|
+
studioServerUrl = opts.serverUrl;
|
|
74
|
+
} else if (opts.site) {
|
|
75
|
+
studioServerUrl = `https://${opts.site}`;
|
|
76
|
+
} else {
|
|
77
|
+
throw new Error("Parameter 'site' or 'serverUrl' is required for VertesiaClient");
|
|
57
78
|
}
|
|
58
|
-
|
|
59
|
-
|
|
79
|
+
|
|
80
|
+
if (opts.storeUrl) {
|
|
81
|
+
zenoServerUrl = opts.storeUrl;
|
|
82
|
+
} else if (opts.site) {
|
|
83
|
+
zenoServerUrl = `https://${opts.site}`;
|
|
84
|
+
} else {
|
|
85
|
+
throw new Error("Parameter 'site' or 'storeUrl' is required for VertesiaClient");
|
|
60
86
|
}
|
|
87
|
+
|
|
88
|
+
super(studioServerUrl);
|
|
89
|
+
|
|
61
90
|
this.store = new ZenoClient({
|
|
62
|
-
serverUrl:
|
|
91
|
+
serverUrl: zenoServerUrl,
|
|
63
92
|
apikey: opts.apikey,
|
|
64
93
|
onRequest: opts.onRequest,
|
|
65
94
|
onResponse: opts.onResponse
|
|
@@ -103,6 +132,21 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
103
132
|
);
|
|
104
133
|
}
|
|
105
134
|
|
|
135
|
+
async getRawJWT() {
|
|
136
|
+
if (!this._jwt && this._auth) {
|
|
137
|
+
const auth = await this._auth();
|
|
138
|
+
if (!this._jwt) { // the _jwt may be set by the auth callback
|
|
139
|
+
this._jwt = auth.trim().split(' ')[1]; // remove Bearer prefix
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return this._jwt || null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async getDecodedJWT() {
|
|
146
|
+
const jwt = await this.getRawJWT();
|
|
147
|
+
return jwt ? decodeJWT(jwt) : null;
|
|
148
|
+
}
|
|
149
|
+
|
|
106
150
|
/**
|
|
107
151
|
* Alias for store.workflows
|
|
108
152
|
*/
|
|
@@ -128,6 +172,9 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
128
172
|
return this.store.types;
|
|
129
173
|
}
|
|
130
174
|
|
|
175
|
+
get storeUrl() {
|
|
176
|
+
return this.store.baseUrl;
|
|
177
|
+
}
|
|
131
178
|
|
|
132
179
|
set project(projectId: string | null) {
|
|
133
180
|
if (projectId) {
|
|
@@ -182,10 +229,34 @@ function isTokenExpired(token: string | null) {
|
|
|
182
229
|
return true;
|
|
183
230
|
}
|
|
184
231
|
|
|
185
|
-
const
|
|
186
|
-
const decodedJson = Buffer.from(payloadBase64, 'base64').toString();
|
|
187
|
-
const decoded = JSON.parse(decodedJson)
|
|
232
|
+
const decoded = decodeJWT(token);
|
|
188
233
|
const exp = decoded.exp;
|
|
189
234
|
const currentTime = Date.now();
|
|
190
235
|
return (currentTime <= exp * 1000 - EXPIRATION_THRESHOLD);
|
|
191
236
|
}
|
|
237
|
+
|
|
238
|
+
function decodeJWT(jwt: string) {
|
|
239
|
+
const payloadBase64 = jwt.split('.')[1];
|
|
240
|
+
const decodedJson = base64UrlDecode(payloadBase64);
|
|
241
|
+
return JSON.parse(decodedJson)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function base64UrlDecode(input: string): string {
|
|
245
|
+
// Convert base64url to base64
|
|
246
|
+
const base64 = input.replace(/-/g, '+').replace(/_/g, '/')
|
|
247
|
+
// Pad with '=' to make length a multiple of 4
|
|
248
|
+
.padEnd(Math.ceil(input.length / 4) * 4, '=');
|
|
249
|
+
|
|
250
|
+
if (typeof Buffer !== 'undefined') {
|
|
251
|
+
// Node.js
|
|
252
|
+
return Buffer.from(base64, 'base64').toString('utf-8');
|
|
253
|
+
} else if (typeof atob !== 'undefined' && typeof TextDecoder !== 'undefined') {
|
|
254
|
+
// Browser
|
|
255
|
+
const binary = atob(base64);
|
|
256
|
+
const bytes = Uint8Array.from(binary, c => c.charCodeAt(0));
|
|
257
|
+
// decode to utf8
|
|
258
|
+
return new TextDecoder().decode(bytes);
|
|
259
|
+
} else {
|
|
260
|
+
throw new Error('No base64 decoder available');
|
|
261
|
+
}
|
|
262
|
+
}
|
package/src/execute.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AsyncExecutionPayload, ExecutionRunStatus, InteractionExecutionPayload, InteractionExecutionResult, NamedInteractionExecutionPayload } from '@vertesia/common';
|
|
2
2
|
import { VertesiaClient } from './client.js';
|
|
3
3
|
|
|
4
4
|
export function EventSourceProvider(): Promise<typeof EventSource> {
|
|
@@ -22,7 +22,7 @@ export function EventSourceProvider(): Promise<typeof EventSource> {
|
|
|
22
22
|
export async function executeInteraction<P = any, R = any>(client: VertesiaClient,
|
|
23
23
|
interactionId: string,
|
|
24
24
|
payload: InteractionExecutionPayload = {},
|
|
25
|
-
onChunk?: (chunk: string) => void): Promise<
|
|
25
|
+
onChunk?: (chunk: string) => void): Promise<InteractionExecutionResult<P, R>> {
|
|
26
26
|
const stream = !!onChunk;
|
|
27
27
|
const response = await client.runs.create({
|
|
28
28
|
...payload, interaction: interactionId, stream
|
|
@@ -55,7 +55,7 @@ export async function executeInteraction<P = any, R = any>(client: VertesiaClien
|
|
|
55
55
|
export async function executeInteractionByName<P = any, R = any>(client: VertesiaClient,
|
|
56
56
|
interaction: string,
|
|
57
57
|
payload: InteractionExecutionPayload = {},
|
|
58
|
-
onChunk?: (chunk: string) => void): Promise<
|
|
58
|
+
onChunk?: (chunk: string) => void): Promise<InteractionExecutionResult<P, R>> {
|
|
59
59
|
const stream = !!onChunk;
|
|
60
60
|
const response = await client.post('/api/v1/execute', {
|
|
61
61
|
payload: {
|
|
@@ -111,4 +111,10 @@ function handleStreaming(client: VertesiaClient, runId: string, onChunk: (chunk:
|
|
|
111
111
|
reject(err);
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function executeInteractionAsync(client: VertesiaClient, payload: AsyncExecutionPayload): Promise<{ runId: string, workflowId: string }> {
|
|
117
|
+
return await client.post('/api/v1/execute/async', {
|
|
118
|
+
payload,
|
|
119
|
+
});
|
|
114
120
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
export * from './client.js';
|
|
1
2
|
export * from './InteractionBase.js';
|
|
3
|
+
export type { AsyncExecutionResult, ComputeInteractionFacetsResponse } from './InteractionsApi.js';
|
|
2
4
|
export type { ComputePromptFacetsResponse, ListInteractionsResponse } from './PromptsApi.js';
|
|
3
|
-
export type { ComputeInteractionFacetsResponse } from './InteractionsApi.js';
|
|
4
5
|
export type { ComputeRunFacetsResponse, FilterOption } from './RunsApi.js';
|
|
5
|
-
export * from './client.js';
|
|
6
|
-
export * from './InteractionBase.js';
|
|
7
6
|
export * from "./store/index.js";
|
|
8
7
|
export * from "./StreamSource.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Readable } from "node:stream";
|
|
2
|
+
import { ReadableStream as NodeReadableStream } from "node:stream/web";
|
|
3
|
+
import { StreamSource } from "../StreamSource.js";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A stream source that wraps a Node.js Readable stream.
|
|
8
|
+
* This class is only works in Node.js environments.
|
|
9
|
+
*/
|
|
10
|
+
export class NodeStreamSource extends StreamSource {
|
|
11
|
+
constructor(stream: Readable, name: string, type?: string, id?: string) {
|
|
12
|
+
super(readableToWebStream(stream) as ReadableStream, name, type, id);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function readableToWebStream<T = string | Buffer>(stream: Readable): ReadableStream<T> {
|
|
17
|
+
if (NodeReadableStream.from) {
|
|
18
|
+
return NodeReadableStream.from(stream) as ReadableStream<T>;
|
|
19
|
+
} else {
|
|
20
|
+
return readableToWebStream_BUN(stream);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Bun implementation since bun is not yet supporting NodeReadableStream.from
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
function readableToWebStream_BUN<T = string | Buffer>(stream: Readable): ReadableStream<T> {
|
|
29
|
+
const it = stream[Symbol.asyncIterator]();
|
|
30
|
+
return new ReadableStream<T>({
|
|
31
|
+
async pull(controller) {
|
|
32
|
+
const { value, done } = await it.next();
|
|
33
|
+
if (done) {
|
|
34
|
+
controller.close();
|
|
35
|
+
} else {
|
|
36
|
+
controller.enqueue(value);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
cancel() {
|
|
40
|
+
it.return?.();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./NodeStreamSource.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
|
|
2
|
-
import {
|
|
2
|
+
import { AdaptedTable, AdaptTablesRequest, DocAnalyzerResultResponse, DocAnalyzeRunStatusResponse, DocImage, DocTableCsv, DocTableJson, ExportTableFormats, GetAdaptedTablesRequestQuery, PdfToRichtextOptions, WorkflowRunStatus } from "@vertesia/common";
|
|
3
3
|
|
|
4
4
|
export class AnalyzeDocApi extends ApiTopic {
|
|
5
5
|
constructor(parent: ClientBase, public objectId: string) {
|
|
@@ -18,24 +18,44 @@ export class AnalyzeDocApi extends ApiTopic {
|
|
|
18
18
|
return this.get("/results");
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
async adaptTables(payload: AdaptTablesRequest): Promise<WorkflowRunStatus> {
|
|
22
|
+
return this.post("/adapt_tables", { payload });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async getAdaptedTables(runId?: string, query?: GetAdaptedTablesRequestQuery): Promise<Record<number, AdaptedTable>> {
|
|
26
|
+
const path = runId ? `/adapt_tables/${runId}` : "/adapt_tables";
|
|
27
|
+
|
|
28
|
+
// Build query parameters
|
|
29
|
+
const queryParams: any = {};
|
|
30
|
+
if (query?.format) queryParams.format = query.format;
|
|
31
|
+
if (query?.raw !== undefined) queryParams.raw = query.raw;
|
|
32
|
+
|
|
33
|
+
// If format is CSV, set response type to text to avoid automatic JSON parsing
|
|
34
|
+
const options: any = { query: queryParams };
|
|
35
|
+
if (query?.format === 'csv') {
|
|
36
|
+
options.responseType = 'text';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return this.get(path, options);
|
|
40
|
+
}
|
|
41
|
+
|
|
21
42
|
async getXml(): Promise<string> {
|
|
22
43
|
return this.get("/xml");
|
|
23
44
|
}
|
|
24
45
|
|
|
25
|
-
async getTables(): Promise<DocTableCsv[] | DocTableJson[]> {
|
|
26
|
-
|
|
46
|
+
async getTables(format?: ExportTableFormats): Promise<DocTableCsv[] | DocTableJson[]> {
|
|
47
|
+
const options: any = {};
|
|
48
|
+
if (format) {
|
|
49
|
+
options.query = {format: format}
|
|
50
|
+
}
|
|
51
|
+
return this.get("/tables", options);
|
|
27
52
|
}
|
|
28
53
|
|
|
29
54
|
async getImages(): Promise<DocImage[]> {
|
|
30
|
-
return this.get("/
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async getParts(): Promise<ContentObject[]> {
|
|
34
|
-
return this.get("/parts");
|
|
55
|
+
return this.get("/images");
|
|
35
56
|
}
|
|
36
57
|
|
|
37
58
|
async getAnnotated(): Promise<{ url: string }> {
|
|
38
59
|
return this.get("/annotated");
|
|
39
60
|
}
|
|
40
|
-
|
|
41
61
|
}
|
package/src/store/CommandsApi.ts
CHANGED
|
@@ -1,42 +1,15 @@
|
|
|
1
1
|
import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { EmbeddingsApi } from "./EmbeddingsApi.js";
|
|
4
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use EmbeddingsApi instead
|
|
6
|
+
* @see EmbeddingsApi
|
|
7
|
+
*/
|
|
5
8
|
export class CommandsApi extends ApiTopic {
|
|
6
9
|
|
|
7
10
|
constructor(parent: ClientBase) {
|
|
8
11
|
super(parent, "/api/v1/commands");
|
|
9
12
|
}
|
|
10
13
|
|
|
11
|
-
embeddings = new EmbeddingsApi(this);
|
|
12
|
-
|
|
14
|
+
embeddings = new EmbeddingsApi(this, "/embeddings");
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
export class EmbeddingsApi extends ApiTopic {
|
|
16
|
-
|
|
17
|
-
constructor(parent: ClientBase) {
|
|
18
|
-
super(parent, "/embeddings");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async status(type: SupportedEmbeddingTypes): Promise<EmbeddingsStatusResponse> {
|
|
22
|
-
return this.get(type + "/status");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async activate(type: SupportedEmbeddingTypes, config: Partial<ProjectConfigurationEmbeddings>): Promise<GenericCommandResponse> {
|
|
26
|
-
|
|
27
|
-
if (!config.environment) {
|
|
28
|
-
throw new Error("Invalid configuration: select environment");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return this.post(type + "/enable", { payload: config });
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async disable(type: SupportedEmbeddingTypes): Promise<GenericCommandResponse> {
|
|
35
|
-
return this.post(type + "/disable");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async recalculate(type: SupportedEmbeddingTypes): Promise<GenericCommandResponse> {
|
|
39
|
-
return this.post(type + "/recalculate");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
|
|
2
|
+
import {
|
|
3
|
+
EmbeddingsStatusResponse,
|
|
4
|
+
GenericCommandResponse,
|
|
5
|
+
ProjectConfigurationEmbeddings,
|
|
6
|
+
SupportedEmbeddingTypes,
|
|
7
|
+
} from "@vertesia/common";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @since 0.52.0
|
|
11
|
+
*/
|
|
12
|
+
export class EmbeddingsApi extends ApiTopic {
|
|
13
|
+
|
|
14
|
+
constructor(parent: ClientBase, basePath: string = "/api/v1/embeddings") {
|
|
15
|
+
super(parent, basePath);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async status(type: SupportedEmbeddingTypes): Promise<EmbeddingsStatusResponse> {
|
|
19
|
+
return this.get(type + "/status");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async activate(type: SupportedEmbeddingTypes, config: Partial<ProjectConfigurationEmbeddings>): Promise<GenericCommandResponse> {
|
|
23
|
+
|
|
24
|
+
if (!config.environment) {
|
|
25
|
+
throw new Error("Invalid configuration: select environment");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return this.post(type + "/enable", { payload: config });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async disable(type: SupportedEmbeddingTypes): Promise<GenericCommandResponse> {
|
|
32
|
+
return this.post(type + "/disable");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async recalculate(type: SupportedEmbeddingTypes): Promise<GenericCommandResponse> {
|
|
36
|
+
return this.post(type + "/recalculate");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
package/src/store/FilesApi.ts
CHANGED
|
@@ -101,6 +101,10 @@ export class FilesApi extends ApiTopic {
|
|
|
101
101
|
}).then((res: Response) => {
|
|
102
102
|
if (res.ok) {
|
|
103
103
|
return res;
|
|
104
|
+
} else if (res.status === 404) {
|
|
105
|
+
throw new Error(`File ${name} not found`); //TODO: type fetch error better with a fetch error class
|
|
106
|
+
} else if (res.status === 403) {
|
|
107
|
+
throw new Error(`File ${name} is forbidden`);
|
|
104
108
|
} else {
|
|
105
109
|
console.log(res);
|
|
106
110
|
throw new Error(`Failed to download file ${name}: ${res.statusText}`);
|
package/src/store/TypesApi.ts
CHANGED
|
@@ -16,7 +16,7 @@ export class TypesApi extends ApiTopic {
|
|
|
16
16
|
* @param options
|
|
17
17
|
* @returns
|
|
18
18
|
*/
|
|
19
|
-
list(payload: ObjectTypeSearchPayload = {}, options?: { layout
|
|
19
|
+
list(payload: ObjectTypeSearchPayload = {}, options?: { layout?: boolean, schema?: boolean }): Promise<ContentObjectTypeItem[]> {
|
|
20
20
|
const limit = payload.limit || 100;
|
|
21
21
|
const offset = payload.offset || 0;
|
|
22
22
|
const query = payload.query || {} as ObjectTypeSearchQuery;
|
|
@@ -26,6 +26,7 @@ export class TypesApi extends ApiTopic {
|
|
|
26
26
|
limit,
|
|
27
27
|
offset,
|
|
28
28
|
layout: options?.layout ? true : false,
|
|
29
|
+
schema: options?.schema ? true : false,
|
|
29
30
|
...query
|
|
30
31
|
}
|
|
31
32
|
});
|