@ai-stack/payloadcms 3.2.16-beta → 3.2.18-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 (220) hide show
  1. package/README.md +79 -0
  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 +57 -13
  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 +60 -13
  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 +7 -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 +111 -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 -12
  90. package/dist/providers/InstructionsProvider/InstructionsProvider.js +7 -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 +45 -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 +8 -5
  115. package/dist/ui/Compose/hooks/menu/TranslateMenu.js +1 -1
  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/useMenu.d.ts +7 -7
  120. package/dist/ui/Compose/hooks/menu/useMenu.js +12 -9
  121. package/dist/ui/Compose/hooks/menu/useMenu.js.map +1 -1
  122. package/dist/ui/Compose/hooks/useGenerate.d.ts +0 -1
  123. package/dist/ui/Compose/hooks/useGenerate.js +41 -20
  124. package/dist/ui/Compose/hooks/useGenerate.js.map +1 -1
  125. package/dist/ui/Compose/hooks/useHistory.d.ts +0 -1
  126. package/dist/ui/Compose/hooks/useHistory.js +2 -2
  127. package/dist/ui/Compose/hooks/useHistory.js.map +1 -1
  128. package/dist/ui/Icons/Icons.d.ts +34 -34
  129. package/dist/ui/Icons/Icons.js +1 -1
  130. package/dist/ui/Icons/Icons.js.map +1 -1
  131. package/dist/ui/Icons/LottieAnimation.d.ts +3 -3
  132. package/dist/ui/Icons/LottieAnimation.js +1 -0
  133. package/dist/ui/Icons/LottieAnimation.js.map +1 -1
  134. package/dist/utilities/editorSchemaValidator.d.ts +1 -2
  135. package/dist/utilities/editorSchemaValidator.js.map +1 -1
  136. package/dist/utilities/extractImageData.d.ts +0 -1
  137. package/dist/utilities/extractPromptAttachments.d.ts +2 -0
  138. package/dist/utilities/extractPromptAttachments.js +32 -0
  139. package/dist/utilities/extractPromptAttachments.js.map +1 -0
  140. package/dist/utilities/getFieldBySchemaPath.d.ts +0 -1
  141. package/dist/utilities/getFieldBySchemaPath.js +12 -4
  142. package/dist/utilities/getFieldBySchemaPath.js.map +1 -1
  143. package/dist/utilities/getFieldInfo.d.ts +1 -2
  144. package/dist/utilities/getGenerationModels.d.ts +1 -2
  145. package/dist/utilities/isPluginActivated.d.ts +0 -1
  146. package/dist/utilities/isPluginActivated.js +1 -1
  147. package/dist/utilities/isPluginActivated.js.map +1 -1
  148. package/dist/utilities/lexicalToHTML.d.ts +0 -1
  149. package/dist/utilities/setSafeLexicalState.d.ts +1 -2
  150. package/dist/utilities/setSafeLexicalState.js.map +1 -1
  151. package/dist/utilities/updateFieldsConfig.d.ts +0 -1
  152. package/dist/utilities/updateFieldsConfig.js +10 -3
  153. package/dist/utilities/updateFieldsConfig.js.map +1 -1
  154. package/package.json +104 -65
  155. package/dist/ai/analyse.d.ts.map +0 -1
  156. package/dist/ai/models/anthropic/generateRichText.d.ts.map +0 -1
  157. package/dist/ai/models/anthropic/index.d.ts.map +0 -1
  158. package/dist/ai/models/elevenLabs/generateVoice.d.ts.map +0 -1
  159. package/dist/ai/models/elevenLabs/index.d.ts.map +0 -1
  160. package/dist/ai/models/elevenLabs/voices.d.ts.map +0 -1
  161. package/dist/ai/models/index.d.ts.map +0 -1
  162. package/dist/ai/models/openai/generateImage.d.ts.map +0 -1
  163. package/dist/ai/models/openai/generateRichText.d.ts.map +0 -1
  164. package/dist/ai/models/openai/generateVoice.d.ts.map +0 -1
  165. package/dist/ai/models/openai/index.d.ts.map +0 -1
  166. package/dist/ai/models/openai/openai.d.ts.map +0 -1
  167. package/dist/ai/prompts.d.ts.map +0 -1
  168. package/dist/ai/schemas/lexicalJsonSchema.d.ts.map +0 -1
  169. package/dist/ai/utils/editImagesWithOpenAI.d.ts.map +0 -1
  170. package/dist/ai/utils/filterEditorSchemaByNodes.d.ts.map +0 -1
  171. package/dist/ai/utils/generateFileNameByPrompt.d.ts.map +0 -1
  172. package/dist/ai/utils/isObjectSchema.d.ts.map +0 -1
  173. package/dist/ai/utils/systemGenerate.d.ts.map +0 -1
  174. package/dist/collections/Instructions.d.ts.map +0 -1
  175. package/dist/defaults.d.ts.map +0 -1
  176. package/dist/endpoints/fetchFields.d.ts.map +0 -1
  177. package/dist/endpoints/index.d.ts.map +0 -1
  178. package/dist/exports/client.d.ts.map +0 -1
  179. package/dist/exports/fields.d.ts.map +0 -1
  180. package/dist/exports/types.d.ts.map +0 -1
  181. package/dist/fields/ComposeField/ComposeField.d.ts.map +0 -1
  182. package/dist/fields/LexicalEditor/ComposeFeatureComponent.d.ts.map +0 -1
  183. package/dist/fields/LexicalEditor/feature.client.d.ts.map +0 -1
  184. package/dist/fields/LexicalEditor/feature.server.d.ts.map +0 -1
  185. package/dist/fields/PromptEditorField/PromptEditorField.d.ts.map +0 -1
  186. package/dist/fields/PromptEditorField/defaultStyle.d.ts.map +0 -1
  187. package/dist/fields/SelectField/SelectField.d.ts.map +0 -1
  188. package/dist/index.d.ts.map +0 -1
  189. package/dist/init.d.ts.map +0 -1
  190. package/dist/libraries/handlebars/asyncHandlebars.d.ts.map +0 -1
  191. package/dist/libraries/handlebars/helpers.d.ts.map +0 -1
  192. package/dist/libraries/handlebars/helpersMap.d.ts.map +0 -1
  193. package/dist/libraries/handlebars/replacePlaceholders.d.ts.map +0 -1
  194. package/dist/plugin.d.ts.map +0 -1
  195. package/dist/providers/FieldProvider/FieldProvider.d.ts.map +0 -1
  196. package/dist/providers/FieldProvider/useFieldProps.d.ts.map +0 -1
  197. package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts.map +0 -1
  198. package/dist/providers/InstructionsProvider/useInstructions.d.ts.map +0 -1
  199. package/dist/translations/index.d.ts.map +0 -1
  200. package/dist/types.d.ts.map +0 -1
  201. package/dist/ui/Compose/Compose.d.ts.map +0 -1
  202. package/dist/ui/Compose/UndoRedoActions.d.ts.map +0 -1
  203. package/dist/ui/Compose/hooks/menu/Item.d.ts.map +0 -1
  204. package/dist/ui/Compose/hooks/menu/TranslateMenu.d.ts.map +0 -1
  205. package/dist/ui/Compose/hooks/menu/items.d.ts.map +0 -1
  206. package/dist/ui/Compose/hooks/menu/itemsMap.d.ts.map +0 -1
  207. package/dist/ui/Compose/hooks/menu/useMenu.d.ts.map +0 -1
  208. package/dist/ui/Compose/hooks/useGenerate.d.ts.map +0 -1
  209. package/dist/ui/Compose/hooks/useHistory.d.ts.map +0 -1
  210. package/dist/ui/Icons/Icons.d.ts.map +0 -1
  211. package/dist/ui/Icons/LottieAnimation.d.ts.map +0 -1
  212. package/dist/utilities/editorSchemaValidator.d.ts.map +0 -1
  213. package/dist/utilities/extractImageData.d.ts.map +0 -1
  214. package/dist/utilities/getFieldBySchemaPath.d.ts.map +0 -1
  215. package/dist/utilities/getFieldInfo.d.ts.map +0 -1
  216. package/dist/utilities/getGenerationModels.d.ts.map +0 -1
  217. package/dist/utilities/isPluginActivated.d.ts.map +0 -1
  218. package/dist/utilities/lexicalToHTML.d.ts.map +0 -1
  219. package/dist/utilities/setSafeLexicalState.d.ts.map +0 -1
  220. package/dist/utilities/updateFieldsConfig.d.ts.map +0 -1
