@ai-stack/payloadcms 3.2.7-beta → 3.2.9-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 (85) hide show
  1. package/README.md +22 -2
  2. package/dist/ai/models/index.d.ts +1 -1
  3. package/dist/ai/models/index.d.ts.map +1 -1
  4. package/dist/ai/models/index.js +1 -1
  5. package/dist/ai/models/index.js.map +1 -1
  6. package/dist/ai/models/openai/generateRichText.d.ts.map +1 -1
  7. package/dist/ai/models/openai/generateRichText.js +1 -1
  8. package/dist/ai/models/openai/generateRichText.js.map +1 -1
  9. package/dist/ai/models/openai/index.d.ts.map +1 -1
  10. package/dist/ai/models/openai/index.js +1 -1
  11. package/dist/ai/models/openai/index.js.map +1 -1
  12. package/dist/ai/models/openai/openai.d.ts +2 -0
  13. package/dist/ai/models/openai/openai.d.ts.map +1 -0
  14. package/dist/ai/models/openai/openai.js +9 -0
  15. package/dist/ai/models/openai/openai.js.map +1 -0
  16. package/dist/ai/schemas/lexicalJsonSchema.d.ts +373 -1
  17. package/dist/ai/schemas/lexicalJsonSchema.d.ts.map +1 -1
  18. package/dist/ai/schemas/lexicalJsonSchema.js +13 -9
  19. package/dist/ai/schemas/lexicalJsonSchema.js.map +1 -1
  20. package/dist/ai/utils/systemGenerate.d.ts +1 -1
  21. package/dist/ai/utils/systemGenerate.d.ts.map +1 -1
  22. package/dist/ai/utils/systemGenerate.js +6 -2
  23. package/dist/ai/utils/systemGenerate.js.map +1 -1
  24. package/dist/collections/Instructions.d.ts +2 -1
  25. package/dist/collections/Instructions.d.ts.map +1 -1
  26. package/dist/collections/Instructions.js +36 -46
  27. package/dist/collections/Instructions.js.map +1 -1
  28. package/dist/endpoints/fetchFields.d.ts +2 -1
  29. package/dist/endpoints/fetchFields.d.ts.map +1 -1
  30. package/dist/endpoints/fetchFields.js +33 -17
  31. package/dist/endpoints/fetchFields.js.map +1 -1
  32. package/dist/endpoints/index.d.ts +2 -2
  33. package/dist/endpoints/index.d.ts.map +1 -1
  34. package/dist/endpoints/index.js +97 -96
  35. package/dist/endpoints/index.js.map +1 -1
  36. package/dist/exports/types.d.ts +1 -1
  37. package/dist/exports/types.d.ts.map +1 -1
  38. package/dist/exports/types.js.map +1 -1
  39. package/dist/fields/ComposeField/ComposeField.js +3 -2
  40. package/dist/fields/ComposeField/ComposeField.js.map +1 -1
  41. package/dist/fields/LexicalEditor/ComposeFeatureComponent.d.ts.map +1 -1
  42. package/dist/fields/LexicalEditor/ComposeFeatureComponent.js +3 -2
  43. package/dist/fields/LexicalEditor/ComposeFeatureComponent.js.map +1 -1
  44. package/dist/fields/LexicalEditor/feature.server.d.ts.map +1 -1
  45. package/dist/fields/LexicalEditor/feature.server.js +2 -3
  46. package/dist/fields/LexicalEditor/feature.server.js.map +1 -1
  47. package/dist/fields/PromptEditorField/PromptEditorField.d.ts.map +1 -1
  48. package/dist/fields/PromptEditorField/PromptEditorField.js +5 -1
  49. package/dist/fields/PromptEditorField/PromptEditorField.js.map +1 -1
  50. package/dist/init.d.ts.map +1 -1
  51. package/dist/init.js +10 -6
  52. package/dist/init.js.map +1 -1
  53. package/dist/libraries/handlebars/replacePlaceholders.d.ts +1 -1
  54. package/dist/libraries/handlebars/replacePlaceholders.d.ts.map +1 -1
  55. package/dist/libraries/handlebars/replacePlaceholders.js.map +1 -1
  56. package/dist/plugin.d.ts.map +1 -1
  57. package/dist/plugin.js +11 -6
  58. package/dist/plugin.js.map +1 -1
  59. package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts +1 -0
  60. package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts.map +1 -1
  61. package/dist/providers/InstructionsProvider/InstructionsProvider.js +11 -4
  62. package/dist/providers/InstructionsProvider/InstructionsProvider.js.map +1 -1
  63. package/dist/types.d.ts +13 -2
  64. package/dist/types.d.ts.map +1 -1
  65. package/dist/types.js.map +1 -1
  66. package/dist/ui/Compose/Compose.d.ts +2 -1
  67. package/dist/ui/Compose/Compose.d.ts.map +1 -1
  68. package/dist/ui/Compose/Compose.js +5 -4
  69. package/dist/ui/Compose/Compose.js.map +1 -1
  70. package/dist/ui/Compose/hooks/menu/TranslateMenu.d.ts.map +1 -1
  71. package/dist/ui/Compose/hooks/menu/TranslateMenu.js +4 -0
  72. package/dist/ui/Compose/hooks/menu/TranslateMenu.js.map +1 -1
  73. package/dist/ui/Compose/hooks/menu/useMenu.d.ts +2 -2
  74. package/dist/ui/Compose/hooks/menu/useMenu.d.ts.map +1 -1
  75. package/dist/ui/Compose/hooks/menu/useMenu.js +8 -4
  76. package/dist/ui/Compose/hooks/menu/useMenu.js.map +1 -1
  77. package/dist/utilities/getGenerationModels.d.ts +3 -0
  78. package/dist/utilities/getGenerationModels.d.ts.map +1 -0
  79. package/dist/utilities/getGenerationModels.js +10 -0
  80. package/dist/utilities/getGenerationModels.js.map +1 -0
  81. package/dist/utilities/isPluginActivated.d.ts +2 -1
  82. package/dist/utilities/isPluginActivated.d.ts.map +1 -1
  83. package/dist/utilities/isPluginActivated.js +3 -2
  84. package/dist/utilities/isPluginActivated.js.map +1 -1
  85. package/package.json +6 -6
