@ai-stack/payloadcms 3.2.14-beta → 3.2.16-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.
Files changed (30) hide show
  1. package/README.md +18 -2
  2. package/dist/ai/utils/filterEditorSchemaByNodes.js +1 -2
  3. package/dist/ai/utils/filterEditorSchemaByNodes.js.map +1 -1
  4. package/dist/collections/Instructions.d.ts.map +1 -1
  5. package/dist/collections/Instructions.js +26 -5
  6. package/dist/collections/Instructions.js.map +1 -1
  7. package/dist/endpoints/fetchFields.d.ts +2 -2
  8. package/dist/endpoints/fetchFields.d.ts.map +1 -1
  9. package/dist/endpoints/fetchFields.js +2 -1
  10. package/dist/endpoints/fetchFields.js.map +1 -1
  11. package/dist/endpoints/index.d.ts.map +1 -1
  12. package/dist/endpoints/index.js +196 -140
  13. package/dist/endpoints/index.js.map +1 -1
  14. package/dist/plugin.d.ts.map +1 -1
  15. package/dist/plugin.js +27 -2
  16. package/dist/plugin.js.map +1 -1
  17. package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts +1 -0
  18. package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts.map +1 -1
  19. package/dist/providers/InstructionsProvider/InstructionsProvider.js +3 -0
  20. package/dist/providers/InstructionsProvider/InstructionsProvider.js.map +1 -1
  21. package/dist/types.d.ts +25 -0
  22. package/dist/types.d.ts.map +1 -1
  23. package/dist/types.js.map +1 -1
  24. package/dist/ui/Compose/hooks/menu/TranslateMenu.d.ts +4 -0
  25. package/dist/ui/Compose/hooks/menu/TranslateMenu.d.ts.map +1 -1
  26. package/dist/ui/Compose/hooks/menu/TranslateMenu.js +9 -4
  27. package/dist/ui/Compose/hooks/menu/TranslateMenu.js.map +1 -1
  28. package/dist/ui/Compose/hooks/menu/itemsMap.js +2 -2
  29. package/dist/ui/Compose/hooks/menu/itemsMap.js.map +1 -1
  30. package/package.json +1 -1
package/README.md CHANGED
@@ -47,10 +47,10 @@ Want to dive deeper?
47
47
  - 🎛️ **Field-level Prompt Customization**
48
48
  - 🔐 **Access Control Support**
49
49
  - 🧠 **Prompt Editor**
50
+ - 🌍 **Internationalization Support**
50
51
  - 📊 **Document Analyzer** (Coming Soon)
51
52
  - ✅ **Fact Checking** (Coming Soon)
52
53
  - 🔄 **Automated Content Workflows** (Coming Soon)
53
- - 🌍 **Internationalization Support** (Coming Soon)
54
54
  - 🌍 **Editor AI suggestions** (Coming Soon)
55
55
  - 💬 **AI Chat Support** (Coming Soon)
56
56
 