package/README.md CHANGED
@@ -187,6 +187,20 @@ export default buildConfig({
187
187
  enabledLanguages: ["en-US", "zh-SG", "zh-CN", "en"],
188
188
  },
189
189
 
190
+ // Optional: Additional fields that can be referenced in prompts
191
+ promptFields: [
192
+ // Expose "url" field on images collection
193
+ {
194
+ name: 'url',
195
+ collections: ['images'],
196
+ },
197
+ // Expose custom async function that generates markdown summary of any document
198
+ {
199
+ name: 'markdown',
200
+ async getter(doc, {collection}) => docToMarkdown(collection, doc)
201
+ }
202
+ ],
203
+
190
204
  // Optional: Custom media upload handling, useful for multi-tenant setups
191
205
  mediaUpload: async (result, { request, collection }) => {
192
206
  return request.payload.create({
@@ -246,3 +260,68 @@ Innovators: welcome! We're always excited to expand our community and hear fresh
246
260
  Feel free to create a pull request with your ideas, improvements, or bug fixes. No contribution is too small, and every bit helps us grow!
247
261
 
248
262
  Join the conversation on Payload's [Discord](https://discord.com/channels/967097582721572934/1264949995656843345) and let’s build something amazing together! 🚀✨
263
+
264
+ ### Local development
265
+
266
+ This repo includes a minimal Payload app under [dev](dev/README.md) to iterate on the plugin quickly.
267
+
268
+ Prerequisites
269
+ - Node.js (see `.nvmrc`) and pnpm
270
+ - A database connection string for `DATABASE_URI` (Postgres or Mongo)
271
+ - Optional: AI provider keys to test features (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `ELEVENLABS_API_KEY`)
272
+
273
+ 1) Install dependencies
274
+ ```bash
275
+ pnpm install
276
+ ```
277
+
278
+ 2) Set up the dev app environment
279
+ ```bash
280
+ cp dev/.env.example dev/.env
281
+ # Edit dev/.env:
282
+ # - Set DATABASE_URI to your DB connection string
283
+ # - Set PAYLOAD_SECRET to a strong random string
284
+ # - Optionally set AI provider keys to exercise features
285
+ ```
286
+
287
+ 3) Start the dev app (admin available at http://localhost:3000)
288
+ ```bash
289
+ pnpm dev
290
+ ```
291
+
292
+ If you run into admin import-map issues, regenerate it:
293
+ ```bash
294
+ pnpm generate:importmap
295
+ ```
296
+ Optionally regenerate Payload types:
297
+ ```bash
298
+ pnpm generate:types
299
+ ```
300
+
301
+ 4) Develop
302
+ - Plugin source lives in `src/`; the dev app imports it locally.
303
+ - Edit files in `src/**` and refresh the dev app to validate changes.
304
+
305
+ 5) Tests, linting, formatting
306
+ ```bash
307
+ pnpm test # runs Vitest + Playwright (see dev/int.spec.ts, dev/e2e.spec.ts)
308
+ pnpm lint # ESLint
309
+ pnpm prettier --write . # Prettier (format all files)
310
+ ```
311
+
312
+ 6) Build the plugin
313
+ ```bash
314
+ pnpm build
315
+ ```
316
+
317
+ 7) Try the built package in another Payload project (optional)
318
+ ```bash
319
+ pnpm pack # creates a tarball in the repo root
320
+ # then in your other project:
321
+ pnpm add /path/to/ai-plugin-*.tgz
322
+ ```
323
+
324
+ Project structure quick reference
325
+ - `src/` — plugin source code
326
+ - `dev/` — minimal Payload app wired to this plugin for local testing
327
+ - Tests — see `dev/int.spec.ts` and `dev/e2e.spec.ts` for integration and e2e tests
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=analyse.d.ts.map
@@ -1,2 +1 @@
1
1
  export declare const generateRichText: (text: string, options: any) => Response;
2
- //# sourceMappingURL=generateRichText.d.ts.map
@@ -1,12 +1,14 @@
1
1
  import { anthropic } from '@ai-sdk/anthropic';
2
2
  import { jsonSchema, streamObject } from 'ai';
3
+ import { extractPromptAttachments } from "../../../utilities/extractPromptAttachments.js";
3
4
  export const generateRichText = (text, options)=>{
4
5
  const streamResult = streamObject({
6
+ maxOutputTokens: options.maxTokens || 5000,
5
7
  model: anthropic(options.model),
6
8
  onError: (error)=>{
7
9
  console.error(`generateRichText: `, error);
8
10
  },
9
- prompt: text,
11
+ prompt: options.extractAttachments ? extractPromptAttachments(text) : text,
10
12
  schema: jsonSchema(options.editorSchema),
11
13
  system: `${options.system}
12
14
 
@@ -16,20 +18,17 @@ RULES:
16
18
  - Utilize the provided rich text editor tools for appropriate formatting.
17
19
  - Ensure the output follows the structure of the sample output object.
18
20
  - Produce valid JSON with no undefined or null values.
19
-
21
+ ---
20
22
  LAYOUT INSTRUCTIONS:
21
23
  ${options.layout}
22
24
 
23
- RICH TEXT EDITOR TOOLS:
24
- - Use appropriate formatting tools such as bold, italic, or underline for emphasis where needed.
25
- - Apply correct heading levels (h1, h2, h3) for hierarchical structure.
26
- - Utilize bullet points or numbered lists as required by the layout.
27
-
25
+ ---
28
26
  ADDITIONAL GUIDELINES:
29
27
  - Ensure coherence and logical flow between all sections.
30
28
  - Maintain a consistent tone and style throughout the content.
31
29
  - Use clear and concise language appropriate for the target audience.
32
- - Double-check that all JSON fields are properly filled and formatted.`
30
+ `,
31
+ temperature: options.temperature || 0.7
33
32
  });
34
33
  return streamResult.toTextStreamResponse();
35
34
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ai/models/anthropic/generateRichText.ts"],"sourcesContent":["import { anthropic } from '@ai-sdk/anthropic'\nimport { jsonSchema, streamObject } from 'ai'\n\nexport const generateRichText = (text: string, options: any) => {\n const streamResult = streamObject({\n model: anthropic(options.model),\n onError: (error) => {\n console.error(`generateRichText: `, error)\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- Double-check that all JSON fields are properly filled and formatted.`,\n })\n\n return streamResult.toTextStreamResponse()\n}\n"],"names":["anthropic","jsonSchema","streamObject","generateRichText","text","options","streamResult","model","onError","error","console","prompt","schema","editorSchema","system","layout","toTextStreamResponse"],"mappings":"AAAA,SAASA,SAAS,QAAQ,oBAAmB;AAC7C,SAASC,UAAU,EAAEC,YAAY,QAAQ,KAAI;AAE7C,OAAO,MAAMC,mBAAmB,CAACC,MAAcC;IAC7C,MAAMC,eAAeJ,aAAa;QAChCK,OAAOP,UAAUK,QAAQE,KAAK;QAC9BC,SAAS,CAACC;YACRC,QAAQD,KAAK,CAAC,CAAC,kBAAkB,CAAC,EAAEA;QACtC;QACAE,QAAQP;QACRQ,QAAQX,WAAWI,QAAQQ,YAAY;QACvCC,QAAQ,GAAGT,QAAQS,MAAM,CAAC;;;;;;;;;;AAU9B,EAAET,QAAQU,MAAM,CAAC;;;;;;;;;;;sEAWqD,CAAC;IACrE;IAEA,OAAOT,aAAaU,oBAAoB;AAC1C,EAAC"}
1
+ {"version":3,"sources":["../../../../src/ai/models/anthropic/generateRichText.ts"],"sourcesContent":["import { anthropic } from '@ai-sdk/anthropic'\nimport { jsonSchema, streamObject } from 'ai'\n\nimport {extractPromptAttachments} from \"../../../utilities/extractPromptAttachments.js\";\n\nexport const generateRichText = (text: string, options: any) => {\n const streamResult = streamObject({\n maxOutputTokens: options.maxTokens || 5000,\n model: anthropic(options.model),\n onError: (error) => {\n console.error(`generateRichText: `, error)\n },\n prompt: options.extractAttachments ? extractPromptAttachments(text) : 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\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 temperature: options.temperature || 0.7,\n })\n\n return streamResult.toTextStreamResponse()\n}\n"],"names":["anthropic","jsonSchema","streamObject","extractPromptAttachments","generateRichText","text","options","streamResult","maxOutputTokens","maxTokens","model","onError","error","console","prompt","extractAttachments","schema","editorSchema","system","layout","temperature","toTextStreamResponse"],"mappings":"AAAA,SAASA,SAAS,QAAQ,oBAAmB;AAC7C,SAASC,UAAU,EAAEC,YAAY,QAAQ,KAAI;AAE7C,SAAQC,wBAAwB,QAAO,iDAAiD;AAExF,OAAO,MAAMC,mBAAmB,CAACC,MAAcC;IAC7C,MAAMC,eAAeL,aAAa;QAChCM,iBAAiBF,QAAQG,SAAS,IAAI;QACtCC,OAAOV,UAAUM,QAAQI,KAAK;QAC9BC,SAAS,CAACC;YACRC,QAAQD,KAAK,CAAC,CAAC,kBAAkB,CAAC,EAAEA;QACtC;QACAE,QAAQR,QAAQS,kBAAkB,GAAGZ,yBAAyBE,QAAQA;QACtEW,QAAQf,WAAWK,QAAQW,YAAY;QACvCC,QAAQ,GAAGZ,QAAQY,MAAM,CAAC;;;;;;;;;;AAU9B,EAAEZ,QAAQa,MAAM,CAAC;;;;;;;AAOjB,CAAC;QACGC,aAAad,QAAQc,WAAW,IAAI;IACtC;IAEA,OAAOb,aAAac,oBAAoB;AAC1C,EAAC"}
@@ -1,3 +1,2 @@
1
1
  import type { GenerationConfig } from '../../../types.js';
