@vertesia/client 0.56.0 → 0.58.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.
Files changed (56) hide show
  1. package/lib/cjs/store/FilesApi.js +29 -19
  2. package/lib/cjs/store/FilesApi.js.map +1 -1
  3. package/lib/cjs/store/ObjectsApi.js +22 -20
  4. package/lib/cjs/store/ObjectsApi.js.map +1 -1
  5. package/lib/cjs/store/WorkflowsApi.js +82 -16
  6. package/lib/cjs/store/WorkflowsApi.js.map +1 -1
  7. package/lib/esm/store/FilesApi.js +29 -19
  8. package/lib/esm/store/FilesApi.js.map +1 -1
  9. package/lib/esm/store/ObjectsApi.js +22 -20
  10. package/lib/esm/store/ObjectsApi.js.map +1 -1
  11. package/lib/esm/store/WorkflowsApi.js +82 -16
  12. package/lib/esm/store/WorkflowsApi.js.map +1 -1
  13. package/lib/tsconfig.tsbuildinfo +1 -1
  14. package/lib/types/AccountApi.d.ts +1 -0
  15. package/lib/types/AccountsApi.d.ts +1 -0
  16. package/lib/types/AnalyticsApi.d.ts +1 -0
  17. package/lib/types/ApiKeysApi.d.ts +1 -0
  18. package/lib/types/CommandsApi.d.ts +1 -0
  19. package/lib/types/EnvironmentsApi.d.ts +1 -0
  20. package/lib/types/IamApi.d.ts +1 -0
  21. package/lib/types/InteractionBase.d.ts +1 -0
  22. package/lib/types/InteractionsApi.d.ts +1 -0
  23. package/lib/types/PluginsApi.d.ts +1 -0
  24. package/lib/types/ProjectsApi.d.ts +1 -0
  25. package/lib/types/PromptsApi.d.ts +1 -0
  26. package/lib/types/RefsApi.d.ts +1 -0
  27. package/lib/types/RunsApi.d.ts +1 -0
  28. package/lib/types/StreamSource.d.ts +1 -0
  29. package/lib/types/TrainingApi.d.ts +1 -0
  30. package/lib/types/UsersApi.d.ts +1 -0
  31. package/lib/types/client.d.ts +1 -0
  32. package/lib/types/execute.d.ts +1 -0
  33. package/lib/types/index.d.ts +1 -0
  34. package/lib/types/nodejs/NodeStreamSource.d.ts +1 -0
  35. package/lib/types/nodejs/index.d.ts +1 -0
  36. package/lib/types/store/AgentsApi.d.ts +1 -0
  37. package/lib/types/store/AnalyzeDocApi.d.ts +1 -0
  38. package/lib/types/store/CollectionsApi.d.ts +1 -0
  39. package/lib/types/store/CommandsApi.d.ts +1 -0
  40. package/lib/types/store/EmbeddingsApi.d.ts +1 -0
  41. package/lib/types/store/FilesApi.d.ts +2 -0
  42. package/lib/types/store/FilesApi.d.ts.map +1 -1
  43. package/lib/types/store/ObjectsApi.d.ts +2 -7
  44. package/lib/types/store/ObjectsApi.d.ts.map +1 -1
  45. package/lib/types/store/TypesApi.d.ts +1 -0
  46. package/lib/types/store/WorkflowsApi.d.ts +1 -0
  47. package/lib/types/store/WorkflowsApi.d.ts.map +1 -1
  48. package/lib/types/store/client.d.ts +1 -0
  49. package/lib/types/store/errors.d.ts +1 -0
  50. package/lib/types/store/index.d.ts +1 -0
  51. package/lib/vertesia-client.js +1 -1
  52. package/lib/vertesia-client.js.map +1 -1
  53. package/package.json +4 -4
  54. package/src/store/FilesApi.ts +83 -55
  55. package/src/store/ObjectsApi.ts +326 -313
  56. package/src/store/WorkflowsApi.ts +91 -17