package/README.md CHANGED
@@ -37,7 +37,9 @@ Want to dive deeper?
37
37
  - 🖼️ **Image Generation** powered by OpenAI
38
38
 
39
39
  ### Other Features
40
+ - 🔌 **Bring your own model** ([Setup guide](https://github.com/ashbuilds/payload-ai/blob/main/guide.md#5-add-custom-model))
40
41
  - 🎛️ **Field-level Prompt Customization**
42
+ - 🔐 **Access Control Support**
41
43
  - 🧠 **Prompt Editor** (Beta)
42
44
  - 📊 **Document Analyzer** (Coming Soon)
43
45
  - ✅ **Fact Checking** (Coming Soon)
@@ -79,7 +81,15 @@ export default buildConfig({
79
81
  [Posts.slug]: true,
80
82
  },
81
83
  debugging: false,
82
- disableSponsorMessage: false
84
+ disableSponsorMessage: false,
85
+
86
+ /* Enable to restrict access to AI plugin settings only to admin users
87
+ access: {
88
+ settings: ({ req }: { req: PayloadRequest }) => {
89
+ return req.user?.role === 'admin';
90
+ },
91
+ },
92
+ */
83
93
  }),
84
94
  ],
85
95
  // ... your existing Payload configuration
@@ -120,8 +130,18 @@ OPENAI_API_KEY=your-openai-api-key
120
130
  ANTHROPIC_API_KEY=your-anthropic-api-key
121
131
  ELEVENLABS_API_KEY=your-elevenlabs-api-key
