@ai-stack/payloadcms 3.2.15-beta → 3.2.17-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/README.md +87 -1
  2. package/dist/ai/analyse.d.ts +0 -1
  3. package/dist/ai/models/anthropic/generateRichText.d.ts +0 -1
  4. package/dist/ai/models/anthropic/generateRichText.js +7 -8
  5. package/dist/ai/models/anthropic/generateRichText.js.map +1 -1
  6. package/dist/ai/models/anthropic/index.d.ts +0 -1
  7. package/dist/ai/models/anthropic/index.js +54 -3
  8. package/dist/ai/models/anthropic/index.js.map +1 -1
  9. package/dist/ai/models/elevenLabs/generateVoice.d.ts +1 -2
  10. package/dist/ai/models/elevenLabs/index.d.ts +0 -1
  11. package/dist/ai/models/elevenLabs/index.js +5 -2
  12. package/dist/ai/models/elevenLabs/index.js.map +1 -1
  13. package/dist/ai/models/elevenLabs/voices.d.ts +6 -2
  14. package/dist/ai/models/elevenLabs/voices.js.map +1 -1
  15. package/dist/ai/models/index.d.ts +0 -1
  16. package/dist/ai/models/openai/generateImage.d.ts +1 -2
  17. package/dist/ai/models/openai/generateImage.js +6 -4
  18. package/dist/ai/models/openai/generateImage.js.map +1 -1
  19. package/dist/ai/models/openai/generateRichText.d.ts +0 -1
  20. package/dist/ai/models/openai/generateRichText.js +9 -12
  21. package/dist/ai/models/openai/generateRichText.js.map +1 -1
  22. package/dist/ai/models/openai/generateVoice.d.ts +1 -2
  23. package/dist/ai/models/openai/index.d.ts +0 -1
  24. package/dist/ai/models/openai/index.js +63 -4
  25. package/dist/ai/models/openai/index.js.map +1 -1
  26. package/dist/ai/models/openai/openai.d.ts +0 -1
  27. package/dist/ai/models/openai/openai.js +1 -2
  28. package/dist/ai/models/openai/openai.js.map +1 -1
  29. package/dist/ai/prompts.d.ts +2 -23
  30. package/dist/ai/prompts.js +2 -2
  31. package/dist/ai/prompts.js.map +1 -1
  32. package/dist/ai/schemas/lexicalJsonSchema.d.ts +5 -4
  33. package/dist/ai/schemas/lexicalJsonSchema.js +3 -1
  34. package/dist/ai/schemas/lexicalJsonSchema.js.map +1 -1
  35. package/dist/ai/utils/editImagesWithOpenAI.d.ts +0 -1
  36. package/dist/ai/utils/filterEditorSchemaByNodes.d.ts +19 -29
  37. package/dist/ai/utils/filterEditorSchemaByNodes.js +4 -2
  38. package/dist/ai/utils/filterEditorSchemaByNodes.js.map +1 -1
  39. package/dist/ai/utils/generateFileNameByPrompt.d.ts +1 -2
  40. package/dist/ai/utils/generateFileNameByPrompt.js.map +1 -1
  41. package/dist/ai/utils/isObjectSchema.d.ts +0 -1
  42. package/dist/ai/utils/systemGenerate.d.ts +0 -1
  43. package/dist/collections/Instructions.d.ts +0 -1
  44. package/dist/collections/Instructions.js +2 -2
  45. package/dist/collections/Instructions.js.map +1 -1
  46. package/dist/defaults.d.ts +0 -1
  47. package/dist/endpoints/fetchFields.d.ts +2 -3
  48. package/dist/endpoints/fetchFields.js +8 -3
  49. package/dist/endpoints/fetchFields.js.map +1 -1
  50. package/dist/endpoints/index.d.ts +0 -1
  51. package/dist/endpoints/index.js +122 -31
  52. package/dist/endpoints/index.js.map +1 -1
  53. package/dist/exports/client.d.ts +1 -1
  54. package/dist/exports/client.js +1 -0
  55. package/dist/exports/client.js.map +1 -1
  56. package/dist/exports/fields.d.ts +0 -1
  57. package/dist/exports/types.d.ts +2 -3
  58. package/dist/exports/types.js.map +1 -1
  59. package/dist/fields/ComposeField/ComposeField.d.ts +10 -2
  60. package/dist/fields/ComposeField/ComposeField.js +13 -5
  61. package/dist/fields/ComposeField/ComposeField.js.map +1 -1
  62. package/dist/fields/LexicalEditor/ComposeFeatureComponent.d.ts +2 -2
  63. package/dist/fields/LexicalEditor/feature.client.d.ts +2 -3
  64. package/dist/fields/LexicalEditor/feature.server.d.ts +0 -1
  65. package/dist/fields/PromptEditorField/PromptEditorField.d.ts +0 -1
  66. package/dist/fields/PromptEditorField/PromptEditorField.js +1 -1
  67. package/dist/fields/PromptEditorField/PromptEditorField.js.map +1 -1
  68. package/dist/fields/PromptEditorField/defaultStyle.d.ts +0 -1
  69. package/dist/fields/SelectField/SelectField.d.ts +2 -2
  70. package/dist/fields/SelectField/SelectField.js +15 -4
  71. package/dist/fields/SelectField/SelectField.js.map +1 -1
  72. package/dist/index.d.ts +2 -6
  73. package/dist/index.js +2 -4
  74. package/dist/index.js.map +1 -1
  75. package/dist/init.d.ts +5 -2
  76. package/dist/init.js +8 -7
  77. package/dist/init.js.map +1 -1
  78. package/dist/libraries/handlebars/asyncHandlebars.d.ts +0 -1
  79. package/dist/libraries/handlebars/helpers.d.ts +1 -2
  80. package/dist/libraries/handlebars/helpers.js +6 -1
  81. package/dist/libraries/handlebars/helpers.js.map +1 -1
  82. package/dist/libraries/handlebars/helpersMap.d.ts +0 -1
  83. package/dist/libraries/handlebars/replacePlaceholders.d.ts +0 -1
  84. package/dist/plugin.d.ts +0 -1
  85. package/dist/plugin.js +7 -5
  86. package/dist/plugin.js.map +1 -1
  87. package/dist/providers/FieldProvider/FieldProvider.d.ts +1 -2
  88. package/dist/providers/FieldProvider/useFieldProps.d.ts +3 -4
  89. package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts +2 -11
  90. package/dist/providers/InstructionsProvider/InstructionsProvider.js +10 -9
  91. package/dist/providers/InstructionsProvider/InstructionsProvider.js.map +1 -1
  92. package/dist/providers/InstructionsProvider/context.d.ts +16 -0
  93. package/dist/providers/InstructionsProvider/context.js +13 -0
  94. package/dist/providers/InstructionsProvider/context.js.map +1 -0
  95. package/dist/providers/InstructionsProvider/useInstructions.d.ts +0 -1
  96. package/dist/providers/InstructionsProvider/useInstructions.js +29 -15
  97. package/dist/providers/InstructionsProvider/useInstructions.js.map +1 -1
  98. package/dist/translations/index.d.ts +0 -1
  99. package/dist/types/handlebars-async-helpers.d.js +2 -0
  100. package/dist/types/handlebars-async-helpers.d.js.map +1 -0
  101. package/dist/types/handlebars-dist-handlebars.d.js +2 -0
  102. package/dist/types/handlebars-dist-handlebars.d.js.map +1 -0
  103. package/dist/types/react-mentions.d.js +2 -0
  104. package/dist/types/react-mentions.d.js.map +1 -0
  105. package/dist/types.d.ts +55 -1
  106. package/dist/types.js.map +1 -1
  107. package/dist/ui/Compose/Compose.d.ts +0 -1
  108. package/dist/ui/Compose/Compose.js +61 -25
  109. package/dist/ui/Compose/Compose.js.map +1 -1
  110. package/dist/ui/Compose/UndoRedoActions.d.ts +2 -2
  111. package/dist/ui/Compose/hooks/menu/Item.d.ts +3 -2
  112. package/dist/ui/Compose/hooks/menu/Item.js +2 -2
  113. package/dist/ui/Compose/hooks/menu/Item.js.map +1 -1
  114. package/dist/ui/Compose/hooks/menu/TranslateMenu.d.ts +10 -3
  115. package/dist/ui/Compose/hooks/menu/TranslateMenu.js +10 -5
  116. package/dist/ui/Compose/hooks/menu/TranslateMenu.js.map +1 -1
  117. package/dist/ui/Compose/hooks/menu/items.d.ts +8 -9
  118. package/dist/ui/Compose/hooks/menu/itemsMap.d.ts +0 -1
  119. package/dist/ui/Compose/hooks/menu/itemsMap.js +2 -2
  120. package/dist/ui/Compose/hooks/menu/itemsMap.js.map +1 -1
  121. package/dist/ui/Compose/hooks/menu/useMenu.d.ts +7 -7
  122. package/dist/ui/Compose/hooks/menu/useMenu.js +12 -9
  123. package/dist/ui/Compose/hooks/menu/useMenu.js.map +1 -1
  124. package/dist/ui/Compose/hooks/useGenerate.d.ts +0 -1
  125. package/dist/ui/Compose/hooks/useGenerate.js +41 -20
  126. package/dist/ui/Compose/hooks/useGenerate.js.map +1 -1
  127. package/dist/ui/Compose/hooks/useHistory.d.ts +0 -1
  128. package/dist/ui/Compose/hooks/useHistory.js +2 -2
  129. package/dist/ui/Compose/hooks/useHistory.js.map +1 -1
  130. package/dist/ui/Icons/Icons.d.ts +34 -34
  131. package/dist/ui/Icons/Icons.js +1 -1
  132. package/dist/ui/Icons/Icons.js.map +1 -1
  133. package/dist/ui/Icons/LottieAnimation.d.ts +3 -3
  134. package/dist/ui/Icons/LottieAnimation.js +1 -0
  135. package/dist/ui/Icons/LottieAnimation.js.map +1 -1
  136. package/dist/utilities/editorSchemaValidator.d.ts +1 -2
  137. package/dist/utilities/editorSchemaValidator.js.map +1 -1
  138. package/dist/utilities/extractImageData.d.ts +0 -1
  139. package/dist/utilities/extractPromptAttachments.d.ts +2 -0
  140. package/dist/utilities/extractPromptAttachments.js +32 -0
  141. package/dist/utilities/extractPromptAttachments.js.map +1 -0
  142. package/dist/utilities/getFieldBySchemaPath.d.ts +0 -1
  143. package/dist/utilities/getFieldBySchemaPath.js +12 -4
  144. package/dist/utilities/getFieldBySchemaPath.js.map +1 -1
  145. package/dist/utilities/getFieldInfo.d.ts +1 -2
  146. package/dist/utilities/getGenerationModels.d.ts +1 -2
  147. package/dist/utilities/isPluginActivated.d.ts +0 -1
  148. package/dist/utilities/isPluginActivated.js +1 -1
  149. package/dist/utilities/isPluginActivated.js.map +1 -1
  150. package/dist/utilities/lexicalToHTML.d.ts +0 -1
  151. package/dist/utilities/setSafeLexicalState.d.ts +1 -2
  152. package/dist/utilities/setSafeLexicalState.js.map +1 -1
  153. package/dist/utilities/updateFieldsConfig.d.ts +0 -1
  154. package/dist/utilities/updateFieldsConfig.js +10 -3
  155. package/dist/utilities/updateFieldsConfig.js.map +1 -1
  156. package/package.json +104 -65
  157. package/dist/ai/analyse.d.ts.map +0 -1
  158. package/dist/ai/models/anthropic/generateRichText.d.ts.map +0 -1
  159. package/dist/ai/models/anthropic/index.d.ts.map +0 -1
  160. package/dist/ai/models/elevenLabs/generateVoice.d.ts.map +0 -1
  161. package/dist/ai/models/elevenLabs/index.d.ts.map +0 -1
  162. package/dist/ai/models/elevenLabs/voices.d.ts.map +0 -1
  163. package/dist/ai/models/index.d.ts.map +0 -1
  164. package/dist/ai/models/openai/generateImage.d.ts.map +0 -1
  165. package/dist/ai/models/openai/generateRichText.d.ts.map +0 -1
  166. package/dist/ai/models/openai/generateVoice.d.ts.map +0 -1
  167. package/dist/ai/models/openai/index.d.ts.map +0 -1
  168. package/dist/ai/models/openai/openai.d.ts.map +0 -1
  169. package/dist/ai/prompts.d.ts.map +0 -1
  170. package/dist/ai/schemas/lexicalJsonSchema.d.ts.map +0 -1
  171. package/dist/ai/utils/editImagesWithOpenAI.d.ts.map +0 -1
  172. package/dist/ai/utils/filterEditorSchemaByNodes.d.ts.map +0 -1
  173. package/dist/ai/utils/generateFileNameByPrompt.d.ts.map +0 -1
  174. package/dist/ai/utils/isObjectSchema.d.ts.map +0 -1
  175. package/dist/ai/utils/systemGenerate.d.ts.map +0 -1
  176. package/dist/collections/Instructions.d.ts.map +0 -1
  177. package/dist/defaults.d.ts.map +0 -1
  178. package/dist/endpoints/fetchFields.d.ts.map +0 -1
  179. package/dist/endpoints/index.d.ts.map +0 -1
  180. package/dist/exports/client.d.ts.map +0 -1
  181. package/dist/exports/fields.d.ts.map +0 -1
  182. package/dist/exports/types.d.ts.map +0 -1
  183. package/dist/fields/ComposeField/ComposeField.d.ts.map +0 -1
  184. package/dist/fields/LexicalEditor/ComposeFeatureComponent.d.ts.map +0 -1
  185. package/dist/fields/LexicalEditor/feature.client.d.ts.map +0 -1
  186. package/dist/fields/LexicalEditor/feature.server.d.ts.map +0 -1
  187. package/dist/fields/PromptEditorField/PromptEditorField.d.ts.map +0 -1
  188. package/dist/fields/PromptEditorField/defaultStyle.d.ts.map +0 -1
  189. package/dist/fields/SelectField/SelectField.d.ts.map +0 -1
  190. package/dist/index.d.ts.map +0 -1
  191. package/dist/init.d.ts.map +0 -1
  192. package/dist/libraries/handlebars/asyncHandlebars.d.ts.map +0 -1
  193. package/dist/libraries/handlebars/helpers.d.ts.map +0 -1
  194. package/dist/libraries/handlebars/helpersMap.d.ts.map +0 -1
  195. package/dist/libraries/handlebars/replacePlaceholders.d.ts.map +0 -1
  196. package/dist/plugin.d.ts.map +0 -1
  197. package/dist/providers/FieldProvider/FieldProvider.d.ts.map +0 -1
  198. package/dist/providers/FieldProvider/useFieldProps.d.ts.map +0 -1
  199. package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts.map +0 -1
  200. package/dist/providers/InstructionsProvider/useInstructions.d.ts.map +0 -1
  201. package/dist/translations/index.d.ts.map +0 -1
  202. package/dist/types.d.ts.map +0 -1
  203. package/dist/ui/Compose/Compose.d.ts.map +0 -1
  204. package/dist/ui/Compose/UndoRedoActions.d.ts.map +0 -1
  205. package/dist/ui/Compose/hooks/menu/Item.d.ts.map +0 -1
  206. package/dist/ui/Compose/hooks/menu/TranslateMenu.d.ts.map +0 -1
  207. package/dist/ui/Compose/hooks/menu/items.d.ts.map +0 -1
  208. package/dist/ui/Compose/hooks/menu/itemsMap.d.ts.map +0 -1
  209. package/dist/ui/Compose/hooks/menu/useMenu.d.ts.map +0 -1
  210. package/dist/ui/Compose/hooks/useGenerate.d.ts.map +0 -1
  211. package/dist/ui/Compose/hooks/useHistory.d.ts.map +0 -1
  212. package/dist/ui/Icons/Icons.d.ts.map +0 -1
  213. package/dist/ui/Icons/LottieAnimation.d.ts.map +0 -1
  214. package/dist/utilities/editorSchemaValidator.d.ts.map +0 -1
  215. package/dist/utilities/extractImageData.d.ts.map +0 -1
  216. package/dist/utilities/getFieldBySchemaPath.d.ts.map +0 -1
  217. package/dist/utilities/getFieldInfo.d.ts.map +0 -1
  218. package/dist/utilities/getGenerationModels.d.ts.map +0 -1
  219. package/dist/utilities/isPluginActivated.d.ts.map +0 -1
  220. package/dist/utilities/lexicalToHTML.d.ts.map +0 -1
  221. package/dist/utilities/setSafeLexicalState.d.ts.map +0 -1
  222. package/dist/utilities/updateFieldsConfig.d.ts.map +0 -1
