@vertesia/client 0.79.0 → 0.79.2
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/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 +20 -6
- package/lib/cjs/InteractionsApi.js.map +1 -1
- package/lib/cjs/ProjectsApi.js +5 -0
- 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 +105 -38
- package/lib/cjs/client.js.map +1 -1
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/store/CollectionsApi.js +30 -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 +5 -4
- 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.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 +20 -6
- package/lib/esm/InteractionsApi.js.map +1 -1
- package/lib/esm/ProjectsApi.js +5 -0
- 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 +105 -38
- package/lib/esm/client.js.map +1 -1
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/store/CollectionsApi.js +30 -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 +5 -4
- 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.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/InteractionCatalogApi.d.ts +36 -0
- package/lib/types/InteractionCatalogApi.d.ts.map +1 -0
- package/lib/types/InteractionOutput.d.ts +174 -0
- package/lib/types/InteractionOutput.d.ts.map +1 -0
- package/lib/types/InteractionResult.example.d.ts +6 -0
- package/lib/types/InteractionResult.example.d.ts.map +1 -0
- package/lib/types/InteractionsApi.d.ts +9 -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/RunsApi.d.ts +6 -4
- package/lib/types/RunsApi.d.ts.map +1 -1
- package/lib/types/client.d.ts +8 -4
- package/lib/types/client.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/store/CollectionsApi.d.ts +18 -2
- package/lib/types/store/CollectionsApi.d.ts.map +1 -1
- package/lib/types/store/FilesApi.d.ts +3 -2
- package/lib/types/store/FilesApi.d.ts.map +1 -1
- package/lib/types/store/ObjectsApi.d.ts +6 -11
- package/lib/types/store/ObjectsApi.d.ts.map +1 -1
- package/lib/types/store/WorkflowsApi.d.ts +12 -0
- package/lib/types/store/WorkflowsApi.d.ts.map +1 -1
- package/lib/types/store/client.d.ts +1 -0
- package/lib/types/store/client.d.ts.map +1 -1
- package/lib/vertesia-client.js +1 -1
- package/lib/vertesia-client.js.map +1 -1
- package/package.json +4 -4
- package/src/InteractionOutput.test.ts +305 -0
- package/src/InteractionOutput.ts +328 -0
- package/src/InteractionResult.example.ts +72 -0
- package/src/InteractionsApi.ts +18 -9
- package/src/RunsApi.ts +7 -4
- package/src/index.ts +1 -0
- package/src/store/CollectionsApi.ts +24 -0
- package/src/store/TypesApi.ts +1 -1
- package/src/store/WorkflowsApi.ts +5 -2
|
@@ -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
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
|
/**
|
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/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/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(
|