122
132
  ```
123
- For detailed guidance on personalizing and configuring the plugin to match your needs, check out the **[Complete Guide](guide.md)**. It walks you through every step, from setting up fields to generating amazing content!
124
133
 
134
+ > **⚠️ Important:** Once you've configured or installed this plugin, a server restart is required to activate the changes.
135
+
136
+ ### OpenAI Endpoint
137
+
138
+ If you want to use a custom endpoint for the OpenAI provider, set your base URL like this:
139
+ ```
140
+ OPENAI_BASE_URL=https://api.openai.com/v1
141
+ ```
142
+ If not specified, the [default](src/ai/models/openai/openai.ts) OpenAI endpoint will be used.
143
+
144
+ For detailed guidance on personalizing and configuring the plugin to match your needs, check out the **[Complete Guide](guide.md)**. It walks you through every step, from setting up fields to generating amazing content!
125
145
 
126
146
  ### Enabling AI for Custom Components
127
147
 
@@ -1,3 +1,3 @@
1
1
  import type { GenerationModel } from '../../types.js';
2
- export declare const GenerationModels: GenerationModel[];
2
+ export declare const defaultGenerationModels: GenerationModel[];
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ai/models/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAMrD,eAAO,MAAM,gBAAgB,EAAE,eAAe,EAI7C,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ai/models/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAMrD,eAAO,MAAM,uBAAuB,EAAE,eAAe,EAIpD,CAAA"}
@@ -2,7 +2,7 @@ import * as process from 'node:process';
2
2
  import { AnthropicConfig } from './anthropic/index.js';
3
3
  import { ElevenLabsConfig } from './elevenLabs/index.js';
4
4
  import { OpenAIConfig } from './openai/index.js';
5
- export const GenerationModels = [
5
+ export const defaultGenerationModels = [
6
6
  ...process.env.OPENAI_API_KEY ? OpenAIConfig.models : [],
7
7
  ...process.env.ANTHROPIC_API_KEY ? AnthropicConfig.models : [],
8
8
  ...process.env.ELEVENLABS_API_KEY ? ElevenLabsConfig.models : []
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/ai/models/index.ts"],"sourcesContent":["import * as process from 'node:process'\n\nimport type { GenerationModel } from '../../types.js'\n\nimport { AnthropicConfig } from './anthropic/index.js'\nimport { ElevenLabsConfig } from './elevenLabs/index.js'\nimport { OpenAIConfig } from './openai/index.js'\n\nexport const GenerationModels: GenerationModel[] = [\n ...(process.env.OPENAI_API_KEY ? OpenAIConfig.models : []),\n ...(process.env.ANTHROPIC_API_KEY ? AnthropicConfig.models : []),\n ...(process.env.ELEVENLABS_API_KEY ? ElevenLabsConfig.models : []),\n]\n"],"names":["process","AnthropicConfig","ElevenLabsConfig","OpenAIConfig","GenerationModels","env","OPENAI_API_KEY","models","ANTHROPIC_API_KEY","ELEVENLABS_API_KEY"],"mappings":"AAAA,YAAYA,aAAa,eAAc;AAIvC,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,OAAO,MAAMC,mBAAsC;OAC7CJ,QAAQK,GAAG,CAACC,cAAc,GAAGH,aAAaI,MAAM,GAAG,EAAE;OACrDP,QAAQK,GAAG,CAACG,iBAAiB,GAAGP,gBAAgBM,MAAM,GAAG,EAAE;OAC3DP,QAAQK,GAAG,CAACI,kBAAkB,GAAGP,iBAAiBK,MAAM,GAAG,EAAE;CAClE,CAAA"}
1
+ {"version":3,"sources":["../../../src/ai/models/index.ts"],"sourcesContent":["import * as process from 'node:process'\n\nimport type { GenerationModel } from '../../types.js'\n\nimport { AnthropicConfig } from './anthropic/index.js'\nimport { ElevenLabsConfig } from './elevenLabs/index.js'\nimport { OpenAIConfig } from './openai/index.js'\n\nexport const defaultGenerationModels: GenerationModel[] = [\n ...(process.env.OPENAI_API_KEY ? OpenAIConfig.models : []),\n ...(process.env.ANTHROPIC_API_KEY ? AnthropicConfig.models : []),\n ...(process.env.ELEVENLABS_API_KEY ? ElevenLabsConfig.models : []),\n]\n"],"names":["process","AnthropicConfig","ElevenLabsConfig","OpenAIConfig","defaultGenerationModels","env","OPENAI_API_KEY","models","ANTHROPIC_API_KEY","ELEVENLABS_API_KEY"],"mappings":"AAAA,YAAYA,aAAa,eAAc;AAIvC,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,OAAO,MAAMC,0BAA6C;OACpDJ,QAAQK,GAAG,CAACC,cAAc,GAAGH,aAAaI,MAAM,GAAG,EAAE;OACrDP,QAAQK,GAAG,CAACG,iBAAiB,GAAGP,gBAAgBM,MAAM,GAAG,EAAE;OAC3DP,QAAQK,GAAG,CAACI,kBAAkB,GAAGP,iBAAiBK,MAAM,GAAG,EAAE;CAClE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"generateRichText.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/openai/generateRichText.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB,GAAU,MAAM,MAAM,EAAE,UAAS,GAAQ,sBAoCrE,CAAA"}
1
+ {"version":3,"file":"generateRichText.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/openai/generateRichText.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,gBAAgB,GAAU,MAAM,MAAM,EAAE,UAAS,GAAQ,sBAoCrE,CAAA"}
@@ -1,5 +1,5 @@
1
- import { openai } from '@ai-sdk/openai';
2
1
  import { jsonSchema, streamObject } from 'ai';
2
+ import { openai } from './openai.js';
3
3
  export const generateRichText = async (text, options = {})=>{
4
4
  // console.log('Running handler with prompts:', options.editorSchema)
5
5
  const streamResult = await streamObject({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ai/models/openai/generateRichText.ts"],"sourcesContent":["import { openai } from '@ai-sdk/openai'\nimport { jsonSchema, streamObject } from 'ai'\n\nexport const generateRichText = async (text: string, options: any = {}) => {\n // console.log('Running handler with prompts:', options.editorSchema)\n const streamResult = await streamObject({\n maxTokens: options.maxTokens || 5000,\n model: openai(options.model,{\n structuredOutputs: true,\n }),\n // onFinish: (result) => {\n // console.log('Finished generating rich text:', { options, rawResponse: result.rawResponse, result })\n // },\n prompt: text,\n schema: jsonSchema(options.editorSchema),\n system: `${options.system}\n\nRULES:\n- Generate original and unique content based on the given topic.\n- Strictly adhere to the specified layout and formatting instructions.\n- Utilize the provided rich text editor tools for appropriate formatting.\n- Ensure the output follows the structure of the sample output object.\n- Produce valid JSON with no undefined or null values.\n\nLAYOUT INSTRUCTIONS:\n${options.layout}\n\nRICH TEXT EDITOR TOOLS:\n- Use appropriate formatting tools such as bold, italic, or underline for emphasis where needed.\n- Apply correct heading levels (h1, h2, h3) for hierarchical structure.\n- Utilize bullet points or numbered lists as required by the layout.\n\nADDITIONAL GUIDELINES:\n- Ensure coherence and logical flow between all sections.\n- Maintain a consistent tone and style throughout the content.\n- Use clear and concise language appropriate for the target audience.\n`,\n })\n return streamResult.toTextStreamResponse()\n}\n"],"names":["openai","jsonSchema","streamObject","generateRichText","text","options","streamResult","maxTokens","model","structuredOutputs","prompt","schema","editorSchema","system","layout","toTextStreamResponse"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iBAAgB;AACvC,SAASC,UAAU,EAAEC,YAAY,QAAQ,KAAI;AAE7C,OAAO,MAAMC,mBAAmB,OAAOC,MAAcC,UAAe,CAAC,CAAC;IACpE,qEAAqE;IACrE,MAAMC,eAAe,MAAMJ,aAAa;QACtCK,WAAWF,QAAQE,SAAS,IAAI;QAChCC,OAAOR,OAAOK,QAAQG,KAAK,EAAC;YAC1BC,mBAAmB;QACrB;QACA,0BAA0B;QAC1B,wGAAwG;QACxG,KAAK;QACLC,QAAQN;QACRO,QAAQV,WAAWI,QAAQO,YAAY;QACvCC,QAAQ,GAAGR,QAAQQ,MAAM,CAAC;;;;;;;;;;AAU9B,EAAER,QAAQS,MAAM,CAAC;;;;;;;;;;;AAWjB,CAAC;IACC;IACA,OAAOR,aAAaS,oBAAoB;AAC1C,EAAC"}
1
+ {"version":3,"sources":["../../../../src/ai/models/openai/generateRichText.ts"],"sourcesContent":["import { jsonSchema, streamObject } from 'ai'\n\nimport { openai } from './openai.js'\n\nexport const generateRichText = async (text: string, options: any = {}) => {\n // console.log('Running handler with prompts:', options.editorSchema)\n const streamResult = await streamObject({\n maxTokens: options.maxTokens || 5000,\n model: openai(options.model, {\n structuredOutputs: true,\n }),\n // onFinish: (result) => {\n // console.log('Finished generating rich text:', { options, rawResponse: result.rawResponse, result })\n // },\n prompt: text,\n schema: jsonSchema(options.editorSchema),\n system: `${options.system}\n\nRULES:\n- Generate original and unique content based on the given topic.\n- Strictly adhere to the specified layout and formatting instructions.\n- Utilize the provided rich text editor tools for appropriate formatting.\n- Ensure the output follows the structure of the sample output object.\n- Produce valid JSON with no undefined or null values.\n\nLAYOUT INSTRUCTIONS:\n${options.layout}\n\nRICH TEXT EDITOR TOOLS:\n- Use appropriate formatting tools such as bold, italic, or underline for emphasis where needed.\n- Apply correct heading levels (h1, h2, h3) for hierarchical structure.\n- Utilize bullet points or numbered lists as required by the layout.\n\nADDITIONAL GUIDELINES:\n- Ensure coherence and logical flow between all sections.\n- Maintain a consistent tone and style throughout the content.\n- Use clear and concise language appropriate for the target audience.\n`,\n })\n return streamResult.toTextStreamResponse()\n}\n"],"names":["jsonSchema","streamObject","openai","generateRichText","text","options","streamResult","maxTokens","model","structuredOutputs","prompt","schema","editorSchema","system","layout","toTextStreamResponse"],"mappings":"AAAA,SAASA,UAAU,EAAEC,YAAY,QAAQ,KAAI;AAE7C,SAASC,MAAM,QAAQ,cAAa;AAEpC,OAAO,MAAMC,mBAAmB,OAAOC,MAAcC,UAAe,CAAC,CAAC;IACpE,qEAAqE;IACrE,MAAMC,eAAe,MAAML,aAAa;QACtCM,WAAWF,QAAQE,SAAS,IAAI;QAChCC,OAAON,OAAOG,QAAQG,KAAK,EAAE;YAC3BC,mBAAmB;QACrB;QACA,0BAA0B;QAC1B,wGAAwG;QACxG,KAAK;QACLC,QAAQN;QACRO,QAAQX,WAAWK,QAAQO,YAAY;QACvCC,QAAQ,GAAGR,QAAQQ,MAAM,CAAC;;;;;;;;;;AAU9B,EAAER,QAAQS,MAAM,CAAC;;;;;;;;;;;AAWjB,CAAC;IACC;IACA,OAAOR,aAAaS,oBAAoB;AAC1C,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/openai/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAWzD,eAAO,MAAM,YAAY,EAAE,gBAsM1B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/openai/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAYzD,eAAO,MAAM,YAAY,EAAE,gBAsM1B,CAAA"}
@@ -1,10 +1,10 @@
1
- import { openai } from '@ai-sdk/openai';
2
1
  import { streamText } from 'ai';
3
2
  import { defaultSystemPrompt } from '../../prompts.js';
4
3
  import { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js';
5
4
  import { generateImage } from './generateImage.js';
6
5
  import { generateRichText } from './generateRichText.js';
7
6
  import { generateVoice } from './generateVoice.js';
7
+ import { openai } from './openai.js';
8
8
  const MODEL_KEY = 'Oai';
9
9
  //TODO: Simplify this file by moving the handlers to separate files and remove duplicate code
10
10
  export const OpenAIConfig = {
@@ -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 { openai } from '@ai-sdk/openai'\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'\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: async (\n prompt: string,\n options: { locale: string; model: string; system: string },\n ) => {\n const streamTextResult = await streamText({\n model: openai(options.model),\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: '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-2024-08-06',\n label: 'Model',\n options: ['gpt-4o', 'gpt-4-turbo', 'gpt-4o-mini', 'gpt-4o-2024-08-06'],\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n ],\n provider: 'OpenAI',\n}\n"],"names":["openai","streamText","defaultSystemPrompt","generateFileNameByPrompt","generateImage","generateRichText","generateVoice","MODEL_KEY","OpenAIConfig","models","id","name","fields","handler","prompt","options","streamTextResult","model","system","toDataStreamResponse","output","settings","type","admin","condition","data","defaultValue","label","imageData","alt","file","buffer","mimetype","size","byteLength","text","voiceData","max","min","provider"],"mappings":"AAGA,SAASA,MAAM,QAAQ,iBAAgB;AACvC,SAASC,UAAU,QAAQ,KAAI;AAI/B,SAASC,mBAAmB,QAAQ,mBAAkB;AACtD,SAASC,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,aAAa,QAAQ,qBAAoB;AAElD,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,OACPC,QACAC;gBAEA,MAAMC,mBAAmB,MAAMf,WAAW;oBACxCgB,OAAOjB,OAAOe,QAAQE,KAAK;oBAC3BH;oBACAI,QAAQH,QAAQG,MAAM,IAAIhB;gBAC5B;gBAEA,OAAOc,iBAAiBG,oBAAoB;YAC9C;YACAC,QAAQ;YACRC,UA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BC,SAAS,CAACsB,MAAcpB;gBACtB,OAAOV,iBAAiB8B,MAAMpB;YAChC;YACAK,QAAQ;YACRC,UAAU;gBACRV,MAAM,GAAGJ,UAAU,gBAAgB,CAAC;gBACpCe,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGlB,UAAU,OAAO,CAAC;oBACnD;gBACF;gBACAK,QAAQ;oBACN;wBACED,MAAM;wBACNW,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPZ,SAAS;4BAAC;4BAAU;4BAAe;4BAAe;yBAAoB;oBACxE;iBACD;gBACDY,OAAO;YACT;QACF;KACD;IACDY,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 { 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: async (\n prompt: string,\n options: { locale: string; model: string; system: string },\n ) => {\n const streamTextResult = await streamText({\n model: openai(options.model),\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: '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-2024-08-06',\n label: 'Model',\n options: ['gpt-4o', 'gpt-4-turbo', 'gpt-4o-mini', 'gpt-4o-2024-08-06'],\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","system","toDataStreamResponse","output","settings","type","admin","condition","data","defaultValue","label","imageData","alt","file","buffer","mimetype","size","byteLength","text","voiceData","max","min","provider"],"mappings":"AAGA,SAASA,UAAU,QAAQ,KAAI;AAI/B,SAASC,mBAAmB,QAAQ,mBAAkB;AACtD,SAASC,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,gBAAgB,QAAQ,wBA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oBAGhE;oBACA;wBACEJ,MAAM;wBACNW,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPZ,SAAS;4BAAC;4BAAS;yBAAW;oBAChC;oBACA;wBACEJ,MAAM;wBACNW,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPZ,SAAS;4BAAC;4BAAO;4BAAQ;4BAAO;4BAAQ;4BAAO;yBAAM;oBAGvD;oBACA;wBACEJ,MAAM;wBACNW,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPU,KAAK;wBACLC,KAAK;oBACP;iBACD;gBACDX,OAAO;YACT;QACF;QACA;YACEjB,IAAI,GAAGH,UAAU,OAAO,CAAC;YACzBI,MAAM;YACNC,QAAQ;gBAAC;aAAW;YACpBC,SAAS,CAACsB,MAAcpB;gBACtB,OAAOX,iBAAiB+B,MAAMpB;YAChC;YACAK,QAAQ;YACRC,UAAU;gBACRV,MAAM,GAAGJ,UAAU,gBAAgB,CAAC;gBACpCe,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGlB,UAAU,OAAO,CAAC;oBACnD;gBACF;gBACAK,QAAQ;oBACN;wBACED,MAAM;wBACNW,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPZ,SAAS;4BAAC;4BAAU;4BAAe;4BAAe;yBAAoB;oBACxE;iBACD;gBACDY,OAAO;YACT;QACF;KACD;IACDY,UAAU;AACZ,EAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const openai: import("@ai-sdk/openai").OpenAIProvider;
2
+ //# sourceMappingURL=openai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../../src/ai/models/openai/openai.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,yCAIjB,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { createOpenAI } from '@ai-sdk/openai';
2
+ // same to default openai with optional baseurl.
3
+ export const openai = createOpenAI({
4
+ apiKey: process.env.OPENAI_API_KEY,
5
+ baseURL: process.env.OPENAI_BASE_URL ?? 'https://api.openai.com/v1',
6
+ compatibility: 'strict'
7
+ });
8
+
9
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +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"}
@@ -371,5 +371,377 @@ export declare const documentSchema: {
371
371
  };
372
372
  required: string[];
373
373
  };
374
- export declare const lexicalJsonSchema: (customNodes?: any[]) => any;
374
+ export declare const lexicalJsonSchema: (customNodes?: any[]) => {
375
+ type: string;
376
+ $schema: string;
377
+ additionalProperties: boolean;
378
+ definitions: {
379
+ TextNode: {
380
+ type: string;
381
+ additionalProperties: boolean;
382
+ properties: {
383
+ type: {
384
+ type: string;
385
+ enum: string[];
386
+ };
387
+ detail: {
388
+ type: string;
389
+ description: string;
390
+ enum: number[];
391
+ examples: {
392
+ description: string;
393
+ value: number;
394
+ }[];
395
+ };
396
+ direction: {
397
+ type: string[];
398
+ enum: string[];
399
+ };
400
+ format: {
401
+ type: string;
402
+ description: string;
403
+ };
404
+ indent: {
405
+ type: string;
406
+ };
407
+ mode: {
408
+ type: string;
409
+ description: string;
410
+ enum: number[];
411
+ examples: {
412
+ description: string;
413
+ value: number;
414
+ }[];
415
+ };
416
+ style: {
417
+ type: string;
418
+ description: string;
419
+ };
420
+ text: {
421
+ type: string;
422
+ };
423
+ version: {
424
+ type: string;
425
+ };
426
+ };
427
+ required: string[];
428
+ };
429
+ TableCellNode: {
430
+ type: string;
431
+ additionalProperties: boolean;
432
+ properties: {
433
+ type: {
434
+ type: string;
435
+ enum: string[];
436
+ };
437
+ children: {
438
+ type: string;
439
+ items: {
440
+ $ref: string;
441
+ };
442
+ };
443
+ colSpan: {
444
+ type: string;
445
+ };
446
+ direction: {
447
+ type: string[];
448
+ enum: string[];
449
+ };
450
+ headerState: {
451
+ type: string;
452
+ };
453
+ indent: {
454
+ type: string;
455
+ };
456
+ version: {
457
+ type: string;
458
+ };
459
+ width: {
460
+ type: string[];
461
+ enum: any[];
462
+ };
463
+ };
464
+ required: string[];
465
+ };
466
+ TableRowNode: {
467
+ type: string;
468
+ additionalProperties: boolean;
469
+ properties: {
470
+ type: {
471
+ type: string;
472
+ enum: string[];
473
+ };
474
+ children: {
475
+ type: string;
476
+ items: {
477
+ $ref: string;
478
+ };
479
+ };
480
+ height: {
481
+ type: string;
482
+ };
483
+ };
484
+ required: string[];
485
+ };
486
+ TableNode: {
487
+ type: string;
488
+ additionalProperties: boolean;
489
+ properties: {
490
+ type: {
491
+ type: string;
492
+ enum: string[];
493
+ };
494
+ children: {
495
+ type: string;
496
+ items: {
497
+ $ref: string;
498
+ };
499
+ };
500
+ };
501
+ required: string[];
502
+ };
503
+ HeadingNode: {
504
+ type: string;
505
+ additionalProperties: boolean;
506
+ properties: {
507
+ type: {
508
+ type: string;
509
+ enum: string[];
510
+ };
511
+ children: {
512
+ type: string;
513
+ items: {
514
+ anyOf: {
515
+ $ref: string;
516
+ }[];
517
+ };
518
+ };
519
+ direction: {
520
+ type: string[];
521
+ enum: string[];
522
+ };
523
+ indent: {
524
+ type: string;
525
+ };
526
+ tag: {
527
+ type: string;
528
+ enum: string[];
529
+ };
530
+ version: {
531
+ type: string;
532
+ };
533
+ };
534
+ required: string[];
535
+ };
536
+ ParagraphNode: {
537
+ type: string;
538
+ additionalProperties: boolean;
539
+ properties: {
540
+ type: {
541
+ type: string;
542
+ enum: string[];
543
+ };
544
+ children: {
545
+ type: string;
546
+ items: {
547
+ anyOf: {
548
+ $ref: string;
549
+ }[];
550
+ };
551
+ };
552
+ direction: {
553
+ type: string[];
554
+ enum: string[];
555
+ };
556
+ format: {
557
+ type: string;
558
+ enum: string[];
559
+ };
560
+ indent: {
561
+ type: string;
562
+ };
563
+ textFormat: {
564
+ type: string;
565
+ };
566
+ textStyle: {
567
+ type: string;
568
+ description: string;
569
+ };
570
+ version: {
571
+ type: string;
572
+ };
573
+ };
574
+ required: string[];
575
+ };
576
+ LinkNode: {
577
+ type: string;
578
+ additionalProperties: boolean;
579
+ properties: {
580
+ type: {
581
+ type: string;
582
+ enum: string[];
583
+ };
584
+ children: {
585
+ type: string;
586
+ items: {
587
+ $ref: string;
588
+ };
589
+ };
590
+ url: {
591
+ type: string;
592
+ };
593
+ };
594
+ required: string[];
595
+ };
596
+ ListItemNode: {
597
+ type: string;
598
+ additionalProperties: boolean;
599
+ properties: {
600
+ indent: {
601
+ type: string;
602
+ enum: number[];
603
+ };
604
+ type: {
605
+ type: string;
606
+ enum: string[];
607
+ };
608
+ children: {
609
+ type: string;
610
+ items: {
611
+ anyOf: {
612
+ $ref: string;
613
+ }[];
614
+ };
615
+ };
616
+ };
617
+ required: string[];
618
+ };
619
+ ListNode: {
620
+ type: string;
621
+ additionalProperties: boolean;
622
+ properties: {
623
+ type: {
624
+ type: string;
625
+ enum: string[];
626
+ };
627
+ children: {
628
+ type: string;
629
+ items: {
630
+ $ref: string;
631
+ };
632
+ };
633
+ listType: {
634
+ type: string;
635
+ enum: string[];
636
+ };
637
+ };
638
+ required: string[];
639
+ };
640
+ QuoteNode: {
641
+ type: string;
642
+ additionalProperties: boolean;
643
+ properties: {
644
+ type: {
645
+ type: string;
646
+ enum: string[];
647
+ };
648
+ children: {
649
+ type: string;
650
+ items: {
651
+ anyOf: {
652
+ $ref: string;
653
+ }[];
654
+ };
655
+ };
656
+ };
657
+ required: string[];
658
+ };
659
+ CodeNode: {
660
+ type: string;
661
+ additionalProperties: boolean;
662
+ properties: {
663
+ type: {
664
+ type: string;
665
+ enum: string[];
666
+ };
667
+ code: {
668
+ type: string;
669
+ };
670
+ language: {
671
+ type: string;
672
+ };
673
+ };
674
+ required: string[];
675
+ };
676
+ HorizontalRuleNode: {
677
+ type: string;
678
+ additionalProperties: boolean;
679
+ properties: {
680
+ type: {
681
+ type: string;
682
+ enum: string[];
683
+ };
684
+ };
685
+ required: string[];
686
+ };
687
+ ImageNode: {
688
+ type: string;
689
+ additionalProperties: boolean;
690
+ properties: {
691
+ type: {
692
+ type: string;
693
+ enum: string[];
694
+ };
695
+ alt: {
696
+ type: string;
697
+ };
698
+ caption: {
699
+ type: string;
700
+ items: {
701
+ $ref: string;
702
+ };
703
+ };
704
+ src: {
705
+ type: string;
706
+ };
707
+ };
708
+ required: string[];
709
+ };
710
+ RootNode: {
711
+ type: string;
712
+ additionalProperties: boolean;
713
+ properties: {
714
+ type: {
715
+ type: string;
716
+ enum: string[];
717
+ };
718
+ children: {
719
+ type: string;
720
+ items: {
721
+ anyOf: {
722
+ $ref: string;
723
+ }[];
724
+ };
725
+ };
726
+ direction: {
727
+ type: string[];
728
+ enum: string[];
729
+ };
730
+ indent: {
731
+ type: string;
732
+ };
733
+ version: {
734
+ type: string;
735
+ };
736
+ };
737
+ required: string[];
738
+ };
739
+ };
740
+ properties: {
741
+ root: {
742
+ $ref: string;
743
+ };
744
+ };
745
+ required: string[];
746
+ };
375
747
  //# sourceMappingURL=lexicalJsonSchema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lexicalJsonSchema.d.ts","sourceRoot":"","sources":["../../../src/ai/schemas/lexicalJsonSchema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAejD,CAAA"}
@@ -392,6 +392,9 @@ export const documentSchema = {
392
392
  type: 'object',
393
393
  additionalProperties: false,
394
394
  properties: {
395
+ // NOTE: Do not change the position of "indent", models like gpt generate properties as they are
396
+ // defined in schema, moving the position of property "indent"
397
+ // can cause issue with schema validation while streaming generated json to lexical editor
395
398
  indent: {
396
399
  type: 'number',
397
400
  enum: [
@@ -641,15 +644,16 @@ export const documentSchema = {
641
644
  ]
642
645
  };
643
646
  export const lexicalJsonSchema = (customNodes = [])=>{
644
- const schema = JSON.parse(JSON.stringify(documentSchema));
645
- // Add custom nodes to the Node definition
646
- if (customNodes.length > 0) {
647
- customNodes.forEach((customNode, index)=>{
648
- const customNodeName = `CustomNode${index + 1}`;
649
- schema.definitions[customNodeName] = customNode;
650
- schema.definitions.Node.oneOf.push({
651
- $ref: `#/definitions/${customNodeName}`
652
- });
647
+ const schema = structuredClone(documentSchema);
648
+ if (Array.isArray(customNodes) && customNodes.length > 0) {
649
+ customNodes.forEach((nodeObj)=>{
650
+ for (const [nodeName, nodeDefinition] of Object.entries(nodeObj)){
651
+ schema.definitions[nodeName] = nodeDefinition;
652
+ const anyOfList = schema?.definitions?.RootNode?.properties?.children?.items?.anyOf;
653
+ anyOfList.push({
654
+ $ref: `#/definitions/${nodeName}`
655
+ });
656
+ }
653
657
  });
654
658
  }
655
659
  return schema;