@ai-stack/payloadcms 3.2.19-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.
- package/dist/ai/models/anthropic/index.js +9 -15
- package/dist/ai/models/anthropic/index.js.map +1 -1
- package/dist/ai/models/generateObject.d.ts +11 -0
- package/dist/ai/models/generateObject.js +22 -0
- package/dist/ai/models/generateObject.js.map +1 -0
- package/dist/ai/models/openai/index.js +19 -17
- package/dist/ai/models/openai/index.js.map +1 -1
- package/dist/ai/prompts.js +1 -1
- package/dist/ai/prompts.js.map +1 -1
- package/dist/collections/Instructions.js +11 -0
- package/dist/collections/Instructions.js.map +1 -1
- package/dist/endpoints/fetchFields.js +1 -0
- package/dist/endpoints/fetchFields.js.map +1 -1
- package/dist/endpoints/index.js +55 -6
- package/dist/endpoints/index.js.map +1 -1
- package/dist/fields/ComposeField/ComposeField.js +8 -6
- package/dist/fields/ComposeField/ComposeField.js.map +1 -1
- package/dist/fields/ComposeField/ComposeField.jsx +32 -0
- package/dist/fields/LexicalEditor/ComposeFeatureComponent.d.ts +1 -1
- package/dist/fields/LexicalEditor/ComposeFeatureComponent.js +5 -2
- package/dist/fields/LexicalEditor/ComposeFeatureComponent.js.map +1 -1
- package/dist/fields/LexicalEditor/ComposeFeatureComponent.jsx +24 -0
- package/dist/fields/LexicalEditor/feature.client.jsx +21 -0
- package/dist/fields/PromptEditorField/PromptEditorField.jsx +42 -0
- package/dist/fields/SelectField/SelectField.jsx +38 -0
- package/dist/providers/FieldProvider/FieldProvider.d.ts +7 -4
- package/dist/providers/FieldProvider/FieldProvider.js +7 -6
- package/dist/providers/FieldProvider/FieldProvider.js.map +1 -1
- package/dist/providers/FieldProvider/FieldProvider.jsx +27 -0
- package/dist/providers/FieldProvider/useFieldProps.d.ts +1 -1
- package/dist/providers/FieldProvider/useFieldProps.js +2 -2
- package/dist/providers/FieldProvider/useFieldProps.js.map +1 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.jsx +45 -0
- package/dist/types.d.ts +4 -4
- package/dist/types.js.map +1 -1
- package/dist/ui/Compose/Compose.js +12 -81
- package/dist/ui/Compose/Compose.js.map +1 -1
- package/dist/ui/Compose/Compose.jsx +141 -0
- package/dist/ui/Compose/UndoRedoActions.jsx +34 -0
- package/dist/ui/Compose/compose.module.css +99 -12
- package/dist/ui/Compose/hooks/menu/Item.jsx +15 -0
- package/dist/ui/Compose/hooks/menu/TranslateMenu.jsx +58 -0
- package/dist/ui/Compose/hooks/menu/items.jsx +10 -0
- package/dist/ui/Compose/hooks/menu/useMenu.js +1 -1
- package/dist/ui/Compose/hooks/menu/useMenu.js.map +1 -1
- package/dist/ui/Compose/hooks/menu/useMenu.jsx +89 -0
- package/dist/ui/Compose/hooks/useActiveFieldTracking.d.ts +5 -0
- package/dist/ui/Compose/hooks/useActiveFieldTracking.js +148 -0
- package/dist/ui/Compose/hooks/useActiveFieldTracking.js.map +1 -0
- package/dist/ui/Compose/hooks/useGenerate.js +46 -79
- package/dist/ui/Compose/hooks/useGenerate.js.map +1 -1
- package/dist/ui/Icons/Icons.jsx +78 -0
- package/dist/ui/Icons/LottieAnimation.jsx +64 -0
- package/dist/utilities/extractPromptAttachments.d.ts +2 -2
- package/dist/utilities/extractPromptAttachments.js.map +1 -1
- package/dist/utilities/fieldToJsonSchema.d.ts +37 -0
- package/dist/utilities/fieldToJsonSchema.js +274 -0
- package/dist/utilities/fieldToJsonSchema.js.map +1 -0
- package/dist/utilities/getFieldBySchemaPath.d.ts +12 -1
- package/dist/utilities/getFieldBySchemaPath.js +63 -29
- package/dist/utilities/getFieldBySchemaPath.js.map +1 -1
- package/package.json +2 -1
- package/dist/ai/models/anthropic/generateRichText.d.ts +0 -1
- package/dist/ai/models/anthropic/generateRichText.js +0 -36
- package/dist/ai/models/anthropic/generateRichText.js.map +0 -1
- package/dist/ai/models/openai/generateRichText.d.ts +0 -1
- package/dist/ai/models/openai/generateRichText.js +0 -37
- 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 {
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
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'\
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
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,mBAAmBlB,WAAW;oBAClCmB,iBAAiBF,QAAQG,SAAS,IAAI;oBACtCC,OAAOd,OAAOU,QAAQI,KAAK;oBAC3BC,SAAS,CAACC;wBACRC,QAAQD,KAAK,CAAC,GAAGf,UAAU,OAAO,CAAC,EAAEe;oBACvC;oBACAE,aAAaR,QAAQQ,WAAW,IAAI;oBAEpC,4CAA4C;oBAC5C,8BAA8B;oBAC9B,sDAAsD;oBACtD,KAAK;oBACLT,QAAQC,QAAQS,kBAAkB,GAAGzB,yBAAyBe,UAAUA;oBACxEW,QAAQV,QAAQU,MAAM,IAAIzB;gBAC5B;gBAEA,OAAOgB,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;wB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;yBAAU;oBAGhE;oBACA;wBACEJ,MAAM;wBACNkB,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPnB,SAAS;4BAAC;4BAAS;yBAAW;oBAChC;oBACA;wBACEJ,MAAM;wBACNkB,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPnB,SAAS;4BAAC;4BAAO;4BAAQ;4BAAO;4BAAQ;4BAAO;yBAAM;oBACvD;oBACA;wBACEJ,MAAM;wBACNkB,MAAM;wBACNI,cAAc;wBACdC,OAAO;wBACPC,KAAK;wBACLC,KAAK;oBACP;iBACD;gBACDF,OAAO;YACT;QACF;QACA;YACExB,IAAI,GAAGJ,UAAU,OAAO,CAAC;YACzBK,MAAM;YACNC,QAAQ;gBAAC;aAAW;YACpBC,SAAS,CAACgC,MAAc9B;gBACtB,OAAOZ,iBAAiB0C,MAAM9B;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;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,OA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,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"}
|
package/dist/ai/prompts.js
CHANGED
|
@@ -198,7 +198,7 @@ For upload:
|
|
|
198
198
|
field-type: upload
|
|
199
199
|
field-name: Voice
|
|
200
200
|
schema-path: posts.upload
|
|
201
|
-
Generated prompt: {{ title }} {{ toHTML schema-path here... }}
|
|
201
|
+
Generated prompt: {{ title }} {{ toHTML [provide schema-path here...] }}
|
|
202
202
|
|
|
203
203
|
|
|
204
204
|
Remember to adapt the prompts based on the specific schema-path provided, considering the context and purpose of the field within the CMS structure. The prompts should directly instruct the AI model on what content to generate or describe, without assuming a user perspective.
|
package/dist/ai/prompts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ai/prompts.ts"],"sourcesContent":["import type { ActionPrompt, SeedPromptFunction } from '../types.js'\n\n//TODO: This is a temporary solution make use of structured output\nexport const defaultSystemPrompt = `IMPORTANT INSTRUCTION:\nProduce only the requested output text.\nDo not add any explanations, comments, or engagement.\nDo not use quotation marks in the response.\nBEGIN OUTPUT:`\n\nexport const defaultPrompts: ActionPrompt[] = [\n {\n name: 'Rephrase',\n system: ({\n prompt = '',\n systemPrompt = '',\n }) => `You are a skilled language expert. Rephrase the given text while maintaining its original meaning, tone, and emotional content. Use different words and sentence structures where possible, but preserve the overall style and sentiment of the original.\n \n -------------\n INSTRUCTIONS:\n - Rephrase the text according to the guidelines of the ORIGINAL SYSTEM PROMPT, if provided.\n - Retain the original meaning, tone, and emotional content.\n - Use different vocabulary and sentence structures where appropriate.\n - Ensure the rephrased text conveys the same message and feeling as the original.\n ${prompt ? '\\n\\nPrevious prompt:\\n' + prompt : ''}\n ${systemPrompt ? '\\n\\nORIGINAL SYSTEM PROMPT:\\n' + systemPrompt : ''}\n -------------`,\n },\n {\n name: 'Expand',\n system:\n () => `You are a creative writer and subject matter expert. Expand the given text by adding depth, detail, and relevant information while maintaining the original tone and style.\n \n -------------\n INSTRUCTIONS:\n - Understand the main ideas and tone of the text.\n - Add more details, examples, explanations, or context.\n - Maintain the original tone, style, and intent.\n - Ensure the expanded version flows naturally and coherently.\n - Do not contradict or alter the original meaning.\n -------------`,\n },\n {\n name: 'Proofread',\n system:\n () => `You are an English language expert. Proofread the given text, focusing on correcting grammar and spelling mistakes without altering the content, style, or tone.\n \n -------------\n INSTRUCTIONS:\n - Correct grammar and spelling errors.\n - Do not change the content, meaning, tone, or style.\n - Return the full text, whether corrections were made or not.\n - Do not provide additional comments or analysis.\n -------------`,\n },\n {\n name: 'Simplify',\n system: ({\n prompt = '',\n }) => `You are a skilled communicator specializing in clear and concise writing. Simplify the given text to make it easier to understand while retaining its core message.\n \n -------------\n INSTRUCTIONS:\n - Simplify the language, using more common words and shorter sentences.\n - Remove unnecessary details or jargon while keeping essential information.\n - Maintain the original meaning and key points.\n - Aim for clarity and readability for a general audience.\n - The simplified text should be more concise than the original.\n ${prompt ? '\\n\\nPREVIOUS PROMPT:\\n' + prompt : ''}\n -------------`,\n },\n {\n name: 'Summarize',\n layout: () => `\n[heading] - Summary\n[paragraph] - Your summary goes here...\n `,\n system: () =>\n `You are an expert at summarizing information. Your task is to create a concise summary of the given text that captures its key points and essential details while preserving the original meaning.\n\nINSTRUCTIONS:\n1. Carefully read and analyze the provided text.\n2. Identify and extract the main ideas and crucial supporting details.\n3. Condense the information into a clear and coherent summary that maintains the core message.\n4. Preserve the original tone and intent of the text.\n5. Ensure your summary is approximately 25-30% of the original text length.\n6. Use clear and precise language, avoiding unnecessary jargon or complexity.\n`,\n },\n {\n name: 'Tone',\n system: () =>\n `You are a tone adjustment specialist. Modify the tone of the given text as specified while keeping the original message and content intact.\n \n -------------\n INSTRUCTIONS:\n - Adjust the tone to match the specified style (e.g., formal, informal, professional, friendly).\n - Maintain the original content and meaning.\n - Ensure the adjusted text flows naturally with the new tone.\n -------------`,\n },\n {\n name: 'Translate',\n system: ({ locale, prompt = '', systemPrompt = '' }) =>\n `You are a skilled translator. Translate the following text into ${locale}, ensuring the original meaning, tone, and context are preserved.\n \n -------------\n INSTRUCTIONS:\n - Accurately translate the text into ${locale}.\n - Preserve the original meaning, tone, and context.\n - Ensure the translation is culturally appropriate and natural in the target language.\n ${prompt ? '\\n\\nPREVIOUS PROMPT:\\n' + prompt : ''}\n ${systemPrompt ? '\\n\\nORIGINAL SYSTEM PROMPT:\\n' + systemPrompt : ''}\n -------------`,\n },\n]\n\nexport const defaultSeedPrompts: SeedPromptFunction = ({\n fieldLabel,\n fieldSchemaPaths,\n fieldType,\n path,\n}: {\n fieldLabel: string\n fieldSchemaPaths: any\n fieldType: string\n path: string\n}) => {\n return {\n prompt: `field-type: ${fieldType}\nfield-name: ${fieldLabel}\nschema-path: ${path}\n\nGive me a prompt that relate to the given field type and schema path.\n\nGenerated prompt:\n`,\n system: `# AI Assistant for CMS Prompt Generation\n\nYour role: Generate prompts for Content Management System (CMS) fields based on field-type and schema-path.\n\n## Key Guidelines:\n- Tailor prompts to specific field-type and purpose\n- Use schema-path for context\n- Include \" {{ title }} \" in every prompt\n- Be clear, concise, and instructive\n- Focus on content generation, not user perspective\n- For Image, Voice, or Banner fields, use provided example prompts verbatim\n- Image, Banner prompt MUST NOT CONTAIN ANY TYPOGRAPHY/TEXT DETAILS\n\n## Field Types and Prompts:\n\n1. richText:\n - Craft detailed, structured content\n - Include intro, sections, body, formatting, and conclusion\n - Aim for engaging, informative, and valuable content\n\n2. text:\n - For titles: Generate concise, engaging titles\n - For keywords: List relevant SEO terms\n\n3. textarea:\n - Provide comprehensive details (e.g., event information)\n\n4. upload:\n - Describe high-quality images or media\n\n## Schema-path Examples:\n- posts.title: Blog/article title\n- products.name: Product name\n\n## Must Follow:\n- Adapt prompts to schema-path context\n- Generate content directly, avoid personal pronouns\n- Use provided examples as guidelines\n\n### Examples for each field type along with generated prompt:\n\nFor richText:\n field-type: richText\n field-name: Content\n schema-path: posts.content\n Generated prompt: Craft compelling content for a blog post with the title \" {{ title }} \". Develop a well-structured narrative that captivates readers from start to finish. Incorporate the following elements to create a polished and engaging piece:\n\n- Engaging introduction that hooks the reader\n- Clearly defined sections with relevant subheadings\n- Well-researched and informative body paragraphs\n- Creative use of formatting to enhance readability (e.g., bullet points, blockquotes, italics, headings, bolds, other text formats)\n- Compelling conclusion that reinforces the main theme\n- Make the format easily digestible and clear for enhanced readability and improved CTR. \n- The user should be engaged, consistently interested, and feel that they’ve gained the knowledge they were seeking. \n\nInfuse the content with your expertise and a touch of personality to make it both informative and enjoyable to read. Aim to provide value to your target audience while maintaining a professional tone that aligns with the blog's overall style.\nFeel free to incorporate relevant anecdotes, statistics, or examples to support your points and add depth to the post. Remember, the goal is to create content that not only informs but also inspires and entertains your readers.\n\nFor text:\n field-type: text\n field-name: title\n schema-path: posts.title\n Generated prompt: Generate a captivating title for the blog post based on \" {{ title }} \" that effectively encapsulates the main theme and draws in readers. The title should be concise, engaging, and relevant to the content being presented. If no input is provided then generate creative title.\n\nFor text:\n field-type: text\n field-name: keywords\n schema-path: posts.keywords\n Generated prompt: Identify and list relevant keywords for the blog post titled \" {{ title }} \". Focus on terms that enhance search engine optimization and accurately reflect the main themes and topics of the content.\nkeywords will with comma separated.\n\n\nFor textarea:\n field-type: textarea:\n field-name: details\n schema-path: posts.details\n Generated prompt: Provide comprehensive details for the event \" {{ title }} \". Include essential information such as date, time, location, and any specific instructions or requirements.\n\nFor upload:\n field-type: upload\n field-name: Featured Image\n schema-path: posts.image\n Generated prompt: Imagine {{ title }}\n\nFor upload:\n field-type: upload\n field-name: Voice\n schema-path: posts.upload\n Generated prompt: {{ title }} {{ toHTML schema-path here... }}\n\n\nRemember to adapt the prompts based on the specific schema-path provided, considering the context and purpose of the field within the CMS structure. The prompts should directly instruct the AI model on what content to generate or describe, without assuming a user perspective.\n\nSchema Map Context:\n${JSON.stringify(fieldSchemaPaths)}\n\n${defaultSystemPrompt}\n`,\n }\n}\n"],"names":["defaultSystemPrompt","defaultPrompts","name","system","prompt","systemPrompt","layout","locale","defaultSeedPrompts","fieldLabel","fieldSchemaPaths","fieldType","path","JSON","stringify"],"mappings":"AAEA,kEAAkE;AAClE,OAAO,MAAMA,sBAAsB,CAAC;;;;aAIvB,CAAC,CAAA;AAEd,OAAO,MAAMC,iBAAiC;IAC5C;QACEC,MAAM;QACNC,QAAQ,CAAC,EACPC,SAAS,EAAE,EACXC,eAAe,EAAE,EAClB,GAAK,CAAC;;;;;;;;MAQL,EAAED,SAAS,2BAA2BA,SAAS,GAAG;MAClD,EAAEC,eAAe,kCAAkCA,eAAe,GAAG;mBACxD,CAAC;IAClB;IACA;QACEH,MAAM;QACNC,QACE,IAAM,CAAC;;;;;;;;;mBASM,CAAC;IAClB;IACA;QACED,MAAM;QACNC,QACE,IAAM,CAAC;;;;;;;;mBAQM,CAAC;IAClB;IACA;QACED,MAAM;QACNC,QAAQ,CAAC,EACPC,SAAS,EAAE,EACZ,GAAK,CAAC;;;;;;;;;MASL,EAAEA,SAAS,2BAA2BA,SAAS,GAAG;mBACrC,CAAC;IAClB;IACA;QACEF,MAAM;QACNI,QAAQ,IAAM,CAAC;;;IAGf,CAAC;QACDH,QAAQ,IACN,CAAC;;;;;;;;;AASP,CAAC;IACC;IACA;QACED,MAAM;QACNC,QAAQ,IACN,CAAC;;;;;;;mBAOY,CAAC;IAClB;IACA;QACED,MAAM;QACNC,QAAQ,CAAC,EAAEI,MAAM,EAAEH,SAAS,EAAE,EAAEC,eAAe,EAAE,EAAE,GACjD,CAAC,gEAAgE,EAAEE,OAAO;;;;yCAIvC,EAAEA,OAAO;;;IAG9C,EAAEH,SAAS,2BAA2BA,SAAS,GAAG;IAClD,EAAEC,eAAe,kCAAkCA,eAAe,GAAG;iBACxD,CAAC;IAChB;CACD,CAAA;AAED,OAAO,MAAMG,qBAAyC,CAAC,EACrDC,UAAU,EACVC,gBAAgB,EAChBC,SAAS,EACTC,IAAI,EAML;IACC,OAAO;QACLR,QAAQ,CAAC,YAAY,EAAEO,UAAU;YACzB,EAAEF,WAAW;aACZ,EAAEG,KAAK;;;;;AAKpB,CAAC;QACGT,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8Fb,EAAEU,KAAKC,SAAS,CAACJ,kBAAkB;;AAEnC,EAAEV,oBAAoB;AACtB,CAAC;IACC;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/ai/prompts.ts"],"sourcesContent":["import type { ActionPrompt, SeedPromptFunction } from '../types.js'\n\n//TODO: This is a temporary solution make use of structured output\nexport const defaultSystemPrompt = `IMPORTANT INSTRUCTION:\nProduce only the requested output text.\nDo not add any explanations, comments, or engagement.\nDo not use quotation marks in the response.\nBEGIN OUTPUT:`\n\nexport const defaultPrompts: ActionPrompt[] = [\n {\n name: 'Rephrase',\n system: ({\n prompt = '',\n systemPrompt = '',\n }) => `You are a skilled language expert. Rephrase the given text while maintaining its original meaning, tone, and emotional content. Use different words and sentence structures where possible, but preserve the overall style and sentiment of the original.\n \n -------------\n INSTRUCTIONS:\n - Rephrase the text according to the guidelines of the ORIGINAL SYSTEM PROMPT, if provided.\n - Retain the original meaning, tone, and emotional content.\n - Use different vocabulary and sentence structures where appropriate.\n - Ensure the rephrased text conveys the same message and feeling as the original.\n ${prompt ? '\\n\\nPrevious prompt:\\n' + prompt : ''}\n ${systemPrompt ? '\\n\\nORIGINAL SYSTEM PROMPT:\\n' + systemPrompt : ''}\n -------------`,\n },\n {\n name: 'Expand',\n system:\n () => `You are a creative writer and subject matter expert. Expand the given text by adding depth, detail, and relevant information while maintaining the original tone and style.\n \n -------------\n INSTRUCTIONS:\n - Understand the main ideas and tone of the text.\n - Add more details, examples, explanations, or context.\n - Maintain the original tone, style, and intent.\n - Ensure the expanded version flows naturally and coherently.\n - Do not contradict or alter the original meaning.\n -------------`,\n },\n {\n name: 'Proofread',\n system:\n () => `You are an English language expert. Proofread the given text, focusing on correcting grammar and spelling mistakes without altering the content, style, or tone.\n \n -------------\n INSTRUCTIONS:\n - Correct grammar and spelling errors.\n - Do not change the content, meaning, tone, or style.\n - Return the full text, whether corrections were made or not.\n - Do not provide additional comments or analysis.\n -------------`,\n },\n {\n name: 'Simplify',\n system: ({\n prompt = '',\n }) => `You are a skilled communicator specializing in clear and concise writing. Simplify the given text to make it easier to understand while retaining its core message.\n \n -------------\n INSTRUCTIONS:\n - Simplify the language, using more common words and shorter sentences.\n - Remove unnecessary details or jargon while keeping essential information.\n - Maintain the original meaning and key points.\n - Aim for clarity and readability for a general audience.\n - The simplified text should be more concise than the original.\n ${prompt ? '\\n\\nPREVIOUS PROMPT:\\n' + prompt : ''}\n -------------`,\n },\n {\n name: 'Summarize',\n layout: () => `\n[heading] - Summary\n[paragraph] - Your summary goes here...\n `,\n system: () =>\n `You are an expert at summarizing information. Your task is to create a concise summary of the given text that captures its key points and essential details while preserving the original meaning.\n\nINSTRUCTIONS:\n1. Carefully read and analyze the provided text.\n2. Identify and extract the main ideas and crucial supporting details.\n3. Condense the information into a clear and coherent summary that maintains the core message.\n4. Preserve the original tone and intent of the text.\n5. Ensure your summary is approximately 25-30% of the original text length.\n6. Use clear and precise language, avoiding unnecessary jargon or complexity.\n`,\n },\n {\n name: 'Tone',\n system: () =>\n `You are a tone adjustment specialist. Modify the tone of the given text as specified while keeping the original message and content intact.\n \n -------------\n INSTRUCTIONS:\n - Adjust the tone to match the specified style (e.g., formal, informal, professional, friendly).\n - Maintain the original content and meaning.\n - Ensure the adjusted text flows naturally with the new tone.\n -------------`,\n },\n {\n name: 'Translate',\n system: ({ locale, prompt = '', systemPrompt = '' }) =>\n `You are a skilled translator. Translate the following text into ${locale}, ensuring the original meaning, tone, and context are preserved.\n \n -------------\n INSTRUCTIONS:\n - Accurately translate the text into ${locale}.\n - Preserve the original meaning, tone, and context.\n - Ensure the translation is culturally appropriate and natural in the target language.\n ${prompt ? '\\n\\nPREVIOUS PROMPT:\\n' + prompt : ''}\n ${systemPrompt ? '\\n\\nORIGINAL SYSTEM PROMPT:\\n' + systemPrompt : ''}\n -------------`,\n },\n]\n\nexport const defaultSeedPrompts: SeedPromptFunction = ({\n fieldLabel,\n fieldSchemaPaths,\n fieldType,\n path,\n}: {\n fieldLabel: string\n fieldSchemaPaths: any\n fieldType: string\n path: string\n}) => {\n return {\n prompt: `field-type: ${fieldType}\nfield-name: ${fieldLabel}\nschema-path: ${path}\n\nGive me a prompt that relate to the given field type and schema path.\n\nGenerated prompt:\n`,\n system: `# AI Assistant for CMS Prompt Generation\n\nYour role: Generate prompts for Content Management System (CMS) fields based on field-type and schema-path.\n\n## Key Guidelines:\n- Tailor prompts to specific field-type and purpose\n- Use schema-path for context\n- Include \" {{ title }} \" in every prompt\n- Be clear, concise, and instructive\n- Focus on content generation, not user perspective\n- For Image, Voice, or Banner fields, use provided example prompts verbatim\n- Image, Banner prompt MUST NOT CONTAIN ANY TYPOGRAPHY/TEXT DETAILS\n\n## Field Types and Prompts:\n\n1. richText:\n - Craft detailed, structured content\n - Include intro, sections, body, formatting, and conclusion\n - Aim for engaging, informative, and valuable content\n\n2. text:\n - For titles: Generate concise, engaging titles\n - For keywords: List relevant SEO terms\n\n3. textarea:\n - Provide comprehensive details (e.g., event information)\n\n4. upload:\n - Describe high-quality images or media\n\n## Schema-path Examples:\n- posts.title: Blog/article title\n- products.name: Product name\n\n## Must Follow:\n- Adapt prompts to schema-path context\n- Generate content directly, avoid personal pronouns\n- Use provided examples as guidelines\n\n### Examples for each field type along with generated prompt:\n\nFor richText:\n field-type: richText\n field-name: Content\n schema-path: posts.content\n Generated prompt: Craft compelling content for a blog post with the title \" {{ title }} \". Develop a well-structured narrative that captivates readers from start to finish. Incorporate the following elements to create a polished and engaging piece:\n\n- Engaging introduction that hooks the reader\n- Clearly defined sections with relevant subheadings\n- Well-researched and informative body paragraphs\n- Creative use of formatting to enhance readability (e.g., bullet points, blockquotes, italics, headings, bolds, other text formats)\n- Compelling conclusion that reinforces the main theme\n- Make the format easily digestible and clear for enhanced readability and improved CTR. \n- The user should be engaged, consistently interested, and feel that they’ve gained the knowledge they were seeking. \n\nInfuse the content with your expertise and a touch of personality to make it both informative and enjoyable to read. Aim to provide value to your target audience while maintaining a professional tone that aligns with the blog's overall style.\nFeel free to incorporate relevant anecdotes, statistics, or examples to support your points and add depth to the post. Remember, the goal is to create content that not only informs but also inspires and entertains your readers.\n\nFor text:\n field-type: text\n field-name: title\n schema-path: posts.title\n Generated prompt: Generate a captivating title for the blog post based on \" {{ title }} \" that effectively encapsulates the main theme and draws in readers. The title should be concise, engaging, and relevant to the content being presented. If no input is provided then generate creative title.\n\nFor text:\n field-type: text\n field-name: keywords\n schema-path: posts.keywords\n Generated prompt: Identify and list relevant keywords for the blog post titled \" {{ title }} \". Focus on terms that enhance search engine optimization and accurately reflect the main themes and topics of the content.\nkeywords will with comma separated.\n\n\nFor textarea:\n field-type: textarea:\n field-name: details\n schema-path: posts.details\n Generated prompt: Provide comprehensive details for the event \" {{ title }} \". Include essential information such as date, time, location, and any specific instructions or requirements.\n\nFor upload:\n field-type: upload\n field-name: Featured Image\n schema-path: posts.image\n Generated prompt: Imagine {{ title }}\n\nFor upload:\n field-type: upload\n field-name: Voice\n schema-path: posts.upload\n Generated prompt: {{ title }} {{ toHTML [provide schema-path here...] }}\n\n\nRemember to adapt the prompts based on the specific schema-path provided, considering the context and purpose of the field within the CMS structure. The prompts should directly instruct the AI model on what content to generate or describe, without assuming a user perspective.\n\nSchema Map Context:\n${JSON.stringify(fieldSchemaPaths)}\n\n${defaultSystemPrompt}\n`,\n }\n}\n"],"names":["defaultSystemPrompt","defaultPrompts","name","system","prompt","systemPrompt","layout","locale","defaultSeedPrompts","fieldLabel","fieldSchemaPaths","fieldType","path","JSON","stringify"],"mappings":"AAEA,kEAAkE;AAClE,OAAO,MAAMA,sBAAsB,CAAC;;;;aAIvB,CAAC,CAAA;AAEd,OAAO,MAAMC,iBAAiC;IAC5C;QACEC,MAAM;QACNC,QAAQ,CAAC,EACPC,SAAS,EAAE,EACXC,eAAe,EAAE,EAClB,GAAK,CAAC;;;;;;;;MAQL,EAAED,SAAS,2BAA2BA,SAAS,GAAG;MAClD,EAAEC,eAAe,kCAAkCA,eAAe,GAAG;mBACxD,CAAC;IAClB;IACA;QACEH,MAAM;QACNC,QACE,IAAM,CAAC;;;;;;;;;mBASM,CAAC;IAClB;IACA;QACED,MAAM;QACNC,QACE,IAAM,CAAC;;;;;;;;mBAQM,CAAC;IAClB;IACA;QACED,MAAM;QACNC,QAAQ,CAAC,EACPC,SAAS,EAAE,EACZ,GAAK,CAAC;;;;;;;;;MASL,EAAEA,SAAS,2BAA2BA,SAAS,GAAG;mBACrC,CAAC;IAClB;IACA;QACEF,MAAM;QACNI,QAAQ,IAAM,CAAC;;;IAGf,CAAC;QACDH,QAAQ,IACN,CAAC;;;;;;;;;AASP,CAAC;IACC;IACA;QACED,MAAM;QACNC,QAAQ,IACN,CAAC;;;;;;;mBAOY,CAAC;IAClB;IACA;QACED,MAAM;QACNC,QAAQ,CAAC,EAAEI,MAAM,EAAEH,SAAS,EAAE,EAAEC,eAAe,EAAE,EAAE,GACjD,CAAC,gEAAgE,EAAEE,OAAO;;;;yCAIvC,EAAEA,OAAO;;;IAG9C,EAAEH,SAAS,2BAA2BA,SAAS,GAAG;IAClD,EAAEC,eAAe,kCAAkCA,eAAe,GAAG;iBACxD,CAAC;IAChB;CACD,CAAA;AAED,OAAO,MAAMG,qBAAyC,CAAC,EACrDC,UAAU,EACVC,gBAAgB,EAChBC,SAAS,EACTC,IAAI,EAML;IACC,OAAO;QACLR,QAAQ,CAAC,YAAY,EAAEO,UAAU;YACzB,EAAEF,WAAW;aACZ,EAAEG,KAAK;;;;;AAKpB,CAAC;QACGT,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8Fb,EAAEU,KAAKC,SAAS,CAACJ,kBAAkB;;AAEnC,EAAEV,oBAAoB;AACtB,CAAC;IACC;AACF,EAAC"}
|
|
@@ -126,6 +126,15 @@ export const instructionsCollection = (pluginConfig)=>({
|
|
|
126
126
|
};
|
|
127
127
|
})
|
|
128
128
|
},
|
|
129
|
+
{
|
|
130
|
+
name: 'disabled',
|
|
131
|
+
type: 'checkbox',
|
|
132
|
+
admin: {
|
|
133
|
+
description: 'Please reload your collection after applying the changes'
|
|
134
|
+
},
|
|
135
|
+
defaultValue: false,
|
|
136
|
+
label: 'Hide Compose button for this field'
|
|
137
|
+
},
|
|
129
138
|
{
|
|
130
139
|
id: 'ai-prompts-tabs',
|
|
131
140
|
type: 'tabs',
|
|
@@ -206,10 +215,12 @@ informative and accurate but also captivating and beautifully structured.`,
|
|
|
206
215
|
* - Layouts can be saved in as an array
|
|
207
216
|
* - User can add their own layout to collections and use it later for generate specific rich text
|
|
208
217
|
* - User can select previously added layout
|
|
218
|
+
* - IMP: Remove layout from default, this seem to affect other functions like rephrase etc.
|
|
209
219
|
*/ /** TODO:
|
|
210
220
|
* - Layouts can be saved in as an array
|
|
211
221
|
* - User can add their own layout to collections and use it later for generate specific rich text
|
|
212
222
|
* - User can select previously added layout
|
|
223
|
+
* - IMP: Remove layout from default, this seem to affect other functions like rephrase etc.
|
|
213
224
|
*/ name: 'layout',
|
|
214
225
|
type: 'textarea',
|
|
215
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 = (\n pluginConfig: PluginConfig,\n) =>\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 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","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,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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;gBACEC,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;QAC7C,OAAO;YACLD,QAAQC,MAAMD,MAAM;YACpBM,OAAOL,MAAMM,IAAI;YACjBC,OAAOP,MAAMQ,EAAE;QACjB;IACF;AAEF,MAAMC,sBAAsB;IAC1BC,QAAQ,CAAC,EAAEC,GAAG,EAA2B;QACvC,IAAI,CAACA,IAAIC,IAAI,EAAE;YACb,OAAO;QACT;QACA,OAAO;IACT;IACAC,QAAQ,CAAC,EAAEF,GAAG,EAA2B;QACvC,IAAI,CAACA,IAAIC,IAAI,EAAE;YACb,OA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K;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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/fetchFields.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload'\n\nimport type { PluginConfig, SerializedPromptField } from '../types.js'\n\nimport { PLUGIN_FETCH_FIELDS_ENDPOINT, PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\n\nexport const fetchFields: (config: PluginConfig) => Endpoint = (
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/fetchFields.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload'\n\nimport type { PluginConfig, SerializedPromptField } from '../types.js'\n\nimport { PLUGIN_FETCH_FIELDS_ENDPOINT, PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\n\nexport const fetchFields: (config: PluginConfig) => Endpoint = (config) => {\n const { access, options = {}, promptFields = [] } = config\n return {\n handler: async (req: PayloadRequest) => {\n const { docs = [] } = await req.payload.find({\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n pagination: false,\n })\n\n let isConfigAllowed = true // Users allowed to update prompts by default\n\n if (access?.settings) {\n try {\n isConfigAllowed = await access.settings({ req })\n } catch (e) {\n req.payload.logger.error(req, 'Please check your \"access.settings\" for request')\n }\n }\n\n const fieldMap: Record<string, { disabled?: boolean; fieldType: any; id: any }> = {}\n docs.forEach((doc) => {\n fieldMap[doc['schema-path']] = {\n id: doc.id,\n disabled: !!doc['disabled'],\n fieldType: doc['field-type'],\n }\n })\n\n return Response.json({\n ...options,\n debugging: config.debugging,\n fields: fieldMap,\n isConfigAllowed,\n promptFields: promptFields.map(({ getter: _getter, ...field }): SerializedPromptField => {\n return field\n }),\n })\n },\n method: 'get',\n path: PLUGIN_FETCH_FIELDS_ENDPOINT,\n }\n}\n"],"names":["PLUGIN_FETCH_FIELDS_ENDPOINT","PLUGIN_INSTRUCTIONS_TABLE","fetchFields","config","access","options","promptFields","handler","req","docs","payload","find","collection","pagination","isConfigAllowed","settings","e","logger","error","fieldMap","forEach","doc","id","disabled","fieldType","Response","json","debugging","fields","map","getter","_getter","field","method","path"],"mappings":"AAIA,SAASA,4BAA4B,EAAEC,yBAAyB,QAAQ,iBAAgB;AAExF,OAAO,MAAMC,cAAkD,CAACC;IAC9D,MAAM,EAAEC,MAAM,EAAEC,UAAU,CAAC,CAAC,EAAEC,eAAe,EAAE,EAAE,GAAGH;IACpD,OAAO;QACLI,SAAS,OAAOC;YACd,MAAM,EAAEC,OAAO,EAAE,EAAE,GAAG,MAAMD,IAAIE,OAAO,CAACC,IAAI,CAAC;gBAC3CC,YAAYX;gBACZY,YAAY;YACd;YAEA,IAAIC,kBAAkB,KAAK,6CAA6C;;YAExE,IAAIV,QAAQW,UAAU;gBACpB,IAAI;oBACFD,kBAAkB,MAAMV,OAAOW,QAAQ,CAAC;wBAAEP;oBAAI;gBAChD,EAAE,OAAOQ,GAAG;oBACVR,IAAIE,OAAO,CAACO,MAAM,CAACC,KAAK,CAACV,KAAK;gBAChC;YACF;YAEA,MAAMW,WAA4E,CAAC;YACnFV,KAAKW,OAAO,CAAC,CAACC;gBACZF,QAAQ,CAACE,GAAG,CAAC,cAAc,CAAC,GAAG;oBAC7BC,IAAID,IAAIC,EAAE;oBACVC,UAAU,CAAC,CAACF,GAAG,CAAC,WAAW;oBAC3BG,WAAWH,GAAG,CAAC,aAAa;gBAC9B;YACF;YAEA,OAAOI,SAASC,IAAI,CAAC;gBACnB,GAAGrB,OAAO;gBACVsB,WAAWxB,OAAOwB,SAAS;gBAC3BC,QAAQT;gBACRL;gBACAR,cAAcA,aAAauB,GAAG,CAAC,CAAC,EAAEC,QAAQC,OAAO,EAAE,GAAGC,OAAO;oBAC3D,OAAOA;gBACT;YACF;QACF;QACAC,QAAQ;QACRC,MAAMlC;IACR;AACF,EAAC"}
|
package/dist/endpoints/index.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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) {
|