commit-insights 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.
@@ -0,0 +1,1051 @@
1
+ import "./chunk-JSBRDJBE.js";
2
+
3
+ // node_modules/@google/generative-ai/dist/index.mjs
4
+ var SchemaType;
5
+ (function(SchemaType2) {
6
+ SchemaType2["STRING"] = "string";
7
+ SchemaType2["NUMBER"] = "number";
8
+ SchemaType2["INTEGER"] = "integer";
9
+ SchemaType2["BOOLEAN"] = "boolean";
10
+ SchemaType2["ARRAY"] = "array";
11
+ SchemaType2["OBJECT"] = "object";
12
+ })(SchemaType || (SchemaType = {}));
13
+ var ExecutableCodeLanguage;
14
+ (function(ExecutableCodeLanguage2) {
15
+ ExecutableCodeLanguage2["LANGUAGE_UNSPECIFIED"] = "language_unspecified";
16
+ ExecutableCodeLanguage2["PYTHON"] = "python";
17
+ })(ExecutableCodeLanguage || (ExecutableCodeLanguage = {}));
18
+ var Outcome;
19
+ (function(Outcome2) {
20
+ Outcome2["OUTCOME_UNSPECIFIED"] = "outcome_unspecified";
21
+ Outcome2["OUTCOME_OK"] = "outcome_ok";
22
+ Outcome2["OUTCOME_FAILED"] = "outcome_failed";
23
+ Outcome2["OUTCOME_DEADLINE_EXCEEDED"] = "outcome_deadline_exceeded";
24
+ })(Outcome || (Outcome = {}));
25
+ var POSSIBLE_ROLES = ["user", "model", "function", "system"];
26
+ var HarmCategory;
27
+ (function(HarmCategory2) {
28
+ HarmCategory2["HARM_CATEGORY_UNSPECIFIED"] = "HARM_CATEGORY_UNSPECIFIED";
29
+ HarmCategory2["HARM_CATEGORY_HATE_SPEECH"] = "HARM_CATEGORY_HATE_SPEECH";
30
+ HarmCategory2["HARM_CATEGORY_SEXUALLY_EXPLICIT"] = "HARM_CATEGORY_SEXUALLY_EXPLICIT";
31
+ HarmCategory2["HARM_CATEGORY_HARASSMENT"] = "HARM_CATEGORY_HARASSMENT";
32
+ HarmCategory2["HARM_CATEGORY_DANGEROUS_CONTENT"] = "HARM_CATEGORY_DANGEROUS_CONTENT";
33
+ HarmCategory2["HARM_CATEGORY_CIVIC_INTEGRITY"] = "HARM_CATEGORY_CIVIC_INTEGRITY";
34
+ })(HarmCategory || (HarmCategory = {}));
35
+ var HarmBlockThreshold;
36
+ (function(HarmBlockThreshold2) {
37
+ HarmBlockThreshold2["HARM_BLOCK_THRESHOLD_UNSPECIFIED"] = "HARM_BLOCK_THRESHOLD_UNSPECIFIED";
38
+ HarmBlockThreshold2["BLOCK_LOW_AND_ABOVE"] = "BLOCK_LOW_AND_ABOVE";
39
+ HarmBlockThreshold2["BLOCK_MEDIUM_AND_ABOVE"] = "BLOCK_MEDIUM_AND_ABOVE";
40
+ HarmBlockThreshold2["BLOCK_ONLY_HIGH"] = "BLOCK_ONLY_HIGH";
41
+ HarmBlockThreshold2["BLOCK_NONE"] = "BLOCK_NONE";
42
+ })(HarmBlockThreshold || (HarmBlockThreshold = {}));
43
+ var HarmProbability;
44
+ (function(HarmProbability2) {
45
+ HarmProbability2["HARM_PROBABILITY_UNSPECIFIED"] = "HARM_PROBABILITY_UNSPECIFIED";
46
+ HarmProbability2["NEGLIGIBLE"] = "NEGLIGIBLE";
47
+ HarmProbability2["LOW"] = "LOW";
48
+ HarmProbability2["MEDIUM"] = "MEDIUM";
49
+ HarmProbability2["HIGH"] = "HIGH";
50
+ })(HarmProbability || (HarmProbability = {}));
51
+ var BlockReason;
52
+ (function(BlockReason2) {
53
+ BlockReason2["BLOCKED_REASON_UNSPECIFIED"] = "BLOCKED_REASON_UNSPECIFIED";
54
+ BlockReason2["SAFETY"] = "SAFETY";
55
+ BlockReason2["OTHER"] = "OTHER";
56
+ })(BlockReason || (BlockReason = {}));
57
+ var FinishReason;
58
+ (function(FinishReason2) {
59
+ FinishReason2["FINISH_REASON_UNSPECIFIED"] = "FINISH_REASON_UNSPECIFIED";
60
+ FinishReason2["STOP"] = "STOP";
61
+ FinishReason2["MAX_TOKENS"] = "MAX_TOKENS";
62
+ FinishReason2["SAFETY"] = "SAFETY";
63
+ FinishReason2["RECITATION"] = "RECITATION";
64
+ FinishReason2["LANGUAGE"] = "LANGUAGE";
65
+ FinishReason2["BLOCKLIST"] = "BLOCKLIST";
66
+ FinishReason2["PROHIBITED_CONTENT"] = "PROHIBITED_CONTENT";
67
+ FinishReason2["SPII"] = "SPII";
68
+ FinishReason2["MALFORMED_FUNCTION_CALL"] = "MALFORMED_FUNCTION_CALL";
69
+ FinishReason2["OTHER"] = "OTHER";
70
+ })(FinishReason || (FinishReason = {}));
71
+ var TaskType;
72
+ (function(TaskType2) {
73
+ TaskType2["TASK_TYPE_UNSPECIFIED"] = "TASK_TYPE_UNSPECIFIED";
74
+ TaskType2["RETRIEVAL_QUERY"] = "RETRIEVAL_QUERY";
75
+ TaskType2["RETRIEVAL_DOCUMENT"] = "RETRIEVAL_DOCUMENT";
76
+ TaskType2["SEMANTIC_SIMILARITY"] = "SEMANTIC_SIMILARITY";
77
+ TaskType2["CLASSIFICATION"] = "CLASSIFICATION";
78
+ TaskType2["CLUSTERING"] = "CLUSTERING";
79
+ })(TaskType || (TaskType = {}));
80
+ var FunctionCallingMode;
81
+ (function(FunctionCallingMode2) {
82
+ FunctionCallingMode2["MODE_UNSPECIFIED"] = "MODE_UNSPECIFIED";
83
+ FunctionCallingMode2["AUTO"] = "AUTO";
84
+ FunctionCallingMode2["ANY"] = "ANY";
85
+ FunctionCallingMode2["NONE"] = "NONE";
86
+ })(FunctionCallingMode || (FunctionCallingMode = {}));
87
+ var DynamicRetrievalMode;
88
+ (function(DynamicRetrievalMode2) {
89
+ DynamicRetrievalMode2["MODE_UNSPECIFIED"] = "MODE_UNSPECIFIED";
90
+ DynamicRetrievalMode2["MODE_DYNAMIC"] = "MODE_DYNAMIC";
91
+ })(DynamicRetrievalMode || (DynamicRetrievalMode = {}));
92
+ var GoogleGenerativeAIError = class extends Error {
93
+ constructor(message) {
94
+ super(`[GoogleGenerativeAI Error]: ${message}`);
95
+ }
96
+ };
97
+ var GoogleGenerativeAIResponseError = class extends GoogleGenerativeAIError {
98
+ constructor(message, response) {
99
+ super(message);
100
+ this.response = response;
101
+ }
102
+ };
103
+ var GoogleGenerativeAIFetchError = class extends GoogleGenerativeAIError {
104
+ constructor(message, status, statusText, errorDetails) {
105
+ super(message);
106
+ this.status = status;
107
+ this.statusText = statusText;
108
+ this.errorDetails = errorDetails;
109
+ }
110
+ };
111
+ var GoogleGenerativeAIRequestInputError = class extends GoogleGenerativeAIError {
112
+ };
113
+ var GoogleGenerativeAIAbortError = class extends GoogleGenerativeAIError {
114
+ };
115
+ var DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com";
116
+ var DEFAULT_API_VERSION = "v1beta";
117
+ var PACKAGE_VERSION = "0.24.1";
118
+ var PACKAGE_LOG_HEADER = "genai-js";
119
+ var Task;
120
+ (function(Task2) {
121
+ Task2["GENERATE_CONTENT"] = "generateContent";
122
+ Task2["STREAM_GENERATE_CONTENT"] = "streamGenerateContent";
123
+ Task2["COUNT_TOKENS"] = "countTokens";
124
+ Task2["EMBED_CONTENT"] = "embedContent";
125
+ Task2["BATCH_EMBED_CONTENTS"] = "batchEmbedContents";
126
+ })(Task || (Task = {}));
127
+ var RequestUrl = class {
128
+ constructor(model, task, apiKey, stream, requestOptions) {
129
+ this.model = model;
130
+ this.task = task;
131
+ this.apiKey = apiKey;
132
+ this.stream = stream;
133
+ this.requestOptions = requestOptions;
134
+ }
135
+ toString() {
136
+ var _a, _b;
137
+ const apiVersion = ((_a = this.requestOptions) === null || _a === void 0 ? void 0 : _a.apiVersion) || DEFAULT_API_VERSION;
138
+ const baseUrl = ((_b = this.requestOptions) === null || _b === void 0 ? void 0 : _b.baseUrl) || DEFAULT_BASE_URL;
139
+ let url = `${baseUrl}/${apiVersion}/${this.model}:${this.task}`;
140
+ if (this.stream) {
141
+ url += "?alt=sse";
142
+ }
143
+ return url;
144
+ }
145
+ };
146
+ function getClientHeaders(requestOptions) {
147
+ const clientHeaders = [];
148
+ if (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.apiClient) {
149
+ clientHeaders.push(requestOptions.apiClient);
150
+ }
151
+ clientHeaders.push(`${PACKAGE_LOG_HEADER}/${PACKAGE_VERSION}`);
152
+ return clientHeaders.join(" ");
153
+ }
154
+ async function getHeaders(url) {
155
+ var _a;
156
+ const headers = new Headers();
157
+ headers.append("Content-Type", "application/json");
158
+ headers.append("x-goog-api-client", getClientHeaders(url.requestOptions));
159
+ headers.append("x-goog-api-key", url.apiKey);
160
+ let customHeaders = (_a = url.requestOptions) === null || _a === void 0 ? void 0 : _a.customHeaders;
161
+ if (customHeaders) {
162
+ if (!(customHeaders instanceof Headers)) {
163
+ try {
164
+ customHeaders = new Headers(customHeaders);
165
+ } catch (e) {
166
+ throw new GoogleGenerativeAIRequestInputError(`unable to convert customHeaders value ${JSON.stringify(customHeaders)} to Headers: ${e.message}`);
167
+ }
168
+ }
169
+ for (const [headerName, headerValue] of customHeaders.entries()) {
170
+ if (headerName === "x-goog-api-key") {
171
+ throw new GoogleGenerativeAIRequestInputError(`Cannot set reserved header name ${headerName}`);
172
+ } else if (headerName === "x-goog-api-client") {
173
+ throw new GoogleGenerativeAIRequestInputError(`Header name ${headerName} can only be set using the apiClient field`);
174
+ }
175
+ headers.append(headerName, headerValue);
176
+ }
177
+ }
178
+ return headers;
179
+ }
180
+ async function constructModelRequest(model, task, apiKey, stream, body, requestOptions) {
181
+ const url = new RequestUrl(model, task, apiKey, stream, requestOptions);
182
+ return {
183
+ url: url.toString(),
184
+ fetchOptions: Object.assign(Object.assign({}, buildFetchOptions(requestOptions)), { method: "POST", headers: await getHeaders(url), body })
185
+ };
186
+ }
187
+ async function makeModelRequest(model, task, apiKey, stream, body, requestOptions = {}, fetchFn = fetch) {
188
+ const { url, fetchOptions } = await constructModelRequest(model, task, apiKey, stream, body, requestOptions);
189
+ return makeRequest(url, fetchOptions, fetchFn);
190
+ }
191
+ async function makeRequest(url, fetchOptions, fetchFn = fetch) {
192
+ let response;
193
+ try {
194
+ response = await fetchFn(url, fetchOptions);
195
+ } catch (e) {
196
+ handleResponseError(e, url);
197
+ }
198
+ if (!response.ok) {
199
+ await handleResponseNotOk(response, url);
200
+ }
201
+ return response;
202
+ }
203
+ function handleResponseError(e, url) {
204
+ let err = e;
205
+ if (err.name === "AbortError") {
206
+ err = new GoogleGenerativeAIAbortError(`Request aborted when fetching ${url.toString()}: ${e.message}`);
207
+ err.stack = e.stack;
208
+ } else if (!(e instanceof GoogleGenerativeAIFetchError || e instanceof GoogleGenerativeAIRequestInputError)) {
209
+ err = new GoogleGenerativeAIError(`Error fetching from ${url.toString()}: ${e.message}`);
210
+ err.stack = e.stack;
211
+ }
212
+ throw err;
213
+ }
214
+ async function handleResponseNotOk(response, url) {
215
+ let message = "";
216
+ let errorDetails;
217
+ try {
218
+ const json = await response.json();
219
+ message = json.error.message;
220
+ if (json.error.details) {
221
+ message += ` ${JSON.stringify(json.error.details)}`;
222
+ errorDetails = json.error.details;
223
+ }
224
+ } catch (e) {
225
+ }
226
+ throw new GoogleGenerativeAIFetchError(`Error fetching from ${url.toString()}: [${response.status} ${response.statusText}] ${message}`, response.status, response.statusText, errorDetails);
227
+ }
228
+ function buildFetchOptions(requestOptions) {
229
+ const fetchOptions = {};
230
+ if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.signal) !== void 0 || (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeout) >= 0) {
231
+ const controller = new AbortController();
232
+ if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeout) >= 0) {
233
+ setTimeout(() => controller.abort(), requestOptions.timeout);
234
+ }
235
+ if (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.signal) {
236
+ requestOptions.signal.addEventListener("abort", () => {
237
+ controller.abort();
238
+ });
239
+ }
240
+ fetchOptions.signal = controller.signal;
241
+ }
242
+ return fetchOptions;
243
+ }
244
+ function addHelpers(response) {
245
+ response.text = () => {
246
+ if (response.candidates && response.candidates.length > 0) {
247
+ if (response.candidates.length > 1) {
248
+ console.warn(`This response had ${response.candidates.length} candidates. Returning text from the first candidate only. Access response.candidates directly to use the other candidates.`);
249
+ }
250
+ if (hadBadFinishReason(response.candidates[0])) {
251
+ throw new GoogleGenerativeAIResponseError(`${formatBlockErrorMessage(response)}`, response);
252
+ }
253
+ return getText(response);
254
+ } else if (response.promptFeedback) {
255
+ throw new GoogleGenerativeAIResponseError(`Text not available. ${formatBlockErrorMessage(response)}`, response);
256
+ }
257
+ return "";
258
+ };
259
+ response.functionCall = () => {
260
+ if (response.candidates && response.candidates.length > 0) {
261
+ if (response.candidates.length > 1) {
262
+ console.warn(`This response had ${response.candidates.length} candidates. Returning function calls from the first candidate only. Access response.candidates directly to use the other candidates.`);
263
+ }
264
+ if (hadBadFinishReason(response.candidates[0])) {
265
+ throw new GoogleGenerativeAIResponseError(`${formatBlockErrorMessage(response)}`, response);
266
+ }
267
+ console.warn(`response.functionCall() is deprecated. Use response.functionCalls() instead.`);
268
+ return getFunctionCalls(response)[0];
269
+ } else if (response.promptFeedback) {
270
+ throw new GoogleGenerativeAIResponseError(`Function call not available. ${formatBlockErrorMessage(response)}`, response);
271
+ }
272
+ return void 0;
273
+ };
274
+ response.functionCalls = () => {
275
+ if (response.candidates && response.candidates.length > 0) {
276
+ if (response.candidates.length > 1) {
277
+ console.warn(`This response had ${response.candidates.length} candidates. Returning function calls from the first candidate only. Access response.candidates directly to use the other candidates.`);
278
+ }
279
+ if (hadBadFinishReason(response.candidates[0])) {
280
+ throw new GoogleGenerativeAIResponseError(`${formatBlockErrorMessage(response)}`, response);
281
+ }
282
+ return getFunctionCalls(response);
283
+ } else if (response.promptFeedback) {
284
+ throw new GoogleGenerativeAIResponseError(`Function call not available. ${formatBlockErrorMessage(response)}`, response);
285
+ }
286
+ return void 0;
287
+ };
288
+ return response;
289
+ }
290
+ function getText(response) {
291
+ var _a, _b, _c, _d;
292
+ const textStrings = [];
293
+ if ((_b = (_a = response.candidates) === null || _a === void 0 ? void 0 : _a[0].content) === null || _b === void 0 ? void 0 : _b.parts) {
294
+ for (const part of (_d = (_c = response.candidates) === null || _c === void 0 ? void 0 : _c[0].content) === null || _d === void 0 ? void 0 : _d.parts) {
295
+ if (part.text) {
296
+ textStrings.push(part.text);
297
+ }
298
+ if (part.executableCode) {
299
+ textStrings.push("\n```" + part.executableCode.language + "\n" + part.executableCode.code + "\n```\n");
300
+ }
301
+ if (part.codeExecutionResult) {
302
+ textStrings.push("\n```\n" + part.codeExecutionResult.output + "\n```\n");
303
+ }
304
+ }
305
+ }
306
+ if (textStrings.length > 0) {
307
+ return textStrings.join("");
308
+ } else {
309
+ return "";
310
+ }
311
+ }
312
+ function getFunctionCalls(response) {
313
+ var _a, _b, _c, _d;
314
+ const functionCalls = [];
315
+ if ((_b = (_a = response.candidates) === null || _a === void 0 ? void 0 : _a[0].content) === null || _b === void 0 ? void 0 : _b.parts) {
316
+ for (const part of (_d = (_c = response.candidates) === null || _c === void 0 ? void 0 : _c[0].content) === null || _d === void 0 ? void 0 : _d.parts) {
317
+ if (part.functionCall) {
318
+ functionCalls.push(part.functionCall);
319
+ }
320
+ }
321
+ }
322
+ if (functionCalls.length > 0) {
323
+ return functionCalls;
324
+ } else {
325
+ return void 0;
326
+ }
327
+ }
328
+ var badFinishReasons = [
329
+ FinishReason.RECITATION,
330
+ FinishReason.SAFETY,
331
+ FinishReason.LANGUAGE
332
+ ];
333
+ function hadBadFinishReason(candidate) {
334
+ return !!candidate.finishReason && badFinishReasons.includes(candidate.finishReason);
335
+ }
336
+ function formatBlockErrorMessage(response) {
337
+ var _a, _b, _c;
338
+ let message = "";
339
+ if ((!response.candidates || response.candidates.length === 0) && response.promptFeedback) {
340
+ message += "Response was blocked";
341
+ if ((_a = response.promptFeedback) === null || _a === void 0 ? void 0 : _a.blockReason) {
342
+ message += ` due to ${response.promptFeedback.blockReason}`;
343
+ }
344
+ if ((_b = response.promptFeedback) === null || _b === void 0 ? void 0 : _b.blockReasonMessage) {
345
+ message += `: ${response.promptFeedback.blockReasonMessage}`;
346
+ }
347
+ } else if ((_c = response.candidates) === null || _c === void 0 ? void 0 : _c[0]) {
348
+ const firstCandidate = response.candidates[0];
349
+ if (hadBadFinishReason(firstCandidate)) {
350
+ message += `Candidate was blocked due to ${firstCandidate.finishReason}`;
351
+ if (firstCandidate.finishMessage) {
352
+ message += `: ${firstCandidate.finishMessage}`;
353
+ }
354
+ }
355
+ }
356
+ return message;
357
+ }
358
+ function __await(v) {
359
+ return this instanceof __await ? (this.v = v, this) : new __await(v);
360
+ }
361
+ function __asyncGenerator(thisArg, _arguments, generator) {
362
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
363
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
364
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
365
+ return this;
366
+ }, i;
367
+ function verb(n) {
368
+ if (g[n]) i[n] = function(v) {
369
+ return new Promise(function(a, b) {
370
+ q.push([n, v, a, b]) > 1 || resume(n, v);
371
+ });
372
+ };
373
+ }
374
+ function resume(n, v) {
375
+ try {
376
+ step(g[n](v));
377
+ } catch (e) {
378
+ settle(q[0][3], e);
379
+ }
380
+ }
381
+ function step(r) {
382
+ r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
383
+ }
384
+ function fulfill(value) {
385
+ resume("next", value);
386
+ }
387
+ function reject(value) {
388
+ resume("throw", value);
389
+ }
390
+ function settle(f, v) {
391
+ if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
392
+ }
393
+ }
394
+ var responseLineRE = /^data\: (.*)(?:\n\n|\r\r|\r\n\r\n)/;
395
+ function processStream(response) {
396
+ const inputStream = response.body.pipeThrough(new TextDecoderStream("utf8", { fatal: true }));
397
+ const responseStream = getResponseStream(inputStream);
398
+ const [stream1, stream2] = responseStream.tee();
399
+ return {
400
+ stream: generateResponseSequence(stream1),
401
+ response: getResponsePromise(stream2)
402
+ };
403
+ }
404
+ async function getResponsePromise(stream) {
405
+ const allResponses = [];
406
+ const reader = stream.getReader();
407
+ while (true) {
408
+ const { done, value } = await reader.read();
409
+ if (done) {
410
+ return addHelpers(aggregateResponses(allResponses));
411
+ }
412
+ allResponses.push(value);
413
+ }
414
+ }
415
+ function generateResponseSequence(stream) {
416
+ return __asyncGenerator(this, arguments, function* generateResponseSequence_1() {
417
+ const reader = stream.getReader();
418
+ while (true) {
419
+ const { value, done } = yield __await(reader.read());
420
+ if (done) {
421
+ break;
422
+ }
423
+ yield yield __await(addHelpers(value));
424
+ }
425
+ });
426
+ }
427
+ function getResponseStream(inputStream) {
428
+ const reader = inputStream.getReader();
429
+ const stream = new ReadableStream({
430
+ start(controller) {
431
+ let currentText = "";
432
+ return pump();
433
+ function pump() {
434
+ return reader.read().then(({ value, done }) => {
435
+ if (done) {
436
+ if (currentText.trim()) {
437
+ controller.error(new GoogleGenerativeAIError("Failed to parse stream"));
438
+ return;
439
+ }
440
+ controller.close();
441
+ return;
442
+ }
443
+ currentText += value;
444
+ let match = currentText.match(responseLineRE);
445
+ let parsedResponse;
446
+ while (match) {
447
+ try {
448
+ parsedResponse = JSON.parse(match[1]);
449
+ } catch (e) {
450
+ controller.error(new GoogleGenerativeAIError(`Error parsing JSON response: "${match[1]}"`));
451
+ return;
452
+ }
453
+ controller.enqueue(parsedResponse);
454
+ currentText = currentText.substring(match[0].length);
455
+ match = currentText.match(responseLineRE);
456
+ }
457
+ return pump();
458
+ }).catch((e) => {
459
+ let err = e;
460
+ err.stack = e.stack;
461
+ if (err.name === "AbortError") {
462
+ err = new GoogleGenerativeAIAbortError("Request aborted when reading from the stream");
463
+ } else {
464
+ err = new GoogleGenerativeAIError("Error reading from the stream");
465
+ }
466
+ throw err;
467
+ });
468
+ }
469
+ }
470
+ });
471
+ return stream;
472
+ }
473
+ function aggregateResponses(responses) {
474
+ const lastResponse = responses[responses.length - 1];
475
+ const aggregatedResponse = {
476
+ promptFeedback: lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.promptFeedback
477
+ };
478
+ for (const response of responses) {
479
+ if (response.candidates) {
480
+ let candidateIndex = 0;
481
+ for (const candidate of response.candidates) {
482
+ if (!aggregatedResponse.candidates) {
483
+ aggregatedResponse.candidates = [];
484
+ }
485
+ if (!aggregatedResponse.candidates[candidateIndex]) {
486
+ aggregatedResponse.candidates[candidateIndex] = {
487
+ index: candidateIndex
488
+ };
489
+ }
490
+ aggregatedResponse.candidates[candidateIndex].citationMetadata = candidate.citationMetadata;
491
+ aggregatedResponse.candidates[candidateIndex].groundingMetadata = candidate.groundingMetadata;
492
+ aggregatedResponse.candidates[candidateIndex].finishReason = candidate.finishReason;
493
+ aggregatedResponse.candidates[candidateIndex].finishMessage = candidate.finishMessage;
494
+ aggregatedResponse.candidates[candidateIndex].safetyRatings = candidate.safetyRatings;
495
+ if (candidate.content && candidate.content.parts) {
496
+ if (!aggregatedResponse.candidates[candidateIndex].content) {
497
+ aggregatedResponse.candidates[candidateIndex].content = {
498
+ role: candidate.content.role || "user",
499
+ parts: []
500
+ };
501
+ }
502
+ const newPart = {};
503
+ for (const part of candidate.content.parts) {
504
+ if (part.text) {
505
+ newPart.text = part.text;
506
+ }
507
+ if (part.functionCall) {
508
+ newPart.functionCall = part.functionCall;
509
+ }
510
+ if (part.executableCode) {
511
+ newPart.executableCode = part.executableCode;
512
+ }
513
+ if (part.codeExecutionResult) {
514
+ newPart.codeExecutionResult = part.codeExecutionResult;
515
+ }
516
+ if (Object.keys(newPart).length === 0) {
517
+ newPart.text = "";
518
+ }
519
+ aggregatedResponse.candidates[candidateIndex].content.parts.push(newPart);
520
+ }
521
+ }
522
+ }
523
+ candidateIndex++;
524
+ }
525
+ if (response.usageMetadata) {
526
+ aggregatedResponse.usageMetadata = response.usageMetadata;
527
+ }
528
+ }
529
+ return aggregatedResponse;
530
+ }
531
+ async function generateContentStream(apiKey, model, params, requestOptions) {
532
+ const response = await makeModelRequest(
533
+ model,
534
+ Task.STREAM_GENERATE_CONTENT,
535
+ apiKey,
536
+ /* stream */
537
+ true,
538
+ JSON.stringify(params),
539
+ requestOptions
540
+ );
541
+ return processStream(response);
542
+ }
543
+ async function generateContent(apiKey, model, params, requestOptions) {
544
+ const response = await makeModelRequest(
545
+ model,
546
+ Task.GENERATE_CONTENT,
547
+ apiKey,
548
+ /* stream */
549
+ false,
550
+ JSON.stringify(params),
551
+ requestOptions
552
+ );
553
+ const responseJson = await response.json();
554
+ const enhancedResponse = addHelpers(responseJson);
555
+ return {
556
+ response: enhancedResponse
557
+ };
558
+ }
559
+ function formatSystemInstruction(input) {
560
+ if (input == null) {
561
+ return void 0;
562
+ } else if (typeof input === "string") {
563
+ return { role: "system", parts: [{ text: input }] };
564
+ } else if (input.text) {
565
+ return { role: "system", parts: [input] };
566
+ } else if (input.parts) {
567
+ if (!input.role) {
568
+ return { role: "system", parts: input.parts };
569
+ } else {
570
+ return input;
571
+ }
572
+ }
573
+ }
574
+ function formatNewContent(request) {
575
+ let newParts = [];
576
+ if (typeof request === "string") {
577
+ newParts = [{ text: request }];
578
+ } else {
579
+ for (const partOrString of request) {
580
+ if (typeof partOrString === "string") {
581
+ newParts.push({ text: partOrString });
582
+ } else {
583
+ newParts.push(partOrString);
584
+ }
585
+ }
586
+ }
587
+ return assignRoleToPartsAndValidateSendMessageRequest(newParts);
588
+ }
589
+ function assignRoleToPartsAndValidateSendMessageRequest(parts) {
590
+ const userContent = { role: "user", parts: [] };
591
+ const functionContent = { role: "function", parts: [] };
592
+ let hasUserContent = false;
593
+ let hasFunctionContent = false;
594
+ for (const part of parts) {
595
+ if ("functionResponse" in part) {
596
+ functionContent.parts.push(part);
597
+ hasFunctionContent = true;
598
+ } else {
599
+ userContent.parts.push(part);
600
+ hasUserContent = true;
601
+ }
602
+ }
603
+ if (hasUserContent && hasFunctionContent) {
604
+ throw new GoogleGenerativeAIError("Within a single message, FunctionResponse cannot be mixed with other type of part in the request for sending chat message.");
605
+ }
606
+ if (!hasUserContent && !hasFunctionContent) {
607
+ throw new GoogleGenerativeAIError("No content is provided for sending chat message.");
608
+ }
609
+ if (hasUserContent) {
610
+ return userContent;
611
+ }
612
+ return functionContent;
613
+ }
614
+ function formatCountTokensInput(params, modelParams) {
615
+ var _a;
616
+ let formattedGenerateContentRequest = {
617
+ model: modelParams === null || modelParams === void 0 ? void 0 : modelParams.model,
618
+ generationConfig: modelParams === null || modelParams === void 0 ? void 0 : modelParams.generationConfig,
619
+ safetySettings: modelParams === null || modelParams === void 0 ? void 0 : modelParams.safetySettings,
620
+ tools: modelParams === null || modelParams === void 0 ? void 0 : modelParams.tools,
621
+ toolConfig: modelParams === null || modelParams === void 0 ? void 0 : modelParams.toolConfig,
622
+ systemInstruction: modelParams === null || modelParams === void 0 ? void 0 : modelParams.systemInstruction,
623
+ cachedContent: (_a = modelParams === null || modelParams === void 0 ? void 0 : modelParams.cachedContent) === null || _a === void 0 ? void 0 : _a.name,
624
+ contents: []
625
+ };
626
+ const containsGenerateContentRequest = params.generateContentRequest != null;
627
+ if (params.contents) {
628
+ if (containsGenerateContentRequest) {
629
+ throw new GoogleGenerativeAIRequestInputError("CountTokensRequest must have one of contents or generateContentRequest, not both.");
630
+ }
631
+ formattedGenerateContentRequest.contents = params.contents;
632
+ } else if (containsGenerateContentRequest) {
633
+ formattedGenerateContentRequest = Object.assign(Object.assign({}, formattedGenerateContentRequest), params.generateContentRequest);
634
+ } else {
635
+ const content = formatNewContent(params);
636
+ formattedGenerateContentRequest.contents = [content];
637
+ }
638
+ return { generateContentRequest: formattedGenerateContentRequest };
639
+ }
640
+ function formatGenerateContentInput(params) {
641
+ let formattedRequest;
642
+ if (params.contents) {
643
+ formattedRequest = params;
644
+ } else {
645
+ const content = formatNewContent(params);
646
+ formattedRequest = { contents: [content] };
647
+ }
648
+ if (params.systemInstruction) {
649
+ formattedRequest.systemInstruction = formatSystemInstruction(params.systemInstruction);
650
+ }
651
+ return formattedRequest;
652
+ }
653
+ function formatEmbedContentInput(params) {
654
+ if (typeof params === "string" || Array.isArray(params)) {
655
+ const content = formatNewContent(params);
656
+ return { content };
657
+ }
658
+ return params;
659
+ }
660
+ var VALID_PART_FIELDS = [
661
+ "text",
662
+ "inlineData",
663
+ "functionCall",
664
+ "functionResponse",
665
+ "executableCode",
666
+ "codeExecutionResult"
667
+ ];
668
+ var VALID_PARTS_PER_ROLE = {
669
+ user: ["text", "inlineData"],
670
+ function: ["functionResponse"],
671
+ model: ["text", "functionCall", "executableCode", "codeExecutionResult"],
672
+ // System instructions shouldn't be in history anyway.
673
+ system: ["text"]
674
+ };
675
+ function validateChatHistory(history) {
676
+ let prevContent = false;
677
+ for (const currContent of history) {
678
+ const { role, parts } = currContent;
679
+ if (!prevContent && role !== "user") {
680
+ throw new GoogleGenerativeAIError(`First content should be with role 'user', got ${role}`);
681
+ }
682
+ if (!POSSIBLE_ROLES.includes(role)) {
683
+ throw new GoogleGenerativeAIError(`Each item should include role field. Got ${role} but valid roles are: ${JSON.stringify(POSSIBLE_ROLES)}`);
684
+ }
685
+ if (!Array.isArray(parts)) {
686
+ throw new GoogleGenerativeAIError("Content should have 'parts' property with an array of Parts");
687
+ }
688
+ if (parts.length === 0) {
689
+ throw new GoogleGenerativeAIError("Each Content should have at least one part");
690
+ }
691
+ const countFields = {
692
+ text: 0,
693
+ inlineData: 0,
694
+ functionCall: 0,
695
+ functionResponse: 0,
696
+ fileData: 0,
697
+ executableCode: 0,
698
+ codeExecutionResult: 0
699
+ };
700
+ for (const part of parts) {
701
+ for (const key of VALID_PART_FIELDS) {
702
+ if (key in part) {
703
+ countFields[key] += 1;
704
+ }
705
+ }
706
+ }
707
+ const validParts = VALID_PARTS_PER_ROLE[role];
708
+ for (const key of VALID_PART_FIELDS) {
709
+ if (!validParts.includes(key) && countFields[key] > 0) {
710
+ throw new GoogleGenerativeAIError(`Content with role '${role}' can't contain '${key}' part`);
711
+ }
712
+ }
713
+ prevContent = true;
714
+ }
715
+ }
716
+ function isValidResponse(response) {
717
+ var _a;
718
+ if (response.candidates === void 0 || response.candidates.length === 0) {
719
+ return false;
720
+ }
721
+ const content = (_a = response.candidates[0]) === null || _a === void 0 ? void 0 : _a.content;
722
+ if (content === void 0) {
723
+ return false;
724
+ }
725
+ if (content.parts === void 0 || content.parts.length === 0) {
726
+ return false;
727
+ }
728
+ for (const part of content.parts) {
729
+ if (part === void 0 || Object.keys(part).length === 0) {
730
+ return false;
731
+ }
732
+ if (part.text !== void 0 && part.text === "") {
733
+ return false;
734
+ }
735
+ }
736
+ return true;
737
+ }
738
+ var SILENT_ERROR = "SILENT_ERROR";
739
+ var ChatSession = class {
740
+ constructor(apiKey, model, params, _requestOptions = {}) {
741
+ this.model = model;
742
+ this.params = params;
743
+ this._requestOptions = _requestOptions;
744
+ this._history = [];
745
+ this._sendPromise = Promise.resolve();
746
+ this._apiKey = apiKey;
747
+ if (params === null || params === void 0 ? void 0 : params.history) {
748
+ validateChatHistory(params.history);
749
+ this._history = params.history;
750
+ }
751
+ }
752
+ /**
753
+ * Gets the chat history so far. Blocked prompts are not added to history.
754
+ * Blocked candidates are not added to history, nor are the prompts that
755
+ * generated them.
756
+ */
757
+ async getHistory() {
758
+ await this._sendPromise;
759
+ return this._history;
760
+ }
761
+ /**
762
+ * Sends a chat message and receives a non-streaming
763
+ * {@link GenerateContentResult}.
764
+ *
765
+ * Fields set in the optional {@link SingleRequestOptions} parameter will
766
+ * take precedence over the {@link RequestOptions} values provided to
767
+ * {@link GoogleGenerativeAI.getGenerativeModel }.
768
+ */
769
+ async sendMessage(request, requestOptions = {}) {
770
+ var _a, _b, _c, _d, _e, _f;
771
+ await this._sendPromise;
772
+ const newContent = formatNewContent(request);
773
+ const generateContentRequest = {
774
+ safetySettings: (_a = this.params) === null || _a === void 0 ? void 0 : _a.safetySettings,
775
+ generationConfig: (_b = this.params) === null || _b === void 0 ? void 0 : _b.generationConfig,
776
+ tools: (_c = this.params) === null || _c === void 0 ? void 0 : _c.tools,
777
+ toolConfig: (_d = this.params) === null || _d === void 0 ? void 0 : _d.toolConfig,
778
+ systemInstruction: (_e = this.params) === null || _e === void 0 ? void 0 : _e.systemInstruction,
779
+ cachedContent: (_f = this.params) === null || _f === void 0 ? void 0 : _f.cachedContent,
780
+ contents: [...this._history, newContent]
781
+ };
782
+ const chatSessionRequestOptions = Object.assign(Object.assign({}, this._requestOptions), requestOptions);
783
+ let finalResult;
784
+ this._sendPromise = this._sendPromise.then(() => generateContent(this._apiKey, this.model, generateContentRequest, chatSessionRequestOptions)).then((result) => {
785
+ var _a2;
786
+ if (isValidResponse(result.response)) {
787
+ this._history.push(newContent);
788
+ const responseContent = Object.assign({
789
+ parts: [],
790
+ // Response seems to come back without a role set.
791
+ role: "model"
792
+ }, (_a2 = result.response.candidates) === null || _a2 === void 0 ? void 0 : _a2[0].content);
793
+ this._history.push(responseContent);
794
+ } else {
795
+ const blockErrorMessage = formatBlockErrorMessage(result.response);
796
+ if (blockErrorMessage) {
797
+ console.warn(`sendMessage() was unsuccessful. ${blockErrorMessage}. Inspect response object for details.`);
798
+ }
799
+ }
800
+ finalResult = result;
801
+ }).catch((e) => {
802
+ this._sendPromise = Promise.resolve();
803
+ throw e;
804
+ });
805
+ await this._sendPromise;
806
+ return finalResult;
807
+ }
808
+ /**
809
+ * Sends a chat message and receives the response as a
810
+ * {@link GenerateContentStreamResult} containing an iterable stream
811
+ * and a response promise.
812
+ *
813
+ * Fields set in the optional {@link SingleRequestOptions} parameter will
814
+ * take precedence over the {@link RequestOptions} values provided to
815
+ * {@link GoogleGenerativeAI.getGenerativeModel }.
816
+ */
817
+ async sendMessageStream(request, requestOptions = {}) {
818
+ var _a, _b, _c, _d, _e, _f;
819
+ await this._sendPromise;
820
+ const newContent = formatNewContent(request);
821
+ const generateContentRequest = {
822
+ safetySettings: (_a = this.params) === null || _a === void 0 ? void 0 : _a.safetySettings,
823
+ generationConfig: (_b = this.params) === null || _b === void 0 ? void 0 : _b.generationConfig,
824
+ tools: (_c = this.params) === null || _c === void 0 ? void 0 : _c.tools,
825
+ toolConfig: (_d = this.params) === null || _d === void 0 ? void 0 : _d.toolConfig,
826
+ systemInstruction: (_e = this.params) === null || _e === void 0 ? void 0 : _e.systemInstruction,
827
+ cachedContent: (_f = this.params) === null || _f === void 0 ? void 0 : _f.cachedContent,
828
+ contents: [...this._history, newContent]
829
+ };
830
+ const chatSessionRequestOptions = Object.assign(Object.assign({}, this._requestOptions), requestOptions);
831
+ const streamPromise = generateContentStream(this._apiKey, this.model, generateContentRequest, chatSessionRequestOptions);
832
+ this._sendPromise = this._sendPromise.then(() => streamPromise).catch((_ignored) => {
833
+ throw new Error(SILENT_ERROR);
834
+ }).then((streamResult) => streamResult.response).then((response) => {
835
+ if (isValidResponse(response)) {
836
+ this._history.push(newContent);
837
+ const responseContent = Object.assign({}, response.candidates[0].content);
838
+ if (!responseContent.role) {
839
+ responseContent.role = "model";
840
+ }
841
+ this._history.push(responseContent);
842
+ } else {
843
+ const blockErrorMessage = formatBlockErrorMessage(response);
844
+ if (blockErrorMessage) {
845
+ console.warn(`sendMessageStream() was unsuccessful. ${blockErrorMessage}. Inspect response object for details.`);
846
+ }
847
+ }
848
+ }).catch((e) => {
849
+ if (e.message !== SILENT_ERROR) {
850
+ console.error(e);
851
+ }
852
+ });
853
+ return streamPromise;
854
+ }
855
+ };
856
+ async function countTokens(apiKey, model, params, singleRequestOptions) {
857
+ const response = await makeModelRequest(model, Task.COUNT_TOKENS, apiKey, false, JSON.stringify(params), singleRequestOptions);
858
+ return response.json();
859
+ }
860
+ async function embedContent(apiKey, model, params, requestOptions) {
861
+ const response = await makeModelRequest(model, Task.EMBED_CONTENT, apiKey, false, JSON.stringify(params), requestOptions);
862
+ return response.json();
863
+ }
864
+ async function batchEmbedContents(apiKey, model, params, requestOptions) {
865
+ const requestsWithModel = params.requests.map((request) => {
866
+ return Object.assign(Object.assign({}, request), { model });
867
+ });
868
+ const response = await makeModelRequest(model, Task.BATCH_EMBED_CONTENTS, apiKey, false, JSON.stringify({ requests: requestsWithModel }), requestOptions);
869
+ return response.json();
870
+ }
871
+ var GenerativeModel = class {
872
+ constructor(apiKey, modelParams, _requestOptions = {}) {
873
+ this.apiKey = apiKey;
874
+ this._requestOptions = _requestOptions;
875
+ if (modelParams.model.includes("/")) {
876
+ this.model = modelParams.model;
877
+ } else {
878
+ this.model = `models/${modelParams.model}`;
879
+ }
880
+ this.generationConfig = modelParams.generationConfig || {};
881
+ this.safetySettings = modelParams.safetySettings || [];
882
+ this.tools = modelParams.tools;
883
+ this.toolConfig = modelParams.toolConfig;
884
+ this.systemInstruction = formatSystemInstruction(modelParams.systemInstruction);
885
+ this.cachedContent = modelParams.cachedContent;
886
+ }
887
+ /**
888
+ * Makes a single non-streaming call to the model
889
+ * and returns an object containing a single {@link GenerateContentResponse}.
890
+ *
891
+ * Fields set in the optional {@link SingleRequestOptions} parameter will
892
+ * take precedence over the {@link RequestOptions} values provided to
893
+ * {@link GoogleGenerativeAI.getGenerativeModel }.
894
+ */
895
+ async generateContent(request, requestOptions = {}) {
896
+ var _a;
897
+ const formattedParams = formatGenerateContentInput(request);
898
+ const generativeModelRequestOptions = Object.assign(Object.assign({}, this._requestOptions), requestOptions);
899
+ return generateContent(this.apiKey, this.model, Object.assign({ generationConfig: this.generationConfig, safetySettings: this.safetySettings, tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, cachedContent: (_a = this.cachedContent) === null || _a === void 0 ? void 0 : _a.name }, formattedParams), generativeModelRequestOptions);
900
+ }
901
+ /**
902
+ * Makes a single streaming call to the model and returns an object
903
+ * containing an iterable stream that iterates over all chunks in the
904
+ * streaming response as well as a promise that returns the final
905
+ * aggregated response.
906
+ *
907
+ * Fields set in the optional {@link SingleRequestOptions} parameter will
908
+ * take precedence over the {@link RequestOptions} values provided to
909
+ * {@link GoogleGenerativeAI.getGenerativeModel }.
910
+ */
911
+ async generateContentStream(request, requestOptions = {}) {
912
+ var _a;
913
+ const formattedParams = formatGenerateContentInput(request);
914
+ const generativeModelRequestOptions = Object.assign(Object.assign({}, this._requestOptions), requestOptions);
915
+ return generateContentStream(this.apiKey, this.model, Object.assign({ generationConfig: this.generationConfig, safetySettings: this.safetySettings, tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, cachedContent: (_a = this.cachedContent) === null || _a === void 0 ? void 0 : _a.name }, formattedParams), generativeModelRequestOptions);
916
+ }
917
+ /**
918
+ * Gets a new {@link ChatSession} instance which can be used for
919
+ * multi-turn chats.
920
+ */
921
+ startChat(startChatParams) {
922
+ var _a;
923
+ return new ChatSession(this.apiKey, this.model, Object.assign({ generationConfig: this.generationConfig, safetySettings: this.safetySettings, tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, cachedContent: (_a = this.cachedContent) === null || _a === void 0 ? void 0 : _a.name }, startChatParams), this._requestOptions);
924
+ }
925
+ /**
926
+ * Counts the tokens in the provided request.
927
+ *
928
+ * Fields set in the optional {@link SingleRequestOptions} parameter will
929
+ * take precedence over the {@link RequestOptions} values provided to
930
+ * {@link GoogleGenerativeAI.getGenerativeModel }.
931
+ */
932
+ async countTokens(request, requestOptions = {}) {
933
+ const formattedParams = formatCountTokensInput(request, {
934
+ model: this.model,
935
+ generationConfig: this.generationConfig,
936
+ safetySettings: this.safetySettings,
937
+ tools: this.tools,
938
+ toolConfig: this.toolConfig,
939
+ systemInstruction: this.systemInstruction,
940
+ cachedContent: this.cachedContent
941
+ });
942
+ const generativeModelRequestOptions = Object.assign(Object.assign({}, this._requestOptions), requestOptions);
943
+ return countTokens(this.apiKey, this.model, formattedParams, generativeModelRequestOptions);
944
+ }
945
+ /**
946
+ * Embeds the provided content.
947
+ *
948
+ * Fields set in the optional {@link SingleRequestOptions} parameter will
949
+ * take precedence over the {@link RequestOptions} values provided to
950
+ * {@link GoogleGenerativeAI.getGenerativeModel }.
951
+ */
952
+ async embedContent(request, requestOptions = {}) {
953
+ const formattedParams = formatEmbedContentInput(request);
954
+ const generativeModelRequestOptions = Object.assign(Object.assign({}, this._requestOptions), requestOptions);
955
+ return embedContent(this.apiKey, this.model, formattedParams, generativeModelRequestOptions);
956
+ }
957
+ /**
958
+ * Embeds an array of {@link EmbedContentRequest}s.
959
+ *
960
+ * Fields set in the optional {@link SingleRequestOptions} parameter will
961
+ * take precedence over the {@link RequestOptions} values provided to
962
+ * {@link GoogleGenerativeAI.getGenerativeModel }.
963
+ */
964
+ async batchEmbedContents(batchEmbedContentRequest, requestOptions = {}) {
965
+ const generativeModelRequestOptions = Object.assign(Object.assign({}, this._requestOptions), requestOptions);
966
+ return batchEmbedContents(this.apiKey, this.model, batchEmbedContentRequest, generativeModelRequestOptions);
967
+ }
968
+ };
969
+ var GoogleGenerativeAI = class {
970
+ constructor(apiKey) {
971
+ this.apiKey = apiKey;
972
+ }
973
+ /**
974
+ * Gets a {@link GenerativeModel} instance for the provided model name.
975
+ */
976
+ getGenerativeModel(modelParams, requestOptions) {
977
+ if (!modelParams.model) {
978
+ throw new GoogleGenerativeAIError(`Must provide a model name. Example: genai.getGenerativeModel({ model: 'my-model-name' })`);
979
+ }
980
+ return new GenerativeModel(this.apiKey, modelParams, requestOptions);
981
+ }
982
+ /**
983
+ * Creates a {@link GenerativeModel} instance from provided content cache.
984
+ */
985
+ getGenerativeModelFromCachedContent(cachedContent, modelParams, requestOptions) {
986
+ if (!cachedContent.name) {
987
+ throw new GoogleGenerativeAIRequestInputError("Cached content must contain a `name` field.");
988
+ }
989
+ if (!cachedContent.model) {
990
+ throw new GoogleGenerativeAIRequestInputError("Cached content must contain a `model` field.");
991
+ }
992
+ const disallowedDuplicates = ["model", "systemInstruction"];
993
+ for (const key of disallowedDuplicates) {
994
+ if ((modelParams === null || modelParams === void 0 ? void 0 : modelParams[key]) && cachedContent[key] && (modelParams === null || modelParams === void 0 ? void 0 : modelParams[key]) !== cachedContent[key]) {
995
+ if (key === "model") {
996
+ const modelParamsComp = modelParams.model.startsWith("models/") ? modelParams.model.replace("models/", "") : modelParams.model;
997
+ const cachedContentComp = cachedContent.model.startsWith("models/") ? cachedContent.model.replace("models/", "") : cachedContent.model;
998
+ if (modelParamsComp === cachedContentComp) {
999
+ continue;
1000
+ }
1001
+ }
1002
+ throw new GoogleGenerativeAIRequestInputError(`Different value for "${key}" specified in modelParams (${modelParams[key]}) and cachedContent (${cachedContent[key]})`);
1003
+ }
1004
+ }
1005
+ const modelParamsFromCache = Object.assign(Object.assign({}, modelParams), { model: cachedContent.model, tools: cachedContent.tools, toolConfig: cachedContent.toolConfig, systemInstruction: cachedContent.systemInstruction, cachedContent });
1006
+ return new GenerativeModel(this.apiKey, modelParamsFromCache, requestOptions);
1007
+ }
1008
+ };
1009
+ export {
1010
+ BlockReason,
1011
+ ChatSession,
1012
+ DynamicRetrievalMode,
1013
+ ExecutableCodeLanguage,
1014
+ FinishReason,
1015
+ FunctionCallingMode,
1016
+ GenerativeModel,
1017
+ GoogleGenerativeAI,
1018
+ GoogleGenerativeAIAbortError,
1019
+ GoogleGenerativeAIError,
1020
+ GoogleGenerativeAIFetchError,
1021
+ GoogleGenerativeAIRequestInputError,
1022
+ GoogleGenerativeAIResponseError,
1023
+ HarmBlockThreshold,
1024
+ HarmCategory,
1025
+ HarmProbability,
1026
+ Outcome,
1027
+ POSSIBLE_ROLES,
1028
+ SchemaType,
1029
+ TaskType
1030
+ };
1031
+ /*! Bundled license information:
1032
+
1033
+ @google/generative-ai/dist/index.mjs:
1034
+ @google/generative-ai/dist/index.mjs:
1035
+ (**
1036
+ * @license
1037
+ * Copyright 2024 Google LLC
1038
+ *
1039
+ * Licensed under the Apache License, Version 2.0 (the "License");
1040
+ * you may not use this file except in compliance with the License.
1041
+ * You may obtain a copy of the License at
1042
+ *
1043
+ * http://www.apache.org/licenses/LICENSE-2.0
1044
+ *
1045
+ * Unless required by applicable law or agreed to in writing, software
1046
+ * distributed under the License is distributed on an "AS IS" BASIS,
1047
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1048
+ * See the License for the specific language governing permissions and
1049
+ * limitations under the License.
1050
+ *)
1051
+ */