@ai-stack/payloadcms 3.2.20-beta → 3.2.21-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 (63) hide show
  1. package/dist/ai/models/anthropic/index.js +9 -15
  2. package/dist/ai/models/anthropic/index.js.map +1 -1
  3. package/dist/ai/models/generateObject.d.ts +11 -0
  4. package/dist/ai/models/generateObject.js +22 -0
  5. package/dist/ai/models/generateObject.js.map +1 -0
  6. package/dist/ai/models/openai/index.js +19 -17
  7. package/dist/ai/models/openai/index.js.map +1 -1
  8. package/dist/collections/Instructions.js +2 -0
  9. package/dist/collections/Instructions.js.map +1 -1
  10. package/dist/endpoints/index.js +55 -6
  11. package/dist/endpoints/index.js.map +1 -1
  12. package/dist/fields/ComposeField/ComposeField.js +5 -3
  13. package/dist/fields/ComposeField/ComposeField.js.map +1 -1
  14. package/dist/fields/ComposeField/ComposeField.jsx +32 -0
  15. package/dist/fields/LexicalEditor/ComposeFeatureComponent.js +1 -1
  16. package/dist/fields/LexicalEditor/ComposeFeatureComponent.js.map +1 -1
  17. package/dist/fields/LexicalEditor/ComposeFeatureComponent.jsx +24 -0
  18. package/dist/fields/LexicalEditor/feature.client.jsx +21 -0
  19. package/dist/fields/PromptEditorField/PromptEditorField.jsx +42 -0
  20. package/dist/fields/SelectField/SelectField.jsx +38 -0
  21. package/dist/providers/FieldProvider/FieldProvider.d.ts +7 -4
  22. package/dist/providers/FieldProvider/FieldProvider.js +7 -6
  23. package/dist/providers/FieldProvider/FieldProvider.js.map +1 -1
  24. package/dist/providers/FieldProvider/FieldProvider.jsx +27 -0
  25. package/dist/providers/FieldProvider/useFieldProps.d.ts +1 -1
  26. package/dist/providers/FieldProvider/useFieldProps.js +2 -2
  27. package/dist/providers/FieldProvider/useFieldProps.js.map +1 -1
  28. package/dist/providers/InstructionsProvider/InstructionsProvider.jsx +45 -0
  29. package/dist/types.d.ts +4 -4
  30. package/dist/types.js.map +1 -1
  31. package/dist/ui/Compose/Compose.js +12 -81
  32. package/dist/ui/Compose/Compose.js.map +1 -1
  33. package/dist/ui/Compose/Compose.jsx +141 -0
  34. package/dist/ui/Compose/UndoRedoActions.jsx +34 -0
  35. package/dist/ui/Compose/compose.module.css +99 -12
  36. package/dist/ui/Compose/hooks/menu/Item.jsx +15 -0
  37. package/dist/ui/Compose/hooks/menu/TranslateMenu.jsx +58 -0
  38. package/dist/ui/Compose/hooks/menu/items.jsx +10 -0
  39. package/dist/ui/Compose/hooks/menu/useMenu.js +1 -1
  40. package/dist/ui/Compose/hooks/menu/useMenu.js.map +1 -1
  41. package/dist/ui/Compose/hooks/menu/useMenu.jsx +89 -0
  42. package/dist/ui/Compose/hooks/useActiveFieldTracking.d.ts +5 -0
  43. package/dist/ui/Compose/hooks/useActiveFieldTracking.js +148 -0
  44. package/dist/ui/Compose/hooks/useActiveFieldTracking.js.map +1 -0
  45. package/dist/ui/Compose/hooks/useGenerate.js +46 -79
  46. package/dist/ui/Compose/hooks/useGenerate.js.map +1 -1
  47. package/dist/ui/Icons/Icons.jsx +78 -0
  48. package/dist/ui/Icons/LottieAnimation.jsx +64 -0
  49. package/dist/utilities/extractPromptAttachments.d.ts +2 -2
  50. package/dist/utilities/extractPromptAttachments.js.map +1 -1
  51. package/dist/utilities/fieldToJsonSchema.d.ts +37 -0
  52. package/dist/utilities/fieldToJsonSchema.js +274 -0
  53. package/dist/utilities/fieldToJsonSchema.js.map +1 -0
  54. package/dist/utilities/getFieldBySchemaPath.d.ts +12 -1
  55. package/dist/utilities/getFieldBySchemaPath.js +63 -29
  56. package/dist/utilities/getFieldBySchemaPath.js.map +1 -1
  57. package/package.json +2 -1
  58. package/dist/ai/models/anthropic/generateRichText.d.ts +0 -1
  59. package/dist/ai/models/anthropic/generateRichText.js +0 -36
  60. package/dist/ai/models/anthropic/generateRichText.js.map +0 -1
  61. package/dist/ai/models/openai/generateRichText.d.ts +0 -1
  62. package/dist/ai/models/openai/generateRichText.js +0 -37
  63. package/dist/ai/models/openai/generateRichText.js.map +0 -1
@@ -1,8 +1,6 @@
1
1
  import { anthropic } from '@ai-sdk/anthropic';
2
- import { streamText } from 'ai';
3
- import { extractPromptAttachments } from '../../../utilities/extractPromptAttachments.js';
4
2
  import { defaultSystemPrompt } from '../../prompts.js';
5
- import { generateRichText } from './generateRichText.js';
3
+ import { generateObject } from '../generateObject.js';
6
4
  const MODEL_KEY = 'ANTH-C';
