@ai-stack/payloadcms 3.68.0 → 3.76.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/core/media/image/generateImage.js +2 -6
- package/dist/ai/core/media/image/generateImage.js.map +1 -1
- package/dist/ai/core/media/image/handlers/multimodal.js +5 -0
- package/dist/ai/core/media/image/handlers/multimodal.js.map +1 -1
- package/dist/ai/core/streamObject.js +3 -3
- package/dist/ai/core/streamObject.js.map +1 -1
- package/dist/ai/core/types.d.ts +3 -0
- package/dist/ai/core/types.js.map +1 -1
- package/dist/ai/prompts.d.ts +1 -2
- package/dist/ai/prompts.js +0 -110
- package/dist/ai/prompts.js.map +1 -1
- package/dist/ai/providers/blocks/anthropic.js +2 -1
- package/dist/ai/providers/blocks/anthropic.js.map +1 -1
- package/dist/ai/providers/blocks/elevenlabs.js +3 -2
- package/dist/ai/providers/blocks/elevenlabs.js.map +1 -1
- package/dist/ai/providers/blocks/fal.js +2 -1
- package/dist/ai/providers/blocks/fal.js.map +1 -1
- package/dist/ai/providers/blocks/google.js +11 -6
- package/dist/ai/providers/blocks/google.js.map +1 -1
- package/dist/ai/providers/blocks/openai-compatible.js +2 -1
- package/dist/ai/providers/blocks/openai-compatible.js.map +1 -1
- package/dist/ai/providers/blocks/openai.js +3 -2
- package/dist/ai/providers/blocks/openai.js.map +1 -1
- package/dist/ai/providers/blocks/xai.js +2 -1
- package/dist/ai/providers/blocks/xai.js.map +1 -1
- package/dist/ai/providers/icons.d.ts +7 -0
- package/dist/ai/providers/icons.js +9 -0
- package/dist/ai/providers/icons.js.map +1 -0
- package/dist/ai/providers/registry.js +34 -24
- package/dist/ai/providers/registry.js.map +1 -1
- package/dist/ai/utils/filterEditorSchemaByNodes.d.ts +9 -0
- package/dist/ai/utils/filterEditorSchemaByNodes.js +30 -3
- package/dist/ai/utils/filterEditorSchemaByNodes.js.map +1 -1
- package/dist/ai/utils/nodeToSchemaMap.d.ts +22 -0
- package/dist/ai/utils/nodeToSchemaMap.js +72 -0
- package/dist/ai/utils/nodeToSchemaMap.js.map +1 -0
- package/dist/collections/AIJobs.js +1 -1
- package/dist/collections/AIJobs.js.map +1 -1
- package/dist/collections/AISettings.js +47 -20
- package/dist/collections/AISettings.js.map +1 -1
- package/dist/collections/Instructions.js +37 -0
- package/dist/collections/Instructions.js.map +1 -1
- package/dist/defaults.d.ts +1 -0
- package/dist/defaults.js +8 -0
- package/dist/defaults.js.map +1 -1
- package/dist/endpoints/chat.d.ts +4 -0
- package/dist/endpoints/fetchFields.js +10 -0
- package/dist/endpoints/fetchFields.js.map +1 -1
- package/dist/endpoints/fetchVoices.js +41 -24
- package/dist/endpoints/fetchVoices.js.map +1 -1
- package/dist/endpoints/index.js +194 -16
- package/dist/endpoints/index.js.map +1 -1
- package/dist/exports/fields.d.ts +1 -0
- package/dist/exports/fields.js +1 -0
- package/dist/exports/fields.js.map +1 -1
- package/dist/fields/ArrayComposeField/ArrayComposeField.d.ts +15 -0
- package/dist/fields/ArrayComposeField/ArrayComposeField.js +87 -0
- package/dist/fields/ArrayComposeField/ArrayComposeField.js.map +1 -0
- package/dist/fields/ArrayComposeField/ArrayComposeField.jsx +73 -0
- package/dist/fields/PromptEditorField/PromptEditorField.js +7 -2
- package/dist/fields/PromptEditorField/PromptEditorField.js.map +1 -1
- package/dist/fields/PromptEditorField/PromptEditorField.jsx +5 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/payload-ai.d.ts +152 -0
- package/dist/plugin.js +16 -32
- package/dist/plugin.js.map +1 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.js +47 -15
- package/dist/providers/InstructionsProvider/InstructionsProvider.js.map +1 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.jsx +39 -16
- package/dist/providers/InstructionsProvider/context.d.ts +3 -0
- package/dist/providers/InstructionsProvider/context.js +2 -0
- package/dist/providers/InstructionsProvider/context.js.map +1 -1
- package/dist/providers/InstructionsProvider/useInstructions.js +21 -2
- package/dist/providers/InstructionsProvider/useInstructions.js.map +1 -1
- package/dist/styles.d.ts +11 -0
- package/dist/types/handlebars-async-helpers.d.ts +1 -0
- package/dist/types/handlebars-dist-handlebars.d.ts +1 -0
- package/dist/types/react-mentions.d.ts +1 -0
- package/dist/types.d.ts +34 -5
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/dist/ui/AIConfigDashboard/index.js +198 -22
- package/dist/ui/AIConfigDashboard/index.js.map +1 -1
- package/dist/ui/AIConfigDashboard/index.jsx +159 -13
- package/dist/ui/Compose/Compose.d.ts +1 -0
- package/dist/ui/Compose/Compose.js +23 -4
- package/dist/ui/Compose/Compose.js.map +1 -1
- package/dist/ui/Compose/Compose.jsx +23 -4
- package/dist/ui/Compose/UndoRedoActions.d.ts +2 -2
- package/dist/ui/Compose/UndoRedoActions.js +8 -5
- package/dist/ui/Compose/UndoRedoActions.js.map +1 -1
- package/dist/ui/Compose/UndoRedoActions.jsx +6 -5
- package/dist/ui/Compose/compose.module.css +56 -16
- package/dist/ui/Compose/hooks/menu/itemsMap.js +12 -6
- package/dist/ui/Compose/hooks/menu/itemsMap.js.map +1 -1
- package/dist/ui/Compose/hooks/menu/useMenu.js +26 -15
- package/dist/ui/Compose/hooks/menu/useMenu.js.map +1 -1
- package/dist/ui/Compose/hooks/menu/useMenu.jsx +25 -12
- package/dist/ui/Compose/hooks/useGenerate.js +26 -174
- package/dist/ui/Compose/hooks/useGenerate.js.map +1 -1
- package/dist/ui/Compose/hooks/useGenerateUpload.d.ts +11 -0
- package/dist/ui/Compose/hooks/useGenerateUpload.js +150 -0
- package/dist/ui/Compose/hooks/useGenerateUpload.js.map +1 -0
- package/dist/ui/Compose/hooks/useHistory.d.ts +0 -1
- package/dist/ui/Compose/hooks/useHistory.js +65 -25
- package/dist/ui/Compose/hooks/useHistory.js.map +1 -1
- package/dist/ui/Compose/hooks/useStreamingUpdate.d.ts +8 -0
- package/dist/ui/Compose/hooks/useStreamingUpdate.js +48 -0
- package/dist/ui/Compose/hooks/useStreamingUpdate.js.map +1 -0
- package/dist/ui/DynamicVoiceSelect/index.js +63 -11
- package/dist/ui/DynamicVoiceSelect/index.js.map +1 -1
- package/dist/ui/DynamicVoiceSelect/index.jsx +47 -14
- package/dist/ui/EncryptedTextField/index.js +4 -4
- package/dist/ui/EncryptedTextField/index.js.map +1 -1
- package/dist/ui/EncryptedTextField/index.jsx +4 -4
- package/dist/ui/VoicesFetcher/index.js +34 -16
- package/dist/ui/VoicesFetcher/index.js.map +1 -1
- package/dist/ui/VoicesFetcher/index.jsx +32 -15
- package/dist/utilities/buildSmartPrompt.d.ts +22 -0
- package/dist/utilities/buildSmartPrompt.js +141 -0
- package/dist/utilities/buildSmartPrompt.js.map +1 -0
- package/dist/utilities/encryption.js +2 -1
- package/dist/utilities/encryption.js.map +1 -1
- package/dist/utilities/fieldToJsonSchema.js +32 -3
- package/dist/utilities/fieldToJsonSchema.js.map +1 -1
- package/dist/utilities/resolveImageReferences.d.ts +3 -1
- package/dist/utilities/resolveImageReferences.js +21 -2
- package/dist/utilities/resolveImageReferences.js.map +1 -1
- package/dist/utilities/seedProperties.d.ts +7 -0
- package/dist/utilities/seedProperties.js +100 -0
- package/dist/utilities/seedProperties.js.map +1 -0
- package/dist/utilities/setSafeLexicalState.js +79 -6
- package/dist/utilities/setSafeLexicalState.js.map +1 -1
- package/dist/utilities/updateFieldsConfig.d.ts +1 -1
- package/dist/utilities/updateFieldsConfig.js +8 -1
- package/dist/utilities/updateFieldsConfig.js.map +1 -1
- package/package.json +35 -33
- package/dist/endpoints/chat.d.js +0 -3
- package/dist/endpoints/chat.d.js.map +0 -1
- package/dist/init.d.ts +0 -7
- package/dist/init.js +0 -135
- package/dist/init.js.map +0 -1
- package/dist/payload-ai.d.js +0 -3
- package/dist/payload-ai.d.js.map +0 -1
- package/dist/styles.d.js +0 -2
- package/dist/styles.d.js.map +0 -1
- package/dist/types/handlebars-async-helpers.d.js +0 -2
- package/dist/types/handlebars-async-helpers.d.js.map +0 -1
- package/dist/types/handlebars-dist-handlebars.d.js +0 -2
- package/dist/types/handlebars-dist-handlebars.d.js.map +0 -1
- package/dist/types/react-mentions.d.js +0 -2
- package/dist/types/react-mentions.d.js.map +0 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps Lexical node type values to JSON schema definition names.
|
|
3
|
+
* This is used to filter the editor schema based on allowed editor nodes.
|
|
4
|
+
*
|
|
5
|
+
* The keys are the type values that appear in serialized Lexical JSON (e.g., 'heading', 'paragraph').
|
|
6
|
+
* The values are the schema definition names as defined in lexicalJsonSchema.ts.
|
|
7
|
+
*/ export const nodeTypeToSchemaMap = {
|
|
8
|
+
// Core nodes (typically always included)
|
|
9
|
+
text: 'TextNode',
|
|
10
|
+
linebreak: 'LineBreakNode',
|
|
11
|
+
tab: 'TabNode',
|
|
12
|
+
root: 'RootNode',
|
|
13
|
+
// Block nodes
|
|
14
|
+
paragraph: 'ParagraphNode',
|
|
15
|
+
heading: 'HeadingNode',
|
|
16
|
+
quote: 'QuoteNode',
|
|
17
|
+
list: 'ListNode',
|
|
18
|
+
listitem: 'ListItemNode',
|
|
19
|
+
// Rich content nodes
|
|
20
|
+
link: 'LinkNode',
|
|
21
|
+
code: 'CodeNode',
|
|
22
|
+
horizontalrule: 'HorizontalRuleNode',
|
|
23
|
+
// Table nodes
|
|
24
|
+
table: 'TableNode',
|
|
25
|
+
tablerow: 'TableRowNode',
|
|
26
|
+
tablecell: 'TableCellNode',
|
|
27
|
+
// Media nodes
|
|
28
|
+
image: 'ImageNode'
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Core nodes that should always be included in the filtered schema
|
|
32
|
+
*/ export const coreNodeTypes = [
|
|
33
|
+
'text',
|
|
34
|
+
'linebreak',
|
|
35
|
+
'tab',
|
|
36
|
+
'root',
|
|
37
|
+
'paragraph'
|
|
38
|
+
];
|
|
39
|
+
/**
|
|
40
|
+
* Converts a Lexical node class name (e.g., 'HeadingNode') to its type value (e.g., 'heading').
|
|
41
|
+
* This handles the common pattern where node classes are named with the pattern `{Type}Node`.
|
|
42
|
+
*/ export function nodeClassToType(nodeClassName) {
|
|
43
|
+
// Handle common formats:
|
|
44
|
+
// 'HeadingNode' -> 'heading'
|
|
45
|
+
// 'ParagraphNode' -> 'paragraph'
|
|
46
|
+
// 'HorizontalRuleNode' -> 'horizontalrule'
|
|
47
|
+
return nodeClassName.replace(/Node$/, '').toLowerCase();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Converts a set of Lexical node class names to their corresponding schema definition names.
|
|
51
|
+
* Includes core nodes automatically.
|
|
52
|
+
*/ export function nodeClassesToSchemaDefinitions(nodeClassNames) {
|
|
53
|
+
const definitions = new Set();
|
|
54
|
+
// Always include core nodes
|
|
55
|
+
for (const coreType of coreNodeTypes){
|
|
56
|
+
const def = nodeTypeToSchemaMap[coreType];
|
|
57
|
+
if (def) {
|
|
58
|
+
definitions.add(def);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Convert each node class to its definition
|
|
62
|
+
for (const className of nodeClassNames){
|
|
63
|
+
const type = nodeClassToType(className);
|
|
64
|
+
const def = nodeTypeToSchemaMap[type];
|
|
65
|
+
if (def) {
|
|
66
|
+
definitions.add(def);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return Array.from(definitions);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=nodeToSchemaMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/ai/utils/nodeToSchemaMap.ts"],"sourcesContent":["/**\n * Maps Lexical node type values to JSON schema definition names.\n * This is used to filter the editor schema based on allowed editor nodes.\n *\n * The keys are the type values that appear in serialized Lexical JSON (e.g., 'heading', 'paragraph').\n * The values are the schema definition names as defined in lexicalJsonSchema.ts.\n */\nexport const nodeTypeToSchemaMap: Record<string, string> = {\n // Core nodes (typically always included)\n text: 'TextNode',\n linebreak: 'LineBreakNode',\n tab: 'TabNode',\n root: 'RootNode',\n\n // Block nodes\n paragraph: 'ParagraphNode',\n heading: 'HeadingNode',\n quote: 'QuoteNode',\n list: 'ListNode',\n listitem: 'ListItemNode',\n\n // Rich content nodes\n link: 'LinkNode',\n code: 'CodeNode',\n horizontalrule: 'HorizontalRuleNode',\n\n // Table nodes\n table: 'TableNode',\n tablerow: 'TableRowNode',\n tablecell: 'TableCellNode',\n\n // Media nodes\n image: 'ImageNode',\n}\n\n/**\n * Core nodes that should always be included in the filtered schema\n */\nexport const coreNodeTypes = ['text', 'linebreak', 'tab', 'root', 'paragraph']\n\n/**\n * Converts a Lexical node class name (e.g., 'HeadingNode') to its type value (e.g., 'heading').\n * This handles the common pattern where node classes are named with the pattern `{Type}Node`.\n */\nexport function nodeClassToType(nodeClassName: string): string {\n // Handle common formats:\n // 'HeadingNode' -> 'heading'\n // 'ParagraphNode' -> 'paragraph'\n // 'HorizontalRuleNode' -> 'horizontalrule'\n return nodeClassName.replace(/Node$/, '').toLowerCase()\n}\n\n/**\n * Converts a set of Lexical node class names to their corresponding schema definition names.\n * Includes core nodes automatically.\n */\nexport function nodeClassesToSchemaDefinitions(nodeClassNames: string[]): string[] {\n const definitions = new Set<string>()\n\n // Always include core nodes\n for (const coreType of coreNodeTypes) {\n const def = nodeTypeToSchemaMap[coreType]\n if (def) {\n definitions.add(def)\n }\n }\n\n // Convert each node class to its definition\n for (const className of nodeClassNames) {\n const type = nodeClassToType(className)\n const def = nodeTypeToSchemaMap[type]\n if (def) {\n definitions.add(def)\n }\n }\n\n return Array.from(definitions)\n}\n"],"names":["nodeTypeToSchemaMap","text","linebreak","tab","root","paragraph","heading","quote","list","listitem","link","code","horizontalrule","table","tablerow","tablecell","image","coreNodeTypes","nodeClassToType","nodeClassName","replace","toLowerCase","nodeClassesToSchemaDefinitions","nodeClassNames","definitions","Set","coreType","def","add","className","type","Array","from"],"mappings":"AAAA;;;;;;CAMC,GACD,OAAO,MAAMA,sBAA8C;IACzD,yCAAyC;IACzCC,MAAM;IACNC,WAAW;IACXC,KAAK;IACLC,MAAM;IAEN,cAAc;IACdC,WAAW;IACXC,SAAS;IACTC,OAAO;IACPC,MAAM;IACNC,UAAU;IAEV,qBAAqB;IACrBC,MAAM;IACNC,MAAM;IACNC,gBAAgB;IAEhB,cAAc;IACdC,OAAO;IACPC,UAAU;IACVC,WAAW;IAEX,cAAc;IACdC,OAAO;AACT,EAAC;AAED;;CAEC,GACD,OAAO,MAAMC,gBAAgB;IAAC;IAAQ;IAAa;IAAO;IAAQ;CAAY,CAAA;AAE9E;;;CAGC,GACD,OAAO,SAASC,gBAAgBC,aAAqB;IACnD,yBAAyB;IACzB,6BAA6B;IAC7B,iCAAiC;IACjC,2CAA2C;IAC3C,OAAOA,cAAcC,OAAO,CAAC,SAAS,IAAIC,WAAW;AACvD;AAEA;;;CAGC,GACD,OAAO,SAASC,+BAA+BC,cAAwB;IACrE,MAAMC,cAAc,IAAIC;IAExB,4BAA4B;IAC5B,KAAK,MAAMC,YAAYT,cAAe;QACpC,MAAMU,MAAM3B,mBAAmB,CAAC0B,SAAS;QACzC,IAAIC,KAAK;YACPH,YAAYI,GAAG,CAACD;QAClB;IACF;IAEA,4CAA4C;IAC5C,KAAK,MAAME,aAAaN,eAAgB;QACtC,MAAMO,OAAOZ,gBAAgBW;QAC7B,MAAMF,MAAM3B,mBAAmB,CAAC8B,KAAK;QACrC,IAAIH,KAAK;YACPH,YAAYI,GAAG,CAACD;QAClB;IACF;IAEA,OAAOI,MAAMC,IAAI,CAACR;AACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/AIJobs.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport { PLUGIN_AI_JOBS_TABLE, PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\n\nconst defaultAccessConfig = {\n create: ({ req }: { req: { user?: any } }) => !!req.user,\n delete: ({ req }: { req: { user?: any } }) => !!req.user,\n read: ({ req }: { req: { user?: any } }) => !!req.user,\n update: ({ req }: { req: { user?: any } }) => !!req.user,\n}\n\nconst defaultAdminConfig = {\n group: 'Plugins',\n hidden:
|
|
1
|
+
{"version":3,"sources":["../../src/collections/AIJobs.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport { PLUGIN_AI_JOBS_TABLE, PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\n\nconst defaultAccessConfig = {\n create: ({ req }: { req: { user?: any } }) => !!req.user,\n delete: ({ req }: { req: { user?: any } }) => !!req.user,\n read: ({ req }: { req: { user?: any } }) => !!req.user,\n update: ({ req }: { req: { user?: any } }) => !!req.user,\n}\n\nconst defaultAdminConfig = {\n group: 'Plugins',\n hidden: true,\n}\n\nexport const aiJobsCollection = (): CollectionConfig => ({\n slug: PLUGIN_AI_JOBS_TABLE,\n access: defaultAccessConfig,\n admin: defaultAdminConfig,\n fields: [\n {\n name: 'instructionId',\n type: 'relationship',\n relationTo: PLUGIN_INSTRUCTIONS_TABLE,\n required: true,\n },\n {\n name: 'task_id',\n type: 'text',\n required: true,\n unique: true,\n },\n {\n name: 'status',\n type: 'select',\n defaultValue: 'queued',\n options: [\n { label: 'Queued', value: 'queued' },\n { label: 'Running', value: 'running' },\n { label: 'Completed', value: 'completed' },\n { label: 'Failed', value: 'failed' },\n { label: 'Canceled', value: 'canceled' },\n ],\n },\n {\n name: 'progress',\n type: 'number',\n max: 100,\n min: 0,\n },\n {\n name: 'result_id',\n type: 'text',\n },\n {\n name: 'error',\n type: 'textarea',\n },\n {\n name: 'meta',\n type: 'json',\n },\n ],\n labels: {\n plural: 'AI Jobs',\n singular: 'AI Job',\n },\n})\n"],"names":["PLUGIN_AI_JOBS_TABLE","PLUGIN_INSTRUCTIONS_TABLE","defaultAccessConfig","create","req","user","delete","read","update","defaultAdminConfig","group","hidden","aiJobsCollection","slug","access","admin","fields","name","type","relationTo","required","unique","defaultValue","options","label","value","max","min","labels","plural","singular"],"mappings":"AAEA,SAASA,oBAAoB,EAAEC,yBAAyB,QAAQ,iBAAgB;AAEhF,MAAMC,sBAAsB;IAC1BC,QAAQ,CAAC,EAAEC,GAAG,EAA2B,GAAK,CAAC,CAACA,IAAIC,IAAI;IACxDC,QAAQ,CAAC,EAAEF,GAAG,EAA2B,GAAK,CAAC,CAACA,IAAIC,IAAI;IACxDE,MAAM,CAAC,EAAEH,GAAG,EAA2B,GAAK,CAAC,CAACA,IAAIC,IAAI;IACtDG,QAAQ,CAAC,EAAEJ,GAAG,EAA2B,GAAK,CAAC,CAACA,IAAIC,IAAI;AAC1D;AAEA,MAAMI,qBAAqB;IACzBC,OAAO;IACPC,QAAQ;AACV;AAEA,OAAO,MAAMC,mBAAmB,IAAyB,CAAA;QACvDC,MAAMb;QACNc,QAAQZ;QACRa,OAAON;QACPO,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNC,YAAYlB;gBACZmB,UAAU;YACZ;YACA;gBACEH,MAAM;gBACNC,MAAM;gBACNE,UAAU;gBACVC,QAAQ;YACV;YACA;gBACEJ,MAAM;gBACNC,MAAM;gBACNI,cAAc;gBACdC,SAAS;oBACP;wBAAEC,OAAO;wBAAUC,OAAO;oBAAS;oBACnC;wBAAED,OAAO;wBAAWC,OAAO;oBAAU;oBACrC;wBAAED,OAAO;wBAAaC,OAAO;oBAAY;oBACzC;wBAAED,OAAO;wBAAUC,OAAO;oBAAS;oBACnC;wBAAED,OAAO;wBAAYC,OAAO;oBAAW;iBACxC;YACH;YACA;gBACER,MAAM;gBACNC,MAAM;gBACNQ,KAAK;gBACLC,KAAK;YACP;YACA;gBACEV,MAAM;gBACNC,MAAM;YACR;YACA;gBACED,MAAM;gBACNC,MAAM;YACR;YACA;gBACED,MAAM;gBACNC,MAAM;YACR;SACD;QACDU,QAAQ;YACNC,QAAQ;YACRC,UAAU;QACZ;IACF,CAAA,EAAE"}
|
|
@@ -5,9 +5,9 @@ export const aiSettingsGlobal = {
|
|
|
5
5
|
read: ({ req })=>!!req.user,
|
|
6
6
|
update: ({ req })=>!!req.user
|
|
7
7
|
},
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
admin: {
|
|
9
|
+
group: false
|
|
10
|
+
},
|
|
11
11
|
fields: [
|
|
12
12
|
{
|
|
13
13
|
name: 'providers',
|
|
@@ -20,11 +20,18 @@ export const aiSettingsGlobal = {
|
|
|
20
20
|
label: 'AI Providers',
|
|
21
21
|
required: true
|
|
22
22
|
},
|
|
23
|
+
{
|
|
24
|
+
name: 'enabledCollections',
|
|
25
|
+
type: 'json',
|
|
26
|
+
admin: {
|
|
27
|
+
hidden: true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
23
30
|
{
|
|
24
31
|
name: 'defaults',
|
|
25
32
|
type: 'group',
|
|
26
33
|
admin: {
|
|
27
|
-
description: '
|
|
34
|
+
description: 'Please provide default provider/model behavior for each use case'
|
|
28
35
|
},
|
|
29
36
|
fields: [
|
|
30
37
|
{
|
|
@@ -119,7 +126,7 @@ export const aiSettingsGlobal = {
|
|
|
119
126
|
{
|
|
120
127
|
fields: [
|
|
121
128
|
{
|
|
122
|
-
name: '
|
|
129
|
+
name: 'tts',
|
|
123
130
|
type: 'group',
|
|
124
131
|
fields: [
|
|
125
132
|
{
|
|
@@ -142,6 +149,16 @@ export const aiSettingsGlobal = {
|
|
|
142
149
|
},
|
|
143
150
|
label: 'Default Model'
|
|
144
151
|
},
|
|
152
|
+
{
|
|
153
|
+
name: 'voice',
|
|
154
|
+
type: 'text',
|
|
155
|
+
admin: {
|
|
156
|
+
components: {
|
|
157
|
+
Field: '@ai-stack/payloadcms/client#DynamicVoiceSelect'
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
label: 'Default Voice'
|
|
161
|
+
},
|
|
145
162
|
{
|
|
146
163
|
name: 'options',
|
|
147
164
|
type: 'json',
|
|
@@ -157,12 +174,15 @@ export const aiSettingsGlobal = {
|
|
|
157
174
|
label: ''
|
|
158
175
|
}
|
|
159
176
|
],
|
|
160
|
-
label: '
|
|
177
|
+
label: 'Speech Generation'
|
|
161
178
|
},
|
|
162
179
|
{
|
|
180
|
+
admin: {
|
|
181
|
+
disabled: true
|
|
182
|
+
},
|
|
163
183
|
fields: [
|
|
164
184
|
{
|
|
165
|
-
name: '
|
|
185
|
+
name: 'video',
|
|
166
186
|
type: 'group',
|
|
167
187
|
fields: [
|
|
168
188
|
{
|
|
@@ -185,16 +205,6 @@ export const aiSettingsGlobal = {
|
|
|
185
205
|
},
|
|
186
206
|
label: 'Default Model'
|
|
187
207
|
},
|
|
188
|
-
{
|
|
189
|
-
name: 'voice',
|
|
190
|
-
type: 'text',
|
|
191
|
-
admin: {
|
|
192
|
-
components: {
|
|
193
|
-
Field: '@ai-stack/payloadcms/client#DynamicVoiceSelect'
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
label: 'Default Voice'
|
|
197
|
-
},
|
|
198
208
|
{
|
|
199
209
|
name: 'options',
|
|
200
210
|
type: 'json',
|
|
@@ -210,7 +220,7 @@ export const aiSettingsGlobal = {
|
|
|
210
220
|
label: ''
|
|
211
221
|
}
|
|
212
222
|
],
|
|
213
|
-
label: '
|
|
223
|
+
label: 'Video Generation'
|
|
214
224
|
}
|
|
215
225
|
]
|
|
216
226
|
}
|
|
@@ -219,6 +229,18 @@ export const aiSettingsGlobal = {
|
|
|
219
229
|
}
|
|
220
230
|
],
|
|
221
231
|
hooks: {
|
|
232
|
+
afterChange: [
|
|
233
|
+
async ({ doc, req })=>{
|
|
234
|
+
if (doc.enabledCollections && doc.enabledCollections.length > 0) {
|
|
235
|
+
const { seedProperties } = await import('../utilities/seedProperties.js');
|
|
236
|
+
await seedProperties({
|
|
237
|
+
enabledCollections: doc.enabledCollections,
|
|
238
|
+
req
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return doc;
|
|
242
|
+
}
|
|
243
|
+
],
|
|
222
244
|
afterRead: [
|
|
223
245
|
async ({ context, doc, req })=>{
|
|
224
246
|
if (!req.payload.secret) {
|
|
@@ -254,10 +276,15 @@ export const aiSettingsGlobal = {
|
|
|
254
276
|
if (data.providers) {
|
|
255
277
|
data.providers = data.providers.map((provider)=>{
|
|
256
278
|
if (provider.apiKey) {
|
|
257
|
-
|
|
279
|
+
const originalProvider = originalDoc?.providers?.find((p)=>p.id === provider.id);
|
|
280
|
+
// If the key strictly equals the existing one (e.g. partial update merge), do nothing.
|
|
281
|
+
// This prevents re-encrypting an already encrypted key.
|
|
282
|
+
if (originalProvider?.apiKey && provider.apiKey === originalProvider.apiKey) {
|
|
283
|
+
return provider;
|
|
284
|
+
}
|
|
285
|
+
// If it looks like a masked key, don't re-encrypt (it means it wasn't changed via UI)
|
|
258
286
|
if (provider.apiKey.startsWith('sk-') && provider.apiKey.includes('****')) {
|
|
259
287
|
// Restore the original encrypted key from originalDoc
|
|
260
|
-
const originalProvider = originalDoc?.providers?.find((p)=>p.id === provider.id);
|
|
261
288
|
if (originalProvider?.apiKey) {
|
|
262
289
|
provider.apiKey = originalProvider.apiKey;
|
|
263
290
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/AISettings.ts"],"sourcesContent":["import type { GlobalConfig } from 'payload'\n\nimport { allProviderBlocks } from '../ai/providers/blocks/index.js'\n\nexport const aiSettingsGlobal: GlobalConfig = {\n slug: 'ai-settings',\n access: {\n read: ({ req }) => !!req.user,\n update: ({ req }) => !!req.user,\n },\n // admin: {\n // description: 'Configure AI providers, models, and default settings',\n // },\n fields: [\n {\n name: 'providers',\n type: 'blocks',\n admin: {\n description: 'Configure which AI providers to use and their settings',\n initCollapsed: true,\n },\n blocks: allProviderBlocks,\n label: 'AI Providers',\n required: true,\n },\n {\n name: 'defaults',\n type: 'group',\n admin: {\n description: 'Default provider/model behavior for each use case',\n },\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n fields: [\n {\n name: 'text',\n type: 'group',\n fields: [\n {\n name: 'provider',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicProviderSelect',\n },\n },\n label: 'Default Provider',\n },\n {\n name: 'model',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicModelSelect',\n },\n },\n label: 'Default Model',\n },\n {\n name: 'options',\n type: 'json',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#ProviderOptionsEditor',\n },\n description: 'Default options for this model (global)',\n },\n label: 'Global Model Options',\n },\n ],\n label: '',\n },\n ],\n label: 'Text Generation',\n },\n {\n fields: [\n {\n name: 'image',\n type: 'group',\n fields: [\n {\n name: 'provider',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicProviderSelect',\n },\n },\n label: 'Default Provider',\n },\n {\n name: 'model',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicModelSelect',\n },\n },\n label: 'Default Model',\n },\n {\n name: 'options',\n type: 'json',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#ProviderOptionsEditor',\n },\n description: 'Default options for this model (global)',\n },\n label: 'Global Model Options',\n },\n ],\n label: '',\n },\n ],\n label: 'Image Generation',\n },\n {\n fields: [\n {\n name: 'video',\n type: 'group',\n fields: [\n {\n name: 'provider',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicProviderSelect',\n },\n },\n label: 'Default Provider',\n },\n {\n name: 'model',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicModelSelect',\n },\n },\n label: 'Default Model',\n },\n {\n name: 'options',\n type: 'json',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#ProviderOptionsEditor',\n },\n description: 'Default options for this model (global)',\n },\n label: 'Global Model Options',\n },\n ],\n label: '',\n },\n ],\n label: 'Video Generation',\n },\n {\n fields: [\n {\n name: 'tts',\n type: 'group',\n fields: [\n {\n name: 'provider',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicProviderSelect',\n },\n },\n label: 'Default Provider',\n },\n {\n name: 'model',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicModelSelect',\n },\n },\n label: 'Default Model',\n },\n {\n name: 'voice',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicVoiceSelect',\n },\n },\n label: 'Default Voice',\n },\n {\n name: 'options',\n type: 'json',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#ProviderOptionsEditor',\n },\n description: 'Default options for this model (global)',\n },\n label: 'Global Model Options',\n },\n ],\n label: '',\n },\n ],\n label: 'Text-to-Speech',\n },\n ],\n },\n ],\n label: 'Default Models',\n },\n ],\n hooks: {\n afterRead: [\n async ({ context, doc, req }) => {\n if (!req.payload.secret) {\n return doc\n }\n\n const { decrypt } = await import('../utilities/encryption.js')\n\n if (doc.providers) {\n doc.providers = doc.providers.map((provider: any) => {\n if (provider.apiKey) {\n if (context.unsafe) {\n // Internal use: decrypt\n provider.apiKey = decrypt(provider.apiKey, req.payload.secret)\n } else {\n // Admin UI: mask\n // We can't easily check if it's valid without decrypting, but for UI we just show mask\n // If we want to show \"present\", we can return a mask\n provider.apiKey = 'sk-****' + provider.apiKey.slice(-4)\n }\n }\n return provider\n })\n }\n return doc\n },\n ],\n beforeChange: [\n async ({ data, originalDoc, req }) => {\n if (!req.payload.secret) {\n return data\n }\n\n const { encrypt } = await import('../utilities/encryption.js')\n\n // Iterate over providers and encrypt API keys\n if (data.providers) {\n data.providers = data.providers.map((provider: any) => {\n if (provider.apiKey) {\n // If it looks like a masked key, don't re-encrypt (it means it wasn't changed)\n if (provider.apiKey.startsWith('sk-') && provider.apiKey.includes('****')) {\n // Restore the original encrypted key from originalDoc\n const originalProvider = originalDoc?.providers?.find(\n (p: any) => p.id === provider.id,\n )\n if (originalProvider?.apiKey) {\n provider.apiKey = originalProvider.apiKey\n }\n } else {\n // Encrypt new key\n provider.apiKey = encrypt(provider.apiKey, req.payload.secret)\n }\n }\n return provider\n })\n }\n return data\n },\n ],\n },\n label: 'AI Configuration',\n}\n"],"names":["allProviderBlocks","aiSettingsGlobal","slug","access","read","req","user","update","fields","name","type","admin","description","initCollapsed","blocks","label","required","tabs","components","Field","hooks","afterRead","context","doc","payload","secret","decrypt","providers","map","provider","apiKey","unsafe","slice","beforeChange","data","originalDoc","encrypt","startsWith","includes","originalProvider","find","p","id"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,kCAAiC;AAEnE,OAAO,MAAMC,mBAAiC;IAC5CC,MAAM;IACNC,QAAQ;QACNC,MAAM,CAAC,EAAEC,GAAG,EAAE,GAAK,CAAC,CAACA,IAAIC,IAAI;QAC7BC,QAAQ,CAAC,EAAEF,GAAG,EAAE,GAAK,CAAC,CAACA,IAAIC,IAAI;IACjC;IACA,WAAW;IACX,yEAAyE;IACzE,KAAK;IACLE,QAAQ;QACN;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;gBACbC,eAAe;YACjB;YACAC,QAAQd;YACRe,OAAO;YACPC,UAAU;QACZ;QACA;YACEP,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,aAAa;YACf;YACAJ,QAAQ;gBACN;oBACEE,MAAM;oBACNO,MAAM;wBACJ;4BACET,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNF,QAAQ;wCACN;4CACEC,MAAM;4CACNC,MAAM;4CACNC,OAAO;gDACLO,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAJ,OAAO;wCACT;wCACA;4CACEN,MAAM;4CACNC,MAAM;4CACNC,OAAO;gDACLO,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAJ,OAAO;wCACT;wCACA;4CACEN,MAAM;4CACNC,MAAM;4CACNC,OAAO;gDACLO,YAAY;oDACVC,OAAO;gDACT;gDACAP,aAAa;4CACf;4CACAG,OAAO;wCACT;qCACD;oCACDA,OAAO;gCACT;6BACD;4BACDA,OAAO;wBACT;wBACA;4BACEP,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNF,QAAQ;wCACN;4CACEC,MAAM;4CACNC,MAAM;4CACNC,OAAO;gDACLO,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAJ,OAAO;wCACT;wCACA;4CACEN,MAAM;4CACNC,MAAM;4CACNC,OAAO;gDACLO,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAJ,OAAO;wCACT;wCACA;4CACEN,MAAM;4CACNC,MAAM;4CACNC,OAAO;gDACLO,YAAY;oDACVC,OAAO;gDACT;gDACAP,aAAa;4CACf;4CACAG,OAAO;wCACT;qCACD;oCACDA,OAAO;gCACT;6BACD;4BACDA,OAAO;wBACT;wBACA;4BACEP,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNF,QAAQ;wCACN;4CACEC,MAAM;4CACNC,MAAM;4CACNC,OAAO;gDACLO,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAJ,OAAO;wCACT;wCACA;4CACEN,MAAM;4CACNC,MAAM;4CACNC,OAAO;gDACLO,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAJ,OAAO;wCACT;wCACA;4CACEN,MAAM;4CACNC,MAAM;4CACNC,OAAO;gDACLO,YAAY;oDACVC,OAAO;gDACT;gDACAP,aAAa;4CACf;4CACAG,OAAO;wCACT;qCACD;oCACDA,OAAO;gCACT;6BACD;4BACDA,OAAO;wBACT;wBACA;4BACEP,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNF,QAAQ;wCACN;4CACEC,MAAM;4CACNC,MAAM;4CACNC,OAAO;gDACLO,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAJ,OAAO;wCACT;wCACA;4CACEN,MAAM;4CACNC,MAAM;4CACNC,OAAO;gDACLO,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAJ,OAAO;wCACT;wCACA;4CACEN,MAAM;4CACNC,MAAM;4CACNC,OAAO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G,CAAC,CAACC;wBACnC,IAAIA,SAASC,MAAM,EAAE;4BACnB,+EAA+E;4BAC/E,IAAID,SAASC,MAAM,CAACO,UAAU,CAAC,UAAUR,SAASC,MAAM,CAACQ,QAAQ,CAAC,SAAS;gCACzE,sDAAsD;gCACtD,MAAMC,mBAAmBJ,aAAaR,WAAWa,KAC/C,CAACC,IAAWA,EAAEC,EAAE,KAAKb,SAASa,EAAE;gCAElC,IAAIH,kBAAkBT,QAAQ;oCAC5BD,SAASC,MAAM,GAAGS,iBAAiBT,MAAM;gCAC3C;4BACF,OAAO;gCACL,kBAAkB;gCAClBD,SAASC,MAAM,GAAGM,QAAQP,SAASC,MAAM,EAAEzB,IAAImB,OAAO,CAACC,MAAM;4BAC/D;wBACF;wBACA,OAAOI;oBACT;gBACF;gBACA,OAAOK;YACT;SACD;IACH;IACAnB,OAAO;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/collections/AISettings.ts"],"sourcesContent":["import type { GlobalConfig } from 'payload'\n\nimport { allProviderBlocks } from '../ai/providers/blocks/index.js'\n\nexport const aiSettingsGlobal: GlobalConfig = {\n slug: 'ai-settings',\n access: {\n read: ({ req }) => !!req.user,\n update: ({ req }) => !!req.user,\n },\n admin: {\n group: false,\n },\n fields: [\n {\n name: 'providers',\n type: 'blocks',\n admin: {\n description: 'Configure which AI providers to use and their settings',\n initCollapsed: true,\n },\n blocks: allProviderBlocks,\n label: 'AI Providers',\n required: true,\n },\n {\n name: 'enabledCollections',\n type: 'json',\n admin: {\n hidden: true,\n },\n },\n {\n name: 'defaults',\n type: 'group',\n admin: {\n description: 'Please provide default provider/model behavior for each use case',\n },\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n fields: [\n {\n name: 'text',\n type: 'group',\n fields: [\n {\n name: 'provider',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicProviderSelect',\n },\n },\n label: 'Default Provider',\n },\n {\n name: 'model',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicModelSelect',\n },\n },\n label: 'Default Model',\n },\n {\n name: 'options',\n type: 'json',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#ProviderOptionsEditor',\n },\n description: 'Default options for this model (global)',\n },\n label: 'Global Model Options',\n },\n ],\n label: '',\n },\n ],\n label: 'Text Generation',\n },\n {\n fields: [\n {\n name: 'image',\n type: 'group',\n fields: [\n {\n name: 'provider',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicProviderSelect',\n },\n },\n label: 'Default Provider',\n },\n {\n name: 'model',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicModelSelect',\n },\n },\n label: 'Default Model',\n },\n {\n name: 'options',\n type: 'json',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#ProviderOptionsEditor',\n },\n description: 'Default options for this model (global)',\n },\n label: 'Global Model Options',\n },\n ],\n label: '',\n },\n ],\n label: 'Image Generation',\n },\n {\n fields: [\n {\n name: 'tts',\n type: 'group',\n fields: [\n {\n name: 'provider',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicProviderSelect',\n },\n },\n label: 'Default Provider',\n },\n {\n name: 'model',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicModelSelect',\n },\n },\n label: 'Default Model',\n },\n {\n name: 'voice',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicVoiceSelect',\n },\n },\n label: 'Default Voice',\n },\n {\n name: 'options',\n type: 'json',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#ProviderOptionsEditor',\n },\n description: 'Default options for this model (global)',\n },\n label: 'Global Model Options',\n },\n ],\n label: '',\n },\n ],\n label: 'Speech Generation',\n },\n {\n admin: {\n disabled: true,\n },\n fields: [\n {\n name: 'video',\n type: 'group',\n fields: [\n {\n name: 'provider',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicProviderSelect',\n },\n },\n label: 'Default Provider',\n },\n {\n name: 'model',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicModelSelect',\n },\n },\n label: 'Default Model',\n },\n {\n name: 'options',\n type: 'json',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#ProviderOptionsEditor',\n },\n description: 'Default options for this model (global)',\n },\n label: 'Global Model Options',\n },\n ],\n label: '',\n },\n ],\n label: 'Video Generation',\n },\n ],\n },\n ],\n label: 'Default Models',\n },\n ],\n hooks: {\n afterChange: [\n async ({ doc, req }) => {\n if (doc.enabledCollections && doc.enabledCollections.length > 0) {\n const { seedProperties } = await import('../utilities/seedProperties.js')\n await seedProperties({\n enabledCollections: doc.enabledCollections,\n req,\n })\n }\n return doc\n },\n ],\n afterRead: [\n async ({ context, doc, req }) => {\n if (!req.payload.secret) {\n return doc\n }\n\n const { decrypt } = await import('../utilities/encryption.js')\n\n if (doc.providers) {\n doc.providers = doc.providers.map((provider: any) => {\n if (provider.apiKey) {\n if (context.unsafe) {\n // Internal use: decrypt\n provider.apiKey = decrypt(provider.apiKey, req.payload.secret)\n } else {\n // Admin UI: mask\n // We can't easily check if it's valid without decrypting, but for UI we just show mask\n // If we want to show \"present\", we can return a mask\n provider.apiKey = 'sk-****' + provider.apiKey.slice(-4)\n }\n }\n return provider\n })\n }\n return doc\n },\n ],\n beforeChange: [\n async ({ data, originalDoc, req }) => {\n if (!req.payload.secret) {\n return data\n }\n\n const { encrypt } = await import('../utilities/encryption.js')\n\n // Iterate over providers and encrypt API keys\n if (data.providers) {\n data.providers = data.providers.map((provider: any) => {\n if (provider.apiKey) {\n const originalProvider = originalDoc?.providers?.find(\n (p: any) => p.id === provider.id,\n )\n\n // If the key strictly equals the existing one (e.g. partial update merge), do nothing.\n // This prevents re-encrypting an already encrypted key.\n if (originalProvider?.apiKey && provider.apiKey === originalProvider.apiKey) {\n return provider\n }\n\n // If it looks like a masked key, don't re-encrypt (it means it wasn't changed via UI)\n if (provider.apiKey.startsWith('sk-') && provider.apiKey.includes('****')) {\n // Restore the original encrypted key from originalDoc\n if (originalProvider?.apiKey) {\n provider.apiKey = originalProvider.apiKey\n }\n } else {\n // Encrypt new key\n provider.apiKey = encrypt(provider.apiKey, req.payload.secret)\n }\n }\n return provider\n })\n }\n return data\n },\n ],\n },\n label: 'AI Configuration',\n}\n"],"names":["allProviderBlocks","aiSettingsGlobal","slug","access","read","req","user","update","admin","group","fields","name","type","description","initCollapsed","blocks","label","required","hidden","tabs","components","Field","disabled","hooks","afterChange","doc","enabledCollections","length","seedProperties","afterRead","context","payload","secret","decrypt","providers","map","provider","apiKey","unsafe","slice","beforeChange","data","originalDoc","encrypt","originalProvider","find","p","id","startsWith","includes"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,kCAAiC;AAEnE,OAAO,MAAMC,mBAAiC;IAC5CC,MAAM;IACNC,QAAQ;QACNC,MAAM,CAAC,EAAEC,GAAG,EAAE,GAAK,CAAC,CAACA,IAAIC,IAAI;QAC7BC,QAAQ,CAAC,EAAEF,GAAG,EAAE,GAAK,CAAC,CAACA,IAAIC,IAAI;IACjC;IACAE,OAAO;QACLC,OAAO;IACT;IACAC,QAAQ;QACN;YACEC,MAAM;YACNC,MAAM;YACNJ,OAAO;gBACLK,aAAa;gBACbC,eAAe;YACjB;YACAC,QAAQf;YACRgB,OAAO;YACPC,UAAU;QACZ;QACA;YACEN,MAAM;YACNC,MAAM;YACNJ,OAAO;gBACLU,QAAQ;YACV;QACF;QACA;YACEP,MAAM;YACNC,MAAM;YACNJ,OAAO;gBACLK,aAAa;YACf;YACAH,QAAQ;gBACN;oBACEE,MAAM;oBACNO,MAAM;wBACJ;4BACET,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNF,QAAQ;wCACN;4CACEC,MAAM;4CACNC,MAAM;4CACNJ,OAAO;gDACLY,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAL,OAAO;wCACT;wCACA;4CACEL,MAAM;4CACNC,MAAM;4CACNJ,OAAO;gDACLY,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAL,OAAO;wCACT;wCACA;4CACEL,MAAM;4CACNC,MAAM;4CACNJ,OAAO;gDACLY,YAAY;oDACVC,OAAO;gDACT;gDACAR,aAAa;4CACf;4CACAG,OAAO;wCACT;qCACD;oCACDA,OAAO;gCACT;6BACD;4BACDA,OAAO;wBACT;wBACA;4BACEN,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNF,QAAQ;wCACN;4CACEC,MAAM;4CACNC,MAAM;4CACNJ,OAAO;gDACLY,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAL,OAAO;wCACT;wCACA;4CACEL,MAAM;4CACNC,MAAM;4CACNJ,OAAO;gDACLY,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAL,OAAO;wCACT;wCACA;4CACEL,MAAM;4CACNC,MAAM;4CACNJ,OAAO;gDACLY,YAAY;oDACVC,OAAO;gDACT;gDACAR,aAAa;4CACf;4CACAG,OAAO;wCACT;qCACD;oCACDA,OAAO;gCACT;6BACD;4BACDA,OAAO;wBACT;wBACA;4BACEN,QAAQ;gCACN;oCACEC,MAAM;oCACNC,MAAM;oCACNF,QAAQ;wCACN;4CACEC,MAAM;4CACNC,MAAM;4CACNJ,OAAO;gDACLY,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAL,OAAO;wCACT;wCACA;4CACEL,MAAM;4CACNC,MAAM;4CACNJ,OAAO;gDACLY,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAL,OAAO;wCACT;wCACA;4CACEL,MAAM;4CACNC,MAAM;4CACNJ,OAAO;gDACLY,YAAY;oDACVC,OAAO;gDACT;4CACF;4CACAL,OAAO;wCACT;wCACA;4CACEL,MAAM;4CACNC,MAAM;4CACNJ,OAAO;gDACLY,YAAY;oDACVC,OAAO;gDACT;gDACAR,aAAa;4CACf;4CACAG,OAAO;wCACT;qCACD;oCACDA,O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H;IACAzB,OAAO;AACT,EAAC"}
|
|
@@ -30,6 +30,13 @@ const CAPABILITIES = [
|
|
|
30
30
|
fields: [
|
|
31
31
|
'upload'
|
|
32
32
|
]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: 'array',
|
|
36
|
+
name: 'Array Generation',
|
|
37
|
+
fields: [
|
|
38
|
+
'array'
|
|
39
|
+
]
|
|
33
40
|
}
|
|
34
41
|
];
|
|
35
42
|
const defaultAccessConfig = {
|
|
@@ -174,6 +181,10 @@ export const instructionsCollection = (pluginConfig)=>({
|
|
|
174
181
|
{
|
|
175
182
|
label: 'richText',
|
|
176
183
|
value: 'richText'
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
label: 'array',
|
|
187
|
+
value: 'array'
|
|
177
188
|
}
|
|
178
189
|
]
|
|
179
190
|
},
|
|
@@ -391,6 +402,32 @@ informative and accurate but also captivating and beautifully structured.`,
|
|
|
391
402
|
providerOptionsJson
|
|
392
403
|
],
|
|
393
404
|
label: 'TTS Settings'
|
|
405
|
+
},
|
|
406
|
+
// Array Settings
|
|
407
|
+
// Array Settings
|
|
408
|
+
{
|
|
409
|
+
name: 'array-settings',
|
|
410
|
+
type: 'group',
|
|
411
|
+
admin: {
|
|
412
|
+
condition: (data)=>data['model-id'] === 'array'
|
|
413
|
+
},
|
|
414
|
+
fields: [
|
|
415
|
+
providerSelect,
|
|
416
|
+
modelSelect,
|
|
417
|
+
{
|
|
418
|
+
name: 'count',
|
|
419
|
+
type: 'number',
|
|
420
|
+
admin: {
|
|
421
|
+
description: 'Number of items to generate'
|
|
422
|
+
},
|
|
423
|
+
defaultValue: 3,
|
|
424
|
+
label: 'Items to Generate',
|
|
425
|
+
max: 20,
|
|
426
|
+
min: 1
|
|
427
|
+
},
|
|
428
|
+
providerOptionsJson
|
|
429
|
+
],
|
|
430
|
+
label: 'Array Settings'
|
|
394
431
|
}
|
|
395
432
|
]
|
|
396
433
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/Instructions.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\nimport type { PluginConfig } from 'src/types.js'\n\nimport { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\n\n// Defined capabilities replacing src/ai/models/\nconst CAPABILITIES = [\n {\n id: 'text',\n name: 'Text Generation',\n fields: ['text', 'textarea'],\n },\n {\n id: 'richtext',\n name: 'Rich Text Generation',\n fields: ['richText'],\n },\n {\n id: 'image',\n name: 'Image Generation',\n fields: ['upload'],\n },\n {\n id: 'tts',\n name: 'Text to Speech',\n fields: ['upload'],\n },\n]\n\nconst defaultAccessConfig = {\n create: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n delete: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n read: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n update: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n}\n\nconst defaultAdminConfig = {\n group: 'Plugins',\n hidden: true,\n}\n\nconst providerSelect = {\n name: 'provider',\n type: 'text' as const,\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicProviderSelect',\n },\n },\n label: 'Provider',\n}\n\nconst modelSelect = {\n name: 'model',\n type: 'text' as const,\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicModelSelect',\n },\n },\n label: 'Model',\n}\n\nconst providerOptionsJson = {\n name: 'providerOptions',\n type: 'json' as const,\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#ProviderOptionsEditor',\n },\n description: 'Provider-specific options. Defaults are inherited from AI Settings.',\n },\n label: 'Provider Options',\n}\n\nconst commonTextParams = [\n {\n type: 'row' as const,\n fields: [\n {\n name: 'maxTokens',\n type: 'number' as const,\n admin: {\n placeholder: 'Model Default',\n },\n label: 'Max Tokens',\n },\n {\n name: 'temperature',\n type: 'number' as const,\n defaultValue: 0.7,\n label: 'Temperature',\n max: 1,\n min: 0,\n },\n ],\n },\n {\n name: 'extractAttachments',\n type: 'checkbox' as const,\n label: 'Extract Attachments',\n },\n]\n\nexport const instructionsCollection = (pluginConfig: PluginConfig) =>\n <CollectionConfig>{\n labels: {\n plural: 'Compose Settings',\n singular: 'Compose Setting',\n },\n ...pluginConfig.overrideInstructions,\n slug: PLUGIN_INSTRUCTIONS_TABLE,\n access: {\n ...defaultAccessConfig,\n ...pluginConfig.overrideInstructions?.access,\n },\n admin: {\n ...defaultAdminConfig,\n ...pluginConfig.overrideInstructions?.admin,\n components: {\n beforeList: ['@ai-stack/payloadcms/client#AIConfigDashboard'],\n },\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: CAPABILITIES.map((c) => ({\n fields: c.fields,\n label: c.name,\n value: c.id,\n })),\n },\n path: '@ai-stack/payloadcms/fields#SelectField',\n },\n },\n },\n label: 'Capability',\n options: CAPABILITIES.map((c) => ({\n label: c.name,\n value: c.id,\n })),\n },\n {\n name: 'disabled',\n type: 'checkbox',\n admin: {\n description: 'Please reload your collection after applying the changes',\n },\n defaultValue: false,\n label: 'Hide Compose button for this field',\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'] === 'image'\n },\n },\n description:\n 'These images will be used to generate new visuals in a similar style, layout, or content.',\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 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 \n // Inline Settings Groups by Capability\n \n // Text Settings\n {\n name: 'text-settings',\n type: 'group',\n admin: {\n condition: (data) => data['model-id'] === 'text',\n },\n fields: [\n providerSelect,\n modelSelect,\n ...commonTextParams,\n providerOptionsJson,\n ],\n label: 'Text Settings',\n },\n \n // Rich Text Settings\n {\n name: 'richtext-settings',\n type: 'group',\n admin: {\n condition: (data) => data['model-id'] === 'richtext',\n },\n fields: [\n providerSelect,\n modelSelect,\n ...commonTextParams,\n providerOptionsJson,\n ],\n label: 'Rich Text Settings',\n },\n \n // Image Settings\n {\n name: 'image-settings',\n type: 'group',\n admin: {\n condition: (data) => data['model-id'] === 'image',\n },\n fields: [\n providerSelect,\n modelSelect,\n providerOptionsJson,\n ],\n label: 'Image Settings',\n },\n \n // TTS Settings\n {\n name: 'tts-settings',\n type: 'group',\n admin: {\n condition: (data) => data['model-id'] === 'tts',\n },\n fields: [\n providerSelect,\n modelSelect,\n {\n name: 'voice',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicVoiceSelect',\n },\n },\n label: 'Voice',\n },\n providerOptionsJson,\n ],\n label: 'TTS Settings',\n },\n ],\n }\n"],"names":["PLUGIN_INSTRUCTIONS_TABLE","CAPABILITIES","id","name","fields","defaultAccessConfig","create","req","user","delete","read","update","defaultAdminConfig","group","hidden","providerSelect","type","admin","components","Field","label","modelSelect","providerOptionsJson","description","commonTextParams","placeholder","defaultValue","max","min","instructionsCollection","pluginConfig","labels","plural","singular","overrideInstructions","slug","access","beforeList","unique","options","value","condition","_","current","clientProps","filterByField","map","c","path","tabs","relationTo","uploadCollectionSlug","data"],"mappings":"AAGA,SAASA,yBAAyB,QAAQ,iBAAgB;AAE1D,gDAAgD;AAAhD,gDAAgD;AAChD,MAAMC,eAAe;IACnB;QACEC,IAAI;QACJC,MAAM;QACNC,QAAQ;YAAC;YAAQ;SAAW;IAC9B;IACA;QACEF,IAAI;QACJC,MAAM;QACNC,QAAQ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AAM;gCACNC,OAAO;oCACLwB,WAAW,CAACC,GAAGC;wCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;oCACnC;gCACF;gCACAjB,cAAc,CAAC;;;;;;;2HAO4F,CAAC;gCAC5GN,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;iBACD;YACH;YAEA,uCAAuC;YAEvC,gBAAgB;YAFhB,uCAAuC;YAEvC,gBAAgB;YAChB;gBACEjB,MAAM;gBACNa,MAAM;gBACNC,OAAO;oBACLwB,WAAW,CAACW,OAASA,IAAI,CAAC,WAAW,KAAK;gBAC5C;gBACAhD,QAAQ;oBACNW;oBACAM;uBACGG;oBACHF;iBACD;gBACDF,OAAO;YACT;YAEA,qBAAqB;YAArB,qBAAqB;YACrB;gBACEjB,MAAM;gBACNa,MAAM;gBACNC,OAAO;oBACLwB,WAAW,CAACW,OAASA,IAAI,CAAC,WAAW,KAAK;gBAC5C;gBACAhD,QAAQ;oBACNW;oBACAM;uBACGG;oBACHF;iBACD;gBACDF,OAAO;YACT;YAEA,iBAAiB;YAAjB,iBAAiB;YACjB;gBACEjB,MAAM;gBACNa,MAAM;gBACNC,OAAO;oBACLwB,WAAW,CAACW,OAASA,IAAI,CAAC,WAAW,KAAK;gBAC5C;gBACAhD,QAAQ;oBACNW;oBACAM;oBACAC;iBACD;gBACDF,OAAO;YACT;YAEA,eAAe;YAAf,eAAe;YACf;gBACEjB,MAAM;gBACNa,MAAM;gBACNC,OAAO;oBACLwB,WAAW,CAACW,OAASA,IAAI,CAAC,WAAW,KAAK;gBAC5C;gBACAhD,QAAQ;oBACNW;oBACAM;oBACA;wBACElB,MAAM;wBACNa,MAAM;wBACNC,OAAO;4BACLC,YAAY;gCACVC,OAAO;4BACT;wBACF;wBACAC,OAAO;oBACT;oBACAE;iBACD;gBACDF,OAAO;YACT;SACD;IACH,CAAA,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/collections/Instructions.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\nimport type { PluginConfig } from 'src/types.js'\n\nimport { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\n\n// Defined capabilities replacing src/ai/models/\nconst CAPABILITIES = [\n {\n id: 'text',\n name: 'Text Generation',\n fields: ['text', 'textarea'],\n },\n {\n id: 'richtext',\n name: 'Rich Text Generation',\n fields: ['richText'],\n },\n {\n id: 'image',\n name: 'Image Generation',\n fields: ['upload'],\n },\n {\n id: 'tts',\n name: 'Text to Speech',\n fields: ['upload'],\n },\n {\n id: 'array',\n name: 'Array Generation',\n fields: ['array'],\n },\n]\n\nconst defaultAccessConfig = {\n create: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n delete: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n read: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n update: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n}\n\nconst defaultAdminConfig = {\n group: 'Plugins',\n hidden: true,\n}\n\nconst providerSelect = {\n name: 'provider',\n type: 'text' as const,\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicProviderSelect',\n },\n },\n label: 'Provider',\n}\n\nconst modelSelect = {\n name: 'model',\n type: 'text' as const,\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicModelSelect',\n },\n },\n label: 'Model',\n}\n\nconst providerOptionsJson = {\n name: 'providerOptions',\n type: 'json' as const,\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#ProviderOptionsEditor',\n },\n description: 'Provider-specific options. Defaults are inherited from AI Settings.',\n },\n label: 'Provider Options',\n}\n\nconst commonTextParams = [\n {\n type: 'row' as const,\n fields: [\n {\n name: 'maxTokens',\n type: 'number' as const,\n admin: {\n placeholder: 'Model Default',\n },\n label: 'Max Tokens',\n },\n {\n name: 'temperature',\n type: 'number' as const,\n defaultValue: 0.7,\n label: 'Temperature',\n max: 1,\n min: 0,\n },\n ],\n },\n {\n name: 'extractAttachments',\n type: 'checkbox' as const,\n label: 'Extract Attachments',\n },\n]\n\nexport const instructionsCollection = (pluginConfig: PluginConfig) =>\n <CollectionConfig>{\n labels: {\n plural: 'Compose Settings',\n singular: 'Compose Setting',\n },\n ...pluginConfig.overrideInstructions,\n slug: PLUGIN_INSTRUCTIONS_TABLE,\n access: {\n ...defaultAccessConfig,\n ...pluginConfig.overrideInstructions?.access,\n },\n admin: {\n ...defaultAdminConfig,\n ...pluginConfig.overrideInstructions?.admin,\n components: {\n beforeList: ['@ai-stack/payloadcms/client#AIConfigDashboard'],\n },\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 label: 'array',\n value: 'array',\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: CAPABILITIES.map((c) => ({\n fields: c.fields,\n label: c.name,\n value: c.id,\n })),\n },\n path: '@ai-stack/payloadcms/fields#SelectField',\n },\n },\n },\n label: 'Capability',\n options: CAPABILITIES.map((c) => ({\n label: c.name,\n value: c.id,\n })),\n },\n {\n name: 'disabled',\n type: 'checkbox',\n admin: {\n description: 'Please reload your collection after applying the changes',\n },\n defaultValue: false,\n label: 'Hide Compose button for this field',\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'] === 'image'\n },\n },\n description:\n 'These images will be used to generate new visuals in a similar style, layout, or content.',\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 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 \n // Inline Settings Groups by Capability\n \n // Text Settings\n {\n name: 'text-settings',\n type: 'group',\n admin: {\n condition: (data) => data['model-id'] === 'text',\n },\n fields: [\n providerSelect,\n modelSelect,\n ...commonTextParams,\n providerOptionsJson,\n ],\n label: 'Text Settings',\n },\n \n // Rich Text Settings\n {\n name: 'richtext-settings',\n type: 'group',\n admin: {\n condition: (data) => data['model-id'] === 'richtext',\n },\n fields: [\n providerSelect,\n modelSelect,\n ...commonTextParams,\n providerOptionsJson,\n ],\n label: 'Rich Text Settings',\n },\n \n // Image Settings\n {\n name: 'image-settings',\n type: 'group',\n admin: {\n condition: (data) => data['model-id'] === 'image',\n },\n fields: [\n providerSelect,\n modelSelect,\n providerOptionsJson,\n ],\n label: 'Image Settings',\n },\n \n // TTS Settings\n {\n name: 'tts-settings',\n type: 'group',\n admin: {\n condition: (data) => data['model-id'] === 'tts',\n },\n fields: [\n providerSelect,\n modelSelect,\n {\n name: 'voice',\n type: 'text',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/client#DynamicVoiceSelect',\n },\n },\n label: 'Voice',\n },\n providerOptionsJson,\n ],\n label: 'TTS Settings',\n },\n \n // Array Settings\n {\n name: 'array-settings',\n type: 'group',\n admin: {\n condition: (data) => data['model-id'] === 'array',\n },\n fields: [\n providerSelect,\n modelSelect,\n {\n name: 'count',\n type: 'number',\n admin: {\n description: 'Number of items to generate',\n },\n defaultValue: 3,\n label: 'Items to Generate',\n max: 20,\n min: 1,\n },\n providerOptionsJson,\n ],\n label: 'Array Settings',\n },\n ],\n }\n"],"names":["PLUGIN_INSTRUCTIONS_TABLE","CAPABILITIES","id","name","fields","defaultAccessConfig","create","req","user","delete","read","update","defaultAdminConfig","group","hidden","providerSelect","type","admin","components","Field","label","modelSelect","providerOptionsJson","description","commonTextParams","placeholder","defaultValue","max","min","instructionsCollection","pluginConfig","labels","plural","singular","overrideInstructions","slug","access","beforeList","unique","options","value","condition","_","current","clientProps","filterByField","map","c","path","tabs","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oBACLwB,WAAW,CAACW,OAASA,IAAI,CAAC,WAAW,KAAK;gBAC5C;gBACAhD,QAAQ;oBACNW;oBACAM;oBACA;wBACElB,MAAM;wBACNa,MAAM;wBACNC,OAAO;4BACLC,YAAY;gCACVC,OAAO;4BACT;wBACF;wBACAC,OAAO;oBACT;oBACAE;iBACD;gBACDF,OAAO;YACT;YAEA,iBAAiB;YAAjB,iBAAiB;YACjB;gBACEjB,MAAM;gBACNa,MAAM;gBACNC,OAAO;oBACLwB,WAAW,CAACW,OAASA,IAAI,CAAC,WAAW,KAAK;gBAC5C;gBACAhD,QAAQ;oBACNW;oBACAM;oBACA;wBACElB,MAAM;wBACNa,MAAM;wBACNC,OAAO;4BACLM,aAAa;wBACf;wBACAG,cAAc;wBACdN,OAAO;wBACPO,KAAK;wBACLC,KAAK;oBACP;oBACAN;iBACD;gBACDF,OAAO;YACT;SACD;IACH,CAAA,EAAC"}
|
package/dist/defaults.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export declare const PLUGIN_API_ENDPOINT_VIDEOGEN_WEBHOOK = "/plugin-ai/videogen
|
|
|
10
10
|
export declare const PLUGIN_API_ENDPOINT_FETCH_VOICES = "/plugin-ai/elevenlabs/fetch-voices";
|
|
11
11
|
export declare const PLUGIN_DEFAULT_OPENAI_MODEL = "gpt-4o-mini";
|
|
12
12
|
export declare const PLUGIN_DEFAULT_ANTHROPIC_MODEL = "claude-3-5-sonnet-latest";
|
|
13
|
+
export declare const excludeCollections: string[];
|
package/dist/defaults.js
CHANGED
|
@@ -12,5 +12,13 @@ export const PLUGIN_API_ENDPOINT_FETCH_VOICES = `${PLUGIN_API_ENDPOINT_BASE}/ele
|
|
|
12
12
|
// LLM Settings
|
|
13
13
|
export const PLUGIN_DEFAULT_OPENAI_MODEL = `gpt-4o-mini`;
|
|
14
14
|
export const PLUGIN_DEFAULT_ANTHROPIC_MODEL = `claude-3-5-sonnet-latest`;
|
|
15
|
+
export const excludeCollections = [
|
|
16
|
+
'payload-preferences',
|
|
17
|
+
'payload-migrations',
|
|
18
|
+
'payload-locked-documents',
|
|
19
|
+
'ai-settings',
|
|
20
|
+
PLUGIN_INSTRUCTIONS_TABLE,
|
|
21
|
+
PLUGIN_AI_JOBS_TABLE
|
|
22
|
+
];
|
|
15
23
|
|
|
16
24
|
//# sourceMappingURL=defaults.js.map
|
package/dist/defaults.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const PLUGIN_NAME = 'plugin-ai'\nexport const PLUGIN_INSTRUCTIONS_TABLE = `${PLUGIN_NAME}-instructions`\nexport const PLUGIN_AI_JOBS_TABLE = `${PLUGIN_NAME}-ai-jobs`\nexport const PLUGIN_LEXICAL_EDITOR_FEATURE = `${PLUGIN_NAME}-actions-feature`\n\n// Endpoint defaults\nexport const PLUGIN_API_ENDPOINT_BASE = `/${PLUGIN_NAME}`\nexport const PLUGIN_API_ENDPOINT_GENERATE = `${PLUGIN_API_ENDPOINT_BASE}/generate`\nexport const PLUGIN_API_ENDPOINT_GENERATE_UPLOAD = `${PLUGIN_API_ENDPOINT_GENERATE}/upload`\nexport const PLUGIN_FETCH_FIELDS_ENDPOINT = `${PLUGIN_API_ENDPOINT_BASE}/fetch-fields`\nexport const PLUGIN_API_ENDPOINT_VIDEOGEN_WEBHOOK = `${PLUGIN_API_ENDPOINT_BASE}/videogen/webhook`\nexport const PLUGIN_API_ENDPOINT_FETCH_VOICES = `${PLUGIN_API_ENDPOINT_BASE}/elevenlabs/fetch-voices`\n\n// LLM Settings\nexport const PLUGIN_DEFAULT_OPENAI_MODEL = `gpt-4o-mini`\nexport const PLUGIN_DEFAULT_ANTHROPIC_MODEL = `claude-3-5-sonnet-latest`\n"],"names":["PLUGIN_NAME","PLUGIN_INSTRUCTIONS_TABLE","PLUGIN_AI_JOBS_TABLE","PLUGIN_LEXICAL_EDITOR_FEATURE","PLUGIN_API_ENDPOINT_BASE","PLUGIN_API_ENDPOINT_GENERATE","PLUGIN_API_ENDPOINT_GENERATE_UPLOAD","PLUGIN_FETCH_FIELDS_ENDPOINT","PLUGIN_API_ENDPOINT_VIDEOGEN_WEBHOOK","PLUGIN_API_ENDPOINT_FETCH_VOICES","PLUGIN_DEFAULT_OPENAI_MODEL","PLUGIN_DEFAULT_ANTHROPIC_MODEL"],"mappings":"AAAA,OAAO,MAAMA,cAAc,YAAW;AACtC,OAAO,MAAMC,4BAA4B,CAAC,EAAED,YAAY,aAAa,CAAC,CAAA;AACtE,OAAO,MAAME,uBAAuB,CAAC,EAAEF,YAAY,QAAQ,CAAC,CAAA;AAC5D,OAAO,MAAMG,gCAAgC,CAAC,EAAEH,YAAY,gBAAgB,CAAC,CAAA;AAE7E,oBAAoB;AACpB,OAAO,MAAMI,2BAA2B,CAAC,CAAC,EAAEJ,YAAY,CAAC,CAAA;AACzD,OAAO,MAAMK,+BAA+B,CAAC,EAAED,yBAAyB,SAAS,CAAC,CAAA;AAClF,OAAO,MAAME,sCAAsC,CAAC,EAAED,6BAA6B,OAAO,CAAC,CAAA;AAC3F,OAAO,MAAME,+BAA+B,CAAC,EAAEH,yBAAyB,aAAa,CAAC,CAAA;AACtF,OAAO,MAAMI,uCAAuC,CAAC,EAAEJ,yBAAyB,iBAAiB,CAAC,CAAA;AAClG,OAAO,MAAMK,mCAAmC,CAAC,EAAEL,yBAAyB,wBAAwB,CAAC,CAAA;AAErG,eAAe;AACf,OAAO,MAAMM,8BAA8B,CAAC,WAAW,CAAC,CAAA;AACxD,OAAO,MAAMC,iCAAiC,CAAC,wBAAwB,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const PLUGIN_NAME = 'plugin-ai'\nexport const PLUGIN_INSTRUCTIONS_TABLE = `${PLUGIN_NAME}-instructions`\nexport const PLUGIN_AI_JOBS_TABLE = `${PLUGIN_NAME}-ai-jobs`\nexport const PLUGIN_LEXICAL_EDITOR_FEATURE = `${PLUGIN_NAME}-actions-feature`\n\n// Endpoint defaults\nexport const PLUGIN_API_ENDPOINT_BASE = `/${PLUGIN_NAME}`\nexport const PLUGIN_API_ENDPOINT_GENERATE = `${PLUGIN_API_ENDPOINT_BASE}/generate`\nexport const PLUGIN_API_ENDPOINT_GENERATE_UPLOAD = `${PLUGIN_API_ENDPOINT_GENERATE}/upload`\nexport const PLUGIN_FETCH_FIELDS_ENDPOINT = `${PLUGIN_API_ENDPOINT_BASE}/fetch-fields`\nexport const PLUGIN_API_ENDPOINT_VIDEOGEN_WEBHOOK = `${PLUGIN_API_ENDPOINT_BASE}/videogen/webhook`\nexport const PLUGIN_API_ENDPOINT_FETCH_VOICES = `${PLUGIN_API_ENDPOINT_BASE}/elevenlabs/fetch-voices`\n\n// LLM Settings\nexport const PLUGIN_DEFAULT_OPENAI_MODEL = `gpt-4o-mini`\nexport const PLUGIN_DEFAULT_ANTHROPIC_MODEL = `claude-3-5-sonnet-latest`\n\nexport const excludeCollections = [\n 'payload-preferences',\n 'payload-migrations',\n 'payload-locked-documents',\n 'ai-settings',\n PLUGIN_INSTRUCTIONS_TABLE,\n PLUGIN_AI_JOBS_TABLE,\n]\n"],"names":["PLUGIN_NAME","PLUGIN_INSTRUCTIONS_TABLE","PLUGIN_AI_JOBS_TABLE","PLUGIN_LEXICAL_EDITOR_FEATURE","PLUGIN_API_ENDPOINT_BASE","PLUGIN_API_ENDPOINT_GENERATE","PLUGIN_API_ENDPOINT_GENERATE_UPLOAD","PLUGIN_FETCH_FIELDS_ENDPOINT","PLUGIN_API_ENDPOINT_VIDEOGEN_WEBHOOK","PLUGIN_API_ENDPOINT_FETCH_VOICES","PLUGIN_DEFAULT_OPENAI_MODEL","PLUGIN_DEFAULT_ANTHROPIC_MODEL","excludeCollections"],"mappings":"AAAA,OAAO,MAAMA,cAAc,YAAW;AACtC,OAAO,MAAMC,4BAA4B,CAAC,EAAED,YAAY,aAAa,CAAC,CAAA;AACtE,OAAO,MAAME,uBAAuB,CAAC,EAAEF,YAAY,QAAQ,CAAC,CAAA;AAC5D,OAAO,MAAMG,gCAAgC,CAAC,EAAEH,YAAY,gBAAgB,CAAC,CAAA;AAE7E,oBAAoB;AACpB,OAAO,MAAMI,2BAA2B,CAAC,CAAC,EAAEJ,YAAY,CAAC,CAAA;AACzD,OAAO,MAAMK,+BAA+B,CAAC,EAAED,yBAAyB,SAAS,CAAC,CAAA;AAClF,OAAO,MAAME,sCAAsC,CAAC,EAAED,6BAA6B,OAAO,CAAC,CAAA;AAC3F,OAAO,MAAME,+BAA+B,CAAC,EAAEH,yBAAyB,aAAa,CAAC,CAAA;AACtF,OAAO,MAAMI,uCAAuC,CAAC,EAAEJ,yBAAyB,iBAAiB,CAAC,CAAA;AAClG,OAAO,MAAMK,mCAAmC,CAAC,EAAEL,yBAAyB,wBAAwB,CAAC,CAAA;AAErG,eAAe;AACf,OAAO,MAAMM,8BAA8B,CAAC,WAAW,CAAC,CAAA;AACxD,OAAO,MAAMC,iCAAiC,CAAC,wBAAwB,CAAC,CAAA;AAExE,OAAO,MAAMC,qBAAqB;IAChC;IACA;IACA;IACA;IACAX;IACAC;CACD,CAAA"}
|
|
@@ -9,6 +9,15 @@ export const fetchFields = (config)=>{
|
|
|
9
9
|
});
|
|
10
10
|
let isConfigAllowed = true // Users allowed to update prompts by default
|
|
11
11
|
;
|
|
12
|
+
let enabledCollections = [];
|
|
13
|
+
try {
|
|
14
|
+
const { enabledCollections: storedEnabledCollections } = await req.payload.findGlobal({
|
|
15
|
+
slug: 'ai-settings'
|
|
16
|
+
});
|
|
17
|
+
enabledCollections = storedEnabledCollections || [];
|
|
18
|
+
} catch (e) {
|
|
19
|
+
req.payload.logger.error('Failed to fetch AI settings');
|
|
20
|
+
}
|
|
12
21
|
if (access?.settings) {
|
|
13
22
|
try {
|
|
14
23
|
isConfigAllowed = await access.settings({
|
|
@@ -29,6 +38,7 @@ export const fetchFields = (config)=>{
|
|
|
29
38
|
return Response.json({
|
|
30
39
|
...options,
|
|
31
40
|
debugging: config.debugging,
|
|
41
|
+
enabledCollections,
|
|
32
42
|
fields: fieldMap,
|
|
33
43
|
isConfigAllowed,
|
|
34
44
|
promptFields: promptFields.map(({ getter: _getter, ...field })=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/fetchFields.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload'\n\nimport type { PluginConfig, SerializedPromptField } from '../types.js'\n\nimport { PLUGIN_FETCH_FIELDS_ENDPOINT, PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\n\nexport const fetchFields: (config: PluginConfig) => Endpoint = (config) => {\n const { access, options = {}, promptFields = [] } = config\n return {\n handler: async (req: PayloadRequest) => {\n const { docs = [] } = await req.payload.find({\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n pagination: false,\n })\n\n let isConfigAllowed = true // Users allowed to update prompts by default\n\n if (access?.settings) {\n try {\n isConfigAllowed = await access.settings({ req })\n } catch (e) {\n req.payload.logger.error(req, 'Please check your \"access.settings\" for request')\n }\n }\n\n const fieldMap: Record<string, { disabled?: boolean; fieldType: any; id: any }> = {}\n docs.forEach((doc) => {\n fieldMap[doc['schema-path']] = {\n id: doc.id,\n disabled: !!doc['disabled'],\n fieldType: doc['field-type'],\n }\n })\n\n return Response.json({\n ...options,\n debugging: config.debugging,\n fields: fieldMap,\n isConfigAllowed,\n promptFields: promptFields.map(({ getter: _getter, ...field }): SerializedPromptField => {\n return field\n }),\n })\n },\n method: 'get',\n path: PLUGIN_FETCH_FIELDS_ENDPOINT,\n }\n}\n"],"names":["PLUGIN_FETCH_FIELDS_ENDPOINT","PLUGIN_INSTRUCTIONS_TABLE","fetchFields","config","access","options","promptFields","handler","req","docs","payload","find","collection","pagination","isConfigAllowed","
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/fetchFields.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload'\n\nimport type { PluginConfig, SerializedPromptField } from '../types.js'\n\nimport { PLUGIN_FETCH_FIELDS_ENDPOINT, PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\n\nexport const fetchFields: (config: PluginConfig) => Endpoint = (config) => {\n const { access, options = {}, promptFields = [] } = config\n return {\n handler: async (req: PayloadRequest) => {\n const { docs = [] } = await req.payload.find({\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n pagination: false,\n })\n\n let isConfigAllowed = true // Users allowed to update prompts by default\n let enabledCollections: string[] = []\n\n try {\n const { enabledCollections: storedEnabledCollections } = await req.payload.findGlobal({\n slug: 'ai-settings',\n })\n enabledCollections = (storedEnabledCollections as string[]) || []\n } catch (e) {\n req.payload.logger.error('Failed to fetch AI settings')\n }\n\n if (access?.settings) {\n try {\n isConfigAllowed = await access.settings({ req })\n } catch (e) {\n req.payload.logger.error(req, 'Please check your \"access.settings\" for request')\n }\n }\n\n const fieldMap: Record<string, { disabled?: boolean; fieldType: any; id: any }> = {}\n docs.forEach((doc) => {\n fieldMap[doc['schema-path']] = {\n id: doc.id,\n disabled: !!doc['disabled'],\n fieldType: doc['field-type'],\n }\n })\n\n return Response.json({\n ...options,\n debugging: config.debugging,\n enabledCollections,\n fields: fieldMap,\n isConfigAllowed,\n promptFields: promptFields.map(({ getter: _getter, ...field }): SerializedPromptField => {\n return field\n }),\n })\n },\n method: 'get',\n path: PLUGIN_FETCH_FIELDS_ENDPOINT,\n }\n}\n"],"names":["PLUGIN_FETCH_FIELDS_ENDPOINT","PLUGIN_INSTRUCTIONS_TABLE","fetchFields","config","access","options","promptFields","handler","req","docs","payload","find","collection","pagination","isConfigAllowed","enabledCollections","storedEnabledCollections","findGlobal","slug","e","logger","error","settings","fieldMap","forEach","doc","id","disabled","fieldType","Response","json","debugging","fields","map","getter","_getter","field","method","path"],"mappings":"AAIA,SAASA,4BAA4B,EAAEC,yBAAyB,QAAQ,iBAAgB;AAExF,OAAO,MAAMC,cAAkD,CAACC;IAC9D,MAAM,EAAEC,MAAM,EAAEC,UAAU,CAAC,CAAC,EAAEC,eAAe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