@elizaos/plugin-openai 1.0.11 → 1.5.11

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 CHANGED
@@ -26,7 +26,9 @@ The plugin requires these environment variables (can be set in .env file or char
26
26
  "OPENAI_EMBEDDING_DIMENSIONS": "1536",
27
27
  "OPENAI_IMAGE_DESCRIPTION_MODEL": "gpt-4o-mini",
28
28
  "OPENAI_IMAGE_DESCRIPTION_MAX_TOKENS": "8192",
29
- "OPENAI_EXPERIMENTAL_TELEMETRY": "false"
29
+ "OPENAI_EXPERIMENTAL_TELEMETRY": "false",
30
+ "OPENAI_BROWSER_BASE_URL": "https://your-proxy.example.com/openai",
31
+ "OPENAI_BROWSER_EMBEDDING_URL": "https://your-proxy.example.com/openai"
30
32
  }
31
33
  ```
32
34
 
@@ -45,6 +47,9 @@ OPENAI_EMBEDDING_DIMENSIONS=1536
45
47
  OPENAI_IMAGE_DESCRIPTION_MODEL=gpt-4o-mini
46
48
  OPENAI_IMAGE_DESCRIPTION_MAX_TOKENS=8192
47
49
  OPENAI_EXPERIMENTAL_TELEMETRY=false
50
+ # Browser proxy (frontend builds only)
51
+ OPENAI_BROWSER_BASE_URL=https://your-proxy.example.com/openai
52
+ OPENAI_BROWSER_EMBEDDING_URL=https://your-proxy.example.com/openai
48
53
  ```
49
54
 
50
55
  ### Configuration Options
@@ -60,6 +65,37 @@ OPENAI_EXPERIMENTAL_TELEMETRY=false
60
65
  - `OPENAI_IMAGE_DESCRIPTION_MODEL`: Model used for image description (default: "gpt-4o-mini")
61
66
  - `OPENAI_IMAGE_DESCRIPTION_MAX_TOKENS`: Maximum tokens for image descriptions (default: 8192)
62
67
  - `OPENAI_EXPERIMENTAL_TELEMETRY`: Enable experimental telemetry features for enhanced debugging and usage analytics (default: false)
68
+ - `OPENAI_BROWSER_BASE_URL`: Browser-only base URL to a proxy endpoint that forwards requests to OpenAI without exposing keys
69
+ - `OPENAI_BROWSER_EMBEDDING_URL`: Browser-only embeddings endpoint base URL
70
+
71
+ ### Browser mode and proxying
72
+
73
+ When bundled for the browser, this plugin avoids sending Authorization headers. Set `OPENAI_BROWSER_BASE_URL` (and optionally `OPENAI_BROWSER_EMBEDDING_URL`) to a server-side proxy you control that injects the OpenAI API key. This prevents exposing secrets in frontend builds.
74
+
75
+ Example minimal proxy (Express):
76
+
77
+ ```ts
78
+ import express from 'express';
79
+ import fetch from 'node-fetch';
80
+
81
+ const app = express();
82
+ app.use(express.json());
83
+
84
+ app.post('/openai/*', async (req, res) => {
85
+ const url = `https://api.openai.com/v1/${req.params[0]}`;
86
+ const r = await fetch(url, {
87
+ method: 'POST',
88
+ headers: {
89
+ 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
90
+ 'Content-Type': 'application/json',
91
+ },
92
+ body: JSON.stringify(req.body),
93
+ });
94
+ res.status(r.status).set(Object.fromEntries(r.headers)).send(await r.text());
95
+ });
96
+
97
+ app.listen(3000);
98
+ ```
63
99
 
64
100
  ### Experimental Telemetry
65
101
 
@@ -89,9 +125,9 @@ The plugin provides these model classes:
89
125
 
90
126
  ```js
91
127
  await runtime.useModel(ModelType.IMAGE, {
92
- prompt: 'A sunset over mountains',
128
+ prompt: "A sunset over mountains",
93
129
  n: 1, // number of images
94
- size: '1024x1024', // image resolution
130
+ size: "1024x1024", // image resolution
95
131
  });
96
132
  ```
97
133
 
@@ -109,15 +145,16 @@ const transcription = await runtime.useModel(
109
145
  ```js
110
146
  const { title, description } = await runtime.useModel(
111
147
  ModelType.IMAGE_DESCRIPTION,
112
- 'https://example.com/image.jpg'
148
+ "https://example.com/image.jpg"
113
149
  );
114
150
  ```
115
151
 
116
152
  ### Text Embeddings
117
153
 
118
154
  ```js
