@elizaos/plugin-google-genai 2.0.3-beta.5 → 2.0.3-beta.7
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/browser/index.browser.js +795 -0
- package/dist/browser/index.browser.js.map +18 -0
- package/dist/browser/index.d.ts +2 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.node.cjs +854 -0
- package/dist/cjs/index.node.js.map +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.node.js +795 -0
- package/dist/node/index.node.js.map +18 -0
- package/package.json +5 -5
|
@@ -0,0 +1,854 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
for (let key of __getOwnPropNames(mod))
|
|
23
|
+
if (!__hasOwnProp.call(to, key))
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
26
|
+
enumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toCommonJS = (from) => {
|
|
33
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
34
|
+
if (entry)
|
|
35
|
+
return entry;
|
|
36
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
37
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
38
|
+
for (var key of __getOwnPropNames(from))
|
|
39
|
+
if (!__hasOwnProp.call(entry, key))
|
|
40
|
+
__defProp(entry, key, {
|
|
41
|
+
get: __accessProp.bind(from, key),
|
|
42
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
__moduleCache.set(from, entry);
|
|
46
|
+
return entry;
|
|
47
|
+
};
|
|
48
|
+
var __moduleCache;
|
|
49
|
+
var __returnValue = (v) => v;
|
|
50
|
+
function __exportSetter(name, newValue) {
|
|
51
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
52
|
+
}
|
|
53
|
+
var __export = (target, all) => {
|
|
54
|
+
for (var name in all)
|
|
55
|
+
__defProp(target, name, {
|
|
56
|
+
get: all[name],
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
set: __exportSetter.bind(all, name)
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// index.node.ts
|
|
64
|
+
var exports_index_node = {};
|
|
65
|
+
__export(exports_index_node, {
|
|
66
|
+
googleGenAIPlugin: () => googleGenAIPlugin,
|
|
67
|
+
default: () => index_node_default
|
|
68
|
+
});
|
|
69
|
+
module.exports = __toCommonJS(exports_index_node);
|
|
70
|
+
|
|
71
|
+
// index.ts
|
|
72
|
+
var import_core6 = require("@elizaos/core");
|
|
73
|
+
var import_genai3 = require("@google/genai");
|
|
74
|
+
|
|
75
|
+
// init.ts
|
|
76
|
+
var import_core2 = require("@elizaos/core");
|
|
77
|
+
var import_genai2 = require("@google/genai");
|
|
78
|
+
|
|
79
|
+
// utils/config.ts
|
|
80
|
+
var import_core = require("@elizaos/core");
|
|
81
|
+
var import_genai = require("@google/genai");
|
|
82
|
+
function getEnvValue(key) {
|
|
83
|
+
if (typeof process === "undefined") {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const value = process.env[key];
|
|
87
|
+
return normalizeSettingValue(value);
|
|
88
|
+
}
|
|
89
|
+
function normalizeSettingValue(value) {
|
|
90
|
+
if (value === undefined || value === null) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const trimmed = String(value).trim();
|
|
94
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
95
|
+
}
|
|
96
|
+
function getSetting(runtime, key, defaultValue) {
|
|
97
|
+
const runtimeValue = normalizeSettingValue(runtime.getSetting(key));
|
|
98
|
+
if (runtimeValue !== undefined) {
|
|
99
|
+
return runtimeValue;
|
|
100
|
+
}
|
|
101
|
+
return getEnvValue(key) ?? defaultValue;
|
|
102
|
+
}
|
|
103
|
+
function getApiKey(runtime) {
|
|
104
|
+
return getSetting(runtime, "GOOGLE_GENERATIVE_AI_API_KEY");
|
|
105
|
+
}
|
|
106
|
+
function getSmallModel(runtime) {
|
|
107
|
+
return getSetting(runtime, "GOOGLE_SMALL_MODEL") ?? getSetting(runtime, "SMALL_MODEL", "gemini-2.0-flash-001") ?? "gemini-2.0-flash-001";
|
|
108
|
+
}
|
|
109
|
+
function getNanoModel(runtime) {
|
|
110
|
+
return getSetting(runtime, "GOOGLE_NANO_MODEL") ?? getSetting(runtime, "NANO_MODEL") ?? getSmallModel(runtime);
|
|
111
|
+
}
|
|
112
|
+
function getMediumModel(runtime) {
|
|
113
|
+
return getSetting(runtime, "GOOGLE_MEDIUM_MODEL") ?? getSetting(runtime, "MEDIUM_MODEL") ?? getSmallModel(runtime);
|
|
114
|
+
}
|
|
115
|
+
function getLargeModel(runtime) {
|
|
116
|
+
return getSetting(runtime, "GOOGLE_LARGE_MODEL") ?? getSetting(runtime, "LARGE_MODEL", "gemini-2.5-pro-preview-03-25") ?? "gemini-2.5-pro-preview-03-25";
|
|
117
|
+
}
|
|
118
|
+
function getMegaModel(runtime) {
|
|
119
|
+
return getSetting(runtime, "GOOGLE_MEGA_MODEL") ?? getSetting(runtime, "MEGA_MODEL") ?? getLargeModel(runtime);
|
|
120
|
+
}
|
|
121
|
+
function getResponseHandlerModel(runtime) {
|
|
122
|
+
return getSetting(runtime, "GOOGLE_RESPONSE_HANDLER_MODEL") ?? getSetting(runtime, "GOOGLE_SHOULD_RESPOND_MODEL") ?? getSetting(runtime, "RESPONSE_HANDLER_MODEL") ?? getSetting(runtime, "SHOULD_RESPOND_MODEL") ?? getNanoModel(runtime);
|
|
123
|
+
}
|
|
124
|
+
function getActionPlannerModel(runtime) {
|
|
125
|
+
return getSetting(runtime, "GOOGLE_ACTION_PLANNER_MODEL") ?? getSetting(runtime, "GOOGLE_PLANNER_MODEL") ?? getSetting(runtime, "ACTION_PLANNER_MODEL") ?? getSetting(runtime, "PLANNER_MODEL") ?? getMediumModel(runtime);
|
|
126
|
+
}
|
|
127
|
+
function getImageModel(runtime) {
|
|
128
|
+
return getSetting(runtime, "GOOGLE_IMAGE_MODEL") ?? getSetting(runtime, "IMAGE_MODEL", "gemini-2.5-pro-preview-03-25") ?? "gemini-2.5-pro-preview-03-25";
|
|
129
|
+
}
|
|
130
|
+
function getEmbeddingModel(runtime) {
|
|
131
|
+
return getSetting(runtime, "GOOGLE_EMBEDDING_MODEL", "text-embedding-004") ?? "text-embedding-004";
|
|
132
|
+
}
|
|
133
|
+
function createGoogleGenAI(runtime) {
|
|
134
|
+
const apiKey = getApiKey(runtime);
|
|
135
|
+
if (!apiKey) {
|
|
136
|
+
import_core.logger.error("Google Generative AI API Key is missing");
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
return new import_genai.GoogleGenAI({ apiKey });
|
|
140
|
+
}
|
|
141
|
+
function getSafetySettings() {
|
|
142
|
+
return [
|
|
143
|
+
{
|
|
144
|
+
category: import_genai.HarmCategory.HARM_CATEGORY_HARASSMENT,
|
|
145
|
+
threshold: import_genai.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
category: import_genai.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
|
|
149
|
+
threshold: import_genai.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
category: import_genai.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
|
|
153
|
+
threshold: import_genai.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
category: import_genai.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
|
|
157
|
+
threshold: import_genai.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
|
|
158
|
+
}
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// init.ts
|
|
163
|
+
function initializeGoogleGenAI(_config, runtime) {
|
|
164
|
+
(async () => {
|
|
165
|
+
try {
|
|
166
|
+
const apiKey = getApiKey(runtime);
|
|
167
|
+
if (!apiKey) {
|
|
168
|
+
import_core2.logger.warn("GOOGLE_GENERATIVE_AI_API_KEY is not set");
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const genAI = new import_genai2.GoogleGenAI({ apiKey });
|
|
172
|
+
const modelList = await genAI.models.list();
|
|
173
|
+
const models = [];
|
|
174
|
+
for await (const model of modelList) {
|
|
175
|
+
models.push(model);
|
|
176
|
+
}
|
|
177
|
+
import_core2.logger.log(`Google AI API key validated. Available models: ${models.length}`);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
import_core2.logger.warn(`Google AI configuration error: ${error instanceof Error ? error.message : String(error)}`);
|
|
180
|
+
}
|
|
181
|
+
})();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// models/embedding.ts
|
|
185
|
+
var ElizaCore = __toESM(require("@elizaos/core"));
|
|
186
|
+
var import_core3 = require("@elizaos/core");
|
|
187
|
+
|
|
188
|
+
// utils/events.ts
|
|
189
|
+
var MODEL_USED_EVENT = "MODEL_USED";
|
|
190
|
+
function emitModelUsageEvent(runtime, type, _prompt, usage) {
|
|
191
|
+
runtime.emitEvent(MODEL_USED_EVENT, {
|
|
192
|
+
runtime,
|
|
193
|
+
source: "plugin-google-genai",
|
|
194
|
+
type,
|
|
195
|
+
tokens: {
|
|
196
|
+
prompt: usage.promptTokens,
|
|
197
|
+
completion: usage.completionTokens,
|
|
198
|
+
total: usage.totalTokens
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// utils/tokenization.ts
|
|
204
|
+
async function countTokens(text) {
|
|
205
|
+
return Math.ceil(text.length / 4);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// models/embedding.ts
|
|
209
|
+
var TEXT_EMBEDDING_MODEL_TYPE = ElizaCore.ModelType?.TEXT_EMBEDDING ?? "TEXT_EMBEDDING";
|
|
210
|
+
function createInitProbeVector() {
|
|
211
|
+
const vector = Array(768).fill(0);
|
|
212
|
+
vector[0] = 0.1;
|
|
213
|
+
return vector;
|
|
214
|
+
}
|
|
215
|
+
function extractText(params) {
|
|
216
|
+
if (params === null) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
if (typeof params === "string") {
|
|
220
|
+
return params;
|
|
221
|
+
}
|
|
222
|
+
if (typeof params === "object" && typeof params.text === "string") {
|
|
223
|
+
return params.text;
|
|
224
|
+
}
|
|
225
|
+
throw new Error("Invalid input format for embedding: expected string or { text: string }");
|
|
226
|
+
}
|
|
227
|
+
async function handleTextEmbedding(runtime, params) {
|
|
228
|
+
if (params === null) {
|
|
229
|
+
return createInitProbeVector();
|
|
230
|
+
}
|
|
231
|
+
let text = extractText(params);
|
|
232
|
+
if (text === null) {
|
|
233
|
+
return createInitProbeVector();
|
|
234
|
+
}
|
|
235
|
+
if (!text.trim()) {
|
|
236
|
+
throw new Error("Cannot generate embedding for empty text");
|
|
237
|
+
}
|
|
238
|
+
const genAI = createGoogleGenAI(runtime);
|
|
239
|
+
if (!genAI) {
|
|
240
|
+
throw new Error("Google Generative AI client not initialized");
|
|
241
|
+
}
|
|
242
|
+
const embeddingModelName = getEmbeddingModel(runtime);
|
|
243
|
+
import_core3.logger.debug(`[TEXT_EMBEDDING] Using model: ${embeddingModelName}`);
|
|
244
|
+
const maxChars = 8192 * 4;
|
|
245
|
+
if (text.length > maxChars) {
|
|
246
|
+
import_core3.logger.warn(`[Google GenAI] Embedding input too long (~${Math.ceil(text.length / 4)} tokens), truncating to ~8192 tokens`);
|
|
247
|
+
text = text.slice(0, maxChars);
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
const response = await genAI.models.embedContent({
|
|
251
|
+
model: embeddingModelName,
|
|
252
|
+
contents: text
|
|
253
|
+
});
|
|
254
|
+
const embedding = response.embeddings?.[0]?.values || [];
|
|
255
|
+
if (embedding.length === 0) {
|
|
256
|
+
throw new Error("Google GenAI API returned no embedding");
|
|
257
|
+
}
|
|
258
|
+
const promptTokens = await countTokens(text);
|
|
259
|
+
emitModelUsageEvent(runtime, TEXT_EMBEDDING_MODEL_TYPE, text, {
|
|
260
|
+
promptTokens,
|
|
261
|
+
completionTokens: 0,
|
|
262
|
+
totalTokens: promptTokens
|
|
263
|
+
});
|
|
264
|
+
import_core3.logger.log(`Got embedding with length ${embedding.length}`);
|
|
265
|
+
return embedding;
|
|
266
|
+
} catch (error) {
|
|
267
|
+
import_core3.logger.error(`Error generating embedding: ${error instanceof Error ? error.message : String(error)}`);
|
|
268
|
+
throw error instanceof Error ? error : new Error(String(error));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
// models/image.ts
|
|
272
|
+
var import_core4 = require("@elizaos/core");
|
|
273
|
+
async function handleImageDescription(runtime, params) {
|
|
274
|
+
const genAI = createGoogleGenAI(runtime);
|
|
275
|
+
if (!genAI) {
|
|
276
|
+
throw new Error("Google Generative AI client not initialized");
|
|
277
|
+
}
|
|
278
|
+
let imageUrl;
|
|
279
|
+
let promptText;
|
|
280
|
+
const modelName = getImageModel(runtime);
|
|
281
|
+
import_core4.logger.log(`[IMAGE_DESCRIPTION] Using model: ${modelName}`);
|
|
282
|
+
if (typeof params === "string") {
|
|
283
|
+
imageUrl = params;
|
|
284
|
+
promptText = "Please analyze this image and provide a title and detailed description.";
|
|
285
|
+
} else {
|
|
286
|
+
imageUrl = params.imageUrl;
|
|
287
|
+
promptText = params.prompt || "Please analyze this image and provide a title and detailed description.";
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
const imageResponse = await fetch(imageUrl);
|
|
291
|
+
if (!imageResponse.ok) {
|
|
292
|
+
throw new Error(`Failed to fetch image: ${imageResponse.statusText}`);
|
|
293
|
+
}
|
|
294
|
+
const imageData = await imageResponse.arrayBuffer();
|
|
295
|
+
const base64Image = Buffer.from(imageData).toString("base64");
|
|
296
|
+
const contentType = imageResponse.headers.get("content-type") || "image/jpeg";
|
|
297
|
+
const details = {
|
|
298
|
+
model: modelName,
|
|
299
|
+
systemPrompt: "",
|
|
300
|
+
userPrompt: promptText,
|
|
301
|
+
temperature: 0.7,
|
|
302
|
+
maxTokens: 8192,
|
|
303
|
+
purpose: "external_llm",
|
|
304
|
+
actionType: "google-genai.IMAGE_DESCRIPTION.generateContent"
|
|
305
|
+
};
|
|
306
|
+
const response = await import_core4.recordLlmCall(runtime, details, async () => {
|
|
307
|
+
const result = await genAI.models.generateContent({
|
|
308
|
+
model: modelName,
|
|
309
|
+
contents: [
|
|
310
|
+
{
|
|
311
|
+
role: "user",
|
|
312
|
+
parts: [
|
|
313
|
+
{ text: promptText },
|
|
314
|
+
{
|
|
315
|
+
inlineData: {
|
|
316
|
+
mimeType: contentType,
|
|
317
|
+
data: base64Image
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
]
|
|
321
|
+
}
|
|
322
|
+
],
|
|
323
|
+
config: {
|
|
324
|
+
temperature: 0.7,
|
|
325
|
+
topK: 40,
|
|
326
|
+
topP: 0.95,
|
|
327
|
+
maxOutputTokens: 8192,
|
|
328
|
+
safetySettings: getSafetySettings()
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
const responseText2 = result.text || "";
|
|
332
|
+
details.response = responseText2;
|
|
333
|
+
details.promptTokens = await countTokens(promptText);
|
|
334
|
+
details.completionTokens = await countTokens(responseText2);
|
|
335
|
+
return result;
|
|
336
|
+
});
|
|
337
|
+
const responseText = response.text || "";
|
|
338
|
+
try {
|
|
339
|
+
const jsonResponse = JSON.parse(responseText);
|
|
340
|
+
if (typeof jsonResponse.title === "string" && typeof jsonResponse.description === "string") {
|
|
341
|
+
return {
|
|
342
|
+
title: jsonResponse.title,
|
|
343
|
+
description: jsonResponse.description
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
} catch {}
|
|
347
|
+
const titleMatch = responseText.match(/title[:\s]+(.+?)(?:\n|$)/i);
|
|
348
|
+
const title = titleMatch?.[1]?.trim() || "Image Analysis";
|
|
349
|
+
const description = titleMatch ? responseText.replace(/title[:\s]+(.+?)(?:\n|$)/i, "").trim() : responseText.trim();
|
|
350
|
+
return { title, description };
|
|
351
|
+
} catch (error) {
|
|
352
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
353
|
+
import_core4.logger.error(`Error analyzing image: ${message}`);
|
|
354
|
+
return {
|
|
355
|
+
title: "Failed to analyze image",
|
|
356
|
+
description: `Error: ${message}`
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
// models/text.ts
|
|
361
|
+
var import_core5 = require("@elizaos/core");
|
|
362
|
+
var TEXT_NANO_MODEL_TYPE = import_core5.ModelType.TEXT_NANO;
|
|
363
|
+
var TEXT_MEDIUM_MODEL_TYPE = import_core5.ModelType.TEXT_MEDIUM;
|
|
364
|
+
var TEXT_SMALL_MODEL_TYPE = import_core5.ModelType.TEXT_SMALL;
|
|
365
|
+
var TEXT_LARGE_MODEL_TYPE = import_core5.ModelType.TEXT_LARGE;
|
|
366
|
+
var TEXT_MEGA_MODEL_TYPE = import_core5.ModelType.TEXT_MEGA;
|
|
367
|
+
var RESPONSE_HANDLER_MODEL_TYPE = import_core5.ModelType.RESPONSE_HANDLER;
|
|
368
|
+
var ACTION_PLANNER_MODEL_TYPE = import_core5.ModelType.ACTION_PLANNER;
|
|
369
|
+
function normalizeToolsForGoogle(tools) {
|
|
370
|
+
if (!tools)
|
|
371
|
+
return;
|
|
372
|
+
if (Array.isArray(tools) && tools.length > 0 && typeof tools[0] === "object" && tools[0] !== null && "functionDeclarations" in tools[0]) {
|
|
373
|
+
return tools;
|
|
374
|
+
}
|
|
375
|
+
const flat = Array.isArray(tools) ? tools : Object.entries(tools).map(([name, value]) => ({ name, ...value }));
|
|
376
|
+
const declarations = [];
|
|
377
|
+
for (const tool of flat) {
|
|
378
|
+
const name = tool.name ?? tool.function?.name;
|
|
379
|
+
if (!name) {
|
|
380
|
+
throw new Error("[GoogleGenAI] Tool definition is missing a name.");
|
|
381
|
+
}
|
|
382
|
+
const description = tool.description ?? tool.function?.description;
|
|
383
|
+
const parameters = tool.parameters ?? tool.inputSchema ?? tool.function?.parameters ?? {
|
|
384
|
+
type: "object",
|
|
385
|
+
properties: {}
|
|
386
|
+
};
|
|
387
|
+
declarations.push({
|
|
388
|
+
name,
|
|
389
|
+
...description ? { description } : {},
|
|
390
|
+
parameters
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
return declarations.length > 0 ? [{ functionDeclarations: declarations }] : undefined;
|
|
394
|
+
}
|
|
395
|
+
function normalizeToolConfigForGoogle(toolChoice) {
|
|
396
|
+
if (!toolChoice)
|
|
397
|
+
return;
|
|
398
|
+
if (toolChoice === "auto") {
|
|
399
|
+
return { functionCallingConfig: { mode: "AUTO" } };
|
|
400
|
+
}
|
|
401
|
+
if (toolChoice === "required") {
|
|
402
|
+
return { functionCallingConfig: { mode: "ANY" } };
|
|
403
|
+
}
|
|
404
|
+
if (toolChoice === "none") {
|
|
405
|
+
return { functionCallingConfig: { mode: "NONE" } };
|
|
406
|
+
}
|
|
407
|
+
let toolName;
|
|
408
|
+
if ("type" in toolChoice) {
|
|
409
|
+
toolName = toolChoice.type === "function" ? toolChoice.function.name : toolChoice.toolName ?? toolChoice.name;
|
|
410
|
+
} else {
|
|
411
|
+
toolName = toolChoice.name;
|
|
412
|
+
}
|
|
413
|
+
if (toolName) {
|
|
414
|
+
return {
|
|
415
|
+
functionCallingConfig: {
|
|
416
|
+
mode: "ANY",
|
|
417
|
+
allowedFunctionNames: [toolName]
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
function resolveResponseJsonSchema(responseSchema) {
|
|
424
|
+
if (!responseSchema)
|
|
425
|
+
return;
|
|
426
|
+
if ("schema" in responseSchema && responseSchema.schema) {
|
|
427
|
+
return responseSchema.schema;
|
|
428
|
+
}
|
|
429
|
+
return responseSchema;
|
|
430
|
+
}
|
|
431
|
+
function buildPromptParts(prompt, attachments) {
|
|
432
|
+
const parts = [{ text: prompt }];
|
|
433
|
+
for (const attachment of attachments ?? []) {
|
|
434
|
+
if (attachment.data instanceof URL) {
|
|
435
|
+
parts.push({
|
|
436
|
+
fileData: {
|
|
437
|
+
mimeType: attachment.mediaType,
|
|
438
|
+
fileUri: attachment.data.toString()
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
if (typeof attachment.data === "string" && /^https?:\/\//i.test(attachment.data)) {
|
|
444
|
+
parts.push({
|
|
445
|
+
fileData: {
|
|
446
|
+
mimeType: attachment.mediaType,
|
|
447
|
+
fileUri: attachment.data
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
if (typeof attachment.data === "string") {
|
|
453
|
+
const dataUrlMatch = attachment.data.match(/^data:([^;,]+);base64,(.+)$/i);
|
|
454
|
+
parts.push({
|
|
455
|
+
inlineData: {
|
|
456
|
+
mimeType: dataUrlMatch?.[1] ?? attachment.mediaType,
|
|
457
|
+
data: dataUrlMatch?.[2] ?? attachment.data
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
parts.push({
|
|
463
|
+
inlineData: {
|
|
464
|
+
mimeType: attachment.mediaType,
|
|
465
|
+
data: Buffer.from(attachment.data).toString("base64")
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
return parts;
|
|
470
|
+
}
|
|
471
|
+
function resolveGoogleSystemInstruction(runtime, params) {
|
|
472
|
+
return import_core5.resolveEffectiveSystemPrompt({
|
|
473
|
+
params,
|
|
474
|
+
fallback: import_core5.buildCanonicalSystemPrompt({ character: runtime.character })
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
function resolveGooglePrompt(params, systemInstruction) {
|
|
478
|
+
return import_core5.renderChatMessagesForPrompt(params.messages, {
|
|
479
|
+
omitDuplicateSystem: systemInstruction
|
|
480
|
+
}) ?? params.prompt ?? "";
|
|
481
|
+
}
|
|
482
|
+
function getModelNameForType(runtime, modelType) {
|
|
483
|
+
switch (modelType) {
|
|
484
|
+
case TEXT_NANO_MODEL_TYPE:
|
|
485
|
+
return getNanoModel(runtime);
|
|
486
|
+
case TEXT_MEDIUM_MODEL_TYPE:
|
|
487
|
+
return getMediumModel(runtime);
|
|
488
|
+
case TEXT_SMALL_MODEL_TYPE:
|
|
489
|
+
return getSmallModel(runtime);
|
|
490
|
+
case TEXT_LARGE_MODEL_TYPE:
|
|
491
|
+
return getLargeModel(runtime);
|
|
492
|
+
case TEXT_MEGA_MODEL_TYPE:
|
|
493
|
+
return getMegaModel(runtime);
|
|
494
|
+
case RESPONSE_HANDLER_MODEL_TYPE:
|
|
495
|
+
return getResponseHandlerModel(runtime);
|
|
496
|
+
case ACTION_PLANNER_MODEL_TYPE:
|
|
497
|
+
return getActionPlannerModel(runtime);
|
|
498
|
+
default:
|
|
499
|
+
return getLargeModel(runtime);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
function buildGoogleGenerationConfig(params, systemInstruction, temperature, maxTokens, stopSequences) {
|
|
503
|
+
const tools = normalizeToolsForGoogle(params.tools);
|
|
504
|
+
const toolConfig = normalizeToolConfigForGoogle(params.toolChoice);
|
|
505
|
+
const responseJsonSchema = resolveResponseJsonSchema(params.responseSchema);
|
|
506
|
+
const baseConfig = {
|
|
507
|
+
temperature,
|
|
508
|
+
topK: 40,
|
|
509
|
+
topP: 0.95,
|
|
510
|
+
stopSequences,
|
|
511
|
+
safetySettings: getSafetySettings(),
|
|
512
|
+
...typeof maxTokens === "number" ? { maxOutputTokens: maxTokens } : {},
|
|
513
|
+
...systemInstruction && { systemInstruction },
|
|
514
|
+
...tools ? { tools } : {},
|
|
515
|
+
...toolConfig ? { toolConfig } : {},
|
|
516
|
+
...responseJsonSchema ? {
|
|
517
|
+
responseMimeType: "application/json",
|
|
518
|
+
responseJsonSchema
|
|
519
|
+
} : {}
|
|
520
|
+
};
|
|
521
|
+
return baseConfig;
|
|
522
|
+
}
|
|
523
|
+
function createLlmCallDetails(modelName, modelType, prompt, systemInstruction, temperature, maxTokens, maxTokensOmitted) {
|
|
524
|
+
return {
|
|
525
|
+
model: modelName,
|
|
526
|
+
systemPrompt: systemInstruction ?? "",
|
|
527
|
+
userPrompt: prompt,
|
|
528
|
+
temperature,
|
|
529
|
+
maxTokens: maxTokens ?? 0,
|
|
530
|
+
maxTokensOmitted: maxTokensOmitted ? true : undefined,
|
|
531
|
+
purpose: "external_llm",
|
|
532
|
+
actionType: `google-genai.${modelType}.generateContent`
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
async function generateContentWithTrajectory(runtime, genAI, modelName, modelType, prompt, systemInstruction, temperature, maxTokens, maxTokensOmitted, request) {
|
|
536
|
+
const details = createLlmCallDetails(modelName, modelType, prompt, systemInstruction, temperature, maxTokens, maxTokensOmitted);
|
|
537
|
+
const response = await import_core5.recordLlmCall(runtime, details, async () => {
|
|
538
|
+
const result = await genAI.models.generateContent(request);
|
|
539
|
+
const text2 = result.text || "";
|
|
540
|
+
details.response = text2;
|
|
541
|
+
details.promptTokens = await countTokens(prompt);
|
|
542
|
+
details.completionTokens = await countTokens(text2);
|
|
543
|
+
return result;
|
|
544
|
+
});
|
|
545
|
+
const text = response.text || "";
|
|
546
|
+
const promptTokens = details.promptTokens ?? await countTokens(prompt);
|
|
547
|
+
const completionTokens = details.completionTokens ?? await countTokens(text);
|
|
548
|
+
emitModelUsageEvent(runtime, modelType, prompt, {
|
|
549
|
+
promptTokens,
|
|
550
|
+
completionTokens,
|
|
551
|
+
totalTokens: promptTokens + completionTokens
|
|
552
|
+
});
|
|
553
|
+
return text;
|
|
554
|
+
}
|
|
555
|
+
async function handleTextSmall(runtime, params) {
|
|
556
|
+
const { stopSequences = [], temperature = 0.7, attachments } = params;
|
|
557
|
+
const maxTokens = params.omitMaxTokens ? undefined : params.maxTokens ?? 8192;
|
|
558
|
+
const genAI = createGoogleGenAI(runtime);
|
|
559
|
+
if (!genAI) {
|
|
560
|
+
throw new Error("Google Generative AI client not initialized");
|
|
561
|
+
}
|
|
562
|
+
const modelName = getModelNameForType(runtime, TEXT_SMALL_MODEL_TYPE);
|
|
563
|
+
import_core5.logger.log(`[TEXT_SMALL] Using model: ${modelName}`);
|
|
564
|
+
try {
|
|
565
|
+
const systemInstruction = resolveGoogleSystemInstruction(runtime, params);
|
|
566
|
+
const promptText = resolveGooglePrompt(params, systemInstruction);
|
|
567
|
+
return await generateContentWithTrajectory(runtime, genAI, modelName, TEXT_SMALL_MODEL_TYPE, promptText, systemInstruction, temperature, maxTokens, params.omitMaxTokens, {
|
|
568
|
+
model: modelName,
|
|
569
|
+
contents: (attachments?.length ?? 0) > 0 ? [
|
|
570
|
+
{
|
|
571
|
+
role: "user",
|
|
572
|
+
parts: buildPromptParts(promptText, attachments)
|
|
573
|
+
}
|
|
574
|
+
] : promptText,
|
|
575
|
+
config: buildGoogleGenerationConfig(params, systemInstruction, temperature, maxTokens, stopSequences)
|
|
576
|
+
});
|
|
577
|
+
} catch (error) {
|
|
578
|
+
import_core5.logger.error(`[TEXT_SMALL] Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
579
|
+
throw error;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
async function handleTextLarge(runtime, params) {
|
|
583
|
+
const { stopSequences = [], temperature = 0.7, attachments } = params;
|
|
584
|
+
const maxTokens = params.omitMaxTokens ? undefined : params.maxTokens ?? 8192;
|
|
585
|
+
const genAI = createGoogleGenAI(runtime);
|
|
586
|
+
if (!genAI) {
|
|
587
|
+
throw new Error("Google Generative AI client not initialized");
|
|
588
|
+
}
|
|
589
|
+
const modelName = getModelNameForType(runtime, TEXT_LARGE_MODEL_TYPE);
|
|
590
|
+
import_core5.logger.log(`[TEXT_LARGE] Using model: ${modelName}`);
|
|
591
|
+
try {
|
|
592
|
+
const systemInstruction = resolveGoogleSystemInstruction(runtime, params);
|
|
593
|
+
const promptText = resolveGooglePrompt(params, systemInstruction);
|
|
594
|
+
return await generateContentWithTrajectory(runtime, genAI, modelName, TEXT_LARGE_MODEL_TYPE, promptText, systemInstruction, temperature, maxTokens, params.omitMaxTokens, {
|
|
595
|
+
model: modelName,
|
|
596
|
+
contents: (attachments?.length ?? 0) > 0 ? [
|
|
597
|
+
{
|
|
598
|
+
role: "user",
|
|
599
|
+
parts: buildPromptParts(promptText, attachments)
|
|
600
|
+
}
|
|
601
|
+
] : promptText,
|
|
602
|
+
config: buildGoogleGenerationConfig(params, systemInstruction, temperature, maxTokens, stopSequences)
|
|
603
|
+
});
|
|
604
|
+
} catch (error) {
|
|
605
|
+
import_core5.logger.error(`[TEXT_LARGE] Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
606
|
+
throw error;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
async function handleTextNano(runtime, params) {
|
|
610
|
+
return handleTextWithType(runtime, TEXT_NANO_MODEL_TYPE, params);
|
|
611
|
+
}
|
|
612
|
+
async function handleTextMedium(runtime, params) {
|
|
613
|
+
return handleTextWithType(runtime, TEXT_MEDIUM_MODEL_TYPE, params);
|
|
614
|
+
}
|
|
615
|
+
async function handleTextMega(runtime, params) {
|
|
616
|
+
return handleTextWithType(runtime, TEXT_MEGA_MODEL_TYPE, params);
|
|
617
|
+
}
|
|
618
|
+
async function handleResponseHandler(runtime, params) {
|
|
619
|
+
return handleTextWithType(runtime, RESPONSE_HANDLER_MODEL_TYPE, params);
|
|
620
|
+
}
|
|
621
|
+
async function handleActionPlanner(runtime, params) {
|
|
622
|
+
return handleTextWithType(runtime, ACTION_PLANNER_MODEL_TYPE, params);
|
|
623
|
+
}
|
|
624
|
+
async function handleTextWithType(runtime, modelType, params) {
|
|
625
|
+
const { stopSequences = [], temperature = 0.7, attachments } = params;
|
|
626
|
+
const maxTokens = params.omitMaxTokens ? undefined : params.maxTokens ?? 8192;
|
|
627
|
+
const genAI = createGoogleGenAI(runtime);
|
|
628
|
+
if (!genAI) {
|
|
629
|
+
throw new Error("Google Generative AI client not initialized");
|
|
630
|
+
}
|
|
631
|
+
const modelName = getModelNameForType(runtime, modelType);
|
|
632
|
+
import_core5.logger.log(`[${modelType}] Using model: ${modelName}`);
|
|
633
|
+
try {
|
|
634
|
+
const systemInstruction = resolveGoogleSystemInstruction(runtime, params);
|
|
635
|
+
const promptText = resolveGooglePrompt(params, systemInstruction);
|
|
636
|
+
return await generateContentWithTrajectory(runtime, genAI, modelName, modelType, promptText, systemInstruction, temperature, maxTokens, params.omitMaxTokens, {
|
|
637
|
+
model: modelName,
|
|
638
|
+
contents: (attachments?.length ?? 0) > 0 ? [
|
|
639
|
+
{
|
|
640
|
+
role: "user",
|
|
641
|
+
parts: buildPromptParts(promptText, attachments)
|
|
642
|
+
}
|
|
643
|
+
] : promptText,
|
|
644
|
+
config: buildGoogleGenerationConfig(params, systemInstruction, temperature, maxTokens, stopSequences)
|
|
645
|
+
});
|
|
646
|
+
} catch (error) {
|
|
647
|
+
import_core5.logger.error(`[${modelType}] Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
648
|
+
throw error;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
// index.ts
|
|
652
|
+
var TEXT_NANO_MODEL_TYPE2 = import_core6.ModelType.TEXT_NANO;
|
|
653
|
+
var TEXT_MEDIUM_MODEL_TYPE2 = import_core6.ModelType.TEXT_MEDIUM;
|
|
654
|
+
var TEXT_SMALL_MODEL_TYPE2 = import_core6.ModelType.TEXT_SMALL;
|
|
655
|
+
var TEXT_LARGE_MODEL_TYPE2 = import_core6.ModelType.TEXT_LARGE;
|
|
656
|
+
var TEXT_EMBEDDING_MODEL_TYPE2 = import_core6.ModelType.TEXT_EMBEDDING;
|
|
657
|
+
var IMAGE_DESCRIPTION_MODEL_TYPE = import_core6.ModelType.IMAGE_DESCRIPTION;
|
|
658
|
+
var TEXT_MEGA_MODEL_TYPE2 = import_core6.ModelType.TEXT_MEGA;
|
|
659
|
+
var RESPONSE_HANDLER_MODEL_TYPE2 = import_core6.ModelType.RESPONSE_HANDLER;
|
|
660
|
+
var ACTION_PLANNER_MODEL_TYPE2 = import_core6.ModelType.ACTION_PLANNER;
|
|
661
|
+
var pluginTests = [
|
|
662
|
+
{
|
|
663
|
+
name: "google_genai_plugin_tests",
|
|
664
|
+
tests: [
|
|
665
|
+
{
|
|
666
|
+
name: "google_test_api_key_validation",
|
|
667
|
+
fn: async (runtime) => {
|
|
668
|
+
const apiKey = getApiKey(runtime);
|
|
669
|
+
if (!apiKey) {
|
|
670
|
+
throw new Error("GOOGLE_GENERATIVE_AI_API_KEY not set");
|
|
671
|
+
}
|
|
672
|
+
const genAI = new import_genai3.GoogleGenAI({ apiKey });
|
|
673
|
+
const modelList = await genAI.models.list();
|
|
674
|
+
const models = [];
|
|
675
|
+
for await (const model of modelList) {
|
|
676
|
+
models.push(model);
|
|
677
|
+
}
|
|
678
|
+
import_core6.logger.log(`Available models: ${models.length}`);
|
|
679
|
+
}
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
name: "google_test_text_embedding",
|
|
683
|
+
fn: async (runtime) => {
|
|
684
|
+
try {
|
|
685
|
+
const embedding = await runtime.useModel(import_core6.ModelType.TEXT_EMBEDDING, {
|
|
686
|
+
text: "Hello, world!"
|
|
687
|
+
});
|
|
688
|
+
import_core6.logger.log(`Embedding dimension: ${embedding.length}`);
|
|
689
|
+
if (embedding.length === 0) {
|
|
690
|
+
throw new Error("Failed to generate embedding");
|
|
691
|
+
}
|
|
692
|
+
} catch (error) {
|
|
693
|
+
import_core6.logger.error(`Error in test_text_embedding: ${error instanceof Error ? error.message : String(error)}`);
|
|
694
|
+
throw error;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
name: "google_test_text_small",
|
|
700
|
+
fn: async (runtime) => {
|
|
701
|
+
try {
|
|
702
|
+
const text = await runtime.useModel(import_core6.ModelType.TEXT_SMALL, {
|
|
703
|
+
prompt: "What is the nature of reality in 10 words?"
|
|
704
|
+
});
|
|
705
|
+
if (text.length === 0) {
|
|
706
|
+
throw new Error("Failed to generate text");
|
|
707
|
+
}
|
|
708
|
+
import_core6.logger.log("Generated with TEXT_SMALL:", text);
|
|
709
|
+
} catch (error) {
|
|
710
|
+
import_core6.logger.error(`Error in test_text_small: ${error instanceof Error ? error.message : String(error)}`);
|
|
711
|
+
throw error;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
name: "google_test_text_large",
|
|
717
|
+
fn: async (runtime) => {
|
|
718
|
+
try {
|
|
719
|
+
const text = await runtime.useModel(import_core6.ModelType.TEXT_LARGE, {
|
|
720
|
+
prompt: "Explain quantum mechanics in simple terms."
|
|
721
|
+
});
|
|
722
|
+
if (text.length === 0) {
|
|
723
|
+
throw new Error("Failed to generate text");
|
|
724
|
+
}
|
|
725
|
+
import_core6.logger.log("Generated with TEXT_LARGE:", `${text.substring(0, 100)}...`);
|
|
726
|
+
} catch (error) {
|
|
727
|
+
import_core6.logger.error(`Error in test_text_large: ${error instanceof Error ? error.message : String(error)}`);
|
|
728
|
+
throw error;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
name: "google_test_image_description",
|
|
734
|
+
fn: async (runtime) => {
|
|
735
|
+
try {
|
|
736
|
+
const result = await runtime.useModel(import_core6.ModelType.IMAGE_DESCRIPTION, "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1c/Vitalik_Buterin_TechCrunch_London_2015_%28cropped%29.jpg/537px-Vitalik_Buterin_TechCrunch_London_2015_%28cropped%29.jpg");
|
|
737
|
+
if (result != null && typeof result === "object" && "title" in result && "description" in result) {
|
|
738
|
+
import_core6.logger.log("Image description:", JSON.stringify(result));
|
|
739
|
+
} else {
|
|
740
|
+
import_core6.logger.error(`Invalid image description result format: ${JSON.stringify(result)}`);
|
|
741
|
+
}
|
|
742
|
+
} catch (error) {
|
|
743
|
+
import_core6.logger.error(`Error in test_image_description: ${error instanceof Error ? error.message : String(error)}`);
|
|
744
|
+
throw error;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
name: "google_test_structured_output_via_text_large",
|
|
750
|
+
fn: async (runtime) => {
|
|
751
|
+
try {
|
|
752
|
+
const schema = {
|
|
753
|
+
type: "object",
|
|
754
|
+
properties: {
|
|
755
|
+
name: { type: "string" },
|
|
756
|
+
age: { type: "number" },
|
|
757
|
+
hobbies: { type: "array", items: { type: "string" } }
|
|
758
|
+
},
|
|
759
|
+
required: ["name", "age", "hobbies"]
|
|
760
|
+
};
|
|
761
|
+
const result = await runtime.useModel(import_core6.ModelType.TEXT_LARGE, {
|
|
762
|
+
prompt: "Generate a person profile with name, age, and hobbies.",
|
|
763
|
+
responseSchema: schema
|
|
764
|
+
});
|
|
765
|
+
import_core6.logger.log("Generated structured output:", JSON.stringify(result));
|
|
766
|
+
if (!result) {
|
|
767
|
+
throw new Error("Generated structured output is empty");
|
|
768
|
+
}
|
|
769
|
+
} catch (error) {
|
|
770
|
+
import_core6.logger.error(`Error in test_structured_output_via_text_large: ${error instanceof Error ? error.message : String(error)}`);
|
|
771
|
+
throw error;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
]
|
|
776
|
+
}
|
|
777
|
+
];
|
|
778
|
+
function getProcessEnv() {
|
|
779
|
+
if (typeof process === "undefined") {
|
|
780
|
+
return {};
|
|
781
|
+
}
|
|
782
|
+
return process.env;
|
|
783
|
+
}
|
|
784
|
+
var env = getProcessEnv();
|
|
785
|
+
var googleGenAIPlugin = {
|
|
786
|
+
name: "google-genai",
|
|
787
|
+
description: "Google Generative AI plugin for Gemini models",
|
|
788
|
+
autoEnable: {
|
|
789
|
+
envKeys: ["GOOGLE_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEY"]
|
|
790
|
+
},
|
|
791
|
+
config: {
|
|
792
|
+
GOOGLE_GENERATIVE_AI_API_KEY: env.GOOGLE_GENERATIVE_AI_API_KEY ?? null,
|
|
793
|
+
GOOGLE_NANO_MODEL: env.GOOGLE_NANO_MODEL ?? null,
|
|
794
|
+
GOOGLE_MEDIUM_MODEL: env.GOOGLE_MEDIUM_MODEL ?? null,
|
|
795
|
+
GOOGLE_SMALL_MODEL: env.GOOGLE_SMALL_MODEL ?? null,
|
|
796
|
+
GOOGLE_LARGE_MODEL: env.GOOGLE_LARGE_MODEL ?? null,
|
|
797
|
+
GOOGLE_MEGA_MODEL: env.GOOGLE_MEGA_MODEL ?? null,
|
|
798
|
+
GOOGLE_RESPONSE_HANDLER_MODEL: env.GOOGLE_RESPONSE_HANDLER_MODEL ?? null,
|
|
799
|
+
GOOGLE_SHOULD_RESPOND_MODEL: env.GOOGLE_SHOULD_RESPOND_MODEL ?? null,
|
|
800
|
+
GOOGLE_ACTION_PLANNER_MODEL: env.GOOGLE_ACTION_PLANNER_MODEL ?? null,
|
|
801
|
+
GOOGLE_PLANNER_MODEL: env.GOOGLE_PLANNER_MODEL ?? null,
|
|
802
|
+
GOOGLE_IMAGE_MODEL: env.GOOGLE_IMAGE_MODEL ?? null,
|
|
803
|
+
GOOGLE_EMBEDDING_MODEL: env.GOOGLE_EMBEDDING_MODEL ?? null,
|
|
804
|
+
NANO_MODEL: env.NANO_MODEL ?? null,
|
|
805
|
+
MEDIUM_MODEL: env.MEDIUM_MODEL ?? null,
|
|
806
|
+
SMALL_MODEL: env.SMALL_MODEL ?? null,
|
|
807
|
+
LARGE_MODEL: env.LARGE_MODEL ?? null,
|
|
808
|
+
MEGA_MODEL: env.MEGA_MODEL ?? null,
|
|
809
|
+
RESPONSE_HANDLER_MODEL: env.RESPONSE_HANDLER_MODEL ?? null,
|
|
810
|
+
SHOULD_RESPOND_MODEL: env.SHOULD_RESPOND_MODEL ?? null,
|
|
811
|
+
ACTION_PLANNER_MODEL: env.ACTION_PLANNER_MODEL ?? null,
|
|
812
|
+
PLANNER_MODEL: env.PLANNER_MODEL ?? null,
|
|
813
|
+
IMAGE_MODEL: env.IMAGE_MODEL ?? null
|
|
814
|
+
},
|
|
815
|
+
async init(config, runtime) {
|
|
816
|
+
initializeGoogleGenAI(config, runtime);
|
|
817
|
+
},
|
|
818
|
+
models: {
|
|
819
|
+
[TEXT_NANO_MODEL_TYPE2]: async (runtime, params) => {
|
|
820
|
+
return handleTextNano(runtime, params);
|
|
821
|
+
},
|
|
822
|
+
[TEXT_MEDIUM_MODEL_TYPE2]: async (runtime, params) => {
|
|
823
|
+
return handleTextMedium(runtime, params);
|
|
824
|
+
},
|
|
825
|
+
[TEXT_SMALL_MODEL_TYPE2]: async (runtime, params) => {
|
|
826
|
+
return handleTextSmall(runtime, params);
|
|
827
|
+
},
|
|
828
|
+
[TEXT_LARGE_MODEL_TYPE2]: async (runtime, params) => {
|
|
829
|
+
return handleTextLarge(runtime, params);
|
|
830
|
+
},
|
|
831
|
+
[TEXT_MEGA_MODEL_TYPE2]: async (runtime, params) => {
|
|
832
|
+
return handleTextMega(runtime, params);
|
|
833
|
+
},
|
|
834
|
+
[RESPONSE_HANDLER_MODEL_TYPE2]: async (runtime, params) => {
|
|
835
|
+
return handleResponseHandler(runtime, params);
|
|
836
|
+
},
|
|
837
|
+
[ACTION_PLANNER_MODEL_TYPE2]: async (runtime, params) => {
|
|
838
|
+
return handleActionPlanner(runtime, params);
|
|
839
|
+
},
|
|
840
|
+
[TEXT_EMBEDDING_MODEL_TYPE2]: async (runtime, params) => {
|
|
841
|
+
return handleTextEmbedding(runtime, params);
|
|
842
|
+
},
|
|
843
|
+
[IMAGE_DESCRIPTION_MODEL_TYPE]: async (runtime, params) => {
|
|
844
|
+
return handleImageDescription(runtime, params);
|
|
845
|
+
}
|
|
846
|
+
},
|
|
847
|
+
tests: pluginTests
|
|
848
|
+
};
|
|
849
|
+
var plugin_google_genai_default = googleGenAIPlugin;
|
|
850
|
+
|
|
851
|
+
// index.node.ts
|
|
852
|
+
var index_node_default = plugin_google_genai_default;
|
|
853
|
+
|
|
854
|
+
//# debugId=948BCDD0820931CA64756E2164756E21
|