@ai-stack/payloadcms 3.0.0-beta.104.2 → 3.0.0-beta.65.0
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 +2 -16
- package/dist/ai/{schemas → editor}/lexical.schema.d.ts +2 -2
- package/dist/ai/editor/lexical.schema.d.ts.map +1 -0
- package/dist/ai/editor/lexical.schema.js.map +1 -0
- package/dist/ai/models/anthropic/generateRichText.js.map +1 -1
- package/dist/ai/models/anthropic/index.d.ts.map +1 -1
- package/dist/ai/models/anthropic/index.js +4 -43
- package/dist/ai/models/anthropic/index.js.map +1 -1
- package/dist/ai/models/elevenLabs/index.d.ts.map +1 -1
- package/dist/ai/models/elevenLabs/index.js +11 -1
- package/dist/ai/models/elevenLabs/index.js.map +1 -1
- package/dist/ai/models/index.d.ts.map +1 -1
- package/dist/ai/models/index.js +3 -3
- package/dist/ai/models/index.js.map +1 -1
- package/dist/ai/models/openai/generateRichText.js.map +1 -1
- package/dist/ai/models/openai/index.js +3 -3
- package/dist/ai/models/openai/index.js.map +1 -1
- package/dist/ai/models/style.d.ts +2 -0
- package/dist/ai/models/style.d.ts.map +1 -0
- package/dist/ai/models/style.js +31 -0
- package/dist/ai/models/style.js.map +1 -0
- package/dist/ai/prompts.d.ts +6 -7
- package/dist/ai/prompts.d.ts.map +1 -1
- package/dist/ai/prompts.js +16 -24
- package/dist/ai/prompts.js.map +1 -1
- package/dist/ai/utils/generateFileNameByPrompt.js.map +1 -1
- package/dist/ai/utils/generateSeedPrompt.d.ts.map +1 -1
- package/dist/ai/utils/generateSeedPrompt.js +5 -14
- package/dist/ai/utils/generateSeedPrompt.js.map +1 -1
- package/dist/collections/Instructions.d.ts.map +1 -1
- package/dist/collections/Instructions.js +13 -10
- package/dist/collections/Instructions.js.map +1 -1
- package/dist/defaults.d.ts +2 -3
- package/dist/defaults.d.ts.map +1 -1
- package/dist/defaults.js +2 -3
- package/dist/defaults.js.map +1 -1
- package/dist/endpoints/index.d.ts +1 -1
- package/dist/endpoints/index.d.ts.map +1 -1
- package/dist/endpoints/index.js +51 -17
- package/dist/endpoints/index.js.map +1 -1
- package/dist/exports/fields.d.ts +1 -3
- package/dist/exports/fields.d.ts.map +1 -1
- package/dist/exports/fields.js +0 -3
- package/dist/exports/fields.js.map +1 -1
- package/dist/fields/DescriptionField/DescriptionField.d.ts +3 -0
- package/dist/fields/DescriptionField/DescriptionField.d.ts.map +1 -0
- package/dist/fields/DescriptionField/DescriptionField.js +15 -0
- package/dist/fields/DescriptionField/DescriptionField.js.map +1 -0
- package/dist/fields/DescriptionField/DescriptionFieldComponent.d.ts +4 -0
- package/dist/fields/DescriptionField/DescriptionFieldComponent.d.ts.map +1 -0
- package/dist/fields/{ComposeField/ComposeField.js → DescriptionField/DescriptionFieldComponent.js} +5 -5
- package/dist/fields/DescriptionField/DescriptionFieldComponent.js.map +1 -0
- package/dist/fields/LexicalEditor/ActionsFeatureComponent.d.ts +2 -0
- package/dist/fields/LexicalEditor/ActionsFeatureComponent.d.ts.map +1 -0
- package/dist/fields/LexicalEditor/{ComposeFeatureComponent.js → ActionsFeatureComponent.js} +5 -5
- package/dist/fields/LexicalEditor/ActionsFeatureComponent.js.map +1 -0
- package/dist/fields/LexicalEditor/feature.client.d.ts +4 -1
- package/dist/fields/LexicalEditor/feature.client.d.ts.map +1 -1
- package/dist/fields/LexicalEditor/feature.client.js +2 -2
- package/dist/fields/LexicalEditor/feature.client.js.map +1 -1
- package/dist/fields/LexicalEditor/feature.server.d.ts +7 -1
- package/dist/fields/LexicalEditor/feature.server.d.ts.map +1 -1
- package/dist/fields/LexicalEditor/feature.server.js +11 -4
- package/dist/fields/LexicalEditor/feature.server.js.map +1 -1
- package/dist/fields/PromptEditorField/PromptEditorField.d.ts +2 -2
- package/dist/fields/PromptEditorField/PromptEditorField.d.ts.map +1 -1
- package/dist/fields/PromptEditorField/PromptEditorField.js +51 -32
- package/dist/fields/PromptEditorField/PromptEditorField.js.map +1 -1
- package/dist/fields/SelectField/SelectField.d.ts +2 -9
- package/dist/fields/SelectField/SelectField.d.ts.map +1 -1
- package/dist/fields/SelectField/SelectField.js +23 -26
- package/dist/fields/SelectField/SelectField.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +1 -2
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +19 -35
- package/dist/init.js.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +73 -104
- package/dist/plugin.js.map +1 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts +3 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts.map +1 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.js.map +1 -1
- package/dist/providers/InstructionsProvider/hook.d.ts +9 -0
- package/dist/providers/InstructionsProvider/hook.d.ts.map +1 -0
- package/dist/providers/InstructionsProvider/hook.js +17 -0
- package/dist/providers/InstructionsProvider/hook.js.map +1 -0
- package/dist/providers/InstructionsProvider/index.d.ts +5 -0
- package/dist/providers/InstructionsProvider/index.d.ts.map +1 -0
- package/dist/providers/InstructionsProvider/index.js +10 -0
- package/dist/providers/InstructionsProvider/index.js.map +1 -0
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/ui/Actions/Actions.d.ts +5 -0
- package/dist/ui/Actions/Actions.d.ts.map +1 -0
- package/dist/ui/{Compose/Compose.js → Actions/Actions.js} +18 -17
- package/dist/ui/Actions/Actions.js.map +1 -0
- package/dist/ui/{Compose → Actions}/UndoRedoActions.d.ts.map +1 -1
- package/dist/ui/{Compose → Actions}/UndoRedoActions.js +2 -15
- package/dist/ui/Actions/UndoRedoActions.js.map +1 -0
- package/dist/ui/Actions/hooks/highlight.module.scss +3 -0
- package/dist/ui/{Compose → Actions}/hooks/menu/Item.d.ts.map +1 -1
- package/dist/ui/{Compose → Actions}/hooks/menu/Item.js.map +1 -1
- package/dist/ui/Actions/hooks/menu/TranslateMenu.d.ts.map +1 -0
- package/dist/ui/{Compose → Actions}/hooks/menu/TranslateMenu.js.map +1 -1
- package/dist/ui/{Compose → Actions}/hooks/menu/items.d.ts.map +1 -1
- package/dist/ui/{Compose → Actions}/hooks/menu/items.js.map +1 -1
- package/dist/ui/{Compose → Actions}/hooks/menu/itemsMap.d.ts.map +1 -1
- package/dist/ui/{Compose → Actions}/hooks/menu/itemsMap.js.map +1 -1
- package/dist/ui/{Compose → Actions}/hooks/menu/useMenu.d.ts.map +1 -1
- package/dist/ui/{Compose → Actions}/hooks/menu/useMenu.js.map +1 -1
- package/dist/ui/{Compose → Actions}/hooks/useGenerate.d.ts.map +1 -1
- package/dist/ui/{Compose → Actions}/hooks/useGenerate.js +12 -10
- package/dist/ui/Actions/hooks/useGenerate.js.map +1 -0
- package/dist/ui/Actions/hooks/useHistory.d.ts.map +1 -0
- package/dist/ui/{Compose → Actions}/hooks/useHistory.js +1 -3
- package/dist/ui/Actions/hooks/useHistory.js.map +1 -0
- package/dist/ui/Floatype/Floatype.d.ts +21 -0
- package/dist/ui/Floatype/Floatype.d.ts.map +1 -0
- package/dist/ui/Floatype/Floatype.js +245 -0
- package/dist/ui/Floatype/Floatype.js.map +1 -0
- package/dist/ui/Floatype/floatype.module.css +25 -0
- package/dist/utilities/getFieldBySchemaPath.d.ts +2 -2
- package/dist/utilities/getFieldBySchemaPath.d.ts.map +1 -1
- package/dist/utilities/getFieldBySchemaPath.js.map +1 -1
- package/dist/utilities/updateFieldsConfig.d.ts.map +1 -1
- package/dist/utilities/updateFieldsConfig.js +8 -14
- package/dist/utilities/updateFieldsConfig.js.map +1 -1
- package/package.json +50 -72
- package/dist/ai/schemas/lexical.schema.d.ts.map +0 -1
- package/dist/ai/schemas/lexical.schema.js.map +0 -1
- package/dist/exports/client.d.ts +0 -3
- package/dist/exports/client.d.ts.map +0 -1
- package/dist/exports/client.js +0 -4
- package/dist/exports/client.js.map +0 -1
- package/dist/fields/ComposeField/ComposeField.d.ts +0 -4
- package/dist/fields/ComposeField/ComposeField.d.ts.map +0 -1
- package/dist/fields/ComposeField/ComposeField.js.map +0 -1
- package/dist/fields/LexicalEditor/ComposeFeatureComponent.d.ts +0 -2
- package/dist/fields/LexicalEditor/ComposeFeatureComponent.d.ts.map +0 -1
- package/dist/fields/LexicalEditor/ComposeFeatureComponent.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
- package/dist/libraries/handlebars/asyncHandlebars.d.ts +0 -2
- package/dist/libraries/handlebars/asyncHandlebars.d.ts.map +0 -1
- package/dist/libraries/handlebars/asyncHandlebars.js +0 -5
- package/dist/libraries/handlebars/asyncHandlebars.js.map +0 -1
- package/dist/libraries/handlebars/helpers.d.ts +0 -2
- package/dist/libraries/handlebars/helpers.d.ts.map +0 -1
- package/dist/libraries/handlebars/helpers.js +0 -22
- package/dist/libraries/handlebars/helpers.js.map +0 -1
- package/dist/libraries/handlebars/helpersMap.d.ts +0 -12
- package/dist/libraries/handlebars/helpersMap.d.ts.map +0 -1
- package/dist/libraries/handlebars/helpersMap.js +0 -13
- package/dist/libraries/handlebars/helpersMap.js.map +0 -1
- package/dist/libraries/handlebars/replacePlaceholders.d.ts +0 -2
- package/dist/libraries/handlebars/replacePlaceholders.d.ts.map +0 -1
- package/dist/libraries/handlebars/replacePlaceholders.js +0 -8
- package/dist/libraries/handlebars/replacePlaceholders.js.map +0 -1
- package/dist/providers/InstructionsProvider/useInstructions.d.ts +0 -4
- package/dist/providers/InstructionsProvider/useInstructions.d.ts.map +0 -1
- package/dist/providers/InstructionsProvider/useInstructions.js +0 -38
- package/dist/providers/InstructionsProvider/useInstructions.js.map +0 -1
- package/dist/ui/Compose/Compose.d.ts +0 -9
- package/dist/ui/Compose/Compose.d.ts.map +0 -1
- package/dist/ui/Compose/Compose.js.map +0 -1
- package/dist/ui/Compose/UndoRedoActions.js.map +0 -1
- package/dist/ui/Compose/hooks/menu/TranslateMenu.d.ts.map +0 -1
- package/dist/ui/Compose/hooks/useGenerate.js.map +0 -1
- package/dist/ui/Compose/hooks/useHistory.d.ts.map +0 -1
- package/dist/ui/Compose/hooks/useHistory.js.map +0 -1
- package/dist/utilities/getFieldInfo.d.ts +0 -3
- package/dist/utilities/getFieldInfo.d.ts.map +0 -1
- package/dist/utilities/getFieldInfo.js +0 -14
- package/dist/utilities/getFieldInfo.js.map +0 -1
- package/dist/utilities/isPluginActivated.d.ts +0 -2
- package/dist/utilities/isPluginActivated.d.ts.map +0 -1
- package/dist/utilities/isPluginActivated.js +0 -5
- package/dist/utilities/isPluginActivated.js.map +0 -1
- /package/dist/ai/{schemas → editor}/lexical.schema.js +0 -0
- /package/dist/ui/{Compose → Actions}/UndoRedoActions.d.ts +0 -0
- /package/dist/ui/{Compose/compose.module.scss → Actions/actions.module.scss} +0 -0
- /package/dist/ui/{Compose → Actions}/hooks/menu/Item.d.ts +0 -0
- /package/dist/ui/{Compose → Actions}/hooks/menu/Item.js +0 -0
- /package/dist/ui/{Compose → Actions}/hooks/menu/TranslateMenu.d.ts +0 -0
- /package/dist/ui/{Compose → Actions}/hooks/menu/TranslateMenu.js +0 -0
- /package/dist/ui/{Compose → Actions}/hooks/menu/items.d.ts +0 -0
- /package/dist/ui/{Compose → Actions}/hooks/menu/items.js +0 -0
- /package/dist/ui/{Compose → Actions}/hooks/menu/itemsMap.d.ts +0 -0
- /package/dist/ui/{Compose → Actions}/hooks/menu/itemsMap.js +0 -0
- /package/dist/ui/{Compose → Actions}/hooks/menu/menu.module.scss +0 -0
- /package/dist/ui/{Compose → Actions}/hooks/menu/useMenu.d.ts +0 -0
- /package/dist/ui/{Compose → Actions}/hooks/menu/useMenu.js +0 -0
- /package/dist/ui/{Compose → Actions}/hooks/useGenerate.d.ts +0 -0
- /package/dist/ui/{Compose → Actions}/hooks/useHistory.d.ts +0 -0
package/dist/ai/prompts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ai/prompts.ts"],"sourcesContent":["import type { ActionMenuItems } from '../types.js'\n\ntype ActionPromptOptions = {\n layout?: string\n locale?: string\n prompt?: string\n systemPrompt?: string\n}\n\ntype ActionPrompt = {\n layout?: (options?: ActionPromptOptions) => string\n name: ActionMenuItems\n system: (options: ActionPromptOptions) => string\n}\n\n//TODO: This is a temporary solution make use of structured object in API\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 seedPrompts = ({ fieldLabel, fieldSchemaPaths, fieldType, path }) => {\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 }} {{ toLexicalHTML [provide schema-path for richText] }}\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","seedPrompts","fieldLabel","fieldSchemaPaths","fieldType","path","JSON","stringify"],"mappings":"AAeA,yEAAyE;AACzE,OAAO,MAAMA,sBAAsB,CAAC;;;;aAIvB,CAAC,CAAA;AAEd,OAAO,MAAMC,iBAAiC;IAC5C;QACEC,MAAM;QACNC,QAAQ,CAAC,EACPC,SAAS,EAAE,EAC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AEnC,EAAEV,oBAAoB;AACtB,CAAC;IACC;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/ai/prompts.ts"],"sourcesContent":["import type { ActionMenuItems } from '../types.js'\n\ntype ActionPromptOptions = {\n prompt?: string\n systemPrompt?: string\n locale?: string\n layout?: string\n}\n\ntype ActionPrompt = {\n name: ActionMenuItems\n system: (options: ActionPromptOptions) => string\n layout?: (options?: ActionPromptOptions) => string\n}\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 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 layout: () => `\n[heading] - Summary\n[paragraph] - Your summary goes here...\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: ({ prompt = '', systemPrompt = '', locale }) =>\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 seedPrompts = ({ fieldLabel, fieldType, path, fieldSchemaPaths }) => {\n return {\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 a high-quality featured image for '{{ title }}\n\nFor upload:\n field-type: upload\n field-name: Voice\n schema-path: posts.upload\n Generated prompt: {{ title }} {{ toLexicalHTML [provide field-path for richText] }}\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 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 }\n}\n"],"names":["defaultPrompts","name","system","prompt","systemPrompt","layout","locale","seedPrompts","fieldLabel","fieldType","path","fieldSchemaPaths","JSON","stringify"],"mappings":"AAeA,OAAO,MAAMA,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;QACNC,QAAQ,IACN,CAAC;;;;;;;;;AASP,CAAC;QACGG,QAAQ,IAAM,CAAC;;;IAGf,CAAC;IACH;IACA;QACEJ,MAAM;QACNC,QAAQ,IACN,CAAC;;;;;;;mBAOY,CAAC;IAClB;IACA;QACED,MAAM;QACNC,QAAQ,CAAC,EAAEC,SAAS,EAAE,EAAEC,eAAe,EAAE,EAAEE,MAAM,EAAE,GACjD,CAAC,gEAAgE,EAAEA,OAAO;;;;yCAIvC,EAAEA,OAAO;;;IAG9C,EAAEH,SAAS,2BAA2BA,SAAS,GAAG;IAClD,EAAEC,eAAe,kCAAkCA,eAAe,GAAG;iBACxD,CAAC;IAChB;CACD,CAAA;AAED,OAAO,MAAMG,cAAc,CAAC,EAAEC,UAAU,EAAEC,SAAS,EAAEC,IAAI,EAAEC,gBAAgB,EAAE;IAC3E,OAAO;QACLT,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8Fb,EAAEU,KAAKC,SAAS,CAACF,kBAAkB;AACnC,CAAC;QACGR,QAAQ,CAAC,YAAY,EAAEM,UAAU;YACzB,EAAED,WAAW;aACZ,EAAEE,KAAK;;;;;AAKpB,CAAC;IACC;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ai/utils/generateFileNameByPrompt.ts"],"sourcesContent":["export function generateFileNameByPrompt(prompt) {\n // Helper function to get a random integer between min and max (inclusive)\n function getRandomInt(min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min\n }\n\n // Define the desired length of the filename part from the prompt\n const maxLength = 30\n const promptLength = prompt.length\n\n // Determine the start position for the random substring\n const startPos = getRandomInt(0, Math.max(0, promptLength - maxLength))\n\n // Get the random substring and truncate it if necessary\n let randomSubstring = prompt.substring(startPos, startPos + maxLength)\n\n // Replace invalid filename characters with an underscore\n randomSubstring = randomSubstring.replace(/[^a-z\\d]/gi, '_').toLowerCase()\n\n // Add a timestamp for uniqueness\n const timestamp = new Date().toISOString().replace(/[:.-]/g, '')\n\n // Combine the truncated prompt and timestamp to form the filename\n return `${randomSubstring}_${timestamp}`\n}\n"],"names":["generateFileNameByPrompt","prompt","getRandomInt","min","max","Math","floor","random","maxLength","promptLength","length","startPos","randomSubstring","substring","replace","toLowerCase","timestamp","Date","toISOString"],"mappings":"AAAA,OAAO,SAASA,yBAAyBC,MAAM;IAC7C,0EAA0E;IAC1E,SAASC,aAAaC,GAAG,EAAEC,GAAG;QAC5B,OAAOC,KAAKC,KAAK,CAACD,KAAKE,MAAM,KAAMH,CAAAA,MAAMD,MAAM,CAAA,KAAMA;IACvD;IAEA,iEAAiE;IACjE,MAAMK,YAAY;IAClB,MAAMC,eAAeR,OAAOS,MAAM;IAElC,wDAAwD;IACxD,MAAMC,WAAWT,aAAa,GAAGG,KAAKD,GAAG,CAAC,GAAGK,eAAeD;IAE5D,wDAAwD;IACxD,IAAII,kBAAkBX,OAAOY,SAAS,CAACF,UAAUA,WAAWH;IAE5D,yDAAyD;IACzDI,kBAAkBA,gBAAgBE,OAAO,CAAC,cAAc,KAAKC,WAAW;IAExE,iCAAiC;IACjC,MAAMC,YAAY,IAAIC,OAAOC,WAAW,GAAGJ,OAAO,CAAC,UAAU;IAE7D,kEAAkE;IAClE,OAAO,
|
|
1
|
+
{"version":3,"sources":["../../../src/ai/utils/generateFileNameByPrompt.ts"],"sourcesContent":["export function generateFileNameByPrompt(prompt) {\n // Helper function to get a random integer between min and max (inclusive)\n function getRandomInt(min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min\n }\n\n // Define the desired length of the filename part from the prompt\n const maxLength = 30\n const promptLength = prompt.length\n\n // Determine the start position for the random substring\n const startPos = getRandomInt(0, Math.max(0, promptLength - maxLength))\n\n // Get the random substring and truncate it if necessary\n let randomSubstring = prompt.substring(startPos, startPos + maxLength)\n\n // Replace invalid filename characters with an underscore\n randomSubstring = randomSubstring.replace(/[^a-z\\d]/gi, '_').toLowerCase()\n\n // Add a timestamp for uniqueness\n const timestamp = new Date().toISOString().replace(/[:.-]/g, '')\n\n // Combine the truncated prompt and timestamp to form the filename\n return `${randomSubstring}_${timestamp}`\n}\n"],"names":["generateFileNameByPrompt","prompt","getRandomInt","min","max","Math","floor","random","maxLength","promptLength","length","startPos","randomSubstring","substring","replace","toLowerCase","timestamp","Date","toISOString"],"mappings":"AAAA,OAAO,SAASA,yBAAyBC,MAAM;IAC7C,0EAA0E;IAC1E,SAASC,aAAaC,GAAG,EAAEC,GAAG;QAC5B,OAAOC,KAAKC,KAAK,CAACD,KAAKE,MAAM,KAAMH,CAAAA,MAAMD,MAAM,CAAA,KAAMA;IACvD;IAEA,iEAAiE;IACjE,MAAMK,YAAY;IAClB,MAAMC,eAAeR,OAAOS,MAAM;IAElC,wDAAwD;IACxD,MAAMC,WAAWT,aAAa,GAAGG,KAAKD,GAAG,CAAC,GAAGK,eAAeD;IAE5D,wDAAwD;IACxD,IAAII,kBAAkBX,OAAOY,SAAS,CAACF,UAAUA,WAAWH;IAE5D,yDAAyD;IACzDI,kBAAkBA,gBAAgBE,OAAO,CAAC,cAAc,KAAKC,WAAW;IAExE,iCAAiC;IACjC,MAAMC,YAAY,IAAIC,OAAOC,WAAW,GAAGJ,OAAO,CAAC,UAAU;IAE7D,kEAAkE;IAClE,OAAO,CAAC,EAAEF,gBAAgB,CAAC,EAAEI,UAAU,CAAC;AAC1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateSeedPrompt.d.ts","sourceRoot":"","sources":["../../../src/ai/utils/generateSeedPrompt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateSeedPrompt.d.ts","sourceRoot":"","sources":["../../../src/ai/utils/generateSeedPrompt.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,SAAgB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,oBAUhF,CAAA"}
|
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
import { anthropic } from '@ai-sdk/anthropic';
|
|
2
|
-
import { openai } from '@ai-sdk/openai';
|
|
3
1
|
import { generateText } from 'ai';
|
|
4
|
-
import {
|
|
2
|
+
import { openai } from '@ai-sdk/openai';
|
|
3
|
+
import { PLUGIN_DEFAULT_MODEL_NAME } from '../../defaults.js';
|
|
5
4
|
export const generateSeedPrompt = async (data)=>{
|
|
6
5
|
const { prompt, system } = data;
|
|
7
|
-
let model = null;
|
|
8
|
-
if (process.env.OPENAI_API_KEY) {
|
|
9
|
-
model = openai(PLUGIN_DEFAULT_OPENAI_MODEL);
|
|
10
|
-
} else if (process.env.ANTHROPIC_API_KEY) {
|
|
11
|
-
model = anthropic(PLUGIN_DEFAULT_ANTHROPIC_MODEL);
|
|
12
|
-
} else {
|
|
13
|
-
throw new Error('- AI Plugin: Please check your environment variables!');
|
|
14
|
-
}
|
|
15
6
|
const { text } = await generateText({
|
|
16
|
-
model,
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
model: openai(PLUGIN_DEFAULT_MODEL_NAME),
|
|
8
|
+
system,
|
|
9
|
+
prompt
|
|
19
10
|
});
|
|
20
11
|
return text;
|
|
21
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ai/utils/generateSeedPrompt.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/ai/utils/generateSeedPrompt.ts"],"sourcesContent":["import { generateText } from 'ai'\nimport { openai } from '@ai-sdk/openai'\nimport { PLUGIN_DEFAULT_MODEL_NAME } from '../../defaults.js'\n\nexport const generateSeedPrompt = async (data: { prompt: string; system: string }) => {\n const { prompt, system } = data\n\n const { text } = await generateText({\n model: openai(PLUGIN_DEFAULT_MODEL_NAME),\n system,\n prompt,\n })\n\n return text\n}\n"],"names":["generateText","openai","PLUGIN_DEFAULT_MODEL_NAME","generateSeedPrompt","data","prompt","system","text","model"],"mappings":"AAAA,SAASA,YAAY,QAAQ,KAAI;AACjC,SAASC,MAAM,QAAQ,iBAAgB;AACvC,SAASC,yBAAyB,QAAQ,oBAAmB;AAE7D,OAAO,MAAMC,qBAAqB,OAAOC;IACvC,MAAM,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAGF;IAE3B,MAAM,EAAEG,IAAI,EAAE,GAAG,MAAMP,aAAa;QAClCQ,OAAOP,OAAOC;QACdI;QACAD;IACF;IAEA,OAAOE;AACT,EAAC"}
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"Instructions.d.ts","sourceRoot":"","sources":["../../src/collections/Instructions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,SAAS,CAAA;AAsB3D,eAAO,MAAM,YAAY,EAAE,gBA6F1B,CAAA"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { GenerationModels } from '../ai/models/index.js';
|
|
2
2
|
import { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js';
|
|
3
|
+
import { PromptEditorField } from '../fields/PromptEditorField/PromptEditorField.js';
|
|
4
|
+
import { SelectField } from '../fields/SelectField/SelectField.js';
|
|
3
5
|
const groupSettings = GenerationModels.reduce((fields, model)=>{
|
|
4
6
|
if (model.settings) {
|
|
5
7
|
fields.push(model.settings);
|
|
@@ -29,6 +31,7 @@ export const Instructions = {
|
|
|
29
31
|
name: 'schema-path',
|
|
30
32
|
type: 'text',
|
|
31
33
|
admin: {
|
|
34
|
+
hidden: true,
|
|
32
35
|
readOnly: true
|
|
33
36
|
},
|
|
34
37
|
unique: true
|
|
@@ -37,6 +40,7 @@ export const Instructions = {
|
|
|
37
40
|
name: 'field-type',
|
|
38
41
|
type: 'select',
|
|
39
42
|
admin: {
|
|
43
|
+
hidden: true,
|
|
40
44
|
readOnly: true
|
|
41
45
|
},
|
|
42
46
|
defaultValue: 'text',
|
|
@@ -65,13 +69,11 @@ export const Instructions = {
|
|
|
65
69
|
type: 'select',
|
|
66
70
|
admin: {
|
|
67
71
|
components: {
|
|
68
|
-
Field:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
path: '@ai-stack/payloadcms/fields#SelectField'
|
|
74
|
-
}
|
|
72
|
+
Field: SelectField
|
|
73
|
+
},
|
|
74
|
+
custom: {
|
|
75
|
+
filterByField: 'field-type',
|
|
76
|
+
options: modelOptions
|
|
75
77
|
}
|
|
76
78
|
},
|
|
77
79
|
label: 'Model',
|
|
@@ -80,14 +82,15 @@ export const Instructions = {
|
|
|
80
82
|
label: option.label,
|
|
81
83
|
value: option.value
|
|
82
84
|
};
|
|
83
|
-
})
|
|
85
|
+
}),
|
|
86
|
+
validate: ()=>true
|
|
84
87
|
},
|
|
85
88
|
{
|
|
86
89
|
name: 'prompt',
|
|
87
90
|
type: 'textarea',
|
|
88
91
|
admin: {
|
|
89
92
|
components: {
|
|
90
|
-
Field:
|
|
93
|
+
Field: PromptEditorField
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
},
|
|
@@ -96,7 +99,7 @@ export const Instructions = {
|
|
|
96
99
|
hooks: {
|
|
97
100
|
beforeChange: [
|
|
98
101
|
(req)=>{
|
|
99
|
-
if (req.data['openai-gpt-object-settings']
|
|
102
|
+
if (req.data['openai-gpt-object-settings'].layout?.length === 0) {
|
|
100
103
|
// TODO: why??
|
|
101
104
|
req.data['openai-gpt-object-settings'].layout = '';
|
|
102
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/Instructions.ts"],"sourcesContent":["import type { CollectionConfig, GroupField } from 'payload'\n\nimport { GenerationModels } from '../ai/models/index.js'\nimport { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\n\nconst groupSettings = GenerationModels.reduce((fields, model) => {\n if (model.settings) {\n fields.push(model.settings)\n }\n return fields\n}, [] as GroupField[])\n\nconst modelOptions = GenerationModels.map((model) => {\n return {\n fields: model.fields,\n label: model.name,\n value: model.id,\n }\n})\n\nexport const Instructions: CollectionConfig = {\n slug: PLUGIN_INSTRUCTIONS_TABLE,\n\n // TODO: Revisit permissions, better if end user can provide this\n access: {\n create: () => true,\n read: () => true,\n update: () => true,\n },\n admin: {\n hidden: true,\n },\n fields: [\n {\n name: 'schema-path',\n type: 'text',\n admin: {\n readOnly: true,\n },\n unique: true,\n },\n {\n name: 'field-type',\n type: 'select',\n admin: {\n readOnly: true,\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: 'model-id',\n type: 'select',\n admin: {\n components: {\n Field:
|
|
1
|
+
{"version":3,"sources":["../../src/collections/Instructions.ts"],"sourcesContent":["import type { CollectionConfig, GroupField } from 'payload'\n\nimport { GenerationModels } from '../ai/models/index.js'\nimport { PLUGIN_INSTRUCTIONS_TABLE } from '../defaults.js'\nimport { PromptEditorField } from '../fields/PromptEditorField/PromptEditorField.js'\nimport { SelectField } from '../fields/SelectField/SelectField.js'\n\nconst groupSettings = GenerationModels.reduce((fields, model) => {\n if (model.settings) {\n fields.push(model.settings)\n }\n return fields\n}, [] as GroupField[])\n\nconst modelOptions = GenerationModels.map((model) => {\n return {\n fields: model.fields,\n label: model.name,\n value: model.id,\n }\n})\n\nexport const Instructions: CollectionConfig = {\n slug: PLUGIN_INSTRUCTIONS_TABLE,\n\n // TODO: Revisit permissions, better if end user can provide this\n access: {\n create: () => true,\n read: () => true,\n update: () => true,\n },\n admin: {\n hidden: true,\n },\n fields: [\n {\n name: 'schema-path',\n type: 'text',\n admin: {\n hidden: true,\n readOnly: true,\n },\n unique: true,\n },\n {\n name: 'field-type',\n type: 'select',\n admin: {\n hidden: true,\n readOnly: true,\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: 'model-id',\n type: 'select',\n admin: {\n components: {\n Field: SelectField,\n },\n custom: {\n filterByField: 'field-type',\n options: modelOptions,\n },\n },\n label: 'Model',\n options: modelOptions.map((option) => {\n return {\n label: option.label,\n value: option.value,\n }\n }),\n validate: () => true,\n },\n {\n name: 'prompt',\n type: 'textarea',\n admin: {\n components: {\n Field: PromptEditorField,\n },\n },\n },\n ...groupSettings,\n ],\n hooks: {\n beforeChange: [\n (req) => {\n if (req.data['openai-gpt-object-settings'].layout?.length === 0) {\n // TODO: why??\n req.data['openai-gpt-object-settings'].layout = ''\n }\n return req.data\n },\n ],\n },\n}\n"],"names":["GenerationModels","PLUGIN_INSTRUCTIONS_TABLE","PromptEditorField","SelectField","groupSettings","reduce","fields","model","settings","push","modelOptions","map","label","name","value","id","Instructions","slug","access","create","read","update","admin","hidden","type","readOnly","unique","defaultValue","options","components","Field","custom","filterByField","option","validate","hooks","beforeChange","req","data","layout","length"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,yBAAyB,QAAQ,iBAAgB;AAC1D,SAASC,iBAAiB,QAAQ,mDAAkD;AACpF,SAASC,WAAW,QAAQ,uCAAsC;AAElE,MAAMC,gBAAgBJ,iBAAiBK,MAAM,CAAC,CAACC,QAAQC;IACrD,IAAIA,MAAMC,QAAQ,EAAE;QAClBF,OAAOG,IAAI,CAACF,MAAMC,QAAQ;IAC5B;IACA,OAAOF;AACT,GAAG,EAAE;AAE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,IAAI,CAAC,6BAA6B,CAACC,MAAM,GAAG;gBAClD;gBACA,OAAOF,IAAIC,IAAI;YACjB;SACD;IACH;AACF,EAAC"}
|
package/dist/defaults.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export declare const PLUGIN_NAME = "plugin-ai";
|
|
2
2
|
export declare const PLUGIN_INSTRUCTIONS_TABLE = "plugin-ai-instructions";
|
|
3
|
-
export declare const PLUGIN_INSTRUCTIONS_MAP_GLOBAL = "plugin-ai-instructions-map";
|
|
3
|
+
export declare const PLUGIN_INSTRUCTIONS_MAP_GLOBAL = "plugin-ai-plugin-ai-instructions-map";
|
|
4
4
|
export declare const PLUGIN_LEXICAL_EDITOR_FEATURE = "plugin-ai-actions-feature";
|
|
5
5
|
export declare const PLUGIN_API_ENDPOINT_BASE = "/plugin-ai";
|
|
6
6
|
export declare const PLUGIN_API_ENDPOINT_GENERATE = "/plugin-ai/generate";
|
|
7
7
|
export declare const PLUGIN_API_ENDPOINT_GENERATE_UPLOAD = "/plugin-ai/generate/upload";
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const PLUGIN_DEFAULT_ANTHROPIC_MODEL = "claude-3-sonnet-20240229";
|
|
8
|
+
export declare const PLUGIN_DEFAULT_MODEL_NAME = "gpt-4o-mini";
|
|
10
9
|
//# sourceMappingURL=defaults.d.ts.map
|
package/dist/defaults.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,cAAc,CAAA;AACtC,eAAO,MAAM,yBAAyB,2BAAgC,CAAA;AACtE,eAAO,MAAM,8BAA8B
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,cAAc,CAAA;AACtC,eAAO,MAAM,yBAAyB,2BAAgC,CAAA;AACtE,eAAO,MAAM,8BAA8B,yCAAoD,CAAA;AAC/F,eAAO,MAAM,6BAA6B,8BAAmC,CAAA;AAG7E,eAAO,MAAM,wBAAwB,eAAoB,CAAA;AACzD,eAAO,MAAM,4BAA4B,wBAAyC,CAAA;AAClF,eAAO,MAAM,mCAAmC,+BAA2C,CAAA;AAG3F,eAAO,MAAM,yBAAyB,gBAAgB,CAAA"}
|
package/dist/defaults.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
export const PLUGIN_NAME = 'plugin-ai';
|
|
2
2
|
export const PLUGIN_INSTRUCTIONS_TABLE = `${PLUGIN_NAME}-instructions`;
|
|
3
|
-
export const PLUGIN_INSTRUCTIONS_MAP_GLOBAL = `${PLUGIN_INSTRUCTIONS_TABLE}-map`;
|
|
3
|
+
export const PLUGIN_INSTRUCTIONS_MAP_GLOBAL = `${PLUGIN_NAME}-${PLUGIN_INSTRUCTIONS_TABLE}-map`;
|
|
4
4
|
export const PLUGIN_LEXICAL_EDITOR_FEATURE = `${PLUGIN_NAME}-actions-feature`;
|
|
5
5
|
// Endpoint defaults
|
|
6
6
|
export const PLUGIN_API_ENDPOINT_BASE = `/${PLUGIN_NAME}`;
|
|
7
7
|
export const PLUGIN_API_ENDPOINT_GENERATE = `${PLUGIN_API_ENDPOINT_BASE}/generate`;
|
|
8
8
|
export const PLUGIN_API_ENDPOINT_GENERATE_UPLOAD = `${PLUGIN_API_ENDPOINT_GENERATE}/upload`;
|
|
9
9
|
// LLM Settings
|
|
10
|
-
export const
|
|
11
|
-
export const PLUGIN_DEFAULT_ANTHROPIC_MODEL = `claude-3-sonnet-20240229`;
|
|
10
|
+
export const PLUGIN_DEFAULT_MODEL_NAME = `gpt-4o-mini`;
|
|
12
11
|
|
|
13
12
|
//# 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_INSTRUCTIONS_MAP_GLOBAL = `${PLUGIN_INSTRUCTIONS_TABLE}-map`\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`\n\n// LLM Settings\nexport const
|
|
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_INSTRUCTIONS_MAP_GLOBAL = `${PLUGIN_NAME}-${PLUGIN_INSTRUCTIONS_TABLE}-map`\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`\n\n// LLM Settings\nexport const PLUGIN_DEFAULT_MODEL_NAME = `gpt-4o-mini`\n"],"names":["PLUGIN_NAME","PLUGIN_INSTRUCTIONS_TABLE","PLUGIN_INSTRUCTIONS_MAP_GLOBAL","PLUGIN_LEXICAL_EDITOR_FEATURE","PLUGIN_API_ENDPOINT_BASE","PLUGIN_API_ENDPOINT_GENERATE","PLUGIN_API_ENDPOINT_GENERATE_UPLOAD","PLUGIN_DEFAULT_MODEL_NAME"],"mappings":"AAAA,OAAO,MAAMA,cAAc,YAAW;AACtC,OAAO,MAAMC,4BAA4B,CAAC,EAAED,YAAY,aAAa,CAAC,CAAA;AACtE,OAAO,MAAME,iCAAiC,CAAC,EAAEF,YAAY,CAAC,EAAEC,0BAA0B,IAAI,CAAC,CAAA;AAC/F,OAAO,MAAME,gCAAgC,CAAC,EAAEH,YAAY,gBAAgB,CAAC,CAAA;AAE7E,oBAAoB;AACpB,OAAO,MAAMI,2BAA2B,CAAC,CAAC,EAAEJ,YAAY,CAAC,CAAA;AACzD,OAAO,MAAMK,+BAA+B,CAAC,EAAED,yBAAyB,SAAS,CAAC,CAAA;AAClF,OAAO,MAAME,sCAAsC,CAAC,EAAED,6BAA6B,OAAO,CAAC,CAAA;AAE3F,eAAe;AACf,OAAO,MAAME,4BAA4B,CAAC,WAAW,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":"AAMA,OAAO,EAAmB,SAAS,EAAE,MAAM,aAAa,CAAA;AAiHxD,eAAO,MAAM,SAAS,EAAE,SAwIvB,CAAA"}
|
package/dist/endpoints/index.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Handlebars from 'handlebars';
|
|
2
|
+
import asyncHelpers from 'handlebars-async-helpers';
|
|
2
3
|
import { GenerationModels } from '../ai/models/index.js';
|
|
3
4
|
import { defaultPrompts } from '../ai/prompts.js';
|
|
4
5
|
import { PLUGIN_API_ENDPOINT_GENERATE, PLUGIN_API_ENDPOINT_GENERATE_UPLOAD, PLUGIN_INSTRUCTIONS_TABLE, PLUGIN_NAME } from '../defaults.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
const
|
|
6
|
+
import { getFieldBySchemaPath } from '../utilities/getFieldBySchemaPath.js';
|
|
7
|
+
import { lexicalToHTML } from '../utilities/lexicalToHTML.js';
|
|
8
|
+
import { lexicalSchema } from '../ai/editor/lexical.schema.js';
|
|
9
|
+
const asyncHandlebars = asyncHelpers(Handlebars);
|
|
10
|
+
const replacePlaceholders = (prompt, values)=>{
|
|
11
|
+
return asyncHandlebars.compile(prompt, {
|
|
12
|
+
trackIds: true
|
|
13
|
+
})(values);
|
|
14
|
+
};
|
|
15
|
+
const assignPrompt = async (action, { type, actionParams, context, field, systemPrompt = '', template, layout })=>{
|
|
9
16
|
const prompt = await replacePlaceholders(template, context);
|
|
10
|
-
const toLexicalHTML = type === 'richText' ?
|
|
17
|
+
const toLexicalHTML = type === 'richText' ? 'toLexicalHTML' : '';
|
|
11
18
|
const assignedPrompts = {
|
|
12
|
-
layout,
|
|
13
19
|
prompt,
|
|
14
|
-
system: systemPrompt
|
|
20
|
+
system: systemPrompt,
|
|
21
|
+
layout
|
|
15
22
|
};
|
|
16
23
|
if (action === 'Compose') {
|
|
17
24
|
return assignedPrompts;
|
|
18
25
|
}
|
|
19
|
-
const {
|
|
26
|
+
const { system: getSystemPrompt, layout: getLayout } = defaultPrompts.find((p)=>p.name === action);
|
|
20
27
|
let updatedLayout = layout;
|
|
21
28
|
if (getLayout) {
|
|
22
29
|
updatedLayout = getLayout();
|
|
@@ -27,12 +34,38 @@ const assignPrompt = async (action, { type, actionParams, context, field, layout
|
|
|
27
34
|
systemPrompt
|
|
28
35
|
});
|
|
29
36
|
return {
|
|
30
|
-
layout: updatedLayout,
|
|
31
|
-
// TODO: revisit this toLexicalHTML
|
|
32
37
|
prompt: await replacePlaceholders(`{{${toLexicalHTML} ${field}}}`, context),
|
|
33
|
-
system
|
|
38
|
+
system,
|
|
39
|
+
layout: updatedLayout
|
|
34
40
|
};
|
|
35
41
|
};
|
|
42
|
+
const registerEditorHelper = (payload, schemaPath)=>{
|
|
43
|
+
//TODO: add autocomplete ability using handlebars template on PromptEditorField and include custom helpers in dropdown
|
|
44
|
+
let fieldInfo = getFieldInfo(payload.collections, schemaPath);
|
|
45
|
+
const schemaPathChunks = schemaPath.split('.');
|
|
46
|
+
asyncHandlebars.registerHelper('toLexicalHTML', async function(content, options) {
|
|
47
|
+
const collectionSlug = schemaPathChunks[0];
|
|
48
|
+
const { ids } = options;
|
|
49
|
+
for (const id of ids){
|
|
50
|
+
//TODO: Find a better way to get schemaPath of defined field in prompt editor
|
|
51
|
+
const path = `${collectionSlug}.${id}`;
|
|
52
|
+
fieldInfo = getFieldInfo(payload.collections, path);
|
|
53
|
+
}
|
|
54
|
+
const html = await lexicalToHTML(content, fieldInfo.editor?.editorConfig);
|
|
55
|
+
return new asyncHandlebars.SafeString(html);
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
const getFieldInfo = (collections, schemaPath)=>{
|
|
59
|
+
let fieldInfo = null;
|
|
60
|
+
//TODO: Only run below for enabled collections
|
|
61
|
+
for(const collectionsKey in collections){
|
|
62
|
+
const collection = collections[collectionsKey];
|
|
63
|
+
fieldInfo = getFieldBySchemaPath(collection.config, schemaPath);
|
|
64
|
+
if (fieldInfo) {
|
|
65
|
+
return fieldInfo;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
36
69
|
export const endpoints = {
|
|
37
70
|
textarea: {
|
|
38
71
|
handler: async (req)=>{
|
|
@@ -43,7 +76,7 @@ export const endpoints = {
|
|
|
43
76
|
if (!instructionId) {
|
|
44
77
|
throw new Error(`Instruction ID is required for "${PLUGIN_NAME}" to work, please check your configuration`);
|
|
45
78
|
}
|
|
46
|
-
|
|
79
|
+
let instructions = await req.payload.findByID({
|
|
47
80
|
id: instructionId,
|
|
48
81
|
collection: PLUGIN_INSTRUCTIONS_TABLE
|
|
49
82
|
});
|
|
@@ -72,17 +105,17 @@ export const endpoints = {
|
|
|
72
105
|
actionParams,
|
|
73
106
|
context: contextData,
|
|
74
107
|
field: fieldName,
|
|
75
|
-
layout: modelOptions.layout,
|
|
76
108
|
systemPrompt: modelOptions.system,
|
|
77
|
-
template: promptTemplate
|
|
109
|
+
template: promptTemplate,
|
|
110
|
+
layout: modelOptions.layout
|
|
78
111
|
});
|
|
79
112
|
console.log('Running handler with prompts:', prompts);
|
|
80
113
|
return model.handler?.(prompts.prompt, {
|
|
81
114
|
...modelOptions,
|
|
82
115
|
...opt,
|
|
116
|
+
system: prompts.system,
|
|
83
117
|
editorSchema,
|
|
84
|
-
layout: prompts.layout
|
|
85
|
-
system: prompts.system
|
|
118
|
+
layout: prompts.layout
|
|
86
119
|
}).catch((error)=>{
|
|
87
120
|
console.error('Error: endpoint - generating text:', error);
|
|
88
121
|
return new Response(JSON.stringify(error.message), {
|
|
@@ -126,6 +159,7 @@ export const endpoints = {
|
|
|
126
159
|
data: result.data,
|
|
127
160
|
file: result.file
|
|
128
161
|
});
|
|
162
|
+
console.log('assetData', assetData);
|
|
129
163
|
return new Response(JSON.stringify({
|
|
130
164
|
result: {
|
|
131
165
|
id: assetData.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/index.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport type { ActionMenuItems, Endpoints } from '../types.js'\n\nimport { lexicalSchema } from '../ai/schemas/lexical.schema.js'\nimport { GenerationModels } from '../ai/models/index.js'\nimport { defaultPrompts } from '../ai/prompts.js'\nimport {\n PLUGIN_API_ENDPOINT_GENERATE,\n PLUGIN_API_ENDPOINT_GENERATE_UPLOAD,\n PLUGIN_INSTRUCTIONS_TABLE,\n PLUGIN_NAME,\n} from '../defaults.js'\nimport { registerEditorHelper } from '../libraries/handlebars/helpers.js'\nimport { handlebarsHelpersMap } from '../libraries/handlebars/helpersMap.js'\nimport { replacePlaceholders } from '../libraries/handlebars/replacePlaceholders.js'\n\nconst assignPrompt = async (\n action: ActionMenuItems,\n {\n type,\n actionParams,\n context,\n field,\n layout,\n systemPrompt = '',\n template,\n }: {\n actionParams: Record<any, any>\n context: object\n field: string\n layout: string\n systemPrompt: string\n template: string\n type: string\n },\n) => {\n const prompt = await replacePlaceholders(template, context)\n const toLexicalHTML = type === 'richText' ? handlebarsHelpersMap.toHTML.name : ''\n const assignedPrompts = {\n layout,\n prompt,\n system: systemPrompt,\n }\n\n if (action === 'Compose') {\n return assignedPrompts\n }\n\n const { layout: getLayout, system: getSystemPrompt } = defaultPrompts.find(\n (p) => p.name === action,\n )\n\n let updatedLayout = layout\n if (getLayout) {\n updatedLayout = getLayout()\n }\n\n const system = getSystemPrompt({\n ...(actionParams || {}),\n prompt,\n systemPrompt,\n })\n\n return {\n layout: updatedLayout,\n // TODO: revisit this toLexicalHTML\n prompt: await replacePlaceholders(`{{${toLexicalHTML} ${field}}}`, context),\n system,\n }\n}\n\nexport const endpoints: Endpoints = {\n textarea: {\n handler: async (req: PayloadRequest) => {\n const data = await req.json?.()\n\n const { locale = 'en', options } = data\n const { action, actionParams, instructionId } = options\n const contextData = data.doc\n\n if (!instructionId) {\n throw new Error(\n `Instruction ID is required for \"${PLUGIN_NAME}\" to work, please check your configuration`,\n )\n }\n\n const instructions = await req.payload.findByID({\n id: instructionId,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n })\n\n const { collections } = req.payload.config\n const collection = collections.find(\n (collection) => collection.slug === PLUGIN_INSTRUCTIONS_TABLE,\n )\n\n const { editorConfig: { schema: editorSchema = lexicalSchema() } = {} } =\n collection.custom || {}\n\n const { prompt: promptTemplate = '' } = instructions\n\n const schemaPath = instructions['schema-path'] as string\n const fieldName = schemaPath?.split('.').pop()\n\n registerEditorHelper(req.payload, schemaPath)\n\n const { defaultLocale, locales = [] } = req.payload.config.localization || {}\n const localeData = locales.find((l) => {\n return l.code === locale\n })\n\n const localeInfo = localeData?.label[defaultLocale] || locale\n\n //TODO: remove this\n const opt = {\n locale: localeInfo,\n modelId: instructions['model-id'],\n }\n\n const model = GenerationModels.find((model) => model.id === opt.modelId)\n const settingsName = model.settings?.name\n const modelOptions = instructions[settingsName] as {\n layout: string\n system: string\n }\n\n const prompts = await assignPrompt(action, {\n type: instructions['field-type'] as string,\n actionParams,\n context: contextData,\n field: fieldName,\n layout: modelOptions.layout,\n systemPrompt: modelOptions.system,\n template: promptTemplate as string,\n })\n\n console.log('Running handler with prompts:', prompts)\n return model\n .handler?.(prompts.prompt, {\n ...modelOptions,\n ...opt,\n editorSchema,\n layout: prompts.layout,\n system: prompts.system,\n })\n .catch((error) => {\n console.error('Error: endpoint - generating text:', error)\n return new Response(JSON.stringify(error.message), { status: 500 })\n })\n },\n method: 'post',\n path: PLUGIN_API_ENDPOINT_GENERATE,\n },\n upload: {\n handler: async (req: PayloadRequest) => {\n const data = await req.json?.()\n\n const { options } = data\n const { instructionId, uploadCollectionSlug } = options\n const contextData = data.doc\n\n let instructions = { 'model-id': '', prompt: '' }\n\n if (instructionId) {\n // @ts-expect-error\n instructions = await req.payload.findByID({\n id: instructionId,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n })\n }\n\n const { prompt: promptTemplate = '' } = instructions\n const schemaPath = instructions['schema-path']\n\n registerEditorHelper(req.payload, schemaPath)\n\n const text = await replacePlaceholders(promptTemplate, contextData)\n const modelId = instructions['model-id']\n console.log('prompt text:', text)\n\n const model = GenerationModels.find((model) => model.id === modelId)\n const settingsName = model.settings?.name\n const modelOptions = instructions[settingsName] || {}\n console.log('modelOptions', modelOptions)\n\n const result = await model.handler?.(text, modelOptions)\n\n const assetData = await req.payload.create({\n collection: uploadCollectionSlug,\n data: result.data,\n file: result.file,\n })\n\n return new Response(\n JSON.stringify({\n result: {\n id: assetData.id,\n alt: assetData.alt,\n },\n }),\n )\n },\n method: 'post',\n path: PLUGIN_API_ENDPOINT_GENERATE_UPLOAD,\n },\n}\n"],"names":["lexicalSchema","GenerationModels","defaultPrompts","PLUGIN_API_ENDPOINT_GENERATE","PLUGIN_API_ENDPOINT_GENERATE_UPLOAD","PLUGIN_INSTRUCTIONS_TABLE","PLUGIN_NAME","registerEditorHelper","handlebarsHelpersMap","replacePlaceholders","assignPrompt","action","type","actionParams","context","field","layout","systemPrompt","template","prompt","toLexicalHTML","toHTML","name","assignedPrompts","system","getLayout","getSystemPrompt","find","p","updatedLayout","endpoints","textarea","handler","req","data","json","locale","options","instructionId","contextData","doc","Error","instructions","payload","findByID","id","collection","collections","config","slug","editorConfig","schema","editorSchema","custom","promptTemplate","schemaPath","fieldName","split","pop","defaultLocale","locales","localization","localeData","l","code","localeInfo","label","opt","modelId","model","settingsName","settings","modelOptions","prompts","console","log","catch","error","Response","JSON","stringify","message","status","method","path","upload","uploadCollectionSlug","text","result","assetData","create","file","alt"],"mappings":"AAIA,SAASA,aAAa,QAAQ,kCAAiC;AAC/D,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SACEC,4BAA4B,EAC5BC,mCAAmC,EACnCC,yBAAyB,EACzBC,WAAW,QACN,iBAAgB;AACvB,SAASC,oBAAoB,QAAQ,qCAAoC;AACzE,SAASC,oBAAoB,QAAQ,wCAAuC;AAC5E,SAASC,mBAAmB,QAAQ,iDAAgD;AAEpF,MAAMC,eAAe,OACnBC,QACA,EACEC,IAAI,EACJC,YAAY,EACZC,OAAO,EACPC,KAAK,EACLC,MAAM,EACNC,eAAe,EAAE,EACjBC,QAAQ,EAST;IAED,MAAMC,SAAS,MAAMV,oBAAoBS,UAAUJ;IACnD,MAAMM,gBAAgBR,SAAS,aAAaJ,qBAAqBa,MAAM,CAACC,IAAI,GAAG;IAC/E,MAAMC,kBAAkB;QACtBP;QACAG;QACAK,QAAQP;IACV;IAEA,IAAIN,WAAW,WAAW;QACxB,OAAOY;IACT;IAEA,MAAM,EAAEP,QAAQS,SAAS,EAAED,QAAQE,eAAe,EAAE,GAAGxB,eAAeyB,IAAI,CACxE,CAACC,IAAMA,EAAEN,IAAI,KAAKX;IAGpB,IAAIkB,gBAAgBb;IACpB,IAAIS,WAAW;QACbI,gBAAgBJ;IAClB;IAEA,MAAMD,SAASE,gBAAgB;Q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Y;gBAAIvB,QAAQ;YAAG;YAEhD,IAAImB,eAAe;gBACjB,mBAAmB;gBACnBI,eAAe,MAAMT,IAAIU,OAAO,CAACC,QAAQ,CAAC;oBACxCC,IAAIP;oBACJQ,YAAYzC;gBACd;YACF;YAEA,MAAM,EAAEc,QAAQmC,iBAAiB,EAAE,EAAE,GAAGZ;YACxC,MAAMa,aAAab,YAAY,CAAC,cAAc;YAE9CnC,qBAAqB0B,IAAIU,OAAO,EAAEY;YAElC,MAAMgC,OAAO,MAAM9E,oBAAoB6C,gBAAgBf;YACvD,MAAM6B,UAAU1B,YAAY,CAAC,WAAW;YACxCgC,QAAQC,GAAG,CAAC,gBAAgBY;YAE5B,MAAMlB,QAAQpE,iBAAiB0B,IAAI,CAAC,CAAC0C,QAAUA,MAAMxB,EAAE,KAAKuB;YAC5D,MAAME,eAAeD,MAAME,QAAQ,EAAEjD;YACrC,MAAMkD,eAAe9B,YAAY,CAAC4B,aAAa,IAAI,CAAC;YACpDI,QAAQC,GAAG,CAAC,gBAAgBH;YAE5B,MAAMgB,SAAS,MAAMnB,MAAMrC,OAAO,GAAGuD,MAAMf;YAE3C,MAAMiB,YAAY,MAAMxD,IAAIU,OAAO,CAAC+C,MAAM,CAAC;gBACzC5C,YAAYwC;gBACZpD,MAAMsD,OAAOtD,IAAI;gBACjByD,MAAMH,OAAOG,IAAI;YACnB;YAEA,OAAO,IAAIb,SACTC,KAAKC,SAAS,CAAC;gBACbQ,QAAQ;oBACN3C,IAAI4C,UAAU5C,EAAE;oBAChB+C,KAAKH,UAAUG,GAAG;gBACpB;YACF;QAEJ;QACAT,QAAQ;QACRC,MAAMhF;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/index.ts"],"sourcesContent":["import type { SerializedEditorState } from 'lexical'\nimport type { BasePayload, PayloadRequest } from 'payload'\n\nimport Handlebars from 'handlebars'\nimport asyncHelpers from 'handlebars-async-helpers'\n\nimport { ActionMenuItems, Endpoints } from '../types.js'\n\nimport { GenerationModels } from '../ai/models/index.js'\nimport { defaultPrompts } from '../ai/prompts.js'\nimport {\n PLUGIN_API_ENDPOINT_GENERATE,\n PLUGIN_API_ENDPOINT_GENERATE_UPLOAD,\n PLUGIN_INSTRUCTIONS_TABLE,\n PLUGIN_NAME,\n} from '../defaults.js'\nimport { getFieldBySchemaPath } from '../utilities/getFieldBySchemaPath.js'\nimport { lexicalToHTML } from '../utilities/lexicalToHTML.js'\nimport { lexicalSchema } from '../ai/editor/lexical.schema.js'\nimport { generateText } from 'ai'\nimport { openai } from '@ai-sdk/openai'\n\nconst asyncHandlebars = asyncHelpers(Handlebars)\n\nconst replacePlaceholders = (prompt: string, values: object) => {\n return asyncHandlebars.compile(prompt, { trackIds: true })(values)\n}\n\nconst assignPrompt = async (\n action: ActionMenuItems,\n {\n type,\n actionParams,\n context,\n field,\n systemPrompt = '',\n template,\n layout,\n }: {\n actionParams: Record<any, any>\n context: object\n field: string\n systemPrompt: string\n template: string\n type: string\n layout: string\n },\n) => {\n const prompt = await replacePlaceholders(template, context)\n\n const toLexicalHTML = type === 'richText' ? 'toLexicalHTML' : ''\n\n const assignedPrompts = {\n prompt,\n system: systemPrompt,\n layout,\n }\n\n if (action === 'Compose') {\n return assignedPrompts\n }\n\n const { system: getSystemPrompt, layout: getLayout } = defaultPrompts.find(\n (p) => p.name === action,\n )\n\n let updatedLayout = layout\n if (getLayout) {\n updatedLayout = getLayout()\n }\n\n const system = getSystemPrompt({\n ...(actionParams || {}),\n prompt,\n systemPrompt,\n })\n\n return {\n prompt: await replacePlaceholders(`{{${toLexicalHTML} ${field}}}`, context),\n system,\n layout: updatedLayout,\n }\n}\n\nconst registerEditorHelper = (payload, schemaPath) => {\n //TODO: add autocomplete ability using handlebars template on PromptEditorField and include custom helpers in dropdown\n\n let fieldInfo = getFieldInfo(payload.collections, schemaPath)\n const schemaPathChunks = schemaPath.split('.')\n\n asyncHandlebars.registerHelper(\n 'toLexicalHTML',\n async function (content: SerializedEditorState, options) {\n const collectionSlug = schemaPathChunks[0]\n const { ids } = options\n for (const id of ids) {\n //TODO: Find a better way to get schemaPath of defined field in prompt editor\n const path = `${collectionSlug}.${id}`\n fieldInfo = getFieldInfo(payload.collections, path)\n }\n\n const html = await lexicalToHTML(content, fieldInfo.editor?.editorConfig)\n return new asyncHandlebars.SafeString(html)\n },\n )\n}\n\nconst getFieldInfo = (collections: BasePayload['collections'], schemaPath: string) => {\n let fieldInfo = null\n //TODO: Only run below for enabled collections\n for (const collectionsKey in collections) {\n const collection = collections[collectionsKey]\n fieldInfo = getFieldBySchemaPath(collection.config, schemaPath)\n if (fieldInfo) {\n return fieldInfo\n }\n }\n}\n\nexport const endpoints: Endpoints = {\n textarea: {\n handler: async (req: PayloadRequest) => {\n const data = await req.json?.()\n\n const { locale = 'en', options } = data\n const { action, actionParams, instructionId } = options\n const contextData = data.doc\n\n if (!instructionId) {\n throw new Error(\n `Instruction ID is required for \"${PLUGIN_NAME}\" to work, please check your configuration`,\n )\n }\n\n let instructions = await req.payload.findByID({\n id: instructionId,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n })\n\n const { collections } = req.payload.config\n const collection = collections.find(\n (collection) => collection.slug === PLUGIN_INSTRUCTIONS_TABLE,\n )\n\n const { editorConfig: { schema: editorSchema = lexicalSchema() } = {} } =\n collection.custom || {}\n\n const { prompt: promptTemplate = '' } = instructions\n\n const schemaPath = instructions['schema-path'] as string\n const fieldName = schemaPath?.split('.').pop()\n\n registerEditorHelper(req.payload, schemaPath)\n\n const { defaultLocale, locales = [] } = req.payload.config.localization || {}\n const localeData = locales.find((l) => {\n return l.code === locale\n })\n\n const localeInfo = localeData?.label[defaultLocale] || locale\n\n //TODO: remove this\n const opt = {\n locale: localeInfo,\n modelId: instructions['model-id'],\n }\n\n const model = GenerationModels.find((model) => model.id === opt.modelId)\n const settingsName = model.settings?.name\n const modelOptions = instructions[settingsName] as {\n system: string\n layout: string\n }\n\n const prompts = await assignPrompt(action, {\n type: instructions['field-type'] as string,\n actionParams,\n context: contextData,\n field: fieldName,\n systemPrompt: modelOptions.system,\n template: promptTemplate as string,\n layout: modelOptions.layout,\n })\n\n console.log('Running handler with prompts:', prompts)\n return model\n .handler?.(prompts.prompt, {\n ...modelOptions,\n ...opt,\n system: prompts.system,\n editorSchema,\n layout: prompts.layout,\n })\n .catch((error) => {\n console.error('Error: endpoint - generating text:', error)\n return new Response(JSON.stringify(error.message), { status: 500 })\n })\n },\n method: 'post',\n path: PLUGIN_API_ENDPOINT_GENERATE,\n },\n upload: {\n handler: async (req: PayloadRequest) => {\n const data = await req.json?.()\n\n const { options } = data\n const { instructionId, uploadCollectionSlug } = options\n const contextData = data.doc\n\n let instructions = { 'model-id': '', prompt: '' }\n\n if (instructionId) {\n // @ts-expect-error\n instructions = await req.payload.findByID({\n id: instructionId,\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n })\n }\n\n const { prompt: promptTemplate = '' } = instructions\n const schemaPath = instructions['schema-path']\n\n registerEditorHelper(req.payload, schemaPath)\n\n const text = await replacePlaceholders(promptTemplate, contextData)\n const modelId = instructions['model-id']\n console.log('prompt text:', text)\n\n const model = GenerationModels.find((model) => model.id === modelId)\n const settingsName = model.settings?.name\n const modelOptions = instructions[settingsName] || {}\n console.log('modelOptions', modelOptions)\n\n const result = await model.handler?.(text, modelOptions)\n\n const assetData = await req.payload.create({\n collection: uploadCollectionSlug,\n data: result.data,\n file: result.file,\n })\n\n console.log('assetData', assetData)\n\n return new Response(\n JSON.stringify({\n result: {\n id: assetData.id,\n alt: assetData.alt,\n },\n }),\n )\n },\n method: 'post',\n path: PLUGIN_API_ENDPOINT_GENERATE_UPLOAD,\n },\n}\n"],"names":["Handlebars","asyncHelpers","GenerationModels","defaultPrompts","PLUGIN_API_ENDPOINT_GENERATE","PLUGIN_API_ENDPOINT_GENERATE_UPLOAD","PLUGIN_INSTRUCTIONS_TABLE","PLUGIN_NAME","getFieldBySchemaPath","lexicalToHTML","lexicalSchema","asyncHandlebars","replacePlaceholders","prompt","values","compile","trackIds","assignPrompt","action","type","actionParams","context","field","systemPrompt","template","layout","toLexicalHTML","assignedPrompts","system","getSystemPrompt","getLayout","find","p","name","updatedLayout","registerEditorHelper","payload","schemaPath","fieldInfo","getFieldInfo","collections","schemaPathChunks","split","registerHelper","content","options","collectionSlug","ids","id","path","html","editor","editorConfig","SafeString","collectionsKey","collection","config","endpoints","textarea","handler","req","data","json","locale","instructionId","contextData","doc","Error","instructions","findByID","slug","schema","editorSchema","custom","promptTemplate","fieldName","pop","defaultLocale","locales","localization","localeData","l","code","localeInfo","label","opt","modelId","model","settingsName","settings","modelOptions","prompts","console","log","catch","error","Response","JSON","stringify","message","status","method","upload","uploadCollectionSlug","text","result","assetData","create","file","alt"],"mappings":"AAGA,OAAOA,gBAAgB,aAAY;AACnC,OAAOC,kBAAkB,2BAA0B;AAInD,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SACEC,4BAA4B,EAC5BC,mCAAmC,EACnCC,yBAAyB,EACzBC,WAAW,QACN,iBAAgB;AACvB,SAASC,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,aAAa,QAAQ,gCAA+B;AAC7D,SAASC,aAAa,QAAQ,iCAAgC;AAI9D,MAAMC,kBAAkBV,aAAaD;AAErC,MAAMY,sBAAsB,CAACC,QAAgBC;IAC3C,OAAOH,gBAAgBI,OAAO,CAACF,QAAQ;QAAEG,UAAU;IAAK,GAAGF;AAC7D;AAEA,MAAMG,eAAe,OACnBC,QACA,EACEC,IAAI,EACJC,YAAY,EACZC,OAAO,EACPC,KAAK,EACLC,eAAe,EAAE,EACjBC,QAAQ,EACRC,MAAM,EASP;IAED,MAAMZ,SAAS,MAAMD,oBAAoBY,UAAUH;IAEnD,MAAMK,gBAAgBP,SAAS,aAAa,kBAAkB;IAE9D,MAAMQ,kBAAkB;QACtBd;QACAe,QAAQL;QACRE;IACF;IAEA,IAAIP,WAAW,WAAW;QACxB,OAAO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M,EAAEO,QAAQ6D,iBAAiB,EAAE,EAAE,GAAGN;YACxC,MAAM/B,aAAa+B,YAAY,CAAC,cAAc;YAE9CjC,qBAAqByB,IAAIxB,OAAO,EAAEC;YAElC,MAAMmE,OAAO,MAAM5F,oBAAoB8D,gBAAgBT;YACvD,MAAMqB,UAAUlB,YAAY,CAAC,WAAW;YACxCwB,QAAQC,GAAG,CAAC,gBAAgBW;YAE5B,MAAMjB,QAAQrF,iBAAiB6B,IAAI,CAAC,CAACwD,QAAUA,MAAMvC,EAAE,KAAKsC;YAC5D,MAAME,eAAeD,MAAME,QAAQ,EAAExD;YACrC,MAAMyD,eAAetB,YAAY,CAACoB,aAAa,IAAI,CAAC;YACpDI,QAAQC,GAAG,CAAC,gBAAgBH;YAE5B,MAAMe,SAAS,MAAMlB,MAAM5B,OAAO,GAAG6C,MAAMd;YAE3C,MAAMgB,YAAY,MAAM9C,IAAIxB,OAAO,CAACuE,MAAM,CAAC;gBACzCpD,YAAYgD;gBACZ1C,MAAM4C,OAAO5C,IAAI;gBACjB+C,MAAMH,OAAOG,IAAI;YACnB;YAEAhB,QAAQC,GAAG,CAAC,aAAaa;YAEzB,OAAO,IAAIV,SACTC,KAAKC,SAAS,CAAC;gBACbO,QAAQ;oBACNzD,IAAI0D,UAAU1D,EAAE;oBAChB6D,KAAKH,UAAUG,GAAG;gBACpB;YACF;QAEJ;QACAR,QAAQ;QACRpD,MAAM5C;IACR;AACF,EAAC"}
|
package/dist/exports/fields.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { SelectField } from '../fields/SelectField/SelectField.js';
|
|
3
|
-
export { ComposeField } from '../fields/ComposeField/ComposeField.js';
|
|
1
|
+
export {};
|
|
4
2
|
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../src/exports/fields.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../src/exports/fields.ts"],"names":[],"mappings":""}
|
package/dist/exports/fields.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/fields.ts"],"
|
|
1
|
+
{"version":3,"sources":["../../src/exports/fields.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DescriptionField.d.ts","sourceRoot":"","sources":["../../../src/fields/DescriptionField/DescriptionField.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAG9C,eAAO,MAAM,gBAAgB,EAAE,oBAW9B,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { withMergedProps } from '@payloadcms/ui/shared';
|
|
2
|
+
import { DescriptionFieldComponent } from './DescriptionFieldComponent.js';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
export const DescriptionField = (options)=>{
|
|
5
|
+
const mergedPropsFunc = withMergedProps({
|
|
6
|
+
Component: DescriptionFieldComponent,
|
|
7
|
+
sanitizeServerOnlyProps: true,
|
|
8
|
+
toMergeIntoProps: options
|
|
9
|
+
});
|
|
10
|
+
// TODO: Might use this in order to add field entry for Instructions on plugin Init
|
|
11
|
+
mergedPropsFunc.displayName = 'DescriptionField';
|
|
12
|
+
return mergedPropsFunc;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=DescriptionField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/DescriptionField/DescriptionField.tsx"],"sourcesContent":["import { withMergedProps } from '@payloadcms/ui/shared'\n\nimport { DescriptionFieldComponent } from './DescriptionFieldComponent.js'\nimport { DescriptionComponent } from 'payload'\n\n// @ts-ignore\nexport const DescriptionField: DescriptionComponent = (options: any) => {\n const mergedPropsFunc = withMergedProps({\n Component: DescriptionFieldComponent,\n sanitizeServerOnlyProps: true,\n toMergeIntoProps: options,\n })\n\n // TODO: Might use this in order to add field entry for Instructions on plugin Init\n mergedPropsFunc.displayName = 'DescriptionField'\n\n return mergedPropsFunc\n}\n"],"names":["withMergedProps","DescriptionFieldComponent","DescriptionField","options","mergedPropsFunc","Component","sanitizeServerOnlyProps","toMergeIntoProps","displayName"],"mappings":"AAAA,SAASA,eAAe,QAAQ,wBAAuB;AAEvD,SAASC,yBAAyB,QAAQ,iCAAgC;AAG1E,aAAa;AACb,OAAO,MAAMC,mBAAyC,CAACC;IACrD,MAAMC,kBAAkBJ,gBAAgB;QACtCK,WAAWJ;QACXK,yBAAyB;QACzBC,kBAAkBJ;IACpB;IAEA,mFAAmF;IACnFC,gBAAgBI,WAAW,GAAG;IAE9B,OAAOJ;AACT,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DescriptionFieldComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/DescriptionField/DescriptionFieldComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAGpD,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAOrE,CAAA"}
|
package/dist/fields/{ComposeField/ComposeField.js → DescriptionField/DescriptionFieldComponent.js}
RENAMED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useFieldProps } from '@payloadcms/ui';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import { useInstructions } from '../../providers/InstructionsProvider/
|
|
6
|
-
import {
|
|
7
|
-
export const
|
|
5
|
+
import { useInstructions } from '../../providers/InstructionsProvider/hook.js';
|
|
6
|
+
import { Actions } from '../../ui/Actions/Actions.js';
|
|
7
|
+
export const DescriptionFieldComponent = (props)=>{
|
|
8
8
|
const { schemaPath } = useFieldProps();
|
|
9
9
|
const { id: instructionId } = useInstructions({
|
|
10
10
|
path: schemaPath
|
|
11
11
|
});
|
|
12
|
-
return /*#__PURE__*/ _jsx(
|
|
12
|
+
return /*#__PURE__*/ _jsx(Actions, {
|
|
13
13
|
descriptionProps: props,
|
|
14
14
|
instructionId: instructionId
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
//# sourceMappingURL=
|
|
18
|
+
//# sourceMappingURL=DescriptionFieldComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/DescriptionField/DescriptionFieldComponent.tsx"],"sourcesContent":["'use client'\n\nimport type { FieldDescriptionProps } from 'payload'\n\nimport { useFieldProps } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { useInstructions } from '../../providers/InstructionsProvider/hook.js'\nimport { Actions } from '../../ui/Actions/Actions.js'\n\nexport const DescriptionFieldComponent: React.FC<FieldDescriptionProps> = (props) => {\n const { schemaPath } = useFieldProps()\n const { id: instructionId } = useInstructions({\n path: schemaPath,\n })\n\n return <Actions descriptionProps={props} instructionId={instructionId} />\n}\n"],"names":["useFieldProps","React","useInstructions","Actions","DescriptionFieldComponent","props","schemaPath","id","instructionId","path","descriptionProps"],"mappings":"AAAA;;AAIA,SAASA,aAAa,QAAQ,iBAAgB;AAC9C,OAAOC,WAAW,QAAO;AAEzB,SAASC,eAAe,QAAQ,+CAA8C;AAC9E,SAASC,OAAO,QAAQ,8BAA6B;AAErD,OAAO,MAAMC,4BAA6D,CAACC;IACzE,MAAM,EAAEC,UAAU,EAAE,GAAGN;IACvB,MAAM,EAAEO,IAAIC,aAAa,EAAE,GAAGN,gBAAgB;QAC5CO,MAAMH;IACR;IAEA,qBAAO,KAACH;QAAQO,kBAAkBL;QAAOG,eAAeA;;AAC1D,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActionsFeatureComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/LexicalEditor/ActionsFeatureComponent.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,uBAAuB,+CAQnC,CAAA"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useFieldProps } from '@payloadcms/ui';
|
|
3
|
-
import { useInstructions } from '../../providers/InstructionsProvider/
|
|
4
|
-
import {
|
|
5
|
-
export const
|
|
3
|
+
import { useInstructions } from '../../providers/InstructionsProvider/hook.js';
|
|
4
|
+
import { Actions } from '../../ui/Actions/Actions.js';
|
|
5
|
+
export const ActionsFeatureComponent = ()=>{
|
|
6
6
|
const { schemaPath } = useFieldProps();
|
|
7
7
|
const { id: instructionId } = useInstructions({
|
|
8
8
|
path: schemaPath
|
|
9
9
|
});
|
|
10
|
-
return /*#__PURE__*/ _jsx(
|
|
10
|
+
return /*#__PURE__*/ _jsx(Actions, {
|
|
11
11
|
instructionId: instructionId
|
|
12
12
|
});
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
//# sourceMappingURL=
|
|
15
|
+
//# sourceMappingURL=ActionsFeatureComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/LexicalEditor/ActionsFeatureComponent.tsx"],"sourcesContent":["import { useFieldProps } from '@payloadcms/ui'\n\nimport { useInstructions } from '../../providers/InstructionsProvider/hook.js'\nimport { Actions } from '../../ui/Actions/Actions.js'\n\nexport const ActionsFeatureComponent = () => {\n const { schemaPath } = useFieldProps()\n\n const { id: instructionId } = useInstructions({\n path: schemaPath,\n })\n\n return <Actions instructionId={instructionId} />\n}\n"],"names":["useFieldProps","useInstructions","Actions","ActionsFeatureComponent","schemaPath","id","instructionId","path"],"mappings":";AAAA,SAASA,aAAa,QAAQ,iBAAgB;AAE9C,SAASC,eAAe,QAAQ,+CAA8C;AAC9E,SAASC,OAAO,QAAQ,8BAA6B;AAErD,OAAO,MAAMC,0BAA0B;IACrC,MAAM,EAAEC,UAAU,EAAE,GAAGJ;IAEvB,MAAM,EAAEK,IAAIC,aAAa,EAAE,GAAGL,gBAAgB;QAC5CM,MAAMH;IACR;IAEA,qBAAO,KAACF;QAAQI,eAAeA;;AACjC,EAAC"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export declare const LexicalEditorFeatureClient: import("
|
|
1
|
+
export declare const LexicalEditorFeatureClient: import("react").FC<{
|
|
2
|
+
featureKey: string;
|
|
3
|
+
order: number;
|
|
4
|
+
}>;
|
|
2
5
|
//# sourceMappingURL=feature.client.d.ts.map
|