@vertesia/client 0.57.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.
- package/lib/cjs/store/FilesApi.js +29 -19
- package/lib/cjs/store/FilesApi.js.map +1 -1
- package/lib/cjs/store/ObjectsApi.js +20 -17
- package/lib/cjs/store/ObjectsApi.js.map +1 -1
- package/lib/esm/store/FilesApi.js +29 -19
- package/lib/esm/store/FilesApi.js.map +1 -1
- package/lib/esm/store/ObjectsApi.js +20 -17
- package/lib/esm/store/ObjectsApi.js.map +1 -1
- 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/CommandsApi.d.ts +1 -0
- package/lib/types/EnvironmentsApi.d.ts +1 -0
- package/lib/types/IamApi.d.ts +1 -0
- package/lib/types/InteractionBase.d.ts +1 -0
- package/lib/types/InteractionsApi.d.ts +1 -0
- package/lib/types/PluginsApi.d.ts +1 -0
- package/lib/types/ProjectsApi.d.ts +1 -0
- package/lib/types/PromptsApi.d.ts +1 -0
- package/lib/types/RefsApi.d.ts +1 -0
- package/lib/types/RunsApi.d.ts +1 -0
- 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 +1 -0
- package/lib/types/execute.d.ts +1 -0
- package/lib/types/index.d.ts +1 -0
- 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 +1 -0
- 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 +2 -0
- package/lib/types/store/FilesApi.d.ts.map +1 -1
- package/lib/types/store/ObjectsApi.d.ts +2 -7
- 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 +1 -0
- package/lib/types/store/client.d.ts +1 -0
- package/lib/types/store/errors.d.ts +1 -0
- package/lib/types/store/index.d.ts +1 -0
- package/lib/vertesia-client.js +1 -1
- package/lib/vertesia-client.js.map +1 -1
- package/package.json +4 -4
- package/src/store/FilesApi.ts +83 -55
- package/src/store/ObjectsApi.ts +311 -296
package/src/store/FilesApi.ts
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
|
|
2
|
-
import {
|
|
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 =
|
|
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(
|
|
53
|
+
return this.post("/bucket");
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
getUploadUrl(payload: GetUploadUrlPayload): Promise<GetFileUrlResponse> {
|
|
51
|
-
return this.post(
|
|
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(
|
|
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:
|
|
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
|
-
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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:
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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(
|
|
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")
|
|
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(
|
|
145
|
+
return this.uploadFile(
|
|
146
|
+
new StreamSource(file.stream(), nameWithExt, file.type, fileId),
|
|
147
|
+
);
|
|
130
148
|
} else {
|
|
131
|
-
return this.uploadFile(
|
|
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(
|
|
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");
|