@ai-stack/payloadcms 3.2.16-beta → 3.2.17-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 +79 -0
- package/dist/ai/analyse.d.ts +0 -1
- package/dist/ai/models/anthropic/generateRichText.d.ts +0 -1
- package/dist/ai/models/anthropic/generateRichText.js +7 -8
- package/dist/ai/models/anthropic/generateRichText.js.map +1 -1
- package/dist/ai/models/anthropic/index.d.ts +0 -1
- package/dist/ai/models/anthropic/index.js +54 -3
- package/dist/ai/models/anthropic/index.js.map +1 -1
- package/dist/ai/models/elevenLabs/generateVoice.d.ts +1 -2
- package/dist/ai/models/elevenLabs/index.d.ts +0 -1
- package/dist/ai/models/elevenLabs/index.js +5 -2
- package/dist/ai/models/elevenLabs/index.js.map +1 -1
- package/dist/ai/models/elevenLabs/voices.d.ts +6 -2
- package/dist/ai/models/elevenLabs/voices.js.map +1 -1
- package/dist/ai/models/index.d.ts +0 -1
- package/dist/ai/models/openai/generateImage.d.ts +1 -2
- package/dist/ai/models/openai/generateImage.js +6 -4
- package/dist/ai/models/openai/generateImage.js.map +1 -1
- package/dist/ai/models/openai/generateRichText.d.ts +0 -1
- package/dist/ai/models/openai/generateRichText.js +9 -12
- package/dist/ai/models/openai/generateRichText.js.map +1 -1
- package/dist/ai/models/openai/generateVoice.d.ts +1 -2
- package/dist/ai/models/openai/index.d.ts +0 -1
- package/dist/ai/models/openai/index.js +63 -4
- package/dist/ai/models/openai/index.js.map +1 -1
- package/dist/ai/models/openai/openai.d.ts +0 -1
- package/dist/ai/models/openai/openai.js +1 -2
- package/dist/ai/models/openai/openai.js.map +1 -1
- package/dist/ai/prompts.d.ts +2 -23
- package/dist/ai/prompts.js +2 -2
- package/dist/ai/prompts.js.map +1 -1
- package/dist/ai/schemas/lexicalJsonSchema.d.ts +5 -4
- package/dist/ai/schemas/lexicalJsonSchema.js +3 -1
- package/dist/ai/schemas/lexicalJsonSchema.js.map +1 -1
- package/dist/ai/utils/editImagesWithOpenAI.d.ts +0 -1
- package/dist/ai/utils/filterEditorSchemaByNodes.d.ts +19 -29
- package/dist/ai/utils/filterEditorSchemaByNodes.js +4 -2
- package/dist/ai/utils/filterEditorSchemaByNodes.js.map +1 -1
- package/dist/ai/utils/generateFileNameByPrompt.d.ts +1 -2
- package/dist/ai/utils/generateFileNameByPrompt.js.map +1 -1
- package/dist/ai/utils/isObjectSchema.d.ts +0 -1
- package/dist/ai/utils/systemGenerate.d.ts +0 -1
- package/dist/collections/Instructions.d.ts +0 -1
- package/dist/collections/Instructions.js +2 -2
- package/dist/collections/Instructions.js.map +1 -1
- package/dist/defaults.d.ts +0 -1
- package/dist/endpoints/fetchFields.d.ts +2 -3
- package/dist/endpoints/fetchFields.js +7 -3
- package/dist/endpoints/fetchFields.js.map +1 -1
- package/dist/endpoints/index.d.ts +0 -1
- package/dist/endpoints/index.js +111 -31
- package/dist/endpoints/index.js.map +1 -1
- package/dist/exports/client.d.ts +1 -1
- package/dist/exports/client.js +1 -0
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/fields.d.ts +0 -1
- package/dist/exports/types.d.ts +2 -3
- package/dist/exports/types.js.map +1 -1
- package/dist/fields/ComposeField/ComposeField.d.ts +10 -2
- package/dist/fields/ComposeField/ComposeField.js +13 -5
- package/dist/fields/ComposeField/ComposeField.js.map +1 -1
- package/dist/fields/LexicalEditor/ComposeFeatureComponent.d.ts +2 -2
- package/dist/fields/LexicalEditor/feature.client.d.ts +2 -3
- package/dist/fields/LexicalEditor/feature.server.d.ts +0 -1
- package/dist/fields/PromptEditorField/PromptEditorField.d.ts +0 -1
- package/dist/fields/PromptEditorField/PromptEditorField.js +1 -1
- package/dist/fields/PromptEditorField/PromptEditorField.js.map +1 -1
- package/dist/fields/PromptEditorField/defaultStyle.d.ts +0 -1
- package/dist/fields/SelectField/SelectField.d.ts +2 -2
- package/dist/fields/SelectField/SelectField.js +15 -4
- package/dist/fields/SelectField/SelectField.js.map +1 -1
- package/dist/index.d.ts +2 -6
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +5 -2
- package/dist/init.js +8 -7
- package/dist/init.js.map +1 -1
- package/dist/libraries/handlebars/asyncHandlebars.d.ts +0 -1
- package/dist/libraries/handlebars/helpers.d.ts +1 -2
- package/dist/libraries/handlebars/helpers.js +6 -1
- package/dist/libraries/handlebars/helpers.js.map +1 -1
- package/dist/libraries/handlebars/helpersMap.d.ts +0 -1
- package/dist/libraries/handlebars/replacePlaceholders.d.ts +0 -1
- package/dist/plugin.d.ts +0 -1
- package/dist/plugin.js +7 -5
- package/dist/plugin.js.map +1 -1
- package/dist/providers/FieldProvider/FieldProvider.d.ts +1 -2
- package/dist/providers/FieldProvider/useFieldProps.d.ts +3 -4
- package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts +2 -12
- package/dist/providers/InstructionsProvider/InstructionsProvider.js +7 -9
- package/dist/providers/InstructionsProvider/InstructionsProvider.js.map +1 -1
- package/dist/providers/InstructionsProvider/context.d.ts +16 -0
- package/dist/providers/InstructionsProvider/context.js +13 -0
- package/dist/providers/InstructionsProvider/context.js.map +1 -0
- package/dist/providers/InstructionsProvider/useInstructions.d.ts +0 -1
- package/dist/providers/InstructionsProvider/useInstructions.js +29 -15
- package/dist/providers/InstructionsProvider/useInstructions.js.map +1 -1
- package/dist/translations/index.d.ts +0 -1
- package/dist/types/handlebars-async-helpers.d.js +2 -0
- package/dist/types/handlebars-async-helpers.d.js.map +1 -0
- package/dist/types/handlebars-dist-handlebars.d.js +2 -0
- package/dist/types/handlebars-dist-handlebars.d.js.map +1 -0
- package/dist/types/react-mentions.d.js +2 -0
- package/dist/types/react-mentions.d.js.map +1 -0
- package/dist/types.d.ts +45 -1
- package/dist/types.js.map +1 -1
- package/dist/ui/Compose/Compose.d.ts +0 -1
- package/dist/ui/Compose/Compose.js +61 -25
- package/dist/ui/Compose/Compose.js.map +1 -1
- package/dist/ui/Compose/UndoRedoActions.d.ts +2 -2
- package/dist/ui/Compose/hooks/menu/Item.d.ts +3 -2
- package/dist/ui/Compose/hooks/menu/Item.js +2 -2
- package/dist/ui/Compose/hooks/menu/Item.js.map +1 -1
- package/dist/ui/Compose/hooks/menu/TranslateMenu.d.ts +8 -5
- package/dist/ui/Compose/hooks/menu/TranslateMenu.js +1 -1
- package/dist/ui/Compose/hooks/menu/TranslateMenu.js.map +1 -1
- package/dist/ui/Compose/hooks/menu/items.d.ts +8 -9
- package/dist/ui/Compose/hooks/menu/itemsMap.d.ts +0 -1
- package/dist/ui/Compose/hooks/menu/useMenu.d.ts +7 -7
- package/dist/ui/Compose/hooks/menu/useMenu.js +12 -9
- package/dist/ui/Compose/hooks/menu/useMenu.js.map +1 -1
- package/dist/ui/Compose/hooks/useGenerate.d.ts +0 -1
- package/dist/ui/Compose/hooks/useGenerate.js +41 -20
- package/dist/ui/Compose/hooks/useGenerate.js.map +1 -1
- package/dist/ui/Compose/hooks/useHistory.d.ts +0 -1
- package/dist/ui/Compose/hooks/useHistory.js +2 -2
- package/dist/ui/Compose/hooks/useHistory.js.map +1 -1
- package/dist/ui/Icons/Icons.d.ts +34 -34
- package/dist/ui/Icons/Icons.js +1 -1
- package/dist/ui/Icons/Icons.js.map +1 -1
- package/dist/ui/Icons/LottieAnimation.d.ts +3 -3
- package/dist/ui/Icons/LottieAnimation.js +1 -0
- package/dist/ui/Icons/LottieAnimation.js.map +1 -1
- package/dist/utilities/editorSchemaValidator.d.ts +1 -2
- package/dist/utilities/editorSchemaValidator.js.map +1 -1
- package/dist/utilities/extractImageData.d.ts +0 -1
- package/dist/utilities/extractPromptAttachments.d.ts +2 -0
- package/dist/utilities/extractPromptAttachments.js +32 -0
- package/dist/utilities/extractPromptAttachments.js.map +1 -0
- package/dist/utilities/getFieldBySchemaPath.d.ts +0 -1
- package/dist/utilities/getFieldBySchemaPath.js +12 -4
- package/dist/utilities/getFieldBySchemaPath.js.map +1 -1
- package/dist/utilities/getFieldInfo.d.ts +1 -2
- package/dist/utilities/getGenerationModels.d.ts +1 -2
- package/dist/utilities/isPluginActivated.d.ts +0 -1
- package/dist/utilities/isPluginActivated.js +1 -1
- package/dist/utilities/isPluginActivated.js.map +1 -1
- package/dist/utilities/lexicalToHTML.d.ts +0 -1
- package/dist/utilities/setSafeLexicalState.d.ts +1 -2
- package/dist/utilities/setSafeLexicalState.js.map +1 -1
- package/dist/utilities/updateFieldsConfig.d.ts +0 -1
- package/dist/utilities/updateFieldsConfig.js +10 -3
- package/dist/utilities/updateFieldsConfig.js.map +1 -1
- package/package.json +104 -65
- package/dist/ai/analyse.d.ts.map +0 -1
- package/dist/ai/models/anthropic/generateRichText.d.ts.map +0 -1
- package/dist/ai/models/anthropic/index.d.ts.map +0 -1
- package/dist/ai/models/elevenLabs/generateVoice.d.ts.map +0 -1
- package/dist/ai/models/elevenLabs/index.d.ts.map +0 -1
- package/dist/ai/models/elevenLabs/voices.d.ts.map +0 -1
- package/dist/ai/models/index.d.ts.map +0 -1
- package/dist/ai/models/openai/generateImage.d.ts.map +0 -1
- package/dist/ai/models/openai/generateRichText.d.ts.map +0 -1
- package/dist/ai/models/openai/generateVoice.d.ts.map +0 -1
- package/dist/ai/models/openai/index.d.ts.map +0 -1
- package/dist/ai/models/openai/openai.d.ts.map +0 -1
- package/dist/ai/prompts.d.ts.map +0 -1
- package/dist/ai/schemas/lexicalJsonSchema.d.ts.map +0 -1
- package/dist/ai/utils/editImagesWithOpenAI.d.ts.map +0 -1
- package/dist/ai/utils/filterEditorSchemaByNodes.d.ts.map +0 -1
- package/dist/ai/utils/generateFileNameByPrompt.d.ts.map +0 -1
- package/dist/ai/utils/isObjectSchema.d.ts.map +0 -1
- package/dist/ai/utils/systemGenerate.d.ts.map +0 -1
- package/dist/collections/Instructions.d.ts.map +0 -1
- package/dist/defaults.d.ts.map +0 -1
- package/dist/endpoints/fetchFields.d.ts.map +0 -1
- package/dist/endpoints/index.d.ts.map +0 -1
- package/dist/exports/client.d.ts.map +0 -1
- package/dist/exports/fields.d.ts.map +0 -1
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/fields/ComposeField/ComposeField.d.ts.map +0 -1
- package/dist/fields/LexicalEditor/ComposeFeatureComponent.d.ts.map +0 -1
- package/dist/fields/LexicalEditor/feature.client.d.ts.map +0 -1
- package/dist/fields/LexicalEditor/feature.server.d.ts.map +0 -1
- package/dist/fields/PromptEditorField/PromptEditorField.d.ts.map +0 -1
- package/dist/fields/PromptEditorField/defaultStyle.d.ts.map +0 -1
- package/dist/fields/SelectField/SelectField.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/init.d.ts.map +0 -1
- package/dist/libraries/handlebars/asyncHandlebars.d.ts.map +0 -1
- package/dist/libraries/handlebars/helpers.d.ts.map +0 -1
- package/dist/libraries/handlebars/helpersMap.d.ts.map +0 -1
- package/dist/libraries/handlebars/replacePlaceholders.d.ts.map +0 -1
- package/dist/plugin.d.ts.map +0 -1
- package/dist/providers/FieldProvider/FieldProvider.d.ts.map +0 -1
- package/dist/providers/FieldProvider/useFieldProps.d.ts.map +0 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts.map +0 -1
- package/dist/providers/InstructionsProvider/useInstructions.d.ts.map +0 -1
- package/dist/translations/index.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/ui/Compose/Compose.d.ts.map +0 -1
- package/dist/ui/Compose/UndoRedoActions.d.ts.map +0 -1
- package/dist/ui/Compose/hooks/menu/Item.d.ts.map +0 -1
- package/dist/ui/Compose/hooks/menu/TranslateMenu.d.ts.map +0 -1
- package/dist/ui/Compose/hooks/menu/items.d.ts.map +0 -1
- package/dist/ui/Compose/hooks/menu/itemsMap.d.ts.map +0 -1
- package/dist/ui/Compose/hooks/menu/useMenu.d.ts.map +0 -1
- package/dist/ui/Compose/hooks/useGenerate.d.ts.map +0 -1
- package/dist/ui/Compose/hooks/useHistory.d.ts.map +0 -1
- package/dist/ui/Icons/Icons.d.ts.map +0 -1
- package/dist/ui/Icons/LottieAnimation.d.ts.map +0 -1
- package/dist/utilities/editorSchemaValidator.d.ts.map +0 -1
- package/dist/utilities/extractImageData.d.ts.map +0 -1
- package/dist/utilities/getFieldBySchemaPath.d.ts.map +0 -1
- package/dist/utilities/getFieldInfo.d.ts.map +0 -1
- package/dist/utilities/getGenerationModels.d.ts.map +0 -1
- package/dist/utilities/isPluginActivated.d.ts.map +0 -1
- package/dist/utilities/lexicalToHTML.d.ts.map +0 -1
- package/dist/utilities/setSafeLexicalState.d.ts.map +0 -1
- package/dist/utilities/updateFieldsConfig.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ai/utils/generateFileNameByPrompt.ts"],"sourcesContent":["export function generateFileNameByPrompt(prompt) {\n // Helper function to get a random integer between min and max (inclusive)\n function getRandomInt(min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min\n }\n\n // Define the desired length of the filename part from the prompt\n const maxLength = 30\n const promptLength = prompt.length\n\n // Determine the start position for the random substring\n const startPos = getRandomInt(0, Math.max(0, promptLength - maxLength))\n\n // Get the random substring and truncate it if necessary\n let randomSubstring = prompt.substring(startPos, startPos + maxLength)\n\n // Replace invalid filename characters with an underscore\n randomSubstring = randomSubstring.replace(/[^a-z\\d]/gi, '_').toLowerCase()\n\n // Add a timestamp for uniqueness\n const timestamp = new Date().toISOString().replace(/[:.-]/g, '')\n\n // Combine the truncated prompt and timestamp to form the filename\n return `${randomSubstring}_${timestamp}`\n}\n"],"names":["generateFileNameByPrompt","prompt","getRandomInt","min","max","Math","floor","random","maxLength","promptLength","length","startPos","randomSubstring","substring","replace","toLowerCase","timestamp","Date","toISOString"],"mappings":"AAAA,OAAO,SAASA,yBAAyBC,
|
|
1
|
+
{"version":3,"sources":["../../../src/ai/utils/generateFileNameByPrompt.ts"],"sourcesContent":["export function generateFileNameByPrompt(prompt: string) {\n // Helper function to get a random integer between min and max (inclusive)\n function getRandomInt(min: number, max: number) {\n return Math.floor(Math.random() * (max - min + 1)) + min\n }\n\n // Define the desired length of the filename part from the prompt\n const maxLength = 30\n const promptLength = prompt.length\n\n // Determine the start position for the random substring\n const startPos = getRandomInt(0, Math.max(0, promptLength - maxLength))\n\n // Get the random substring and truncate it if necessary\n let randomSubstring = prompt.substring(startPos, startPos + maxLength)\n\n // Replace invalid filename characters with an underscore\n randomSubstring = randomSubstring.replace(/[^a-z\\d]/gi, '_').toLowerCase()\n\n // Add a timestamp for uniqueness\n const timestamp = new Date().toISOString().replace(/[:.-]/g, '')\n\n // Combine the truncated prompt and timestamp to form the filename\n return `${randomSubstring}_${timestamp}`\n}\n"],"names":["generateFileNameByPrompt","prompt","getRandomInt","min","max","Math","floor","random","maxLength","promptLength","length","startPos","randomSubstring","substring","replace","toLowerCase","timestamp","Date","toISOString"],"mappings":"AAAA,OAAO,SAASA,yBAAyBC,MAAc;IACrD,0EAA0E;IAC1E,SAASC,aAAaC,GAAW,EAAEC,GAAW;QAC5C,OAAOC,KAAKC,KAAK,CAACD,KAAKE,MAAM,KAAMH,CAAAA,MAAMD,MAAM,CAAA,KAAMA;IACvD;IAEA,iEAAiE;IACjE,MAAMK,YAAY;IAClB,MAAMC,eAAeR,OAAOS,MAAM;IAElC,wDAAwD;IACxD,MAAMC,WAAWT,aAAa,GAAGG,KAAKD,GAAG,CAAC,GAAGK,eAAeD;IAE5D,wDAAwD;IACxD,IAAII,kBAAkBX,OAAOY,SAAS,CAACF,UAAUA,WAAWH;IAE5D,yDAAyD;IACzDI,kBAAkBA,gBAAgBE,OAAO,CAAC,cAAc,KAAKC,WAAW;IAExE,iCAAiC;IACjC,MAAMC,YAAY,IAAIC,OAAOC,WAAW,GAAGJ,OAAO,CAAC,UAAU;IAE7D,kEAAkE;IAClE,OAAO,GAAGF,gBAAgB,CAAC,EAAEI,WAAW;AAC1C"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { CollectionConfig } from 'payload';
|
|
2
2
|
import type { PluginConfig } from 'src/types.js';
|
|
3
3
|
export declare const instructionsCollection: (pluginConfig: PluginConfig, options?: Partial<CollectionConfig>) => CollectionConfig;
|
|
4
|
-
//# sourceMappingURL=Instructions.d.ts.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js';
|
|
2
2
|
import { getGenerationModels } from '../utilities/getGenerationModels.js';
|
|
3
|
-
const groupSettings = (pluginConfig)=>getGenerationModels(pluginConfig).reduce((fields, model)=>{
|
|
3
|
+
const groupSettings = (pluginConfig)=>(getGenerationModels(pluginConfig) ?? []).reduce((fields, model)=>{
|
|
4
4
|
if (model.settings) {
|
|
5
5
|
fields.push(model.settings);
|
|
6
6
|
}
|
|
7
7
|
return fields;
|
|
8
8
|
}, []);
|
|
9
|
-
const modelOptions = (pluginConfig)=>getGenerationModels(pluginConfig).map((model)=>{
|
|
9
|
+
const modelOptions = (pluginConfig)=>(getGenerationModels(pluginConfig) ?? []).map((model)=>{
|
|
10
10
|
return {
|
|
11
11
|
fields: model.fields,
|
|
12
12
|
label: model.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/Instructions.ts"],"sourcesContent":["import type { CollectionConfig, GroupField } from 'payload'\nimport type { PluginConfig } from 'src/types.js'\n\nimport { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\nimport { getGenerationModels } from '../utilities/getGenerationModels.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: ({ req }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n delete: ({ req }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n read: ({ req }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n update: ({ req }) => {\n if (!req.user) {\n return false\n }\n return true\n },\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 description:\n 'Define dynamic templates using {{ fieldName }}. Type { to see available field suggestions.',\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 admin: {\n condition: (_, current) => {\n return current['field-type'] === 'upload' && current['model-id'] === 'gpt-image-1'\n },\n },\n description:\n 'These images will be used to generate new visuals in a similar style, layout, or content. You can combine multiple references for more controlled results.',\n fields: [\n {\n name: 'images',\n type: 'array',\n fields: [\n {\n name: 'image',\n type: 'upload',\n admin: {\n description: 'Please make sure the image is publicly accessible.',\n },\n relationTo: pluginConfig.uploadCollectionSlug\n ? pluginConfig.uploadCollectionSlug\n : 'media',\n },\n ],\n },\n ],\n label: 'Sample Images',\n },\n {\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'richText'\n },\n },\n description: '',\n fields: [\n {\n name: 'system',\n type: 'textarea',\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 admin: {\n condition: (_, current) => {\n return current['field-type'] === 'richText'\n },\n },\n description: '',\n fields: [\n {\n /** TODO:\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":["PLUGIN_INSTRUCTIONS_TABLE","getGenerationModels","groupSettings","pluginConfig","reduce","fields","model","settings","push","modelOptions","map","label","name","value","id","defaultAccessConfig","create","req","user","delete","read","update","defaultAdminConfig","group","hidden","instructionsCollection","options","slug","access","admin","type","description","unique","defaultValue","condition","_","current","components","Field","clientProps","filterByField","path","option","tabs","relationTo","uploadCollectionSlug","labels","plural","singular"],"mappings":"AAGA,SAASA,yBAAyB,QAAQ,iBAAgB;AAC1D,SAASC,mBAAmB,QAAQ,sCAAqC;AAEzE,MAAMC,gBAAgB,CAACC,eACrBF,oBAAoBE,cAAcC,MAAM,CAAC,CAACC,QAAQC;QAChD,IAAIA,MAAMC,QAAQ,EAAE;YAClBF,OAAOG,IAAI,CAACF,MAAMC,QAAQ;QAC5B;QACA,OAAOF;IACT,GAAG,EAAE;AAEP,MAAMI,eAAe,CAACN,eACpBF,oBAAoBE,cAAcO,GAAG,CAAC,CAACJ;QACrC,OAAO;YACLD,QAAQC,MAAMD,MAAM;YACpBM,OAAOL,MAAMM,IAAI;YACjBC,OAAOP,MAAMQ,EAAE;QACjB;IACF;AAEF,MAAMC,sBAAsB;IAC1BC,QAAQ,CAAC,EAAEC,GAAG,EAAE;QACd,IAAI,CAACA,IAAIC,IAAI,EAAE;YACb,OAAO;QACT;QACA,OAAO;IACT;IACAC,QAAQ,CAAC,EAAEF,GAAG,EAAE;QACd,IAAI,CAACA,IAAIC,IAAI,EAAE;YACb,OAAO;QACT;QACA,OAAO;IACT;IACAE,MAAM,CAAC,EAAEH,GAAG,EAAE;QACZ,IAAI,CAACA,IAAIC,IAAI,EAAE;YACb,OAAO;QACT;QACA,OAAO;IACT;IACAG,QAAQ,CAAC,EAAEJ,GAAG,EAAE;QACd,IAAI,CAACA,IAAIC,IAAI,EAAE;YACb,OAAO;QACT;QACA,OAAO;IACT;AACF;AAEA,MAAMI,qBAAqB;IACzBC,OAAO;IACPC,QAAQ;AACV;AAEA,OAAO,MAAMC,yBAAyB,CACpCtB,cACAuB,UAEkB,CAAA;QAChBC,MAAM3B;QACN4B,QAAQ;YACN,GAAGb,mBAAmB;YACtB,GAAGW,SAASE,MAAM;QACpB;QACAC,OAAO;YACL,GAAGP,kBAAkB;YACrB,GAAGI,SAASG,KAAK;YACjBN,OAAO;QACT;QACAlB,QAAQ;YACN;gBACEO,MAAM;gBACNkB,MAAM;gBACND,OAAO;oBACLE,aAAa;gBACf;gBACAC,QAAQ;YACV;YACA;gBACEpB,MAAM;gBACNkB,MAAM;gBACND,OAAO;oBACLE,aAAa;gBACf;gBACAE,cAAc;gBACdtB,OAAO;gBACPe,SAAS;oBACP;wBACEf,OAAO;wBACPE,OAAO;oBACT;oBACA;wBACEF,OAAO;wBACPE,OAAO;oBACT;oBACA;wBACEF,OAAO;wBACPE,OAAO;oBACT;oBACA;wBACEF,OAAO;wBACPE,OAAO;oBACT;iBACD;YACH;YACA;gBACED,MAAM;gBACNkB,MAAM;gBACND,OAAO;oBACLK,WAAW,CAACC,GAAGC;wBACb,OAAOA,OAAO,CAAC,aAAa,KAAK;oBACnC;gBACF;gBACAzB,OAAO;YACT;YACA;gBACEC,MAAM;gBACNkB,MAAM;gBACND,OAAO;oBACLQ,YAAY;wBACVC,OAAO;4BACLC,aAAa;gCACXC,eAAe;gCACfd,SAASjB,aAAaN;4BACxB;4BACAsC,MAAM;wBACR;oBACF;gBACF;gBACA9B,OAAO;gBACPe,SAASjB,aAAaN,cAAcO,GAAG,CAAC,CAACgC;oBACvC,OAAO;wBACL/B,OAAO+B,OAAO/B,KAAK;wBACnBE,OAAO6B,OAAO7B,KAAK;oBACrB;gBACF;YACF;YACA;gBACEC,IAAI;gBACJgB,MAAM;gBACNa,MAAM;oBACJ;wBACEZ,aACE;wBACF1B,QAAQ;4BACN;gCACEO,MAAM;gCACNkB,MAAM;gCACND,OAAO;oCACLQ,YAAY;wCACVC,OAAO;oCACT;oCACAP,aAAa;gCACf;gCACApB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;oBACA;wBACEkB,OAAO;4BACLK,WAAW,CAACC,GAAGC;gCACb,OAAOA,OAAO,CAAC,aAAa,KAAK,YAAYA,OAAO,CAAC,WAAW,KAAK;4BACvE;wBACF;wBACAL,aACE;wBACF1B,QAAQ;4BACN;gCACEO,MAAM;gCACNkB,MAAM;gCACNzB,QAAQ;oCACN;wCACEO,MAAM;wCACNkB,MAAM;wCACND,OAAO;4CACLE,aAAa;wCACf;wCACAa,YAAYzC,aAAa0C,oBAAoB,GACzC1C,aAAa0C,oBAAoB,GACjC;oCACN;iCACD;4BACH;yBACD;wBACDlC,OAAO;oBACT;oBACA;wBACEkB,OAAO;4BACLK,WAAW,CAACC,GAAGC;gCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;4BACnC;wBACF;wBACAL,aAAa;wBACb1B,QAAQ;4BACN;gCACEO,MAAM;gCACNkB,MAAM;gCACNG,cAAc,CAAC;;;;yEAI0C,CAAC;gCAC1DtB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;oBACA;wBACEkB,OAAO;4BACLK,WAAW,CAACC,GAAGC;gCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;4BACnC;wBACF;wBACAL,aAAa;wBACb1B,QAAQ;4BACN;gCACE;;;;iBAIC,GAJD;;;;iBAIC,GACDO,MAAM;gCACNkB,MAAM;gCACND,OAAO;oCACLK,WAAW,CAACC,GAAGC;wCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;oCACnC;gCACF;gCACAH,cAAc,CAAC;;;;;;;2HAO4F,CAAC;gCAC5GtB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;iBACD;YACH;eACGT,cAAcC;SAClB;QACD2C,QAAQ;YACNC,QAAQ;YACRC,UAAU;QACZ;IACF,CAAA,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/collections/Instructions.ts"],"sourcesContent":["import type { CollectionConfig, GroupField } from 'payload'\nimport type { PluginConfig } from 'src/types.js'\n\nimport { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\nimport { getGenerationModels } from '../utilities/getGenerationModels.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: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n delete: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n read: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n update: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\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 description:\n 'Define dynamic templates using {{ fieldName }}. Type { to see available field suggestions.',\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 admin: {\n condition: (_, current) => {\n return current['field-type'] === 'upload' && current['model-id'] === 'gpt-image-1'\n },\n },\n description:\n 'These images will be used to generate new visuals in a similar style, layout, or content. You can combine multiple references for more controlled results.',\n fields: [\n {\n name: 'images',\n type: 'array',\n fields: [\n {\n name: 'image',\n type: 'upload',\n admin: {\n description: 'Please make sure the image is publicly accessible.',\n },\n relationTo: pluginConfig.uploadCollectionSlug\n ? pluginConfig.uploadCollectionSlug\n : 'media',\n },\n ],\n },\n ],\n label: 'Sample Images',\n },\n {\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'richText'\n },\n },\n description: '',\n fields: [\n {\n name: 'system',\n type: 'textarea',\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 admin: {\n condition: (_, current) => {\n return current['field-type'] === 'richText'\n },\n },\n description: '',\n fields: [\n {\n /** TODO:\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":["PLUGIN_INSTRUCTIONS_TABLE","getGenerationModels","groupSettings","pluginConfig","reduce","fields","model","settings","push","modelOptions","map","label","name","value","id","defaultAccessConfig","create","req","user","delete","read","update","defaultAdminConfig","group","hidden","instructionsCollection","options","slug","access","admin","type","description","unique","defaultValue","condition","_","current","components","Field","clientProps","filterByField","path","option","tabs","relationTo","uploadCollectionSlug","labels","plural","singular"],"mappings":"AAGA,SAASA,yBAAyB,QAAQ,iBAAgB;AAC1D,SAASC,mBAAmB,QAAQ,sCAAqC;AAEzE,MAAMC,gBAAgB,CAACC,eACrB,AAACF,CAAAA,oBAAoBE,iBAAiB,EAAE,AAAD,EAAGC,MAAM,CAAC,CAACC,QAAQC;QACxD,IAAIA,MAAMC,QAAQ,EAAE;YAClBF,OAAOG,IAAI,CAACF,MAAMC,QAAQ;QAC5B;QACA,OAAOF;IACT,GAAG,EAAE;AAEP,MAAMI,eAAe,CAACN,eACpB,AAACF,CAAAA,oBAAoBE,iBAAiB,EAAE,AAAD,EAAGO,GAAG,CAAC,CAACJ;QAC7C,OAAO;YACLD,QAAQC,MAAMD,MAAM;YACpBM,OAAOL,MAAMM,IAAI;YACjBC,OAAOP,MAAMQ,EAAE;QACjB;IACF;AAEF,MAAMC,sBAAsB;IAC1BC,QAAQ,CAAC,EAAEC,GAAG,EA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AAQ;4BACN;gCACE;;;;iBAIC,GAJD;;;;iBAIC,GACDO,MAAM;gCACNkB,MAAM;gCACND,OAAO;oCACLK,WAAW,CAACC,GAAGC;wCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;oCACnC;gCACF;gCACAH,cAAc,CAAC;;;;;;;2HAO4F,CAAC;gCAC5GtB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;iBACD;YACH;eACGT,cAAcC;SAClB;QACD2C,QAAQ;YACNC,QAAQ;YACRC,UAAU;QACZ;IACF,CAAA,EAAC"}
|
package/dist/defaults.d.ts
CHANGED
|
@@ -7,4 +7,3 @@ export declare const PLUGIN_API_ENDPOINT_GENERATE_UPLOAD = "/plugin-ai/generate/
|
|
|
7
7
|
export declare const PLUGIN_FETCH_FIELDS_ENDPOINT = "/plugin-ai/fetch-fields";
|
|
8
8
|
export declare const PLUGIN_DEFAULT_OPENAI_MODEL = "gpt-4o-mini";
|
|
9
9
|
export declare const PLUGIN_DEFAULT_ANTHROPIC_MODEL = "claude-3-5-sonnet-latest";
|
|
10
|
-
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { Endpoint } from 'payload';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const fetchFields: (
|
|
4
|
-
//# sourceMappingURL=fetchFields.d.ts.map
|
|
2
|
+
import type { PluginConfig } from '../types.js';
|
|
3
|
+
export declare const fetchFields: (config: PluginConfig) => Endpoint;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PLUGIN_FETCH_FIELDS_ENDPOINT, PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js';
|
|
2
|
-
export const fetchFields = (
|
|
2
|
+
export const fetchFields = (config)=>{
|
|
3
|
+
const { access, options = {}, promptFields = [] } = config;
|
|
3
4
|
return {
|
|
4
5
|
handler: async (req)=>{
|
|
5
6
|
const { docs = [] } = await req.payload.find({
|
|
@@ -14,7 +15,7 @@ export const fetchFields = (access, options = {})=>{
|
|
|
14
15
|
req
|
|
15
16
|
});
|
|
16
17
|
} catch (e) {
|
|
17
|
-
req.payload.logger.error('Please check your "access.settings" for request
|
|
18
|
+
req.payload.logger.error(req, 'Please check your "access.settings" for request');
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
const fieldMap = {};
|
|
@@ -27,7 +28,10 @@ export const fetchFields = (access, options = {})=>{
|
|
|
27
28
|
return Response.json({
|
|
28
29
|
...options,
|
|
29
30
|
fields: fieldMap,
|
|
30
|
-
isConfigAllowed
|
|
31
|
+
isConfigAllowed,
|
|
32
|
+
promptFields: promptFields.map(({ getter: _getter, ...field })=>{
|
|
33
|
+
return field;
|
|
34
|
+
})
|
|
31
35
|
});
|
|
32
36
|
},
|
|
33
37
|
method: 'get',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/fetchFields.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload'\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/fetchFields.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload'\n\nimport type { PluginConfig, SerializedPromptField } from '../types.js'\n\nimport { PLUGIN_FETCH_FIELDS_ENDPOINT, PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\n\nexport const fetchFields: (config: PluginConfig) => Endpoint = (\n config\n) => {\n const {access, options = {}, promptFields = []} = config\n return {\n handler: async (req: PayloadRequest) => {\n const { docs = [] } = await req.payload.find({\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n pagination: false,\n })\n\n let isConfigAllowed = true // Users allowed to update prompts by default\n\n if (access?.settings) {\n try {\n isConfigAllowed = await access.settings({ req })\n } catch (e) {\n req.payload.logger.error(req, 'Please check your \"access.settings\" for request')\n }\n }\n\n const fieldMap: Record<string, { fieldType: any; id: any }> = {}\n docs.forEach((doc) => {\n fieldMap[doc['schema-path']] = {\n id: doc.id,\n fieldType: doc['field-type'],\n }\n })\n\n return Response.json({\n ...options,\n fields: fieldMap,\n isConfigAllowed,\n promptFields: promptFields.map(({getter: _getter, ...field}): SerializedPromptField => {\n return field\n }),\n })\n },\n method: 'get',\n path: PLUGIN_FETCH_FIELDS_ENDPOINT,\n }\n}\n"],"names":["PLUGIN_FETCH_FIELDS_ENDPOINT","PLUGIN_INSTRUCTIONS_TABLE","fetchFields","config","access","options","promptFields","handler","req","docs","payload","find","collection","pagination","isConfigAllowed","settings","e","logger","error","fieldMap","forEach","doc","id","fieldType","Response","json","fields","map","getter","_getter","field","method","path"],"mappings":"AAIA,SAASA,4BAA4B,EAAEC,yBAAyB,QAAQ,iBAAgB;AAExF,OAAO,MAAMC,cAAkD,CAC7DC;IAEA,MAAM,EAACC,MAAM,EAAEC,UAAU,CAAC,CAAC,EAAEC,eAAe,EAAE,EAAC,GAAGH;IAClD,OAAO;QACLI,SAAS,OAAOC;YACd,MAAM,EAAEC,OAAO,EAAE,EAAE,GAAG,MAAMD,IAAIE,OAAO,CAACC,IAAI,CAAC;gBAC3CC,YAAYX;gBACZY,YAAY;YACd;YAEA,IAAIC,kBAAkB,KAAK,6CAA6C;;YAExE,IAAIV,QAAQW,UAAU;gBACpB,IAAI;oBACFD,kBAAkB,MAAMV,OAAOW,QAAQ,CAAC;wBAAEP;oBAAI;gBAChD,EAAE,OAAOQ,GAAG;oBACVR,IAAIE,OAAO,CAACO,MAAM,CAACC,KAAK,CAACV,KAAK;gBAChC;YACF;YAEA,MAAMW,WAAwD,CAAC;YAC/DV,KAAKW,OAAO,CAAC,CAACC;gBACZF,QAAQ,CAACE,GAAG,CAAC,cAAc,CAAC,GAAG;oBAC7BC,IAAID,IAAIC,EAAE;oBACVC,WAAWF,GAAG,CAAC,aAAa;gBAC9B;YACF;YAEA,OAAOG,SAASC,IAAI,CAAC;gBACnB,GAAGpB,OAAO;gBACVqB,QAAQP;gBACRL;gBACAR,cAAcA,aAAaqB,GAAG,CAAC,CAAC,EAACC,QAAQC,OAAO,EAAE,GAAGC,OAAM;oBACzD,OAAOA;gBACT;YACF;QACF;QACAC,QAAQ;QACRC,MAAMhC;IACR;AACF,EAAC"}
|
package/dist/endpoints/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import * as process from 'node:process';
|
|
|
2
2
|
import { defaultPrompts } from '../ai/prompts.js';
|
|
3
3
|
import { filterEditorSchemaByNodes } from '../ai/utils/filterEditorSchemaByNodes.js';
|
|
4
4
|
import { PLUGIN_API_ENDPOINT_GENERATE, PLUGIN_API_ENDPOINT_GENERATE_UPLOAD, PLUGIN_INSTRUCTIONS_TABLE, PLUGIN_NAME } from '../defaults.js';
|
|
5
|
+
import { asyncHandlebars } from '../libraries/handlebars/asyncHandlebars.js';
|
|
5
6
|
import { registerEditorHelper } from '../libraries/handlebars/helpers.js';
|
|
6
7
|
import { handlebarsHelpersMap } from '../libraries/handlebars/helpersMap.js';
|
|
7
8
|
import { replacePlaceholders } from '../libraries/handlebars/replacePlaceholders.js';
|
|
@@ -25,8 +26,51 @@ const checkAccess = async (req, pluginConfig)=>{
|
|
|
25
26
|
}
|
|
26
27
|
return true;
|
|
27
28
|
};
|
|
28
|
-
const
|
|
29
|
-
const
|
|
29
|
+
const extendContextWithPromptFields = (data, ctx, pluginConfig)=>{
|
|
30
|
+
const { promptFields = [] } = pluginConfig;
|
|
31
|
+
const fieldsMap = new Map(promptFields.filter((f)=>!f.collections || f.collections.includes(ctx.collection)).map((f)=>[
|
|
32
|
+
f.name,
|
|
33
|
+
f
|
|
34
|
+
]));
|
|
35
|
+
return new Proxy(data, {
|
|
36
|
+
get: (target, prop)=>{
|
|
37
|
+
const field = fieldsMap.get(prop);
|
|
38
|
+
if (field?.getter) {
|
|
39
|
+
const value = field.getter(data, ctx);
|
|
40
|
+
return Promise.resolve(value).then((v)=>new asyncHandlebars.SafeString(v));
|
|
41
|
+
}
|
|
42
|
+
// {{prop}} escapes content by default. Here we make sure it won't be escaped.
|
|
43
|
+
const value = typeof target === "object" ? target[prop] : undefined;
|
|
44
|
+
return typeof value === 'string' ? new asyncHandlebars.SafeString(value) : value;
|
|
45
|
+
},
|
|
46
|
+
// It's used by the handlebars library to determine if the property is enumerable
|
|
47
|
+
getOwnPropertyDescriptor: (target, prop)=>{
|
|
48
|
+
const field = fieldsMap.get(prop);
|
|
49
|
+
if (field) {
|
|
50
|
+
return {
|
|
51
|
+
configurable: true,
|
|
52
|
+
enumerable: true
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
56
|
+
},
|
|
57
|
+
has: (target, prop)=>{
|
|
58
|
+
return fieldsMap.has(prop) || prop in target;
|
|
59
|
+
},
|
|
60
|
+
ownKeys: (target)=>{
|
|
61
|
+
return [
|
|
62
|
+
...fieldsMap.keys(),
|
|
63
|
+
...Object.keys(target)
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const assignPrompt = async (action, { type, actionParams, collection, context, field, layout, locale, pluginConfig, systemPrompt = '', template })=>{
|
|
69
|
+
const extendedContext = extendContextWithPromptFields(context, {
|
|
70
|
+
type,
|
|
71
|
+
collection
|
|
72
|
+
}, pluginConfig);
|
|
73
|
+
const prompt = await replacePlaceholders(template, extendedContext);
|
|
30
74
|
const toLexicalHTML = type === 'richText' ? handlebarsHelpersMap.toHTML.name : '';
|
|
31
75
|
const assignedPrompts = {
|
|
32
76
|
layout: type === 'richText' ? layout : undefined,
|
|
@@ -47,20 +91,26 @@ const assignPrompt = async (action, { type, actionParams, context, field, layout
|
|
|
47
91
|
}
|
|
48
92
|
return assignedPrompts;
|
|
49
93
|
}
|
|
50
|
-
const
|
|
94
|
+
const prompts = [
|
|
95
|
+
...pluginConfig.prompts || [],
|
|
96
|
+
...defaultPrompts
|
|
97
|
+
];
|
|
98
|
+
const foundPrompt = prompts.find((p)=>p.name === action);
|
|
99
|
+
const getLayout = foundPrompt?.layout;
|
|
100
|
+
const getSystemPrompt = foundPrompt?.system;
|
|
51
101
|
let updatedLayout = layout;
|
|
52
102
|
if (getLayout) {
|
|
53
103
|
updatedLayout = getLayout();
|
|
54
104
|
}
|
|
55
|
-
const system = getSystemPrompt({
|
|
105
|
+
const system = getSystemPrompt ? getSystemPrompt({
|
|
56
106
|
...actionParams || {},
|
|
57
107
|
prompt,
|
|
58
108
|
systemPrompt
|
|
59
|
-
});
|
|
109
|
+
}) : '';
|
|
60
110
|
return {
|
|
61
111
|
layout: updatedLayout,
|
|
62
112
|
// TODO: revisit this toLexicalHTML
|
|
63
|
-
prompt: await replacePlaceholders(`{{${toLexicalHTML} ${field}}}`,
|
|
113
|
+
prompt: await replacePlaceholders(`{{${toLexicalHTML} ${field}}}`, extendedContext),
|
|
64
114
|
system
|
|
65
115
|
};
|
|
66
116
|
};
|
|
@@ -76,7 +126,7 @@ export const endpoints = (pluginConfig)=>({
|
|
|
76
126
|
const { action, actionParams, instructionId } = options;
|
|
77
127
|
const contextData = data.doc;
|
|
78
128
|
if (!instructionId) {
|
|
79
|
-
throw new Error(`Instruction ID is required for "${PLUGIN_NAME}" to work, please check your configuration`);
|
|
129
|
+
throw new Error(`Instruction ID is required for "${PLUGIN_NAME}" to work, please check your configuration, or try again`);
|
|
80
130
|
}
|
|
81
131
|
// Verify user has access to the specific instruction
|
|
82
132
|
const instructions = await req.payload.findByID({
|
|
@@ -86,6 +136,9 @@ export const endpoints = (pluginConfig)=>({
|
|
|
86
136
|
});
|
|
87
137
|
const { collections } = req.payload.config;
|
|
88
138
|
const collection = collections.find((collection)=>collection.slug === PLUGIN_INSTRUCTIONS_TABLE);
|
|
139
|
+
if (!collection) {
|
|
140
|
+
throw new Error('Collection not found');
|
|
141
|
+
}
|
|
89
142
|
const { custom: { [PLUGIN_NAME]: { editorConfig = {} } = {} } = {} } = collection.admin;
|
|
90
143
|
const { schema: editorSchema = {} } = editorConfig;
|
|
91
144
|
const { prompt: promptTemplate = '' } = instructions;
|
|
@@ -94,30 +147,44 @@ export const endpoints = (pluginConfig)=>({
|
|
|
94
147
|
allowedEditorSchema = filterEditorSchemaByNodes(editorSchema, allowedEditorNodes);
|
|
95
148
|
}
|
|
96
149
|
const schemaPath = instructions['schema-path'];
|
|
97
|
-
const fieldName = schemaPath?.split('.')
|
|
150
|
+
const [collectionName, fieldName] = schemaPath?.split('.') || [];
|
|
98
151
|
registerEditorHelper(req.payload, schemaPath);
|
|
99
152
|
const { defaultLocale, locales = [] } = req.payload.config.localization || {};
|
|
100
153
|
const localeData = locales.find((l)=>{
|
|
101
154
|
return l.code === locale;
|
|
102
155
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
156
|
+
let localeInfo = locale;
|
|
157
|
+
if (localeData && defaultLocale && localeData.label && typeof localeData.label === 'object' && defaultLocale in localeData.label) {
|
|
158
|
+
localeInfo = localeData.label[defaultLocale];
|
|
159
|
+
}
|
|
160
|
+
const models = getGenerationModels(pluginConfig);
|
|
161
|
+
const model = models && Array.isArray(models) ? models.find((model)=>model.id === instructions['model-id']) : undefined;
|
|
162
|
+
if (!model) {
|
|
163
|
+
throw new Error('Model not found');
|
|
164
|
+
}
|
|
165
|
+
// @ts-ignore
|
|
166
|
+
const settingsName = model && model.settings ? model.settings.name : undefined;
|
|
107
167
|
if (!settingsName) {
|
|
108
168
|
req.payload.logger.error('— AI Plugin: Error fetching settings name!');
|
|
109
169
|
}
|
|
110
|
-
const modelOptions = instructions[settingsName] || {};
|
|
170
|
+
const modelOptions = settingsName ? instructions[settingsName] || {} : {};
|
|
111
171
|
const prompts = await assignPrompt(action, {
|
|
112
|
-
type: instructions['field-type'],
|
|
172
|
+
type: String(instructions['field-type']),
|
|
113
173
|
actionParams,
|
|
174
|
+
collection: collectionName,
|
|
114
175
|
context: contextData,
|
|
115
|
-
field: fieldName,
|
|
176
|
+
field: fieldName || '',
|
|
116
177
|
layout: instructions.layout,
|
|
117
178
|
locale: localeInfo,
|
|
179
|
+
pluginConfig,
|
|
118
180
|
systemPrompt: instructions.system,
|
|
119
|
-
template: promptTemplate
|
|
181
|
+
template: String(promptTemplate)
|
|
120
182
|
});
|
|
183
|
+
if (pluginConfig.debugging) {
|
|
184
|
+
req.payload.logger.info({
|
|
185
|
+
prompts
|
|
186
|
+
}, `— AI Plugin: Executing text prompt on ${schemaPath} using ${model.id}`);
|
|
187
|
+
}
|
|
121
188
|
return model.handler?.(prompts.prompt, {
|
|
122
189
|
...modelOptions,
|
|
123
190
|
editorSchema: allowedEditorSchema,
|
|
@@ -126,14 +193,15 @@ export const endpoints = (pluginConfig)=>({
|
|
|
126
193
|
system: prompts.system
|
|
127
194
|
});
|
|
128
195
|
} catch (error) {
|
|
129
|
-
req.payload.logger.error('Error generating content: '
|
|
196
|
+
req.payload.logger.error(error, 'Error generating content: ');
|
|
197
|
+
const message = error && typeof error === 'object' && 'message' in error ? error.message : String(error);
|
|
130
198
|
return new Response(JSON.stringify({
|
|
131
|
-
error:
|
|
199
|
+
error: message
|
|
132
200
|
}), {
|
|
133
201
|
headers: {
|
|
134
202
|
'Content-Type': 'application/json'
|
|
135
203
|
},
|
|
136
|
-
status:
|
|
204
|
+
status: message.includes('Authentication required') || message.includes('Insufficient permissions') ? 401 : 500
|
|
137
205
|
});
|
|
138
206
|
}
|
|
139
207
|
},
|
|
@@ -158,7 +226,7 @@ export const endpoints = (pluginConfig)=>({
|
|
|
158
226
|
req
|
|
159
227
|
});
|
|
160
228
|
} catch (e) {
|
|
161
|
-
req.payload.logger.error('— AI Plugin: Error fetching document, you should try again after enabling drafts for this collection');
|
|
229
|
+
req.payload.logger.error(e, '— AI Plugin: Error fetching document, you should try again after enabling drafts for this collection');
|
|
162
230
|
}
|
|
163
231
|
}
|
|
164
232
|
const contextData = {
|
|
@@ -172,7 +240,6 @@ export const endpoints = (pluginConfig)=>({
|
|
|
172
240
|
};
|
|
173
241
|
if (instructionId) {
|
|
174
242
|
// Verify user has access to the specific instruction
|
|
175
|
-
// @ts-expect-error
|
|
176
243
|
instructions = await req.payload.findByID({
|
|
177
244
|
id: instructionId,
|
|
178
245
|
collection: PLUGIN_INSTRUCTIONS_TABLE,
|
|
@@ -182,7 +249,11 @@ export const endpoints = (pluginConfig)=>({
|
|
|
182
249
|
const { images: sampleImages = [], prompt: promptTemplate = '' } = instructions;
|
|
183
250
|
const schemaPath = instructions['schema-path'];
|
|
184
251
|
registerEditorHelper(req.payload, schemaPath);
|
|
185
|
-
const
|
|
252
|
+
const extendedContext = extendContextWithPromptFields(contextData, {
|
|
253
|
+
type: instructions['field-type'],
|
|
254
|
+
collection: collectionSlug
|
|
255
|
+
}, pluginConfig);
|
|
256
|
+
const text = await replacePlaceholders(promptTemplate, extendedContext);
|
|
186
257
|
const modelId = instructions['model-id'];
|
|
187
258
|
const uploadCollectionSlug = instructions['relation-to'];
|
|
188
259
|
const images = [
|
|
@@ -209,22 +280,30 @@ export const endpoints = (pluginConfig)=>({
|
|
|
209
280
|
url: `${serverURL}${img.image.url}`
|
|
210
281
|
});
|
|
211
282
|
} catch (e) {
|
|
212
|
-
req.payload.logger.error('Error fetching reference images!');
|
|
213
|
-
console.error(e);
|
|
283
|
+
req.payload.logger.error(e, 'Error fetching reference images!');
|
|
214
284
|
throw Error("We couldn't fetch the images. Please ensure the images are accessible and hosted publicly.");
|
|
215
285
|
}
|
|
216
286
|
}
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
287
|
+
const modelsUpload = getGenerationModels(pluginConfig);
|
|
288
|
+
const model = modelsUpload && Array.isArray(modelsUpload) ? modelsUpload.find((model)=>model.id === modelId) : undefined;
|
|
289
|
+
if (!model) {
|
|
290
|
+
throw new Error('Model not found');
|
|
291
|
+
}
|
|
292
|
+
// @ts-ignore
|
|
293
|
+
const settingsName = model && model.settings ? model.settings.name : undefined;
|
|
220
294
|
if (!settingsName) {
|
|
221
295
|
req.payload.logger.error('— AI Plugin: Error fetching settings name!');
|
|
222
296
|
}
|
|
223
|
-
let modelOptions = instructions[settingsName] || {};
|
|
297
|
+
let modelOptions = settingsName ? instructions[settingsName] || {} : {};
|
|
224
298
|
modelOptions = {
|
|
225
299
|
...modelOptions,
|
|
226
300
|
images: editImages
|
|
227
301
|
};
|
|
302
|
+
if (pluginConfig.debugging) {
|
|
303
|
+
req.payload.logger.info({
|
|
304
|
+
text
|
|
305
|
+
}, `— AI Plugin: Executing image prompt using ${model.id}`);
|
|
306
|
+
}
|
|
228
307
|
const result = await model.handler?.(text, modelOptions);
|
|
229
308
|
let assetData;
|
|
230
309
|
if (typeof pluginConfig.mediaUpload === 'function') {
|
|
@@ -251,14 +330,15 @@ export const endpoints = (pluginConfig)=>({
|
|
|
251
330
|
}
|
|
252
331
|
}));
|
|
253
332
|
} catch (error) {
|
|
254
|
-
req.payload.logger.error('Error generating upload: '
|
|
333
|
+
req.payload.logger.error(error, 'Error generating upload: ');
|
|
334
|
+
const message = error && typeof error === 'object' && 'message' in error ? error.message : String(error);
|
|
255
335
|
return new Response(JSON.stringify({
|
|
256
|
-
error:
|
|
336
|
+
error: message
|
|
257
337
|
}), {
|
|
258
338
|
headers: {
|
|
259
339
|
'Content-Type': 'application/json'
|
|
260
340
|
},
|
|
261
|
-
status:
|
|
341
|
+
status: message.includes('Authentication required') || message.includes('Insufficient permissions') ? 401 : 500
|
|
262
342
|
});
|
|
263
343
|
}
|
|
264
344
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/index.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport * as process from 'node:process'\n\nimport type { ActionMenuItems, Endpoints, PluginConfig } from '../types.js'\n\nimport { defaultPrompts } from '../ai/prompts.js'\nimport { filterEditorSchemaByNodes } from '../ai/utils/filterEditorSchemaByNodes.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 { extractImageData } from '../utilities/extractImageData.js'\nimport { getGenerationModels } from '../utilities/getGenerationModels.js'\n\nconst requireAuthentication = (req: PayloadRequest) => {\n if (!req.user) {\n throw new Error('Authentication required. Please log in to use AI features.')\n }\n return true\n}\n\nconst checkAccess = async (req: PayloadRequest, pluginConfig: PluginConfig) => {\n requireAuthentication(req)\n\n if (pluginConfig.access?.generate) {\n const hasAccess = await pluginConfig.access.generate({ req })\n if (!hasAccess) {\n throw new Error('Insufficient permissions to use AI generation features.')\n }\n }\n\n return true\n}\n\nconst assignPrompt = async (\n action: ActionMenuItems,\n {\n type,\n actionParams,\n context,\n field,\n layout,\n locale,\n systemPrompt = '',\n template,\n }: {\n actionParams: Record<any, any>\n context: object\n field: string\n layout: string\n locale: 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 if (locale && locale !== 'en') {\n /**\n * NOTE: Avoid using the \"system prompt\" for setting the output language,\n * as it causes quotation marks to appear in the output (Currently only tested with openai models).\n * Appending the language instruction directly to the prompt resolves this issue.\n **/\n assignedPrompts.prompt += `\n --- \n OUTPUT LANGUAGE: ${locale}\n `\n }\n\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 try {\n // Check authentication and authorization first\n await checkAccess(req, pluginConfig)\n\n const data = await req.json?.()\n\n const { allowedEditorNodes = [], 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 // Verify user has access to the specific instruction\n const instructions = await req.payload.findByID({\n id: instructionId,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n req, // Pass req to ensure access control is applied\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 let allowedEditorSchema = editorSchema\n if (allowedEditorNodes.length) {\n allowedEditorSchema = filterEditorSchemaByNodes(editorSchema, allowedEditorNodes)\n }\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).find(\n (model) => model.id === instructions['model-id'],\n )\n\n // @ts-expect-error\n const settingsName = model.settings?.name\n if (!settingsName) {\n req.payload.logger.error('— AI Plugin: Error fetching settings name!')\n }\n\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 locale: localeInfo,\n systemPrompt: instructions.system,\n template: promptTemplate as string,\n })\n\n return model.handler?.(prompts.prompt, {\n ...modelOptions,\n editorSchema: allowedEditorSchema,\n layout: prompts.layout,\n locale: localeInfo,\n system: prompts.system,\n })\n } catch (error) {\n req.payload.logger.error('Error generating content: ', error)\n return new Response(JSON.stringify({ error: error.message }), {\n headers: { 'Content-Type': 'application/json' },\n status:\n error.message.includes('Authentication required') ||\n error.message.includes('Insufficient permissions')\n ? 401\n : 500,\n })\n }\n },\n method: 'post',\n path: PLUGIN_API_ENDPOINT_GENERATE,\n },\n upload: {\n handler: async (req: PayloadRequest) => {\n try {\n // Check authentication and authorization first\n await checkAccess(req, pluginConfig)\n\n const data = await req.json?.()\n\n const { collectionSlug, documentId, options } = data\n const { instructionId } = options\n let docData = {}\n\n if (documentId) {\n try {\n docData = await req.payload.findByID({\n id: documentId,\n collection: collectionSlug,\n draft: true,\n req, // Pass req to ensure access control is applied\n })\n } catch (e) {\n req.payload.logger.error(\n '— AI Plugin: Error fetching document, you should try again after enabling drafts for this collection',\n )\n }\n }\n\n const contextData = {\n ...data.doc,\n ...docData,\n }\n\n let instructions = { images: [], 'model-id': '', prompt: '' }\n\n if (instructionId) {\n // Verify user has access to the specific instruction\n // @ts-expect-error\n instructions = await req.payload.findByID({\n id: instructionId,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n req, // Pass req to ensure access control is applied\n })\n }\n\n const { images: sampleImages = [], 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 images = [...extractImageData(text), ...sampleImages]\n\n const editImages = []\n for (const img of images) {\n try {\n const serverURL =\n req.payload.config?.serverURL ||\n process.env.SERVER_URL ||\n process.env.NEXT_PUBLIC_SERVER_URL\n\n const response = await fetch(`${serverURL}${img.image.url}`, {\n headers: {\n //TODO: Further testing needed or so find a proper way.\n Authorization: `Bearer ${req.headers.get('Authorization')?.split('Bearer ')[1] || ''}`,\n },\n method: 'GET',\n })\n\n const blob = await response.blob()\n editImages.push({\n name: img.image.name,\n type: img.image.type,\n data: blob,\n size: blob.size,\n url: `${serverURL}${img.image.url}`,\n })\n } catch (e) {\n req.payload.logger.error('Error fetching reference images!')\n console.error(e)\n throw Error(\n \"We couldn't fetch the images. Please ensure the images are accessible and hosted publicly.\",\n )\n }\n }\n\n const model = getGenerationModels(pluginConfig).find((model) => model.id === modelId)\n\n // @ts-expect-error\n const settingsName = model.settings?.name\n if (!settingsName) {\n req.payload.logger.error('— AI Plugin: Error fetching settings name!')\n }\n\n let modelOptions = instructions[settingsName] || {}\n modelOptions = {\n ...modelOptions,\n images: editImages,\n }\n\n const result = await model.handler?.(text, modelOptions)\n let assetData: { alt?: string; id: number | string }\n\n if (typeof pluginConfig.mediaUpload === 'function') {\n assetData = await pluginConfig.mediaUpload(result, {\n collection: uploadCollectionSlug,\n request: req,\n })\n } else {\n assetData = await req.payload.create({\n collection: uploadCollectionSlug,\n data: result.data,\n file: result.file,\n req, // Pass req to ensure access control is applied\n })\n }\n\n if (!assetData.id) {\n req.payload.logger.error(\n 'Error uploading generated media, is your media upload function correct?',\n )\n throw new Error('Error uploading generated media!')\n }\n\n return new Response(\n JSON.stringify({\n result: {\n id: assetData.id,\n alt: assetData.alt,\n },\n }),\n )\n } catch (error) {\n req.payload.logger.error('Error generating upload: ', error)\n return new Response(JSON.stringify({ error: error.message }), {\n headers: { 'Content-Type': 'application/json' },\n status:\n error.message.includes('Authentication required') ||\n error.message.includes('Insufficient permissions')\n ? 401\n : 500,\n })\n }\n },\n method: 'post',\n path: PLUGIN_API_ENDPOINT_GENERATE_UPLOAD,\n },\n }) satisfies Endpoints\n"],"names":["process","defaultPrompts","filterEditorSchemaByNodes","PLUGIN_API_ENDPOINT_GENERATE","PLUGIN_API_ENDPOINT_GENERATE_UPLOAD","PLUGIN_INSTRUCTIONS_TABLE","PLUGIN_NAME","registerEditorHelper","handlebarsHelpersMap","replacePlaceholders","extractImageData","getGenerationModels","requireAuthentication","req","user","Error","checkAccess","pluginConfig","access","generate","hasAccess","assignPrompt","action","type","actionParams","context","field","layout","locale","systemPrompt","template","prompt","toLexicalHTML","toHTML","name","assignedPrompts","undefined","system","getLayout","getSystemPrompt","find","p","updatedLayout","endpoints","textarea","handler","data","json","allowedEditorNodes","options","instructionId","contextData","doc","instructions","payload","findByID","id","collection","collections","config","slug","custom","editorConfig","admin","schema","editorSchema","promptTemplate","allowedEditorSchema","length","schemaPath","fieldName","split","pop","defaultLocale","locales","localization","localeData","l","code","localeInfo","label","model","settingsName","settings","logger","error","modelOptions","prompts","Response","JSON","stringify","message","headers","status","includes","method","path","upload","collectionSlug","documentId","docData","draft","e","images","sampleImages","text","modelId","uploadCollectionSlug","editImages","img","serverURL","env","SERVER_URL","NEXT_PUBLIC_SERVER_URL","response","fetch","image","url","Authorization","get","blob","push","size","console","result","assetData","mediaUpload","request","create","file","alt"],"mappings":"AAEA,YAAYA,aAAa,eAAc;AAIvC,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,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,gBAAgB,QAAQ,mCAAkC;AACnE,SAASC,mBAAmB,QAAQ,sCAAqC;AAEzE,MAAMC,wBAAwB,CAACC;IAC7B,IAAI,CAACA,IAAIC,IAAI,EAAE;QACb,MAAM,IAAIC,MAAM;IAClB;IACA,OAAO;AACT;AAEA,MAAMC,cAAc,OAAOH,KAAqBI;IAC9CL,sBAAsBC;IAEtB,IAAII,aAAaC,MAAM,EAAEC,UAAU;QACjC,MAAMC,YAAY,MAAMH,aAAaC,MAAM,CAACC,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AAM3C,MAAMpC,OAAO,GAAG4D,MAAMnB;oBAC3C,IAAIuC;oBAEJ,IAAI,OAAO5G,aAAa6G,WAAW,KAAK,YAAY;wBAClDD,YAAY,MAAM5G,aAAa6G,WAAW,CAACF,QAAQ;4BACjDnE,YAAYkD;4BACZoB,SAASlH;wBACX;oBACF,OAAO;wBACLgH,YAAY,MAAMhH,IAAIyC,OAAO,CAAC0E,MAAM,CAAC;4BACnCvE,YAAYkD;4BACZ7D,MAAM8E,OAAO9E,IAAI;4BACjBmF,MAAML,OAAOK,IAAI;4BACjBpH;wBACF;oBACF;oBAEA,IAAI,CAACgH,UAAUrE,EAAE,EAAE;wBACjB3C,IAAIyC,OAAO,CAAC8B,MAAM,CAACC,KAAK,CACtB;wBAEF,MAAM,IAAItE,MAAM;oBAClB;oBAEA,OAAO,IAAIyE,SACTC,KAAKC,SAAS,CAAC;wBACbkC,QAAQ;4BACNpE,IAAIqE,UAAUrE,EAAE;4BAChB0E,KAAKL,UAAUK,GAAG;wBACpB;oBACF;gBAEJ,EAAE,OAAO7C,OAAO;oBACdxE,IAAIyC,OAAO,CAAC8B,MAAM,CAACC,KAAK,CAAC,6BAA6BA;oBACtD,OAAO,IAAIG,SAASC,KAAKC,SAAS,CAAC;wBAAEL,OAAOA,MAAMM,OAAO;oBAAC,IAAI;wBAC5DC,SAAS;4BAAE,gBAAgB;wBAAmB;wBAC9CC,QACER,MAAMM,OAAO,CAACG,QAAQ,CAAC,8BACvBT,MAAMM,OAAO,CAACG,QAAQ,CAAC,8BACnB,MACA;oBACR;gBACF;YACF;YACAC,QAAQ;YACRC,MAAM5F;QACR;IACF,CAAA,EAAsB"}
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/index.ts"],"sourcesContent":["import type { CollectionSlug, PayloadRequest } from 'payload'\n\nimport * as process from 'node:process'\n\nimport type {\n ActionMenuItems,\n Endpoints,\n PluginConfig,\n PromptFieldGetterContext,\n} from '../types.js'\n\nimport { defaultPrompts } from '../ai/prompts.js'\nimport { filterEditorSchemaByNodes } from '../ai/utils/filterEditorSchemaByNodes.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 { asyncHandlebars } from '../libraries/handlebars/asyncHandlebars.js'\nimport { registerEditorHelper } from '../libraries/handlebars/helpers.js'\nimport { handlebarsHelpersMap } from '../libraries/handlebars/helpersMap.js'\nimport { replacePlaceholders } from '../libraries/handlebars/replacePlaceholders.js'\nimport { extractImageData } from '../utilities/extractImageData.js'\nimport { getGenerationModels } from '../utilities/getGenerationModels.js'\n\nconst requireAuthentication = (req: PayloadRequest) => {\n if (!req.user) {\n throw new Error('Authentication required. Please log in to use AI features.')\n }\n return true\n}\n\nconst checkAccess = async (req: PayloadRequest, pluginConfig: PluginConfig) => {\n requireAuthentication(req)\n\n if (pluginConfig.access?.generate) {\n const hasAccess = await pluginConfig.access.generate({ req })\n if (!hasAccess) {\n throw new Error('Insufficient permissions to use AI generation features.')\n }\n }\n\n return true\n}\n\nconst extendContextWithPromptFields = (\n data: object,\n ctx: PromptFieldGetterContext,\n pluginConfig: PluginConfig,\n) => {\n const { promptFields = [] } = pluginConfig\n const fieldsMap = new Map(\n promptFields\n .filter((f) => !f.collections || f.collections.includes(ctx.collection))\n .map((f) => [f.name, f]),\n )\n return new Proxy(data, {\n get: (target, prop: string) => {\n const field = fieldsMap.get(prop as string)\n if (field?.getter) {\n const value = field.getter(data, ctx)\n return Promise.resolve(value).then((v) => new asyncHandlebars.SafeString(v))\n }\n // {{prop}} escapes content by default. Here we make sure it won't be escaped.\n const value = typeof target === \"object\" ? (target as any)[prop] : undefined\n return typeof value === 'string' ? new asyncHandlebars.SafeString(value) : value\n },\n // It's used by the handlebars library to determine if the property is enumerable\n getOwnPropertyDescriptor: (target, prop) => {\n const field = fieldsMap.get(prop as string)\n if (field) {\n return {\n configurable: true,\n enumerable: true,\n }\n }\n return Object.getOwnPropertyDescriptor(target, prop)\n },\n has: (target, prop) => {\n return fieldsMap.has(prop as string) || prop in target\n },\n ownKeys: (target) => {\n return [...fieldsMap.keys(), ...Object.keys(target)]\n },\n })\n}\n\nconst assignPrompt = async (\n action: ActionMenuItems,\n {\n type,\n actionParams,\n collection,\n context,\n field,\n layout,\n locale,\n pluginConfig,\n systemPrompt = '',\n template,\n }: {\n actionParams: Record<any, any>\n collection: CollectionSlug\n context: object\n field: string\n layout: string\n locale: string\n pluginConfig: PluginConfig\n systemPrompt: string\n template: string\n type: string\n },\n) => {\n const extendedContext = extendContextWithPromptFields(context, { type, collection }, pluginConfig)\n const prompt = await replacePlaceholders(template, extendedContext)\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 if (locale && locale !== 'en') {\n /**\n * NOTE: Avoid using the \"system prompt\" for setting the output language,\n * as it causes quotation marks to appear in the output (Currently only tested with openai models).\n * Appending the language instruction directly to the prompt resolves this issue.\n **/\n assignedPrompts.prompt += `\n --- \n OUTPUT LANGUAGE: ${locale}\n `\n }\n\n return assignedPrompts\n }\n\n const prompts = [...(pluginConfig.prompts || []), ...defaultPrompts]\n const foundPrompt = prompts.find((p) => p.name === action)\n const getLayout = foundPrompt?.layout\n const getSystemPrompt = foundPrompt?.system\n\n let updatedLayout = layout\n if (getLayout) {\n updatedLayout = getLayout()\n }\n\n const system = getSystemPrompt\n ? getSystemPrompt({\n ...(actionParams || {}),\n prompt,\n systemPrompt,\n })\n : ''\n\n return {\n layout: updatedLayout,\n // TODO: revisit this toLexicalHTML\n prompt: await replacePlaceholders(`{{${toLexicalHTML} ${field}}}`, extendedContext),\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 try {\n // Check authentication and authorization first\n await checkAccess(req, pluginConfig)\n\n const data = await req.json?.()\n\n const { allowedEditorNodes = [], 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, or try again`,\n )\n }\n\n // Verify user has access to the specific instruction\n const instructions = await req.payload.findByID({\n id: instructionId,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n req, // Pass req to ensure access control is applied\n })\n\n const { collections } = req.payload.config\n const collection = collections.find(\n (collection) => collection.slug === PLUGIN_INSTRUCTIONS_TABLE,\n )\n\n if (!collection) {\n throw new Error('Collection not found')\n }\n\n const { custom: { [PLUGIN_NAME]: { editorConfig = {} } = {} } = {} } = collection.admin\n const { schema: editorSchema = {} } = editorConfig\n const { prompt: promptTemplate = '' } = instructions\n\n let allowedEditorSchema = editorSchema\n if (allowedEditorNodes.length) {\n allowedEditorSchema = filterEditorSchemaByNodes(editorSchema, allowedEditorNodes)\n }\n\n const schemaPath = instructions['schema-path'] as string\n const [collectionName, fieldName] = schemaPath?.split('.') || []\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 let localeInfo = locale\n if (\n localeData &&\n defaultLocale &&\n localeData.label &&\n typeof localeData.label === 'object' &&\n defaultLocale in localeData.label\n ) {\n localeInfo = localeData.label[defaultLocale]\n }\n\n const models = getGenerationModels(pluginConfig)\n const model =\n models && Array.isArray(models)\n ? models.find((model) => model.id === instructions['model-id'])\n : undefined\n\n if (!model) {\n throw new Error('Model not found')\n }\n\n // @ts-ignore\n const settingsName = model && model.settings ? model.settings.name : undefined\n if (!settingsName) {\n req.payload.logger.error('— AI Plugin: Error fetching settings name!')\n }\n\n const modelOptions = settingsName ? instructions[settingsName] || {} : {}\n\n const prompts = await assignPrompt(action, {\n type: String(instructions['field-type']),\n actionParams,\n collection: collectionName,\n context: contextData,\n field: fieldName || '',\n layout: instructions.layout,\n locale: localeInfo,\n pluginConfig,\n systemPrompt: instructions.system,\n template: String(promptTemplate),\n })\n\n if (pluginConfig.debugging) {\n req.payload.logger.info(\n { prompts },\n `— AI Plugin: Executing text prompt on ${schemaPath} using ${model.id}`,\n )\n }\n\n return model.handler?.(prompts.prompt, {\n ...modelOptions,\n editorSchema: allowedEditorSchema,\n layout: prompts.layout,\n locale: localeInfo,\n system: prompts.system,\n })\n } catch (error) {\n req.payload.logger.error(error, 'Error generating content: ')\n const message =\n error && typeof error === 'object' && 'message' in error\n ? (error as any).message\n : String(error)\n return new Response(JSON.stringify({ error: message }), {\n headers: { 'Content-Type': 'application/json' },\n status:\n message.includes('Authentication required') ||\n message.includes('Insufficient permissions')\n ? 401\n : 500,\n })\n }\n },\n method: 'post',\n path: PLUGIN_API_ENDPOINT_GENERATE,\n },\n upload: {\n handler: async (req: PayloadRequest) => {\n try {\n // Check authentication and authorization first\n await checkAccess(req, pluginConfig)\n\n const data = await req.json?.()\n\n const { collectionSlug, documentId, options } = data\n const { instructionId } = options\n let docData = {}\n\n if (documentId) {\n try {\n docData = await req.payload.findByID({\n id: documentId,\n collection: collectionSlug,\n draft: true,\n req, // Pass req to ensure access control is applied\n })\n } catch (e) {\n req.payload.logger.error(\n e,\n '— AI Plugin: Error fetching document, you should try again after enabling drafts for this collection',\n )\n }\n }\n\n const contextData = {\n ...data.doc,\n ...docData,\n }\n\n let instructions: Record<string, any> = { images: [], 'model-id': '', prompt: '' }\n\n if (instructionId) {\n // Verify user has access to the specific instruction\n instructions = await req.payload.findByID({\n id: instructionId,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n req, // Pass req to ensure access control is applied\n })\n }\n\n const { images: sampleImages = [], prompt: promptTemplate = '' } = instructions\n const schemaPath = instructions['schema-path']\n\n registerEditorHelper(req.payload, schemaPath)\n\n const extendedContext = extendContextWithPromptFields(\n contextData,\n { type: instructions['field-type'], collection: collectionSlug },\n pluginConfig,\n )\n const text = await replacePlaceholders(promptTemplate, extendedContext)\n const modelId = instructions['model-id']\n const uploadCollectionSlug = instructions['relation-to']\n\n const images = [...extractImageData(text), ...sampleImages]\n\n const editImages = []\n for (const img of images) {\n try {\n const serverURL =\n req.payload.config?.serverURL ||\n process.env.SERVER_URL ||\n process.env.NEXT_PUBLIC_SERVER_URL\n\n const response = await fetch(`${serverURL}${img.image.url}`, {\n headers: {\n //TODO: Further testing needed or so find a proper way.\n Authorization: `Bearer ${req.headers.get('Authorization')?.split('Bearer ')[1] || ''}`,\n },\n method: 'GET',\n })\n\n const blob = await response.blob()\n editImages.push({\n name: img.image.name,\n type: img.image.type,\n data: blob,\n size: blob.size,\n url: `${serverURL}${img.image.url}`,\n })\n } catch (e) {\n req.payload.logger.error(e, 'Error fetching reference images!')\n throw Error(\n \"We couldn't fetch the images. Please ensure the images are accessible and hosted publicly.\",\n )\n }\n }\n\n const modelsUpload = getGenerationModels(pluginConfig)\n const model =\n modelsUpload && Array.isArray(modelsUpload)\n ? modelsUpload.find((model) => model.id === modelId)\n : undefined\n\n if (!model) {\n throw new Error('Model not found')\n }\n\n // @ts-ignore\n const settingsName = model && model.settings ? model.settings.name : undefined\n if (!settingsName) {\n req.payload.logger.error('— AI Plugin: Error fetching settings name!')\n }\n\n let modelOptions = settingsName ? instructions[settingsName] || {} : {}\n modelOptions = {\n ...modelOptions,\n images: editImages,\n }\n\n if (pluginConfig.debugging) {\n req.payload.logger.info(\n { text },\n `— AI Plugin: Executing image prompt using ${model.id}`,\n )\n }\n\n const result = await model.handler?.(text, modelOptions)\n let assetData: { alt?: string; id: number | string }\n\n if (typeof pluginConfig.mediaUpload === 'function') {\n assetData = await pluginConfig.mediaUpload(result, {\n collection: uploadCollectionSlug,\n request: req,\n })\n } else {\n assetData = await req.payload.create({\n collection: uploadCollectionSlug,\n data: result.data,\n file: result.file,\n req, // Pass req to ensure access control is applied\n })\n }\n\n if (!assetData.id) {\n req.payload.logger.error(\n 'Error uploading generated media, is your media upload function correct?',\n )\n throw new Error('Error uploading generated media!')\n }\n\n return new Response(\n JSON.stringify({\n result: {\n id: assetData.id,\n alt: assetData.alt,\n },\n }),\n )\n } catch (error) {\n req.payload.logger.error(error, 'Error generating upload: ')\n const message =\n error && typeof error === 'object' && 'message' in error\n ? (error as any).message\n : String(error)\n return new Response(JSON.stringify({ error: message }), {\n headers: { 'Content-Type': 'application/json' },\n status:\n message.includes('Authentication required') ||\n message.includes('Insufficient permissions')\n ? 401\n : 500,\n })\n }\n },\n method: 'post',\n path: PLUGIN_API_ENDPOINT_GENERATE_UPLOAD,\n },\n }) satisfies Endpoints\n"],"names":["process","defaultPrompts","filterEditorSchemaByNodes","PLUGIN_API_ENDPOINT_GENERATE","PLUGIN_API_ENDPOINT_GENERATE_UPLOAD","PLUGIN_INSTRUCTIONS_TABLE","PLUGIN_NAME","asyncHandlebars","registerEditorHelper","handlebarsHelpersMap","replacePlaceholders","extractImageData","getGenerationModels","requireAuthentication","req","user","Error","checkAccess","pluginConfig","access","generate","hasAccess","extendContextWithPromptFields","data","ctx","promptFields","fieldsMap","Map","filter","f","collections","includes","collection","map","name","Proxy","get","target","prop","field","getter","value","Promise","resolve","then","v","SafeString","undefined","getOwnPropertyDescriptor","configurable","enumerable","Object","has","ownKeys","keys","assignPrompt","action","type","actionParams","context","layout","locale","systemPrompt","template","extendedContext","prompt","toLexicalHTML","toHTML","assignedPrompts","system","prompts","foundPrompt","find","p","getLayout","getSystemPrompt","updatedLayout","endpoints","textarea","handler","json","allowedEditorNodes","options","instructionId","contextData","doc","instructions","payload","findByID","id","config","slug","custom","editorConfig","admin","schema","editorSchema","promptTemplate","allowedEditorSchema","length","schemaPath","collectionName","fieldName","split","defaultLocale","locales","localization","localeData","l","code","localeInfo","label","models","model","Array","isArray","settingsName","settings","logger","error","modelOptions","String","debugging","info","message","Response","JSON","stringify","headers","status","method","path","upload","collectionSlug","documentId","docData","draft","e","images","sampleImages","text","modelId","uploadCollectionSlug","editImages","img","serverURL","env","SERVER_URL","NEXT_PUBLIC_SERVER_URL","response","fetch","image","url","Authorization","blob","push","size","modelsUpload","result","assetData","mediaUpload","request","create","file","alt"],"mappings":"AAEA,YAAYA,aAAa,eAAc;AASvC,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SACEC,4BAA4B,EAC5BC,mCAAmC,EACnCC,yBAAyB,EACzBC,WAAW,QACN,iBAAgB;AACvB,SAASC,eAAe,QAAQ,6CAA4C;AAC5E,SAASC,oBAAoB,QAAQ,qCAAoC;AACzE,SAASC,oBAAoB,QAAQ,wCAAuC;AAC5E,SAASC,mBAAmB,QAAQ,iDAAgD;AACpF,SAASC,gBAAgB,QAAQ,mCAAkC;AACnE,SAASC,mBAAmB,QAAQ,sCAAqC;AAEzE,MAAMC,wBAAwB,CAACC;IAC7B,IAAI,CAACA,IAAIC,IAAI,EAAE;QACb,MAAM,IAAIC,MAAM;IAClB;IACA,OAAO;AACT;AAEA,MAAMC,cAAc,OAAOH,KAAqBI;IAC9CL,sBAAsBC;IAEtB,IAAII,aAAaC,MAAM,EAAEC,UAAU;QACjC,MAAMC,YAAY,MAAMH,aAAaC,MAAM,CAACC,QAAQ,CAAC;YAAEN;QAAI;QAC3D,IAAI,CAACO,WAAW;YACd,MAAM,IAAIL,MAAM;QAClB;IACF;IAEA,OAAO;AACT;AAEA,MAAMM,gCAAgC,CACpCC,MACAC,KACAN;IAEA,MAAM,EAAEO,eAAe,EAAE,EAAE,GAAGP;IAC9B,MAAMQ,YAAY,IAAIC,IACpBF,aACGG,MAAM,CAAC,CAACC,IAAM,CAACA,EAAEC,WAAW,IAAID,EAAEC,WAAW,CAACC,QAAQ,CAACP,IAAIQ,UAAU,GACrEC,GAAG,CAAC,CAACJ,IAAM;YAACA,EAAEK,IAAI;YAAEL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J,UAAUtE,EAAE,EAAE;wBACjB3E,IAAIyE,OAAO,CAAC+B,MAAM,CAACC,KAAK,CACtB;wBAEF,MAAM,IAAIvG,MAAM;oBAClB;oBAEA,OAAO,IAAI6G,SACTC,KAAKC,SAAS,CAAC;wBACb+B,QAAQ;4BACNrE,IAAIsE,UAAUtE,EAAE;4BAChB2E,KAAKL,UAAUK,GAAG;wBACpB;oBACF;gBAEJ,EAAE,OAAO7C,OAAO;oBACdzG,IAAIyE,OAAO,CAAC+B,MAAM,CAACC,KAAK,CAACA,OAAO;oBAChC,MAAMK,UACJL,SAAS,OAAOA,UAAU,YAAY,aAAaA,QAC/C,AAACA,MAAcK,OAAO,GACtBH,OAAOF;oBACb,OAAO,IAAIM,SAASC,KAAKC,SAAS,CAAC;wBAAER,OAAOK;oBAAQ,IAAI;wBACtDI,SAAS;4BAAE,gBAAgB;wBAAmB;wBAC9CC,QACEL,QAAQ7F,QAAQ,CAAC,8BACjB6F,QAAQ7F,QAAQ,CAAC,8BACb,MACA;oBACR;gBACF;YACF;YACAmG,QAAQ;YACRC,MAAM/H;QACR;IACF,CAAA,EAAsB"}
|
package/dist/exports/client.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { LexicalEditorFeatureClient } from '../fields/LexicalEditor/feature.client.js';
|
|
2
|
+
export { InstructionsContext } from '../providers/InstructionsProvider/context.js';
|
|
2
3
|
export { InstructionsProvider } from '../providers/InstructionsProvider/InstructionsProvider.js';
|
|
3
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/exports/client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { LexicalEditorFeatureClient } from '../fields/LexicalEditor/feature.client.js';
|
|
2
|
+
export { InstructionsContext } from '../providers/InstructionsProvider/context.js';
|
|
2
3
|
export { InstructionsProvider } from '../providers/InstructionsProvider/InstructionsProvider.js';
|
|
3
4
|
|
|
4
5
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { LexicalEditorFeatureClient } from '../fields/LexicalEditor/feature.client.js'\nexport { InstructionsProvider } from '../providers/InstructionsProvider/InstructionsProvider.js'\n"],"names":["LexicalEditorFeatureClient","InstructionsProvider"],"mappings":"AAAA,SAASA,0BAA0B,QAAQ,4CAA2C;AACtF,SAASC,oBAAoB,QAAQ,4DAA2D"}
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { LexicalEditorFeatureClient } from '../fields/LexicalEditor/feature.client.js'\nexport { InstructionsContext } from '../providers/InstructionsProvider/context.js'\nexport { InstructionsProvider } from '../providers/InstructionsProvider/InstructionsProvider.js'\n"],"names":["LexicalEditorFeatureClient","InstructionsContext","InstructionsProvider"],"mappings":"AAAA,SAASA,0BAA0B,QAAQ,4CAA2C;AACtF,SAASC,mBAAmB,QAAQ,+CAA8C;AAClF,SAASC,oBAAoB,QAAQ,4DAA2D"}
|
package/dist/exports/fields.d.ts
CHANGED
package/dist/exports/types.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export type { payloadAiPlugin } from '../
|
|
2
|
-
export type {
|
|
3
|
-
//# sourceMappingURL=types.d.ts.map
|
|
1
|
+
export type { payloadAiPlugin } from '../index.ts';
|
|
2
|
+
export type { GenerationConfig, GenerationModel, PluginConfig } from '../types.ts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type { payloadAiPlugin } from '../
|
|
1
|
+
{"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type { payloadAiPlugin } from '../index.ts'\nexport type { GenerationConfig, GenerationModel, PluginConfig } from '../types.ts'\n"],"names":[],"mappings":"AACA,WAAkF"}
|