@ai-stack/payloadcms 3.2.9-beta → 3.2.11-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/README.md +36 -21
- package/dist/ai/models/anthropic/generateRichText.d.ts +1 -1
- package/dist/ai/models/anthropic/generateRichText.d.ts.map +1 -1
- package/dist/ai/models/anthropic/generateRichText.js +5 -6
- package/dist/ai/models/anthropic/generateRichText.js.map +1 -1
- package/dist/ai/models/anthropic/index.js +15 -12
- package/dist/ai/models/anthropic/index.js.map +1 -1
- package/dist/ai/models/openai/generateImage.d.ts +2 -6
- package/dist/ai/models/openai/generateImage.d.ts.map +1 -1
- package/dist/ai/models/openai/generateImage.js +19 -9
- package/dist/ai/models/openai/generateImage.js.map +1 -1
- package/dist/ai/models/openai/generateRichText.d.ts +1 -1
- package/dist/ai/models/openai/generateRichText.d.ts.map +1 -1
- package/dist/ai/models/openai/generateRichText.js +5 -6
- package/dist/ai/models/openai/generateRichText.js.map +1 -1
- package/dist/ai/models/openai/index.d.ts.map +1 -1
- package/dist/ai/models/openai/index.js +133 -4
- package/dist/ai/models/openai/index.js.map +1 -1
- package/dist/ai/prompts.js +6 -6
- package/dist/ai/prompts.js.map +1 -1
- package/dist/ai/schemas/lexicalJsonSchema.d.ts +19 -741
- package/dist/ai/schemas/lexicalJsonSchema.d.ts.map +1 -1
- package/dist/ai/schemas/lexicalJsonSchema.js +72 -4
- package/dist/ai/schemas/lexicalJsonSchema.js.map +1 -1
- package/dist/ai/utils/editImagesWithOpenAI.d.ts +11 -0
- package/dist/ai/utils/editImagesWithOpenAI.d.ts.map +1 -0
- package/dist/ai/utils/editImagesWithOpenAI.js +37 -0
- package/dist/ai/utils/editImagesWithOpenAI.js.map +1 -0
- package/dist/ai/utils/filterEditorSchemaByNodes.d.ts +72 -0
- package/dist/ai/utils/filterEditorSchemaByNodes.d.ts.map +1 -0
- package/dist/ai/utils/filterEditorSchemaByNodes.js +43 -0
- package/dist/ai/utils/filterEditorSchemaByNodes.js.map +1 -0
- package/dist/ai/utils/isObjectSchema.d.ts +3 -0
- package/dist/ai/utils/isObjectSchema.d.ts.map +1 -0
- package/dist/ai/utils/isObjectSchema.js +5 -0
- package/dist/ai/utils/isObjectSchema.js.map +1 -0
- package/dist/collections/Instructions.d.ts.map +1 -1
- package/dist/collections/Instructions.js +26 -1
- package/dist/collections/Instructions.js.map +1 -1
- package/dist/defaults.d.ts +1 -1
- package/dist/defaults.js +1 -1
- package/dist/defaults.js.map +1 -1
- package/dist/endpoints/index.d.ts.map +1 -1
- package/dist/endpoints/index.js +65 -15
- package/dist/endpoints/index.js.map +1 -1
- package/dist/fields/PromptEditorField/PromptEditorField.d.ts.map +1 -1
- package/dist/fields/PromptEditorField/PromptEditorField.js +46 -16
- package/dist/fields/PromptEditorField/PromptEditorField.js.map +1 -1
- package/dist/fields/PromptEditorField/defaultStyle.d.ts +50 -0
- package/dist/fields/PromptEditorField/defaultStyle.d.ts.map +1 -0
- package/dist/fields/PromptEditorField/defaultStyle.js +51 -0
- package/dist/fields/PromptEditorField/defaultStyle.js.map +1 -0
- package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts +2 -0
- package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts.map +1 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.js +4 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.js.map +1 -1
- package/dist/providers/InstructionsProvider/useInstructions.d.ts.map +1 -1
- package/dist/providers/InstructionsProvider/useInstructions.js +54 -29
- package/dist/providers/InstructionsProvider/useInstructions.js.map +1 -1
- package/dist/types.d.ts +18 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/ui/Compose/Compose.js +2 -2
- package/dist/ui/Compose/Compose.js.map +1 -1
- package/dist/ui/Compose/hooks/menu/useMenu.d.ts +1 -1
- package/dist/ui/Compose/hooks/menu/useMenu.d.ts.map +1 -1
- package/dist/ui/Compose/hooks/menu/useMenu.js +2 -1
- package/dist/ui/Compose/hooks/menu/useMenu.js.map +1 -1
- package/dist/ui/Compose/hooks/useGenerate.d.ts.map +1 -1
- package/dist/ui/Compose/hooks/useGenerate.js +11 -4
- package/dist/ui/Compose/hooks/useGenerate.js.map +1 -1
- package/dist/utilities/extractImageData.d.ts +10 -0
- package/dist/utilities/extractImageData.d.ts.map +1 -0
- package/dist/utilities/extractImageData.js +22 -0
- package/dist/utilities/extractImageData.js.map +1 -0
- package/dist/utilities/setSafeLexicalState.js +5 -2
- package/dist/utilities/setSafeLexicalState.js.map +1 -1
- package/package.json +14 -9
- package/dist/ai/models/example-prompt-rich-text.md +0 -47
- package/dist/ai/models/example.d.ts +0 -73
- package/dist/ai/models/example.d.ts.map +0 -1
- package/dist/ai/models/example.js +0 -126
- package/dist/ai/models/example.js.map +0 -1
- package/dist/libraries/autocomplete/AutocompleteTextArea.d.ts +0 -8
- package/dist/libraries/autocomplete/AutocompleteTextArea.d.ts.map +0 -1
- package/dist/libraries/autocomplete/AutocompleteTextArea.js +0 -437
- package/dist/libraries/autocomplete/AutocompleteTextArea.js.map +0 -1
- package/dist/libraries/autocomplete/AutocompleteTextArea.module.scss +0 -35
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicalJsonSchema.d.ts","sourceRoot":"","sources":["../../../src/ai/schemas/lexicalJsonSchema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc
|
|
1
|
+
{"version":3,"file":"lexicalJsonSchema.d.ts","sourceRoot":"","sources":["../../../src/ai/schemas/lexicalJsonSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAI9C,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,UAAU,EAAE;QACV,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;QAClB,QAAQ,CAAC,EAAE;YACT,KAAK,EAAE;gBACL,IAAI,CAAC,EAAE,MAAM,CAAA;gBACb,KAAK,CAAC,EAAE;oBAAE,IAAI,EAAE,MAAM,CAAA;iBAAE,EAAE,CAAA;aAC3B,CAAA;YACD,IAAI,EAAE,OAAO,CAAA;SACd,CAAA;QACD,IAAI,CAAC,EAAE;YACL,IAAI,EAAE,MAAM,EAAE,CAAA;YACd,IAAI,EAAE,QAAQ,CAAA;SACf,CAAA;KACF,CAAA;IACD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,IAAI,EAAE,QAAQ,CAAA;CACf;AAED,eAAO,MAAM,cAAc,EAAE,iBA8Y5B,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,mBAAgB,sBAuBjD,CAAA"}
|
|
@@ -1,8 +1,47 @@
|
|
|
1
|
+
import { isObjectSchema } from '../utils/isObjectSchema.js';
|
|
1
2
|
export const documentSchema = {
|
|
2
3
|
type: 'object',
|
|
3
4
|
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
4
5
|
additionalProperties: false,
|
|
5
6
|
definitions: {
|
|
7
|
+
LineBreakNode: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
additionalProperties: false,
|
|
10
|
+
properties: {
|
|
11
|
+
type: {
|
|
12
|
+
type: 'string',
|
|
13
|
+
enum: [
|
|
14
|
+
'linebreak'
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
version: {
|
|
18
|
+
type: 'number'
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
required: [
|
|
22
|
+
'type',
|
|
23
|
+
'version'
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
TabNode: {
|
|
27
|
+
type: 'object',
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
properties: {
|
|
30
|
+
type: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
enum: [
|
|
33
|
+
'tab'
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
version: {
|
|
37
|
+
type: 'number'
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
required: [
|
|
41
|
+
'type',
|
|
42
|
+
'version'
|
|
43
|
+
]
|
|
44
|
+
},
|
|
6
45
|
// Text Node (Leaf Node)
|
|
7
46
|
TextNode: {
|
|
8
47
|
type: 'object',
|
|
@@ -252,6 +291,12 @@ export const documentSchema = {
|
|
|
252
291
|
},
|
|
253
292
|
{
|
|
254
293
|
$ref: '#/definitions/LinkNode'
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
$ref: '#/definitions/LineBreakNode'
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
$ref: '#/definitions/TabNode'
|
|
255
300
|
}
|
|
256
301
|
]
|
|
257
302
|
}
|
|
@@ -313,6 +358,12 @@ export const documentSchema = {
|
|
|
313
358
|
},
|
|
314
359
|
{
|
|
315
360
|
$ref: '#/definitions/CodeNode'
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
$ref: '#/definitions/LineBreakNode'
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
$ref: '#/definitions/TabNode'
|
|
316
367
|
}
|
|
317
368
|
]
|
|
318
369
|
}
|
|
@@ -329,6 +380,7 @@ export const documentSchema = {
|
|
|
329
380
|
},
|
|
330
381
|
format: {
|
|
331
382
|
type: 'string',
|
|
383
|
+
description: 'Format alignment based on content. Prioritize "start", then "center", and use "right" only when appropriate.',
|
|
332
384
|
enum: [
|
|
333
385
|
'start',
|
|
334
386
|
'center',
|
|
@@ -417,6 +469,9 @@ export const documentSchema = {
|
|
|
417
469
|
},
|
|
418
470
|
{
|
|
419
471
|
$ref: '#/definitions/ListNode'
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
$ref: '#/definitions/LineBreakNode'
|
|
420
475
|
}
|
|
421
476
|
]
|
|
422
477
|
}
|
|
@@ -479,6 +534,12 @@ export const documentSchema = {
|
|
|
479
534
|
},
|
|
480
535
|
{
|
|
481
536
|
$ref: '#/definitions/ParagraphNode'
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
$ref: '#/definitions/LineBreakNode'
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
$ref: '#/definitions/TabNode'
|
|
482
543
|
}
|
|
483
544
|
]
|
|
484
545
|
}
|
|
@@ -649,10 +710,17 @@ export const lexicalJsonSchema = (customNodes = [])=>{
|
|
|
649
710
|
customNodes.forEach((nodeObj)=>{
|
|
650
711
|
for (const [nodeName, nodeDefinition] of Object.entries(nodeObj)){
|
|
651
712
|
schema.definitions[nodeName] = nodeDefinition;
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
713
|
+
const rootNode = schema.definitions['RootNode'];
|
|
714
|
+
if (isObjectSchema(rootNode)) {
|
|
715
|
+
const children = rootNode.properties?.children;
|
|
716
|
+
const items = children?.items;
|
|
717
|
+
const anyOfList = items?.anyOf;
|
|
718
|
+
if (Array.isArray(anyOfList)) {
|
|
719
|
+
anyOfList.push({
|
|
720
|
+
$ref: `#/definitions/${nodeName}`
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
}
|
|
656
724
|
}
|
|
657
725
|
});
|
|
658
726
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ai/schemas/lexicalJsonSchema.ts"],"sourcesContent":["export const documentSchema = {\n type: 'object',\n $schema: 'http://json-schema.org/draft-07/schema#',\n additionalProperties: false,\n definitions: {\n // Text Node (Leaf Node)\n TextNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['text'] },\n detail: {\n type: 'number',\n description: 'Text detail flags',\n enum: [\n 0, // No details\n 1, // IS_DIRECTIONLESS\n 2, // IS_UNMERGEABLE\n 3, // IS_DIRECTIONLESS + IS_UNMERGEABLE\n ],\n examples: [\n { description: 'No special details', value: 0 },\n { description: 'Directionless', value: 1 },\n { description: 'Unmergeable', value: 2 },\n { description: 'Directionless + Unmergeable', value: 3 },\n ],\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n format: {\n type: 'number',\n description: `Format flags for text:\n 0 = No format\n 1 = Bold\n 2 = Italic\n 3 = Bold + Italic (1|2)\n 4 = Strikethrough\n 8 = Underline\n 9 = Bold + Underline (1|8)\n 16 = Code\n 32 = Subscript\n 64 = Superscript\n 128 = Highlight\n \n Formats can be combined using binary OR (|).\n Example combinations:\n - Bold + Italic = 1|2 = 3\n - Bold + Underline = 1|8 = 9\n - Italic + Underline = 2|8 = 10\n - Bold + Italic + Underline = 1|2|8 = 11`,\n },\n indent: { type: 'number' },\n mode: {\n type: 'number',\n description: 'Text mode flags',\n enum: [\n 0, // Normal\n 1, // Token\n 2, // Segmented\n ],\n examples: [\n { description: 'Normal text', value: 0 },\n { description: 'Token text', value: 1 },\n { description: 'Segmented text', value: 2 },\n ],\n },\n style: {\n type: 'string',\n description: 'CSS style string (e.g., \"color: red; font-size: 12px;\")',\n },\n text: { type: 'string' },\n version: { type: 'number' },\n },\n required: [\n 'type',\n 'text',\n 'format',\n 'style',\n 'mode',\n 'detail',\n 'direction',\n 'indent',\n 'version',\n ],\n },\n // Styled Table Cell Node\n TableCellNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['tablecell'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TextNode',\n },\n },\n colSpan: { type: 'number' },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n headerState: { type: 'number' },\n indent: { type: 'number' },\n version: { type: 'number' },\n width: {\n type: ['null'],\n enum: [null],\n },\n },\n required: [\n 'type',\n 'children',\n 'headerState',\n 'colSpan',\n 'width',\n 'direction',\n 'indent',\n 'version',\n ],\n },\n // Styled Table Row Node\n TableRowNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['tablerow'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TableCellNode',\n },\n },\n height: { type: 'number' },\n },\n required: ['type', 'children', 'height'],\n },\n // Styled Table Node\n TableNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['table'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TableRowNode',\n },\n },\n },\n required: ['type', 'children'],\n },\n // Heading Node\n HeadingNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['heading'] },\n children: {\n type: 'array',\n items: {\n anyOf: [{ $ref: '#/definitions/TextNode' }, { $ref: '#/definitions/LinkNode' }],\n },\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n indent: { type: 'number' },\n tag: { type: 'string', enum: ['h1', 'h2', 'h3'] },\n version: { type: 'number' },\n },\n required: ['type', 'tag', 'children', 'direction', 'indent', 'version'],\n },\n // Paragraph Node\n ParagraphNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['paragraph'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/LinkNode' },\n { $ref: '#/definitions/CodeNode' },\n ],\n },\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n format: { type: 'string', enum: ['start', 'center', 'right'] },\n indent: { type: 'number' },\n textFormat: { type: 'number' },\n textStyle: {\n type: 'string',\n description: 'CSS style string (e.g., \"color: red; font-size: 12px;\")',\n },\n version: { type: 'number' },\n },\n required: [\n 'type',\n 'children',\n 'direction',\n 'format',\n 'indent',\n 'textFormat',\n 'textStyle',\n 'version',\n ],\n },\n // Link Node\n LinkNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['link'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TextNode',\n },\n },\n url: { type: 'string' },\n },\n required: ['type', 'url', 'children'],\n },\n // List Item Node\n ListItemNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n // NOTE: Do not change the position of \"indent\", models like gpt generate properties as they are\n // defined in schema, moving the position of property \"indent\"\n // can cause issue with schema validation while streaming generated json to lexical editor\n indent: { type: 'number', enum: [0, 1] },\n type: { type: 'string', enum: ['listitem'] },\n children: {\n type: 'array',\n items: {\n anyOf: [{ $ref: '#/definitions/ParagraphNode' }, { $ref: '#/definitions/ListNode' }],\n },\n },\n },\n required: ['indent', 'type', 'children'],\n },\n // List Node\n ListNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['list'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/ListItemNode',\n },\n },\n listType: { type: 'string', enum: ['bullet', 'number'] },\n },\n required: ['type', 'listType', 'children'],\n },\n // Quote Node\n QuoteNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['quote'] },\n children: {\n type: 'array',\n items: {\n anyOf: [{ $ref: '#/definitions/TextNode' }, { $ref: '#/definitions/ParagraphNode' }],\n },\n },\n },\n required: ['type', 'children'],\n },\n // Code Node\n CodeNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['code'] },\n code: { type: 'string' },\n language: { type: 'string' },\n },\n required: ['type', 'code', 'language'],\n },\n // Horizontal Rule Node\n HorizontalRuleNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['horizontalrule'] },\n },\n required: ['type'],\n },\n // Image Node\n ImageNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['image'] },\n alt: { type: 'string' },\n caption: {\n type: 'array',\n items: {\n $ref: '#/definitions/TextNode',\n },\n },\n src: { type: 'string' },\n },\n required: ['type', 'src', 'alt', 'caption'],\n },\n // Root Node\n RootNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['root'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/HeadingNode' },\n { $ref: '#/definitions/ParagraphNode' },\n { $ref: '#/definitions/LinkNode' },\n { $ref: '#/definitions/ListNode' },\n { $ref: '#/definitions/QuoteNode' },\n { $ref: '#/definitions/CodeNode' },\n { $ref: '#/definitions/HorizontalRuleNode' },\n { $ref: '#/definitions/ImageNode' },\n { $ref: '#/definitions/TableNode' },\n ],\n },\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n indent: { type: 'number' },\n version: { type: 'number' },\n },\n required: ['type', 'children', 'direction', 'indent', 'version'],\n },\n },\n properties: {\n root: {\n $ref: '#/definitions/RootNode',\n },\n },\n required: ['root'],\n}\n\nexport const lexicalJsonSchema = (customNodes = []) => {\n const schema = structuredClone(documentSchema)\n\n if (Array.isArray(customNodes) && customNodes.length > 0) {\n customNodes.forEach((nodeObj) => {\n for (const [nodeName, nodeDefinition] of Object.entries(nodeObj)) {\n schema.definitions[nodeName] = nodeDefinition\n const anyOfList = schema?.definitions?.RootNode?.properties?.children?.items?.anyOf\n\n anyOfList.push({ $ref: `#/definitions/${nodeName}` })\n }\n })\n }\n\n return schema\n}\n"],"names":["documentSchema","type","$schema","additionalProperties","definitions","TextNode","properties","enum","detail","description","examples","value","direction","format","indent","mode","style","text","version","required","TableCellNode","children","items","$ref","colSpan","headerState","width","TableRowNode","height","TableNode","HeadingNode","anyOf","tag","ParagraphNode","textFormat","textStyle","LinkNode","url","ListItemNode","ListNode","listType","QuoteNode","CodeNode","code","language","HorizontalRuleNode","ImageNode","alt","caption","src","RootNode","root","lexicalJsonSchema","customNodes","schema","structuredClone","Array","isArray","length","forEach","nodeObj","nodeName","nodeDefinition","Object","entries","anyOfList","push"],"mappings":"AAAA,OAAO,MAAMA,iBAAiB;IAC5BC,MAAM;IACNC,SAAS;IACTC,sBAAsB;IACtBC,aAAa;QACX,wBAAwB;QACxBC,UAAU;YACRJ,MAAM;YACNE,sBAAsB;YACtBG,YAAY;gBACVL,MAAM;oBAAEA,MAAM;oBAAUM,MAAM;wBAAC;qBAAO;gBAAC;gBACvCC,QAAQ;oBACNP,MAAM;oBACNQ,aAAa;oBACbF,MAAM;wBACJ;wBACA;wBACA;w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AAU;gBAAC;gBAAQ;gBAAY;gBAAa;gBAAU;aAAU;QAClE;IACF;IACAb,YAAY;QACV6C,MAAM;YACJ5B,MAAM;QACR;IACF;IACAJ,UAAU;QAAC;KAAO;AACpB,EAAC;AAED,OAAO,MAAMiC,oBAAoB,CAACC,cAAc,EAAE;IAChD,MAAMC,SAASC,gBAAgBvD;IAE/B,IAAIwD,MAAMC,OAAO,CAACJ,gBAAgBA,YAAYK,MAAM,GAAG,GAAG;QACxDL,YAAYM,OAAO,CAAC,CAACC;YACnB,KAAK,MAAM,CAACC,UAAUC,eAAe,IAAIC,OAAOC,OAAO,CAACJ,SAAU;gBAChEN,OAAOlD,WAAW,CAACyD,SAAS,GAAGC;gBAC/B,MAAMG,YAAYX,QAAQlD,aAAa8C,UAAU5C,YAAYe,UAAUC,OAAOS;gBAE9EkC,UAAUC,IAAI,CAAC;oBAAE3C,MAAM,CAAC,cAAc,EAAEsC,UAAU;gBAAC;YACrD;QACF;IACF;IAEA,OAAOP;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/ai/schemas/lexicalJsonSchema.ts"],"sourcesContent":["import type { JSONSchema7 } from 'json-schema'\n\nimport { isObjectSchema } from '../utils/isObjectSchema.js'\n\nexport interface LexicalNodeSchema extends JSONSchema7 {\n additionalProperties?: boolean\n properties: {\n [key: string]: any\n children?: {\n items: {\n $ref?: string\n anyOf?: { $ref: string }[]\n }\n type: 'array'\n }\n type?: {\n enum: string[]\n type: 'string'\n }\n }\n required?: string[]\n type: 'object'\n}\n\nexport const documentSchema: LexicalNodeSchema = {\n type: 'object',\n $schema: 'http://json-schema.org/draft-07/schema#',\n additionalProperties: false,\n definitions: {\n LineBreakNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['linebreak'] },\n version: { type: 'number' },\n },\n required: ['type', 'version'],\n },\n TabNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['tab'] },\n version: { type: 'number' },\n },\n required: ['type', 'version'],\n },\n // Text Node (Leaf Node)\n TextNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['text'] },\n detail: {\n type: 'number',\n description: 'Text detail flags',\n enum: [\n 0, // No details\n 1, // IS_DIRECTIONLESS\n 2, // IS_UNMERGEABLE\n 3, // IS_DIRECTIONLESS + IS_UNMERGEABLE\n ],\n examples: [\n { description: 'No special details', value: 0 },\n { description: 'Directionless', value: 1 },\n { description: 'Unmergeable', value: 2 },\n { description: 'Directionless + Unmergeable', value: 3 },\n ],\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n format: {\n type: 'number',\n description: `Format flags for text:\n 0 = No format\n 1 = Bold\n 2 = Italic\n 3 = Bold + Italic (1|2)\n 4 = Strikethrough\n 8 = Underline\n 9 = Bold + Underline (1|8)\n 16 = Code\n 32 = Subscript\n 64 = Superscript\n 128 = Highlight\n \n Formats can be combined using binary OR (|).\n Example combinations:\n - Bold + Italic = 1|2 = 3\n - Bold + Underline = 1|8 = 9\n - Italic + Underline = 2|8 = 10\n - Bold + Italic + Underline = 1|2|8 = 11`,\n },\n indent: { type: 'number' },\n mode: {\n type: 'number',\n description: 'Text mode flags',\n enum: [\n 0, // Normal\n 1, // Token\n 2, // Segmented\n ],\n examples: [\n { description: 'Normal text', value: 0 },\n { description: 'Token text', value: 1 },\n { description: 'Segmented text', value: 2 },\n ],\n },\n style: {\n type: 'string',\n description: 'CSS style string (e.g., \"color: red; font-size: 12px;\")',\n },\n text: { type: 'string' },\n version: { type: 'number' },\n },\n required: [\n 'type',\n 'text',\n 'format',\n 'style',\n 'mode',\n 'detail',\n 'direction',\n 'indent',\n 'version',\n ],\n },\n // Styled Table Cell Node\n TableCellNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['tablecell'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TextNode',\n },\n },\n colSpan: { type: 'number' },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n headerState: { type: 'number' },\n indent: { type: 'number' },\n version: { type: 'number' },\n width: {\n type: ['null'],\n enum: [null],\n },\n },\n required: [\n 'type',\n 'children',\n 'headerState',\n 'colSpan',\n 'width',\n 'direction',\n 'indent',\n 'version',\n ],\n },\n // Styled Table Row Node\n TableRowNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['tablerow'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TableCellNode',\n },\n },\n height: { type: 'number' },\n },\n required: ['type', 'children', 'height'],\n },\n // Styled Table Node\n TableNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['table'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TableRowNode',\n },\n },\n },\n required: ['type', 'children'],\n },\n // Heading Node\n HeadingNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['heading'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/LinkNode' },\n { $ref: '#/definitions/LineBreakNode' },\n { $ref: '#/definitions/TabNode' },\n ],\n },\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n indent: { type: 'number' },\n tag: { type: 'string', enum: ['h1', 'h2', 'h3'] },\n version: { type: 'number' },\n },\n required: ['type', 'tag', 'children', 'direction', 'indent', 'version'],\n },\n // Paragraph Node\n ParagraphNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['paragraph'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/LinkNode' },\n { $ref: '#/definitions/CodeNode' },\n { $ref: '#/definitions/LineBreakNode' },\n { $ref: '#/definitions/TabNode' },\n ],\n },\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n format: {\n type: 'string',\n description:\n 'Format alignment based on content. Prioritize \"start\", then \"center\", and use \"right\" only when appropriate.',\n enum: ['start', 'center', 'right'],\n },\n indent: { type: 'number' },\n textFormat: { type: 'number' },\n textStyle: {\n type: 'string',\n description: 'CSS style string (e.g., \"color: red; font-size: 12px;\")',\n },\n version: { type: 'number' },\n },\n required: [\n 'type',\n 'children',\n 'direction',\n 'format',\n 'indent',\n 'textFormat',\n 'textStyle',\n 'version',\n ],\n },\n // Link Node\n LinkNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['link'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/TextNode',\n },\n },\n url: { type: 'string' },\n },\n required: ['type', 'url', 'children'],\n },\n // List Item Node\n ListItemNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n // NOTE: Do not change the position of \"indent\", models like gpt generate properties as they are\n // defined in schema, moving the position of property \"indent\"\n // can cause issue with schema validation while streaming generated json to lexical editor\n indent: { type: 'number', enum: [0, 1] },\n\n type: { type: 'string', enum: ['listitem'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/ParagraphNode' },\n { $ref: '#/definitions/ListNode' },\n { $ref: '#/definitions/LineBreakNode' },\n ],\n },\n },\n },\n required: ['indent', 'type', 'children'],\n },\n // List Node\n ListNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['list'] },\n children: {\n type: 'array',\n items: {\n $ref: '#/definitions/ListItemNode',\n },\n },\n listType: { type: 'string', enum: ['bullet', 'number'] },\n },\n required: ['type', 'listType', 'children'],\n },\n // Quote Node\n QuoteNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['quote'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/ParagraphNode' },\n { $ref: '#/definitions/LineBreakNode' },\n { $ref: '#/definitions/TabNode' },\n ],\n },\n },\n },\n required: ['type', 'children'],\n },\n // Code Node\n CodeNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['code'] },\n code: { type: 'string' },\n language: { type: 'string' },\n },\n required: ['type', 'code', 'language'],\n },\n // Horizontal Rule Node\n HorizontalRuleNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['horizontalrule'] },\n },\n required: ['type'],\n },\n // Image Node\n ImageNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['image'] },\n alt: { type: 'string' },\n caption: {\n type: 'array',\n items: {\n $ref: '#/definitions/TextNode',\n },\n },\n src: { type: 'string' },\n },\n required: ['type', 'src', 'alt', 'caption'],\n },\n // Root Node\n RootNode: {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', enum: ['root'] },\n children: {\n type: 'array',\n items: {\n anyOf: [\n { $ref: '#/definitions/TextNode' },\n { $ref: '#/definitions/HeadingNode' },\n { $ref: '#/definitions/ParagraphNode' },\n { $ref: '#/definitions/LinkNode' },\n { $ref: '#/definitions/ListNode' },\n { $ref: '#/definitions/QuoteNode' },\n { $ref: '#/definitions/CodeNode' },\n { $ref: '#/definitions/HorizontalRuleNode' },\n { $ref: '#/definitions/ImageNode' },\n { $ref: '#/definitions/TableNode' },\n ],\n },\n },\n direction: {\n type: ['string', 'null'],\n enum: ['ltr', null],\n },\n indent: { type: 'number' },\n version: { type: 'number' },\n },\n required: ['type', 'children', 'direction', 'indent', 'version'],\n },\n },\n properties: {\n root: {\n $ref: '#/definitions/RootNode',\n },\n },\n required: ['root'],\n}\n\nexport const lexicalJsonSchema = (customNodes = []) => {\n const schema = structuredClone(documentSchema)\n\n if (Array.isArray(customNodes) && customNodes.length > 0) {\n customNodes.forEach((nodeObj) => {\n for (const [nodeName, nodeDefinition] of Object.entries(nodeObj)) {\n schema.definitions[nodeName] = nodeDefinition\n\n const rootNode = schema.definitions['RootNode']\n if (isObjectSchema(rootNode)) {\n const children = rootNode.properties?.children\n const items = children?.items\n const anyOfList = (items as any)?.anyOf\n\n if (Array.isArray(anyOfList)) {\n anyOfList.push({ $ref: `#/definitions/${nodeName}` })\n }\n }\n }\n })\n }\n\n return schema\n}\n"],"names":["isObjectSchema","documentSchema","type","$schema","additionalProperties","definitions","LineBreakNode","properties","enum","version","required","TabNode","TextNode","detail","description","examples","value","direction","format","indent","mode","style","text","TableCellNode","children","items","$ref","colSpan","headerState","width","TableRowNode","height","TableNode","HeadingNode","anyOf","tag","ParagraphNode","textFormat","textStyle","LinkNode","url","ListItemNode","ListNode","listType","QuoteNode","CodeNode","code","language","HorizontalRuleNode","ImageNode","alt","caption","src","RootNode","root","lexicalJsonSchema","customNodes","schema","structuredClone","Array","isArray","length","forEach","nodeObj","nodeName","nodeDefinition","Object","entries","rootNode","anyOfList","push"],"mappings":"AAEA,SAASA,cAAc,QAAQ,6BAA4B;AAsB3D,OAAO,MAAMC,iBAAoC;IAC/CC,MAAM;IACNC,SAAS;IACTC,sBAAsB;IACtBC,aAAa;QACXC,eAAe;YACbJ,MAAM;YACNE,sBAAsB;YACtBG,YAAY;gBACVL,MAAM;oBAAEA,MAAM;oBAAUM,MAAM;wBAAC;qBAAY;gBAAC;gBAC5CC,SAAS;oBAAEP,MAAM;gBAAS;YAC5B;YACAQ,UAAU;gBAAC;gBAAQ;aAAU;QAC/B;QACAC,SAAS;YACPT,MAAM;YACNE,sBAAsB;YACtBG,YAAY;gBACVL,MAAM;oBAAEA,MAAM;oBAAUM,MAAM;wBAAC;qBAAM;gBAAC;gBACtCC,SAAS;oBAAEP,MAAM;gBAAS;YAC5B;YACAQ,UAAU;gBAAC;gBAAQ;aAAU;QAC/B;QACA,wBAAwB;QACxBE,UAAU;YACRV,MAAM;YACNE,sBAAsB;YACtBG,YAAY;gBACVL,MAAM;oBAAEA,MAAM;oBAAUM,MAAM;wBAAC;qBAAO;gBAAC;gBACvCK,QAAQ;oBACNX,MAAM;oBACNY,aAAa;oBACbN,MAAM;wBACJ;wBACA;wBACA;wBACA;qBACD;oBACDO,UAAU;wBACR;4BA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F;gBACAT,WAAW;oBACTf,MAAM;wBAAC;wBAAU;qBAAO;oBACxBM,MAAM;wBAAC;wBAAO;qBAAK;gBACrB;gBACAW,QAAQ;oBAAEjB,MAAM;gBAAS;gBACzBO,SAAS;oBAAEP,MAAM;gBAAS;YAC5B;YACAQ,UAAU;gBAAC;gBAAQ;gBAAY;gBAAa;gBAAU;aAAU;QAClE;IACF;IACAH,YAAY;QACV+C,MAAM;YACJ5B,MAAM;QACR;IACF;IACAhB,UAAU;QAAC;KAAO;AACpB,EAAC;AAED,OAAO,MAAM6C,oBAAoB,CAACC,cAAc,EAAE;IAChD,MAAMC,SAASC,gBAAgBzD;IAE/B,IAAI0D,MAAMC,OAAO,CAACJ,gBAAgBA,YAAYK,MAAM,GAAG,GAAG;QACxDL,YAAYM,OAAO,CAAC,CAACC;YACnB,KAAK,MAAM,CAACC,UAAUC,eAAe,IAAIC,OAAOC,OAAO,CAACJ,SAAU;gBAChEN,OAAOpD,WAAW,CAAC2D,SAAS,GAAGC;gBAE/B,MAAMG,WAAWX,OAAOpD,WAAW,CAAC,WAAW;gBAC/C,IAAIL,eAAeoE,WAAW;oBAC5B,MAAM5C,WAAW4C,SAAS7D,UAAU,EAAEiB;oBACtC,MAAMC,QAAQD,UAAUC;oBACxB,MAAM4C,YAAa5C,OAAeS;oBAElC,IAAIyB,MAAMC,OAAO,CAACS,YAAY;wBAC5BA,UAAUC,IAAI,CAAC;4BAAE5C,MAAM,CAAC,cAAc,EAAEsC,UAAU;wBAAC;oBACrD;gBACF;YACF;QACF;IACF;IAEA,OAAOP;AACT,EAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ImageReference } from '../../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Send multiple images as `image[]` to OpenAI's image edit endpoint using gpt-image-1.
|
|
4
|
+
* @param images
|
|
5
|
+
* @param prompt Prompt to guide the image edit
|
|
6
|
+
* @param model
|
|
7
|
+
* @returns base64 string of the edited image
|
|
8
|
+
* @note: Remove this function, once https://github.com/openai/openai-node/issues/1492 is fixed.
|
|
9
|
+
*/
|
|
10
|
+
export declare function editImagesWithOpenAI(images: ImageReference[], prompt: string, model?: string): Promise<any>;
|
|
11
|
+
//# sourceMappingURL=editImagesWithOpenAI.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editImagesWithOpenAI.d.ts","sourceRoot":"","sources":["../../../src/ai/utils/editImagesWithOpenAI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,cAAc,EAAE,EACxB,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,MAAsB,gBAmC9B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Send multiple images as `image[]` to OpenAI's image edit endpoint using gpt-image-1.
|
|
3
|
+
* @param images
|
|
4
|
+
* @param prompt Prompt to guide the image edit
|
|
5
|
+
* @param model
|
|
6
|
+
* @returns base64 string of the edited image
|
|
7
|
+
* @note: Remove this function, once https://github.com/openai/openai-node/issues/1492 is fixed.
|
|
8
|
+
*/ export async function editImagesWithOpenAI(images, prompt, model = 'gpt-image-1') {
|
|
9
|
+
try {
|
|
10
|
+
const formData = new FormData();
|
|
11
|
+
for (const [_, img] of images.entries()){
|
|
12
|
+
const extension = img.data.type.split('/')[1];
|
|
13
|
+
formData.append('image[]', img.data, `${img.name}.${extension}`);
|
|
14
|
+
}
|
|
15
|
+
formData.append('prompt', prompt);
|
|
16
|
+
formData.append('model', model);
|
|
17
|
+
const baseURL = process.env.OPENAI_BASE_URL ?? 'https://api.openai.com/v1';
|
|
18
|
+
const openaiRes = await fetch(`${baseURL}/images/edits`, {
|
|
19
|
+
body: formData,
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
|
|
22
|
+
'OpenAI-Organization': process.env.OPENAI_ORG_ID || ''
|
|
23
|
+
},
|
|
24
|
+
method: 'POST'
|
|
25
|
+
});
|
|
26
|
+
if (!openaiRes.ok) {
|
|
27
|
+
const errorText = await openaiRes.text();
|
|
28
|
+
throw new Error(`OpenAI edit error: ${openaiRes.status} - ${errorText}`);
|
|
29
|
+
}
|
|
30
|
+
return openaiRes.json();
|
|
31
|
+
} catch (e) {
|
|
32
|
+
console.error('Error editing images: ', e);
|
|
33
|
+
throw Error('Image edit request failed. Please ensure the images are accessible and hosted publicly.');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=editImagesWithOpenAI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/ai/utils/editImagesWithOpenAI.ts"],"sourcesContent":["import type { ImageReference } from '../../types.js'\n\n/**\n * Send multiple images as `image[]` to OpenAI's image edit endpoint using gpt-image-1.\n * @param images\n * @param prompt Prompt to guide the image edit\n * @param model\n * @returns base64 string of the edited image\n * @note: Remove this function, once https://github.com/openai/openai-node/issues/1492 is fixed.\n */\nexport async function editImagesWithOpenAI(\n images: ImageReference[],\n prompt: string,\n model: string = 'gpt-image-1',\n) {\n try {\n const formData = new FormData()\n\n for (const [_, img] of images.entries()) {\n const extension = img.data.type.split('/')[1]\n formData.append('image[]', img.data, `${img.name}.${extension}`)\n }\n\n formData.append('prompt', prompt)\n formData.append('model', model)\n\n const baseURL = process.env.OPENAI_BASE_URL ?? 'https://api.openai.com/v1'\n const openaiRes = await fetch(`${baseURL}/images/edits`, {\n body: formData,\n headers: {\n Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,\n 'OpenAI-Organization': process.env.OPENAI_ORG_ID || '',\n },\n method: 'POST',\n })\n\n if (!openaiRes.ok) {\n const errorText = await openaiRes.text()\n throw new Error(`OpenAI edit error: ${openaiRes.status} - ${errorText}`)\n }\n\n return openaiRes.json()\n } catch (e) {\n console.error('Error editing images: ', e)\n throw Error(\n 'Image edit request failed. Please ensure the images are accessible and hosted publicly.',\n )\n }\n}\n"],"names":["editImagesWithOpenAI","images","prompt","model","formData","FormData","_","img","entries","extension","data","type","split","append","name","baseURL","process","env","OPENAI_BASE_URL","openaiRes","fetch","body","headers","Authorization","OPENAI_API_KEY","OPENAI_ORG_ID","method","ok","errorText","text","Error","status","json","e","console","error"],"mappings":"AAEA;;;;;;;CAOC,GACD,OAAO,eAAeA,qBACpBC,MAAwB,EACxBC,MAAc,EACdC,QAAgB,aAAa;IAE7B,IAAI;QACF,MAAMC,WAAW,IAAIC;QAErB,KAAK,MAAM,CAACC,GAAGC,IAAI,IAAIN,OAAOO,OAAO,GAAI;YACvC,MAAMC,YAAYF,IAAIG,IAAI,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;YAC7CR,SAASS,MAAM,CAAC,WAAWN,IAAIG,IAAI,EAAE,GAAGH,IAAIO,IAAI,CAAC,CAAC,EAAEL,WAAW;QACjE;QAEAL,SAASS,MAAM,CAAC,UAAUX;QAC1BE,SAASS,MAAM,CAAC,SAASV;QAEzB,MAAMY,UAAUC,QAAQC,GAAG,CAACC,eAAe,IAAI;QAC/C,MAAMC,YAAY,MAAMC,MAAM,GAAGL,QAAQ,aAAa,CAAC,EAAE;YACvDM,MAAMjB;YACNkB,SAAS;gBACPC,eAAe,CAAC,OAAO,EAAEP,QAAQC,GAAG,CAACO,cAAc,EAAE;gBACrD,uBAAuBR,QAAQC,GAAG,CAACQ,aAAa,IAAI;YACtD;YACAC,QAAQ;QACV;QAEA,IAAI,CAACP,UAAUQ,EAAE,EAAE;YACjB,MAAMC,YAAY,MAAMT,UAAUU,IAAI;YACtC,MAAM,IAAIC,MAAM,CAAC,mBAAmB,EAAEX,UAAUY,MAAM,CAAC,GAAG,EAAEH,WAAW;QACzE;QAEA,OAAOT,UAAUa,IAAI;IACvB,EAAE,OAAOC,GAAG;QACVC,QAAQC,KAAK,CAAC,0BAA0BF;QACxC,MAAMH,MACJ;IAEJ;AACF"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { LexicalNodeSchema } from '../schemas/lexicalJsonSchema.js';
|
|
2
|
+
export declare function filterEditorSchemaByNodes(schema: LexicalNodeSchema, allowedNodes: any): {
|
|
3
|
+
definitions: {};
|
|
4
|
+
additionalProperties?: boolean;
|
|
5
|
+
properties: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
children?: {
|
|
8
|
+
items: {
|
|
9
|
+
$ref?: string;
|
|
10
|
+
anyOf?: {
|
|
11
|
+
$ref: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
type: "array";
|
|
15
|
+
};
|
|
16
|
+
type?: {
|
|
17
|
+
enum: string[];
|
|
18
|
+
type: "string";
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
required?: string[];
|
|
22
|
+
type: "object";
|
|
23
|
+
$id?: string | undefined;
|
|
24
|
+
$ref?: string | undefined;
|
|
25
|
+
$schema?: import("json-schema").JSONSchema7Version | undefined;
|
|
26
|
+
$comment?: string | undefined;
|
|
27
|
+
$defs?: {
|
|
28
|
+
[key: string]: import("json-schema").JSONSchema7Definition;
|
|
29
|
+
} | undefined;
|
|
30
|
+
enum?: import("json-schema").JSONSchema7Type[] | undefined;
|
|
31
|
+
const?: import("json-schema").JSONSchema7Type | undefined;
|
|
32
|
+
multipleOf?: number | undefined;
|
|
33
|
+
maximum?: number | undefined;
|
|
34
|
+
exclusiveMaximum?: number | undefined;
|
|
35
|
+
minimum?: number | undefined;
|
|
36
|
+
exclusiveMinimum?: number | undefined;
|
|
37
|
+
maxLength?: number | undefined;
|
|
38
|
+
minLength?: number | undefined;
|
|
39
|
+
pattern?: string | undefined;
|
|
40
|
+
items?: import("json-schema").JSONSchema7Definition | import("json-schema").JSONSchema7Definition[] | undefined;
|
|
41
|
+
additionalItems?: import("json-schema").JSONSchema7Definition | undefined;
|
|
42
|
+
maxItems?: number | undefined;
|
|
43
|
+
minItems?: number | undefined;
|
|
44
|
+
uniqueItems?: boolean | undefined;
|
|
45
|
+
contains?: import("json-schema").JSONSchema7Definition | undefined;
|
|
46
|
+
maxProperties?: number | undefined;
|
|
47
|
+
minProperties?: number | undefined;
|
|
48
|
+
patternProperties?: {
|
|
49
|
+
[key: string]: import("json-schema").JSONSchema7Definition;
|
|
50
|
+
} | undefined;
|
|
51
|
+
dependencies?: {
|
|
52
|
+
[key: string]: import("json-schema").JSONSchema7Definition | string[];
|
|
53
|
+
} | undefined;
|
|
54
|
+
propertyNames?: import("json-schema").JSONSchema7Definition | undefined;
|
|
55
|
+
if?: import("json-schema").JSONSchema7Definition | undefined;
|
|
56
|
+
then?: import("json-schema").JSONSchema7Definition | undefined;
|
|
57
|
+
else?: import("json-schema").JSONSchema7Definition | undefined;
|
|
58
|
+
allOf?: import("json-schema").JSONSchema7Definition[] | undefined;
|
|
59
|
+
anyOf?: import("json-schema").JSONSchema7Definition[] | undefined;
|
|
60
|
+
oneOf?: import("json-schema").JSONSchema7Definition[] | undefined;
|
|
61
|
+
not?: import("json-schema").JSONSchema7Definition | undefined;
|
|
62
|
+
format?: string | undefined;
|
|
63
|
+
contentMediaType?: string | undefined;
|
|
64
|
+
contentEncoding?: string | undefined;
|
|
65
|
+
title?: string | undefined;
|
|
66
|
+
description?: string | undefined;
|
|
67
|
+
default?: import("json-schema").JSONSchema7Type | undefined;
|
|
68
|
+
readOnly?: boolean | undefined;
|
|
69
|
+
writeOnly?: boolean | undefined;
|
|
70
|
+
examples?: import("json-schema").JSONSchema7Type | undefined;
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=filterEditorSchemaByNodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterEditorSchemaByNodes.d.ts","sourceRoot":"","sources":["../../../src/ai/utils/filterEditorSchemaByNodes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAIxE,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,iBAAiB,EAAE,YAAY,KAAA;;;;;gBAC5C,CAAC;;oBAEf,CAAC;qBAEZ,CAAC;;;;;;YAA+D,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuC5E"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isObjectSchema } from './isObjectSchema.js';
|
|
2
|
+
export function filterEditorSchemaByNodes(schema, allowedNodes) {
|
|
3
|
+
const allowedTypes = new Set(allowedNodes);
|
|
4
|
+
const filteredDefinitions = {};
|
|
5
|
+
// First pass: collect definitions whose "type.enum" includes an allowed type
|
|
6
|
+
for (const [key, def] of Object.entries(schema.definitions)){
|
|
7
|
+
if (isObjectSchema(def)) {
|
|
8
|
+
const typeEnum = def.properties?.type?.enum;
|
|
9
|
+
if (typeEnum && typeEnum.some((t)=>allowedTypes.has(t))) {
|
|
10
|
+
filteredDefinitions[key] = JSON.parse(JSON.stringify(def)) // Deep copy to safely mutate
|
|
11
|
+
;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// Helper to check if a $ref points to an allowed definition
|
|
16
|
+
const isAllowedRef = (ref)=>{
|
|
17
|
+
if (typeof ref !== 'string') return false;
|
|
18
|
+
const defName = ref.replace('#/definitions/', '');
|
|
19
|
+
return defName in filteredDefinitions;
|
|
20
|
+
};
|
|
21
|
+
// Second pass: update "children" in each definition to only include allowed refs
|
|
22
|
+
for (const def of Object.values(filteredDefinitions)){
|
|
23
|
+
if (isObjectSchema(def) && def.properties?.children?.items) {
|
|
24
|
+
const items = def.properties.children.items;
|
|
25
|
+
if (Array.isArray(items.anyOf)) {
|
|
26
|
+
// Filter anyOf to only allowed $refs
|
|
27
|
+
items.anyOf = items.anyOf.filter((entry)=>isAllowedRef(entry.$ref));
|
|
28
|
+
if (items.anyOf.length === 0) {
|
|
29
|
+
delete def.properties.children;
|
|
30
|
+
}
|
|
31
|
+
} else if (items.$ref && !isAllowedRef(items.$ref)) {
|
|
32
|
+
delete def.properties.children;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Return the new schema with pruned definitions
|
|
37
|
+
return {
|
|
38
|
+
...schema,
|
|
39
|
+
definitions: filteredDefinitions
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=filterEditorSchemaByNodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/ai/utils/filterEditorSchemaByNodes.ts"],"sourcesContent":["import type { LexicalNodeSchema } from '../schemas/lexicalJsonSchema.js'\n\nimport { isObjectSchema } from './isObjectSchema.js'\n\nexport function filterEditorSchemaByNodes(schema: LexicalNodeSchema, allowedNodes) {\n const allowedTypes = new Set(allowedNodes)\n\n const filteredDefinitions = {}\n\n // First pass: collect definitions whose \"type.enum\" includes an allowed type\n for (const [key, def] of Object.entries(schema.definitions)) {\n if(isObjectSchema(def)) {\n const typeEnum = def.properties?.type?.enum\n if (typeEnum && typeEnum.some((t) => allowedTypes.has(t))) {\n filteredDefinitions[key] = JSON.parse(JSON.stringify(def)) // Deep copy to safely mutate\n }\n }\n }\n\n // Helper to check if a $ref points to an allowed definition\n const isAllowedRef = (ref) => {\n if (typeof ref !== 'string') return false\n const defName = ref.replace('#/definitions/', '')\n return defName in filteredDefinitions\n }\n\n // Second pass: update \"children\" in each definition to only include allowed refs\n for (const def of Object.values(filteredDefinitions)) {\n if (isObjectSchema(def) && def.properties?.children?.items) {\n const items = def.properties.children.items\n\n if (Array.isArray(items.anyOf)) {\n // Filter anyOf to only allowed $refs\n items.anyOf = items.anyOf.filter((entry) => isAllowedRef(entry.$ref))\n if (items.anyOf.length === 0) {\n delete def.properties.children\n }\n } else if (items.$ref && !isAllowedRef(items.$ref)) {\n delete def.properties.children\n }\n }\n }\n\n // Return the new schema with pruned definitions\n return {\n ...schema,\n definitions: filteredDefinitions,\n }\n}\n"],"names":["isObjectSchema","filterEditorSchemaByNodes","schema","allowedNodes","allowedTypes","Set","filteredDefinitions","key","def","Object","entries","definitions","typeEnum","properties","type","enum","some","t","has","JSON","parse","stringify","isAllowedRef","ref","defName","replace","values","children","items","Array","isArray","anyOf","filter","entry","$ref","length"],"mappings":"AAEA,SAASA,cAAc,QAAQ,sBAAqB;AAEpD,OAAO,SAASC,0BAA0BC,MAAyB,EAAEC,YAAY;IAC/E,MAAMC,eAAe,IAAIC,IAAIF;IAE7B,MAAMG,sBAAsB,CAAC;IAE7B,6EAA6E;IAC7E,KAAK,MAAM,CAACC,KAAKC,IAAI,IAAIC,OAAOC,OAAO,CAACR,OAAOS,WAAW,EAAG;QAC3D,IAAGX,eAAeQ,MAAM;YACtB,MAAMI,WAAWJ,IAAIK,UAAU,EAAEC,MAAMC;YACvC,IAAIH,YAAYA,SAASI,IAAI,CAAC,CAACC,IAAMb,aAAac,GAAG,CAACD,KAAK;gBACzDX,mBAAmB,CAACC,IAAI,GAAGY,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACb,MAAM,6BAA6B;;YAC1F;QACF;IACF;IAEA,4DAA4D;IAC5D,MAAMc,eAAe,CAACC;QACpB,IAAI,OAAOA,QAAQ,UAAU,OAAO;QACpC,MAAMC,UAAUD,IAAIE,OAAO,CAAC,kBAAkB;QAC9C,OAAOD,WAAWlB;IACpB;IAEA,iFAAiF;IACjF,KAAK,MAAME,OAAOC,OAAOiB,MAAM,CAACpB,qBAAsB;QACpD,IAAIN,eAAeQ,QAAQA,IAAIK,UAAU,EAAEc,UAAUC,OAAO;YAC1D,MAAMA,QAAQpB,IAAIK,UAAU,CAACc,QAAQ,CAACC,KAAK;YAE3C,IAAIC,MAAMC,OAAO,CAACF,MAAMG,KAAK,GAAG;gBAC9B,qCAAqC;gBACrCH,MAAMG,KAAK,GAAGH,MAAMG,KAAK,CAACC,MAAM,CAAC,CAACC,QAAUX,aAAaW,MAAMC,IAAI;gBACnE,IAAIN,MAAMG,KAAK,CAACI,MAAM,KAAK,GAAG;oBAC5B,OAAO3B,IAAIK,UAAU,CAACc,QAAQ;gBAChC;YACF,OAAO,IAAIC,MAAMM,IAAI,IAAI,CAACZ,aAAaM,MAAMM,IAAI,GAAG;gBAClD,OAAO1B,IAAIK,UAAU,CAACc,QAAQ;YAChC;QACF;IACF;IAEA,gDAAgD;IAChD,OAAO;QACL,GAAGzB,MAAM;QACTS,aAAaL;IACf;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isObjectSchema.d.ts","sourceRoot":"","sources":["../../../src/ai/utils/isObjectSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAExE,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,iBAAiB,CAE3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/ai/utils/isObjectSchema.ts"],"sourcesContent":["import type { LexicalNodeSchema } from '../schemas/lexicalJsonSchema.js'\n\nexport function isObjectSchema(schema: unknown): schema is LexicalNodeSchema {\n return typeof schema === 'object' && schema !== null && !Array.isArray(schema)\n}\n"],"names":["isObjectSchema","schema","Array","isArray"],"mappings":"AAEA,OAAO,SAASA,eAAeC,MAAe;IAC5C,OAAO,OAAOA,WAAW,YAAYA,WAAW,QAAQ,CAACC,MAAMC,OAAO,CAACF;AACzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Instructions.d.ts","sourceRoot":"","sources":["../../src/collections/Instructions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,SAAS,CAAA;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAiChD,eAAO,MAAM,sBAAsB,GACjC,cAAc,YAAY,EAC1B,UAAU,OAAO,CAAC,gBAAgB,CAAC,KAElC,
|
|
1
|
+
{"version":3,"file":"Instructions.d.ts","sourceRoot":"","sources":["../../src/collections/Instructions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,SAAS,CAAA;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAiChD,eAAO,MAAM,sBAAsB,GACjC,cAAc,YAAY,EAC1B,UAAU,OAAO,CAAC,gBAAgB,CAAC,KAElC,gBAgMA,CAAA"}
|
|
@@ -106,7 +106,7 @@ export const instructionsCollection = (pluginConfig, options)=>({
|
|
|
106
106
|
type: 'tabs',
|
|
107
107
|
tabs: [
|
|
108
108
|
{
|
|
109
|
-
description: '
|
|
109
|
+
description: 'Define dynamic templates using {{ fieldName }}. Type { to see available field suggestions.',
|
|
110
110
|
fields: [
|
|
111
111
|
{
|
|
112
112
|
name: 'prompt',
|
|
@@ -122,6 +122,31 @@ export const instructionsCollection = (pluginConfig, options)=>({
|
|
|
122
122
|
],
|
|
123
123
|
label: 'Prompt'
|
|
124
124
|
},
|
|
125
|
+
{
|
|
126
|
+
admin: {
|
|
127
|
+
condition: (_, current)=>{
|
|
128
|
+
return current['field-type'] === 'upload' && current['model-id'] === 'gpt-image-1';
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
description: '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.',
|
|
132
|
+
fields: [
|
|
133
|
+
{
|
|
134
|
+
name: 'images',
|
|
135
|
+
type: 'array',
|
|
136
|
+
fields: [
|
|
137
|
+
{
|
|
138
|
+
name: 'image',
|
|
139
|
+
type: 'upload',
|
|
140
|
+
admin: {
|
|
141
|
+
description: 'Please make sure the image is publicly accessible.'
|
|
142
|
+
},
|
|
143
|
+
relationTo: pluginConfig.uploadCollectionSlug ? pluginConfig.uploadCollectionSlug : 'media'
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
],
|
|
148
|
+
label: 'Sample Images'
|
|
149
|
+
},
|
|
125
150
|
{
|
|
126
151
|
admin: {
|
|
127
152
|
condition: (_, current)=>{
|
|
@@ -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: () => true,\n read: () => true,\n update: () => true,\n}\n\nconst defaultAdminConfig = {\n group: 'Plugins',\n hidden: true,\n}\n\nexport const instructionsCollection = (\n pluginConfig: PluginConfig,\n options?: Partial<CollectionConfig>,\n) =>\n <CollectionConfig>{\n slug: PLUGIN_INSTRUCTIONS_TABLE,\n access: {\n ...defaultAccessConfig,\n ...options?.access,\n },\n admin: {\n ...defaultAdminConfig,\n ...options?.admin,\n group: 'Plugins',\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 'The Prompt field allows you to define dynamic templates using placeholders (e.g., {{ fieldName }}) to customize output based on your data fields.',\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'] === '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 labels: {\n plural: 'Compose Settings',\n singular: 'Compose Setting',\n },\n }\n"],"names":["PLUGIN_INSTRUCTIONS_TABLE","getGenerationModels","groupSettings","pluginConfig","reduce","fields","model","settings","push","modelOptions","map","label","name","value","id","defaultAccessConfig","create","read","update","defaultAdminConfig","group","hidden","instructionsCollection","options","slug","access","admin","type","description","unique","defaultValue","condition","_","current","components","Field","clientProps","filterByField","path","option","tabs","labels","plural","singular"],"mappings":"AAGA,SAASA,yBAAyB,QAAQ,iBAAgB;AAC1D,SAASC,mBAAmB,QAAQ,sCAAqC;AAEzE,MAAMC,gBAAgB,CAACC,eACrBF,oBAAoBE,cAAcC,MAAM,CAAC,CAACC,QAAQC;QAChD,IAAIA,MAAMC,QAAQ,EAAE;YAClBF,OAAOG,IAAI,CAACF,MAAMC,QAAQ;QAC5B;QACA,OAAOF;IACT,GAAG,EAAE;AAEP,MAAMI,eAAe,CAACN,eACpBF,oBAAoBE,cAAcO,GAAG,CAAC,CAACJ;QACrC,OAAO;YACLD,QAAQC,MAAMD,MAAM;YACpBM,OAAOL,MAAMM,IAAI;YACjBC,OAAOP,MAAMQ,EAAE;QACjB;IACF;AAEF,MAAMC,sBAAsB;IAC1BC,QAAQ,IAAM;IACdC,MAAM,IAAM;IACZC,QAAQ,IAAM;AAChB;AAEA,MAAMC,qBAAqB;IACzBC,OAAO;IACPC,QAAQ;AACV;AAEA,OAAO,MAAMC,yBAAyB,CACpCnB,cACAoB,UAEkB,CAAA;QAChBC,MAAMxB;QACNyB,QAAQ;YACN,GAAGV,mBAAmB;YACtB,GAAGQ,SAASE,MAAM;QACpB;QACAC,OAAO;YACL,GAAGP,kBAAkB;YACrB,GAAGI,SAASG,KAAK;YACjBN,OAAO;QACT;QACAf,QAAQ;YACN;gBACEO,MAAM;gBACNe,MAAM;gBACND,OAAO;oBACLE,aAAa;gBACf;gBACAC,QAAQ;YACV;YACA;gBACEjB,MAAM;gBACNe,MAAM;gBACND,OAAO;oBACLE,aAAa;gBACf;gBACAE,cAAc;gBACdnB,OAAO;gBACPY,SAAS;oBACP;wBACEZ,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;gBACNe,MAAM;gBACND,OAAO;oBACLK,WAAW,CAACC,GAAGC;wBACb,OAAOA,OAAO,CAAC,aAAa,KAAK;oBACnC;gBACF;gBACAtB,OAAO;YACT;YACA;gBACEC,MAAM;gBACNe,MAAM;gBACND,OAAO;oBACLQ,YAAY;wBACVC,OAAO;4BACLC,aAAa;gCACXC,eAAe;gCACfd,SAASd,aAAaN;4BACxB;4BACAmC,MAAM;wBACR;oBACF;gBACF;gBACA3B,OAAO;gBACPY,SAASd,aAAaN,cAAcO,GAAG,CAAC,CAAC6B;oBACvC,OAAO;wBACL5B,OAAO4B,OAAO5B,KAAK;wBACnBE,OAAO0B,OAAO1B,KAAK;oBACrB;gBACF;YACF;YACA;gBACEC,IAAI;gBACJa,MAAM;gBACNa,MAAM;oBACJ;wBACEZ,aACE;wBACFvB,QAAQ;4BACN;gCACEO,MAAM;gCACNe,MAAM;gCACND,OAAO;oCACLQ,YAAY;wCACVC,OAAO;oCACT;oCACAP,aAAa;gCACf;gCACAjB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;oBACA;wBACEe,OAAO;4BACLK,WAAW,CAACC,GAAGC;gCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;4BACnC;wBACF;wBACAL,aAAa;wBACbvB,QAAQ;4BACN;gCACEO,MAAM;gCACNe,MAAM;gCACNG,cAAc,CAAC;;;;yEAI0C,CAAC;gCAC1DnB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;oBACA;wBACEe,OAAO;4BACLK,WAAW,CAACC,GAAGC;gCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;4BACnC;wBACF;wBACAL,aAAa;wBACbvB,QAAQ;4BACN;gCACE;;;;iBAIC,GAJD;;;;iBAIC,GACDO,MAAM;gCACNe,MAAM;gCACND,OAAO;oCACLK,WAAW,CAACC,GAAGC;wCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;oCACnC;gCACF;gCACAH,cAAc,CAAC;;;;;;;2HAO4F,CAAC;gCAC5GnB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;iBACD;YACH;eACGT,cAAcC;SAClB;QACDsC,QAAQ;YACNC,QAAQ;YACRC,UAAU;QACZ;IACF,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: () => true,\n read: () => true,\n update: () => true,\n}\n\nconst defaultAdminConfig = {\n group: 'Plugins',\n hidden: true,\n}\n\nexport const instructionsCollection = (\n pluginConfig: PluginConfig,\n options?: Partial<CollectionConfig>,\n) =>\n <CollectionConfig>{\n slug: PLUGIN_INSTRUCTIONS_TABLE,\n access: {\n ...defaultAccessConfig,\n ...options?.access,\n },\n admin: {\n ...defaultAdminConfig,\n ...options?.admin,\n group: 'Plugins',\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 labels: {\n plural: 'Compose Settings',\n singular: 'Compose Setting',\n },\n }\n"],"names":["PLUGIN_INSTRUCTIONS_TABLE","getGenerationModels","groupSettings","pluginConfig","reduce","fields","model","settings","push","modelOptions","map","label","name","value","id","defaultAccessConfig","create","read","update","defaultAdminConfig","group","hidden","instructionsCollection","options","slug","access","admin","type","description","unique","defaultValue","condition","_","current","components","Field","clientProps","filterByField","path","option","tabs","relationTo","uploadCollectionSlug","labels","plural","singular"],"mappings":"AAGA,SAASA,yBAAyB,QAAQ,iBAAgB;AAC1D,SAASC,mBAAmB,QAAQ,sCAAqC;AAEzE,MAAMC,gBAAgB,CAACC,eACrBF,oBAAoBE,cAAcC,MAAM,CAAC,CAACC,QAAQC;QAChD,IAAI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gCACNe,MAAM;gCACND,OAAO;oCACLK,WAAW,CAACC,GAAGC;wCACb,OAAOA,OAAO,CAAC,aAAa,KAAK;oCACnC;gCACF;gCACAH,cAAc,CAAC;;;;;;;2HAO4F,CAAC;gCAC5GnB,OAAO;4BACT;yBACD;wBACDA,OAAO;oBACT;iBACD;YACH;eACGT,cAAcC;SAClB;QACDwC,QAAQ;YACNC,QAAQ;YACRC,UAAU;QACZ;IACF,CAAA,EAAC"}
|
package/dist/defaults.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export declare const PLUGIN_API_ENDPOINT_GENERATE = "/plugin-ai/generate";
|
|
|
6
6
|
export declare const PLUGIN_API_ENDPOINT_GENERATE_UPLOAD = "/plugin-ai/generate/upload";
|
|
7
7
|
export declare const PLUGIN_FETCH_FIELDS_ENDPOINT = "/plugin-ai/fetch-fields";
|
|
8
8
|
export declare const PLUGIN_DEFAULT_OPENAI_MODEL = "gpt-4o-mini";
|
|
9
|
-
export declare const PLUGIN_DEFAULT_ANTHROPIC_MODEL = "claude-3-sonnet-
|
|
9
|
+
export declare const PLUGIN_DEFAULT_ANTHROPIC_MODEL = "claude-3-5-sonnet-latest";
|
|
10
10
|
//# sourceMappingURL=defaults.d.ts.map
|
package/dist/defaults.js
CHANGED
|
@@ -8,6 +8,6 @@ export const PLUGIN_API_ENDPOINT_GENERATE_UPLOAD = `${PLUGIN_API_ENDPOINT_GENERA
|
|
|
8
8
|
export const PLUGIN_FETCH_FIELDS_ENDPOINT = `${PLUGIN_API_ENDPOINT_BASE}/fetch-fields`;
|
|
9
9
|
// LLM Settings
|
|
10
10
|
export const PLUGIN_DEFAULT_OPENAI_MODEL = `gpt-4o-mini`;
|
|
11
|
-
export const PLUGIN_DEFAULT_ANTHROPIC_MODEL = `claude-3-sonnet-
|
|
11
|
+
export const PLUGIN_DEFAULT_ANTHROPIC_MODEL = `claude-3-5-sonnet-latest`;
|
|
12
12
|
|
|
13
13
|
//# sourceMappingURL=defaults.js.map
|
package/dist/defaults.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const PLUGIN_NAME = 'plugin-ai'\nexport const PLUGIN_INSTRUCTIONS_TABLE = `${PLUGIN_NAME}-instructions`\nexport const PLUGIN_LEXICAL_EDITOR_FEATURE = `${PLUGIN_NAME}-actions-feature`\n\n// Endpoint defaults\nexport const PLUGIN_API_ENDPOINT_BASE = `/${PLUGIN_NAME}`\nexport const PLUGIN_API_ENDPOINT_GENERATE = `${PLUGIN_API_ENDPOINT_BASE}/generate`\nexport const PLUGIN_API_ENDPOINT_GENERATE_UPLOAD = `${PLUGIN_API_ENDPOINT_GENERATE}/upload`\nexport const PLUGIN_FETCH_FIELDS_ENDPOINT = `${PLUGIN_API_ENDPOINT_BASE}/fetch-fields`\n\n// LLM Settings\nexport const PLUGIN_DEFAULT_OPENAI_MODEL = `gpt-4o-mini`\nexport const PLUGIN_DEFAULT_ANTHROPIC_MODEL = `claude-3-sonnet-
|
|
1
|
+
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const PLUGIN_NAME = 'plugin-ai'\nexport const PLUGIN_INSTRUCTIONS_TABLE = `${PLUGIN_NAME}-instructions`\nexport const PLUGIN_LEXICAL_EDITOR_FEATURE = `${PLUGIN_NAME}-actions-feature`\n\n// Endpoint defaults\nexport const PLUGIN_API_ENDPOINT_BASE = `/${PLUGIN_NAME}`\nexport const PLUGIN_API_ENDPOINT_GENERATE = `${PLUGIN_API_ENDPOINT_BASE}/generate`\nexport const PLUGIN_API_ENDPOINT_GENERATE_UPLOAD = `${PLUGIN_API_ENDPOINT_GENERATE}/upload`\nexport const PLUGIN_FETCH_FIELDS_ENDPOINT = `${PLUGIN_API_ENDPOINT_BASE}/fetch-fields`\n\n// LLM Settings\nexport const PLUGIN_DEFAULT_OPENAI_MODEL = `gpt-4o-mini`\nexport const PLUGIN_DEFAULT_ANTHROPIC_MODEL = `claude-3-5-sonnet-latest`\n"],"names":["PLUGIN_NAME","PLUGIN_INSTRUCTIONS_TABLE","PLUGIN_LEXICAL_EDITOR_FEATURE","PLUGIN_API_ENDPOINT_BASE","PLUGIN_API_ENDPOINT_GENERATE","PLUGIN_API_ENDPOINT_GENERATE_UPLOAD","PLUGIN_FETCH_FIELDS_ENDPOINT","PLUGIN_DEFAULT_OPENAI_MODEL","PLUGIN_DEFAULT_ANTHROPIC_MODEL"],"mappings":"AAAA,OAAO,MAAMA,cAAc,YAAW;AACtC,OAAO,MAAMC,4BAA4B,GAAGD,YAAY,aAAa,CAAC,CAAA;AACtE,OAAO,MAAME,gCAAgC,GAAGF,YAAY,gBAAgB,CAAC,CAAA;AAE7E,oBAAoB;AACpB,OAAO,MAAMG,2BAA2B,CAAC,CAAC,EAAEH,aAAa,CAAA;AACzD,OAAO,MAAMI,+BAA+B,GAAGD,yBAAyB,SAAS,CAAC,CAAA;AAClF,OAAO,MAAME,sCAAsC,GAAGD,6BAA6B,OAAO,CAAC,CAAA;AAC3F,OAAO,MAAME,+BAA+B,GAAGH,yBAAyB,aAAa,CAAC,CAAA;AAEtF,eAAe;AACf,OAAO,MAAMI,8BAA8B,CAAC,WAAW,CAAC,CAAA;AACxD,OAAO,MAAMC,iCAAiC,CAAC,wBAAwB,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/endpoints/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/endpoints/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAmB,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAyE3E,eAAO,MAAM,SAAS,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,SAmLhC,CAAA"}
|