@vertesia/client 0.78.0 → 0.79.1
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/AppsApi.js +8 -0
- package/lib/cjs/AppsApi.js.map +1 -1
- package/lib/cjs/InteractionBase.js.map +1 -1
- package/lib/cjs/InteractionCatalogApi.js +64 -0
- package/lib/cjs/InteractionCatalogApi.js.map +1 -0
- package/lib/cjs/InteractionOutput.js +300 -0
- package/lib/cjs/InteractionOutput.js.map +1 -0
- package/lib/cjs/InteractionResult.example.js +57 -0
- package/lib/cjs/InteractionResult.example.js.map +1 -0
- package/lib/cjs/InteractionsApi.js +28 -6
- package/lib/cjs/InteractionsApi.js.map +1 -1
- package/lib/cjs/ProjectsApi.js +2 -1
- package/lib/cjs/ProjectsApi.js.map +1 -1
- package/lib/cjs/RunsApi.js +12 -4
- package/lib/cjs/RunsApi.js.map +1 -1
- package/lib/cjs/client.js +122 -39
- 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 +6 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/store/CollectionsApi.js +21 -0
- package/lib/cjs/store/CollectionsApi.js.map +1 -1
- package/lib/cjs/store/FilesApi.js +9 -8
- package/lib/cjs/store/FilesApi.js.map +1 -1
- package/lib/cjs/store/ObjectsApi.js +36 -18
- package/lib/cjs/store/ObjectsApi.js.map +1 -1
- package/lib/cjs/store/TypesApi.js +1 -1
- package/lib/cjs/store/TypesApi.js.map +1 -1
- package/lib/cjs/store/WorkflowsApi.js +151 -2
- package/lib/cjs/store/WorkflowsApi.js.map +1 -1
- package/lib/cjs/store/client.js +17 -1
- package/lib/cjs/store/client.js.map +1 -1
- package/lib/cjs/store/version.js +6 -0
- package/lib/cjs/store/version.js.map +1 -0
- package/lib/esm/AppsApi.js +8 -0
- package/lib/esm/AppsApi.js.map +1 -1
- package/lib/esm/InteractionBase.js.map +1 -1
- package/lib/esm/InteractionCatalogApi.js +60 -0
- package/lib/esm/InteractionCatalogApi.js.map +1 -0
- package/lib/esm/InteractionOutput.js +293 -0
- package/lib/esm/InteractionOutput.js.map +1 -0
- package/lib/esm/InteractionResult.example.js +55 -0
- package/lib/esm/InteractionResult.example.js.map +1 -0
- package/lib/esm/InteractionsApi.js +29 -7
- package/lib/esm/InteractionsApi.js.map +1 -1
- package/lib/esm/ProjectsApi.js +1 -1
- package/lib/esm/ProjectsApi.js.map +1 -1
- package/lib/esm/RunsApi.js +12 -4
- package/lib/esm/RunsApi.js.map +1 -1
- package/lib/esm/client.js +121 -38
- 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 +3 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/store/CollectionsApi.js +21 -0
- package/lib/esm/store/CollectionsApi.js.map +1 -1
- package/lib/esm/store/FilesApi.js +9 -8
- package/lib/esm/store/FilesApi.js.map +1 -1
- package/lib/esm/store/ObjectsApi.js +36 -18
- package/lib/esm/store/ObjectsApi.js.map +1 -1
- package/lib/esm/store/TypesApi.js +1 -1
- package/lib/esm/store/TypesApi.js.map +1 -1
- package/lib/esm/store/WorkflowsApi.js +151 -2
- package/lib/esm/store/WorkflowsApi.js.map +1 -1
- package/lib/esm/store/client.js +17 -1
- package/lib/esm/store/client.js.map +1 -1
- package/lib/esm/store/version.js +3 -0
- package/lib/esm/store/version.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/AccountApi.d.ts +1 -0
- package/lib/types/AccountsApi.d.ts +1 -0
- package/lib/types/AnalyticsApi.d.ts +1 -0
- package/lib/types/ApiKeysApi.d.ts +1 -0
- package/lib/types/AppsApi.d.ts +8 -1
- package/lib/types/AppsApi.d.ts.map +1 -1
- package/lib/types/CommandsApi.d.ts +1 -0
- package/lib/types/EnvironmentsApi.d.ts +1 -0
- package/lib/types/GroupsApi.d.ts +1 -0
- package/lib/types/IamApi.d.ts +1 -0
- package/lib/types/InteractionBase.d.ts +3 -2
- package/lib/types/InteractionBase.d.ts.map +1 -1
- package/lib/types/InteractionCatalogApi.d.ts +37 -0
- package/lib/types/InteractionCatalogApi.d.ts.map +1 -0
- package/lib/types/InteractionOutput.d.ts +175 -0
- package/lib/types/InteractionOutput.d.ts.map +1 -0
- package/lib/types/InteractionResult.example.d.ts +7 -0
- package/lib/types/InteractionResult.example.d.ts.map +1 -0
- package/lib/types/InteractionsApi.d.ts +16 -6
- package/lib/types/InteractionsApi.d.ts.map +1 -1
- package/lib/types/ProjectsApi.d.ts +2 -1
- package/lib/types/ProjectsApi.d.ts.map +1 -1
- package/lib/types/PromptsApi.d.ts +1 -0
- package/lib/types/RefsApi.d.ts +1 -0
- package/lib/types/RunsApi.d.ts +7 -4
- package/lib/types/RunsApi.d.ts.map +1 -1
- package/lib/types/StreamSource.d.ts +1 -0
- package/lib/types/TrainingApi.d.ts +1 -0
- package/lib/types/UsersApi.d.ts +1 -0
- package/lib/types/client.d.ts +15 -5
- package/lib/types/client.d.ts.map +1 -1
- package/lib/types/execute.d.ts +5 -3
- package/lib/types/execute.d.ts.map +1 -1
- package/lib/types/index.d.ts +6 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/nodejs/NodeStreamSource.d.ts +1 -0
- package/lib/types/nodejs/index.d.ts +1 -0
- package/lib/types/store/AgentsApi.d.ts +1 -0
- package/lib/types/store/AnalyzeDocApi.d.ts +1 -0
- package/lib/types/store/CollectionsApi.d.ts +8 -0
- package/lib/types/store/CollectionsApi.d.ts.map +1 -1
- package/lib/types/store/CommandsApi.d.ts +1 -0
- package/lib/types/store/EmbeddingsApi.d.ts +1 -0
- package/lib/types/store/FilesApi.d.ts +4 -2
- package/lib/types/store/FilesApi.d.ts.map +1 -1
- package/lib/types/store/ObjectsApi.d.ts +13 -15
- package/lib/types/store/ObjectsApi.d.ts.map +1 -1
- package/lib/types/store/TypesApi.d.ts +1 -0
- package/lib/types/store/WorkflowsApi.d.ts +13 -0
- package/lib/types/store/WorkflowsApi.d.ts.map +1 -1
- package/lib/types/store/client.d.ts +8 -1
- package/lib/types/store/client.d.ts.map +1 -1
- package/lib/types/store/errors.d.ts +1 -0
- package/lib/types/store/index.d.ts +1 -0
- package/lib/types/store/version.d.ts +3 -0
- package/lib/types/store/version.d.ts.map +1 -0
- package/lib/vertesia-client.js +1 -1
- package/lib/vertesia-client.js.map +1 -1
- package/package.json +54 -54
- package/src/AppsApi.ts +10 -1
- package/src/InteractionBase.ts +3 -3
- package/src/InteractionOutput.test.ts +305 -0
- package/src/InteractionOutput.ts +328 -0
- package/src/InteractionResult.example.ts +72 -0
- package/src/InteractionsApi.ts +28 -10
- package/src/RunsApi.ts +7 -4
- package/src/client.ts +18 -0
- package/src/execute.ts +11 -5
- package/src/index.ts +1 -0
- package/src/store/CollectionsApi.ts +24 -0
- package/src/store/ObjectsApi.ts +40 -13
- package/src/store/TypesApi.ts +1 -1
- package/src/store/WorkflowsApi.ts +5 -2
- package/src/store/client.ts +18 -1
- package/src/store/version.ts +2 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example usage of InteractionOutput
|
|
3
|
+
* This file demonstrates the Proxy-based approach where the result acts as both
|
|
4
|
+
* an array and has convenience methods.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { CompletionResult } from '@llumiverse/common';
|
|
8
|
+
import { InteractionOutput } from './InteractionOutput.js';
|
|
9
|
+
|
|
10
|
+
// Sample data
|
|
11
|
+
const sampleResults: CompletionResult[] = [
|
|
12
|
+
{ type: 'text', value: 'Hello, ' },
|
|
13
|
+
{ type: 'text', value: 'World!' },
|
|
14
|
+
{ type: 'json', value: { name: 'Alice', age: 30 } },
|
|
15
|
+
{ type: 'json', value: { title: 'Engineer', level: 'Senior' } },
|
|
16
|
+
{ type: 'image', value: 'data:image/png;base64,iVBORw0K...' }
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
// Example 1: Using InteractionOutput.from() (Proxy approach - RECOMMENDED)
|
|
20
|
+
console.log('=== Example 1: Proxy Approach ===');
|
|
21
|
+
interface Person { name: string; age: number; }
|
|
22
|
+
const output = InteractionOutput.from<Person>(sampleResults);
|
|
23
|
+
|
|
24
|
+
// Works as an array
|
|
25
|
+
console.log('Array length:', output.length); // 5
|
|
26
|
+
console.log('First item:', output[0]); // { type: 'text', value: 'Hello, ' }
|
|
27
|
+
console.log('Types:', output.map(r => r.type)); // ['text', 'text', 'json', 'json', 'image']
|
|
28
|
+
|
|
29
|
+
// Has convenience methods
|
|
30
|
+
console.log('All text:', output.text); // 'Hello, World!'
|
|
31
|
+
console.log('First object:', output.object()); // { name: 'Alice', age: 30 } (typed as Person)
|
|
32
|
+
console.log('All objects:', output.objects()); // [{ name: 'Alice', age: 30 }, { title: 'Engineer', level: 'Senior' }]
|
|
33
|
+
console.log('First image:', output.image); // 'data:image/png;base64,iVBORw0K...'
|
|
34
|
+
|
|
35
|
+
// Override type for specific objects
|
|
36
|
+
interface Job { title: string; level: string; }
|
|
37
|
+
console.log('Second object:', output.objectAt<Job>(1)); // { title: 'Engineer', level: 'Senior' } (typed as Job)
|
|
38
|
+
|
|
39
|
+
// Example 2: Using InteractionOutput class directly
|
|
40
|
+
console.log('\n=== Example 2: Class Approach ===');
|
|
41
|
+
const wrapper = new InteractionOutput<Person>(sampleResults);
|
|
42
|
+
|
|
43
|
+
// Access through wrapper properties (no array access)
|
|
44
|
+
console.log('All text:', wrapper.text);
|
|
45
|
+
console.log('Raw results:', wrapper.results); // Original array
|
|
46
|
+
console.log('First object:', wrapper.object());
|
|
47
|
+
|
|
48
|
+
// Example 3: Type safety demonstration
|
|
49
|
+
console.log('\n=== Example 3: Type Safety ===');
|
|
50
|
+
|
|
51
|
+
interface Contract { title: string; parties: string[]; }
|
|
52
|
+
const contractResults: CompletionResult[] = [
|
|
53
|
+
{ type: 'json', value: { title: 'Sales Agreement', parties: ['Alice', 'Bob'] } }
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
const contractOutput = InteractionOutput.from<Contract>(contractResults);
|
|
57
|
+
const contract = contractOutput.object(); // TypeScript knows this is Contract
|
|
58
|
+
console.log('Contract title:', contract.title);
|
|
59
|
+
console.log('Parties:', contract.parties.join(', '));
|
|
60
|
+
|
|
61
|
+
// Example 4: Mixed content
|
|
62
|
+
console.log('\n=== Example 4: Mixed Content ===');
|
|
63
|
+
const mixedResults: CompletionResult[] = [
|
|
64
|
+
{ type: 'text', value: 'Analysis complete. Results: ' },
|
|
65
|
+
{ type: 'json', value: { score: 0.95, confidence: 'high' } },
|
|
66
|
+
{ type: 'text', value: '\nThank you!' }
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
const mixed = InteractionOutput.from(mixedResults);
|
|
70
|
+
console.log('Full text:', mixed.text); // 'Analysis complete. Results: \nThank you!'
|
|
71
|
+
console.log('Analysis:', mixed.object()); // { score: 0.95, confidence: 'high' }
|
|
72
|
+
console.log('Text parts:', mixed.texts); // ['Analysis complete. Results: ', '\nThank you!']
|
package/src/InteractionsApi.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { ApiTopic, ClientBase, ServerError } from "@vertesia/api-fetch-client";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AsyncExecutionPayload, ComputeInteractionFacetPayload, GenerateInteractionPayload, GenerateTestDataPayload, ImprovePromptPayload,
|
|
4
|
+
Interaction, InteractionCreatePayload, InteractionEndpoint, InteractionEndpointQuery, InteractionExecutionPayload, InteractionForkPayload,
|
|
5
|
+
InteractionPublishPayload, InteractionRef, InteractionRefWithSchema, InteractionSearchPayload, InteractionSearchQuery,
|
|
6
|
+
InteractionsExportPayload, InteractionUpdatePayload, RateLimitRequestPayload, RateLimitRequestResponse
|
|
7
|
+
} from "@vertesia/common";
|
|
3
8
|
import { VertesiaClient } from "./client.js";
|
|
4
|
-
import { executeInteraction, executeInteractionAsync, executeInteractionByName } from "./execute.js";
|
|
9
|
+
import { checkRateLimit, executeInteraction, executeInteractionAsync, executeInteractionByName } from "./execute.js";
|
|
10
|
+
import { EnhancedExecutionRun, EnhancedInteractionExecutionResult, enhanceExecutionRun, enhanceInteractionExecutionResult } from "./InteractionOutput.js";
|
|
5
11
|
|
|
6
12
|
export interface ComputeInteractionFacetsResponse {
|
|
7
13
|
tags?: { _id: string, count: number }[];
|
|
@@ -132,15 +138,16 @@ export default class InteractionsApi extends ApiTopic {
|
|
|
132
138
|
* @throws 500 if interaction execution fails
|
|
133
139
|
* @throws 500 if interaction execution times out
|
|
134
140
|
**/
|
|
135
|
-
execute<
|
|
136
|
-
onChunk?: (chunk: string) => void): Promise<
|
|
137
|
-
|
|
141
|
+
async execute<ResultT = any, ParamsT = any>(id: string, payload: InteractionExecutionPayload = {},
|
|
142
|
+
onChunk?: (chunk: string) => void): Promise<EnhancedInteractionExecutionResult<ResultT, ParamsT>> {
|
|
143
|
+
const r = await executeInteraction<ParamsT>(this.client as VertesiaClient, id, payload, onChunk).catch(err => {
|
|
138
144
|
if (err instanceof ServerError && err.payload?.id) {
|
|
139
145
|
throw err.updateDetails({ run_id: err.payload.id });
|
|
140
146
|
} else {
|
|
141
147
|
throw err;
|
|
142
148
|
}
|
|
143
149
|
});
|
|
150
|
+
return enhanceInteractionExecutionResult<ResultT, ParamsT>(r);
|
|
144
151
|
}
|
|
145
152
|
|
|
146
153
|
/**
|
|
@@ -158,15 +165,16 @@ export default class InteractionsApi extends ApiTopic {
|
|
|
158
165
|
* @param onChunk
|
|
159
166
|
* @returns
|
|
160
167
|
*/
|
|
161
|
-
executeByName<
|
|
162
|
-
onChunk?: (chunk: string) => void): Promise<
|
|
163
|
-
|
|
168
|
+
async executeByName<ResultT = any, ParamsT = any>(nameWithTag: string, payload: InteractionExecutionPayload = {},
|
|
169
|
+
onChunk?: (chunk: string) => void): Promise<EnhancedInteractionExecutionResult<ResultT, ParamsT>> {
|
|
170
|
+
const r = await executeInteractionByName<ParamsT>(this.client as VertesiaClient, nameWithTag, payload, onChunk).catch(err => {
|
|
164
171
|
if (err instanceof ServerError && err.payload?.id) {
|
|
165
172
|
throw err.updateDetails({ run_id: err.payload.id });
|
|
166
173
|
} else {
|
|
167
174
|
throw err;
|
|
168
175
|
}
|
|
169
176
|
});
|
|
177
|
+
return enhanceInteractionExecutionResult<ResultT, ParamsT>(r);
|
|
170
178
|
}
|
|
171
179
|
|
|
172
180
|
/**
|
|
@@ -214,10 +222,11 @@ export default class InteractionsApi extends ApiTopic {
|
|
|
214
222
|
/**
|
|
215
223
|
* Suggest Improvement for a prompt
|
|
216
224
|
*/
|
|
217
|
-
suggestImprovements(id: string, payload: ImprovePromptPayload): Promise<
|
|
218
|
-
|
|
225
|
+
async suggestImprovements<ResultT = any, ParamsT = any>(id: string, payload: ImprovePromptPayload): Promise<EnhancedExecutionRun<ResultT, ParamsT>> {
|
|
226
|
+
const r = await this.post(`${id}/suggest-prompt-improvements`, {
|
|
219
227
|
payload
|
|
220
228
|
});
|
|
229
|
+
return enhanceExecutionRun<ResultT, ParamsT>(r);
|
|
221
230
|
}
|
|
222
231
|
|
|
223
232
|
/**
|
|
@@ -238,4 +247,13 @@ export default class InteractionsApi extends ApiTopic {
|
|
|
238
247
|
return this.get(`/${id}/forks`);
|
|
239
248
|
}
|
|
240
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Request a time slot to execute an interaction with a given environment / model
|
|
252
|
+
* @param payload RateLimitRequestPayload
|
|
253
|
+
* @returns RateLimitRequestResponse with delay_ms
|
|
254
|
+
*/
|
|
255
|
+
requestSlot(payload: RateLimitRequestPayload): Promise<RateLimitRequestResponse> {
|
|
256
|
+
return checkRateLimit(this.client as VertesiaClient, payload);
|
|
257
|
+
}
|
|
258
|
+
|
|
241
259
|
}
|
package/src/RunsApi.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from "@vertesia/common";
|
|
15
15
|
import { VertesiaClient } from "./client.js";
|
|
16
16
|
import type { ExecutionResponse } from "@llumiverse/common";
|
|
17
|
+
import { EnhancedExecutionRun, enhanceExecutionRun } from "./InteractionOutput.js";
|
|
17
18
|
|
|
18
19
|
export interface FilterOption {
|
|
19
20
|
id: string;
|
|
@@ -63,8 +64,9 @@ export class RunsApi extends ApiTopic {
|
|
|
63
64
|
* @param id
|
|
64
65
|
* @returns InteractionResult
|
|
65
66
|
**/
|
|
66
|
-
retrieve<
|
|
67
|
-
|
|
67
|
+
async retrieve<ResultT = any, ParamsT = any>(id: string): Promise<EnhancedExecutionRun<ResultT, ParamsT>> {
|
|
68
|
+
const r = await this.get("/" + id);
|
|
69
|
+
return enhanceExecutionRun<ResultT, ParamsT>(r);
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
/**
|
|
@@ -78,7 +80,7 @@ export class RunsApi extends ApiTopic {
|
|
|
78
80
|
return this.get(`/filter-options/${field}`, { query });
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
create(payload: RunCreatePayload): Promise<
|
|
83
|
+
async create<ResultT = any, ParamsT = any>(payload: RunCreatePayload): Promise<EnhancedExecutionRun<ResultT, ParamsT>> {
|
|
82
84
|
const sessionTags = (this.client as VertesiaClient).sessionTags;
|
|
83
85
|
if (sessionTags) {
|
|
84
86
|
let tags = Array.isArray(sessionTags) ? sessionTags : [sessionTags];
|
|
@@ -89,9 +91,10 @@ export class RunsApi extends ApiTopic {
|
|
|
89
91
|
}
|
|
90
92
|
payload = { ...payload, tags };
|
|
91
93
|
}
|
|
92
|
-
|
|
94
|
+
const r = await this.post("/", {
|
|
93
95
|
payload,
|
|
94
96
|
});
|
|
97
|
+
return enhanceExecutionRun<ResultT, ParamsT>(r);
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
/**
|
package/src/client.ts
CHANGED
|
@@ -16,6 +16,8 @@ import { RunsApi } from "./RunsApi.js";
|
|
|
16
16
|
import { ZenoClient } from "./store/client.js";
|
|
17
17
|
import TrainingApi from "./TrainingApi.js";
|
|
18
18
|
import UsersApi from "./UsersApi.js";
|
|
19
|
+
import { VERSION, VERSION_HEADER } from "./store/version.js";
|
|
20
|
+
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* 1 min threshold constant in ms
|
|
@@ -130,6 +132,15 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
130
132
|
this.sessionTags = opts.sessionTags;
|
|
131
133
|
}
|
|
132
134
|
|
|
135
|
+
withApiVersion(version: string | number | null) {
|
|
136
|
+
if (!version) {
|
|
137
|
+
delete this.headers[VERSION_HEADER];
|
|
138
|
+
} else {
|
|
139
|
+
this.headers[VERSION_HEADER] = String(version);
|
|
140
|
+
}
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
|
|
133
144
|
/**
|
|
134
145
|
* Overwrite to keep store and composable clients synchronized on the auth callback
|
|
135
146
|
* @param authCb
|
|
@@ -227,6 +238,13 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
227
238
|
return this.get('/auth/token', { query: query, headers: { "authorization": undefined } as any });
|
|
228
239
|
}
|
|
229
240
|
|
|
241
|
+
get initialHeaders() {
|
|
242
|
+
return {
|
|
243
|
+
...super.initialHeaders,
|
|
244
|
+
[VERSION_HEADER]: VERSION
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
230
248
|
projects = new ProjectsApi(this);
|
|
231
249
|
environments = new EnvironmentsApi(this);
|
|
232
250
|
interactions = new InteractionsApi(this);
|
package/src/execute.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsyncExecutionPayload, ExecutionRunStatus, InteractionExecutionPayload, InteractionExecutionResult, NamedInteractionExecutionPayload } from '@vertesia/common';
|
|
1
|
+
import { AsyncExecutionPayload, ExecutionRunStatus, InteractionExecutionPayload, InteractionExecutionResult, NamedInteractionExecutionPayload, RateLimitRequestPayload, RateLimitRequestResponse } from '@vertesia/common';
|
|
2
2
|
import { VertesiaClient } from './client.js';
|
|
3
3
|
|
|
4
4
|
export async function EventSourceProvider(): Promise<typeof EventSource> {
|
|
@@ -19,10 +19,10 @@ export async function EventSourceProvider(): Promise<typeof EventSource> {
|
|
|
19
19
|
* @param payload InteractionExecutionPayload
|
|
20
20
|
* @param onChunk callback to be called when the next chunk of the response is available
|
|
21
21
|
*/
|
|
22
|
-
export async function executeInteraction<P = any
|
|
22
|
+
export async function executeInteraction<P = any>(client: VertesiaClient,
|
|
23
23
|
interactionId: string,
|
|
24
24
|
payload: InteractionExecutionPayload = {},
|
|
25
|
-
onChunk?: (chunk: string) => void): Promise<InteractionExecutionResult<P
|
|
25
|
+
onChunk?: (chunk: string) => void): Promise<InteractionExecutionResult<P>> {
|
|
26
26
|
const stream = !!onChunk;
|
|
27
27
|
const response = await client.runs.create({
|
|
28
28
|
...payload, interaction: interactionId, stream
|
|
@@ -52,10 +52,10 @@ export async function executeInteraction<P = any, R = any>(client: VertesiaClien
|
|
|
52
52
|
* @param onChunk
|
|
53
53
|
* @returns
|
|
54
54
|
*/
|
|
55
|
-
export async function executeInteractionByName<P = any
|
|
55
|
+
export async function executeInteractionByName<P = any>(client: VertesiaClient,
|
|
56
56
|
interaction: string,
|
|
57
57
|
payload: InteractionExecutionPayload = {},
|
|
58
|
-
onChunk?: (chunk: string) => void): Promise<InteractionExecutionResult<P
|
|
58
|
+
onChunk?: (chunk: string) => void): Promise<InteractionExecutionResult<P>> {
|
|
59
59
|
const stream = !!onChunk;
|
|
60
60
|
const response = await client.post('/api/v1/execute', {
|
|
61
61
|
payload: {
|
|
@@ -117,4 +117,10 @@ export async function executeInteractionAsync(client: VertesiaClient, payload: A
|
|
|
117
117
|
return await client.post('/api/v1/execute/async', {
|
|
118
118
|
payload,
|
|
119
119
|
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export async function checkRateLimit(client: VertesiaClient, payload: RateLimitRequestPayload): Promise<RateLimitRequestResponse> {
|
|
123
|
+
return await client.post('/api/v1/execute/rate-limit/request', {
|
|
124
|
+
payload
|
|
125
|
+
});
|
|
120
126
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './client.js';
|
|
2
2
|
export * from './InteractionBase.js';
|
|
3
|
+
export * from './InteractionOutput.js';
|
|
3
4
|
export type { AsyncExecutionResult, ComputeInteractionFacetsResponse } from './InteractionsApi.js';
|
|
4
5
|
export type { ComputePromptFacetsResponse, ListInteractionsResponse } from './PromptsApi.js';
|
|
5
6
|
export type { ComputeRunFacetsResponse, FilterOption } from './RunsApi.js';
|
|
@@ -91,6 +91,30 @@ export class CollectionsApi extends ApiTopic {
|
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
addChildren(collectionId: string, children: string[]): Promise<{ count: number }> {
|
|
95
|
+
return this.post(`/${collectionId}/children`, {
|
|
96
|
+
payload: {
|
|
97
|
+
action: 'add',
|
|
98
|
+
children
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
deleteChildren(collectionId: string, children: string[]): Promise<{ count: number }> {
|
|
104
|
+
return this.post(`/${collectionId}/children`, {
|
|
105
|
+
payload: {
|
|
106
|
+
action: 'delete',
|
|
107
|
+
children
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
searchChildren(collectionId: string, query: ComplexCollectionSearchQuery = {}): Promise<CollectionItem[]> {
|
|
113
|
+
return this.post(`/${collectionId}/children/search`, {
|
|
114
|
+
payload: query
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
94
118
|
delete(id: string) {
|
|
95
119
|
return this.del(`/${id}`);
|
|
96
120
|
}
|
package/src/store/ObjectsApi.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
|
|
2
2
|
import {
|
|
3
|
+
ContentObjectApiHeaders,
|
|
3
4
|
ComplexSearchPayload,
|
|
4
5
|
ComputeObjectFacetPayload,
|
|
5
6
|
ContentObject,
|
|
@@ -48,7 +49,7 @@ export interface ComputeFacetsResponse {
|
|
|
48
49
|
type?: { _id: string; count: number }[];
|
|
49
50
|
location?: { _id: string; count: number }[];
|
|
50
51
|
status?: { _id: string; count: number }[];
|
|
51
|
-
total?:
|
|
52
|
+
total?: number;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
export interface SearchResponse {
|
|
@@ -231,9 +232,18 @@ export class ObjectsApi extends ApiTopic {
|
|
|
231
232
|
) {
|
|
232
233
|
createPayload.content = await this.upload(payload.content);
|
|
233
234
|
}
|
|
235
|
+
|
|
236
|
+
const headers: Record<string, string> = {};
|
|
237
|
+
if (options?.processing_priority) {
|
|
238
|
+
headers[ContentObjectApiHeaders.PROCESSING_PRIORITY] = options.processing_priority;
|
|
239
|
+
}
|
|
240
|
+
if (options?.collection_id) {
|
|
241
|
+
headers[ContentObjectApiHeaders.COLLECTION_ID] = options.collection_id;
|
|
242
|
+
}
|
|
243
|
+
|
|
234
244
|
return await this.post("/", {
|
|
235
245
|
payload: createPayload,
|
|
236
|
-
|
|
246
|
+
headers: headers,
|
|
237
247
|
});
|
|
238
248
|
}
|
|
239
249
|
|
|
@@ -243,11 +253,16 @@ export class ObjectsApi extends ApiTopic {
|
|
|
243
253
|
* For the s3 blobs you must use a hash with the blob #region. Ex: s3://bucket/path/to/file#us-east-1
|
|
244
254
|
* @param uri
|
|
245
255
|
* @param payload
|
|
256
|
+
* @param options
|
|
246
257
|
* @returns
|
|
247
258
|
*/
|
|
248
259
|
async createFromExternalSource(
|
|
249
260
|
uri: string,
|
|
250
261
|
payload: CreateContentObjectPayload = {},
|
|
262
|
+
options?: {
|
|
263
|
+
collection_id?: string;
|
|
264
|
+
processing_priority?: ContentObjectProcessingPriority;
|
|
265
|
+
},
|
|
251
266
|
): Promise<ContentObject> {
|
|
252
267
|
const metadata = await (this.client as ZenoClient).files.getMetadata(
|
|
253
268
|
uri,
|
|
@@ -261,8 +276,18 @@ export class ObjectsApi extends ApiTopic {
|
|
|
261
276
|
etag: metadata.etag,
|
|
262
277
|
},
|
|
263
278
|
};
|
|
279
|
+
|
|
280
|
+
const headers: Record<string, string> = {};
|
|
281
|
+
if (options?.processing_priority) {
|
|
282
|
+
headers[ContentObjectApiHeaders.PROCESSING_PRIORITY] = options.processing_priority;
|
|
283
|
+
}
|
|
284
|
+
if (options?.collection_id) {
|
|
285
|
+
headers[ContentObjectApiHeaders.COLLECTION_ID] = options.collection_id;
|
|
286
|
+
}
|
|
287
|
+
|
|
264
288
|
return await this.post("/", {
|
|
265
289
|
payload: createPayload,
|
|
290
|
+
headers: headers,
|
|
266
291
|
});
|
|
267
292
|
}
|
|
268
293
|
|
|
@@ -298,19 +323,21 @@ export class ObjectsApi extends ApiTopic {
|
|
|
298
323
|
updatePayload.content = await this.upload(payload.content);
|
|
299
324
|
}
|
|
300
325
|
|
|
326
|
+
const headers: Record<string, string> = {};
|
|
327
|
+
if (options?.processing_priority) {
|
|
328
|
+
headers[ContentObjectApiHeaders.PROCESSING_PRIORITY] = options.processing_priority;
|
|
329
|
+
}
|
|
301
330
|
if (options?.createRevision) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
headers
|
|
305
|
-
|
|
306
|
-
"x-revision-label": options.revisionLabel || "",
|
|
307
|
-
},
|
|
308
|
-
});
|
|
309
|
-
} else {
|
|
310
|
-
return this.put(`/${id}`, {
|
|
311
|
-
payload: updatePayload,
|
|
312
|
-
});
|
|
331
|
+
headers[ContentObjectApiHeaders.CREATE_REVISION] = "true";
|
|
332
|
+
if (options.revisionLabel) {
|
|
333
|
+
headers[ContentObjectApiHeaders.REVISION_LABEL] = options.revisionLabel;
|
|
334
|
+
}
|
|
313
335
|
}
|
|
336
|
+
|
|
337
|
+
return this.put(`/${id}`, {
|
|
338
|
+
payload: updatePayload,
|
|
339
|
+
headers,
|
|
340
|
+
});
|
|
314
341
|
}
|
|
315
342
|
|
|
316
343
|
/**
|
package/src/store/TypesApi.ts
CHANGED
|
@@ -17,7 +17,7 @@ export class TypesApi extends ApiTopic {
|
|
|
17
17
|
* @returns
|
|
18
18
|
*/
|
|
19
19
|
list(payload: ObjectTypeSearchPayload = {}, options?: { layout?: boolean, schema?: boolean }): Promise<ContentObjectTypeItem[]> {
|
|
20
|
-
const limit = payload.limit ||
|
|
20
|
+
const limit = payload.limit || 2000;
|
|
21
21
|
const offset = payload.offset || 0;
|
|
22
22
|
const query = payload.query || {} as ObjectTypeSearchQuery;
|
|
23
23
|
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
ListWorkflowInteractionsResponse,
|
|
11
11
|
ListWorkflowRunsPayload,
|
|
12
12
|
ListWorkflowRunsResponse,
|
|
13
|
+
WorkflowActionPayload,
|
|
13
14
|
WorkflowDefinitionRef,
|
|
14
15
|
WorkflowRule,
|
|
15
16
|
WorkflowRuleItem,
|
|
@@ -56,11 +57,13 @@ export class WorkflowsApi extends ApiTopic {
|
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
terminate(workflowId: string, runId: string, reason?: string): Promise<{ message: string }> {
|
|
59
|
-
|
|
60
|
+
const payload: WorkflowActionPayload = { reason };
|
|
61
|
+
return this.post(`/runs/${workflowId}/${runId}/actions/terminate`, { payload });
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
cancel(workflowId: string, runId: string, reason?: string): Promise<{ message: string }> {
|
|
63
|
-
|
|
65
|
+
const payload: WorkflowActionPayload = { reason };
|
|
66
|
+
return this.post(`/runs/${workflowId}/${runId}/actions/cancel`, { payload });
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
execute(
|
package/src/store/client.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { AbstractFetchClient, RequestError } from "@vertesia/api-fetch-client";
|
|
2
2
|
import { BulkOperationPayload, BulkOperationResult } from "@vertesia/common";
|
|
3
3
|
import { AgentsApi } from "./AgentsApi.js";
|
|
4
|
+
import { CollectionsApi } from "./CollectionsApi.js";
|
|
4
5
|
import { CommandsApi } from "./CommandsApi.js";
|
|
5
6
|
import { EmbeddingsApi } from "./EmbeddingsApi.js";
|
|
6
7
|
import { ZenoClientNotFoundError } from "./errors.js";
|
|
7
8
|
import { FilesApi } from "./FilesApi.js";
|
|
8
9
|
import { ObjectsApi } from "./ObjectsApi.js";
|
|
9
10
|
import { TypesApi } from "./TypesApi.js";
|
|
11
|
+
import { VERSION, VERSION_HEADER } from "./version.js";
|
|
10
12
|
import { WorkflowsApi } from "./WorkflowsApi.js";
|
|
11
|
-
import { CollectionsApi } from "./CollectionsApi.js";
|
|
12
13
|
|
|
13
14
|
export interface ZenoClientProps {
|
|
14
15
|
serverUrl?: string;
|
|
@@ -44,6 +45,15 @@ export class ZenoClient extends AbstractFetchClient<ZenoClient> {
|
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
withApiVersion(version: string | number | null) {
|
|
49
|
+
if (!version) {
|
|
50
|
+
delete this.headers[VERSION_HEADER];
|
|
51
|
+
} else {
|
|
52
|
+
this.headers[VERSION_HEADER] = String(version);
|
|
53
|
+
}
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
|
|
47
57
|
withApiKey(apiKey: string | null) {
|
|
48
58
|
return this.withAuthCallback(
|
|
49
59
|
apiKey ? () => Promise.resolve(`Bearer ${apiKey}`) : undefined
|
|
@@ -56,6 +66,13 @@ export class ZenoClient extends AbstractFetchClient<ZenoClient> {
|
|
|
56
66
|
});
|
|
57
67
|
}
|
|
58
68
|
|
|
69
|
+
get initialHeaders() {
|
|
70
|
+
return {
|
|
71
|
+
...super.initialHeaders,
|
|
72
|
+
[VERSION_HEADER]: VERSION
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
59
76
|
objects = new ObjectsApi(this);
|
|
60
77
|
types = new TypesApi(this);
|
|
61
78
|
workflows = new WorkflowsApi(this);
|