7
5
  const MODELS = [
8
6
  'claude-opus-4-1',
@@ -23,17 +21,10 @@ export const AnthropicConfig = {
23
21
  'textarea'
24
22
  ],
25
23
  handler: (prompt, options)=>{
26
- const streamTextResult = streamText({
27
- maxOutputTokens: options.maxTokens || 5000,
28
- model: anthropic(options.model),
29
- onError: (error)=>{
30
- console.error(`${MODEL_KEY}-text: `, error);
31
- },
32
- prompt: options.extractAttachments ? extractPromptAttachments(prompt) : prompt,
33
- system: options.system || defaultSystemPrompt,
34
- temperature: options.temperature || 0.7
35
- });
36
- return streamTextResult.toUIMessageStreamResponse();
24
+ return generateObject(prompt, {
25
+ ...options,
26
+ system: options.system || defaultSystemPrompt
27
+ }, anthropic(options.model));
37
28
  },
38
29
  output: 'text',
39
30
  settings: {
@@ -84,7 +75,10 @@ export const AnthropicConfig = {
84
75
  'richText'
85
76
  ],
86
77
  handler: (text, options)=>{
87
- return generateRichText(text, options);
78
+ return generateObject(text, {
79
+ ...options,
80
+ system: options.system || defaultSystemPrompt
81
+ }, anthropic(options.model));
88
82
  },
89
83
  output: 'text',
90
84
  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 { 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;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AU;AACZ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/ai/models/anthropic/index.ts"],"sourcesContent":["import { anthropic } from '@ai-sdk/anthropic'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { defaultSystemPrompt } from '../../prompts.js'\nimport { generateObject } from '../generateObject.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: (\n prompt: string,\n options: {\n extractAttachments?: boolean\n locale?: string\n maxTokens?: number\n model: string\n schema?: Record<string, any>\n system?: string\n temperature?: number\n },\n ) => {\n return generateObject(\n prompt,\n {\n ...options,\n system: options.system || defaultSystemPrompt,\n },\n anthropic(options.model),\n )\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',\n 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 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 generateObject(\n text,\n {\n ...options,\n system: options.system || defaultSystemPrompt,\n },\n anthropic(options.model),\n )\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',\n 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 name: 'extractAttachments',\n type: 'checkbox',\n },\n ],\n label: 'Anthropic Claude Settings',\n },\n },\n ],\n provider: 'Anthropic',\n}\n"],"names":["anthropic","defaultSystemPrompt","generateObject","MODEL_KEY","MODELS","AnthropicConfig","models","id","name","fields","handler","prompt","options","system","model","output","settings","type","admin","condition","data","defaultValue","label","max","min","text","provider"],"mappings":"AAAA,SAASA,SAAS,QAAQ,oBAAmB;AAI7C,SAASC,mBAAmB,QAAQ,mBAAkB;AACtD,SAASC,cAAc,QAAQ,uBAAsB;AAErD,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,CACPC,QACAC;gBAUA,OAAOV,eACLS,QACA;oBACE,GAAGC,OAAO;oBACVC,QAAQD,QAAQC,MAAM,IAAIZ;gBAC5B,GACAD,UAAUY,QAAQE,KAAK;YAE3B;YACAC,QAAQ;YACRC,UAAU;gBACRR,MAAM,GAAGL,UAAU,cAAc,CAAC;gBAClCc,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGjB,UAAU,KAAK,CAAC;oBACjD;gBACF;gBACAM,QAAQ;oBACN;wBACED,MAAM;wBACNS,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPV,SAASR;oBACX;oBACA;wBACEa,MAAM;wBACNR,QAAQ;4BACN;gCACED,MAAM;gCACNS,MAAM;gCACNI,cAAc;4BAChB;4BACA;gCACEb,MAAM;gCACNS,MAAM;gCACNI,cAAc;gCACdE,KAAK;gCACLC,KAAK;4BACP;yBACD;oBACH;oBACA;wBACEhB,MAAM;wBACNS,MAAM;oBACR;iBACD;gBACDK,OAAO;YACT;QACF;QACA;YACEf,IAAI,GAAGJ,UAAU,OAAO,CAAC;YACzBK,MAAM;YACNC,QAAQ;gBAAC;aAAW;YACpBC,SAAS,CAACe,MAAcb;gBACtB,OAAOV,eACLuB,MACA;oBACE,GAAGb,OAAO;oBACVC,QAAQD,QAAQC,MAAM,IAAIZ;gBAC5B,GACAD,UAAUY,QAAQE,KAAK;YAE3B;YACAC,QAAQ;YACRC,UAAU;gBACRR,MAAM,GAAGL,UAAU,gBAAgB,CAAC;gBACpCc,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGjB,UAAU,OAAO,CAAC;oBACnD;gBACF;gBACAM,QAAQ;oBACN;wBACED,MAAM;wBACNS,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPV,SAASR;oBACX;oBACA;wBACEa,MAAM;wBACNR,QAAQ;4BACN;gCACED,MAAM;gCACNS,MAAM;gCACNI,cAAc;4BAChB;4BACA;gCACEb,MAAM;gCACNS,MAAM;gCACNI,cAAc;gCACdE,KAAK;gCACLC,KAAK;4BACP;yBACD;oBACH;oBACA;wBACEhB,MAAM;wBACNS,MAAM;oBACR;iBACD;gBACDK,OAAO;YACT;QACF;KACD;IACDI,UAAU;AACZ,EAAC"}
@@ -0,0 +1,11 @@
1
+ import type { LanguageModel } from 'ai';
2
+ export interface GenerateObjectOptions {
3
+ [key: string]: any;
4
+ extractAttachments?: boolean;
5
+ maxTokens?: number;
6
+ providerOptions?: Record<string, any>;
7
+ schema?: Record<string, any>;
8
+ system?: string;
9
+ temperature?: number;
10
+ }
11
+ export declare const generateObject: (text: string, options: GenerateObjectOptions | undefined, model: LanguageModel) => Response;
@@ -0,0 +1,22 @@
1
+ import { jsonSchema, streamObject } from 'ai';
2
+ import { extractPromptAttachments } from '../../utilities/extractPromptAttachments.js';
3
+ export const generateObject = (text, options = {}, model)=>{
4
+ const prompt = options.extractAttachments ? extractPromptAttachments(text) : text;
5
+ const streamResult = streamObject({
6
+ maxOutputTokens: options.maxTokens || 5000,
7
+ model,
8
+ onError: (error)=>{
9
+ console.error('generateObject (structured): ', error);
10
+ },
11
+ prompt,
12
+ schema: jsonSchema(options.schema),
13
+ system: options.system,
14
+ temperature: options.temperature ?? 0.7,
15
+ ...options.providerOptions ? {
16
+ providerOptions: options.providerOptions
17
+ } : {}
18
+ });
19
+ return streamResult.toTextStreamResponse();
20
+ };
21
+
22
+ //# sourceMappingURL=generateObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/ai/models/generateObject.ts"],"sourcesContent":["import type { LanguageModel } from 'ai'\n\nimport { jsonSchema, streamObject } from 'ai'\n\nimport { extractPromptAttachments } from '../../utilities/extractPromptAttachments.js'\n\nexport interface GenerateObjectOptions {\n // Allow additional provider-specific params without typing friction\n [key: string]: any\n\n extractAttachments?: boolean\n maxTokens?: number\n // Provider-specific passthrough options (e.g., OpenAI strictJsonSchema)\n providerOptions?: Record<string, any>\n // Structured output schema (JSON Schema for object generation)\n schema?: Record<string, any>\n\n // Common generation options\n system?: string\n\n temperature?: number\n}\n\nexport const generateObject = (\n text: string,\n options: GenerateObjectOptions = {},\n model: LanguageModel,\n) => {\n const prompt = options.extractAttachments ? extractPromptAttachments(text) : text\n\n const streamResult = streamObject({\n maxOutputTokens: options.maxTokens || 5000,\n model,\n onError: (error) => {\n console.error('generateObject (structured): ', error)\n },\n prompt,\n schema: jsonSchema(options.schema as any),\n system: options.system,\n temperature: options.temperature ?? 0.7,\n ...(options.providerOptions ? { providerOptions: options.providerOptions } : {}),\n })\n\n return streamResult.toTextStreamResponse()\n}\n"],"names":["jsonSchema","streamObject","extractPromptAttachments","generateObject","text","options","model","prompt","extractAttachments","streamResult","maxOutputTokens","maxTokens","onError","error","console","schema","system","temperature","providerOptions","toTextStreamResponse"],"mappings":"AAEA,SAASA,UAAU,EAAEC,YAAY,QAAQ,KAAI;AAE7C,SAASC,wBAAwB,QAAQ,8CAA6C;AAmBtF,OAAO,MAAMC,iBAAiB,CAC5BC,MACAC,UAAiC,CAAC,CAAC,EACnCC;IAEA,MAAMC,SAASF,QAAQG,kBAAkB,GAAGN,yBAAyBE,QAAQA;IAE3E,MAAMK,eAAeR,aAAa;QAChCS,iBAAiBL,QAAQM,SAAS,IAAI;QACtCL;QACAM,SAAS,CAACC;YACRC,QAAQD,KAAK,CAAC,iCAAiCA;QACjD;QACAN;QACAQ,QAAQf,WAAWK,QAAQU,MAAM;QACjCC,QAAQX,QAAQW,MAAM;QACtBC,aAAaZ,QAAQY,WAAW,IAAI;QACpC,GAAIZ,QAAQa,eAAe,GAAG;YAAEA,iBAAiBb,QAAQa,eAAe;QAAC,IAAI,CAAC,CAAC;IACjF;IAEA,OAAOT,aAAaU,oBAAoB;AAC5C,EAAC"}
@@ -1,9 +1,7 @@
1
- import { streamText } from 'ai';
2
- import { extractPromptAttachments } from '../../../utilities/extractPromptAttachments.js';
3
1
  import { defaultSystemPrompt } from '../../prompts.js';
4
2
  import { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js';
3
+ import { generateObject } from '../generateObject.js';
5
4
  import { generateImage } from './generateImage.js';
6
- import { generateRichText } from './generateRichText.js';
7
5
  import { generateVoice } from './generateVoice.js';
8
6
  import { openai } from './openai.js';
9
7
  const MODEL_KEY = 'Oai';
@@ -28,21 +26,16 @@ export const OpenAIConfig = {
28
26
  'textarea'
29
27
  ],
30
28
  handler: (prompt, options)=>{
31
- const streamTextResult = streamText({
32
- maxOutputTokens: options.maxTokens || 5000,
33
- model: openai(options.model),
34
- onError: (error)=>{
35
- console.error(`${MODEL_KEY}-text: `, error);
29
+ return generateObject(prompt, {
30
+ ...options,
31
+ providerOptions: {
32
+ openai: {
33
+ strictJsonSchema: true,
34
+ structuredOutputs: true
35
+ }
36
36
  },
37
- temperature: options.temperature || 0.7,
38
- // TODO: Implement billing/token consumption
39
- // onFinish: (stepResult) => {
40
- // console.log('streamText : finish : ', stepResult)
41
- // },
42
- prompt: options.extractAttachments ? extractPromptAttachments(prompt) : prompt,
43
37
  system: options.system || defaultSystemPrompt
44
- });
45
- return streamTextResult.toUIMessageStreamResponse();
38
+ }, openai(options.model));
46
39
  },
47
40
  output: 'text',
48
41
  settings: {
@@ -375,7 +368,16 @@ export const OpenAIConfig = {
375
368
  'richText'
376
369
  ],
377
370
  handler: (text, options)=>{
378
- return generateRichText(text, options);
371
+ return generateObject(text, {
372
+ ...options,
373
+ providerOptions: {
374
+ openai: {
375
+ strictJsonSchema: true,
376
+ structuredOutputs: true
377
+ }
378
+ },
379
+ system: options.system || defaultSystemPrompt
380
+ }, openai(options.model));
379
381
  },
380
382
  output: 'text',
381
383
  settings: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ai/models/openai/index.ts"],"sourcesContent":["import type { SpeechCreateParams } from 'openai/resources/audio/speech'\nimport type { File } from 'payload'\n\nimport { streamText } from 'ai'\n\nimport type { GenerationConfig } from '../../../types.js'\n\nimport { extractPromptAttachments } from '../../../utilities/extractPromptAttachments.js'\nimport { defaultSystemPrompt } from '../../prompts.js'\nimport { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js'\nimport { generateImage } from './generateImage.js'\nimport { generateRichText } from './generateRichText.js'\nimport { generateVoice } from './generateVoice.js'\nimport { openai } from './openai.js'\n\nconst MODEL_KEY = 'Oai'\nconst MODELS = [\n 'gpt-5',\n 'gpt-5-mini',\n 'gpt-5-nano',\n 'gpt-4.1',\n 'gpt-4o',\n 'gpt-4-turbo',\n 'gpt-4o-mini',\n 'gpt-3.5-turbo',\n]\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: (\n prompt: string,\n options: {\n extractAttachments: boolean\n locale: string\n maxTokens: number\n model: string\n system: string\n temperature: number\n },\n ) => {\n const streamTextResult = streamText({\n maxOutputTokens: options.maxTokens || 5000,\n model: openai(options.model),\n onError: (error) => {\n console.error(`${MODEL_KEY}-text: `, error)\n },\n temperature: options.temperature || 0.7,\n\n // TODO: Implement billing/token consumption\n // onFinish: (stepResult) => {\n // console.log('streamText : finish : ', stepResult)\n // },\n prompt: options.extractAttachments ? extractPromptAttachments(prompt) : prompt,\n system: options.system || defaultSystemPrompt,\n })\n\n return streamTextResult.toUIMessageStreamResponse()\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-text-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-text`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o-mini',\n label: 'Model',\n options: MODELS,\n },\n {\n type: 'row',\n 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 name: 'extractAttachments',\n type: 'checkbox',\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n {\n id: 'dall-e',\n name: 'OpenAI DALL-E',\n fields: ['upload'],\n handler: async (prompt: string, options) => {\n const imageData = await generateImage(prompt, options)\n return {\n data: {\n alt: imageData.alt,\n },\n file: {\n name: `image_${generateFileNameByPrompt(imageData.alt || prompt)}.jpeg`,\n data: imageData.buffer,\n mimetype: 'image/jpeg',\n size: imageData.buffer.byteLength,\n } as File,\n }\n },\n output: 'image',\n settings: {\n name: 'dalle-e-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'dall-e'\n },\n },\n fields: [\n {\n name: 'version',\n type: 'select',\n defaultValue: 'dall-e-3',\n label: 'Version',\n options: ['dall-e-3', 'dall-e-2'],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'size',\n type: 'select',\n defaultValue: '1024x1024',\n label: 'Size',\n options: ['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792'],\n },\n {\n name: 'style',\n type: 'select',\n defaultValue: 'natural',\n label: 'Style',\n options: ['vivid', 'natural'],\n },\n ],\n },\n {\n name: 'enable-prompt-optimization',\n type: 'checkbox',\n label: 'Optimize prompt',\n },\n ],\n label: 'OpenAI DALL-E Settings',\n },\n },\n {\n id: 'gpt-image-1',\n name: 'OpenAI GPT Image 1',\n fields: ['upload'],\n handler: async (prompt: string, options) => {\n const imageData = await generateImage(prompt, options)\n return {\n data: {\n alt: imageData.alt,\n },\n file: {\n name: `image_${generateFileNameByPrompt(imageData.alt || prompt)}.png`,\n data: imageData.buffer,\n mimetype: 'image/png',\n size: imageData.buffer.byteLength,\n } as File,\n }\n },\n output: 'image',\n settings: {\n name: 'gpt-image-1-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'gpt-image-1'\n },\n },\n fields: [\n {\n name: 'version',\n type: 'select',\n defaultValue: 'gpt-image-1',\n label: 'Version',\n options: ['gpt-image-1'],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'size',\n type: 'select',\n defaultValue: 'auto',\n label: 'Size',\n options: ['1024x1024', '1024x1536', '1536x1024', 'auto'],\n },\n {\n name: 'quality',\n type: 'select',\n defaultValue: 'auto',\n label: 'Quality',\n options: ['low', 'medium', 'high', 'auto'],\n },\n ],\n },\n {\n name: 'output_format',\n type: 'select',\n defaultValue: 'png',\n label: 'Output Format',\n options: ['png', 'jpeg', 'webp'],\n },\n {\n name: 'output_compression',\n type: 'number',\n admin: {\n condition(data) {\n return data.output_format === 'jpeg' || data.output_format === 'webp'\n },\n },\n defaultValue: 100,\n label: 'Output Compression',\n max: 100,\n min: 0,\n },\n {\n name: 'background',\n type: 'select',\n admin: {\n condition(data) {\n return data.output_format === 'png' || data.output_format === 'webp'\n },\n },\n defaultValue: 'white',\n label: 'Background',\n options: ['white', 'transparent'],\n },\n {\n name: 'moderation',\n type: 'select',\n defaultValue: 'auto',\n label: 'Moderation',\n options: ['auto', 'low'],\n },\n ],\n label: 'OpenAI GPT Image 1 Settings',\n },\n },\n {\n id: 'tts',\n name: 'OpenAI Text-to-Speech',\n fields: ['upload'],\n handler: async (text: string, options) => {\n //TODO: change it to open ai text to speech api\n const voiceData = await generateVoice(text, options)\n if (!voiceData || !voiceData.buffer) {\n throw new Error('Voice data missing')\n }\n return {\n data: {\n alt: text,\n },\n file: {\n name: `voice_${generateFileNameByPrompt(text)}.mp3`,\n data: voiceData.buffer,\n mimetype: 'audio/mp3',\n size: voiceData.buffer.byteLength,\n } as File,\n }\n },\n output: 'audio',\n settings: {\n name: `${MODEL_KEY}-tts-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'tts'\n },\n },\n fields: [\n {\n name: 'voice',\n type: 'select',\n defaultValue: 'alloy',\n label: 'Voice',\n options: ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'] as Array<\n SpeechCreateParams['voice']\n >,\n },\n {\n name: 'model',\n type: 'select',\n defaultValue: 'tts-1',\n label: 'Model',\n options: ['tts-1', 'tts-1-hd'] as Array<SpeechCreateParams['model']>,\n },\n {\n name: 'response_format',\n type: 'select',\n defaultValue: 'mp3',\n label: 'Response Format',\n options: ['mp3', 'opus', 'aac', 'flac', 'wav', 'pcm'],\n },\n {\n name: 'speed',\n type: 'number',\n defaultValue: 1,\n label: 'Speed',\n max: 4,\n min: 0.25,\n },\n ],\n label: 'OpenAI Text-to-Speech Settings',\n },\n },\n {\n id: `${MODEL_KEY}-object`,\n name: 'OpenAI GPT',\n fields: ['richText'],\n handler: (text: string, options) => {\n return generateRichText(text, options)\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-object-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-object`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o',\n label: 'Model',\n options: MODELS,\n },\n {\n type: 'row',\n 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 name: 'extractAttachments',\n type: 'checkbox',\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n ],\n provider: 'OpenAI',\n}\n"],"names":["streamText","extractPromptAttachments","defaultSystemPrompt","generateFileNameByPrompt","generateImage","generateRichText","generateVoice","openai","MODEL_KEY","MODELS","OpenAIConfig","models","id","name","fields","handler","prompt","options","streamTextResult","maxOutputTokens","maxTokens","model","onError","error","console","temperature","extractAttachments","system","toUIMessageStreamResponse","output","settings","type","admin","condition","data","defaultValue","label","max","min","imageData","alt","file","buffer","mimetype","size","byteLength","output_format","text","voiceData","Error","provider"],"mappings":"AAGA,SAASA,UAAU,QAAQ,KAAI;AAI/B,SAASC,wBAAwB,QAAQ,iDAAgD;AACzF,SAASC,mBAAmB,QAAQ,mBAAkB;AACtD,SAASC,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,MAAM,QAAQ,cAAa;AAEpC,MAAMC,YAAY;AAClB,MAAMC,SAAS;IACb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,6FAA6F;AAC7F,OAAO,MAAMC,eAAiC;IAC5CC,QAAQ;QACN;YACEC,IAAI,GAAGJ,UAAU,KAAK,CAAC;YACvBK,MAAM;YACNC,QAAQ;gBAAC;gBAAQ;aAAW;YAC5BC,SAAS,CACPC,QACAC;gBASA,MAAMC,mBAAmBl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CuB,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;wBACNjB,QAAQ;4BACN;gCACED,MAAM;gCACNkB,MAAM;gCACNI,cAAc;4BAChB;4BACA;gCACEtB,MAAM;gCACNkB,MAAM;gCACNI,cAAc;gCACdE,KAAK;gCACLC,KAAK;4BACP;yBACD;oBACH;oBACA;wBACEzB,MAAM;wBACNkB,MAAM;oBACR;iBACD;gBACDK,OAAO;YACT;QACF;KACD;IACDc,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 type { GenerationConfig } from '../../../types.js'\n\nimport { defaultSystemPrompt } from '../../prompts.js'\nimport { generateFileNameByPrompt } from '../../utils/generateFileNameByPrompt.js'\nimport { generateObject } from '../generateObject.js'\nimport { generateImage } from './generateImage.js'\nimport { generateVoice } from './generateVoice.js'\nimport { openai } from './openai.js'\n\nconst MODEL_KEY = 'Oai'\nconst MODELS = [\n 'gpt-5',\n 'gpt-5-mini',\n 'gpt-5-nano',\n 'gpt-4.1',\n 'gpt-4o',\n 'gpt-4-turbo',\n 'gpt-4o-mini',\n 'gpt-3.5-turbo',\n]\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: (\n prompt: string,\n options: {\n extractAttachments?: boolean\n locale?: string\n maxTokens?: number\n model: string\n schema?: Record<string, any>\n system?: string\n temperature?: number\n },\n ) => {\n return generateObject(\n prompt,\n {\n ...options,\n providerOptions: {\n openai: {\n strictJsonSchema: true,\n structuredOutputs: true,\n },\n },\n system: options.system || defaultSystemPrompt,\n },\n openai(options.model),\n )\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: MODELS,\n },\n {\n type: 'row',\n 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 name: 'extractAttachments',\n type: 'checkbox',\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n {\n id: 'dall-e',\n name: 'OpenAI DALL-E',\n fields: ['upload'],\n handler: async (prompt: string, options) => {\n const imageData = await generateImage(prompt, options)\n return {\n data: {\n alt: imageData.alt,\n },\n file: {\n name: `image_${generateFileNameByPrompt(imageData.alt || prompt)}.jpeg`,\n data: imageData.buffer,\n mimetype: 'image/jpeg',\n size: imageData.buffer.byteLength,\n } as File,\n }\n },\n output: 'image',\n settings: {\n name: 'dalle-e-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'dall-e'\n },\n },\n fields: [\n {\n name: 'version',\n type: 'select',\n defaultValue: 'dall-e-3',\n label: 'Version',\n options: ['dall-e-3', 'dall-e-2'],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'size',\n type: 'select',\n defaultValue: '1024x1024',\n label: 'Size',\n options: ['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792'],\n },\n {\n name: 'style',\n type: 'select',\n defaultValue: 'natural',\n label: 'Style',\n options: ['vivid', 'natural'],\n },\n ],\n },\n {\n name: 'enable-prompt-optimization',\n type: 'checkbox',\n label: 'Optimize prompt',\n },\n ],\n label: 'OpenAI DALL-E Settings',\n },\n },\n {\n id: 'gpt-image-1',\n name: 'OpenAI GPT Image 1',\n fields: ['upload'],\n handler: async (prompt: string, options) => {\n const imageData = await generateImage(prompt, options)\n return {\n data: {\n alt: imageData.alt,\n },\n file: {\n name: `image_${generateFileNameByPrompt(imageData.alt || prompt)}.png`,\n data: imageData.buffer,\n mimetype: 'image/png',\n size: imageData.buffer.byteLength,\n } as File,\n }\n },\n output: 'image',\n settings: {\n name: 'gpt-image-1-settings',\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'gpt-image-1'\n },\n },\n fields: [\n {\n name: 'version',\n type: 'select',\n defaultValue: 'gpt-image-1',\n label: 'Version',\n options: ['gpt-image-1'],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'size',\n type: 'select',\n defaultValue: 'auto',\n label: 'Size',\n options: ['1024x1024', '1024x1536', '1536x1024', 'auto'],\n },\n {\n name: 'quality',\n type: 'select',\n defaultValue: 'auto',\n label: 'Quality',\n options: ['low', 'medium', 'high', 'auto'],\n },\n ],\n },\n {\n name: 'output_format',\n type: 'select',\n defaultValue: 'png',\n label: 'Output Format',\n options: ['png', 'jpeg', 'webp'],\n },\n {\n name: 'output_compression',\n type: 'number',\n admin: {\n condition(data) {\n return data.output_format === 'jpeg' || data.output_format === 'webp'\n },\n },\n defaultValue: 100,\n label: 'Output Compression',\n max: 100,\n min: 0,\n },\n {\n name: 'background',\n type: 'select',\n admin: {\n condition(data) {\n return data.output_format === 'png' || data.output_format === 'webp'\n },\n },\n defaultValue: 'white',\n label: 'Background',\n options: ['white', 'transparent'],\n },\n {\n name: 'moderation',\n type: 'select',\n defaultValue: 'auto',\n label: 'Moderation',\n options: ['auto', 'low'],\n },\n ],\n label: 'OpenAI GPT Image 1 Settings',\n },\n },\n {\n id: 'tts',\n name: 'OpenAI Text-to-Speech',\n fields: ['upload'],\n handler: async (text: string, options) => {\n //TODO: change it to open ai text to speech api\n const voiceData = await generateVoice(text, options)\n if (!voiceData || !voiceData.buffer) {\n throw new Error('Voice data missing')\n }\n return {\n data: {\n alt: text,\n },\n file: {\n name: `voice_${generateFileNameByPrompt(text)}.mp3`,\n data: voiceData.buffer,\n mimetype: 'audio/mp3',\n size: voiceData.buffer.byteLength,\n } as File,\n }\n },\n output: 'audio',\n settings: {\n name: `${MODEL_KEY}-tts-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === 'tts'\n },\n },\n fields: [\n {\n name: 'voice',\n type: 'select',\n defaultValue: 'alloy',\n label: 'Voice',\n options: ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'] as Array<\n SpeechCreateParams['voice']\n >,\n },\n {\n name: 'model',\n type: 'select',\n defaultValue: 'tts-1',\n label: 'Model',\n options: ['tts-1', 'tts-1-hd'] as Array<SpeechCreateParams['model']>,\n },\n {\n name: 'response_format',\n type: 'select',\n defaultValue: 'mp3',\n label: 'Response Format',\n options: ['mp3', 'opus', 'aac', 'flac', 'wav', 'pcm'],\n },\n {\n name: 'speed',\n type: 'number',\n defaultValue: 1,\n label: 'Speed',\n max: 4,\n min: 0.25,\n },\n ],\n label: 'OpenAI Text-to-Speech Settings',\n },\n },\n {\n id: `${MODEL_KEY}-object`,\n name: 'OpenAI GPT',\n fields: ['richText'],\n handler: (text: string, options) => {\n return generateObject(\n text,\n {\n ...options,\n providerOptions: {\n openai: {\n strictJsonSchema: true,\n structuredOutputs: true,\n },\n },\n system: options.system || defaultSystemPrompt,\n },\n openai(options.model),\n )\n },\n output: 'text',\n settings: {\n name: `${MODEL_KEY}-object-settings`,\n type: 'group',\n admin: {\n condition(data) {\n return data['model-id'] === `${MODEL_KEY}-object`\n },\n },\n fields: [\n {\n name: 'model',\n type: 'select',\n defaultValue: 'gpt-4o',\n label: 'Model',\n options: MODELS,\n },\n {\n type: 'row',\n 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 name: 'extractAttachments',\n type: 'checkbox',\n },\n ],\n label: 'OpenAI GPT Settings',\n },\n },\n ],\n provider: 'OpenAI',\n}\n"],"names":["defaultSystemPrompt","generateFileNameByPrompt","generateObject","generateImage","generateVoice","openai","MODEL_KEY","MODELS","OpenAIConfig","models","id","name","fields","handler","prompt","options","providerOptions","strictJsonSchema","structuredOutputs","system","model","output","settings","type","admin","condition","data","defaultValue","label","max","min","imageData","alt","file","buffer","mimetype","size","byteLength","output_format","text","voiceData","Error","provider"],"mappings":"AAKA,SAASA,mBAAmB,QAAQ,mBAAkB;AACtD,SAASC,wBAAwB,QAAQ,0CAAyC;AAClF,SAASC,cAAc,QAAQ,uBAAsB;AACrD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,MAAM,QAAQ,cAAa;AAEpC,MAAMC,YAAY;AAClB,MAAMC,SAAS;IACb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,6FAA6F;AAC7F,OAAO,MAAMC,eAAiC;IAC5CC,QAAQ;QACN;YACEC,IAAI,GAAGJ,UAAU,KAAK,CAAC;YACvBK,MAAM;YACNC,QAAQ;gBAAC;gBAAQ;aAAW;YAC5BC,SAAS,CACPC,QACAC;gBAUA,OAAOb,eACLY,QACA;oBACE,GAAGC,OAAO;oBACVC,iBAAiB;wBACfX,QAAQ;4BACNY,kBAAkB;4BAClBC,mBAAmB;wBACrB;oBACF;oBACAC,QAAQJ,QAAQI,MAAM,IAAInB;gBAC5B,GACAK,OAAOU,QAAQK,KAAK;YAExB;YACAC,QAAQ;YACRC,UAAU;gBACRX,MAAM,GAAGL,UAAU,cAAc,CAAC;gBAClCiB,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGpB,UAAU,KAAK,CAAC;oBACjD;gBACF;gBACAM,QAAQ;oBACN;wBACED,MAAM;wBACNY,MAAM;wBACNI,cAAc;wBACdC,OAAO;w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AAS;yBAAW;oBAChC;oBACA;wBACEJ,MAAM;wBACNY,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPb,SAAS;4BAAC;4BAAO;4BAAQ;4BAAO;4BAAQ;4BAAO;yBAAM;oBACvD;oBACA;wBACEJ,MAAM;wBACNY,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPC,KAAK;wBACLC,KAAK;oBACP;iBACD;gBACDF,OAAO;YACT;QACF;QACA;YACElB,IAAI,GAAGJ,UAAU,OAAO,CAAC;YACzBK,MAAM;YACNC,QAAQ;gBAAC;aAAW;YACpBC,SAAS,CAAC0B,MAAcxB;gBACtB,OAAOb,eACLqC,MACA;oBACE,GAAGxB,OAAO;oBACVC,iBAAiB;wBACfX,QAAQ;4BACNY,kBAAkB;4BAClBC,mBAAmB;wBACrB;oBACF;oBACAC,QAAQJ,QAAQI,MAAM,IAAInB;gBAC5B,GACAK,OAAOU,QAAQK,KAAK;YAExB;YACAC,QAAQ;YACRC,UAAU;gBACRX,MAAM,GAAGL,UAAU,gBAAgB,CAAC;gBACpCiB,MAAM;gBACNC,OAAO;oBACLC,WAAUC,IAAI;wBACZ,OAAOA,IAAI,CAAC,WAAW,KAAK,GAAGpB,UAAU,OAAO,CAAC;oBACnD;gBACF;gBACAM,QAAQ;oBACN;wBACED,MAAM;wBACNY,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPb,SAASR;oBACX;oBACA;wBACEgB,MAAM;wBACNX,QAAQ;4BACN;gCACED,MAAM;gCACNY,MAAM;gCACNI,cAAc;4BAChB;4BACA;gCACEhB,MAAM;gCACNY,MAAM;gCACNI,cAAc;gCACdE,KAAK;gCACLC,KAAK;4BACP;yBACD;oBACH;oBACA;wBACEnB,MAAM;wBACNY,MAAM;oBACR;iBACD;gBACDK,OAAO;YACT;QACF;KACD;IACDc,UAAU;AACZ,EAAC"}
@@ -215,10 +215,12 @@ informative and accurate but also captivating and beautifully structured.`,
215
215
  * - Layouts can be saved in as an array
216
216
  * - User can add their own layout to collections and use it later for generate specific rich text
217
217
  * - User can select previously added layout
218
+ * - IMP: Remove layout from default, this seem to affect other functions like rephrase etc.
218
219
  */ /** TODO:
219
220
  * - Layouts can be saved in as an array
220
221
  * - User can add their own layout to collections and use it later for generate specific rich text
221
222
  * - User can select previously added layout
223
+ * - IMP: Remove layout from default, this seem to affect other functions like rephrase etc.
222
224
  */ name: 'layout',
223
225
  type: 'textarea',
224
226
  admin: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/collections/Instructions.ts"],"sourcesContent":["import type { CollectionConfig, GroupField } from 'payload'\nimport type { PluginConfig } from 'src/types.js'\n\nimport { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\nimport { getGenerationModels } from '../utilities/getGenerationModels.js'\n\nconst groupSettings = (pluginConfig: PluginConfig) =>\n (getGenerationModels(pluginConfig) ?? []).reduce((fields, model) => {\n if (model.settings) {\n fields.push(model.settings)\n }\n return fields\n }, [] as GroupField[])\n\nconst modelOptions = (pluginConfig: PluginConfig) =>\n (getGenerationModels(pluginConfig) ?? []).map((model) => {\n return {\n fields: model.fields,\n label: model.name,\n value: model.id,\n }\n })\n\nconst defaultAccessConfig = {\n create: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n delete: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n read: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n update: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n}\n\nconst defaultAdminConfig = {\n group: 'Plugins',\n hidden: true,\n}\n\nexport const instructionsCollection = (pluginConfig: PluginConfig) =>\n <CollectionConfig>{\n labels: {\n plural: 'Compose Settings',\n singular: 'Compose Setting',\n },\n ...pluginConfig.overrideInstructions,\n slug: PLUGIN_INSTRUCTIONS_TABLE,\n access: {\n ...defaultAccessConfig,\n ...pluginConfig.overrideInstructions?.access,\n },\n admin: {\n ...defaultAdminConfig,\n ...pluginConfig.overrideInstructions?.admin,\n },\n fields: [\n {\n name: 'schema-path',\n type: 'text',\n admin: {\n description: \"Please don't change this unless you're sure of what you're doing\",\n },\n unique: true,\n },\n {\n name: 'field-type',\n type: 'select',\n admin: {\n description: \"Please don't change this unless you're sure of what you're doing\",\n },\n defaultValue: 'text',\n label: 'Field type',\n options: [\n {\n label: 'text',\n value: 'text',\n },\n {\n label: 'textarea',\n value: 'textarea',\n },\n {\n label: 'upload',\n value: 'upload',\n },\n {\n label: 'richText',\n value: 'richText',\n },\n ],\n },\n {\n name: 'relation-to',\n type: 'text',\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'upload'\n },\n },\n label: 'Relation to',\n },\n {\n name: 'model-id',\n type: 'select',\n admin: {\n components: {\n Field: {\n clientProps: {\n filterByField: 'field-type',\n options: modelOptions(pluginConfig),\n },\n path: '@ai-stack/payloadcms/fields#SelectField',\n },\n },\n },\n label: 'Model',\n options: modelOptions(pluginConfig).map((option) => {\n return {\n label: option.label,\n value: option.value,\n }\n }),\n },\n {\n name: 'disabled',\n type: 'checkbox',\n admin: {\n description: 'Please reload your collection after applying the changes',\n },\n defaultValue: false,\n label: 'Hide Compose button for this field',\n },\n {\n id: 'ai-prompts-tabs',\n type: 'tabs',\n tabs: [\n {\n description:\n 'Define dynamic templates using {{ fieldName }}. Type { to see available field suggestions.',\n fields: [\n {\n name: 'prompt',\n type: 'textarea',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/fields#PromptEditorField',\n },\n description: \"Click 'Compose' to run this custom prompt and generate content\",\n },\n label: '',\n },\n ],\n label: 'Prompt',\n },\n {\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'upload' && current['model-id'] === 'gpt-image-1'\n },\n },\n description:\n 'These images will be used to generate new visuals in a similar style, layout, or content. You can combine multiple references for more controlled results.',\n fields: [\n {\n name: 'images',\n type: 'array',\n fields: [\n {\n name: 'image',\n type: 'upload',\n admin: {\n description: 'Please make sure the image is publicly accessible.',\n },\n relationTo: pluginConfig.uploadCollectionSlug\n ? pluginConfig.uploadCollectionSlug\n : 'media',\n },\n ],\n },\n ],\n label: 'Sample Images',\n },\n {\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'richText'\n },\n },\n description: '',\n fields: [\n {\n name: 'system',\n type: 'textarea',\n defaultValue: `INSTRUCTIONS:\nYou are a highly skilled and professional blog writer,\nrenowned for crafting engaging and well-organized articles.\nWhen given a title, you meticulously create blogs that are not only\ninformative and accurate but also captivating and beautifully structured.`,\n label: '',\n },\n ],\n label: 'System prompt',\n },\n {\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'richText'\n },\n },\n description: '',\n fields: [\n {\n /** TODO:\n * - Layouts can be saved in as an array\n * - User can add their own layout to collections and use it later for generate specific rich text\n * - User can select previously added layout\n */\n name: 'layout',\n type: 'textarea',\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'richText'\n },\n },\n defaultValue: `[paragraph] - Write a concise introduction (2-3 sentences) that outlines the main topic.\n[horizontalrule] - Insert a horizontal rule to separate the introduction from the main content.\n[list] - Create a list with 3-5 items. Each list item should contain:\n a. [heading] - A brief, descriptive heading (up to 5 words)\n b. [paragraph] - A short explanation or elaboration (1-2 sentences)\n[horizontalrule] - Insert another horizontal rule to separate the main content from the conclusion.\n[paragraph] - Compose a brief conclusion (2-3 sentences) summarizing the key points.\n[quote] - Include a relevant quote from a famous person, directly related to the topic. Format: \"Quote text.\" - Author Name`,\n label: '',\n },\n ],\n label: 'Layout',\n },\n ],\n },\n ...groupSettings(pluginConfig),\n ],\n }\n"],"names":["PLUGIN_INSTRUCTIONS_TABLE","getGenerationModels","groupSettings","pluginConfig","reduce","fields","model","settings","push","modelOptions","map","label","name","value","id","defaultAccessConfig","create","req","user","delete","read","update","defaultAdminConfig","group","hidden","instructionsCollection","labels","plural","singular","overrideInstructions","slug","access","admin","type","description","unique","defaultValue","options","condition","_","current","components","Field","clientProps","filterByField","path","option","tabs","relationTo","uploadCollectionSl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oB,EAAEE,MAAM;QAC9C;QACAC,OAAO;YACL,GAAGV,kBAAkB;YACrB,GAAGnB,aAAa0B,oBAAoB,EAAEG,KAAK;QAC7C;QACA3B,QAAQ;YACN;gBACEO,MAAM;gBACNqB,MAAM;gBACND,OAAO;oBACLE,aAAa;gBACf;gBACAC,QAAQ;YACV;YACA;gBACEvB,MAAM;gBACNqB,MAAM;gBACND,OAAO;oBACLE,aAAa;gBACf;gBACAE,cAAc;gBACdzB,OAAO;gBACP0B,SAAS;oBACP;wBACE1B,OAAO;wBACPE,OAAO;oBACT;oBACA;wBACEF,OAAO;wBACPE,OAAO;oBACT;oBACA;wBACEF,OAAO;wBACPE,OAAO;oBACT;oBACA;wBACEF,OAAO;wBACPE,OAAO;oBACT;iBACD;YACH;YACA;gBACED,MAAM;gBACNqB,MAAM;gBACND,OAAO;oBACLM,WAAW,CAACC,GAAGC;wBACb,OAAOA,OAAO,CAAC,aAAa,KAAK;oBACnC;gBACF;gBACA7B,OAAO;YACT;YACA;gBACEC,MAAM;gBACNqB,MAAM;gBACND,OAAO;oBACLS,YAAY;wBACVC,OAAO;4BACLC,aAAa;gCACXC,eAAe;gCACfP,SAAS5B,aAAaN;4BACxB;4BACA0C,MAAM;wBACR;oBACF;gBACF;gBACAlC,OAAO;gBACP0B,SAAS5B,aAAaN,cAAcO,GAAG,CAAC,CAACoC;oBACvC,OAAO;wBACLnC,OAAOmC,OAAOnC,KAAK;wBACnBE,OAAOiC,OAAOjC,KAAK;oBACrB;gBACF;YACF;YACA;gBACED,MAAM;gBACNqB,MAAM;gBACND,OAAO;oBACLE,aAAa;gBACf;gBACAE,cAAc;gBACdzB,OAAO;YACT;YACA;gBACEG,IAAI;gBACJmB,MAAM;gBACNc,MAAM;oBACJ;wBACEb,aACE;wBACF7B,QAAQ;4BACN;gCACEO,MAAM;gCACNqB,MAAM;gCACND,OAAO;oCACLS,YAAY;wCACVC,OAAO;oCACT;oCACAR,aAAa;gCACf;gCACAvB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;oBACA;wBACEqB,OAAO;4BACLM,WAAW,CAACC,GAAGC;gCACb,OAAOA,OAAO,CAAC,aAAa,KAAK,YAAYA,OAAO,CAAC,WAAW,KAAK;4BACvE;wBACF;wBACAN,aACE;wBACF7B,QAAQ;4BACN;gCACEO,MAAM;gCACNqB,MAAM;gCACN5B,QAAQ;oCACN;wCACEO,MAAM;wCACNqB,MAAM;wCACND,OAAO;4CACLE,aAAa;wCACf;wCACAc,YAAY7C,aAAa8C,oBAAoB,GACzC9C,aAAa8C,oBAAoB,GACjC;oCACN;iCACD;4BACH;yBACD;wBACDtC,OAAO;oBACT;oBACA;wBACEqB,OAAO;4BACLM,WAAW,CAACC,GAAGC;gCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;4BACnC;wBACF;wBACAN,aAAa;wBACb7B,QAAQ;4BACN;gCACEO,MAAM;gCACNqB,MAAM;gCACNG,cAAc,CAAC;;;;yEAI0C,CAAC;gCAC1DzB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;oBACA;wBACEqB,OAAO;4BACLM,WAAW,CAACC,GAAGC;gCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;4BACnC;wBACF;wBACAN,aAAa;wBACb7B,QAAQ;4BACN;gCACE;;;;iBAIC,GAJD;;;;iBAIC,GACDO,MAAM;gCACNqB,MAAM;gCACND,OAAO;oCACLM,WAAW,CAACC,GAAGC;wCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;oCACnC;gCACF;gCACAJ,cAAc,CAAC;;;;;;;2HAO4F,CAAC;gCAC5GzB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;iBACD;YACH;eACGT,cAAcC;SAClB;IACH,CAAA,EAAC"}
1
+ {"version":3,"sources":["../../src/collections/Instructions.ts"],"sourcesContent":["import type { CollectionConfig, GroupField } from 'payload'\nimport type { PluginConfig } from 'src/types.js'\n\nimport { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\nimport { getGenerationModels } from '../utilities/getGenerationModels.js'\n\nconst groupSettings = (pluginConfig: PluginConfig) =>\n (getGenerationModels(pluginConfig) ?? []).reduce((fields, model) => {\n if (model.settings) {\n fields.push(model.settings)\n }\n return fields\n }, [] as GroupField[])\n\nconst modelOptions = (pluginConfig: PluginConfig) =>\n (getGenerationModels(pluginConfig) ?? []).map((model) => {\n return {\n fields: model.fields,\n label: model.name,\n value: model.id,\n }\n })\n\nconst defaultAccessConfig = {\n create: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n delete: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n read: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n update: ({ req }: { req: { user?: any } }) => {\n if (!req.user) {\n return false\n }\n return true\n },\n}\n\nconst defaultAdminConfig = {\n group: 'Plugins',\n hidden: true,\n}\n\nexport const instructionsCollection = (pluginConfig: PluginConfig) =>\n <CollectionConfig>{\n labels: {\n plural: 'Compose Settings',\n singular: 'Compose Setting',\n },\n ...pluginConfig.overrideInstructions,\n slug: PLUGIN_INSTRUCTIONS_TABLE,\n access: {\n ...defaultAccessConfig,\n ...pluginConfig.overrideInstructions?.access,\n },\n admin: {\n ...defaultAdminConfig,\n ...pluginConfig.overrideInstructions?.admin,\n },\n fields: [\n {\n name: 'schema-path',\n type: 'text',\n admin: {\n description: \"Please don't change this unless you're sure of what you're doing\",\n },\n unique: true,\n },\n {\n name: 'field-type',\n type: 'select',\n admin: {\n description: \"Please don't change this unless you're sure of what you're doing\",\n },\n defaultValue: 'text',\n label: 'Field type',\n options: [\n {\n label: 'text',\n value: 'text',\n },\n {\n label: 'textarea',\n value: 'textarea',\n },\n {\n label: 'upload',\n value: 'upload',\n },\n {\n label: 'richText',\n value: 'richText',\n },\n ],\n },\n {\n name: 'relation-to',\n type: 'text',\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'upload'\n },\n },\n label: 'Relation to',\n },\n {\n name: 'model-id',\n type: 'select',\n admin: {\n components: {\n Field: {\n clientProps: {\n filterByField: 'field-type',\n options: modelOptions(pluginConfig),\n },\n path: '@ai-stack/payloadcms/fields#SelectField',\n },\n },\n },\n label: 'Model',\n options: modelOptions(pluginConfig).map((option) => {\n return {\n label: option.label,\n value: option.value,\n }\n }),\n },\n {\n name: 'disabled',\n type: 'checkbox',\n admin: {\n description: 'Please reload your collection after applying the changes',\n },\n defaultValue: false,\n label: 'Hide Compose button for this field',\n },\n {\n id: 'ai-prompts-tabs',\n type: 'tabs',\n tabs: [\n {\n description:\n 'Define dynamic templates using {{ fieldName }}. Type { to see available field suggestions.',\n fields: [\n {\n name: 'prompt',\n type: 'textarea',\n admin: {\n components: {\n Field: '@ai-stack/payloadcms/fields#PromptEditorField',\n },\n description: \"Click 'Compose' to run this custom prompt and generate content\",\n },\n label: '',\n },\n ],\n label: 'Prompt',\n },\n {\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'upload' && current['model-id'] === 'gpt-image-1'\n },\n },\n description:\n 'These images will be used to generate new visuals in a similar style, layout, or content. You can combine multiple references for more controlled results.',\n fields: [\n {\n name: 'images',\n type: 'array',\n fields: [\n {\n name: 'image',\n type: 'upload',\n admin: {\n description: 'Please make sure the image is publicly accessible.',\n },\n relationTo: pluginConfig.uploadCollectionSlug\n ? pluginConfig.uploadCollectionSlug\n : 'media',\n },\n ],\n },\n ],\n label: 'Sample Images',\n },\n {\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'richText'\n },\n },\n description: '',\n fields: [\n {\n name: 'system',\n type: 'textarea',\n defaultValue: `INSTRUCTIONS:\nYou are a highly skilled and professional blog writer,\nrenowned for crafting engaging and well-organized articles.\nWhen given a title, you meticulously create blogs that are not only\ninformative and accurate but also captivating and beautifully structured.`,\n label: '',\n },\n ],\n label: 'System prompt',\n },\n {\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'richText'\n },\n },\n description: '',\n fields: [\n {\n /** TODO:\n * - Layouts can be saved in as an array\n * - User can add their own layout to collections and use it later for generate specific rich text\n * - User can select previously added layout\n * - IMP: Remove layout from default, this seem to affect other functions like rephrase etc.\n */\n name: 'layout',\n type: 'textarea',\n admin: {\n condition: (_, current) => {\n return current['field-type'] === 'richText'\n },\n },\n defaultValue: `[paragraph] - Write a concise introduction (2-3 sentences) that outlines the main topic.\n[horizontalrule] - Insert a horizontal rule to separate the introduction from the main content.\n[list] - Create a list with 3-5 items. Each list item should contain:\n a. [heading] - A brief, descriptive heading (up to 5 words)\n b. [paragraph] - A short explanation or elaboration (1-2 sentences)\n[horizontalrule] - Insert another horizontal rule to separate the main content from the conclusion.\n[paragraph] - Compose a brief conclusion (2-3 sentences) summarizing the key points.\n[quote] - Include a relevant quote from a famous person, directly related to the topic. Format: \"Quote text.\" - Author Name`,\n label: '',\n },\n ],\n label: 'Layout',\n },\n ],\n },\n ...groupSettings(pluginConfig),\n ],\n }\n"],"names":["PLUGIN_INSTRUCTIONS_TABLE","getGenerationModels","groupSettings","pluginConfig","reduce","fields","model","settings","push","modelOptions","map","label","name","value","id","defaultAccessConfig","create","req","user","delete","read","update","defaultAdminConfig","group","hidden","instructionsCollection","labels","plural","singular","overrideInstructions","slug","access","admin","type","description","unique","defaultValue","options","condition","_","current","components","Field","clientProps","filterByField","path","option","tabs","relationTo","uploadCollectionSlug"],"mappings":"AAGA,SAASA,yBAAyB,QAAQ,iBAAgB;AAC1D,SAASC,mBAAmB,QAAQ,sCAAqC;AAEzE,MAAMC,gBAAgB,CAACC,eACrB,AAACF,CAAAA,oBAAoBE,iBAAiB,EAAE,AAAD,EAAGC,MAAM,CAAC,CAACC,QAAQC;QACxD,IAAIA,MAAMC,QAAQ,EAAE;YAClBF,OAAOG,IAAI,CAACF,MAAMC,QAAQ;QAC5B;QACA,OAAOF;IACT,GAAG,EAAE;AAEP,MAAMI,eAAe,CAACN,eACpB,AAACF,CAAAA,oBAAoBE,iBAAiB,EAAE,AAAD,EAAGO,GAAG,CAAC,CAACJ;QA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;wBACPE,OAAO;oBACT;oBACA;wBACEF,OAAO;wBACPE,OAAO;oBACT;iBACD;YACH;YACA;gBACED,MAAM;gBACNqB,MAAM;gBACND,OAAO;oBACLM,WAAW,CAACC,GAAGC;wBACb,OAAOA,OAAO,CAAC,aAAa,KAAK;oBACnC;gBACF;gBACA7B,OAAO;YACT;YACA;gBACEC,MAAM;gBACNqB,MAAM;gBACND,OAAO;oBACLS,YAAY;wBACVC,OAAO;4BACLC,aAAa;gCACXC,eAAe;gCACfP,SAAS5B,aAAaN;4BACxB;4BACA0C,MAAM;wBACR;oBACF;gBACF;gBACAlC,OAAO;gBACP0B,SAAS5B,aAAaN,cAAcO,GAAG,CAAC,CAACoC;oBACvC,OAAO;wBACLnC,OAAOmC,OAAOnC,KAAK;wBACnBE,OAAOiC,OAAOjC,KAAK;oBACrB;gBACF;YACF;YACA;gBACED,MAAM;gBACNqB,MAAM;gBACND,OAAO;oBACLE,aAAa;gBACf;gBACAE,cAAc;gBACdzB,OAAO;YACT;YACA;gBACEG,IAAI;gBACJmB,MAAM;gBACNc,MAAM;oBACJ;wBACEb,aACE;wBACF7B,QAAQ;4BACN;gCACEO,MAAM;gCACNqB,MAAM;gCACND,OAAO;oCACLS,YAAY;wCACVC,OAAO;oCACT;oCACAR,aAAa;gCACf;gCACAvB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;oBACA;wBACEqB,OAAO;4BACLM,WAAW,CAACC,GAAGC;gCACb,OAAOA,OAAO,CAAC,aAAa,KAAK,YAAYA,OAAO,CAAC,WAAW,KAAK;4BACvE;wBACF;wBACAN,aACE;wBACF7B,QAAQ;4BACN;gCACEO,MAAM;gCACNqB,MAAM;gCACN5B,QAAQ;oCACN;wCACEO,MAAM;wCACNqB,MAAM;wCACND,OAAO;4CACLE,aAAa;wCACf;wCACAc,YAAY7C,aAAa8C,oBAAoB,GACzC9C,aAAa8C,oBAAoB,GACjC;oCACN;iCACD;4BACH;yBACD;wBACDtC,OAAO;oBACT;oBACA;wBACEqB,OAAO;4BACLM,WAAW,CAACC,GAAGC;gCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;4BACnC;wBACF;wBACAN,aAAa;wBACb7B,QAAQ;4BACN;gCACEO,MAAM;gCACNqB,MAAM;gCACNG,cAAc,CAAC;;;;yEAI0C,CAAC;gCAC1DzB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;oBACA;wBACEqB,OAAO;4BACLM,WAAW,CAACC,GAAGC;gCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;4BACnC;wBACF;wBACAN,aAAa;wBACb7B,QAAQ;4BACN;gCACE;;;;;iBAKC,GALD;;;;;iBAKC,GACDO,MAAM;gCACNqB,MAAM;gCACND,OAAO;oCACLM,WAAW,CAACC,GAAGC;wCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;oCACnC;gCACF;gCACAJ,cAAc,CAAC;;;;;;;2HAO4F,CAAC;gCAC5GzB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;iBACD;YACH;eACGT,cAAcC;SAClB;IACH,CAAA,EAAC"}
@@ -7,6 +7,8 @@ import { registerEditorHelper } from '../libraries/handlebars/helpers.js';
7
7
  import { handlebarsHelpersMap } from '../libraries/handlebars/helpersMap.js';
8
8
  import { replacePlaceholders } from '../libraries/handlebars/replacePlaceholders.js';
9
9
  import { extractImageData } from '../utilities/extractImageData.js';
10
+ import { fieldToJsonSchema } from '../utilities/fieldToJsonSchema.js';
11
+ import { getFieldBySchemaPath } from '../utilities/getFieldBySchemaPath.js';
10
12
  import { getGenerationModels } from '../utilities/getGenerationModels.js';
11
13
  const requireAuthentication = (req)=>{
12
14
  if (!req.user) {
@@ -65,6 +67,26 @@ const extendContextWithPromptFields = (data, ctx, pluginConfig)=>{
65
67
  }
66
68
  });
67
69
  };
70
+ const buildRichTextSystem = (baseSystem, layout)=>{
71
+ return `${baseSystem}
72
+
73
+ RULES:
74
+ - Generate original and unique content based on the given topic.
75
+ - Strictly adhere to the specified layout and formatting instructions.
76
+ - Utilize the provided rich text editor tools for appropriate formatting.
77
+ - Ensure the output follows the structure of the sample output object.
78
+ - Produce valid JSON with no undefined or null values.
79
+ ---
80
+ LAYOUT INSTRUCTIONS:
81
+ ${layout}
82
+
83
+ ---
84
+ ADDITIONAL GUIDELINES:
85
+ - Ensure coherence and logical flow between all sections.
86
+ - Maintain a consistent tone and style throughout the content.
87
+ - Use clear and concise language appropriate for the target audience.
88
+ `;
89
+ };
68
90
  const assignPrompt = async (action, { type, actionParams, collection, context, field, layout, locale, pluginConfig, systemPrompt = '', template })=>{
69
91
  const extendedContext = extendContextWithPromptFields(context, {
70
92
  type,
@@ -76,7 +98,7 @@ const assignPrompt = async (action, { type, actionParams, collection, context, f
76
98
  layout: type === 'richText' ? layout : undefined,
77
99
  prompt,
78
100
  //TODO: Define only once on a collection level
79
- system: type === 'richText' ? systemPrompt : undefined
101
+ system: type === 'richText' ? buildRichTextSystem(systemPrompt, layout) : undefined
80
102
  };
81
103
  if (action === 'Compose') {
82
104
  if (locale && locale !== 'en') {
@@ -111,7 +133,7 @@ const assignPrompt = async (action, { type, actionParams, collection, context, f
111
133
  layout: updatedLayout,
112
134
  // TODO: revisit this toLexicalHTML
113
135
  prompt: await replacePlaceholders(`{{${toLexicalHTML} ${field}}}`, extendedContext),
114
- system
136
+ system: type === 'richText' ? buildRichTextSystem(system, updatedLayout) : system
115
137
  };
116
138
  };
117
139
  export const endpoints = (pluginConfig)=>({
@@ -147,7 +169,9 @@ export const endpoints = (pluginConfig)=>({
147
169
  allowedEditorSchema = filterEditorSchemaByNodes(editorSchema, allowedEditorNodes);
148
170
  }
149
171
  const schemaPath = instructions['schema-path'];
150
- const [collectionName, fieldName] = schemaPath?.split('.') || [];
172
+ const parts = schemaPath?.split('.') || [];
173
+ const collectionName = parts[0];
174
+ const fieldName = parts.length > 1 ? parts[parts.length - 1] : '';
151
175
  registerEditorHelper(req.payload, schemaPath);
152
176
  const { defaultLocale, locales = [] } = req.payload.config.localization || {};
153
177
  const localeData = locales.find((l)=>{
@@ -162,8 +186,7 @@ export const endpoints = (pluginConfig)=>({
162
186
  if (!model) {
163
187
  throw new Error('Model not found');
164
188
  }
165
- // @ts-ignore
166
- const settingsName = model && model.settings ? model.settings.name : undefined;
189
+ const settingsName = model.settings && "name" in model.settings ? model.settings.name : undefined;
167
190
  if (!settingsName) {
168
191
  req.payload.logger.error('— AI Plugin: Error fetching settings name!');
169
192
  }
@@ -185,11 +208,37 @@ export const endpoints = (pluginConfig)=>({
185
208
  prompts
186
209
  }, `— AI Plugin: Executing text prompt on ${schemaPath} using ${model.id}`);
187
210
  }
211
+ // Build per-field JSON schema for structured generation when applicable
212
+ let jsonSchema = allowedEditorSchema;
213
+ try {
214
+ const targetCollection = req.payload.config.collections.find((c)=>c.slug === collectionName);
215
+ if (targetCollection && fieldName) {
216
+ const targetField = getFieldBySchemaPath(targetCollection, schemaPath);
217
+ const supported = [
218
+ 'text',
219
+ 'textarea',
220
+ 'select',
221
+ 'number',
222
+ 'date',
223
+ 'code',
224
+ 'email',
225
+ 'json'
226
+ ];
227
+ const t = String(targetField?.type || '');
228
+ if (targetField && supported.includes(t)) {
229
+ jsonSchema = fieldToJsonSchema(targetField, {
230
+ nameOverride: fieldName
231
+ });
232
+ }
233
+ }
234
+ } catch (e) {
235
+ req.payload.logger.error(e, '— AI Plugin: Error building field JSON schema');
236
+ }
188
237
  return model.handler?.(prompts.prompt, {
189
238
  ...modelOptions,
190
- editorSchema: allowedEditorSchema,
191
239
  layout: prompts.layout,
192
240
  locale: localeInfo,
241
+ schema: jsonSchema,
193
242
  system: prompts.system
194
243
  });
195
244
  } catch (error) {