@ai-stack/payloadcms 3.68.0-beta.1 → 3.68.0-beta.3

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 (134) hide show
  1. package/dist/ai/core/media/image/generateImage.js +2 -6
  2. package/dist/ai/core/media/image/generateImage.js.map +1 -1
  3. package/dist/ai/core/media/image/handlers/multimodal.js +5 -0
  4. package/dist/ai/core/media/image/handlers/multimodal.js.map +1 -1
  5. package/dist/ai/core/streamObject.js +0 -3
  6. package/dist/ai/core/streamObject.js.map +1 -1
  7. package/dist/ai/providers/blocks/anthropic.js +2 -1
  8. package/dist/ai/providers/blocks/anthropic.js.map +1 -1
  9. package/dist/ai/providers/blocks/elevenlabs.js +3 -2
  10. package/dist/ai/providers/blocks/elevenlabs.js.map +1 -1
  11. package/dist/ai/providers/blocks/fal.js +2 -1
  12. package/dist/ai/providers/blocks/fal.js.map +1 -1
  13. package/dist/ai/providers/blocks/google.js +11 -6
  14. package/dist/ai/providers/blocks/google.js.map +1 -1
  15. package/dist/ai/providers/blocks/openai-compatible.js +2 -1
  16. package/dist/ai/providers/blocks/openai-compatible.js.map +1 -1
  17. package/dist/ai/providers/blocks/openai.js +3 -2
  18. package/dist/ai/providers/blocks/openai.js.map +1 -1
  19. package/dist/ai/providers/blocks/xai.js +2 -1
  20. package/dist/ai/providers/blocks/xai.js.map +1 -1
  21. package/dist/ai/providers/icons.d.ts +7 -0
  22. package/dist/ai/providers/icons.js +9 -0
  23. package/dist/ai/providers/icons.js.map +1 -0
  24. package/dist/ai/providers/registry.js +34 -23
  25. package/dist/ai/providers/registry.js.map +1 -1
  26. package/dist/collections/AISettings.js +44 -17
  27. package/dist/collections/AISettings.js.map +1 -1
  28. package/dist/collections/Instructions.js +37 -0
  29. package/dist/collections/Instructions.js.map +1 -1
  30. package/dist/defaults.d.ts +1 -0
  31. package/dist/defaults.js +8 -0
  32. package/dist/defaults.js.map +1 -1
  33. package/dist/endpoints/chat.d.ts +4 -0
  34. package/dist/endpoints/fetchFields.js +10 -0
  35. package/dist/endpoints/fetchFields.js.map +1 -1
  36. package/dist/endpoints/index.js +86 -10
  37. package/dist/endpoints/index.js.map +1 -1
  38. package/dist/exports/fields.d.ts +1 -0
  39. package/dist/exports/fields.js +1 -0
  40. package/dist/exports/fields.js.map +1 -1
  41. package/dist/fields/ArrayComposeField/ArrayComposeField.d.ts +15 -0
  42. package/dist/fields/ArrayComposeField/ArrayComposeField.js +87 -0
  43. package/dist/fields/ArrayComposeField/ArrayComposeField.js.map +1 -0
  44. package/dist/fields/ArrayComposeField/ArrayComposeField.jsx +73 -0
  45. package/dist/fields/PromptEditorField/PromptEditorField.js +7 -2
  46. package/dist/fields/PromptEditorField/PromptEditorField.js.map +1 -1
  47. package/dist/fields/PromptEditorField/PromptEditorField.jsx +5 -2
  48. package/dist/index.d.ts +2 -0
  49. package/dist/index.js +1 -0
  50. package/dist/index.js.map +1 -1
  51. package/dist/payload-ai.d.ts +149 -0
  52. package/dist/plugin.js +16 -32
  53. package/dist/plugin.js.map +1 -1
  54. package/dist/providers/InstructionsProvider/InstructionsProvider.js +47 -15
  55. package/dist/providers/InstructionsProvider/InstructionsProvider.js.map +1 -1
  56. package/dist/providers/InstructionsProvider/InstructionsProvider.jsx +39 -16
  57. package/dist/providers/InstructionsProvider/context.d.ts +3 -0
  58. package/dist/providers/InstructionsProvider/context.js +2 -0
  59. package/dist/providers/InstructionsProvider/context.js.map +1 -1
  60. package/dist/providers/InstructionsProvider/useInstructions.js +21 -2
  61. package/dist/providers/InstructionsProvider/useInstructions.js.map +1 -1
  62. package/dist/styles.d.ts +11 -0
  63. package/dist/types/handlebars-async-helpers.d.ts +1 -0
  64. package/dist/types/handlebars-dist-handlebars.d.ts +1 -0
  65. package/dist/types/react-mentions.d.ts +1 -0
  66. package/dist/types.d.ts +0 -3
  67. package/dist/types.js.map +1 -1
  68. package/dist/ui/AIConfigDashboard/index.js +198 -22
  69. package/dist/ui/AIConfigDashboard/index.js.map +1 -1
  70. package/dist/ui/AIConfigDashboard/index.jsx +159 -13
  71. package/dist/ui/Compose/Compose.d.ts +1 -0
  72. package/dist/ui/Compose/Compose.js +7 -5
  73. package/dist/ui/Compose/Compose.js.map +1 -1
  74. package/dist/ui/Compose/Compose.jsx +5 -5
  75. package/dist/ui/Compose/UndoRedoActions.d.ts +2 -2
  76. package/dist/ui/Compose/UndoRedoActions.js +8 -5
  77. package/dist/ui/Compose/UndoRedoActions.js.map +1 -1
  78. package/dist/ui/Compose/UndoRedoActions.jsx +6 -5
  79. package/dist/ui/Compose/compose.module.css +56 -16
  80. package/dist/ui/Compose/hooks/menu/itemsMap.js +12 -6
  81. package/dist/ui/Compose/hooks/menu/itemsMap.js.map +1 -1
  82. package/dist/ui/Compose/hooks/menu/useMenu.js +26 -15
  83. package/dist/ui/Compose/hooks/menu/useMenu.js.map +1 -1
  84. package/dist/ui/Compose/hooks/menu/useMenu.jsx +25 -12
  85. package/dist/ui/Compose/hooks/useGenerate.js +34 -131
  86. package/dist/ui/Compose/hooks/useGenerate.js.map +1 -1
  87. package/dist/ui/Compose/hooks/useGenerateUpload.d.ts +11 -0
  88. package/dist/ui/Compose/hooks/useGenerateUpload.js +123 -0
  89. package/dist/ui/Compose/hooks/useGenerateUpload.js.map +1 -0
  90. package/dist/ui/Compose/hooks/useHistory.d.ts +0 -1
  91. package/dist/ui/Compose/hooks/useHistory.js +65 -25
  92. package/dist/ui/Compose/hooks/useHistory.js.map +1 -1
  93. package/dist/ui/Compose/hooks/useStreamingUpdate.d.ts +8 -0
  94. package/dist/ui/Compose/hooks/useStreamingUpdate.js +48 -0
  95. package/dist/ui/Compose/hooks/useStreamingUpdate.js.map +1 -0
  96. package/dist/ui/DynamicVoiceSelect/index.js +63 -11
  97. package/dist/ui/DynamicVoiceSelect/index.js.map +1 -1
  98. package/dist/ui/DynamicVoiceSelect/index.jsx +47 -14
  99. package/dist/ui/EncryptedTextField/index.js +4 -4
  100. package/dist/ui/EncryptedTextField/index.js.map +1 -1
  101. package/dist/ui/EncryptedTextField/index.jsx +4 -4
  102. package/dist/ui/VoicesFetcher/index.js +54 -8
  103. package/dist/ui/VoicesFetcher/index.js.map +1 -1
  104. package/dist/ui/VoicesFetcher/index.jsx +32 -9
  105. package/dist/utilities/buildSmartPrompt.d.ts +22 -0
  106. package/dist/utilities/buildSmartPrompt.js +143 -0
  107. package/dist/utilities/buildSmartPrompt.js.map +1 -0
  108. package/dist/utilities/resolveImageReferences.d.ts +3 -1
  109. package/dist/utilities/resolveImageReferences.js +21 -2
  110. package/dist/utilities/resolveImageReferences.js.map +1 -1
  111. package/dist/utilities/seedProperties.d.ts +7 -0
  112. package/dist/utilities/seedProperties.js +117 -0
  113. package/dist/utilities/seedProperties.js.map +1 -0
  114. package/dist/utilities/setSafeLexicalState.js +80 -6
  115. package/dist/utilities/setSafeLexicalState.js.map +1 -1
  116. package/dist/utilities/updateFieldsConfig.d.ts +1 -1
  117. package/dist/utilities/updateFieldsConfig.js +8 -1
  118. package/dist/utilities/updateFieldsConfig.js.map +1 -1
  119. package/package.json +4 -3
  120. package/dist/endpoints/chat.d.js +0 -3
  121. package/dist/endpoints/chat.d.js.map +0 -1
  122. package/dist/init.d.ts +0 -7
  123. package/dist/init.js +0 -135
  124. package/dist/init.js.map +0 -1
  125. package/dist/payload-ai.d.js +0 -3
  126. package/dist/payload-ai.d.js.map +0 -1
  127. package/dist/styles.d.js +0 -2
  128. package/dist/styles.d.js.map +0 -1
  129. package/dist/types/handlebars-async-helpers.d.js +0 -2
  130. package/dist/types/handlebars-async-helpers.d.js.map +0 -1
  131. package/dist/types/handlebars-dist-handlebars.d.js +0 -2
  132. package/dist/types/handlebars-dist-handlebars.d.js.map +0 -1
  133. package/dist/types/react-mentions.d.js +0 -2
  134. package/dist/types/react-mentions.d.js.map +0 -1
