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