@@ -1,21 +1,28 @@
1
1
  import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
- import { GetFileUrlPayload, GetFileUrlResponse, GetUploadUrlPayload } from "@vertesia/common";
2
+ import {
3
+ GetFileUrlPayload,
4
+ GetFileUrlResponse,
5
+ GetUploadUrlPayload,
6
+ } from "@vertesia/common";
3
7
  import { StreamSource } from "../StreamSource.js";
4
8
 
5
- export const MEMORIES_PREFIX = 'memories';
9
+ export const MEMORIES_PREFIX = "memories";
6
10
 
7
11
  export function getMemoryFilePath(name: string) {
8
12
  const nameWithExt = name.endsWith(".tar.gz") ? name : name + ".tar.gz";
9
13
  return `${MEMORIES_PREFIX}/${nameWithExt}`;
10
14
  }
11
15
 
12
-
13
16
  export class FilesApi extends ApiTopic {
14
-
15
17
  constructor(parent: ClientBase) {
16
18
  super(parent, "/api/v1/files");
17
19
  }
18
20
 
21
+ async deleteFile(path: string, prefix?: boolean): Promise<void | number> {
22
+ const res = await this.delete(`/${path}`, { query: { prefix } });
23
+ return res.count;
24
+ }
25
+
19
26
  /**
20
27
  * get the metadata of a blob given its URI. Supported URI are:
21
28
  * starting with s3:// and gs://.
@@ -24,17 +31,16 @@ export class FilesApi extends ApiTopic {
24
31
  * @returns
25
32
  */
26
33
  getMetadata(uri: string): Promise<{
27
- name: string,
28
- size: number,
29
- contentType: string,
30
- contentDisposition?:
31
- string,
32
- etag?: string
34
+ name: string;
35
+ size: number;
36
+ contentType: string;
37
+ contentDisposition?: string;
38
+ etag?: string;
33
39
  }> {
34
40
  return this.get("/metadata", {
35
41
  query: {
36
- file: uri
37
- }
42
+ file: uri,
43
+ },
38
44
  });
39
45
  }
40
46
 
@@ -44,21 +50,21 @@ export class FilesApi extends ApiTopic {
44
50
  * @returns
45
51
  */
46
52
  getOrCreateBucket(): Promise<{ bucket: string }> {
47
- return this.post('/bucket');
53
+ return this.post("/bucket");
48
54
  }
49
55
 
50
56
  getUploadUrl(payload: GetUploadUrlPayload): Promise<GetFileUrlResponse> {
51
- return this.post('/upload-url', {
52
- payload
53
- })
57
+ return this.post("/upload-url", {
58
+ payload,
59
+ });
54
60
  }
55
61
 
56
62
  getDownloadUrl(file: string): Promise<GetFileUrlResponse> {
57
- return this.post('/download-url', {
63
+ return this.post("/download-url", {
58
64
  payload: {
59
- file
60
- } satisfies GetFileUrlPayload
61
- })
65
+ file,
66
+ } satisfies GetFileUrlPayload,
67
+ });
62
68
  }
63
69
 
