@elizaos/plugin-elizacloud 1.5.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,796 @@
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
+ var __toESM = (mod, isNodeMode, target) => {
8
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
9
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
+ for (let key of __getOwnPropNames(mod))
11
+ if (!__hasOwnProp.call(to, key))
12
+ __defProp(to, key, {
13
+ get: () => mod[key],
14
+ enumerable: true
15
+ });
16
+ return to;
17
+ };
18
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
19
+ var __toCommonJS = (from) => {
20
+ var entry = __moduleCache.get(from), desc;
21
+ if (entry)
22
+ return entry;
23
+ entry = __defProp({}, "__esModule", { value: true });
24
+ if (from && typeof from === "object" || typeof from === "function")
25
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
26
+ get: () => from[key],
27
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
28
+ }));
29
+ __moduleCache.set(from, entry);
30
+ return entry;
31
+ };
32
+ var __export = (target, all) => {
33
+ for (var name in all)
34
+ __defProp(target, name, {
35
+ get: all[name],
36
+ enumerable: true,
37
+ configurable: true,
38
+ set: (newValue) => all[name] = () => newValue
39
+ });
40
+ };
41
+
42
+ // src/index.node.ts
43
+ var exports_index_node = {};
44
+ __export(exports_index_node, {
45
+ elizaOSCloudPlugin: () => elizaOSCloudPlugin,
46
+ default: () => src_default
47
+ });
48
+ module.exports = __toCommonJS(exports_index_node);
49
+
50
+ // src/index.ts
51
+ var import_core10 = require("@elizaos/core");
52
+
53
+ // src/init.ts
54
+ var import_core2 = require("@elizaos/core");
55
+
56
+ // src/utils/config.ts
57
+ var import_core = require("@elizaos/core");
58
+ function getSetting(runtime, key, defaultValue) {
59
+ return runtime.getSetting(key) ?? process.env[key] ?? defaultValue;
60
+ }
61
+ function isBrowser() {
62
+ return typeof globalThis !== "undefined" && typeof globalThis.document !== "undefined";
63
+ }
64
+ function isProxyMode(runtime) {
65
+ return isBrowser() && !!getSetting(runtime, "ELIZAOS_CLOUD_BROWSER_BASE_URL");
66
+ }
67
+ function getAuthHeader(runtime, forEmbedding = false) {
68
+ if (isBrowser())
69
+ return {};
70
+ const key = forEmbedding ? getEmbeddingApiKey(runtime) : getApiKey(runtime);
71
+ return key ? { Authorization: `Bearer ${key}` } : {};
72
+ }
73
+ function getBaseURL(runtime) {
74
+ const browserURL = getSetting(runtime, "ELIZAOS_CLOUD_BROWSER_BASE_URL");
75
+ const baseURL = isBrowser() && browserURL ? browserURL : getSetting(runtime, "ELIZAOS_CLOUD_BASE_URL", "https://www.elizacloud.ai/api/v1");
76
+ import_core.logger.debug(`[ELIZAOS_CLOUD] Default base URL: ${baseURL}`);
77
+ return baseURL;
78
+ }
79
+ function getEmbeddingBaseURL(runtime) {
80
+ const embeddingURL = isBrowser() ? getSetting(runtime, "ELIZAOS_CLOUD_BROWSER_EMBEDDING_URL") || getSetting(runtime, "ELIZAOS_CLOUD_BROWSER_BASE_URL") : getSetting(runtime, "ELIZAOS_CLOUD_EMBEDDING_URL");
81
+ if (embeddingURL) {
82
+ import_core.logger.debug(`[ELIZAOS_CLOUD] Using specific embedding base URL: ${embeddingURL}`);
83
+ return embeddingURL;
84
+ }
85
+ import_core.logger.debug("[ELIZAOS_CLOUD] Falling back to general base URL for embeddings.");
86
+ return getBaseURL(runtime);
87
+ }
88
+ function getApiKey(runtime) {
89
+ return getSetting(runtime, "ELIZAOS_CLOUD_API_KEY");
90
+ }
91
+ function getEmbeddingApiKey(runtime) {
92
+ const embeddingApiKey = getSetting(runtime, "ELIZAOS_CLOUD_EMBEDDING_API_KEY");
93
+ if (embeddingApiKey) {
94
+ import_core.logger.debug("[ELIZAOS_CLOUD] Using specific embedding API key (present)");
95
+ return embeddingApiKey;
96
+ }
97
+ import_core.logger.debug("[ELIZAOS_CLOUD] Falling back to general API key for embeddings.");
98
+ return getApiKey(runtime);
99
+ }
100
+ function getSmallModel(runtime) {
101
+ return getSetting(runtime, "ELIZAOS_CLOUD_SMALL_MODEL") ?? getSetting(runtime, "SMALL_MODEL", "gpt-4o-mini");
102
+ }
103
+ function getLargeModel(runtime) {
104
+ return getSetting(runtime, "ELIZAOS_CLOUD_LARGE_MODEL") ?? getSetting(runtime, "LARGE_MODEL", "gpt-4o");
105
+ }
106
+ function getImageDescriptionModel(runtime) {
107
+ return getSetting(runtime, "ELIZAOS_CLOUD_IMAGE_DESCRIPTION_MODEL", "gpt-4o-mini") ?? "gpt-4o-mini";
108
+ }
109
+ function getExperimentalTelemetry(runtime) {
110
+ const setting = getSetting(runtime, "ELIZAOS_CLOUD_EXPERIMENTAL_TELEMETRY", "false");
111
+ const normalizedSetting = String(setting).toLowerCase();
112
+ const result = normalizedSetting === "true";
113
+ import_core.logger.debug(`[ELIZAOS_CLOUD] Experimental telemetry in function: "${setting}" (type: ${typeof setting}, normalized: "${normalizedSetting}", result: ${result})`);
114
+ return result;
115
+ }
116
+
117
+ // src/init.ts
118
+ function initializeOpenAI(_config, runtime) {
119
+ new Promise(async (resolve) => {
120
+ resolve();
121
+ try {
122
+ if (!getApiKey(runtime) && !isBrowser()) {
123
+ import_core2.logger.warn("ELIZAOS_CLOUD_API_KEY is not set in environment - ElizaOS Cloud functionality will be limited");
124
+ import_core2.logger.info("Get your API key from https://www.elizacloud.ai/dashboard/api-keys");
125
+ return;
126
+ }
127
+ try {
128
+ const baseURL = getBaseURL(runtime);
129
+ const response = await fetch(`${baseURL}/models`, {
130
+ headers: { ...getAuthHeader(runtime) }
131
+ });
132
+ if (!response.ok) {
133
+ import_core2.logger.warn(`ElizaOS Cloud API key validation failed: ${response.statusText}`);
134
+ import_core2.logger.warn("ElizaOS Cloud functionality will be limited until a valid API key is provided");
135
+ import_core2.logger.info("Get your API key from https://www.elizacloud.ai/dashboard/api-keys");
136
+ } else {
137
+ import_core2.logger.log("ElizaOS Cloud API key validated successfully");
138
+ }
139
+ } catch (fetchError) {
140
+ const message = fetchError instanceof Error ? fetchError.message : String(fetchError);
141
+ import_core2.logger.warn(`Error validating ElizaOS Cloud API key: ${message}`);
142
+ import_core2.logger.warn("ElizaOS Cloud functionality will be limited until a valid API key is provided");
143
+ }
144
+ } catch (error) {
145
+ const message = error?.errors?.map((e) => e.message).join(", ") || (error instanceof Error ? error.message : String(error));
146
+ import_core2.logger.warn(`ElizaOS Cloud plugin configuration issue: ${message} - You need to configure the ELIZAOS_CLOUD_API_KEY in your environment variables`);
147
+ import_core2.logger.info("Get your API key from https://www.elizacloud.ai/dashboard/api-keys");
148
+ }
149
+ });
150
+ }
151
+
152
+ // src/models/text.ts
153
+ var import_core4 = require("@elizaos/core");
154
+ var import_ai = require("ai");
155
+
156
+ // src/providers/openai.ts
157
+ var import_openai = require("@ai-sdk/openai");
158
+ function createOpenAIClient(runtime) {
159
+ const baseURL = getBaseURL(runtime);
160
+ const apiKey = getApiKey(runtime) ?? (isProxyMode(runtime) ? "eliza-proxy" : undefined);
161
+ return import_openai.createOpenAI({ apiKey: apiKey ?? "", baseURL });
162
+ }
163
+
164
+ // src/utils/events.ts
165
+ var import_core3 = require("@elizaos/core");
166
+ function emitModelUsageEvent(runtime, type, prompt, usage) {
167
+ runtime.emitEvent(import_core3.EventType.MODEL_USED, {
168
+ provider: "openai",
169
+ type,
170
+ prompt,
171
+ tokens: {
172
+ prompt: usage.inputTokens,
173
+ completion: usage.outputTokens,
174
+ total: usage.totalTokens
175
+ }
176
+ });
177
+ }
178
+
179
+ // src/models/text.ts
180
+ async function handleTextSmall(runtime, {
181
+ prompt,
182
+ stopSequences = [],
183
+ maxTokens = 8192,
184
+ temperature = 0.7,
185
+ frequencyPenalty = 0.7,
186
+ presencePenalty = 0.7
187
+ }) {
188
+ const openai = createOpenAIClient(runtime);
189
+ const modelName = getSmallModel(runtime);
190
+ const experimentalTelemetry = getExperimentalTelemetry(runtime);
191
+ import_core4.logger.log(`[ELIZAOS_CLOUD] Using TEXT_SMALL model: ${modelName}`);
192
+ import_core4.logger.log(prompt);
193
+ const { text: openaiResponse, usage } = await import_ai.generateText({
194
+ model: openai.languageModel(modelName),
195
+ prompt,
196
+ system: runtime.character.system ?? undefined,
197
+ temperature,
198
+ maxOutputTokens: maxTokens,
199
+ frequencyPenalty,
200
+ presencePenalty,
201
+ stopSequences,
202
+ experimental_telemetry: {
203
+ isEnabled: experimentalTelemetry
204
+ }
205
+ });
206
+ if (usage) {
207
+ emitModelUsageEvent(runtime, import_core4.ModelType.TEXT_SMALL, prompt, usage);
208
+ }
209
+ return openaiResponse;
210
+ }
211
+ async function handleTextLarge(runtime, {
212
+ prompt,
213
+ stopSequences = [],
214
+ maxTokens = 8192,
215
+ temperature = 0.7,
216
+ frequencyPenalty = 0.7,
217
+ presencePenalty = 0.7
218
+ }) {
219
+ const openai = createOpenAIClient(runtime);
220
+ const modelName = getLargeModel(runtime);
221
+ const experimentalTelemetry = getExperimentalTelemetry(runtime);
222
+ import_core4.logger.log(`[ELIZAOS_CLOUD] Using TEXT_LARGE model: ${modelName}`);
223
+ import_core4.logger.log(prompt);
224
+ const { text: openaiResponse, usage } = await import_ai.generateText({
225
+ model: openai.languageModel(modelName),
226
+ prompt,
227
+ system: runtime.character.system ?? undefined,
228
+ temperature,
229
+ maxOutputTokens: maxTokens,
230
+ frequencyPenalty,
231
+ presencePenalty,
232
+ stopSequences,
233
+ experimental_telemetry: {
234
+ isEnabled: experimentalTelemetry
235
+ }
236
+ });
237
+ if (usage) {
238
+ emitModelUsageEvent(runtime, import_core4.ModelType.TEXT_LARGE, prompt, usage);
239
+ }
240
+ return openaiResponse;
241
+ }
242
+ // src/models/object.ts
243
+ var import_core6 = require("@elizaos/core");
244
+ var import_ai3 = require("ai");
245
+
246
+ // src/utils/helpers.ts
247
+ var import_core5 = require("@elizaos/core");
248
+ var import_ai2 = require("ai");
249
+ function getJsonRepairFunction() {
250
+ return async ({ text, error }) => {
251
+ try {
252
+ if (error instanceof import_ai2.JSONParseError) {
253
+ const cleanedText = text.replace(/```json\n|\n```|```/g, "");
254
+ JSON.parse(cleanedText);
255
+ return cleanedText;
256
+ }
257
+ return null;
258
+ } catch (jsonError) {
259
+ const message = jsonError instanceof Error ? jsonError.message : String(jsonError);
260
+ import_core5.logger.warn(`Failed to repair JSON text: ${message}`);
261
+ return null;
262
+ }
263
+ };
264
+ }
265
+ async function webStreamToNodeStream(webStream) {
266
+ try {
267
+ const { Readable } = await import("node:stream");
268
+ const reader = webStream.getReader();
269
+ return new Readable({
270
+ async read() {
271
+ try {
272
+ const { done, value } = await reader.read();
273
+ if (done) {
274
+ this.push(null);
275
+ } else {
276
+ this.push(value);
277
+ }
278
+ } catch (error) {
279
+ this.destroy(error);
280
+ }
281
+ },
282
+ destroy(error, callback) {
283
+ reader.cancel().finally(() => callback(error));
284
+ }
285
+ });
286
+ } catch (error) {
287
+ const message = error instanceof Error ? error.message : String(error);
288
+ import_core5.logger.error(`Failed to load node:stream module: ${message}`);
289
+ throw new Error(`Cannot convert stream: node:stream module unavailable. This feature requires a Node.js environment.`);
290
+ }
291
+ }
292
+ function parseImageDescriptionResponse(responseText) {
293
+ const titleMatch = responseText.match(/title[:\s]+(.+?)(?:\n|$)/i);
294
+ const title = titleMatch?.[1]?.trim() || "Image Analysis";
295
+ const description = responseText.replace(/title[:\s]+(.+?)(?:\n|$)/i, "").trim();
296
+ return { title, description };
297
+ }
298
+
299
+ // src/models/object.ts
300
+ async function generateObjectByModelType(runtime, params, modelType, getModelFn) {
301
+ const openai = createOpenAIClient(runtime);
302
+ const modelName = getModelFn(runtime);
303
+ import_core6.logger.log(`[ELIZAOS_CLOUD] Using ${modelType} model: ${modelName}`);
304
+ const temperature = params.temperature ?? 0;
305
+ const schemaPresent = !!params.schema;
306
+ if (schemaPresent) {
307
+ import_core6.logger.info(`Using ${modelType} without schema validation (schema provided but output=no-schema)`);
308
+ }
309
+ try {
310
+ const { object, usage } = await import_ai3.generateObject({
311
+ model: openai.languageModel(modelName),
312
+ output: "no-schema",
313
+ prompt: params.prompt,
314
+ temperature,
315
+ experimental_repairText: getJsonRepairFunction()
316
+ });
317
+ if (usage) {
318
+ emitModelUsageEvent(runtime, modelType, params.prompt, usage);
319
+ }
320
+ return object;
321
+ } catch (error) {
322
+ if (error instanceof import_ai3.JSONParseError) {
323
+ import_core6.logger.error(`[generateObject] Failed to parse JSON: ${error.message}`);
324
+ const repairFunction = getJsonRepairFunction();
325
+ const repairedJsonString = await repairFunction({
326
+ text: error.text,
327
+ error
328
+ });
329
+ if (repairedJsonString) {
330
+ try {
331
+ const repairedObject = JSON.parse(repairedJsonString);
332
+ import_core6.logger.info("[generateObject] Successfully repaired JSON.");
333
+ return repairedObject;
334
+ } catch (repairParseError) {
335
+ const message = repairParseError instanceof Error ? repairParseError.message : String(repairParseError);
336
+ import_core6.logger.error(`[generateObject] Failed to parse repaired JSON: ${message}`);
337
+ throw repairParseError;
338
+ }
339
+ } else {
340
+ import_core6.logger.error("[generateObject] JSON repair failed.");
341
+ throw error;
342
+ }
343
+ } else {
344
+ const message = error instanceof Error ? error.message : String(error);
345
+ import_core6.logger.error(`[generateObject] Unknown error: ${message}`);
346
+ throw error;
347
+ }
348
+ }
349
+ }
350
+ async function handleObjectSmall(runtime, params) {
351
+ return generateObjectByModelType(runtime, params, import_core6.ModelType.OBJECT_SMALL, getSmallModel);
352
+ }
353
+ async function handleObjectLarge(runtime, params) {
354
+ return generateObjectByModelType(runtime, params, import_core6.ModelType.OBJECT_LARGE, getLargeModel);
355
+ }
356
+ // src/models/embeddings.ts
357
+ var import_core7 = require("@elizaos/core");
358
+ async function handleTextEmbedding(runtime, params) {
359
+ const embeddingModelName = getSetting(runtime, "ELIZAOS_CLOUD_EMBEDDING_MODEL", "text-embedding-3-small");
360
+ const embeddingDimension = Number.parseInt(getSetting(runtime, "ELIZAOS_CLOUD_EMBEDDING_DIMENSIONS", "1536") || "1536", 10);
361
+ if (!Object.values(import_core7.VECTOR_DIMS).includes(embeddingDimension)) {
362
+ const errorMsg = `Invalid embedding dimension: ${embeddingDimension}. Must be one of: ${Object.values(import_core7.VECTOR_DIMS).join(", ")}`;
363
+ import_core7.logger.error(errorMsg);
364
+ throw new Error(errorMsg);
365
+ }
366
+ if (params === null) {
367
+ import_core7.logger.debug("Creating test embedding for initialization");
368
+ const testVector = Array(embeddingDimension).fill(0);
369
+ testVector[0] = 0.1;
370
+ return testVector;
371
+ }
372
+ let text;
373
+ if (typeof params === "string") {
374
+ text = params;
375
+ } else if (typeof params === "object" && params.text) {
376
+ text = params.text;
377
+ } else {
378
+ import_core7.logger.warn("Invalid input format for embedding");
379
+ const fallbackVector = Array(embeddingDimension).fill(0);
380
+ fallbackVector[0] = 0.2;
381
+ return fallbackVector;
382
+ }
383
+ if (!text.trim()) {
384
+ import_core7.logger.warn("Empty text for embedding");
385
+ const emptyVector = Array(embeddingDimension).fill(0);
386
+ emptyVector[0] = 0.3;
387
+ return emptyVector;
388
+ }
389
+ const embeddingBaseURL = getEmbeddingBaseURL(runtime);
390
+ try {
391
+ const response = await fetch(`${embeddingBaseURL}/embeddings`, {
392
+ method: "POST",
393
+ headers: {
394
+ ...getAuthHeader(runtime, true),
395
+ "Content-Type": "application/json"
396
+ },
397
+ body: JSON.stringify({
398
+ model: embeddingModelName,
399
+ input: text
400
+ })
401
+ });
402
+ if (!response.ok) {
403
+ import_core7.logger.error(`ElizaOS Cloud API error: ${response.status} - ${response.statusText}`);
404
+ const errorVector = Array(embeddingDimension).fill(0);
405
+ errorVector[0] = 0.4;
406
+ return errorVector;
407
+ }
408
+ const data = await response.json();
409
+ if (!data?.data?.[0]?.embedding) {
410
+ import_core7.logger.error("API returned invalid structure");
411
+ const errorVector = Array(embeddingDimension).fill(0);
412
+ errorVector[0] = 0.5;
413
+ return errorVector;
414
+ }
415
+ const embedding = data.data[0].embedding;
416
+ if (data.usage) {
417
+ const usage = {
418
+ inputTokens: data.usage.prompt_tokens,
419
+ outputTokens: 0,
420
+ totalTokens: data.usage.total_tokens
421
+ };
422
+ emitModelUsageEvent(runtime, import_core7.ModelType.TEXT_EMBEDDING, text, usage);
423
+ }
424
+ import_core7.logger.log(`Got valid embedding with length ${embedding.length}`);
425
+ return embedding;
426
+ } catch (error) {
427
+ const message = error instanceof Error ? error.message : String(error);
428
+ import_core7.logger.error(`Error generating embedding: ${message}`);
429
+ const errorVector = Array(embeddingDimension).fill(0);
430
+ errorVector[0] = 0.6;
431
+ return errorVector;
432
+ }
433
+ }
434
+ // src/models/image.ts
435
+ var import_core8 = require("@elizaos/core");
436
+ async function handleImageGeneration(runtime, params) {
437
+ const numImages = params.n || 1;
438
+ const size = params.size || "1024x1024";
439
+ const prompt = params.prompt;
440
+ const modelName = "google/gemini-2.5-flash-image-preview";
441
+ import_core8.logger.log(`[ELIZAOS_CLOUD] Using IMAGE model: ${modelName}`);
442
+ const baseURL = getBaseURL(runtime);
443
+ const aspectRatioMap = {
444
+ "1024x1024": "1:1",
445
+ "1792x1024": "16:9",
446
+ "1024x1792": "9:16"
447
+ };
448
+ const aspectRatio = aspectRatioMap[size] || "1:1";
449
+ try {
450
+ const response = await fetch(`${baseURL}/generate-image`, {
451
+ method: "POST",
452
+ headers: {
453
+ ...getAuthHeader(runtime),
454
+ "Content-Type": "application/json"
455
+ },
456
+ body: JSON.stringify({
457
+ prompt,
458
+ numImages,
459
+ aspectRatio
460
+ })
461
+ });
462
+ if (!response.ok) {
463
+ const errorText = await response.text();
464
+ throw new Error(`Failed to generate image: ${response.status} ${errorText}`);
465
+ }
466
+ const data = await response.json();
467
+ const typedData = data;
468
+ return typedData.images.map((img) => ({
469
+ url: img.url || img.image
470
+ }));
471
+ } catch (error) {
472
+ const message = error instanceof Error ? error.message : String(error);
473
+ import_core8.logger.error(`[ELIZAOS_CLOUD] Image generation error: ${message}`);
474
+ throw error;
475
+ }
476
+ }
477
+ async function handleImageDescription(runtime, params) {
478
+ let imageUrl;
479
+ let promptText;
480
+ const modelName = getImageDescriptionModel(runtime);
481
+ import_core8.logger.log(`[ELIZAOS_CLOUD] Using IMAGE_DESCRIPTION model: ${modelName}`);
482
+ const maxTokens = Number.parseInt(getSetting(runtime, "ELIZAOS_CLOUD_IMAGE_DESCRIPTION_MAX_TOKENS", "8192") || "8192", 10);
483
+ if (typeof params === "string") {
484
+ imageUrl = params;
485
+ promptText = "Please analyze this image and provide a title and detailed description.";
486
+ } else {
487
+ imageUrl = params.imageUrl;
488
+ promptText = params.prompt || "Please analyze this image and provide a title and detailed description.";
489
+ }
490
+ const messages = [
491
+ {
492
+ role: "user",
493
+ content: [
494
+ { type: "text", text: promptText },
495
+ { type: "image_url", image_url: { url: imageUrl } }
496
+ ]
497
+ }
498
+ ];
499
+ const baseURL = getBaseURL(runtime);
500
+ try {
501
+ const requestBody = {
502
+ model: modelName,
503
+ messages,
504
+ max_tokens: maxTokens
505
+ };
506
+ const response = await fetch(`${baseURL}/chat/completions`, {
507
+ method: "POST",
508
+ headers: {
509
+ "Content-Type": "application/json",
510
+ ...getAuthHeader(runtime)
511
+ },
512
+ body: JSON.stringify(requestBody)
513
+ });
514
+ if (!response.ok) {
515
+ throw new Error(`ElizaOS Cloud API error: ${response.status}`);
516
+ }
517
+ const result = await response.json();
518
+ const typedResult = result;
519
+ const content = typedResult.choices?.[0]?.message?.content;
520
+ if (typedResult.usage) {
521
+ emitModelUsageEvent(runtime, import_core8.ModelType.IMAGE_DESCRIPTION, typeof params === "string" ? params : params.prompt || "", {
522
+ inputTokens: typedResult.usage.prompt_tokens,
523
+ outputTokens: typedResult.usage.completion_tokens,
524
+ totalTokens: typedResult.usage.total_tokens
525
+ });
526
+ }
527
+ if (!content) {
528
+ return {
529
+ title: "Failed to analyze image",
530
+ description: "No response from API"
531
+ };
532
+ }
533
+ const isCustomPrompt = typeof params === "object" && params.prompt && params.prompt !== "Please analyze this image and provide a title and detailed description.";
534
+ if (isCustomPrompt) {
535
+ return content;
536
+ }
537
+ const processedResult = parseImageDescriptionResponse(content);
538
+ return processedResult;
539
+ } catch (error) {
540
+ const message = error instanceof Error ? error.message : String(error);
541
+ import_core8.logger.error(`Error analyzing image: ${message}`);
542
+ return {
543
+ title: "Failed to analyze image",
544
+ description: `Error: ${message}`
545
+ };
546
+ }
547
+ }
548
+ // src/models/speech.ts
549
+ var import_core9 = require("@elizaos/core");
550
+ async function fetchTextToSpeech(runtime, options) {
551
+ const defaultModel = getSetting(runtime, "ELIZAOS_CLOUD_TTS_MODEL", "gpt-4o-mini-tts");
552
+ const defaultVoice = getSetting(runtime, "ELIZAOS_CLOUD_TTS_VOICE", "nova");
553
+ const defaultInstructions = getSetting(runtime, "ELIZAOS_CLOUD_TTS_INSTRUCTIONS", "");
554
+ const baseURL = getBaseURL(runtime);
555
+ const model = options.model || defaultModel;
556
+ const voice = options.voice || defaultVoice;
557
+ const instructions = options.instructions ?? defaultInstructions;
558
+ const format = options.format || "mp3";
559
+ try {
560
+ const res = await fetch(`${baseURL}/audio/speech`, {
561
+ method: "POST",
562
+ headers: {
563
+ ...getAuthHeader(runtime),
564
+ "Content-Type": "application/json",
565
+ ...format === "mp3" ? { Accept: "audio/mpeg" } : {}
566
+ },
567
+ body: JSON.stringify({
568
+ model,
569
+ voice,
570
+ input: options.text,
571
+ format,
572
+ ...instructions && { instructions }
573
+ })
574
+ });
575
+ if (!res.ok) {
576
+ const err = await res.text();
577
+ throw new Error(`ElizaOS Cloud TTS error ${res.status}: ${err}`);
578
+ }
579
+ if (!res.body) {
580
+ throw new Error("ElizaOS Cloud TTS response body is null");
581
+ }
582
+ if (!isBrowser()) {
583
+ return await webStreamToNodeStream(res.body);
584
+ }
585
+ return res.body;
586
+ } catch (err) {
587
+ const message = err instanceof Error ? err.message : String(err);
588
+ throw new Error(`Failed to fetch speech from ElizaOS Cloud TTS: ${message}`);
589
+ }
590
+ }
591
+ // src/index.ts
592
+ var elizaOSCloudPlugin = {
593
+ name: "elizaOSCloud",
594
+ description: "ElizaOS Cloud plugin - Multi-model AI generation with text, image, and video support",
595
+ config: {
596
+ ELIZAOS_CLOUD_API_KEY: process.env.ELIZAOS_CLOUD_API_KEY,
597
+ ELIZAOS_CLOUD_BASE_URL: process.env.ELIZAOS_CLOUD_BASE_URL,
598
+ ELIZAOS_CLOUD_SMALL_MODEL: process.env.ELIZAOS_CLOUD_SMALL_MODEL,
599
+ ELIZAOS_CLOUD_LARGE_MODEL: process.env.ELIZAOS_CLOUD_LARGE_MODEL,
600
+ SMALL_MODEL: process.env.SMALL_MODEL,
601
+ LARGE_MODEL: process.env.LARGE_MODEL,
602
+ ELIZAOS_CLOUD_EMBEDDING_MODEL: process.env.ELIZAOS_CLOUD_EMBEDDING_MODEL,
603
+ ELIZAOS_CLOUD_EMBEDDING_API_KEY: process.env.ELIZAOS_CLOUD_EMBEDDING_API_KEY,
604
+ ELIZAOS_CLOUD_EMBEDDING_URL: process.env.ELIZAOS_CLOUD_EMBEDDING_URL,
605
+ ELIZAOS_CLOUD_EMBEDDING_DIMENSIONS: process.env.ELIZAOS_CLOUD_EMBEDDING_DIMENSIONS,
606
+ ELIZAOS_CLOUD_IMAGE_DESCRIPTION_MODEL: process.env.ELIZAOS_CLOUD_IMAGE_DESCRIPTION_MODEL,
607
+ ELIZAOS_CLOUD_IMAGE_DESCRIPTION_MAX_TOKENS: process.env.ELIZAOS_CLOUD_IMAGE_DESCRIPTION_MAX_TOKENS,
608
+ ELIZAOS_CLOUD_EXPERIMENTAL_TELEMETRY: process.env.ELIZAOS_CLOUD_EXPERIMENTAL_TELEMETRY
609
+ },
610
+ async init(config, runtime) {
611
+ initializeOpenAI(config, runtime);
612
+ },
613
+ models: {
614
+ [import_core10.ModelType.TEXT_EMBEDDING]: handleTextEmbedding,
615
+ [import_core10.ModelType.TEXT_SMALL]: handleTextSmall,
616
+ [import_core10.ModelType.TEXT_LARGE]: handleTextLarge,
617
+ [import_core10.ModelType.IMAGE]: handleImageGeneration,
618
+ [import_core10.ModelType.IMAGE_DESCRIPTION]: handleImageDescription,
619
+ [import_core10.ModelType.OBJECT_SMALL]: handleObjectSmall,
620
+ [import_core10.ModelType.OBJECT_LARGE]: handleObjectLarge
621
+ },
622
+ tests: [
623
+ {
624
+ name: "ELIZAOS_CLOUD_plugin_tests",
625
+ tests: [
626
+ {
627
+ name: "ELIZAOS_CLOUD_test_url_and_api_key_validation",
628
+ fn: async (runtime) => {
629
+ const baseURL = getBaseURL(runtime);
630
+ const response = await fetch(`${baseURL}/models`, {
631
+ headers: {
632
+ Authorization: `Bearer ${getApiKey(runtime)}`
633
+ }
634
+ });
635
+ const data = await response.json();
636
+ import_core10.logger.log({ data: data?.data?.length ?? "N/A" }, "Models Available");
637
+ if (!response.ok) {
638
+ throw new Error(`Failed to validate OpenAI API key: ${response.statusText}`);
639
+ }
640
+ }
641
+ },
642
+ {
643
+ name: "ELIZAOS_CLOUD_test_text_embedding",
644
+ fn: async (runtime) => {
645
+ try {
646
+ const embedding = await runtime.useModel(import_core10.ModelType.TEXT_EMBEDDING, {
647
+ text: "Hello, world!"
648
+ });
649
+ import_core10.logger.log({ embedding }, "embedding");
650
+ } catch (error) {
651
+ const message = error instanceof Error ? error.message : String(error);
652
+ import_core10.logger.error(`Error in test_text_embedding: ${message}`);
653
+ throw error;
654
+ }
655
+ }
656
+ },
657
+ {
658
+ name: "ELIZAOS_CLOUD_test_text_large",
659
+ fn: async (runtime) => {
660
+ try {
661
+ const text = await runtime.useModel(import_core10.ModelType.TEXT_LARGE, {
662
+ prompt: "What is the nature of reality in 10 words?"
663
+ });
664
+ if (text.length === 0) {
665
+ throw new Error("Failed to generate text");
666
+ }
667
+ import_core10.logger.log({ text }, "generated with test_text_large");
668
+ } catch (error) {
669
+ const message = error instanceof Error ? error.message : String(error);
670
+ import_core10.logger.error(`Error in test_text_large: ${message}`);
671
+ throw error;
672
+ }
673
+ }
674
+ },
675
+ {
676
+ name: "ELIZAOS_CLOUD_test_text_small",
677
+ fn: async (runtime) => {
678
+ try {
679
+ const text = await runtime.useModel(import_core10.ModelType.TEXT_SMALL, {
680
+ prompt: "What is the nature of reality in 10 words?"
681
+ });
682
+ if (text.length === 0) {
683
+ throw new Error("Failed to generate text");
684
+ }
685
+ import_core10.logger.log({ text }, "generated with test_text_small");
686
+ } catch (error) {
687
+ const message = error instanceof Error ? error.message : String(error);
688
+ import_core10.logger.error(`Error in test_text_small: ${message}`);
689
+ throw error;
690
+ }
691
+ }
692
+ },
693
+ {
694
+ name: "ELIZAOS_CLOUD_test_image_generation",
695
+ fn: async (runtime) => {
696
+ import_core10.logger.log("ELIZAOS_CLOUD_test_image_generation");
697
+ try {
698
+ const image = await runtime.useModel(import_core10.ModelType.IMAGE, {
699
+ prompt: "A beautiful sunset over a calm ocean",
700
+ n: 1,
701
+ size: "1024x1024"
702
+ });
703
+ import_core10.logger.log({ image }, "generated with test_image_generation");
704
+ } catch (error) {
705
+ const message = error instanceof Error ? error.message : String(error);
706
+ import_core10.logger.error(`Error in test_image_generation: ${message}`);
707
+ throw error;
708
+ }
709
+ }
710
+ },
711
+ {
712
+ name: "image-description",
713
+ fn: async (runtime) => {
714
+ try {
715
+ import_core10.logger.log("ELIZAOS_CLOUD_test_image_description");
716
+ try {
717
+ const result = await runtime.useModel(import_core10.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");
718
+ if (result && typeof result === "object" && "title" in result && "description" in result) {
719
+ import_core10.logger.log({ result }, "Image description");
720
+ } else {
721
+ import_core10.logger.error("Invalid image description result format:", result);
722
+ }
723
+ } catch (e) {
724
+ const message = e instanceof Error ? e.message : String(e);
725
+ import_core10.logger.error(`Error in image description test: ${message}`);
726
+ }
727
+ } catch (e) {
728
+ const message = e instanceof Error ? e.message : String(e);
729
+ import_core10.logger.error(`Error in ELIZAOS_CLOUD_test_image_description: ${message}`);
730
+ }
731
+ }
732
+ },
733
+ {
734
+ name: "ELIZAOS_CLOUD_test_transcription",
735
+ fn: async (runtime) => {
736
+ import_core10.logger.log("ELIZAOS_CLOUD_test_transcription");
737
+ try {
738
+ const response = await fetch("https://upload.wikimedia.org/wikipedia/en/4/40/Chris_Benoit_Voice_Message.ogg");
739
+ const arrayBuffer = await response.arrayBuffer();
740
+ const transcription = await runtime.useModel(import_core10.ModelType.TRANSCRIPTION, Buffer.from(new Uint8Array(arrayBuffer)));
741
+ import_core10.logger.log({ transcription }, "generated with test_transcription");
742
+ } catch (error) {
743
+ const message = error instanceof Error ? error.message : String(error);
744
+ import_core10.logger.error(`Error in test_transcription: ${message}`);
745
+ throw error;
746
+ }
747
+ }
748
+ },
749
+ {
750
+ name: "ELIZAOS_CLOUD_test_text_tokenizer_encode",
751
+ fn: async (runtime) => {
752
+ const prompt = "Hello tokenizer encode!";
753
+ const tokens = await runtime.useModel(import_core10.ModelType.TEXT_TOKENIZER_ENCODE, { prompt });
754
+ if (!Array.isArray(tokens) || tokens.length === 0) {
755
+ throw new Error("Failed to tokenize text: expected non-empty array of tokens");
756
+ }
757
+ import_core10.logger.log({ tokens }, "Tokenized output");
758
+ }
759
+ },
760
+ {
761
+ name: "ELIZAOS_CLOUD_test_text_tokenizer_decode",
762
+ fn: async (runtime) => {
763
+ const prompt = "Hello tokenizer decode!";
764
+ const tokens = await runtime.useModel(import_core10.ModelType.TEXT_TOKENIZER_ENCODE, { prompt });
765
+ const decodedText = await runtime.useModel(import_core10.ModelType.TEXT_TOKENIZER_DECODE, { tokens });
766
+ if (decodedText !== prompt) {
767
+ throw new Error(`Decoded text does not match original. Expected "${prompt}", got "${decodedText}"`);
768
+ }
769
+ import_core10.logger.log({ decodedText }, "Decoded text");
770
+ }
771
+ },
772
+ {
773
+ name: "ELIZAOS_CLOUD_test_text_to_speech",
774
+ fn: async (runtime) => {
775
+ try {
776
+ const response = await fetchTextToSpeech(runtime, {
777
+ text: "Hello, this is a test for text-to-speech."
778
+ });
779
+ if (!response) {
780
+ throw new Error("Failed to generate speech");
781
+ }
782
+ import_core10.logger.log("Generated speech successfully");
783
+ } catch (error) {
784
+ const message = error instanceof Error ? error.message : String(error);
785
+ import_core10.logger.error(`Error in ELIZAOS_CLOUD_test_text_to_speech: ${message}`);
786
+ throw error;
787
+ }
788
+ }
789
+ }
790
+ ]
791
+ }
792
+ ]
793
+ };
794
+ var src_default = elizaOSCloudPlugin;
795
+
796
+ //# debugId=62AC16B013B01D9364756E2164756E21