2
2
  export declare const AnthropicConfig: GenerationConfig;
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,8 +1,18 @@
1
1
  import { anthropic } from '@ai-sdk/anthropic';
2
2
  import { streamText } from 'ai';
3
+ import { extractPromptAttachments } from '../../../utilities/extractPromptAttachments.js';
3
4
  import { defaultSystemPrompt } from '../../prompts.js';
4
5
  import { generateRichText } from './generateRichText.js';
5
6
  const MODEL_KEY = 'ANTH-C';
7
+ const MODELS = [
8
+ 'claude-opus-4-1',
9
+ 'claude-opus-4-0',
10
+ 'claude-sonnet-4-0',
11
+ 'claude-3-opus-latest',
12
+ 'claude-3-5-haiku-latest',
13
+ 'claude-3-5-sonnet-latest',
14
+ 'claude-3-7-sonnet-latest'
15
+ ];
6
16
  export const AnthropicConfig = {
7
17
  models: [
8
18
  {
@@ -14,14 +24,16 @@ export const AnthropicConfig = {
14
24
  ],
15
25
  handler: (prompt, options)=>{
16
26
  const streamTextResult = streamText({
27
+ maxOutputTokens: options.maxTokens || 5000,
17
28
  model: anthropic(options.model),
18
29
  onError: (error)=>{
19
30
  console.error(`${MODEL_KEY}-text: `, error);
20
31
  },
21
- prompt,
22
- system: options.system || defaultSystemPrompt
32
+ prompt: options.extractAttachments ? extractPromptAttachments(prompt) : prompt,
33
+ system: options.system || defaultSystemPrompt,
34
+ temperature: options.temperature || 0.7
23
35
  });
24
- return streamTextResult.toDataStreamResponse();
36
+ return streamTextResult.toUIMessageStreamResponse();
25
37
  },
26
38
  output: 'text',
27
39
  settings: {
@@ -38,12 +50,28 @@ export const AnthropicConfig = {
38
50
  type: 'select',
39
51
  defaultValue: 'claude-3-5-sonnet-latest',
40
52
  label: 'Model',
41
- options: [
42
- 'claude-3-opus-latest',
43
- 'claude-3-5-haiku-latest',
44
- 'claude-3-5-sonnet-latest',
45
- 'claude-3-7-sonnet-latest'
53
+ options: MODELS
54
+ },
55
+ {
56
+ type: 'row',
57
+ fields: [
58
+ {
59
+ name: 'maxTokens',
60
+ type: 'number',
61
+ defaultValue: 5000
62
+ },
63
+ {
64
+ name: 'temperature',
65
+ type: 'number',
66
+ defaultValue: 0.7,
67
+ max: 1,
68
+ min: 0
69
+ }
46
70
  ]
71
+ },
72
+ {
73
+ name: 'extractAttachments',
74
+ type: 'checkbox'
47
75
  }
48
76
  ],
49
77
  label: 'Anthropic Claude Settings'
@@ -73,12 +101,28 @@ export const AnthropicConfig = {
73
101
  type: 'select',
74
102
  defaultValue: 'claude-3-5-sonnet-latest',
75
103
  label: 'Model',
76
- options: [
77
- 'claude-3-opus-latest',
78
- 'claude-3-5-haiku-latest',
79
- 'claude-3-5-sonnet-latest',
80
- 'claude-3-7-sonnet-latest'
104
+ options: MODELS
105
+ },
106
+ {
107
+ type: 'row',
108
+ fields: [
109
+ {
110
+ name: 'maxTokens',
111
+ type: 'number',
112
+ defaultValue: 5000
113
+ },
114
+ {
115
+ name: 'temperature',
116
+ type: 'number',
117
+ defaultValue: 0.7,
118
+ max: 1,
119
+ min: 0
120
+ }
81
121
  ]
122
+ },
123
+ {
124
+ name: 'extractAttachments',
125
+ type: 'checkbox'
82
126
  }
83
127
  ],
84
128
  label: 'Anthropic Claude Settings'
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ai/models/anthropic/index.ts"],"sourcesContent":["import { anthropic } from '@ai-sdk/anthropic'\nimport { streamText } from 'ai'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { defaultSystemPrompt } from '../../prompts.js'\nimport { generateRichText } from './generateRichText.js'\n\nconst MODEL_KEY = 'ANTH-C'\n\nexport const AnthropicConfig: GenerationConfig = {\n models: [\n {\n id: `${MODEL_KEY}-text`,\n name: 'Anthropic Claude',\n fields: ['text', 'textarea'],\n handler: (prompt: string, options: { locale: string; model: string; system: string }) => {\n const streamTextResult = streamText({\n model: anthropic(options.model),\n onError: (error) => {\n console.error(`${MODEL_KEY}-text: `, error)\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: 'claude-3-5-sonnet-latest',\n label: 'Model',\n options: [\n 'claude-3-opus-latest',\n 'claude-3-5-haiku-latest',\n 'claude-3-5-sonnet-latest',\n 'claude-3-7-sonnet-latest',\n ],\n },\n ],\n label: 'Anthropic Claude Settings',\n },\n },\n {\n id: `${MODEL_KEY}-object`,\n name: 'Anthropic Claude',\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: 'claude-3-5-sonnet-latest',\n label: 'Model',\n options: [\n 'claude-3-opus-latest',\n 'claude-3-5-haiku-latest',\n 'claude-3-5-sonnet-latest',\n 'claude-3-7-sonnet-latest',\n ],\n },\n ],\n label: 'Anthropic Claude Settings',\n },\n },\n ],\n provider: 'Anthropic',\n}\n"],"names":["anthropic","streamText","defaultSystemPrompt","generateRichText","MODEL_KEY","AnthropicConfig","models","id","name","fields","handler","prompt","options","streamTextResult","model","onError","error","console","system","toDataStreamResponse","output","settings","type","admin","condition","data","defaultValue","label","text","provider"],"mappings":"AAAA,SAASA,SAAS,QAAQ,oBAAmB;AAC7C,SAASC,UAAU,QAAQ,KAAI;AAI/B,SAASC,mBAAmB,QAAQ,mBAAkB;AACtD,SAASC,gBAAgB,QAAQ,wBAAuB;AAExD,MAAMC,YAAY;AAElB,OAAO,MAAMC,kBAAoC;IAC/CC,QAAQ;QACN;YACEC,IAAI,GAAGH,UAAU,KAAK,CAAC;YACvBI,MAAM;YACNC,QAAQ;gBAAC;gBAAQ;aAAW;YAC5BC,SAAS,CAACC,QAAgBC;gBACxB,MAAMC,mBAAmBZ,WAAW;oBAClCa,OAAOd,UAAUY,QAAQE,KAAK;oBAC9BC,SAAS,CAACC;wBACRC,QAAQD,KAAK,CAAC,GAAGZ,UAAU,OAAO,CAAC,EAAEY;oBACvC;oBACAL;oBACAO,QAAQN,QAAQM,MAAM,IAAIhB;gBAC5B;gBAEA,OAAOW,iBAAiBM,oBAAoB;YAC9C;YACAC,QAAQ;YACRC,UAAU;gBACRb,MAAM,GAAGJ,UAAU,cAAc,CAAC;gBAClCkB,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGrB,UAAU,KAAK,CAAC;oBACjD;gBACF;gBACAK,QAAQ;oBACN;wBACED,MAAM;wBACNc,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPf,SAAS;4BACP;4BACA;4BACA;4BACA;yBACD;oBACH;iBACD;gBACDe,OAAO;YACT;QACF;QACA;YACEpB,IAAI,GAAGH,UAAU,OAAO,CAAC;YACzBI,MAAM;YACNC,QAAQ;gBAAC;aAAW;YACpBC,SAAS,CAACkB,MAAchB;gBACtB,OAAOT,iBAAiByB,MAAMhB;YAChC;YACAQ,QAAQ;YACRC,UAAU;gBACRb,MAAM,GAAGJ,UAAU,gBAAgB,CAAC;gBACpCkB,MAAM;gBACNC,OAAO;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;4BACP;4BACA;4BACA;4BACA;yBACD;oBACH;iBACD;gBACDe,OAAO;YACT;QACF;KACD;IACDE,UAAU;AACZ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/ai/models/anthropic/index.ts"],"sourcesContent":["import { anthropic } from '@ai-sdk/anthropic'\nimport { streamText } from 'ai'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { extractPromptAttachments } from '../../../utilities/extractPromptAttachments.js'\nimport { defaultSystemPrompt } from '../../prompts.js'\nimport { generateRichText } from './generateRichText.js'\n\nconst MODEL_KEY = 'ANTH-C'\nconst MODELS = [\n 'claude-opus-4-1',\n 'claude-opus-4-0',\n 'claude-sonnet-4-0',\n 'claude-3-opus-latest',\n 'claude-3-5-haiku-latest',\n 'claude-3-5-sonnet-latest',\n 'claude-3-7-sonnet-latest',\n]\n\nexport const AnthropicConfig: GenerationConfig = {\n models: [\n {\n id: `${MODEL_KEY}-text`,\n name: 'Anthropic Claude',\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: anthropic(options.model),\n onError: (error) => {\n console.error(`${MODEL_KEY}-text: `, error)\n },\n prompt: options.extractAttachments ? extractPromptAttachments(prompt) : prompt,\n system: options.system || defaultSystemPrompt,\n temperature: options.temperature || 0.7,\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: 'claude-3-5-sonnet-latest',\n label: 'Model',\n options: MODELS,\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: 'Anthropic Claude Settings',\n },\n },\n {\n id: `${MODEL_KEY}-object`,\n name: 'Anthropic Claude',\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: 'claude-3-5-sonnet-latest',\n label: 'Model',\n options: MODELS,\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: 'Anthropic Claude Settings',\n },\n },\n ],\n provider: 'Anthropic',\n}\n"],"names":["anthropic","streamText","extractPromptAttachments","defaultSystemPrompt","generateRichText","MODEL_KEY","MODELS","AnthropicConfig","models","id","name","fields","handler","prompt","options","streamTextResult","maxOutputTokens","maxTokens","model","onError","error","console","extractAttachments","system","temperature","toUIMessageStreamResponse","output","settings","type","admin","condition","data","defaultValue","label","max","min","text","provider"],"mappings":"AAAA,SAASA,SAAS,QAAQ,oBAAmB;AAC7C,SAASC,UAAU,QAAQ,KAAI;AAI/B,SAASC,wBAAwB,QAAQ,iDAAgD;AACzF,SAASC,mBAAmB,QAAQ,mBAAkB;AACtD,SAASC,gBAAgB,QAAQ,wBAAuB;AAExD,MAAMC,YAAY;AAClB,MAAMC,SAAS;IACb;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,OAAO,MAAMC,kBAAoC;IAC/CC,QAAQ;QACN;YACEC,IAAI,GAAGJ,UAAU,KAAK,CAAC;YACvBK,MAAM;YACNC,QAAQ;gBAAC;gBAAQ;aAAW;YAC5BC,SAAS,CAACC,QAAgBC;gBACxB,MAAMC,mBAAmBd,WAAW;oBAClCe,iBAAiBF,QAAQG,SAAS,IAAI;oBACtCC,OAAOlB,UAAUc,QAAQI,KAAK;oBAC9BC,SAAS,CAACC;wBACRC,QAAQD,KAAK,CAAC,GAAGf,UAAU,OAAO,CAAC,EAAEe;oBACvC;oBACAP,QAAQC,QAAQQ,kBAAkB,GAAGpB,yBAAyBW,UAAUA;oBACxEU,QAAQT,QAAQS,MAAM,IAAIpB;oBAC1BqB,aAAaV,QAAQU,WAAW,IAAI;gBACtC;gBAEA,OAAOT,iBAAiBU,yBAAyB;YACnD;YACAC,QAAQ;YACRC,UAAU;gBACRjB,MAAM,GAAGL,UAAU,cAAc,CAAC;gBAClCuB,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAG1B,UAAU,KAAK,CAAC;oBACjD;gBACF;gBACAM,QAAQ;oBACN;wBACED,MAAM;wBACNkB,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPnB,SAASR;oBACX;oBACA;wBACEsB,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;QACA;YACExB,IAAI,GAAGJ,UAAU,OAAO,CAAC;YACzBK,MAAM;YACNC,QAAQ;gBAAC;aAAW;YACpBC,SAAS,CAACwB,MAActB;gBACtB,OAAOV,iBAAiBgC,MAAMtB;YAChC;YACAY,QAAQ;YACRC,UAAU;gBACRjB,MAAM,GAAGL,UAAU,gBAAgB,CAAC;gBACpCuB,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAG1B,UAAU,OAAO,CAAC;oBACnD;gBACF;gBACAM,QAAQ;oBACN;wBACED,MAAM;wBACNkB,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPnB,SAASR;oBACX;oBACA;wBACEsB,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;IACDI,UAAU;AACZ,EAAC"}
@@ -4,6 +4,5 @@ type ElevenLabsTextToSpeechOptions = {
4
4
  export declare const generateVoice: (text: string, options: ElevenLabsTextToSpeechOptions) => Promise<{
5
5
  alignment: string[];
6
6
  buffer: Buffer<ArrayBuffer>;
7
- }>;
7
+ } | undefined>;
8
8
  export {};
