@vertesia/client 0.50.1 → 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 +25 -0
- package/lib/cjs/InteractionsApi.js.map +1 -1
- package/lib/cjs/RunsApi.js +34 -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 +56 -0
- package/lib/cjs/store/AnalyzeDocApi.js.map +1 -0
- package/lib/cjs/store/CollectionsApi.js +77 -0
- package/lib/cjs/store/CollectionsApi.js.map +1 -0
- 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/ObjectsApi.js +4 -0
- package/lib/cjs/store/ObjectsApi.js.map +1 -1
- package/lib/cjs/store/TypesApi.js +11 -6
- 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 +4 -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 +26 -1
- package/lib/esm/InteractionsApi.js.map +1 -1
- package/lib/esm/RunsApi.js +34 -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 +52 -0
- package/lib/esm/store/AnalyzeDocApi.js.map +1 -0
- package/lib/esm/store/CollectionsApi.js +73 -0
- package/lib/esm/store/CollectionsApi.js.map +1 -0
- 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/ObjectsApi.js +4 -0
- package/lib/esm/store/ObjectsApi.js.map +1 -1
- package/lib/esm/store/TypesApi.js +11 -6
- 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 +4 -0
- package/lib/esm/store/client.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/AccountApi.d.ts +8 -2
- package/lib/types/AccountApi.d.ts.map +1 -1
- package/lib/types/AccountsApi.d.ts +1 -0
- package/lib/types/AccountsApi.d.ts.map +1 -1
- package/lib/types/InteractionsApi.d.ts +23 -2
- package/lib/types/InteractionsApi.d.ts.map +1 -1
- package/lib/types/ProjectsApi.d.ts +2 -2
- package/lib/types/ProjectsApi.d.ts.map +1 -1
- package/lib/types/RunsApi.d.ts +17 -2
- package/lib/types/RunsApi.d.ts.map +1 -1
- package/lib/types/client.d.ts +20 -4
- package/lib/types/client.d.ts.map +1 -1
- package/lib/types/execute.d.ts +7 -3
- package/lib/types/execute.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -3
- 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/AnalyzeDocApi.d.ts +17 -0
- package/lib/types/store/AnalyzeDocApi.d.ts.map +1 -0
- package/lib/types/store/CollectionsApi.d.ts +37 -0
- package/lib/types/store/CollectionsApi.d.ts.map +1 -0
- package/lib/types/store/CommandsApi.d.ts +5 -8
- 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.map +1 -1
- package/lib/types/store/ObjectsApi.d.ts +2 -0
- package/lib/types/store/ObjectsApi.d.ts.map +1 -1
- package/lib/types/store/TypesApi.d.ts +13 -3
- package/lib/types/store/TypesApi.d.ts.map +1 -1
- package/lib/types/store/WorkflowsApi.d.ts +16 -8
- package/lib/types/store/WorkflowsApi.d.ts.map +1 -1
- package/lib/types/store/client.d.ts +4 -0
- package/lib/types/store/client.d.ts.map +1 -1
- package/package.json +25 -10
- package/src/AccountApi.ts +14 -2
- package/src/AccountsApi.ts +4 -0
- package/src/InteractionsApi.ts +34 -3
- package/src/ProjectsApi.ts +2 -2
- package/src/RunsApi.ts +67 -29
- 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 +61 -0
- package/src/store/CollectionsApi.ts +93 -0
- package/src/store/CommandsApi.ts +6 -33
- package/src/store/EmbeddingsApi.ts +39 -0
- package/src/store/FilesApi.ts +4 -0
- package/src/store/ObjectsApi.ts +5 -0
- package/src/store/TypesApi.ts +12 -8
- package/src/store/WorkflowsApi.ts +127 -25
- package/src/store/client.ts +4 -0
|
@@ -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";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
|
|
2
|
+
import { AdaptedTable, AdaptTablesRequest, DocAnalyzerResultResponse, DocAnalyzeRunStatusResponse, DocImage, DocTableCsv, DocTableJson, ExportTableFormats, GetAdaptedTablesRequestQuery, PdfToRichtextOptions, WorkflowRunStatus } from "@vertesia/common";
|
|
3
|
+
|
|
4
|
+
export class AnalyzeDocApi extends ApiTopic {
|
|
5
|
+
constructor(parent: ClientBase, public objectId: string) {
|
|
6
|
+
super(parent, `/${objectId}/analyze`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async start(payload: PdfToRichtextOptions): Promise<DocAnalyzeRunStatusResponse> {
|
|
10
|
+
return this.post("/", { payload });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async getStatus(): Promise<DocAnalyzeRunStatusResponse> {
|
|
14
|
+
return this.get("/status");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async getResults(): Promise<DocAnalyzerResultResponse> {
|
|
18
|
+
return this.get("/results");
|
|
19
|
+
}
|
|
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
|
+
|
|
42
|
+
async getXml(): Promise<string> {
|
|
43
|
+
return this.get("/xml");
|
|
44
|
+
}
|
|
45
|
+
|
|
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);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async getImages(): Promise<DocImage[]> {
|
|
55
|
+
return this.get("/images");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async getAnnotated(): Promise<{ url: string }> {
|
|
59
|
+
return this.get("/annotated");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
|
|
2
|
+
import { Collection, CollectionItem, CollectionSearchPayload, ComplexSearchPayload, ComputeObjectFacetPayload, ContentObjectItem, ContentObjectStatus, CreateCollectionPayload, DynamicCollection } from "@vertesia/common";
|
|
3
|
+
import { ComputeFacetsResponse } from "./ObjectsApi.js";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export class CollectionsApi extends ApiTopic {
|
|
7
|
+
|
|
8
|
+
constructor(parent: ClientBase) {
|
|
9
|
+
super(parent, "/api/v1/collections");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* List collections
|
|
14
|
+
* @param payload
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
list(payload: CollectionSearchPayload = {}): Promise<CollectionItem[]> {
|
|
18
|
+
return this.get("/", {
|
|
19
|
+
query: {
|
|
20
|
+
limit: 100,
|
|
21
|
+
offset: 0,
|
|
22
|
+
...payload
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Get the collection data without members
|
|
29
|
+
* @param collectionId
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
retrieve(collectionId: string): Promise<Collection | DynamicCollection> {
|
|
33
|
+
return this.get(`/${collectionId}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
create(payload: CreateCollectionPayload): Promise<Collection> {
|
|
37
|
+
return this.post(`/`, {
|
|
38
|
+
payload
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
update(collectionId: string, payload: Partial<CreateCollectionPayload>): Promise<{ id: string }> {
|
|
43
|
+
return this.put(`/${collectionId}`, {
|
|
44
|
+
payload
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
addMembers(collectionId: string, members: string[]): Promise<{ id: string }> {
|
|
49
|
+
return this.post(`/${collectionId}/members`, {
|
|
50
|
+
payload: {
|
|
51
|
+
action: 'add',
|
|
52
|
+
members
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
listMembers(collectionId: string, payload: {
|
|
58
|
+
limit?: number,
|
|
59
|
+
offset?: number,
|
|
60
|
+
status?: ContentObjectStatus,
|
|
61
|
+
type?: string,
|
|
62
|
+
}): Promise<ContentObjectItem[]> {
|
|
63
|
+
return this.get(`/${collectionId}/members`, {
|
|
64
|
+
query: {
|
|
65
|
+
...payload
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
computeFacets(collectionId: string, query: ComputeObjectFacetPayload): Promise<ComputeFacetsResponse> {
|
|
71
|
+
return this.post(`/${collectionId}/facets`, {
|
|
72
|
+
payload: query
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
searchMembers(collectionId: string, payload: ComplexSearchPayload): Promise<ContentObjectItem[]> {
|
|
77
|
+
return this.post(`/${collectionId}/search`, { payload });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
deleteMembers(collectionId: string, members: string[]): Promise<{ id: string }> {
|
|
81
|
+
return this.post(`/${collectionId}/members`, {
|
|
82
|
+
payload: {
|
|
83
|
+
action: 'delete',
|
|
84
|
+
members
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
delete(id: string) {
|
|
90
|
+
return this.del(`/${id}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
}
|
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/ObjectsApi.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ComplexSearchPayload, ComputeObjectFacetPayload, ContentObject, Content
|
|
|
3
3
|
|
|
4
4
|
import { StreamSource } from '../StreamSource.js';
|
|
5
5
|
import { ZenoClient } from './client.js';
|
|
6
|
+
import { AnalyzeDocApi } from './AnalyzeDocApi.js';
|
|
6
7
|
|
|
7
8
|
export interface UploadContentObjectPayload extends Omit<CreateContentObjectPayload, 'content'> {
|
|
8
9
|
content?: StreamSource | File | {
|
|
@@ -33,6 +34,10 @@ export class ObjectsApi extends ApiTopic {
|
|
|
33
34
|
super(parent, "/api/v1/objects");
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
analyze(objectId: string) {
|
|
38
|
+
return new AnalyzeDocApi(this, objectId);
|
|
39
|
+
}
|
|
40
|
+
|
|
36
41
|
getUploadUrl(payload: GetUploadUrlPayload): Promise<GetFileUrlResponse> {
|
|
37
42
|
return this.post('/upload-url', {
|
|
38
43
|
payload
|
package/src/store/TypesApi.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContentObjectType, ContentObjectTypeItem,
|
|
1
|
+
import { ContentObjectType, ContentObjectTypeItem, CreateContentObjectTypePayload, FindPayload, ObjectTypeSearchQuery, ObjectTypeSearchPayload } from "@vertesia/common";
|
|
2
2
|
import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
|
|
3
3
|
|
|
4
4
|
|
|
@@ -8,7 +8,15 @@ export class TypesApi extends ApiTopic {
|
|
|
8
8
|
super(parent, "/api/v1/types");
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The options can be used to include more information in the return objects.
|
|
13
|
+
* You can specify to also include layout information using `layout: true`.
|
|
14
|
+
* By default the layout information is not included.
|
|
15
|
+
* @param payload
|
|
16
|
+
* @param options
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
list(payload: ObjectTypeSearchPayload = {}, options?: { layout?: boolean, schema?: boolean }): Promise<ContentObjectTypeItem[]> {
|
|
12
20
|
const limit = payload.limit || 100;
|
|
13
21
|
const offset = payload.offset || 0;
|
|
14
22
|
const query = payload.query || {} as ObjectTypeSearchQuery;
|
|
@@ -17,6 +25,8 @@ export class TypesApi extends ApiTopic {
|
|
|
17
25
|
query: {
|
|
18
26
|
limit,
|
|
19
27
|
offset,
|
|
28
|
+
layout: options?.layout ? true : false,
|
|
29
|
+
schema: options?.schema ? true : false,
|
|
20
30
|
...query
|
|
21
31
|
}
|
|
22
32
|
});
|
|
@@ -28,12 +38,6 @@ export class TypesApi extends ApiTopic {
|
|
|
28
38
|
});
|
|
29
39
|
}
|
|
30
40
|
|
|
31
|
-
layouts(): Promise<ContentObjectTypeLayout[]> {
|
|
32
|
-
return this.get('/', {
|
|
33
|
-
query: { layout: true }
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
41
|
retrieve(typeId: string): Promise<ContentObjectType> {
|
|
38
42
|
return this.get(`/${typeId}`);
|
|
39
43
|
}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
import { ApiTopic, ClientBase } from
|
|
2
|
-
import {
|
|
1
|
+
import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
|
|
2
|
+
import {
|
|
3
|
+
ActivityCatalog,
|
|
4
|
+
AgentMessage,
|
|
5
|
+
AgentMessageType,
|
|
6
|
+
CreateWorkflowRulePayload,
|
|
7
|
+
DSLWorkflowDefinition,
|
|
8
|
+
DSLWorkflowSpec,
|
|
9
|
+
ExecuteWorkflowPayload,
|
|
10
|
+
ListWorkflowRunsPayload,
|
|
11
|
+
ListWorkflowRunsResponse,
|
|
12
|
+
WorkflowDefinitionRef,
|
|
13
|
+
WorkflowRule,
|
|
14
|
+
WorkflowRuleItem,
|
|
15
|
+
WorkflowRunWithDetails,
|
|
16
|
+
} from "@vertesia/common";
|
|
17
|
+
import { VertesiaClient } from "../client.js";
|
|
18
|
+
import { EventSourceProvider } from "../execute.js";
|
|
3
19
|
|
|
4
20
|
export class WorkflowsApi extends ApiTopic {
|
|
5
|
-
|
|
6
21
|
constructor(parent: ClientBase) {
|
|
7
22
|
super(parent, "/api/v1/workflows");
|
|
8
23
|
}
|
|
@@ -19,53 +34,142 @@ export class WorkflowsApi extends ApiTopic {
|
|
|
19
34
|
return this.post(`/runs`, { payload: payload });
|
|
20
35
|
}
|
|
21
36
|
|
|
37
|
+
sendSignal(workflowId: string, runId: string, signal: string, payload?: any): Promise<{ message: string }> {
|
|
38
|
+
return this.post(`/runs/${workflowId}/${runId}/signal/${signal}`, { payload });
|
|
39
|
+
}
|
|
40
|
+
|
|
22
41
|
getRunDetails(runId: string, workflowId: string): Promise<WorkflowRunWithDetails> {
|
|
23
|
-
return this.get(`/runs/${workflowId}/${runId}
|
|
42
|
+
return this.get(`/runs/${workflowId}/${runId}`);
|
|
24
43
|
}
|
|
25
44
|
|
|
26
45
|
terminate(workflowId: string, runId: string, reason?: string): Promise<{ message: string }> {
|
|
27
|
-
return this.post(`/runs/${workflowId}/${runId}/terminate`, { payload: { reason } });
|
|
46
|
+
return this.post(`/runs/${workflowId}/${runId}/actions/terminate`, { payload: { reason } });
|
|
28
47
|
}
|
|
29
48
|
|
|
30
49
|
cancel(workflowId: string, runId: string, reason?: string): Promise<{ message: string }> {
|
|
31
|
-
return this.post(`/runs/${workflowId}/${runId}/cancel`, { payload: { reason } });
|
|
50
|
+
return this.post(`/runs/${workflowId}/${runId}/actions/cancel`, { payload: { reason } });
|
|
32
51
|
}
|
|
33
52
|
|
|
34
|
-
execute(
|
|
53
|
+
execute(
|
|
54
|
+
name: string,
|
|
55
|
+
payload: ExecuteWorkflowPayload = {},
|
|
56
|
+
): Promise<({ run_id: string; workflow_id: string } | undefined)[]> {
|
|
35
57
|
return this.post(`/execute/${name}`, { payload });
|
|
36
58
|
}
|
|
37
59
|
|
|
60
|
+
postMessage(runId: string, message: string, type?: AgentMessageType, details?: any): Promise<void> {
|
|
61
|
+
if (!runId) {
|
|
62
|
+
throw new Error("runId is required");
|
|
63
|
+
}
|
|
64
|
+
const payload = {
|
|
65
|
+
message,
|
|
66
|
+
type,
|
|
67
|
+
details,
|
|
68
|
+
};
|
|
69
|
+
return this.post(`/runs/${runId}/updates`, { payload });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
retrieveMessages(runId: string, since?: number): Promise<AgentMessage[]> {
|
|
73
|
+
const query = {
|
|
74
|
+
since,
|
|
75
|
+
};
|
|
76
|
+
return this.get(`/runs/${runId}/updates`, { query });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
streamMessages(runId: string, onMessage?: (message: AgentMessage) => void, since?: number): Promise<void> {
|
|
80
|
+
return new Promise(async (resolve, reject) => {
|
|
81
|
+
try {
|
|
82
|
+
const EventSourceImpl = await EventSourceProvider();
|
|
83
|
+
const client = this.client as VertesiaClient;
|
|
84
|
+
const streamUrl = new URL(client.workflows.baseUrl + "/runs/" + runId + "/stream");
|
|
85
|
+
|
|
86
|
+
if (since) {
|
|
87
|
+
streamUrl.searchParams.set("since", since.toString());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const bearerToken = client._auth ? await client._auth() : undefined;
|
|
91
|
+
if (!bearerToken) return reject(new Error("No auth token available"));
|
|
92
|
+
|
|
93
|
+
const token = bearerToken.split(" ")[1];
|
|
94
|
+
streamUrl.searchParams.set("access_token", token);
|
|
95
|
+
|
|
96
|
+
const sse = new EventSourceImpl(streamUrl.href);
|
|
97
|
+
let isClosed = false;
|
|
98
|
+
|
|
99
|
+
sse.onmessage = (ev: MessageEvent) => {
|
|
100
|
+
if (!ev.data || ev.data.startsWith(":")) {
|
|
101
|
+
console.log("Received comment or heartbeat; ignoring it.: ", ev.data);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const message = JSON.parse(ev.data) as AgentMessage;
|
|
107
|
+
if (onMessage) onMessage(message);
|
|
108
|
+
|
|
109
|
+
if (message.type === AgentMessageType.COMPLETE) {
|
|
110
|
+
sse.close();
|
|
111
|
+
isClosed = true;
|
|
112
|
+
resolve();
|
|
113
|
+
}
|
|
114
|
+
} catch (err) {
|
|
115
|
+
console.error("Failed to parse SSE message:", err, ev.data);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
sse.onerror = (err: any) => {
|
|
120
|
+
if (!isClosed) {
|
|
121
|
+
console.error("SSE stream error:", err);
|
|
122
|
+
sse.close();
|
|
123
|
+
reject(err);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// Prevent Node from exiting prematurely
|
|
128
|
+
const interval = setInterval(() => { }, 1000);
|
|
129
|
+
|
|
130
|
+
// Cleanup when stream resolves
|
|
131
|
+
const cleanup = () => {
|
|
132
|
+
clearInterval(interval);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// Attach cleanup
|
|
136
|
+
sse.addEventListener("close", () => {
|
|
137
|
+
isClosed = true;
|
|
138
|
+
cleanup();
|
|
139
|
+
resolve();
|
|
140
|
+
});
|
|
141
|
+
} catch (err) {
|
|
142
|
+
reject(err);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
38
147
|
rules = new WorkflowsRulesApi(this);
|
|
39
148
|
definitions = new WorkflowsDefinitionApi(this);
|
|
40
|
-
|
|
41
149
|
}
|
|
42
150
|
|
|
43
|
-
|
|
44
151
|
export class WorkflowsRulesApi extends ApiTopic {
|
|
45
|
-
|
|
46
152
|
constructor(parent: WorkflowsApi) {
|
|
47
153
|
super(parent, "/rules");
|
|
48
154
|
}
|
|
49
155
|
|
|
50
|
-
|
|
51
156
|
list(): Promise<WorkflowRuleItem[]> {
|
|
52
157
|
return this.get("/");
|
|
53
158
|
}
|
|
54
159
|
|
|
55
|
-
|
|
56
160
|
retrieve(id: string): Promise<WorkflowRule> {
|
|
57
161
|
return this.get(`/${id}`);
|
|
58
162
|
}
|
|
59
163
|
|
|
60
164
|
update(id: string, payload: any): Promise<WorkflowRule> {
|
|
61
165
|
return this.put(`/${id}`, {
|
|
62
|
-
payload
|
|
166
|
+
payload,
|
|
63
167
|
});
|
|
64
168
|
}
|
|
65
169
|
|
|
66
170
|
create(payload: CreateWorkflowRulePayload): Promise<WorkflowRule> {
|
|
67
171
|
return this.post("/", {
|
|
68
|
-
payload
|
|
172
|
+
payload,
|
|
69
173
|
});
|
|
70
174
|
}
|
|
71
175
|
|
|
@@ -73,19 +177,20 @@ export class WorkflowsRulesApi extends ApiTopic {
|
|
|
73
177
|
return this.del(`/${id}`);
|
|
74
178
|
}
|
|
75
179
|
|
|
76
|
-
|
|
77
|
-
|
|
180
|
+
execute(
|
|
181
|
+
id: string,
|
|
182
|
+
objectIds?: string[],
|
|
183
|
+
vars?: Record<string, any>,
|
|
184
|
+
): Promise<({ run_id: string; workflow_id: string } | undefined)[]> {
|
|
78
185
|
const payload: ExecuteWorkflowPayload = {
|
|
79
186
|
objectIds,
|
|
80
|
-
vars
|
|
187
|
+
vars,
|
|
81
188
|
};
|
|
82
189
|
return this.post(`/${id}/execute`, { payload });
|
|
83
190
|
}
|
|
84
|
-
|
|
85
191
|
}
|
|
86
192
|
|
|
87
193
|
export class WorkflowsDefinitionApi extends ApiTopic {
|
|
88
|
-
|
|
89
194
|
//model: DSLWorkflowDefinition;
|
|
90
195
|
|
|
91
196
|
constructor(parent: WorkflowsApi) {
|
|
@@ -96,26 +201,23 @@ export class WorkflowsDefinitionApi extends ApiTopic {
|
|
|
96
201
|
return this.get("/");
|
|
97
202
|
}
|
|
98
203
|
|
|
99
|
-
|
|
100
204
|
retrieve(id: string): Promise<DSLWorkflowDefinition> {
|
|
101
205
|
return this.get(`/${id}`);
|
|
102
206
|
}
|
|
103
207
|
|
|
104
208
|
update(id: string, payload: any): Promise<DSLWorkflowDefinition> {
|
|
105
209
|
return this.put(`/${id}`, {
|
|
106
|
-
payload
|
|
210
|
+
payload,
|
|
107
211
|
});
|
|
108
212
|
}
|
|
109
213
|
|
|
110
214
|
create(payload: DSLWorkflowSpec): Promise<DSLWorkflowDefinition> {
|
|
111
215
|
return this.post("/", {
|
|
112
|
-
payload
|
|
216
|
+
payload,
|
|
113
217
|
});
|
|
114
218
|
}
|
|
115
219
|
|
|
116
220
|
delete(id: string) {
|
|
117
221
|
return this.del(`/${id}`);
|
|
118
222
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
223
|
+
}
|
package/src/store/client.ts
CHANGED
|
@@ -2,11 +2,13 @@ import { AbstractFetchClient, RequestError } from "@vertesia/api-fetch-client";
|
|
|
2
2
|
import { BulkOperationPayload, BulkOperationResult } from "@vertesia/common";
|
|
3
3
|
import { AgentsApi } from "./AgentsApi.js";
|
|
4
4
|
import { CommandsApi } from "./CommandsApi.js";
|
|
5
|
+
import { EmbeddingsApi } from "./EmbeddingsApi.js";
|
|
5
6
|
import { ZenoClientNotFoundError } from "./errors.js";
|
|
6
7
|
import { FilesApi } from "./FilesApi.js";
|
|
7
8
|
import { ObjectsApi } from "./ObjectsApi.js";
|
|
8
9
|
import { TypesApi } from "./TypesApi.js";
|
|
9
10
|
import { WorkflowsApi } from "./WorkflowsApi.js";
|
|
11
|
+
import { CollectionsApi } from "./CollectionsApi.js";
|
|
10
12
|
|
|
11
13
|
export interface ZenoClientProps {
|
|
12
14
|
serverUrl?: string;
|
|
@@ -60,4 +62,6 @@ export class ZenoClient extends AbstractFetchClient<ZenoClient> {
|
|
|
60
62
|
files = new FilesApi(this);
|
|
61
63
|
commands = new CommandsApi(this);
|
|
62
64
|
agents = new AgentsApi(this);
|
|
65
|
+
collections = new CollectionsApi(this);
|
|
66
|
+
embeddings = new EmbeddingsApi(this);
|
|
63
67
|
}
|