@@ -154,6 +154,11 @@ export default buildConfig({
154
154
  [Posts.slug]: true,
155
155
  },
156
156
 
157
+ // Optional
158
+ globals: {
159
+ [Home.slug]: true,
160
+ },
161
+
157
162
  // Optional: Show debug logs to list AI-enabled fields
158
163
  debugging: false,
159
164
 
@@ -166,11 +171,22 @@ export default buildConfig({
166
171
  // Optional: Specify the media collection used by the gpt-image-1 model to reference images (defaults to media)
167
172
  uploadCollectionSlug: "media",
168
173
 
169
- // Optional: Restrict plugin settings to admin users only
174
+ // Optional: Access control for AI features
170
175
  access: {
176
+ // Control who can generate AI content
177
+ generate: ({ req }) => req.user?.role === 'admin',
178
+
179
+ // Control who can modify AI settings and prompts
171
180
  settings: ({ req }) => req.user?.role === 'admin',
172
181
  },
173
182
 
183
+ options: {
184
+ // Visit locale-codes for tags,
185
+ // defaults to display all language options for Translate feature
186
+ // https://www.npmjs.com/package/locale-codes
187
+ enabledLanguages: ["en-US", "zh-SG", "zh-CN", "en"],
188
+ },
189
+
174
190
  // Optional: Custom media upload handling, useful for multi-tenant setups
175
191
  mediaUpload: async (result, { request, collection }) => {
176
192
  return request.payload.create({
@@ -7,8 +7,7 @@ export function filterEditorSchemaByNodes(schema, allowedNodes) {
7
7
  if (isObjectSchema(def)) {
8
8
  const typeEnum = def.properties?.type?.enum;
9
9
  if (typeEnum && typeEnum.some((t)=>allowedTypes.has(t))) {
10
- filteredDefinitions[key] = JSON.parse(JSON.stringify(def)) // Deep copy to safely mutate
11
- ;
10
+ filteredDefinitions[key] = JSON.parse(JSON.stringify(def)); // Deep copy to safely mutate
12
11
  }
13
12
  }
14
13
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/ai/utils/filterEditorSchemaByNodes.ts"],"sourcesContent":["import type { LexicalNodeSchema } from '../schemas/lexicalJsonSchema.js'\n\nimport { isObjectSchema } from './isObjectSchema.js'\n\nexport function filterEditorSchemaByNodes(schema: LexicalNodeSchema, allowedNodes) {\n const allowedTypes = new Set(allowedNodes)\n\n const filteredDefinitions = {}\n\n // First pass: collect definitions whose \"type.enum\" includes an allowed type\n for (const [key, def] of Object.entries(schema.definitions)) {\n if(isObjectSchema(def)) {\n const typeEnum = def.properties?.type?.enum\n if (typeEnum && typeEnum.some((t) => allowedTypes.has(t))) {\n filteredDefinitions[key] = JSON.parse(JSON.stringify(def)) // Deep copy to safely mutate\n }\n }\n }\n\n // Helper to check if a $ref points to an allowed definition\n const isAllowedRef = (ref) => {\n if (typeof ref !== 'string') return false\n const defName = ref.replace('#/definitions/', '')\n return defName in filteredDefinitions\n }\n\n // Second pass: update \"children\" in each definition to only include allowed refs\n for (const def of Object.values(filteredDefinitions)) {\n if (isObjectSchema(def) && def.properties?.children?.items) {\n const items = def.properties.children.items\n\n if (Array.isArray(items.anyOf)) {\n // Filter anyOf to only allowed $refs\n items.anyOf = items.anyOf.filter((entry) => isAllowedRef(entry.$ref))\n if (items.anyOf.length === 0) {\n delete def.properties.children\n }\n } else if (items.$ref && !isAllowedRef(items.$ref)) {\n delete def.properties.children\n }\n }\n }\n\n // Return the new schema with pruned definitions\n return {\n ...schema,\n definitions: filteredDefinitions,\n }\n}\n"],"names":["isObjectSchema","filterEditorSchemaByNodes","schema","allowedNodes","allowedTypes","Set","filteredDefinitions","key","def","Object","entries","definitions","typeEnum","properties","type","enum","some","t","has","JSON","parse","stringify","isAllowedRef","ref","defName","replace","values","children","items","Array","isArray","anyOf","filter","entry","$ref","length"],"mappings":"AAEA,SAASA,cAAc,QAAQ,sBA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AAgD;IAChD,OAAO;QACL,GAAGzB,MAAM;QACTS,aAAaL;IACf;AACF"}
1
+ {"version":3,"sources":["../../../src/ai/utils/filterEditorSchemaByNodes.ts"],"sourcesContent":["import type { LexicalNodeSchema } from '../schemas/lexicalJsonSchema.js'\n\nimport { isObjectSchema } from './isObjectSchema.js'\n\nexport function filterEditorSchemaByNodes(schema: LexicalNodeSchema, allowedNodes) {\n const allowedTypes = new Set(allowedNodes)\n\n const filteredDefinitions = {}\n\n // First pass: collect definitions whose \"type.enum\" includes an allowed type\n for (const [key, def] of Object.entries(schema.definitions)) {\n if(isObjectSchema(def)) {\n const typeEnum = def.properties?.type?.enum\n if (typeEnum && typeEnum.some((t) => allowedTypes.has(t))) {\n filteredDefinitions[key] = JSON.parse(JSON.stringify(def)) // Deep copy to safely mutate\n }\n }\n }\n\n // Helper to check if a $ref points to an allowed definition\n const isAllowedRef = (ref) => {\n if (typeof ref !== 'string') return false\n const defName = ref.replace('#/definitions/', '')\n return defName in filteredDefinitions\n }\n\n // Second pass: update \"children\" in each definition to only include allowed refs\n for (const def of Object.values(filteredDefinitions)) {\n if (isObjectSchema(def) && def.properties?.children?.items) {\n const items = def.properties.children.items\n\n if (Array.isArray(items.anyOf)) {\n // Filter anyOf to only allowed $refs\n items.anyOf = items.anyOf.filter((entry) => isAllowedRef(entry.$ref))\n if (items.anyOf.length === 0) {\n delete def.properties.children\n }\n } else if (items.$ref && !isAllowedRef(items.$ref)) {\n delete def.properties.children\n }\n }\n }\n\n // Return the new schema with pruned definitions\n return {\n ...schema,\n definitions: filteredDefinitions,\n }\n}\n"],"names":["isObjectSchema","filterEditorSchemaByNodes","schema","allowedNodes","allowedTypes","Set","filteredDefinitions","key","def","Object","entries","definitions","typeEnum","properties","type","enum","some","t","has","JSON","parse","stringify","isAllowedRef","ref","defName","replace","values","children","items","Array","isArray","anyOf","filter","entry","$ref","length"],"mappings":"AAEA,SAASA,cAAc,QAAQ,sBAAqB;AAEpD,OAAO,SAASC,0BAA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,MAAM;QACTS,aAAaL;IACf;AACF"}
@@ -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;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAiChD,eAAO,MAAM,sBAAsB,GACjC,cAAc,YAAY,EAC1B,UAAU,OAAO,CAAC,gBAAgB,CAAC,KAElC,gBAgMA,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;AAsDhD,eAAO,MAAM,sBAAsB,GACjC,cAAc,YAAY,EAC1B,UAAU,OAAO,CAAC,gBAAgB,CAAC,KAElC,gBAgMA,CAAA"}
@@ -14,9 +14,30 @@ const modelOptions = (pluginConfig)=>getGenerationModels(pluginConfig).map((mode
14
14
  };
15
15
  });
16
16
  const defaultAccessConfig = {
17
- create: ()=>true,
18
- read: ()=>true,
19
- update: ()=>true
17
+ create: ({ req })=>{
18
+ if (!req.user) {
19
+ return false;
20
+ }
21
+ return true;
22
+ },
23
+ delete: ({ req })=>{
24
+ if (!req.user) {
25
+ return false;
26
+ }
27
+ return true;
28
+ },
29
+ read: ({ req })=>{
30
+ if (!req.user) {
31
+ return false;
32
+ }
33
+ return true;
34
+ },
35
+ update: ({ req })=>{
36
+ if (!req.user) {
37
+ return false;
38
+ }
39
+ return true;
40
+ }
20
41
  };
21
42
  const defaultAdminConfig = {
22
43
  group: 'Plugins',
@@ -38,7 +59,7 @@ export const instructionsCollection = (pluginConfig, options)=>({
38
59
  name: 'schema-path',
39
60
  type: 'text',
40
61
  admin: {
41
- description: "Please dont change this unless you're sure of what you're doing"
62
+ description: "Please don't change this unless you're sure of what you're doing"
42
63
  },
43
64
  unique: true
44
65
  },
@@ -46,7 +67,7 @@ export const instructionsCollection = (pluginConfig, options)=>({
46
67
  name: 'field-type',
47
68
  type: 'select',
48
69
  admin: {
49
- description: "Please dont change this unless you're sure of what you're doing"
70
+ description: "Please don't change this unless you're sure of what you're doing"
50
71
  },
51
72
  defaultValue: 'text',
52
73
  label: 'Field type',
@@ -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: () => 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 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","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;YACL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;oBACT;iBACD;YACH;eACGT,cAAcC;SAClB;QACDwC,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 }) => {\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,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ACT;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,4 +1,4 @@
1
1
  import type { Endpoint } from 'payload';
2
- import type { PluginConfigAccess } from '../types.js';
3
- export declare const fetchFields: (access: PluginConfigAccess) => Endpoint;
2
+ import type { PluginConfigAccess, PluginOptions } from '../types.js';
3
+ export declare const fetchFields: (access: PluginConfigAccess, options?: PluginOptions) => Endpoint;
4
4
  //# sourceMappingURL=fetchFields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchFields.d.ts","sourceRoot":"","sources":["../../src/endpoints/fetchFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAkB,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,eAAO,MAAM,WAAW,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,QAkCzD,CAAA"}
1
+ {"version":3,"file":"fetchFields.d.ts","sourceRoot":"","sources":["../../src/endpoints/fetchFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAkB,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAIpE,eAAO,MAAM,WAAW,EAAE,CAAC,MAAM,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,QAsClF,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { PLUGIN_FETCH_FIELDS_ENDPOINT, PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js';
2
- export const fetchFields = (access)=>{
2
+ export const fetchFields = (access, options = {})=>{
3
3
  return {
4
4
  handler: async (req)=>{
5
5
  const { docs = [] } = await req.payload.find({
@@ -25,6 +25,7 @@ export const fetchFields = (access)=>{
25
25
  };
26
26
  });
27
27
  return Response.json({
28
+ ...options,
28
29
  fields: fieldMap,
29
30
  isConfigAllowed
30
31
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/endpoints/fetchFields.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload'\n\nimport type { PluginConfigAccess } from '../types.js'\n\nimport { PLUGIN_FETCH_FIELDS_ENDPOINT, PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\n\nexport const fetchFields: (access: PluginConfigAccess) => Endpoint = (access) => {\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('Please check your \"access.settings\" for request:', req)\n }\n }\n\n const fieldMap = {}\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 fields: fieldMap,\n isConfigAllowed,\n })\n },\n method: 'get',\n path: PLUGIN_FETCH_FIELDS_ENDPOINT,\n }\n}\n"],"names":["PLUGIN_FETCH_FIELDS_ENDPOINT","PLUGIN_INSTRUCTIONS_TABLE","fetchFields","access","handler","req","docs","payload","find","collection","pagination","isConfigAllowed","settings","e","logger","error","fieldMap","forEach","doc","id","fieldType","Response","json","fields","method","path"],"mappings":"AAIA,SAASA,4BAA4B,EAAEC,yBAAyB,QAAQ,iBAAgB;AAExF,OAAO,MAAMC,cAAwD,CAACC;IACpE,OAAO;QACLC,SAAS,OAAOC;YACd,MAAM,EAAEC,OAAO,EAAE,EAAE,GAAG,MAAMD,IAAIE,OAAO,CAACC,IAAI,CAAC;gBAC3CC,YAAYR;gBACZS,YAAY;YACd;YAEA,IAAIC,kBAAkB,KAAK,6CAA6C;;YAExE,IAAIR,QAAQS,UAAU;gBACpB,IAAI;oBACFD,kBAAkB,MAAMR,OAAOS,QAAQ,CAAC;wBAAEP;oBAAI;gBAChD,EAAE,OAAOQ,GAAG;oBACVR,IAAIE,OAAO,CAACO,MAAM,CAACC,KAAK,CAAC,oDAAoDV;gBAC/E;YACF;YAEA,MAAMW,WAAW,CAAC;YAClBV,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;gBACnBC,QAAQP;gBACRL;YACF;QACF;QACAa,QAAQ;QACRC,MAAMzB;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/endpoints/fetchFields.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload'\n\nimport type { PluginConfigAccess, PluginOptions } from '../types.js'\n\nimport { PLUGIN_FETCH_FIELDS_ENDPOINT, PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\n\nexport const fetchFields: (access: PluginConfigAccess, options?: PluginOptions) => Endpoint = (\n access,\n options = {},\n) => {\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('Please check your \"access.settings\" for request:', req)\n }\n }\n\n const fieldMap = {}\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 })\n },\n method: 'get',\n path: PLUGIN_FETCH_FIELDS_ENDPOINT,\n }\n}\n"],"names":["PLUGIN_FETCH_FIELDS_ENDPOINT","PLUGIN_INSTRUCTIONS_TABLE","fetchFields","access","options","handler","req","docs","payload","find","collection","pagination","isConfigAllowed","settings","e","logger","error","fieldMap","forEach","doc","id","fieldType","Response","json","fields","method","path"],"mappings":"AAIA,SAASA,4BAA4B,EAAEC,yBAAyB,QAAQ,iBAAgB;AAExF,OAAO,MAAMC,cAAiF,CAC5FC,QACAC,UAAU,CAAC,CAAC;IAEZ,OAAO;QACLC,SAAS,OAAOC;YACd,MAAM,EAAEC,OAAO,EAAE,EAAE,GAAG,MAAMD,IAAIE,OAAO,CAACC,IAAI,CAAC;gBAC3CC,YAAYT;gBACZU,YAAY;YACd;YAEA,IAAIC,kBAAkB,KAAK,6CAA6C;;YAExE,IAAIT,QAAQU,UAAU;gBACpB,IAAI;oBACFD,kBAAkB,MAAMT,OAAOU,QAAQ,CAAC;wBAAEP;oBAAI;gBAChD,EAAE,OAAOQ,GAAG;oBACVR,IAAIE,OAAO,CAACO,MAAM,CAACC,KAAK,CAAC,oDAAoDV;gBAC/E;YACF;YAEA,MAAMW,WAAW,CAAC;YAClBV,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,GAAGnB,OAAO;gBACVoB,QAAQP;gBACRL;YACF;QACF;QACAa,QAAQ;QACRC,MAAM1B;IACR;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/endpoints/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAmB,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAyE3E,eAAO,MAAM,SAAS,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,SAwNhC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/endpoints/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAmB,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AA2G3E,eAAO,MAAM,SAAS,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,SAwPhC,CAAA"}
@@ -7,7 +7,25 @@ import { handlebarsHelpersMap } from '../libraries/handlebars/helpersMap.js';
7
7
  import { replacePlaceholders } from '../libraries/handlebars/replacePlaceholders.js';
8
8
  import { extractImageData } from '../utilities/extractImageData.js';
9
9
  import { getGenerationModels } from '../utilities/getGenerationModels.js';
10
- const assignPrompt = async (action, { type, actionParams, context, field, layout, systemPrompt = '', template })=>{
10
+ const requireAuthentication = (req)=>{
11
+ if (!req.user) {
12
+ throw new Error('Authentication required. Please log in to use AI features.');
13
+ }
14
+ return true;
15
+ };
16
+ const checkAccess = async (req, pluginConfig)=>{
17
+ requireAuthentication(req);
18
+ if (pluginConfig.access?.generate) {
19
+ const hasAccess = await pluginConfig.access.generate({
20
+ req
21
+ });
22
+ if (!hasAccess) {
23
+ throw new Error('Insufficient permissions to use AI generation features.');
24
+ }
25
+ }
26
+ return true;
27
+ };
28
+ const assignPrompt = async (action, { type, actionParams, context, field, layout, locale, systemPrompt = '', template })=>{
11
29
  const prompt = await replacePlaceholders(template, context);
12
30
  const toLexicalHTML = type === 'richText' ? handlebarsHelpersMap.toHTML.name : '';
13
31
  const assignedPrompts = {
@@ -17,6 +35,16 @@ const assignPrompt = async (action, { type, actionParams, context, field, layout
17
35
  system: type === 'richText' ? systemPrompt : undefined
18
36
  };
19
37
  if (action === 'Compose') {
38
+ if (locale && locale !== 'en') {
39
+ /**
40
+ * NOTE: Avoid using the "system prompt" for setting the output language,
41
+ * as it causes quotation marks to appear in the output (Currently only tested with openai models).
42
+ * Appending the language instruction directly to the prompt resolves this issue.
43
+ **/ assignedPrompts.prompt += `
44
+ ---
45
+ OUTPUT LANGUAGE: ${locale}
46
+ `;
47
+ }
20
48
  return assignedPrompts;
21
49
  }
22
50
  const { layout: getLayout, system: getSystemPrompt } = defaultPrompts.find((p)=>p.name === action);
@@ -40,51 +68,56 @@ export const endpoints = (pluginConfig)=>({
40
68
  textarea: {
41
69
  //TODO: This is the main endpoint for generating content - its just needs to be renamed to 'generate' or something.
42
70
  handler: async (req)=>{
43
- const data = await req.json?.();
44
- const { allowedEditorNodes = [], locale = 'en', options } = data;
45
- const { action, actionParams, instructionId } = options;
46
- const contextData = data.doc;
47
- if (!instructionId) {
48
- throw new Error(`Instruction ID is required for "${PLUGIN_NAME}" to work, please check your configuration`);
49
- }
50
- const instructions = await req.payload.findByID({
51
- id: instructionId,
52
- collection: PLUGIN_INSTRUCTIONS_TABLE
53
- });
54
- const { collections } = req.payload.config;
55
- const collection = collections.find((collection)=>collection.slug === PLUGIN_INSTRUCTIONS_TABLE);
56
- const { custom: { [PLUGIN_NAME]: { editorConfig = {} } = {} } = {} } = collection.admin;
57
- const { schema: editorSchema = {} } = editorConfig;
58
- const { prompt: promptTemplate = '' } = instructions;
59
- let allowedEditorSchema = editorSchema;
60
- if (allowedEditorNodes.length) {
61
- allowedEditorSchema = filterEditorSchemaByNodes(editorSchema, allowedEditorNodes);
62
- }
63
- const schemaPath = instructions['schema-path'];
64
- const fieldName = schemaPath?.split('.').pop();
65
- registerEditorHelper(req.payload, schemaPath);
66
- const { defaultLocale, locales = [] } = req.payload.config.localization || {};
67
- const localeData = locales.find((l)=>{
68
- return l.code === locale;
69
- });
70
- const localeInfo = localeData?.label[defaultLocale] || locale;
71
- const model = getGenerationModels(pluginConfig).find((model)=>model.id === instructions['model-id']);
72
- // @ts-expect-error
73
- const settingsName = model.settings?.name;
74
- if (!settingsName) {
75
- req.payload.logger.error('— AI Plugin: Error fetching settings name!');
76
- }
77
- const modelOptions = instructions[settingsName] || {};
78
- const prompts = await assignPrompt(action, {
79
- type: instructions['field-type'],
80
- actionParams,
81
- context: contextData,
82
- field: fieldName,
83
- layout: instructions.layout,
84
- systemPrompt: instructions.system,
85
- template: promptTemplate
86
- });
87
71
  try {
72
+ // Check authentication and authorization first
73
+ await checkAccess(req, pluginConfig);
74
+ const data = await req.json?.();
75
+ const { allowedEditorNodes = [], locale = 'en', options } = data;
76
+ const { action, actionParams, instructionId } = options;
77
+ const contextData = data.doc;
78
+ if (!instructionId) {
79
+ throw new Error(`Instruction ID is required for "${PLUGIN_NAME}" to work, please check your configuration`);
80
+ }
81
+ // Verify user has access to the specific instruction
82
+ const instructions = await req.payload.findByID({
83
+ id: instructionId,
84
+ collection: PLUGIN_INSTRUCTIONS_TABLE,
85
+ req
86
+ });
87
+ const { collections } = req.payload.config;
88
+ const collection = collections.find((collection)=>collection.slug === PLUGIN_INSTRUCTIONS_TABLE);
89
+ const { custom: { [PLUGIN_NAME]: { editorConfig = {} } = {} } = {} } = collection.admin;
90
+ const { schema: editorSchema = {} } = editorConfig;
91
+ const { prompt: promptTemplate = '' } = instructions;
92
+ let allowedEditorSchema = editorSchema;
93
+ if (allowedEditorNodes.length) {
94
+ allowedEditorSchema = filterEditorSchemaByNodes(editorSchema, allowedEditorNodes);
95
+ }
96
+ const schemaPath = instructions['schema-path'];
97
+ const fieldName = schemaPath?.split('.').pop();
98
+ registerEditorHelper(req.payload, schemaPath);
99
+ const { defaultLocale, locales = [] } = req.payload.config.localization || {};
100
+ const localeData = locales.find((l)=>{
101
+ return l.code === locale;
102
+ });
103
+ const localeInfo = localeData?.label[defaultLocale] || locale;
104
+ const model = getGenerationModels(pluginConfig).find((model)=>model.id === instructions['model-id']);
105
+ // @ts-expect-error
106
+ const settingsName = model.settings?.name;
107
+ if (!settingsName) {
108
+ req.payload.logger.error('— AI Plugin: Error fetching settings name!');
109
+ }
110
+ const modelOptions = instructions[settingsName] || {};
111
+ const prompts = await assignPrompt(action, {
112
+ type: instructions['field-type'],
113
+ actionParams,
114
+ context: contextData,
115
+ field: fieldName,
116
+ layout: instructions.layout,
117
+ locale: localeInfo,
118
+ systemPrompt: instructions.system,
119
+ template: promptTemplate
120
+ });
88
121
  return model.handler?.(prompts.prompt, {
89
122
  ...modelOptions,
90
123
  editorSchema: allowedEditorSchema,
@@ -94,8 +127,13 @@ export const endpoints = (pluginConfig)=>({
94
127
  });
95
128
  } catch (error) {
96
129
  req.payload.logger.error('Error generating content: ', error);
97
- return new Response(JSON.stringify(error.message), {
98
- status: 500
130
+ return new Response(JSON.stringify({
131
+ error: error.message
132
+ }), {
133
+ headers: {
134
+ 'Content-Type': 'application/json'
135
+ },
136
+ status: error.message.includes('Authentication required') || error.message.includes('Insufficient permissions') ? 401 : 500
99
137
  });
100
138
  }
101
139
  },
@@ -104,107 +142,125 @@ export const endpoints = (pluginConfig)=>({
104
142
  },
105
143
  upload: {
106
144
  handler: async (req)=>{
107
- const data = await req.json?.();
108
- const { collectionSlug, documentId, options } = data;
109
- const { instructionId } = options;
110
- let docData = {};
111
- if (documentId) {
112
- try {
113
- docData = await req.payload.findByID({
114
- id: documentId,
115
- collection: collectionSlug,
116
- draft: true
145
+ try {
146
+ // Check authentication and authorization first
147
+ await checkAccess(req, pluginConfig);
148
+ const data = await req.json?.();
149
+ const { collectionSlug, documentId, options } = data;
150
+ const { instructionId } = options;
151
+ let docData = {};
152
+ if (documentId) {
153
+ try {
154
+ docData = await req.payload.findByID({
155
+ id: documentId,
156
+ collection: collectionSlug,
157
+ draft: true,
158
+ req
159
+ });
160
+ } catch (e) {
161
+ req.payload.logger.error('— AI Plugin: Error fetching document, you should try again after enabling drafts for this collection');
162
+ }
163
+ }
164
+ const contextData = {
165
+ ...data.doc,
166
+ ...docData
167
+ };
168
+ let instructions = {
169
+ images: [],
170
+ 'model-id': '',
171
+ prompt: ''
172
+ };
173
+ if (instructionId) {
174
+ // Verify user has access to the specific instruction
175
+ // @ts-expect-error
176
+ instructions = await req.payload.findByID({
177
+ id: instructionId,
178
+ collection: PLUGIN_INSTRUCTIONS_TABLE,
179
+ req
117
180
  });
118
- } catch (e) {
119
- req.payload.logger.error('— AI Plugin: Error fetching document, you should try again after enabling drafts for this collection');
120
181
  }
121
- }
122
- const contextData = {
123
- ...data.doc,
124
- ...docData
125
- };
126
- let instructions = {
127
- images: [],
128
- 'model-id': '',
129
- prompt: ''
130
- };
131
- if (instructionId) {
182
+ const { images: sampleImages = [], prompt: promptTemplate = '' } = instructions;
183
+ const schemaPath = instructions['schema-path'];
184
+ registerEditorHelper(req.payload, schemaPath);
185
+ const text = await replacePlaceholders(promptTemplate, contextData);
186
+ const modelId = instructions['model-id'];
187
+ const uploadCollectionSlug = instructions['relation-to'];
188
+ const images = [
189
+ ...extractImageData(text),
190
+ ...sampleImages
191
+ ];
192
+ const editImages = [];
193
+ for (const img of images){
194
+ try {
195
+ const serverURL = req.payload.config?.serverURL || process.env.SERVER_URL || process.env.NEXT_PUBLIC_SERVER_URL;
196
+ const response = await fetch(`${serverURL}${img.image.url}`, {
197
+ headers: {
198
+ //TODO: Further testing needed or so find a proper way.
199
+ Authorization: `Bearer ${req.headers.get('Authorization')?.split('Bearer ')[1] || ''}`
200
+ },
201
+ method: 'GET'
202
+ });
203
+ const blob = await response.blob();
204
+ editImages.push({
205
+ name: img.image.name,
206
+ type: img.image.type,
207
+ data: blob,
208
+ size: blob.size,
209
+ url: `${serverURL}${img.image.url}`
210
+ });
211
+ } catch (e) {
212
+ req.payload.logger.error('Error fetching reference images!');
213
+ console.error(e);
214
+ throw Error("We couldn't fetch the images. Please ensure the images are accessible and hosted publicly.");
215
+ }
216
+ }
217
+ const model = getGenerationModels(pluginConfig).find((model)=>model.id === modelId);
132
218
  // @ts-expect-error
133
- instructions = await req.payload.findByID({
134
- id: instructionId,
135
- collection: PLUGIN_INSTRUCTIONS_TABLE
136
- });
137
- }
138
- const { images: sampleImages = [], prompt: promptTemplate = '' } = instructions;
139
- const schemaPath = instructions['schema-path'];
140
- registerEditorHelper(req.payload, schemaPath);
141
- const text = await replacePlaceholders(promptTemplate, contextData);
142
- const modelId = instructions['model-id'];
143
- const uploadCollectionSlug = instructions['relation-to'];
144
- const images = [
145
- ...extractImageData(text),
146
- ...sampleImages
147
- ];
148
- const editImages = [];
149
- for (const img of images){
150
- try {
151
- const serverURL = req.payload.config?.serverURL || process.env.SERVER_URL || process.env.NEXT_PUBLIC_SERVER_URL;
152
- const response = await fetch(`${serverURL}${img.image.url}`, {
153
- headers: {
154
- //TODO: Further testing needed or so find a proper way.
155
- Authorization: `Bearer ${req.headers.get('Authorization')?.split('Bearer ')[1] || ''}`
156
- },
157
- method: 'GET'
219
+ const settingsName = model.settings?.name;
220
+ if (!settingsName) {
221
+ req.payload.logger.error('— AI Plugin: Error fetching settings name!');
222
+ }
223
+ let modelOptions = instructions[settingsName] || {};
224
+ modelOptions = {
225
+ ...modelOptions,
226
+ images: editImages
227
+ };
228
+ const result = await model.handler?.(text, modelOptions);
229
+ let assetData;
230
+ if (typeof pluginConfig.mediaUpload === 'function') {
231
+ assetData = await pluginConfig.mediaUpload(result, {
232
+ collection: uploadCollectionSlug,
233
+ request: req
158
234
  });
159
- const blob = await response.blob();
160
- editImages.push({
161
- name: img.image.name,
162
- type: img.image.type,
163
- data: blob,
164
- size: blob.size,
165
- url: `${serverURL}${img.image.url}`
235
+ } else {
236
+ assetData = await req.payload.create({
237
+ collection: uploadCollectionSlug,
238
+ data: result.data,
239
+ file: result.file,
240
+ req
166
241
  });
167
- } catch (e) {
168
- req.payload.logger.error('Error fetching reference images!');
169
- console.error(e);
170
- throw Error("We couldn't fetch the images. Please ensure the images are accessible and hosted publicly.");
171
242
  }
172
- }
173
- const model = getGenerationModels(pluginConfig).find((model)=>model.id === modelId);
174
- // @ts-expect-error
175
- const settingsName = model.settings?.name;
176
- if (!settingsName) {
177
- req.payload.logger.error('— AI Plugin: Error fetching settings name!');
178
- }
179
- let modelOptions = instructions[settingsName] || {};
180
- modelOptions = {
181
- ...modelOptions,
182
- images: editImages
183
- };
184
- const result = await model.handler?.(text, modelOptions);
185
- let assetData;
186
- if (typeof pluginConfig.mediaUpload === 'function') {
187
- assetData = await pluginConfig.mediaUpload(result, {
188
- collection: uploadCollectionSlug,
189
- request: req
190
- });
191
- } else {
192
- assetData = await req.payload.create({
193
- collection: uploadCollectionSlug,
194
- data: result.data,
195
- file: result.file
243
+ if (!assetData.id) {
244
+ req.payload.logger.error('Error uploading generated media, is your media upload function correct?');
245
+ throw new Error('Error uploading generated media!');
246
+ }
247
+ return new Response(JSON.stringify({
248
+ result: {
249
+ id: assetData.id,
250
+ alt: assetData.alt
251
+ }
252
+ }));
253
+ } catch (error) {
254
+ req.payload.logger.error('Error generating upload: ', error);
255
+ return new Response(JSON.stringify({
256
+ error: error.message
257
+ }), {
258
+ headers: {
259
+ 'Content-Type': 'application/json'
260
+ },
261
+ status: error.message.includes('Authentication required') || error.message.includes('Insufficient permissions') ? 401 : 500
196
262
  });
197
263
  }
198
- if (!assetData.id) {
199
- req.payload.logger.error('Error uploading generated media, is your media upload function correct?');
200
- throw new Error('Error uploading generated media!');
201
- }
202
- return new Response(JSON.stringify({
203
- result: {
204
- id: assetData.id,
205
- alt: assetData.alt
206
- }
207
- }));
208
264
  },
209
265
  method: 'post',
210
266
  path: PLUGIN_API_ENDPOINT_GENERATE_UPLOAD
@@ -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 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 { 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 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 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 systemPrompt: instructions.system,\n template: promptTemplate as string,\n })\n\n try {\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.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 { 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 })\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 // @ts-expect-error\n instructions = await req.payload.findByID({\n id: instructionId,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\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 })\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 },\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","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","allowedEditorNodes","locale","options","instructionId","contextData","doc","Error","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","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","headers","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,oBA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M,CAACC,KAAK,CACtB;oBAEF,MAAM,IAAIjC,MAAM;gBAClB;gBAEA,OAAO,IAAIoC,SACTC,KAAKC,SAAS,CAAC;oBACbiC,QAAQ;wBACNnE,IAAIoE,UAAUpE,EAAE;wBAChByE,KAAKL,UAAUK,GAAG;oBACpB;gBACF;YAEJ;YACApC,QAAQ;YACRC,MAAMpF;QACR;IACF,CAAA,EAAsB"}
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,QAAQ,CAAC;YAAEN;QAAI;QAC3D,IAAI,CAACO,WAAW;YACd,MAAM,IAAIL,MAAM;QAClB;IACF;IAEA,OAAO;AACT;AAEA,MAAMM,eAAe,OACnBC,QACA,EACEC,IAAI,EACJC,YAAY,EACZC,OAAO,EACPC,KAAK,EACLC,MAAM,EACNC,MAAM,EACNC,eAAe,EAAE,EACjBC,QAAQ,EAUT;IAED,MAAMC,SAAS,MAAMtB,oBAAoBqB,UAAUL;IACnD,MAAMO,gBAAgBT,SAAS,aAAaf,qBAAqByB,MAAM,CAACC,IAAI,GAAG;IAE/E,MAAMC,kBAAkB;QACtBR,QAAQJ,SAAS,aAAaI,SAASS;QACvCL;QACA,8CAA8C;QAC9CM,QAAQd,SAAS,aAAaM,eAAeO;IAC/C;IAEA,IAAId,WAAW,WAAW;QACxB,IAAIM,UAAUA,WAAW,MAAM;YAC7B;;;;QAIE,GACFO,gBAAgBJ,M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qE,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 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,MAAM,EAAgB,MAAM,SAAS,CAAA;AAIrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAyC9C,QAAA,MAAM,eAAe,GAClB,cAAc,YAAY,MACxB,gBAAgB,MAAM,KAAG,MAiHzB,CAAA;AAEL,OAAO,EAAE,eAAe,EAAE,CAAA"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,MAAM,EAAgB,MAAM,SAAS,CAAA;AAIrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AA4D9C,QAAA,MAAM,eAAe,GAClB,cAAc,YAAY,MACxB,gBAAgB,MAAM,KAAG,MA6HzB,CAAA;AAEL,OAAO,EAAE,eAAe,EAAE,CAAA"}
package/dist/plugin.js CHANGED
@@ -11,6 +11,10 @@ import { getGenerationModels } from './utilities/getGenerationModels.js';
11
11
  import { isPluginActivated } from './utilities/isPluginActivated.js';
12
12
  import { updateFieldsConfig } from './utilities/updateFieldsConfig.js';
13
13
  const defaultPluginConfig = {
14
+ access: {
15
+ generate: ({ req })=>!!req.user,
16
+ settings: ({ req })=>!!req.user
17
+ },
14
18
  collections: {},
15
19
  disableSponsorMessage: false,
16
20
  generatePromptOnInit: true,
@@ -35,10 +39,28 @@ const sponsorMessage = `
35
39
  ║ Thank you again, and happy building! ║
36
40
  ╚═══════════════════════════════════════════════════════════════╝
37
41
  `;
42
+ const securityMessage = `
43
+ ╔═══════════════════════════════════════════════════════════════╗
44
+ ║ SECURITY NOTICE ║
45
+ ║ ║
46
+ ║ The AI Plugin now requires authentication by default. ║
47
+ ║ All AI features are restricted to authenticated users. ║
48
+ ║ ║
49
+ ║ To customize access control, configure the 'access' option ║
50
+ ║ in your plugin settings. See documentation for details. ║
51
+ ║ ║
52
+ ║ If you need different access patterns, please configure ║
53
+ ║ them explicitly in your plugin configuration. ║
54
+ ╚═══════════════════════════════════════════════════════════════╝
55
+ `;
38
56
  const payloadAiPlugin = (pluginConfig)=>(incomingConfig)=>{
39
57
  pluginConfig = {
40
58
  ...defaultPluginConfig,
41
- ...pluginConfig
59
+ ...pluginConfig,
60
+ access: {
61
+ ...defaultPluginConfig.access,
62
+ ...pluginConfig.access
63
+ }
42
64
  };
43
65
  pluginConfig.generationModels = getGenerationModels(pluginConfig);
44
66
  const isActivated = isPluginActivated(pluginConfig);
@@ -102,7 +124,7 @@ const payloadAiPlugin = (pluginConfig)=>(incomingConfig)=>{
102
124
  ...incomingConfig.endpoints ?? [],
103
125
  pluginEndpoints.textarea,
104
126
  pluginEndpoints.upload,
105
- fetchFields(pluginConfig.access)
127
+ fetchFields(pluginConfig.access, pluginConfig.options)
106
128
  ],
107
129
  globals: globals.map((global)=>{
108
130
  if (globalsSlugs[global.slug]) {
@@ -133,6 +155,9 @@ const payloadAiPlugin = (pluginConfig)=>(incomingConfig)=>{
133
155
  console.error(error);
134
156
  payload.logger.error(`— AI Plugin: Initialization Error: ${error}`);
135
157
  }).finally(()=>{
158
+ setTimeout(()=>{
159
+ payload.logger.info(securityMessage);
160
+ }, 1000);
136
161
  if (!pluginConfig.disableSponsorMessage) {
137
162
  setTimeout(()=>{
138
163
  payload.logger.info(sponsorMessage);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { CollectionConfig, Config, GlobalConfig } from 'payload'\n\nimport { deepMerge } from 'payload/shared'\n\nimport type { PluginConfig } from './types.js'\n\nimport { defaultGenerationModels } from './ai/models/index.js'\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 { getGenerationModels } from './utilities/getGenerationModels.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 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\n pluginConfig = { ...defaultPluginConfig, ...pluginConfig }\n pluginConfig.generationModels = getGenerationModels(pluginConfig)\n\n const isActivated = isPluginActivated(pluginConfig)\n let updatedConfig: Config = { ...incomingConfig }\n let collectionsFieldPathMap = {}\n\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 globals = [...(incomingConfig.globals ?? [])]\n const { collections: collectionSlugs = [], globals: globalsSlugs = [] } = 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 as CollectionConfig\n }\n\n return collection\n }),\n endpoints: [\n ...(incomingConfig.endpoints ?? []),\n pluginEndpoints.textarea,\n pluginEndpoints.upload,\n fetchFields(pluginConfig.access),\n ],\n globals: globals.map((global) => {\n if (globalsSlugs[global.slug]) {\n const { schemaPathMap, updatedCollectionConfig } = updateFieldsConfig(global)\n collectionsFieldPathMap = {\n ...collectionsFieldPathMap,\n ...schemaPathMap,\n }\n return updatedCollectionConfig as GlobalConfig;\n }\n\n return global\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","defaultGenerationModels","lexicalJsonSchema","instructionsCollection","PLUGIN_NAME","fetchFields","endpoints","init","translations","getGenerationModels","isPluginActivated","updateFieldsConfig","defaultPluginConfig","collections","disableSponsorMessage","generatePromptOnInit","generationModels","sponsorMessage","payloadAiPlugin","pluginConfig","incomingConfig","isActivated","updatedConfig","collectionsFieldPathMap","Instructions","lexicalSchema","editorConfig","nodes","debugging","admin","hidden","custom","schema","globals","collectionSlugs","globalsSlugs","components","providers","updatedProviders","path","pluginEndpoints","map","collection","slug","schemaPathMap","updatedCollectionConfig","textarea","upload","access","global","i18n","onInit","payload","logger","warn","catch","error","console","finally","setTimeout","info"],"mappings":"AAEA,SAASA,SAAS,QAAQ,iBAAgB;AAI1C,SAASC,uBAAuB,QAAQ,uBAAsB;AAC9D,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,mBAAmB,QAAQ,qCAAoC;AACxE,SAASC,iBAAiB,QAAQ,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M,CAACC,IAAI,CAAC,CAAC,gEAAgE,CAAC;gBACtF;YACF;YAEA,MAAM/C,KAAK6C,SAAS7B,yBAAyBJ,cAC1CoC,KAAK,CAAC,CAACC;gBACNC,QAAQD,KAAK,CAACA;gBACdJ,QAAQC,MAAM,CAACG,KAAK,CAAC,CAAC,mCAAmC,EAAEA,OAAO;YACpE,GACCE,OAAO,CAAC;gBACP,IAAI,CAACvC,aAAaL,qBAAqB,EAAE;oBACvC6C,WAAW;wBACTP,QAAQC,MAAM,CAACO,IAAI,CAAC3C;oBACtB,GAAG;gBACL;YACF;QACJ;QAEA,OAAOK;IACT;AAEJ,SAASJ,eAAe,GAAE"}
1
+ {"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { CollectionConfig, Config, GlobalConfig } from 'payload'\n\nimport { deepMerge } from 'payload/shared'\n\nimport type { PluginConfig } from './types.js'\n\nimport { defaultGenerationModels } from './ai/models/index.js'\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 { getGenerationModels } from './utilities/getGenerationModels.js'\nimport { isPluginActivated } from './utilities/isPluginActivated.js'\nimport { updateFieldsConfig } from './utilities/updateFieldsConfig.js'\n\nconst defaultPluginConfig: PluginConfig = {\n access: {\n generate: ({ req }) => !!req.user,\n settings: ({ req }) => !!req.user,\n },\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 securityMessage = `\n╔═══════════════════════════════════════════════════════════════╗\n║ SECURITY NOTICE ║\n║ ║\n║ The AI Plugin now requires authentication by default. ║\n║ All AI features are restricted to authenticated users. ║\n║ ║\n║ To customize access control, configure the 'access' option ║\n║ in your plugin settings. See documentation for details. ║\n║ ║\n║ If you need different access patterns, please configure ║\n║ them explicitly in your plugin configuration. ║\n╚═══════════════════════════════════════════════════════════════╝\n`\n\nconst payloadAiPlugin =\n (pluginConfig: PluginConfig) =>\n (incomingConfig: Config): Config => {\n\n pluginConfig = { \n ...defaultPluginConfig, \n ...pluginConfig,\n access: {\n ...defaultPluginConfig.access,\n ...pluginConfig.access,\n }\n }\n \n pluginConfig.generationModels = getGenerationModels(pluginConfig)\n\n const isActivated = isPluginActivated(pluginConfig)\n let updatedConfig: Config = { ...incomingConfig }\n let collectionsFieldPathMap = {}\n\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 globals = [...(incomingConfig.globals ?? [])]\n const { collections: collectionSlugs = [], globals: globalsSlugs = [] } = 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 as CollectionConfig\n }\n\n return collection\n }),\n endpoints: [\n ...(incomingConfig.endpoints ?? []),\n pluginEndpoints.textarea,\n pluginEndpoints.upload,\n fetchFields(pluginConfig.access, pluginConfig.options),\n ],\n globals: globals.map((global) => {\n if (globalsSlugs[global.slug]) {\n const { schemaPathMap, updatedCollectionConfig } = updateFieldsConfig(global)\n collectionsFieldPathMap = {\n ...collectionsFieldPathMap,\n ...schemaPathMap,\n }\n return updatedCollectionConfig as GlobalConfig;\n }\n\n return global\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 setTimeout(() => {\n payload.logger.info(securityMessage)\n }, 1000)\n \n if (!pluginConfig.disableSponsorMessage) {\n setTimeout(() => {\n payload.logger.info(sponsorMessage)\n }, 3000)\n }\n })\n }\n\n return updatedConfig\n }\n\nexport { payloadAiPlugin }"],"names":["deepMerge","defaultGenerationModels","lexicalJsonSchema","instructionsCollection","PLUGIN_NAME","fetchFields","endpoints","init","translations","getGenerationModels","isPluginActivated","updateFieldsConfig","defaultPluginConfig","access","generate","req","user","settings","collections","disableSponsorMessage","generatePromptOnInit","generationModels","sponsorMessage","securityMessage","payloadAiPlugin","pluginConfig","incomingConfig","isActivated","updatedConfig","collectionsFieldPathMap","Instructions","lexicalSchema","editorConfig","nodes","debugging","admin","hidden","custom","schema","globals","collectionSlugs","globalsSlugs","components","providers","updatedProviders","path","pluginEndpoints","map","collection","slug","schemaPathMap","updatedCollectionConfig","textarea","upload","options","global","i18n","onInit","payload","logger","warn","catch","error","console","finally","setTimeout","info"],"mappings":"AAEA,SAASA,SAAS,QAAQ,iBAAgB;AAI1C,SAASC,uBAAuB,QAAQ,uBAAsB;AAC9D,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,mBAAmB,QAAQ,qCAAoC;AACxE,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,kBAAkB,QAAQ,oCAAmC;AAEtE,MAAMC,sBAAoC;IACxCC,QAAQ;QACNC,UAAU,CAAC,EAAEC,GAAG,EAAE,GAAK,CAAC,CAACA,IAAIC,IAAI;QACjCC,UAAU,CAAC,EAAEF,GAAG,EAAE,GAAK,CAAC,CAACA,IAAIC,IAAI;IACnC;IACAE,aAAa,CAAC;IACdC,uBAAuB;IACvBC,sBAAsB;IACtBC,kBAAkBpB;AACpB;AAEA,MAAMqB,iBAAiB,CAAC;;;;;;;;;;;;;;;;;;AAkBxB,CAAC;AAED,MAAMC,kBAAkB,CAAC;;;;;;;;;;;;;AAazB,CAAC;AAED,MAAMC,kBACJ,CAACC,eACC,CAACC;QAECD,eAAe;YACb,GAAGb,mBAAmB;YACtB,GAA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ACG,KAAK,CAAC,CAAC,mCAAmC,EAAEA,OAAO;YACpE,GACCE,OAAO,CAAC;gBACPC,WAAW;oBACTP,QAAQC,MAAM,CAACO,IAAI,CAAC3C;gBACtB,GAAG;gBAEH,IAAI,CAACE,aAAaN,qBAAqB,EAAE;oBACvC8C,WAAW;wBACTP,QAAQC,MAAM,CAACO,IAAI,CAAC5C;oBACtB,GAAG;gBACL;YACF;QACJ;QAEA,OAAOM;IACT;AAEJ,SAASJ,eAAe,GAAE"}
@@ -2,6 +2,7 @@ import type { Field } from 'payload';
2
2
  import React from 'react';
3
3
  export declare const InstructionsContext: React.Context<{
4
4
  activeCollection?: string;
5
+ enabledLanguages?: string[];
5
6
  field?: Field;
6
7
  instructions: Record<string, any>;
7
8
  isConfigAllowed: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"InstructionsProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/InstructionsProvider/InstructionsProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAGpC,OAAO,KAA6C,MAAM,OAAO,CAAA;AAoBjE,eAAO,MAAM,mBAAmB;uBAfX,MAAM;YACjB,KAAK;kBACC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;qBAChB,OAAO;WACjB,MAAM;iBACA,OAAO;0BACE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI;EASkB,CAAA;AAEhE,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAkCxC,CAAA"}
1
+ {"version":3,"file":"InstructionsProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/InstructionsProvider/InstructionsProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAGpC,OAAO,KAA6C,MAAM,OAAO,CAAA;AAqBjE,eAAO,MAAM,mBAAmB;uBAhBX,MAAM;uBACN,MAAM,EAAE;YACnB,KAAK;kBACC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;qBAChB,OAAO;WACjB,MAAM;iBACA,OAAO;0BACE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI;EASkB,CAAA;AAEhE,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EA0CxC,CAAA"}
@@ -15,6 +15,7 @@ export const InstructionsProvider = ({ children })=>{
15
15
  const [instructions, setInstructionsState] = useState({});
16
16
  const [activeCollection, setActiveCollection] = useState('');
17
17
  const [isConfigAllowed, setIsConfigAllowed] = useState(false);
18
+ const [enabledLanguages, setEnabledLanguages] = useState();
18
19
  const { user } = useAuth();
19
20
  const { config } = useConfig();
20
21
  const { routes: { api }, serverURL } = config;
@@ -24,6 +25,7 @@ export const InstructionsProvider = ({ children })=>{
24
25
  fetch(`${serverURL}${api}${PLUGIN_FETCH_FIELDS_ENDPOINT}`).then(async (res)=>{
25
26
  await res.json().then((data)=>{
26
27
  setIsConfigAllowed(data?.isConfigAllowed);
28
+ setEnabledLanguages(data?.enabledLanguages);
27
29
  setInstructionsState(data?.fields);
28
30
  });
29
31
  }).catch((err)=>{
@@ -35,6 +37,7 @@ export const InstructionsProvider = ({ children })=>{
35
37
  return /*#__PURE__*/ _jsx(InstructionsContext.Provider, {
36
38
  value: {
37
39
  activeCollection,
40
+ enabledLanguages,
38
41
  instructions,
39
42
  isConfigAllowed,
40
43
  setActiveCollection
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/providers/InstructionsProvider/InstructionsProvider.tsx"],"sourcesContent":["'use client'\n\nimport type { Field } from 'payload'\n\nimport { useAuth, useConfig } from '@payloadcms/ui'\nimport React, { createContext, useEffect, useState } from 'react'\n\nimport { PLUGIN_FETCH_FIELDS_ENDPOINT } from '../../defaults.js'\n\nconst initialContext: {\n activeCollection?: string\n field?: Field\n instructions: Record<string, any>\n isConfigAllowed: boolean\n path?: string\n schemaPath?: unknown\n setActiveCollection?: (val: unknown) => void\n} = {\n field: undefined,\n instructions: undefined,\n isConfigAllowed: true,\n path: '',\n schemaPath: '',\n}\n\nexport const InstructionsContext = createContext(initialContext)\n\nexport const InstructionsProvider: React.FC = ({ children }: { children: React.ReactNode }) => {\n const [instructions, setInstructionsState] = useState({})\n const [activeCollection, setActiveCollection] = useState('')\n const [isConfigAllowed, setIsConfigAllowed] = useState(false)\n const { user } = useAuth()\n\n const { config } = useConfig()\n const {\n routes: { api },\n serverURL,\n } = config\n\n // This is here because each field have separate instructions and\n // their ID is needed to edit them for Drawer\n useEffect(() => {\n fetch(`${serverURL}${api}${PLUGIN_FETCH_FIELDS_ENDPOINT}`)\n .then(async (res) => {\n await res.json().then((data) => {\n setIsConfigAllowed(data?.isConfigAllowed)\n setInstructionsState(data?.fields)\n })\n })\n .catch((err) => {\n console.error('InstructionsProvider:', err)\n })\n }, [user])\n\n return (\n <InstructionsContext.Provider\n value={{ activeCollection, instructions, isConfigAllowed, setActiveCollection }}\n >\n {children}\n </InstructionsContext.Provider>\n )\n}\n"],"names":["useAuth","useConfig","React","createContext","useEffect","useState","PLUGIN_FETCH_FIELDS_ENDPOINT","initialContext","field","undefined","instructions","isConfigAllowed","path","schemaPath","InstructionsContext","InstructionsProvider","children","setInstructionsState","activeCollection","setActiveCollection","setIsConfigAllowed","user","config","routes","api","serverURL","fetch","then","res","json","data","fields","catch","err","console","error","Provider","value"],"mappings":"AAAA;;AAIA,SAASA,OAAO,EAAEC,SAAS,QAAQ,iBAAgB;AACnD,OAAOC,SAASC,aAAa,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAEjE,SAASC,4BAA4B,QAAQ,oBAAmB;AAEhE,MAAMC,iBAQF;IACFC,OAAOC;IACPC,cAAcD;IACdE,iBAAiB;IACjBC,MAAM;IACNC,YAAY;AACd;AAEA,OAAO,MAAMC,oCAAsBX,cAAcI,gBAAe;AAEhE,OAAO,MAAMQ,uBAAiC,CAAC,EAAEC,QAAQ,EAAiC;IACxF,MAAM,CAACN,cAAcO,qBAAqB,GAAGZ,SAAS,CAAC;IACvD,MAAM,CAACa,kBAAkBC,oBAAoB,GAAGd,SAAS;IACzD,MAAM,CAACM,iBAAiBS,mBAAmB,GAAGf,SAAS;IACvD,MAAM,EAAEgB,IAAI,EAAE,GAAGrB;IAEjB,MAAM,EAAEsB,MAAM,EAAE,GAAGrB;IACnB,MAAM,EACJsB,QAAQ,EAAEC,GAAG,EAAE,EACfC,SAAS,EACV,GAAGH;IAEJ,iEAAiE;IACjE,6CAA6C;IAC7ClB,UAAU;QACRsB,MAAM,GAAGD,YAAYD,MAAMlB,8BAA8B,EACtDqB,IAAI,CAAC,OAAOC;YACX,MAAMA,IAAIC,IAAI,GAAGF,IAAI,CAAC,CAACG;gBACrBV,mBAAmBU,MAAMnB;gBACzBM,qBAAqBa,MAAMC;YAC7B;QACF,GACCC,KAAK,CAAC,CAACC;YACNC,QAAQC,KAAK,CAAC,yBAAyBF;QACzC;IACJ,GAAG;QAACZ;KAAK;IAET,qBACE,KAACP,oBAAoBsB,QAAQ;QAC3BC,OAAO;YAAEnB;YAAkBR;YAAcC;YAAiBQ;QAAoB;kBAE7EH;;AAGP,EAAC"}
1
+ {"version":3,"sources":["../../../src/providers/InstructionsProvider/InstructionsProvider.tsx"],"sourcesContent":["'use client'\n\nimport type { Field } from 'payload'\n\nimport { useAuth, useConfig } from '@payloadcms/ui'\nimport React, { createContext, useEffect, useState } from 'react'\n\nimport { PLUGIN_FETCH_FIELDS_ENDPOINT } from '../../defaults.js'\n\nconst initialContext: {\n activeCollection?: string\n enabledLanguages?: string[]\n field?: Field\n instructions: Record<string, any>\n isConfigAllowed: boolean\n path?: string\n schemaPath?: unknown\n setActiveCollection?: (val: unknown) => void\n} = {\n field: undefined,\n instructions: undefined,\n isConfigAllowed: true,\n path: '',\n schemaPath: '',\n}\n\nexport const InstructionsContext = createContext(initialContext)\n\nexport const InstructionsProvider: React.FC = ({ children }: { children: React.ReactNode }) => {\n const [instructions, setInstructionsState] = useState({})\n const [activeCollection, setActiveCollection] = useState('')\n const [isConfigAllowed, setIsConfigAllowed] = useState(false)\n const [enabledLanguages, setEnabledLanguages] = useState<string[]>()\n const { user } = useAuth()\n\n const { config } = useConfig()\n const {\n routes: { api },\n serverURL,\n } = config\n\n // This is here because each field have separate instructions and\n // their ID is needed to edit them for Drawer\n useEffect(() => {\n fetch(`${serverURL}${api}${PLUGIN_FETCH_FIELDS_ENDPOINT}`)\n .then(async (res) => {\n await res.json().then((data) => {\n setIsConfigAllowed(data?.isConfigAllowed)\n setEnabledLanguages(data?.enabledLanguages)\n setInstructionsState(data?.fields)\n })\n })\n .catch((err) => {\n console.error('InstructionsProvider:', err)\n })\n }, [user])\n\n return (\n <InstructionsContext.Provider\n value={{\n activeCollection,\n enabledLanguages,\n instructions,\n isConfigAllowed,\n setActiveCollection,\n }}\n >\n {children}\n </InstructionsContext.Provider>\n )\n}\n"],"names":["useAuth","useConfig","React","createContext","useEffect","useState","PLUGIN_FETCH_FIELDS_ENDPOINT","initialContext","field","undefined","instructions","isConfigAllowed","path","schemaPath","InstructionsContext","InstructionsProvider","children","setInstructionsState","activeCollection","setActiveCollection","setIsConfigAllowed","enabledLanguages","setEnabledLanguages","user","config","routes","api","serverURL","fetch","then","res","json","data","fields","catch","err","console","error","Provider","value"],"mappings":"AAAA;;AAIA,SAASA,OAAO,EAAEC,SAAS,QAAQ,iBAAgB;AACnD,OAAOC,SAASC,aAAa,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAEjE,SAASC,4BAA4B,QAAQ,oBAAmB;AAEhE,MAAMC,iBASF;IACFC,OAAOC;IACPC,cAAcD;IACdE,iBAAiB;IACjBC,MAAM;IACNC,YAAY;AACd;AAEA,OAAO,MAAMC,oCAAsBX,cAAcI,gBAAe;AAEhE,OAAO,MAAMQ,uBAAiC,CAAC,EAAEC,QAAQ,EAAiC;IACxF,MAAM,CAACN,cAAcO,qBAAqB,GAAGZ,SAAS,CAAC;IACvD,MAAM,CAACa,kBAAkBC,oBAAoB,GAAGd,SAAS;IACzD,MAAM,CAACM,iBAAiBS,mBAAmB,GAAGf,SAAS;IACvD,MAAM,CAACgB,kBAAkBC,oBAAoB,GAAGjB;IAChD,MAAM,EAAEkB,IAAI,EAAE,GAAGvB;IAEjB,MAAM,EAAEwB,MAAM,EAAE,GAAGvB;IACnB,MAAM,EACJwB,QAAQ,EAAEC,GAAG,EAAE,EACfC,SAAS,EACV,GAAGH;IAEJ,iEAAiE;IACjE,6CAA6C;IAC7CpB,UAAU;QACRwB,MAAM,GAAGD,YAAYD,MAAMpB,8BAA8B,EACtDuB,IAAI,CAAC,OAAOC;YACX,MAAMA,IAAIC,IAAI,GAAGF,IAAI,CAAC,CAACG;gBACrBZ,mBAAmBY,MAAMrB;gBACzBW,oBAAoBU,MAAMX;gBAC1BJ,qBAAqBe,MAAMC;YAC7B;QACF,GACCC,KAAK,CAAC,CAACC;YACNC,QAAQC,KAAK,CAAC,yBAAyBF;QACzC;IACJ,GAAG;QAACZ;KAAK;IAET,qBACE,KAACT,oBAAoBwB,QAAQ;QAC3BC,OAAO;YACLrB;YACAG;YACAX;YACAC;YACAQ;QACF;kBAECH;;AAGP,EAAC"}
package/dist/types.d.ts CHANGED
@@ -3,10 +3,30 @@ import type { ImageGenerateParams } from 'openai/resources/images';
3
3
  import type { CollectionSlug, DataFromCollectionSlug, Endpoint, Field, File, GlobalConfig, GroupField, PayloadRequest } from 'payload';
4
4
  import type { CSSProperties, MouseEventHandler } from 'react';
5
5
  export interface PluginConfigAccess {
6
+ /**
7
+ * Control access to AI generation features (generate text, images, audio)
8
+ * @default () => !!req.user (requires authentication)
9
+ */
10
+ generate?: ({ req }: {
11
+ req: PayloadRequest;
12
+ }) => Promise<boolean> | boolean;
13
+ /**
14
+ * Control access to AI settings/configuration
15
+ * @default () => !!req.user (requires authentication)
16
+ */
6
17
  settings?: ({ req }: {
7
18
  req: PayloadRequest;
8
19
  }) => Promise<boolean> | boolean;
9
20
  }
21
+ export interface PluginOptions {
22
+ /**
23
+ * Provide local tags to filter language options from the Translate Menu
24
+ * Check for the available local tags,
25
+ * visit: https://www.npmjs.com/package/locale-codes
26
+ * Example: ["en-US", "zh-SG", "zh-CN", "en"]
27
+ */
28
+ enabledLanguages?: string[];
29
+ }
10
30
  export type PluginConfigMediaUploadFunction = (result: {
11
31
  data: Record<any, any>;
12
32
  file: File;
@@ -15,6 +35,10 @@ export type PluginConfigMediaUploadFunction = (result: {
15
35
  request: PayloadRequest;
16
36
  }) => Promise<DataFromCollectionSlug<CollectionSlug>>;
17
37
  export interface PluginConfig {
38
+ /**
39
+ * Access control configuration for AI features
40
+ * By default, all AI features require authentication
41
+ */
18
42
  access?: PluginConfigAccess;
19
43
  collections: {
20
44
  [key: CollectionSlug]: boolean;
@@ -32,6 +56,7 @@ export interface PluginConfig {
32
56
  };
33
57
  interfaceName?: string;
34
58
  mediaUpload?: PluginConfigMediaUploadFunction;
59
+ options?: PluginOptions;
35
60
  uploadCollectionSlug?: CollectionSlug;
36
61
  }
37
62
  export interface GenerationModel {
@@ -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,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAClE,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,UAAU,EACV,cAAc,EACf,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAE7D,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE;QAAE,GAAG,EAAE,cAAc,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAA;CAC5E;AAED,MAAM,MAAM,+BAA+B,GAAG,CAC5C,MAAM,EAAE;IAAE,IA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A;IAC/C,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAA;IACjC,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,CAAC,EAAE,cAAc,EAAE,CAAA;IACzB,IAAI,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAA;IAClC,KAAK,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAA;IACpC,OAAO,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAA;CACvC,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 { ImageGenerateParams } from 'openai/resources/images'\nimport type {\n CollectionSlug,\n DataFromCollectionSlug,\n Endpoint,\n Field,\n File,\n GlobalConfig,\n GroupField,\n PayloadRequest,\n} from 'payload'\nimport type { CSSProperties, MouseEventHandler } from 'react'\n\nexport interface PluginConfigAccess {\n settings?: ({ req }: { req: PayloadRequest }) => Promise<boolean> | boolean\n}\n\nexport type PluginConfigMediaUploadFunction = (\n result: { data: Record<any, any>; file: File },\n {\n collection,\n request,\n }: {\n collection: CollectionSlug\n request: PayloadRequest\n },\n) => Promise<DataFromCollectionSlug<CollectionSlug>>\n\nexport interface PluginConfig {\n access?: PluginConfigAccess\n collections: {\n [key: CollectionSlug]: 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?: {\n [key: GlobalConfig['slug']]: boolean\n }\n interfaceName?: string\n mediaUpload?: PluginConfigMediaUploadFunction\n uploadCollectionSlug?: CollectionSlug\n}\n\nexport interface GenerationModel {\n fields: string[]\n generateText?: (prompt: string, system: string) => Promise<string>\n handler?: (prompt: string, options: any) => Promise<any> | Response\n id: string\n name: string\n output: 'audio' | 'file' | 'image' | 'json' | 'text' | 'video'\n settings?: GroupField\n supportsPromptOptimization?: boolean\n}\n\nexport interface GenerationConfig {\n models: GenerationModel[]\n provider: string\n}\n\nexport type GenerateTextarea<T = any> = (args: {\n collectionSlug: CollectionSlug\n doc: T\n documentId?: number | string\n locale?: string\n options?: any\n}) => Promise<string> | string\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 UseMenuOptions = {\n isConfigAllowed: boolean\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\nexport type ImageReference = {\n data: Blob\n name: string\n size: number\n type: string\n url: string\n}\n\nexport type GenerateImageParams = {\n images?: ImageReference[]\n size?: ImageGenerateParams['size']\n style?: ImageGenerateParams['style']\n version?: ImageGenerateParams['model']\n}\n"],"names":[],"mappings":"AAgIA,WAKC"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { JSONSchema } from 'openai/lib/jsonschema'\nimport type { ImageGenerateParams } from 'openai/resources/images'\nimport type {\n CollectionSlug,\n DataFromCollectionSlug,\n Endpoint,\n Field,\n File,\n GlobalConfig,\n GroupField,\n PayloadRequest,\n} from 'payload'\nimport type { CSSProperties, MouseEventHandler } from 'react'\n\nexport interface PluginConfigAccess {\n /**\n * Control access to AI generation features (generate text, images, audio)\n * @default () => !!req.user (requires authentication)\n */\n generate?: ({ req }: { req: PayloadRequest }) => Promise<boolean> | boolean\n /**\n * Control access to AI settings/configuration\n * @default () => !!req.user (requires authentication)\n */\n settings?: ({ req }: { req: PayloadRequest }) => Promise<boolean> | boolean\n}\n\nexport interface PluginOptions {\n\n /**\n * Provide local tags to filter language options from the Translate Menu\n * Check for the available local tags,\n * visit: https://www.npmjs.com/package/locale-codes\n * Example: [\"en-US\", \"zh-SG\", \"zh-CN\", \"en\"]\n */\n enabledLanguages?: string[]\n}\n\nexport type PluginConfigMediaUploadFunction = (\n result: { data: Record<any, any>; file: File },\n {\n collection,\n request,\n }: {\n collection: CollectionSlug\n request: PayloadRequest\n },\n) => Promise<DataFromCollectionSlug<CollectionSlug>>\n\nexport interface PluginConfig {\n /**\n * Access control configuration for AI features\n * By default, all AI features require authentication\n */\n access?: PluginConfigAccess\n collections: {\n [key: CollectionSlug]: 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?: {\n [key: GlobalConfig['slug']]: boolean\n }\n interfaceName?: string\n mediaUpload?: PluginConfigMediaUploadFunction\n options?: PluginOptions\n uploadCollectionSlug?: CollectionSlug\n}\n\nexport interface GenerationModel {\n fields: string[]\n generateText?: (prompt: string, system: string) => Promise<string>\n handler?: (prompt: string, options: any) => Promise<any> | Response\n id: string\n name: string\n output: 'audio' | 'file' | 'image' | 'json' | 'text' | 'video'\n settings?: GroupField\n supportsPromptOptimization?: boolean\n}\n\nexport interface GenerationConfig {\n models: GenerationModel[]\n provider: string\n}\n\nexport type GenerateTextarea<T = any> = (args: {\n collectionSlug: CollectionSlug\n doc: T\n documentId?: number | string\n locale?: string\n options?: any\n}) => Promise<string> | string\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 UseMenuOptions = {\n isConfigAllowed: boolean\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\nexport type ImageReference = {\n data: Blob\n name: string\n size: number\n type: string\n url: string\n}\n\nexport type GenerateImageParams = {\n images?: ImageReference[]\n size?: ImageGenerateParams['size']\n style?: ImageGenerateParams['style']\n version?: ImageGenerateParams['model']\n}\n"],"names":[],"mappings":"AAyJA,WAKC"}
@@ -1,4 +1,8 @@
1
+ import React from 'react';
1
2
  export declare const TranslateMenu: ({ onClick }: {
2
3
  onClick: any;
3
4
  }) => import("react/jsx-runtime").JSX.Element;
5
+ export declare const MemoizedTranslateMenu: React.MemoExoticComponent<({ onClick }: {
6
+ onClick: any;
7
+ }) => import("react/jsx-runtime").JSX.Element>;
4
8
  //# sourceMappingURL=TranslateMenu.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TranslateMenu.d.ts","sourceRoot":"","sources":["../../../../../src/ui/Compose/hooks/menu/TranslateMenu.tsx"],"names":[],"mappings":"AAOA,eAAO,MAAM,aAAa,GAAI;;CAAW,4CA6ExC,CAAA"}
1
+ {"version":3,"file":"TranslateMenu.d.ts","sourceRoot":"","sources":["../../../../../src/ui/Compose/hooks/menu/TranslateMenu.tsx"],"names":[],"mappings":"AACA,OAAO,KAAyB,MAAM,OAAO,CAAA;AAO7C,eAAO,MAAM,aAAa,GAAI;;CAAW,4CAsFxC,CAAA;AAED,eAAO,MAAM,qBAAqB;;8CAAsB,CAAA"}
@@ -1,14 +1,19 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import locales from 'locale-codes';
3
- import React, { useState } from 'react';
3
+ import React, { memo, useState } from 'react';
4
+ import { useInstructions } from '../../../../providers/InstructionsProvider/useInstructions.js';
4
5
  import { Item } from './Item.js';
5
6
  import { Translate } from './items.js';
6
7
  import styles from './menu.module.scss';
7
8
  export const TranslateMenu = ({ onClick })=>{
8
9
  const [show, setShow] = useState(false);
9
- const filteredLocales = locales.all.filter((a)=>{
10
+ const { enabledLanguages = [] } = useInstructions();
11
+ let filteredLocales = locales.all.filter((a)=>{
10
12
  return a.tag && a.location;
11
13
  });
14
+ if (enabledLanguages?.length) {
15
+ filteredLocales = filteredLocales.filter((a)=>enabledLanguages?.includes(a.tag));
16
+ }
12
17
  const [languages, setLanguages] = useState(filteredLocales);
13
18
  const [inputFocus, setInputFocus] = useState(false);
14
19
  return /*#__PURE__*/ _jsxs("div", {
@@ -33,8 +38,7 @@ export const TranslateMenu = ({ onClick })=>{
33
38
  children: /*#__PURE__*/ _jsxs("div", {
34
39
  className: `${styles.menu} ${styles.subMenu}`,
35
40
  style: {
36
- background: "var(--popup-bg)",
37
- minHeight: "300px"
41
+ background: 'var(--popup-bg)'
38
42
  },
39
43
  children: [
40
44
  /*#__PURE__*/ _jsx(Item, {
@@ -78,5 +82,6 @@ export const TranslateMenu = ({ onClick })=>{
78
82
  ]
79
83
  });
80
84
  };
85
+ export const MemoizedTranslateMenu = /*#__PURE__*/ memo(TranslateMenu);
81
86
 
82
87
  //# sourceMappingURL=TranslateMenu.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/ui/Compose/hooks/menu/TranslateMenu.tsx"],"sourcesContent":["import locales from 'locale-codes'\nimport React, { useState } from 'react'\n\nimport { Item } from './Item.js'\nimport { Translate } from './items.js'\nimport styles from './menu.module.scss'\n\nexport const TranslateMenu = ({ onClick }) => {\n const [show, setShow] = useState(false)\n\n const filteredLocales = locales.all.filter((a) => {\n return a.tag && a.location\n })\n\n const [languages, setLanguages] = useState(filteredLocales)\n const [inputFocus, setInputFocus] = useState(false)\n\n return (\n <div\n className={styles.menu}\n onMouseLeave={() => {\n if (!inputFocus) {\n setShow(false)\n }\n }}\n >\n <Translate\n isActive={show}\n isMenu\n onClick={() => {\n setShow(!show)\n }}\n onMouseEnter={() => setShow(true)}\n />\n <div className={styles.hoverMenu} data-show={show}>\n <div className={`${styles.menu} ${styles.subMenu}`} style={{\n background: \"var(--popup-bg)\",\n minHeight: \"300px\"\n }}>\n <Item\n onClick={() => {}}\n style={{\n background: 'transparent',\n padding: '0 0 5px 0',\n position: 'sticky',\n top: 0,\n }}\n >\n <input\n className={styles.menuInput}\n onBlur={() => setInputFocus(false)}\n onChange={(event) => {\n const value = event.target.value\n setLanguages(\n filteredLocales.filter((l) => {\n const lowerCaseValue = value.toLowerCase()\n return (\n l.name.toLowerCase().startsWith(lowerCaseValue) ||\n l.location.toLowerCase().startsWith(lowerCaseValue) ||\n l.tag.toLowerCase().startsWith(lowerCaseValue)\n )\n }),\n )\n }}\n onFocus={() => setInputFocus(true)}\n placeholder=\"Search...\"\n />\n </Item>\n {languages.map((locale) => {\n return (\n <Item\n key={locale.tag}\n onClick={() => {\n onClick({ locale: locale.tag })\n }}\n >\n <span className={styles.ellipsis}>{`${locale.location} (${locale.tag})`}</span>\n </Item>\n )\n })}\n </div>\n </div>\n </div>\n )\n}\n"],"names":["locales","React","useState","Item","Translate","styles","TranslateMenu","onClick","show","setShow","filteredLocales","all","filter","a","tag","location","languages","setLanguages","inputFocus","setInputFocus","div","className","menu","onMouseLeave","isActive","isMenu","onMouseEnter","hoverMenu","data-show","subMenu","style","background","minHeight","padding","position","top","input","menuInput","onBlur","onChange","event","value","target","l","lowerCaseValue","toLowerCase","name","startsWith","onFocus","placeholder","map","locale","span","ellipsis"],"mappings":";AAAA,OAAOA,aAAa,eAAc;AAClC,OAAOC,SAASC,QAAQ,QAAQ,QAAO;AAEvC,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,SAAS,QAAQ,aAAY;AACtC,OAAOC,YAAY,qBAAoB;AAEvC,OAAO,MAAMC,gBAAgB,CAAC,EAAEC,OAAO,EAAE;IACvC,MAAM,CAACC,MAAMC,QAAQ,GAAGP,SAAS;IAEjC,MAAMQ,kBAAkBV,QAAQW,GAAG,CAACC,MAAM,CAAC,CAACC;QAC1C,OAAOA,EAAEC,GAAG,IAAID,EAAEE,QAAQ;IAC5B;IAEA,MAAM,CAACC,WAAWC,aAAa,GAAGf,SAASQ;IAC3C,MAAM,CAACQ,YAAYC,cAAc,GAAGjB,SAAS;IAE7C,qBACE,MAACkB;QACCC,WAAWhB,OAAOiB,IAAI;QACtBC,cAAc;YACZ,IAAI,CAACL,YAAY;gBACfT,QAAQ;YACV;QACF;;0BAEA,KAACL;gBACCoB,UAAUhB;gBACViB,MAAM;gBACNlB,SAAS;oBACPE,QAAQ,CAACD;gBACX;gBACAkB,cAAc,IAAMjB,QAAQ;;0BAE9B,KAACW;gBAAIC,WAAWhB,OAAOsB,SAAS;gBAAEC,aAAWpB;0BAC3C,cAAA,MAACY;oBAAIC,WAAW,GAAGhB,OAAOiB,IAAI,CAAC,CAAC,EAAEjB,OAAOwB,OAAO,EAAE;oBAAEC,OAAO;wBACzDC,YAAY;wBACZC,WAAW;oBACb;;sCACE,KAAC7B;4BACCI,SAAS,KAAO;4BAChBuB,OAAO;gCACLC,YAAY;gCACZE,SAAS;gCACTC,UAAU;gCACVC,KAAK;4BACP;sCAEA,cAAA,KAACC;gCACCf,WAAWhB,OAAOgC,SAAS;gCAC3BC,QAAQ,IAAMnB,cAAc;gCAC5BoB,UAAU,CAACC;oCACT,MAAMC,QAAQD,MAAME,MAAM,CAACD,KAAK;oCAChCxB,aACEP,gBAAgBE,MAAM,CAAC,CAAC+B;wCACtB,MAAMC,iBAAiBH,MAAMI,WAAW;wCACxC,OACEF,EAAEG,IAAI,CAACD,WAAW,GAAGE,UAAU,CAACH,mBAChCD,EAAE5B,QAAQ,CAAC8B,WAAW,GAAGE,UAAU,CAACH,mBACpCD,EAAE7B,GAAG,CAAC+B,WAAW,GAAGE,UAAU,CAACH;oCAEnC;gCAEJ;gCACAI,SAAS,IAAM7B,cAAc;gCAC7B8B,aAAY;;;wBAGfjC,UAAUkC,GAAG,CAAC,CAACC;4BACd,qBACE,KAAChD;gCAECI,SAAS;oCACPA,QAAQ;wCAAE4C,QAAQA,OAAOrC,GAAG;oCAAC;gCAC/B;0CAEA,cAAA,KAACsC;oCAAK/B,WAAWhB,OAAOgD,QAAQ;8CAAG,GAAGF,OAAOpC,QAAQ,CAAC,EAAE,EAAEoC,OAAOrC,GAAG,CAAC,CAAC,CAAC;;+BALlEqC,OAAOrC,GAAG;wBAQrB;;;;;;AAKV,EAAC"}
1
+ {"version":3,"sources":["../../../../../src/ui/Compose/hooks/menu/TranslateMenu.tsx"],"sourcesContent":["import locales from 'locale-codes'\nimport React, { memo, useState } from 'react'\n\nimport { useInstructions } from '../../../../providers/InstructionsProvider/useInstructions.js'\nimport { Item } from './Item.js'\nimport { Translate } from './items.js'\nimport styles from './menu.module.scss'\n\nexport const TranslateMenu = ({ onClick }) => {\n const [show, setShow] = useState(false)\n\n const { enabledLanguages = [] } = useInstructions()\n\n let filteredLocales = locales.all.filter((a) => {\n return a.tag && a.location\n })\n\n if (enabledLanguages?.length) {\n filteredLocales = filteredLocales.filter((a) => enabledLanguages?.includes(a.tag))\n }\n\n const [languages, setLanguages] = useState(filteredLocales)\n const [inputFocus, setInputFocus] = useState(false)\n\n return (\n <div\n className={styles.menu}\n onMouseLeave={() => {\n if (!inputFocus) {\n setShow(false)\n }\n }}\n >\n <Translate\n isActive={show}\n isMenu\n onClick={() => {\n setShow(!show)\n }}\n onMouseEnter={() => setShow(true)}\n />\n <div className={styles.hoverMenu} data-show={show}>\n <div\n className={`${styles.menu} ${styles.subMenu}`}\n style={{\n background: 'var(--popup-bg)',\n // minHeight: '300px',\n }}\n >\n <Item\n onClick={() => {}}\n style={{\n background: 'transparent',\n padding: '0 0 5px 0',\n position: 'sticky',\n top: 0,\n }}\n >\n <input\n className={styles.menuInput}\n onBlur={() => setInputFocus(false)}\n onChange={(event) => {\n const value = event.target.value\n setLanguages(\n filteredLocales.filter((l) => {\n const lowerCaseValue = value.toLowerCase()\n return (\n l.name.toLowerCase().startsWith(lowerCaseValue) ||\n l.location.toLowerCase().startsWith(lowerCaseValue) ||\n l.tag.toLowerCase().startsWith(lowerCaseValue)\n )\n }),\n )\n }}\n onFocus={() => setInputFocus(true)}\n placeholder=\"Search...\"\n />\n </Item>\n {languages.map((locale) => {\n return (\n <Item\n key={locale.tag}\n onClick={() => {\n onClick({ locale: locale.tag })\n }}\n >\n <span className={styles.ellipsis}>{`${locale.location} (${locale.tag})`}</span>\n </Item>\n )\n })}\n </div>\n </div>\n </div>\n )\n}\n\nexport const MemoizedTranslateMenu = memo(TranslateMenu)\n"],"names":["locales","React","memo","useState","useInstructions","Item","Translate","styles","TranslateMenu","onClick","show","setShow","enabledLanguages","filteredLocales","all","filter","a","tag","location","length","includes","languages","setLanguages","inputFocus","setInputFocus","div","className","menu","onMouseLeave","isActive","isMenu","onMouseEnter","hoverMenu","data-show","subMenu","style","background","padding","position","top","input","menuInput","onBlur","onChange","event","value","target","l","lowerCaseValue","toLowerCase","name","startsWith","onFocus","placeholder","map","locale","span","ellipsis","MemoizedTranslateMenu"],"mappings":";AAAA,OAAOA,aAAa,eAAc;AAClC,OAAOC,SAASC,IAAI,EAAEC,QAAQ,QAAQ,QAAO;AAE7C,SAASC,eAAe,QAAQ,gEAA+D;AAC/F,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,SAAS,QAAQ,aAAY;AACtC,OAAOC,YAAY,qBAAoB;AAEvC,OAAO,MAAMC,gBAAgB,CAAC,EAAEC,OAAO,EAAE;IACvC,MAAM,CAACC,MAAMC,QAAQ,GAAGR,SAAS;IAEjC,MAAM,EAAES,mBAAmB,EAAE,EAAE,GAAGR;IAElC,IAAIS,kBAAkBb,QAAQc,GAAG,CAACC,MAAM,CAAC,CAACC;QACxC,OAAOA,EAAEC,GAAG,IAAID,EAAEE,QAAQ;IAC5B;IAEA,IAAIN,kBAAkBO,QAAQ;QAC5BN,kBAAkBA,gBAAgBE,MAAM,CAAC,CAACC,IAAMJ,kBAAkBQ,SAASJ,EAAEC,GAAG;IAClF;IAEA,MAAM,CAACI,WAAWC,aAAa,GAAGnB,SAASU;IAC3C,MAAM,CAACU,YAAYC,cAAc,GAAGrB,SAAS;IAE7C,qBACE,MAACsB;QACCC,WAAWnB,OAAOoB,IAAI;QACtBC,cAAc;YACZ,IAAI,CAACL,YAAY;gBACfZ,QAAQ;YACV;QACF;;0BAEA,KAACL;gBACCuB,UAAUnB;gBACVoB,MAAM;gBACNrB,SAAS;oBACPE,QAAQ,CAACD;gBACX;gBACAqB,cAAc,IAAMpB,QAAQ;;0BAE9B,KAACc;gBAAIC,WAAWnB,OAAOyB,SAAS;gBAAEC,aAAWvB;0BAC3C,cAAA,MAACe;oBACCC,WAAW,GAAGnB,OAAOoB,IAAI,CAAC,CAAC,EAAEpB,OAAO2B,OAAO,EAAE;oBAC7CC,OAAO;wBACLC,YAAY;oBAEd;;sCAEA,KAAC/B;4BACCI,SAAS,KAAO;4BAChB0B,OAAO;gCACLC,YAAY;gCACZC,SAAS;gCACTC,UAAU;gCACVC,KAAK;4BACP;sCAEA,cAAA,KAACC;gCACCd,WAAWnB,OAAOkC,SAAS;gCAC3BC,QAAQ,IAAMlB,cAAc;gCAC5BmB,UAAU,CAACC;oCACT,MAAMC,QAAQD,MAAME,MAAM,CAACD,KAAK;oCAChCvB,aACET,gBAAgBE,MAAM,CAAC,CAACgC;wCACtB,MAAMC,iBAAiBH,MAAMI,WAAW;wCACxC,OACEF,EAAEG,IAAI,CAACD,WAAW,GAAGE,UAAU,CAACH,mBAChCD,EAAE7B,QAAQ,CAAC+B,WAAW,GAAGE,UAAU,CAACH,mBACpCD,EAAE9B,GAAG,CAACgC,WAAW,GAAGE,UAAU,CAACH;oCAEnC;gCAEJ;gCACAI,SAAS,IAAM5B,cAAc;gCAC7B6B,aAAY;;;wBAGfhC,UAAUiC,GAAG,CAAC,CAACC;4BACd,qBACE,KAAClD;gCAECI,SAAS;oCACPA,QAAQ;wCAAE8C,QAAQA,OAAOtC,GAAG;oCAAC;gCAC/B;0CAEA,cAAA,KAACuC;oCAAK9B,WAAWnB,OAAOkD,QAAQ;8CAAG,GAAGF,OAAOrC,QAAQ,CAAC,EAAE,EAAEqC,OAAOtC,GAAG,CAAC,CAAC,CAAC;;+BALlEsC,OAAOtC,GAAG;wBAQrB;;;;;;AAKV,EAAC;AAED,OAAO,MAAMyC,sCAAwBxD,KAAKM,eAAc"}
@@ -1,4 +1,4 @@
1
- import { TranslateMenu } from './TranslateMenu.js';
1
+ import { MemoizedTranslateMenu } from './TranslateMenu.js';
2
2
  import { Compose, Expand, Proofread, Rephrase, Settings, Simplify, Summarize } from './items.js';
3
3
  export const menuItemsMap = [
4
4
  {
@@ -19,7 +19,7 @@ export const menuItemsMap = [
19
19
  },
20
20
  {
21
21
  name: 'Translate',
22
- component: TranslateMenu,
22
+ component: MemoizedTranslateMenu,
23
23
  excludedFor: [
24
24
  'upload'
25
25
  ],
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/ui/Compose/hooks/menu/itemsMap.ts"],"sourcesContent":["import type React from 'react'\n\nimport type { ActionMenuItems, BaseItemProps } from '../../../../types.js'\n\nimport { TranslateMenu } from './TranslateMenu.js'\nimport { Compose, Expand, Proofread, Rephrase, Settings, Simplify, Summarize } from './items.js'\n\ntype MenuItemsMapType = {\n component: React.FC<BaseItemProps>\n excludedFor?: string[]\n loadingText?: string\n name: ActionMenuItems\n}\n\nexport const menuItemsMap: MenuItemsMapType[] = [\n { name: 'Proofread', component: Proofread, excludedFor: ['upload'], loadingText: 'Proofreading' },\n { name: 'Rephrase', component: Rephrase, excludedFor: ['upload'], loadingText: 'Rephrasing' },\n {\n name: 'Translate',\n component: TranslateMenu,\n excludedFor: ['upload'],\n loadingText: 'Translating',\n },\n { name: 'Expand', component: Expand, excludedFor: ['upload', 'text'], loadingText: 'Expanding' },\n {\n // Turned off - WIP\n name: 'Summarize',\n component: Summarize,\n excludedFor: ['upload', 'text', 'richText'],\n loadingText: 'Summarizing',\n },\n { name: 'Simplify', component: Simplify, excludedFor: ['upload'], loadingText: 'Simplifying' },\n { name: 'Compose', component: Compose, loadingText: 'Composing' },\n { name: 'Settings', component: Settings },\n]\n"],"names":["TranslateMenu","Compose","Expand","Proofread","Rephrase","Settings","Simplify","Summarize","menuItemsMap","name","component","excludedFor","loadingText"],"mappings":"AAIA,SAASA,aAAa,QAAQ,qBAAoB;AAClD,SAASC,OAAO,EAAEC,MAAM,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,aAAY;AAShG,OAAO,MAAMC,eAAmC;IAC9C;QAAEC,MAAM;QAAaC,WAAWP;QAAWQ,aAAa;YAAC;SAAS;QAAEC,aAAa;IAAe;IAChG;QAAEH,MAAM;QAAYC,WAAWN;QAAUO,aAAa;YAAC;SAAS;QAAEC,aAAa;IAAa;IAC5F;QACEH,MAAM;QACNC,WAAWV;QACXW,aAAa;YAAC;SAAS;QACvBC,aAAa;IACf;IACA;QAAEH,MAAM;QAAUC,WAAWR;QAAQS,aAAa;YAAC;YAAU;SAAO;QAAEC,aAAa;IAAY;IAC/F;QACE,mBAAmB;QACnBH,MAAM;QACNC,WAAWH;QACXI,aAAa;YAAC;YAAU;YAAQ;SAAW;QAC3CC,aAAa;IACf;IACA;QAAEH,MAAM;QAAYC,WAAWJ;QAAUK,aAAa;YAAC;SAAS;QAAEC,aAAa;IAAc;IAC7F;QAAEH,MAAM;QAAWC,WAAWT;QAASW,aAAa;IAAY;IAChE;QAAEH,MAAM;QAAYC,WAAWL;IAAS;CACzC,CAAA"}
1
+ {"version":3,"sources":["../../../../../src/ui/Compose/hooks/menu/itemsMap.ts"],"sourcesContent":["import type React from 'react'\n\nimport type { ActionMenuItems, BaseItemProps } from '../../../../types.js'\n\nimport { MemoizedTranslateMenu, TranslateMenu } from './TranslateMenu.js'\nimport { Compose, Expand, Proofread, Rephrase, Settings, Simplify, Summarize } from './items.js'\n\ntype MenuItemsMapType = {\n component: React.FC<BaseItemProps>\n excludedFor?: string[]\n loadingText?: string\n name: ActionMenuItems\n}\n\nexport const menuItemsMap: MenuItemsMapType[] = [\n { name: 'Proofread', component: Proofread, excludedFor: ['upload'], loadingText: 'Proofreading' },\n { name: 'Rephrase', component: Rephrase, excludedFor: ['upload'], loadingText: 'Rephrasing' },\n {\n name: 'Translate',\n component: MemoizedTranslateMenu,\n excludedFor: ['upload'],\n loadingText: 'Translating',\n },\n { name: 'Expand', component: Expand, excludedFor: ['upload', 'text'], loadingText: 'Expanding' },\n {\n // Turned off - WIP\n name: 'Summarize',\n component: Summarize,\n excludedFor: ['upload', 'text', 'richText'],\n loadingText: 'Summarizing',\n },\n { name: 'Simplify', component: Simplify, excludedFor: ['upload'], loadingText: 'Simplifying' },\n { name: 'Compose', component: Compose, loadingText: 'Composing' },\n { name: 'Settings', component: Settings },\n]\n"],"names":["MemoizedTranslateMenu","Compose","Expand","Proofread","Rephrase","Settings","Simplify","Summarize","menuItemsMap","name","component","excludedFor","loadingText"],"mappings":"AAIA,SAASA,qBAAqB,QAAuB,qBAAoB;AACzE,SAASC,OAAO,EAAEC,MAAM,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,aAAY;AAShG,OAAO,MAAMC,eAAmC;IAC9C;QAAEC,MAAM;QAAaC,WAAWP;QAAWQ,aAAa;YAAC;SAAS;QAAEC,aAAa;IAAe;IAChG;QAAEH,MAAM;QAAYC,WAAWN;QAAUO,aAAa;YAAC;SAAS;QAAEC,aAAa;IAAa;IAC5F;QACEH,MAAM;QACNC,WAAWV;QACXW,aAAa;YAAC;SAAS;QACvBC,aAAa;IACf;IACA;QAAEH,MAAM;QAAUC,WAAWR;QAAQS,aAAa;YAAC;YAAU;SAAO;QAAEC,aAAa;IAAY;IAC/F;QACE,mBAAmB;QACnBH,MAAM;QACNC,WAAWH;QACXI,aAAa;YAAC;YAAU;YAAQ;SAAW;QAC3CC,aAAa;IACf;IACA;QAAEH,MAAM;QAAYC,WAAWJ;QAAUK,aAAa;YAAC;SAAS;QAAEC,aAAa;IAAc;IAC7F;QAAEH,MAAM;QAAWC,WAAWT;QAASW,aAAa;IAAY;IAChE;QAAEH,MAAM;QAAYC,WAAWL;IAAS;CACzC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-stack/payloadcms",
3
- "version": "3.2.14-beta",
3
+ "version": "3.2.16-beta",
4
4
  "private": false,
5
5
  "bugs": "https://github.com/ashbuilds/payload-ai/issues",
6
6
  "repository": "https://github.com/ashbuilds/payload-ai",