@ai-stack/payloadcms 3.0.0-beta.65.2 → 3.0.0-beta.95.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/models/anthropic/index.d.ts.map +1 -1
- package/dist/ai/models/anthropic/index.js +3 -3
- 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 +1 -11
- package/dist/ai/models/elevenLabs/index.js.map +1 -1
- package/dist/ai/models/index.js +2 -2
- package/dist/ai/models/index.js.map +1 -1
- package/dist/ai/models/openai/index.d.ts.map +1 -1
- package/dist/ai/models/openai/index.js +3 -2
- package/dist/ai/models/openai/index.js.map +1 -1
- package/dist/ai/prompts.d.ts +1 -0
- package/dist/ai/prompts.d.ts.map +1 -1
- package/dist/ai/prompts.js +5 -2
- package/dist/ai/prompts.js.map +1 -1
- package/dist/ai/{editor → schemas}/lexical.schema.d.ts +2 -2
- package/dist/ai/schemas/lexical.schema.d.ts.map +1 -0
- package/dist/ai/schemas/lexical.schema.js.map +1 -0
- package/dist/collections/Instructions.d.ts.map +1 -1
- package/dist/collections/Instructions.js +9 -12
- package/dist/collections/Instructions.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 +17 -50
- package/dist/endpoints/index.js.map +1 -1
- package/dist/exports/client.d.ts +4 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +5 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/fields.d.ts +2 -1
- package/dist/exports/fields.d.ts.map +1 -1
- package/dist/exports/fields.js +2 -0
- package/dist/exports/fields.js.map +1 -1
- package/dist/fields/DescriptionField/DescriptionField.d.ts +1 -2
- package/dist/fields/DescriptionField/DescriptionField.d.ts.map +1 -1
- package/dist/fields/DescriptionField/DescriptionField.js +2 -1
- package/dist/fields/DescriptionField/DescriptionField.js.map +1 -1
- package/dist/fields/DescriptionField/DescriptionFieldComponent.d.ts +1 -2
- package/dist/fields/DescriptionField/DescriptionFieldComponent.d.ts.map +1 -1
- package/dist/fields/DescriptionField/DescriptionFieldComponent.js +2 -1
- package/dist/fields/DescriptionField/DescriptionFieldComponent.js.map +1 -1
- package/dist/fields/LexicalEditor/ActionsFeatureComponent.js +1 -1
- package/dist/fields/LexicalEditor/ActionsFeatureComponent.js.map +1 -1
- package/dist/fields/LexicalEditor/feature.server.d.ts +1 -7
- package/dist/fields/LexicalEditor/feature.server.d.ts.map +1 -1
- package/dist/fields/LexicalEditor/feature.server.js +3 -11
- package/dist/fields/LexicalEditor/feature.server.js.map +1 -1
- package/dist/fields/PromptEditorField/PromptEditorField.d.ts +1 -1
- package/dist/fields/PromptEditorField/PromptEditorField.d.ts.map +1 -1
- package/dist/fields/PromptEditorField/PromptEditorField.js +32 -51
- package/dist/fields/PromptEditorField/PromptEditorField.js.map +1 -1
- package/dist/fields/SelectField/SelectField.d.ts +9 -2
- package/dist/fields/SelectField/SelectField.d.ts.map +1 -1
- package/dist/fields/SelectField/SelectField.js +26 -23
- 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.map +1 -1
- package/dist/init.js +14 -2
- package/dist/init.js.map +1 -1
- package/dist/libraries/autocomplete/AutocompleteTextArea.d.ts +8 -0
- package/dist/libraries/autocomplete/AutocompleteTextArea.d.ts.map +1 -0
- package/dist/libraries/autocomplete/AutocompleteTextArea.js +435 -0
- package/dist/libraries/autocomplete/AutocompleteTextArea.js.map +1 -0
- package/dist/libraries/autocomplete/AutocompleteTextArea.module.scss +35 -0
- package/dist/libraries/handlebars/asyncHandlebars.d.ts +2 -0
- package/dist/libraries/handlebars/asyncHandlebars.d.ts.map +1 -0
- package/dist/libraries/handlebars/asyncHandlebars.js +5 -0
- package/dist/libraries/handlebars/asyncHandlebars.js.map +1 -0
- package/dist/libraries/handlebars/helpers.d.ts +2 -0
- package/dist/libraries/handlebars/helpers.d.ts.map +1 -0
- package/dist/libraries/handlebars/helpers.js +22 -0
- package/dist/libraries/handlebars/helpers.js.map +1 -0
- package/dist/libraries/handlebars/helpersMap.d.ts +12 -0
- package/dist/libraries/handlebars/helpersMap.d.ts.map +1 -0
- package/dist/libraries/handlebars/helpersMap.js +13 -0
- package/dist/libraries/handlebars/helpersMap.js.map +1 -0
- package/dist/libraries/handlebars/replacePlaceholders.d.ts +2 -0
- package/dist/libraries/handlebars/replacePlaceholders.d.ts.map +1 -0
- package/dist/libraries/handlebars/replacePlaceholders.js +8 -0
- package/dist/libraries/handlebars/replacePlaceholders.js.map +1 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +6 -3
- package/dist/plugin.js.map +1 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts +1 -3
- package/dist/providers/InstructionsProvider/InstructionsProvider.d.ts.map +1 -1
- package/dist/providers/InstructionsProvider/InstructionsProvider.js.map +1 -1
- package/dist/providers/InstructionsProvider/useInstructions.d.ts +4 -0
- package/dist/providers/InstructionsProvider/useInstructions.d.ts.map +1 -0
- package/dist/providers/InstructionsProvider/useInstructions.js +34 -0
- package/dist/providers/InstructionsProvider/useInstructions.js.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/ui/Actions/Actions.js +32 -39
- package/dist/ui/Actions/Actions.js.map +1 -1
- package/dist/ui/Actions/hooks/useGenerate.d.ts.map +1 -1
- package/dist/ui/Actions/hooks/useGenerate.js +4 -4
- package/dist/ui/Actions/hooks/useGenerate.js.map +1 -1
- 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/getFieldInfo.d.ts +3 -0
- package/dist/utilities/getFieldInfo.d.ts.map +1 -0
- package/dist/utilities/getFieldInfo.js +14 -0
- package/dist/utilities/getFieldInfo.js.map +1 -0
- package/dist/utilities/updateFieldsConfig.d.ts.map +1 -1
- package/dist/utilities/updateFieldsConfig.js +1 -5
- package/dist/utilities/updateFieldsConfig.js.map +1 -1
- package/package.json +59 -38
- package/dist/ai/editor/lexical.schema.d.ts.map +0 -1
- package/dist/ai/editor/lexical.schema.js.map +0 -1
- package/dist/ai/models/style.d.ts +0 -2
- package/dist/ai/models/style.d.ts.map +0 -1
- package/dist/ai/models/style.js +0 -31
- package/dist/ai/models/style.js.map +0 -1
- package/dist/providers/InstructionsProvider/hook.d.ts +0 -9
- package/dist/providers/InstructionsProvider/hook.d.ts.map +0 -1
- package/dist/providers/InstructionsProvider/hook.js +0 -17
- package/dist/providers/InstructionsProvider/hook.js.map +0 -1
- package/dist/providers/InstructionsProvider/index.d.ts +0 -5
- package/dist/providers/InstructionsProvider/index.d.ts.map +0 -1
- package/dist/providers/InstructionsProvider/index.js +0 -10
- package/dist/providers/InstructionsProvider/index.js.map +0 -1
- package/dist/ui/Floatype/Floatype.d.ts +0 -21
- package/dist/ui/Floatype/Floatype.d.ts.map +0 -1
- package/dist/ui/Floatype/Floatype.js +0 -245
- package/dist/ui/Floatype/Floatype.js.map +0 -1
- package/dist/ui/Floatype/floatype.module.css +0 -25
- /package/dist/ai/{editor → schemas}/lexical.schema.js +0 -0
|
@@ -1 +1 @@
|
|
|
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,OAAOS;IACT;IAEA,MAAM,EAAEC,QAAQC,eAAe,EAAEJ,QAAQK,SAAS,EAAE,GAAG3B,eAAe4B,IAAI,CACxE,CAACC,IA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B,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"}
|
|
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 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":["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,EAA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IACR;AACF,EAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DescriptionFieldComponent } from '../fields/DescriptionField/DescriptionFieldComponent.js';
|
|
2
|
+
export { LexicalEditorFeatureClient } from '../fields/LexicalEditor/feature.client.js';
|
|
3
|
+
export { InstructionsProvider } from '../providers/InstructionsProvider/InstructionsProvider.js';
|
|
4
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,yDAAyD,CAAA;AACnG,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAA;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2DAA2D,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { DescriptionFieldComponent } from '../fields/DescriptionField/DescriptionFieldComponent.js';
|
|
2
|
+
export { LexicalEditorFeatureClient } from '../fields/LexicalEditor/feature.client.js';
|
|
3
|
+
export { InstructionsProvider } from '../providers/InstructionsProvider/InstructionsProvider.js';
|
|
4
|
+
|
|
5
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { DescriptionFieldComponent } from '../fields/DescriptionField/DescriptionFieldComponent.js'\nexport { LexicalEditorFeatureClient } from '../fields/LexicalEditor/feature.client.js'\nexport { InstructionsProvider } from '../providers/InstructionsProvider/InstructionsProvider.js'\n"],"names":["DescriptionFieldComponent","LexicalEditorFeatureClient","InstructionsProvider"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,0DAAyD;AACnG,SAASC,0BAA0B,QAAQ,4CAA2C;AACtF,SAASC,oBAAoB,QAAQ,4DAA2D"}
|
package/dist/exports/fields.d.ts
CHANGED
|
@@ -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":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kDAAkD,CAAA;AACpF,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAA"}
|
package/dist/exports/fields.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/fields.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":["../../src/exports/fields.ts"],"sourcesContent":["export { PromptEditorField } from '../fields/PromptEditorField/PromptEditorField.js'\nexport { SelectField } from '../fields/SelectField/SelectField.js'\n"],"names":["PromptEditorField","SelectField"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,mDAAkD;AACpF,SAASC,WAAW,QAAQ,uCAAsC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DescriptionField.d.ts","sourceRoot":"","sources":["../../../src/fields/DescriptionField/DescriptionField.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DescriptionField.d.ts","sourceRoot":"","sources":["../../../src/fields/DescriptionField/DescriptionField.tsx"],"names":[],"mappings":"AAOA,eAAO,MAAM,gBAAgB,YAAa,GAAG,2BAW5C,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { withMergedProps } from '@payloadcms/ui/shared';
|
|
2
2
|
import { DescriptionFieldComponent } from './DescriptionFieldComponent.js';
|
|
3
|
-
//
|
|
3
|
+
// import { DescriptionComponent } from 'payload'
|
|
4
|
+
//DescriptionField: DescriptionComponent
|
|
4
5
|
export const DescriptionField = (options)=>{
|
|
5
6
|
const mergedPropsFunc = withMergedProps({
|
|
6
7
|
Component: DescriptionFieldComponent,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/DescriptionField/DescriptionField.tsx"],"sourcesContent":["import { withMergedProps } from '@payloadcms/ui/shared'\n\nimport { DescriptionFieldComponent } from './DescriptionFieldComponent.js'\
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/DescriptionField/DescriptionField.tsx"],"sourcesContent":["import { withMergedProps } from '@payloadcms/ui/shared'\n\nimport { DescriptionFieldComponent } from './DescriptionFieldComponent.js'\n// import { DescriptionComponent } from 'payload'\n\n//DescriptionField: DescriptionComponent\n\nexport const DescriptionField = (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;AAC1E,iDAAiD;AAEjD,wCAAwC;AAExC,OAAO,MAAMC,mBAAmB,CAACC;IAC/B,MAAMC,kBAAkBJ,gBAAgB;QACtCK,WAAWJ;QACXK,yBAAyB;QACzBC,kBAAkBJ;IACpB;IAEA,mFAAmF;IACnFC,gBAAgBI,WAAW,GAAG;IAE9B,OAAOJ;AACT,EAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { FieldDescriptionProps } from 'payload';
|
|
2
1
|
import React from 'react';
|
|
3
|
-
export declare const DescriptionFieldComponent: React.FC
|
|
2
|
+
export declare const DescriptionFieldComponent: React.FC;
|
|
4
3
|
//# sourceMappingURL=DescriptionFieldComponent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DescriptionFieldComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/DescriptionField/DescriptionFieldComponent.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DescriptionFieldComponent.d.ts","sourceRoot":"","sources":["../../../src/fields/DescriptionField/DescriptionFieldComponent.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,EAO7C,CAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// import type { FieldDescriptionProps } from 'payload'
|
|
3
4
|
import { useFieldProps } from '@payloadcms/ui';
|
|
4
5
|
import React from 'react';
|
|
5
|
-
import { useInstructions } from '../../providers/InstructionsProvider/
|
|
6
|
+
import { useInstructions } from '../../providers/InstructionsProvider/useInstructions.js';
|
|
6
7
|
import { Actions } from '../../ui/Actions/Actions.js';
|
|
7
8
|
export const DescriptionFieldComponent = (props)=>{
|
|
8
9
|
const { schemaPath } = useFieldProps();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/DescriptionField/DescriptionFieldComponent.tsx"],"sourcesContent":["'use client'\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/DescriptionField/DescriptionFieldComponent.tsx"],"sourcesContent":["'use client'\n\n// import type { FieldDescriptionProps } from 'payload'\n\nimport { useFieldProps } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { useInstructions } from '../../providers/InstructionsProvider/useInstructions.js'\nimport { Actions } from '../../ui/Actions/Actions.js'\n\nexport const DescriptionFieldComponent: React.FC = (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;;AAEA,uDAAuD;AAEvD,SAASA,aAAa,QAAQ,iBAAgB;AAC9C,OAAOC,WAAW,QAAO;AAEzB,SAASC,eAAe,QAAQ,0DAAyD;AACzF,SAASC,OAAO,QAAQ,8BAA6B;AAErD,OAAO,MAAMC,4BAAsC,CAACC;IAClD,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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useFieldProps } from '@payloadcms/ui';
|
|
3
|
-
import { useInstructions } from '../../providers/InstructionsProvider/
|
|
3
|
+
import { useInstructions } from '../../providers/InstructionsProvider/useInstructions.js';
|
|
4
4
|
import { Actions } from '../../ui/Actions/Actions.js';
|
|
5
5
|
export const ActionsFeatureComponent = ()=>{
|
|
6
6
|
const { schemaPath } = useFieldProps();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/LexicalEditor/ActionsFeatureComponent.tsx"],"sourcesContent":["import { useFieldProps } from '@payloadcms/ui'\n\nimport { useInstructions } from '../../providers/InstructionsProvider/
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/LexicalEditor/ActionsFeatureComponent.tsx"],"sourcesContent":["import { useFieldProps } from '@payloadcms/ui'\n\nimport { useInstructions } from '../../providers/InstructionsProvider/useInstructions.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,0DAAyD;AACzF,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,8 +1,2 @@
|
|
|
1
|
-
export declare const PayloadAiPluginLexicalEditorFeature: import("@payloadcms/richtext-lexical").FeatureProviderProviderServer<undefined,
|
|
2
|
-
applyToFocusedEditor: any;
|
|
3
|
-
disableIfParentHasFixedToolbar: any;
|
|
4
|
-
}, {
|
|
5
|
-
applyToFocusedEditor: any;
|
|
6
|
-
disableIfParentHasFixedToolbar: any;
|
|
7
|
-
}>;
|
|
1
|
+
export declare const PayloadAiPluginLexicalEditorFeature: import("@payloadcms/richtext-lexical").FeatureProviderProviderServer<undefined, undefined, undefined>;
|
|
8
2
|
//# sourceMappingURL=feature.server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../src/fields/LexicalEditor/feature.server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../src/fields/LexicalEditor/feature.server.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,mCAAmC,uGAK9C,CAAA"}
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { createServerFeature } from '@payloadcms/richtext-lexical';
|
|
2
2
|
import { PLUGIN_LEXICAL_EDITOR_FEATURE } from '../../defaults.js';
|
|
3
3
|
import { isPluginActivated } from '../../utilities/isPluginActivated.js';
|
|
4
|
-
|
|
4
|
+
const isActivated = isPluginActivated();
|
|
5
5
|
export const PayloadAiPluginLexicalEditorFeature = createServerFeature({
|
|
6
|
-
feature:
|
|
7
|
-
|
|
8
|
-
applyToFocusedEditor: props?.applyToFocusedEditor === undefined ? false : props.applyToFocusedEditor,
|
|
9
|
-
disableIfParentHasFixedToolbar: props?.disableIfParentHasFixedToolbar === undefined ? false : props.disableIfParentHasFixedToolbar
|
|
10
|
-
};
|
|
11
|
-
return {
|
|
12
|
-
ClientFeature: isPluginActivated() ? LexicalEditorFeatureClient : null,
|
|
13
|
-
clientFeatureProps: sanitizedProps,
|
|
14
|
-
sanitizedServerFeatureProps: sanitizedProps
|
|
15
|
-
};
|
|
6
|
+
feature: {
|
|
7
|
+
ClientFeature: isActivated ? '@ai-stack/payloadcms/client#LexicalEditorFeatureClient' : null
|
|
16
8
|
},
|
|
17
9
|
key: PLUGIN_LEXICAL_EDITOR_FEATURE
|
|
18
10
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/LexicalEditor/feature.server.ts"],"sourcesContent":["import { createServerFeature } from '@payloadcms/richtext-lexical'\n\nimport { PLUGIN_LEXICAL_EDITOR_FEATURE } from '../../defaults.js'\nimport { isPluginActivated } from '../../utilities/isPluginActivated.js'\
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/LexicalEditor/feature.server.ts"],"sourcesContent":["import { createServerFeature } from '@payloadcms/richtext-lexical'\n\nimport { PLUGIN_LEXICAL_EDITOR_FEATURE } from '../../defaults.js'\nimport { isPluginActivated } from '../../utilities/isPluginActivated.js'\n\nconst isActivated = isPluginActivated()\n\nexport const PayloadAiPluginLexicalEditorFeature = createServerFeature({\n feature: {\n ClientFeature: isActivated ? '@ai-stack/payloadcms/client#LexicalEditorFeatureClient' : null,\n },\n key: PLUGIN_LEXICAL_EDITOR_FEATURE,\n})\n"],"names":["createServerFeature","PLUGIN_LEXICAL_EDITOR_FEATURE","isPluginActivated","isActivated","PayloadAiPluginLexicalEditorFeature","feature","ClientFeature","key"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,+BAA8B;AAElE,SAASC,6BAA6B,QAAQ,oBAAmB;AACjE,SAASC,iBAAiB,QAAQ,uCAAsC;AAExE,MAAMC,cAAcD;AAEpB,OAAO,MAAME,sCAAsCJ,oBAAoB;IACrEK,SAAS;QACPC,eAAeH,cAAc,2DAA2D;IAC1F;IACAI,KAAKN;AACP,GAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromptEditorField.d.ts","sourceRoot":"","sources":["../../../src/fields/PromptEditorField/PromptEditorField.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"PromptEditorField.d.ts","sourceRoot":"","sources":["../../../src/fields/PromptEditorField/PromptEditorField.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAGjD,OAAO,KAAK,MAAM,OAAO,CAAA;AAMzB,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA4B1D,CAAA"}
|
|
@@ -1,59 +1,40 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import React
|
|
5
|
-
import { useInstructions } from '../../providers/InstructionsProvider/
|
|
6
|
-
import {
|
|
7
|
-
//
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FieldLabel, useField, useFieldProps } from '@payloadcms/ui';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useInstructions } from '../../providers/InstructionsProvider/useInstructions.js';
|
|
6
|
+
import { AutocompleteTextField } from '../../libraries/autocomplete/AutocompleteTextArea.js';
|
|
7
|
+
//NOTE: HMR does not work for plugin components anymore, I think it has to do with importMap/ string path
|
|
8
8
|
export const PromptEditorField = (props)=>{
|
|
9
|
-
const {
|
|
9
|
+
const { field } = props;
|
|
10
10
|
const { path: pathFromContext } = useFieldProps();
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
path: pathFromProps
|
|
11
|
+
const { setValue, value } = useField({
|
|
12
|
+
path: pathFromContext
|
|
14
13
|
});
|
|
15
|
-
const {
|
|
16
|
-
path: pathFromContext
|
|
14
|
+
const { promptEditorSuggestions } = useInstructions({
|
|
15
|
+
path: pathFromContext
|
|
17
16
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const handleUpdate = useCallback((value)=>{
|
|
40
|
-
if (value) setValue(value);
|
|
41
|
-
}, [
|
|
42
|
-
setValue
|
|
43
|
-
]);
|
|
44
|
-
const CustomDescription = !initializing ? /*#__PURE__*/ _jsx(Floatype, {
|
|
45
|
-
options: {
|
|
46
|
-
onQuery: handleQuery,
|
|
47
|
-
onSelect: handleSelect,
|
|
48
|
-
onUpdate: handleUpdate
|
|
49
|
-
},
|
|
50
|
-
ref: elementRef
|
|
51
|
-
}) : null;
|
|
52
|
-
return /*#__PURE__*/ _jsx(InputField, {
|
|
53
|
-
...restProps,
|
|
54
|
-
CustomDescription: CustomDescription,
|
|
55
|
-
name: name,
|
|
56
|
-
path: pathFromProps
|
|
17
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
18
|
+
className: "field-type textarea",
|
|
19
|
+
children: [
|
|
20
|
+
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
21
|
+
field: field,
|
|
22
|
+
label: field.label
|
|
23
|
+
}),
|
|
24
|
+
/*#__PURE__*/ _jsx(AutocompleteTextField, {
|
|
25
|
+
changeOnSelect: (trigger, selected)=>{
|
|
26
|
+
return trigger + selected + ' }}';
|
|
27
|
+
},
|
|
28
|
+
onChange: (val)=>{
|
|
29
|
+
setValue(val);
|
|
30
|
+
},
|
|
31
|
+
options: promptEditorSuggestions,
|
|
32
|
+
trigger: [
|
|
33
|
+
'{{ '
|
|
34
|
+
],
|
|
35
|
+
value: value
|
|
36
|
+
})
|
|
37
|
+
]
|
|
57
38
|
});
|
|
58
39
|
};
|
|
59
40
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/PromptEditorField/PromptEditorField.tsx"],"sourcesContent":["'use client'\n\nimport type { TextareaFieldProps } from '
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/PromptEditorField/PromptEditorField.tsx"],"sourcesContent":["'use client'\n\nimport type { TextareaFieldProps } from 'payload'\n\nimport { FieldLabel, useField, useFieldProps } from '@payloadcms/ui'\nimport React from 'react'\n\nimport { useInstructions } from '../../providers/InstructionsProvider/useInstructions.js'\nimport { AutocompleteTextField } from '../../libraries/autocomplete/AutocompleteTextArea.js'\n\n//NOTE: HMR does not work for plugin components anymore, I think it has to do with importMap/ string path\nexport const PromptEditorField: React.FC<TextareaFieldProps> = (props) => {\n const { field } = props\n const { path: pathFromContext } = useFieldProps()\n\n const { setValue, value } = useField<string>({\n path: pathFromContext,\n })\n\n const { promptEditorSuggestions } = useInstructions({\n path: pathFromContext,\n })\n\n return (\n <div className=\"field-type textarea\">\n <FieldLabel field={field} label={field.label} />\n <AutocompleteTextField\n changeOnSelect={(trigger, selected) => {\n return trigger + selected + ' }}'\n }}\n onChange={(val: string) => {\n setValue(val)\n }}\n options={promptEditorSuggestions}\n trigger={['{{ ']}\n value={value}\n />\n </div>\n )\n}\n"],"names":["FieldLabel","useField","useFieldProps","React","useInstructions","AutocompleteTextField","PromptEditorField","props","field","path","pathFromContext","setValue","value","promptEditorSuggestions","div","className","label","changeOnSelect","trigger","selected","onChange","val","options"],"mappings":"AAAA;;AAIA,SAASA,UAAU,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,iBAAgB;AACpE,OAAOC,WAAW,QAAO;AAEzB,SAASC,eAAe,QAAQ,0DAAyD;AACzF,SAASC,qBAAqB,QAAQ,uDAAsD;AAE5F,yGAAyG;AACzG,OAAO,MAAMC,oBAAkD,CAACC;IAC9D,MAAM,EAAEC,KAAK,EAAE,GAAGD;IAClB,MAAM,EAAEE,MAAMC,eAAe,EAAE,GAAGR;IAElC,MAAM,EAAES,QAAQ,EAAEC,KAAK,EAAE,GAAGX,SAAiB;QAC3CQ,MAAMC;IACR;IAEA,MAAM,EAAEG,uBAAuB,EAAE,GAAGT,gBAAgB;QAClDK,MAAMC;IACR;IAEA,qBACE,MAACI;QAAIC,WAAU;;0BACb,KAACf;gBAAWQ,OAAOA;gBAAOQ,OAAOR,MAAMQ,KAAK;;0BAC5C,KAACX;gBACCY,gBAAgB,CAACC,SAASC;oBACxB,OAAOD,UAAUC,WAAW;gBAC9B;gBACAC,UAAU,CAACC;oBACTV,SAASU;gBACX;gBACAC,SAAST;gBACTK,SAAS;oBAAC;iBAAM;gBAChBN,OAAOA;;;;AAIf,EAAC"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import type { SelectFieldProps } from '
|
|
2
|
-
export declare const SelectField: (props:
|
|
1
|
+
import type { SelectFieldProps } from 'payload';
|
|
2
|
+
export declare const SelectField: (props: {
|
|
3
|
+
filterByField: string;
|
|
4
|
+
options: {
|
|
5
|
+
fields: string[];
|
|
6
|
+
label: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}[];
|
|
9
|
+
} & SelectFieldProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
10
|
//# sourceMappingURL=SelectField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectField.d.ts","sourceRoot":"","sources":["../../../src/fields/SelectField/SelectField.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"SelectField.d.ts","sourceRoot":"","sources":["../../../src/fields/SelectField/SelectField.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAM7D,eAAO,MAAM,WAAW,UACf;IACL,aAAa,EAAE,MAAM,CAAA;IACrB,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAC9D,GAAG,gBAAgB,4CAqCrB,CAAA"}
|
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { SelectInput, useField, useFieldProps } from '@payloadcms/ui';
|
|
4
4
|
import React, { useEffect, useState } from 'react';
|
|
5
|
+
// Use to filter model options in settings based on field types
|
|
5
6
|
export const SelectField = (props)=>{
|
|
6
|
-
const
|
|
7
|
-
const {
|
|
8
|
-
const {
|
|
9
|
-
const { filterByField, options } = selectOptions;
|
|
10
|
-
const { value } = useField({
|
|
7
|
+
const { field, filterByField, options } = props;
|
|
8
|
+
const { path } = useFieldProps();
|
|
9
|
+
const { value: relatedField } = useField({
|
|
11
10
|
path: filterByField
|
|
12
11
|
});
|
|
13
12
|
const [filterOptions, setFilterOptions] = useState([]);
|
|
14
|
-
//TODO: Remove this mess, find alternative
|
|
15
13
|
useEffect(()=>{
|
|
16
|
-
if (Array.isArray(options))
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} else {
|
|
25
|
-
setFilterOptions(optionsFromProps);
|
|
26
|
-
}
|
|
14
|
+
if (!Array.isArray(options)) return;
|
|
15
|
+
const opts = options.filter((option)=>{
|
|
16
|
+
if (!relatedField || !option.fields) return true;
|
|
17
|
+
if (Array.isArray(option.fields)) {
|
|
18
|
+
return option.fields.includes(relatedField);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
setFilterOptions(opts);
|
|
27
22
|
}, [
|
|
28
|
-
|
|
29
|
-
optionsFromProps,
|
|
23
|
+
relatedField,
|
|
30
24
|
options
|
|
31
25
|
]);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
const { setValue, value: selectValue } = useField({
|
|
27
|
+
path
|
|
28
|
+
});
|
|
29
|
+
return /*#__PURE__*/ _jsx(SelectInput, {
|
|
30
|
+
label: field.label,
|
|
31
|
+
name: path,
|
|
32
|
+
onChange: (e)=>{
|
|
33
|
+
setValue(e.value);
|
|
34
|
+
},
|
|
35
|
+
options: filterOptions,
|
|
36
|
+
path: path,
|
|
37
|
+
value: selectValue
|
|
35
38
|
});
|
|
36
39
|
};
|
|
37
40
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/SelectField/SelectField.tsx"],"sourcesContent":["'use client'\n\nimport type { SelectFieldProps } from '
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/SelectField/SelectField.tsx"],"sourcesContent":["'use client'\n\nimport type { OptionObject, SelectFieldProps } from 'payload'\n\nimport { SelectInput, useField, useFieldProps } from '@payloadcms/ui'\nimport React, { useEffect, useState } from 'react'\n\n// Use to filter model options in settings based on field types\nexport const SelectField = (\n props: {\n filterByField: string\n options: { fields: string[]; label: string; value: string }[]\n } & SelectFieldProps,\n) => {\n const { field, filterByField, options } = props\n const { path } = useFieldProps()\n const { value: relatedField } = useField<string>({\n path: filterByField,\n })\n\n const [filterOptions, setFilterOptions] = useState<OptionObject[]>([])\n\n useEffect(() => {\n if (!Array.isArray(options)) return\n\n const opts = options.filter((option) => {\n if (!relatedField || !option.fields) return true\n\n if (Array.isArray(option.fields)) {\n return option.fields.includes(relatedField)\n }\n })\n setFilterOptions(opts)\n }, [relatedField, options])\n\n const { setValue, value: selectValue } = useField<string>({ path })\n\n return (\n <SelectInput\n label={field.label}\n name={path}\n onChange={(e: OptionObject) => {\n setValue(e.value)\n }}\n options={filterOptions}\n path={path}\n value={selectValue}\n />\n )\n}\n"],"names":["SelectInput","useField","useFieldProps","React","useEffect","useState","SelectField","props","field","filterByField","options","path","value","relatedField","filterOptions","setFilterOptions","Array","isArray","opts","filter","option","fields","includes","setValue","selectValue","label","name","onChange","e"],"mappings":"AAAA;;AAIA,SAASA,WAAW,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,iBAAgB;AACrE,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAElD,+DAA+D;AAC/D,OAAO,MAAMC,cAAc,CACzBC;IAKA,MAAM,EAAEC,KAAK,EAAEC,aAAa,EAAEC,OAAO,EAAE,GAAGH;IAC1C,MAAM,EAAEI,IAAI,EAAE,GAAGT;IACjB,MAAM,EAAEU,OAAOC,YAAY,EAAE,GAAGZ,SAAiB;QAC/CU,MAAMF;IACR;IAEA,MAAM,CAACK,eAAeC,iBAAiB,GAAGV,SAAyB,EAAE;IAErED,UAAU;QACR,IAAI,CAACY,MAAMC,OAAO,CAACP,UAAU;QAE7B,MAAMQ,OAAOR,QAAQS,MAAM,CAAC,CAACC;YAC3B,IAAI,CAACP,gBAAgB,CAACO,OAAOC,MAAM,EAAE,OAAO;YAE5C,IAAIL,MAAMC,OAAO,CAACG,OAAOC,MAAM,GAAG;gBAChC,OAAOD,OAAOC,MAAM,CAACC,QAAQ,CAACT;YAChC;QACF;QACAE,iBAAiBG;IACnB,GAAG;QAACL;QAAcH;KAAQ;IAE1B,MAAM,EAAEa,QAAQ,EAAEX,OAAOY,WAAW,EAAE,GAAGvB,SAAiB;QAAEU;IAAK;IAEjE,qBACE,KAACX;QACCyB,OAAOjB,MAAMiB,KAAK;QAClBC,MAAMf;QACNgB,UAAU,CAACC;YACTL,SAASK,EAAEhB,KAAK;QAClB;QACAF,SAASI;QACTH,MAAMA;QACNC,OAAOY;;AAGb,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* COMMERCIAL-LICENSE.md. Unauthorized commercial use or resale of modified versions
|
|
5
5
|
* without appropriate licensing is prohibited.
|
|
6
6
|
*/
|
|
7
|
-
export { PayloadAiPluginLexicalEditorFeature } from './fields/LexicalEditor/feature.server.js';
|
|
8
7
|
export { payloadAiPlugin } from './plugin.js';
|
|
9
|
-
export {
|
|
8
|
+
export { PayloadAiPluginLexicalEditorFeature } from './fields/LexicalEditor/feature.server.js';
|
|
9
|
+
export { LexicalBaseNode } from './ai/schemas/lexical.schema.js';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,mCAAmC,EAAE,MAAM,0CAA0C,CAAA;AAC9F,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* redistribution, or embedding in proprietary systems, please refer to the
|
|
4
4
|
* COMMERCIAL-LICENSE.md. Unauthorized commercial use or resale of modified versions
|
|
5
5
|
* without appropriate licensing is prohibited.
|
|
6
|
-
*/ export {
|
|
7
|
-
export {
|
|
8
|
-
export { LexicalBaseNode } from './ai/
|
|
6
|
+
*/ export { payloadAiPlugin } from './plugin.js';
|
|
7
|
+
export { PayloadAiPluginLexicalEditorFeature } from './fields/LexicalEditor/feature.server.js';
|
|
8
|
+
export { LexicalBaseNode } from './ai/schemas/lexical.schema.js';
|
|
9
9
|
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @license This software is licensed under the MIT License. For commercial use,\n * redistribution, or embedding in proprietary systems, please refer to the\n * COMMERCIAL-LICENSE.md. Unauthorized commercial use or resale of modified versions\n * without appropriate licensing is prohibited.\n */\n\nexport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @license This software is licensed under the MIT License. For commercial use,\n * redistribution, or embedding in proprietary systems, please refer to the\n * COMMERCIAL-LICENSE.md. Unauthorized commercial use or resale of modified versions\n * without appropriate licensing is prohibited.\n */\n\nexport { payloadAiPlugin } from './plugin.js'\nexport { PayloadAiPluginLexicalEditorFeature } from './fields/LexicalEditor/feature.server.js'\nexport { LexicalBaseNode } from './ai/schemas/lexical.schema.js'\n"],"names":["payloadAiPlugin","PayloadAiPluginLexicalEditorFeature","LexicalBaseNode"],"mappings":"AAAA;;;;;CAKC,GAED,SAASA,eAAe,QAAQ,cAAa;AAC7C,SAASC,mCAAmC,QAAQ,2CAA0C;AAC9F,SAASC,eAAe,QAAQ,iCAAgC"}
|
package/dist/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAOtC,eAAO,MAAM,IAAI,YAAmB,OAAO,
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAOtC,eAAO,MAAM,IAAI,YAAmB,OAAO,yCAoF1C,CAAA"}
|
package/dist/init.js
CHANGED
|
@@ -9,6 +9,7 @@ export const init = async (payload, fieldSchemaPaths)=>{
|
|
|
9
9
|
for(let i = 0; i < paths.length; i++){
|
|
10
10
|
const path = paths[i];
|
|
11
11
|
const { type: fieldType, label: fieldLabel } = fieldSchemaPaths[path];
|
|
12
|
+
//TODO: if global is broken the plugin doesn't know and does not run reindexing
|
|
12
13
|
const entry = await payload.find({
|
|
13
14
|
collection: PLUGIN_INSTRUCTIONS_TABLE,
|
|
14
15
|
where: {
|
|
@@ -42,11 +43,22 @@ export const init = async (payload, fieldSchemaPaths)=>{
|
|
|
42
43
|
prompt: generatedPrompt,
|
|
43
44
|
'schema-path': path
|
|
44
45
|
}
|
|
46
|
+
}).then((a)=>a).catch((a)=>{
|
|
47
|
+
console.log('err-', a);
|
|
45
48
|
});
|
|
46
|
-
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
if (instructions?.id) {
|
|
51
|
+
fieldInstructionsMap[path] = {
|
|
52
|
+
id: instructions.id,
|
|
53
|
+
fieldType
|
|
54
|
+
};
|
|
55
|
+
}
|
|
47
56
|
} else {
|
|
48
57
|
const [instructions] = entry.docs;
|
|
49
|
-
fieldInstructionsMap[path] =
|
|
58
|
+
fieldInstructionsMap[path] = {
|
|
59
|
+
id: instructions.id,
|
|
60
|
+
fieldType
|
|
61
|
+
};
|
|
50
62
|
}
|
|
51
63
|
}
|
|
52
64
|
payload.logger.info(`— AI Plugin: Enabled fieldMap: ${JSON.stringify(fieldInstructionsMap, null, 2)}`);
|
package/dist/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport { GenerationModels } from './ai/models/index.js'\nimport { seedPrompts } from './ai/prompts.js'\nimport { generateSeedPrompt } from './ai/utils/generateSeedPrompt.js'\nimport { PLUGIN_INSTRUCTIONS_MAP_GLOBAL, PLUGIN_INSTRUCTIONS_TABLE } from './defaults.js'\n\nexport const init = async (payload: Payload, fieldSchemaPaths) => {\n payload.logger.info(`— AI Plugin: Initializing...`)\n\n const paths = Object.keys(fieldSchemaPaths)\n\n const fieldInstructionsMap = {}\n for (let i = 0; i < paths.length; i++) {\n const path = paths[i]\n const { type: fieldType, label: fieldLabel } = fieldSchemaPaths[path]\n const entry = await payload.find({\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n where: {\n 'field-type': {\n equals: fieldType,\n },\n 'schema-path': {\n equals: path,\n },\n },\n })\n\n if (!entry?.docs?.length) {\n const { prompt, system } = seedPrompts({\n fieldLabel,\n fieldSchemaPaths,\n fieldType,\n path,\n })\n const generatedPrompt = await generateSeedPrompt({\n prompt,\n system,\n })\n payload.logger.info(\n `\\nPrompt generated for \"${fieldLabel}\" field:\\nprompt: ${generatedPrompt}\\n\\n`,\n )\n const instructions = await payload.create({\n
|
|
1
|
+
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport { GenerationModels } from './ai/models/index.js'\nimport { seedPrompts } from './ai/prompts.js'\nimport { generateSeedPrompt } from './ai/utils/generateSeedPrompt.js'\nimport { PLUGIN_INSTRUCTIONS_MAP_GLOBAL, PLUGIN_INSTRUCTIONS_TABLE } from './defaults.js'\n\nexport const init = async (payload: Payload, fieldSchemaPaths) => {\n payload.logger.info(`— AI Plugin: Initializing...`)\n\n const paths = Object.keys(fieldSchemaPaths)\n\n const fieldInstructionsMap = {}\n for (let i = 0; i < paths.length; i++) {\n const path = paths[i]\n const { type: fieldType, label: fieldLabel } = fieldSchemaPaths[path]\n //TODO: if global is broken the plugin doesn't know and does not run reindexing\n const entry = await payload.find({\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n where: {\n 'field-type': {\n equals: fieldType,\n },\n 'schema-path': {\n equals: path,\n },\n },\n })\n\n if (!entry?.docs?.length) {\n const { prompt, system } = seedPrompts({\n fieldLabel,\n fieldSchemaPaths,\n fieldType,\n path,\n })\n const generatedPrompt = await generateSeedPrompt({\n prompt,\n system,\n })\n payload.logger.info(\n `\\nPrompt generated for \"${fieldLabel}\" field:\\nprompt: ${generatedPrompt}\\n\\n`,\n )\n const instructions = await payload\n .create({\n collection: PLUGIN_INSTRUCTIONS_TABLE,\n data: {\n 'field-type': fieldType,\n 'model-id': GenerationModels.find((a) => {\n return a.fields.includes(fieldType)\n })?.id,\n prompt: generatedPrompt,\n 'schema-path': path,\n },\n })\n .then((a) => a)\n .catch((a) => {\n console.log('err-', a)\n })\n\n // @ts-expect-error\n if (instructions?.id) {\n fieldInstructionsMap[path] = {\n id: instructions.id,\n fieldType,\n }\n }\n } else {\n const [instructions] = entry.docs\n fieldInstructionsMap[path] = {\n id: instructions.id,\n fieldType,\n }\n }\n }\n\n payload.logger.info(\n `— AI Plugin: Enabled fieldMap: ${JSON.stringify(fieldInstructionsMap, null, 2)}`,\n )\n await payload.updateGlobal({\n slug: PLUGIN_INSTRUCTIONS_MAP_GLOBAL, // required\n data: {\n map: fieldInstructionsMap,\n },\n depth: 2,\n })\n\n payload.logger.info(`— AI Plugin: Initialized!`)\n payload.logger.info(\n '\\n\\n-AI Plugin: Example prompts are added to get you started, Now go break some code 🚀🚀🚀\\n\\n',\n )\n}\n"],"names":["GenerationModels","seedPrompts","generateSeedPrompt","PLUGIN_INSTRUCTIONS_MAP_GLOBAL","PLUGIN_INSTRUCTIONS_TABLE","init","payload","fieldSchemaPaths","logger","info","paths","Object","keys","fieldInstructionsMap","i","length","path","type","fieldType","label","fieldLabel","entry","find","collection","where","equals","docs","prompt","system","generatedPrompt","instructions","create","data","a","fields","includes","id","then","catch","console","log","JSON","stringify","updateGlobal","slug","map","depth"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,uBAAsB;AACvD,SAASC,WAAW,QAAQ,kBAAiB;AAC7C,SAASC,kBAAkB,QAAQ,mCAAkC;AACrE,SAASC,8BAA8B,EAAEC,yBAAyB,QAAQ,gBAAe;AAEzF,OAAO,MAAMC,OAAO,OAAOC,SAAkBC;IAC3CD,QAAQE,MAAM,CAACC,IAAI,CAAC,CAAC,4BAA4B,CAAC;IAElD,MAAMC,QAAQC,OAAOC,IAAI,CAACL;IAE1B,MAAMM,uBAAuB,CAAC;IAC9B,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,MAAMK,MAAM,EAAED,IAAK;QACrC,MAAME,OAAON,KAAK,CAACI,EAAE;QACrB,MAAM,EAAEG,MAAMC,SAAS,EAAEC,OAAOC,UAAU,EAAE,GAAGb,gBAAgB,CAACS,KAAK;QACrE,+EAA+E;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