@@ -1,15 +1,89 @@
1
+ const sanitizeLexicalState = (state)=>{
2
+ // 1. Ensure root exists and is valid
3
+ if (!state || typeof state !== 'object') {
4
+ return null;
5
+ }
6
+ // If no root, or root is not an object, it's invalid
7
+ if (!state.root || typeof state.root !== 'object') {
8
+ return null;
9
+ }
10
+ // 2. Clone to avoid mutation
11
+ const cleanState = JSON.parse(JSON.stringify(state));
12
+ // 3. Ensure root has required props
13
+ cleanState.root.type = 'root';
14
+ cleanState.root.format = cleanState.root.format || '';
15
+ cleanState.root.indent = cleanState.root.indent || 0;
16
+ cleanState.root.version = cleanState.root.version || 1;
17
+ // 4. Recursive sanitizer for children
18
+ const sanitizeNode = (node)=>{
19
+ if (!node || typeof node !== 'object') {
20
+ return null;
21
+ }
22
+ // Must have a type. If streaming incomplete node (type is missing/empty), discard it.
23
+ if (!node.type || typeof node.type !== 'string') {
24
+ return null;
25
+ }
26
+ // Default version if missing
27
+ node.version = node.version || 1;
28
+ // If node has children, sanitize them
29
+ if (Array.isArray(node.children)) {
30
+ node.children = node.children.map(sanitizeNode).filter((child)=>child !== null);
31
+ } else {
32
+ // Ensure children is at least an empty array if it's supposed to be there?
33
+ // Actually lots of leaf nodes don't have children.
34
+ // But Root, Paragraph, etc do.
35
+ // Let's safe-guard standard ElementNodes:
36
+ if ([
37
+ 'heading',
38
+ 'link',
39
+ 'list',
40
+ 'listitem',
41
+ 'paragraph',
42
+ 'quote',
43
+ 'root'
44
+ ].includes(node.type)) {
45
+ node.children = node.children || [];
46
+ }
47
+ }
48
+ // Specific node fixes
49
+ if (node.type === 'text') {
50
+ // Text nodes must have text prop
51
+ if (typeof node.text !== 'string') {
52
+ // If text is missing, it might be incomplete.
53
+ // We can either discard or default to empty string.
54
+ // For streaming, empty string is safer than discarding early if we want to show cursor?
55
+ node.text = node.text || '';
56
+ }
57
+ node.mode = node.mode ?? 0;
58
+ node.style = node.style || '';
59
+ node.detail = node.detail ?? 0;
60
+ node.format = node.format ?? 0;
61
+ }
62
+ return node;
63
+ };
64
+ // 5. Sanitize root's children
65
+ if (Array.isArray(cleanState.root.children)) {
66
+ cleanState.root.children = cleanState.root.children.map(sanitizeNode).filter((child)=>child !== null);
67
+ } else {
68
+ cleanState.root.children = [];
69
+ }
70
+ return cleanState;
71
+ };
1
72
  export const setSafeLexicalState = (state, editorInstance)=>{
2
73
  try {
3
- const editorState = editorInstance.parseEditorState(state);
74
+ const validState = sanitizeLexicalState(state);
75
+ if (!validState) {
76
+ return;
77
+ }
78
+ const editorState = editorInstance.parseEditorState(validState);
4
79
  if (editorState.isEmpty()) {
5
80
  return;
6
81
  }
7
82
  editorInstance.setEditorState(editorState);
8
- } catch (error) {
9
- console.error('Error setting editor state: ', {
10
- error,
11
- state
12
- });
83
+ } catch (_error) {
84
+ // Silently catch errors during streaming to avoid console noise.
85
+ // Lexical's parseEditorState is very strict and will throw if the
86
+ // object structure is even slightly incomplete during the stream.
13
87
  }
14
88
  };
