@ai-stack/payloadcms 3.76.0-beta.1 → 3.76.0-beta.2

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 (337) hide show
  1. package/dist/ai/core/generateObject.js +1 -4
  2. package/dist/ai/core/generateObject.js.map +1 -1
  3. package/dist/ai/core/generateText.js +1 -5
  4. package/dist/ai/core/generateText.js.map +1 -1
  5. package/dist/ai/core/media/generateMedia.js +1 -4
  6. package/dist/ai/core/media/generateMedia.js.map +1 -1
  7. package/dist/ai/core/media/image/generateImage.js +4 -14
  8. package/dist/ai/core/media/image/generateImage.js.map +1 -1
  9. package/dist/ai/core/media/image/handlers/multimodal.js +8 -25
  10. package/dist/ai/core/media/image/handlers/multimodal.js.map +1 -1
  11. package/dist/ai/core/media/image/handlers/standard.js +7 -2
  12. package/dist/ai/core/media/image/handlers/standard.js.map +1 -1
  13. package/dist/ai/core/media/speech/generateSpeech.js +2 -3
  14. package/dist/ai/core/media/speech/generateSpeech.js.map +1 -1
  15. package/dist/ai/core/media/types.d.ts +2 -3
  16. package/dist/ai/core/media/types.js.map +1 -1
  17. package/dist/ai/core/streamObject.js +0 -3
  18. package/dist/ai/core/streamObject.js.map +1 -1
  19. package/dist/ai/core/streamText.js +1 -4
  20. package/dist/ai/core/streamText.js.map +1 -1
  21. package/dist/ai/core/types.d.ts +2 -2
  22. package/dist/ai/core/types.js.map +1 -1
  23. package/dist/ai/providers/blocks/anthropic.js +0 -42
  24. package/dist/ai/providers/blocks/anthropic.js.map +1 -1
  25. package/dist/ai/providers/blocks/elevenlabs.js +1 -106
  26. package/dist/ai/providers/blocks/elevenlabs.js.map +1 -1
  27. package/dist/ai/providers/blocks/fal.js +0 -118
  28. package/dist/ai/providers/blocks/fal.js.map +1 -1
  29. package/dist/ai/providers/blocks/google.js +2 -237
  30. package/dist/ai/providers/blocks/google.js.map +1 -1
  31. package/dist/ai/providers/blocks/openai-compatible.js +0 -144
  32. package/dist/ai/providers/blocks/openai-compatible.js.map +1 -1
  33. package/dist/ai/providers/blocks/openai.js +0 -200
  34. package/dist/ai/providers/blocks/openai.js.map +1 -1
  35. package/dist/ai/providers/blocks/xai.js +0 -53
  36. package/dist/ai/providers/blocks/xai.js.map +1 -1
  37. package/dist/ai/providers/index.d.ts +1 -1
  38. package/dist/ai/providers/index.js +0 -2
  39. package/dist/ai/providers/index.js.map +1 -1
  40. package/dist/ai/providers/registry.d.ts +24 -28
  41. package/dist/ai/providers/registry.js +184 -138
  42. package/dist/ai/providers/registry.js.map +1 -1
  43. package/dist/ai/providers/types.d.ts +12 -33
  44. package/dist/ai/providers/types.js +0 -1
  45. package/dist/ai/providers/types.js.map +1 -1
  46. package/dist/ai/schemas/lexicalJsonSchema.js +1 -1
  47. package/dist/ai/schemas/lexicalJsonSchema.js.map +1 -1
  48. package/dist/ai/utilities/filterEditorSchemaByNodes.js.map +1 -0
  49. package/dist/ai/utilities/generateFileNameByPrompt.js.map +1 -0
  50. package/dist/ai/utilities/isObjectSchema.js.map +1 -0
  51. package/dist/ai/utilities/nodeToSchemaMap.js.map +1 -0
  52. package/dist/ai/{prompts.d.ts → utilities/prompts.d.ts} +1 -1
  53. package/dist/ai/utilities/prompts.js.map +1 -0
  54. package/dist/ai/utilities/systemGenerate.js.map +1 -0
  55. package/dist/collections/AIJobs.js +3 -12
  56. package/dist/collections/AIJobs.js.map +1 -1
  57. package/dist/collections/AIProviders.js +47 -20
  58. package/dist/collections/AIProviders.js.map +1 -1
  59. package/dist/collections/Instructions.js +86 -54
  60. package/dist/collections/Instructions.js.map +1 -1
  61. package/dist/collections/shared.d.ts +30 -0
  62. package/dist/collections/shared.js +15 -0
  63. package/dist/collections/shared.js.map +1 -0
  64. package/dist/endpoints/fetchFields.js +14 -6
  65. package/dist/endpoints/fetchFields.js.map +1 -1
  66. package/dist/endpoints/fetchVoices.js +1 -1
  67. package/dist/endpoints/fetchVoices.js.map +1 -1
  68. package/dist/endpoints/generate.d.ts +7 -0
  69. package/dist/endpoints/generate.js +268 -0
  70. package/dist/endpoints/generate.js.map +1 -0
  71. package/dist/endpoints/index.js +9 -639
  72. package/dist/endpoints/index.js.map +1 -1
  73. package/dist/endpoints/promptMentions.d.ts +2 -0
  74. package/dist/endpoints/promptMentions.js +166 -0
  75. package/dist/endpoints/promptMentions.js.map +1 -0
  76. package/dist/endpoints/upload.d.ts +7 -0
  77. package/dist/endpoints/upload.js +294 -0
  78. package/dist/endpoints/upload.js.map +1 -0
  79. package/dist/endpoints/videogenWebhook.d.ts +7 -0
  80. package/dist/endpoints/videogenWebhook.js +132 -0
  81. package/dist/endpoints/videogenWebhook.js.map +1 -0
  82. package/dist/exports/client.d.ts +2 -1
  83. package/dist/exports/client.js +2 -1
  84. package/dist/exports/client.js.map +1 -1
  85. package/dist/exports/fields.d.ts +2 -1
  86. package/dist/exports/fields.js +2 -1
  87. package/dist/exports/fields.js.map +1 -1
  88. package/dist/fields/ArrayComposeField/ArrayComposeField.js +1 -1
  89. package/dist/fields/ArrayComposeField/ArrayComposeField.js.map +1 -1
  90. package/dist/fields/ArrayComposeField/ArrayComposeField.jsx +1 -1
  91. package/dist/fields/ComposeField/ComposeField.d.ts +1 -0
  92. package/dist/fields/ComposeField/ComposeField.js +18 -8
  93. package/dist/fields/ComposeField/ComposeField.js.map +1 -1
  94. package/dist/fields/ComposeField/ComposeField.jsx +12 -7
  95. package/dist/fields/PromptEditorField/feature.client.d.ts +1 -0
  96. package/dist/fields/PromptEditorField/feature.client.js +173 -0
  97. package/dist/fields/PromptEditorField/feature.client.js.map +1 -0
  98. package/dist/fields/PromptEditorField/feature.client.jsx +148 -0
  99. package/dist/fields/PromptEditorField/feature.server.d.ts +1 -0
  100. package/dist/fields/PromptEditorField/feature.server.js +30 -0
  101. package/dist/fields/PromptEditorField/feature.server.js.map +1 -0
  102. package/dist/fields/PromptField.d.ts +4 -0
  103. package/dist/fields/PromptField.js +18 -0
  104. package/dist/fields/PromptField.js.map +1 -0
  105. package/dist/fields/SelectField/SelectField.js +0 -1
  106. package/dist/fields/SelectField/SelectField.js.map +1 -1
  107. package/dist/fields/SelectField/SelectField.jsx +0 -1
  108. package/dist/index.d.ts +4 -3
  109. package/dist/index.js +4 -2
  110. package/dist/index.js.map +1 -1
  111. package/dist/libraries/handlebars/helpers.js +2 -2
  112. package/dist/libraries/handlebars/helpers.js.map +1 -1
  113. package/dist/libraries/handlebars/replacePlaceholders.js +5 -1
  114. package/dist/libraries/handlebars/replacePlaceholders.js.map +1 -1
  115. package/dist/payload-ai.d.ts +5 -19
  116. package/dist/plugin.js +17 -20
  117. package/dist/plugin.js.map +1 -1
  118. package/dist/providers/FieldProvider/FieldProvider.js +10 -19
  119. package/dist/providers/FieldProvider/FieldProvider.js.map +1 -1
  120. package/dist/providers/FieldProvider/FieldProvider.jsx +7 -17
  121. package/dist/providers/InstructionsProvider/InstructionsProvider.js +4 -1
  122. package/dist/providers/InstructionsProvider/InstructionsProvider.js.map +1 -1
  123. package/dist/providers/InstructionsProvider/InstructionsProvider.jsx +3 -0
  124. package/dist/translations/de.json +47 -0
  125. package/dist/translations/en.json +45 -2
  126. package/dist/translations/es.json +45 -2
  127. package/dist/translations/fa.json +45 -2
  128. package/dist/translations/fr.json +46 -3
  129. package/dist/translations/hi.json +47 -0
  130. package/dist/translations/index.d.ts +88 -26
  131. package/dist/translations/index.js +18 -32
  132. package/dist/translations/index.js.map +1 -1
  133. package/dist/translations/ja.json +47 -0
  134. package/dist/translations/nb.json +47 -0
  135. package/dist/translations/nl.json +47 -0
  136. package/dist/translations/pl.json +45 -2
  137. package/dist/translations/pt.json +47 -0
  138. package/dist/translations/ru.json +45 -2
  139. package/dist/translations/th.json +47 -0
  140. package/dist/translations/translation-schema.json +184 -11
  141. package/dist/translations/uk.json +45 -2
  142. package/dist/translations/zh.json +47 -0
  143. package/dist/types.d.ts +54 -28
  144. package/dist/types.js.map +1 -1
  145. package/dist/ui/Compose/Compose.js +42 -79
  146. package/dist/ui/Compose/Compose.js.map +1 -1
  147. package/dist/ui/Compose/Compose.jsx +32 -86
  148. package/dist/ui/Compose/ComposePlaceholder.js +1 -1
  149. package/dist/ui/Compose/ComposePlaceholder.js.map +1 -1
  150. package/dist/ui/Compose/ComposePlaceholder.jsx +1 -1
  151. package/dist/ui/Compose/{compose.module.css → compose.module.scss} +3 -5
  152. package/dist/ui/Compose/hooks/menu/Item.d.ts +1 -1
  153. package/dist/ui/Compose/hooks/menu/Item.js +7 -3
  154. package/dist/ui/Compose/hooks/menu/Item.js.map +1 -1
  155. package/dist/ui/Compose/hooks/menu/Item.jsx +11 -5
  156. package/dist/ui/Compose/hooks/menu/TranslateMenu.js +3 -1
  157. package/dist/ui/Compose/hooks/menu/TranslateMenu.js.map +1 -1
  158. package/dist/ui/Compose/hooks/menu/TranslateMenu.jsx +3 -1
  159. package/dist/ui/Compose/hooks/menu/items.d.ts +8 -8
  160. package/dist/ui/Compose/hooks/menu/itemsMap.d.ts +2 -1
  161. package/dist/ui/Compose/hooks/menu/itemsMap.js.map +1 -1
  162. package/dist/ui/Compose/hooks/menu/types.d.ts +21 -0
  163. package/dist/ui/Compose/hooks/menu/types.js +3 -0
  164. package/dist/ui/Compose/hooks/menu/types.js.map +1 -0
  165. package/dist/ui/Compose/hooks/menu/useMenu.d.ts +2 -2
  166. package/dist/ui/Compose/hooks/menu/useMenu.js +45 -23
  167. package/dist/ui/Compose/hooks/menu/useMenu.js.map +1 -1
  168. package/dist/ui/Compose/hooks/menu/useMenu.jsx +43 -23
  169. package/dist/ui/Compose/hooks/mergeGeneratedValue.d.ts +14 -0
  170. package/dist/ui/Compose/hooks/mergeGeneratedValue.js +38 -0
  171. package/dist/ui/Compose/hooks/mergeGeneratedValue.js.map +1 -0
  172. package/dist/ui/Compose/hooks/useGenerate.js +37 -12
  173. package/dist/ui/Compose/hooks/useGenerate.js.map +1 -1
  174. package/dist/ui/Compose/hooks/useGenerateUpload.js +66 -24
  175. package/dist/ui/Compose/hooks/useGenerateUpload.js.map +1 -1
  176. package/dist/ui/Compose/hooks/useStreamingUpdate.js +4 -4
  177. package/dist/ui/Compose/hooks/useStreamingUpdate.js.map +1 -1
  178. package/dist/ui/ConfigDashboard/configDashboard.module.css +94 -0
  179. package/dist/ui/ConfigDashboard/index.js +27 -92
  180. package/dist/ui/ConfigDashboard/index.js.map +1 -1
  181. package/dist/ui/ConfigDashboard/index.jsx +24 -77
  182. package/dist/ui/DynamicModelSelect/index.js +6 -27
  183. package/dist/ui/DynamicModelSelect/index.js.map +1 -1
  184. package/dist/ui/DynamicModelSelect/index.jsx +6 -29
  185. package/dist/ui/DynamicProviderSelect/index.js +6 -27
  186. package/dist/ui/DynamicProviderSelect/index.js.map +1 -1
  187. package/dist/ui/DynamicProviderSelect/index.jsx +6 -29
  188. package/dist/ui/DynamicVoiceSelect/index.js +34 -83
  189. package/dist/ui/DynamicVoiceSelect/index.js.map +1 -1
  190. package/dist/ui/DynamicVoiceSelect/index.jsx +16 -53
  191. package/dist/ui/GlobalProviderOptions/index.d.ts +2 -0
  192. package/dist/ui/GlobalProviderOptions/index.js +118 -0
  193. package/dist/ui/GlobalProviderOptions/index.js.map +1 -0
  194. package/dist/ui/GlobalProviderOptions/index.jsx +60 -0
  195. package/dist/ui/Icons/Icons.js +1 -1
  196. package/dist/ui/Icons/Icons.js.map +1 -1
  197. package/dist/ui/Icons/Icons.jsx +1 -1
  198. package/dist/ui/Icons/LottieAnimation.js +1 -1
  199. package/dist/ui/Icons/LottieAnimation.js.map +1 -1
  200. package/dist/ui/Icons/LottieAnimation.jsx +1 -1
  201. package/dist/ui/InstructionProviderOptions/ProviderOptionsTree.d.ts +12 -0
  202. package/dist/ui/InstructionProviderOptions/ProviderOptionsTree.js +166 -0
  203. package/dist/ui/InstructionProviderOptions/ProviderOptionsTree.js.map +1 -0
  204. package/dist/ui/InstructionProviderOptions/ProviderOptionsTree.jsx +83 -0
  205. package/dist/ui/InstructionProviderOptions/index.d.ts +2 -0
  206. package/dist/ui/InstructionProviderOptions/index.js +157 -0
  207. package/dist/ui/InstructionProviderOptions/index.js.map +1 -0
  208. package/dist/ui/InstructionProviderOptions/index.jsx +92 -0
  209. package/dist/ui/VoicesFetcher/index.js.map +1 -1
  210. package/dist/ui/hooks/useAISettings.d.ts +26 -0
  211. package/dist/ui/hooks/useAISettings.js +73 -0
  212. package/dist/ui/hooks/useAISettings.js.map +1 -0
  213. package/dist/ui/providerOptions/updateProviderOptionsValue.d.ts +6 -0
  214. package/dist/ui/providerOptions/updateProviderOptionsValue.js +50 -0
  215. package/dist/ui/providerOptions/updateProviderOptionsValue.js.map +1 -0
  216. package/dist/ui/shared/handleSelectChange.d.ts +5 -0
  217. package/dist/ui/shared/handleSelectChange.js +12 -0
  218. package/dist/ui/shared/handleSelectChange.js.map +1 -0
  219. package/dist/ui/shared/types.d.ts +11 -0
  220. package/dist/ui/shared/types.js +5 -0
  221. package/dist/ui/shared/types.js.map +1 -0
  222. package/dist/utilities/ai/resolveEffectiveInstructionSettings.d.ts +15 -0
  223. package/dist/utilities/ai/resolveEffectiveInstructionSettings.js +136 -0
  224. package/dist/utilities/ai/resolveEffectiveInstructionSettings.js.map +1 -0
  225. package/dist/{endpoints → utilities}/buildPromptUtils.js +14 -5
  226. package/dist/utilities/buildPromptUtils.js.map +1 -0
  227. package/dist/utilities/buildSmartPrompt.js +3 -3
  228. package/dist/utilities/buildSmartPrompt.js.map +1 -1
  229. package/dist/utilities/fields/fieldToJsonSchema.js.map +1 -0
  230. package/dist/utilities/fields/getFieldBySchemaPath.js.map +1 -0
  231. package/dist/utilities/fields/getFieldInfo.js.map +1 -0
  232. package/dist/utilities/{updateFieldsConfig.js → fields/updateFieldsConfig.js} +7 -2
  233. package/dist/utilities/fields/updateFieldsConfig.js.map +1 -0
  234. package/dist/utilities/images/extractImageData.js.map +1 -0
  235. package/dist/utilities/images/extractPromptAttachments.js.map +1 -0
  236. package/dist/utilities/{fetchImages.d.ts → images/fetchImages.d.ts} +1 -1
  237. package/dist/utilities/images/fetchImages.js +49 -0
  238. package/dist/utilities/images/fetchImages.js.map +1 -0
  239. package/dist/utilities/images/resolveImageReferences.js +183 -0
  240. package/dist/utilities/images/resolveImageReferences.js.map +1 -0
  241. package/dist/utilities/init/autoSetupProviders.d.ts +3 -0
  242. package/dist/utilities/init/autoSetupProviders.js +216 -0
  243. package/dist/utilities/init/autoSetupProviders.js.map +1 -0
  244. package/dist/utilities/lexical/editorSchemaValidator.js.map +1 -0
  245. package/dist/utilities/lexical/lexicalToHTML.js.map +1 -0
  246. package/dist/utilities/lexical/lexicalToPromptTemplate.d.ts +2 -0
  247. package/dist/utilities/lexical/lexicalToPromptTemplate.js +50 -0
  248. package/dist/utilities/lexical/lexicalToPromptTemplate.js.map +1 -0
  249. package/dist/utilities/lexical/setSafeLexicalState.js.map +1 -0
  250. package/dist/utilities/lexical/stringToLexicalJSON.d.ts +2 -0
  251. package/dist/utilities/lexical/stringToLexicalJSON.js +39 -0
  252. package/dist/utilities/lexical/stringToLexicalJSON.js.map +1 -0
  253. package/dist/utilities/sanitizeLog.d.ts +1 -0
  254. package/dist/utilities/sanitizeLog.js +39 -0
  255. package/dist/utilities/sanitizeLog.js.map +1 -0
  256. package/dist/utilities/seedProperties.js +37 -22
  257. package/dist/utilities/seedProperties.js.map +1 -1
  258. package/package.json +5 -2
  259. package/dist/ai/analyse.d.ts +0 -1
  260. package/dist/ai/analyse.js +0 -3
  261. package/dist/ai/analyse.js.map +0 -1
  262. package/dist/ai/index.d.ts +0 -11
  263. package/dist/ai/index.js +0 -25
  264. package/dist/ai/index.js.map +0 -1
  265. package/dist/ai/prompts.js.map +0 -1
  266. package/dist/ai/utils/filterEditorSchemaByNodes.js.map +0 -1
  267. package/dist/ai/utils/generateFileNameByPrompt.js.map +0 -1
  268. package/dist/ai/utils/isObjectSchema.js.map +0 -1
  269. package/dist/ai/utils/nodeToSchemaMap.js.map +0 -1
  270. package/dist/ai/utils/systemGenerate.js.map +0 -1
  271. package/dist/endpoints/buildPromptUtils.js.map +0 -1
  272. package/dist/endpoints/chat.d.ts +0 -4
  273. package/dist/fields/PromptEditorField/PromptEditorField.d.ts +0 -3
  274. package/dist/fields/PromptEditorField/PromptEditorField.js +0 -217
  275. package/dist/fields/PromptEditorField/PromptEditorField.js.map +0 -1
  276. package/dist/fields/PromptEditorField/PromptEditorField.jsx +0 -160
  277. package/dist/ui/AIConfigDashboard/index.d.ts +0 -2
  278. package/dist/ui/AIConfigDashboard/index.js +0 -224
  279. package/dist/ui/AIConfigDashboard/index.js.map +0 -1
  280. package/dist/ui/AIConfigDashboard/index.jsx +0 -175
  281. package/dist/ui/ProviderOptionsEditor/index.d.ts +0 -7
  282. package/dist/ui/ProviderOptionsEditor/index.js +0 -291
  283. package/dist/ui/ProviderOptionsEditor/index.js.map +0 -1
  284. package/dist/ui/ProviderOptionsEditor/index.jsx +0 -210
  285. package/dist/utilities/editorSchemaValidator.js.map +0 -1
  286. package/dist/utilities/extractImageData.js.map +0 -1
  287. package/dist/utilities/extractPromptAttachments.js.map +0 -1
  288. package/dist/utilities/fetchImages.js +0 -38
  289. package/dist/utilities/fetchImages.js.map +0 -1
  290. package/dist/utilities/fieldToJsonSchema.js.map +0 -1
  291. package/dist/utilities/getFieldBySchemaPath.js.map +0 -1
  292. package/dist/utilities/getFieldInfo.js.map +0 -1
  293. package/dist/utilities/getProviderOptionsFields.d.ts +0 -16
  294. package/dist/utilities/getProviderOptionsFields.js +0 -80
  295. package/dist/utilities/getProviderOptionsFields.js.map +0 -1
  296. package/dist/utilities/isPluginActivated.d.ts +0 -2
  297. package/dist/utilities/isPluginActivated.js +0 -5
  298. package/dist/utilities/isPluginActivated.js.map +0 -1
  299. package/dist/utilities/lexicalToHTML.js.map +0 -1
  300. package/dist/utilities/resolveImageReferences.js +0 -167
  301. package/dist/utilities/resolveImageReferences.js.map +0 -1
  302. package/dist/utilities/schemaConverter.d.ts +0 -3
  303. package/dist/utilities/schemaConverter.js +0 -93
  304. package/dist/utilities/schemaConverter.js.map +0 -1
  305. package/dist/utilities/setSafeLexicalState.js.map +0 -1
  306. package/dist/utilities/updateFieldsConfig.js.map +0 -1
  307. /package/dist/ai/{utils → utilities}/filterEditorSchemaByNodes.d.ts +0 -0
  308. /package/dist/ai/{utils → utilities}/filterEditorSchemaByNodes.js +0 -0
  309. /package/dist/ai/{utils → utilities}/generateFileNameByPrompt.d.ts +0 -0
  310. /package/dist/ai/{utils → utilities}/generateFileNameByPrompt.js +0 -0
  311. /package/dist/ai/{utils → utilities}/isObjectSchema.d.ts +0 -0
  312. /package/dist/ai/{utils → utilities}/isObjectSchema.js +0 -0
  313. /package/dist/ai/{utils → utilities}/nodeToSchemaMap.d.ts +0 -0
  314. /package/dist/ai/{utils → utilities}/nodeToSchemaMap.js +0 -0
  315. /package/dist/ai/{prompts.js → utilities/prompts.js} +0 -0
  316. /package/dist/ai/{utils → utilities}/systemGenerate.d.ts +0 -0
  317. /package/dist/ai/{utils → utilities}/systemGenerate.js +0 -0
  318. /package/dist/ui/Icons/{icons.module.css → icons.module.scss} +0 -0
  319. /package/dist/{endpoints → utilities}/buildPromptUtils.d.ts +0 -0
  320. /package/dist/utilities/{fieldToJsonSchema.d.ts → fields/fieldToJsonSchema.d.ts} +0 -0
  321. /package/dist/utilities/{fieldToJsonSchema.js → fields/fieldToJsonSchema.js} +0 -0
  322. /package/dist/utilities/{getFieldBySchemaPath.d.ts → fields/getFieldBySchemaPath.d.ts} +0 -0
  323. /package/dist/utilities/{getFieldBySchemaPath.js → fields/getFieldBySchemaPath.js} +0 -0
  324. /package/dist/utilities/{getFieldInfo.d.ts → fields/getFieldInfo.d.ts} +0 -0
  325. /package/dist/utilities/{getFieldInfo.js → fields/getFieldInfo.js} +0 -0
  326. /package/dist/utilities/{updateFieldsConfig.d.ts → fields/updateFieldsConfig.d.ts} +0 -0
  327. /package/dist/utilities/{extractImageData.d.ts → images/extractImageData.d.ts} +0 -0
  328. /package/dist/utilities/{extractImageData.js → images/extractImageData.js} +0 -0
  329. /package/dist/utilities/{extractPromptAttachments.d.ts → images/extractPromptAttachments.d.ts} +0 -0
  330. /package/dist/utilities/{extractPromptAttachments.js → images/extractPromptAttachments.js} +0 -0
  331. /package/dist/utilities/{resolveImageReferences.d.ts → images/resolveImageReferences.d.ts} +0 -0
  332. /package/dist/utilities/{editorSchemaValidator.d.ts → lexical/editorSchemaValidator.d.ts} +0 -0
  333. /package/dist/utilities/{editorSchemaValidator.js → lexical/editorSchemaValidator.js} +0 -0
  334. /package/dist/utilities/{lexicalToHTML.d.ts → lexical/lexicalToHTML.d.ts} +0 -0
  335. /package/dist/utilities/{lexicalToHTML.js → lexical/lexicalToHTML.js} +0 -0
  336. /package/dist/utilities/{setSafeLexicalState.d.ts → lexical/setSafeLexicalState.d.ts} +0 -0
  337. /package/dist/utilities/{setSafeLexicalState.js → lexical/setSafeLexicalState.js} +0 -0
