UNPKG

@websolutespa/payload-plugin-bowl-llm

Version:

LLM plugin for Bowl PayloadCms plugin

743 lines (741 loc) 20.8 kB
import { CollectionSlug, Payload, PayloadHandler, PayloadRequest, TypeWithID } from "payload"; import { IEquatable, IMedia } from "@websolutespa/bom-core"; import { BowlBlock, BowlPlugin } from "@websolutespa/payload-plugin-bowl"; import { Resource } from "@websolutespa/payload-utils"; //#region src/api/types.d.ts type LlmChunkLog = Record<string, unknown> & { type: 'log'; }; type LlmChunkError = { type: 'error'; error: string; }; type LlmChunkHeader = { type: 'header'; threadId: string; messageId: string; }; type LlmChunkInfo = { type: 'info'; threadId: string; }; type LlmChunkEnd = { type: 'end'; }; type LlmChunkText = { type: 'text'; text: string; }; type LlmChunkString = { type: 'string'; content: string; }; type LlmChunkTextOrString = LlmChunkText | LlmChunkString; declare function isChunkText(chunk: LlmChunkItem): chunk is LlmChunkText; declare function isChunkString(chunk: LlmChunkItem): chunk is LlmChunkString; declare function isChunkTextOrString(chunk: LlmChunkItem): chunk is LlmChunkTextOrString; type LlmChunkImage = { type: 'image'; url: string; }; type LlmChunkFile = { type: 'file'; url: string; }; type ImageUrl = { url: string; }; type LlmChunkImageUrl = { type: 'image_url'; image_url: ImageUrl; }; type LlmChunkKnownItem = LlmChunkEnd | LlmChunkError | LlmChunkFile | LlmChunkImage | LlmChunkImageUrl | LlmChunkHeader | LlmChunkInfo | LlmChunkLog | LlmChunkText | LlmChunkString; type NotA<T> = T extends LlmChunkKnownItem['type'] ? never : T; type NotB<T> = LlmChunkKnownItem['type'] extends T ? never : T; type LlmChunkUnknownItemType<T> = NotA<T> & NotB<T>; type LlmChunkUnknownItem = Omit<Record<string, unknown>, 'type'>; type LlmChunkItem = LlmChunkKnownItem; type LlmChunk = string | LlmChunkItem; type LlmMessage = { messageId?: string; role: string; content: string | LlmChunkItem[]; feedback?: { rating?: number; notes?: string; }; createdAt?: Date | string; }; type LlmSerializedMessage = { messageId?: string; role: string; content: string; }; type LlmDecodedMessage = LlmMessage & { chunks: LlmChunkItem[]; }; type StreamResponse = { chunks: LlmChunkItem[]; threadId: string; messageId: string; }; type LlmUpload = { file: File; base64?: string; }; type LlmUploaded = { id: string; name: string; filename: string; mimeType: string; filesize: number; createdAt: string; updatedAt: string; url: string; type: 'image' | 'file'; }; type LlmAttachment = { type: 'image' | 'file'; url: string; }; type LlmSummary = { fullName: string; email: string; privacy: boolean; appId: string; threadId: string; summaryUrl: string; html: string; }; type LlmAppReferrer = { id: string; referrer: string; }; type LlmMapReplacedField = { srcName: string; destName: string; }; type LlmMapNewField = { name: string; value: string; }; type LlmMapDeletedField = { name: string; }; type LlmMapMetaField = { name: string; description: string; type: string; }; type LlmFieldsMapping = { replacedFields: LlmMapReplacedField[]; newFields: LlmMapNewField[]; deletedFields: LlmMapDeletedField[]; metaFields: LlmMapMetaField[]; }; type LlmKnowledgeBaseEndpoint = { endpointUrl: string; authentication: string; authSecret: string; fieldsMapping: LlmFieldsMapping; id: string; }; type VectorDb = Record<string, unknown> & { id: string; filename: string; mimeType: string; filesize: number; createdAt: Date | string; updatedAt?: Date | string; url: string; }; type LlmKnowledgeBaseFile = { media: IMedia; }; type LlmKnowledgeBase = { integrations: BowlBlock[]; externalEndpoints: LlmKnowledgeBaseEndpoint[]; files?: LlmKnowledgeBaseFile[]; vectorDbType?: string; vectorDbFile: VectorDb; chunkingMethod?: string; chunkSize?: number; chunkOverlap?: number; deepLevel?: number; }; type LlmSearchSettings = { searchType: string; scoreThreshold?: number; searchK?: number; metadataFilters?: string[]; }; type LlmChainSettings = { model: string; prompt: string; temperature: number; outputStructure?: { outputType: 'text' | 'json'; outputFormat?: Record<string, unknown>; }; }; type LlmDbSettings = { connectionString: string; }; type LlmApiSettings = { endpoint?: string; method?: string; headers?: Record<string, string>; payload?: Record<string, unknown>; }; type SharepointSettings = { clientId: string; clientSecret: string; tenantId: string; siteId: string; driveId: string; }; type LlmMcpSettings = { mcpUrl?: string; mcpToolName?: string; mcpAuthToken?: string; }; type LlmAppTool = { id: string; isActive: boolean; nightlyKbGeneration: boolean; name: string; description?: string; type: string; functionId: string; functionName: string; functionDescription: string; secrets: LlmAppToolSecret[]; llmChainSettings: LlmChainSettings; dataSource: string; dbSettings: LlmDbSettings; apiSettings: LlmApiSettings; mcpSettings?: LlmMcpSettings; waitingMessage: string; knowledgeBase: LlmKnowledgeBase; searchSettings: LlmSearchSettings; }; type LlmRules = { vector_type: string; vectorDbFile: VectorDb; threshold: number; }; type LlmFineTuning = { modelNameSuffix: string; fineTunedModelName: string; currentJobId?: string; }; type LlmAppSettings = { credentials: LlmAppCredentials; knowledgeBase: LlmKnowledgeBase; llmConfig: LlmAppConfig; fineTuning: LlmFineTuning; appTools: LlmAppTool[]; rules: LlmRules; nightlyKbGeneration: boolean; }; type LlmAppCredentials = { apiKey: string; appKey: string; httpReferrers: LlmAppReferrer[]; previewEnabled?: boolean; }; type LlmAppPrompt = { systemMessage: string; }; type LlmTool = { name: string; description?: string; functionName: string; functionDescription: string; waitingMessage: string; }; type LlmAppSecrets = Record<string, string>; type LlmAppToolSecret = Record<string, string>; type LlmAppConfig = { provider: string; model: string; temperature: number; prompt: { systemMessage: string; prompt: LlmAppPrompt; }; secrets: LlmAppSecrets; tools: LlmTool[]; langChainTracing: boolean; langChainProject: string; outputStructure?: { outputType: string; outputFormat: object | null; }; }; type LlmAppCard = { icon?: IMedia; title: string; body: string; message: string; }; type LlmLogo = { logo: IMedia; }; type LlmSampleInputText = { id: string; sampleInputText: string; }; type LlmHeaderCta = { id: string; title: string; href: string; target: string; icon?: IMedia; }; type LlmRecognitionMode = ('none' | 'default') & string; type LlmSynthesisMode = ('none' | 'default' | 'elevenlabs') & string; type LlmStorageMode = ('locale' | 'session') & string; type LlmAppContents = { additionalLogos?: LlmLogo[]; collapsedWelcomeText?: string; collapsedWelcomeTextCta?: string; collapsedWelcomeTextHover?: string; customIntro?: string; customTheme?: {}; disablePoweredBy?: boolean; disableSpeechRecognition?: boolean; disableSpeechSynthesis?: boolean; disclaimer?: string; disclaimerFooter?: boolean; disclaimerShort?: string; enableFeedback?: boolean; enableHistory?: boolean; enableMinimize?: boolean; enableUpload?: boolean; extendedWelcomeText?: string; headerCtas?: LlmHeaderCta[]; intro?: string; layoutBuilder?: LlmAppCard[]; logo?: IMedia; logoMini?: IMedia; maxFileSize?: number; mimeTypes?: string; openingSound?: IMedia; promptPlaceholder?: string; promptTokenLimit?: number; recognitionMode?: LlmRecognitionMode; sampleInputTexts?: LlmSampleInputText[]; shortWelcomeText?: string; storageMode?: LlmStorageMode; synthesisMode?: LlmSynthesisMode; textToSpeechApiKey?: string; textToSpeechVoiceId?: string; }; type LlmWebhook = { webhook: string; }; type LlmThread = { message: LlmMessage[]; } & TypeWithID; type LlmInfoThread = { messages: LlmMessage[]; threadId: string; }; type LlmInfo = { contents: LlmAppContents; thread?: LlmInfoThread; }; type LlmAppLink = { title: string; url: string; }; type LlmAppLinksGroup = { title: string; links: LlmAppLink[]; }; type LlmAppPlugin = { name?: string; version?: string; namespace?: string; }; type LlmMode = ('site' | 'chat' | 'url2text' | 'translation') & string; type LlmApp = { createdAt: Date | string; settings: LlmAppSettings; id: string; isActive: boolean; name: string; mode: LlmMode; updatedAt: Date | string; contents: LlmAppContents; webhooks: LlmWebhook[]; linksGroups: LlmAppLinksGroup[]; plugin?: LlmAppPlugin; }; type RobotTaskResult = { success: boolean; file?: string; error?: string; }; type RobotTaskMetadataExtra = { traceId: string; appId: string; toolId?: string; [key: string]: string | undefined; }; type RobotTaskCompleted = { status: 'completed'; result: RobotTaskResult; }; type RobotTaskFailed = { status: 'failed'; error: string; }; type RobotTaskResponse = { id: string; type: string; metadata: { extra?: RobotTaskMetadataExtra; [key: string]: string | object | undefined; }; } & (RobotTaskCompleted | RobotTaskFailed); type RobotTaskRequest = { provider: string; model: string; taskId: string; files?: string[]; dataSource?: string; vectorDbType?: string; integrations?: BowlBlock[]; endpoints?: LlmKnowledgeBaseEndpoint[]; secrets: LlmAppSecrets; downloadPath: string; chunkingMethod?: string; chunkSize?: number; chunkOverlap?: number; deepLevel?: number; metadata: { traceId: string; appId: string; toolId?: string; [key: string]: string | undefined; }; }; type LlmTaskLogData = { taskStatus?: string; taskRequest?: RobotTaskRequest; taskResponse?: RobotTaskResponse; savedVectorDb?: {}; error?: string; }; type LlmFeedbackRequest = { appId: string; apiKey: string; threadId: string; messageId?: string; feedbackRating: number; feedbackMessage?: string; }; type RobotFeedbackRequest = { api_key: string; provider: string; user_id: IEquatable; comment: string; rating: number; anonymize: boolean; timestamp: string; message_id?: string; message_input?: string; message_output?: string; }; type AppToolOption = { value: string; label: string; }; type RobotEndpointPostProcessor = { id: string; value: string; }; type LlmKnowledgeBaseCreationMode = keyof typeof LlmKnowledgeBaseCreationMode; type LlmKnowledgeBaseCreationOptions = { mode: LlmKnowledgeBaseCreationMode; forceKbGeneration: boolean; toolFunctionId?: string; }; type LlmKnowledgeBasePollResponse = { processing: boolean; success?: boolean; errors?: { job: string; taskStatus: string; error: string; }[]; }; type RobotModel = { id: string; created: number; object: string; owned_by: string; }; type RobotProvider = { id: string; value: string; }; type LlmRulesResult = { name: string; vectorDbFile?: string | number; status: string; error?: string; }; type RobotTool = { id: string; value: string; }; type RobotVectorDbType = { id: string; value: string; }; type PythonStreamRequest = { mode: string; systemMessage: string; systemContext: object; messages: LlmMessage[]; provider: string | null; model: string | null; temperature: number | null; secrets: LlmAppSecrets; threadId: string; msgId: string; tools: LlmTool[]; appTools: PythonStreamTool[]; vectorDb: string | null; rules: { vector_db: string | null; threshold: number; }; fineTunedModel: string | null; langChainTracing: boolean; langChainProject: string | null; outputStructure: { outputType: string; outputFormat: object | null; } | null; }; type PythonStreamLlmChainSettings = { prompt: string; temperature: number; }; type PythonStreamDbSettings = { connectionString: string; additionalPrompt?: string; limit?: number; }; type PythonStreamApiSettings = { endpoint?: string; method?: string; headers?: Record<string, string>; payload?: Record<string, unknown>; }; type PythonStreamTool = { name: string; description?: string; type: string; functionId: string; functionName: string; functionDescription: string; model?: string; secrets: LlmAppToolSecret[]; llmChainSettings: PythonStreamLlmChainSettings; dataSource: string; dbSettings: PythonStreamDbSettings; apiSettings: PythonStreamApiSettings; searchSettings: LlmSearchSettings; integrations?: BowlBlock[]; endpoints?: LlmKnowledgeBaseEndpoint[]; waitingMessage: string; vectorDbType: string | null; vectorDbFile: string | null; rulesVectorDb: string | null; }; type PythonStreamResponse = Partial<{ created: number; id: string; model: string; object: string; python: string; system_fingerprint: string | null; threadId: string; messageId: string; version: string; }> & { chunks: LlmChunkItem[]; }; type pythonInvokeRequest = { provider: string; mode: string; systemMessage: string; systemContext: object; messages: LlmMessage[]; model: string | null; secrets: LlmAppSecrets; threadId: string; tools: LlmTool[]; appTools: PythonStreamTool[]; vectorDb: string | null; rules: { vectorDbFile: string | null; threshold: number; }; fineTunedModel: string | null; langChainTracing: boolean; langChainProject: string | null; outputStructure: { outputType: string; outputFormat: object | null; } | null; }; //#endregion //#region src/api/app.handler.d.ts declare const appHandler: (req: PayloadRequest) => Promise<LlmApp>; declare const llmAppsHandler: PayloadHandler; //# sourceMappingURL=app.handler.d.ts.map //#endregion //#region src/api/error.handler.d.ts declare const errorHandler: (error: any, init?: ResponseInit) => Response; //# sourceMappingURL=error.handler.d.ts.map //#endregion //#region src/api/fineTuning.handler.d.ts declare function fineTuningJobsHandler(payload: Payload): Promise<void>; declare const fineTuningHandler: PayloadHandler; //# sourceMappingURL=fineTuning.handler.d.ts.map //#endregion //#region src/api/history.handler.d.ts type LlmHistory = { llmApp: LlmApp; userId: string; llmThread: LlmThread; messageId: string; createdAt: string | Date; updatedAt: string | Date; }; type LlmStoredHistory = { threadId: string; messageId: string; }; declare const historyHandler: PayloadHandler; declare const historyAddHandler: PayloadHandler; declare const historyRemoveHandler: PayloadHandler; //# sourceMappingURL=history.handler.d.ts.map //#endregion //#region src/api/info.handler.d.ts declare const infoHandler: PayloadHandler; //# sourceMappingURL=info.handler.d.ts.map //#endregion //#region src/api/knowledgeBase.handler.d.ts declare const kbPollEndpointHandler: PayloadHandler; declare const kbEndpointHandler: PayloadHandler; declare function llmKnowledgeBase(payload: Payload, app?: LlmApp, creationOptions?: LlmKnowledgeBaseCreationOptions): Promise<string>; //# sourceMappingURL=knowledgeBase.handler.d.ts.map //#endregion //#region src/api/message.handler.d.ts declare const downloadVectorDbFile: (vectorDbFileUrl: string | undefined, destFilepath: string) => Promise<string | null>; declare const messageHandler: PayloadHandler; //# sourceMappingURL=message.handler.d.ts.map //#endregion //#region src/api/python/pythonStream.handler.d.ts declare const textToChunksLastUnparsed: { text: string; }; /** * Executes the ROBOT endpoint returning a stream response. * * @param request - The request to be sent to the ROBOT endpoint. * @param callback - Optional callback function to handle the stream response. * @returns The payload handler function. */ declare const pythonStreamHandler: (request: PythonStreamRequest, raw: boolean, callback?: (response: PythonStreamResponse) => void) => PayloadHandler; //# sourceMappingURL=pythonStream.handler.d.ts.map //#endregion //#region src/api/rules.handler.d.ts declare const rulesEndpointHandler: PayloadHandler; declare function getRulesPath(basePath: string, appName: string): string; declare function rulesHandler(payload: Payload, app?: LlmApp): Promise<LlmRulesResult[]>; //# sourceMappingURL=rules.handler.d.ts.map //#endregion //#region src/api/vectorDb.handler.d.ts declare function llmVectorDbsCleaningHandler(payload: Payload): Promise<(string | number)[]>; declare const vectorDbTypesHandler: PayloadHandler; //# sourceMappingURL=vectorDb.handler.d.ts.map //#endregion //#region src/types.d.ts type LlmSlug = Record<string, CollectionSlug> & { llmApp: CollectionSlug; llmAppTool: CollectionSlug; llmFineTuning: CollectionSlug; llmHistory: CollectionSlug; llmKbApi: CollectionSlug; llmKbAzure: CollectionSlug; llmKbConfluence: CollectionSlug; llmKbDropbox: CollectionSlug; llmKbFile: CollectionSlug; llmKbGcs: CollectionSlug; llmKbGithub: CollectionSlug; llmKbGoogledrive: CollectionSlug; llmKbJira: CollectionSlug; llmKbS3: CollectionSlug; llmKbSftp: CollectionSlug; llmKbSharepoint: CollectionSlug; llmKbSharepointCustom: CollectionSlug; llmKbShopify: CollectionSlug; llmKbSitemap: CollectionSlug; llmKbSlack: CollectionSlug; llmKbThron: CollectionSlug; llmKbZendesk: CollectionSlug; llmPrompt: CollectionSlug; llmRule: CollectionSlug; llmThread: CollectionSlug; llmTool: CollectionSlug; llmUserUpload: CollectionSlug; llmVectorDb: CollectionSlug; [key: string]: string; }; type LlmGroup = { llm: string; [key: string]: string; }; type LlmRoles = { LlmEditor: string; LlmContributor: string; }; type LlmOptions = { group: LlmGroup; slug: LlmSlug; defaultTheme?: Record<string, unknown>; translations: Resource; roles: LlmRoles; }; type LlmInitOptions = { group?: Partial<LlmGroup>; slug?: Partial<LlmSlug>; defaultTheme?: Record<string, unknown>; enabled?: boolean; }; declare const LLM_DEFAULT_MIME_TYPES = ".jpg, .jpeg, .png, .svg, .webp, .txt, .md, .pdf, .csv, .doc, .xls, .ppt"; declare const LLM_DEFAULT_MAX_FILE_SIZE = 1048576; //# sourceMappingURL=types.d.ts.map //#endregion //#region src/llm.d.ts type LocalizationOptions = {}; declare const llm: (sourceOptions?: LlmInitOptions) => BowlPlugin; //# sourceMappingURL=llm.d.ts.map //#endregion //#region src/options.d.ts declare const defaultSlug: LlmSlug; declare const defaultGroup: LlmGroup; declare const options: LlmOptions; declare const internalSlugs: string[]; //# sourceMappingURL=options.d.ts.map //#endregion export { AppToolOption, ImageUrl, LLM_DEFAULT_MAX_FILE_SIZE, LLM_DEFAULT_MIME_TYPES, LlmApiSettings, LlmApp, LlmAppCard, LlmAppConfig, LlmAppContents, LlmAppCredentials, LlmAppLink, LlmAppLinksGroup, LlmAppPlugin, LlmAppPrompt, LlmAppReferrer, LlmAppSecrets, LlmAppSettings, LlmAppTool, LlmAppToolSecret, LlmAttachment, LlmChainSettings, LlmChunk, LlmChunkEnd, LlmChunkError, LlmChunkFile, LlmChunkHeader, LlmChunkImage, LlmChunkImageUrl, LlmChunkInfo, LlmChunkItem, LlmChunkKnownItem, LlmChunkLog, LlmChunkString, LlmChunkText, LlmChunkTextOrString, LlmChunkUnknownItem, LlmChunkUnknownItemType, LlmDbSettings, LlmDecodedMessage, LlmFeedbackRequest, LlmFieldsMapping, LlmFineTuning, LlmGroup, LlmHeaderCta, LlmHistory, LlmInfo, LlmInfoThread, LlmInitOptions, LlmKnowledgeBase, LlmKnowledgeBaseCreationMode, LlmKnowledgeBaseCreationOptions, LlmKnowledgeBaseEndpoint, LlmKnowledgeBaseFile, LlmKnowledgeBasePollResponse, LlmLogo, LlmMapDeletedField, LlmMapMetaField, LlmMapNewField, LlmMapReplacedField, LlmMcpSettings, LlmMessage, LlmMode, LlmOptions, LlmRecognitionMode, LlmRoles, LlmRules, LlmRulesResult, LlmSampleInputText, LlmSearchSettings, LlmSerializedMessage, LlmSlug, LlmStorageMode, LlmStoredHistory, LlmSummary, LlmSynthesisMode, LlmTaskLogData, LlmThread, LlmTool, LlmUpload, LlmUploaded, LlmWebhook, LocalizationOptions, PythonStreamApiSettings, PythonStreamDbSettings, PythonStreamLlmChainSettings, PythonStreamRequest, PythonStreamResponse, PythonStreamTool, RobotEndpointPostProcessor, RobotFeedbackRequest, RobotModel, RobotProvider, RobotTaskCompleted, RobotTaskFailed, RobotTaskMetadataExtra, RobotTaskRequest, RobotTaskResponse, RobotTaskResult, RobotTool, RobotVectorDbType, SharepointSettings, StreamResponse, VectorDb, appHandler, llm as default, defaultGroup, defaultSlug, downloadVectorDbFile, errorHandler, fineTuningHandler, fineTuningJobsHandler, getRulesPath, historyAddHandler, historyHandler, historyRemoveHandler, infoHandler, internalSlugs, isChunkString, isChunkText, isChunkTextOrString, kbEndpointHandler, kbPollEndpointHandler, llm, llmAppsHandler, llmKnowledgeBase, llmVectorDbsCleaningHandler, messageHandler, options, pythonInvokeRequest, pythonStreamHandler, rulesEndpointHandler, rulesHandler, textToChunksLastUnparsed, vectorDbTypesHandler }; //# sourceMappingURL=index.d.ts.map