15
89
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/setSafeLexicalState.ts"],"sourcesContent":["import type { LexicalEditor } from 'lexical'\n\ntype EditorAction = 'replace' | 'update'\n\nexport const setSafeLexicalState = (\n state: unknown,\n editorInstance: LexicalEditor,\n // action: EditorAction = 'replace',\n) => {\n try {\n const editorState = editorInstance.parseEditorState(state as any)\n if (editorState.isEmpty()) {\n return\n }\n\n editorInstance.setEditorState(editorState)\n } catch (error) {\n console.error('Error setting editor state: ', { error, state })\n }\n}\n"],"names":["setSafeLexicalState","state","editorInstance","editorState","parseEditorState","isEmpty","setEditorState","error","console"],"mappings":"AAIA,OAAO,MAAMA,sBAAsB,CACjCC,OACAC;IAGA,IAAI;QACF,MAAMC,cAAcD,eAAeE,gBAAgB,CAACH;QACpD,IAAIE,YAAYE,OAAO,IAAI;YACzB;QACF;QAEAH,eAAeI,cAAc,CAACH;IAChC,EAAE,OAAOI,OAAO;QACdC,QAAQD,KAAK,CAAC,gCAAgC;YAAEA;YAAON;QAAM;IAC/D;AACF,EAAC"}
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 node.format = node.format ?? 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"],"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,KAAKE,SAAS,CAACL;IAE7C,oCAAoC;IACpCE,WAAWD,IAAI,CAACK,IAAI,GAAG;IACvBJ,WAAWD,IAAI,CAACM,MAAM,GAAGL,WAAWD,IAAI,CAACM,MAAM,IAAI;IACnDL,WAAWD,IAAI,CAACO,MAAM,GAAGN,WAAWD,IAAI,CAACO,MAAM,IAAI;IACnDN,WAAWD,IAAI,CAACQ,OAAO,GAAGP,WAAWD,IAAI,CAACQ,OAAO,IAAI;IAErD,sCAAsC;IACtC,MAAMC,eAAe,CAACC;QACpB,IAAI,CAACA,QAAQ,OAAOA,SAAS,UAAU;YACrC,OAAO;QACT;QAEA,sFAAsF;QACtF,IAAI,CAACA,KAAKL,IAAI,IAAI,OAAOK,KAAKL,IAAI,KAAK,UAAU;YAC/C,OAAO;QACT;QAEA,6BAA6B;QAC7BK,KAAKF,OAAO,GAAGE,KAAKF,OAAO,IAAI;QAE/B,sCAAsC;QACtC,IAAIG,MAAMC,OAAO,CAACF,KAAKG,QAAQ,GAAG;YAChCH,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ACF;QACpD,IAAIC,YAAYE,OAAO,IAAI;YACzB;QACF;QAEAJ,eAAeK,cAAc,CAACH;IAChC,EAAE,OAAOI,QAAQ;IACf,iEAAiE;IACjE,kEAAkE;IAClE,kEAAkE;IACpE;AACF,EAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { CollectionConfig, GlobalConfig } from 'payload';
2
2
  interface UpdateFieldsConfig {
3
- schemaPathMap: Record<string, string>;
3
+ schemaPathMap: Record<string, any>;
4
4
  updatedCollectionConfig: CollectionConfig | GlobalConfig;
5
5
  }
6
6
  export declare const updateFieldsConfig: (collectionConfig: CollectionConfig | GlobalConfig) => UpdateFieldsConfig;
@@ -11,6 +11,7 @@ export const updateFieldsConfig = (collectionConfig)=>{
11
11
  // This is done due to save extra API call to get instructions when Field components are loaded in admin
12
12
  // Doing is will only call instructions data when user clicks on settings
13
13
  if ([
14
+ 'array',
14
15
  'richText',
15
16
  'text',
16
17
  'textarea',
@@ -20,13 +21,16 @@ export const updateFieldsConfig = (collectionConfig)=>{
20
21
  ...schemaPathMap,
21
22
  [currentSchemaPath]: {
22
23
  type: field.type,
24
+ custom: field.custom,
23
25
  label: field.label || field.name,
24
26
  relationTo: field.relationTo
25
27
  }
26
28
  };
27
29
  }
28
30
  // Inject AI actions, richText is not included here as it has to be explicitly defined by user
31
+ // Array fields also get AI injection for bulk generation
29
32
  if ([
33
+ 'array',
30
34
  'text',
31
35
  'textarea',
32
36
  'upload'
@@ -39,6 +43,9 @@ export const updateFieldsConfig = (collectionConfig)=>{
39
43
  // by overriding Description. If you need both, consider composing your own wrapper.
40
44
  customField = {};
41
45
  }
46
+ // Array fields use ArrayComposeField (always visible) since they don't have focus events
47
+ // Other fields use ComposeField with focus-dependent visibility
48
+ const componentPath = field.type === 'array' ? '@ai-stack/payloadcms/fields#ArrayComposeField' : '@ai-stack/payloadcms/fields#ComposeField';
42
49
  return {
43
50
  ...field,
44
51
  admin: {
@@ -49,7 +56,7 @@ export const updateFieldsConfig = (collectionConfig)=>{
49
56
  clientProps: {
50
57
  schemaPath: currentSchemaPath
51
58
  },
52
- path: '@ai-stack/payloadcms/fields#ComposeField'
59
+ path: componentPath
53
60
  },
54
61
  ...customField
55
62
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/updateFieldsConfig.ts"],"sourcesContent":["import type { CollectionConfig, GlobalConfig } from 'payload'\n\ninterface UpdateFieldsConfig {\n schemaPathMap: Record<string, string>\n updatedCollectionConfig: CollectionConfig | GlobalConfig\n}\n\nexport const updateFieldsConfig = (collectionConfig: CollectionConfig | GlobalConfig): UpdateFieldsConfig => {\n let schemaPathMap = {}\n\n function updateField(field: any, parentPath = ''): any {\n const currentPath = parentPath ? `${parentPath}.${field.name}` : field.name\n const currentSchemaPath = `${collectionConfig.slug}.${currentPath}`\n\n // Disabled fields/ field types\n if (\n field.admin?.disabled ||\n field.admin?.readOnly ||\n field.admin?.hidden ||\n field.type === 'row'\n ) {\n return field\n }\n\n // Map field path for global fieldInstructionsMap to load related instructions\n // This is done due to save extra API call to get instructions when Field components are loaded in admin\n // Doing is will only call instructions data when user clicks on settings\n if (['richText', 'text', 'textarea', 'upload'].includes(field.type)) {\n schemaPathMap = {\n ...schemaPathMap,\n [currentSchemaPath]: {\n type: field.type,\n label: field.label || field.name,\n relationTo: field.relationTo,\n },\n }\n }\n\n // Inject AI actions, richText is not included here as it has to be explicitly defined by user\n if (['text', 'textarea', 'upload'].includes(field.type)) {\n let customField = {}\n\n // Custom fields don't fully adhere to the Payload schema, making it difficult to\n // determine which components support injecting ComposeField as a Description.\n if (field.admin?.components?.Field || field.admin?.components?.Description) {\n // TODO: If a field already provides its own Description, we still inject our ComposeField\n // by overriding Description. If you need both, consider composing your own wrapper.\n customField = {}\n }\n\n return {\n ...field,\n admin: {\n ...field.admin,\n components: {\n ...(field.admin?.components || {}),\n Description: {\n clientProps: {\n schemaPath: currentSchemaPath,\n },\n path: '@ai-stack/payloadcms/fields#ComposeField',\n },\n ...customField,\n },\n },\n }\n }\n\n if (field.fields) {\n return {\n ...field,\n fields: field.fields.map((subField: any) => updateField(subField, currentPath)),\n }\n }\n\n if (field.tabs) {\n return {\n ...field,\n tabs: field.tabs.map((tab: any) => {\n return {\n ...tab,\n // Tabs are a UI construct and should not add to the schema path\n fields: (tab.fields || []).map((subField: any) => updateField(subField, parentPath)),\n }\n }),\n }\n }\n\n if (field.blocks) {\n return {\n ...field,\n blocks: field.blocks.map((block: any) => ({\n ...block,\n fields: block.fields.map((subField: any) =>\n updateField(subField, `${currentPath}.${block.slug}`),\n ),\n })),\n }\n }\n\n return field\n }\n\n const updatedCollectionConfig = {\n ...collectionConfig,\n fields: collectionConfig.fields.map((field) => updateField(field)),\n }\n\n return {\n schemaPathMap,\n updatedCollectionConfig,\n }\n}\n"],"names":["updateFieldsConfig","collectionConfig","schemaPathMap","updateField","field","parentPath","currentPath","name","currentSchemaPath","slug","admin","disabled","readOnly","hidden","type","includes","label","relationTo","customField","components","Field","Description","clientProps","schemaPath","path","fields","map","subField","tabs","tab","blocks","block","updatedCollectionConfig"],"mappings":"AAOA,OAAO,MAAMA,qBAAqB,CAACC;IACjC,IAAIC,gBAAgB,CAAC;IAErB,SAASC,YAAYC,KAAU,EAAEC,aAAa,EAAE;QAC9C,MAAMC,cAAcD,aAAa,CAAC,EAAEA,WAAW,CAAC,EAAED,MAAMG,IAAI,CAAC,CAAC,GAAGH,MAAMG,IAAI;QAC3E,MAAMC,oBAAoB,CAAC,EAAEP,iBAAiBQ,IAAI,CAAC,CAAC,EAAEH,YAAY,CAAC;QAEnE,+BAA+B;QAC/B,IACEF,MAAMM,KAAK,EAAEC,YACbP,MAAMM,KAAK,EAAEE,YACbR,MAAMM,KAAK,EAAEG,UACbT,MAAMU,IAAI,KAAK,OACf;YACA,OAAOV;QACT;QAEA,8EAA8E;QAC9E,wGAAwG;QACxG,yEAAyE;QACzE,IAAI;YAAC;YAAY;YAAQ;YAAY;SAAS,CAACW,QAAQ,CAACX,MAAMU,IAAI,GAAG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BACL,GAAG1B,KAAK;gBACR0B,QAAQ1B,MAAM0B,MAAM,CAACJ,GAAG,CAAC,CAACK,QAAgB,CAAA;wBACxC,GAAGA,KAAK;wBACRN,QAAQM,MAAMN,MAAM,CAACC,GAAG,CAAC,CAACC,WACxBxB,YAAYwB,UAAU,CAAC,EAAErB,YAAY,CAAC,EAAEyB,MAAMtB,IAAI,CAAC,CAAC;oBAExD,CAAA;YACF;QACF;QAEA,OAAOL;IACT;IAEA,MAAM4B,0BAA0B;QAC9B,GAAG/B,gBAAgB;QACnBwB,QAAQxB,iBAAiBwB,MAAM,CAACC,GAAG,CAAC,CAACtB,QAAUD,YAAYC;IAC7D;IAEA,OAAO;QACLF;QACA8B;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/updateFieldsConfig.ts"],"sourcesContent":["import type { CollectionConfig, GlobalConfig } from 'payload'\n\ninterface UpdateFieldsConfig {\n schemaPathMap: Record<string, any>\n updatedCollectionConfig: CollectionConfig | GlobalConfig\n}\n\nexport const updateFieldsConfig = (collectionConfig: CollectionConfig | GlobalConfig): UpdateFieldsConfig => {\n let schemaPathMap = {}\n\n function updateField(field: any, parentPath = ''): any {\n const currentPath = parentPath ? `${parentPath}.${field.name}` : field.name\n const currentSchemaPath = `${collectionConfig.slug}.${currentPath}`\n\n // Disabled fields/ field types\n if (\n field.admin?.disabled ||\n field.admin?.readOnly ||\n field.admin?.hidden ||\n field.type === 'row'\n ) {\n return field\n }\n\n // Map field path for global fieldInstructionsMap to load related instructions\n // This is done due to save extra API call to get instructions when Field components are loaded in admin\n // Doing is will only call instructions data when user clicks on settings\n if (['array', 'richText', 'text', 'textarea', 'upload'].includes(field.type)) {\n schemaPathMap = {\n ...schemaPathMap,\n [currentSchemaPath]: {\n type: field.type,\n custom: field.custom,\n label: field.label || field.name,\n relationTo: field.relationTo,\n },\n }\n }\n\n // Inject AI actions, richText is not included here as it has to be explicitly defined by user\n // Array fields also get AI injection for bulk generation\n if (['array', 'text', 'textarea', 'upload'].includes(field.type)) {\n let customField = {}\n\n // Custom fields don't fully adhere to the Payload schema, making it difficult to\n // determine which components support injecting ComposeField as a Description.\n if (field.admin?.components?.Field || field.admin?.components?.Description) {\n // TODO: If a field already provides its own Description, we still inject our ComposeField\n // by overriding Description. If you need both, consider composing your own wrapper.\n customField = {}\n }\n\n // Array fields use ArrayComposeField (always visible) since they don't have focus events\n // Other fields use ComposeField with focus-dependent visibility\n const componentPath = field.type === 'array'\n ? '@ai-stack/payloadcms/fields#ArrayComposeField'\n : '@ai-stack/payloadcms/fields#ComposeField'\n\n return {\n ...field,\n admin: {\n ...field.admin,\n components: {\n ...(field.admin?.components || {}),\n Description: {\n clientProps: {\n schemaPath: currentSchemaPath,\n },\n path: componentPath,\n },\n ...customField,\n },\n },\n }\n }\n\n if (field.fields) {\n return {\n ...field,\n fields: field.fields.map((subField: any) => updateField(subField, currentPath)),\n }\n }\n\n if (field.tabs) {\n return {\n ...field,\n tabs: field.tabs.map((tab: any) => {\n return {\n ...tab,\n // Tabs are a UI construct and should not add to the schema path\n fields: (tab.fields || []).map((subField: any) => updateField(subField, parentPath)),\n }\n }),\n }\n }\n\n if (field.blocks) {\n return {\n ...field,\n blocks: field.blocks.map((block: any) => ({\n ...block,\n fields: block.fields.map((subField: any) =>\n updateField(subField, `${currentPath}.${block.slug}`),\n ),\n })),\n }\n }\n\n return field\n }\n\n const updatedCollectionConfig = {\n ...collectionConfig,\n fields: collectionConfig.fields.map((field) => updateField(field)),\n }\n\n return {\n schemaPathMap,\n updatedCollectionConfig,\n }\n}\n"],"names":["updateFieldsConfig","collectionConfig","schemaPathMap","updateField","field","parentPath","currentPath","name","currentSchemaPath","slug","admin","disabled","readOnly","hidden","type","includes","custom","label","relationTo","customField","components","Field","Description","componentPath","clientProps","schemaPath","path","fields","map","subField","tabs","tab","blocks","block","updatedCollectionConfig"],"mappings":"AAOA,OAAO,MAAMA,qBAAqB,CAACC;IACjC,IAAIC,gBAAgB,CAAC;IAErB,SAAS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,EAAEU,cAAc,CAAC,CAAC;wBACjCE,aAAa;4BACXE,aAAa;gCACXC,YAAYjB;4BACd;4BACAkB,MAAMH;wBACR;wBACA,GAAGJ,WAAW;oBAChB;gBACF;YACF;QACF;QAEA,IAAIf,MAAMuB,MAAM,EAAE;YAChB,OAAO;gBACL,GAAGvB,KAAK;gBACRuB,QAAQvB,MAAMuB,MAAM,CAACC,GAAG,CAAC,CAACC,WAAkB1B,YAAY0B,UAAUvB;YACpE;QACF;QAEA,IAAIF,MAAM0B,IAAI,EAAE;YACd,OAAO;gBACL,GAAG1B,KAAK;gBACR0B,MAAM1B,MAAM0B,IAAI,CAACF,GAAG,CAAC,CAACG;oBACpB,OAAO;wBACL,GAAGA,GAAG;wBACN,gEAAgE;wBAChEJ,QAAQ,AAACI,CAAAA,IAAIJ,MAAM,IAAI,EAAE,AAAD,EAAGC,GAAG,CAAC,CAACC,WAAkB1B,YAAY0B,UAAUxB;oBAC1E;gBACF;YACF;QACF;QAEA,IAAID,MAAM4B,MAAM,EAAE;YAChB,OAAO;gBACL,GAAG5B,KAAK;gBACR4B,QAAQ5B,MAAM4B,MAAM,CAACJ,GAAG,CAAC,CAACK,QAAgB,CAAA;wBACxC,GAAGA,KAAK;wBACRN,QAAQM,MAAMN,MAAM,CAACC,GAAG,CAAC,CAACC,WACxB1B,YAAY0B,UAAU,CAAC,EAAEvB,YAAY,CAAC,EAAE2B,MAAMxB,IAAI,CAAC,CAAC;oBAExD,CAAA;YACF;QACF;QAEA,OAAOL;IACT;IAEA,MAAM8B,0BAA0B;QAC9B,GAAGjC,gBAAgB;QACnB0B,QAAQ1B,iBAAiB0B,MAAM,CAACC,GAAG,CAAC,CAACxB,QAAUD,YAAYC;IAC7D;IAEA,OAAO;QACLF;QACAgC;IACF;AACF,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-stack/payloadcms",
3
- "version": "3.68.0-beta.1",
3
+ "version": "3.68.0-beta.3",
4
4
  "private": false,
5
5
  "bugs": "https://github.com/ashbuilds/payload-ai/issues",
6
6
  "repository": "https://github.com/ashbuilds/payload-ai",
@@ -70,10 +70,10 @@
70
70
  "scripts": {
71
71
  "build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
72
72
  "build:dev": "pnpm build --watch",
73
- "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
73
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths --ignore '**/*.d.ts'",
74
74
  "build:types": "tsc --outDir dist --rootDir ./src",
75
75
  "clean": "rimraf {dist,*.tsbuildinfo}",
76
- "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
76
+ "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json,d.ts}\" dist/",
77
77
  "dev": "next dev dev --turbo",
78
78
  "dev:generate-importmap": "pnpm dev:payload generate:importmap",
79
79
  "dev:generate-types": "pnpm dev:payload generate:types",
@@ -134,6 +134,7 @@
134
134
  "@payloadcms/translations": "^3.55.1",
135
135
  "@payloadcms/ui": "^3.55.1",
136
136
  "lexical": "^0.35.0",
137
+ "next": ">=15.0.0",
137
138
  "payload": "^3.55.1"
138
139
  },
139
140
  "engines": {
@@ -1,3 +0,0 @@
1
- export { };
2
-
3
- //# sourceMappingURL=chat.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/endpoints/chat.d.ts"],"sourcesContent":["import type { Endpoint } from 'payload';\n\nimport type { PluginConfig } from '../types.js';\nexport declare const Chat: (pluginConfig: PluginConfig) => Endpoint;\n"],"names":[],"mappings":"AAGA,WAAoE"}
package/dist/init.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { Payload } from 'payload';
2
- import type { PluginConfig } from './types.js';
3
- export declare const init: (payload: Payload, fieldSchemaPaths: Record<string, {
4
- label: string;
5
- relationTo?: string;
6
- type: string;
7
- }>, pluginConfig: PluginConfig) => Promise<void>;
package/dist/init.js DELETED
@@ -1,135 +0,0 @@
1
- import { defaultSeedPrompts } from './ai/prompts.js';
2
- import { PLUGIN_INSTRUCTIONS_TABLE } from './defaults.js';
3
- // Defined capabilities mapping for init
4
- const CAPABILITY_MAP = [
5
- {
6
- id: 'text',
7
- fields: [
8
- 'text',
9
- 'textarea'
10
- ]
11
- },
12
- {
13
- id: 'richtext',
14
- fields: [
15
- 'richText'
16
- ]
17
- },
18
- {
19
- id: 'image',
20
- fields: [
21
- 'upload'
22
- ]
23
- }
24
- ];
25
- export const init = async (payload, fieldSchemaPaths, pluginConfig)=>{
26
- if (!pluginConfig.generatePromptOnInit) {
27
- return;
28
- }
29
- if (pluginConfig.debugging) {
30
- payload.logger.info(`— AI Plugin: Initializing...`);
31
- }
32
- const paths = Object.keys(fieldSchemaPaths);
33
- // Get all instructions for faster initialization
34
- const { docs: allInstructions } = await payload.find({
35
- collection: PLUGIN_INSTRUCTIONS_TABLE,
36
- depth: 0,
37
- pagination: false,
38
- select: {
39
- 'field-type': true,
40
- 'schema-path': true
41
- }
42
- });
43
- const fieldInstructionsMap = {};
44
- for(let i = 0; i < paths.length; i++){
45
- const path = paths[i];
46
- const { type: fieldType, label: fieldLabel, relationTo } = fieldSchemaPaths[path];
47
- let instructions = allInstructions.find((entry)=>entry['schema-path'] === path);
48
- if (!instructions) {
49
- let seed;
50
- const seedOptions = {
51
- fieldLabel,
52
- fieldSchemaPaths,
53
- fieldType,
54
- path
55
- };
56
- if (pluginConfig.seedPrompts) {
57
- seed = await pluginConfig.seedPrompts(seedOptions);
58
- }
59
- if (seed === undefined) {
60
- seed = await defaultSeedPrompts(seedOptions);
61
- }
62
- // Field should be ignored
63
- if (!seed) {
64
- if (pluginConfig.debugging) {
65
- payload.logger.info(`— AI Plugin: No seed prompt for ${path}, ignoring...`);
66
- }
67
- continue;
68
- }
69
- const generatedPrompt = '{{ title }}';
70
- if ('prompt' in seed) {
71
- // Prompt generation currently disabled during migration to AI SDK Providers
72
- // TODO: Re-enable using a default provider from AI Settings if available
73
- /*
74
- generatedPrompt = await systemGenerate(
75
- {
76
- prompt: seed.prompt,
77
- system: seed.system,
78
- },
79
- undefined // No generateTextFn currently
80
- )
81
- */ }
82
- const modelForId = CAPABILITY_MAP.find((a)=>a.fields.includes(fieldType));
83
- const data = {
84
- 'model-id': modelForId?.id,
85
- prompt: generatedPrompt,
86
- ...seed.data,
87
- 'field-type': fieldType,
88
- 'relation-to': relationTo,
89
- 'schema-path': path
90
- };
91
- payload.logger.info({
92
- 'model-id': data['model-id'],
93
- prompt: generatedPrompt,
94
- ...seed.data
95
- }, `Prompt seeded for "${path}" field`);
96
- instructions = await payload.create({
97
- collection: PLUGIN_INSTRUCTIONS_TABLE,
98
- data
99
- }).catch((err)=>{
100
- payload.logger.error(err, '— AI Plugin: Error creating Compose settings-');
101
- });
102
- if (instructions?.id) {
103
- fieldInstructionsMap[path] = {
104
- id: instructions.id,
105
- fieldType
106
- };
107
- }
108
- } else {
109
- if (instructions['field-type'] !== fieldType) {
110
- payload.logger.warn(`— AI Plugin: Field type mismatch for ${path}! Was "${fieldType}", it is "${instructions['field-type']}" now. Updating...`);
111
- await payload.update({
112
- id: instructions.id,
113
- collection: PLUGIN_INSTRUCTIONS_TABLE,
114
- data: {
115
- 'field-type': fieldType
116
- }
117
- });
118
- instructions['field-type'] = fieldType;
119
- }
120
- fieldInstructionsMap[path] = {
121
- id: instructions.id,
122
- fieldType
123
- };
124
- }
125
- }
126
- if (pluginConfig.debugging) {
127
- payload.logger.info(`— AI Plugin: Enabled fields map: ${JSON.stringify(fieldInstructionsMap, null, 2)}`);
128
- payload.logger.info(`— AI Plugin: Initialized!`);
129
- }
130
- if (pluginConfig.generatePromptOnInit) {
131
- payload.logger.info('\n\n-AI Plugin: Example prompts are added to get you started, Now go break some code 🚀🚀🚀\n\n');
132
- }
133
- };
134
-
135
- //# sourceMappingURL=init.js.map
package/dist/init.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport type { PluginConfig } from './types.js'\n\nimport { defaultSeedPrompts } from './ai/prompts.js'\nimport { systemGenerate } from './ai/utils/systemGenerate.js'\nimport { PLUGIN_INSTRUCTIONS_TABLE } from './defaults.js'\n\n// Defined capabilities mapping for init\nconst CAPABILITY_MAP = [\n { id: 'text', fields: ['text', 'textarea'] },\n { id: 'richtext', fields: ['richText'] },\n { id: 'image', fields: ['upload'] },\n // TTS usually outputs to upload, but init logic maps field types to capabilities\n]\n\nexport const init = async (\n payload: Payload,\n fieldSchemaPaths: Record<string, { label: string; relationTo?: string; type: string }>,\n pluginConfig: PluginConfig,\n) => {\n if (!pluginConfig.generatePromptOnInit) {\n return\n }\n\n if (pluginConfig.debugging) {\n payload.logger.info(`— AI Plugin: Initializing...`)\n }\n\n const paths = Object.keys(fieldSchemaPaths)\n\n // Get all instructions for faster initialization\n const { docs: allInstructions } = await payload.find({\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n depth: 0,\n pagination: false,\n select: {\n 'field-type': true,\n 'schema-path': true,\n },\n })\n\n const fieldInstructionsMap: Record<string, { fieldType: any; id: any }> = {}\n\n for (let i = 0; i < paths.length; i++) {\n const path = paths[i]\n const { type: fieldType, label: fieldLabel, relationTo } = fieldSchemaPaths[path]\n let instructions = allInstructions.find((entry) => entry['schema-path'] === path)\n\n if (!instructions) {\n let seed\n const seedOptions = {\n fieldLabel,\n fieldSchemaPaths,\n fieldType,\n path,\n }\n\n if (pluginConfig.seedPrompts) {seed = await pluginConfig.seedPrompts(seedOptions)}\n if (seed === undefined) {seed = await defaultSeedPrompts(seedOptions)}\n // Field should be ignored\n if (!seed) {\n if (pluginConfig.debugging) {\n payload.logger.info(`— AI Plugin: No seed prompt for ${path}, ignoring...`)\n }\n continue\n }\n\n const generatedPrompt: string | undefined = '{{ title }}'\n if ('prompt' in seed) {\n // Prompt generation currently disabled during migration to AI SDK Providers\n // TODO: Re-enable using a default provider from AI Settings if available\n /*\n generatedPrompt = await systemGenerate(\n {\n prompt: seed.prompt,\n system: seed.system,\n },\n undefined // No generateTextFn currently\n )\n */\n }\n\n const modelForId = CAPABILITY_MAP.find((a) => a.fields.includes(fieldType))\n\n const data = {\n 'model-id': modelForId?.id,\n prompt: generatedPrompt,\n ...seed.data, // allow to override data, but not the one below\n 'field-type': fieldType,\n 'relation-to': relationTo,\n 'schema-path': path,\n }\n\n payload.logger.info(\n {\n 'model-id': data['model-id'],\n prompt: generatedPrompt,\n ...seed.data,\n },\n `Prompt seeded for \"${path}\" field`,\n )\n\n instructions = (await payload\n .create({\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n data,\n })\n .catch((err) => {\n payload.logger.error(err, '— AI Plugin: Error creating Compose settings-')\n })) as (typeof allInstructions)[0]\n\n if (instructions?.id) {\n fieldInstructionsMap[path] = {\n id: instructions.id,\n fieldType,\n }\n }\n } else {\n if (instructions['field-type'] !== fieldType) {\n payload.logger.warn(\n `— AI Plugin: Field type mismatch for ${path}! Was \"${fieldType}\", it is \"${instructions['field-type']}\" now. Updating...`,\n )\n await payload.update({\n id: instructions.id,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n data: {\n 'field-type': fieldType,\n },\n })\n instructions['field-type'] = fieldType\n }\n\n fieldInstructionsMap[path] = {\n id: instructions.id,\n fieldType,\n }\n }\n }\n\n if (pluginConfig.debugging) {\n payload.logger.info(\n `— AI Plugin: Enabled fields map: ${JSON.stringify(fieldInstructionsMap, null, 2)}`,\n )\n payload.logger.info(`— AI Plugin: Initialized!`)\n }\n\n if (pluginConfig.generatePromptOnInit) {\n payload.logger.info(\n '\\n\\n-AI Plugin: Example prompts are added to get you started, Now go break some code 🚀🚀🚀\\n\\n',\n )\n }\n}\n"],"names":["defaultSeedPrompts","PLUGIN_INSTRUCTIONS_TABLE","CAPABILITY_MAP","id","fields","init","payload","fieldSchemaPaths","pluginConfig","generatePromptOnInit","debugging","logger","info","paths","Object","keys","docs","allInstructions","find","collection","depth","pagination","select","fieldInstructionsMap","i","length","path","type","fieldType","label","fieldLabel","relationTo","instructions","entry","seed","seedOptions","seedPrompts","undefined","generatedPrompt","modelForId","a","includes","data","prompt","create","catch","err","error","warn","update","JSON","stringify"],"mappings":"AAIA,SAASA,kBAAkB,QAAQ,kBAAiB;AAEpD,SAASC,yBAAyB,QAAQ,gBAAe;AAEzD,wCAAwC;AACxC,MAAMC,iBAAiB;IACrB;QAAEC,IAAI;QAAQC,QAAQ;YAAC;YAAQ;SAAW;IAAC;IAC3C;QAAED,IAAI;QAAYC,QAAQ;YAAC;SAAW;IAAC;IACvC;QAAED,IAAI;QAASC,QAAQ;YAAC;SAAS;IAAC;CAEnC;AAED,OAAO,MAAMC,OAAO,OAClBC,SACAC,kBACAC;IAEA,IAAI,CAACA,aAAaC,oBAAoB,EAAE;QACtC;IACF;IAEA,IAAID,aAAaE,SAAS,EAAE;QAC1BJ,QAAQK,MAAM,CAACC,IAAI,CAAC,CAAC,4BAA4B,CAAC;IACpD;IAEA,MAAMC,QAAQC,OAAOC,IAAI,CAACR;IAE1B,iDAAiD;IACjD,MAAM,EAAES,MAAMC,eAAe,EAAE,GAAG,MAAMX,QAAQY,IAAI,CAAC;QACnDC,YAAYlB;QACZmB,OAAO;QACPC,YAAY;QACZC,QAAQ;YACN,cAAc;YACd,eAAe;QACjB;IACF;IAEA,MAAMC,uBAAoE,CAAC;IAE3E,IAAK,IAAIC,IAAI,GAAGA,IAAIX,MAAMY,MAAM,EAAED,IAAK;QACrC,MAAME,OAAOb,KAAK,CAACW,EAAE;QACrB,MAAM,EAAEG,MAAMC,SAAS,EAAEC,OAAOC,UAAU,EAAEC,UAAU,EAAE,GAAGxB,gBAAgB,CAACmB,KAAK;QACjF,IAAIM,eAAef,gBAAgBC,IAAI,CAAC,CAACe,QAAUA,KAAK,CAAC,cAAc,KAAKP;QAE5E,IAAI,CAACM,cAAc;YACjB,IAAIE;YACJ,MAAMC,cAAc;gBAClBL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B,KAAK,OAAO,EAAEE,UAAU,UAAU,EAAEI,YAAY,CAAC,aAAa,CAAC,kBAAkB,CAAC;gBAE5H,MAAM1B,QAAQ2C,MAAM,CAAC;oBACnB9C,IAAI6B,aAAa7B,EAAE;oBACnBgB,YAAYlB;oBACZyC,MAAM;wBACJ,cAAcd;oBAChB;gBACF;gBACAI,YAAY,CAAC,aAAa,GAAGJ;YAC/B;YAEAL,oBAAoB,CAACG,KAAK,GAAG;gBAC3BvB,IAAI6B,aAAa7B,EAAE;gBACnByB;YACF;QACF;IACF;IAEA,IAAIpB,aAAaE,SAAS,EAAE;QAC1BJ,QAAQK,MAAM,CAACC,IAAI,CACjB,CAAC,iCAAiC,EAAEsC,KAAKC,SAAS,CAAC5B,sBAAsB,MAAM,GAAG,CAAC;QAErFjB,QAAQK,MAAM,CAACC,IAAI,CAAC,CAAC,yBAAyB,CAAC;IACjD;IAEA,IAAIJ,aAAaC,oBAAoB,EAAE;QACrCH,QAAQK,MAAM,CAACC,IAAI,CACjB;IAEJ;AACF,EAAC"}
@@ -1,3 +0,0 @@
1
- export { };
2
-
3
- //# sourceMappingURL=payload-ai.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/payload-ai.d.ts"],"sourcesContent":["import type { GenerateObjectResult } from 'ai'\n// Type definitions for payload.ai API\nimport type { Payload } from 'payload'\n\nimport type {\n MediaResult,\n PayloadGenerateMediaArgs,\n PayloadGenerateObjectArgs,\n PayloadGenerateTextArgs,\n} from './ai/core/types.js'\n\ndeclare module 'payload' {\n interface BasePayload {\n ai: {\n /**\n * @deprecated Use generateObject or generateText instead\n * Legacy generate method for backward compatibility\n */\n generate: (args: unknown) => Promise<unknown>\n\n /**\n * Generate media (images or videos)\n * @param args - Generation arguments including provider, model, prompt, and media options\n * @returns Promise resolving to either a file or async job info\n */\n generateMedia: (args: Omit<PayloadGenerateMediaArgs, 'payload'>) => Promise<MediaResult>\n\n /**\n * Generate structured output with schema validation\n * @param args - Generation arguments including provider, model, prompt, and schema\n * @returns Promise resolving to the generated object\n */\n generateObject: <T = unknown>(args: Omit<PayloadGenerateObjectArgs, 'payload'>) => Promise<GenerateObjectResult<T>>\n\n /**\n * Generate simple text output\n * @param args - Generation arguments including provider, model, and prompt\n * @returns Promise resolving to the generated text\n */\n generateText: (args: Omit<PayloadGenerateTextArgs, 'payload'>) => Promise<string>\n\n /**\n * Get a specific model instance\n * @param provider - Provider name (e.g., 'openai', 'anthropic')\n * @param modelId - Model ID (e.g., 'gpt-4', 'claude-3')\n * @param type - Model type ('text', 'image', or 'tts')\n * @returns Promise resolving to the model instance\n */\n getModel: (provider: string, modelId: string, type?: 'image' | 'text' | 'tts') => Promise<unknown>\n\n /**\n * Get the provider registry\n * @returns Promise resolving to the provider registry\n */\n getRegistry: () => Promise<Record<string, unknown>>\n\n /**\n * Stream structured output with schema validation\n * @param args - Generation arguments including provider, model, prompt, and schema\n * @returns Response stream\n */\n streamObject: <T = unknown>(\n args: Omit<PayloadGenerateObjectArgs, 'payload'>,\n ) => Promise<Response>\n\n /**\n * Stream text output\n * @param args - Generation arguments including provider, model, and prompt\n * @returns Response stream\n */\n streamText: (args: Omit<PayloadGenerateTextArgs, 'payload'>) => Promise<Response>\n }\n }\n}"],"names":[],"mappings":"AAIA,WAK2B"}
package/dist/styles.d.js DELETED
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=styles.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/styles.d.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=handlebars-async-helpers.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/types/handlebars-async-helpers.d.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=handlebars-dist-handlebars.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/types/handlebars-dist-handlebars.d.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=react-mentions.d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/types/react-mentions.d.ts"],"names":[],"mappings":""}