@@ -0,0 +1,50 @@
1
+ export const lexicalToPromptTemplate = (editorState)=>{
2
+ if (!editorState || !editorState.root) {
3
+ return '';
4
+ }
5
+ const traverse = (node)=>{
6
+ if (node.type === 'text') {
7
+ return node.text || '';
8
+ }
9
+ if (node.type === 'beautifulMention') {
10
+ const mentionNode = node;
11
+ // Handle # (Field) -> {{value}}
12
+ if (mentionNode.trigger === '#') {
13
+ // If the value contains spaces or special chars, it might need brackets,
14
+ // but usually for Handlebars variable replacement we expect {{field_name}}
15
+ // The value from our endpoint is the full path e.g. "array.0.field"
16
+ // We assume the value is ready for handlebars.
17
+ return `{{${mentionNode.value}}}`;
18
+ }
19
+ // Handle @ (Image) -> @value
20
+ if (mentionNode.trigger === '@') {
21
+ return `@${mentionNode.value}`;
22
+ }
23
+ return mentionNode.value;
24
+ }
25
+ if (node.type === 'paragraph') {
26
+ const childrenContent = node.children?.map(traverse).join('') || '';
27
+ return childrenContent + '\n';
28
+ }
29
+ if (node.children) {
30
+ return node.children.map(traverse).join('');
31
+ }
32
+ return '';
33
+ };
34
+ const rawTemplate = (editorState.root.children || []).map(traverse).join('').trim();
35
+ // Post-process the template to fix nested handlebars syntax
36
+ // Example 1: `{{toHTML {{content}}}}` -> `{{toHTML content}}`
37
+ // Example 2: `{{#each {{array}}}}` -> `{{#each array}}`
38
+ // Matches any handlebar opening `{{` or `{{#` or `{{/` followed by anything, followed by `{{value}}`, followed by `}}`
39
+ // Actually, a simpler regex: replace `{{(` with `{{` is wrong.
40
+ // We want to replace `{{... {{value}} ...}}` with `{{... value ...}}`
41
+ // Regex to find `{{` inside another `{{` `}}` block is tricky.
42
+ // Instead, let's just globally replace `{{` and `}}` that are immediately inside another tag.
43
+ // Let's use a simpler heuristic: if a mention trigger `#` was used, it returned `{{value}}`.
44
+ // If the user typed `{{toHTML `, then inserted `#content`, then typed `}}`, the raw string is `{{toHTML {{content}}}}`.
45
+ // We can just replace `{{` and `}}` if they are surrounded by an outer bracket context.
46
+ // For safety, let's just fix the specific pattern of nested brackets for mentions.
47
+ return rawTemplate.replace(/({{[^{}]*?){{([^}]+)}}(.*?}})/g, '$1$2$3');
48
+ };
49
+
50
+ //# sourceMappingURL=lexicalToPromptTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utilities/lexical/lexicalToPromptTemplate.ts"],"sourcesContent":["import type { SerializedEditorState, SerializedLexicalNode } from 'lexical'\n\ninterface BeautifulMentionNode extends SerializedLexicalNode {\n trigger: string\n value: string\n data?: Record<string, unknown>\n}\n\nexport const lexicalToPromptTemplate = (editorState: SerializedEditorState | any): string => {\n if (!editorState || !editorState.root) {\n return ''\n }\n\n const traverse = (node: SerializedLexicalNode): string => {\n if (node.type === 'text') {\n return (node as any).text || ''\n }\n\n if (node.type === 'beautifulMention') {\n const mentionNode = node as BeautifulMentionNode\n // Handle # (Field) -> {{value}}\n if (mentionNode.trigger === '#') {\n // If the value contains spaces or special chars, it might need brackets,\n // but usually for Handlebars variable replacement we expect {{field_name}}\n // The value from our endpoint is the full path e.g. \"array.0.field\"\n // We assume the value is ready for handlebars.\n return `{{${mentionNode.value}}}`\n }\n // Handle @ (Image) -> @value\n if (mentionNode.trigger === '@') {\n return `@${mentionNode.value}`\n }\n return mentionNode.value\n }\n\n if (node.type === 'paragraph') {\n const childrenContent = (node as any).children?.map(traverse).join('') || ''\n return childrenContent + '\\n'\n }\n\n if ((node as any).children) {\n return (node as any).children.map(traverse).join('')\n }\n\n return ''\n }\n\n const rawTemplate = (editorState.root.children || []).map(traverse).join('').trim()\n \n // Post-process the template to fix nested handlebars syntax\n // Example 1: `{{toHTML {{content}}}}` -> `{{toHTML content}}`\n // Example 2: `{{#each {{array}}}}` -> `{{#each array}}`\n // Matches any handlebar opening `{{` or `{{#` or `{{/` followed by anything, followed by `{{value}}`, followed by `}}`\n // Actually, a simpler regex: replace `{{(` with `{{` is wrong.\n // We want to replace `{{... {{value}} ...}}` with `{{... value ...}}`\n // Regex to find `{{` inside another `{{` `}}` block is tricky.\n // Instead, let's just globally replace `{{` and `}}` that are immediately inside another tag.\n // Let's use a simpler heuristic: if a mention trigger `#` was used, it returned `{{value}}`.\n // If the user typed `{{toHTML `, then inserted `#content`, then typed `}}`, the raw string is `{{toHTML {{content}}}}`.\n // We can just replace `{{` and `}}` if they are surrounded by an outer bracket context.\n // For safety, let's just fix the specific pattern of nested brackets for mentions.\n return rawTemplate.replace(/({{[^{}]*?){{([^}]+)}}(.*?}})/g, '$1$2$3')\n}\n"],"names":["lexicalToPromptTemplate","editorState","root","traverse","node","type","text","mentionNode","trigger","value","childrenContent","children","map","join","rawTemplate","trim","replace"],"mappings":"AAQA,OAAO,MAAMA,0BAA0B,CAACC;IACtC,IAAI,CAACA,eAAe,CAACA,YAAYC,IAAI,EAAE;QACrC,OAAO;IACT;IAEA,MAAMC,WAAW,CAACC;QAChB,IAAIA,KAAKC,IAAI,KAAK,QAAQ;YACxB,OAAO,AAACD,KAAaE,IAAI,IAAI;QAC/B;QAEA,IAAIF,KAAKC,IAAI,KAAK,oBAAoB;YACpC,MAAME,cAAcH;YACpB,gCAAgC;YAChC,IAAIG,YAAYC,OAAO,KAAK,KAAK;gBAC7B,yEAAyE;gBACzE,2EAA2E;gBAC3E,oEAAoE;gBACpE,+CAA+C;gBAC/C,OAAO,CAAC,EAAE,EAAED,YAAYE,KAAK,CAAC,EAAE,CAAC;YACrC;YACA,6BAA6B;YAC7B,IAAIF,YAAYC,OAAO,KAAK,KAAK;gBAC7B,OAAO,CAAC,CAAC,EAAED,YAAYE,KAAK,CAAC,CAAC;YAClC;YACA,OAAOF,YAAYE,KAAK;QAC1B;QAEA,IAAIL,KAAKC,IAAI,KAAK,aAAa;YAC7B,MAAMK,kBAAkB,AAACN,KAAaO,QAAQ,EAAEC,IAAIT,UAAUU,KAAK,OAAO;YAC1E,OAAOH,kBAAkB;QAC3B;QAEA,IAAI,AAACN,KAAaO,QAAQ,EAAE;YAC1B,OAAO,AAACP,KAAaO,QAAQ,CAACC,GAAG,CAACT,UAAUU,IAAI,CAAC;QACnD;QAEA,OAAO;IACT;IAEA,MAAMC,cAAc,AAACb,CAAAA,YAAYC,IAAI,CAACS,QAAQ,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACT,UAAUU,IAAI,CAAC,IAAIE,IAAI;IAEjF,4DAA4D;IAC5D,8DAA8D;IAC9D,wDAAwD;IACxD,uHAAuH;IACvH,+DAA+D;IAC/D,sEAAsE;IACtE,+DAA+D;IAC/D,8FAA8F;IAC9F,6FAA6F;IAC7F,wHAAwH;IACxH,wFAAwF;IACxF,mFAAmF;IACnF,OAAOD,YAAYE,OAAO,CAAC,kCAAkC;AAC/D,EAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utilities/lexical/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,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,KAAKG,QAAQ,GAAGH,KAAKG,QAAQ,CAC1BC,GAAG,CAACL,cACJM,MAAM,CAAC,CAACC,QAAeA,UAAU;QACtC,OAAO;YACL,4EAA4E;YAC5E,oDAAoD;YACpD,gCAAgC;YAChC,0CAA0C;YAC1C,IAAI;gBAAC;gBAAW;gBAAQ;gBAAQ;gBAAY;gBAAa;gBAAS;aAAO,CAACC,QAAQ,CAACP,KAAKL,IAAI,GAAG;gBAC7FK,KAAKG,QAAQ,GAAGH,KAAKG,QAAQ,IAAI,EAAE;YACrC;QACF;QAEA,sBAAsB;QACtB,IAAIH,KAAKL,IAAI,KAAK,QAAQ;YACxB,iCAAiC;YACjC,IAAI,OAAOK,KAAKQ,IAAI,KAAK,UAAU;gBACjC,+CAA+C;gBAC/C,oDAAoD;gBACpD,wFAAwF;gBACxFR,KAAKQ,IAAI,GAAGR,KAAKQ,IAAI,IAAI;YAC3B;YACAR,KAAKS,IAAI,GAAGT,KAAKS,IAAI,IAAI;YACzBT,KAAKU,KAAK,GAAGV,KAAKU,KAAK,IAAI;YAC3BV,KAAKW,MAAM,GAAGX,KAAKW,MAAM,IAAI;QAC/B;QAEA,OAAOX;IACT;IAEA,8BAA8B;IAC9B,IAAIC,MAAMC,OAAO,CAACX,WAAWD,IAAI,CAACa,QAAQ,GAAG;QAC3CZ,WAAWD,IAAI,CAACa,QAAQ,GAAGZ,WAAWD,IAAI,CAACa,QAAQ,CAChDC,GAAG,CAACL,cACJM,MAAM,CAAC,CAACC,QAAeA,UAAU;IACtC,OAAO;QACLf,WAAWD,IAAI,CAACa,QAAQ,GAAG,EAAE;IAC/B;IAEA,OAAOZ;AACT;AAEA,OAAO,MAAMqB,sBAAsB,CAACvB,OAAgBwB;IAClD,IAAI;QACF,MAAMC,aAAa1B,qBAAqBC;QAExC,IAAI,CAACyB,YAAY;YACf;QACF;QAEA,MAAMC,cAAcF,eAAeG,gBAAgB,CAACF;QACpD,IAAIC,YAAYE,OAAO,IAAI;YACzB;QACF;QAEAJ,eAAeK,cAAc,CAACH;IAChC,EAAE,OAAOI,QAAQ;IACf,iEAAiE;IACjE,kEAAkE;IAClE,kEAAkE;IACpE;AACF,EAAC"}
@@ -0,0 +1,2 @@
1
+ import type { SerializedEditorState } from 'lexical';
2
+ export declare const stringToLexicalJSON: (text: string) => SerializedEditorState;
@@ -0,0 +1,39 @@
1
+ export const stringToLexicalJSON = (text)=>{
2
+ const rootChildren = [];
3
+ const lines = text.split('\n');
4
+ for (const line of lines){
5
+ const children = [];
6
+ if (line.length > 0) {
7
+ children.push({
8
+ detail: 0,
9
+ format: 0,
10
+ mode: 'normal',
11
+ style: '',
12
+ text: line,
13
+ type: 'text',
14
+ version: 1
15
+ });
16
+ }
17
+ rootChildren.push({
18
+ children,
19
+ direction: 'ltr',
20
+ format: '',
21
+ indent: 0,
22
+ type: 'paragraph',
23
+ version: 1,
24
+ textFormat: 0
25
+ });
26
+ }
27
+ return {
28
+ root: {
29
+ children: rootChildren,
30
+ direction: 'ltr',
31
+ format: '',
32
+ indent: 0,
33
+ type: 'root',
34
+ version: 1
35
+ }
36
+ };
37
+ };
38
+
39
+ //# sourceMappingURL=stringToLexicalJSON.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utilities/lexical/stringToLexicalJSON.ts"],"sourcesContent":["import type { SerializedEditorState, SerializedParagraphNode, SerializedTextNode } from 'lexical'\n\nexport const stringToLexicalJSON = (text: string): SerializedEditorState => {\n const rootChildren: SerializedParagraphNode[] = []\n\n const lines = text.split('\\n')\n\n for (const line of lines) {\n const children: SerializedTextNode[] = []\n if (line.length > 0) {\n children.push({\n detail: 0,\n format: 0,\n mode: 'normal',\n style: '',\n text: line,\n type: 'text',\n version: 1,\n })\n }\n\n rootChildren.push({\n children,\n direction: 'ltr',\n format: '',\n indent: 0,\n type: 'paragraph',\n version: 1,\n textFormat: 0, \n } as any)\n }\n\n return {\n root: {\n children: rootChildren,\n direction: 'ltr',\n format: '',\n indent: 0,\n type: 'root',\n version: 1,\n },\n }\n}\n"],"names":["stringToLexicalJSON","text","rootChildren","lines","split","line","children","length","push","detail","format","mode","style","type","version","direction","indent","textFormat","root"],"mappings":"AAEA,OAAO,MAAMA,sBAAsB,CAACC;IAClC,MAAMC,eAA0C,EAAE;IAElD,MAAMC,QAAQF,KAAKG,KAAK,CAAC;IAEzB,KAAK,MAAMC,QAAQF,MAAO;QACxB,MAAMG,WAAiC,EAAE;QACzC,IAAID,KAAKE,MAAM,GAAG,GAAG;YACnBD,SAASE,IAAI,CAAC;gBACZC,QAAQ;gBACRC,QAAQ;gBACRC,MAAM;gBACNC,OAAO;gBACPX,MAAMI;gBACNQ,MAAM;gBACNC,SAAS;YACX;QACF;QAEAZ,aAAaM,IAAI,CAAC;YAChBF;YACAS,WAAW;YACXL,QAAQ;YACRM,QAAQ;YACRH,MAAM;YACNC,SAAS;YACTG,YAAY;QACd;IACF;IAEA,OAAO;QACLC,MAAM;YACJZ,UAAUJ;YACVa,WAAW;YACXL,QAAQ;YACRM,QAAQ;YACRH,MAAM;YACNC,SAAS;QACX;IACF;AACF,EAAC"}
@@ -0,0 +1 @@
1
+ export declare const sanitizeLog: (obj: any) => any;
@@ -0,0 +1,39 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ export const sanitizeLog = (obj)=>{
3
+ if (!obj) {
4
+ return obj;
5
+ }
6
+ // Truncate large string data
7
+ if (typeof obj === 'string') {
8
+ return obj.length > 500 ? `${obj.substring(0, 500)}... [truncated ${obj.length - 500} chars]` : obj;
9
+ }
10
+ // Omit buffer/binary data to prevent huge output
11
+ if (typeof Buffer !== 'undefined' && Buffer.isBuffer(obj) || obj instanceof ArrayBuffer || typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView(obj)) {
12
+ return '[Buffer/Binary omitted for logs]';
13
+ }
14
+ // Recurse arrays
15
+ if (Array.isArray(obj)) {
16
+ return obj.map((item)=>sanitizeLog(item));
17
+ }
18
+ // Clone and recurse objects
19
+ if (typeof obj === 'object') {
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ const serialized = {};
22
+ for(const key in obj){
23
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
24
+ // Explicitly catch AI SDK objects or large image representations
25
+ if (key === 'base64' || key === 'base64Data' || key === 'uint8Array' || key === 'data') {
26
+ if (typeof obj[key] === 'string' && obj[key].length > 500) {
27
+ serialized[key] = '[Base64 omitted for logs]';
28
+ continue;
29
+ }
30
+ }
31
+ serialized[key] = sanitizeLog(obj[key]);
32
+ }
33
+ }
34
+ return serialized;
35
+ }
36
+ return obj;
37
+ };
38
+
39
+ //# sourceMappingURL=sanitizeLog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/sanitizeLog.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const sanitizeLog = (obj: any): any => {\n if (!obj) {\n return obj\n }\n \n // Truncate large string data\n if (typeof obj === 'string') {\n return obj.length > 500\n ? `${obj.substring(0, 500)}... [truncated ${obj.length - 500} chars]`\n : obj\n }\n \n // Omit buffer/binary data to prevent huge output\n if (\n typeof Buffer !== 'undefined' && Buffer.isBuffer(obj) ||\n obj instanceof ArrayBuffer ||\n (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView(obj))\n ) {\n return '[Buffer/Binary omitted for logs]'\n }\n \n // Recurse arrays\n if (Array.isArray(obj)) {\n return obj.map((item) => sanitizeLog(item))\n }\n \n // Clone and recurse objects\n if (typeof obj === 'object') {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const serialized: Record<string, any> = {}\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n // Explicitly catch AI SDK objects or large image representations\n if (key === 'base64' || key === 'base64Data' || key === 'uint8Array' || key === 'data') {\n if (typeof obj[key] === 'string' && obj[key].length > 500) {\n serialized[key] = '[Base64 omitted for logs]'\n continue\n }\n }\n serialized[key] = sanitizeLog(obj[key])\n }\n }\n return serialized\n }\n \n return obj\n}\n"],"names":["sanitizeLog","obj","length","substring","Buffer","isBuffer","ArrayBuffer","isView","Array","isArray","map","item","serialized","key","Object","prototype","hasOwnProperty","call"],"mappings":"AAAA,8DAA8D;AAC9D,OAAO,MAAMA,cAAc,CAACC;IAC1B,IAAI,CAACA,KAAK;QACR,OAAOA;IACT;IAEA,6BAA6B;IAC7B,IAAI,OAAOA,QAAQ,UAAU;QAC3B,OAAOA,IAAIC,MAAM,GAAG,MAChB,CAAC,EAAED,IAAIE,SAAS,CAAC,GAAG,KAAK,eAAe,EAAEF,IAAIC,MAAM,GAAG,IAAI,OAAO,CAAC,GACnED;IACN;IAEA,iDAAiD;IACjD,IACE,OAAOG,WAAW,eAAeA,OAAOC,QAAQ,CAACJ,QACjDA,eAAeK,eACd,OAAOA,gBAAgB,eAAeA,YAAYC,MAAM,CAACN,MAC1D;QACA,OAAO;IACT;IAEA,iBAAiB;IACjB,IAAIO,MAAMC,OAAO,CAACR,MAAM;QACtB,OAAOA,IAAIS,GAAG,CAAC,CAACC,OAASX,YAAYW;IACvC;IAEA,4BAA4B;IAC5B,IAAI,OAAOV,QAAQ,UAAU;QAC3B,8DAA8D;QAC9D,MAAMW,aAAkC,CAAC;QACzC,IAAK,MAAMC,OAAOZ,IAAK;YACrB,IAAIa,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAAChB,KAAKY,MAAM;gBAClD,iEAAiE;gBACjE,IAAIA,QAAQ,YAAYA,QAAQ,gBAAgBA,QAAQ,gBAAgBA,QAAQ,QAAQ;oBACtF,IAAI,OAAOZ,GAAG,CAACY,IAAI,KAAK,YAAYZ,GAAG,CAACY,IAAI,CAACX,MAAM,GAAG,KAAK;wBACzDU,UAAU,CAACC,IAAI,GAAG;wBAClB;oBACF;gBACF;gBACAD,UAAU,CAACC,IAAI,GAAGb,YAAYC,GAAG,CAACY,IAAI;YACxC;QACF;QACA,OAAOD;IACT;IAEA,OAAOX;AACT,EAAC"}
@@ -1,5 +1,6 @@
1
1
  import { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js';
2
- import { updateFieldsConfig } from './updateFieldsConfig.js';
2
+ import { updateFieldsConfig } from './fields/updateFieldsConfig.js';
3
+ import { stringToLexicalJSON } from './lexical/stringToLexicalJSON.js';
3
4
  export const seedProperties = async ({ enabledCollections, req })=>{
4
5
  const { payload } = req;
5
6
  if (!enabledCollections || enabledCollections.length === 0) {
@@ -16,7 +17,11 @@ export const seedProperties = async ({ enabledCollections, req })=>{
16
17
  // Use the side-effect of getting schemaPathMap from it
17
18
  const { schemaPathMap } = updateFieldsConfig(collectionConfig);
18
19
  for (const [schemaPath, fieldInfo] of Object.entries(schemaPathMap)){
19
- const { type, custom, relationTo } = fieldInfo;
20
+ const typedFieldInfo = fieldInfo;
21
+ const custom = typedFieldInfo.custom;
22
+ const hasMany = typedFieldInfo.hasMany;
23
+ const relationTo = typedFieldInfo.relationTo;
24
+ const type = typedFieldInfo.type;
20
25
  // Check if instruction already exists
21
26
  const existingInstruction = await payload.find({
22
27
  collection: PLUGIN_INSTRUCTIONS_TABLE,
@@ -30,39 +35,47 @@ export const seedProperties = async ({ enabledCollections, req })=>{
30
35
  }
31
36
  });
32
37
  if (existingInstruction.totalDocs > 0) {
38
+ const doc = existingInstruction.docs[0];
39
+ const currentPrompt = doc.prompt;
40
+ const currentSystem = doc.system;
41
+ let needsUpdate = false;
42
+ const updateData = {};
43
+ if (!!doc.hasMany !== !!hasMany) {
44
+ updateData.hasMany = !!hasMany;
45
+ needsUpdate = true;
46
+ }
33
47
  // If developer has provided custom prompts in the schema, update the existing record
34
48
  // but only if the values have actually changed.
35
- if (custom?.ai?.prompt || custom?.ai?.system) {
36
- const doc = existingInstruction.docs[0];
37
- const currentPrompt = doc.prompt;
38
- const currentSystem = doc.system;
39
- let needsUpdate = false;
40
- const updateData = {};
49
+ if (custom?.ai?.prompt || custom?.ai?.system || custom?.ai?.alwaysShow !== undefined) {
41
50
  if (custom?.ai?.prompt && custom.ai.prompt !== currentPrompt) {
42
- updateData.prompt = custom.ai.prompt;
51
+ updateData.prompt = stringToLexicalJSON(custom.ai.prompt);
43
52
  needsUpdate = true;
44
53
  }
45
54
  if (custom?.ai?.system && custom.ai.system !== currentSystem) {
46
55
  updateData.system = custom.ai.system;
47
56
  needsUpdate = true;
48
57
  }
49
- if (needsUpdate) {
50
- try {
51
- await payload.update({
52
- id: doc.id,
53
- collection: PLUGIN_INSTRUCTIONS_TABLE,
54
- data: updateData,
55
- overrideAccess: true
56
- });
57
- } catch (error) {
58
- payload.logger.error(`Failed to update instruction for ${schemaPath}: ${error}`);
59
- }
58
+ if (custom?.ai?.alwaysShow !== undefined && custom.ai.alwaysShow !== doc.alwaysShow) {
59
+ updateData.alwaysShow = !!custom.ai.alwaysShow;
60
+ needsUpdate = true;
61
+ }
62
+ }
63
+ if (needsUpdate) {
64
+ try {
65
+ await payload.update({
66
+ id: doc.id,
67
+ collection: PLUGIN_INSTRUCTIONS_TABLE,
68
+ data: updateData,
69
+ overrideAccess: true
70
+ });
71
+ } catch (error) {
72
+ payload.logger.error(`— AI Plugin: Failed to update instruction for ${schemaPath}: ${error}`);
60
73
  }
61
74
  }
62
75
  continue;
63
76
  }
64
77
  // Use custom prompts if provided, otherwise leave empty
65
- const prompt = custom?.ai?.prompt || '';
78
+ const prompt = custom?.ai?.prompt ? stringToLexicalJSON(custom.ai.prompt) : undefined;
66
79
  const system = custom?.ai?.system || '';
67
80
  // Determine model-id based on field type
68
81
  let modelId = 'text';
@@ -80,8 +93,10 @@ export const seedProperties = async ({ enabledCollections, req })=>{
80
93
  await payload.create({
81
94
  collection: PLUGIN_INSTRUCTIONS_TABLE,
82
95
  data: {
96
+ alwaysShow: !!custom?.ai?.alwaysShow,
83
97
  disabled: false,
84
98
  'field-type': type,
99
+ hasMany: !!hasMany,
85
100
  'model-id': modelId,
86
101
  prompt,
87
102
  'relation-to': relationTo,
@@ -91,7 +106,7 @@ export const seedProperties = async ({ enabledCollections, req })=>{
91
106
  overrideAccess: true
92
107
  });
93
108
  } catch (error) {
94
- payload.logger.error(`Failed to seed instruction for ${schemaPath}: ${error}`);
109
+ payload.logger.error(`— AI Plugin: Failed to seed instruction for ${schemaPath}: ${error}`);
95
110
  }
96
111
  }
97
112
  }
@@ -1 +1 @@
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,IA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QuC,MAAM,CAACD,KAAK,CAAC,CAAC,iCAAiC,EAAE3B,WAAW,EAAE,EAAE2B,MAAM,CAAC;wBACjF;oBACF;gBACF;gBACA;YACF;YAEA,wDAAwD;YACxD,MAAMX,SAASX,QAAQU,IAAIC,UAAU;YACrC,MAAMC,SAASZ,QAAQU,IAAIE,UAAU;YAErC,yCAAyC;YACzC,IAAIY,UAAU;YACd,IAAIzB,SAAS,YAAY;gBACvByB,UAAU;YACZ;YACA,IAAIzB,SAAS,UAAU;gBACrByB,UAAU;YACZ,EAAE,6CAA6C;YAC/C,IAAIzB,SAAS,SAAS;gBACpByB,UAAU;YACZ;YAEA,yBAAyB;YACzB,IAAI;gBACF,MAAMxC,QAAQyC,MAAM,CAAC;oBACnBtB,YAAYxB;oBACZ0C,MAAM;wBACJK,UAAU;wBACV,cAAc3B;wBACd,YAAYyB;wBACZb;wBACA,eAAeV;wBACf,eAAeN;wBACfiB;oBACF;oBACAN,gBAAgB;gBAClB;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"}
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 './fields/updateFieldsConfig.js'\nimport { stringToLexicalJSON } from './lexical/stringToLexicalJSON.js'\ninterface SeedPropertiesArgs {\n enabledCollections: string[]\n req: PayloadRequest\n}\n\ninterface SchemaPathFieldInfo {\n custom?: { ai?: { alwaysShow?: boolean; prompt?: string; system?: string } }\n hasMany?: boolean\n relationTo?: string\n type: string\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 typedFieldInfo = fieldInfo as SchemaPathFieldInfo\n const custom = typedFieldInfo.custom\n const hasMany = typedFieldInfo.hasMany\n const relationTo = typedFieldInfo.relationTo\n const type = typedFieldInfo.type\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 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 (!!doc.hasMany !== !!hasMany) {\n updateData.hasMany = !!hasMany\n needsUpdate = true\n }\n\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 || custom?.ai?.alwaysShow !== undefined) {\n if (custom?.ai?.prompt && custom.ai.prompt !== currentPrompt) {\n updateData.prompt = stringToLexicalJSON(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 if (custom?.ai?.alwaysShow !== undefined && custom.ai.alwaysShow !== doc.alwaysShow) {\n updateData.alwaysShow = !!custom.ai.alwaysShow\n needsUpdate = true\n }\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(`— AI Plugin: Failed to update instruction for ${schemaPath}: ${error}`)\n }\n }\n continue\n }\n\n // Use custom prompts if provided, otherwise leave empty\n const prompt = custom?.ai?.prompt ? stringToLexicalJSON(custom.ai.prompt) : undefined\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 alwaysShow: !!custom?.ai?.alwaysShow,\n disabled: false,\n 'field-type': type,\n hasMany: !!hasMany,\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(`— AI Plugin: Failed to seed instruction for ${schemaPath}: ${error}`)\n }\n }\n }\n}\n"],"names":["PLUGIN_INSTRUCTIONS_TABLE","updateFieldsConfig","stringToLexicalJSON","seedProperties","enabledCollections","req","payload","length","allCollections","config","collections","collectionSlug","collectionConfig","find","c","slug","schemaPathMap","schemaPath","fieldInfo","Object","entries","typedFieldInfo","custom","hasMany","relationTo","type","existingInstruction","collection","depth","limit","overrideAccess","where","equals","totalDocs","doc","docs","currentPrompt","prompt","currentSystem","system","needsUpdate","updateData","ai","alwaysShow","undefined","update","id","data","error","logger","modelId","create","disabled"],"mappings":"AAEA,SAASA,yBAAyB,QAAQ,iBAAgB;AAC1D,SAASC,kBAAkB,QAAQ,iCAAgC;AACnE,SAASC,mBAAmB,QAAQ,mCAAkC;AAatE,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,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CAAC,CAACA;wBACX,YAAY2B;wBACZb;wBACA,eAAeb;wBACf,eAAeP;wBACfsB;oBACF;oBACAT,gBAAgB;gBAClB;YACF,EAAE,OAAOkB,OAAO;gBACd1C,QAAQ2C,MAAM,CAACD,KAAK,CAAC,CAAC,4CAA4C,EAAE/B,WAAW,EAAE,EAAE+B,MAAM,CAAC;YAC5F;QACF;IACF;AACF,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-stack/payloadcms",
3
- "version": "3.76.0-beta.1",
3
+ "version": "3.76.0-beta.2",
4
4
  "private": false,
5
5
  "bugs": "https://github.com/ashbuilds/payload-ai/issues",
6
6
  "repository": "https://github.com/ashbuilds/payload-ai",
@@ -130,6 +130,7 @@
130
130
  },
131
131
  "peerDependencies": {
132
132
  "@lexical/html": "^0.35.0",
133
+ "@lexical/react": "^0.35.0",
133
134
  "@payloadcms/richtext-lexical": "^3.55.1",
134
135
  "@payloadcms/translations": "^3.55.1",
135
136
  "@payloadcms/ui": "^3.55.1",
@@ -193,6 +194,7 @@
193
194
  "@anthropic-ai/sdk": "^0.62.0",
194
195
  "@fal-ai/client": "^1.7.0",
195
196
  "@google/genai": "^1.30.0",
197
+ "@payloadcms/live-preview-react": "3.76.0",
196
198
  "ai": "^5.0.104",
197
199
  "ajv": "^8.17.1",
198
200
  "elevenlabs": "^0.8.2",
@@ -205,6 +207,7 @@
205
207
  "react-mentions": "^4.4.10",
206
208
  "scroll-into-view-if-needed": "^3.1.0",
207
209
  "textarea-caret": "^3.0.2",
208
- "zod": "^4.1.7"
210
+ "zod": "^4.1.7",
211
+ "lexical-beautiful-mentions": "^0.1.48"
209
212
  }
210
213
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- // Coming soon...
2
-
3
- //# sourceMappingURL=analyse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/ai/analyse.ts"],"sourcesContent":["// Coming soon...\n"],"names":[],"mappings":"AAAA,iBAAiB"}
@@ -1,11 +0,0 @@
1
- import type { Field, Payload } from 'payload';
2
- export type GenerateArgs = {
3
- mode?: 'auto' | 'json' | 'tool';
4
- model?: string;
5
- payload: Payload;
6
- prompt: string;
7
- provider?: string;
8
- schema?: Field[];
9
- system?: string;
10
- };
11
- export declare function generate(args: GenerateArgs): Promise<import("ai").GenerateObjectResult<Record<string, unknown>> | import("ai").GenerateTextResult<import("ai").ToolSet, never>>;
package/dist/ai/index.js DELETED
@@ -1,25 +0,0 @@
1
- import { generateObject, generateText } from 'ai';
2
- import { convertPayloadSchemaToZod } from '../utilities/schemaConverter.js';
3
- import { getLanguageModel } from './providers/registry.js';
4
- // Use in payload.ai that is injected during payload init. // this will always be non-streaming function, generateText, generateObject, Images etc
5
- export async function generate(args) {
6
- const { mode, model, payload, prompt, provider, schema, system } = args;
7
- const languageModel = await getLanguageModel(payload, provider, model);
8
- if (schema) {
9
- const zodSchema = convertPayloadSchemaToZod(schema);
10
- return generateObject({
11
- mode: mode || 'auto',
12
- model: languageModel,
13
- prompt,
14
- schema: zodSchema,
15
- system
16
- });
17
- }
18
- return generateText({
19
- model: languageModel,
20
- prompt,
21
- system
22
- });
23
- }
24
-
25
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/ai/index.ts"],"sourcesContent":["import type { Field, Payload } from 'payload'\n\nimport { generateObject, generateText } from 'ai'\n\nimport { convertPayloadSchemaToZod } from '../utilities/schemaConverter.js'\nimport { getLanguageModel } from './providers/registry.js'\n\nexport type GenerateArgs = {\n mode?: 'auto' | 'json' | 'tool'\n model?: string\n payload: Payload\n prompt: string\n provider?: string\n schema?: Field[]\n system?: string\n}\n\n// Use in payload.ai that is injected during payload init. // this will always be non-streaming function, generateText, generateObject, Images etc\nexport async function generate(args: GenerateArgs) {\n const { mode, model, payload, prompt, provider, schema, system } = args\n\n const languageModel = await getLanguageModel(payload, provider, model)\n\n if (schema) {\n const zodSchema = convertPayloadSchemaToZod(schema)\n return generateObject({\n mode: mode || 'auto',\n model: languageModel,\n prompt,\n schema: zodSchema,\n system,\n })\n }\n\n return generateText({\n model: languageModel,\n prompt,\n system,\n })\n}\n"],"names":["generateObject","generateText","convertPayloadSchemaToZod","getLanguageModel","generate","args","mode","model","payload","prompt","provider","schema","system","languageModel","zodSchema"],"mappings":"AAEA,SAASA,cAAc,EAAEC,YAAY,QAAQ,KAAI;AAEjD,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,gBAAgB,QAAQ,0BAAyB;AAY1D,kJAAkJ;AAClJ,OAAO,eAAeC,SAASC,IAAkB;IAC/C,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAGP;IAEnE,MAAMQ,gBAAgB,MAAMV,iBAAiBK,SAASE,UAAUH;IAEhE,IAAII,QAAQ;QACV,MAAMG,YAAYZ,0BAA0BS;QAC5C,OAAOX,eAAe;YACpBM,MAAMA,QAAQ;YACdC,OAAOM;YACPJ;YACAE,QAAQG;YACRF;QACF;IACF;IAEA,OAAOX,aAAa;QAClBM,OAAOM;QACPJ;QACAG;IACF;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/ai/prompts.ts"],"sourcesContent":["import type { ActionPrompt } from '../types.js'\n\n//TODO: This is a temporary solution make use of structured output\nexport const defaultSystemPrompt = `IMPORTANT INSTRUCTION:\nProduce only the requested output text.\nDo not add any explanations, comments, or engagement.\nDo not use quotation marks in the response.\nBEGIN OUTPUT:`\n\nexport const defaultPrompts: ActionPrompt[] = [\n {\n name: 'Rephrase',\n system: ({\n prompt = '',\n systemPrompt = '',\n }) => `You are a skilled language expert. Rephrase the given text while maintaining its original meaning, tone, and emotional content. Use different words and sentence structures where possible, but preserve the overall style and sentiment of the original.\n \n -------------\n INSTRUCTIONS:\n - Rephrase the text according to the guidelines of the ORIGINAL SYSTEM PROMPT, if provided.\n - Retain the original meaning, tone, and emotional content.\n - Use different vocabulary and sentence structures where appropriate.\n - Ensure the rephrased text conveys the same message and feeling as the original.\n ${prompt ? '\\n\\nPrevious prompt:\\n' + prompt : ''}\n ${systemPrompt ? '\\n\\nORIGINAL SYSTEM PROMPT:\\n' + systemPrompt : ''}\n -------------`,\n },\n {\n name: 'Expand',\n system:\n () => `You are a creative writer and subject matter expert. Expand the given text by adding depth, detail, and relevant information while maintaining the original tone and style.\n \n -------------\n INSTRUCTIONS:\n - Understand the main ideas and tone of the text.\n - Add more details, examples, explanations, or context.\n - Maintain the original tone, style, and intent.\n - Ensure the expanded version flows naturally and coherently.\n - Do not contradict or alter the original meaning.\n -------------`,\n },\n {\n name: 'Proofread',\n system:\n () => `You are an English language expert. Proofread the given text, focusing on correcting grammar and spelling mistakes without altering the content, style, or tone.\n \n -------------\n INSTRUCTIONS:\n - Correct grammar and spelling errors.\n - Do not change the content, meaning, tone, or style.\n - Return the full text, whether corrections were made or not.\n - Do not provide additional comments or analysis.\n -------------`,\n },\n {\n name: 'Simplify',\n system: ({\n prompt = '',\n }) => `You are a skilled communicator specializing in clear and concise writing. Simplify the given text to make it easier to understand while retaining its core message.\n \n -------------\n INSTRUCTIONS:\n - Simplify the language, using more common words and shorter sentences.\n - Remove unnecessary details or jargon while keeping essential information.\n - Maintain the original meaning and key points.\n - Aim for clarity and readability for a general audience.\n - The simplified text should be more concise than the original.\n ${prompt ? '\\n\\nPREVIOUS PROMPT:\\n' + prompt : ''}\n -------------`,\n },\n {\n name: 'Summarize',\n layout: () => `\n[heading] - Summary\n[paragraph] - Your summary goes here...\n `,\n system: () =>\n `You are an expert at summarizing information. Your task is to create a concise summary of the given text that captures its key points and essential details while preserving the original meaning.\n\nINSTRUCTIONS:\n1. Carefully read and analyze the provided text.\n2. Identify and extract the main ideas and crucial supporting details.\n3. Condense the information into a clear and coherent summary that maintains the core message.\n4. Preserve the original tone and intent of the text.\n5. Ensure your summary is approximately 25-30% of the original text length.\n6. Use clear and precise language, avoiding unnecessary jargon or complexity.\n`,\n },\n {\n name: 'Tone',\n system: () =>\n `You are a tone adjustment specialist. Modify the tone of the given text as specified while keeping the original message and content intact.\n \n -------------\n INSTRUCTIONS:\n - Adjust the tone to match the specified style (e.g., formal, informal, professional, friendly).\n - Maintain the original content and meaning.\n - Ensure the adjusted text flows naturally with the new tone.\n -------------`,\n },\n {\n name: 'Translate',\n system: ({ locale, prompt = '', systemPrompt = '' }) =>\n `You are a skilled translator. Translate the following text into ${locale}, ensuring the original meaning, tone, and context are preserved.\n \n -------------\n INSTRUCTIONS:\n - Accurately translate the text into ${locale}.\n - Preserve the original meaning, tone, and context.\n - Ensure the translation is culturally appropriate and natural in the target language.\n ${prompt ? '\\n\\nPREVIOUS PROMPT:\\n' + prompt : ''}\n ${systemPrompt ? '\\n\\nORIGINAL SYSTEM PROMPT:\\n' + systemPrompt : ''}\n -------------`,\n },\n]\n"],"names":["defaultSystemPrompt","defaultPrompts","name","system","prompt","systemPrompt","layout","locale"],"mappings":"AAEA,kEAAkE;AAClE,OAAO,MAAMA,sBAAsB,CAAC;;;;aAIvB,CAAC,CAAA;AAEd,OAAO,MAAMC,iBAAiC;IAC5C;QACEC,MAAM;QACNC,QAAQ,CAAC,EACPC,SAAS,EAAE,EACXC,eAAe,EAAE,EAClB,GAAK,CAAC;;;;;;;;MAQL,EAAED,SAAS,2BAA2BA,SAAS,GAAG;MAClD,EAAEC,eAAe,kCAAkCA,eAAe,GAAG;mBACxD,CAAC;IAClB;IACA;QACEH,MAAM;QACNC,QACE,IAAM,CAAC;;;;;;;;;mBASM,CAAC;IAClB;IACA;QACED,MAAM;QACNC,QACE,IAAM,CAAC;;;;;;;;mBAQM,CAAC;IAClB;IACA;QACED,MAAM;QACNC,QAAQ,CAAC,EACPC,SAAS,EAAE,EACZ,GAAK,CAAC;;;;;;;;;MASL,EAAEA,SAAS,2BAA2BA,SAAS,GAAG;mBACrC,CAAC;IAClB;IACA;QACEF,MAAM;QACNI,QAAQ,IAAM,CAAC;;;IAGf,CAAC;QACDH,QAAQ,IACN,CAAC;;;;;;;;;AASP,CAAC;IACC;IACA;QACED,MAAM;QACNC,QAAQ,IACN,CAAC;;;;;;;mBAOY,CAAC;IAClB;IACA;QACED,MAAM;QACNC,QAAQ,CAAC,EAAEI,MAAM,EAAEH,SAAS,EAAE,EAAEC,eAAe,EAAE,EAAE,GACjD,CAAC,gEAAgE,EAAEE,OAAO;;;;yCAIvC,EAAEA,OAAO;;;IAG9C,EAAEH,SAAS,2BAA2BA,SAAS,GAAG;IAClD,EAAEC,eAAe,kCAAkCA,eAAe,GAAG;iBACxD,CAAC;IAChB;CACD,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/ai/utils/filterEditorSchemaByNodes.ts"],"sourcesContent":["import type { LexicalNodeSchema } from '../schemas/lexicalJsonSchema.js'\n\nimport { isObjectSchema } from './isObjectSchema.js'\nimport { coreNodeTypes, nodeClassToType, nodeTypeToSchemaMap } from './nodeToSchemaMap.js'\n\n/**\n * Filters the Lexical JSON schema to only include definitions for allowed nodes.\n *\n * @param schema - The full Lexical JSON schema\n * @param allowedNodes - Array of allowed node types. Can be either:\n * - Node class names (e.g., 'HeadingNode', 'ParagraphNode')\n * - Type values (e.g., 'heading', 'paragraph')\n * @returns A filtered schema containing only the allowed definitions\n */\nexport function filterEditorSchemaByNodes(schema: LexicalNodeSchema, allowedNodes: string[]) {\n // Normalize node names to lowercase type values\n const normalizedTypes = new Set<string>()\n\n // Always include core nodes\n for (const coreType of coreNodeTypes) {\n normalizedTypes.add(coreType)\n }\n\n // Add user-specified allowed nodes\n for (const node of allowedNodes) {\n // Handle both formats: 'HeadingNode' and 'heading'\n const normalized = node.includes('Node') ? nodeClassToType(node) : node.toLowerCase()\n normalizedTypes.add(normalized)\n }\n\n const filteredDefinitions: Record<string, any> = {}\n\n // First pass: collect definitions whose \"type.enum\" includes an allowed type\n for (const [key, def] of Object.entries(schema.definitions ?? {})) {\n if (isObjectSchema(def)) {\n const typeEnum = def.properties?.type?.enum\n if (typeEnum && typeEnum.some((t) => normalizedTypes.has(t))) {\n filteredDefinitions[key] = JSON.parse(JSON.stringify(def)) // Deep copy to safely mutate\n }\n }\n }\n\n // Ensure core schema definitions are included by checking the map\n for (const coreType of coreNodeTypes) {\n const defName = nodeTypeToSchemaMap[coreType]\n if (defName && schema.definitions?.[defName] && !filteredDefinitions[defName]) {\n filteredDefinitions[defName] = JSON.parse(JSON.stringify(schema.definitions[defName]))\n }\n }\n\n // Helper to check if a $ref points to an allowed definition\n const isAllowedRef = (ref: string) => {\n if (typeof ref !== 'string') {\n return false\n }\n const defName = ref.replace('#/definitions/', '')\n return defName in filteredDefinitions\n }\n\n // Second pass: update \"children\" in each definition to only include allowed refs\n for (const def of Object.values(filteredDefinitions)) {\n if (isObjectSchema(def) && def.properties?.children?.items) {\n const items = def.properties.children.items\n\n if (Array.isArray(items.anyOf)) {\n // Filter anyOf to only allowed $refs\n items.anyOf = items.anyOf.filter((entry) => isAllowedRef(entry.$ref))\n if (items.anyOf.length === 0) {\n delete def.properties.children\n }\n } else if (items.$ref && !isAllowedRef(items.$ref)) {\n delete def.properties.children\n }\n }\n }\n\n // Return the new schema with pruned definitions\n return {\n ...schema,\n definitions: filteredDefinitions,\n }\n}\n"],"names":["isObjectSchema","coreNodeTypes","nodeClassToType","nodeTypeToSchemaMap","filterEditorSchemaByNodes","schema","allowedNodes","normalizedTypes","Set","coreType","add","node","normalized","includes","toLowerCase","filteredDefinitions","key","def","Object","entries","definitions","typeEnum","properties","type","enum","some","t","has","JSON","parse","stringify","defName","isAllowedRef","ref","replace","values","children","items","Array","isArray","anyOf","filter","entry","$ref","length"],"mappings":"AAEA,SAASA,cAAc,QAAQ,sBAAqB;AACpD,SAASC,aAAa,EAAEC,eAAe,EAAEC,mBAAmB,QAAQ,uBAAsB;AAE1F;;;;;;;;CAQC,GACD,OAAO,SAASC,0BAA0BC,MAAyB,EAAEC,YAAsB;IACzF,gDAAgD;I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sB;QACpD,IAAIf,eAAeiB,QAAQA,IAAIK,UAAU,EAAEc,UAAUC,OAAO;YAC1D,MAAMA,QAAQpB,IAAIK,UAAU,CAACc,QAAQ,CAACC,KAAK;YAE3C,IAAIC,MAAMC,OAAO,CAACF,MAAMG,KAAK,GAAG;gBAC9B,qCAAqC;gBACrCH,MAAMG,KAAK,GAAGH,MAAMG,KAAK,CAACC,MAAM,CAAC,CAACC,QAAUV,aAAaU,MAAMC,IAAI;gBACnE,IAAIN,MAAMG,KAAK,CAACI,MAAM,KAAK,GAAG;oBAC5B,OAAO3B,IAAIK,UAAU,CAACc,QAAQ;gBAChC;YACF,OAAO,IAAIC,MAAMM,IAAI,IAAI,CAACX,aAAaK,MAAMM,IAAI,GAAG;gBAClD,OAAO1B,IAAIK,UAAU,CAACc,QAAQ;YAChC;QACF;IACF;IAEA,gDAAgD;IAChD,OAAO;QACL,GAAG/B,MAAM;QACTe,aAAaL;IACf;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/ai/utils/generateFileNameByPrompt.ts"],"sourcesContent":["export function generateFileNameByPrompt(prompt: string) {\n // Helper function to get a random integer between min and max (inclusive)\n function getRandomInt(min: number, max: number) {\n return Math.floor(Math.random() * (max - min + 1)) + min\n }\n\n // Define the desired length of the filename part from the prompt\n const maxLength = 30\n const promptLength = prompt.length\n\n // Determine the start position for the random substring\n const startPos = getRandomInt(0, Math.max(0, promptLength - maxLength))\n\n // Get the random substring and truncate it if necessary\n let randomSubstring = prompt.substring(startPos, startPos + maxLength)\n\n // Replace invalid filename characters with an underscore\n randomSubstring = randomSubstring.replace(/[^a-z\\d]/gi, '_').toLowerCase()\n\n // Add a timestamp for uniqueness\n const timestamp = new Date().toISOString().replace(/[:.-]/g, '')\n\n // Combine the truncated prompt and timestamp to form the filename\n return `${randomSubstring}_${timestamp}`\n}\n"],"names":["generateFileNameByPrompt","prompt","getRandomInt","min","max","Math","floor","random","maxLength","promptLength","length","startPos","randomSubstring","substring","replace","toLowerCase","timestamp","Date","toISOString"],"mappings":"AAAA,OAAO,SAASA,yBAAyBC,MAAc;IACrD,0EAA0E;IAC1E,SAASC,aAAaC,GAAW,EAAEC,GAAW;QAC5C,OAAOC,KAAKC,KAAK,CAACD,KAAKE,MAAM,KAAMH,CAAAA,MAAMD,MAAM,CAAA,KAAMA;IACvD;IAEA,iEAAiE;IACjE,MAAMK,YAAY;IAClB,MAAMC,eAAeR,OAAOS,MAAM;IAElC,wDAAwD;IACxD,MAAMC,WAAWT,aAAa,GAAGG,KAAKD,GAAG,CAAC,GAAGK,eAAeD;IAE5D,wDAAwD;IACxD,IAAII,kBAAkBX,OAAOY,SAAS,CAACF,UAAUA,WAAWH;IAE5D,yDAAyD;IACzDI,kBAAkBA,gBAAgBE,OAAO,CAAC,cAAc,KAAKC,WAAW;IAExE,iCAAiC;IACjC,MAAMC,YAAY,IAAIC,OAAOC,WAAW,GAAGJ,OAAO,CAAC,UAAU;IAE7D,kEAAkE;IAClE,OAAO,CAAC,EAAEF,gBAAgB,CAAC,EAAEI,UAAU,CAAC;AAC1C"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/ai/utils/isObjectSchema.ts"],"sourcesContent":["import type { LexicalNodeSchema } from '../schemas/lexicalJsonSchema.js'\n\nexport function isObjectSchema(schema: unknown): schema is LexicalNodeSchema {\n return typeof schema === 'object' && schema !== null && !Array.isArray(schema)\n}\n"],"names":["isObjectSchema","schema","Array","isArray"],"mappings":"AAEA,OAAO,SAASA,eAAeC,MAAe;IAC5C,OAAO,OAAOA,WAAW,YAAYA,WAAW,QAAQ,CAACC,MAAMC,OAAO,CAACF;AACzE"}
@@ -1 +0,0 @@
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 +0,0 @@
1
- {"version":3,"sources":["../../../src/ai/utils/systemGenerate.ts"],"sourcesContent":["import { anthropic } from '@ai-sdk/anthropic'\nimport { generateText } from 'ai'\n\nimport { PLUGIN_DEFAULT_ANTHROPIC_MODEL, PLUGIN_DEFAULT_OPENAI_MODEL } from '../../defaults.js'\n// import { openai } from '../models/openai/openai.js'\n\nexport const systemGenerate = async (\n data: { prompt: string; system: string },\n generateTextFn?: (prompt: string, system: string) => Promise<string>,\n) => {\n const { prompt, system } = data\n\n if (generateTextFn) {\n return generateTextFn(prompt, system)\n }\n\n // TODO: to be re-evaluate and implemented in a way that admin ui can generate when needed\n\n // let model = null\n\n\n // If the generateTextFn is not provided, still need OPENAI_API_KEY or ANTHROPIC_API_KEY to initialize\n // if (process.env.OPENAI_API_KEY) {\n // model = openai(PLUGIN_DEFAULT_OPENAI_MODEL)\n // } else if (process.env.ANTHROPIC_API_KEY) {\n // model = anthropic(PLUGIN_DEFAULT_ANTHROPIC_MODEL)\n // } else {\n // throw new Error('- AI Plugin: Please check your environment variables!')\n // }\n //\n // const { text } = await generateText({\n // model,\n // prompt,\n // system,\n // })\n //\n // return text\n}\n"],"names":["systemGenerate","data","generateTextFn","prompt","system"],"mappings":"AAIA,sDAAsD;AAEtD,OAAO,MAAMA,iBAAiB,OAC5BC,MACAC;IAEA,MAAM,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAGH;IAE3B,IAAIC,gBAAgB;QAClB,OAAOA,eAAeC,QAAQC;IAChC;AAEA,0FAA0F;AAE1F,mBAAmB;AAGnB,sGAAsG;AACtG,oCAAoC;AACpC,gDAAgD;AAChD,8CAA8C;AAC9C,sDAAsD;AACtD,WAAW;AACX,6EAA6E;AAC7E,IAAI;AACJ,EAAE;AACF,wCAAwC;AACxC,WAAW;AACX,YAAY;AACZ,YAAY;AACZ,KAAK;AACL,EAAE;AACF,cAAc;AAChB,EAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/endpoints/buildPromptUtils.ts"],"sourcesContent":["import type { CollectionSlug } from 'payload'\n\nimport type {\n ActionMenuItems,\n PluginConfig,\n PromptFieldGetterContext,\n} from '../types.js'\n\nimport { defaultPrompts } from '../ai/prompts.js'\nimport { asyncHandlebars } from '../libraries/handlebars/asyncHandlebars.js'\nimport { handlebarsHelpersMap } from '../libraries/handlebars/helpersMap.js'\nimport { replacePlaceholders } from '../libraries/handlebars/replacePlaceholders.js'\n\nconst buildRichTextSystem = (baseSystem: string, layout: string) => {\n return `${baseSystem}\n\nRULES:\n- Generate original and unique content based on the given topic.\n- Strictly adhere to the specified layout and formatting instructions.\n- Utilize the provided rich text editor tools for appropriate formatting.\n- Ensure the output follows the structure of the sample output object.\n- Produce valid JSON with no undefined or null values.\n---\nLAYOUT INSTRUCTIONS:\n${layout}\n\n---\nADDITIONAL GUIDELINES:\n- Ensure coherence and logical flow between all sections.\n- Maintain a consistent tone and style throughout the content.\n- Use clear and concise language appropriate for the target audience.\n`\n}\n\nexport const assignPrompt = async (\n action: ActionMenuItems,\n {\n type,\n actionParams,\n collection,\n context,\n field,\n layout,\n locale,\n pluginConfig,\n systemPrompt = '',\n template,\n }: {\n actionParams: Record<any, any>\n collection: CollectionSlug\n context: object\n field: string\n layout: string\n locale: string\n pluginConfig: PluginConfig\n systemPrompt: string\n template: string\n type: string\n },\n) => {\n const extendedContext = extendContextWithPromptFields(context, { type, collection }, pluginConfig)\n const prompt = await replacePlaceholders(template, extendedContext)\n const toLexicalHTML = type === 'richText' ? handlebarsHelpersMap.toHTML.name : ''\n\n const assignedPrompts = {\n layout: type === 'richText' ? layout : undefined,\n prompt,\n //TODO: Define only once on a collection level\n system: type === 'richText' ? buildRichTextSystem(systemPrompt, layout) : undefined,\n }\n\n if (action === 'Compose') {\n if (locale && locale !== 'en') {\n /**\n * NOTE: Avoid using the \"system prompt\" for setting the output language,\n * as it causes quotation marks to appear in the output (Currently only tested with openai models).\n * Appending the language instruction directly to the prompt resolves this issue. - revalidate\n **/\n assignedPrompts.prompt += `\n --- \n OUTPUT LANGUAGE: ${locale}\n `\n }\n\n return assignedPrompts\n }\n\n const prompts = [...(pluginConfig.prompts || []), ...defaultPrompts]\n const foundPrompt = prompts.find((p) => p.name === action)\n const getLayout = foundPrompt?.layout\n const getSystemPrompt = foundPrompt?.system\n\n let updatedLayout = layout\n if (getLayout) {\n updatedLayout = getLayout()\n }\n\n const system = getSystemPrompt\n ? getSystemPrompt({\n ...(actionParams || {}),\n prompt,\n systemPrompt,\n })\n : ''\n\n return {\n layout: updatedLayout,\n // TODO: revisit this toLexicalHTML\n prompt: await replacePlaceholders(`{{${toLexicalHTML} ${field}}}`, extendedContext),\n system: type === 'richText' ? buildRichTextSystem(system, updatedLayout) : system,\n }\n}\n\nexport const extendContextWithPromptFields = (\n data: object,\n ctx: PromptFieldGetterContext,\n pluginConfig: PluginConfig,\n) => {\n const { promptFields = [] } = pluginConfig\n const fieldsMap = new Map(\n promptFields\n .filter((f) => !f.collections || f.collections.includes(ctx.collection))\n .map((f) => [f.name, f]),\n )\n return new Proxy(data, {\n get: (target, prop: string) => {\n const field = fieldsMap.get(prop)\n if (field?.getter) {\n const value = field.getter(data, ctx)\n return Promise.resolve(value).then((v) => new asyncHandlebars.SafeString(v))\n }\n // {{prop}} escapes content by default. Here we make sure it won't be escaped.\n const value = typeof target === 'object' ? (target as any)[prop] : undefined\n return typeof value === 'string' ? new asyncHandlebars.SafeString(value) : value\n },\n // It's used by the handlebars library to determine if the property is enumerable\n getOwnPropertyDescriptor: (target, prop) => {\n const field = fieldsMap.get(prop as string)\n if (field) {\n return {\n configurable: true,\n enumerable: true,\n }\n }\n return Object.getOwnPropertyDescriptor(target, prop)\n },\n has: (target, prop) => {\n return fieldsMap.has(prop as string) || (target && prop in target)\n },\n ownKeys: (target) => {\n return [...fieldsMap.keys(), ...Object.keys(target || {})]\n },\n })\n}\n"],"names":["defaultPrompts","asyncHandlebars","handlebarsHelpersMap","replacePlaceholders","buildRichTextSystem","baseSystem","layout","assignPrompt","action","type","actionParams","collection","context","field","locale","pluginConfig","systemPrompt","template","extendedContext","extendContextWithPromptFields","prompt","toLexicalHTML","toHTML","name","assignedPrompts","undefined","system","prompts","foundPrompt","find","p","getLayout","getSystemPrompt","updatedLayout","data","ctx","promptFields","fieldsMap","Map","filter","f","collections","includes","map","Proxy","get","target","prop","getter","value","Promise","resolve","then","v","SafeString","getOwnPropertyDescriptor","configurable","enumerable","Object","has","ownKeys","keys"],"mappings":"AAQA,SAASA,cAAc,QAAQ,mBAAkB;AACjD,SAASC,eAAe,QAAQ,6CAA4C;AAC5E,SAASC,oBAAoB,QAAQ,wCAAuC;AAC5E,SAASC,mBAAmB,QAAQ,iDAAgD;AAEpF,MAAMC,sBAAsB,CAACC,YAAoBC;IAC/C,OAAO,CAAC,EAAED,WAAW;;;;;;;;;;AAUvB,EAAEC,OAAO;;;;;;;AAOT,CAAC;AACD;AAEA,OAAO,MAAMC,eAAe,OAC1BC,QACA,EACEC,IAAI,EACJC,YAAY,EACZC,UAAU,EACVC,OAAO,EACPC,KAAK,EACLP,MAAM,EACNQ,MAAM,EACNC,YAAY,EACZC,eAAe,EAAE,EACjBC,QAAQ,EAYT;IAED,MAAMC,kBAAkBC,8BAA8BP,SAAS;QAAEH;QAAME;IAAW,GAAGI;IACrF,MAAMK,SAAS,MAAMjB,oBAAoBc,UAAUC;IACnD,MAAMG,gBAAgBZ,SAAS,aAAaP,qBAAqBoB,MAAM,CAACC,IAAI,GAAG;IAE/E,MAAMC,kBAAkB;QACtBlB,QAAQG,SAAS,aAAaH,SAASmB;QACvCL;QACA,8CAA8C;QAC9CM,QAAQjB,SAAS,aAAaL,oBAAoBY,cAAcV,UAAUmB;IAC5E;IAEA,IAAIjB,WAAW,WAAW;QACxB,IAAIM,UAAUA,WAAW,MAAM;YAC7B;;;;QAIE,GACFU,gBAAgBJ,MAAM,IAAI,CAAC;;qBAEZ,EAAEN,OAAO;IAC1B,CAAC;QACD;QAEA,OAAOU;IACT;IAEA,MAAMG,UAAU;WAAKZ,aAAaY,OAAO,IAAI,EAAE;WAAM3B;KAAe;IACpE,MAAM4B,cAAcD,QAAQE,IAAI,CAAC,CAACC,IAAMA,EAAEP,IAAI,KAAKf;IACnD,MAAMuB,YAAYH,aAAatB;IAC/B,MAAM0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5B,IAAIlC,OAAO;gBACT,OAAO;oBACL2C,cAAc;oBACdC,YAAY;gBACd;YACF;YACA,OAAOC,OAAOH,wBAAwB,CAACT,QAAQC;QACjD;QACAY,KAAK,CAACb,QAAQC;YACZ,OAAOV,UAAUsB,GAAG,CAACZ,SAAoBD,UAAUC,QAAQD;QAC7D;QACAc,SAAS,CAACd;YACR,OAAO;mBAAIT,UAAUwB,IAAI;mBAAOH,OAAOG,IAAI,CAACf,UAAU,CAAC;aAAG;QAC5D;IACF;AACF,EAAC"}
@@ -1,4 +0,0 @@
1
- import type { Endpoint } from 'payload';
2
-
3
- import type { PluginConfig } from '../types.js';
4
- export declare const Chat: (pluginConfig: PluginConfig) => Endpoint;
@@ -1,3 +0,0 @@
1
- import type { TextareaFieldClientProps } from 'payload';
2
- import React from 'react';
3
- export declare const PromptEditorField: React.FC<TextareaFieldClientProps>;