64
70
  /**
@@ -71,24 +77,26 @@ export class FilesApi extends ApiTopic {
71
77
  const { url, path } = await this.getUploadUrl(source);
72
78
 
73
79
  await fetch(url, {
74
- method: 'PUT',
80
+ method: "PUT",
75
81
  body: isStream ? source.stream : source,
76
82
  //@ts-ignore: duplex is not in the types. See https://github.com/node-fetch/node-fetch/issues/1769
77
83
  duplex: isStream ? "half" : undefined,
78
84
  headers: {
79
- 'Content-Type': source.type || 'application/gzip'
80
- }
81
- }).then((res: Response) => {
82
- if (res.ok) {
83
- return res;
84
- } else {
85
- console.log(res);
86
- throw new Error(`Failed to upload file: ${res.statusText}`);
87
- }
88
- }).catch(err => {
89
- console.error('Failed to upload file', err);
90
- throw err;
91
- });
85
+ "Content-Type": source.type || "application/gzip",
86
+ },
87
+ })
88
+ .then((res: Response) => {
89
+ if (res.ok) {
90
+ return res;
91
+ } else {
92
+ console.log(res);
93
+ throw new Error(`Failed to upload file: ${res.statusText}`);
94
+ }
95
+ })
96
+ .catch((err) => {
97
+ console.error("Failed to upload file", err);
98
+ throw err;
99
+ });
92
100
 
93
101
  return path;
94
102
  }
@@ -97,25 +105,31 @@ export class FilesApi extends ApiTopic {
97
105
  const { url } = await this.getDownloadUrl(name);
98
106
 
99
107
  const res = await fetch(url, {
100
- method: 'GET',
101
- }).then((res: Response) => {
102
- if (res.ok) {
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`);
108
- } else {
109
- console.log(res);
110
- throw new Error(`Failed to download file ${name}: ${res.statusText}`);
111
- }
112
- }).catch(err => {
113
- console.error(`Failed to download file ${name}.`, err);
114
- throw err;
115
- });
108
+ method: "GET",
109
+ })
110
+ .then((res: Response) => {
111
+ if (res.ok) {
112
+ return res;
113
+ } else if (res.status === 404) {
114
+ throw new Error(`File ${name} not found`); //TODO: type fetch error better with a fetch error class
115
+ } else if (res.status === 403) {
116
+ throw new Error(`File ${name} is forbidden`);
117
+ } else {
118
+ console.log(res);
119
+ throw new Error(
120
+ `Failed to download file ${name}: ${res.statusText}`,
121
+ );
122
+ }
123
+ })
124
+ .catch((err) => {
125
+ console.error(`Failed to download file ${name}.`, err);
126
+ throw err;
127
+ });
116
128
 
117
129
  if (!res.body) {
118
- throw new Error(`No body in response while downloading memory pack ${name}`);
130
+ throw new Error(
131
+ `No body in response while downloading memory pack ${name}`,
132
+ );
119
133
  }
120
134
 
121
135
  return res.body;
@@ -123,16 +137,30 @@ export class FilesApi extends ApiTopic {
123
137
 
124
138
  async uploadMemoryPack(source: StreamSource | File): Promise<string> {
125
139
  const fileId = getMemoryFilePath(source.name);
126
- const nameWithExt = source.name.endsWith(".tar.gz") ? source.name : source.name + ".tar.gz";
140
+ const nameWithExt = source.name.endsWith(".tar.gz")
141
+ ? source.name
142
+ : source.name + ".tar.gz";
127
143
  if (source instanceof File) {
128
144
  let file = source as File;
129
- return this.uploadFile(new StreamSource(file.stream(), nameWithExt, file.type, fileId));
145
+ return this.uploadFile(
146
+ new StreamSource(file.stream(), nameWithExt, file.type, fileId),
147
+ );
130
148
  } else {
131
- return this.uploadFile(new StreamSource(source.stream, nameWithExt, source.type, fileId));
149
+ return this.uploadFile(
150
+ new StreamSource(
151
+ source.stream,
152
+ nameWithExt,
153
+ source.type,
154
+ fileId,
155
+ ),
156
+ );
132
157
  }
133
158
  }
134
159
 
135
- async downloadMemoryPack(name: string, gunzip: boolean = false): Promise<ReadableStream<Uint8Array>> {
160
+ async downloadMemoryPack(
161
+ name: string,
162
+ gunzip: boolean = false,
163
+ ): Promise<ReadableStream<Uint8Array>> {
136
164
  let stream = await this.downloadFile(getMemoryFilePath(name));
137
165
  if (gunzip) {
138
166
  const ds = new DecompressionStream("gzip");