@ai-stack/payloadcms 3.2.7-beta → 3.2.8-beta
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 +11 -0
- package/dist/ai/models/index.d.ts +1 -1
- package/dist/ai/models/index.d.ts.map +1 -1
- package/dist/ai/models/index.js +1 -1
- package/dist/ai/models/index.js.map +1 -1
- package/dist/ai/models/openai/generateRichText.d.ts.map +1 -1
- package/dist/ai/models/openai/generateRichText.js +1 -1
- package/dist/ai/models/openai/generateRichText.js.map +1 -1
- package/dist/ai/models/openai/index.d.ts.map +1 -1
- package/dist/ai/models/openai/index.js +1 -1
- package/dist/ai/models/openai/index.js.map +1 -1
- package/dist/ai/models/openai/openai.d.ts +2 -0
- package/dist/ai/models/openai/openai.d.ts.map +1 -0
- package/dist/ai/models/openai/openai.js +9 -0
- package/dist/ai/models/openai/openai.js.map +1 -0
- package/dist/ai/utils/systemGenerate.d.ts +1 -1
- package/dist/ai/utils/systemGenerate.d.ts.map +1 -1
- package/dist/ai/utils/systemGenerate.js +6 -2
- package/dist/ai/utils/systemGenerate.js.map +1 -1
- package/dist/collections/Instructions.d.ts +2 -1
- package/dist/collections/Instructions.d.ts.map +1 -1
- package/dist/collections/Instructions.js +20 -19
- package/dist/collections/Instructions.js.map +1 -1
- package/dist/endpoints/index.d.ts +2 -2
- package/dist/endpoints/index.d.ts.map +1 -1
- package/dist/endpoints/index.js +97 -96
- package/dist/endpoints/index.js.map +1 -1
- package/dist/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/fields/LexicalEditor/feature.server.d.ts.map +1 -1
- package/dist/fields/LexicalEditor/feature.server.js +2 -3
- package/dist/fields/LexicalEditor/feature.server.js.map +1 -1
- package/dist/fields/PromptEditorField/PromptEditorField.d.ts.map +1 -1
- package/dist/fields/PromptEditorField/PromptEditorField.js +5 -1
- package/dist/fields/PromptEditorField/PromptEditorField.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +5 -3
- package/dist/init.js.map +1 -1
- package/dist/libraries/handlebars/replacePlaceholders.d.ts +1 -1
- package/dist/libraries/handlebars/replacePlaceholders.d.ts.map +1 -1
- package/dist/libraries/handlebars/replacePlaceholders.js.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +10 -5
- package/dist/plugin.js.map +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/getGenerationModels.d.ts +3 -0
- package/dist/utilities/getGenerationModels.d.ts.map +1 -0
- package/dist/utilities/getGenerationModels.js +10 -0
- package/dist/utilities/getGenerationModels.js.map +1 -0
- package/dist/utilities/isPluginActivated.d.ts +2 -1
- package/dist/utilities/isPluginActivated.d.ts.map +1 -1
- package/dist/utilities/isPluginActivated.js +3 -2
- package/dist/utilities/isPluginActivated.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,6 +120,17 @@ OPENAI_API_KEY=your-openai-api-key
|
|
|
120
120
|
ANTHROPIC_API_KEY=your-anthropic-api-key
|
|
121
121
|
ELEVENLABS_API_KEY=your-elevenlabs-api-key
|
|
122
122
|
```
|
|
123
|
+
|
|
124
|
+
> **⚠️ Important:** Once you've configured or installed this plugin, a server restart is required to activate the changes.
|
|
125
|
+
|
|
126
|
+
### OpenAI Endpoint
|
|
127
|
+
|
|
128
|
+
If you want to use a custom endpoint for the OpenAI provider, set your base URL like this:
|
|
129
|
+
```
|
|
130
|
+
OPENAI_BASE_URL=https://api.openai.com/v1
|
|
131
|
+
```
|
|
132
|
+
If not specified, the [default](src/ai/models/openai/openai.ts) OpenAI endpoint will be used.
|
|
133
|
+
|
|
123
134
|
For detailed guidance on personalizing and configuring the plugin to match your needs, check out the **[Complete Guide](guide.md)**. It walks you through every step, from setting up fields to generating amazing content!
|
|
124
135
|
|
|
125
136
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ai/models/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAMrD,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ai/models/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAMrD,eAAO,MAAM,uBAAuB,EAAE,eAAe,EAIpD,CAAA"}
|
package/dist/ai/models/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import * as process from 'node:process';
|
|
|
2
2
|
import { AnthropicConfig } from './anthropic/index.js';
|
|
3
3
|
import { ElevenLabsConfig } from './elevenLabs/index.js';
|
|
4
4
|
import { OpenAIConfig } from './openai/index.js';
|
|
5
|
-
export const
|
|
5
|
+
export const defaultGenerationModels = [
|
|
6
6
|
...process.env.OPENAI_API_KEY ? OpenAIConfig.models : [],
|
|
7
7
|
...process.env.ANTHROPIC_API_KEY ? AnthropicConfig.models : [],
|
|
8
8
|
...process.env.ELEVENLABS_API_KEY ? ElevenLabsConfig.models : []
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ai/models/index.ts"],"sourcesContent":["import * as process from 'node:process'\n\nimport type { GenerationModel } from '../../types.js'\n\nimport { AnthropicConfig } from './anthropic/index.js'\nimport { ElevenLabsConfig } from './elevenLabs/index.js'\nimport { OpenAIConfig } from './openai/index.js'\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../../src/ai/models/index.ts"],"sourcesContent":["import * as process from 'node:process'\n\nimport type { GenerationModel } from '../../types.js'\n\nimport { AnthropicConfig } from './anthropic/index.js'\nimport { ElevenLabsConfig } from './elevenLabs/index.js'\nimport { OpenAIConfig } from './openai/index.js'\n\nexport const defaultGenerationModels: GenerationModel[] = [\n ...(process.env.OPENAI_API_KEY ? OpenAIConfig.models : []),\n ...(process.env.ANTHROPIC_API_KEY ? AnthropicConfig.models : []),\n ...(process.env.ELEVENLABS_API_KEY ? ElevenLabsConfig.models : []),\n]\n"],"names":["process","AnthropicConfig","ElevenLabsConfig","OpenAIConfig","defaultGenerationModels","env","OPENAI_API_KEY","models","ANTHROPIC_API_KEY","ELEVENLABS_API_KEY"],"mappings":"AAAA,YAAYA,aAAa,eAAc;AAIvC,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,OAAO,MAAMC,0BAA6C;OACpDJ,QAAQK,GAAG,CAACC,cAAc,GAAGH,aAAaI,MAAM,GAAG,EAAE;OACrDP,QAAQK,GAAG,CAACG,iBAAiB,GAAGP,gBAAgBM,MAAM,GAAG,EAAE;OAC3DP,QAAQK,GAAG,CAACI,kBAAkB,GAAGP,iBAAiBK,MAAM,GAAG,EAAE;CAClE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRichText.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/openai/generateRichText.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateRichText.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/openai/generateRichText.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,gBAAgB,GAAU,MAAM,MAAM,EAAE,UAAS,GAAQ,sBAoCrE,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { openai } from '@ai-sdk/openai';
|
|
2
1
|
import { jsonSchema, streamObject } from 'ai';
|
|
2
|
+
import { openai } from './openai.js';
|
|
3
3
|
export const generateRichText = async (text, options = {})=>{
|
|
4
4
|
// console.log('Running handler with prompts:', options.editorSchema)
|
|
5
5
|
const streamResult = await streamObject({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ai/models/openai/generateRichText.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../src/ai/models/openai/generateRichText.ts"],"sourcesContent":["import { jsonSchema, streamObject } from 'ai'\n\nimport { openai } from './openai.js'\n\nexport const generateRichText = async (text: string, options: any = {}) => {\n // console.log('Running handler with prompts:', options.editorSchema)\n const streamResult = await streamObject({\n maxTokens: options.maxTokens || 5000,\n model: openai(options.model, {\n structuredOutputs: true,\n }),\n // onFinish: (result) => {\n // console.log('Finished generating rich text:', { options, rawResponse: result.rawResponse, result })\n // },\n prompt: text,\n schema: jsonSchema(options.editorSchema),\n system: `${options.system}\n\nRULES:\n- Generate original and unique content based on the given topic.\n- Strictly adhere to the specified layout and formatting instructions.\n- Utilize the provided rich text editor tools for appropriate formatting.\n- Ensure the output follows the structure of the sample output object.\n- Produce valid JSON with no undefined or null values.\n\nLAYOUT INSTRUCTIONS:\n${options.layout}\n\nRICH TEXT EDITOR TOOLS:\n- Use appropriate formatting tools such as bold, italic, or underline for emphasis where needed.\n- Apply correct heading levels (h1, h2, h3) for hierarchical structure.\n- Utilize bullet points or numbered lists as required by the layout.\n\nADDITIONAL GUIDELINES:\n- Ensure coherence and logical flow between all sections.\n- Maintain a consistent tone and style throughout the content.\n- Use clear and concise language appropriate for the target audience.\n`,\n })\n return streamResult.toTextStreamResponse()\n}\n"],"names":["jsonSchema","streamObject","openai","generateRichText","text","options","streamResult","maxTokens","model","structuredOutputs","prompt","schema","editorSchema","system","layout","toTextStreamResponse"],"mappings":"AAAA,SAASA,UAAU,EAAEC,YAAY,QAAQ,KAAI;AAE7C,SAASC,MAAM,QAAQ,cAAa;AAEpC,OAAO,MAAMC,mBAAmB,OAAOC,MAAcC,UAAe,CAAC,CAAC;IACpE,qEAAqE;IACrE,MAAMC,eAAe,MAAML,aAAa;QACtCM,WAAWF,QAAQE,SAAS,IAAI;QAChCC,OAAON,OAAOG,QAAQG,KAAK,EAAE;YAC3BC,mBAAmB;QACrB;QACA,0BAA0B;QAC1B,wGAAwG;QACxG,KAAK;QACLC,QAAQN;QACRO,QAAQX,WAAWK,QAAQO,YAAY;QACvCC,QAAQ,GAAGR,QAAQQ,MAAM,CAAC;;;;;;;;;;AAU9B,EAAER,QAAQS,MAAM,CAAC;;;;;;;;;;;AAWjB,CAAC;IACC;IACA,OAAOR,aAAaS,oBAAoB;AAC1C,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/openai/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/openai/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAYzD,eAAO,MAAM,YAAY,EAAE,gBAsM1B,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { openai } from '@ai-sdk/openai';
|
|
2
1
|
import { streamText } from 'ai';
|
|
3
2
|
import { defaultSystemPrompt } from '../../prompts.js';
|
|
4
3
|
import { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js';
|
|
5
4
|
import { generateImage } from './generateImage.js';
|
|
6
5
|
import { generateRichText } from './generateRichText.js';
|
|
7
6
|
import { generateVoice } from './generateVoice.js';
|
|
7
|
+
import { openai } from './openai.js';
|
|
8
8
|
const MODEL_KEY = 'Oai';
|
|
9
9
|
//TODO: Simplify this file by moving the handlers to separate files and remove duplicate code
|
|
10
10
|
export const OpenAIConfig = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ai/models/openai/index.ts"],"sourcesContent":["import type { SpeechCreateParams } from 'openai/resources/audio/speech'\nimport type { File } from 'payload'\n\nimport { openai } from '@ai-sdk/openai'\nimport { streamText } from 'ai'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { defaultSystemPrompt } from '../../prompts.js'\nimport { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js'\nimport { generateImage } from './generateImage.js'\nimport { generateRichText } from './generateRichText.js'\nimport { generateVoice } from './generateVoice.js'\n\nconst MODEL_KEY = 'Oai'\n\n//TODO: Simplify this file by moving the handlers to separate files and remove duplicate code\nexport const OpenAIConfig: GenerationConfig = {\n models: [\n {\n id: `${MODEL_KEY}-text`,\n name: 'OpenAI GPT Text',\n fields: ['text', 'textarea'],\n handler: async (\n prompt: string,\n options: { locale: string; model: string; system: string },\n ) => {\n const streamTextResult = await streamText({\n model: openai(options.model),\n prompt,\n system: options.system || defaultSystemPrompt,\n })\n\n return streamTextResult.toDataStreamResponse()\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-text-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-text`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o-mini',\n label: 'Model',\n options: ['gpt-4o', 'gpt-4-turbo', 'gpt-4o-mini', 'gpt-3.5-turbo'],\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n {\n id: 'dall-e',\n name: 'OpenAI DALL-E',\n fields: ['upload'],\n handler: async (prompt: string, options) => {\n const imageData = await generateImage(prompt, options)\n return {\n data: {\n alt: imageData.alt,\n },\n file: {\n name: `image_${generateFileNameByPrompt(imageData.alt || prompt)}.jpeg`,\n data: imageData.buffer,\n mimetype: 'image/jpeg',\n size: imageData.buffer.byteLength,\n } as File,\n }\n },\n output: 'image',\n settings: {\n name: 'dalle-e-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'dall-e'\n },\n },\n fields: [\n {\n name: 'version',\n type: 'select',\n defaultValue: 'dall-e-3',\n label: 'Version',\n options: ['dall-e-3', 'dall-e-2'],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'size',\n type: 'select',\n defaultValue: '1024x1024',\n label: 'Size',\n options: ['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792'],\n },\n {\n name: 'style',\n type: 'select',\n defaultValue: 'natural',\n label: 'Style',\n options: ['vivid', 'natural'],\n },\n ],\n },\n {\n name: 'enable-prompt-optimization',\n type: 'checkbox',\n label: 'Optimize prompt',\n },\n ],\n label: 'OpenAI DALL-E Settings',\n },\n },\n {\n id: 'tts',\n name: 'OpenAI Text-to-Speech',\n fields: ['upload'],\n handler: async (text: string, options) => {\n //TODO: change it to open ai text to speech api\n const voiceData = await generateVoice(text, options)\n return {\n data: {\n alt: text,\n },\n file: {\n name: `voice_${generateFileNameByPrompt(text)}.mp3`,\n data: voiceData.buffer,\n mimetype: 'audio/mp3',\n size: voiceData.buffer.byteLength,\n } as File,\n }\n },\n output: 'audio',\n settings: {\n name: `${MODEL_KEY}-tts-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'tts'\n },\n },\n fields: [\n {\n name: 'voice',\n type: 'select',\n defaultValue: 'alloy',\n label: 'Voice',\n options: ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'] as Array<\n SpeechCreateParams['voice']\n >,\n },\n {\n name: 'model',\n type: 'select',\n defaultValue: 'tts-1',\n label: 'Model',\n options: ['tts-1', 'tts-1-hd'] as Array<SpeechCreateParams['model']>,\n },\n {\n name: 'response_format',\n type: 'select',\n defaultValue: 'mp3',\n label: 'Response Format',\n options: ['mp3', 'opus', 'aac', 'flac', 'wav', 'pcm'] as Array<\n SpeechCreateParams['response_format']\n >,\n },\n {\n name: 'speed',\n type: 'number',\n defaultValue: 1,\n label: 'Speed',\n max: 4,\n min: 0.25,\n },\n ],\n label: 'OpenAI Text-to-Speech Settings',\n },\n },\n {\n id: `${MODEL_KEY}-object`,\n name: 'OpenAI GPT',\n fields: ['richText'],\n handler: (text: string, options) => {\n return generateRichText(text, options)\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-object-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-object`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o-2024-08-06',\n label: 'Model',\n options: ['gpt-4o', 'gpt-4-turbo', 'gpt-4o-mini', 'gpt-4o-2024-08-06'],\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n ],\n provider: 'OpenAI',\n}\n"],"names":["openai","streamText","defaultSystemPrompt","generateFileNameByPrompt","generateImage","generateRichText","generateVoice","MODEL_KEY","OpenAIConfig","models","id","name","fields","handler","prompt","options","streamTextResult","model","system","toDataStreamResponse","output","settings","type","admin","condition","data","defaultValue","label","imageData","alt","file","buffer","mimetype","size","byteLength","text","voiceData","max","min","provider"],"mappings":"AAGA,SAASA,MAAM,QAAQ,iBAAgB;AACvC,SAASC,UAAU,QAAQ,KAAI;AAI/B,SAASC,mBAAmB,QAAQ,mBAAkB;AACtD,SAASC,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,aAAa,QAAQ,qBAAoB;AAElD,MAAMC,YAAY;AAElB,6FAA6F;AAC7F,OAAO,MAAMC,eAAiC;IAC5CC,QAAQ;QACN;YACEC,IAAI,GAAGH,UAAU,KAAK,CAAC;YACvBI,MAAM;YACNC,QAAQ;gBAAC;gBAAQ;aAAW;YAC5BC,SAAS,OACPC,QACAC;gBAEA,MAAMC,mBAAmB,MAAMf,WAAW;oBACxCgB,OAAOjB,OAAOe,QAAQE,KAAK;oBAC3BH;oBACAI,QAAQH,QAAQG,MAAM,IAAIhB;gBAC5B;gBAEA,OAAOc,iBAAiBG,oBAAoB;YAC9C;YACAC,QAAQ;YACRC,UAAU;gBACRV,MAAM,GAAGJ,UAAU,cAAc,CAAC;gBAClCe,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGlB,UAAU,KAAK,CAAC;oBACjD;gBACF;gBACAK,QAAQ;oBACN;wBACED,MAAM;wBACNW,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPZ,SAAS;4BAAC;4BAAU;4BAAe;4BAA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ED,MAAM;wBACNW,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPZ,SAAS;4BAAC;4BAAU;4BAAe;4BAAe;yBAAoB;oBACxE;iBACD;gBACDY,OAAO;YACT;QACF;KACD;IACDY,UAAU;AACZ,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/ai/models/openai/index.ts"],"sourcesContent":["import type { SpeechCreateParams } from 'openai/resources/audio/speech'\nimport type { File } from 'payload'\n\nimport { streamText } from 'ai'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { defaultSystemPrompt } from '../../prompts.js'\nimport { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js'\nimport { generateImage } from './generateImage.js'\nimport { generateRichText } from './generateRichText.js'\nimport { generateVoice } from './generateVoice.js'\nimport { openai } from './openai.js'\n\nconst MODEL_KEY = 'Oai'\n\n//TODO: Simplify this file by moving the handlers to separate files and remove duplicate code\nexport const OpenAIConfig: GenerationConfig = {\n models: [\n {\n id: `${MODEL_KEY}-text`,\n name: 'OpenAI GPT Text',\n fields: ['text', 'textarea'],\n handler: async (\n prompt: string,\n options: { locale: string; model: string; system: string },\n ) => {\n const streamTextResult = await streamText({\n model: openai(options.model),\n prompt,\n system: options.system || defaultSystemPrompt,\n })\n\n return streamTextResult.toDataStreamResponse()\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-text-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-text`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o-mini',\n label: 'Model',\n options: ['gpt-4o', 'gpt-4-turbo', 'gpt-4o-mini', 'gpt-3.5-turbo'],\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n {\n id: 'dall-e',\n name: 'OpenAI DALL-E',\n fields: ['upload'],\n handler: async (prompt: string, options) => {\n const imageData = await generateImage(prompt, options)\n return {\n data: {\n alt: imageData.alt,\n },\n file: {\n name: `image_${generateFileNameByPrompt(imageData.alt || prompt)}.jpeg`,\n data: imageData.buffer,\n mimetype: 'image/jpeg',\n size: imageData.buffer.byteLength,\n } as File,\n }\n },\n output: 'image',\n settings: {\n name: 'dalle-e-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'dall-e'\n },\n },\n fields: [\n {\n name: 'version',\n type: 'select',\n defaultValue: 'dall-e-3',\n label: 'Version',\n options: ['dall-e-3', 'dall-e-2'],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'size',\n type: 'select',\n defaultValue: '1024x1024',\n label: 'Size',\n options: ['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792'],\n },\n {\n name: 'style',\n type: 'select',\n defaultValue: 'natural',\n label: 'Style',\n options: ['vivid', 'natural'],\n },\n ],\n },\n {\n name: 'enable-prompt-optimization',\n type: 'checkbox',\n label: 'Optimize prompt',\n },\n ],\n label: 'OpenAI DALL-E Settings',\n },\n },\n {\n id: 'tts',\n name: 'OpenAI Text-to-Speech',\n fields: ['upload'],\n handler: async (text: string, options) => {\n //TODO: change it to open ai text to speech api\n const voiceData = await generateVoice(text, options)\n return {\n data: {\n alt: text,\n },\n file: {\n name: `voice_${generateFileNameByPrompt(text)}.mp3`,\n data: voiceData.buffer,\n mimetype: 'audio/mp3',\n size: voiceData.buffer.byteLength,\n } as File,\n }\n },\n output: 'audio',\n settings: {\n name: `${MODEL_KEY}-tts-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'tts'\n },\n },\n fields: [\n {\n name: 'voice',\n type: 'select',\n defaultValue: 'alloy',\n label: 'Voice',\n options: ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'] as Array<\n SpeechCreateParams['voice']\n >,\n },\n {\n name: 'model',\n type: 'select',\n defaultValue: 'tts-1',\n label: 'Model',\n options: ['tts-1', 'tts-1-hd'] as Array<SpeechCreateParams['model']>,\n },\n {\n name: 'response_format',\n type: 'select',\n defaultValue: 'mp3',\n label: 'Response Format',\n options: ['mp3', 'opus', 'aac', 'flac', 'wav', 'pcm'] as Array<\n SpeechCreateParams['response_format']\n >,\n },\n {\n name: 'speed',\n type: 'number',\n defaultValue: 1,\n label: 'Speed',\n max: 4,\n min: 0.25,\n },\n ],\n label: 'OpenAI Text-to-Speech Settings',\n },\n },\n {\n id: `${MODEL_KEY}-object`,\n name: 'OpenAI GPT',\n fields: ['richText'],\n handler: (text: string, options) => {\n return generateRichText(text, options)\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-object-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-object`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o-2024-08-06',\n label: 'Model',\n options: ['gpt-4o', 'gpt-4-turbo', 'gpt-4o-mini', 'gpt-4o-2024-08-06'],\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n ],\n provider: 'OpenAI',\n}\n"],"names":["streamText","defaultSystemPrompt","generateFileNameByPrompt","generateImage","generateRichText","generateVoice","openai","MODEL_KEY","OpenAIConfig","models","id","name","fields","handler","prompt","options","streamTextResult","model","system","toDataStreamResponse","output","settings","type","admin","condition","data","defaultValue","label","imageData","alt","file","buffer","mimetype","size","byteLength","text","voiceData","max","min","provider"],"mappings":"AAGA,SAASA,UAAU,QAAQ,KAAI;AAI/B,SAASC,mBAAmB,QAAQ,mBAAkB;AACtD,SAASC,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,MAAM,QAAQ,cAAa;AAEpC,MAAMC,YAAY;AAElB,6FAA6F;AAC7F,OAAO,MAAMC,eAAiC;IAC5CC,QAAQ;QACN;YACEC,IAAI,GAAGH,UAAU,KAAK,CAAC;YACvBI,MAAM;YACNC,QAAQ;gBAAC;gBAAQ;aAAW;YAC5BC,SAAS,OACPC,QACAC;gBAEA,MAA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MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPU,KAAK;wBACLC,KAAK;oBACP;iBACD;gBACDX,OAAO;YACT;QACF;QACA;YACEjB,IAAI,GAAGH,UAAU,OAAO,CAAC;YACzBI,MAAM;YACNC,QAAQ;gBAAC;aAAW;YACpBC,SAAS,CAACsB,MAAcpB;gBACtB,OAAOX,iBAAiB+B,MAAMpB;YAChC;YACAK,QAAQ;YACRC,UAAU;gBACRV,MAAM,GAAGJ,UAAU,gBAAgB,CAAC;gBACpCe,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGlB,UAAU,OAAO,CAAC;oBACnD;gBACF;gBACAK,QAAQ;oBACN;wBACED,MAAM;wBACNW,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPZ,SAAS;4BAAC;4BAAU;4BAAe;4BAAe;yBAAoB;oBACxE;iBACD;gBACDY,OAAO;YACT;QACF;KACD;IACDY,UAAU;AACZ,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/openai/openai.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,yCAIjB,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createOpenAI } from '@ai-sdk/openai';
|
|
2
|
+
// same to default openai with optional baseurl.
|
|
3
|
+
export const openai = createOpenAI({
|
|
4
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
5
|
+
baseURL: process.env.OPENAI_BASE_URL ?? 'https://api.openai.com/v1',
|
|
6
|
+
compatibility: 'strict'
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/ai/models/openai/openai.ts"],"sourcesContent":["import { createOpenAI } from '@ai-sdk/openai'\n\n// same to default openai with optional baseurl.\nexport const openai = createOpenAI({\n apiKey: process.env.OPENAI_API_KEY,\n baseURL: process.env.OPENAI_BASE_URL ?? 'https://api.openai.com/v1',\n compatibility: 'strict',\n})\n"],"names":["createOpenAI","openai","apiKey","process","env","OPENAI_API_KEY","baseURL","OPENAI_BASE_URL","compatibility"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAgB;AAE7C,gDAAgD;AAChD,OAAO,MAAMC,SAASD,aAAa;IACjCE,QAAQC,QAAQC,GAAG,CAACC,cAAc;IAClCC,SAASH,QAAQC,GAAG,CAACG,eAAe,IAAI;IACxCC,eAAe;AACjB,GAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemGenerate.d.ts","sourceRoot":"","sources":["../../../src/ai/utils/systemGenerate.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"systemGenerate.d.ts","sourceRoot":"","sources":["../../../src/ai/utils/systemGenerate.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,cAAc,GACzB,MAAM;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACxC,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,oBA0BrE,CAAA"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { anthropic } from '@ai-sdk/anthropic';
|
|
2
|
-
import { openai } from '@ai-sdk/openai';
|
|
3
2
|
import { generateText } from 'ai';
|
|
4
3
|
import { PLUGIN_DEFAULT_ANTHROPIC_MODEL, PLUGIN_DEFAULT_OPENAI_MODEL } from '../../defaults.js';
|
|
5
|
-
|
|
4
|
+
import { openai } from '../models/openai/openai.js';
|
|
5
|
+
export const systemGenerate = async (data, generateTextFn)=>{
|
|
6
6
|
const { prompt, system } = data;
|
|
7
|
+
if (generateTextFn) {
|
|
8
|
+
return generateTextFn(prompt, system);
|
|
9
|
+
}
|
|
7
10
|
let model = null;
|
|
11
|
+
// If the generateTextFn is not provided, still need OPENAI_API_KEY or ANTHROPIC_API_KEY to initialize
|
|
8
12
|
if (process.env.OPENAI_API_KEY) {
|
|
9
13
|
model = openai(PLUGIN_DEFAULT_OPENAI_MODEL);
|
|
10
14
|
} else if (process.env.ANTHROPIC_API_KEY) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ai/utils/systemGenerate.ts"],"sourcesContent":["import { anthropic } from '@ai-sdk/anthropic'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/ai/utils/systemGenerate.ts"],"sourcesContent":["import { anthropic } from '@ai-sdk/anthropic'\nimport { generateText } from 'ai'\n\nimport { PLUGIN_DEFAULT_ANTHROPIC_MODEL, PLUGIN_DEFAULT_OPENAI_MODEL } from '../../defaults.js'\nimport { openai } from '../models/openai/openai.js'\n\nexport const systemGenerate = async (\n data: { prompt: string; system: string },\n generateTextFn?: (prompt: string, system: string) => Promise<string>,\n) => {\n const { prompt, system } = data\n\n if (generateTextFn) {\n return generateTextFn(prompt, system)\n }\n\n let model = null\n\n // If the generateTextFn is not provided, still need OPENAI_API_KEY or ANTHROPIC_API_KEY to initialize\n if (process.env.OPENAI_API_KEY) {\n model = openai(PLUGIN_DEFAULT_OPENAI_MODEL)\n } else if (process.env.ANTHROPIC_API_KEY) {\n model = anthropic(PLUGIN_DEFAULT_ANTHROPIC_MODEL)\n } else {\n throw new Error('- AI Plugin: Please check your environment variables!')\n }\n\n const { text } = await generateText({\n model,\n prompt,\n system,\n })\n\n return text\n}\n"],"names":["anthropic","generateText","PLUGIN_DEFAULT_ANTHROPIC_MODEL","PLUGIN_DEFAULT_OPENAI_MODEL","openai","systemGenerate","data","generateTextFn","prompt","system","model","process","env","OPENAI_API_KEY","ANTHROPIC_API_KEY","Error","text"],"mappings":"AAAA,SAASA,SAAS,QAAQ,oBAAmB;AAC7C,SAASC,YAAY,QAAQ,KAAI;AAEjC,SAASC,8BAA8B,EAAEC,2BAA2B,QAAQ,oBAAmB;AAC/F,SAASC,MAAM,QAAQ,6BAA4B;AAEnD,OAAO,MAAMC,iBAAiB,OAC5BC,MACAC;IAEA,MAAM,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAGH;IAE3B,IAAIC,gBAAgB;QAClB,OAAOA,eAAeC,QAAQC;IAChC;IAEA,IAAIC,QAAQ;IAEZ,sGAAsG;IACtG,IAAIC,QAAQC,GAAG,CAACC,cAAc,EAAE;QAC9BH,QAAQN,OAAOD;IACjB,OAAO,IAAIQ,QAAQC,GAAG,CAACE,iBAAiB,EAAE;QACxCJ,QAAQV,UAAUE;IACpB,OAAO;QACL,MAAM,IAAIa,MAAM;IAClB;IAEA,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAMf,aAAa;QAClCS;QACAF;QACAC;IACF;IAEA,OAAOO;AACT,EAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { CollectionConfig } from 'payload';
|
|
2
|
-
|
|
2
|
+
import type { PluginConfig } from 'src/types.js';
|
|
3
|
+
export declare const instructionsCollection: (pluginConfig: PluginConfig, options?: Partial<CollectionConfig>) => CollectionConfig;
|
|
3
4
|
//# sourceMappingURL=Instructions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Instructions.d.ts","sourceRoot":"","sources":["../../src/collections/Instructions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"Instructions.d.ts","sourceRoot":"","sources":["../../src/collections/Instructions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,SAAS,CAAA;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAiChD,eAAO,MAAM,sBAAsB,GACjC,cAAc,YAAY,EAC1B,UAAU,OAAO,CAAC,gBAAgB,CAAC,KAElC,gBAuKA,CAAA"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getGenerationModels } from '../utilities/getGenerationModels.js';
|
|
2
2
|
import { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js';
|
|
3
|
-
const groupSettings =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}, []);
|
|
9
|
-
const modelOptions =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
3
|
+
const groupSettings = (pluginConfig)=>getGenerationModels(pluginConfig).reduce((fields, model)=>{
|
|
4
|
+
if (model.settings) {
|
|
5
|
+
fields.push(model.settings);
|
|
6
|
+
}
|
|
7
|
+
return fields;
|
|
8
|
+
}, []);
|
|
9
|
+
const modelOptions = (pluginConfig)=>getGenerationModels(pluginConfig).map((model)=>{
|
|
10
|
+
return {
|
|
11
|
+
fields: model.fields,
|
|
12
|
+
label: model.name,
|
|
13
|
+
value: model.id
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
16
|
const defaultAccessConfig = {
|
|
17
17
|
create: ()=>true,
|
|
18
18
|
read: ()=>true,
|
|
@@ -22,7 +22,7 @@ const defaultAdminConfig = {
|
|
|
22
22
|
group: 'Plugins',
|
|
23
23
|
hidden: true
|
|
24
24
|
};
|
|
25
|
-
export const instructionsCollection = (options)=>({
|
|
25
|
+
export const instructionsCollection = (pluginConfig, options)=>({
|
|
26
26
|
slug: PLUGIN_INSTRUCTIONS_TABLE,
|
|
27
27
|
access: {
|
|
28
28
|
...defaultAccessConfig,
|
|
@@ -87,14 +87,14 @@ export const instructionsCollection = (options)=>({
|
|
|
87
87
|
Field: {
|
|
88
88
|
clientProps: {
|
|
89
89
|
filterByField: 'field-type',
|
|
90
|
-
options: modelOptions
|
|
90
|
+
options: modelOptions(pluginConfig)
|
|
91
91
|
},
|
|
92
92
|
path: '@ai-stack/payloadcms/fields#SelectField'
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
label: 'Model',
|
|
97
|
-
options: modelOptions.map((option)=>{
|
|
97
|
+
options: modelOptions(pluginConfig).map((option)=>{
|
|
98
98
|
return {
|
|
99
99
|
label: option.label,
|
|
100
100
|
value: option.value
|
|
@@ -116,7 +116,8 @@ export const instructionsCollection = (options)=>({
|
|
|
116
116
|
admin: {
|
|
117
117
|
components: {
|
|
118
118
|
Field: '@ai-stack/payloadcms/fields#PromptEditorField'
|
|
119
|
-
}
|
|
119
|
+
},
|
|
120
|
+
description: "Click 'Compose' to run this custom prompt and generate content"
|
|
120
121
|
},
|
|
121
122
|
label: ''
|
|
122
123
|
}
|
|
@@ -192,7 +193,7 @@ informative and accurate but also captivating and beautifully structured.`,
|
|
|
192
193
|
}
|
|
193
194
|
]
|
|
194
195
|
},
|
|
195
|
-
...groupSettings
|
|
196
|
+
...groupSettings(pluginConfig)
|
|
196
197
|
],
|
|
197
198
|
labels: {
|
|
198
199
|
plural: 'Compose Settings',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/Instructions.ts"],"sourcesContent":["import type { CollectionConfig, GroupField } from 'payload'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/collections/Instructions.ts"],"sourcesContent":["import type { CollectionConfig, GroupField } from 'payload'\nimport type { PluginConfig } from 'src/types.js'\n\nimport { getGenerationModels } from '../utilities/getGenerationModels.js'\nimport { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\n\nconst groupSettings = (pluginConfig: PluginConfig) =>\n getGenerationModels(pluginConfig).reduce((fields, model) => {\n if (model.settings) {\n fields.push(model.settings)\n }\n return fields\n }, [] as GroupField[])\n\nconst modelOptions = (pluginConfig: PluginConfig) =>\n getGenerationModels(pluginConfig).map((model) => {\n return {\n fields: model.fields,\n label: model.name,\n value: model.id,\n }\n })\n\nconst defaultAccessConfig = {\n create: () => true,\n read: () => true,\n update: () => true,\n}\n\nconst defaultAdminConfig = {\n group: 'Plugins',\n hidden: true,\n}\n\nexport const instructionsCollection = (\n pluginConfig: PluginConfig,\n options?: Partial<CollectionConfig>,\n) =>\n <CollectionConfig>{\n slug: PLUGIN_INSTRUCTIONS_TABLE,\n access: {\n ...defaultAccessConfig,\n ...options?.access,\n },\n admin: {\n ...defaultAdminConfig,\n ...options?.admin,\n group: 'Plugins',\n },\n fields: [\n {\n name: 'schema-path',\n type: 'text',\n admin: {\n description: \"Please don’t change this unless you're sure of what you're doing\",\n },\n unique: true,\n },\n {\n name: 'field-type',\n type: 'select',\n admin: {\n description: \"Please don’t change this unless you're sure of what you're doing\",\n },\n defaultValue: 'text',\n label: 'Field type',\n options: [\n {\n label: 'text',\n value: 'text',\n },\n {\n label: 'textarea',\n value: 'textarea',\n },\n {\n label: 'upload',\n value: 'upload',\n },\n {\n label: 'richText',\n value: 'richText',\n },\n ],\n },\n {\n name: 'relation-to',\n type: 'text',\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'upload'\n },\n },\n label: 'Relation to',\n },\n {\n name: 'model-id',\n type: 'select',\n admin: {\n components: {\n Field: {\n clientProps: {\n filterByField: 'field-type',\n options: modelOptions(pluginConfig),\n },\n path: '@ai-stack/payloadcms/fields#SelectField',\n },\n },\n },\n label: 'Model',\n options: modelOptions(pluginConfig).map((option) => {\n return {\n label: option.label,\n value: option.value,\n }\n }),\n },\n {\n id: 'ai-prompts-tabs',\n type: 'tabs',\n tabs: [\n {\n // TODO: Add some info about the field to guide user\n description:\n 'The Prompt field allows you to define dynamic templates using placeholders (e.g., {{ fieldName }}) to customize output based on your data fields.',\n fields: [\n {\n name: 'prompt',\n type: 'textarea',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/fields#PromptEditorField',\n },\n description: \"Click 'Compose' to run this custom prompt and generate content\",\n },\n label: '',\n },\n ],\n label: 'Prompt',\n },\n {\n description: '',\n fields: [\n {\n name: 'system',\n type: 'textarea',\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'richText'\n },\n },\n defaultValue: `INSTRUCTIONS:\nYou are a highly skilled and professional blog writer,\nrenowned for crafting engaging and well-organized articles.\nWhen given a title, you meticulously create blogs that are not only\ninformative and accurate but also captivating and beautifully structured.`,\n label: '',\n },\n ],\n label: 'System prompt',\n },\n {\n // Note: Update when tabs PR is merged: https://github.com/payloadcms/payload/pull/8406\n // admin: {\n // condition: (_, current) => {\n // console.log('condition in tab', current)\n // return current['field-type'] === 'richText'\n // },\n // },\n description: '',\n fields: [\n {\n /**TODO's:\n * - Layouts can be saved in as an array\n * - user can add their own layout to collections and use it later for generate specific rich text\n * - user can select previously added layout\n */\n name: 'layout',\n type: 'textarea',\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'richText'\n },\n },\n defaultValue: `[paragraph] - Write a concise introduction (2-3 sentences) that outlines the main topic.\n[horizontalrule] - Insert a horizontal rule to separate the introduction from the main content.\n[list] - Create a list with 3-5 items. Each list item should contain:\n a. [heading] - A brief, descriptive heading (up to 5 words)\n b. [paragraph] - A short explanation or elaboration (1-2 sentences)\n[horizontalrule] - Insert another horizontal rule to separate the main content from the conclusion.\n[paragraph] - Compose a brief conclusion (2-3 sentences) summarizing the key points.\n[quote] - Include a relevant quote from a famous person, directly related to the topic. Format: \"Quote text.\" - Author Name`,\n label: '',\n },\n ],\n label: 'Layout',\n },\n ],\n },\n ...groupSettings(pluginConfig),\n ],\n labels: {\n plural: 'Compose Settings',\n singular: 'Compose Setting',\n },\n }\n"],"names":["getGenerationModels","PLUGIN_INSTRUCTIONS_TABLE","groupSettings","pluginConfig","reduce","fields","model","settings","push","modelOptions","map","label","name","value","id","defaultAccessConfig","create","read","update","defaultAdminConfig","group","hidden","instructionsCollection","options","slug","access","admin","type","description","unique","defaultValue","condition","_","current","components","Field","clientProps","filterByField","path","option","tabs","labels","plural","singular"],"mappings":"AAGA,SAASA,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,yBAAyB,QAAQ,iBAAgB;AAE1D,MAAMC,gBAAgB,CAACC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D;wBACDA,OAAO;oBACT;iBACD;YACH;eACGT,cAAcC;SAClB;QACDsC,QAAQ;YACNC,QAAQ;YACRC,UAAU;QACZ;IACF,CAAA,EAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Endpoints } from '../types.js';
|
|
2
|
-
export declare const endpoints: Endpoints;
|
|
1
|
+
import type { Endpoints, PluginConfig } from '../types.js';
|
|
2
|
+
export declare const endpoints: (pluginConfig: PluginConfig) => Endpoints;
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/endpoints/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAmB,SAAS,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/endpoints/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAmB,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAuE3E,eAAO,MAAM,SAAS,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,SA+HhC,CAAA"}
|
package/dist/endpoints/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { GenerationModels } from '../ai/models/index.js';
|
|
2
1
|
import { defaultPrompts } from '../ai/prompts.js';
|
|
3
2
|
import { PLUGIN_API_ENDPOINT_GENERATE, PLUGIN_API_ENDPOINT_GENERATE_UPLOAD, PLUGIN_INSTRUCTIONS_TABLE, PLUGIN_NAME } from '../defaults.js';
|
|
4
3
|
import { registerEditorHelper } from '../libraries/handlebars/helpers.js';
|
|
5
4
|
import { handlebarsHelpersMap } from '../libraries/handlebars/helpersMap.js';
|
|
6
5
|
import { replacePlaceholders } from '../libraries/handlebars/replacePlaceholders.js';
|
|
6
|
+
import { getGenerationModels } from '../utilities/getGenerationModels.js';
|
|
7
7
|
const assignPrompt = async (action, { type, actionParams, context, field, layout, systemPrompt = '', template })=>{
|
|
8
8
|
const prompt = await replacePlaceholders(template, context);
|
|
9
9
|
const toLexicalHTML = type === 'richText' ? handlebarsHelpersMap.toHTML.name : '';
|
|
@@ -33,104 +33,105 @@ const assignPrompt = async (action, { type, actionParams, context, field, layout
|
|
|
33
33
|
system
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
|
-
export const endpoints = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
collection: PLUGIN_INSTRUCTIONS_TABLE
|
|
49
|
-
});
|
|
50
|
-
const { collections } = req.payload.config;
|
|
51
|
-
const collection = collections.find((collection)=>collection.slug === PLUGIN_INSTRUCTIONS_TABLE);
|
|
52
|
-
const { custom: { [PLUGIN_NAME]: { editorConfig = {} } = {} } = {} } = collection.admin;
|
|
53
|
-
const { schema: editorSchema = {} } = editorConfig;
|
|
54
|
-
const { prompt: promptTemplate = '' } = instructions;
|
|
55
|
-
const schemaPath = instructions['schema-path'];
|
|
56
|
-
const fieldName = schemaPath?.split('.').pop();
|
|
57
|
-
registerEditorHelper(req.payload, schemaPath);
|
|
58
|
-
const { defaultLocale, locales = [] } = req.payload.config.localization || {};
|
|
59
|
-
const localeData = locales.find((l)=>{
|
|
60
|
-
return l.code === locale;
|
|
61
|
-
});
|
|
62
|
-
const localeInfo = localeData?.label[defaultLocale] || locale;
|
|
63
|
-
const model = GenerationModels.find((model)=>model.id === instructions['model-id']);
|
|
64
|
-
const settingsName = model.settings?.name;
|
|
65
|
-
const modelOptions = instructions[settingsName] || {};
|
|
66
|
-
const prompts = await assignPrompt(action, {
|
|
67
|
-
type: instructions['field-type'],
|
|
68
|
-
actionParams,
|
|
69
|
-
context: contextData,
|
|
70
|
-
field: fieldName,
|
|
71
|
-
layout: instructions.layout,
|
|
72
|
-
systemPrompt: instructions.system,
|
|
73
|
-
template: promptTemplate
|
|
74
|
-
});
|
|
75
|
-
// console.log('Running handler with prompts:', prompts)
|
|
76
|
-
return model.handler?.(prompts.prompt, {
|
|
77
|
-
...modelOptions,
|
|
78
|
-
editorSchema,
|
|
79
|
-
layout: prompts.layout,
|
|
80
|
-
locale: localeInfo,
|
|
81
|
-
system: prompts.system
|
|
82
|
-
}).catch((error)=>{
|
|
83
|
-
console.error('Error: endpoint - generating text:', error);
|
|
84
|
-
return new Response(JSON.stringify(error.message), {
|
|
85
|
-
status: 500
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
method: 'post',
|
|
90
|
-
path: PLUGIN_API_ENDPOINT_GENERATE
|
|
91
|
-
},
|
|
92
|
-
upload: {
|
|
93
|
-
handler: async (req)=>{
|
|
94
|
-
const data = await req.json?.();
|
|
95
|
-
const { options } = data;
|
|
96
|
-
const { instructionId } = options;
|
|
97
|
-
const contextData = data.doc;
|
|
98
|
-
let instructions = {
|
|
99
|
-
'model-id': '',
|
|
100
|
-
prompt: ''
|
|
101
|
-
};
|
|
102
|
-
if (instructionId) {
|
|
103
|
-
// @ts-expect-error
|
|
104
|
-
instructions = await req.payload.findByID({
|
|
36
|
+
export const endpoints = (pluginConfig)=>({
|
|
37
|
+
textarea: {
|
|
38
|
+
//TODO: This is the main endpoint for generating content - its just needs to be renamed to 'generate' or something.
|
|
39
|
+
handler: async (req)=>{
|
|
40
|
+
const data = await req.json?.();
|
|
41
|
+
const { locale = 'en', options } = data;
|
|
42
|
+
const { action, actionParams, instructionId } = options;
|
|
43
|
+
const contextData = data.doc;
|
|
44
|
+
if (!instructionId) {
|
|
45
|
+
throw new Error(`Instruction ID is required for "${PLUGIN_NAME}" to work, please check your configuration`);
|
|
46
|
+
}
|
|
47
|
+
const instructions = await req.payload.findByID({
|
|
105
48
|
id: instructionId,
|
|
106
49
|
collection: PLUGIN_INSTRUCTIONS_TABLE
|
|
107
50
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
51
|
+
const { collections } = req.payload.config;
|
|
52
|
+
const collection = collections.find((collection)=>collection.slug === PLUGIN_INSTRUCTIONS_TABLE);
|
|
53
|
+
const { custom: { [PLUGIN_NAME]: { editorConfig = {} } = {} } = {} } = collection.admin;
|
|
54
|
+
const { schema: editorSchema = {} } = editorConfig;
|
|
55
|
+
const { prompt: promptTemplate = '' } = instructions;
|
|
56
|
+
const schemaPath = instructions['schema-path'];
|
|
57
|
+
const fieldName = schemaPath?.split('.').pop();
|
|
58
|
+
registerEditorHelper(req.payload, schemaPath);
|
|
59
|
+
const { defaultLocale, locales = [] } = req.payload.config.localization || {};
|
|
60
|
+
const localeData = locales.find((l)=>{
|
|
61
|
+
return l.code === locale;
|
|
62
|
+
});
|
|
63
|
+
const localeInfo = localeData?.label[defaultLocale] || locale;
|
|
64
|
+
const model = getGenerationModels(pluginConfig).find((model)=>model.id === instructions['model-id']);
|
|
65
|
+
const settingsName = model.settings?.name;
|
|
66
|
+
const modelOptions = instructions[settingsName] || {};
|
|
67
|
+
const prompts = await assignPrompt(action, {
|
|
68
|
+
type: instructions['field-type'],
|
|
69
|
+
actionParams,
|
|
70
|
+
context: contextData,
|
|
71
|
+
field: fieldName,
|
|
72
|
+
layout: instructions.layout,
|
|
73
|
+
systemPrompt: instructions.system,
|
|
74
|
+
template: promptTemplate
|
|
75
|
+
});
|
|
76
|
+
// console.log('Running handler with prompts:', prompts)
|
|
77
|
+
return model.handler?.(prompts.prompt, {
|
|
78
|
+
...modelOptions,
|
|
79
|
+
editorSchema,
|
|
80
|
+
layout: prompts.layout,
|
|
81
|
+
locale: localeInfo,
|
|
82
|
+
system: prompts.system
|
|
83
|
+
}).catch((error)=>{
|
|
84
|
+
console.error('Error: endpoint - generating text:', error);
|
|
85
|
+
return new Response(JSON.stringify(error.message), {
|
|
86
|
+
status: 500
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
method: 'post',
|
|
91
|
+
path: PLUGIN_API_ENDPOINT_GENERATE
|
|
130
92
|
},
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
};
|
|
93
|
+
upload: {
|
|
94
|
+
handler: async (req)=>{
|
|
95
|
+
const data = await req.json?.();
|
|
96
|
+
const { options } = data;
|
|
97
|
+
const { instructionId } = options;
|
|
98
|
+
const contextData = data.doc;
|
|
99
|
+
let instructions = {
|
|
100
|
+
'model-id': '',
|
|
101
|
+
prompt: ''
|
|
102
|
+
};
|
|
103
|
+
if (instructionId) {
|
|
104
|
+
// @ts-expect-error
|
|
105
|
+
instructions = await req.payload.findByID({
|
|
106
|
+
id: instructionId,
|
|
107
|
+
collection: PLUGIN_INSTRUCTIONS_TABLE
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const { prompt: promptTemplate = '' } = instructions;
|
|
111
|
+
const schemaPath = instructions['schema-path'];
|
|
112
|
+
registerEditorHelper(req.payload, schemaPath);
|
|
113
|
+
const text = await replacePlaceholders(promptTemplate, contextData);
|
|
114
|
+
const modelId = instructions['model-id'];
|
|
115
|
+
const uploadCollectionSlug = instructions['relation-to'];
|
|
116
|
+
const model = getGenerationModels(pluginConfig).find((model)=>model.id === modelId);
|
|
117
|
+
const settingsName = model.settings?.name;
|
|
118
|
+
const modelOptions = instructions[settingsName] || {};
|
|
119
|
+
const result = await model.handler?.(text, modelOptions);
|
|
120
|
+
const assetData = await req.payload.create({
|
|
121
|
+
collection: uploadCollectionSlug,
|
|
122
|
+
data: result.data,
|
|
123
|
+
file: result.file
|
|
124
|
+
});
|
|
125
|
+
return new Response(JSON.stringify({
|
|
126
|
+
result: {
|
|
127
|
+
id: assetData.id,
|
|
128
|
+
alt: assetData.alt
|
|
129
|
+
}
|
|
130
|
+
}));
|
|
131
|
+
},
|
|
132
|
+
method: 'post',
|
|
133
|
+
path: PLUGIN_API_ENDPOINT_GENERATE_UPLOAD
|
|
134
|
+
}
|
|
135
|
+
});
|
|
135
136
|
|
|
136
137
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/index.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport type { ActionMenuItems, Endpoints } from '../types.js'\n\nimport { GenerationModels } from '../ai/models/index.js'\nimport { defaultPrompts } from '../ai/prompts.js'\nimport {\n PLUGIN_API_ENDPOINT_GENERATE,\n PLUGIN_API_ENDPOINT_GENERATE_UPLOAD,\n PLUGIN_INSTRUCTIONS_TABLE,\n PLUGIN_NAME,\n} from '../defaults.js'\nimport { registerEditorHelper } from '../libraries/handlebars/helpers.js'\nimport { handlebarsHelpersMap } from '../libraries/handlebars/helpersMap.js'\nimport { replacePlaceholders } from '../libraries/handlebars/replacePlaceholders.js'\n\nconst assignPrompt = async (\n action: ActionMenuItems,\n {\n type,\n actionParams,\n context,\n field,\n layout,\n systemPrompt = '',\n template,\n }: {\n actionParams: Record<any, any>\n context: object\n field: string\n layout: string\n systemPrompt: string\n template: string\n type: string\n },\n) => {\n const prompt = await replacePlaceholders(template, context)\n const toLexicalHTML = type === 'richText' ? handlebarsHelpersMap.toHTML.name : ''\n\n const assignedPrompts = {\n layout: type === 'richText' ? layout : undefined,\n prompt,\n //TODO: Define only once on a collection level\n system: type === 'richText' ? systemPrompt : undefined,\n }\n\n if (action === 'Compose') {\n return assignedPrompts\n }\n\n const { layout: getLayout, system: getSystemPrompt } = defaultPrompts.find(\n (p) => p.name === action,\n )\n\n let updatedLayout = layout\n if (getLayout) {\n updatedLayout = getLayout()\n }\n\n const system = getSystemPrompt({\n ...(actionParams || {}),\n prompt,\n systemPrompt,\n })\n\n return {\n layout: updatedLayout,\n // TODO: revisit this toLexicalHTML\n prompt: await replacePlaceholders(`{{${toLexicalHTML} ${field}}}`, context),\n system,\n }\n}\n\nexport const endpoints: Endpoints = {\n textarea: { //TODO: This is the main endpoint for generating content - its just needs to be renamed to 'generate' or something.\n handler: async (req: PayloadRequest) => {\n const data = await req.json?.()\n\n const { locale = 'en', options } = data\n const { action, actionParams, instructionId } = options\n const contextData = data.doc\n\n if (!instructionId) {\n throw new Error(\n `Instruction ID is required for \"${PLUGIN_NAME}\" to work, please check your configuration`,\n )\n }\n\n const instructions = await req.payload.findByID({\n id: instructionId,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n })\n\n const { collections } = req.payload.config\n const collection = collections.find(\n (collection) => collection.slug === PLUGIN_INSTRUCTIONS_TABLE,\n )\n\n const { custom: { [PLUGIN_NAME]: { editorConfig = {} } = {} } = {} } = collection.admin\n const { schema: editorSchema = {} } = editorConfig\n const { prompt: promptTemplate = '' } = instructions\n\n const schemaPath = instructions['schema-path'] as string\n const fieldName = schemaPath?.split('.').pop()\n\n registerEditorHelper(req.payload, schemaPath)\n\n const { defaultLocale, locales = [] } = req.payload.config.localization || {}\n const localeData = locales.find((l) => {\n return l.code === locale\n })\n\n const localeInfo = localeData?.label[defaultLocale] || locale\n\n const model = GenerationModels.find((model) => model.id === instructions['model-id'])\n const settingsName = model.settings?.name\n const modelOptions = instructions[settingsName] || {}\n\n const prompts = await assignPrompt(action, {\n type: instructions['field-type'] as string,\n actionParams,\n context: contextData,\n field: fieldName,\n layout: instructions.layout,\n systemPrompt: instructions.system,\n template: promptTemplate as string,\n })\n\n // console.log('Running handler with prompts:', prompts)\n return model\n .handler?.(prompts.prompt, {\n ...modelOptions,\n editorSchema,\n layout: prompts.layout,\n locale: localeInfo,\n system: prompts.system,\n })\n .catch((error) => {\n console.error('Error: endpoint - generating text:', error)\n return new Response(JSON.stringify(error.message), { status: 500 })\n })\n },\n method: 'post',\n path: PLUGIN_API_ENDPOINT_GENERATE,\n },\n upload: {\n handler: async (req: PayloadRequest) => {\n const data = await req.json?.()\n\n const { options } = data\n const { instructionId } = options\n const contextData = data.doc\n\n let instructions = { 'model-id': '', prompt: '' }\n\n if (instructionId) {\n // @ts-expect-error\n instructions = await req.payload.findByID({\n id: instructionId,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n })\n }\n\n const { prompt: promptTemplate = '' } = instructions\n const schemaPath = instructions['schema-path']\n\n registerEditorHelper(req.payload, schemaPath)\n\n const text = await replacePlaceholders(promptTemplate, contextData)\n const modelId = instructions['model-id']\n const uploadCollectionSlug = instructions['relation-to']\n\n const model = GenerationModels.find((model) => model.id === modelId)\n const settingsName = model.settings?.name\n const modelOptions = instructions[settingsName] || {}\n\n const result = await model.handler?.(text, modelOptions)\n\n const assetData = await req.payload.create({\n collection: uploadCollectionSlug,\n data: result.data,\n file: result.file,\n })\n\n return new Response(\n JSON.stringify({\n result: {\n id: assetData.id,\n alt: assetData.alt,\n },\n }),\n )\n },\n method: 'post',\n path: PLUGIN_API_ENDPOINT_GENERATE_UPLOAD,\n },\n}\n"],"names":["GenerationModels","defaultPrompts","PLUGIN_API_ENDPOINT_GENERATE","PLUGIN_API_ENDPOINT_GENERATE_UPLOAD","PLUGIN_INSTRUCTIONS_TABLE","PLUGIN_NAME","registerEditorHelper","handlebarsHelpersMap","replacePlaceholders","assignPrompt","action","type","actionParams","context","field","layout","systemPrompt","template","prompt","toLexicalHTML","toHTML","name","assignedPrompts","undefined","system","getLayout","getSystemPrompt","find","p","updatedLayout","endpoints","textarea","handler","req","data","json","locale","options","instructionId","contextData","doc","Error","instructions","payload","findByID","id","collection","collections","config","slug","custom","editorConfig","admin","schema","editorSchema","promptTemplate","schemaPath","fieldName","split","pop","defaultLocale","locales","localization","localeData","l","code","localeInfo","label","model","settingsName","settings","modelOptions","prompts","catch","error","console","Response","JSON","stringify","message","status","method","path","upload","text","modelId","uploadCollectionSlug","result","assetData","create","file","alt"],"mappings":"AAIA,SAASA,gBAAg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ACxC,MAAM4C,uBAAuB5C,YAAY,CAAC,cAAc;YAExD,MAAM0B,QAAQpE,iBAAiB2B,IAAI,CAAC,CAACyC,QAAUA,MAAMvB,EAAE,KAAKwC;YAC5D,MAAMhB,eAAeD,MAAME,QAAQ,EAAEjD;YACrC,MAAMkD,eAAe7B,YAAY,CAAC2B,aAAa,IAAI,CAAC;YAEpD,MAAMkB,SAAS,MAAMnB,MAAMpC,OAAO,GAAGoD,MAAMb;YAE3C,MAAMiB,YAAY,MAAMvD,IAAIU,OAAO,CAAC8C,MAAM,CAAC;gBACzC3C,YAAYwC;gBACZpD,MAAMqD,OAAOrD,IAAI;gBACjBwD,MAAMH,OAAOG,IAAI;YACnB;YAEA,OAAO,IAAId,SACTC,KAAKC,SAAS,CAAC;gBACbS,QAAQ;oBACN1C,IAAI2C,UAAU3C,EAAE;oBAChB8C,KAAKH,UAAUG,GAAG;gBACpB;YACF;QAEJ;QACAV,QAAQ;QACRC,MAAM/E;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/index.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport type { ActionMenuItems, Endpoints, PluginConfig } from '../types.js'\n\nimport { defaultPrompts } from '../ai/prompts.js'\nimport {\n PLUGIN_API_ENDPOINT_GENERATE,\n PLUGIN_API_ENDPOINT_GENERATE_UPLOAD,\n PLUGIN_INSTRUCTIONS_TABLE,\n PLUGIN_NAME,\n} from '../defaults.js'\nimport { registerEditorHelper } from '../libraries/handlebars/helpers.js'\nimport { handlebarsHelpersMap } from '../libraries/handlebars/helpersMap.js'\nimport { replacePlaceholders } from '../libraries/handlebars/replacePlaceholders.js'\nimport { getGenerationModels } from '../utilities/getGenerationModels.js'\n\nconst assignPrompt = async (\n action: ActionMenuItems,\n {\n type,\n actionParams,\n context,\n field,\n layout,\n systemPrompt = '',\n template,\n }: {\n actionParams: Record<any, any>\n context: object\n field: string\n layout: string\n systemPrompt: string\n template: string\n type: string\n },\n) => {\n const prompt = await replacePlaceholders(template, context)\n const toLexicalHTML = type === 'richText' ? handlebarsHelpersMap.toHTML.name : ''\n\n const assignedPrompts = {\n layout: type === 'richText' ? layout : undefined,\n prompt,\n //TODO: Define only once on a collection level\n system: type === 'richText' ? systemPrompt : undefined,\n }\n\n if (action === 'Compose') {\n return assignedPrompts\n }\n\n const { layout: getLayout, system: getSystemPrompt } = defaultPrompts.find(\n (p) => p.name === action,\n )\n\n let updatedLayout = layout\n if (getLayout) {\n updatedLayout = getLayout()\n }\n\n const system = getSystemPrompt({\n ...(actionParams || {}),\n prompt,\n systemPrompt,\n })\n\n return {\n layout: updatedLayout,\n // TODO: revisit this toLexicalHTML\n prompt: await replacePlaceholders(`{{${toLexicalHTML} ${field}}}`, context),\n system,\n }\n}\n\nexport const endpoints: (pluginConfig: PluginConfig) => Endpoints = (pluginConfig) =>\n ({\n textarea: {\n //TODO: This is the main endpoint for generating content - its just needs to be renamed to 'generate' or something.\n handler: async (req: PayloadRequest) => {\n const data = await req.json?.()\n\n const { locale = 'en', options } = data\n const { action, actionParams, instructionId } = options\n const contextData = data.doc\n\n if (!instructionId) {\n throw new Error(\n `Instruction ID is required for \"${PLUGIN_NAME}\" to work, please check your configuration`,\n )\n }\n\n const instructions = await req.payload.findByID({\n id: instructionId,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n })\n\n const { collections } = req.payload.config\n const collection = collections.find(\n (collection) => collection.slug === PLUGIN_INSTRUCTIONS_TABLE,\n )\n\n const { custom: { [PLUGIN_NAME]: { editorConfig = {} } = {} } = {} } = collection.admin\n const { schema: editorSchema = {} } = editorConfig\n const { prompt: promptTemplate = '' } = instructions\n\n const schemaPath = instructions['schema-path'] as string\n const fieldName = schemaPath?.split('.').pop()\n\n registerEditorHelper(req.payload, schemaPath)\n\n const { defaultLocale, locales = [] } = req.payload.config.localization || {}\n const localeData = locales.find((l) => {\n return l.code === locale\n })\n\n const localeInfo = localeData?.label[defaultLocale] || locale\n\n const model = getGenerationModels(pluginConfig)\n .find((model) => model.id === instructions['model-id'])\n const settingsName = model.settings?.name\n const modelOptions = instructions[settingsName] || {}\n\n const prompts = await assignPrompt(action, {\n type: instructions['field-type'] as string,\n actionParams,\n context: contextData,\n field: fieldName,\n layout: instructions.layout,\n systemPrompt: instructions.system,\n template: promptTemplate as string,\n })\n\n // console.log('Running handler with prompts:', prompts)\n return model\n .handler?.(prompts.prompt, {\n ...modelOptions,\n editorSchema,\n layout: prompts.layout,\n locale: localeInfo,\n system: prompts.system,\n })\n .catch((error) => {\n console.error('Error: endpoint - generating text:', error)\n return new Response(JSON.stringify(error.message), { status: 500 })\n })\n },\n method: 'post',\n path: PLUGIN_API_ENDPOINT_GENERATE,\n },\n upload: {\n handler: async (req: PayloadRequest) => {\n const data = await req.json?.()\n\n const { options } = data\n const { instructionId } = options\n const contextData = data.doc\n\n let instructions = { 'model-id': '', prompt: '' }\n\n if (instructionId) {\n // @ts-expect-error\n instructions = await req.payload.findByID({\n id: instructionId,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n })\n }\n\n const { prompt: promptTemplate = '' } = instructions\n const schemaPath = instructions['schema-path']\n\n registerEditorHelper(req.payload, schemaPath)\n\n const text = await replacePlaceholders(promptTemplate, contextData)\n const modelId = instructions['model-id']\n const uploadCollectionSlug = instructions['relation-to']\n\n const model = getGenerationModels(pluginConfig)\n .find((model) => model.id === modelId)\n const settingsName = model.settings?.name\n const modelOptions = instructions[settingsName] || {}\n\n const result = await model.handler?.(text, modelOptions)\n\n const assetData = await req.payload.create({\n collection: uploadCollectionSlug,\n data: result.data,\n file: result.file,\n })\n\n return new Response(\n JSON.stringify({\n result: {\n id: assetData.id,\n alt: assetData.alt,\n },\n }),\n )\n },\n method: 'post',\n path: PLUGIN_API_ENDPOINT_GENERATE_UPLOAD,\n },\n }) satisfies Endpoints\n"],"names":["defaultPrompts","PLUGIN_API_ENDPOINT_GENERATE","PLUGIN_API_ENDPOINT_GENERATE_UPLOAD","PLUGIN_INSTRUCTIONS_TABLE","PLUGIN_NAME","registerEditorHelper","handlebarsHelpersMap","replacePlaceholders","getGenerationModels","assignPrompt","action","type","actionParams","context","field","layout","systemPrompt","template","prompt","toLexicalHTML","toHTML","name","assignedPrompts","undefined","system","getLayout","getSystemPrompt","find","p","updatedLayout","endpoints","pluginConfig","textarea","handler","req","data","json","locale","options","instructionId","contextData","doc","Error","instructions","payload","findByID","id","collection","collections","config","slug","custom","editorConfig","admin","schema","editorSchema","promptTemplate","schemaPath","fieldName","split","pop","defaultLocale","locales","localization","localeData","l","code","localeInfo","label","model","settingsName","settings","modelOptions","prompts","catch","error","console","Response","JSON","stringify","message","status","method","path","upload","text","modelId","uploadCollectionSlug","result","assetData","create","file","alt"],"mappings":"AAIA,SAASA,cAAc,QAAQ,mBAAkB;AACjD,SACEC,4BAA4B,EAC5BC,mCAAmC,EACnCC,yBAAyB,EACzBC,WAAW,QACN,iBAAgB;AACvB,SAASC,oBAAoB,QAAQ,qCAAoC;AACzE,SAASC,oBAAoB,QAAQ,wCAAuC;AAC5E,SAASC,mBAAmB,QAAQ,iDAAgD;AACpF,SAASC,mBAAmB,QAAQ,sCAAqC;AAEzE,MAAMC,eAAe,OACnBC,QACA,EACEC,IAAI,EACJC,YAAY,EACZC,OAAO,EACPC,KAAK,EACLC,MAAM,EACNC,eAAe,EAAE,EACjBC,QAAQ,EAST;IAED,MAAMC,SAAS,MAAMX,oBAAoBU,UAAUJ;IACnD,MAAMM,gBAAgBR,SAAS,aAAaL,qBAAqBc,MAAM,CAACC,IAAI,GAAG;IAE/E,MAAMC,kBAAkB;QACtBP,QAAQJ,SAAS,aAAaI,SAASQ;QACvCL;QACA,8CAA8C;QAC9CM,QAAQb,SAAS,aAAaK,eAAeO;IAC/C;IAEA,IAAIb,WAAW,WAAW;QACxB,OAAOY;IACT;IAEA,MAAM,EAAEP,QAAQU,SAAS,EAAED,QAAQE,eAAe,EAAE,GAAG1B,eAAe2B,IAAI,CACxE,CAACC,IAAMA,EAAEP,IAAI,KA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ED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/exports/types.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACnD,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/exports/types.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACnD,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type { payloadAiPlugin } from '../plugin.ts'\nexport type { PluginConfig } from '../types.ts'
|
|
1
|
+
{"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type { payloadAiPlugin } from '../plugin.ts'\nexport type { PluginConfig, GenerationConfig, GenerationModel } from '../types.ts'"],"names":[],"mappings":"AACA,WAAkF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../src/fields/LexicalEditor/feature.server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../src/fields/LexicalEditor/feature.server.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,mCAAmC,uGAK9C,CAAA"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createServerFeature } from '@payloadcms/richtext-lexical';
|
|
2
2
|
import { PLUGIN_LEXICAL_EDITOR_FEATURE } from '../../defaults.js';
|
|
3
|
-
|
|
4
|
-
const isActivated = isPluginActivated();
|
|
3
|
+
// TODO: Find a way to check if the plugin is activated
|
|
5
4
|
export const PayloadAiPluginLexicalEditorFeature = createServerFeature({
|
|
6
5
|
feature: {
|
|
7
|
-
ClientFeature:
|
|
6
|
+
ClientFeature: '@ai-stack/payloadcms/client#LexicalEditorFeatureClient'
|
|
8
7
|
},
|
|
9
8
|
key: PLUGIN_LEXICAL_EDITOR_FEATURE
|
|
10
9
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/LexicalEditor/feature.server.ts"],"sourcesContent":["import { createServerFeature } from '@payloadcms/richtext-lexical'\n\nimport { PLUGIN_LEXICAL_EDITOR_FEATURE } from '../../defaults.js'\
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/LexicalEditor/feature.server.ts"],"sourcesContent":["import { createServerFeature } from '@payloadcms/richtext-lexical'\n\nimport { PLUGIN_LEXICAL_EDITOR_FEATURE } from '../../defaults.js'\n\n// TODO: Find a way to check if the plugin is activated\nexport const PayloadAiPluginLexicalEditorFeature = createServerFeature({\n feature: {\n ClientFeature: '@ai-stack/payloadcms/client#LexicalEditorFeatureClient',\n },\n key: PLUGIN_LEXICAL_EDITOR_FEATURE,\n})\n"],"names":["createServerFeature","PLUGIN_LEXICAL_EDITOR_FEATURE","PayloadAiPluginLexicalEditorFeature","feature","ClientFeature","key"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,+BAA8B;AAElE,SAASC,6BAA6B,QAAQ,oBAAmB;AAEjE,uDAAuD;AACvD,OAAO,MAAMC,sCAAsCF,oBAAoB;IACrEG,SAAS;QACPC,eAAe;IACjB;IACAC,KAAKJ;AACP,GAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromptEditorField.d.ts","sourceRoot":"","sources":["../../../src/fields/PromptEditorField/PromptEditorField.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAGvD,OAAO,KAAK,MAAM,OAAO,CAAA;AAMzB,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,
|
|
1
|
+
{"version":3,"file":"PromptEditorField.d.ts","sourceRoot":"","sources":["../../../src/fields/PromptEditorField/PromptEditorField.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAGvD,OAAO,KAAK,MAAM,OAAO,CAAA;AAMzB,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CA0BhE,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { FieldLabel, useField } from '@payloadcms/ui';
|
|
3
|
+
import { FieldDescription, FieldLabel, useField } from '@payloadcms/ui';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { AutocompleteTextField } from '../../libraries/autocomplete/AutocompleteTextArea.js';
|
|
6
6
|
import { useInstructions } from '../../providers/InstructionsProvider/useInstructions.js';
|
|
@@ -29,6 +29,10 @@ export const PromptEditorField = (props)=>{
|
|
|
29
29
|
'{{ '
|
|
30
30
|
],
|
|
31
31
|
value: value
|
|
32
|
+
}),
|
|
33
|
+
/*#__PURE__*/ _jsx(FieldDescription, {
|
|
34
|
+
description: field?.admin?.description,
|
|
35
|
+
path: ""
|
|
32
36
|
})
|
|
33
37
|
]
|
|
34
38
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/PromptEditorField/PromptEditorField.tsx"],"sourcesContent":["'use client'\n\nimport type { TextareaFieldClientProps } from 'payload'\n\nimport { FieldLabel, useField } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { AutocompleteTextField } from '../../libraries/autocomplete/AutocompleteTextArea.js'\nimport { useInstructions } from '../../providers/InstructionsProvider/useInstructions.js'\n\n//NOTE: HMR does not work for plugin components anymore, I think it has to do with importMap/ string path\nexport const PromptEditorField: React.FC<TextareaFieldClientProps> = (props) => {\n const { field, path: pathFromContext } = props\n\n const { setValue, value } = useField<string>({\n path: pathFromContext,\n })\n\n const { promptEditorSuggestions } = useInstructions()\n\n return (\n <div className=\"field-type textarea\">\n <FieldLabel label={field.label} />\n <AutocompleteTextField\n changeOnSelect={(trigger, selected) => {\n return trigger + selected + ' }}'\n }}\n onChange={(val: string) => {\n setValue(val)\n }}\n options={promptEditorSuggestions}\n trigger={['{{ ']}\n value={value}\n />\n </div>\n )\n}\n"],"names":["FieldLabel","useField","React","AutocompleteTextField","useInstructions","PromptEditorField","props","field","path","pathFromContext","setValue","value","promptEditorSuggestions","div","className","label","changeOnSelect","trigger","selected","onChange","val","options"],"mappings":"AAAA;;AAIA,SAASA,UAAU,EAAEC,QAAQ,QAAQ,iBAAgB;
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/PromptEditorField/PromptEditorField.tsx"],"sourcesContent":["'use client'\n\nimport type { TextareaFieldClientProps } from 'payload'\n\nimport { FieldDescription, FieldLabel, useField } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { AutocompleteTextField } from '../../libraries/autocomplete/AutocompleteTextArea.js'\nimport { useInstructions } from '../../providers/InstructionsProvider/useInstructions.js'\n\n//NOTE: HMR does not work for plugin components anymore, I think it has to do with importMap/ string path\nexport const PromptEditorField: React.FC<TextareaFieldClientProps> = (props) => {\n const { field, path: pathFromContext } = props\n\n const { setValue, value } = useField<string>({\n path: pathFromContext,\n })\n\n const { promptEditorSuggestions } = useInstructions()\n\n return (\n <div className=\"field-type textarea\">\n <FieldLabel label={field.label} />\n <AutocompleteTextField\n changeOnSelect={(trigger, selected) => {\n return trigger + selected + ' }}'\n }}\n onChange={(val: string) => {\n setValue(val)\n }}\n options={promptEditorSuggestions}\n trigger={['{{ ']}\n value={value}\n />\n <FieldDescription description={field?.admin?.description} path=\"\" />\n </div>\n )\n}\n"],"names":["FieldDescription","FieldLabel","useField","React","AutocompleteTextField","useInstructions","PromptEditorField","props","field","path","pathFromContext","setValue","value","promptEditorSuggestions","div","className","label","changeOnSelect","trigger","selected","onChange","val","options","description","admin"],"mappings":"AAAA;;AAIA,SAASA,gBAAgB,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,iBAAgB;AACvE,OAAOC,WAAW,QAAO;AAEzB,SAASC,qBAAqB,QAAQ,uDAAsD;AAC5F,SAASC,eAAe,QAAQ,0DAAyD;AAEzF,yGAAyG;AACzG,OAAO,MAAMC,oBAAwD,CAACC;IACpE,MAAM,EAAEC,KAAK,EAAEC,MAAMC,eAAe,EAAE,GAAGH;IAEzC,MAAM,EAAEI,QAAQ,EAAEC,KAAK,EAAE,GAAGV,SAAiB;QAC3CO,MAAMC;IACR;IAEA,MAAM,EAAEG,uBAAuB,EAAE,GAAGR;IAEpC,qBACE,MAACS;QAAIC,WAAU;;0BACb,KAACd;gBAAWe,OAAOR,MAAMQ,KAAK;;0BAC9B,KAACZ;gBACCa,gBAAgB,CAACC,SAASC;oBACxB,OAAOD,UAAUC,WAAW;gBAC9B;gBACAC,UAAU,CAACC;oBACTV,SAASU;gBACX;gBACAC,SAAST;gBACTK,SAAS;oBAAC;iBAAM;gBAChBN,OAAOA;;0BAET,KAACZ;gBAAiBuB,aAAaf,OAAOgB,OAAOD;gBAAad,MAAK;;;;AAGrE,EAAC"}
|
package/dist/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAO9C,eAAO,MAAM,IAAI,GAAU,SAAS,OAAO,EAAE,qBAAgB,EAAE,cAAc,YAAY,
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAO9C,eAAO,MAAM,IAAI,GAAU,SAAS,OAAO,EAAE,qBAAgB,EAAE,cAAc,YAAY,kBA4FxF,CAAA"}
|
package/dist/init.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { GenerationModels } from './ai/models/index.js';
|
|
2
1
|
import { seedPrompts } from './ai/prompts.js';
|
|
3
2
|
import { systemGenerate } from './ai/utils/systemGenerate.js';
|
|
4
3
|
import { PLUGIN_INSTRUCTIONS_TABLE } from './defaults.js';
|
|
4
|
+
import { getGenerationModels } from './utilities/getGenerationModels.js';
|
|
5
5
|
export const init = async (payload, fieldSchemaPaths, pluginConfig)=>{
|
|
6
6
|
payload.logger.info(`— AI Plugin: Initializing...`);
|
|
7
7
|
const paths = Object.keys(fieldSchemaPaths);
|
|
@@ -30,17 +30,19 @@ export const init = async (payload, fieldSchemaPaths, pluginConfig)=>{
|
|
|
30
30
|
});
|
|
31
31
|
let generatedPrompt = '{{ title }}';
|
|
32
32
|
if (pluginConfig.generatePromptOnInit) {
|
|
33
|
+
// find the model that has the generateText function
|
|
34
|
+
const model = getGenerationModels(pluginConfig).find((model)=>model.generateText);
|
|
33
35
|
generatedPrompt = await systemGenerate({
|
|
34
36
|
prompt,
|
|
35
37
|
system
|
|
36
|
-
});
|
|
38
|
+
}, model?.generateText);
|
|
37
39
|
payload.logger.info(`\nPrompt generated for "${fieldLabel}" field:\nprompt: ${generatedPrompt}\n\n`);
|
|
38
40
|
}
|
|
39
41
|
const instructions = await payload.create({
|
|
40
42
|
collection: PLUGIN_INSTRUCTIONS_TABLE,
|
|
41
43
|
data: {
|
|
42
44
|
'field-type': fieldType,
|
|
43
|
-
'model-id':
|
|
45
|
+
'model-id': getGenerationModels(pluginConfig).find((a)=>{
|
|
44
46
|
return a.fields.includes(fieldType);
|
|
45
47
|
})?.id,
|
|
46
48
|
prompt: generatedPrompt,
|
package/dist/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport type { PluginConfig } from './types.js'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport type { PluginConfig } from './types.js'\n\nimport { seedPrompts } from './ai/prompts.js'\nimport { systemGenerate } from './ai/utils/systemGenerate.js'\nimport { PLUGIN_INSTRUCTIONS_TABLE } from './defaults.js'\nimport { getGenerationModels } from './utilities/getGenerationModels.js'\n\nexport const init = async (payload: Payload, fieldSchemaPaths, pluginConfig: PluginConfig) => {\n payload.logger.info(`— AI Plugin: Initializing...`)\n\n const paths = Object.keys(fieldSchemaPaths)\n\n const fieldInstructionsMap = {}\n for (let i = 0; i < paths.length; i++) {\n const path = paths[i]\n const { type: fieldType, label: fieldLabel, relationTo } = fieldSchemaPaths[path]\n const entry = await payload.find({\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n pagination: false,\n where: {\n 'field-type': {\n equals: fieldType,\n },\n 'schema-path': {\n equals: path,\n },\n },\n })\n\n if (!entry?.docs?.length) {\n const { prompt, system } = seedPrompts({\n fieldLabel,\n fieldSchemaPaths,\n fieldType,\n path,\n })\n\n let generatedPrompt = '{{ title }}'\n if (pluginConfig.generatePromptOnInit) {\n // find the model that has the generateText function\n const model = getGenerationModels(pluginConfig).find((model) => model.generateText)\n generatedPrompt = await systemGenerate(\n {\n prompt,\n system,\n },\n model?.generateText,\n )\n payload.logger.info(\n `\\nPrompt generated for \"${fieldLabel}\" field:\\nprompt: ${generatedPrompt}\\n\\n`,\n )\n }\n\n const instructions = await payload\n .create({\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n data: {\n 'field-type': fieldType,\n 'model-id': getGenerationModels(pluginConfig).find((a) => {\n return a.fields.includes(fieldType)\n })?.id,\n prompt: generatedPrompt,\n 'relation-to': relationTo,\n 'schema-path': path,\n },\n })\n .then((a) => a)\n .catch((err) => {\n console.log('— AI Plugin: Error creating Compose settings-', err)\n })\n\n // @ts-expect-error\n if (instructions?.id) {\n fieldInstructionsMap[path] = {\n id: instructions.id,\n fieldType,\n }\n }\n } else {\n const [instructions] = entry.docs\n fieldInstructionsMap[path] = {\n id: instructions.id,\n fieldType,\n }\n }\n }\n\n if (pluginConfig.debugging) {\n payload.logger.info(\n `— AI Plugin: Enabled fields map: ${JSON.stringify(fieldInstructionsMap, null, 2)}`,\n )\n }\n\n payload.logger.info(`— AI Plugin: Initialized!`)\n if (pluginConfig.generatePromptOnInit) {\n payload.logger.info(\n '\\n\\n-AI Plugin: Example prompts are added to get you started, Now go break some code 🚀🚀🚀\\n\\n',\n )\n }\n}\n"],"names":["seedPrompts","systemGenerate","PLUGIN_INSTRUCTIONS_TABLE","getGenerationModels","init","payload","fieldSchemaPaths","pluginConfig","logger","info","paths","Object","keys","fieldInstructionsMap","i","length","path","type","fieldType","label","fieldLabel","relationTo","entry","find","collection","pagination","where","equals","docs","prompt","system","generatedPrompt","generatePromptOnInit","model","generateText","instructions","create","data","a","fields","includes","id","then","catch","err","console","log","debugging","JSON","stringify"],"mappings":"AAIA,SAASA,WAAW,QAAQ,kBAAiB;AAC7C,SAASC,cAAc,QAAQ,+BAA8B;AAC7D,SAASC,yBAAyB,QAAQ,gBAAe;AACzD,SAASC,mBAAmB,QAAQ,qCAAoC;AAExE,OAAO,MAAMC,OAAO,OAAOC,SAAkBC,kBAAkBC;IAC7DF,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,4BAA4B,CAAC;IAElD,MAAMC,QAAQC,OAAOC,IAAI,CAACN;IAE1B,MAAMO,uBAAuB,CAAC;IAC9B,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,MAAMK,MAAM,EAAED,IAAK;QACrC,MAAME,OAAON,KAAK,CAACI,EAAE;QACrB,MAAM,EAAEG,MAAMC,SAAS,EAAEC,OAAOC,UAAU,EAAEC,UAAU,EAAE,GAAGf,gBAAgB,CAACU,KAAK;QACjF,MAAMM,QAAQ,MAAMjB,QAAQkB,IAAI,CAAC;YAC/BC,YAAYtB;YACZuB,YAAY;YACZ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QG,MAAM,CAACC,IAAI,CACjB,CAAC,iCAAiC,EAAEuC,KAAKC,SAAS,CAACpC,sBAAsB,MAAM,IAAI;IAEvF;IAEAR,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,yBAAyB,CAAC;IAC/C,IAAIF,aAAayB,oBAAoB,EAAE;QACrC3B,QAAQG,MAAM,CAACC,IAAI,CACjB;IAEJ;AACF,EAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const replacePlaceholders: (prompt: string, values: object) =>
|
|
1
|
+
export declare const replacePlaceholders: (prompt: string, values: object) => Promise<string>;
|
|
2
2
|
//# sourceMappingURL=replacePlaceholders.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replacePlaceholders.d.ts","sourceRoot":"","sources":["../../../src/libraries/handlebars/replacePlaceholders.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,GAAI,QAAQ,MAAM,EAAE,QAAQ,MAAM,
|
|
1
|
+
{"version":3,"file":"replacePlaceholders.d.ts","sourceRoot":"","sources":["../../../src/libraries/handlebars/replacePlaceholders.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,GAAI,QAAQ,MAAM,EAAE,QAAQ,MAAM,KACM,OAAO,CAAC,MAAM,CACrF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/libraries/handlebars/replacePlaceholders.ts"],"sourcesContent":["import { asyncHandlebars } from './asyncHandlebars.js'\n\nexport const replacePlaceholders = (prompt: string, values: object) => {\n return asyncHandlebars.compile(prompt, { trackIds: true })(values)
|
|
1
|
+
{"version":3,"sources":["../../../src/libraries/handlebars/replacePlaceholders.ts"],"sourcesContent":["import { asyncHandlebars } from './asyncHandlebars.js'\n\nexport const replacePlaceholders = (prompt: string, values: object) => {\n return asyncHandlebars.compile(prompt, { trackIds: true })(values) as Promise<string>\n}\n"],"names":["asyncHandlebars","replacePlaceholders","prompt","values","compile","trackIds"],"mappings":"AAAA,SAASA,eAAe,QAAQ,uBAAsB;AAEtD,OAAO,MAAMC,sBAAsB,CAACC,QAAgBC;IAClD,OAAOH,gBAAgBI,OAAO,CAACF,QAAQ;QAAEG,UAAU;IAAK,GAAGF;AAC7D,EAAC"}
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAyC9C,QAAA,MAAM,eAAe,GAClB,cAAc,YAAY,MAC1B,gBAAgB,MAAM,KAAG,MAiGzB,CAAA;AAEH,OAAO,EAAE,eAAe,EAAE,CAAA"}
|
package/dist/plugin.js
CHANGED
|
@@ -8,10 +8,13 @@ import { init } from './init.js';
|
|
|
8
8
|
import { translations } from './translations/index.js';
|
|
9
9
|
import { isPluginActivated } from './utilities/isPluginActivated.js';
|
|
10
10
|
import { updateFieldsConfig } from './utilities/updateFieldsConfig.js';
|
|
11
|
+
import { defaultGenerationModels } from './ai/models/index.js';
|
|
12
|
+
import { getGenerationModels } from './utilities/getGenerationModels.js';
|
|
11
13
|
const defaultPluginConfig = {
|
|
12
14
|
collections: {},
|
|
13
15
|
disableSponsorMessage: false,
|
|
14
|
-
generatePromptOnInit: true
|
|
16
|
+
generatePromptOnInit: true,
|
|
17
|
+
generationModels: defaultGenerationModels
|
|
15
18
|
};
|
|
16
19
|
const sponsorMessage = `
|
|
17
20
|
╔═══════════════════════════════════════════════════════════════╗
|
|
@@ -37,13 +40,14 @@ const payloadAiPlugin = (pluginConfig)=>(incomingConfig)=>{
|
|
|
37
40
|
...defaultPluginConfig,
|
|
38
41
|
...pluginConfig
|
|
39
42
|
};
|
|
40
|
-
|
|
43
|
+
pluginConfig.generationModels = getGenerationModels(pluginConfig);
|
|
44
|
+
const isActivated = isPluginActivated(pluginConfig);
|
|
41
45
|
let updatedConfig = {
|
|
42
46
|
...incomingConfig
|
|
43
47
|
};
|
|
44
48
|
let collectionsFieldPathMap = {};
|
|
45
49
|
if (isActivated) {
|
|
46
|
-
const Instructions = instructionsCollection();
|
|
50
|
+
const Instructions = instructionsCollection(pluginConfig);
|
|
47
51
|
// Inject editor schema to config, so that it can be accessed when /textarea endpoint will hit
|
|
48
52
|
const lexicalSchema = lexicalJsonSchema(pluginConfig.editorConfig?.nodes);
|
|
49
53
|
if (pluginConfig.debugging) {
|
|
@@ -77,6 +81,7 @@ const payloadAiPlugin = (pluginConfig)=>(incomingConfig)=>{
|
|
|
77
81
|
providers: updatedProviders
|
|
78
82
|
}
|
|
79
83
|
};
|
|
84
|
+
const pluginEndpoints = endpoints(pluginConfig);
|
|
80
85
|
updatedConfig = {
|
|
81
86
|
...incomingConfig,
|
|
82
87
|
collections: collections.map((collection)=>{
|
|
@@ -92,8 +97,8 @@ const payloadAiPlugin = (pluginConfig)=>(incomingConfig)=>{
|
|
|
92
97
|
}),
|
|
93
98
|
endpoints: [
|
|
94
99
|
...incomingConfig.endpoints ?? [],
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
pluginEndpoints.textarea,
|
|
101
|
+
pluginEndpoints.upload,
|
|
97
102
|
fetchFields
|
|
98
103
|
],
|
|
99
104
|
i18n: {
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport { deepMerge } from 'payload/shared'\n\nimport type { PluginConfig } from './types.js'\n\nimport { lexicalJsonSchema } from './ai/schemas/lexicalJsonSchema.js'\nimport { instructionsCollection } from './collections/Instructions.js'\nimport { PLUGIN_NAME } from './defaults.js'\nimport { fetchFields } from './endpoints/fetchFields.js'\nimport { endpoints } from './endpoints/index.js'\nimport { init } from './init.js'\nimport { translations } from './translations/index.js'\nimport { isPluginActivated } from './utilities/isPluginActivated.js'\nimport { updateFieldsConfig } from './utilities/updateFieldsConfig.js'\n\nconst defaultPluginConfig: PluginConfig = {\n collections: {},\n disableSponsorMessage: false,\n generatePromptOnInit: true,\n}\n\nconst sponsorMessage = `\n╔═══════════════════════════════════════════════════════════════╗\n║ THANK YOU FOR USING THE PAYLOAD AI PLUGIN! ║\n║ ║\n║ If this plugin makes your life easier, please ║\n║ consider supporting its development and maintenance: ║\n║ ║\n║ • Buy me a coffee: https://buymeacoffee.com/ashbuilds ║\n║ • Sponsor on GitHub: https://github.com/sponsors/ashbuilds ║\n║ ║\n║ Your support fuels continued improvements, ║\n║ new features, and more caffeinated coding sessions! ☕ ║\n║ ║\n║ Got feedback or need help? Submit an issue here: ║\n║ • https://github.com/ashbuilds/payload-ai/issues/new ║\n║ ║\n║ Thank you again, and happy building! ║\n╚═══════════════════════════════════════════════════════════════╝\n`\n\nconst payloadAiPlugin =\n (pluginConfig: PluginConfig) =>\n (incomingConfig: Config): Config => {\n pluginConfig = { ...defaultPluginConfig, ...pluginConfig }\n const isActivated = isPluginActivated()\n let updatedConfig: Config = { ...incomingConfig }\n let collectionsFieldPathMap = {}\n if (isActivated) {\n const Instructions = instructionsCollection()\n // Inject editor schema to config, so that it can be accessed when /textarea endpoint will hit\n const lexicalSchema = lexicalJsonSchema(pluginConfig.editorConfig?.nodes)\n\n if (pluginConfig.debugging) {\n Instructions.admin.hidden = false\n }\n\n Instructions.admin.custom = {\n ...(Instructions.admin.custom || {}),\n [PLUGIN_NAME]: {\n editorConfig: {\n // Used in admin client for useObject hook\n schema: lexicalSchema,\n },\n },\n }\n\n const collections = [...(incomingConfig.collections ?? []), Instructions]\n const { collections: collectionSlugs = [] } = pluginConfig\n\n const { components: { providers = [] } = {} } = incomingConfig.admin || {}\n const updatedProviders = [\n ...(providers ?? []),\n {\n path: '@ai-stack/payloadcms/client#InstructionsProvider',\n },\n ]\n\n incomingConfig.admin = {\n ...(incomingConfig.admin || {}),\n components: {\n ...(incomingConfig.admin?.components ?? {}),\n providers: updatedProviders,\n },\n }\n\n updatedConfig = {\n ...incomingConfig,\n collections: collections.map((collection) => {\n if (collectionSlugs[collection.slug]) {\n const { schemaPathMap, updatedCollectionConfig } = updateFieldsConfig(collection)\n collectionsFieldPathMap = {\n ...collectionsFieldPathMap,\n ...schemaPathMap,\n }\n return updatedCollectionConfig\n }\n\n return collection\n }),\n endpoints: [\n ...(incomingConfig.endpoints ?? []),\n
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport { deepMerge } from 'payload/shared'\n\nimport type { PluginConfig } from './types.js'\n\nimport { lexicalJsonSchema } from './ai/schemas/lexicalJsonSchema.js'\nimport { instructionsCollection } from './collections/Instructions.js'\nimport { PLUGIN_NAME } from './defaults.js'\nimport { fetchFields } from './endpoints/fetchFields.js'\nimport { endpoints } from './endpoints/index.js'\nimport { init } from './init.js'\nimport { translations } from './translations/index.js'\nimport { isPluginActivated } from './utilities/isPluginActivated.js'\nimport { updateFieldsConfig } from './utilities/updateFieldsConfig.js'\nimport { defaultGenerationModels } from './ai/models/index.js'\nimport { getGenerationModels } from './utilities/getGenerationModels.js'\n\nconst defaultPluginConfig: PluginConfig = {\n collections: {},\n disableSponsorMessage: false,\n generatePromptOnInit: true,\n generationModels: defaultGenerationModels\n}\n\nconst sponsorMessage = `\n╔═══════════════════════════════════════════════════════════════╗\n║ THANK YOU FOR USING THE PAYLOAD AI PLUGIN! ║\n║ ║\n║ If this plugin makes your life easier, please ║\n║ consider supporting its development and maintenance: ║\n║ ║\n║ • Buy me a coffee: https://buymeacoffee.com/ashbuilds ║\n║ • Sponsor on GitHub: https://github.com/sponsors/ashbuilds ║\n║ ║\n║ Your support fuels continued improvements, ║\n║ new features, and more caffeinated coding sessions! ☕ ║\n║ ║\n║ Got feedback or need help? Submit an issue here: ║\n║ • https://github.com/ashbuilds/payload-ai/issues/new ║\n║ ║\n║ Thank you again, and happy building! ║\n╚═══════════════════════════════════════════════════════════════╝\n`\n\nconst payloadAiPlugin =\n (pluginConfig: PluginConfig) =>\n (incomingConfig: Config): Config => {\n pluginConfig = { ...defaultPluginConfig, ...pluginConfig }\n pluginConfig.generationModels = getGenerationModels(pluginConfig)\n const isActivated = isPluginActivated(pluginConfig)\n let updatedConfig: Config = { ...incomingConfig }\n let collectionsFieldPathMap = {}\n if (isActivated) {\n const Instructions = instructionsCollection(pluginConfig)\n // Inject editor schema to config, so that it can be accessed when /textarea endpoint will hit\n const lexicalSchema = lexicalJsonSchema(pluginConfig.editorConfig?.nodes)\n\n if (pluginConfig.debugging) {\n Instructions.admin.hidden = false\n }\n\n Instructions.admin.custom = {\n ...(Instructions.admin.custom || {}),\n [PLUGIN_NAME]: {\n editorConfig: {\n // Used in admin client for useObject hook\n schema: lexicalSchema,\n },\n },\n }\n\n const collections = [...(incomingConfig.collections ?? []), Instructions]\n const { collections: collectionSlugs = [] } = pluginConfig\n\n const { components: { providers = [] } = {} } = incomingConfig.admin || {}\n const updatedProviders = [\n ...(providers ?? []),\n {\n path: '@ai-stack/payloadcms/client#InstructionsProvider',\n },\n ]\n\n incomingConfig.admin = {\n ...(incomingConfig.admin || {}),\n components: {\n ...(incomingConfig.admin?.components ?? {}),\n providers: updatedProviders,\n },\n }\n\n const pluginEndpoints = endpoints(pluginConfig)\n updatedConfig = {\n ...incomingConfig,\n collections: collections.map((collection) => {\n if (collectionSlugs[collection.slug]) {\n const { schemaPathMap, updatedCollectionConfig } = updateFieldsConfig(collection)\n collectionsFieldPathMap = {\n ...collectionsFieldPathMap,\n ...schemaPathMap,\n }\n return updatedCollectionConfig\n }\n\n return collection\n }),\n endpoints: [\n ...(incomingConfig.endpoints ?? []),\n pluginEndpoints.textarea,\n pluginEndpoints.upload,\n fetchFields,\n ],\n i18n: {\n ...(incomingConfig.i18n || {}),\n translations: {\n ...deepMerge(translations, incomingConfig.i18n?.translations ?? {}),\n },\n },\n }\n }\n\n updatedConfig.onInit = async (payload) => {\n if (incomingConfig.onInit) await incomingConfig.onInit(payload)\n\n if (!isActivated) {\n payload.logger.warn(`— AI Plugin: Not activated. Please verify your environment keys.`)\n return\n }\n\n await init(payload, collectionsFieldPathMap, pluginConfig)\n .catch((error) => {\n console.error(error)\n payload.logger.error(`— AI Plugin: Initialization Error: ${error}`)\n })\n .finally(() => {\n if (!pluginConfig.disableSponsorMessage) {\n setTimeout(() => {\n payload.logger.info(sponsorMessage)\n }, 3000)\n }\n })\n }\n\n return updatedConfig\n }\n\nexport { payloadAiPlugin }\n"],"names":["deepMerge","lexicalJsonSchema","instructionsCollection","PLUGIN_NAME","fetchFields","endpoints","init","translations","isPluginActivated","updateFieldsConfig","defaultGenerationModels","getGenerationModels","defaultPluginConfig","collections","disableSponsorMessage","generatePromptOnInit","generationModels","sponsorMessage","payloadAiPlugin","pluginConfig","incomingConfig","isActivated","updatedConfig","collectionsFieldPathMap","Instructions","lexicalSchema","editorConfig","nodes","debugging","admin","hidden","custom","schema","collectionSlugs","components","providers","updatedProviders","path","pluginEndpoints","map","collection","slug","schemaPathMap","updatedCollectionConfig","textarea","upload","i18n","onInit","payload","logger","warn","catch","error","console","finally","setTimeout","info"],"mappings":"AAEA,SAASA,SAAS,QAAQ,iBAAgB;AAI1C,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,sBAAsB,QAAQ,gCAA+B;AACtE,SAASC,WAAW,QAAQ,gBAAe;AAC3C,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,YAAY,QAAQ,0BAAyB;AACtD,SAASC,iBAAiB,QAAQ,mCAA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CAACO,IAAI,CAACvC;oBACtB,GAAG;gBACL;YACF;QACJ;QAEA,OAAOK;IACT;AAEF,SAASJ,eAAe,GAAE"}
|
package/dist/types.d.ts
CHANGED
|
@@ -12,17 +12,19 @@ export interface PluginConfig {
|
|
|
12
12
|
};
|
|
13
13
|
fields?: Field[];
|
|
14
14
|
generatePromptOnInit?: boolean;
|
|
15
|
+
generationModels?: ((defaultModels: GenerationModel[]) => GenerationModel[]) | GenerationModel[];
|
|
15
16
|
globals?: string[];
|
|
16
17
|
interfaceName?: string;
|
|
17
18
|
}
|
|
18
19
|
export interface GenerationModel {
|
|
19
20
|
fields: string[];
|
|
20
|
-
handler?: (
|
|
21
|
+
handler?: (prompt: string, options: any) => Promise<any>;
|
|
21
22
|
id: string;
|
|
22
23
|
name: string;
|
|
23
24
|
output: 'audio' | 'file' | 'image' | 'json' | 'text' | 'video';
|
|
24
25
|
settings?: GroupField;
|
|
25
26
|
supportsPromptOptimization?: boolean;
|
|
27
|
+
generateText?: (prompt: string, system: string) => Promise<string>;
|
|
26
28
|
}
|
|
27
29
|
export interface GenerationConfig {
|
|
28
30
|
models: GenerationModel[];
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAE7D,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE;QACX,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KACvB,CAAA;IACD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,YAAY,CAAC,EAAE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Y,GACZ,YAAY,GACZ,aAAa,GACb,QAAQ,GACR,aAAa,CAAA;AAEjB,MAAM,MAAM,aAAa,GAAG;KACzB,GAAG,IAAI,gBAAgB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI;CACrD,CAAA;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,GAAG,IAAI;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IACjC,YAAY,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;IAC/C,YAAY,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;IAC/C,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAA;IACjC,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { JSONSchema } from 'openai/lib/jsonschema'\nimport type { Endpoint, Field, GroupField } from 'payload'\nimport type { CSSProperties, MouseEventHandler } from 'react'\n\nexport interface PluginConfig {\n collections: {\n [key: string]: boolean\n }\n debugging?: boolean\n disableSponsorMessage?: boolean\n editorConfig?: { nodes: JSONSchema[] }\n fields?: Field[]\n generatePromptOnInit?: boolean\n globals?: string[]\n interfaceName?: string\n}\n\nexport interface GenerationModel {\n fields: string[]\n handler?: (
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { JSONSchema } from 'openai/lib/jsonschema'\nimport type { Endpoint, Field, GroupField } from 'payload'\nimport type { CSSProperties, MouseEventHandler } from 'react'\n\nexport interface PluginConfig {\n collections: {\n [key: string]: boolean\n }\n debugging?: boolean\n disableSponsorMessage?: boolean\n editorConfig?: { nodes: JSONSchema[] }\n fields?: Field[]\n generatePromptOnInit?: boolean\n generationModels?: ((defaultModels: GenerationModel[]) => GenerationModel[]) | GenerationModel[]\n globals?: string[]\n interfaceName?: string\n}\n\nexport interface GenerationModel {\n fields: string[]\n handler?: (prompt: string, options: any) => Promise<any>\n id: string\n name: string\n output: 'audio' | 'file' | 'image' | 'json' | 'text' | 'video'\n settings?: GroupField\n supportsPromptOptimization?: boolean\n generateText?: (prompt: string, system: string) => Promise<string>\n}\n\nexport interface GenerationConfig {\n models: GenerationModel[]\n provider: string\n}\n\nexport type GenerateTextarea<T = any> = (args: {\n doc: T\n locale?: string\n options?: any\n}) => Promise<string> | string\n\nexport interface Instructions {\n 'collection-slug': string\n id: string\n 'model-id': string\n prompt: string\n}\n\nexport interface Endpoints {\n textarea: Omit<Endpoint, 'root'>\n upload: Omit<Endpoint, 'root'>\n}\n\nexport type ActionMenuItems =\n | 'Compose'\n | 'Expand'\n | 'Proofread'\n | 'Rephrase'\n | 'Settings'\n | 'Simplify'\n | 'Summarize'\n | 'Tone'\n | 'Translate'\n\nexport type ActionMenuEvents =\n | 'onCompose'\n | 'onExpand'\n | 'onProofread'\n | 'onRephrase'\n | 'onSettings'\n | 'onSimplify'\n | 'onSummarize'\n | 'onTone'\n | 'onTranslate'\n\nexport type UseMenuEvents = {\n [key in ActionMenuEvents]?: (data?: unknown) => void\n}\n\nexport type BaseItemProps<T = any> = {\n children?: React.ReactNode\n disabled?: boolean\n hideIcon?: boolean\n isActive?: boolean\n isMenu?: boolean\n onClick: (data?: unknown) => void\n onMouseEnter?: MouseEventHandler<T> | undefined\n onMouseLeave?: MouseEventHandler<T> | undefined\n style?: CSSProperties | undefined\n title?: string\n}\n"],"names":[],"mappings":"AA8EA,WAWC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getGenerationModels.d.ts","sourceRoot":"","sources":["../../src/utilities/getGenerationModels.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,YAAY,2CAO3B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defaultGenerationModels } from '../ai/models/index.js';
|
|
2
|
+
export function getGenerationModels(pluginConfig) {
|
|
3
|
+
const { generationModels } = pluginConfig;
|
|
4
|
+
if (typeof generationModels === 'function') {
|
|
5
|
+
return generationModels(defaultGenerationModels);
|
|
6
|
+
}
|
|
7
|
+
return generationModels;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=getGenerationModels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getGenerationModels.ts"],"sourcesContent":["import { defaultGenerationModels } from '../ai/models/index.js'\nimport { PluginConfig } from '../types.js'\n\nexport function getGenerationModels(\n pluginConfig: PluginConfig,\n) {\n const { generationModels } = pluginConfig\n if (typeof generationModels === 'function') {\n return generationModels(defaultGenerationModels)\n }\n return generationModels\n}\n"],"names":["defaultGenerationModels","getGenerationModels","pluginConfig","generationModels"],"mappings":"AAAA,SAASA,uBAAuB,QAAQ,wBAAuB;AAG/D,OAAO,SAASC,oBACdC,YAA0B;IAE1B,MAAM,EAAEC,gBAAgB,EAAE,GAAGD;IAC7B,IAAI,OAAOC,qBAAqB,YAAY;QAC1C,OAAOA,iBAAiBH;IAC1B;IACA,OAAOG;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPluginActivated.d.ts","sourceRoot":"","sources":["../../src/utilities/isPluginActivated.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isPluginActivated.d.ts","sourceRoot":"","sources":["../../src/utilities/isPluginActivated.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,eAAO,MAAM,iBAAiB,GAAI,cAAc,YAAY,YAE3D,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { getGenerationModels } from './getGenerationModels.js';
|
|
2
|
+
export const isPluginActivated = (pluginConfig)=>{
|
|
3
|
+
return getGenerationModels(pluginConfig).length > 0;
|
|
3
4
|
};
|
|
4
5
|
|
|
5
6
|
//# sourceMappingURL=isPluginActivated.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/isPluginActivated.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/isPluginActivated.ts"],"sourcesContent":["import { getGenerationModels } from './getGenerationModels.js'\nimport { PluginConfig } from '../types.js'\n\nexport const isPluginActivated = (pluginConfig: PluginConfig) => {\n return getGenerationModels(pluginConfig).length > 0\n}\n"],"names":["getGenerationModels","isPluginActivated","pluginConfig","length"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,2BAA0B;AAG9D,OAAO,MAAMC,oBAAoB,CAACC;IAChC,OAAOF,oBAAoBE,cAAcC,MAAM,GAAG;AACpD,EAAC"}
|