payload-canvas 0.4.0 → 0.5.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/README.md +626 -154
- package/dist/admin/AiKeyField.d.ts +8 -0
- package/dist/admin/AiKeyField.js +54 -0
- package/dist/admin/BuilderTab.js +4 -1
- package/dist/admin/DocumentEditView.d.ts +9 -0
- package/dist/admin/DocumentEditView.js +45 -0
- package/dist/admin/LayoutField.d.ts +2 -2
- package/dist/admin/LayoutField.js +10 -7
- package/dist/admin/TemplateConditionsField.d.ts +9 -0
- package/dist/admin/TemplateConditionsField.js +22 -0
- package/dist/admin/aiKeyField.scss +58 -0
- package/dist/admin/client.d.ts +3 -0
- package/dist/admin/client.js +6 -0
- package/dist/admin/diff/changes.js +5 -0
- package/dist/admin/editor/Canvas.js +20 -5
- package/dist/admin/editor/Editor.d.ts +3 -1
- package/dist/admin/editor/Editor.js +6 -3
- package/dist/admin/editor/Inspector.js +75 -28
- package/dist/admin/editor/Library.js +40 -15
- package/dist/admin/editor/Outline.js +21 -16
- package/dist/admin/editor/Overlay.js +8 -3
- package/dist/admin/editor/actions.d.ts +10 -2
- package/dist/admin/editor/actions.js +18 -3
- package/dist/admin/editor/assistant/AssistantPanel.js +3 -1
- package/dist/admin/editor/classes/ClassManager.d.ts +4 -0
- package/dist/admin/editor/classes/ClassManager.js +56 -0
- package/dist/admin/editor/classes/controller.d.ts +112 -0
- package/dist/admin/editor/classes/controller.js +326 -0
- package/dist/admin/editor/classes/manager.scss +262 -0
- package/dist/admin/editor/classes/managerModel.d.ts +5 -0
- package/dist/admin/editor/classes/managerModel.js +27 -0
- package/dist/admin/editor/comments/CommentLayer.d.ts +2 -0
- package/dist/admin/editor/comments/CommentLayer.js +143 -0
- package/dist/admin/editor/comments/CommentsPanel.d.ts +8 -0
- package/dist/admin/editor/comments/CommentsPanel.js +73 -0
- package/dist/admin/editor/comments/Thread.d.ts +26 -0
- package/dist/admin/editor/comments/Thread.js +84 -0
- package/dist/admin/editor/comments/comments.scss +539 -0
- package/dist/admin/editor/comments/controller.d.ts +48 -0
- package/dist/admin/editor/comments/controller.js +142 -0
- package/dist/admin/editor/contentMode.d.ts +17 -0
- package/dist/admin/editor/contentMode.js +37 -0
- package/dist/admin/editor/dnd/DropOutlines.d.ts +1 -0
- package/dist/admin/editor/dnd/DropOutlines.js +73 -0
- package/dist/admin/editor/dnd/dnd.scss +43 -0
- package/dist/admin/editor/dnd/mode.d.ts +4 -0
- package/dist/admin/editor/dnd/mode.js +39 -0
- package/dist/admin/editor/editor.scss +13 -58
- package/dist/admin/editor/empty/EmptyStart.js +18 -66
- package/dist/admin/editor/fields/AddButton.d.ts +15 -0
- package/dist/admin/editor/fields/AddButton.js +14 -0
- package/dist/admin/editor/fields/ArrayField.js +3 -2
- package/dist/admin/editor/fields/CheckedInputs.d.ts +1 -0
- package/dist/admin/editor/fields/ConditionRows.d.ts +19 -0
- package/dist/admin/editor/fields/ConditionRows.js +137 -0
- package/dist/admin/editor/fields/ListWhereField.d.ts +8 -0
- package/dist/admin/editor/fields/ListWhereField.js +20 -0
- package/dist/admin/editor/fields/QueryFiltersField.d.ts +18 -0
- package/dist/admin/editor/fields/QueryFiltersField.js +41 -0
- package/dist/admin/editor/fields/RelatedField.d.ts +19 -0
- package/dist/admin/editor/fields/RelatedField.js +44 -0
- package/dist/admin/editor/fields/SortField.d.ts +13 -0
- package/dist/admin/editor/fields/SortField.js +37 -0
- package/dist/admin/editor/fields/WhereField.d.ts +12 -4
- package/dist/admin/editor/fields/WhereField.js +33 -53
- package/dist/admin/editor/fields/collectionFields.d.ts +6 -0
- package/dist/admin/editor/fields/collectionFields.js +15 -0
- package/dist/admin/editor/fields/conditions.d.ts +99 -0
- package/dist/admin/editor/fields/conditions.js +339 -0
- package/dist/admin/editor/fields/fields.scss +232 -9
- package/dist/admin/editor/fields/listOptions.d.ts +44 -0
- package/dist/admin/editor/fields/listOptions.js +111 -0
- package/dist/admin/editor/fields/queryFilterRows.d.ts +8 -0
- package/dist/admin/editor/fields/queryFilterRows.js +29 -0
- package/dist/admin/editor/fields/whereRows.d.ts +11 -12
- package/dist/admin/editor/fields/whereRows.js +83 -34
- package/dist/admin/editor/icons.d.ts +16 -1
- package/dist/admin/editor/icons.js +30 -1
- package/dist/admin/editor/inline.js +9 -0
- package/dist/admin/editor/insert/InsertHandle.js +4 -1
- package/dist/admin/editor/insert/picker.d.ts +3 -1
- package/dist/admin/editor/insert/picker.js +17 -10
- package/dist/admin/editor/insert/spots.d.ts +12 -1
- package/dist/admin/editor/insert/spots.js +49 -10
- package/dist/admin/editor/layout/LeftPanel.js +11 -6
- package/dist/admin/editor/live/useMultiplayer.js +9 -1
- package/dist/admin/editor/menu/blockMenu.js +27 -17
- package/dist/admin/editor/names.js +11 -3
- package/dist/admin/editor/renderField.d.ts +3 -1
- package/dist/admin/editor/renderField.js +63 -12
- package/dist/admin/editor/runtime.d.ts +14 -0
- package/dist/admin/editor/runtime.js +67 -6
- package/dist/admin/editor/sections/ComponentFields.d.ts +8 -0
- package/dist/admin/editor/sections/ComponentFields.js +116 -0
- package/dist/admin/editor/sections/PropertyControls.d.ts +18 -0
- package/dist/admin/editor/sections/PropertyControls.js +65 -0
- package/dist/admin/editor/sections/components.d.ts +29 -0
- package/dist/admin/editor/sections/components.js +112 -0
- package/dist/admin/editor/sections/components.scss +238 -0
- package/dist/admin/editor/sections/variants.d.ts +32 -0
- package/dist/admin/editor/sections/variants.js +59 -0
- package/dist/admin/editor/sections/variants.scss +90 -0
- package/dist/admin/editor/shortcuts.d.ts +4 -1
- package/dist/admin/editor/shortcuts.js +19 -3
- package/dist/admin/editor/store.d.ts +18 -0
- package/dist/admin/editor/store.js +46 -0
- package/dist/admin/editor/styles/ClassBar.d.ts +14 -0
- package/dist/admin/editor/styles/ClassBar.js +90 -0
- package/dist/admin/editor/styles/ClassCss.d.ts +4 -0
- package/dist/admin/editor/styles/ClassCss.js +28 -0
- package/dist/admin/editor/styles/ClassDialog.d.ts +2 -0
- package/dist/admin/editor/styles/ClassDialog.js +151 -0
- package/dist/admin/editor/styles/ColorPicker.js +5 -2
- package/dist/admin/editor/styles/RawClasses.d.ts +26 -1
- package/dist/admin/editor/styles/RawClasses.js +184 -32
- package/dist/admin/editor/styles/StylesPanel.d.ts +3 -3
- package/dist/admin/editor/styles/StylesPanel.js +53 -14
- package/dist/admin/editor/styles/VariantBar.js +2 -2
- package/dist/admin/editor/styles/classEdit.d.ts +4 -0
- package/dist/admin/editor/styles/classEdit.js +20 -0
- package/dist/admin/editor/styles/classes.scss +381 -0
- package/dist/admin/editor/styles/context.d.ts +19 -6
- package/dist/admin/editor/styles/context.js +24 -6
- package/dist/admin/editor/styles/controls.d.ts +3 -1
- package/dist/admin/editor/styles/controls.js +30 -12
- package/dist/admin/editor/styles/popover.d.ts +6 -0
- package/dist/admin/editor/styles/popover.js +5 -5
- package/dist/admin/editor/styles/styles.scss +26 -104
- package/dist/admin/editor/styles/suggestions.d.ts +22 -0
- package/dist/admin/editor/styles/suggestions.js +77 -0
- package/dist/admin/editor/styles/tokens.js +14 -0
- package/dist/admin/editor/templates/Bindable.js +86 -57
- package/dist/admin/editor/templates/SamplePicker.js +1 -1
- package/dist/admin/editor/templates/Visibility.d.ts +9 -0
- package/dist/admin/editor/templates/Visibility.js +54 -0
- package/dist/admin/editor/templates/binding.d.ts +2 -2
- package/dist/admin/editor/templates/binding.js +2 -2
- package/dist/admin/editor/templates/templates.scss +27 -0
- package/dist/admin/editor/templates/visibilityRows.d.ts +22 -0
- package/dist/admin/editor/templates/visibilityRows.js +83 -0
- package/dist/admin/editor/topbar/ContentModeToggle.d.ts +5 -0
- package/dist/admin/editor/topbar/ContentModeToggle.js +26 -0
- package/dist/admin/editor/topbar/DocumentActions.d.ts +1 -1
- package/dist/admin/editor/topbar/DocumentActions.js +5 -4
- package/dist/admin/editor/topbar/DocumentTitle.js +7 -2
- package/dist/admin/editor/topbar/TopBar.js +15 -3
- package/dist/admin/editor/topbar/contentMode.scss +35 -0
- package/dist/admin/editor/topbar/topbar.scss +3 -1
- package/dist/admin/formChoice.d.ts +3 -0
- package/dist/admin/formChoice.js +10 -0
- package/dist/admin/layoutField.scss +69 -0
- package/dist/admin/screen/BuilderScreen.d.ts +6 -1
- package/dist/admin/screen/BuilderScreen.js +4 -3
- package/dist/admin/server/BuilderView.js +10 -3
- package/dist/admin/templateConditions.scss +24 -0
- package/dist/ai/adapters/anthropic.js +17 -4
- package/dist/ai/adapters/cloudflare-gateway.js +7 -1
- package/dist/ai/adapters/cloudflare-workers-ai.js +2 -0
- package/dist/ai/adapters/openai-compatible.js +1 -0
- package/dist/ai/adapters/openrouter.js +2 -0
- package/dist/ai/config.d.ts +24 -4
- package/dist/ai/config.js +27 -8
- package/dist/ai/endpoint.d.ts +5 -2
- package/dist/ai/endpoint.js +31 -26
- package/dist/ai/images/cloudflare-workers-ai.js +6 -2
- package/dist/ai/images/openai.js +8 -3
- package/dist/ai/images/openrouter.js +6 -2
- package/dist/ai/images/service.d.ts +10 -4
- package/dist/ai/images/service.js +23 -7
- package/dist/ai/openai-format.d.ts +7 -0
- package/dist/ai/openai-format.js +17 -5
- package/dist/ai/prompt.d.ts +8 -0
- package/dist/ai/prompt.js +25 -5
- package/dist/ai/settings/index.d.ts +62 -0
- package/dist/ai/settings/index.js +264 -0
- package/dist/ai/settings/secret.d.ts +11 -0
- package/dist/ai/settings/secret.js +46 -0
- package/dist/ai/settings/shared.d.ts +22 -0
- package/dist/ai/settings/shared.js +3 -0
- package/dist/ai/tools.d.ts +3 -0
- package/dist/ai/tools.js +79 -15
- package/dist/ai/types.d.ts +43 -0
- package/dist/blocks/builtins/adjacentLinks.d.ts +5 -0
- package/dist/blocks/builtins/adjacentLinks.js +76 -0
- package/dist/blocks/builtins/carousel.d.ts +2 -29
- package/dist/blocks/builtins/carousel.js +44 -51
- package/dist/blocks/builtins/disclosure.d.ts +2 -1
- package/dist/blocks/builtins/disclosure.js +22 -32
- package/dist/blocks/builtins/embed.d.ts +15 -0
- package/dist/blocks/builtins/embed.js +47 -0
- package/dist/blocks/builtins/faq.d.ts +1 -1
- package/dist/blocks/builtins/faq.js +2 -2
- package/dist/blocks/builtins/filterLink.d.ts +1 -19
- package/dist/blocks/builtins/filterLink.js +9 -50
- package/dist/blocks/builtins/icon.d.ts +2 -0
- package/dist/blocks/builtins/icon.js +8 -8
- package/dist/blocks/builtins/index.d.ts +18 -13
- package/dist/blocks/builtins/index.js +43 -22
- package/dist/blocks/builtins/marquee.d.ts +5 -0
- package/dist/blocks/builtins/marquee.js +68 -0
- package/dist/blocks/builtins/popup.d.ts +5 -0
- package/dist/blocks/builtins/popup.js +83 -0
- package/dist/blocks/builtins/sectionRef.d.ts +16 -2
- package/dist/blocks/builtins/sectionRef.js +34 -12
- package/dist/blocks/builtins/shared.d.ts +18 -23
- package/dist/blocks/builtins/shared.js +34 -42
- package/dist/blocks/builtins/tableOfContents.d.ts +4 -0
- package/dist/blocks/builtins/tableOfContents.js +12 -18
- package/dist/blocks/builtins/tabs.d.ts +6 -0
- package/dist/blocks/builtins/tabs.js +87 -0
- package/dist/blocks/client/adjacentLinks.d.ts +4 -0
- package/dist/blocks/client/adjacentLinks.js +4 -0
- package/dist/blocks/client/carousel.d.ts +45 -0
- package/dist/blocks/client/carousel.js +53 -0
- package/dist/blocks/client/embed.d.ts +21 -0
- package/dist/blocks/client/embed.js +23 -0
- package/dist/blocks/client/field.d.ts +7 -0
- package/dist/blocks/client/field.js +8 -0
- package/dist/blocks/client/filterLink.d.ts +19 -0
- package/dist/blocks/client/filterLink.js +30 -0
- package/dist/blocks/client/helpers.d.ts +21 -0
- package/dist/blocks/client/helpers.js +24 -0
- package/dist/blocks/client/marquee.d.ts +14 -0
- package/dist/blocks/client/marquee.js +25 -0
- package/dist/blocks/client/menu.d.ts +46 -0
- package/dist/blocks/client/menu.js +49 -0
- package/dist/blocks/client/popup.d.ts +15 -0
- package/dist/blocks/client/popup.js +16 -0
- package/dist/blocks/client/tabs.d.ts +10 -0
- package/dist/blocks/client/tabs.js +11 -0
- package/dist/blocks/defaults.d.ts +15 -52
- package/dist/blocks/defaults.js +203 -437
- package/dist/blocks/index.d.ts +1 -1
- package/dist/blocks/index.js +2 -1
- package/dist/classes/actions.d.ts +97 -0
- package/dist/classes/actions.js +296 -0
- package/dist/classes/collection.d.ts +5 -0
- package/dist/classes/collection.js +189 -0
- package/dist/classes/config.d.ts +34 -0
- package/dist/classes/config.js +8 -0
- package/dist/classes/endpoints.d.ts +2 -0
- package/dist/classes/endpoints.js +120 -0
- package/dist/classes/index.d.ts +36 -0
- package/dist/classes/index.js +42 -0
- package/dist/classes/mcp.d.ts +6 -0
- package/dist/classes/mcp.js +161 -0
- package/dist/classes/shared.d.ts +131 -0
- package/dist/classes/shared.js +300 -0
- package/dist/classes/sheet.d.ts +34 -0
- package/dist/classes/sheet.js +126 -0
- package/dist/classes/usage.d.ts +57 -0
- package/dist/classes/usage.js +208 -0
- package/dist/comments/collection.d.ts +38 -0
- package/dist/comments/collection.js +226 -0
- package/dist/comments/config.d.ts +15 -0
- package/dist/comments/config.js +2 -0
- package/dist/comments/index.d.ts +20 -0
- package/dist/comments/index.js +22 -0
- package/dist/comments/shared.d.ts +54 -0
- package/dist/comments/shared.js +104 -0
- package/dist/core/bindings.d.ts +77 -32
- package/dist/core/bindings.js +319 -134
- package/dist/core/blockNames.d.ts +9 -0
- package/dist/core/blockNames.js +11 -0
- package/dist/core/blocks.d.ts +21 -8
- package/dist/core/blocks.js +37 -16
- package/dist/core/classes.d.ts +16 -8
- package/dist/core/classes.js +31 -27
- package/dist/core/components.d.ts +72 -0
- package/dist/core/components.js +294 -0
- package/dist/core/contentMode.d.ts +27 -0
- package/dist/core/contentMode.js +0 -0
- package/dist/core/dropTarget.d.ts +11 -0
- package/dist/core/dropTarget.js +24 -1
- package/dist/core/fields.d.ts +5 -0
- package/dist/core/fields.js +11 -0
- package/dist/core/headings.d.ts +5 -2
- package/dist/core/headings.js +14 -6
- package/dist/core/index.d.ts +8 -3
- package/dist/core/index.js +8 -3
- package/dist/core/layers.d.ts +9 -0
- package/dist/core/layers.js +29 -0
- package/dist/core/operations.d.ts +6 -0
- package/dist/core/operations.js +85 -24
- package/dist/core/payloadBlocks.js +5 -1
- package/dist/core/references.js +28 -0
- package/dist/core/schema.js +20 -6
- package/dist/core/sectionOrigin.d.ts +6 -0
- package/dist/core/sectionOrigin.js +21 -0
- package/dist/core/sections.d.ts +72 -0
- package/dist/core/sections.js +331 -0
- package/dist/core/templateChoice.d.ts +24 -0
- package/dist/core/templateChoice.js +43 -0
- package/dist/core/tree.js +18 -6
- package/dist/core/types.d.ts +148 -18
- package/dist/core/validate.d.ts +4 -1
- package/dist/core/validate.js +28 -11
- package/dist/core/visibility.d.ts +63 -0
- package/dist/core/visibility.js +214 -0
- package/dist/core/whereValues.d.ts +22 -0
- package/dist/core/whereValues.js +43 -0
- package/dist/css/classes.d.ts +16 -0
- package/dist/css/classes.js +172 -0
- package/dist/css/index.d.ts +32 -1
- package/dist/css/index.js +64 -5
- package/dist/css/tokens.d.ts +10 -0
- package/dist/css/tokens.js +23 -10
- package/dist/index.d.ts +5 -2
- package/dist/index.js +6 -1
- package/dist/live/contentMode.d.ts +24 -0
- package/dist/live/contentMode.js +39 -0
- package/dist/live/endpoints.js +3 -0
- package/dist/live/session.d.ts +5 -0
- package/dist/live/session.js +8 -0
- package/dist/live/types.d.ts +16 -1
- package/dist/mcp/index.d.ts +10 -1
- package/dist/mcp/index.js +146 -54
- package/dist/mcp/shared.d.ts +93 -3
- package/dist/mcp/shared.js +211 -15
- package/dist/plugin/hook.d.ts +7 -1
- package/dist/plugin/hook.js +30 -4
- package/dist/plugin/index.d.ts +19 -8
- package/dist/plugin/index.js +89 -20
- package/dist/plugin/links.d.ts +24 -0
- package/dist/plugin/links.js +27 -0
- package/dist/plugin/listCollections.d.ts +9 -7
- package/dist/plugin/listCollections.js +30 -21
- package/dist/plugin/sections.d.ts +14 -7
- package/dist/plugin/sections.js +69 -23
- package/dist/plugin/sectionsUsedIn.d.ts +6 -0
- package/dist/plugin/sectionsUsedIn.js +24 -0
- package/dist/plugin/templateEndpoint.d.ts +9 -0
- package/dist/plugin/templateEndpoint.js +49 -0
- package/dist/plugin/templates.js +23 -8
- package/dist/protocol/index.d.ts +16 -1
- package/dist/react/canvas/BuilderCanvas.js +144 -21
- package/dist/react/canvas/classes.d.ts +17 -0
- package/dist/react/canvas/classes.js +102 -0
- package/dist/react/canvas/controls.d.ts +31 -0
- package/dist/react/canvas/controls.js +75 -0
- package/dist/react/canvas/fetchDocs.d.ts +2 -2
- package/dist/react/canvas/fetchDocs.js +16 -8
- package/dist/react/canvas/measure.d.ts +9 -0
- package/dist/react/canvas/measure.js +106 -7
- package/dist/react/canvas/resolveLayout.d.ts +1 -1
- package/dist/react/canvas/resolveLayout.js +4 -3
- package/dist/react/canvas/thumbnail/ThumbnailCanvas.js +17 -4
- package/dist/react/classes/ClassesStyle.d.ts +27 -0
- package/dist/react/classes/ClassesStyle.js +27 -0
- package/dist/react/components/Button.d.ts +2 -11
- package/dist/react/components/Button.js +8 -43
- package/dist/react/components/CollectionList.d.ts +4 -1
- package/dist/react/components/CollectionList.js +10 -3
- package/dist/react/components/Container.d.ts +5 -2
- package/dist/react/components/Container.js +7 -4
- package/dist/react/components/Field.js +3 -14
- package/dist/react/components/Link.d.ts +1 -1
- package/dist/react/components/Link.js +5 -3
- package/dist/react/components/List.d.ts +1 -1
- package/dist/react/components/List.js +2 -2
- package/dist/react/components/Menu.d.ts +10 -1
- package/dist/react/components/Menu.js +39 -12
- package/dist/react/components/RichText.d.ts +3 -4
- package/dist/react/components/RichText.js +5 -5
- package/dist/react/components/builtins/Accordion.d.ts +4 -3
- package/dist/react/components/builtins/Accordion.js +6 -5
- package/dist/react/components/builtins/AdjacentLinks.d.ts +11 -0
- package/dist/react/components/builtins/AdjacentLinks.js +20 -0
- package/dist/react/components/builtins/Carousel.d.ts +21 -10
- package/dist/react/components/builtins/Carousel.js +175 -100
- package/dist/react/components/builtins/Disclosure.d.ts +4 -3
- package/dist/react/components/builtins/Disclosure.js +6 -5
- package/dist/react/components/builtins/Embed.d.ts +11 -0
- package/dist/react/components/builtins/Embed.js +23 -0
- package/dist/react/components/builtins/EmbedHtml.d.ts +15 -0
- package/dist/react/components/builtins/EmbedHtml.js +51 -0
- package/dist/react/components/builtins/EmbedPreview.d.ts +34 -0
- package/dist/react/components/builtins/EmbedPreview.js +105 -0
- package/dist/react/components/builtins/FilterLink.d.ts +1 -1
- package/dist/react/components/builtins/FilterLink.js +4 -4
- package/dist/react/components/builtins/Marquee.d.ts +8 -0
- package/dist/react/components/builtins/Marquee.js +15 -0
- package/dist/react/components/builtins/Popup.d.ts +26 -0
- package/dist/react/components/builtins/Popup.js +146 -0
- package/dist/react/components/builtins/SectionRef.d.ts +4 -3
- package/dist/react/components/builtins/SectionRef.js +9 -5
- package/dist/react/components/builtins/Tab.d.ts +7 -0
- package/dist/react/components/builtins/Tab.js +21 -0
- package/dist/react/components/builtins/TableOfContents.d.ts +17 -3
- package/dist/react/components/builtins/TableOfContents.js +22 -7
- package/dist/react/components/builtins/Tabs.d.ts +17 -0
- package/dist/react/components/builtins/Tabs.js +71 -0
- package/dist/react/components/builtins/index.d.ts +37 -20
- package/dist/react/components/builtins/index.js +54 -20
- package/dist/react/components/builtins/tabsContext.d.ts +12 -0
- package/dist/react/components/builtins/tabsContext.js +6 -0
- package/dist/react/components/index.js +11 -8
- package/dist/react/components/lazy.d.ts +32 -0
- package/dist/react/components/lazy.js +20 -0
- package/dist/react/components/lazyBlock.d.ts +17 -0
- package/dist/react/components/lazyBlock.js +23 -0
- package/dist/react/index.d.ts +6 -3
- package/dist/react/index.js +5 -2
- package/dist/react/render/RenderLayout.d.ts +9 -7
- package/dist/react/render/RenderLayout.js +96 -45
- package/dist/react/render/canvasMode.d.ts +13 -0
- package/dist/react/render/canvasMode.js +13 -0
- package/dist/react/render/canvasServer.js +4 -3
- package/dist/react/render/canvasServerTypes.d.ts +5 -0
- package/dist/react/render/lists.d.ts +36 -4
- package/dist/react/render/lists.js +132 -15
- package/dist/react/render/marks.d.ts +15 -0
- package/dist/react/render/marks.js +23 -0
- package/dist/react/render/payload.d.ts +8 -1
- package/dist/react/render/payload.js +12 -3
- package/dist/react/render/preview.d.ts +11 -0
- package/dist/react/render/preview.js +13 -0
- package/dist/react/render/relations.d.ts +10 -0
- package/dist/react/render/relations.js +39 -0
- package/dist/react/render/resolve.d.ts +8 -4
- package/dist/react/render/resolve.js +11 -5
- package/dist/react/render/reveal.d.ts +17 -0
- package/dist/react/render/reveal.js +39 -0
- package/dist/react/render/sections.d.ts +11 -5
- package/dist/react/render/sections.js +52 -24
- package/dist/react/render/templates.d.ts +47 -0
- package/dist/react/render/templates.js +139 -0
- package/dist/react/render/types.d.ts +62 -5
- package/dist/react/server.d.ts +2 -37
- package/dist/react/server.js +8 -133
- package/dist/react/theme/ThemeLiveLoader.d.ts +4 -0
- package/dist/react/theme/ThemeLiveLoader.js +5 -0
- package/dist/react/theme/ThemeStyle.js +1 -1
- package/dist/theme/admin/Variables.d.ts +11 -0
- package/dist/theme/admin/Variables.js +115 -0
- package/dist/theme/admin/fields.scss +113 -0
- package/dist/theme/client.d.ts +1 -0
- package/dist/theme/client.js +2 -0
- package/dist/theme/css.d.ts +6 -1
- package/dist/theme/css.js +12 -4
- package/dist/theme/global.js +83 -0
- package/dist/theme/index.d.ts +1 -0
- package/dist/theme/index.js +1 -0
- package/dist/theme/server.d.ts +15 -0
- package/dist/theme/server.js +43 -0
- package/dist/theme/usage.d.ts +23 -0
- package/dist/theme/usage.js +68 -0
- package/dist/theme/variables.d.ts +72 -0
- package/dist/theme/variables.js +231 -0
- package/package.json +4 -2
- package/dist/admin/editor/styles/SiteClasses.d.ts +0 -9
- package/dist/admin/editor/styles/SiteClasses.js +0 -31
- package/dist/blocks/builtins/headingId.d.ts +0 -15
- package/dist/blocks/builtins/headingId.js +0 -36
- package/dist/blocks/builtins/lightbox.d.ts +0 -43
- package/dist/blocks/builtins/lightbox.js +0 -93
- package/dist/blocks/builtins/mediaBackdrop.d.ts +0 -11
- package/dist/blocks/builtins/mediaBackdrop.js +0 -79
- package/dist/react/components/Quote.d.ts +0 -3
- package/dist/react/components/Quote.js +0 -12
- package/dist/react/components/Spacer.d.ts +0 -3
- package/dist/react/components/Spacer.js +0 -6
- package/dist/react/components/builtins/BackdropVideo.d.ts +0 -13
- package/dist/react/components/builtins/BackdropVideo.js +0 -16
- package/dist/react/components/builtins/Lightbox.d.ts +0 -45
- package/dist/react/components/builtins/Lightbox.js +0 -252
- package/dist/react/components/builtins/MediaBackdrop.d.ts +0 -14
- package/dist/react/components/builtins/MediaBackdrop.js +0 -61
|
@@ -22,12 +22,15 @@ export function cloudflareGatewayAdapter(options = {}) {
|
|
|
22
22
|
const key = clean(rawKey);
|
|
23
23
|
const keyHint = 'Set CF_AIG_TOKEN (the gateway token, for stored provider keys or unified billing) and/or a provider key in .env and restart the server.';
|
|
24
24
|
let setupProblem = null;
|
|
25
|
+
let missingKey = false;
|
|
25
26
|
if (!accountId || !gatewayId)
|
|
26
27
|
setupProblem = 'Set the Cloudflare account id and gateway id (CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_AI_GATEWAY_ID in .env).';
|
|
27
28
|
else if (!model)
|
|
28
29
|
setupProblem = 'Set the model for Cloudflare AI Gateway, for example "openai/gpt-5.2".';
|
|
29
|
-
else if (!token && !key)
|
|
30
|
+
else if (!token && !key) {
|
|
30
31
|
setupProblem = `No Cloudflare AI Gateway credentials. ${keyHint}`;
|
|
32
|
+
missingKey = true;
|
|
33
|
+
}
|
|
31
34
|
return createOpenAIFormatAdapter({
|
|
32
35
|
...transport,
|
|
33
36
|
name: 'cloudflare-gateway',
|
|
@@ -38,7 +41,10 @@ export function cloudflareGatewayAdapter(options = {}) {
|
|
|
38
41
|
...(key ? { Authorization: bearer(key) } : {}),
|
|
39
42
|
...(token ? { 'cf-aig-authorization': bearer(token) } : {}),
|
|
40
43
|
},
|
|
44
|
+
// A key from the AI settings is the gateway token (CF_AIG_TOKEN).
|
|
45
|
+
keyHeaders: (adminToken) => ({ 'cf-aig-authorization': bearer(adminToken) }),
|
|
41
46
|
ready: setupProblem === null,
|
|
47
|
+
missingKey,
|
|
42
48
|
setupProblem,
|
|
43
49
|
keyEnv: 'CF_AIG_TOKEN',
|
|
44
50
|
keyUrl: 'https://dash.cloudflare.com/?to=/:account/ai/ai-gateway',
|
|
@@ -36,7 +36,9 @@ export function cloudflareWorkersAIAdapter(options = {}) {
|
|
|
36
36
|
...(token ? { Authorization: bearer(token) } : {}),
|
|
37
37
|
...(gatewayId ? { 'cf-aig-gateway-id': gatewayId } : {}),
|
|
38
38
|
},
|
|
39
|
+
keyHeaders: (adminToken) => ({ Authorization: bearer(adminToken) }),
|
|
39
40
|
ready: setupProblem === null,
|
|
41
|
+
missingKey: Boolean(accountId) && !token,
|
|
40
42
|
setupProblem,
|
|
41
43
|
keyEnv: 'CLOUDFLARE_API_TOKEN',
|
|
42
44
|
keyUrl: 'https://dash.cloudflare.com/profile/api-tokens',
|
|
@@ -37,6 +37,7 @@ export function openAICompatibleAdapter(options = {}) {
|
|
|
37
37
|
url: chatCompletionsUrl(baseURL),
|
|
38
38
|
// No key is fine for local servers: a 401 then says what to set.
|
|
39
39
|
authHeaders: key ? { Authorization: bearer(key) } : {},
|
|
40
|
+
keyHeaders: (adminKey) => ({ Authorization: bearer(adminKey) }),
|
|
40
41
|
ready: setupProblem === null,
|
|
41
42
|
setupProblem,
|
|
42
43
|
keyEnv: keyEnv ?? null,
|
|
@@ -32,7 +32,9 @@ export function openRouterAdapter(options = {}) {
|
|
|
32
32
|
'X-Title': title,
|
|
33
33
|
'X-OpenRouter-Title': title,
|
|
34
34
|
},
|
|
35
|
+
keyHeaders: (key) => ({ Authorization: bearer(key) }),
|
|
35
36
|
ready: Boolean(apiKey),
|
|
37
|
+
missingKey: !apiKey,
|
|
36
38
|
setupProblem: apiKey ? null : `No OpenRouter API key. ${keyHint}`,
|
|
37
39
|
keyEnv: 'OPENROUTER_API_KEY',
|
|
38
40
|
keyUrl: 'https://openrouter.ai/keys',
|
package/dist/ai/config.d.ts
CHANGED
|
@@ -1,13 +1,33 @@
|
|
|
1
|
-
import type { AiClientConfig, AiImagesClientConfig, AiOptions } from './types.js';
|
|
1
|
+
import type { AiAdapter, AiClientConfig, AiImageAdapter, AiImagesClientConfig, AiOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* What the server knows at request time: which uses have a key in the AI settings, and the
|
|
4
|
+
* settings page (null when settings are off or the user may not open them).
|
|
5
|
+
*/
|
|
6
|
+
export type AiRequestState = {
|
|
7
|
+
keys?: {
|
|
8
|
+
chat?: boolean;
|
|
9
|
+
images?: boolean;
|
|
10
|
+
};
|
|
11
|
+
settingsUrl?: string | null;
|
|
12
|
+
};
|
|
13
|
+
/** The adapter can run: ready from its options, or only the key was missing and the AI settings have one. */
|
|
14
|
+
export declare function adapterReady(adapter: Pick<AiAdapter | AiImageAdapter, 'ready' | 'missingKey' | 'acceptsApiKey'>, settingsKey: boolean | string | undefined): boolean;
|
|
15
|
+
/** Appended to a setup problem when the AI settings can take the key. */
|
|
16
|
+
export declare const SETTINGS_KEY_HINT = "Or paste an API key in the admin: AI settings.";
|
|
17
|
+
/** The adapter's setup problem, plus the AI settings hint when a key there would fix it. */
|
|
18
|
+
export declare function setupProblemOf(adapter: Pick<AiAdapter | AiImageAdapter, 'label' | 'setupProblem' | 'missingKey' | 'acceptsApiKey'>, settings: boolean, what?: string): string;
|
|
2
19
|
/** `AiClientConfig.images`: null unless an image adapter is ready. */
|
|
3
|
-
export declare function imagesClientConfig(ai: AiOptions, endpoint: string): AiImagesClientConfig | null;
|
|
20
|
+
export declare function imagesClientConfig(ai: AiOptions, endpoint: string, state?: AiRequestState): AiImagesClientConfig | null;
|
|
4
21
|
/** Shown when `ai` is set without an adapter. */
|
|
5
22
|
export declare const NO_ADAPTER_PROBLEM = "No AI adapter is configured. Add one to the plugin options, for example ai: { adapter: openRouterAdapter({ apiKey: process.env.OPENROUTER_API_KEY }) } from \"payload-canvas/ai/openrouter\".";
|
|
6
23
|
/** Shown when a config still uses the removed `ai.provider` option. */
|
|
7
24
|
export declare const PROVIDER_REMOVED_PROBLEM = "The ai.provider option and the BUILDER_AI_* environment variables were replaced by adapters. Set ai.adapter instead, for example openRouterAdapter() from \"payload-canvas/ai/openrouter\". See docs/ai/providers.md.";
|
|
8
25
|
/** Why the assistant has no adapter: no adapter at all, or a config written for the old `provider` option. */
|
|
9
26
|
export declare function missingAdapterProblem(ai: AiOptions): string;
|
|
10
|
-
/**
|
|
11
|
-
|
|
27
|
+
/**
|
|
28
|
+
* `BuilderClientConfig.ai` for the editor. `state`: the AI settings at request time (the builder
|
|
29
|
+
* view passes it). Without it, readiness comes from the adapter options only.
|
|
30
|
+
*/
|
|
31
|
+
export declare function aiClientConfig(ai: AiOptions, endpoint: string, state?: AiRequestState): AiClientConfig;
|
|
12
32
|
/** The history identity the editor uses: `${adapter}:${model}`, the same as the server's. */
|
|
13
33
|
export declare function clientIdentity(config: Pick<AiClientConfig, 'adapter' | 'model'>): string;
|
package/dist/ai/config.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
// The plugin option `ai` as the editor sees it. Client-safe: the editor imports clientIdentity.
|
|
2
2
|
import { IMAGE_ASPECT_RATIOS } from './images/ratios.js';
|
|
3
|
+
/** The adapter can run: ready from its options, or only the key was missing and the AI settings have one. */
|
|
4
|
+
export function adapterReady(adapter, settingsKey) {
|
|
5
|
+
return adapter.ready || Boolean(adapter.missingKey && adapter.acceptsApiKey && settingsKey);
|
|
6
|
+
}
|
|
7
|
+
/** Appended to a setup problem when the AI settings can take the key. */
|
|
8
|
+
export const SETTINGS_KEY_HINT = 'Or paste an API key in the admin: AI settings.';
|
|
9
|
+
/** The adapter's setup problem, plus the AI settings hint when a key there would fix it. */
|
|
10
|
+
export function setupProblemOf(adapter, settings, what = '') {
|
|
11
|
+
const problem = adapter.setupProblem?.trim() || `${adapter.label}${what} is not set up.`;
|
|
12
|
+
return settings && adapter.missingKey && adapter.acceptsApiKey ? `${problem} ${SETTINGS_KEY_HINT}` : problem;
|
|
13
|
+
}
|
|
3
14
|
/** `AiClientConfig.images`: null unless an image adapter is ready. */
|
|
4
|
-
export function imagesClientConfig(ai, endpoint) {
|
|
15
|
+
export function imagesClientConfig(ai, endpoint, state = {}) {
|
|
5
16
|
const images = ai.images;
|
|
6
|
-
if (!images?.
|
|
17
|
+
if (!images || !adapterReady(images, state.keys?.images))
|
|
7
18
|
return null;
|
|
8
19
|
return { endpoint: `${endpoint}/image`, label: images.label, model: images.model, collection: ai.mediaCollection ?? 'media', aspectRatios: [...IMAGE_ASPECT_RATIOS] };
|
|
9
20
|
}
|
|
@@ -15,9 +26,13 @@ export const PROVIDER_REMOVED_PROBLEM = 'The ai.provider option and the BUILDER_
|
|
|
15
26
|
export function missingAdapterProblem(ai) {
|
|
16
27
|
return 'provider' in ai ? PROVIDER_REMOVED_PROBLEM : NO_ADAPTER_PROBLEM;
|
|
17
28
|
}
|
|
18
|
-
/**
|
|
19
|
-
|
|
29
|
+
/**
|
|
30
|
+
* `BuilderClientConfig.ai` for the editor. `state`: the AI settings at request time (the builder
|
|
31
|
+
* view passes it). Without it, readiness comes from the adapter options only.
|
|
32
|
+
*/
|
|
33
|
+
export function aiClientConfig(ai, endpoint, state = {}) {
|
|
20
34
|
const adapter = ai.adapter;
|
|
35
|
+
const settingsUrl = state.settingsUrl ?? null;
|
|
21
36
|
if (!adapter) {
|
|
22
37
|
return {
|
|
23
38
|
endpoint,
|
|
@@ -28,19 +43,23 @@ export function aiClientConfig(ai, endpoint) {
|
|
|
28
43
|
setupProblem: missingAdapterProblem(ai),
|
|
29
44
|
keyEnv: null,
|
|
30
45
|
keyUrl: null,
|
|
31
|
-
images: imagesClientConfig(ai, endpoint),
|
|
46
|
+
images: imagesClientConfig(ai, endpoint, state),
|
|
47
|
+
settingsUrl: null,
|
|
32
48
|
};
|
|
33
49
|
}
|
|
50
|
+
const ready = adapterReady(adapter, state.keys?.chat);
|
|
34
51
|
return {
|
|
35
52
|
endpoint,
|
|
36
53
|
adapter: adapter.name,
|
|
37
54
|
label: adapter.label,
|
|
38
55
|
model: adapter.model,
|
|
39
|
-
ready
|
|
40
|
-
setupProblem:
|
|
56
|
+
ready,
|
|
57
|
+
setupProblem: ready ? null : setupProblemOf(adapter, ai.settings !== false),
|
|
41
58
|
keyEnv: adapter.keyEnv ?? null,
|
|
42
59
|
keyUrl: adapter.keyUrl ?? null,
|
|
43
|
-
images: imagesClientConfig(ai, endpoint),
|
|
60
|
+
images: imagesClientConfig(ai, endpoint, state),
|
|
61
|
+
// Only when a key there makes the assistant work.
|
|
62
|
+
settingsUrl: adapter.acceptsApiKey ? settingsUrl : null,
|
|
44
63
|
};
|
|
45
64
|
}
|
|
46
65
|
/** The history identity the editor uses: `${adapter}:${model}`, the same as the server's. */
|
package/dist/ai/endpoint.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Endpoint, type PayloadRequest } from 'payload';
|
|
2
2
|
import type { BindingField, BlockDefinition, LocaleSettings, SectionDefinition, StyleTokens } from '../core/types.js';
|
|
3
3
|
import { type GenerateImageOutcome, type ImageService } from './images/service.js';
|
|
4
|
+
import { type AiSettingsRuntime } from './settings/index.js';
|
|
4
5
|
import { type MediaItem } from './tools.js';
|
|
5
6
|
import type { AiChatRequest, AiOptions } from './types.js';
|
|
6
7
|
/** Path of the assistant endpoints below the API route. */
|
|
@@ -14,8 +15,8 @@ export type AiEndpointOptions = {
|
|
|
14
15
|
}>;
|
|
15
16
|
blocks: BlockDefinition[];
|
|
16
17
|
sections: SectionDefinition[];
|
|
17
|
-
/** Theme tokens for the system prompt (colors, fonts, breakpoints). Null when unavailable. */
|
|
18
|
-
getTokens: () => Promise<StyleTokens | null>;
|
|
18
|
+
/** Theme tokens for the system prompt (colors, fonts, breakpoints, design variables). Null when unavailable. */
|
|
19
|
+
getTokens: (req?: PayloadRequest) => Promise<StyleTokens | null>;
|
|
19
20
|
/** The templates collection and the bindable fields. Null when no collection uses templates. */
|
|
20
21
|
templates: {
|
|
21
22
|
slug: string;
|
|
@@ -27,6 +28,8 @@ export type AiEndpointOptions = {
|
|
|
27
28
|
} | null;
|
|
28
29
|
/** Image generation, shared with the MCP tools (one hourly limit). Default: built from `ai`. */
|
|
29
30
|
images?: ImageService;
|
|
31
|
+
/** The AI settings global: its chat key is read on every request and wins over the adapter's own key. Null: off. */
|
|
32
|
+
settings?: AiSettingsRuntime | null;
|
|
30
33
|
/** Tests: replaces the update-access check (default: Payload's docAccessOperation). */
|
|
31
34
|
canUpdate?: (req: PayloadRequest, collection: string, id: string | number, field: string) => Promise<boolean>;
|
|
32
35
|
};
|
package/dist/ai/endpoint.js
CHANGED
|
@@ -6,12 +6,15 @@ import { addDataAndFileToRequest, docAccessOperation } from 'payload';
|
|
|
6
6
|
import { TEMPLATE_TARGET_FIELD } from '../core/bindings.js';
|
|
7
7
|
import { knownLocale } from '../core/locale.js';
|
|
8
8
|
import { indexLayout, isPlainObject, normalizeLayout } from '../core/tree.js';
|
|
9
|
+
import { canEditDesign } from '../live/contentMode.js';
|
|
9
10
|
import { SSE_HEADERS, sseFrame } from '../live/endpoints.js';
|
|
10
11
|
import { loadSavedSections } from '../plugin/sections.js';
|
|
11
|
-
import { missingAdapterProblem } from './config.js';
|
|
12
|
+
import { missingAdapterProblem, SETTINGS_KEY_HINT } from './config.js';
|
|
12
13
|
import { createImageService, generateImageToMedia } from './images/service.js';
|
|
13
14
|
import { adapterIdentity, runAgent } from './loop.js';
|
|
15
|
+
import { classesConfigOf, loadClasses } from '../classes/index.js';
|
|
14
16
|
import { breakpointsPx, contextText, systemPrompt } from './prompt.js';
|
|
17
|
+
import { withSettingsKey } from './settings/index.js';
|
|
15
18
|
import { toolDefinitions, Workspace } from './tools.js';
|
|
16
19
|
/** Path of the assistant endpoints below the API route. */
|
|
17
20
|
export const AI_PATH = '/builder/ai';
|
|
@@ -182,29 +185,22 @@ export function aiEndpoints(options) {
|
|
|
182
185
|
};
|
|
183
186
|
// Built once, in a fixed order: tools and system prompt are the cached prompt prefix.
|
|
184
187
|
const tools = toolDefinitions({ ...env, searchMedia: async () => [] });
|
|
185
|
-
// The system prompt is built once (the theme is read once) and reused byte for byte.
|
|
186
188
|
let prompt = null;
|
|
187
|
-
const getPrompt = () => {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
cache: true,
|
|
203
|
-
},
|
|
204
|
-
],
|
|
205
|
-
breakpoints: breakpointsPx(tokens),
|
|
206
|
-
}));
|
|
207
|
-
return prompt;
|
|
189
|
+
const getPrompt = async (req) => {
|
|
190
|
+
const tokens = await options.getTokens(req).catch(() => null);
|
|
191
|
+
const key = tokens ? JSON.stringify(tokens.variables ?? []) : 'none';
|
|
192
|
+
if (prompt?.key === key)
|
|
193
|
+
return prompt.value;
|
|
194
|
+
const system = systemPrompt({
|
|
195
|
+
blocks,
|
|
196
|
+
sections,
|
|
197
|
+
tokens,
|
|
198
|
+
bindings: Boolean(templates),
|
|
199
|
+
instructions: ai.instructions,
|
|
200
|
+
savedSections: savedSections !== null,
|
|
201
|
+
});
|
|
202
|
+
prompt = { key, value: { system: [{ text: system, cache: true }], breakpoints: breakpointsPx(tokens) } };
|
|
203
|
+
return prompt.value;
|
|
208
204
|
};
|
|
209
205
|
const chat = {
|
|
210
206
|
path: `${AI_PATH}/chat`,
|
|
@@ -263,17 +259,24 @@ export function aiEndpoints(options) {
|
|
|
263
259
|
if (foreign) {
|
|
264
260
|
return errorResponse(409, 'invalid_request', `This chat was started with another AI model (${foreign.provider}). The assistant now uses ${identity}. Start a new chat.`);
|
|
265
261
|
}
|
|
266
|
-
const { system, breakpoints } = await getPrompt();
|
|
262
|
+
const { system, breakpoints } = await getPrompt(req);
|
|
263
|
+
// The key from the AI settings, read now: a new key works without a restart.
|
|
264
|
+
const settings = options.settings ?? null;
|
|
265
|
+
const settingsKey = settings && adapter.acceptsApiKey ? await settings.keyFor(req.payload, 'chat') : undefined;
|
|
266
|
+
const model = withSettingsKey(adapter, settingsKey, settings ? SETTINGS_KEY_HINT : null);
|
|
267
267
|
const layout = normalizeLayout(body.layout);
|
|
268
268
|
// Localized layouts: the assistant reads and writes the editor's locale.
|
|
269
269
|
const localization = target.localization ?? null;
|
|
270
270
|
const locale = localization ? knownLocale(localization, body.locale) : null;
|
|
271
|
-
const
|
|
271
|
+
const contentOnly = !(await canEditDesign(req));
|
|
272
|
+
const workspace = new Workspace(layout, blocks, { localization, locale, contentOnly });
|
|
272
273
|
const selectedId = body.selectedId && indexLayout(layout).has(body.selectedId) ? body.selectedId : null;
|
|
273
274
|
const titleField = config?.admin?.useAsTitle;
|
|
274
275
|
const title = titleField && typeof doc[titleField] === 'string' ? doc[titleField] : undefined;
|
|
275
276
|
// Saved sections differ per user and change often: they go in the context, not the cached prompt.
|
|
276
277
|
const saved = savedSections ? await loadSavedSections(req, savedSections.slug) : [];
|
|
278
|
+
// Editable classes change at any time too.
|
|
279
|
+
const classes = classesConfigOf(req.payload) ? await loadClasses(req).catch(() => []) : [];
|
|
277
280
|
const isTemplate = templates !== null && body.collection === templates.slug;
|
|
278
281
|
const templateTarget = isTemplate
|
|
279
282
|
? (typeof doc[TEMPLATE_TARGET_FIELD] === 'string' ? doc[TEMPLATE_TARGET_FIELD] : (body.context?.collection ?? null))
|
|
@@ -297,6 +300,8 @@ export function aiEndpoints(options) {
|
|
|
297
300
|
templateTarget,
|
|
298
301
|
sample: isTemplate ? body.context : null,
|
|
299
302
|
savedSections: saved,
|
|
303
|
+
classes: classes.map(({ name, label, group }) => ({ name, ...(label ? { label } : {}), ...(group ? { group } : {}) })),
|
|
304
|
+
contentOnly,
|
|
300
305
|
}),
|
|
301
306
|
},
|
|
302
307
|
],
|
|
@@ -325,7 +330,7 @@ export function aiEndpoints(options) {
|
|
|
325
330
|
heartbeat = setInterval(() => write(': ping\n\n'), HEARTBEAT_MS);
|
|
326
331
|
try {
|
|
327
332
|
await runAgent({
|
|
328
|
-
adapter,
|
|
333
|
+
adapter: model,
|
|
329
334
|
system,
|
|
330
335
|
tools,
|
|
331
336
|
effort: ai.effort,
|
|
@@ -48,8 +48,12 @@ export function cloudflareWorkersAIImageAdapter(options = {}) {
|
|
|
48
48
|
setupProblem,
|
|
49
49
|
keyEnv: 'CLOUDFLARE_API_TOKEN',
|
|
50
50
|
keyUrl: 'https://dash.cloudflare.com/profile/api-tokens',
|
|
51
|
+
acceptsApiKey: true,
|
|
52
|
+
missingKey: Boolean(accountId) && !token,
|
|
51
53
|
async generate(request) {
|
|
52
|
-
|
|
54
|
+
// A token from the AI settings wins over the token from the options.
|
|
55
|
+
const authToken = clean(request.apiKey) ?? token;
|
|
56
|
+
if (setupProblem && !(accountId && authToken))
|
|
53
57
|
throw new AiImageError('auth', setupProblem);
|
|
54
58
|
const { width, height } = sizeForRatio(request.aspectRatio, longEdge, 16);
|
|
55
59
|
let body;
|
|
@@ -69,7 +73,7 @@ export function cloudflareWorkersAIImageAdapter(options = {}) {
|
|
|
69
73
|
body = { prompt: request.prompt, width, height, ...extraInput };
|
|
70
74
|
}
|
|
71
75
|
const url = `${CLOUDFLARE_API_URL}/accounts/${encodeURIComponent(accountId ?? '')}/ai/run/${model}`;
|
|
72
|
-
const headers = { Authorization: bearer(
|
|
76
|
+
const headers = { Authorization: bearer(authToken ?? ''), ...(gatewayId ? { 'cf-aig-gateway-id': gatewayId } : {}), ...transport.headers };
|
|
73
77
|
// One image per call: Workers AI models return one.
|
|
74
78
|
const images = [];
|
|
75
79
|
for (let i = 0; i < Math.max(1, request.n); i++) {
|
package/dist/ai/images/openai.js
CHANGED
|
@@ -51,7 +51,8 @@ export function openAIImageAdapter(options = {}) {
|
|
|
51
51
|
const keyHint = `Check ${keyEnv} in .env and restart the server.`;
|
|
52
52
|
const context = { label, model, keyHint };
|
|
53
53
|
// Only OpenAI itself needs a key for sure; a local server may not.
|
|
54
|
-
const
|
|
54
|
+
const keyMissing = Boolean(hostOf(base)) && official && !apiKey;
|
|
55
|
+
const setupProblem = !hostOf(base) ? 'Set baseURL to the API base URL, for example https://api.openai.com/v1.' : keyMissing ? `No OpenAI API key for image generation. Set ${keyEnv} in .env and restart the server.` : null;
|
|
55
56
|
const url = base.endsWith('/images/generations') ? base : `${base}/images/generations`;
|
|
56
57
|
return {
|
|
57
58
|
name: name ?? 'openai',
|
|
@@ -61,14 +62,18 @@ export function openAIImageAdapter(options = {}) {
|
|
|
61
62
|
setupProblem,
|
|
62
63
|
keyEnv,
|
|
63
64
|
keyUrl: official ? 'https://platform.openai.com/api-keys' : null,
|
|
65
|
+
acceptsApiKey: true,
|
|
66
|
+
missingKey: keyMissing,
|
|
64
67
|
async generate(request) {
|
|
65
|
-
|
|
68
|
+
// A key from the AI settings wins over the key from the options.
|
|
69
|
+
const key = clean(request.apiKey) ?? apiKey;
|
|
70
|
+
if (setupProblem && !(keyMissing && key))
|
|
66
71
|
throw new AiImageError('auth', setupProblem);
|
|
67
72
|
const sizeValue = size ? size(request.aspectRatio, model) : openAIImageSize(model, request.aspectRatio);
|
|
68
73
|
const response = await postImageRequest({
|
|
69
74
|
...transport,
|
|
70
75
|
url,
|
|
71
|
-
headers: { ...(
|
|
76
|
+
headers: { ...(key ? { Authorization: bearer(key) } : {}), ...transport.headers },
|
|
72
77
|
body: {
|
|
73
78
|
model,
|
|
74
79
|
prompt: request.prompt,
|
|
@@ -79,8 +79,12 @@ export function openRouterImageAdapter(options = {}) {
|
|
|
79
79
|
setupProblem: apiKey ? null : `No OpenRouter API key for image generation. ${keyHint}`,
|
|
80
80
|
keyEnv: 'OPENROUTER_API_KEY',
|
|
81
81
|
keyUrl: 'https://openrouter.ai/keys',
|
|
82
|
+
acceptsApiKey: true,
|
|
83
|
+
missingKey: !apiKey,
|
|
82
84
|
async generate(request) {
|
|
83
|
-
|
|
85
|
+
// A key from the AI settings wins over the key from the options.
|
|
86
|
+
const key = clean(request.apiKey) ?? apiKey;
|
|
87
|
+
if (!key)
|
|
84
88
|
throw new AiImageError('auth', `No OpenRouter API key. ${keyHint}`);
|
|
85
89
|
const supported = await modelParams();
|
|
86
90
|
const has = (name) => supported.params === null || supported.params.has(name);
|
|
@@ -99,7 +103,7 @@ export function openRouterImageAdapter(options = {}) {
|
|
|
99
103
|
...transport,
|
|
100
104
|
url: `${base}/images`,
|
|
101
105
|
headers: {
|
|
102
|
-
Authorization: bearer(
|
|
106
|
+
Authorization: bearer(key),
|
|
103
107
|
...(site ? { 'HTTP-Referer': site } : {}),
|
|
104
108
|
'X-Title': title,
|
|
105
109
|
'X-OpenRouter-Title': title,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { KVAdapter, PayloadRequest } from 'payload';
|
|
1
|
+
import type { KVAdapter, Payload, PayloadRequest } from 'payload';
|
|
2
2
|
import type { AiImageAdapter, AiImageAspectRatio, AiOptions } from '../types.js';
|
|
3
3
|
/** Key under `config.custom` where the plugin stores the ImageService (the MCP tools read it). */
|
|
4
4
|
export declare const AI_IMAGES_KEY = "websiteBuilderImages";
|
|
@@ -40,14 +40,20 @@ export type ImageService = {
|
|
|
40
40
|
limiter: HourlyLimiter;
|
|
41
41
|
/** Field name for the "generated by" note, or false. */
|
|
42
42
|
markerField: string | false;
|
|
43
|
+
/**
|
|
44
|
+
* Reads the image key from the AI settings global at request time. Undefined: none set. A key
|
|
45
|
+
* from there wins over the adapter's own key. Null or left out: settings are off.
|
|
46
|
+
*/
|
|
47
|
+
resolveKey?: ((payload: Payload) => Promise<string | undefined>) | null;
|
|
43
48
|
};
|
|
44
49
|
/**
|
|
45
50
|
* `store`: where the hourly counts live. Default: the request's `payload.kv`.
|
|
46
51
|
* `now`: the clock, for tests.
|
|
47
52
|
*/
|
|
48
|
-
export declare function createImageService(ai: Pick<AiOptions, 'images' | 'imageLimits' | 'mediaCollection' | 'imageMarkerField'>, { now, store }?: {
|
|
53
|
+
export declare function createImageService(ai: Pick<AiOptions, 'images' | 'imageLimits' | 'mediaCollection' | 'imageMarkerField'>, { now, store, resolveKey }?: {
|
|
49
54
|
now?: () => number;
|
|
50
55
|
store?: ImageCountStore;
|
|
56
|
+
resolveKey?: ImageService['resolveKey'];
|
|
51
57
|
}): ImageService;
|
|
52
58
|
/** The plugin's ImageService, or null when the plugin has no `ai` option. */
|
|
53
59
|
export declare function imageServiceOf(payload: {
|
|
@@ -55,8 +61,8 @@ export declare function imageServiceOf(payload: {
|
|
|
55
61
|
custom?: Record<string, unknown>;
|
|
56
62
|
};
|
|
57
63
|
}): ImageService | null;
|
|
58
|
-
/** A setup problem, or null when the service can generate. */
|
|
59
|
-
export declare function imagesSetupProblem(service: ImageService | null): string | null;
|
|
64
|
+
/** A setup problem, or null when the service can generate. `settingsKey`: the key from the AI settings, if any. */
|
|
65
|
+
export declare function imagesSetupProblem(service: ImageService | null, settingsKey?: string): string | null;
|
|
60
66
|
/** One saved image, as the tools and the editor see it. */
|
|
61
67
|
export type GeneratedMedia = {
|
|
62
68
|
id: string | number;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// the request's user. Shared by the assistant tool, the editor's Generate action (endpoint) and the
|
|
3
3
|
// MCP tool, so they share one hourly limit per user, kept in Payload's KV store. Server only.
|
|
4
4
|
import { isPlainObject } from '../../core/tree.js';
|
|
5
|
+
import { adapterReady, setupProblemOf } from '../config.js';
|
|
5
6
|
import { AiImageError, IMAGE_ASPECT_RATIOS, isAspectRatio } from './shared.js';
|
|
6
7
|
/** Key under `config.custom` where the plugin stores the ImageService (the MCP tools read it). */
|
|
7
8
|
export const AI_IMAGES_KEY = 'websiteBuilderImages';
|
|
@@ -103,7 +104,7 @@ const positive = (value, fallback) => (typeof value === 'number' && Number.isFin
|
|
|
103
104
|
* `store`: where the hourly counts live. Default: the request's `payload.kv`.
|
|
104
105
|
* `now`: the clock, for tests.
|
|
105
106
|
*/
|
|
106
|
-
export function createImageService(ai, { now, store } = {}) {
|
|
107
|
+
export function createImageService(ai, { now, store, resolveKey } = {}) {
|
|
107
108
|
const limits = ai.imageLimits ?? {};
|
|
108
109
|
return {
|
|
109
110
|
adapter: ai.images ?? null,
|
|
@@ -111,21 +112,34 @@ export function createImageService(ai, { now, store } = {}) {
|
|
|
111
112
|
perRequest: positive(limits.perRequest, DEFAULT_IMAGES_PER_REQUEST),
|
|
112
113
|
limiter: new HourlyLimiter(positive(limits.perHour, DEFAULT_IMAGES_PER_HOUR), now, store),
|
|
113
114
|
markerField: ai.imageMarkerField === undefined ? 'generatedBy' : ai.imageMarkerField,
|
|
115
|
+
resolveKey: resolveKey ?? null,
|
|
114
116
|
};
|
|
115
117
|
}
|
|
116
118
|
/** The plugin's ImageService, or null when the plugin has no `ai` option. */
|
|
117
119
|
export function imageServiceOf(payload) {
|
|
118
120
|
return payload.config.custom?.[AI_IMAGES_KEY] ?? null;
|
|
119
121
|
}
|
|
120
|
-
/** A setup problem, or null when the service can generate. */
|
|
121
|
-
export function imagesSetupProblem(service) {
|
|
122
|
+
/** A setup problem, or null when the service can generate. `settingsKey`: the key from the AI settings, if any. */
|
|
123
|
+
export function imagesSetupProblem(service, settingsKey) {
|
|
122
124
|
const adapter = service?.adapter;
|
|
123
125
|
if (!adapter)
|
|
124
126
|
return IMAGES_NOT_CONFIGURED;
|
|
125
|
-
if (!adapter
|
|
126
|
-
return `${adapter
|
|
127
|
+
if (!adapterReady(adapter, settingsKey))
|
|
128
|
+
return `${setupProblemOf(adapter, Boolean(service?.resolveKey), ' image generation')} See docs/ai/images.md.`;
|
|
127
129
|
return null;
|
|
128
130
|
}
|
|
131
|
+
/** The image key from the AI settings for this request. Undefined when settings are off, nothing is set, or the read fails. */
|
|
132
|
+
async function settingsKeyOf(req, service) {
|
|
133
|
+
if (!req.user || !service?.adapter?.acceptsApiKey || !service.resolveKey)
|
|
134
|
+
return undefined;
|
|
135
|
+
try {
|
|
136
|
+
return await service.resolveKey(req.payload);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
req.payload.logger.warn({ err: error }, 'website builder: could not read the image key from the AI settings');
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
129
143
|
const failure = (code, status, message) => ({ ok: false, code, status, message });
|
|
130
144
|
const str = (value) => (typeof value === 'string' && value ? value : null);
|
|
131
145
|
const num = (value) => (typeof value === 'number' ? value : null);
|
|
@@ -164,7 +178,9 @@ function userKey(req) {
|
|
|
164
178
|
* (`overrideAccess: false`). Never throws.
|
|
165
179
|
*/
|
|
166
180
|
export async function generateImageToMedia(req, service, input) {
|
|
167
|
-
|
|
181
|
+
// Read at request time: a key pasted in the AI settings works without a restart.
|
|
182
|
+
const settingsKey = await settingsKeyOf(req, service);
|
|
183
|
+
const problem = imagesSetupProblem(service, settingsKey);
|
|
168
184
|
if (problem || !service?.adapter)
|
|
169
185
|
return failure('not_configured', 501, problem ?? IMAGES_NOT_CONFIGURED);
|
|
170
186
|
const adapter = service.adapter;
|
|
@@ -230,7 +246,7 @@ export async function generateImageToMedia(req, service, input) {
|
|
|
230
246
|
const started = Date.now();
|
|
231
247
|
let result;
|
|
232
248
|
try {
|
|
233
|
-
result = await adapter.generate({ prompt, aspectRatio, n: 1, signal: input.signal });
|
|
249
|
+
result = await adapter.generate({ prompt, aspectRatio, n: 1, signal: input.signal, ...(settingsKey ? { apiKey: settingsKey } : {}) });
|
|
234
250
|
}
|
|
235
251
|
catch (error) {
|
|
236
252
|
await giveBack();
|
|
@@ -26,7 +26,14 @@ export type OpenAIFormatAdapterOptions = OpenAIFormatTransportOptions & {
|
|
|
26
26
|
url: string;
|
|
27
27
|
/** Credential headers (Authorization, …). Merged before `headers`. Never logged. */
|
|
28
28
|
authHeaders?: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* The credential headers for a key from the AI settings (`AiModelRequest.apiKey`). They replace
|
|
31
|
+
* the same headers of `authHeaders` for that request. Without it the adapter ignores `apiKey`.
|
|
32
|
+
*/
|
|
33
|
+
keyHeaders?: (apiKey: string) => Record<string, string>;
|
|
29
34
|
ready?: boolean;
|
|
35
|
+
/** `ready` is false only because the key is missing: a request with `apiKey` runs anyway. */
|
|
36
|
+
missingKey?: boolean;
|
|
30
37
|
setupProblem?: string | null;
|
|
31
38
|
keyEnv?: string | null;
|
|
32
39
|
keyUrl?: string | null;
|
package/dist/ai/openai-format.js
CHANGED
|
@@ -449,10 +449,17 @@ export function createOpenAIFormatAdapter(options) {
|
|
|
449
449
|
const idleMs = options.idleTimeoutMs ?? DEFAULT_IDLE_TIMEOUT_MS;
|
|
450
450
|
const maxRetries = options.maxRetries ?? 2;
|
|
451
451
|
const baseDelay = options.retryDelayMs ?? 1000;
|
|
452
|
-
|
|
452
|
+
/** The request headers. A key from the AI settings replaces the key from the options. */
|
|
453
|
+
const headersFor = (apiKey) => ({
|
|
454
|
+
'Content-Type': 'application/json',
|
|
455
|
+
Accept: 'text/event-stream',
|
|
456
|
+
...options.authHeaders,
|
|
457
|
+
...(apiKey && options.keyHeaders ? options.keyHeaders(apiKey) : {}),
|
|
458
|
+
...options.headers,
|
|
459
|
+
});
|
|
453
460
|
let includeUsage = options.includeUsage ?? true;
|
|
454
461
|
/** One HTTP attempt. The returned controller also stops the body read (idle timeout, abort). */
|
|
455
|
-
const attempt = async (body, signal) => {
|
|
462
|
+
const attempt = async (body, headers, signal) => {
|
|
456
463
|
if (signal?.aborted)
|
|
457
464
|
throw abortError();
|
|
458
465
|
const controller = new AbortController();
|
|
@@ -484,6 +491,7 @@ export function createOpenAIFormatAdapter(options) {
|
|
|
484
491
|
/** Sends the request, retrying 408 / 429 / 5xx / network errors with backoff. */
|
|
485
492
|
const send = async (request) => {
|
|
486
493
|
const tools = chatTools(request.tools);
|
|
494
|
+
const headers = headersFor(clean(request.apiKey));
|
|
487
495
|
for (let retry = 0;; retry++) {
|
|
488
496
|
const body = {
|
|
489
497
|
model: options.model,
|
|
@@ -496,7 +504,7 @@ export function createOpenAIFormatAdapter(options) {
|
|
|
496
504
|
};
|
|
497
505
|
let failure;
|
|
498
506
|
try {
|
|
499
|
-
const sent = await attempt(body, request.signal);
|
|
507
|
+
const sent = await attempt(body, headers, request.signal);
|
|
500
508
|
if (sent.response.ok && sent.response.body)
|
|
501
509
|
return sent;
|
|
502
510
|
sent.cleanup();
|
|
@@ -528,9 +536,13 @@ export function createOpenAIFormatAdapter(options) {
|
|
|
528
536
|
setupProblem: options.setupProblem ?? null,
|
|
529
537
|
keyEnv: options.keyEnv ?? null,
|
|
530
538
|
keyUrl: options.keyUrl ?? null,
|
|
539
|
+
acceptsApiKey: Boolean(options.keyHeaders),
|
|
540
|
+
missingKey: options.ready === false && Boolean(options.missingKey),
|
|
531
541
|
async *stream(request) {
|
|
532
|
-
// Missing key or config: say what to set, without a network call.
|
|
533
|
-
|
|
542
|
+
// Missing key or config: say what to set, without a network call. A key from the AI settings
|
|
543
|
+
// is enough when only the key was missing.
|
|
544
|
+
const keyFromSettings = Boolean(options.keyHeaders && clean(request.apiKey));
|
|
545
|
+
if (options.ready === false && !(options.missingKey && keyFromSettings)) {
|
|
534
546
|
yield { type: 'error', code: 'auth', message: options.setupProblem || `${options.label} is not set up.` };
|
|
535
547
|
return;
|
|
536
548
|
}
|
package/dist/ai/prompt.d.ts
CHANGED
|
@@ -37,12 +37,20 @@ export type ContextInput = {
|
|
|
37
37
|
sample?: TemplateContext | null;
|
|
38
38
|
/** Saved sections the user can read (people made them on this site). Not in the cached system prompt. */
|
|
39
39
|
savedSections?: SectionDefinition[];
|
|
40
|
+
/** The editable classes (the classes collection). They change at any time, so they go here, not in the cached prompt. */
|
|
41
|
+
classes?: Array<{
|
|
42
|
+
name: string;
|
|
43
|
+
label?: string;
|
|
44
|
+
group?: string;
|
|
45
|
+
}>;
|
|
40
46
|
/** Localized layouts: the locale the user edits, and how many props still show the fallback language. */
|
|
41
47
|
locale?: {
|
|
42
48
|
settings: LocaleSettings;
|
|
43
49
|
locale: string;
|
|
44
50
|
untranslated: number;
|
|
45
51
|
} | null;
|
|
52
|
+
/** Content mode: the user may change only content (core/contentMode.ts). */
|
|
53
|
+
contentOnly?: boolean;
|
|
46
54
|
};
|
|
47
55
|
/** A short, JSON-safe summary of a document: strings cut, rich text as plain text, few array items. */
|
|
48
56
|
export declare function summarizeDoc(value: unknown, depth?: number): unknown;
|