9
- //# sourceMappingURL=generateVoice.d.ts.map
@@ -1,3 +1,2 @@
1
1
  import type { GenerationConfig } from '../../../types.js';
2
2
  export declare const ElevenLabsConfig: GenerationConfig;
3
- //# sourceMappingURL=index.d.ts.map
@@ -4,14 +4,14 @@ import { getAllVoices } from './voices.js';
4
4
  const { voices = [] } = await getAllVoices();
5
5
  const voiceOptions = voices.map((voice)=>{
6
6
  return {
7
- label: voice.name,
7
+ label: voice.name ?? '',
8
8
  value: voice.voice_id,
9
9
  ...voice
10
10
  };
11
11
  });
12
12
  const fieldVoiceOptions = voiceOptions.map((option)=>{
13
13
  return {
14
- label: option.name,
14
+ label: option.name ?? '',
15
15
  value: option.voice_id
16
16
  };
17
17
  });
@@ -98,6 +98,9 @@ export const ElevenLabsConfig = {
98
98
  ],
99
99
  handler: async (text, options)=>{
100
100
  const voiceData = await generateVoice(text, options);
101
+ if (!voiceData || !voiceData.buffer) {
102
+ throw new Error('Voice data missing');
103
+ }
101
104
  return {
102
105
  data: {
103
106
  alt: 'voice over'
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ai/models/elevenLabs/index.ts"],"sourcesContent":["import type { Field, File } from 'payload'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js'\nimport { generateVoice } from './generateVoice.js'\nimport { getAllVoices } from './voices.js'\n\nconst { voices = [] } = await getAllVoices()\n\nconst voiceOptions = voices.map((voice) => {\n return {\n label: voice.name,\n value: voice.voice_id,\n ...voice,\n }\n})\n\nconst fieldVoiceOptions = voiceOptions.map((option) => {\n return {\n label: option.name,\n value: option.voice_id,\n }\n})\n\nconst fields: Field[] = [\n {\n type: 'collapsible',\n admin: {\n initCollapsed: false,\n },\n fields: [\n {\n name: 'stability',\n type: 'number',\n defaultValue: 0.5,\n label: 'Stability',\n max: 1,\n min: 0,\n required: true,\n },\n {\n name: 'similarity_boost',\n type: 'number',\n defaultValue: 0.5,\n label: 'Similarity Boost',\n max: 1,\n min: 0,\n required: true,\n },\n {\n name: 'style',\n type: 'number',\n defaultValue: 0.5,\n label: 'Style',\n max: 1,\n min: 0,\n },\n {\n name: 'use_speaker_boost',\n type: 'checkbox',\n label: 'Use Speaker Boost',\n },\n ],\n label: 'Voice Settings',\n },\n {\n name: 'seed',\n type: 'number',\n label: 'Seed',\n },\n {\n type: 'row',\n fields: [\n {\n name: 'previous_text',\n type: 'textarea',\n label: 'Previous Text',\n },\n {\n name: 'next_text',\n type: 'textarea',\n label: 'Next Text',\n },\n ],\n },\n]\n\nif (voiceOptions.length) {\n fields.unshift({\n name: 'voice_id',\n type: 'select',\n defaultValue: voiceOptions[0]?.voice_id,\n label: 'Voice',\n options: fieldVoiceOptions,\n required: true,\n })\n}\n\nconst MODEL_KEY = '11Labs'\n\nexport const ElevenLabsConfig: GenerationConfig = {\n models: [\n {\n id: `${MODEL_KEY}-m-v2`,\n name: 'ElevenLabs Multilingual v2',\n fields: ['upload'],\n handler: async (text: string, options) => {\n const voiceData = await generateVoice(text, options)\n return {\n data: {\n alt: 'voice over',\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}-settings`,\n type: 'group',\n admin: {\n condition: (data) => {\n return data['model-id'] === `${MODEL_KEY}-m-v2`\n },\n },\n fields,\n label: 'ElevenLabs Multilingual v2 Settings',\n },\n },\n ],\n provider: 'ElevenLabs',\n}\n"],"names":["generateFileNameByPrompt","generateVoice","getAllVoices","voices","voiceOptions","map","voice","label","name","value","voice_id","fieldVoiceOptions","option","fields","type","admin","initCollapsed","defaultValue","max","min","required","length","unshift","options","MODEL_KEY","ElevenLabsConfig","models","id","handler","text","voiceData","data","alt","file","buffer","mimetype","size","byteLength","output","settings","condition","provider"],"mappings":"AAIA,SAASA,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,YAAY,QAAQ,cAAa;AAE1C,MAAM,EAAEC,SAAS,EAAE,EAAE,GAAG,MAAMD;AAE9B,MAAME,eAAeD,OAAOE,GAAG,CAAC,CAACC;IAC/B,OAAO;QACLC,OAAOD,MAAME,IAAI;QACjBC,OAAOH,MAAMI,QAAQ;QACrB,GAAGJ,KAAK;IACV;AACF;AAEA,MAAMK,oBAAoBP,aAAaC,GAAG,CAAC,CAACO;IAC1C,OAAO;QACLL,OAAOK,OAAOJ,IAAI;QAClBC,OAAOG,OAAOF,QAAQ;IACxB;AACF;AAEA,MAAMG,SAAkB;IACtB;QACEC,MAAM;QACNC,OAAO;YACLC,eAAe;QACjB;QACAH,QAAQ;YACN;gBACEL,MAAM;gBACNM,MAAM;gBACNG,cAAc;gBACdV,OAAO;gBACPW,KAAK;gBACLC,KAAK;gBACLC,UAAU;YACZ;YACA;gBACEZ,MAAM;gBACNM,MAAM;gBACNG,cAAc;gBACdV,OAAO;gBACPW,KAAK;gBACLC,KAAK;gBACLC,UAAU;YACZ;YACA;gBACEZ,MAAM;gBACNM,MAAM;gBACNG,cAAc;gBACdV,OAAO;gBACPW,KAAK;gBACLC,KAAK;YACP;YACA;gBACEX,MAAM;gBACNM,MAAM;gBACNP,OAAO;YACT;SACD;QACDA,OAAO;IACT;IACA;QACEC,MAAM;QACNM,MAAM;QACNP,OAAO;IACT;IACA;QACEO,MAAM;QACND,QAAQ;YACN;gBACEL,MAAM;gBACNM,MAAM;gBACNP,OAAO;YACT;YACA;gBACEC,MAAM;gBACNM,MAAM;gBACNP,OAAO;YACT;SACD;IACH;CACD;AAED,IAAIH,aAAaiB,MAAM,EAAE;IACvBR,OAAOS,OAAO,CAAC;QACbd,MAAM;QACNM,MAAM;QACNG,cAAcb,YAAY,CAAC,EAAE,EAAEM;QAC/BH,OAAO;QACPgB,SAASZ;QACTS,UAAU;IACZ;AACF;AAEA,MAAMI,YAAY;AAElB,OAAO,MAAMC,mBAAqC;IAChDC,QAAQ;QACN;YACEC,IAAI,GAAGH,UAAU,KAAK,CAAC;YACvBhB,MAAM;YACNK,QAAQ;gBAAC;aAAS;YAClBe,SAAS,OAAOC,MAAcN;gBAC5B,MAAMO,YAAY,MAAM7B,cAAc4B,MAAMN;gBAC5C,OAAO;oBACLQ,MAAM;wBACJC,KAAK;oBACP;oBACAC,MAAM;wBACJzB,MAAM,CAAC,MAAM,EAAER,yBAAyB6B,MAAM,IAAI,CAAC;wBACnDE,MAAMD,UAAUI,MAAM;wBACtBC,UAAU;wBACVC,MAAMN,UAAUI,MAAM,CAACG,UAAU;oBACnC;gBACF;YACF;YACAC,QAAQ;YACRC,UAAU;gBACR/B,MAAM,GAAGgB,UAAU,SAAS,CAAC;gBAC7BV,MAAM;gBACNC,OAAO;oBACLyB,WAAW,CAACT;wBACV,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGP,UAAU,KAAK,CAAC;oBACjD;gBACF;gBACAX;gBACAN,OAAO;YACT;QACF;KACD;IACDkC,UAAU;AACZ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/ai/models/elevenLabs/index.ts"],"sourcesContent":["import type { Field, File } from 'payload'\n\nimport type { GenerationConfig } from '../../../types.js'\nimport type { Voice } from './voices.js'\n\nimport { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js'\nimport { generateVoice } from './generateVoice.js'\nimport { getAllVoices } from './voices.js'\n\nconst { voices = [] }: { voices: Voice[] } = await getAllVoices()\n\nconst voiceOptions = voices.map((voice) => {\n return {\n label: voice.name ?? '',\n value: voice.voice_id,\n ...voice,\n }\n})\n\nconst fieldVoiceOptions = voiceOptions.map((option) => {\n return {\n label: option.name ?? '',\n value: option.voice_id,\n }\n})\n\nconst fields: Field[] = [\n {\n type: 'collapsible',\n admin: {\n initCollapsed: false,\n },\n fields: [\n {\n name: 'stability',\n type: 'number',\n defaultValue: 0.5,\n label: 'Stability',\n max: 1,\n min: 0,\n required: true,\n },\n {\n name: 'similarity_boost',\n type: 'number',\n defaultValue: 0.5,\n label: 'Similarity Boost',\n max: 1,\n min: 0,\n required: true,\n },\n {\n name: 'style',\n type: 'number',\n defaultValue: 0.5,\n label: 'Style',\n max: 1,\n min: 0,\n },\n {\n name: 'use_speaker_boost',\n type: 'checkbox',\n label: 'Use Speaker Boost',\n },\n ],\n label: 'Voice Settings',\n },\n {\n name: 'seed',\n type: 'number',\n label: 'Seed',\n },\n {\n type: 'row',\n fields: [\n {\n name: 'previous_text',\n type: 'textarea',\n label: 'Previous Text',\n },\n {\n name: 'next_text',\n type: 'textarea',\n label: 'Next Text',\n },\n ],\n },\n]\n\nif (voiceOptions.length) {\n fields.unshift({\n name: 'voice_id',\n type: 'select',\n defaultValue: voiceOptions[0]?.voice_id,\n label: 'Voice',\n options: fieldVoiceOptions,\n required: true,\n })\n}\n\nconst MODEL_KEY = '11Labs'\n\nexport const ElevenLabsConfig: GenerationConfig = {\n models: [\n {\n id: `${MODEL_KEY}-m-v2`,\n name: 'ElevenLabs Multilingual v2',\n fields: ['upload'],\n handler: async (text: string, options) => {\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: 'voice over',\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}-settings`,\n type: 'group',\n admin: {\n condition: (data) => {\n return data['model-id'] === `${MODEL_KEY}-m-v2`\n },\n },\n fields,\n label: 'ElevenLabs Multilingual v2 Settings',\n },\n },\n ],\n provider: 'ElevenLabs',\n}\n"],"names":["generateFileNameByPrompt","generateVoice","getAllVoices","voices","voiceOptions","map","voice","label","name","value","voice_id","fieldVoiceOptions","option","fields","type","admin","initCollapsed","defaultValue","max","min","required","length","unshift","options","MODEL_KEY","ElevenLabsConfig","models","id","handler","text","voiceData","buffer","Error","data","alt","file","mimetype","size","byteLength","output","settings","condition","provider"],"mappings":"AAKA,SAASA,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,YAAY,QAAQ,cAAa;AAE1C,MAAM,EAAEC,SAAS,EAAE,EAAE,GAAwB,MAAMD;AAEnD,MAAME,eAAeD,OAAOE,GAAG,CAAC,CAACC;IAC/B,OAAO;QACLC,OAAOD,MAAME,IAAI,IAAI;QACrBC,OAAOH,MAAMI,QAAQ;QACrB,GAAGJ,KAAK;IACV;AACF;AAEA,MAAMK,oBAAoBP,aAAaC,GAAG,CAAC,CAACO;IAC1C,OAAO;QACLL,OAAOK,OAAOJ,IAAI,IAAI;QACtBC,OAAOG,OAAOF,QAAQ;IACxB;AACF;AAEA,MAAMG,SAAkB;IACtB;QACEC,MAAM;QACNC,OAAO;YACLC,eAAe;QACjB;QACAH,QAAQ;YACN;gBACEL,MAAM;gBACNM,MAAM;gBACNG,cAAc;gBACdV,OAAO;gBACPW,KAAK;gBACLC,KAAK;gBACLC,UAAU;YACZ;YACA;gBACEZ,MAAM;gBACNM,MAAM;gBACNG,cAAc;gBACdV,OAAO;gBACPW,KAAK;gBACLC,KAAK;gBACLC,UAAU;YACZ;YACA;gBACEZ,MAAM;gBACNM,MAAM;gBACNG,cAAc;gBACdV,OAAO;gBACPW,KAAK;gBACLC,KAAK;YACP;YACA;gBACEX,MAAM;gBACNM,MAAM;gBACNP,OAAO;YACT;SACD;QACDA,OAAO;IACT;IACA;QACEC,MAAM;QACNM,MAAM;QACNP,OAAO;IACT;IACA;QACEO,MAAM;QACND,QAAQ;YACN;gBACEL,MAAM;gBACNM,MAAM;gBACNP,OAAO;YACT;YACA;gBACEC,MAAM;gBACNM,MAAM;gBACNP,OAAO;YACT;SACD;IACH;CACD;AAED,IAAIH,aAAaiB,MAAM,EAAE;IACvBR,OAAOS,OAAO,CAAC;QACbd,MAAM;QACNM,MAAM;QACNG,cAAcb,YAAY,CAAC,EAAE,EAAEM;QAC/BH,OAAO;QACPgB,SAASZ;QACTS,UAAU;IACZ;AACF;AAEA,MAAMI,YAAY;AAElB,OAAO,MAAMC,mBAAqC;IAChDC,QAAQ;QACN;YACEC,IAAI,GAAGH,UAAU,KAAK,CAAC;YACvBhB,MAAM;YACNK,QAAQ;gBAAC;aAAS;YAClBe,SAAS,OAAOC,MAAcN;gBAC5B,MAAMO,YAAY,MAAM7B,cAAc4B,MAAMN;gBAC5C,IAAI,CAACO,aAAa,CAACA,UAAUC,MAAM,EAAE;oBACnC,MAAM,IAAIC,MAAM;gBAClB;gBACA,OAAO;oBACLC,MAAM;wBACJC,KAAK;oBACP;oBACAC,MAAM;wBACJ3B,MAAM,CAAC,MAAM,EAAER,yBAAyB6B,MAAM,IAAI,CAAC;wBACnDI,MAAMH,UAAUC,MAAM;wBACtBK,UAAU;wBACVC,MAAMP,UAAUC,MAAM,CAACO,UAAU;oBACnC;gBACF;YACF;YACAC,QAAQ;YACRC,UAAU;gBACRhC,MAAM,GAAGgB,UAAU,SAAS,CAAC;gBAC7BV,MAAM;gBACNC,OAAO;oBACL0B,WAAW,CAACR;wBACV,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGT,UAAU,KAAK,CAAC;oBACjD;gBACF;gBACAX;gBACAN,OAAO;YACT;QACF;KACD;IACDmC,UAAU;AACZ,EAAC"}
@@ -1,4 +1,8 @@
1
+ export type Voice = {
2
+ [key: string]: any;
3
+ name?: string;
4
+ voice_id: string;
5
+ };
1
6
  export declare const getAllVoices: () => Promise<{
2
- voices: any[];
7
+ voices: Voice[];
3
8
  }>;
4
- //# sourceMappingURL=voices.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ai/models/elevenLabs/voices.ts"],"sourcesContent":["import { ElevenLabsClient } from 'elevenlabs'\nimport * as process from 'node:process'\n\nlet voicesState = { voices: [] }\nexport const getAllVoices = async () => {\n if (!process.env.ELEVENLABS_API_KEY) {\n return voicesState\n }\n\n try {\n const elevenLabs = new ElevenLabsClient()\n if (!voicesState.voices.length) {\n voicesState = await elevenLabs.voices.getAll({\n timeoutInSeconds: 10000,\n })\n }\n return voicesState\n } catch (error) {\n console.error('getAllVoices: ', error)\n return voicesState\n }\n}\n"],"names":["ElevenLabsClient","process","voicesState","voices","getAllVoices","env","ELEVENLABS_API_KEY","elevenLabs","length","getAll","timeoutInSeconds","error","console"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,aAAY;AAC7C,YAAYC,aAAa,eAAc;AAEvC,IAAIC,cAAc;IAAEC,QAAQ,EAAE;AAAC;AAC/B,OAAO,MAAMC,eAAe;IAC1B,IAAI,CAACH,QAAQI,GAAG,CAACC,kBAAkB,EAAE;QACnC,OAAOJ;IACT;IAEA,IAAI;QACF,MAAMK,aAAa,IAAIP;QACvB,IAAI,CAACE,YAAYC,MAAM,CAACK,MAAM,EAAE;YAC9BN,cAAc,MAAMK,WAAWJ,MAAM,CAACM,MAAM,CAAC;gBAC3CC,kBAAkB;YACpB;QACF;QACA,OAAOR;IACT,EAAE,OAAOS,OAAO;QACdC,QAAQD,KAAK,CAAC,kBAAkBA;QAChC,OAAOT;IACT;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/ai/models/elevenLabs/voices.ts"],"sourcesContent":["export type Voice = {\n [key: string]: any\n name?: string\n voice_id: string\n}\n\nimport { ElevenLabsClient } from 'elevenlabs'\nimport * as process from 'node:process'\n\nlet voicesState: { voices: Voice[] } = { voices: [] }\nexport const getAllVoices = async (): Promise<{ voices: Voice[] }> => {\n if (!process.env.ELEVENLABS_API_KEY) {\n return voicesState\n }\n\n try {\n const elevenLabs = new ElevenLabsClient()\n if (!voicesState.voices.length) {\n voicesState = await elevenLabs.voices.getAll({\n timeoutInSeconds: 10000,\n })\n }\n return voicesState\n } catch (error) {\n console.error('getAllVoices: ', error)\n return voicesState\n }\n}\n"],"names":["ElevenLabsClient","process","voicesState","voices","getAllVoices","env","ELEVENLABS_API_KEY","elevenLabs","length","getAll","timeoutInSeconds","error","console"],"mappings":"AAMA,SAASA,gBAAgB,QAAQ,aAAY;AAC7C,YAAYC,aAAa,eAAc;AAEvC,IAAIC,cAAmC;IAAEC,QAAQ,EAAE;AAAC;AACpD,OAAO,MAAMC,eAAe;IAC1B,IAAI,CAACH,QAAQI,GAAG,CAACC,kBAAkB,EAAE;QACnC,OAAOJ;IACT;IAEA,IAAI;QACF,MAAMK,aAAa,IAAIP;QACvB,IAAI,CAACE,YAAYC,MAAM,CAACK,MAAM,EAAE;YAC9BN,cAAc,MAAMK,WAAWJ,MAAM,CAACM,MAAM,CAAC;gBAC3CC,kBAAkB;YACpB;QACF;QACA,OAAOR;IACT,EAAE,OAAOS,OAAO;QACdC,QAAQD,KAAK,CAAC,kBAAkBA;QAChC,OAAOT;IACT;AACF,EAAC"}
@@ -1,3 +1,2 @@
1
1
  import type { GenerationModel } from '../../types.js';
2
2
  export declare const defaultGenerationModels: GenerationModel[];
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,5 @@
1
1
  import type { GenerateImageParams } from '../../../types.js';
2
2
  export declare const generateImage: (prompt: string, { images, size, style, version, }?: GenerateImageParams) => Promise<{
3
- alt: string;
3
+ alt: string | undefined;
4
4
  buffer: Buffer<ArrayBuffer>;
5
5
  }>;
6
- //# sourceMappingURL=generateImage.d.ts.map
@@ -8,21 +8,23 @@ export const generateImage = async (prompt, { images = [], size = '1024x1024', s
8
8
  options['style'] = style;
9
9
  }
10
10
  let response;
11
+ const safeVersion = version ?? undefined;
11
12
  if (images?.length) {
12
- response = await editImagesWithOpenAI(images, prompt, version);
13
+ response = await editImagesWithOpenAI(images, prompt, safeVersion);
13
14
  } else {
14
15
  response = await openaiAPI.images.generate({
15
- model: version,
16
+ model: safeVersion,
16
17
  n: 1,
17
18
  prompt,
18
19
  size,
19
20
  ...options
20
21
  });
21
22
  }
22
- const { b64_json, revised_prompt } = response.data[0] || {};
23
+ const dataArr = response?.data ?? [];
24
+ const { b64_json, revised_prompt } = dataArr[0] || {};
23
25
  return {
24
26
  alt: revised_prompt,
25
- buffer: Buffer.from(b64_json, 'base64')
27
+ buffer: Buffer.from(b64_json ?? '', 'base64')
26
28
  };
27
29
  };
28
30
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ai/models/openai/generateImage.ts"],"sourcesContent":["import type { ImagesResponse } from 'openai/resources/images'\n\nimport OpenAI from 'openai'\n\nimport type { GenerateImageParams} from '../../../types.js';\n\nimport { editImagesWithOpenAI } from '../../utils/editImagesWithOpenAI.js'\n\nexport const generateImage = async (\n prompt: string,\n {\n images = [],\n size = '1024x1024',\n style = 'natural',\n version = 'dall-e-3',\n }: GenerateImageParams = {},\n) => {\n const openaiAPI = new OpenAI()\n\n const options = {}\n if (version?.startsWith('dall')) {\n options['response_format'] = 'b64_json'\n options['style'] = style\n }\n\n let response: ImagesResponse\n if (images?.length) {\n response = await editImagesWithOpenAI(images, prompt, version)\n } else {\n response = await openaiAPI.images.generate({\n model: version,\n n: 1,\n prompt,\n size,\n ...options,\n })\n }\n\n const { b64_json, revised_prompt } = response.data[0] || {}\n return {\n alt: revised_prompt,\n buffer: Buffer.from(b64_json, 'base64'),\n }\n}\n"],"names":["OpenAI","editImagesWithOpenAI","generateImage","prompt","images","size","style","version","openaiAPI","options","startsWith","response","length","generate","model","n","b64_json","revised_prompt","data","alt","buffer","Buffer","from"],"mappings":"AAEA,OAAOA,YAAY,SAAQ;AAI3B,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E,OAAO,MAAMC,gBAAgB,OAC3BC,QACA,EACEC,SAAS,EAAE,EACXC,OAAO,WAAW,EAClBC,QAAQ,SAAS,EACjBC,UAAU,UAAU,EACA,GAAG,CAAC,CAAC;IAE3B,MAAMC,YAAY,IAAIR;IAEtB,MAAMS,UAAU,CAAC;IACjB,IAAIF,SAASG,WAAW,SAAS;QAC/BD,OAAO,CAAC,kBAAkB,GAAG;QAC7BA,OAAO,CAAC,QAAQ,GAAGH;IACrB;IAEA,IAAIK;IACJ,IAAIP,QAAQQ,QAAQ;QAClBD,WAAW,MAAMV,qBAAqBG,QAAQD,QAAQI;IACxD,OAAO;QACLI,WAAW,MAAMH,UAAUJ,MAAM,CAACS,QAAQ,CAAC;YACzCC,OAAOP;YACPQ,GAAG;YACHZ;YACAE;YACA,GAAGI,OAAO;QACZ;IACF;IAEA,MAAM,EAAEO,QAAQ,EAAEC,cAAc,EAAE,GAAGN,SAASO,IAAI,CAAC,EAAE,IAAI,CAAC;IAC1D,OAAO;QACLC,KAAKF;QACLG,QAAQC,OAAOC,IAAI,CAACN,UAAU;IAChC;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/ai/models/openai/generateImage.ts"],"sourcesContent":["import type { ImagesResponse } from 'openai/resources/images'\n\nimport OpenAI from 'openai'\n\nimport type { GenerateImageParams } from '../../../types.js'\n\nimport { editImagesWithOpenAI } from '../../utils/editImagesWithOpenAI.js'\n\nexport const generateImage = async (\n prompt: string,\n {\n images = [],\n size = '1024x1024',\n style = 'natural',\n version = 'dall-e-3',\n }: GenerateImageParams = {},\n) => {\n const openaiAPI = new OpenAI()\n\n const options: Record<string, any> = {}\n if (version?.startsWith('dall')) {\n options['response_format'] = 'b64_json'\n options['style'] = style\n }\n\n let response: ImagesResponse\n const safeVersion = version ?? undefined\n if (images?.length) {\n response = await editImagesWithOpenAI(images, prompt, safeVersion)\n } else {\n response = await openaiAPI.images.generate({\n model: safeVersion,\n n: 1,\n prompt,\n size,\n ...options,\n })\n }\n\n const dataArr = response?.data ?? []\n const { b64_json, revised_prompt } = dataArr[0] || {}\n return {\n alt: revised_prompt,\n buffer: Buffer.from(b64_json ?? '', 'base64'),\n }\n}\n"],"names":["OpenAI","editImagesWithOpenAI","generateImage","prompt","images","size","style","version","openaiAPI","options","startsWith","response","safeVersion","undefined","length","generate","model","n","dataArr","data","b64_json","revised_prompt","alt","buffer","Buffer","from"],"mappings":"AAEA,OAAOA,YAAY,SAAQ;AAI3B,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E,OAAO,MAAMC,gBAAgB,OAC3BC,QACA,EACEC,SAAS,EAAE,EACXC,OAAO,WAAW,EAClBC,QAAQ,SAAS,EACjBC,UAAU,UAAU,EACA,GAAG,CAAC,CAAC;IAE3B,MAAMC,YAAY,IAAIR;IAEtB,MAAMS,UAA+B,CAAC;IACtC,IAAIF,SAASG,WAAW,SAAS;QAC/BD,OAAO,CAAC,kBAAkB,GAAG;QAC7BA,OAAO,CAAC,QAAQ,GAAGH;IACrB;IAEA,IAAIK;IACJ,MAAMC,cAAcL,WAAWM;IAC/B,IAAIT,QAAQU,QAAQ;QAClBH,WAAW,MAAMV,qBAAqBG,QAAQD,QAAQS;IACxD,OAAO;QACLD,WAAW,MAAMH,UAAUJ,MAAM,CAACW,QAAQ,CAAC;YACzCC,OAAOJ;YACPK,GAAG;YACHd;YACAE;YACA,GAAGI,OAAO;QACZ;IACF;IAEA,MAAMS,UAAUP,UAAUQ,QAAQ,EAAE;IACpC,MAAM,EAAEC,QAAQ,EAAEC,cAAc,EAAE,GAAGH,OAAO,CAAC,EAAE,IAAI,CAAC;IACpD,OAAO;QACLI,KAAKD;QACLE,QAAQC,OAAOC,IAAI,CAACL,YAAY,IAAI;IACtC;AACF,EAAC"}
@@ -1,2 +1 @@
1
1
  export declare const generateRichText: (text: string, options?: any) => Response;
2
- //# sourceMappingURL=generateRichText.d.ts.map
@@ -1,15 +1,15 @@
1
1
  import { jsonSchema, streamObject } from 'ai';
2
+ import { extractPromptAttachments } from "../../../utilities/extractPromptAttachments.js";
2
3
  import { openai } from './openai.js';
3
4
  export const generateRichText = (text, options = {})=>{
5
+ console.log("options.layout ", options.layout);
4
6
  const streamResult = streamObject({
5
- maxTokens: options.maxTokens || 5000,
6
- model: openai(options.model, {
7
- structuredOutputs: true
8
- }),
7
+ maxOutputTokens: options.maxTokens || 5000,
8
+ model: openai(options.model),
9
9
  onError: (error)=>{
10
10
  console.error(`generateRichText: `, error);
11
11
  },
12
- prompt: text,
12
+ prompt: options.extractAttachments ? extractPromptAttachments(text) : text,
13
13
  schema: jsonSchema(options.editorSchema),
14
14
  system: `${options.system}
15
15
 
@@ -19,20 +19,17 @@ RULES:
19
19
  - Utilize the provided rich text editor tools for appropriate formatting.
20
20
  - Ensure the output follows the structure of the sample output object.
21
21
  - Produce valid JSON with no undefined or null values.
22
-
22
+ ---
23
23
  LAYOUT INSTRUCTIONS:
24
24
  ${options.layout}
25
25
 
26
- RICH TEXT EDITOR TOOLS:
27
- - Use appropriate formatting tools such as bold, italic, or underline for emphasis where needed.
28
- - Apply correct heading levels (h1, h2, h3) for hierarchical structure.
29
- - Utilize bullet points or numbered lists as required by the layout.
30
-
26
+ ---
31
27
  ADDITIONAL GUIDELINES:
32
28
  - Ensure coherence and logical flow between all sections.
33
29
  - Maintain a consistent tone and style throughout the content.
34
30
  - Use clear and concise language appropriate for the target audience.
35
- `
31
+ `,
32
+ temperature: options.temperature || 0.7
36
33
  });
37
34
  return streamResult.toTextStreamResponse();
38
35
  };
@@ -1 +1 @@
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 = (text: string, options: any = {}) => {\n const streamResult = streamObject({\n maxTokens: options.maxTokens || 5000,\n model: openai(options.model, {\n structuredOutputs: true,\n }),\n onError: (error) => {\n console.error(`generateRichText: `, error)\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","onError","error","console","prompt","schema","editorSchema","system","layout","toTextStreamResponse"],"mappings":"AAAA,SAASA,UAAU,EAAEC,YAAY,QAAQ,KAAI;AAE7C,SAASC,MAAM,QAAQ,cAAa;AAEpC,OAAO,MAAMC,mBAAmB,CAACC,MAAcC,UAAe,CAAC,CAAC;IAC9D,MAAMC,eAAeL,aAAa;QAChCM,WAAWF,QAAQE,SAAS,IAAI;QAChCC,OAAON,OAAOG,QAAQG,KAAK,EAAE;YAC3BC,mBAAmB;QACrB;QACAC,SAAS,CAACC;YACRC,QAAQD,KAAK,CAAC,CAAC,kBAAkB,CAAC,EAAEA;QACtC;QACAE,QAAQT;QACRU,QAAQd,WAAWK,QAAQU,YAAY;QACvCC,QAAQ,GAAGX,QAAQW,MAAM,CAAC;;;;;;;;;;AAU9B,EAAEX,QAAQY,MAAM,CAAC;;;;;;;;;;;AAWjB,CAAC;IACC;IACA,OAAOX,aAAaY,oBAAoB;AAC1C,EAAC"}
1
+ {"version":3,"sources":["../../../../src/ai/models/openai/generateRichText.ts"],"sourcesContent":["import { jsonSchema, streamObject } from 'ai'\n\nimport {extractPromptAttachments} from \"../../../utilities/extractPromptAttachments.js\";\nimport { openai } from './openai.js'\n\n\nexport const generateRichText = (text: string, options: any = {}) => {\n console.log(\"options.layout \", options.layout)\n const streamResult = streamObject({\n maxOutputTokens: options.maxTokens || 5000,\n model: openai(options.model),\n onError: (error) => {\n console.error(`generateRichText: `, error)\n },\n prompt: options.extractAttachments ? extractPromptAttachments(text) : 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\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 temperature: options.temperature || 0.7,\n })\n return streamResult.toTextStreamResponse()\n}\n"],"names":["jsonSchema","streamObject","extractPromptAttachments","openai","generateRichText","text","options","console","log","layout","streamResult","maxOutputTokens","maxTokens","model","onError","error","prompt","extractAttachments","schema","editorSchema","system","temperature","toTextStreamResponse"],"mappings":"AAAA,SAASA,UAAU,EAAEC,YAAY,QAAQ,KAAI;AAE7C,SAAQC,wBAAwB,QAAO,iDAAiD;AACxF,SAASC,MAAM,QAAQ,cAAa;AAGpC,OAAO,MAAMC,mBAAmB,CAACC,MAAcC,UAAe,CAAC,CAAC;IAC9DC,QAAQC,GAAG,CAAC,mBAAmBF,QAAQG,MAAM;IAC7C,MAAMC,eAAeT,aAAa;QAChCU,iBAAiBL,QAAQM,SAAS,IAAI;QACtCC,OAAOV,OAAOG,QAAQO,KAAK;QAC3BC,SAAS,CAACC;YACRR,QAAQQ,KAAK,CAAC,CAAC,kBAAkB,CAAC,EAAEA;QACtC;QACAC,QAAQV,QAAQW,kBAAkB,GAAGf,yBAAyBG,QAAQA;QACtEa,QAAQlB,WAAWM,QAAQa,YAAY;QACvCC,QAAQ,GAAGd,QAAQc,MAAM,CAAC;;;;;;;;;;AAU9B,EAAEd,QAAQG,MAAM,CAAC;;;;;;;AAOjB,CAAC;QACGY,aAAaf,QAAQe,WAAW,IAAI;IACtC;IACA,OAAOX,aAAaY,oBAAoB;AAC1C,EAAC"}
@@ -2,6 +2,5 @@ import type { SpeechCreateParams } from 'openai/resources/audio/speech';
2
2
  type OpenAITextToSpeechOptions = Exclude<SpeechCreateParams, 'input'>;
3
3
  export declare const generateVoice: (text: string, options: OpenAITextToSpeechOptions) => Promise<{
4
4
  buffer: Buffer<ArrayBuffer>;
5
- }>;
5
+ } | undefined>;
6
6
  export {};
7
- //# sourceMappingURL=generateVoice.d.ts.map
@@ -1,3 +1,2 @@
1
1
  import type { GenerationConfig } from '../../../types.js';
2
2
  export declare const OpenAIConfig: GenerationConfig;
3
- //# sourceMappingURL=index.d.ts.map