@langchain/google-common 0.0.27 → 0.1.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/dist/auth.cjs +26 -5
- package/dist/auth.d.ts +3 -2
- package/dist/auth.js +26 -5
- package/dist/chat_models.cjs +11 -10
- package/dist/chat_models.d.ts +4 -4
- package/dist/chat_models.js +12 -11
- package/dist/connection.cjs +34 -7
- package/dist/connection.d.ts +14 -8
- package/dist/connection.js +32 -6
- package/dist/embeddings.cjs +4 -2
- package/dist/embeddings.js +4 -2
- package/dist/experimental/media.cjs +494 -0
- package/dist/experimental/media.d.ts +210 -0
- package/dist/experimental/media.js +478 -0
- package/dist/experimental/utils/media_core.cjs +524 -0
- package/dist/experimental/utils/media_core.d.ts +209 -0
- package/dist/experimental/utils/media_core.js +514 -0
- package/dist/llms.cjs +10 -5
- package/dist/llms.d.ts +4 -1
- package/dist/llms.js +11 -6
- package/dist/types.d.ts +8 -1
- package/dist/utils/gemini.cjs +491 -491
- package/dist/utils/gemini.d.ts +15 -50
- package/dist/utils/gemini.js +489 -465
- package/experimental/media.cjs +1 -0
- package/experimental/media.d.cts +1 -0
- package/experimental/media.d.ts +1 -0
- package/experimental/media.js +1 -0
- package/experimental/utils/media_core.cjs +1 -0
- package/experimental/utils/media_core.d.cts +1 -0
- package/experimental/utils/media_core.d.ts +1 -0
- package/experimental/utils/media_core.js +1 -0
- package/package.json +32 -3
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlobStoreAIStudioFileBase = exports.AIStudioFileDownloadConnection = exports.AIStudioFileUploadConnection = exports.AIStudioMediaBlob = exports.BlobStoreGoogleCloudStorageBase = exports.GoogleCloudStorageRawConnection = exports.GoogleCloudStorageDownloadConnection = exports.GoogleCloudStorageUploadConnection = exports.GoogleCloudStorageUri = exports.BlobStoreGoogle = exports.GoogleDownloadRawConnection = exports.GoogleDownloadConnection = exports.GoogleMultipartUploadConnection = void 0;
|
|
4
|
+
const async_caller_1 = require("@langchain/core/utils/async_caller");
|
|
5
|
+
const env_1 = require("@langchain/core/utils/env");
|
|
6
|
+
const media_core_js_1 = require("./utils/media_core.cjs");
|
|
7
|
+
const connection_js_1 = require("../connection.cjs");
|
|
8
|
+
const auth_js_1 = require("../auth.cjs");
|
|
9
|
+
class GoogleMultipartUploadConnection extends connection_js_1.GoogleHostConnection {
|
|
10
|
+
constructor(fields, caller, client) {
|
|
11
|
+
super(fields, caller, client);
|
|
12
|
+
}
|
|
13
|
+
async _body(separator, data, metadata) {
|
|
14
|
+
const contentType = data.mimetype;
|
|
15
|
+
const { encoded, encoding } = await data.encode();
|
|
16
|
+
const body = [
|
|
17
|
+
`--${separator}`,
|
|
18
|
+
"Content-Type: application/json; charset=UTF-8",
|
|
19
|
+
"",
|
|
20
|
+
JSON.stringify(metadata),
|
|
21
|
+
"",
|
|
22
|
+
`--${separator}`,
|
|
23
|
+
`Content-Type: ${contentType}`,
|
|
24
|
+
`Content-Transfer-Encoding: ${encoding}`,
|
|
25
|
+
"",
|
|
26
|
+
encoded,
|
|
27
|
+
`--${separator}--`,
|
|
28
|
+
];
|
|
29
|
+
return body.join("\n");
|
|
30
|
+
}
|
|
31
|
+
async request(data, metadata, options) {
|
|
32
|
+
const separator = `separator-${Date.now()}`;
|
|
33
|
+
const body = await this._body(separator, data, metadata);
|
|
34
|
+
const requestHeaders = {
|
|
35
|
+
"Content-Type": `multipart/related; boundary=${separator}`,
|
|
36
|
+
"X-Goog-Upload-Protocol": "multipart",
|
|
37
|
+
};
|
|
38
|
+
const response = this._request(body, options, requestHeaders);
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.GoogleMultipartUploadConnection = GoogleMultipartUploadConnection;
|
|
43
|
+
class GoogleDownloadConnection extends connection_js_1.GoogleHostConnection {
|
|
44
|
+
async request(options) {
|
|
45
|
+
return this._request(undefined, options);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.GoogleDownloadConnection = GoogleDownloadConnection;
|
|
49
|
+
class GoogleDownloadRawConnection extends connection_js_1.GoogleRawConnection {
|
|
50
|
+
buildMethod() {
|
|
51
|
+
return "GET";
|
|
52
|
+
}
|
|
53
|
+
async request(options) {
|
|
54
|
+
return this._request(undefined, options);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.GoogleDownloadRawConnection = GoogleDownloadRawConnection;
|
|
58
|
+
class BlobStoreGoogle extends media_core_js_1.BlobStore {
|
|
59
|
+
constructor(fields) {
|
|
60
|
+
super(fields);
|
|
61
|
+
Object.defineProperty(this, "caller", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
writable: true,
|
|
65
|
+
value: void 0
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(this, "client", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
configurable: true,
|
|
70
|
+
writable: true,
|
|
71
|
+
value: void 0
|
|
72
|
+
});
|
|
73
|
+
this.caller = new async_caller_1.AsyncCaller(fields ?? {});
|
|
74
|
+
this.client = this.buildClient(fields);
|
|
75
|
+
}
|
|
76
|
+
async _set(keyValuePair) {
|
|
77
|
+
const [, blob] = keyValuePair;
|
|
78
|
+
const setMetadata = this.buildSetMetadata(keyValuePair);
|
|
79
|
+
const metadata = setMetadata;
|
|
80
|
+
const options = {};
|
|
81
|
+
const connection = this.buildSetConnection(keyValuePair);
|
|
82
|
+
const response = await connection.request(blob, metadata, options);
|
|
83
|
+
return response;
|
|
84
|
+
}
|
|
85
|
+
async mset(keyValuePairs) {
|
|
86
|
+
const ret = keyValuePairs.map((keyValue) => this._set(keyValue));
|
|
87
|
+
await Promise.all(ret);
|
|
88
|
+
}
|
|
89
|
+
async _getMetadata(key) {
|
|
90
|
+
const connection = this.buildGetMetadataConnection(key);
|
|
91
|
+
const options = {};
|
|
92
|
+
const response = await connection.request(options);
|
|
93
|
+
return response.data;
|
|
94
|
+
}
|
|
95
|
+
async _getData(key) {
|
|
96
|
+
const connection = this.buildGetDataConnection(key);
|
|
97
|
+
const options = {};
|
|
98
|
+
const response = await connection.request(options);
|
|
99
|
+
return response.data;
|
|
100
|
+
}
|
|
101
|
+
_getMimetypeFromMetadata(metadata) {
|
|
102
|
+
return metadata.contentType;
|
|
103
|
+
}
|
|
104
|
+
async _get(key) {
|
|
105
|
+
const metadata = await this._getMetadata(key);
|
|
106
|
+
const data = await this._getData(key);
|
|
107
|
+
if (data && metadata) {
|
|
108
|
+
const ret = await media_core_js_1.MediaBlob.fromBlob(data, { metadata, path: key });
|
|
109
|
+
return ret;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async mget(keys) {
|
|
116
|
+
const ret = keys.map((key) => this._get(key));
|
|
117
|
+
return await Promise.all(ret);
|
|
118
|
+
}
|
|
119
|
+
async _del(key) {
|
|
120
|
+
const connection = this.buildDeleteConnection(key);
|
|
121
|
+
const options = {};
|
|
122
|
+
await connection.request(options);
|
|
123
|
+
}
|
|
124
|
+
async mdelete(keys) {
|
|
125
|
+
const ret = keys.map((key) => this._del(key));
|
|
126
|
+
await Promise.all(ret);
|
|
127
|
+
}
|
|
128
|
+
// eslint-disable-next-line require-yield
|
|
129
|
+
async *yieldKeys(_prefix) {
|
|
130
|
+
// TODO: Implement. Most have an implementation that uses nextToken.
|
|
131
|
+
throw new Error("yieldKeys is not implemented");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.BlobStoreGoogle = BlobStoreGoogle;
|
|
135
|
+
class GoogleCloudStorageUri {
|
|
136
|
+
constructor(uri) {
|
|
137
|
+
Object.defineProperty(this, "bucket", {
|
|
138
|
+
enumerable: true,
|
|
139
|
+
configurable: true,
|
|
140
|
+
writable: true,
|
|
141
|
+
value: void 0
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(this, "path", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
configurable: true,
|
|
146
|
+
writable: true,
|
|
147
|
+
value: void 0
|
|
148
|
+
});
|
|
149
|
+
const bucketAndPath = GoogleCloudStorageUri.uriToBucketAndPath(uri);
|
|
150
|
+
this.bucket = bucketAndPath.bucket;
|
|
151
|
+
this.path = bucketAndPath.path;
|
|
152
|
+
}
|
|
153
|
+
get uri() {
|
|
154
|
+
return `gs://${this.bucket}/${this.path}`;
|
|
155
|
+
}
|
|
156
|
+
get isValid() {
|
|
157
|
+
return (typeof this.bucket !== "undefined" && typeof this.path !== "undefined");
|
|
158
|
+
}
|
|
159
|
+
static uriToBucketAndPath(uri) {
|
|
160
|
+
const match = this.uriRegexp.exec(uri);
|
|
161
|
+
if (!match) {
|
|
162
|
+
throw new Error(`Invalid gs:// URI: ${uri}`);
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
bucket: match[1],
|
|
166
|
+
path: match[2],
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
static isValidUri(uri) {
|
|
170
|
+
return this.uriRegexp.test(uri);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.GoogleCloudStorageUri = GoogleCloudStorageUri;
|
|
174
|
+
Object.defineProperty(GoogleCloudStorageUri, "uriRegexp", {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
configurable: true,
|
|
177
|
+
writable: true,
|
|
178
|
+
value: /gs:\/\/([a-z0-9][a-z0-9._-]+[a-z0-9])\/(.*)/
|
|
179
|
+
});
|
|
180
|
+
class GoogleCloudStorageUploadConnection extends GoogleMultipartUploadConnection {
|
|
181
|
+
constructor(fields, caller, client) {
|
|
182
|
+
super(fields, caller, client);
|
|
183
|
+
Object.defineProperty(this, "uri", {
|
|
184
|
+
enumerable: true,
|
|
185
|
+
configurable: true,
|
|
186
|
+
writable: true,
|
|
187
|
+
value: void 0
|
|
188
|
+
});
|
|
189
|
+
this.uri = new GoogleCloudStorageUri(fields.uri);
|
|
190
|
+
}
|
|
191
|
+
async buildUrl() {
|
|
192
|
+
return `https://storage.googleapis.com/upload/storage/${this.apiVersion}/b/${this.uri.bucket}/o?uploadType=multipart`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.GoogleCloudStorageUploadConnection = GoogleCloudStorageUploadConnection;
|
|
196
|
+
class GoogleCloudStorageDownloadConnection extends GoogleDownloadConnection {
|
|
197
|
+
constructor(fields, caller, client) {
|
|
198
|
+
super(fields, caller, client);
|
|
199
|
+
Object.defineProperty(this, "uri", {
|
|
200
|
+
enumerable: true,
|
|
201
|
+
configurable: true,
|
|
202
|
+
writable: true,
|
|
203
|
+
value: void 0
|
|
204
|
+
});
|
|
205
|
+
Object.defineProperty(this, "method", {
|
|
206
|
+
enumerable: true,
|
|
207
|
+
configurable: true,
|
|
208
|
+
writable: true,
|
|
209
|
+
value: void 0
|
|
210
|
+
});
|
|
211
|
+
Object.defineProperty(this, "alt", {
|
|
212
|
+
enumerable: true,
|
|
213
|
+
configurable: true,
|
|
214
|
+
writable: true,
|
|
215
|
+
value: void 0
|
|
216
|
+
});
|
|
217
|
+
this.uri = new GoogleCloudStorageUri(fields.uri);
|
|
218
|
+
this.method = fields.method;
|
|
219
|
+
this.alt = fields.alt;
|
|
220
|
+
}
|
|
221
|
+
buildMethod() {
|
|
222
|
+
return this.method;
|
|
223
|
+
}
|
|
224
|
+
async buildUrl() {
|
|
225
|
+
const path = encodeURIComponent(this.uri.path);
|
|
226
|
+
const ret = `https://storage.googleapis.com/storage/${this.apiVersion}/b/${this.uri.bucket}/o/${path}`;
|
|
227
|
+
return this.alt ? `${ret}?alt=${this.alt}` : ret;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
exports.GoogleCloudStorageDownloadConnection = GoogleCloudStorageDownloadConnection;
|
|
231
|
+
class GoogleCloudStorageRawConnection extends GoogleDownloadRawConnection {
|
|
232
|
+
constructor(fields, caller, client) {
|
|
233
|
+
super(fields, caller, client);
|
|
234
|
+
Object.defineProperty(this, "uri", {
|
|
235
|
+
enumerable: true,
|
|
236
|
+
configurable: true,
|
|
237
|
+
writable: true,
|
|
238
|
+
value: void 0
|
|
239
|
+
});
|
|
240
|
+
this.uri = new GoogleCloudStorageUri(fields.uri);
|
|
241
|
+
}
|
|
242
|
+
async buildUrl() {
|
|
243
|
+
const path = encodeURIComponent(this.uri.path);
|
|
244
|
+
const ret = `https://storage.googleapis.com/storage/${this.apiVersion}/b/${this.uri.bucket}/o/${path}?alt=media`;
|
|
245
|
+
return ret;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
exports.GoogleCloudStorageRawConnection = GoogleCloudStorageRawConnection;
|
|
249
|
+
class BlobStoreGoogleCloudStorageBase extends BlobStoreGoogle {
|
|
250
|
+
constructor(fields) {
|
|
251
|
+
super(fields);
|
|
252
|
+
Object.defineProperty(this, "params", {
|
|
253
|
+
enumerable: true,
|
|
254
|
+
configurable: true,
|
|
255
|
+
writable: true,
|
|
256
|
+
value: void 0
|
|
257
|
+
});
|
|
258
|
+
this.params = fields;
|
|
259
|
+
this.defaultStoreOptions = {
|
|
260
|
+
...this.defaultStoreOptions,
|
|
261
|
+
pathPrefix: fields.uriPrefix.uri,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
buildSetConnection([key, _blob]) {
|
|
265
|
+
const params = {
|
|
266
|
+
...this.params,
|
|
267
|
+
uri: key,
|
|
268
|
+
};
|
|
269
|
+
return new GoogleCloudStorageUploadConnection(params, this.caller, this.client);
|
|
270
|
+
}
|
|
271
|
+
buildSetMetadata([key, blob]) {
|
|
272
|
+
const uri = new GoogleCloudStorageUri(key);
|
|
273
|
+
const ret = {
|
|
274
|
+
name: uri.path,
|
|
275
|
+
metadata: blob.metadata,
|
|
276
|
+
contentType: blob.mimetype,
|
|
277
|
+
};
|
|
278
|
+
return ret;
|
|
279
|
+
}
|
|
280
|
+
buildGetMetadataConnection(key) {
|
|
281
|
+
const params = {
|
|
282
|
+
uri: key,
|
|
283
|
+
method: "GET",
|
|
284
|
+
alt: undefined,
|
|
285
|
+
};
|
|
286
|
+
return new GoogleCloudStorageDownloadConnection(params, this.caller, this.client);
|
|
287
|
+
}
|
|
288
|
+
buildGetDataConnection(key) {
|
|
289
|
+
const params = {
|
|
290
|
+
uri: key,
|
|
291
|
+
};
|
|
292
|
+
return new GoogleCloudStorageRawConnection(params, this.caller, this.client);
|
|
293
|
+
}
|
|
294
|
+
buildDeleteConnection(key) {
|
|
295
|
+
const params = {
|
|
296
|
+
uri: key,
|
|
297
|
+
method: "DELETE",
|
|
298
|
+
alt: undefined,
|
|
299
|
+
};
|
|
300
|
+
return new GoogleCloudStorageDownloadConnection(params, this.caller, this.client);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
exports.BlobStoreGoogleCloudStorageBase = BlobStoreGoogleCloudStorageBase;
|
|
304
|
+
class AIStudioMediaBlob extends media_core_js_1.MediaBlob {
|
|
305
|
+
_valueAsDate(value) {
|
|
306
|
+
if (!value) {
|
|
307
|
+
return new Date(0);
|
|
308
|
+
}
|
|
309
|
+
return new Date(value);
|
|
310
|
+
}
|
|
311
|
+
_metadataFieldAsDate(field) {
|
|
312
|
+
return this._valueAsDate(this.metadata?.[field]);
|
|
313
|
+
}
|
|
314
|
+
get createDate() {
|
|
315
|
+
return this._metadataFieldAsDate("createTime");
|
|
316
|
+
}
|
|
317
|
+
get updateDate() {
|
|
318
|
+
return this._metadataFieldAsDate("updateTime");
|
|
319
|
+
}
|
|
320
|
+
get expirationDate() {
|
|
321
|
+
return this._metadataFieldAsDate("expirationTime");
|
|
322
|
+
}
|
|
323
|
+
get isExpired() {
|
|
324
|
+
const now = new Date().toISOString();
|
|
325
|
+
const exp = this.metadata?.expirationTime ?? now;
|
|
326
|
+
return exp <= now;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
exports.AIStudioMediaBlob = AIStudioMediaBlob;
|
|
330
|
+
class AIStudioFileUploadConnection extends GoogleMultipartUploadConnection {
|
|
331
|
+
constructor() {
|
|
332
|
+
super(...arguments);
|
|
333
|
+
Object.defineProperty(this, "apiVersion", {
|
|
334
|
+
enumerable: true,
|
|
335
|
+
configurable: true,
|
|
336
|
+
writable: true,
|
|
337
|
+
value: "v1beta"
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
async buildUrl() {
|
|
341
|
+
return `https://generativelanguage.googleapis.com/upload/${this.apiVersion}/files`;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
exports.AIStudioFileUploadConnection = AIStudioFileUploadConnection;
|
|
345
|
+
class AIStudioFileDownloadConnection extends GoogleDownloadConnection {
|
|
346
|
+
constructor(fields, caller, client) {
|
|
347
|
+
super(fields, caller, client);
|
|
348
|
+
Object.defineProperty(this, "method", {
|
|
349
|
+
enumerable: true,
|
|
350
|
+
configurable: true,
|
|
351
|
+
writable: true,
|
|
352
|
+
value: void 0
|
|
353
|
+
});
|
|
354
|
+
Object.defineProperty(this, "name", {
|
|
355
|
+
enumerable: true,
|
|
356
|
+
configurable: true,
|
|
357
|
+
writable: true,
|
|
358
|
+
value: void 0
|
|
359
|
+
});
|
|
360
|
+
Object.defineProperty(this, "apiVersion", {
|
|
361
|
+
enumerable: true,
|
|
362
|
+
configurable: true,
|
|
363
|
+
writable: true,
|
|
364
|
+
value: "v1beta"
|
|
365
|
+
});
|
|
366
|
+
this.method = fields.method;
|
|
367
|
+
this.name = fields.name;
|
|
368
|
+
}
|
|
369
|
+
buildMethod() {
|
|
370
|
+
return this.method;
|
|
371
|
+
}
|
|
372
|
+
async buildUrl() {
|
|
373
|
+
return `https://generativelanguage.googleapis.com/${this.apiVersion}/files/${this.name}`;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
exports.AIStudioFileDownloadConnection = AIStudioFileDownloadConnection;
|
|
377
|
+
class BlobStoreAIStudioFileBase extends BlobStoreGoogle {
|
|
378
|
+
constructor(fields) {
|
|
379
|
+
const params = {
|
|
380
|
+
defaultStoreOptions: {
|
|
381
|
+
pathPrefix: "https://generativelanguage.googleapis.com/v1beta/files/",
|
|
382
|
+
actionIfInvalid: "removePath",
|
|
383
|
+
},
|
|
384
|
+
...fields,
|
|
385
|
+
};
|
|
386
|
+
super(params);
|
|
387
|
+
Object.defineProperty(this, "params", {
|
|
388
|
+
enumerable: true,
|
|
389
|
+
configurable: true,
|
|
390
|
+
writable: true,
|
|
391
|
+
value: void 0
|
|
392
|
+
});
|
|
393
|
+
Object.defineProperty(this, "retryTime", {
|
|
394
|
+
enumerable: true,
|
|
395
|
+
configurable: true,
|
|
396
|
+
writable: true,
|
|
397
|
+
value: 1000
|
|
398
|
+
});
|
|
399
|
+
this.params = params;
|
|
400
|
+
this.retryTime = params?.retryTime ?? this.retryTime ?? 1000;
|
|
401
|
+
}
|
|
402
|
+
_pathToName(path) {
|
|
403
|
+
return path.split("/").pop() ?? path;
|
|
404
|
+
}
|
|
405
|
+
buildApiKeyClient(apiKey) {
|
|
406
|
+
return new auth_js_1.ApiKeyGoogleAuth(apiKey);
|
|
407
|
+
}
|
|
408
|
+
buildApiKey(fields) {
|
|
409
|
+
return fields?.apiKey ?? (0, env_1.getEnvironmentVariable)("GOOGLE_API_KEY");
|
|
410
|
+
}
|
|
411
|
+
buildClient(fields) {
|
|
412
|
+
const apiKey = this.buildApiKey(fields);
|
|
413
|
+
if (apiKey) {
|
|
414
|
+
return this.buildApiKeyClient(apiKey);
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
// TODO: Test that you can use OAuth to access
|
|
418
|
+
return this.buildAbstractedClient(fields);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
async _regetMetadata(key) {
|
|
422
|
+
// Sleep for some time period
|
|
423
|
+
// eslint-disable-next-line no-promise-executor-return
|
|
424
|
+
await new Promise((resolve) => setTimeout(resolve, this.retryTime));
|
|
425
|
+
// Fetch the latest metadata
|
|
426
|
+
return this._getMetadata(key);
|
|
427
|
+
}
|
|
428
|
+
async _set([key, blob]) {
|
|
429
|
+
const response = (await super._set([
|
|
430
|
+
key,
|
|
431
|
+
blob,
|
|
432
|
+
]));
|
|
433
|
+
let file = response.data?.file ?? { state: "FAILED" };
|
|
434
|
+
while (file.state === "PROCESSING" && file.uri && this.retryTime > 0) {
|
|
435
|
+
file = await this._regetMetadata(file.uri);
|
|
436
|
+
}
|
|
437
|
+
// The response should contain the name (and valid URI), so we need to
|
|
438
|
+
// update the blob with this. We can't return a new blob, since mset()
|
|
439
|
+
// doesn't return anything.
|
|
440
|
+
/* eslint-disable no-param-reassign */
|
|
441
|
+
blob.path = file.uri;
|
|
442
|
+
blob.metadata = {
|
|
443
|
+
...blob.metadata,
|
|
444
|
+
...file,
|
|
445
|
+
};
|
|
446
|
+
/* eslint-enable no-param-reassign */
|
|
447
|
+
return response;
|
|
448
|
+
}
|
|
449
|
+
buildSetConnection([_key, _blob]) {
|
|
450
|
+
return new AIStudioFileUploadConnection(this.params, this.caller, this.client);
|
|
451
|
+
}
|
|
452
|
+
buildSetMetadata([_key, _blob]) {
|
|
453
|
+
return {};
|
|
454
|
+
}
|
|
455
|
+
buildGetMetadataConnection(key) {
|
|
456
|
+
const params = {
|
|
457
|
+
...this.params,
|
|
458
|
+
method: "GET",
|
|
459
|
+
name: this._pathToName(key),
|
|
460
|
+
};
|
|
461
|
+
return new AIStudioFileDownloadConnection(params, this.caller, this.client);
|
|
462
|
+
}
|
|
463
|
+
buildGetDataConnection(_key) {
|
|
464
|
+
throw new Error("AI Studio File API does not provide data");
|
|
465
|
+
}
|
|
466
|
+
async _get(key) {
|
|
467
|
+
const metadata = await this._getMetadata(key);
|
|
468
|
+
if (metadata) {
|
|
469
|
+
const contentType = metadata?.mimeType ?? "application/octet-stream";
|
|
470
|
+
// TODO - Get the actual data (and other metadata) from an optional backing store
|
|
471
|
+
const data = {
|
|
472
|
+
value: "",
|
|
473
|
+
type: contentType,
|
|
474
|
+
};
|
|
475
|
+
return new media_core_js_1.MediaBlob({
|
|
476
|
+
path: key,
|
|
477
|
+
data,
|
|
478
|
+
metadata,
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
return undefined;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
buildDeleteConnection(key) {
|
|
486
|
+
const params = {
|
|
487
|
+
...this.params,
|
|
488
|
+
method: "DELETE",
|
|
489
|
+
name: this._pathToName(key),
|
|
490
|
+
};
|
|
491
|
+
return new AIStudioFileDownloadConnection(params, this.caller, this.client);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
exports.BlobStoreAIStudioFileBase = BlobStoreAIStudioFileBase;
|