119
- const embedding = await runtime.useModel(
120
- ModelType.TEXT_EMBEDDING,
121
- 'text to embed'
122
- );
155
+ await runtime.useModel(ModelType.TEXT_EMBEDDING, "text to embed");
123
156
  ```
157
+
158
+ ### Tokenizer in browser
159
+
160
+ js-tiktoken is WASM and browser-safe; this plugin uses `encodingForModel` directly in both Node and browser builds.
@@ -0,0 +1,3 @@
1
+ import{createOpenAI as M}from"@ai-sdk/openai";import{EventType as c,logger as X,ModelType as _,VECTOR_DIMS as V}from"@elizaos/core";import{generateObject as T,generateText as A,JSONParseError as x}from"ai";import{encodingForModel as S}from"js-tiktoken";function J(Q,G,W){return Q.getSetting(G)??process.env[G]??W}function h(){return typeof globalThis<"u"&&typeof globalThis.document<"u"}function v(Q,G=!1){if(h())return{};let W=G?d(Q):D(Q);return W?{Authorization:`Bearer ${W}`}:{}}function K(Q){let G=J(Q,"OPENAI_BROWSER_BASE_URL"),W=h()&&G?G:J(Q,"OPENAI_BASE_URL","https://api.openai.com/v1");return X.debug(`[OpenAI] Default base URL: ${W}`),W}function y(Q){let G=h()?J(Q,"OPENAI_BROWSER_EMBEDDING_URL")||J(Q,"OPENAI_BROWSER_BASE_URL"):J(Q,"OPENAI_EMBEDDING_URL");if(G)return X.debug(`[OpenAI] Using specific embedding base URL: ${G}`),G;return X.debug("[OpenAI] Falling back to general base URL for embeddings."),K(Q)}function D(Q){return J(Q,"OPENAI_API_KEY")}function d(Q){let G=J(Q,"OPENAI_EMBEDDING_API_KEY");if(G)return X.debug("[OpenAI] Using specific embedding API key (present)"),G;return X.debug("[OpenAI] Falling back to general API key for embeddings."),D(Q)}function L(Q){return J(Q,"OPENAI_SMALL_MODEL")??J(Q,"SMALL_MODEL","gpt-5-nano")}function E(Q){return J(Q,"OPENAI_LARGE_MODEL")??J(Q,"LARGE_MODEL","gpt-5-mini")}function l(Q){return J(Q,"OPENAI_IMAGE_DESCRIPTION_MODEL","gpt-5-nano")??"gpt-5-nano"}function k(Q){let G=J(Q,"OPENAI_EXPERIMENTAL_TELEMETRY","false"),W=String(G).toLowerCase(),Y=W==="true";return X.debug(`[OpenAI] Experimental telemetry in function: "${G}" (type: ${typeof G}, normalized: "${W}", result: ${Y})`),Y}function P(Q){return M({apiKey:D(Q),baseURL:K(Q)})}async function p(Q,G){let W=Q===_.TEXT_SMALL?process.env.OPENAI_SMALL_MODEL??process.env.SMALL_MODEL??"gpt-5-nano":process.env.LARGE_MODEL??"gpt-5-mini";return S(W).encode(G)}async function u(Q,G){let W=Q===_.TEXT_SMALL?process.env.OPENAI_SMALL_MODEL??process.env.SMALL_MODEL??"gpt-5-nano":process.env.OPENAI_LARGE_MODEL??process.env.LARGE_MODEL??"gpt-5-mini";return S(W).decode(G)}async function B(Q,G,W,Y){let C=P(Q),I=Y(Q);X.log(`[OpenAI] Using ${W} model: ${I}`);let Z=G.temperature??0;if(!!G.schema)X.info(`Using ${W} without schema validation (schema provided but output=no-schema)`);try{let{object:F,usage:$}=await T({model:C.languageModel(I),output:"no-schema",prompt:G.prompt,temperature:Z,experimental_repairText:U()});if($)j(Q,W,G.prompt,$);return F}catch(F){if(F instanceof x){X.error(`[generateObject] Failed to parse JSON: ${F.message}`);let w=await U()({text:F.text,error:F});if(w)try{let H=JSON.parse(w);return X.info("[generateObject] Successfully repaired JSON."),H}catch(H){let N=H instanceof Error?H.message:String(H);throw X.error(`[generateObject] Failed to parse repaired JSON: ${N}`),H}else throw X.error("[generateObject] JSON repair failed."),F}else{let $=F instanceof Error?F.message:String(F);throw X.error(`[generateObject] Unknown error: ${$}`),F}}}function U(){return async({text:Q,error:G})=>{try{if(G instanceof x){let W=Q.replace(/```json\n|\n```|```/g,"");return JSON.parse(W),W}return null}catch(W){let Y=W instanceof Error?W.message:String(W);return X.warn(`Failed to repair JSON text: ${Y}`),null}}}function j(Q,G,W,Y){Q.emitEvent(c.MODEL_USED,{provider:"openai",type:G,prompt:W,tokens:{prompt:Y.inputTokens,completion:Y.outputTokens,total:Y.totalTokens}})}async function R(Q,G){let W=J(Q,"OPENAI_TTS_MODEL","gpt-4o-mini-tts"),Y=J(Q,"OPENAI_TTS_VOICE","nova"),C=J(Q,"OPENAI_TTS_INSTRUCTIONS",""),I=K(Q);try{let Z=await fetch(`${I}/audio/speech`,{method:"POST",headers:{...v(Q),"Content-Type":"application/json"},body:JSON.stringify({model:W,voice:Y,input:G,...C&&{instructions:C}})});if(!Z.ok){let z=await Z.text();throw Error(`OpenAI TTS error ${Z.status}: ${z}`)}return Z.body}catch(Z){let z=Z instanceof Error?Z.message:String(Z);throw Error(`Failed to fetch speech from OpenAI TTS: ${z}`)}}var s={name:"openai",description:"OpenAI plugin",config:{OPENAI_API_KEY:process.env.OPENAI_API_KEY,OPENAI_BASE_URL:process.env.OPENAI_BASE_URL,OPENAI_SMALL_MODEL:process.env.OPENAI_SMALL_MODEL,OPENAI_LARGE_MODEL:process.env.OPENAI_LARGE_MODEL,SMALL_MODEL:process.env.SMALL_MODEL,LARGE_MODEL:process.env.LARGE_MODEL,OPENAI_EMBEDDING_MODEL:process.env.OPENAI_EMBEDDING_MODEL,OPENAI_EMBEDDING_API_KEY:process.env.OPENAI_EMBEDDING_API_KEY,OPENAI_EMBEDDING_URL:process.env.OPENAI_EMBEDDING_URL,OPENAI_EMBEDDING_DIMENSIONS:process.env.OPENAI_EMBEDDING_DIMENSIONS,OPENAI_IMAGE_DESCRIPTION_MODEL:process.env.OPENAI_IMAGE_DESCRIPTION_MODEL,OPENAI_IMAGE_DESCRIPTION_MAX_TOKENS:process.env.OPENAI_IMAGE_DESCRIPTION_MAX_TOKENS,OPENAI_EXPERIMENTAL_TELEMETRY:process.env.OPENAI_EXPERIMENTAL_TELEMETRY},async init(Q,G){new Promise(async(W)=>{W();try{if(!D(G)&&!h()){X.warn("OPENAI_API_KEY is not set in environment - OpenAI functionality will be limited");return}try{let Y=K(G),C=await fetch(`${Y}/models`,{headers:{...v(G)}});if(!C.ok)X.warn(`OpenAI API key validation failed: ${C.statusText}`),X.warn("OpenAI functionality will be limited until a valid API key is provided");else X.log("OpenAI API key validated successfully")}catch(Y){let C=Y instanceof Error?Y.message:String(Y);X.warn(`Error validating OpenAI API key: ${C}`),X.warn("OpenAI functionality will be limited until a valid API key is provided")}}catch(Y){let C=Y?.errors?.map((I)=>I.message).join(", ")||(Y instanceof Error?Y.message:String(Y));X.warn(`OpenAI plugin configuration issue: ${C} - You need to configure the OPENAI_API_KEY in your environment variables`)}})},models:{[_.TEXT_EMBEDDING]:async(Q,G)=>{let W=J(Q,"OPENAI_EMBEDDING_MODEL","text-embedding-3-small"),Y=Number.parseInt(J(Q,"OPENAI_EMBEDDING_DIMENSIONS","1536")||"1536",10);if(!Object.values(V).includes(Y)){let Z=`Invalid embedding dimension: ${Y}. Must be one of: ${Object.values(V).join(", ")}`;throw X.error(Z),Error(Z)}if(G===null){X.debug("Creating test embedding for initialization");let Z=Array(Y).fill(0);return Z[0]=0.1,Z}let C;if(typeof G==="string")C=G;else if(typeof G==="object"&&G.text)C=G.text;else{X.warn("Invalid input format for embedding");let Z=Array(Y).fill(0);return Z[0]=0.2,Z}if(!C.trim()){X.warn("Empty text for embedding");let Z=Array(Y).fill(0);return Z[0]=0.3,Z}let I=y(Q);try{let Z=await fetch(`${I}/embeddings`,{method:"POST",headers:{...v(Q,!0),"Content-Type":"application/json"},body:JSON.stringify({model:W,input:C})}),F=await Z.clone().text();if(!Z.ok){X.error(`OpenAI API error: ${Z.status} - ${Z.statusText}`);let H=Array(Y).fill(0);return H[0]=0.4,H}let $=await Z.json();if(!$?.data?.[0]?.embedding){X.error("API returned invalid structure");let H=Array(Y).fill(0);return H[0]=0.5,H}let w=$.data[0].embedding;if($.usage){let H={inputTokens:$.usage.prompt_tokens,outputTokens:0,totalTokens:$.usage.total_tokens};j(Q,_.TEXT_EMBEDDING,C,H)}return X.log(`Got valid embedding with length ${w.length}`),w}catch(Z){let z=Z instanceof Error?Z.message:String(Z);X.error(`Error generating embedding: ${z}`);let F=Array(Y).fill(0);return F[0]=0.6,F}},[_.TEXT_TOKENIZER_ENCODE]:async(Q,{prompt:G,modelType:W=_.TEXT_LARGE})=>{return await p(W??_.TEXT_LARGE,G)},[_.TEXT_TOKENIZER_DECODE]:async(Q,{tokens:G,modelType:W=_.TEXT_LARGE})=>{return await u(W??_.TEXT_LARGE,G)},[_.TEXT_SMALL]:async(Q,{prompt:G,stopSequences:W=[],maxTokens:Y=8192,temperature:C=0.7,frequencyPenalty:I=0.7,presencePenalty:Z=0.7})=>{let z=P(Q),F=L(Q),$=k(Q);X.log(`[OpenAI] Using TEXT_SMALL model: ${F}`),X.log(G);let{text:w,usage:H}=await A({model:z.languageModel(F),prompt:G,system:Q.character.system??void 0,temperature:C,maxOutputTokens:Y,frequencyPenalty:I,presencePenalty:Z,stopSequences:W,experimental_telemetry:{isEnabled:$}});if(H)j(Q,_.TEXT_SMALL,G,H);return w},[_.TEXT_LARGE]:async(Q,{prompt:G,stopSequences:W=[],maxTokens:Y=8192,temperature:C=0.7,frequencyPenalty:I=0.7,presencePenalty:Z=0.7})=>{let z=P(Q),F=E(Q),$=k(Q);X.log(`[OpenAI] Using TEXT_LARGE model: ${F}`),X.log(G);let{text:w,usage:H}=await A({model:z.languageModel(F),prompt:G,system:Q.character.system??void 0,temperature:C,maxOutputTokens:Y,frequencyPenalty:I,presencePenalty:Z,stopSequences:W,experimental_telemetry:{isEnabled:$}});if(H)j(Q,_.TEXT_LARGE,G,H);return w},[_.IMAGE]:async(Q,G)=>{let W=G.n||1,Y=G.size||"1024x1024",C=G.prompt,I="dall-e-3";X.log("[OpenAI] Using IMAGE model: dall-e-3");let Z=K(Q);try{let z=await fetch(`${Z}/images/generations`,{method:"POST",headers:{...v(Q),"Content-Type":"application/json"},body:JSON.stringify({prompt:C,n:W,size:Y})}),$=await z.clone().text();if(!z.ok)throw Error(`Failed to generate image: ${z.statusText}`);return(await z.json()).data}catch(z){let F=z instanceof Error?z.message:String(z);throw z}},[_.IMAGE_DESCRIPTION]:async(Q,G)=>{let W,Y,C=l(Q);X.log(`[OpenAI] Using IMAGE_DESCRIPTION model: ${C}`);let I=Number.parseInt(J(Q,"OPENAI_IMAGE_DESCRIPTION_MAX_TOKENS","8192")||"8192",10);if(typeof G==="string")W=G,Y="Please analyze this image and provide a title and detailed description.";else W=G.imageUrl,Y=G.prompt||"Please analyze this image and provide a title and detailed description.";let Z=[{role:"user",content:[{type:"text",text:Y},{type:"image_url",image_url:{url:W}}]}],z=K(Q);try{let F={model:C,messages:Z,max_tokens:I},$=await fetch(`${z}/chat/completions`,{method:"POST",headers:{"Content-Type":"application/json",...v(Q)},body:JSON.stringify(F)}),H=await $.clone().text();if(!$.ok)throw Error(`OpenAI API error: ${$.status}`);let q=await $.json(),O=q.choices?.[0]?.message?.content;if(q.usage)j(Q,_.IMAGE_DESCRIPTION,typeof G==="string"?G:G.prompt||"",{inputTokens:q.usage.prompt_tokens,outputTokens:q.usage.completion_tokens,totalTokens:q.usage.total_tokens});if(!O)return{title:"Failed to analyze image",description:"No response from API"};if(typeof G==="object"&&G.prompt&&G.prompt!=="Please analyze this image and provide a title and detailed description.")return O;let b=O.match(/title[:\s]+(.+?)(?:\n|$)/i)?.[1]?.trim()||"Image Analysis",f=O.replace(/title[:\s]+(.+?)(?:\n|$)/i,"").trim();return{title:b,description:f}}catch(F){let $=F instanceof Error?F.message:String(F);return X.error(`Error analyzing image: ${$}`),{title:"Failed to analyze image",description:`Error: ${$}`}}},[_.TRANSCRIPTION]:async(Q,G)=>{X.debug({size:G?.length??0},"audioBuffer received");let W="whisper-1";X.log(`[OpenAI] Using TRANSCRIPTION model: ${W}`);let Y=K(Q);if(!G||G.length===0)throw Error("Audio buffer is empty or invalid for transcription");let C=new FormData,I=G.buffer,Z=G.byteOffset||0,z=Z+(G.byteLength||0),F=I.slice(Z,z);C.append("file",new Blob([F],{type:"audio/mpeg"}),"recording.mp3"),C.append("model","whisper-1");try{let $=await fetch(`${Y}/audio/transcriptions`,{method:"POST",headers:{...v(Q)},body:C}),H=await $.clone().text();if(X.log({response:$},"response"),!$.ok)throw Error(`Failed to transcribe audio: ${$.statusText}`);return(await $.json()).text}catch($){let w=$ instanceof Error?$.message:String($);throw $}},[_.TEXT_TO_SPEECH]:async(Q,G)=>{let W=J(Q,"OPENAI_TTS_MODEL","gpt-4o-mini-tts");X.log(`[OpenAI] Using TEXT_TO_SPEECH model: ${W}`);try{return await R(Q,G)}catch(Y){let C=Y instanceof Error?Y.message:String(Y);throw Y}},[_.OBJECT_SMALL]:async(Q,G)=>{return B(Q,G,_.OBJECT_SMALL,L)},[_.OBJECT_LARGE]:async(Q,G)=>{return B(Q,G,_.OBJECT_LARGE,E)}},tests:[{name:"openai_plugin_tests",tests:[{name:"openai_test_url_and_api_key_validation",fn:async(Q)=>{let G=K(Q),W=await fetch(`${G}/models`,{headers:{Authorization:`Bearer ${D(Q)}`}}),Y=await W.json();if(X.log({data:Y?.data?.length??"N/A"},"Models Available"),!W.ok)throw Error(`Failed to validate OpenAI API key: ${W.statusText}`)}},{name:"openai_test_text_embedding",fn:async(Q)=>{try{let G=await Q.useModel(_.TEXT_EMBEDDING,{text:"Hello, world!"});X.log({embedding:G},"embedding")}catch(G){let W=G instanceof Error?G.message:String(G);throw X.error(`Error in test_text_embedding: ${W}`),G}}},{name:"openai_test_text_large",fn:async(Q)=>{try{let G=await Q.useModel(_.TEXT_LARGE,{prompt:"What is the nature of reality in 10 words?"});if(G.length===0)throw Error("Failed to generate text");X.log({text:G},"generated with test_text_large")}catch(G){let W=G instanceof Error?G.message:String(G);throw X.error(`Error in test_text_large: ${W}`),G}}},{name:"openai_test_text_small",fn:async(Q)=>{try{let G=await Q.useModel(_.TEXT_SMALL,{prompt:"What is the nature of reality in 10 words?"});if(G.length===0)throw Error("Failed to generate text");X.log({text:G},"generated with test_text_small")}catch(G){let W=G instanceof Error?G.message:String(G);throw X.error(`Error in test_text_small: ${W}`),G}}},{name:"openai_test_image_generation",fn:async(Q)=>{X.log("openai_test_image_generation");try{let G=await Q.useModel(_.IMAGE,{prompt:"A beautiful sunset over a calm ocean",n:1,size:"1024x1024"});X.log({image:G},"generated with test_image_generation")}catch(G){let W=G instanceof Error?G.message:String(G);throw X.error(`Error in test_image_generation: ${W}`),G}}},{name:"image-description",fn:async(Q)=>{try{X.log("openai_test_image_description");try{let G=await Q.useModel(_.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");if(G&&typeof G==="object"&&"title"in G&&"description"in G)X.log({result:G},"Image description");else X.error("Invalid image description result format:",G)}catch(G){let W=G instanceof Error?G.message:String(G);X.error(`Error in image description test: ${W}`)}}catch(G){let W=G instanceof Error?G.message:String(G);X.error(`Error in openai_test_image_description: ${W}`)}}},{name:"openai_test_transcription",fn:async(Q)=>{X.log("openai_test_transcription");try{let W=await(await fetch("https://upload.wikimedia.org/wikipedia/en/4/40/Chris_Benoit_Voice_Message.ogg")).arrayBuffer(),Y=await Q.useModel(_.TRANSCRIPTION,Buffer.from(new Uint8Array(W)));X.log({transcription:Y},"generated with test_transcription")}catch(G){let W=G instanceof Error?G.message:String(G);throw X.error(`Error in test_transcription: ${W}`),G}}},{name:"openai_test_text_tokenizer_encode",fn:async(Q)=>{let W=await Q.useModel(_.TEXT_TOKENIZER_ENCODE,{prompt:"Hello tokenizer encode!"});if(!Array.isArray(W)||W.length===0)throw Error("Failed to tokenize text: expected non-empty array of tokens");X.log({tokens:W},"Tokenized output")}},{name:"openai_test_text_tokenizer_decode",fn:async(Q)=>{let W=await Q.useModel(_.TEXT_TOKENIZER_ENCODE,{prompt:"Hello tokenizer decode!"}),Y=await Q.useModel(_.TEXT_TOKENIZER_DECODE,{tokens:W});if(Y!=="Hello tokenizer decode!")throw Error(`Decoded text does not match original. Expected "Hello tokenizer decode!", got "${Y}"`);X.log({decodedText:Y},"Decoded text")}},{name:"openai_test_text_to_speech",fn:async(Q)=>{try{if(!await R(Q,"Hello, this is a test for text-to-speech."))throw Error("Failed to generate speech");X.log("Generated speech successfully")}catch(G){let W=G instanceof Error?G.message:String(G);throw X.error(`Error in openai_test_text_to_speech: ${W}`),G}}}]}]},g=s;export{s as openaiPlugin,g as default};
2
+
3
+ //# debugId=BFB4D0C1712EB03A64756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": [
5
+ "import { createOpenAI } from \"@ai-sdk/openai\";\nimport type {\n DetokenizeTextParams,\n GenerateTextParams,\n IAgentRuntime,\n ImageDescriptionParams,\n ModelTypeName,\n ObjectGenerationParams,\n Plugin,\n TextEmbeddingParams,\n TokenizeTextParams,\n} from \"@elizaos/core\";\nimport { EventType, logger, ModelType, VECTOR_DIMS } from \"@elizaos/core\";\nimport {\n generateObject,\n generateText,\n JSONParseError,\n type JSONValue,\n type LanguageModelUsage,\n} from \"ai\";\nimport { encodingForModel, type TiktokenModel } from \"js-tiktoken\";\n\n/**\n * Retrieves a configuration setting from the runtime, falling back to environment variables or a default value if not found.\n *\n * @param key - The name of the setting to retrieve.\n * @param defaultValue - The value to return if the setting is not found in the runtime or environment.\n * @returns The resolved setting value, or {@link defaultValue} if not found.\n */\nfunction getSetting(\n runtime: IAgentRuntime,\n key: string,\n defaultValue?: string,\n): string | undefined {\n return runtime.getSetting(key) ?? process.env[key] ?? defaultValue;\n}\n\nfunction isBrowser(): boolean {\n return (\n typeof globalThis !== \"undefined\" &&\n typeof (globalThis as any).document !== \"undefined\"\n );\n}\n\nfunction getAuthHeader(\n runtime: IAgentRuntime,\n forEmbedding = false,\n): Record<string, string> {\n if (isBrowser()) return {};\n const key = forEmbedding ? getEmbeddingApiKey(runtime) : getApiKey(runtime);\n return key ? { Authorization: `Bearer ${key}` } : {};\n}\n\n/**\n * Retrieves the OpenAI API base URL from runtime settings, environment variables, or defaults, using provider-aware resolution.\n *\n * @returns The resolved base URL for OpenAI API requests.\n */\nfunction getBaseURL(runtime: IAgentRuntime): string {\n const browserURL = getSetting(runtime, \"OPENAI_BROWSER_BASE_URL\");\n const baseURL = (\n isBrowser() && browserURL\n ? browserURL\n : getSetting(runtime, \"OPENAI_BASE_URL\", \"https://api.openai.com/v1\")\n ) as string;\n logger.debug(`[OpenAI] Default base URL: ${baseURL}`);\n return baseURL;\n}\n\n/**\n * Retrieves the OpenAI API base URL for embeddings, falling back to the general base URL.\n *\n * @returns The resolved base URL for OpenAI embedding requests.\n */\nfunction getEmbeddingBaseURL(runtime: IAgentRuntime): string {\n const embeddingURL = isBrowser()\n ? getSetting(runtime, \"OPENAI_BROWSER_EMBEDDING_URL\") ||\n getSetting(runtime, \"OPENAI_BROWSER_BASE_URL\")\n : getSetting(runtime, \"OPENAI_EMBEDDING_URL\");\n if (embeddingURL) {\n logger.debug(`[OpenAI] Using specific embedding base URL: ${embeddingURL}`);\n return embeddingURL;\n }\n logger.debug(\"[OpenAI] Falling back to general base URL for embeddings.\");\n return getBaseURL(runtime);\n}\n\n/**\n * Helper function to get the API key for OpenAI\n *\n * @param runtime The runtime context\n * @returns The configured API key\n */\nfunction getApiKey(runtime: IAgentRuntime): string | undefined {\n return getSetting(runtime, \"OPENAI_API_KEY\");\n}\n\n/**\n * Helper function to get the embedding API key for OpenAI, falling back to the general API key if not set.\n *\n * @param runtime The runtime context\n * @returns The configured API key\n */\nfunction getEmbeddingApiKey(runtime: IAgentRuntime): string | undefined {\n const embeddingApiKey = getSetting(runtime, \"OPENAI_EMBEDDING_API_KEY\");\n if (embeddingApiKey) {\n logger.debug(\"[OpenAI] Using specific embedding API key (present)\");\n return embeddingApiKey;\n }\n logger.debug(\"[OpenAI] Falling back to general API key for embeddings.\");\n return getApiKey(runtime);\n}\n\n/**\n * Helper function to get the small model name with fallbacks\n *\n * @param runtime The runtime context\n * @returns The configured small model name\n */\nfunction getSmallModel(runtime: IAgentRuntime): string {\n return (\n getSetting(runtime, \"OPENAI_SMALL_MODEL\") ??\n (getSetting(runtime, \"SMALL_MODEL\", \"gpt-5-nano\") as string)\n );\n}\n\n/**\n * Helper function to get the large model name with fallbacks\n *\n * @param runtime The runtime context\n * @returns The configured large model name\n */\nfunction getLargeModel(runtime: IAgentRuntime): string {\n return (\n getSetting(runtime, \"OPENAI_LARGE_MODEL\") ??\n (getSetting(runtime, \"LARGE_MODEL\", \"gpt-5-mini\") as string)\n );\n}\n\n/**\n * Helper function to get the image description model name with fallbacks\n *\n * @param runtime The runtime context\n * @returns The configured image description model name\n */\nfunction getImageDescriptionModel(runtime: IAgentRuntime): string {\n return (\n getSetting(runtime, \"OPENAI_IMAGE_DESCRIPTION_MODEL\", \"gpt-5-nano\") ??\n \"gpt-5-nano\"\n );\n}\n\n/**\n * Helper function to get experimental telemetry setting\n *\n * @param runtime The runtime context\n * @returns Whether experimental telemetry is enabled\n */\nfunction getExperimentalTelemetry(runtime: IAgentRuntime): boolean {\n const setting = getSetting(runtime, \"OPENAI_EXPERIMENTAL_TELEMETRY\", \"false\");\n // Convert to string and check for truthy values\n const normalizedSetting = String(setting).toLowerCase();\n const result = normalizedSetting === \"true\";\n logger.debug(\n `[OpenAI] Experimental telemetry in function: \"${setting}\" (type: ${typeof setting}, normalized: \"${normalizedSetting}\", result: ${result})`,\n );\n return result;\n}\n\n/**\n * Create an OpenAI client with proper configuration\n *\n * @param runtime The runtime context\n * @returns Configured OpenAI client\n */\nfunction createOpenAIClient(runtime: IAgentRuntime) {\n return createOpenAI({\n apiKey: getApiKey(runtime),\n baseURL: getBaseURL(runtime),\n });\n}\n\n/**\n * Asynchronously tokenizes the given text based on the specified model and prompt.\n *\n * @param {ModelTypeName} model - The type of model to use for tokenization.\n * @param {string} prompt - The text prompt to tokenize.\n * @returns {number[]} - An array of tokens representing the encoded prompt.\n */\nasync function tokenizeText(model: ModelTypeName, prompt: string) {\n const modelName =\n model === ModelType.TEXT_SMALL\n ? (process.env.OPENAI_SMALL_MODEL ??\n process.env.SMALL_MODEL ??\n \"gpt-5-nano\")\n : (process.env.LARGE_MODEL ?? \"gpt-5-mini\");\n const tokens = encodingForModel(modelName as TiktokenModel).encode(prompt);\n return tokens;\n}\n\n/**\n * Detokenize a sequence of tokens back into text using the specified model.\n *\n * @param {ModelTypeName} model - The type of model to use for detokenization.\n * @param {number[]} tokens - The sequence of tokens to detokenize.\n * @returns {string} The detokenized text.\n */\nasync function detokenizeText(model: ModelTypeName, tokens: number[]) {\n const modelName =\n model === ModelType.TEXT_SMALL\n ? (process.env.OPENAI_SMALL_MODEL ??\n process.env.SMALL_MODEL ??\n \"gpt-5-nano\")\n : (process.env.OPENAI_LARGE_MODEL ??\n process.env.LARGE_MODEL ??\n \"gpt-5-mini\");\n return encodingForModel(modelName as TiktokenModel).decode(tokens);\n}\n\n/**\n * Helper function to generate objects using specified model type\n */\nasync function generateObjectByModelType(\n runtime: IAgentRuntime,\n params: ObjectGenerationParams,\n modelType: string,\n getModelFn: (runtime: IAgentRuntime) => string,\n): Promise<JSONValue> {\n const openai = createOpenAIClient(runtime);\n const modelName = getModelFn(runtime);\n logger.log(`[OpenAI] Using ${modelType} model: ${modelName}`);\n const temperature = params.temperature ?? 0;\n const schemaPresent = !!params.schema;\n\n if (schemaPresent) {\n logger.info(\n `Using ${modelType} without schema validation (schema provided but output=no-schema)`,\n );\n }\n\n try {\n const { object, usage } = await generateObject({\n model: openai.languageModel(modelName),\n output: \"no-schema\",\n prompt: params.prompt,\n temperature: temperature,\n experimental_repairText: getJsonRepairFunction(),\n });\n\n if (usage) {\n emitModelUsageEvent(\n runtime,\n modelType as ModelTypeName,\n params.prompt,\n usage,\n );\n }\n return object;\n } catch (error: unknown) {\n if (error instanceof JSONParseError) {\n logger.error(`[generateObject] Failed to parse JSON: ${error.message}`);\n\n const repairFunction = getJsonRepairFunction();\n const repairedJsonString = await repairFunction({\n text: error.text,\n error,\n });\n\n if (repairedJsonString) {\n try {\n const repairedObject = JSON.parse(repairedJsonString);\n logger.info(\"[generateObject] Successfully repaired JSON.\");\n return repairedObject;\n } catch (repairParseError: unknown) {\n const message =\n repairParseError instanceof Error\n ? repairParseError.message\n : String(repairParseError);\n logger.error(\n `[generateObject] Failed to parse repaired JSON: ${message}`,\n );\n throw repairParseError;\n }\n } else {\n logger.error(\"[generateObject] JSON repair failed.\");\n throw error;\n }\n } else {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`[generateObject] Unknown error: ${message}`);\n throw error;\n }\n }\n}\n\n/**\n * Returns a function to repair JSON text\n */\nfunction getJsonRepairFunction(): (params: {\n text: string;\n error: unknown;\n}) => Promise<string | null> {\n return async ({ text, error }: { text: string; error: unknown }) => {\n try {\n if (error instanceof JSONParseError) {\n const cleanedText = text.replace(/```json\\n|\\n```|```/g, \"\");\n JSON.parse(cleanedText);\n return cleanedText;\n }\n return null;\n } catch (jsonError: unknown) {\n const message =\n jsonError instanceof Error ? jsonError.message : String(jsonError);\n logger.warn(`Failed to repair JSON text: ${message}`);\n return null;\n }\n };\n}\n\n/**\n * Emits a model usage event\n * @param runtime The runtime context\n * @param type The model type\n * @param prompt The prompt used\n * @param usage The LLM usage data\n */\nfunction emitModelUsageEvent(\n runtime: IAgentRuntime,\n type: ModelTypeName,\n prompt: string,\n usage: LanguageModelUsage,\n) {\n runtime.emitEvent(EventType.MODEL_USED, {\n provider: \"openai\",\n type,\n prompt,\n tokens: {\n prompt: usage.inputTokens,\n completion: usage.outputTokens,\n total: usage.totalTokens,\n },\n });\n}\n\n/**\n * function for text-to-speech\n */\nasync function fetchTextToSpeech(runtime: IAgentRuntime, text: string) {\n const model = getSetting(runtime, \"OPENAI_TTS_MODEL\", \"gpt-4o-mini-tts\");\n const voice = getSetting(runtime, \"OPENAI_TTS_VOICE\", \"nova\");\n const instructions = getSetting(runtime, \"OPENAI_TTS_INSTRUCTIONS\", \"\");\n const baseURL = getBaseURL(runtime);\n\n try {\n const res = await fetch(`${baseURL}/audio/speech`, {\n method: \"POST\",\n headers: {\n ...getAuthHeader(runtime),\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n model,\n voice,\n input: text,\n ...(instructions && { instructions }),\n }),\n });\n\n if (!res.ok) {\n const err = await res.text();\n throw new Error(`OpenAI TTS error ${res.status}: ${err}`);\n }\n\n return res.body;\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(`Failed to fetch speech from OpenAI TTS: ${message}`);\n }\n}\n\n/**\n * Defines the OpenAI plugin with its name, description, and configuration options.\n * @type {Plugin}\n */\nexport const openaiPlugin: Plugin = {\n name: \"openai\",\n description: \"OpenAI plugin\",\n config: {\n OPENAI_API_KEY: process.env.OPENAI_API_KEY,\n OPENAI_BASE_URL: process.env.OPENAI_BASE_URL,\n OPENAI_SMALL_MODEL: process.env.OPENAI_SMALL_MODEL,\n OPENAI_LARGE_MODEL: process.env.OPENAI_LARGE_MODEL,\n SMALL_MODEL: process.env.SMALL_MODEL,\n LARGE_MODEL: process.env.LARGE_MODEL,\n OPENAI_EMBEDDING_MODEL: process.env.OPENAI_EMBEDDING_MODEL,\n OPENAI_EMBEDDING_API_KEY: process.env.OPENAI_EMBEDDING_API_KEY,\n OPENAI_EMBEDDING_URL: process.env.OPENAI_EMBEDDING_URL,\n OPENAI_EMBEDDING_DIMENSIONS: process.env.OPENAI_EMBEDDING_DIMENSIONS,\n OPENAI_IMAGE_DESCRIPTION_MODEL: process.env.OPENAI_IMAGE_DESCRIPTION_MODEL,\n OPENAI_IMAGE_DESCRIPTION_MAX_TOKENS:\n process.env.OPENAI_IMAGE_DESCRIPTION_MAX_TOKENS,\n OPENAI_EXPERIMENTAL_TELEMETRY: process.env.OPENAI_EXPERIMENTAL_TELEMETRY,\n },\n async init(_config, runtime) {\n // do check in the background\n new Promise<void>(async (resolve) => {\n resolve();\n try {\n if (!getApiKey(runtime) && !isBrowser()) {\n logger.warn(\n \"OPENAI_API_KEY is not set in environment - OpenAI functionality will be limited\",\n );\n return;\n }\n try {\n const baseURL = getBaseURL(runtime);\n const response = await fetch(`${baseURL}/models`, {\n headers: { ...getAuthHeader(runtime) },\n });\n if (!response.ok) {\n logger.warn(\n `OpenAI API key validation failed: ${response.statusText}`,\n );\n logger.warn(\n \"OpenAI functionality will be limited until a valid API key is provided\",\n );\n } else {\n logger.log(\"OpenAI API key validated successfully\");\n }\n } catch (fetchError: unknown) {\n const message =\n fetchError instanceof Error\n ? fetchError.message\n : String(fetchError);\n logger.warn(`Error validating OpenAI API key: ${message}`);\n logger.warn(\n \"OpenAI functionality will be limited until a valid API key is provided\",\n );\n }\n } catch (error: unknown) {\n const message =\n (error as { errors?: Array<{ message: string }> })?.errors\n ?.map((e) => e.message)\n .join(\", \") ||\n (error instanceof Error ? error.message : String(error));\n logger.warn(\n `OpenAI plugin configuration issue: ${message} - You need to configure the OPENAI_API_KEY in your environment variables`,\n );\n }\n });\n },\n\n models: {\n [ModelType.TEXT_EMBEDDING]: async (\n runtime: IAgentRuntime,\n params: TextEmbeddingParams | string | null,\n ): Promise<number[]> => {\n const embeddingModelName = getSetting(\n runtime,\n \"OPENAI_EMBEDDING_MODEL\",\n \"text-embedding-3-small\",\n );\n const embeddingDimension = Number.parseInt(\n getSetting(runtime, \"OPENAI_EMBEDDING_DIMENSIONS\", \"1536\") || \"1536\",\n 10,\n ) as (typeof VECTOR_DIMS)[keyof typeof VECTOR_DIMS];\n\n if (!Object.values(VECTOR_DIMS).includes(embeddingDimension)) {\n const errorMsg = `Invalid embedding dimension: ${embeddingDimension}. Must be one of: ${Object.values(VECTOR_DIMS).join(\", \")}`;\n logger.error(errorMsg);\n throw new Error(errorMsg);\n }\n if (params === null) {\n logger.debug(\"Creating test embedding for initialization\");\n const testVector = Array(embeddingDimension).fill(0);\n testVector[0] = 0.1;\n return testVector;\n }\n let text: string;\n if (typeof params === \"string\") {\n text = params;\n } else if (typeof params === \"object\" && params.text) {\n text = params.text;\n } else {\n logger.warn(\"Invalid input format for embedding\");\n const fallbackVector = Array(embeddingDimension).fill(0);\n fallbackVector[0] = 0.2;\n return fallbackVector;\n }\n if (!text.trim()) {\n logger.warn(\"Empty text for embedding\");\n const emptyVector = Array(embeddingDimension).fill(0);\n emptyVector[0] = 0.3;\n return emptyVector;\n }\n\n const embeddingBaseURL = getEmbeddingBaseURL(runtime);\n\n try {\n const response = await fetch(`${embeddingBaseURL}/embeddings`, {\n method: \"POST\",\n headers: {\n ...getAuthHeader(runtime, true),\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n model: embeddingModelName,\n input: text,\n }),\n });\n\n const responseClone = response.clone();\n const rawResponseBody = await responseClone.text();\n\n if (!response.ok) {\n logger.error(\n `OpenAI API error: ${response.status} - ${response.statusText}`,\n );\n const errorVector = Array(embeddingDimension).fill(0);\n errorVector[0] = 0.4;\n return errorVector;\n }\n\n const data = (await response.json()) as {\n data: [{ embedding: number[] }];\n usage?: { prompt_tokens: number; total_tokens: number };\n };\n\n if (!data?.data?.[0]?.embedding) {\n logger.error(\"API returned invalid structure\");\n const errorVector = Array(embeddingDimension).fill(0);\n errorVector[0] = 0.5;\n return errorVector;\n }\n\n const embedding = data.data[0].embedding;\n\n if (data.usage) {\n const usage = {\n inputTokens: data.usage.prompt_tokens,\n outputTokens: 0,\n totalTokens: data.usage.total_tokens,\n };\n\n emitModelUsageEvent(runtime, ModelType.TEXT_EMBEDDING, text, usage);\n }\n\n logger.log(`Got valid embedding with length ${embedding.length}`);\n return embedding;\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error generating embedding: ${message}`);\n const errorVector = Array(embeddingDimension).fill(0);\n errorVector[0] = 0.6;\n return errorVector;\n }\n },\n [ModelType.TEXT_TOKENIZER_ENCODE]: async (\n _runtime,\n { prompt, modelType = ModelType.TEXT_LARGE }: TokenizeTextParams,\n ) => {\n return await tokenizeText(modelType ?? ModelType.TEXT_LARGE, prompt);\n },\n [ModelType.TEXT_TOKENIZER_DECODE]: async (\n _runtime,\n { tokens, modelType = ModelType.TEXT_LARGE }: DetokenizeTextParams,\n ) => {\n return await detokenizeText(modelType ?? ModelType.TEXT_LARGE, tokens);\n },\n [ModelType.TEXT_SMALL]: async (\n runtime: IAgentRuntime,\n {\n prompt,\n stopSequences = [],\n maxTokens = 8192,\n temperature = 0.7,\n frequencyPenalty = 0.7,\n presencePenalty = 0.7,\n }: GenerateTextParams,\n ) => {\n const openai = createOpenAIClient(runtime);\n const modelName = getSmallModel(runtime);\n const experimentalTelemetry = getExperimentalTelemetry(runtime);\n\n logger.log(`[OpenAI] Using TEXT_SMALL model: ${modelName}`);\n logger.log(prompt);\n\n const { text: openaiResponse, usage } = await generateText({\n model: openai.languageModel(modelName),\n prompt: prompt,\n system: runtime.character.system ?? undefined,\n temperature: temperature,\n maxOutputTokens: maxTokens,\n frequencyPenalty: frequencyPenalty,\n presencePenalty: presencePenalty,\n stopSequences: stopSequences,\n experimental_telemetry: {\n isEnabled: experimentalTelemetry,\n },\n });\n\n if (usage) {\n emitModelUsageEvent(runtime, ModelType.TEXT_SMALL, prompt, usage);\n }\n\n return openaiResponse;\n },\n [ModelType.TEXT_LARGE]: async (\n runtime: IAgentRuntime,\n {\n prompt,\n stopSequences = [],\n maxTokens = 8192,\n temperature = 0.7,\n frequencyPenalty = 0.7,\n presencePenalty = 0.7,\n }: GenerateTextParams,\n ) => {\n const openai = createOpenAIClient(runtime);\n const modelName = getLargeModel(runtime);\n const experimentalTelemetry = getExperimentalTelemetry(runtime);\n\n logger.log(`[OpenAI] Using TEXT_LARGE model: ${modelName}`);\n logger.log(prompt);\n\n const { text: openaiResponse, usage } = await generateText({\n model: openai.languageModel(modelName),\n prompt: prompt,\n system: runtime.character.system ?? undefined,\n temperature: temperature,\n maxOutputTokens: maxTokens,\n frequencyPenalty: frequencyPenalty,\n presencePenalty: presencePenalty,\n stopSequences: stopSequences,\n experimental_telemetry: {\n isEnabled: experimentalTelemetry,\n },\n });\n\n if (usage) {\n emitModelUsageEvent(runtime, ModelType.TEXT_LARGE, prompt, usage);\n }\n\n return openaiResponse;\n },\n [ModelType.IMAGE]: async (\n runtime: IAgentRuntime,\n params: {\n prompt: string;\n n?: number;\n size?: string;\n },\n ) => {\n const n = params.n || 1;\n const size = params.size || \"1024x1024\";\n const prompt = params.prompt;\n const modelName = \"dall-e-3\"; // Default DALL-E model\n logger.log(`[OpenAI] Using IMAGE model: ${modelName}`);\n\n const baseURL = getBaseURL(runtime);\n\n try {\n const response = await fetch(`${baseURL}/images/generations`, {\n method: \"POST\",\n headers: {\n ...getAuthHeader(runtime),\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n prompt: prompt,\n n: n,\n size: size,\n }),\n });\n\n const responseClone = response.clone();\n const rawResponseBody = await responseClone.text();\n\n if (!response.ok) {\n throw new Error(`Failed to generate image: ${response.statusText}`);\n }\n\n const data = await response.json();\n const typedData = data as { data: { url: string }[] };\n\n return typedData.data;\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n throw error;\n }\n },\n [ModelType.IMAGE_DESCRIPTION]: async (\n runtime: IAgentRuntime,\n params: ImageDescriptionParams | string,\n ) => {\n let imageUrl: string;\n let promptText: string | undefined;\n const modelName = getImageDescriptionModel(runtime);\n logger.log(`[OpenAI] Using IMAGE_DESCRIPTION model: ${modelName}`);\n const maxTokens = Number.parseInt(\n getSetting(runtime, \"OPENAI_IMAGE_DESCRIPTION_MAX_TOKENS\", \"8192\") ||\n \"8192\",\n 10,\n );\n\n if (typeof params === \"string\") {\n imageUrl = params;\n promptText =\n \"Please analyze this image and provide a title and detailed description.\";\n } else {\n imageUrl = params.imageUrl;\n promptText =\n params.prompt ||\n \"Please analyze this image and provide a title and detailed description.\";\n }\n\n const messages = [\n {\n role: \"user\",\n content: [\n { type: \"text\", text: promptText },\n { type: \"image_url\", image_url: { url: imageUrl } },\n ],\n },\n ];\n\n const baseURL = getBaseURL(runtime);\n\n try {\n const requestBody: Record<string, any> = {\n model: modelName,\n messages: messages,\n max_tokens: maxTokens,\n };\n\n const response = await fetch(`${baseURL}/chat/completions`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...getAuthHeader(runtime),\n },\n body: JSON.stringify(requestBody),\n });\n\n const responseClone = response.clone();\n const rawResponseBody = await responseClone.text();\n\n if (!response.ok) {\n throw new Error(`OpenAI API error: ${response.status}`);\n }\n\n const result: unknown = await response.json();\n\n type OpenAIResponseType = {\n choices?: Array<{\n message?: { content?: string };\n finish_reason?: string;\n }>;\n usage?: {\n prompt_tokens: number;\n completion_tokens: number;\n total_tokens: number;\n };\n };\n\n const typedResult = result as OpenAIResponseType;\n const content = typedResult.choices?.[0]?.message?.content;\n\n if (typedResult.usage) {\n emitModelUsageEvent(\n runtime,\n ModelType.IMAGE_DESCRIPTION,\n typeof params === \"string\" ? params : params.prompt || \"\",\n {\n inputTokens: typedResult.usage.prompt_tokens,\n outputTokens: typedResult.usage.completion_tokens,\n totalTokens: typedResult.usage.total_tokens,\n },\n );\n }\n\n if (!content) {\n return {\n title: \"Failed to analyze image\",\n description: \"No response from API\",\n };\n }\n\n // Check if a custom prompt was provided (not the default prompt)\n const isCustomPrompt =\n typeof params === \"object\" &&\n params.prompt &&\n params.prompt !==\n \"Please analyze this image and provide a title and detailed description.\";\n\n // If custom prompt is used, return the raw content\n if (isCustomPrompt) {\n return content;\n }\n\n // Otherwise, maintain backwards compatibility with object return\n const titleMatch = content.match(/title[:\\s]+(.+?)(?:\\n|$)/i);\n const title = titleMatch?.[1]?.trim() || \"Image Analysis\";\n const description = content\n .replace(/title[:\\s]+(.+?)(?:\\n|$)/i, \"\")\n .trim();\n\n const processedResult = { title, description };\n return processedResult;\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Error analyzing image: ${message}`);\n return {\n title: \"Failed to analyze image\",\n description: `Error: ${message}`,\n };\n }\n },\n [ModelType.TRANSCRIPTION]: async (\n runtime: IAgentRuntime,\n audioBuffer: Buffer,\n ) => {\n logger.debug({ size: audioBuffer?.length ?? 0 }, \"audioBuffer received\");\n\n const modelName = \"whisper-1\";\n logger.log(`[OpenAI] Using TRANSCRIPTION model: ${modelName}`);\n\n const baseURL = getBaseURL(runtime);\n if (!audioBuffer || audioBuffer.length === 0) {\n throw new Error(\"Audio buffer is empty or invalid for transcription\");\n }\n\n const formData = new FormData();\n const arrayBuffer = (\n audioBuffer as unknown as {\n buffer: ArrayBuffer;\n byteOffset: number;\n byteLength: number;\n }\n ).buffer;\n const start = (audioBuffer as any).byteOffset || 0;\n const end = start + ((audioBuffer as any).byteLength || 0);\n const safeArrayBuffer = arrayBuffer.slice(start, end);\n formData.append(\n \"file\",\n new Blob([safeArrayBuffer], { type: \"audio/mpeg\" }),\n \"recording.mp3\",\n );\n formData.append(\"model\", \"whisper-1\");\n\n try {\n const response = await fetch(`${baseURL}/audio/transcriptions`, {\n method: \"POST\",\n headers: {\n ...getAuthHeader(runtime),\n },\n body: formData,\n });\n\n const responseClone = response.clone();\n const rawResponseBody = await responseClone.text();\n\n logger.log({ response }, \"response\");\n\n if (!response.ok) {\n throw new Error(`Failed to transcribe audio: ${response.statusText}`);\n }\n\n const data = (await response.json()) as { text: string };\n const processedText = data.text;\n\n return processedText;\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n throw error;\n }\n },\n [ModelType.TEXT_TO_SPEECH]: async (\n runtime: IAgentRuntime,\n text: string,\n ) => {\n const ttsModelName = getSetting(\n runtime,\n \"OPENAI_TTS_MODEL\",\n \"gpt-4o-mini-tts\",\n );\n logger.log(`[OpenAI] Using TEXT_TO_SPEECH model: ${ttsModelName}`);\n try {\n const speechStream = await fetchTextToSpeech(runtime, text);\n return speechStream;\n } catch (error: unknown) {\n const message = error instanceof Error ? error.message : String(error);\n throw error;\n }\n },\n [ModelType.OBJECT_SMALL]: async (\n runtime: IAgentRuntime,\n params: ObjectGenerationParams,\n ) => {\n return generateObjectByModelType(\n runtime,\n params,\n ModelType.OBJECT_SMALL,\n getSmallModel,\n );\n },\n [ModelType.OBJECT_LARGE]: async (\n runtime: IAgentRuntime,\n params: ObjectGenerationParams,\n ) => {\n return generateObjectByModelType(\n runtime,\n params,\n ModelType.OBJECT_LARGE,\n getLargeModel,\n );\n },\n },\n tests: [\n {\n name: \"openai_plugin_tests\",\n tests: [\n {\n name: \"openai_test_url_and_api_key_validation\",\n fn: async (runtime: IAgentRuntime) => {\n const baseURL = getBaseURL(runtime);\n const response = await fetch(`${baseURL}/models`, {\n headers: {\n Authorization: `Bearer ${getApiKey(runtime)}`,\n },\n });\n const data = await response.json();\n logger.log(\n { data: (data as { data?: unknown[] })?.data?.length ?? \"N/A\" },\n \"Models Available\",\n );\n if (!response.ok) {\n throw new Error(\n `Failed to validate OpenAI API key: ${response.statusText}`,\n );\n }\n },\n },\n {\n name: \"openai_test_text_embedding\",\n fn: async (runtime: IAgentRuntime) => {\n try {\n const embedding = await runtime.useModel(\n ModelType.TEXT_EMBEDDING,\n {\n text: \"Hello, world!\",\n },\n );\n logger.log({ embedding }, \"embedding\");\n } catch (error: unknown) {\n const message =\n error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_text_embedding: ${message}`);\n throw error;\n }\n },\n },\n {\n name: \"openai_test_text_large\",\n fn: async (runtime: IAgentRuntime) => {\n try {\n const text = await runtime.useModel(ModelType.TEXT_LARGE, {\n prompt: \"What is the nature of reality in 10 words?\",\n });\n if (text.length === 0) {\n throw new Error(\"Failed to generate text\");\n }\n logger.log({ text }, \"generated with test_text_large\");\n } catch (error: unknown) {\n const message =\n error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_text_large: ${message}`);\n throw error;\n }\n },\n },\n {\n name: \"openai_test_text_small\",\n fn: async (runtime: IAgentRuntime) => {\n try {\n const text = await runtime.useModel(ModelType.TEXT_SMALL, {\n prompt: \"What is the nature of reality in 10 words?\",\n });\n if (text.length === 0) {\n throw new Error(\"Failed to generate text\");\n }\n logger.log({ text }, \"generated with test_text_small\");\n } catch (error: unknown) {\n const message =\n error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_text_small: ${message}`);\n throw error;\n }\n },\n },\n {\n name: \"openai_test_image_generation\",\n fn: async (runtime: IAgentRuntime) => {\n logger.log(\"openai_test_image_generation\");\n try {\n const image = await runtime.useModel(ModelType.IMAGE, {\n prompt: \"A beautiful sunset over a calm ocean\",\n n: 1,\n size: \"1024x1024\",\n });\n logger.log({ image }, \"generated with test_image_generation\");\n } catch (error: unknown) {\n const message =\n error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_image_generation: ${message}`);\n throw error;\n }\n },\n },\n {\n name: \"image-description\",\n fn: async (runtime: IAgentRuntime) => {\n try {\n logger.log(\"openai_test_image_description\");\n try {\n const result = await runtime.useModel(\n ModelType.IMAGE_DESCRIPTION,\n \"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\",\n );\n\n if (\n result &&\n typeof result === \"object\" &&\n \"title\" in result &&\n \"description\" in result\n ) {\n logger.log({ result }, \"Image description\");\n } else {\n logger.error(\n \"Invalid image description result format:\",\n result,\n );\n }\n } catch (e: unknown) {\n const message = e instanceof Error ? e.message : String(e);\n logger.error(`Error in image description test: ${message}`);\n }\n } catch (e: unknown) {\n const message = e instanceof Error ? e.message : String(e);\n logger.error(\n `Error in openai_test_image_description: ${message}`,\n );\n }\n },\n },\n {\n name: \"openai_test_transcription\",\n fn: async (runtime: IAgentRuntime) => {\n logger.log(\"openai_test_transcription\");\n try {\n const response = await fetch(\n \"https://upload.wikimedia.org/wikipedia/en/4/40/Chris_Benoit_Voice_Message.ogg\",\n );\n const arrayBuffer = await response.arrayBuffer();\n const transcription = await runtime.useModel(\n ModelType.TRANSCRIPTION,\n Buffer.from(new Uint8Array(arrayBuffer)),\n );\n logger.log(\n { transcription },\n \"generated with test_transcription\",\n );\n } catch (error: unknown) {\n const message =\n error instanceof Error ? error.message : String(error);\n logger.error(`Error in test_transcription: ${message}`);\n throw error;\n }\n },\n },\n {\n name: \"openai_test_text_tokenizer_encode\",\n fn: async (runtime: IAgentRuntime) => {\n const prompt = \"Hello tokenizer encode!\";\n const tokens = await runtime.useModel(\n ModelType.TEXT_TOKENIZER_ENCODE,\n { prompt },\n );\n if (!Array.isArray(tokens) || tokens.length === 0) {\n throw new Error(\n \"Failed to tokenize text: expected non-empty array of tokens\",\n );\n }\n logger.log({ tokens }, \"Tokenized output\");\n },\n },\n {\n name: \"openai_test_text_tokenizer_decode\",\n fn: async (runtime: IAgentRuntime) => {\n const prompt = \"Hello tokenizer decode!\";\n const tokens = await runtime.useModel(\n ModelType.TEXT_TOKENIZER_ENCODE,\n { prompt },\n );\n const decodedText = await runtime.useModel(\n ModelType.TEXT_TOKENIZER_DECODE,\n { tokens },\n );\n if (decodedText !== prompt) {\n throw new Error(\n `Decoded text does not match original. Expected \"${prompt}\", got \"${decodedText}\"`,\n );\n }\n logger.log({ decodedText }, \"Decoded text\");\n },\n },\n {\n name: \"openai_test_text_to_speech\",\n fn: async (runtime: IAgentRuntime) => {\n try {\n const text = \"Hello, this is a test for text-to-speech.\";\n const response = await fetchTextToSpeech(runtime, text);\n if (!response) {\n throw new Error(\"Failed to generate speech\");\n }\n logger.log(\"Generated speech successfully\");\n } catch (error: unknown) {\n const message =\n error instanceof Error ? error.message : String(error);\n logger.error(`Error in openai_test_text_to_speech: ${message}`);\n throw error;\n }\n },\n },\n ],\n },\n ],\n};\nexport default openaiPlugin;\n"
6
+ ],
7
+ "mappings": "AAAA,uBAAS,uBAYT,oBAAS,YAAW,eAAQ,iBAAW,sBACvC,yBACE,kBACA,oBACA,WAIF,2BAAS,oBAST,SAAS,CAAU,CACjB,EACA,EACA,EACoB,CACpB,OAAO,EAAQ,WAAW,CAAG,GAAK,QAAQ,IAAI,IAAQ,EAGxD,SAAS,CAAS,EAAY,CAC5B,OACE,OAAO,WAAe,KACtB,OAAQ,WAAmB,SAAa,IAI5C,SAAS,CAAa,CACpB,EACA,EAAe,GACS,CACxB,GAAI,EAAU,EAAG,MAAO,CAAC,EACzB,IAAM,EAAM,EAAe,EAAmB,CAAO,EAAI,EAAU,CAAO,EAC1E,OAAO,EAAM,CAAE,cAAe,UAAU,GAAM,EAAI,CAAC,EAQrD,SAAS,CAAU,CAAC,EAAgC,CAClD,IAAM,EAAa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1,2 @@
1
+ export * from '../index';
2
+ export { default } from '../index';
@@ -0,0 +1,2 @@
1
+ export * from '../index';
2
+ export { default } from '../index';