@@ -1,4 +1,5 @@
1
1
  import { streamText } from 'ai';
2
+ import { extractPromptAttachments } from "../../../utilities/extractPromptAttachments.js";
2
3
  import { defaultSystemPrompt } from '../../prompts.js';
3
4
  import { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js';
4
5
  import { generateImage } from './generateImage.js';
@@ -18,18 +19,20 @@ export const OpenAIConfig = {
18
19
  ],
19
20
  handler: (prompt, options)=>{
20
21
  const streamTextResult = streamText({
22
+ maxOutputTokens: options.maxTokens || 5000,
21
23
  model: openai(options.model),
22
24
  onError: (error)=>{
23
25
  console.error(`${MODEL_KEY}-text: `, error);
24
26
  },
27
+ temperature: options.temperature || 0.7,
25
28
  // TODO: Implement billing/token consumption
26
29
  // onFinish: (stepResult) => {
27
30
  // console.log('streamText : finish : ', stepResult)
28
31
  // },
29
- prompt,
32
+ prompt: options.extractAttachments ? extractPromptAttachments(prompt) : prompt,
30
33
  system: options.system || defaultSystemPrompt
31
34
  });
32
- return streamTextResult.toDataStreamResponse();
35
+ return streamTextResult.toUIMessageStreamResponse();
33
36
  },
34
37
  output: 'text',
35
38
  settings: {
@@ -47,11 +50,38 @@ export const OpenAIConfig = {
47
50
  defaultValue: 'gpt-4o-mini',
48
51
  label: 'Model',
49
52
  options: [
53
+ 'gpt-5',
54
+ 'gpt-5-mini',
55
+ 'gpt-5-nano',
56
+ 'gpt-4.1',
50
57
  'gpt-4o',
51
58
  'gpt-4-turbo',
52
59
  'gpt-4o-mini',
53
- 'gpt-3.5-turbo'
60
+ 'gpt-3.5-turbo',
61
+ 'gpt-4.1',
62
+ 'gpt-5'
54
63
  ]
64
+ },
65
+ {
66
+ type: 'row',
67
+ fields: [
68
+ {
69
+ name: 'maxTokens',
70
+ type: 'number',
71
+ defaultValue: 5000
72
+ },
73
+ {
74
+ name: 'temperature',
75
+ type: 'number',
76
+ defaultValue: 0.7,
77
+ max: 1,
78
+ min: 0
79
+ }
80
+ ]
81
+ },
82
+ {
83
+ name: 'extractAttachments',
84
+ type: 'checkbox'
55
85
  }
56
86
  ],
57
87
  label: 'OpenAI GPT Settings'
@@ -264,6 +294,9 @@ export const OpenAIConfig = {
264
294
  handler: async (text, options)=>{
265
295
  //TODO: change it to open ai text to speech api
266
296
  const voiceData = await generateVoice(text, options);
297
+ if (!voiceData || !voiceData.buffer) {
298
+ throw new Error('Voice data missing');
299
+ }
267
300
  return {
268
301
  data: {
269
302
  alt: text
@@ -361,12 +394,38 @@ export const OpenAIConfig = {
361
394
  defaultValue: 'gpt-4o',
362
395
  label: 'Model',
363
396
  options: [
397
+ 'gpt-5',
398
+ 'gpt-5-mini',
399
+ 'gpt-5-nano',
400
+ 'gpt-4.1',
364
401
  'gpt-4o',
365
402
  'gpt-4-turbo',
366
403
  'gpt-4o-mini',
404
+ 'o4-mini',
367
405
  'gpt-4.1',
368
- 'o4-mini'
406
+ 'gpt-5'
407
+ ]
408
+ },
409
+ {
410
+ type: 'row',
411
+ fields: [
412
+ {
413
+ name: 'maxTokens',
414
+ type: 'number',
415
+ defaultValue: 5000
416
+ },
417
+ {
418
+ name: 'temperature',
419
+ type: 'number',
420
+ defaultValue: 0.7,
421
+ max: 1,
422
+ min: 0
423
+ }
369
424
  ]
425
+ },
426
+ {
427
+ name: 'extractAttachments',
428
+ type: 'checkbox'
370
429
  }
371
430
  ],
372
431
  label: 'OpenAI GPT Settings'
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ai/models/openai/index.ts"],"sourcesContent":["import type { SpeechCreateParams } from 'openai/resources/audio/speech'\nimport type { File } from 'payload'\n\nimport { streamText } from 'ai'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { defaultSystemPrompt } from '../../prompts.js'\nimport { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js'\nimport { generateImage } from './generateImage.js'\nimport { generateRichText } from './generateRichText.js'\nimport { generateVoice } from './generateVoice.js'\nimport { openai } from './openai.js'\n\nconst MODEL_KEY = 'Oai'\n\n//TODO: Simplify this file by moving the handlers to separate files and remove duplicate code\nexport const OpenAIConfig: GenerationConfig = {\n models: [\n {\n id: `${MODEL_KEY}-text`,\n name: 'OpenAI GPT Text',\n fields: ['text', 'textarea'],\n handler: (prompt: string, options: { locale: string; model: string; system: string }) => {\n const streamTextResult = streamText({\n model: openai(options.model),\n onError: (error) => {\n console.error(`${MODEL_KEY}-text: `, error)\n },\n\n // TODO: Implement billing/token consumption\n // onFinish: (stepResult) => {\n // console.log('streamText : finish : ', stepResult)\n // },\n prompt,\n system: options.system || defaultSystemPrompt,\n })\n\n return streamTextResult.toDataStreamResponse()\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-text-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-text`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o-mini',\n label: 'Model',\n options: ['gpt-4o', 'gpt-4-turbo', 'gpt-4o-mini', 'gpt-3.5-turbo'],\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n {\n id: 'dall-e',\n name: 'OpenAI DALL-E',\n fields: ['upload'],\n handler: async (prompt: string, options) => {\n const imageData = await generateImage(prompt, options)\n return {\n data: {\n alt: imageData.alt,\n },\n file: {\n name: `image_${generateFileNameByPrompt(imageData.alt || prompt)}.jpeg`,\n data: imageData.buffer,\n mimetype: 'image/jpeg',\n size: imageData.buffer.byteLength,\n } as File,\n }\n },\n output: 'image',\n settings: {\n name: 'dalle-e-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'dall-e'\n },\n },\n fields: [\n {\n name: 'version',\n type: 'select',\n defaultValue: 'dall-e-3',\n label: 'Version',\n options: ['dall-e-3', 'dall-e-2'],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'size',\n type: 'select',\n defaultValue: '1024x1024',\n label: 'Size',\n options: ['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792'],\n },\n {\n name: 'style',\n type: 'select',\n defaultValue: 'natural',\n label: 'Style',\n options: ['vivid', 'natural'],\n },\n ],\n },\n {\n name: 'enable-prompt-optimization',\n type: 'checkbox',\n label: 'Optimize prompt',\n },\n ],\n label: 'OpenAI DALL-E Settings',\n },\n },\n {\n id: 'gpt-image-1',\n name: 'OpenAI GPT Image 1',\n fields: ['upload'],\n handler: async (prompt: string, options) => {\n const imageData = await generateImage(prompt, options)\n return {\n data: {\n alt: imageData.alt,\n },\n file: {\n name: `image_${generateFileNameByPrompt(imageData.alt || prompt)}.png`,\n data: imageData.buffer,\n mimetype: 'image/png',\n size: imageData.buffer.byteLength,\n } as File,\n }\n },\n output: 'image',\n settings: {\n name: 'gpt-image-1-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'gpt-image-1'\n },\n },\n fields: [\n {\n name: 'version',\n type: 'select',\n defaultValue: 'gpt-image-1',\n label: 'Version',\n options: ['gpt-image-1'],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'size',\n type: 'select',\n defaultValue: 'auto',\n label: 'Size',\n options: ['1024x1024', '1024x1536', '1536x1024', 'auto'],\n },\n {\n name: 'quality',\n type: 'select',\n defaultValue: 'auto',\n label: 'Quality',\n options: ['low', 'medium', 'high', 'auto'],\n },\n ],\n },\n {\n name: 'output_format',\n type: 'select',\n defaultValue: 'png',\n label: 'Output Format',\n options: ['png', 'jpeg', 'webp'],\n },\n {\n name: 'output_compression',\n type: 'number',\n admin: {\n condition(data) {\n return data.output_format === 'jpeg' || data.output_format === 'webp'\n },\n },\n defaultValue: 100,\n label: 'Output Compression',\n max: 100,\n min: 0,\n },\n {\n name: 'background',\n type: 'select',\n admin: {\n condition(data) {\n return data.output_format === 'png' || data.output_format === 'webp'\n },\n },\n defaultValue: 'white',\n label: 'Background',\n options: ['white', 'transparent'],\n },\n {\n name: 'moderation',\n type: 'select',\n defaultValue: 'auto',\n label: 'Moderation',\n options: ['auto', 'low'],\n },\n ],\n label: 'OpenAI GPT Image 1 Settings',\n },\n },\n {\n id: 'tts',\n name: 'OpenAI Text-to-Speech',\n fields: ['upload'],\n handler: async (text: string, options) => {\n //TODO: change it to open ai text to speech api\n const voiceData = await generateVoice(text, options)\n return {\n data: {\n alt: text,\n },\n file: {\n name: `voice_${generateFileNameByPrompt(text)}.mp3`,\n data: voiceData.buffer,\n mimetype: 'audio/mp3',\n size: voiceData.buffer.byteLength,\n } as File,\n }\n },\n output: 'audio',\n settings: {\n name: `${MODEL_KEY}-tts-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'tts'\n },\n },\n fields: [\n {\n name: 'voice',\n type: 'select',\n defaultValue: 'alloy',\n label: 'Voice',\n options: ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'] as Array<\n SpeechCreateParams['voice']\n >,\n },\n {\n name: 'model',\n type: 'select',\n defaultValue: 'tts-1',\n label: 'Model',\n options: ['tts-1', 'tts-1-hd'] as Array<SpeechCreateParams['model']>,\n },\n {\n name: 'response_format',\n type: 'select',\n defaultValue: 'mp3',\n label: 'Response Format',\n options: ['mp3', 'opus', 'aac', 'flac', 'wav', 'pcm'] as Array<\n SpeechCreateParams['response_format']\n >,\n },\n {\n name: 'speed',\n type: 'number',\n defaultValue: 1,\n label: 'Speed',\n max: 4,\n min: 0.25,\n },\n ],\n label: 'OpenAI Text-to-Speech Settings',\n },\n },\n {\n id: `${MODEL_KEY}-object`,\n name: 'OpenAI GPT',\n fields: ['richText'],\n handler: (text: string, options) => {\n return generateRichText(text, options)\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-object-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-object`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o',\n label: 'Model',\n options: ['gpt-4o', 'gpt-4-turbo', 'gpt-4o-mini', 'gpt-4.1', 'o4-mini'],\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n ],\n provider: 'OpenAI',\n}\n"],"names":["streamText","defaultSystemPrompt","generateFileNameByPrompt","generateImage","generateRichText","generateVoice","openai","MODEL_KEY","OpenAIConfig","models","id","name","fields","handler","prompt","options","streamTextResult","model","onError","error","console","system","toDataStreamResponse","output","settings","type","admin","condition","data","defaultValue","label","imageData","alt","file","buffer","mimetype","size","byteLength","output_format","max","min","text","voiceData","provider"],"mappings":"AAGA,SAASA,UAAU,QAAQ,KAAI;AAI/B,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O;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGrB,UAAU,OAAO,CAAC;oBACnD;gBACF;gBACAK,QAAQ;oBACN;wBACED,MAAM;wBACNc,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPf,SAAS;4BAAC;4BAAU;4BAAe;4BAAe;4BAAW;yBAAU;oBACzE;iBACD;gBACDe,OAAO;YACT;QACF;KACD;IACDa,UAAU;AACZ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/ai/models/openai/index.ts"],"sourcesContent":["import type { SpeechCreateParams } from 'openai/resources/audio/speech'\nimport type { File } from 'payload'\n\nimport { streamText } from 'ai'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { extractPromptAttachments } from \"../../../utilities/extractPromptAttachments.js\";\nimport { defaultSystemPrompt } from '../../prompts.js'\nimport { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js'\nimport { generateImage } from './generateImage.js'\nimport { generateRichText } from './generateRichText.js'\nimport { generateVoice } from './generateVoice.js'\nimport { openai } from './openai.js'\n\nconst MODEL_KEY = 'Oai'\n\n//TODO: Simplify this file by moving the handlers to separate files and remove duplicate code\nexport const OpenAIConfig: GenerationConfig = {\n models: [\n {\n id: `${MODEL_KEY}-text`,\n name: 'OpenAI GPT Text',\n fields: ['text', 'textarea'],\n handler: (prompt: string, options: { extractAttachments: boolean; locale: string; maxTokens: number; model: string; system: string; temperature: number; }) => {\n const streamTextResult = streamText({\n maxOutputTokens: options.maxTokens || 5000,\n model: openai(options.model),\n onError: (error) => {\n console.error(`${MODEL_KEY}-text: `, error)\n },\n temperature: options.temperature || 0.7,\n\n // TODO: Implement billing/token consumption\n // onFinish: (stepResult) => {\n // console.log('streamText : finish : ', stepResult)\n // },\n prompt: options.extractAttachments ? extractPromptAttachments(prompt) : prompt,\n system: options.system || defaultSystemPrompt,\n })\n\n return streamTextResult.toUIMessageStreamResponse();\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-text-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-text`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o-mini',\n label: 'Model',\n options: [\n 'gpt-5',\n 'gpt-5-mini',\n 'gpt-5-nano',\n 'gpt-4.1',\n 'gpt-4o',\n 'gpt-4-turbo',\n 'gpt-4o-mini',\n 'gpt-3.5-turbo'\n , 'gpt-4.1', 'gpt-5'],\n },\n {\n type: 'row', fields: [\n {\n name: 'maxTokens',\n type: 'number',\n defaultValue: 5000,\n },\n {\n name: 'temperature',\n type: 'number',\n defaultValue: 0.7,\n max: 1,\n min: 0,\n },\n\n ]\n },\n {\n name: 'extractAttachments',\n type: 'checkbox',\n }\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n {\n id: 'dall-e',\n name: 'OpenAI DALL-E',\n fields: ['upload'],\n handler: async (prompt: string, options) => {\n const imageData = await generateImage(prompt, options)\n return {\n data: {\n alt: imageData.alt,\n },\n file: {\n name: `image_${generateFileNameByPrompt(imageData.alt || prompt)}.jpeg`,\n data: imageData.buffer,\n mimetype: 'image/jpeg',\n size: imageData.buffer.byteLength,\n } as File,\n }\n },\n output: 'image',\n settings: {\n name: 'dalle-e-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'dall-e'\n },\n },\n fields: [\n {\n name: 'version',\n type: 'select',\n defaultValue: 'dall-e-3',\n label: 'Version',\n options: ['dall-e-3', 'dall-e-2'],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'size',\n type: 'select',\n defaultValue: '1024x1024',\n label: 'Size',\n options: ['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792'],\n },\n {\n name: 'style',\n type: 'select',\n defaultValue: 'natural',\n label: 'Style',\n options: ['vivid', 'natural'],\n },\n ],\n },\n {\n name: 'enable-prompt-optimization',\n type: 'checkbox',\n label: 'Optimize prompt',\n },\n ],\n label: 'OpenAI DALL-E Settings',\n },\n },\n {\n id: 'gpt-image-1',\n name: 'OpenAI GPT Image 1',\n fields: ['upload'],\n handler: async (prompt: string, options) => {\n const imageData = await generateImage(prompt, options)\n return {\n data: {\n alt: imageData.alt,\n },\n file: {\n name: `image_${generateFileNameByPrompt(imageData.alt || prompt)}.png`,\n data: imageData.buffer,\n mimetype: 'image/png',\n size: imageData.buffer.byteLength,\n } as File,\n }\n },\n output: 'image',\n settings: {\n name: 'gpt-image-1-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'gpt-image-1'\n },\n },\n fields: [\n {\n name: 'version',\n type: 'select',\n defaultValue: 'gpt-image-1',\n label: 'Version',\n options: ['gpt-image-1'],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'size',\n type: 'select',\n defaultValue: 'auto',\n label: 'Size',\n options: ['1024x1024', '1024x1536', '1536x1024', 'auto'],\n },\n {\n name: 'quality',\n type: 'select',\n defaultValue: 'auto',\n label: 'Quality',\n options: ['low', 'medium', 'high', 'auto'],\n },\n ],\n },\n {\n name: 'output_format',\n type: 'select',\n defaultValue: 'png',\n label: 'Output Format',\n options: ['png', 'jpeg', 'webp'],\n },\n {\n name: 'output_compression',\n type: 'number',\n admin: {\n condition(data) {\n return data.output_format === 'jpeg' || data.output_format === 'webp'\n },\n },\n defaultValue: 100,\n label: 'Output Compression',\n max: 100,\n min: 0,\n },\n {\n name: 'background',\n type: 'select',\n admin: {\n condition(data) {\n return data.output_format === 'png' || data.output_format === 'webp'\n },\n },\n defaultValue: 'white',\n label: 'Background',\n options: ['white', 'transparent'],\n },\n {\n name: 'moderation',\n type: 'select',\n defaultValue: 'auto',\n label: 'Moderation',\n options: ['auto', 'low'],\n },\n ],\n label: 'OpenAI GPT Image 1 Settings',\n },\n },\n {\n id: 'tts',\n name: 'OpenAI Text-to-Speech',\n fields: ['upload'],\n handler: async (text: string, options) => {\n //TODO: change it to open ai text to speech api\n const voiceData = await generateVoice(text, options)\n if (!voiceData || !voiceData.buffer) {\n throw new Error('Voice data missing')\n }\n return {\n data: {\n alt: text,\n },\n file: {\n name: `voice_${generateFileNameByPrompt(text)}.mp3`,\n data: voiceData.buffer,\n mimetype: 'audio/mp3',\n size: voiceData.buffer.byteLength,\n } as File,\n }\n },\n output: 'audio',\n settings: {\n name: `${MODEL_KEY}-tts-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'tts'\n },\n },\n fields: [\n {\n name: 'voice',\n type: 'select',\n defaultValue: 'alloy',\n label: 'Voice',\n options: ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'] as Array<\n SpeechCreateParams['voice']\n >,\n },\n {\n name: 'model',\n type: 'select',\n defaultValue: 'tts-1',\n label: 'Model',\n options: ['tts-1', 'tts-1-hd'] as Array<SpeechCreateParams['model']>,\n },\n {\n name: 'response_format',\n type: 'select',\n defaultValue: 'mp3',\n label: 'Response Format',\n options: ['mp3', 'opus', 'aac', 'flac', 'wav', 'pcm'],\n },\n {\n name: 'speed',\n type: 'number',\n defaultValue: 1,\n label: 'Speed',\n max: 4,\n min: 0.25,\n },\n ],\n label: 'OpenAI Text-to-Speech Settings',\n },\n },\n {\n id: `${MODEL_KEY}-object`,\n name: 'OpenAI GPT',\n fields: ['richText'],\n handler: (text: string, options) => {\n return generateRichText(text, options)\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-object-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-object`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o',\n label: 'Model',\n options: [\n 'gpt-5',\n 'gpt-5-mini',\n 'gpt-5-nano',\n 'gpt-4.1',\n 'gpt-4o',\n 'gpt-4-turbo',\n 'gpt-4o-mini',\n 'o4-mini'\n , 'gpt-4.1', 'gpt-5'],\n },\n {\n type: 'row', fields: [\n {\n name: 'maxTokens',\n type: 'number',\n defaultValue: 5000,\n },\n {\n name: 'temperature',\n type: 'number',\n defaultValue: 0.7,\n max: 1,\n min: 0,\n },\n\n ]\n },\n {\n name: 'extractAttachments',\n type: 'checkbox',\n }\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n ],\n provider: 'OpenAI',\n}\n"],"names":["streamText","extractPromptAttachments","defaultSystemPrompt","generateFileNameByPrompt","generateImage","generateRichText","generateVoice","openai","MODEL_KEY","OpenAIConfig","models","id","name","fields","handler","prompt","options","streamTextResult","maxOutputTokens","maxTokens","model","onError","error","console","temperature","extractAttachments","system","toUIMessageStreamResponse","output","settings","type","admin","condition","data","defaultValue","label","max","min","imageData","alt","file","buffer","mimetype","size","byteLength","output_format","text","voiceData","Error","provider"],"mappings":"AAGA,SAASA,UAAU,QAAQ,KAAI;AAI/B,SAASC,wBAAwB,QAAQ,iDAAiD;AAC1F,SAASC,mBAAmB,QAAQ,mBAAkB;AACtD,SAASC,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,MAAM,QAAQ,cAAa;AAEpC,MAAMC,YAAY;AAElB,6FAA6F;AAC7F,OAAO,MAAMC,eAAiC;IAC5CC,QAAQ;QACN;YACEC,IAAI,GAAGH,UAAU,KAAK,CAAC;YACvBI,MAAM;YACNC,QAAQ;gBAAC;gBAAQ;aAAW;YAC5BC,SAAS,CAACC,QAAgBC;gBACxB,MAAMC,mBAAmBjB,WAAW;oBAClCkB,iBAAiBF,QAAQG,SAAS,IAAI;oBACtCC,OAAOb,OAAOS,QAAQI,KAAK;oBAC3BC,SAAS,CAACC;wBACRC,QAAQD,KAAK,CAAC,GAAGd,UAAU,OAAO,CAAC,EAAEc;oBACvC;oBACAE,aAAaR,QAAQQ,WAAW,IAAI;oBAEpC,4CAA4C;oBAC5C,8BAA8B;oBAC9B,sDAAsD;oBACtD,KAAK;oBACLT,QAAQC,QAAQS,kBAAkB,GAAGxB,yBAAyBc,UAAUA;oBACxEW,QAAQV,QAAQ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;oBACvB;oBACA;wBACEc,MAAM;wBAAOjB,QAAQ;4BACnB;gCACED,MAAM;gCACNkB,MAAM;gCACNI,cAAc;4BAChB;4BACA;gCACEtB,MAAM;gCACNkB,MAAM;gCACNI,cAAc;gCACdE,KAAK;gCACLC,KAAK;4BACP;yBAED;oBACH;oBACA;wBACEzB,MAAM;wBACNkB,MAAM;oBACR;iBACD;gBACDK,OAAO;YACT;QACF;KACD;IACDc,UAAU;AACZ,EAAC"}
@@ -1,2 +1 @@
1
1
  export declare const openai: import("@ai-sdk/openai").OpenAIProvider;
2
- //# sourceMappingURL=openai.d.ts.map
@@ -2,8 +2,7 @@ import { createOpenAI } from '@ai-sdk/openai';
2
2
  // same to default openai with optional baseurl.
3
3
  export const openai = createOpenAI({
4
4
  apiKey: process.env.OPENAI_API_KEY,
5
- baseURL: process.env.OPENAI_BASE_URL ?? 'https://api.openai.com/v1',
6
- compatibility: 'strict'
5
+ baseURL: process.env.OPENAI_BASE_URL ?? 'https://api.openai.com/v1'
7
6
  });
8
7
 
9
8
  //# sourceMappingURL=openai.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ai/models/openai/openai.ts"],"sourcesContent":["import { createOpenAI } from '@ai-sdk/openai'\n\n// same to default openai with optional baseurl.\nexport const openai = createOpenAI({\n apiKey: process.env.OPENAI_API_KEY,\n baseURL: process.env.OPENAI_BASE_URL ?? 'https://api.openai.com/v1',\n compatibility: 'strict',\n})\n"],"names":["createOpenAI","openai","apiKey","process","env","OPENAI_API_KEY","baseURL","OPENAI_BASE_URL","compatibility"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAgB;AAE7C,gDAAgD;AAChD,OAAO,MAAMC,SAASD,aAAa;IACjCE,QAAQC,QAAQC,GAAG,CAACC,cAAc;IAClCC,SAASH,QAAQC,GAAG,CAACG,eAAe,IAAI;IACxCC,eAAe;AACjB,GAAE"}
1
+ {"version":3,"sources":["../../../../src/ai/models/openai/openai.ts"],"sourcesContent":["import { createOpenAI } from '@ai-sdk/openai'\n\n// same to default openai with optional baseurl.\nexport const openai = createOpenAI({\n apiKey: process.env.OPENAI_API_KEY,\n baseURL: process.env.OPENAI_BASE_URL ?? 'https://api.openai.com/v1'\n})\n"],"names":["createOpenAI","openai","apiKey","process","env","OPENAI_API_KEY","baseURL","OPENAI_BASE_URL"],"mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAgB;AAE7C,gDAAgD;AAChD,OAAO,MAAMC,SAASD,aAAa;IACjCE,QAAQC,QAAQC,GAAG,CAACC,cAAc;IAClCC,SAASH,QAAQC,GAAG,CAACG,eAAe,IAAI;AAC1C,GAAE"}
@@ -1,25 +1,4 @@
1
- import type { ActionMenuItems } from '../types.js';
2
- type ActionPromptOptions = {
3
- layout?: string;
4
- locale?: string;
5
- prompt?: string;
6
- systemPrompt?: string;
7
- };
8
- type ActionPrompt = {
9
- layout?: (options?: ActionPromptOptions) => string;
10
- name: ActionMenuItems;
11
- system: (options: ActionPromptOptions) => string;
12
- };
1
+ import type { ActionPrompt, SeedPromptFunction } from '../types.js';
13
2
  export declare 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:";
14
3
  export declare const defaultPrompts: ActionPrompt[];
15
- export declare const seedPrompts: ({ fieldLabel, fieldSchemaPaths, fieldType, path }: {
16
- fieldLabel: any;
17
- fieldSchemaPaths: any;
18
- fieldType: any;
19
- path: any;
20
- }) => {
21
- prompt: string;
22
- system: string;
23
- };
24
- export {};
25
- //# sourceMappingURL=prompts.d.ts.map
4
+ export declare const defaultSeedPrompts: SeedPromptFunction;
@@ -100,7 +100,7 @@ INSTRUCTIONS:
100
100
  -------------`
101
101
  }
102
102
  ];
103
- export const seedPrompts = ({ fieldLabel, fieldSchemaPaths, fieldType, path })=>{
103
+ export const defaultSeedPrompts = ({ fieldLabel, fieldSchemaPaths, fieldType, path })=>{
104
104
  return {
105
105
  prompt: `field-type: ${fieldType}
106
106
  field-name: ${fieldLabel}
@@ -198,7 +198,7 @@ For upload:
198
198
  field-type: upload
199
199
  field-name: Voice
200
200
  schema-path: posts.upload
201
- Generated prompt: {{ title }} {{ toHTML [provide schema-path for richText] }}
201
+ Generated prompt: {{ title }} {{ toHTML schema-path here... }}
202
202
 
203
203
 
204
204
  Remember to adapt the prompts based on the specific schema-path provided, considering the context and purpose of the field within the CMS structure. The prompts should directly instruct the AI model on what content to generate or describe, without assuming a user perspective.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ai/prompts.ts"],"sourcesContent":["import type { ActionMenuItems } from '../types.js'\n\ntype ActionPromptOptions = {\n layout?: string\n locale?: string\n prompt?: string\n systemPrompt?: string\n}\n\ntype ActionPrompt = {\n layout?: (options?: ActionPromptOptions) => string\n name: ActionMenuItems\n system: (options: ActionPromptOptions) => string\n}\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\nexport const seedPrompts = ({ fieldLabel, fieldSchemaPaths, fieldType, path }) => {\n return {\n prompt: `field-type: ${fieldType}\nfield-name: ${fieldLabel}\nschema-path: ${path}\n\nGive me a prompt that relate to the given field type and schema path.\n\nGenerated prompt:\n`,\n system: `# AI Assistant for CMS Prompt Generation\n\nYour role: Generate prompts for Content Management System (CMS) fields based on field-type and schema-path.\n\n## Key Guidelines:\n- Tailor prompts to specific field-type and purpose\n- Use schema-path for context\n- Include \" {{ title }} \" in every prompt\n- Be clear, concise, and instructive\n- Focus on content generation, not user perspective\n- For Image, Voice, or Banner fields, use provided example prompts verbatim\n- Image, Banner prompt MUST NOT CONTAIN ANY TYPOGRAPHY/TEXT DETAILS\n\n## Field Types and Prompts:\n\n1. richText:\n - Craft detailed, structured content\n - Include intro, sections, body, formatting, and conclusion\n - Aim for engaging, informative, and valuable content\n\n2. text:\n - For titles: Generate concise, engaging titles\n - For keywords: List relevant SEO terms\n\n3. textarea:\n - Provide comprehensive details (e.g., event information)\n\n4. upload:\n - Describe high-quality images or media\n\n## Schema-path Examples:\n- posts.title: Blog/article title\n- products.name: Product name\n\n## Must Follow:\n- Adapt prompts to schema-path context\n- Generate content directly, avoid personal pronouns\n- Use provided examples as guidelines\n\n### Examples for each field type along with generated prompt:\n\nFor richText:\n field-type: richText\n field-name: Content\n schema-path: posts.content\n Generated prompt: Craft compelling content for a blog post with the title \" {{ title }} \". Develop a well-structured narrative that captivates readers from start to finish. Incorporate the following elements to create a polished and engaging piece:\n\n- Engaging introduction that hooks the reader\n- Clearly defined sections with relevant subheadings\n- Well-researched and informative body paragraphs\n- Creative use of formatting to enhance readability (e.g., bullet points, blockquotes, italics, headings, bolds, other text formats)\n- Compelling conclusion that reinforces the main theme\n- Make the format easily digestible and clear for enhanced readability and improved CTR. \n- The user should be engaged, consistently interested, and feel that they’ve gained the knowledge they were seeking. \n\nInfuse the content with your expertise and a touch of personality to make it both informative and enjoyable to read. Aim to provide value to your target audience while maintaining a professional tone that aligns with the blog's overall style.\nFeel free to incorporate relevant anecdotes, statistics, or examples to support your points and add depth to the post. Remember, the goal is to create content that not only informs but also inspires and entertains your readers.\n\nFor text:\n field-type: text\n field-name: title\n schema-path: posts.title\n Generated prompt: Generate a captivating title for the blog post based on \" {{ title }} \" that effectively encapsulates the main theme and draws in readers. The title should be concise, engaging, and relevant to the content being presented. If no input is provided then generate creative title.\n\nFor text:\n field-type: text\n field-name: keywords\n schema-path: posts.keywords\n Generated prompt: Identify and list relevant keywords for the blog post titled \" {{ title }} \". Focus on terms that enhance search engine optimization and accurately reflect the main themes and topics of the content.\nkeywords will with comma separated.\n\n\nFor textarea:\n field-type: textarea:\n field-name: details\n schema-path: posts.details\n Generated prompt: Provide comprehensive details for the event \" {{ title }} \". Include essential information such as date, time, location, and any specific instructions or requirements.\n\nFor upload:\n field-type: upload\n field-name: Featured Image\n schema-path: posts.image\n Generated prompt: Imagine {{ title }}\n\nFor upload:\n field-type: upload\n field-name: Voice\n schema-path: posts.upload\n Generated prompt: {{ title }} {{ toHTML [provide schema-path for richText] }}\n\n\nRemember to adapt the prompts based on the specific schema-path provided, considering the context and purpose of the field within the CMS structure. The prompts should directly instruct the AI model on what content to generate or describe, without assuming a user perspective.\n\nSchema Map Context:\n${JSON.stringify(fieldSchemaPaths)}\n\n${defaultSystemPrompt}\n`,\n }\n}\n"],"names":["defaultSystemPrompt","defaultPrompts","name","system","prompt","systemPrompt","layout","locale","seedPrompts","fieldLabel","fieldSchemaPaths","fieldType","path","JSON","stringify"],"mappings":"AAeA,kEAAkE;AAClE,OA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8Fb,EAAEU,KAAKC,SAAS,CAACJ,kBAAkB;;AAEnC,EAAEV,oBAAoB;AACtB,CAAC;IACC;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/ai/prompts.ts"],"sourcesContent":["import type { ActionPrompt, SeedPromptFunction } 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\nexport const defaultSeedPrompts: SeedPromptFunction = ({\n fieldLabel,\n fieldSchemaPaths,\n fieldType,\n path,\n}: {\n fieldLabel: string\n fieldSchemaPaths: any\n fieldType: string\n path: string\n}) => {\n return {\n prompt: `field-type: ${fieldType}\nfield-name: ${fieldLabel}\nschema-path: ${path}\n\nGive me a prompt that relate to the given field type and schema path.\n\nGenerated prompt:\n`,\n system: `# AI Assistant for CMS Prompt Generation\n\nYour role: Generate prompts for Content Management System (CMS) fields based on field-type and schema-path.\n\n## Key Guidelines:\n- Tailor prompts to specific field-type and purpose\n- Use schema-path for context\n- Include \" {{ title }} \" in every prompt\n- Be clear, concise, and instructive\n- Focus on content generation, not user perspective\n- For Image, Voice, or Banner fields, use provided example prompts verbatim\n- Image, Banner prompt MUST NOT CONTAIN ANY TYPOGRAPHY/TEXT DETAILS\n\n## Field Types and Prompts:\n\n1. richText:\n - Craft detailed, structured content\n - Include intro, sections, body, formatting, and conclusion\n - Aim for engaging, informative, and valuable content\n\n2. text:\n - For titles: Generate concise, engaging titles\n - For keywords: List relevant SEO terms\n\n3. textarea:\n - Provide comprehensive details (e.g., event information)\n\n4. upload:\n - Describe high-quality images or media\n\n## Schema-path Examples:\n- posts.title: Blog/article title\n- products.name: Product name\n\n## Must Follow:\n- Adapt prompts to schema-path context\n- Generate content directly, avoid personal pronouns\n- Use provided examples as guidelines\n\n### Examples for each field type along with generated prompt:\n\nFor richText:\n field-type: richText\n field-name: Content\n schema-path: posts.content\n Generated prompt: Craft compelling content for a blog post with the title \" {{ title }} \". Develop a well-structured narrative that captivates readers from start to finish. Incorporate the following elements to create a polished and engaging piece:\n\n- Engaging introduction that hooks the reader\n- Clearly defined sections with relevant subheadings\n- Well-researched and informative body paragraphs\n- Creative use of formatting to enhance readability (e.g., bullet points, blockquotes, italics, headings, bolds, other text formats)\n- Compelling conclusion that reinforces the main theme\n- Make the format easily digestible and clear for enhanced readability and improved CTR. \n- The user should be engaged, consistently interested, and feel that they’ve gained the knowledge they were seeking. \n\nInfuse the content with your expertise and a touch of personality to make it both informative and enjoyable to read. Aim to provide value to your target audience while maintaining a professional tone that aligns with the blog's overall style.\nFeel free to incorporate relevant anecdotes, statistics, or examples to support your points and add depth to the post. Remember, the goal is to create content that not only informs but also inspires and entertains your readers.\n\nFor text:\n field-type: text\n field-name: title\n schema-path: posts.title\n Generated prompt: Generate a captivating title for the blog post based on \" {{ title }} \" that effectively encapsulates the main theme and draws in readers. The title should be concise, engaging, and relevant to the content being presented. If no input is provided then generate creative title.\n\nFor text:\n field-type: text\n field-name: keywords\n schema-path: posts.keywords\n Generated prompt: Identify and list relevant keywords for the blog post titled \" {{ title }} \". Focus on terms that enhance search engine optimization and accurately reflect the main themes and topics of the content.\nkeywords will with comma separated.\n\n\nFor textarea:\n field-type: textarea:\n field-name: details\n schema-path: posts.details\n Generated prompt: Provide comprehensive details for the event \" {{ title }} \". Include essential information such as date, time, location, and any specific instructions or requirements.\n\nFor upload:\n field-type: upload\n field-name: Featured Image\n schema-path: posts.image\n Generated prompt: Imagine {{ title }}\n\nFor upload:\n field-type: upload\n field-name: Voice\n schema-path: posts.upload\n Generated prompt: {{ title }} {{ toHTML schema-path here... }}\n\n\nRemember to adapt the prompts based on the specific schema-path provided, considering the context and purpose of the field within the CMS structure. The prompts should directly instruct the AI model on what content to generate or describe, without assuming a user perspective.\n\nSchema Map Context:\n${JSON.stringify(fieldSchemaPaths)}\n\n${defaultSystemPrompt}\n`,\n }\n}\n"],"names":["defaultSystemPrompt","defaultPrompts","name","system","prompt","systemPrompt","layout","locale","defaultSeedPrompts","fieldLabel","fieldSchemaPaths","fieldType","path","JSON","stringify"],"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,2BA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@@
1
- import type { JSONSchema7 } from 'json-schema';
2
- export interface LexicalNodeSchema extends JSONSchema7 {
1
+ import type { JSONSchema } from 'openai/lib/jsonschema';
2
+ export interface LexicalNodeSchema extends JSONSchema {
3
+ $schema?: string;
3
4
  additionalProperties?: boolean;
5
+ definitions?: Record<string, any>;
4
6
  properties: {
5
7
  [key: string]: any;
6
8
  children?: {
@@ -21,5 +23,4 @@ export interface LexicalNodeSchema extends JSONSchema7 {
21
23
  type: 'object';
22
24
  }
23
25
  export declare const documentSchema: LexicalNodeSchema;
24
- export declare const lexicalJsonSchema: (customNodes?: any[]) => LexicalNodeSchema;
25
- //# sourceMappingURL=lexicalJsonSchema.d.ts.map
26
+ export declare const lexicalJsonSchema: (customNodes: JSONSchema[] | undefined) => LexicalNodeSchema;
@@ -704,12 +704,14 @@ export const documentSchema = {
704
704
  'root'
705
705
  ]
706
706
  };
707
- export const lexicalJsonSchema = (customNodes = [])=>{
707
+ export const lexicalJsonSchema = (customNodes)=>{
708
708
  const schema = structuredClone(documentSchema);
709
709
  if (Array.isArray(customNodes) && customNodes.length > 0) {
710
710
  customNodes.forEach((nodeObj)=>{
711
711
  for (const [nodeName, nodeDefinition] of Object.entries(nodeObj)){
712
+ // @ts-ignore
712
713
  schema.definitions[nodeName] = nodeDefinition;
714
+ // @ts-ignore
713
715
  const rootNode = schema.definitions['RootNode'];
714
716
  if (isObjectSchema(rootNode)) {
715
717
  const children = rootNode.properties?.children;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/ai/schemas/lexicalJsonSchema.ts"],"sourcesContent":["import type { JSONSchema7 } from 'json-schema'\n\nimport { isObjectSchema } from '../utils/isObjectSchema.js'\n\nexport interface LexicalNodeSchema extends JSONSchema7 {\n additionalProperties?: boolean\n properties: {\n [key: string]: any\n children?: {\n items: {\n $ref?: string\n anyOf?: { $ref: string }[]\n }\n type: 'array'\n }\n type?: {\n enum: string[]\n type: 'string'\n }\n }\n required?: string[]\n type: 'object'\n}\n\nexport const documentSchema: LexicalNodeSchema = {\n type: 'object',\n $schema: 'http://json-schema.org/draft-07/schema#',\n additionalProperties: false,\n definitions: {\n LineBreakNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['linebreak'] },\n version: { type: 'number' },\n },\n required: ['type', 'version'],\n },\n TabNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['tab'] },\n version: { type: 'number' },\n },\n required: ['type', 'version'],\n },\n // Text Node (Leaf Node)\n TextNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['text'] },\n detail: {\n type: 'number',\n description: 'Text detail flags',\n enum: [\n 0, // No details\n 1, // IS_DIRECTIONLESS\n 2, // IS_UNMERGEABLE\n 3, // IS_DIRECTIONLESS + IS_UNMERGEABLE\n ],\n examples: [\n { description: 'No special details', value: 0 },\n { description: 'Directionless', value: 1 },\n { description: 'Unmergeable', value: 2 },\n { description: 'Directionless + Unmergeable', value: 3 },\n ],\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n format: {\n type: 'number',\n description: `Format flags for text:\n 0 = No format\n 1 = Bold\n 2 = Italic\n 3 = Bold + Italic (1|2)\n 4 = Strikethrough\n 8 = Underline\n 9 = Bold + Underline (1|8)\n 16 = Code\n 32 = Subscript\n 64 = Superscript\n 128 = Highlight\n \n Formats can be combined using binary OR (|).\n Example combinations:\n - Bold + Italic = 1|2 = 3\n - Bold + Underline = 1|8 = 9\n - Italic + Underline = 2|8 = 10\n - Bold + Italic + Underline = 1|2|8 = 11`,\n },\n indent: { type: 'number' },\n mode: {\n type: 'number',\n description: 'Text mode flags',\n enum: [\n 0, // Normal\n 1, // Token\n 2, // Segmented\n ],\n examples: [\n { description: 'Normal text', value: 0 },\n { description: 'Token text', value: 1 },\n { description: 'Segmented text', value: 2 },\n ],\n },\n style: {\n type: 'string',\n description: 'CSS style string (e.g., \"color: red; font-size: 12px;\")',\n },\n text: { type: 'string' },\n version: { type: 'number' },\n },\n required: [\n 'type',\n 'text',\n 'format',\n 'style',\n 'mode',\n 'detail',\n 'direction',\n 'indent',\n 'version',\n ],\n },\n // Styled Table Cell Node\n TableCellNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['tablecell'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TextNode',\n },\n },\n colSpan: { type: 'number' },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n headerState: { type: 'number' },\n indent: { type: 'number' },\n version: { type: 'number' },\n width: {\n type: ['null'],\n enum: [null],\n },\n },\n required: [\n 'type',\n 'children',\n 'headerState',\n 'colSpan',\n 'width',\n 'direction',\n 'indent',\n 'version',\n ],\n },\n // Styled Table Row Node\n TableRowNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['tablerow'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TableCellNode',\n },\n },\n height: { type: 'number' },\n },\n required: ['type', 'children', 'height'],\n },\n // Styled Table Node\n TableNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['table'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TableRowNode',\n },\n },\n },\n required: ['type', 'children'],\n },\n // Heading Node\n HeadingNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['heading'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/LinkNode' },\n { $ref: '#/definitions/LineBreakNode' },\n { $ref: '#/definitions/TabNode' },\n ],\n },\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n indent: { type: 'number' },\n tag: { type: 'string', enum: ['h1', 'h2', 'h3'] },\n version: { type: 'number' },\n },\n required: ['type', 'tag', 'children', 'direction', 'indent', 'version'],\n },\n // Paragraph Node\n ParagraphNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['paragraph'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/LinkNode' },\n { $ref: '#/definitions/CodeNode' },\n { $ref: '#/definitions/LineBreakNode' },\n { $ref: '#/definitions/TabNode' },\n ],\n },\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n format: {\n type: 'string',\n description:\n 'Format alignment based on content. Prioritize \"start\", then \"center\", and use \"right\" only when appropriate.',\n enum: ['start', 'center', 'right'],\n },\n indent: { type: 'number' },\n textFormat: { type: 'number' },\n textStyle: {\n type: 'string',\n description: 'CSS style string (e.g., \"color: red; font-size: 12px;\")',\n },\n version: { type: 'number' },\n },\n required: [\n 'type',\n 'children',\n 'direction',\n 'format',\n 'indent',\n 'textFormat',\n 'textStyle',\n 'version',\n ],\n },\n // Link Node\n LinkNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['link'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TextNode',\n },\n },\n url: { type: 'string' },\n },\n required: ['type', 'url', 'children'],\n },\n // List Item Node\n ListItemNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n // NOTE: Do not change the position of \"indent\", models like gpt generate properties as they are\n // defined in schema, moving the position of property \"indent\"\n // can cause issue with schema validation while streaming generated json to lexical editor\n indent: { type: 'number', enum: [0, 1] },\n\n type: { type: 'string', enum: ['listitem'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/ParagraphNode' },\n { $ref: '#/definitions/ListNode' },\n { $ref: '#/definitions/LineBreakNode' },\n ],\n },\n },\n },\n required: ['indent', 'type', 'children'],\n },\n // List Node\n ListNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['list'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/ListItemNode',\n },\n },\n listType: { type: 'string', enum: ['bullet', 'number'] },\n },\n required: ['type', 'listType', 'children'],\n },\n // Quote Node\n QuoteNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['quote'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/ParagraphNode' },\n { $ref: '#/definitions/LineBreakNode' },\n { $ref: '#/definitions/TabNode' },\n ],\n },\n },\n },\n required: ['type', 'children'],\n },\n // Code Node\n CodeNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['code'] },\n code: { type: 'string' },\n language: { type: 'string' },\n },\n required: ['type', 'code', 'language'],\n },\n // Horizontal Rule Node\n HorizontalRuleNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['horizontalrule'] },\n },\n required: ['type'],\n },\n // Image Node\n ImageNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['image'] },\n alt: { type: 'string' },\n caption: {\n type: 'array',\n items: {\n $ref: '#/definitions/TextNode',\n },\n },\n src: { type: 'string' },\n },\n required: ['type', 'src', 'alt', 'caption'],\n },\n // Root Node\n RootNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['root'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/HeadingNode' },\n { $ref: '#/definitions/ParagraphNode' },\n { $ref: '#/definitions/LinkNode' },\n { $ref: '#/definitions/ListNode' },\n { $ref: '#/definitions/QuoteNode' },\n { $ref: '#/definitions/CodeNode' },\n { $ref: '#/definitions/HorizontalRuleNode' },\n { $ref: '#/definitions/ImageNode' },\n { $ref: '#/definitions/TableNode' },\n ],\n },\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n indent: { type: 'number' },\n version: { type: 'number' },\n },\n required: ['type', 'children', 'direction', 'indent', 'version'],\n },\n },\n properties: {\n root: {\n $ref: '#/definitions/RootNode',\n },\n },\n required: ['root'],\n}\n\nexport const lexicalJsonSchema = (customNodes = []) => {\n const schema = structuredClone(documentSchema)\n\n if (Array.isArray(customNodes) && customNodes.length > 0) {\n customNodes.forEach((nodeObj) => {\n for (const [nodeName, nodeDefinition] of Object.entries(nodeObj)) {\n schema.definitions[nodeName] = nodeDefinition\n\n const rootNode = schema.definitions['RootNode']\n if (isObjectSchema(rootNode)) {\n const children = rootNode.properties?.children\n const items = children?.items\n const anyOfList = (items as any)?.anyOf\n\n if (Array.isArray(anyOfList)) {\n anyOfList.push({ $ref: `#/definitions/${nodeName}` })\n }\n }\n }\n })\n }\n\n return schema\n}\n"],"names":["isObjectSchema","documentSchema","type","$schema","additionalProperties","definitions","LineBreakNode","properties","enum","version","required","TabNode","TextNode","detail","description","examples","value","direction","format","indent","mode","style","text","TableCellNode","children","items","$ref","colSpan","headerState","width","TableRowNode","height","TableNode","HeadingNode","anyOf","tag","ParagraphNode","textFormat","textStyle","LinkNode","url","ListItemNode","ListNode","listType","QuoteNode","CodeNode","code","language","HorizontalRuleNode","ImageNode","alt","caption","src","RootNode","root","lexicalJsonSchema","customNodes","schema","structuredClone","Array","isArray","length","forEach","nodeObj","nodeName","nodeDefinition","Object","entries","rootNode","anyOfList","push"],"mappings":"AAEA,SAASA,cAAc,QAAQ,6BAA4B;AAsB3D,OAAO,MAAMC,iBAAoC;IAC/CC,MAAM;IACNC,SAAS;IACTC,sBAAsB;IACtBC,aAAa;QACXC,eAAe;YACbJ,MAAM;YACNE,sBAAsB;YACtBG,YAAY;gBACVL,MAAM;oBAAEA,MAAM;oBAAUM,MAAM;wBAAC;qBAAY;gBAAC;gBAC5CC,SAAS;oBAAEP,MAAM;gBAAS;YAC5B;YACAQ,UAAU;gBAAC;gBAAQ;aAAU;QAC/B;QACAC,SAAS;YACPT,MAAM;YACNE,sBAAsB;YACtBG,YAAY;gBACVL,MAAM;oBAAEA,MAAM;oBAAUM,MAAM;wBAAC;qBAAM;gBAAC;gBACtCC,SAAS;oBAAEP,MAAM;gBAAS;YAC5B;YACAQ,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IAEA,OAAOP;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/ai/schemas/lexicalJsonSchema.ts"],"sourcesContent":["import type { JSONSchema } from 'openai/lib/jsonschema'\n\nimport { isObjectSchema } from '../utils/isObjectSchema.js'\n\nexport interface LexicalNodeSchema extends JSONSchema {\n $schema?: string\n additionalProperties?: boolean\n definitions?: Record<string, any>\n properties: {\n [key: string]: any\n children?: {\n items: {\n $ref?: string\n anyOf?: { $ref: string }[]\n }\n type: 'array'\n }\n type?: {\n enum: string[]\n type: 'string'\n }\n }\n required?: string[]\n type: 'object'\n}\n\nexport const documentSchema: LexicalNodeSchema = {\n type: 'object',\n $schema: 'http://json-schema.org/draft-07/schema#',\n additionalProperties: false,\n definitions: {\n LineBreakNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['linebreak'] },\n version: { type: 'number' },\n },\n required: ['type', 'version'],\n },\n TabNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['tab'] },\n version: { type: 'number' },\n },\n required: ['type', 'version'],\n },\n // Text Node (Leaf Node)\n TextNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['text'] },\n detail: {\n type: 'number',\n description: 'Text detail flags',\n enum: [\n 0, // No details\n 1, // IS_DIRECTIONLESS\n 2, // IS_UNMERGEABLE\n 3, // IS_DIRECTIONLESS + IS_UNMERGEABLE\n ],\n examples: [\n { description: 'No special details', value: 0 },\n { description: 'Directionless', value: 1 },\n { description: 'Unmergeable', value: 2 },\n { description: 'Directionless + Unmergeable', value: 3 },\n ],\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n format: {\n type: 'number',\n description: `Format flags for text:\n 0 = No format\n 1 = Bold\n 2 = Italic\n 3 = Bold + Italic (1|2)\n 4 = Strikethrough\n 8 = Underline\n 9 = Bold + Underline (1|8)\n 16 = Code\n 32 = Subscript\n 64 = Superscript\n 128 = Highlight\n \n Formats can be combined using binary OR (|).\n Example combinations:\n - Bold + Italic = 1|2 = 3\n - Bold + Underline = 1|8 = 9\n - Italic + Underline = 2|8 = 10\n - Bold + Italic + Underline = 1|2|8 = 11`,\n },\n indent: { type: 'number' },\n mode: {\n type: 'number',\n description: 'Text mode flags',\n enum: [\n 0, // Normal\n 1, // Token\n 2, // Segmented\n ],\n examples: [\n { description: 'Normal text', value: 0 },\n { description: 'Token text', value: 1 },\n { description: 'Segmented text', value: 2 },\n ],\n },\n style: {\n type: 'string',\n description: 'CSS style string (e.g., \"color: red; font-size: 12px;\")',\n },\n text: { type: 'string' },\n version: { type: 'number' },\n },\n required: [\n 'type',\n 'text',\n 'format',\n 'style',\n 'mode',\n 'detail',\n 'direction',\n 'indent',\n 'version',\n ],\n },\n // Styled Table Cell Node\n TableCellNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['tablecell'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TextNode',\n },\n },\n colSpan: { type: 'number' },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n headerState: { type: 'number' },\n indent: { type: 'number' },\n version: { type: 'number' },\n width: {\n type: ['null'],\n enum: [null],\n },\n },\n required: [\n 'type',\n 'children',\n 'headerState',\n 'colSpan',\n 'width',\n 'direction',\n 'indent',\n 'version',\n ],\n },\n // Styled Table Row Node\n TableRowNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['tablerow'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TableCellNode',\n },\n },\n height: { type: 'number' },\n },\n required: ['type', 'children', 'height'],\n },\n // Styled Table Node\n TableNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['table'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TableRowNode',\n },\n },\n },\n required: ['type', 'children'],\n },\n // Heading Node\n HeadingNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['heading'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/LinkNode' },\n { $ref: '#/definitions/LineBreakNode' },\n { $ref: '#/definitions/TabNode' },\n ],\n },\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n indent: { type: 'number' },\n tag: { type: 'string', enum: ['h1', 'h2', 'h3'] },\n version: { type: 'number' },\n },\n required: ['type', 'tag', 'children', 'direction', 'indent', 'version'],\n },\n // Paragraph Node\n ParagraphNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['paragraph'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/LinkNode' },\n { $ref: '#/definitions/CodeNode' },\n { $ref: '#/definitions/LineBreakNode' },\n { $ref: '#/definitions/TabNode' },\n ],\n },\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n format: {\n type: 'string',\n description:\n 'Format alignment based on content. Prioritize \"start\", then \"center\", and use \"right\" only when appropriate.',\n enum: ['start', 'center', 'right'],\n },\n indent: { type: 'number' },\n textFormat: { type: 'number' },\n textStyle: {\n type: 'string',\n description: 'CSS style string (e.g., \"color: red; font-size: 12px;\")',\n },\n version: { type: 'number' },\n },\n required: [\n 'type',\n 'children',\n 'direction',\n 'format',\n 'indent',\n 'textFormat',\n 'textStyle',\n 'version',\n ],\n },\n // Link Node\n LinkNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['link'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TextNode',\n },\n },\n url: { type: 'string' },\n },\n required: ['type', 'url', 'children'],\n },\n // List Item Node\n ListItemNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n // NOTE: Do not change the position of \"indent\", models like gpt generate properties as they are\n // defined in schema, moving the position of property \"indent\"\n // can cause issue with schema validation while streaming generated json to lexical editor\n indent: { type: 'number', enum: [0, 1] },\n\n type: { type: 'string', enum: ['listitem'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/ParagraphNode' },\n { $ref: '#/definitions/ListNode' },\n { $ref: '#/definitions/LineBreakNode' },\n ],\n },\n },\n },\n required: ['indent', 'type', 'children'],\n },\n // List Node\n ListNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['list'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/ListItemNode',\n },\n },\n listType: { type: 'string', enum: ['bullet', 'number'] },\n },\n required: ['type', 'listType', 'children'],\n },\n // Quote Node\n QuoteNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['quote'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/ParagraphNode' },\n { $ref: '#/definitions/LineBreakNode' },\n { $ref: '#/definitions/TabNode' },\n ],\n },\n },\n },\n required: ['type', 'children'],\n },\n // Code Node\n CodeNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['code'] },\n code: { type: 'string' },\n language: { type: 'string' },\n },\n required: ['type', 'code', 'language'],\n },\n // Horizontal Rule Node\n HorizontalRuleNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['horizontalrule'] },\n },\n required: ['type'],\n },\n // Image Node\n ImageNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['image'] },\n alt: { type: 'string' },\n caption: {\n type: 'array',\n items: {\n $ref: '#/definitions/TextNode',\n },\n },\n src: { type: 'string' },\n },\n required: ['type', 'src', 'alt', 'caption'],\n },\n // Root Node\n RootNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['root'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/HeadingNode' },\n { $ref: '#/definitions/ParagraphNode' },\n { $ref: '#/definitions/LinkNode' },\n { $ref: '#/definitions/ListNode' },\n { $ref: '#/definitions/QuoteNode' },\n { $ref: '#/definitions/CodeNode' },\n { $ref: '#/definitions/HorizontalRuleNode' },\n { $ref: '#/definitions/ImageNode' },\n { $ref: '#/definitions/TableNode' },\n ],\n },\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n indent: { type: 'number' },\n version: { type: 'number' },\n },\n required: ['type', 'children', 'direction', 'indent', 'version'],\n },\n },\n properties: {\n root: {\n $ref: '#/definitions/RootNode',\n },\n },\n required: ['root'],\n}\n\nexport const lexicalJsonSchema = (customNodes: JSONSchema[] | undefined) => {\n const schema = structuredClone(documentSchema)\n\n if (Array.isArray(customNodes) && customNodes.length > 0) {\n customNodes.forEach((nodeObj) => {\n for (const [nodeName, nodeDefinition] of Object.entries(nodeObj)) {\n // @ts-ignore\n schema.definitions[nodeName] = nodeDefinition\n\n // @ts-ignore\n const rootNode = schema.definitions['RootNode']\n if (isObjectSchema(rootNode)) {\n const children = rootNode.properties?.children\n const items = children?.items\n const anyOfList = (items as any)?.anyOf\n\n if (Array.isArray(anyOfList)) {\n anyOfList.push({ $ref: `#/definitions/${nodeName}` })\n }\n }\n }\n })\n }\n\n return schema\n}\n"],"names":["isObjectSchema","documentSchema","type","$schema","additionalProperties","definitions","LineBreakNode","properties","enum","version","required","TabNode","TextNode","detail","description","examples","value","direction","format","indent","mode","style","text","TableCellNode","children","items","$ref","colSpan","headerState","width","TableRowNode","height","TableNode","HeadingNode","anyOf","tag","ParagraphNode","textFormat","textStyle","LinkNode","url","ListItemNode","ListNode","listType","QuoteNode","CodeNode","code","language","HorizontalRuleNode","ImageNode","alt","caption","src","RootNode","root","lexicalJsonSchema","customNodes","schema","structuredClone","Array","isArray","length","forEach","nodeObj","nodeName","nodeDefinition","Object","entries","rootNode","anyOfList","push"],"mappings":"AAEA,SAASA,cAAc,QAAQ,6BAA4B;AAwB3D,OAAO,MAAMC,iBAAoC;IAC/CC,M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OC,OAAO,CAACJ,SAAU;gBAChE,aAAa;gBACbN,OAAOpD,WAAW,CAAC2D,SAAS,GAAGC;gBAE/B,aAAa;gBACb,MAAMG,WAAWX,OAAOpD,WAAW,CAAC,WAAW;gBAC/C,IAAIL,eAAeoE,WAAW;oBAC5B,MAAM5C,WAAW4C,SAAS7D,UAAU,EAAEiB;oBACtC,MAAMC,QAAQD,UAAUC;oBACxB,MAAM4C,YAAa5C,OAAeS;oBAElC,IAAIyB,MAAMC,OAAO,CAACS,YAAY;wBAC5BA,UAAUC,IAAI,CAAC;4BAAE5C,MAAM,CAAC,cAAc,EAAEsC,UAAU;wBAAC;oBACrD;gBACF;YACF;QACF;IACF;IAEA,OAAOP;AACT,EAAC"}
@@ -8,4 +8,3 @@ import type { ImageReference } from '../../types.js';
8
8
  * @note: Remove this function, once https://github.com/openai/openai-node/issues/1492 is fixed.
9
9
  */
10
10
  export declare function editImagesWithOpenAI(images: ImageReference[], prompt: string, model?: string): Promise<any>;
11
- //# sourceMappingURL=editImagesWithOpenAI.d.ts.map
@@ -1,6 +1,7 @@
1
1
  import type { LexicalNodeSchema } from '../schemas/lexicalJsonSchema.js';
2
- export declare function filterEditorSchemaByNodes(schema: LexicalNodeSchema, allowedNodes: any): {
3
- definitions: {};
2
+ export declare function filterEditorSchemaByNodes(schema: LexicalNodeSchema, allowedNodes: string[]): {
3
+ definitions: Record<string, any>;
4
+ $schema?: string;
4
5
  additionalProperties?: boolean;
5
6
  properties: {
6
7
  [key: string]: any;
@@ -21,14 +22,9 @@ export declare function filterEditorSchemaByNodes(schema: LexicalNodeSchema, all
21
22
  required?: string[];
22
23
  type: "object";
23
24
  $id?: string | undefined;
24
- $ref?: string | undefined;
25
- $schema?: import("json-schema").JSONSchema7Version | undefined;
26
25
  $comment?: string | undefined;
27
- $defs?: {
28
- [key: string]: import("json-schema").JSONSchema7Definition;
29
- } | undefined;
30
- enum?: import("json-schema").JSONSchema7Type[] | undefined;
31
- const?: import("json-schema").JSONSchema7Type | undefined;
26
+ enum?: import("openai/lib/jsonschema.mjs").JSONSchemaType[] | undefined;
27
+ const?: import("openai/lib/jsonschema.mjs").JSONSchemaType | undefined;
32
28
  multipleOf?: number | undefined;
33
29
  maximum?: number | undefined;
34
30
  exclusiveMaximum?: number | undefined;
@@ -37,36 +33,30 @@ export declare function filterEditorSchemaByNodes(schema: LexicalNodeSchema, all
37
33
  maxLength?: number | undefined;
38
34
  minLength?: number | undefined;
39
35
  pattern?: string | undefined;
40
- items?: import("json-schema").JSONSchema7Definition | import("json-schema").JSONSchema7Definition[] | undefined;
41
- additionalItems?: import("json-schema").JSONSchema7Definition | undefined;
36
+ items?: import("openai/lib/jsonschema.mjs").JSONSchemaDefinition | import("openai/lib/jsonschema.mjs").JSONSchemaDefinition[] | undefined;
37
+ additionalItems?: import("openai/lib/jsonschema.mjs").JSONSchemaDefinition | undefined;
42
38
  maxItems?: number | undefined;
43
39
  minItems?: number | undefined;
44
40
  uniqueItems?: boolean | undefined;
45
- contains?: import("json-schema").JSONSchema7Definition | undefined;
41
+ contains?: import("openai/lib/jsonschema.mjs").JSONSchemaDefinition | undefined;
46
42
  maxProperties?: number | undefined;
47
43
  minProperties?: number | undefined;
48
44
  patternProperties?: {
49
- [key: string]: import("json-schema").JSONSchema7Definition;
50
- } | undefined;
51
- dependencies?: {
52
- [key: string]: import("json-schema").JSONSchema7Definition | string[];
45
+ [key: string]: import("openai/lib/jsonschema.mjs").JSONSchemaDefinition;
53
46
  } | undefined;
54
- propertyNames?: import("json-schema").JSONSchema7Definition | undefined;
55
- if?: import("json-schema").JSONSchema7Definition | undefined;
56
- then?: import("json-schema").JSONSchema7Definition | undefined;
57
- else?: import("json-schema").JSONSchema7Definition | undefined;
58
- allOf?: import("json-schema").JSONSchema7Definition[] | undefined;
59
- anyOf?: import("json-schema").JSONSchema7Definition[] | undefined;
60
- oneOf?: import("json-schema").JSONSchema7Definition[] | undefined;
61
- not?: import("json-schema").JSONSchema7Definition | undefined;
47
+ propertyNames?: import("openai/lib/jsonschema.mjs").JSONSchemaDefinition | undefined;
48
+ if?: import("openai/lib/jsonschema.mjs").JSONSchemaDefinition | undefined;
49
+ then?: import("openai/lib/jsonschema.mjs").JSONSchemaDefinition | undefined;
50
+ else?: import("openai/lib/jsonschema.mjs").JSONSchemaDefinition | undefined;
51
+ allOf?: import("openai/lib/jsonschema.mjs").JSONSchemaDefinition[] | undefined;
52
+ anyOf?: import("openai/lib/jsonschema.mjs").JSONSchemaDefinition[] | undefined;
53
+ oneOf?: import("openai/lib/jsonschema.mjs").JSONSchemaDefinition[] | undefined;
54
+ not?: import("openai/lib/jsonschema.mjs").JSONSchemaDefinition | undefined;
62
55
  format?: string | undefined;
63
- contentMediaType?: string | undefined;
64
- contentEncoding?: string | undefined;
65
56
  title?: string | undefined;
66
57
  description?: string | undefined;
67
- default?: import("json-schema").JSONSchema7Type | undefined;
58
+ default?: import("openai/lib/jsonschema.mjs").JSONSchemaType | undefined;
68
59
  readOnly?: boolean | undefined;
69
60
  writeOnly?: boolean | undefined;
70
- examples?: import("json-schema").JSONSchema7Type | undefined;
61
+ examples?: import("openai/lib/jsonschema.mjs").JSONSchemaType | undefined;
71
62
  };
72
- //# sourceMappingURL=filterEditorSchemaByNodes.d.ts.map
@@ -3,7 +3,7 @@ export function filterEditorSchemaByNodes(schema, allowedNodes) {
3
3
  const allowedTypes = new Set(allowedNodes);
4
4
  const filteredDefinitions = {};
5
5
  // First pass: collect definitions whose "type.enum" includes an allowed type
6
- for (const [key, def] of Object.entries(schema.definitions)){
6
+ for (const [key, def] of Object.entries(schema.definitions ?? {})){
7
7
  if (isObjectSchema(def)) {
8
8
  const typeEnum = def.properties?.type?.enum;
9
9
  if (typeEnum && typeEnum.some((t)=>allowedTypes.has(t))) {
@@ -13,7 +13,9 @@ export function filterEditorSchemaByNodes(schema, allowedNodes) {
13
13
  }
14
14
  // Helper to check if a $ref points to an allowed definition
15
15
  const isAllowedRef = (ref)=>{
16
- if (typeof ref !== 'string') return false;
16
+ if (typeof ref !== 'string') {
17
+ return false;
18
+ }
17
19
  const defName = ref.replace('#/definitions/', '');
18
20
  return defName in filteredDefinitions;
19
21
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/ai/utils/filterEditorSchemaByNodes.ts"],"sourcesContent":["import type { LexicalNodeSchema } from '../schemas/lexicalJsonSchema.js'\n\nimport { isObjectSchema } from './isObjectSchema.js'\n\nexport function filterEditorSchemaByNodes(schema: LexicalNodeSchema, allowedNodes) {\n const allowedTypes = new Set(allowedNodes)\n\n const filteredDefinitions = {}\n\n // First pass: collect definitions whose \"type.enum\" includes an allowed type\n for (const [key, def] of Object.entries(schema.definitions)) {\n if(isObjectSchema(def)) {\n const typeEnum = def.properties?.type?.enum\n if (typeEnum && typeEnum.some((t) => allowedTypes.has(t))) {\n filteredDefinitions[key] = JSON.parse(JSON.stringify(def)) // Deep copy to safely mutate\n }\n }\n }\n\n // Helper to check if a $ref points to an allowed definition\n const isAllowedRef = (ref) => {\n if (typeof ref !== 'string') return false\n const defName = ref.replace('#/definitions/', '')\n return defName in filteredDefinitions\n }\n\n // Second pass: update \"children\" in each definition to only include allowed refs\n for (const def of Object.values(filteredDefinitions)) {\n if (isObjectSchema(def) && def.properties?.children?.items) {\n const items = def.properties.children.items\n\n if (Array.isArray(items.anyOf)) {\n // Filter anyOf to only allowed $refs\n items.anyOf = items.anyOf.filter((entry) => isAllowedRef(entry.$ref))\n if (items.anyOf.length === 0) {\n delete def.properties.children\n }\n } else if (items.$ref && !isAllowedRef(items.$ref)) {\n delete def.properties.children\n }\n }\n }\n\n // Return the new schema with pruned definitions\n return {\n ...schema,\n definitions: filteredDefinitions,\n }\n}\n"],"names":["isObjectSchema","filterEditorSchemaByNodes","schema","allowedNodes","allowedTypes","Set","filteredDefinitions","key","def","Object","entries","definitions","typeEnum","properties","type","enum","some","t","has","JSON","parse","stringify","isAllowedRef","ref","defName","replace","values","children","items","Array","isArray","anyOf","filter","entry","$ref","length"],"mappings":"AAEA,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ChC;QACF;IACF;IAEA,gDAAgD;IAChD,OAAO;QACL,GAAGzB,MAAM;QACTS,aAAaL;IACf;AACF"}
1
+ {"version":3,"sources":["../../../src/ai/utils/filterEditorSchemaByNodes.ts"],"sourcesContent":["import type { LexicalNodeSchema } from '../schemas/lexicalJsonSchema.js'\n\nimport { isObjectSchema } from './isObjectSchema.js'\n\nexport function filterEditorSchemaByNodes(schema: LexicalNodeSchema, allowedNodes: string[]) {\n const allowedTypes = new Set(allowedNodes)\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) => allowedTypes.has(t))) {\n filteredDefinitions[key] = JSON.parse(JSON.stringify(def)) // Deep copy to safely mutate\n }\n }\n }\n\n // Helper to check if a $ref points to an allowed definition\n const isAllowedRef = (ref: 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","filterEditorSchemaByNodes","schema","allowedNodes","allowedTypes","Set","filteredDefinitions","key","def","Object","entries","definitions","typeEnum","properties","type","enum","some","t","has","JSON","parse","stringify","isAllowedRef","ref","defName","replace","values","children","items","Array","isArray","anyOf","filter","entry","$ref","length"],"mappings":"AAEA,S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AU,CAACc,QAAQ;YAChC;QACF;IACF;IAEA,gDAAgD;IAChD,OAAO;QACL,GAAGzB,MAAM;QACTS,aAAaL;IACf;AACF"}
@@ -1,2 +1 @@
1
- export declare function generateFileNameByPrompt(prompt: any): string;
2
- //# sourceMappingURL=generateFileNameByPrompt.d.ts.map
1
+ export declare function generateFileNameByPrompt(prompt: string): string;