@ai-stack/payloadcms 3.68.0-beta.3 → 3.68.0-beta.5
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/streamObject.js +3 -0
- 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/registry.js +0 -1
- 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 +3 -3
- package/dist/collections/AISettings.js.map +1 -1
- package/dist/endpoints/fetchVoices.js +41 -24
- package/dist/endpoints/fetchVoices.js.map +1 -1
- package/dist/endpoints/index.js +108 -6
- package/dist/endpoints/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/payload-ai.d.ts +7 -4
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/dist/types.d.ts +34 -2
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/dist/ui/Compose/Compose.js +23 -6
- package/dist/ui/Compose/Compose.js.map +1 -1
- package/dist/ui/Compose/Compose.jsx +23 -4
- package/dist/ui/Compose/hooks/useGenerate.js +21 -72
- package/dist/ui/Compose/hooks/useGenerate.js.map +1 -1
- package/dist/ui/Compose/hooks/useGenerateUpload.d.ts +3 -3
- package/dist/ui/Compose/hooks/useGenerateUpload.js +37 -10
- package/dist/ui/Compose/hooks/useGenerateUpload.js.map +1 -1
- package/dist/ui/Compose/hooks/useStreamingUpdate.js.map +1 -1
- package/dist/ui/VoicesFetcher/index.js +33 -61
- package/dist/ui/VoicesFetcher/index.js.map +1 -1
- package/dist/ui/VoicesFetcher/index.jsx +31 -37
- package/dist/utilities/buildSmartPrompt.js +4 -6
- package/dist/utilities/buildSmartPrompt.js.map +1 -1
- package/dist/utilities/encryption.js +2 -1
- package/dist/utilities/encryption.js.map +1 -1
- package/dist/utilities/seedProperties.js +7 -24
- package/dist/utilities/seedProperties.js.map +1 -1
- package/dist/utilities/setSafeLexicalState.js +1 -2
- package/dist/utilities/setSafeLexicalState.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/seedProperties.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/seedProperties.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\nimport { updateFieldsConfig } from './updateFieldsConfig.js'\n\ninterface SeedPropertiesArgs {\n enabledCollections: string[]\n req: PayloadRequest\n}\n\nexport const seedProperties = async ({ enabledCollections, req }: SeedPropertiesArgs): Promise<void> => {\n const { payload } = req\n\n if (!enabledCollections || enabledCollections.length === 0) {\n return\n }\n\n // Get all collections from payload config\n const allCollections = payload.config.collections\n\n for (const collectionSlug of enabledCollections) {\n const collectionConfig = allCollections.find((c) => c.slug === collectionSlug)\n if (!collectionConfig) {\n continue\n }\n\n // Traverse the collection config effectively using updateFieldsConfig\n // Use the side-effect of getting schemaPathMap from it\n const { schemaPathMap } = updateFieldsConfig(collectionConfig)\n\n for (const [schemaPath, fieldInfo] of Object.entries(schemaPathMap)) {\n const { type, custom, relationTo } = fieldInfo as {\n custom?: { ai?: { prompt?: string; system?: string } }\n relationTo?: string\n type: string\n }\n\n // Check if instruction already exists\n const existingInstruction = await payload.find({\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n depth: 0,\n limit: 1,\n overrideAccess: true,\n where: {\n 'schema-path': {\n equals: schemaPath,\n },\n },\n })\n\n if (existingInstruction.totalDocs > 0) {\n // If developer has provided custom prompts in the schema, update the existing record\n // but only if the values have actually changed.\n if (custom?.ai?.prompt || custom?.ai?.system) {\n const doc = existingInstruction.docs[0] as any\n const currentPrompt = doc.prompt\n const currentSystem = doc.system\n\n let needsUpdate = false\n const updateData: any = {}\n\n if (custom?.ai?.prompt && custom.ai.prompt !== currentPrompt) {\n updateData.prompt = custom.ai.prompt\n needsUpdate = true\n }\n if (custom?.ai?.system && custom.ai.system !== currentSystem) {\n updateData.system = custom.ai.system\n needsUpdate = true\n }\n\n if (needsUpdate) {\n try {\n await payload.update({\n id: doc.id,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n data: updateData,\n overrideAccess: true,\n })\n } catch (error) {\n payload.logger.error(`Failed to update instruction for ${schemaPath}: ${error}`)\n }\n }\n }\n continue\n }\n\n // Use custom prompts if provided, otherwise leave empty\n const prompt = custom?.ai?.prompt || ''\n const system = custom?.ai?.system || ''\n\n // Determine model-id based on field type\n let modelId = 'text'\n if (type === 'richText') {\n modelId = 'richtext'\n }\n if (type === 'upload') {\n modelId = 'image'\n } // defaulting to image generation for uploads\n if (type === 'array') {\n modelId = 'array'\n }\n\n // Create new instruction\n try {\n await payload.create({\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n data: {\n disabled: false,\n 'field-type': type,\n 'model-id': modelId,\n prompt,\n 'relation-to': relationTo,\n 'schema-path': schemaPath,\n system,\n },\n overrideAccess: true,\n })\n } catch (error) {\n payload.logger.error(`Failed to seed instruction for ${schemaPath}: ${error}`)\n }\n }\n }\n}\n"],"names":["PLUGIN_INSTRUCTIONS_TABLE","updateFieldsConfig","seedProperties","enabledCollections","req","payload","length","allCollections","config","collections","collectionSlug","collectionConfig","find","c","slug","schemaPathMap","schemaPath","fieldInfo","Object","entries","type","custom","relationTo","existingInstruction","collection","depth","limit","overrideAccess","where","equals","totalDocs","ai","prompt","system","doc","docs","currentPrompt","currentSystem","needsUpdate","updateData","update","id","data","error","logger","modelId","create","disabled"],"mappings":"AAEA,SAASA,yBAAyB,QAAQ,iBAAgB;AAC1D,SAASC,kBAAkB,QAAQ,0BAAyB;AAO5D,OAAO,MAAMC,iBAAiB,OAAO,EAAEC,kBAAkB,EAAEC,GAAG,EAAsB;IAClF,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,IAAI,CAACD,sBAAsBA,mBAAmBG,MAAM,KAAK,GAAG;QAC1D;IACF;IAEA,0CAA0C;IAC1C,MAAMC,iBAAiBF,QAAQG,MAAM,CAACC,WAAW;IAEjD,KAAK,MAAMC,kBAAkBP,mBAAoB;QAC/C,MAAMQ,mBAAmBJ,eAAeK,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ;QAC/D,IAAI,CAACC,kBAAkB;YACrB;QACF;QAEA,sEAAsE;QACtE,uDAAuD;QACvD,MAAM,EAAEI,aAAa,EAAE,GAAGd,mBAAmBU;QAE7C,KAAK,MAAM,CAACK,YAAYC,UAAU,IAAIC,OAAOC,OAAO,CAACJ,eAAgB;YACnE,MAAM,EAAEK,IAAI,EAAEC,MAAM,EAAEC,UAAU,EAAE,GAAGL;YAMrC,sCAAsC;YACtC,MAAMM,sBAAsB,MAAMlB,QAAQO,IAAI,CAAC;gBAC7CY,YAAYxB;gBACZyB,OAAO;gBACPC,OAAO;gBACPC,gBAAgB;gBAChBC,OAAO;oBACL,eAAe;wBACbC,QAAQb;oBACV;gBACF;YACF;YAEA,IAAIO,oBAAoBO,SAAS,GAAG,GAAG;gBACrC,qFAAqF;gBACrF,gDAAgD;gBAChD,IAAIT,QAAQU,IAAIC,UAAUX,QAAQU,IAAIE,QAAQ;oBAC5C,MAAMC,MAAMX,oBAAoBY,IAAI,CA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BAClB;YACF,EAAE,OAAOgB,OAAO;gBACdtC,QAAQuC,MAAM,CAACD,KAAK,CAAC,CAAC,+BAA+B,EAAE3B,WAAW,EAAE,EAAE2B,MAAM,CAAC;YAC/E;QACF;IACF;AACF,EAAC"}
|
|
@@ -11,7 +11,7 @@ const sanitizeLexicalState = (state)=>{
|
|
|
11
11
|
const cleanState = JSON.parse(JSON.stringify(state));
|
|
12
12
|
// 3. Ensure root has required props
|
|
13
13
|
cleanState.root.type = 'root';
|
|
14
|
-
cleanState.root.format = cleanState.root.format || '';
|
|
14
|
+
cleanState.root.format = cleanState.root.format || 'left';
|
|
15
15
|
cleanState.root.indent = cleanState.root.indent || 0;
|
|
16
16
|
cleanState.root.version = cleanState.root.version || 1;
|
|
17
17
|
// 4. Recursive sanitizer for children
|
|
@@ -57,7 +57,6 @@ const sanitizeLexicalState = (state)=>{
|
|
|
57
57
|
node.mode = node.mode ?? 0;
|
|
58
58
|
node.style = node.style || '';
|
|
59
59
|
node.detail = node.detail ?? 0;
|
|
60
|
-
node.format = node.format ?? 0;
|
|
61
60
|
}
|
|
62
61
|
return node;
|
|
63
62
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/setSafeLexicalState.ts"],"sourcesContent":["import type { LexicalEditor } from 'lexical'\n\nconst sanitizeLexicalState = (state: any): any => {\n // 1. Ensure root exists and is valid\n if (!state || typeof state !== 'object') {\n return null\n }\n\n // If no root, or root is not an object, it's invalid\n if (!state.root || typeof state.root !== 'object') {\n return null\n }\n\n // 2. Clone to avoid mutation\n const cleanState = JSON.parse(JSON.stringify(state))\n\n // 3. Ensure root has required props\n cleanState.root.type = 'root'\n cleanState.root.format = cleanState.root.format || ''\n cleanState.root.indent = cleanState.root.indent || 0\n cleanState.root.version = cleanState.root.version || 1\n\n // 4. Recursive sanitizer for children\n const sanitizeNode = (node: any): any => {\n if (!node || typeof node !== 'object') {\n return null\n }\n\n // Must have a type. If streaming incomplete node (type is missing/empty), discard it.\n if (!node.type || typeof node.type !== 'string') {\n return null\n }\n\n // Default version if missing\n node.version = node.version || 1\n\n // If node has children, sanitize them\n if (Array.isArray(node.children)) {\n node.children = node.children\n .map(sanitizeNode)\n .filter((child: any) => child !== null)\n } else {\n // Ensure children is at least an empty array if it's supposed to be there? \n // Actually lots of leaf nodes don't have children. \n // But Root, Paragraph, etc do. \n // Let's safe-guard standard ElementNodes:\n if (['heading', 'link', 'list', 'listitem', 'paragraph', 'quote', 'root'].includes(node.type)) {\n node.children = node.children || []\n }\n }\n\n // Specific node fixes\n if (node.type === 'text') {\n // Text nodes must have text prop\n if (typeof node.text !== 'string') {\n // If text is missing, it might be incomplete. \n // We can either discard or default to empty string.\n // For streaming, empty string is safer than discarding early if we want to show cursor?\n node.text = node.text || ''\n }\n node.mode = node.mode ?? 0\n node.style = node.style || ''\n node.detail = node.detail ?? 0\n
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/setSafeLexicalState.ts"],"sourcesContent":["import type { LexicalEditor } from 'lexical'\n\nconst sanitizeLexicalState = (state: any): any => {\n // 1. Ensure root exists and is valid\n if (!state || typeof state !== 'object') {\n return null\n }\n\n // If no root, or root is not an object, it's invalid\n if (!state.root || typeof state.root !== 'object') {\n return null\n }\n\n // 2. Clone to avoid mutation\n const cleanState = JSON.parse(JSON.stringify(state))\n\n // 3. Ensure root has required props\n cleanState.root.type = 'root'\n cleanState.root.format = cleanState.root.format || 'left'\n cleanState.root.indent = cleanState.root.indent || 0\n cleanState.root.version = cleanState.root.version || 1\n\n // 4. Recursive sanitizer for children\n const sanitizeNode = (node: any): any => {\n if (!node || typeof node !== 'object') {\n return null\n }\n\n // Must have a type. If streaming incomplete node (type is missing/empty), discard it.\n if (!node.type || typeof node.type !== 'string') {\n return null\n }\n\n // Default version if missing\n node.version = node.version || 1\n\n // If node has children, sanitize them\n if (Array.isArray(node.children)) {\n node.children = node.children\n .map(sanitizeNode)\n .filter((child: any) => child !== null)\n } else {\n // Ensure children is at least an empty array if it's supposed to be there? \n // Actually lots of leaf nodes don't have children. \n // But Root, Paragraph, etc do. \n // Let's safe-guard standard ElementNodes:\n if (['heading', 'link', 'list', 'listitem', 'paragraph', 'quote', 'root'].includes(node.type)) {\n node.children = node.children || []\n }\n }\n\n // Specific node fixes\n if (node.type === 'text') {\n // Text nodes must have text prop\n if (typeof node.text !== 'string') {\n // If text is missing, it might be incomplete. \n // We can either discard or default to empty string.\n // For streaming, empty string is safer than discarding early if we want to show cursor?\n node.text = node.text || ''\n }\n node.mode = node.mode ?? 0\n node.style = node.style || ''\n node.detail = node.detail ?? 0\n }\n\n return node\n }\n\n // 5. Sanitize root's children\n if (Array.isArray(cleanState.root.children)) {\n cleanState.root.children = cleanState.root.children\n .map(sanitizeNode)\n .filter((child: any) => child !== null)\n } else {\n cleanState.root.children = []\n }\n\n return cleanState\n}\n\nexport const setSafeLexicalState = (state: unknown, editorInstance: LexicalEditor) => {\n try {\n const validState = sanitizeLexicalState(state)\n \n if (!validState) {\n return\n }\n\n const editorState = editorInstance.parseEditorState(validState)\n if (editorState.isEmpty()) {\n return\n }\n\n editorInstance.setEditorState(editorState)\n } catch (_error) {\n // Silently catch errors during streaming to avoid console noise.\n // Lexical's parseEditorState is very strict and will throw if the\n // object structure is even slightly incomplete during the stream.\n }\n}\n\n"],"names":["sanitizeLexicalState","state","root","cleanState","JSON","parse","stringify","type","format","indent","version","sanitizeNode","node","Array","isArray","children","map","filter","child","includes","text","mode","style","detail","setSafeLexicalState","editorInstance","validState","editorState","parseEditorState","isEmpty","setEditorState","_error"],"mappings":"AAEA,MAAMA,uBAAuB,CAACC;IAC5B,qCAAqC;IACrC,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAO;IACT;IAEA,qDAAqD;IACrD,IAAI,CAACA,MAAMC,IAAI,IAAI,OAAOD,MAAMC,IAAI,KAAK,UAAU;QACjD,OAAO;IACT;IAEA,6BAA6B;IAC7B,MAAMC,aAAaC,KAAKC,KAAK,CAACD,KA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