@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.
- package/lib/cjs/store/FilesApi.js +29 -19
- package/lib/cjs/store/FilesApi.js.map +1 -1
- package/lib/cjs/store/ObjectsApi.js +22 -20
- package/lib/cjs/store/ObjectsApi.js.map +1 -1
- package/lib/cjs/store/WorkflowsApi.js +82 -16
- package/lib/cjs/store/WorkflowsApi.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 +22 -20
- package/lib/esm/store/ObjectsApi.js.map +1 -1
- package/lib/esm/store/WorkflowsApi.js +82 -16
- package/lib/esm/store/WorkflowsApi.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/WorkflowsApi.d.ts.map +1 -1
- 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 +326 -313
- package/src/store/WorkflowsApi.ts +91 -17
package/src/store/ObjectsApi.ts
CHANGED
|
@@ -1,162 +1,166 @@
|
|
|
1
1
|
import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
ComplexSearchPayload,
|
|
4
|
+
ComputeObjectFacetPayload,
|
|
5
|
+
ContentObject,
|
|
6
|
+
ContentObjectItem,
|
|
7
|
+
ContentSource,
|
|
8
|
+
CreateContentObjectPayload,
|
|
9
|
+
Embedding,
|
|
10
|
+
ExportPropertiesPayload,
|
|
11
|
+
ExportPropertiesResponse,
|
|
12
|
+
FindPayload,
|
|
13
|
+
GetFileUrlPayload,
|
|
14
|
+
GetFileUrlResponse,
|
|
15
|
+
GetRenditionParams,
|
|
16
|
+
GetRenditionResponse,
|
|
17
|
+
GetUploadUrlPayload,
|
|
18
|
+
ListWorkflowRunsResponse,
|
|
19
|
+
ObjectSearchPayload,
|
|
20
|
+
ObjectSearchQuery,
|
|
21
|
+
SupportedEmbeddingTypes,
|
|
21
22
|
} from "@vertesia/common";
|
|
22
23
|
|
|
23
24
|
import { StreamSource } from "../StreamSource.js";
|
|
24
|
-
import { ZenoClient } from "./client.js";
|
|
25
25
|
import { AnalyzeDocApi } from "./AnalyzeDocApi.js";
|
|
26
|
+
import { ZenoClient } from "./client.js";
|
|
26
27
|
|
|
27
|
-
export interface UploadContentObjectPayload
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
export interface UploadContentObjectPayload
|
|
29
|
+
extends Omit<CreateContentObjectPayload, "content"> {
|
|
30
|
+
content?:
|
|
31
|
+
| StreamSource
|
|
32
|
+
| File
|
|
33
|
+
| {
|
|
34
|
+
// the source URI
|
|
35
|
+
source: string;
|
|
36
|
+
// the original name of the input file if any
|
|
37
|
+
name?: string;
|
|
38
|
+
// the mime type of the content source.
|
|
39
|
+
type?: string;
|
|
40
|
+
|
|
41
|
+
// the target id in the content store
|
|
42
|
+
id?: string;
|
|
43
|
+
};
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export interface ComputeFacetsResponse {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
type?: { _id: string; count: number }[];
|
|
48
|
+
location?: { _id: string; count: number }[];
|
|
49
|
+
status?: { _id: string; count: number }[];
|
|
50
|
+
total?: { count: number }[];
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
export class ObjectsApi extends ApiTopic {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
54
|
+
constructor(parent: ClientBase) {
|
|
55
|
+
super(parent, "/api/v1/objects");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
analyze(objectId: string) {
|
|
59
|
+
return new AnalyzeDocApi(this, objectId);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getUploadUrl(payload: GetUploadUrlPayload): Promise<GetFileUrlResponse> {
|
|
63
|
+
return this.post("/upload-url", {
|
|
64
|
+
payload,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getDownloadUrl(fileUri: string): Promise<{ url: string }> {
|
|
69
|
+
return this.post("/download-url", {
|
|
70
|
+
payload: {
|
|
71
|
+
file: fileUri,
|
|
72
|
+
} satisfies GetFileUrlPayload,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getContentSource(objectId: string): Promise<ContentSource> {
|
|
77
|
+
return this.get(`/${objectId}/content-source`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* List objects with revision filtering options
|
|
82
|
+
*
|
|
83
|
+
* @param payload Search/filter parameters
|
|
84
|
+
* @returns Matching content objects
|
|
85
|
+
*/
|
|
86
|
+
list<T = any>(
|
|
87
|
+
payload: ObjectSearchPayload = {},
|
|
88
|
+
): Promise<ContentObjectItem<T>[]> {
|
|
89
|
+
const limit = payload.limit || 100;
|
|
90
|
+
const offset = payload.offset || 0;
|
|
91
|
+
const query = payload.query || ({} as ObjectSearchQuery);
|
|
92
|
+
|
|
93
|
+
// Add revision filtering options
|
|
94
|
+
const showAllRevisions = payload.all_revisions === true;
|
|
95
|
+
const revisionRoot = payload.from_root;
|
|
96
|
+
|
|
97
|
+
return this.get("/", {
|
|
98
|
+
query: {
|
|
99
|
+
limit,
|
|
100
|
+
offset,
|
|
101
|
+
...query,
|
|
102
|
+
all_revisions: showAllRevisions ? "true" : undefined,
|
|
103
|
+
from_root: revisionRoot,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
computeFacets(
|
|
109
|
+
query: ComputeObjectFacetPayload,
|
|
110
|
+
): Promise<ComputeFacetsResponse> {
|
|
111
|
+
return this.post("/facets", {
|
|
112
|
+
payload: query,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
listFolders(path: string = "/") {
|
|
117
|
+
path; //TODO
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Find object based on query */
|
|
121
|
+
find(payload: FindPayload): Promise<ContentObject[]> {
|
|
122
|
+
return this.post("/find", {
|
|
123
|
+
payload,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Count number of objects matching this query */
|
|
128
|
+
count(payload: FindPayload): Promise<{ count: number }> {
|
|
129
|
+
return this.post("/count", {
|
|
130
|
+
payload,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Search object — different from find because allow full text search */
|
|
135
|
+
search(payload: ComplexSearchPayload): Promise<ContentObjectItem[]> {
|
|
136
|
+
return this.post("/search", {
|
|
137
|
+
payload,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
retrieve(id: string, select?: string): Promise<ContentObject> {
|
|
142
|
+
return this.get(`/${id}`, {
|
|
143
|
+
query: {
|
|
144
|
+
select,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
getObjectText(id: string): Promise<{ text: string }> {
|
|
150
|
+
return this.get(`/${id}/text`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async upload(source: StreamSource | File) {
|
|
154
|
+
const isStream = source instanceof StreamSource;
|
|
155
|
+
// get a signed URL to upload the file a computed mimeType and the file object id.
|
|
156
|
+
const { url, id, mime_type } = await this.getUploadUrl({
|
|
157
|
+
id: isStream ? source.id : undefined,
|
|
158
|
+
name: source.name,
|
|
159
|
+
mime_type: source.type,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// upload the file content to the signed URL
|
|
163
|
+
/*const res = await this.fetch(url, {
|
|
160
164
|
method: 'PUT',
|
|
161
165
|
//@ts-ignore: duplex is not in the types. See https://github.com/node-fetch/node-fetch/issues/1769
|
|
162
166
|
duplex: isStream ? "half" : undefined,
|
|
@@ -173,177 +177,186 @@ export class ObjectsApi extends ApiTopic {
|
|
|
173
177
|
}
|
|
174
178
|
});*/
|
|
175
179
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
} else {
|
|
189
|
-
console.log(res);
|
|
190
|
-
throw new Error(`Failed to upload file: ${res.statusText}`);
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
.catch((err) => {
|
|
194
|
-
console.error("Failed to upload file", err);
|
|
195
|
-
throw err;
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
//Etag need to be unquoted
|
|
199
|
-
//When a server returns an ETag header, it includes the quotes around the actual hash value.
|
|
200
|
-
//This is part of the HTTP specification (RFC 7232), which states that ETags should be
|
|
201
|
-
//enclosed in double quotes.
|
|
202
|
-
const etag = res.headers.get("etag")?.replace(/^"(.*)"$/, "$1");
|
|
203
|
-
|
|
204
|
-
return {
|
|
205
|
-
source: id,
|
|
206
|
-
name: source.name,
|
|
207
|
-
type: mime_type,
|
|
208
|
-
etag,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
async create(
|
|
213
|
-
payload: UploadContentObjectPayload,
|
|
214
|
-
options?: {
|
|
215
|
-
collection_id?: string;
|
|
216
|
-
},
|
|
217
|
-
): Promise<ContentObject> {
|
|
218
|
-
const createPayload: CreateContentObjectPayload = {
|
|
219
|
-
...payload,
|
|
220
|
-
};
|
|
221
|
-
if (payload.content instanceof StreamSource || payload.content instanceof File) {
|
|
222
|
-
createPayload.content = await this.upload(payload.content);
|
|
223
|
-
}
|
|
224
|
-
return await this.post("/", {
|
|
225
|
-
payload: createPayload,
|
|
226
|
-
query: options || {},
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Create an object which holds a reference to an external blob (i.e. not in the project bucket)
|
|
232
|
-
* The uri should starts either with gs:// or s3://. Not other protocols are supported yet.
|
|
233
|
-
* For the s3 blobs you must use a hash with the blob #region. Ex: s3://bucket/path/to/file#us-east-1
|
|
234
|
-
* @param uri
|
|
235
|
-
* @param payload
|
|
236
|
-
* @returns
|
|
237
|
-
*/
|
|
238
|
-
async createFromExternalSource(uri: string, payload: CreateContentObjectPayload = {}): Promise<ContentObject> {
|
|
239
|
-
const metadata = await (this.client as ZenoClient).files.getMetadata(uri);
|
|
240
|
-
const createPayload: CreateContentObjectPayload = {
|
|
241
|
-
...payload,
|
|
242
|
-
content: {
|
|
243
|
-
source: uri,
|
|
244
|
-
name: metadata.name,
|
|
245
|
-
type: metadata.contentType,
|
|
246
|
-
etag: metadata.etag,
|
|
247
|
-
},
|
|
248
|
-
};
|
|
249
|
-
return await this.post("/", {
|
|
250
|
-
payload: createPayload,
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Updates an existing object or creates a new revision
|
|
256
|
-
* Handles file uploads similar to the create method
|
|
257
|
-
*
|
|
258
|
-
* @param id The ID of the object to update
|
|
259
|
-
* @param payload The changes to apply
|
|
260
|
-
* @param options Additional options
|
|
261
|
-
* @param options.createRevision Whether to create a new revision instead of updating in place
|
|
262
|
-
* @param options.revisionLabel Optional label for the revision (e.g., "v1.2")
|
|
263
|
-
* @returns The updated object or newly created revision
|
|
264
|
-
*/
|
|
265
|
-
async update(
|
|
266
|
-
id: string,
|
|
267
|
-
payload: Partial<CreateContentObjectPayload>,
|
|
268
|
-
options?: {
|
|
269
|
-
createRevision?: boolean;
|
|
270
|
-
revisionLabel?: string;
|
|
271
|
-
},
|
|
272
|
-
): Promise<ContentObject> {
|
|
273
|
-
const updatePayload: Partial<CreateContentObjectPayload> = {
|
|
274
|
-
...payload,
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
// Handle file upload if content is provided as File or StreamSource
|
|
278
|
-
if (payload.content instanceof StreamSource || payload.content instanceof File) {
|
|
279
|
-
updatePayload.content = await this.upload(payload.content);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (options?.createRevision) {
|
|
283
|
-
return this.put(`/${id}`, {
|
|
284
|
-
payload: updatePayload,
|
|
285
|
-
headers: {
|
|
286
|
-
"x-create-revision": "true",
|
|
287
|
-
"x-revision-label": options.revisionLabel || "",
|
|
288
|
-
},
|
|
289
|
-
});
|
|
180
|
+
const res = await fetch(url, {
|
|
181
|
+
method: "PUT",
|
|
182
|
+
body: isStream ? source.stream : source,
|
|
183
|
+
//@ts-ignore: duplex is not in the types. See https://github.com/node-fetch/node-fetch/issues/1769
|
|
184
|
+
duplex: isStream ? "half" : undefined,
|
|
185
|
+
headers: {
|
|
186
|
+
"Content-Type": mime_type || "application/octet-stream",
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
.then((res: Response) => {
|
|
190
|
+
if (res.ok) {
|
|
191
|
+
return res;
|
|
290
192
|
} else {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
});
|
|
193
|
+
console.log(res);
|
|
194
|
+
throw new Error(`Failed to upload file: ${res.statusText}`);
|
|
294
195
|
}
|
|
196
|
+
})
|
|
197
|
+
.catch((err) => {
|
|
198
|
+
console.error("Failed to upload file", err);
|
|
199
|
+
throw err;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
//Etag need to be unquoted
|
|
203
|
+
//When a server returns an ETag header, it includes the quotes around the actual hash value.
|
|
204
|
+
//This is part of the HTTP specification (RFC 7232), which states that ETags should be
|
|
205
|
+
//enclosed in double quotes.
|
|
206
|
+
const etag = res.headers.get("etag")?.replace(/^"(.*)"$/, "$1");
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
source: id,
|
|
210
|
+
name: source.name,
|
|
211
|
+
type: mime_type,
|
|
212
|
+
etag,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async create(
|
|
217
|
+
payload: UploadContentObjectPayload,
|
|
218
|
+
options?: {
|
|
219
|
+
collection_id?: string;
|
|
220
|
+
},
|
|
221
|
+
): Promise<ContentObject> {
|
|
222
|
+
const createPayload: CreateContentObjectPayload = {
|
|
223
|
+
...payload,
|
|
224
|
+
};
|
|
225
|
+
if (
|
|
226
|
+
payload.content instanceof StreamSource ||
|
|
227
|
+
payload.content instanceof File
|
|
228
|
+
) {
|
|
229
|
+
createPayload.content = await this.upload(payload.content);
|
|
295
230
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
231
|
+
return await this.post("/", {
|
|
232
|
+
payload: createPayload,
|
|
233
|
+
query: options || {},
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Create an object which holds a reference to an external blob (i.e. not in the project bucket)
|
|
239
|
+
* The uri should starts either with gs:// or s3://. Not other protocols are supported yet.
|
|
240
|
+
* For the s3 blobs you must use a hash with the blob #region. Ex: s3://bucket/path/to/file#us-east-1
|
|
241
|
+
* @param uri
|
|
242
|
+
* @param payload
|
|
243
|
+
* @returns
|
|
244
|
+
*/
|
|
245
|
+
async createFromExternalSource(
|
|
246
|
+
uri: string,
|
|
247
|
+
payload: CreateContentObjectPayload = {},
|
|
248
|
+
): Promise<ContentObject> {
|
|
249
|
+
const metadata = await (this.client as ZenoClient).files.getMetadata(uri);
|
|
250
|
+
const createPayload: CreateContentObjectPayload = {
|
|
251
|
+
...payload,
|
|
252
|
+
content: {
|
|
253
|
+
source: uri,
|
|
254
|
+
name: metadata.name,
|
|
255
|
+
type: metadata.contentType,
|
|
256
|
+
etag: metadata.etag,
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
return await this.post("/", {
|
|
260
|
+
payload: createPayload,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Updates an existing object or creates a new revision
|
|
266
|
+
* Handles file uploads similar to the create method
|
|
267
|
+
*
|
|
268
|
+
* @param id The ID of the object to update
|
|
269
|
+
* @param payload The changes to apply
|
|
270
|
+
* @param options Additional options
|
|
271
|
+
* @param options.createRevision Whether to create a new revision instead of updating in place
|
|
272
|
+
* @param options.revisionLabel Optional label for the revision (e.g., "v1.2")
|
|
273
|
+
* @returns The updated object or newly created revision
|
|
274
|
+
*/
|
|
275
|
+
async update(
|
|
276
|
+
id: string,
|
|
277
|
+
payload: Partial<CreateContentObjectPayload>,
|
|
278
|
+
options?: {
|
|
279
|
+
createRevision?: boolean;
|
|
280
|
+
revisionLabel?: string;
|
|
281
|
+
},
|
|
282
|
+
): Promise<ContentObject> {
|
|
283
|
+
const updatePayload: Partial<CreateContentObjectPayload> = {
|
|
284
|
+
...payload,
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// Handle file upload if content is provided as File or StreamSource
|
|
288
|
+
if (
|
|
289
|
+
payload.content instanceof StreamSource ||
|
|
290
|
+
payload.content instanceof File
|
|
291
|
+
) {
|
|
292
|
+
updatePayload.content = await this.upload(payload.content);
|
|
317
293
|
}
|
|
318
294
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
setEmbedding(
|
|
335
|
-
id: string,
|
|
336
|
-
type: SupportedEmbeddingTypes,
|
|
337
|
-
payload: Embedding,
|
|
338
|
-
): Promise<Record<SupportedEmbeddingTypes, Embedding>> {
|
|
339
|
-
return this.put(`/${id}/embeddings/${type}`, {
|
|
340
|
-
payload,
|
|
341
|
-
});
|
|
295
|
+
if (options?.createRevision) {
|
|
296
|
+
return this.put(`/${id}`, {
|
|
297
|
+
payload: updatePayload,
|
|
298
|
+
headers: {
|
|
299
|
+
"x-create-revision": "true",
|
|
300
|
+
"x-revision-label": options.revisionLabel || "",
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
} else {
|
|
304
|
+
return this.put(`/${id}`, {
|
|
305
|
+
payload: updatePayload,
|
|
306
|
+
});
|
|
342
307
|
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Retrieves all revisions of a content object
|
|
312
|
+
*
|
|
313
|
+
* @param id The ID of any revision in the object's history
|
|
314
|
+
* @returns Array of all revisions sharing the same root
|
|
315
|
+
*/
|
|
316
|
+
getRevisions(id: string): Promise<ContentObjectItem[]> {
|
|
317
|
+
return this.get(`/${id}/revisions`);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
delete(id: string): Promise<{ id: string }> {
|
|
321
|
+
return this.del(`/${id}`);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
listWorkflowRuns(documentId: string): Promise<ListWorkflowRunsResponse> {
|
|
325
|
+
return this.get(`/${documentId}/workflow-runs`);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
listRenditions(documentId: string): Promise<ContentObjectItem[]> {
|
|
329
|
+
return this.get(`/${documentId}/renditions`);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
getRendition(
|
|
333
|
+
documentId: string,
|
|
334
|
+
options: GetRenditionParams,
|
|
335
|
+
): Promise<GetRenditionResponse> {
|
|
336
|
+
const query = {
|
|
337
|
+
max_hw: options.max_hw,
|
|
338
|
+
generate_if_missing: options.generate_if_missing,
|
|
339
|
+
as_signed_url: options.sign_url,
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
return this.get(`/${documentId}/renditions/${options.format}`, { query });
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
exportProperties(
|
|
346
|
+
payload: ExportPropertiesPayload,
|
|
347
|
+
): Promise<ExportPropertiesResponse> {
|
|
348
|
+
return this.post("/export", {
|
|
349
|
+
payload,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
setEmbedding(
|
|
354
|
+
id: string,
|
|
355
|
+
type: SupportedEmbeddingTypes,
|
|
356
|
+
payload: Embedding,
|
|
357
|
+
): Promise<Record<SupportedEmbeddingTypes, Embedding>> {
|
|
358
|
+
return this.put(`/${id}/embeddings/${type}`, {
|
|
359
|
+
payload,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
349
362
|
}
|