@smythos/sre 1.5.31 → 1.5.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import dotenv from"dotenv";import Joi from"joi";import"dotenv/config";import winston from"winston";import Transport from"winston-transport";import pLimit from"p-limit";import axios,{AxiosHeaders}from"axios";import*as fs from"fs";import fs__default,{existsSync,mkdirSync,writeFileSync,readFileSync,unlinkSync}from"fs";import*as FileType from"file-type";import{fileTypeFromBuffer}from"file-type";import{isBinaryFileSync}from"isbinaryfile";import EventEmitter$1,{EventEmitter}from"events";import crypto$1,{createHash,randomUUID}from"crypto";import{encode,encodeChat}from"gpt-tokenizer";import path from"path";import os from"os";import"process";import mime from"mime";import{Readable}from"stream";import xxhash from"xxhashjs";import{jsonrepair}from"jsonrepair";import yaml from"js-yaml";import{EventSource}from"eventsource";import*as acorn from"acorn";import dayjs from"dayjs";import querystring from"querystring";import{HfInference}from"@huggingface/inference";import{Runware}from"@runware/sdk-js";import FormData from"form-data";import{SocksProxyAgent}from"socks-proxy-agent";import OAuth from"oauth-1.0a";import zl from"zip-lib";import{LambdaClient,GetFunctionCommand,UpdateFunctionCodeCommand,Runtime,CreateFunctionCommand,InvokeCommand}from"@aws-sdk/client-lambda";import{IAMClient,GetRoleCommand,CreateRoleCommand}from"@aws-sdk/client-iam";import{Client}from"@modelcontextprotocol/sdk/client/index.js";import{SSEClientTransport}from"@modelcontextprotocol/sdk/client/sse.js";import{GetBucketLifecycleConfigurationCommand,PutBucketLifecycleConfigurationCommand,S3Client,HeadObjectCommand,DeleteObjectCommand,GetObjectCommand,PutObjectCommand,PutObjectTaggingCommand,GetObjectTaggingCommand,CopyObjectCommand}from"@aws-sdk/client-s3";import imageSize from"image-size";import{execSync}from"child_process";import{Pinecone}from"@pinecone-database/pinecone";import OpenAI,{toFile,OpenAI as OpenAI$1}from"openai";import{MilvusClient,DataType,ErrorCode}from"@zilliz/milvus2-sdk-node";import{GoogleGenerativeAI}from"@google/generative-ai";import{GoogleAIFileManager,FileState}from"@google/generative-ai/server";import Anthropic from"@anthropic-ai/sdk";import Groq from"groq-sdk";import{BedrockRuntimeClient,ConverseCommand,ConverseStreamCommand}from"@aws-sdk/client-bedrock-runtime";import{VertexAI}from"@google-cloud/vertexai";import chokidar from"chokidar";import fs$1 from"fs/promises";import IORedis from"ioredis";import mysql from"mysql2/promise";import{SecretsManagerClient,ListSecretsCommand,GetSecretValueCommand,PutSecretValueCommand,CreateSecretCommand,DeleteSecretCommand}from"@aws-sdk/client-secrets-manager";import*as readlineSync from"readline-sync";var version="1.5.31";dotenv.config();const config={env:{LOG_LEVEL:process.env.LOG_LEVEL||"none",LOG_FILTER:process.env.LOG_FILTER||"",NODE_ENV:process.env?.NODE_ENV}},REQUEST_METHODS=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"],REQUEST_CONTENT_TYPES={none:"none",urlEncodedFormData:"application/x-www-form-urlencoded",multipartFormData:"multipart/form-data",json:"application/json",text:"text/plain",xml:"application/xml",binary:"binary"};var EMBODIMENT_TYPES=(EMBODIMENT_TYPES2=>(EMBODIMENT_TYPES2.ChatBot="chatBot",EMBODIMENT_TYPES2.ChatGPT="chatGPT",EMBODIMENT_TYPES2))(EMBODIMENT_TYPES||{});const ERR_MSG_INVALID_IMAGE_SOURCE="Please provide a valid Image Source. Supported image sources are: HTTP(S) URL, Base64 string, Data URL, Output Image from other component(s).",ERR_MSG_INVALID_BINARY="Please provide a valid data that is either a Blob, SmythFileObject (Binary Output from any Component), ArrayBuffer, Buffer, Base64 string, Data URL, or HTTP(s) URL",ERR_MSG_MAX_DEPTH="The maximum depth has been exceeded for the provided array or object.",ERR_MSG_MAX_ARRAY_SIZE="The maximum array size has been exceeded for the provided array.",ERR_MSG_MAX_OBJECT_SIZE="The maximum object size has been exceeded for the provided object.",MAX_DEPTH=10,MAX_OBJECT_SIZE=1e3,MAX_ARRAY_SIZE=1e3,MAX_FILE_SIZE=10*1024*1024,MAX_FILE_COUNT=10,DEFAULT_MAX_TOKENS_FOR_LLM=2048,S3_DAILY_PURGE_LIFECYCLE_TAG="ExpirationPolicy=DeleteDaily",S3_WEEKLY_PURGE_LIFECYCLE_TAG="ExpirationPolicy=DeleteWeekly",S3_MONTHLY_PURGE_LIFECYCLE_TAG="ExpirationPolicy=DeleteMonthly",TOOL_USE_DEFAULT_MODEL="gpt-4o-mini",COMP_NAMES={apiCall:"APICall",code:"Code",llmPrompt:"PromptGenerator",visionLLM:"VisionLLM"},JSON_RESPONSE_INSTRUCTION=`
1
+ import dotenv from"dotenv";import Joi from"joi";import"dotenv/config";import winston from"winston";import Transport from"winston-transport";import pLimit from"p-limit";import axios,{AxiosHeaders}from"axios";import*as fs from"fs";import fs__default,{existsSync,mkdirSync,writeFileSync,readFileSync,unlinkSync}from"fs";import*as FileType from"file-type";import{fileTypeFromBuffer}from"file-type";import{isBinaryFileSync}from"isbinaryfile";import EventEmitter$1,{EventEmitter}from"events";import crypto$1,{createHash,randomUUID}from"crypto";import{encode,encodeChat}from"gpt-tokenizer";import path from"path";import os from"os";import"process";import mime from"mime";import{Readable}from"stream";import xxhash from"xxhashjs";import{jsonrepair}from"jsonrepair";import yaml from"js-yaml";import{EventSource}from"eventsource";import*as acorn from"acorn";import dayjs from"dayjs";import querystring from"querystring";import{HfInference}from"@huggingface/inference";import{Runware}from"@runware/sdk-js";import FormData from"form-data";import{SocksProxyAgent}from"socks-proxy-agent";import OAuth from"oauth-1.0a";import zl from"zip-lib";import{LambdaClient,GetFunctionCommand,UpdateFunctionCodeCommand,Runtime,CreateFunctionCommand,InvokeCommand}from"@aws-sdk/client-lambda";import{IAMClient,GetRoleCommand,CreateRoleCommand}from"@aws-sdk/client-iam";import{Client}from"@modelcontextprotocol/sdk/client/index.js";import{SSEClientTransport}from"@modelcontextprotocol/sdk/client/sse.js";import{GetBucketLifecycleConfigurationCommand,PutBucketLifecycleConfigurationCommand,S3Client,HeadObjectCommand,DeleteObjectCommand,GetObjectCommand,PutObjectCommand,PutObjectTaggingCommand,GetObjectTaggingCommand,CopyObjectCommand}from"@aws-sdk/client-s3";import imageSize from"image-size";import{execSync}from"child_process";import{Pinecone}from"@pinecone-database/pinecone";import OpenAI,{toFile,OpenAI as OpenAI$1}from"openai";import{MilvusClient,DataType,ErrorCode}from"@zilliz/milvus2-sdk-node";import{GoogleGenerativeAI}from"@google/generative-ai";import{GoogleAIFileManager,FileState}from"@google/generative-ai/server";import Anthropic from"@anthropic-ai/sdk";import Groq from"groq-sdk";import{BedrockRuntimeClient,ConverseCommand,ConverseStreamCommand}from"@aws-sdk/client-bedrock-runtime";import{VertexAI}from"@google-cloud/vertexai";import chokidar from"chokidar";import fs$1 from"fs/promises";import IORedis from"ioredis";import mysql from"mysql2/promise";import{SecretsManagerClient,ListSecretsCommand,GetSecretValueCommand,PutSecretValueCommand,CreateSecretCommand,DeleteSecretCommand}from"@aws-sdk/client-secrets-manager";import*as readlineSync from"readline-sync";var version="1.5.32";dotenv.config();const config={env:{LOG_LEVEL:process.env.LOG_LEVEL||"none",LOG_FILTER:process.env.LOG_FILTER||"",NODE_ENV:process.env?.NODE_ENV}},REQUEST_METHODS=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"],REQUEST_CONTENT_TYPES={none:"none",urlEncodedFormData:"application/x-www-form-urlencoded",multipartFormData:"multipart/form-data",json:"application/json",text:"text/plain",xml:"application/xml",binary:"binary"};var EMBODIMENT_TYPES=(EMBODIMENT_TYPES2=>(EMBODIMENT_TYPES2.ChatBot="chatBot",EMBODIMENT_TYPES2.ChatGPT="chatGPT",EMBODIMENT_TYPES2))(EMBODIMENT_TYPES||{});const ERR_MSG_INVALID_IMAGE_SOURCE="Please provide a valid Image Source. Supported image sources are: HTTP(S) URL, Base64 string, Data URL, Output Image from other component(s).",ERR_MSG_INVALID_BINARY="Please provide a valid data that is either a Blob, SmythFileObject (Binary Output from any Component), ArrayBuffer, Buffer, Base64 string, Data URL, or HTTP(s) URL",ERR_MSG_MAX_DEPTH="The maximum depth has been exceeded for the provided array or object.",ERR_MSG_MAX_ARRAY_SIZE="The maximum array size has been exceeded for the provided array.",ERR_MSG_MAX_OBJECT_SIZE="The maximum object size has been exceeded for the provided object.",MAX_DEPTH=10,MAX_OBJECT_SIZE=1e3,MAX_ARRAY_SIZE=1e3,MAX_FILE_SIZE=10*1024*1024,MAX_FILE_COUNT=10,DEFAULT_MAX_TOKENS_FOR_LLM=2048,S3_DAILY_PURGE_LIFECYCLE_TAG="ExpirationPolicy=DeleteDaily",S3_WEEKLY_PURGE_LIFECYCLE_TAG="ExpirationPolicy=DeleteWeekly",S3_MONTHLY_PURGE_LIFECYCLE_TAG="ExpirationPolicy=DeleteMonthly",TOOL_USE_DEFAULT_MODEL="gpt-4o-mini",COMP_NAMES={apiCall:"APICall",code:"Code",llmPrompt:"PromptGenerator",visionLLM:"VisionLLM"},JSON_RESPONSE_INSTRUCTION=`
2
2
  Respond ONLY with a valid, parsable JSON object. Follow these strict guidelines:
3
3
  1. The response must begin with '{' and end with '}'.
4
4
  2. Use double quotes for all keys and string values.
@@ -93,7 +93,7 @@ ${_error}
93
93
  ${_error}
94
94
  `),{hash:void 0,_error,_debug:logger2.output,_debug_time:logger2.elapsedTime}}}}class FTimestamp extends Component{constructor(){super()}init(){}async process(input,config2,agent){await super.process(input,config2,agent);const logger2=this.createComponentLogger(agent,config2);try{const format=config2.data.format,Timestamp=Date.now();return logger2.debug(`Timestamp : ${Timestamp}`),{Timestamp,_error:void 0,_debug:logger2.output,_debug_time:logger2.elapsedTime}}catch(err){const _error=err?.response?.data||err?.message||err.toString();return logger2.error(` Error processing data
95
95
  ${_error}
96
- `),{hash:void 0,_error,_debug:logger2.output,_debug_time:logger2.elapsedTime}}}}var __defProp$11=Object.defineProperty,__defNormalProp$11=(obj,key,value)=>key in obj?__defProp$11(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,__publicField$11=(obj,key,value)=>__defNormalProp$11(obj,typeof key!="symbol"?key+"":key,value);class GenAILLM extends Component{constructor(){super(),__publicField$11(this,"schema",{name:"GenAILLM",description:"Use this component to generate a responses from an LLM",settings:{model:{type:"string",max:200,required:!0},prompt:{type:"string",max:8e6,label:"Prompt"},temperature:{type:"number",min:0,max:5,label:"Temperature"},maxTokens:{type:"number",min:1,label:"Maximum Tokens"},maxThinkingTokens:{type:"number",min:1,label:"Maximum Thinking Tokens"},stopSequences:{type:"string",max:400,label:"Stop Sequences",allowEmpty:!0},topP:{type:"number",min:0,max:1,label:"Top P"},topK:{type:"number",min:0,max:500,label:"Top K"},frequencyPenalty:{type:"number",min:0,max:2,label:"Frequency Penalty"},presencePenalty:{type:"number",min:0,max:2,label:"Presence Penalty"},responseFormat:{type:"string",valid:["json","text"],label:"Response Format"},passthrough:{type:"boolean",description:"If true, the LLM response will be returned as is by the agent",label:"Passthrough"},useSystemPrompt:{type:"boolean",description:"If true, the component will use parent agent system prompt",label:"Use System Prompt"},useContextWindow:{type:"boolean",description:"If true, the component will use parent agent context window",label:"Use Context Window"},maxContextWindowLength:{type:"number",min:0,description:"The maximum number of messages to use from this component context window (if useContextWindow is true)",label:"Maximum Context Window Length"},useWebSearch:{type:"boolean",description:"If true, the component will use web search for additional context",label:"Use Web Search"},webSearchContextSize:{type:"string",valid:["high","medium","low"],label:"Web Search Context Size"},webSearchCity:{type:"string",max:100,label:"Web Search City",allowEmpty:!0},webSearchCountry:{type:"string",max:2,label:"Web Search Country",allowEmpty:!0},webSearchRegion:{type:"string",max:100,label:"Web Search Region",allowEmpty:!0},webSearchTimezone:{type:"string",max:100,label:"Web Search Timezone",allowEmpty:!0},useSearch:{type:"boolean",description:"If true, the component will use xAI live search capabilities",label:"Use Search"},searchMode:{type:"string",valid:["auto","on","off"],label:"Search Mode"},returnCitations:{type:"boolean",description:"If true, include citations and sources in the response",label:"Return Citations"},maxSearchResults:{type:"number",min:1,max:50,label:"Max Search Results"},searchDataSources:{type:"array",max:4,label:"Search Data Sources",allowEmpty:!0},searchCountry:{type:"string",max:2,label:"Search Country",allowEmpty:!0},excludedWebsites:{type:"string",max:1e4,label:"Excluded Websites",allowEmpty:!0},allowedWebsites:{type:"string",max:1e4,label:"Allowed Websites",allowEmpty:!0},includedXHandles:{type:"string",max:1e3,label:"Included X Handles",allowEmpty:!0},excludedXHandles:{type:"string",max:1e3,label:"Excluded X Handles",allowEmpty:!0},postFavoriteCount:{type:"number",min:0,max:1e9,label:"Post Favorite Count"},postViewCount:{type:"number",min:0,max:1e9,label:"Post View Count"},link:{type:"string",max:5e3,label:"RSS Link",allowEmpty:!0},safeSearch:{type:"boolean",description:"If true, enable safe search filtering",label:"Safe Search"},fromDate:{type:"string",max:10,label:"From Date",allowEmpty:!0},toDate:{type:"string",max:10,label:"To Date",allowEmpty:!0}},inputs:{Input:{type:"Any",description:"An input that you can pass to the LLM"},Attachment:{type:"Binary",description:"An attachment that you can pass to the LLM",optional:!0}},outputs:{Reply:{default:!0}}}),__publicField$11(this,"configSchema",Joi.object({model:Joi.string().max(200).required(),prompt:Joi.string().required().max(8e6).label("Prompt"),temperature:Joi.number().min(0).max(5).label("Temperature"),maxTokens:Joi.number().min(1).label("Maximum Tokens"),stopSequences:Joi.string().allow("").max(400).label("Stop Sequences"),topP:Joi.number().min(0).max(1).label("Top P"),topK:Joi.number().min(0).max(500).label("Top K"),frequencyPenalty:Joi.number().min(0).max(2).label("Frequency Penalty"),presencePenalty:Joi.number().min(0).max(2).label("Presence Penalty"),responseFormat:Joi.string().valid("json","text").allow("").optional().label("Response Format"),passthrough:Joi.boolean().optional().label("Passthrough"),useSystemPrompt:Joi.boolean().optional().label("Use System Prompt"),useContextWindow:Joi.boolean().optional().label("Use Context Window"),maxContextWindowLength:Joi.number().optional().min(0).label("Maximum Context Window Length"),useWebSearch:Joi.boolean().optional().label("Use Web Search"),webSearchContextSize:Joi.string().valid("high","medium","low").optional().label("Web Search Context Size"),webSearchCity:Joi.string().max(100).optional().allow("").label("Web Search City"),webSearchCountry:Joi.string().max(2).optional().allow("").label("Web Search Country"),webSearchRegion:Joi.string().max(100).optional().allow("").label("Web Search Region"),webSearchTimezone:Joi.string().max(100).optional().allow("").label("Web Search Timezone"),useSearch:Joi.boolean().optional().label("Use Search"),searchMode:Joi.string().valid("auto","on","off").optional().label("Search Mode"),returnCitations:Joi.boolean().optional().label("Return Citations"),maxSearchResults:Joi.number().min(1).max(100).optional().label("Max Search Results"),searchDataSources:Joi.array().items(Joi.string().valid("web","x","news","rss")).max(4).optional().label("Search Data Sources"),searchCountry:Joi.string().length(2).optional().allow("").label("Search Country"),excludedWebsites:Joi.string().max(1e4).optional().allow("").label("Excluded Websites"),allowedWebsites:Joi.string().max(1e4).optional().allow("").label("Allowed Websites"),includedXHandles:Joi.string().max(1e3).optional().allow("").label("Included X Handles"),excludedXHandles:Joi.string().max(1e3).optional().allow("").label("Excluded X Handles"),postFavoriteCount:Joi.number().min(0).max(1e9).optional().label("Post Favorite Count"),postViewCount:Joi.number().min(0).max(1e9).optional().label("Post View Count"),rssLinks:Joi.string().max(1e4).optional().allow("").label("RSS Link"),safeSearch:Joi.boolean().optional().label("Safe Search"),fromDate:Joi.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("").label("From Date"),toDate:Joi.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("").label("To Date"),useReasoning:Joi.boolean().optional().label("Use Reasoning"),maxThinkingTokens:Joi.number().min(1).label("Maximum Thinking Tokens")}))}init(){}async process(input,config2,agent){await super.process(input,config2,agent);const logger2=this.createComponentLogger(agent,config2);try{logger2.debug("=== GenAILLM Log ===");let teamId=agent?.teamId;const passThrough=config2.data.passthrough||!1,useContextWindow=config2.data.useContextWindow||!1,useSystemPrompt=config2.data.useSystemPrompt||!1,useWebSearch=config2.data.useWebSearch||!1,maxTokens=parseInt(config2.data.maxTokens)||1024,maxContextWindowLength=parseInt(config2.data.maxContextWindowLength)||1024,model=config2.data.model||"echo",llmInference=await LLMInference$1.getInstance(model,AccessCandidate.agent(agent.id));if(!llmInference.connector)return{_error:`The model '${model}' is not available. Please try a different one.`,_debug:logger2.output};const modelId=await agent.modelsProvider.getModelId(model);logger2.debug(` Model : ${modelId||model}`);let prompt=TemplateString(config2.data.prompt).parse(input).result,files=parseFiles$1(input,config2),isMultimodalRequest=!1;const provider=await agent.modelsProvider.getProvider(model),isEcho=provider==="Echo";if(files?.length>0&&!isEcho){const supportedFileTypes=SUPPORTED_MIME_TYPES_MAP?.[provider]||{},features=(await agent.modelsProvider.getModelInfo(model))?.features||[],fileTypes=new Set;if(files=(await Promise.all(files.map(async file=>{const mimeType=file?.mimetype||await getMimeType(file),[requestFeature=""]=Object.entries(supportedFileTypes).find(([key,value])=>value.includes(mimeType))||[];return mimeType&&fileTypes.add(mimeType),features?.includes(requestFeature)?file:null}))).filter(Boolean),files.length===0)return{_error:`Model does not support ${fileTypes?.size>0?Array.from(fileTypes).join(", "):"File(s)"}`,_debug:logger2.output};isMultimodalRequest=!0}logger2.debug(` Prompt
96
+ `),{hash:void 0,_error,_debug:logger2.output,_debug_time:logger2.elapsedTime}}}}var __defProp$11=Object.defineProperty,__defNormalProp$11=(obj,key,value)=>key in obj?__defProp$11(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,__publicField$11=(obj,key,value)=>__defNormalProp$11(obj,typeof key!="symbol"?key+"":key,value);class GenAILLM extends Component{constructor(){super(),__publicField$11(this,"schema",{name:"GenAILLM",description:"Use this component to generate a responses from an LLM",settings:{model:{type:"string",max:200,required:!0},prompt:{type:"string",max:8e6,label:"Prompt"},temperature:{type:"number",min:0,max:5,label:"Temperature"},maxTokens:{type:"number",min:1,label:"Maximum Tokens"},maxThinkingTokens:{type:"number",min:1,label:"Maximum Thinking Tokens"},stopSequences:{type:"string",max:400,label:"Stop Sequences",allowEmpty:!0},topP:{type:"number",min:0,max:1,label:"Top P"},topK:{type:"number",min:0,max:500,label:"Top K"},frequencyPenalty:{type:"number",min:0,max:2,label:"Frequency Penalty"},presencePenalty:{type:"number",min:0,max:2,label:"Presence Penalty"},responseFormat:{type:"string",valid:["json","text"],label:"Response Format"},passthrough:{type:"boolean",description:"If true, the LLM response will be returned as is by the agent",label:"Passthrough"},useSystemPrompt:{type:"boolean",description:"If true, the component will use parent agent system prompt",label:"Use System Prompt"},useContextWindow:{type:"boolean",description:"If true, the component will use parent agent context window",label:"Use Context Window"},maxContextWindowLength:{type:"number",min:0,description:"The maximum number of messages to use from this component context window (if useContextWindow is true)",label:"Maximum Context Window Length"},useWebSearch:{type:"boolean",description:"If true, the component will use web search for additional context",label:"Use Web Search"},webSearchContextSize:{type:"string",valid:["high","medium","low"],label:"Web Search Context Size"},webSearchCity:{type:"string",max:100,label:"Web Search City",allowEmpty:!0},webSearchCountry:{type:"string",max:2,label:"Web Search Country",allowEmpty:!0},webSearchRegion:{type:"string",max:100,label:"Web Search Region",allowEmpty:!0},webSearchTimezone:{type:"string",max:100,label:"Web Search Timezone",allowEmpty:!0},useSearch:{type:"boolean",description:"If true, the component will use xAI live search capabilities",label:"Use Search",allowEmpty:!0},searchMode:{type:"string",valid:["auto","on","off"],label:"Search Mode",allowEmpty:!0},returnCitations:{type:"boolean",description:"If true, include citations and sources in the response",label:"Return Citations",allowEmpty:!0},maxSearchResults:{type:"number",min:1,max:50,label:"Max Search Results",allowEmpty:!0},searchDataSources:{type:"array",max:4,label:"Search Data Sources",allowEmpty:!0},searchCountry:{type:"string",max:2,label:"Search Country",allowEmpty:!0},excludedWebsites:{type:"string",max:1e4,label:"Excluded Websites",allowEmpty:!0},allowedWebsites:{type:"string",max:1e4,label:"Allowed Websites",allowEmpty:!0},includedXHandles:{type:"string",max:1e3,label:"Included X Handles",allowEmpty:!0},excludedXHandles:{type:"string",max:1e3,label:"Excluded X Handles",allowEmpty:!0},postFavoriteCount:{type:"number",min:0,max:1e9,label:"Post Favorite Count",allowEmpty:!0},postViewCount:{type:"number",min:0,max:1e9,label:"Post View Count",allowEmpty:!0},link:{type:"string",max:5e3,label:"RSS Link",allowEmpty:!0},safeSearch:{type:"boolean",description:"If true, enable safe search filtering",label:"Safe Search",allowEmpty:!0},fromDate:{type:"string",max:10,label:"From Date",allowEmpty:!0},toDate:{type:"string",max:10,label:"To Date",allowEmpty:!0}},inputs:{Input:{type:"Any",description:"An input that you can pass to the LLM"},Attachment:{type:"Binary",description:"An attachment that you can pass to the LLM",optional:!0}},outputs:{Reply:{default:!0}}}),__publicField$11(this,"configSchema",Joi.object({model:Joi.string().max(200).required(),prompt:Joi.string().required().max(8e6).label("Prompt"),temperature:Joi.number().min(0).max(5).label("Temperature"),maxTokens:Joi.number().min(1).label("Maximum Tokens"),stopSequences:Joi.string().allow("").max(400).label("Stop Sequences"),topP:Joi.number().min(0).max(1).label("Top P"),topK:Joi.number().min(0).max(500).label("Top K"),frequencyPenalty:Joi.number().min(0).max(2).label("Frequency Penalty"),presencePenalty:Joi.number().min(0).max(2).label("Presence Penalty"),responseFormat:Joi.string().valid("json","text").allow("").optional().label("Response Format"),passthrough:Joi.boolean().optional().label("Passthrough"),useSystemPrompt:Joi.boolean().optional().label("Use System Prompt"),useContextWindow:Joi.boolean().optional().label("Use Context Window"),maxContextWindowLength:Joi.number().optional().min(0).label("Maximum Context Window Length"),useWebSearch:Joi.boolean().optional().label("Use Web Search"),webSearchContextSize:Joi.string().valid("high","medium","low").optional().label("Web Search Context Size"),webSearchCity:Joi.string().max(100).optional().allow("").label("Web Search City"),webSearchCountry:Joi.string().max(2).optional().allow("").label("Web Search Country"),webSearchRegion:Joi.string().max(100).optional().allow("").label("Web Search Region"),webSearchTimezone:Joi.string().max(100).optional().allow("").label("Web Search Timezone"),useSearch:Joi.boolean().optional().allow("").label("Use Search"),searchMode:Joi.string().valid("auto","on","off").optional().allow("").label("Search Mode"),returnCitations:Joi.boolean().optional().allow("").label("Return Citations"),maxSearchResults:Joi.number().min(1).max(100).optional().allow("").label("Max Search Results"),searchDataSources:Joi.array().items(Joi.string().valid("web","x","news","rss")).max(4).optional().allow("").label("Search Data Sources"),searchCountry:Joi.string().length(2).optional().allow("").label("Search Country"),excludedWebsites:Joi.string().max(1e4).optional().allow("").label("Excluded Websites"),allowedWebsites:Joi.string().max(1e4).optional().allow("").label("Allowed Websites"),includedXHandles:Joi.string().max(1e3).optional().allow("").label("Included X Handles"),excludedXHandles:Joi.string().max(1e3).optional().allow("").label("Excluded X Handles"),postFavoriteCount:Joi.number().min(0).max(1e9).optional().allow("").label("Post Favorite Count"),postViewCount:Joi.number().min(0).max(1e9).optional().allow("").label("Post View Count"),rssLinks:Joi.string().max(1e4).optional().allow("").label("RSS Link"),safeSearch:Joi.boolean().optional().allow("").label("Safe Search"),fromDate:Joi.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("").label("From Date"),toDate:Joi.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("").label("To Date"),useReasoning:Joi.boolean().optional().label("Use Reasoning"),maxThinkingTokens:Joi.number().min(1).label("Maximum Thinking Tokens")}))}init(){}async process(input,config2,agent){await super.process(input,config2,agent);const logger2=this.createComponentLogger(agent,config2);try{logger2.debug("=== GenAILLM Log ===");let teamId=agent?.teamId;const passThrough=config2.data.passthrough||!1,useContextWindow=config2.data.useContextWindow||!1,useSystemPrompt=config2.data.useSystemPrompt||!1,useWebSearch=config2.data.useWebSearch||!1,maxTokens=parseInt(config2.data.maxTokens)||1024,maxContextWindowLength=parseInt(config2.data.maxContextWindowLength)||1024,model=config2.data.model||"echo",llmInference=await LLMInference$1.getInstance(model,AccessCandidate.agent(agent.id));if(!llmInference.connector)return{_error:`The model '${model}' is not available. Please try a different one.`,_debug:logger2.output};const modelId=await agent.modelsProvider.getModelId(model);logger2.debug(` Model : ${modelId||model}`);let prompt=TemplateString(config2.data.prompt).parse(input).result,files=parseFiles$1(input,config2),isMultimodalRequest=!1;const provider=await agent.modelsProvider.getProvider(model),isEcho=provider==="Echo";if(files?.length>0&&!isEcho){const supportedFileTypes=SUPPORTED_MIME_TYPES_MAP?.[provider]||{},features=(await agent.modelsProvider.getModelInfo(model))?.features||[],fileTypes=new Set;if(files=(await Promise.all(files.map(async file=>{const mimeType=file?.mimetype||await getMimeType(file),[requestFeature=""]=Object.entries(supportedFileTypes).find(([key,value])=>value.includes(mimeType))||[];return mimeType&&fileTypes.add(mimeType),features?.includes(requestFeature)?file:null}))).filter(Boolean),files.length===0)return{_error:`Model does not support ${fileTypes?.size>0?Array.from(fileTypes).join(", "):"File(s)"}`,_debug:logger2.output};isMultimodalRequest=!0}logger2.debug(` Prompt
97
97
  `,prompt,`
98
98
  `),isEcho||logger2.debug(` Files
99
99
  `,await Promise.all(files.map(file=>formatDataForDebug(file))));const hasCustomOutputs=config2?.outputs?.some(output=>!output.default);config2.data.responseFormat=config2.data?.responseFormat||(hasCustomOutputs?"json":"");let response;const _prompt=llmInference.connector.enhancePrompt(prompt,config2);let messages=[],systemPrompt="";if(useSystemPrompt&&(systemPrompt=await agent.agentRuntime.llmCache.get("systemPrompt","text")||agent.data?.behavior||"",systemPrompt&&logger2.debug(` Using Agent System Prompt