@elizaos/plugin-google-genai 2.0.0-alpha.5 → 2.0.0-alpha.537
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/README.md +122 -0
- package/dist/browser/index.browser.js +232 -32
- package/dist/browser/index.browser.js.map +12 -11
- package/dist/build.d.ts +3 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +117 -0
- package/dist/cjs/index.node.cjs +300 -66
- package/dist/cjs/index.node.js.map +12 -11
- package/dist/generated/specs/specs.d.ts +55 -0
- package/dist/generated/specs/specs.d.ts.map +1 -0
- package/dist/generated/specs/specs.js +34 -0
- package/dist/index.browser.d.ts +5 -0
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.browser.js +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +252 -0
- package/dist/index.node.d.ts +5 -0
- package/dist/index.node.d.ts.map +1 -0
- package/dist/index.node.js +4 -0
- package/dist/init.d.ts +16 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +27 -0
- package/dist/models/embedding.d.ts +6 -0
- package/dist/models/embedding.d.ts.map +1 -0
- package/dist/models/embedding.js +57 -0
- package/dist/models/image.d.ts +7 -0
- package/dist/models/image.d.ts.map +1 -0
- package/dist/models/image.js +91 -0
- package/dist/models/index.d.ts +13 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +12 -0
- package/dist/models/object.d.ts +10 -0
- package/dist/models/object.d.ts.map +1 -0
- package/dist/models/object.js +84 -0
- package/dist/models/text.d.ts +51 -0
- package/dist/models/text.d.ts.map +1 -0
- package/dist/models/text.js +257 -0
- package/dist/node/index.node.js +232 -32
- package/dist/node/index.node.js.map +12 -11
- package/dist/types/index.d.ts +47 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/config.d.ts +25 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +115 -0
- package/dist/utils/events.d.ts +12 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/utils/events.js +14 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/tokenization.d.ts +2 -0
- package/dist/utils/tokenization.d.ts.map +1 -0
- package/dist/utils/tokenization.js +3 -0
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/dist/vitest.config.js +8 -0
- package/package.json +17 -13
package/dist/cjs/index.node.cjs
CHANGED
|
@@ -1,28 +1,62 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
1
3
|
var __defProp = Object.defineProperty;
|
|
2
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
|
|
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
|
+
};
|
|
6
32
|
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
33
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
8
34
|
if (entry)
|
|
9
35
|
return entry;
|
|
10
36
|
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
}
|
|
16
45
|
__moduleCache.set(from, entry);
|
|
17
46
|
return entry;
|
|
18
47
|
};
|
|
48
|
+
var __moduleCache;
|
|
49
|
+
var __returnValue = (v) => v;
|
|
50
|
+
function __exportSetter(name, newValue) {
|
|
51
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
52
|
+
}
|
|
19
53
|
var __export = (target, all) => {
|
|
20
54
|
for (var name in all)
|
|
21
55
|
__defProp(target, name, {
|
|
22
56
|
get: all[name],
|
|
23
57
|
enumerable: true,
|
|
24
58
|
configurable: true,
|
|
25
|
-
set: (
|
|
59
|
+
set: __exportSetter.bind(all, name)
|
|
26
60
|
});
|
|
27
61
|
};
|
|
28
62
|
|
|
@@ -30,12 +64,13 @@ var __export = (target, all) => {
|
|
|
30
64
|
var exports_index_node = {};
|
|
31
65
|
__export(exports_index_node, {
|
|
32
66
|
googleGenAIPlugin: () => googleGenAIPlugin,
|
|
33
|
-
default: () =>
|
|
67
|
+
default: () => index_node_default
|
|
34
68
|
});
|
|
35
69
|
module.exports = __toCommonJS(exports_index_node);
|
|
36
70
|
|
|
37
71
|
// index.ts
|
|
38
|
-
var
|
|
72
|
+
var ElizaCore3 = __toESM(require("@elizaos/core"));
|
|
73
|
+
var import_core7 = require("@elizaos/core");
|
|
39
74
|
var import_genai3 = require("@google/genai");
|
|
40
75
|
|
|
41
76
|
// init.ts
|
|
@@ -65,9 +100,24 @@ function getApiKey(runtime) {
|
|
|
65
100
|
function getSmallModel(runtime) {
|
|
66
101
|
return getSetting(runtime, "GOOGLE_SMALL_MODEL") ?? getSetting(runtime, "SMALL_MODEL", "gemini-2.0-flash-001") ?? "gemini-2.0-flash-001";
|
|
67
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
|
+
}
|
|
68
109
|
function getLargeModel(runtime) {
|
|
69
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";
|
|
70
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
|
+
}
|
|
71
121
|
function getImageModel(runtime) {
|
|
72
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";
|
|
73
123
|
}
|
|
@@ -126,12 +176,13 @@ function initializeGoogleGenAI(_config, runtime) {
|
|
|
126
176
|
}
|
|
127
177
|
|
|
128
178
|
// models/embedding.ts
|
|
129
|
-
var
|
|
179
|
+
var ElizaCore = __toESM(require("@elizaos/core"));
|
|
180
|
+
var import_core3 = require("@elizaos/core");
|
|
130
181
|
|
|
131
182
|
// utils/events.ts
|
|
132
|
-
var
|
|
183
|
+
var MODEL_USED_EVENT = "MODEL_USED";
|
|
133
184
|
function emitModelUsageEvent(runtime, type, _prompt, usage) {
|
|
134
|
-
runtime.emitEvent(
|
|
185
|
+
runtime.emitEvent(MODEL_USED_EVENT, {
|
|
135
186
|
runtime,
|
|
136
187
|
source: "plugin-google-genai",
|
|
137
188
|
type,
|
|
@@ -149,24 +200,25 @@ async function countTokens(text) {
|
|
|
149
200
|
}
|
|
150
201
|
|
|
151
202
|
// models/embedding.ts
|
|
203
|
+
var TEXT_EMBEDDING_MODEL_TYPE = ElizaCore.ModelType?.TEXT_EMBEDDING ?? "TEXT_EMBEDDING";
|
|
152
204
|
async function handleTextEmbedding(runtime, params) {
|
|
153
205
|
const genAI = createGoogleGenAI(runtime);
|
|
154
206
|
if (!genAI) {
|
|
155
207
|
throw new Error("Google Generative AI client not initialized");
|
|
156
208
|
}
|
|
157
209
|
const embeddingModelName = getEmbeddingModel(runtime);
|
|
158
|
-
|
|
210
|
+
import_core3.logger.debug(`[TEXT_EMBEDDING] Using model: ${embeddingModelName}`);
|
|
159
211
|
if (params === null) {
|
|
160
212
|
return Array(768).fill(0);
|
|
161
213
|
}
|
|
162
214
|
let text = typeof params === "string" ? params : typeof params === "object" && params.text ? params.text : "";
|
|
163
215
|
if (!text.trim()) {
|
|
164
|
-
|
|
216
|
+
import_core3.logger.warn("Empty text for embedding");
|
|
165
217
|
return Array(768).fill(0);
|
|
166
218
|
}
|
|
167
|
-
const maxChars =
|
|
219
|
+
const maxChars = 8192 * 4;
|
|
168
220
|
if (text.length > maxChars) {
|
|
169
|
-
|
|
221
|
+
import_core3.logger.warn(`[Google GenAI] Embedding input too long (~${Math.ceil(text.length / 4)} tokens), truncating to ~8192 tokens`);
|
|
170
222
|
text = text.slice(0, maxChars);
|
|
171
223
|
}
|
|
172
224
|
try {
|
|
@@ -176,20 +228,20 @@ async function handleTextEmbedding(runtime, params) {
|
|
|
176
228
|
});
|
|
177
229
|
const embedding = response.embeddings?.[0]?.values || [];
|
|
178
230
|
const promptTokens = await countTokens(text);
|
|
179
|
-
emitModelUsageEvent(runtime,
|
|
231
|
+
emitModelUsageEvent(runtime, TEXT_EMBEDDING_MODEL_TYPE, text, {
|
|
180
232
|
promptTokens,
|
|
181
233
|
completionTokens: 0,
|
|
182
234
|
totalTokens: promptTokens
|
|
183
235
|
});
|
|
184
|
-
|
|
236
|
+
import_core3.logger.log(`Got embedding with length ${embedding.length}`);
|
|
185
237
|
return embedding;
|
|
186
238
|
} catch (error) {
|
|
187
|
-
|
|
239
|
+
import_core3.logger.error(`Error generating embedding: ${error instanceof Error ? error.message : String(error)}`);
|
|
188
240
|
return Array(768).fill(0);
|
|
189
241
|
}
|
|
190
242
|
}
|
|
191
243
|
// models/image.ts
|
|
192
|
-
var
|
|
244
|
+
var import_core4 = require("@elizaos/core");
|
|
193
245
|
var crossFetch = typeof globalThis.fetch === "function" ? globalThis.fetch : fetch;
|
|
194
246
|
async function handleImageDescription(runtime, params) {
|
|
195
247
|
const genAI = createGoogleGenAI(runtime);
|
|
@@ -199,7 +251,7 @@ async function handleImageDescription(runtime, params) {
|
|
|
199
251
|
let imageUrl;
|
|
200
252
|
let promptText;
|
|
201
253
|
const modelName = getImageModel(runtime);
|
|
202
|
-
|
|
254
|
+
import_core4.logger.log(`[IMAGE_DESCRIPTION] Using model: ${modelName}`);
|
|
203
255
|
if (typeof params === "string") {
|
|
204
256
|
imageUrl = params;
|
|
205
257
|
promptText = "Please analyze this image and provide a title and detailed description.";
|
|
@@ -255,7 +307,7 @@ async function handleImageDescription(runtime, params) {
|
|
|
255
307
|
return { title, description };
|
|
256
308
|
} catch (error) {
|
|
257
309
|
const message = error instanceof Error ? error.message : String(error);
|
|
258
|
-
|
|
310
|
+
import_core4.logger.error(`Error analyzing image: ${message}`);
|
|
259
311
|
return {
|
|
260
312
|
title: "Failed to analyze image",
|
|
261
313
|
description: `Error: ${message}`
|
|
@@ -263,7 +315,7 @@ async function handleImageDescription(runtime, params) {
|
|
|
263
315
|
}
|
|
264
316
|
}
|
|
265
317
|
// models/object.ts
|
|
266
|
-
var
|
|
318
|
+
var import_core5 = require("@elizaos/core");
|
|
267
319
|
async function generateObjectByModelType(runtime, params, modelType, getModelFn) {
|
|
268
320
|
const genAI = createGoogleGenAI(runtime);
|
|
269
321
|
if (!genAI) {
|
|
@@ -271,7 +323,7 @@ async function generateObjectByModelType(runtime, params, modelType, getModelFn)
|
|
|
271
323
|
}
|
|
272
324
|
const modelName = getModelFn(runtime);
|
|
273
325
|
const temperature = params.temperature ?? 0.1;
|
|
274
|
-
|
|
326
|
+
import_core5.logger.info(`Using ${modelType} model: ${modelName}`);
|
|
275
327
|
try {
|
|
276
328
|
let enhancedPrompt = params.prompt;
|
|
277
329
|
if (params.schema) {
|
|
@@ -314,7 +366,7 @@ ${JSON.stringify(params.schema, null, 2)}`;
|
|
|
314
366
|
throw new Error("Failed to parse JSON from response");
|
|
315
367
|
}
|
|
316
368
|
} catch (error) {
|
|
317
|
-
|
|
369
|
+
import_core5.logger.error(`[generateObject] Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
318
370
|
throw error;
|
|
319
371
|
}
|
|
320
372
|
}
|
|
@@ -325,19 +377,136 @@ async function handleObjectLarge(runtime, params) {
|
|
|
325
377
|
return generateObjectByModelType(runtime, params, "OBJECT_LARGE", getLargeModel);
|
|
326
378
|
}
|
|
327
379
|
// models/text.ts
|
|
328
|
-
var
|
|
329
|
-
|
|
380
|
+
var ElizaCore2 = __toESM(require("@elizaos/core"));
|
|
381
|
+
var import_core6 = require("@elizaos/core");
|
|
382
|
+
var CORE_MODEL_TYPES = ElizaCore2.ModelType ?? {};
|
|
383
|
+
var TEXT_NANO_MODEL_TYPE = CORE_MODEL_TYPES.TEXT_NANO ?? "TEXT_NANO";
|
|
384
|
+
var TEXT_MEDIUM_MODEL_TYPE = CORE_MODEL_TYPES.TEXT_MEDIUM ?? "TEXT_MEDIUM";
|
|
385
|
+
var TEXT_SMALL_MODEL_TYPE = CORE_MODEL_TYPES.TEXT_SMALL ?? "TEXT_SMALL";
|
|
386
|
+
var TEXT_LARGE_MODEL_TYPE = CORE_MODEL_TYPES.TEXT_LARGE ?? "TEXT_LARGE";
|
|
387
|
+
var TEXT_MEGA_MODEL_TYPE = CORE_MODEL_TYPES.TEXT_MEGA ?? "TEXT_MEGA";
|
|
388
|
+
var RESPONSE_HANDLER_MODEL_TYPE = CORE_MODEL_TYPES.RESPONSE_HANDLER ?? "RESPONSE_HANDLER";
|
|
389
|
+
var ACTION_PLANNER_MODEL_TYPE = CORE_MODEL_TYPES.ACTION_PLANNER ?? "ACTION_PLANNER";
|
|
390
|
+
function buildPromptParts(prompt, attachments) {
|
|
391
|
+
const parts = [{ text: prompt }];
|
|
392
|
+
for (const attachment of attachments ?? []) {
|
|
393
|
+
if (attachment.data instanceof URL) {
|
|
394
|
+
parts.push({
|
|
395
|
+
fileData: {
|
|
396
|
+
mimeType: attachment.mediaType,
|
|
397
|
+
fileUri: attachment.data.toString()
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (typeof attachment.data === "string" && /^https?:\/\//i.test(attachment.data)) {
|
|
403
|
+
parts.push({
|
|
404
|
+
fileData: {
|
|
405
|
+
mimeType: attachment.mediaType,
|
|
406
|
+
fileUri: attachment.data
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
if (typeof attachment.data === "string") {
|
|
412
|
+
const dataUrlMatch = attachment.data.match(/^data:([^;,]+);base64,(.+)$/i);
|
|
413
|
+
parts.push({
|
|
414
|
+
inlineData: {
|
|
415
|
+
mimeType: dataUrlMatch?.[1] ?? attachment.mediaType,
|
|
416
|
+
data: dataUrlMatch?.[2] ?? attachment.data
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
parts.push({
|
|
422
|
+
inlineData: {
|
|
423
|
+
mimeType: attachment.mediaType,
|
|
424
|
+
data: Buffer.from(attachment.data).toString("base64")
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
return parts;
|
|
429
|
+
}
|
|
430
|
+
function getModelNameForType(runtime, modelType) {
|
|
431
|
+
switch (modelType) {
|
|
432
|
+
case TEXT_NANO_MODEL_TYPE:
|
|
433
|
+
return getNanoModel(runtime);
|
|
434
|
+
case TEXT_MEDIUM_MODEL_TYPE:
|
|
435
|
+
return getMediumModel(runtime);
|
|
436
|
+
case TEXT_SMALL_MODEL_TYPE:
|
|
437
|
+
return getSmallModel(runtime);
|
|
438
|
+
case TEXT_LARGE_MODEL_TYPE:
|
|
439
|
+
return getLargeModel(runtime);
|
|
440
|
+
case TEXT_MEGA_MODEL_TYPE:
|
|
441
|
+
return getMegaModel(runtime);
|
|
442
|
+
case RESPONSE_HANDLER_MODEL_TYPE:
|
|
443
|
+
return getResponseHandlerModel(runtime);
|
|
444
|
+
case ACTION_PLANNER_MODEL_TYPE:
|
|
445
|
+
return getActionPlannerModel(runtime);
|
|
446
|
+
default:
|
|
447
|
+
return getLargeModel(runtime);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
async function handleTextSmall(runtime, {
|
|
451
|
+
prompt,
|
|
452
|
+
stopSequences = [],
|
|
453
|
+
maxTokens = 8192,
|
|
454
|
+
temperature = 0.7,
|
|
455
|
+
attachments
|
|
456
|
+
}) {
|
|
457
|
+
const genAI = createGoogleGenAI(runtime);
|
|
458
|
+
if (!genAI) {
|
|
459
|
+
throw new Error("Google Generative AI client not initialized");
|
|
460
|
+
}
|
|
461
|
+
const modelName = getModelNameForType(runtime, TEXT_SMALL_MODEL_TYPE);
|
|
462
|
+
import_core6.logger.log(`[TEXT_SMALL] Using model: ${modelName}`);
|
|
463
|
+
try {
|
|
464
|
+
const systemInstruction = runtime.character.system || undefined;
|
|
465
|
+
const response = await genAI.models.generateContent({
|
|
466
|
+
model: modelName,
|
|
467
|
+
contents: (attachments?.length ?? 0) > 0 ? [{ role: "user", parts: buildPromptParts(prompt, attachments) }] : prompt,
|
|
468
|
+
config: {
|
|
469
|
+
temperature,
|
|
470
|
+
topK: 40,
|
|
471
|
+
topP: 0.95,
|
|
472
|
+
maxOutputTokens: maxTokens,
|
|
473
|
+
stopSequences,
|
|
474
|
+
safetySettings: getSafetySettings(),
|
|
475
|
+
...systemInstruction && { systemInstruction }
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
const text = response.text || "";
|
|
479
|
+
const promptTokens = await countTokens(prompt);
|
|
480
|
+
const completionTokens = await countTokens(text);
|
|
481
|
+
emitModelUsageEvent(runtime, TEXT_SMALL_MODEL_TYPE, prompt, {
|
|
482
|
+
promptTokens,
|
|
483
|
+
completionTokens,
|
|
484
|
+
totalTokens: promptTokens + completionTokens
|
|
485
|
+
});
|
|
486
|
+
return text;
|
|
487
|
+
} catch (error) {
|
|
488
|
+
import_core6.logger.error(`[TEXT_SMALL] Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
489
|
+
throw error;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
async function handleTextLarge(runtime, {
|
|
493
|
+
prompt,
|
|
494
|
+
stopSequences = [],
|
|
495
|
+
maxTokens = 8192,
|
|
496
|
+
temperature = 0.7,
|
|
497
|
+
attachments
|
|
498
|
+
}) {
|
|
330
499
|
const genAI = createGoogleGenAI(runtime);
|
|
331
500
|
if (!genAI) {
|
|
332
501
|
throw new Error("Google Generative AI client not initialized");
|
|
333
502
|
}
|
|
334
|
-
const modelName =
|
|
335
|
-
|
|
503
|
+
const modelName = getModelNameForType(runtime, TEXT_LARGE_MODEL_TYPE);
|
|
504
|
+
import_core6.logger.log(`[TEXT_LARGE] Using model: ${modelName}`);
|
|
336
505
|
try {
|
|
337
506
|
const systemInstruction = runtime.character.system || undefined;
|
|
338
507
|
const response = await genAI.models.generateContent({
|
|
339
508
|
model: modelName,
|
|
340
|
-
contents: prompt,
|
|
509
|
+
contents: (attachments?.length ?? 0) > 0 ? [{ role: "user", parts: buildPromptParts(prompt, attachments) }] : prompt,
|
|
341
510
|
config: {
|
|
342
511
|
temperature,
|
|
343
512
|
topK: 40,
|
|
@@ -351,29 +520,50 @@ async function handleTextSmall(runtime, { prompt, stopSequences = [], maxTokens
|
|
|
351
520
|
const text = response.text || "";
|
|
352
521
|
const promptTokens = await countTokens(prompt);
|
|
353
522
|
const completionTokens = await countTokens(text);
|
|
354
|
-
emitModelUsageEvent(runtime,
|
|
523
|
+
emitModelUsageEvent(runtime, TEXT_LARGE_MODEL_TYPE, prompt, {
|
|
355
524
|
promptTokens,
|
|
356
525
|
completionTokens,
|
|
357
526
|
totalTokens: promptTokens + completionTokens
|
|
358
527
|
});
|
|
359
528
|
return text;
|
|
360
529
|
} catch (error) {
|
|
361
|
-
|
|
530
|
+
import_core6.logger.error(`[TEXT_LARGE] Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
362
531
|
throw error;
|
|
363
532
|
}
|
|
364
533
|
}
|
|
365
|
-
async function
|
|
534
|
+
async function handleTextNano(runtime, params) {
|
|
535
|
+
return handleTextWithType(runtime, TEXT_NANO_MODEL_TYPE, params);
|
|
536
|
+
}
|
|
537
|
+
async function handleTextMedium(runtime, params) {
|
|
538
|
+
return handleTextWithType(runtime, TEXT_MEDIUM_MODEL_TYPE, params);
|
|
539
|
+
}
|
|
540
|
+
async function handleTextMega(runtime, params) {
|
|
541
|
+
return handleTextWithType(runtime, TEXT_MEGA_MODEL_TYPE, params);
|
|
542
|
+
}
|
|
543
|
+
async function handleResponseHandler(runtime, params) {
|
|
544
|
+
return handleTextWithType(runtime, RESPONSE_HANDLER_MODEL_TYPE, params);
|
|
545
|
+
}
|
|
546
|
+
async function handleActionPlanner(runtime, params) {
|
|
547
|
+
return handleTextWithType(runtime, ACTION_PLANNER_MODEL_TYPE, params);
|
|
548
|
+
}
|
|
549
|
+
async function handleTextWithType(runtime, modelType, {
|
|
550
|
+
prompt,
|
|
551
|
+
stopSequences = [],
|
|
552
|
+
maxTokens = 8192,
|
|
553
|
+
temperature = 0.7,
|
|
554
|
+
attachments
|
|
555
|
+
}) {
|
|
366
556
|
const genAI = createGoogleGenAI(runtime);
|
|
367
557
|
if (!genAI) {
|
|
368
558
|
throw new Error("Google Generative AI client not initialized");
|
|
369
559
|
}
|
|
370
|
-
const modelName =
|
|
371
|
-
|
|
560
|
+
const modelName = getModelNameForType(runtime, modelType);
|
|
561
|
+
import_core6.logger.log(`[${modelType}] Using model: ${modelName}`);
|
|
372
562
|
try {
|
|
373
563
|
const systemInstruction = runtime.character.system || undefined;
|
|
374
564
|
const response = await genAI.models.generateContent({
|
|
375
565
|
model: modelName,
|
|
376
|
-
contents: prompt,
|
|
566
|
+
contents: (attachments?.length ?? 0) > 0 ? [{ role: "user", parts: buildPromptParts(prompt, attachments) }] : prompt,
|
|
377
567
|
config: {
|
|
378
568
|
temperature,
|
|
379
569
|
topK: 40,
|
|
@@ -387,18 +577,30 @@ async function handleTextLarge(runtime, { prompt, stopSequences = [], maxTokens
|
|
|
387
577
|
const text = response.text || "";
|
|
388
578
|
const promptTokens = await countTokens(prompt);
|
|
389
579
|
const completionTokens = await countTokens(text);
|
|
390
|
-
emitModelUsageEvent(runtime,
|
|
580
|
+
emitModelUsageEvent(runtime, modelType, prompt, {
|
|
391
581
|
promptTokens,
|
|
392
582
|
completionTokens,
|
|
393
583
|
totalTokens: promptTokens + completionTokens
|
|
394
584
|
});
|
|
395
585
|
return text;
|
|
396
586
|
} catch (error) {
|
|
397
|
-
|
|
587
|
+
import_core6.logger.error(`[${modelType}] Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
398
588
|
throw error;
|
|
399
589
|
}
|
|
400
590
|
}
|
|
401
591
|
// index.ts
|
|
592
|
+
var CORE_MODEL_TYPES2 = ElizaCore3.ModelType ?? {};
|
|
593
|
+
var TEXT_NANO_MODEL_TYPE2 = CORE_MODEL_TYPES2.TEXT_NANO ?? "TEXT_NANO";
|
|
594
|
+
var TEXT_MEDIUM_MODEL_TYPE2 = CORE_MODEL_TYPES2.TEXT_MEDIUM ?? "TEXT_MEDIUM";
|
|
595
|
+
var TEXT_SMALL_MODEL_TYPE2 = CORE_MODEL_TYPES2.TEXT_SMALL ?? "TEXT_SMALL";
|
|
596
|
+
var TEXT_LARGE_MODEL_TYPE2 = CORE_MODEL_TYPES2.TEXT_LARGE ?? "TEXT_LARGE";
|
|
597
|
+
var TEXT_EMBEDDING_MODEL_TYPE2 = CORE_MODEL_TYPES2.TEXT_EMBEDDING ?? "TEXT_EMBEDDING";
|
|
598
|
+
var IMAGE_DESCRIPTION_MODEL_TYPE = CORE_MODEL_TYPES2.IMAGE_DESCRIPTION ?? "IMAGE_DESCRIPTION";
|
|
599
|
+
var OBJECT_SMALL_MODEL_TYPE = CORE_MODEL_TYPES2.OBJECT_SMALL ?? "OBJECT_SMALL";
|
|
600
|
+
var OBJECT_LARGE_MODEL_TYPE = CORE_MODEL_TYPES2.OBJECT_LARGE ?? "OBJECT_LARGE";
|
|
601
|
+
var TEXT_MEGA_MODEL_TYPE2 = CORE_MODEL_TYPES2.TEXT_MEGA ?? "TEXT_MEGA";
|
|
602
|
+
var RESPONSE_HANDLER_MODEL_TYPE2 = CORE_MODEL_TYPES2.RESPONSE_HANDLER ?? "RESPONSE_HANDLER";
|
|
603
|
+
var ACTION_PLANNER_MODEL_TYPE2 = CORE_MODEL_TYPES2.ACTION_PLANNER ?? "ACTION_PLANNER";
|
|
402
604
|
var pluginTests = [
|
|
403
605
|
{
|
|
404
606
|
name: "google_genai_plugin_tests",
|
|
@@ -416,22 +618,22 @@ var pluginTests = [
|
|
|
416
618
|
for await (const model of modelList) {
|
|
417
619
|
models.push(model);
|
|
418
620
|
}
|
|
419
|
-
|
|
621
|
+
import_core7.logger.log(`Available models: ${models.length}`);
|
|
420
622
|
}
|
|
421
623
|
},
|
|
422
624
|
{
|
|
423
625
|
name: "google_test_text_embedding",
|
|
424
626
|
fn: async (runtime) => {
|
|
425
627
|
try {
|
|
426
|
-
const embedding = await runtime.useModel(
|
|
628
|
+
const embedding = await runtime.useModel(import_core7.ModelType.TEXT_EMBEDDING, {
|
|
427
629
|
text: "Hello, world!"
|
|
428
630
|
});
|
|
429
|
-
|
|
631
|
+
import_core7.logger.log(`Embedding dimension: ${embedding.length}`);
|
|
430
632
|
if (embedding.length === 0) {
|
|
431
633
|
throw new Error("Failed to generate embedding");
|
|
432
634
|
}
|
|
433
635
|
} catch (error) {
|
|
434
|
-
|
|
636
|
+
import_core7.logger.error(`Error in test_text_embedding: ${error instanceof Error ? error.message : String(error)}`);
|
|
435
637
|
throw error;
|
|
436
638
|
}
|
|
437
639
|
}
|
|
@@ -440,15 +642,15 @@ var pluginTests = [
|
|
|
440
642
|
name: "google_test_text_small",
|
|
441
643
|
fn: async (runtime) => {
|
|
442
644
|
try {
|
|
443
|
-
const text = await runtime.useModel(
|
|
645
|
+
const text = await runtime.useModel(import_core7.ModelType.TEXT_SMALL, {
|
|
444
646
|
prompt: "What is the nature of reality in 10 words?"
|
|
445
647
|
});
|
|
446
648
|
if (text.length === 0) {
|
|
447
649
|
throw new Error("Failed to generate text");
|
|
448
650
|
}
|
|
449
|
-
|
|
651
|
+
import_core7.logger.log("Generated with TEXT_SMALL:", text);
|
|
450
652
|
} catch (error) {
|
|
451
|
-
|
|
653
|
+
import_core7.logger.error(`Error in test_text_small: ${error instanceof Error ? error.message : String(error)}`);
|
|
452
654
|
throw error;
|
|
453
655
|
}
|
|
454
656
|
}
|
|
@@ -457,15 +659,15 @@ var pluginTests = [
|
|
|
457
659
|
name: "google_test_text_large",
|
|
458
660
|
fn: async (runtime) => {
|
|
459
661
|
try {
|
|
460
|
-
const text = await runtime.useModel(
|
|
662
|
+
const text = await runtime.useModel(import_core7.ModelType.TEXT_LARGE, {
|
|
461
663
|
prompt: "Explain quantum mechanics in simple terms."
|
|
462
664
|
});
|
|
463
665
|
if (text.length === 0) {
|
|
464
666
|
throw new Error("Failed to generate text");
|
|
465
667
|
}
|
|
466
|
-
|
|
668
|
+
import_core7.logger.log("Generated with TEXT_LARGE:", `${text.substring(0, 100)}...`);
|
|
467
669
|
} catch (error) {
|
|
468
|
-
|
|
670
|
+
import_core7.logger.error(`Error in test_text_large: ${error instanceof Error ? error.message : String(error)}`);
|
|
469
671
|
throw error;
|
|
470
672
|
}
|
|
471
673
|
}
|
|
@@ -474,14 +676,14 @@ var pluginTests = [
|
|
|
474
676
|
name: "google_test_image_description",
|
|
475
677
|
fn: async (runtime) => {
|
|
476
678
|
try {
|
|
477
|
-
const result = await runtime.useModel(
|
|
478
|
-
if (result && typeof result === "object" && "title" in result && "description" in result) {
|
|
479
|
-
|
|
679
|
+
const result = await runtime.useModel(import_core7.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");
|
|
680
|
+
if (result != null && typeof result === "object" && "title" in result && "description" in result) {
|
|
681
|
+
import_core7.logger.log("Image description:", JSON.stringify(result));
|
|
480
682
|
} else {
|
|
481
|
-
|
|
683
|
+
import_core7.logger.error(`Invalid image description result format: ${JSON.stringify(result)}`);
|
|
482
684
|
}
|
|
483
685
|
} catch (error) {
|
|
484
|
-
|
|
686
|
+
import_core7.logger.error(`Error in test_image_description: ${error instanceof Error ? error.message : String(error)}`);
|
|
485
687
|
throw error;
|
|
486
688
|
}
|
|
487
689
|
}
|
|
@@ -499,16 +701,16 @@ var pluginTests = [
|
|
|
499
701
|
},
|
|
500
702
|
required: ["name", "age", "hobbies"]
|
|
501
703
|
};
|
|
502
|
-
const result = await runtime.useModel(
|
|
704
|
+
const result = await runtime.useModel(import_core7.ModelType.OBJECT_SMALL, {
|
|
503
705
|
prompt: "Generate a person profile with name, age, and hobbies.",
|
|
504
706
|
schema
|
|
505
707
|
});
|
|
506
|
-
|
|
507
|
-
if (!result
|
|
708
|
+
import_core7.logger.log("Generated object:", JSON.stringify(result));
|
|
709
|
+
if (!result?.name || !result?.age || !result?.hobbies) {
|
|
508
710
|
throw new Error("Generated object missing required fields");
|
|
509
711
|
}
|
|
510
712
|
} catch (error) {
|
|
511
|
-
|
|
713
|
+
import_core7.logger.error(`Error in test_object_generation: ${error instanceof Error ? error.message : String(error)}`);
|
|
512
714
|
throw error;
|
|
513
715
|
}
|
|
514
716
|
}
|
|
@@ -528,39 +730,71 @@ var googleGenAIPlugin = {
|
|
|
528
730
|
description: "Google Generative AI plugin for Gemini models",
|
|
529
731
|
config: {
|
|
530
732
|
GOOGLE_GENERATIVE_AI_API_KEY: env.GOOGLE_GENERATIVE_AI_API_KEY ?? null,
|
|
733
|
+
GOOGLE_NANO_MODEL: env.GOOGLE_NANO_MODEL ?? null,
|
|
734
|
+
GOOGLE_MEDIUM_MODEL: env.GOOGLE_MEDIUM_MODEL ?? null,
|
|
531
735
|
GOOGLE_SMALL_MODEL: env.GOOGLE_SMALL_MODEL ?? null,
|
|
532
736
|
GOOGLE_LARGE_MODEL: env.GOOGLE_LARGE_MODEL ?? null,
|
|
737
|
+
GOOGLE_MEGA_MODEL: env.GOOGLE_MEGA_MODEL ?? null,
|
|
738
|
+
GOOGLE_RESPONSE_HANDLER_MODEL: env.GOOGLE_RESPONSE_HANDLER_MODEL ?? null,
|
|
739
|
+
GOOGLE_SHOULD_RESPOND_MODEL: env.GOOGLE_SHOULD_RESPOND_MODEL ?? null,
|
|
740
|
+
GOOGLE_ACTION_PLANNER_MODEL: env.GOOGLE_ACTION_PLANNER_MODEL ?? null,
|
|
741
|
+
GOOGLE_PLANNER_MODEL: env.GOOGLE_PLANNER_MODEL ?? null,
|
|
533
742
|
GOOGLE_IMAGE_MODEL: env.GOOGLE_IMAGE_MODEL ?? null,
|
|
534
743
|
GOOGLE_EMBEDDING_MODEL: env.GOOGLE_EMBEDDING_MODEL ?? null,
|
|
744
|
+
NANO_MODEL: env.NANO_MODEL ?? null,
|
|
745
|
+
MEDIUM_MODEL: env.MEDIUM_MODEL ?? null,
|
|
535
746
|
SMALL_MODEL: env.SMALL_MODEL ?? null,
|
|
536
747
|
LARGE_MODEL: env.LARGE_MODEL ?? null,
|
|
748
|
+
MEGA_MODEL: env.MEGA_MODEL ?? null,
|
|
749
|
+
RESPONSE_HANDLER_MODEL: env.RESPONSE_HANDLER_MODEL ?? null,
|
|
750
|
+
SHOULD_RESPOND_MODEL: env.SHOULD_RESPOND_MODEL ?? null,
|
|
751
|
+
ACTION_PLANNER_MODEL: env.ACTION_PLANNER_MODEL ?? null,
|
|
752
|
+
PLANNER_MODEL: env.PLANNER_MODEL ?? null,
|
|
537
753
|
IMAGE_MODEL: env.IMAGE_MODEL ?? null
|
|
538
754
|
},
|
|
539
755
|
async init(config, runtime) {
|
|
540
756
|
initializeGoogleGenAI(config, runtime);
|
|
541
757
|
},
|
|
542
758
|
models: {
|
|
543
|
-
[
|
|
759
|
+
[TEXT_NANO_MODEL_TYPE2]: async (runtime, params) => {
|
|
760
|
+
return handleTextNano(runtime, params);
|
|
761
|
+
},
|
|
762
|
+
[TEXT_MEDIUM_MODEL_TYPE2]: async (runtime, params) => {
|
|
763
|
+
return handleTextMedium(runtime, params);
|
|
764
|
+
},
|
|
765
|
+
[TEXT_SMALL_MODEL_TYPE2]: async (runtime, params) => {
|
|
544
766
|
return handleTextSmall(runtime, params);
|
|
545
767
|
},
|
|
546
|
-
[
|
|
768
|
+
[TEXT_LARGE_MODEL_TYPE2]: async (runtime, params) => {
|
|
547
769
|
return handleTextLarge(runtime, params);
|
|
548
770
|
},
|
|
549
|
-
[
|
|
771
|
+
[TEXT_MEGA_MODEL_TYPE2]: async (runtime, params) => {
|
|
772
|
+
return handleTextMega(runtime, params);
|
|
773
|
+
},
|
|
774
|
+
[RESPONSE_HANDLER_MODEL_TYPE2]: async (runtime, params) => {
|
|
775
|
+
return handleResponseHandler(runtime, params);
|
|
776
|
+
},
|
|
777
|
+
[ACTION_PLANNER_MODEL_TYPE2]: async (runtime, params) => {
|
|
778
|
+
return handleActionPlanner(runtime, params);
|
|
779
|
+
},
|
|
780
|
+
[TEXT_EMBEDDING_MODEL_TYPE2]: async (runtime, params) => {
|
|
550
781
|
return handleTextEmbedding(runtime, params);
|
|
551
782
|
},
|
|
552
|
-
[
|
|
783
|
+
[IMAGE_DESCRIPTION_MODEL_TYPE]: async (runtime, params) => {
|
|
553
784
|
return handleImageDescription(runtime, params);
|
|
554
785
|
},
|
|
555
|
-
[
|
|
786
|
+
[OBJECT_SMALL_MODEL_TYPE]: async (runtime, params) => {
|
|
556
787
|
return handleObjectSmall(runtime, params);
|
|
557
788
|
},
|
|
558
|
-
[
|
|
789
|
+
[OBJECT_LARGE_MODEL_TYPE]: async (runtime, params) => {
|
|
559
790
|
return handleObjectLarge(runtime, params);
|
|
560
791
|
}
|
|
561
792
|
},
|
|
562
793
|
tests: pluginTests
|
|
563
794
|
};
|
|
564
|
-
var
|
|
795
|
+
var plugin_google_genai_default = googleGenAIPlugin;
|
|
796
|
+
|
|
797
|
+
// index.node.ts
|
|
798
|
+
var index_node_default = plugin_google_genai_default;
|
|
565
799
|
|
|
566
|
-
//# debugId=
|
|
800
|
+
//# debugId=43A781C1488C22D064756E2164756E21
|