@elizaos/plugin-google-genai 2.0.0-alpha.8 → 2.0.0-beta.1

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