@btst/stack 3.0.0-rc.2 → 3.0.0-rc.4
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 +118 -38
- package/dist/api/index.cjs +133 -29
- package/dist/api/index.d.cts +14 -32
- package/dist/api/index.d.mts +14 -32
- package/dist/api/index.d.ts +14 -32
- package/dist/api/index.mjs +133 -28
- package/dist/authorization/client.cjs +154 -0
- package/dist/authorization/client.d.cts +70 -0
- package/dist/authorization/client.d.mts +70 -0
- package/dist/authorization/client.d.ts +70 -0
- package/dist/authorization/client.mjs +152 -0
- package/dist/authorization/index.cjs +371 -0
- package/dist/authorization/index.d.cts +201 -0
- package/dist/authorization/index.d.mts +201 -0
- package/dist/authorization/index.d.ts +201 -0
- package/dist/authorization/index.mjs +365 -0
- package/dist/authorization/remote.cjs +117 -0
- package/dist/authorization/remote.d.cts +79 -0
- package/dist/authorization/remote.d.mts +79 -0
- package/dist/authorization/remote.d.ts +79 -0
- package/dist/authorization/remote.mjs +111 -0
- package/dist/authorization/server.cjs +77 -0
- package/dist/authorization/server.d.cts +51 -0
- package/dist/authorization/server.d.mts +51 -0
- package/dist/authorization/server.d.ts +51 -0
- package/dist/authorization/server.mjs +73 -0
- package/dist/client/components/index.cjs +1 -0
- package/dist/client/components/index.d.cts +23 -6
- package/dist/client/components/index.d.mts +23 -6
- package/dist/client/components/index.d.ts +23 -6
- package/dist/client/components/index.mjs +1 -1
- package/dist/client/hooks/index.cjs +8 -0
- package/dist/client/hooks/index.d.cts +25 -0
- package/dist/client/hooks/index.d.mts +25 -0
- package/dist/client/hooks/index.d.ts +25 -0
- package/dist/client/hooks/index.mjs +2 -0
- package/dist/client/index.cjs +38 -7
- package/dist/client/index.d.cts +30 -100
- package/dist/client/index.d.mts +30 -100
- package/dist/client/index.d.ts +30 -100
- package/dist/client/index.mjs +38 -7
- package/dist/client/server.cjs +96 -0
- package/dist/client/server.d.cts +57 -0
- package/dist/client/server.d.mts +57 -0
- package/dist/client/server.d.ts +57 -0
- package/dist/client/server.mjs +92 -0
- package/dist/components/auto-form/index.d.cts +2 -2
- package/dist/components/auto-form/index.d.mts +2 -2
- package/dist/components/auto-form/index.d.ts +2 -2
- package/dist/components/form-builder/index.d.cts +1 -1
- package/dist/components/form-builder/index.d.mts +1 -1
- package/dist/components/form-builder/index.d.ts +1 -1
- package/dist/components/stepped-auto-form/index.d.cts +1 -1
- package/dist/components/stepped-auto-form/index.d.mts +1 -1
- package/dist/components/stepped-auto-form/index.d.ts +1 -1
- package/dist/context/index.cjs +8 -2
- package/dist/context/index.d.cts +111 -89
- package/dist/context/index.d.mts +111 -89
- package/dist/context/index.d.ts +111 -89
- package/dist/context/index.mjs +3 -1
- package/dist/index.cjs +1 -2
- package/dist/index.d.cts +8 -3
- package/dist/index.d.mts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.mjs +1 -1
- package/dist/next/index.d.cts +19 -7
- package/dist/next/index.d.mts +19 -7
- package/dist/next/index.d.ts +19 -7
- package/dist/next/server.cjs +7 -0
- package/dist/next/server.d.cts +56 -0
- package/dist/next/server.d.mts +56 -0
- package/dist/next/server.d.ts +56 -0
- package/dist/next/server.mjs +1 -0
- package/dist/packages/stack/src/authorization/json.cjs +57 -0
- package/dist/packages/stack/src/authorization/json.mjs +55 -0
- package/dist/packages/stack/src/client/components/compose.cjs +91 -9
- package/dist/packages/stack/src/client/components/compose.mjs +92 -11
- package/dist/packages/stack/src/client/runtime.cjs +295 -0
- package/dist/packages/stack/src/client/runtime.mjs +293 -0
- package/dist/packages/stack/src/context/auth.cjs +141 -73
- package/dist/packages/stack/src/context/auth.mjs +139 -73
- package/dist/packages/stack/src/context/provider.cjs +11 -5
- package/dist/packages/stack/src/context/provider.mjs +11 -5
- package/dist/packages/stack/src/context/router.cjs +9 -0
- package/dist/packages/stack/src/context/router.mjs +7 -0
- package/dist/packages/stack/src/context/site-navigation.cjs +40 -0
- package/dist/packages/stack/src/context/site-navigation.mjs +38 -0
- package/dist/packages/stack/src/next/layout.cjs +27 -0
- package/dist/packages/stack/src/next/layout.mjs +25 -0
- package/dist/packages/stack/src/plugin-registration.cjs +59 -0
- package/dist/packages/stack/src/plugin-registration.mjs +57 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/lifecycle-migrations.cjs +18 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/lifecycle-migrations.mjs +16 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/operations.cjs +1341 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/operations.mjs +1333 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/plugin.cjs +82 -640
- package/dist/packages/stack/src/plugins/ai-chat/api/plugin.mjs +78 -641
- package/dist/packages/stack/src/plugins/ai-chat/api/serializers.cjs +23 -0
- package/dist/packages/stack/src/plugins/ai-chat/api/serializers.mjs +20 -0
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-input.cjs +183 -111
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-input.mjs +187 -115
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-interface.cjs +562 -116
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-interface.mjs +567 -121
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-layout.cjs +6 -6
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-layout.mjs +6 -6
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-message.cjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-message.mjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-sidebar.cjs +45 -29
- package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-sidebar.mjs +46 -30
- package/dist/packages/stack/src/plugins/ai-chat/client/components/pages/404-page.cjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/pages/404-page.mjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/pages/chat-page.cjs +46 -7
- package/dist/packages/stack/src/plugins/ai-chat/client/components/pages/chat-page.internal.cjs +5 -3
- package/dist/packages/stack/src/plugins/ai-chat/client/components/pages/chat-page.internal.mjs +5 -3
- package/dist/packages/stack/src/plugins/ai-chat/client/components/pages/chat-page.mjs +48 -9
- package/dist/packages/stack/src/plugins/ai-chat/client/components/shared/default-error.cjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/shared/default-error.mjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/tool-call-display.cjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/components/tool-call-display.mjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/hooks/ai-chat-resource.cjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/hooks/ai-chat-resource.mjs +1 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/hooks/chat-hooks.cjs +179 -19
- package/dist/packages/stack/src/plugins/ai-chat/client/hooks/chat-hooks.mjs +180 -21
- package/dist/packages/stack/src/plugins/ai-chat/client/navigation.cjs +11 -0
- package/dist/packages/stack/src/plugins/ai-chat/client/navigation.mjs +9 -0
- package/dist/packages/stack/src/plugins/ai-chat/client/overrides.cjs +24 -0
- package/dist/packages/stack/src/plugins/ai-chat/client/overrides.mjs +21 -1
- package/dist/packages/stack/src/plugins/ai-chat/client/plugin.cjs +152 -82
- package/dist/packages/stack/src/plugins/ai-chat/client/plugin.mjs +152 -82
- package/dist/packages/stack/src/plugins/api/create-endpoint.cjs +27 -9
- package/dist/packages/stack/src/plugins/api/create-endpoint.mjs +27 -10
- package/dist/packages/stack/src/plugins/api/endpoint-inventory.cjs +125 -0
- package/dist/packages/stack/src/plugins/api/endpoint-inventory.mjs +123 -0
- package/dist/packages/stack/src/plugins/api/operation.cjs +208 -0
- package/dist/packages/stack/src/plugins/api/operation.mjs +198 -0
- package/dist/packages/stack/src/plugins/blog/api/lifecycle-migrations.cjs +17 -0
- package/dist/packages/stack/src/plugins/blog/api/lifecycle-migrations.mjs +15 -0
- package/dist/packages/stack/src/plugins/blog/api/mutations.cjs +10 -2
- package/dist/packages/stack/src/plugins/blog/api/mutations.mjs +10 -2
- package/dist/packages/stack/src/plugins/blog/api/operations.cjs +455 -0
- package/dist/packages/stack/src/plugins/blog/api/operations.mjs +448 -0
- package/dist/packages/stack/src/plugins/blog/api/plugin.cjs +51 -298
- package/dist/packages/stack/src/plugins/blog/api/plugin.mjs +55 -304
- package/dist/packages/stack/src/plugins/blog/client/components/forms/image-field.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/forms/image-field.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/forms/markdown-editor-with-overrides.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/forms/markdown-editor-with-overrides.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/forms/post-forms.cjs +82 -67
- package/dist/packages/stack/src/plugins/blog/client/components/forms/post-forms.mjs +84 -69
- package/dist/packages/stack/src/plugins/blog/client/components/pages/404-page.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/404-page.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/edit-post-page.cjs +22 -4
- package/dist/packages/stack/src/plugins/blog/client/components/pages/edit-post-page.internal.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/edit-post-page.internal.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/edit-post-page.mjs +23 -5
- package/dist/packages/stack/src/plugins/blog/client/components/pages/home-page.cjs +6 -2
- package/dist/packages/stack/src/plugins/blog/client/components/pages/home-page.internal.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/home-page.internal.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/home-page.mjs +6 -2
- package/dist/packages/stack/src/plugins/blog/client/components/pages/new-post-page.cjs +4 -2
- package/dist/packages/stack/src/plugins/blog/client/components/pages/new-post-page.internal.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/new-post-page.internal.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/new-post-page.mjs +4 -2
- package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.cjs +30 -3
- package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.internal.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.internal.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.mjs +31 -4
- package/dist/packages/stack/src/plugins/blog/client/components/pages/tag-page.cjs +4 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/tag-page.internal.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/tag-page.internal.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/pages/tag-page.mjs +4 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/collapsible-tag-list.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/collapsible-tag-list.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/default-error.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/default-error.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/on-this-page.cjs +3 -2
- package/dist/packages/stack/src/plugins/blog/client/components/shared/on-this-page.mjs +3 -2
- package/dist/packages/stack/src/plugins/blog/client/components/shared/page-wrapper.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/page-wrapper.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/post-card.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/post-card.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/posts-list.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/posts-list.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/recent-posts-carousel.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/recent-posts-carousel.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/components/shared/search-input.cjs +2 -2
- package/dist/packages/stack/src/plugins/blog/client/components/shared/search-input.mjs +1 -1
- package/dist/packages/stack/src/plugins/blog/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/blog/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/blog/client/hooks/blog-resource.cjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/hooks/blog-resource.mjs +2 -1
- package/dist/packages/stack/src/plugins/blog/client/plugin.cjs +169 -163
- package/dist/packages/stack/src/plugins/blog/client/plugin.mjs +169 -163
- package/dist/packages/stack/src/plugins/client/resource/hooks.cjs +31 -16
- package/dist/packages/stack/src/plugins/client/resource/hooks.mjs +31 -16
- package/dist/packages/stack/src/plugins/client/resource/internal.cjs +66 -52
- package/dist/packages/stack/src/plugins/client/resource/internal.mjs +66 -52
- package/dist/packages/stack/src/plugins/client/resource/use-form.cjs +20 -17
- package/dist/packages/stack/src/plugins/client/resource/use-form.mjs +20 -17
- package/dist/packages/stack/src/plugins/client/resource/use-select.cjs +39 -33
- package/dist/packages/stack/src/plugins/client/resource/use-select.mjs +39 -33
- package/dist/packages/stack/src/plugins/cms/api/lifecycle-migrations.cjs +13 -0
- package/dist/packages/stack/src/plugins/cms/api/lifecycle-migrations.mjs +11 -0
- package/dist/packages/stack/src/plugins/cms/api/operations.cjs +1763 -0
- package/dist/packages/stack/src/plugins/cms/api/operations.mjs +1756 -0
- package/dist/packages/stack/src/plugins/cms/api/plugin.cjs +165 -752
- package/dist/packages/stack/src/plugins/cms/api/plugin.mjs +164 -755
- package/dist/packages/stack/src/plugins/cms/client/components/forms/content-form.cjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/forms/content-form.mjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/forms/file-upload.cjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/forms/file-upload.mjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/forms/relation-field.cjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/forms/relation-field.mjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/inverse-relations-panel.cjs +23 -13
- package/dist/packages/stack/src/plugins/cms/client/components/inverse-relations-panel.mjs +24 -14
- package/dist/packages/stack/src/plugins/cms/client/components/pages/404-page.cjs +5 -4
- package/dist/packages/stack/src/plugins/cms/client/components/pages/404-page.mjs +6 -5
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.cjs +40 -7
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.cjs +15 -9
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.mjs +14 -8
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.mjs +41 -8
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-list-page.cjs +7 -1
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-list-page.internal.cjs +42 -29
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-list-page.internal.mjs +40 -27
- package/dist/packages/stack/src/plugins/cms/client/components/pages/content-list-page.mjs +7 -1
- package/dist/packages/stack/src/plugins/cms/client/components/pages/dashboard-page.cjs +4 -1
- package/dist/packages/stack/src/plugins/cms/client/components/pages/dashboard-page.internal.cjs +13 -7
- package/dist/packages/stack/src/plugins/cms/client/components/pages/dashboard-page.internal.mjs +12 -6
- package/dist/packages/stack/src/plugins/cms/client/components/pages/dashboard-page.mjs +4 -1
- package/dist/packages/stack/src/plugins/cms/client/components/shared/page-wrapper.cjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/components/shared/page-wrapper.mjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/cms/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/cms/client/hooks/cms-resource.cjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/hooks/cms-resource.mjs +2 -1
- package/dist/packages/stack/src/plugins/cms/client/overrides.cjs +26 -0
- package/dist/packages/stack/src/plugins/cms/client/overrides.mjs +24 -0
- package/dist/packages/stack/src/plugins/cms/client/plugin.cjs +102 -81
- package/dist/packages/stack/src/plugins/cms/client/plugin.mjs +103 -82
- package/dist/packages/stack/src/plugins/comments/api/getters.cjs +6 -2
- package/dist/packages/stack/src/plugins/comments/api/getters.mjs +6 -3
- package/dist/packages/stack/src/plugins/comments/api/lifecycle-migrations.cjs +18 -0
- package/dist/packages/stack/src/plugins/comments/api/lifecycle-migrations.mjs +16 -0
- package/dist/packages/stack/src/plugins/comments/api/mutations.cjs +179 -68
- package/dist/packages/stack/src/plugins/comments/api/mutations.mjs +179 -68
- package/dist/packages/stack/src/plugins/comments/api/operations.cjs +453 -0
- package/dist/packages/stack/src/plugins/comments/api/operations.mjs +445 -0
- package/dist/packages/stack/src/plugins/comments/api/plugin.cjs +51 -276
- package/dist/packages/stack/src/plugins/comments/api/plugin.mjs +48 -277
- package/dist/packages/stack/src/plugins/comments/client/components/comment-count.cjs +32 -5
- package/dist/packages/stack/src/plugins/comments/client/components/comment-count.mjs +34 -7
- package/dist/packages/stack/src/plugins/comments/client/components/comment-thread.cjs +160 -104
- package/dist/packages/stack/src/plugins/comments/client/components/comment-thread.mjs +161 -105
- package/dist/packages/stack/src/plugins/comments/client/components/pages/moderation-page.cjs +14 -2
- package/dist/packages/stack/src/plugins/comments/client/components/pages/moderation-page.internal.cjs +141 -71
- package/dist/packages/stack/src/plugins/comments/client/components/pages/moderation-page.internal.mjs +142 -72
- package/dist/packages/stack/src/plugins/comments/client/components/pages/moderation-page.mjs +14 -2
- package/dist/packages/stack/src/plugins/comments/client/components/pages/moderation-state.cjs +12 -0
- package/dist/packages/stack/src/plugins/comments/client/components/pages/moderation-state.mjs +9 -0
- package/dist/packages/stack/src/plugins/comments/client/components/pages/my-comments-page.cjs +2 -1
- package/dist/packages/stack/src/plugins/comments/client/components/pages/my-comments-page.internal.cjs +40 -26
- package/dist/packages/stack/src/plugins/comments/client/components/pages/my-comments-page.internal.mjs +40 -26
- package/dist/packages/stack/src/plugins/comments/client/components/pages/my-comments-page.mjs +2 -1
- package/dist/packages/stack/src/plugins/comments/client/components/pages/resource-comments-page.cjs +9 -1
- package/dist/packages/stack/src/plugins/comments/client/components/pages/resource-comments-page.internal.cjs +25 -20
- package/dist/packages/stack/src/plugins/comments/client/components/pages/resource-comments-page.internal.mjs +26 -21
- package/dist/packages/stack/src/plugins/comments/client/components/pages/resource-comments-page.mjs +9 -1
- package/dist/packages/stack/src/plugins/comments/client/components/shared/page-wrapper.cjs +2 -1
- package/dist/packages/stack/src/plugins/comments/client/components/shared/page-wrapper.mjs +2 -1
- package/dist/packages/stack/src/plugins/comments/client/components/shared/pagination.cjs +2 -1
- package/dist/packages/stack/src/plugins/comments/client/components/shared/pagination.mjs +2 -1
- package/dist/packages/stack/src/plugins/comments/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/comments/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/comments/client/hooks/use-comments.cjs +323 -290
- package/dist/packages/stack/src/plugins/comments/client/hooks/use-comments.mjs +325 -292
- package/dist/packages/stack/src/plugins/comments/client/localization/comments-thread.cjs +1 -0
- package/dist/packages/stack/src/plugins/comments/client/localization/comments-thread.mjs +1 -0
- package/dist/packages/stack/src/plugins/comments/client/plugin.cjs +78 -46
- package/dist/packages/stack/src/plugins/comments/client/plugin.mjs +80 -48
- package/dist/packages/stack/src/plugins/form-builder/api/getters.cjs +9 -0
- package/dist/packages/stack/src/plugins/form-builder/api/getters.mjs +9 -1
- package/dist/packages/stack/src/plugins/form-builder/api/lifecycle-migrations.cjs +15 -0
- package/dist/packages/stack/src/plugins/form-builder/api/lifecycle-migrations.mjs +13 -0
- package/dist/packages/stack/src/plugins/form-builder/api/operations.cjs +1093 -0
- package/dist/packages/stack/src/plugins/form-builder/api/operations.mjs +1082 -0
- package/dist/packages/stack/src/plugins/form-builder/api/plugin.cjs +97 -466
- package/dist/packages/stack/src/plugins/form-builder/api/plugin.mjs +92 -468
- package/dist/packages/stack/src/plugins/form-builder/api/query-key-defs.cjs +5 -0
- package/dist/packages/stack/src/plugins/form-builder/api/query-key-defs.mjs +5 -0
- package/dist/packages/stack/src/plugins/form-builder/client/components/forms/form-renderer.cjs +41 -11
- package/dist/packages/stack/src/plugins/form-builder/client/components/forms/form-renderer.mjs +42 -12
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/404-page.cjs +8 -5
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/404-page.mjs +9 -6
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-builder-page.cjs +36 -3
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-builder-page.internal.cjs +32 -11
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-builder-page.internal.mjs +35 -14
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-builder-page.mjs +37 -4
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-list-page.cjs +6 -1
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-list-page.internal.cjs +34 -26
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-list-page.internal.mjs +34 -26
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/form-list-page.mjs +6 -1
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.cjs +24 -7
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.cjs +72 -40
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.mjs +76 -44
- package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.mjs +25 -8
- package/dist/packages/stack/src/plugins/form-builder/client/components/shared/page-wrapper.cjs +2 -1
- package/dist/packages/stack/src/plugins/form-builder/client/components/shared/page-wrapper.mjs +2 -1
- package/dist/packages/stack/src/plugins/form-builder/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/form-builder/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/form-builder/client/hooks/form-builder-hooks.cjs +29 -0
- package/dist/packages/stack/src/plugins/form-builder/client/hooks/form-builder-hooks.mjs +28 -1
- package/dist/packages/stack/src/plugins/form-builder/client/hooks/form-builder-resource.cjs +2 -1
- package/dist/packages/stack/src/plugins/form-builder/client/hooks/form-builder-resource.mjs +2 -1
- package/dist/packages/stack/src/plugins/form-builder/client/plugin.cjs +113 -86
- package/dist/packages/stack/src/plugins/form-builder/client/plugin.mjs +114 -87
- package/dist/packages/stack/src/plugins/form-builder/schemas.cjs +9 -3
- package/dist/packages/stack/src/plugins/form-builder/schemas.mjs +9 -3
- package/dist/packages/stack/src/plugins/kanban/api/getters.cjs +47 -36
- package/dist/packages/stack/src/plugins/kanban/api/getters.mjs +47 -37
- package/dist/packages/stack/src/plugins/kanban/api/lifecycle-migrations.cjs +23 -0
- package/dist/packages/stack/src/plugins/kanban/api/lifecycle-migrations.mjs +21 -0
- package/dist/packages/stack/src/plugins/kanban/api/operations.cjs +1552 -0
- package/dist/packages/stack/src/plugins/kanban/api/operations.mjs +1543 -0
- package/dist/packages/stack/src/plugins/kanban/api/plugin.cjs +64 -631
- package/dist/packages/stack/src/plugins/kanban/api/plugin.mjs +62 -634
- package/dist/packages/stack/src/plugins/kanban/api/serializers.cjs +21 -0
- package/dist/packages/stack/src/plugins/kanban/api/serializers.mjs +21 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/forms/board-form.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/forms/board-form.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/forms/column-form.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/forms/column-form.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/forms/task-form.cjs +72 -54
- package/dist/packages/stack/src/plugins/kanban/client/components/forms/task-form.mjs +74 -56
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/404-page.cjs +4 -6
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/404-page.mjs +5 -7
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/board-page.cjs +22 -6
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/board-page.internal.cjs +82 -77
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/board-page.internal.mjs +83 -78
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/board-page.mjs +23 -7
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/boards-list-page.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/boards-list-page.internal.cjs +34 -24
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/boards-list-page.internal.mjs +35 -25
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/boards-list-page.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/new-board-page.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/new-board-page.internal.cjs +6 -9
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/new-board-page.internal.mjs +7 -10
- package/dist/packages/stack/src/plugins/kanban/client/components/pages/new-board-page.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/column-content.cjs +72 -45
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/column-content.mjs +73 -46
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/default-error.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/default-error.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/kanban-board.cjs +4 -4
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/kanban-board.mjs +4 -4
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/permission-access-any.cjs +23 -0
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/permission-access-any.mjs +21 -0
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/task-card.cjs +54 -17
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/task-card.mjs +55 -18
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/user-avatar.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/components/shared/user-avatar.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/kanban/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/kanban/client/hooks/kanban-hooks.cjs +38 -9
- package/dist/packages/stack/src/plugins/kanban/client/hooks/kanban-hooks.mjs +39 -10
- package/dist/packages/stack/src/plugins/kanban/client/hooks/kanban-resource.cjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/hooks/kanban-resource.mjs +2 -1
- package/dist/packages/stack/src/plugins/kanban/client/plugin.cjs +177 -104
- package/dist/packages/stack/src/plugins/kanban/client/plugin.mjs +178 -105
- package/dist/packages/stack/src/plugins/kanban/schemas.cjs +32 -23
- package/dist/packages/stack/src/plugins/kanban/schemas.mjs +33 -21
- package/dist/packages/stack/src/plugins/media/api/lifecycle-migrations.cjs +9 -0
- package/dist/packages/stack/src/plugins/media/api/lifecycle-migrations.mjs +7 -0
- package/dist/packages/stack/src/plugins/media/api/mutations.cjs +7 -2
- package/dist/packages/stack/src/plugins/media/api/mutations.mjs +7 -2
- package/dist/packages/stack/src/plugins/media/api/operations.cjs +1299 -0
- package/dist/packages/stack/src/plugins/media/api/operations.mjs +1290 -0
- package/dist/packages/stack/src/plugins/media/api/plugin.cjs +131 -508
- package/dist/packages/stack/src/plugins/media/api/plugin.mjs +127 -510
- package/dist/packages/stack/src/plugins/media/api/query-key-defs.cjs +26 -2
- package/dist/packages/stack/src/plugins/media/api/query-key-defs.mjs +25 -3
- package/dist/packages/stack/src/plugins/media/api/serializers.cjs +4 -2
- package/dist/packages/stack/src/plugins/media/api/serializers.mjs +4 -2
- package/dist/packages/stack/src/plugins/media/asset-url.cjs +13 -0
- package/dist/packages/stack/src/plugins/media/asset-url.mjs +11 -0
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/asset-card.cjs +10 -10
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/asset-card.mjs +12 -12
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/folder-tree.cjs +47 -27
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/folder-tree.mjs +49 -29
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/index.cjs +225 -180
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/index.mjs +228 -183
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/upload-tab.cjs +1 -8
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/upload-tab.mjs +2 -9
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/url-tab.cjs +0 -6
- package/dist/packages/stack/src/plugins/media/client/components/media-picker/url-tab.mjs +1 -7
- package/dist/packages/stack/src/plugins/media/client/components/pages/library-page.cjs +4 -2
- package/dist/packages/stack/src/plugins/media/client/components/pages/library-page.internal.cjs +92 -75
- package/dist/packages/stack/src/plugins/media/client/components/pages/library-page.internal.mjs +93 -76
- package/dist/packages/stack/src/plugins/media/client/components/pages/library-page.mjs +4 -2
- package/dist/packages/stack/src/plugins/media/client/components/upload-permission-check.cjs +52 -0
- package/dist/packages/stack/src/plugins/media/client/components/upload-permission-check.mjs +49 -0
- package/dist/packages/stack/src/plugins/media/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/media/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/media/client/hooks/media-resource.cjs +2 -1
- package/dist/packages/stack/src/plugins/media/client/hooks/media-resource.mjs +2 -1
- package/dist/packages/stack/src/plugins/media/client/hooks/use-media.cjs +214 -43
- package/dist/packages/stack/src/plugins/media/client/hooks/use-media.mjs +217 -46
- package/dist/packages/stack/src/plugins/media/client/plugin.cjs +122 -62
- package/dist/packages/stack/src/plugins/media/client/plugin.mjs +123 -63
- package/dist/packages/stack/src/plugins/media/client/upload.cjs +121 -52
- package/dist/packages/stack/src/plugins/media/client/upload.mjs +121 -53
- package/dist/packages/stack/src/plugins/media/db.cjs +8 -0
- package/dist/packages/stack/src/plugins/media/db.mjs +8 -0
- package/dist/packages/stack/src/plugins/open-api/api/generator.cjs +36 -5
- package/dist/packages/stack/src/plugins/open-api/api/generator.mjs +36 -5
- package/dist/packages/stack/src/plugins/open-api/api/plugin.cjs +22 -11
- package/dist/packages/stack/src/plugins/open-api/api/plugin.mjs +22 -11
- package/dist/packages/stack/src/plugins/route-docs/client/components/pages/docs-page.cjs +65 -34
- package/dist/packages/stack/src/plugins/route-docs/client/components/pages/docs-page.mjs +56 -25
- package/dist/packages/stack/src/plugins/route-docs/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/route-docs/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/route-docs/client/hooks.cjs +9 -8
- package/dist/packages/stack/src/plugins/route-docs/client/hooks.mjs +10 -9
- package/dist/packages/stack/src/plugins/route-docs/client/plugin.cjs +143 -75
- package/dist/packages/stack/src/plugins/route-docs/client/plugin.mjs +144 -74
- package/dist/packages/stack/src/plugins/route-docs/client/schema.cjs +26 -0
- package/dist/packages/stack/src/plugins/route-docs/client/schema.mjs +23 -0
- package/dist/packages/stack/src/plugins/route-docs/generator.cjs +7 -4
- package/dist/packages/stack/src/plugins/route-docs/generator.mjs +7 -4
- package/dist/packages/stack/src/plugins/ui-builder/client/components/page-renderer.cjs +41 -12
- package/dist/packages/stack/src/plugins/ui-builder/client/components/page-renderer.mjs +42 -13
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-builder-page.cjs +37 -3
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-builder-page.internal.cjs +32 -20
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-builder-page.internal.mjs +34 -22
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-builder-page.mjs +38 -4
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-list-page.cjs +8 -2
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-list-page.internal.cjs +37 -19
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-list-page.internal.mjs +38 -20
- package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-list-page.mjs +8 -2
- package/dist/packages/stack/src/plugins/ui-builder/client/components/shared/default-error.cjs +2 -1
- package/dist/packages/stack/src/plugins/ui-builder/client/components/shared/default-error.mjs +2 -1
- package/dist/packages/stack/src/plugins/ui-builder/client/components/shared/page-wrapper.cjs +2 -1
- package/dist/packages/stack/src/plugins/ui-builder/client/components/shared/page-wrapper.mjs +2 -1
- package/dist/packages/stack/src/plugins/ui-builder/client/constants.cjs +5 -0
- package/dist/packages/stack/src/plugins/ui-builder/client/constants.mjs +3 -0
- package/dist/packages/stack/src/plugins/ui-builder/client/hooks/ui-builder-resource.cjs +2 -1
- package/dist/packages/stack/src/plugins/ui-builder/client/hooks/ui-builder-resource.mjs +2 -1
- package/dist/packages/stack/src/plugins/ui-builder/client/overrides.cjs +8 -0
- package/dist/packages/stack/src/plugins/ui-builder/client/overrides.mjs +6 -0
- package/dist/packages/stack/src/plugins/ui-builder/client/plugin.cjs +93 -53
- package/dist/packages/stack/src/plugins/ui-builder/client/plugin.mjs +94 -54
- package/dist/packages/stack/src/plugins/utils.cjs +4 -12
- package/dist/packages/stack/src/plugins/utils.mjs +5 -12
- package/dist/packages/stack/src/react-router/layout.cjs +14 -0
- package/dist/packages/stack/src/react-router/layout.mjs +12 -0
- package/dist/packages/stack/src/react-router/page.cjs +10 -5
- package/dist/packages/stack/src/react-router/page.mjs +11 -6
- package/dist/packages/stack/src/shared/initial-identity.cjs +27 -0
- package/dist/packages/stack/src/shared/initial-identity.mjs +23 -0
- package/dist/packages/stack/src/tanstack/layout.cjs +10 -0
- package/dist/packages/stack/src/tanstack/layout.mjs +8 -0
- package/dist/packages/stack/src/tanstack/page.cjs +6 -2
- package/dist/packages/stack/src/tanstack/page.mjs +6 -2
- package/dist/plugins/ai-chat/api/index.cjs +10 -0
- package/dist/plugins/ai-chat/api/index.d.cts +31 -5
- package/dist/plugins/ai-chat/api/index.d.mts +31 -5
- package/dist/plugins/ai-chat/api/index.d.ts +31 -5
- package/dist/plugins/ai-chat/api/index.mjs +3 -1
- package/dist/plugins/ai-chat/client/components/index.d.cts +1 -1
- package/dist/plugins/ai-chat/client/components/index.d.mts +1 -1
- package/dist/plugins/ai-chat/client/components/index.d.ts +1 -1
- package/dist/plugins/ai-chat/client/hooks/index.cjs +1 -0
- package/dist/plugins/ai-chat/client/hooks/index.d.cts +14 -8
- package/dist/plugins/ai-chat/client/hooks/index.d.mts +14 -8
- package/dist/plugins/ai-chat/client/hooks/index.d.ts +14 -8
- package/dist/plugins/ai-chat/client/hooks/index.mjs +1 -1
- package/dist/plugins/ai-chat/client/index.d.cts +21 -25
- package/dist/plugins/ai-chat/client/index.d.mts +21 -25
- package/dist/plugins/ai-chat/client/index.d.ts +21 -25
- package/dist/plugins/ai-chat/permissions.cjs +90 -0
- package/dist/plugins/ai-chat/permissions.d.cts +84 -0
- package/dist/plugins/ai-chat/permissions.d.mts +84 -0
- package/dist/plugins/ai-chat/permissions.d.ts +84 -0
- package/dist/plugins/ai-chat/permissions.mjs +88 -0
- package/dist/plugins/ai-chat/query-keys.cjs +116 -18
- package/dist/plugins/ai-chat/query-keys.d.cts +6 -2
- package/dist/plugins/ai-chat/query-keys.d.mts +6 -2
- package/dist/plugins/ai-chat/query-keys.d.ts +6 -2
- package/dist/plugins/ai-chat/query-keys.mjs +116 -19
- package/dist/plugins/api/index.cjs +4 -0
- package/dist/plugins/api/index.d.cts +13 -18
- package/dist/plugins/api/index.d.mts +13 -18
- package/dist/plugins/api/index.d.ts +13 -18
- package/dist/plugins/api/index.mjs +1 -0
- package/dist/plugins/blog/api/index.cjs +9 -2
- package/dist/plugins/blog/api/index.d.cts +118 -4
- package/dist/plugins/blog/api/index.d.mts +118 -4
- package/dist/plugins/blog/api/index.d.ts +118 -4
- package/dist/plugins/blog/api/index.mjs +4 -1
- package/dist/plugins/blog/client/hooks/index.d.cts +2 -2
- package/dist/plugins/blog/client/hooks/index.d.mts +2 -2
- package/dist/plugins/blog/client/hooks/index.d.ts +2 -2
- package/dist/plugins/blog/client/index.d.cts +210 -226
- package/dist/plugins/blog/client/index.d.mts +210 -226
- package/dist/plugins/blog/client/index.d.ts +210 -226
- package/dist/plugins/blog/permissions.cjs +47 -0
- package/dist/plugins/blog/permissions.d.cts +49 -0
- package/dist/plugins/blog/permissions.d.mts +49 -0
- package/dist/plugins/blog/permissions.d.ts +49 -0
- package/dist/plugins/blog/permissions.mjs +45 -0
- package/dist/plugins/blog/query-keys.d.cts +7 -3
- package/dist/plugins/blog/query-keys.d.mts +7 -3
- package/dist/plugins/blog/query-keys.d.ts +7 -3
- package/dist/plugins/client/hooks/index.d.cts +2 -2
- package/dist/plugins/client/hooks/index.d.mts +2 -2
- package/dist/plugins/client/hooks/index.d.ts +2 -2
- package/dist/plugins/client/index.cjs +3 -0
- package/dist/plugins/client/index.d.cts +30 -10
- package/dist/plugins/client/index.d.mts +30 -10
- package/dist/plugins/client/index.d.ts +30 -10
- package/dist/plugins/client/index.mjs +3 -0
- package/dist/plugins/cms/api/index.cjs +7 -0
- package/dist/plugins/cms/api/index.d.cts +173 -4
- package/dist/plugins/cms/api/index.d.mts +173 -4
- package/dist/plugins/cms/api/index.d.ts +173 -4
- package/dist/plugins/cms/api/index.mjs +2 -0
- package/dist/plugins/cms/client/hooks/index.d.cts +1 -1
- package/dist/plugins/cms/client/hooks/index.d.mts +1 -1
- package/dist/plugins/cms/client/hooks/index.d.ts +1 -1
- package/dist/plugins/cms/client/index.d.cts +188 -184
- package/dist/plugins/cms/client/index.d.mts +188 -184
- package/dist/plugins/cms/client/index.d.ts +188 -184
- package/dist/plugins/cms/permissions.cjs +46 -0
- package/dist/plugins/cms/permissions.d.cts +42 -0
- package/dist/plugins/cms/permissions.d.mts +42 -0
- package/dist/plugins/cms/permissions.d.ts +42 -0
- package/dist/plugins/cms/permissions.mjs +44 -0
- package/dist/plugins/cms/query-keys.d.cts +4 -4
- package/dist/plugins/cms/query-keys.d.mts +4 -4
- package/dist/plugins/cms/query-keys.d.ts +4 -4
- package/dist/plugins/comments/api/index.cjs +10 -0
- package/dist/plugins/comments/api/index.d.cts +54 -18
- package/dist/plugins/comments/api/index.d.mts +54 -18
- package/dist/plugins/comments/api/index.d.ts +54 -18
- package/dist/plugins/comments/api/index.mjs +3 -0
- package/dist/plugins/comments/client/components/index.d.cts +2 -2
- package/dist/plugins/comments/client/components/index.d.mts +2 -2
- package/dist/plugins/comments/client/components/index.d.ts +2 -2
- package/dist/plugins/comments/client/hooks/index.d.cts +12 -18
- package/dist/plugins/comments/client/hooks/index.d.mts +12 -18
- package/dist/plugins/comments/client/hooks/index.d.ts +12 -18
- package/dist/plugins/comments/client/index.d.cts +96 -114
- package/dist/plugins/comments/client/index.d.mts +96 -114
- package/dist/plugins/comments/client/index.d.ts +96 -114
- package/dist/plugins/comments/permissions.cjs +70 -0
- package/dist/plugins/comments/permissions.d.cts +76 -0
- package/dist/plugins/comments/permissions.d.mts +76 -0
- package/dist/plugins/comments/permissions.d.ts +76 -0
- package/dist/plugins/comments/permissions.mjs +68 -0
- package/dist/plugins/comments/query-keys.cjs +1 -1
- package/dist/plugins/comments/query-keys.d.cts +16 -19
- package/dist/plugins/comments/query-keys.d.mts +16 -19
- package/dist/plugins/comments/query-keys.d.ts +16 -19
- package/dist/plugins/comments/query-keys.mjs +1 -1
- package/dist/plugins/form-builder/api/index.cjs +8 -0
- package/dist/plugins/form-builder/api/index.d.cts +115 -4
- package/dist/plugins/form-builder/api/index.d.mts +115 -4
- package/dist/plugins/form-builder/api/index.d.ts +115 -4
- package/dist/plugins/form-builder/api/index.mjs +4 -1
- package/dist/plugins/form-builder/client/components/index.d.cts +6 -2
- package/dist/plugins/form-builder/client/components/index.d.mts +6 -2
- package/dist/plugins/form-builder/client/components/index.d.ts +6 -2
- package/dist/plugins/form-builder/client/hooks/index.cjs +2 -0
- package/dist/plugins/form-builder/client/hooks/index.d.cts +34 -8
- package/dist/plugins/form-builder/client/hooks/index.d.mts +34 -8
- package/dist/plugins/form-builder/client/hooks/index.d.ts +34 -8
- package/dist/plugins/form-builder/client/hooks/index.mjs +1 -1
- package/dist/plugins/form-builder/client/index.d.cts +153 -174
- package/dist/plugins/form-builder/client/index.d.mts +153 -174
- package/dist/plugins/form-builder/client/index.d.ts +153 -174
- package/dist/plugins/form-builder/permissions.cjs +95 -0
- package/dist/plugins/form-builder/permissions.d.cts +94 -0
- package/dist/plugins/form-builder/permissions.d.mts +94 -0
- package/dist/plugins/form-builder/permissions.d.ts +94 -0
- package/dist/plugins/form-builder/permissions.mjs +93 -0
- package/dist/plugins/form-builder/query-keys.cjs +11 -4
- package/dist/plugins/form-builder/query-keys.d.cts +38 -12
- package/dist/plugins/form-builder/query-keys.d.mts +38 -12
- package/dist/plugins/form-builder/query-keys.d.ts +38 -12
- package/dist/plugins/form-builder/query-keys.mjs +11 -4
- package/dist/plugins/kanban/api/index.cjs +9 -0
- package/dist/plugins/kanban/api/index.d.cts +137 -5
- package/dist/plugins/kanban/api/index.d.mts +137 -5
- package/dist/plugins/kanban/api/index.d.ts +137 -5
- package/dist/plugins/kanban/api/index.mjs +5 -2
- package/dist/plugins/kanban/client/components/index.d.cts +18 -10
- package/dist/plugins/kanban/client/components/index.d.mts +18 -10
- package/dist/plugins/kanban/client/components/index.d.ts +18 -10
- package/dist/plugins/kanban/client/hooks/index.d.cts +15 -7
- package/dist/plugins/kanban/client/hooks/index.d.mts +15 -7
- package/dist/plugins/kanban/client/hooks/index.d.ts +15 -7
- package/dist/plugins/kanban/client/index.d.cts +32 -28
- package/dist/plugins/kanban/client/index.d.mts +32 -28
- package/dist/plugins/kanban/client/index.d.ts +32 -28
- package/dist/plugins/kanban/permissions.cjs +101 -0
- package/dist/plugins/kanban/permissions.d.cts +109 -0
- package/dist/plugins/kanban/permissions.d.mts +109 -0
- package/dist/plugins/kanban/permissions.d.ts +109 -0
- package/dist/plugins/kanban/permissions.mjs +99 -0
- package/dist/plugins/kanban/query-keys.cjs +14 -15
- package/dist/plugins/kanban/query-keys.d.cts +63 -42
- package/dist/plugins/kanban/query-keys.d.mts +63 -42
- package/dist/plugins/kanban/query-keys.d.ts +63 -42
- package/dist/plugins/kanban/query-keys.mjs +14 -15
- package/dist/plugins/media/api/adapters/local.d.cts +1 -1
- package/dist/plugins/media/api/adapters/local.d.mts +1 -1
- package/dist/plugins/media/api/adapters/local.d.ts +1 -1
- package/dist/plugins/media/api/adapters/s3.d.cts +1 -1
- package/dist/plugins/media/api/adapters/s3.d.mts +1 -1
- package/dist/plugins/media/api/adapters/s3.d.ts +1 -1
- package/dist/plugins/media/api/adapters/vercel-blob.cjs +46 -0
- package/dist/plugins/media/api/adapters/vercel-blob.d.cts +6 -9
- package/dist/plugins/media/api/adapters/vercel-blob.d.mts +6 -9
- package/dist/plugins/media/api/adapters/vercel-blob.d.ts +6 -9
- package/dist/plugins/media/api/adapters/vercel-blob.mjs +46 -0
- package/dist/plugins/media/api/index.cjs +10 -0
- package/dist/plugins/media/api/index.d.cts +93 -6
- package/dist/plugins/media/api/index.d.mts +93 -6
- package/dist/plugins/media/api/index.d.ts +93 -6
- package/dist/plugins/media/api/index.mjs +2 -0
- package/dist/plugins/media/client/components/index.d.cts +1 -1
- package/dist/plugins/media/client/components/index.d.mts +1 -1
- package/dist/plugins/media/client/components/index.d.ts +1 -1
- package/dist/plugins/media/client/hooks/index.d.cts +20 -10
- package/dist/plugins/media/client/hooks/index.d.mts +20 -10
- package/dist/plugins/media/client/hooks/index.d.ts +20 -10
- package/dist/plugins/media/client/index.cjs +1 -0
- package/dist/plugins/media/client/index.d.cts +112 -100
- package/dist/plugins/media/client/index.d.mts +112 -100
- package/dist/plugins/media/client/index.d.ts +112 -100
- package/dist/plugins/media/client/index.mjs +1 -1
- package/dist/plugins/media/permissions.cjs +63 -0
- package/dist/plugins/media/permissions.d.cts +64 -0
- package/dist/plugins/media/permissions.d.mts +64 -0
- package/dist/plugins/media/permissions.d.ts +64 -0
- package/dist/plugins/media/permissions.mjs +61 -0
- package/dist/plugins/media/query-keys.cjs +29 -17
- package/dist/plugins/media/query-keys.d.cts +24 -31
- package/dist/plugins/media/query-keys.d.mts +24 -31
- package/dist/plugins/media/query-keys.d.ts +24 -31
- package/dist/plugins/media/query-keys.mjs +30 -18
- package/dist/plugins/open-api/api/index.d.cts +9 -4
- package/dist/plugins/open-api/api/index.d.mts +9 -4
- package/dist/plugins/open-api/api/index.d.ts +9 -4
- package/dist/plugins/route-docs/client/index.cjs +2 -2
- package/dist/plugins/route-docs/client/index.d.cts +54 -53
- package/dist/plugins/route-docs/client/index.d.mts +54 -53
- package/dist/plugins/route-docs/client/index.d.ts +54 -53
- package/dist/plugins/route-docs/client/index.mjs +2 -1
- package/dist/plugins/ui-builder/client/components/index.d.cts +8 -5
- package/dist/plugins/ui-builder/client/components/index.d.mts +8 -5
- package/dist/plugins/ui-builder/client/components/index.d.ts +8 -5
- package/dist/plugins/ui-builder/client/hooks/index.d.cts +5 -5
- package/dist/plugins/ui-builder/client/hooks/index.d.mts +5 -5
- package/dist/plugins/ui-builder/client/hooks/index.d.ts +5 -5
- package/dist/plugins/ui-builder/client/index.d.cts +151 -199
- package/dist/plugins/ui-builder/client/index.d.mts +151 -199
- package/dist/plugins/ui-builder/client/index.d.ts +151 -199
- package/dist/plugins/ui-builder/index.d.cts +11 -8
- package/dist/plugins/ui-builder/index.d.mts +11 -8
- package/dist/plugins/ui-builder/index.d.ts +11 -8
- package/dist/plugins/ui-builder/query-keys.d.cts +6 -6
- package/dist/plugins/ui-builder/query-keys.d.mts +6 -6
- package/dist/plugins/ui-builder/query-keys.d.ts +6 -6
- package/dist/react-router/index.cjs +2 -0
- package/dist/react-router/index.d.cts +29 -5
- package/dist/react-router/index.d.mts +29 -5
- package/dist/react-router/index.d.ts +29 -5
- package/dist/react-router/index.mjs +1 -0
- package/dist/shared/stack.0O62uXqP.d.ts +613 -0
- package/dist/shared/stack.0y6iTP03.d.ts +533 -0
- package/dist/shared/{stack.CbZenbej.d.cts → stack.1ukVJym7.d.cts} +3 -4
- package/dist/shared/{stack.CbZenbej.d.mts → stack.1ukVJym7.d.mts} +3 -4
- package/dist/shared/{stack.CbZenbej.d.ts → stack.1ukVJym7.d.ts} +3 -4
- package/dist/shared/stack.3Sr6qRtT.d.ts +507 -0
- package/dist/shared/{stack.9BAOaSqE.d.cts → stack.5_zzCejP.d.cts} +16 -14
- package/dist/shared/{stack.9BAOaSqE.d.mts → stack.5_zzCejP.d.mts} +16 -14
- package/dist/shared/{stack.9BAOaSqE.d.ts → stack.5_zzCejP.d.ts} +16 -14
- package/dist/shared/{stack.oVIdV7XS.d.mts → stack.94kN3pEK.d.mts} +4 -4
- package/dist/shared/stack.B1UrNoVl.d.mts +533 -0
- package/dist/shared/{stack.B2xi4jj7.d.cts → stack.B1srlBud.d.mts} +2 -2
- package/dist/shared/stack.B3_aDcYL.d.cts +281 -0
- package/dist/shared/stack.B3_aDcYL.d.mts +281 -0
- package/dist/shared/stack.B3_aDcYL.d.ts +281 -0
- package/dist/shared/stack.B5yPgHsp.d.mts +507 -0
- package/dist/shared/stack.BFP_9pRX.d.cts +707 -0
- package/dist/shared/stack.BJx1ZXrN.d.cts +118 -0
- package/dist/shared/{stack.7b3vsM8_.d.ts → stack.BK9Z2dcL.d.ts} +2 -2
- package/dist/shared/stack.BMHoxAn7.d.mts +707 -0
- package/dist/shared/stack.BMlTZnZp.d.ts +764 -0
- package/dist/shared/stack.BMmvEBH_.d.ts +118 -0
- package/dist/shared/stack.BPLykw4s.d.ts +436 -0
- package/dist/shared/{stack.aqVZ6PEW.d.mts → stack.BRvqQWGt.d.cts} +40 -1
- package/dist/shared/{stack.aqVZ6PEW.d.cts → stack.BRvqQWGt.d.mts} +40 -1
- package/dist/shared/{stack.aqVZ6PEW.d.ts → stack.BRvqQWGt.d.ts} +40 -1
- package/dist/shared/stack.BSACE667.d.cts +23 -0
- package/dist/shared/{stack.DzwZw-Ck.d.cts → stack.BTStHVTy.d.cts} +4 -4
- package/dist/shared/stack.BV0uNV4f.d.cts +764 -0
- package/dist/shared/stack.BYMentwB.d.cts +47 -0
- package/dist/shared/stack.BYMentwB.d.mts +47 -0
- package/dist/shared/stack.BYMentwB.d.ts +47 -0
- package/dist/shared/stack.BggTHKlo.d.mts +1184 -0
- package/dist/shared/stack.Bt8hfw9o.d.ts +707 -0
- package/dist/shared/{stack.D7bewlgt.d.mts → stack.Bu2IPOLi.d.cts} +1 -0
- package/dist/shared/{stack.D7bewlgt.d.ts → stack.Bu2IPOLi.d.mts} +1 -0
- package/dist/shared/{stack.D7bewlgt.d.cts → stack.Bu2IPOLi.d.ts} +1 -0
- package/dist/shared/stack.BzWGB5MG.d.cts +436 -0
- package/dist/shared/stack.C3bU9w6L.d.ts +351 -0
- package/dist/shared/stack.C4oVW2qK.d.cts +507 -0
- package/dist/shared/stack.CGmh-Lpe.d.ts +408 -0
- package/dist/shared/stack.CKXzdGiJ.d.cts +3 -0
- package/dist/shared/stack.CKXzdGiJ.d.mts +3 -0
- package/dist/shared/stack.CKXzdGiJ.d.ts +3 -0
- package/dist/shared/{stack.C3GBG8in.d.ts → stack.COrJrztD.d.cts} +1 -1
- package/dist/shared/{stack.C3GBG8in.d.cts → stack.COrJrztD.d.mts} +1 -1
- package/dist/shared/{stack.C3GBG8in.d.mts → stack.COrJrztD.d.ts} +1 -1
- package/dist/shared/stack.Cbd7sD5M.d.mts +118 -0
- package/dist/shared/{stack.B9NtGpAR.d.ts → stack.CcjENrr4.d.cts} +1 -5
- package/dist/shared/stack.CfK5NKlK.d.mts +613 -0
- package/dist/shared/stack.Cmg7lzzy.d.cts +44 -0
- package/dist/shared/stack.Cmg7lzzy.d.mts +44 -0
- package/dist/shared/stack.Cmg7lzzy.d.ts +44 -0
- package/dist/shared/stack.CpE1mS3p.d.ts +331 -0
- package/dist/shared/stack.CskhFw3z.d.mts +23 -0
- package/dist/shared/stack.CtrnoQgH.d.cts +1184 -0
- package/dist/shared/stack.CvlC5kqe.d.cts +331 -0
- package/dist/shared/stack.CxKc9evq.d.ts +23 -0
- package/dist/shared/{stack.lkebw2nj.d.mts → stack.DVEjWKCT.d.cts} +19 -5
- package/dist/shared/{stack.lkebw2nj.d.ts → stack.DVEjWKCT.d.mts} +19 -5
- package/dist/shared/{stack.lkebw2nj.d.cts → stack.DVEjWKCT.d.ts} +19 -5
- package/dist/shared/{stack.Cp_6mO5s.d.mts → stack.DbbvHbhn.d.mts} +1 -5
- package/dist/shared/{stack.DseBJmGF.d.ts → stack.DfrRYOIl.d.ts} +4 -4
- package/dist/shared/stack.DiuRuzIs.d.cts +613 -0
- package/dist/shared/{stack.BMlLOMED.d.cts → stack.DjGixVx3.d.cts} +6 -2
- package/dist/shared/{stack.BMlLOMED.d.mts → stack.DjGixVx3.d.mts} +6 -2
- package/dist/shared/{stack.BMlLOMED.d.ts → stack.DjGixVx3.d.ts} +6 -2
- package/dist/shared/stack.DlCycSM-.d.mts +331 -0
- package/dist/shared/{stack.DycBcTeg.d.mts → stack.DmpPDPxA.d.cts} +2 -2
- package/dist/shared/stack.Doy2_wgl.d.mts +408 -0
- package/dist/shared/stack.DxHPKr2R.d.mts +436 -0
- package/dist/shared/stack.Mak7pzIV.d.cts +533 -0
- package/dist/shared/stack.OYT8WU4n.d.mts +351 -0
- package/dist/shared/{stack.CPsYC2-Z.d.cts → stack.fdi94T4S.d.cts} +7 -7
- package/dist/shared/{stack.CPsYC2-Z.d.mts → stack.fdi94T4S.d.mts} +7 -7
- package/dist/shared/{stack.CPsYC2-Z.d.ts → stack.fdi94T4S.d.ts} +7 -7
- package/dist/shared/{stack.Dlgtumru.d.cts → stack.kaCV7vEL.d.ts} +1 -5
- package/dist/shared/stack.lPKwd_v0.d.ts +1184 -0
- package/dist/shared/stack.lsbdKRj7.d.mts +764 -0
- package/dist/shared/stack.v2O65JqF.d.cts +351 -0
- package/dist/shared/stack.zch70Loj.d.cts +408 -0
- package/dist/tanstack/index.cjs +2 -0
- package/dist/tanstack/index.d.cts +27 -5
- package/dist/tanstack/index.d.mts +27 -5
- package/dist/tanstack/index.d.ts +27 -5
- package/dist/tanstack/index.mjs +1 -0
- package/dist/tanstack/server.cjs +9 -0
- package/dist/tanstack/server.d.cts +15 -0
- package/dist/tanstack/server.d.mts +15 -0
- package/dist/tanstack/server.d.ts +15 -0
- package/dist/tanstack/server.mjs +7 -0
- package/package.json +198 -3
- package/src/__tests__/ai-chat-client-runtime.test.ts +481 -0
- package/src/__tests__/ai-chat-client-runtime.typecheck.tsx +130 -0
- package/src/__tests__/ai-chat-lifecycle-migrations.typecheck.ts +61 -0
- package/src/__tests__/ai-chat-query-keys.test.ts +125 -22
- package/src/__tests__/auth-provider.test.tsx +41 -314
- package/src/__tests__/auth-test-utils.ts +24 -0
- package/src/__tests__/authorization-client.test.tsx +767 -0
- package/src/__tests__/authorization-contraction.test.ts +182 -0
- package/src/__tests__/authorization-remote.test.ts +222 -0
- package/src/__tests__/authorization-server.test.ts +90 -0
- package/src/__tests__/authorization.test.ts +652 -0
- package/src/__tests__/authorization.typecheck.ts +671 -0
- package/src/__tests__/backend-plugin-factories.test.ts +54 -0
- package/src/__tests__/backend-plugin-factories.typecheck.ts +133 -0
- package/src/__tests__/client-plugin-ssr-loaders.test.ts +304 -138
- package/src/__tests__/client-runtime.test.ts +1021 -0
- package/src/__tests__/client-runtime.typecheck.ts +107 -0
- package/src/__tests__/client-stack-test-utils.ts +36 -0
- package/src/__tests__/content-lifecycle-migrations.typecheck.ts +122 -0
- package/src/__tests__/endpoint-inventory.test.ts +768 -0
- package/src/__tests__/form-builder-query-keys.test.ts +32 -0
- package/src/__tests__/i18n-provider.test.tsx +4 -3
- package/src/__tests__/initial-identity-hydration.test.tsx +156 -0
- package/src/__tests__/initial-identity-layouts.test.tsx +204 -0
- package/src/__tests__/kanban-query-keys.test.ts +189 -2
- package/src/__tests__/managed-origin-hydration.browser.test.tsx +163 -0
- package/src/__tests__/media-query-keys.test.ts +91 -17
- package/src/__tests__/notify-provider.test.tsx +3 -2
- package/src/__tests__/package-metadata.test.ts +294 -0
- package/src/__tests__/page-component-overrides.test.tsx +3 -4
- package/src/__tests__/plugin-registration.test.tsx +183 -0
- package/src/__tests__/plugin-registration.typecheck.tsx +139 -0
- package/src/__tests__/plugins.test.tsx +72 -42
- package/src/__tests__/resource-factory.test.tsx +79 -2
- package/src/__tests__/resource-use-form.test.tsx +2 -2
- package/src/__tests__/resource-use-select.test.tsx +2 -4
- package/src/__tests__/router-overrides.test.tsx +20 -8
- package/src/__tests__/sitemap.test.ts +38 -22
- package/src/__tests__/stack-api.test.ts +39 -34
- package/src/__tests__/stack-auth.test.ts +44 -140
- package/src/__tests__/stack-constructors.test.ts +96 -0
- package/src/__tests__/stack-constructors.typecheck.ts +115 -0
- package/src/__tests__/use-list-state.test.tsx +7 -6
- package/src/__tests__/workflow-lifecycle-migrations.typecheck.ts +150 -0
- package/src/api/index.ts +204 -99
- package/src/authorization/client.tsx +310 -0
- package/src/authorization/index.ts +873 -0
- package/src/authorization/json.ts +70 -0
- package/src/authorization/remote.ts +234 -0
- package/src/authorization/server.ts +171 -0
- package/src/client/__tests__/server-origin.test.ts +119 -0
- package/src/client/components/compose.tsx +126 -18
- package/src/client/hooks/index.ts +12 -0
- package/src/client/hooks/use-list-state.ts +7 -13
- package/src/client/index.ts +105 -50
- package/src/client/runtime.ts +414 -0
- package/src/client/server.ts +174 -0
- package/src/context/auth.tsx +205 -154
- package/src/context/index.ts +10 -4
- package/src/context/provider.tsx +96 -57
- package/src/context/router.tsx +7 -0
- package/src/context/site-navigation.ts +52 -0
- package/src/next/layout.tsx +81 -0
- package/src/next/page.tsx +16 -3
- package/src/next/router.tsx +1 -1
- package/src/next/server.ts +5 -0
- package/src/plugin-registration.ts +70 -0
- package/src/plugins/ai-chat/__tests__/authorization.test.ts +2051 -0
- package/src/plugins/ai-chat/__tests__/chat-hooks.test.tsx +147 -0
- package/src/plugins/ai-chat/__tests__/chat-input-authorization.test.tsx +188 -0
- package/src/plugins/ai-chat/__tests__/client-sweep.test.tsx +1506 -34
- package/src/plugins/ai-chat/__tests__/hooks.test.tsx +131 -23
- package/src/plugins/ai-chat/api/getters.ts +2 -2
- package/src/plugins/ai-chat/api/index.ts +6 -1
- package/src/plugins/ai-chat/api/lifecycle-migrations.ts +20 -0
- package/src/plugins/ai-chat/api/operations.ts +1865 -0
- package/src/plugins/ai-chat/api/plugin.ts +78 -1168
- package/src/plugins/ai-chat/api/serializers.ts +30 -0
- package/src/plugins/ai-chat/client/components/chat-input.tsx +228 -129
- package/src/plugins/ai-chat/client/components/chat-interface.tsx +776 -183
- package/src/plugins/ai-chat/client/components/chat-layout.tsx +6 -7
- package/src/plugins/ai-chat/client/components/chat-message.tsx +1 -1
- package/src/plugins/ai-chat/client/components/chat-sidebar.tsx +57 -37
- package/src/plugins/ai-chat/client/components/pages/404-page.tsx +1 -1
- package/src/plugins/ai-chat/client/components/pages/chat-page.internal.tsx +5 -3
- package/src/plugins/ai-chat/client/components/pages/chat-page.tsx +56 -15
- package/src/plugins/ai-chat/client/components/shared/default-error.tsx +1 -1
- package/src/plugins/ai-chat/client/components/tool-call-display.tsx +1 -1
- package/src/plugins/ai-chat/client/hooks/ai-chat-resource.ts +1 -1
- package/src/plugins/ai-chat/client/hooks/chat-hooks.tsx +253 -20
- package/src/plugins/ai-chat/client/index.ts +1 -0
- package/src/plugins/ai-chat/client/navigation.ts +11 -0
- package/src/plugins/ai-chat/client/overrides.ts +47 -11
- package/src/plugins/ai-chat/client/plugin.tsx +208 -111
- package/src/plugins/ai-chat/permissions.ts +89 -0
- package/src/plugins/ai-chat/query-keys.ts +183 -25
- package/src/plugins/ai-chat/types.ts +7 -5
- package/src/plugins/api/create-endpoint.ts +40 -22
- package/src/plugins/api/endpoint-inventory.ts +206 -0
- package/src/plugins/api/index.ts +38 -4
- package/src/plugins/api/operation.ts +600 -0
- package/src/plugins/blog/__tests__/authorization.test.ts +1366 -0
- package/src/plugins/blog/__tests__/client-runtime.browser.test.tsx +257 -0
- package/src/plugins/blog/__tests__/client-runtime.test.ts +283 -0
- package/src/plugins/blog/__tests__/client-runtime.typecheck.tsx +98 -0
- package/src/plugins/blog/__tests__/client-sweep.test.tsx +212 -37
- package/src/plugins/blog/api/getters.ts +3 -3
- package/src/plugins/blog/api/index.ts +2 -0
- package/src/plugins/blog/api/lifecycle-migrations.ts +19 -0
- package/src/plugins/blog/api/mutations.ts +26 -5
- package/src/plugins/blog/api/operations.ts +727 -0
- package/src/plugins/blog/api/plugin.ts +99 -504
- package/src/plugins/blog/client/components/forms/image-field.tsx +2 -1
- package/src/plugins/blog/client/components/forms/markdown-editor-with-overrides.tsx +2 -1
- package/src/plugins/blog/client/components/forms/post-forms.tsx +61 -33
- package/src/plugins/blog/client/components/pages/404-page.tsx +3 -1
- package/src/plugins/blog/client/components/pages/edit-post-page.internal.tsx +2 -1
- package/src/plugins/blog/client/components/pages/edit-post-page.tsx +28 -5
- package/src/plugins/blog/client/components/pages/home-page.internal.tsx +2 -1
- package/src/plugins/blog/client/components/pages/home-page.tsx +7 -4
- package/src/plugins/blog/client/components/pages/new-post-page.internal.tsx +2 -1
- package/src/plugins/blog/client/components/pages/new-post-page.tsx +5 -2
- package/src/plugins/blog/client/components/pages/post-page.internal.tsx +2 -1
- package/src/plugins/blog/client/components/pages/post-page.tsx +38 -4
- package/src/plugins/blog/client/components/pages/tag-page.internal.tsx +2 -1
- package/src/plugins/blog/client/components/pages/tag-page.tsx +5 -1
- package/src/plugins/blog/client/components/shared/collapsible-tag-list.tsx +2 -1
- package/src/plugins/blog/client/components/shared/default-error.tsx +3 -1
- package/src/plugins/blog/client/components/shared/on-this-page.tsx +5 -2
- package/src/plugins/blog/client/components/shared/page-wrapper.tsx +2 -1
- package/src/plugins/blog/client/components/shared/post-card.tsx +2 -1
- package/src/plugins/blog/client/components/shared/posts-list.tsx +2 -1
- package/src/plugins/blog/client/components/shared/recent-posts-carousel.tsx +2 -1
- package/src/plugins/blog/client/components/shared/search-input.tsx +1 -1
- package/src/plugins/blog/client/constants.ts +2 -0
- package/src/plugins/blog/client/hooks/blog-resource.ts +2 -1
- package/src/plugins/blog/client/overrides.ts +1 -6
- package/src/plugins/blog/client/plugin.tsx +145 -129
- package/src/plugins/blog/permissions.ts +44 -0
- package/src/plugins/client/index.ts +108 -7
- package/src/plugins/client/resource/hooks.tsx +41 -18
- package/src/plugins/client/resource/internal.ts +77 -61
- package/src/plugins/client/resource/queries.ts +3 -4
- package/src/plugins/client/resource/use-form.ts +23 -20
- package/src/plugins/client/resource/use-select.ts +40 -34
- package/src/plugins/cms/__tests__/authorization.test.ts +2188 -0
- package/src/plugins/cms/__tests__/client-runtime.browser.test.tsx +245 -0
- package/src/plugins/cms/__tests__/client-runtime.test.ts +320 -0
- package/src/plugins/cms/__tests__/client-runtime.typecheck.tsx +208 -0
- package/src/plugins/cms/__tests__/client-sweep.test.tsx +202 -50
- package/src/plugins/cms/api/getters.ts +4 -4
- package/src/plugins/cms/api/index.ts +20 -0
- package/src/plugins/cms/api/lifecycle-migrations.ts +15 -0
- package/src/plugins/cms/api/mutations.ts +2 -2
- package/src/plugins/cms/api/operations.ts +2218 -0
- package/src/plugins/cms/api/plugin.ts +169 -1047
- package/src/plugins/cms/api/relations.ts +3 -1
- package/src/plugins/cms/client/components/forms/content-form.tsx +2 -1
- package/src/plugins/cms/client/components/forms/file-upload.tsx +3 -1
- package/src/plugins/cms/client/components/forms/relation-field.tsx +3 -1
- package/src/plugins/cms/client/components/inverse-relations-panel.tsx +29 -17
- package/src/plugins/cms/client/components/pages/404-page.tsx +7 -5
- package/src/plugins/cms/client/components/pages/content-editor-page.internal.tsx +19 -10
- package/src/plugins/cms/client/components/pages/content-editor-page.tsx +50 -12
- package/src/plugins/cms/client/components/pages/content-list-page.internal.tsx +48 -34
- package/src/plugins/cms/client/components/pages/content-list-page.tsx +8 -1
- package/src/plugins/cms/client/components/pages/dashboard-page.internal.tsx +15 -8
- package/src/plugins/cms/client/components/pages/dashboard-page.tsx +5 -1
- package/src/plugins/cms/client/components/shared/page-wrapper.tsx +2 -1
- package/src/plugins/cms/client/constants.ts +2 -0
- package/src/plugins/cms/client/hooks/cms-resource.ts +2 -1
- package/src/plugins/cms/client/index.ts +6 -1
- package/src/plugins/cms/client/overrides.ts +46 -6
- package/src/plugins/cms/client/plugin.tsx +135 -80
- package/src/plugins/cms/permissions.ts +43 -0
- package/src/plugins/cms/types.ts +174 -46
- package/src/plugins/comments/__tests__/authorization.test.ts +1570 -0
- package/src/plugins/comments/__tests__/client-runtime.browser.test.tsx +207 -0
- package/src/plugins/comments/__tests__/client-runtime.test.ts +224 -0
- package/src/plugins/comments/__tests__/client-runtime.typecheck.tsx +85 -0
- package/src/plugins/comments/__tests__/client-sweep.test.tsx +445 -82
- package/src/plugins/comments/api/getters.ts +19 -3
- package/src/plugins/comments/api/index.ts +2 -6
- package/src/plugins/comments/api/lifecycle-migrations.ts +20 -0
- package/src/plugins/comments/api/mutations.ts +261 -88
- package/src/plugins/comments/api/operations.ts +742 -0
- package/src/plugins/comments/api/plugin.ts +76 -548
- package/src/plugins/comments/client/components/comment-count.tsx +38 -5
- package/src/plugins/comments/client/components/comment-thread.tsx +148 -110
- package/src/plugins/comments/client/components/pages/moderation-page.internal.tsx +144 -78
- package/src/plugins/comments/client/components/pages/moderation-page.tsx +18 -2
- package/src/plugins/comments/client/components/pages/moderation-state.ts +13 -0
- package/src/plugins/comments/client/components/pages/my-comments-page.internal.tsx +38 -30
- package/src/plugins/comments/client/components/pages/my-comments-page.tsx +3 -1
- package/src/plugins/comments/client/components/pages/resource-comments-page.internal.tsx +29 -30
- package/src/plugins/comments/client/components/pages/resource-comments-page.tsx +10 -1
- package/src/plugins/comments/client/components/shared/page-wrapper.tsx +2 -1
- package/src/plugins/comments/client/components/shared/pagination.tsx +2 -1
- package/src/plugins/comments/client/constants.ts +2 -0
- package/src/plugins/comments/client/hooks/use-comments.tsx +430 -421
- package/src/plugins/comments/client/localization/comments-thread.ts +1 -0
- package/src/plugins/comments/client/plugin.tsx +113 -72
- package/src/plugins/comments/permissions.ts +68 -0
- package/src/plugins/comments/query-keys.ts +9 -10
- package/src/plugins/comments/schemas.ts +7 -8
- package/src/plugins/form-builder/__tests__/authorization.test.ts +1600 -0
- package/src/plugins/form-builder/__tests__/client-runtime.browser.test.tsx +255 -0
- package/src/plugins/form-builder/__tests__/client-runtime.test.ts +132 -0
- package/src/plugins/form-builder/__tests__/client-runtime.typecheck.tsx +77 -0
- package/src/plugins/form-builder/__tests__/client-sweep.test.tsx +350 -54
- package/src/plugins/form-builder/__tests__/form-renderer-authorization.test.tsx +162 -0
- package/src/plugins/form-builder/api/getters.ts +21 -5
- package/src/plugins/form-builder/api/index.ts +31 -0
- package/src/plugins/form-builder/api/lifecycle-migrations.ts +17 -0
- package/src/plugins/form-builder/api/operations.ts +1493 -0
- package/src/plugins/form-builder/api/plugin.ts +125 -632
- package/src/plugins/form-builder/api/query-key-defs.ts +7 -0
- package/src/plugins/form-builder/api/serializers.ts +1 -0
- package/src/plugins/form-builder/client/components/forms/form-renderer.tsx +49 -19
- package/src/plugins/form-builder/client/components/pages/404-page.tsx +9 -9
- package/src/plugins/form-builder/client/components/pages/form-builder-page.internal.tsx +54 -30
- package/src/plugins/form-builder/client/components/pages/form-builder-page.tsx +42 -9
- package/src/plugins/form-builder/client/components/pages/form-list-page.internal.tsx +46 -34
- package/src/plugins/form-builder/client/components/pages/form-list-page.tsx +6 -2
- package/src/plugins/form-builder/client/components/pages/submissions-page.internal.tsx +98 -64
- package/src/plugins/form-builder/client/components/pages/submissions-page.tsx +29 -9
- package/src/plugins/form-builder/client/components/shared/page-wrapper.tsx +2 -1
- package/src/plugins/form-builder/client/constants.ts +2 -0
- package/src/plugins/form-builder/client/hooks/form-builder-hooks.tsx +68 -4
- package/src/plugins/form-builder/client/hooks/form-builder-resource.ts +2 -1
- package/src/plugins/form-builder/client/hooks/index.tsx +1 -0
- package/src/plugins/form-builder/client/overrides.ts +1 -6
- package/src/plugins/form-builder/client/plugin.tsx +128 -96
- package/src/plugins/form-builder/permissions.ts +94 -0
- package/src/plugins/form-builder/query-keys.ts +28 -3
- package/src/plugins/form-builder/schemas.ts +9 -1
- package/src/plugins/form-builder/types.ts +173 -41
- package/src/plugins/kanban/__tests__/authorization.test.ts +1382 -0
- package/src/plugins/kanban/__tests__/client-runtime.browser.test.tsx +302 -0
- package/src/plugins/kanban/__tests__/client-runtime.test.ts +130 -0
- package/src/plugins/kanban/__tests__/client-runtime.typecheck.tsx +81 -0
- package/src/plugins/kanban/__tests__/client-sweep.test.tsx +418 -33
- package/src/plugins/kanban/__tests__/identity-partition.test.tsx +306 -0
- package/src/plugins/kanban/api/getters.ts +65 -50
- package/src/plugins/kanban/api/index.ts +55 -4
- package/src/plugins/kanban/api/lifecycle-migrations.ts +25 -0
- package/src/plugins/kanban/api/mutations.ts +3 -3
- package/src/plugins/kanban/api/operations.ts +2065 -0
- package/src/plugins/kanban/api/plugin.ts +83 -1013
- package/src/plugins/kanban/api/serializers.ts +26 -0
- package/src/plugins/kanban/client/components/forms/board-form.tsx +3 -1
- package/src/plugins/kanban/client/components/forms/column-form.tsx +3 -1
- package/src/plugins/kanban/client/components/forms/task-form.tsx +92 -74
- package/src/plugins/kanban/client/components/pages/404-page.tsx +6 -9
- package/src/plugins/kanban/client/components/pages/board-page.internal.tsx +57 -74
- package/src/plugins/kanban/client/components/pages/board-page.tsx +31 -7
- package/src/plugins/kanban/client/components/pages/boards-list-page.internal.tsx +54 -45
- package/src/plugins/kanban/client/components/pages/boards-list-page.tsx +2 -1
- package/src/plugins/kanban/client/components/pages/new-board-page.internal.tsx +8 -12
- package/src/plugins/kanban/client/components/pages/new-board-page.tsx +2 -1
- package/src/plugins/kanban/client/components/shared/column-content.tsx +61 -48
- package/src/plugins/kanban/client/components/shared/default-error.tsx +3 -1
- package/src/plugins/kanban/client/components/shared/kanban-board.tsx +6 -6
- package/src/plugins/kanban/client/components/shared/permission-access-any.tsx +32 -0
- package/src/plugins/kanban/client/components/shared/task-card.tsx +64 -20
- package/src/plugins/kanban/client/components/shared/user-avatar.tsx +3 -1
- package/src/plugins/kanban/client/constants.ts +2 -0
- package/src/plugins/kanban/client/hooks/kanban-hooks.tsx +55 -10
- package/src/plugins/kanban/client/hooks/kanban-resource.ts +2 -1
- package/src/plugins/kanban/client/overrides.ts +0 -5
- package/src/plugins/kanban/client/plugin.tsx +201 -113
- package/src/plugins/kanban/permissions.ts +100 -0
- package/src/plugins/kanban/query-keys.ts +61 -21
- package/src/plugins/kanban/schemas.ts +44 -18
- package/src/plugins/kanban/types.ts +381 -1
- package/src/plugins/media/__tests__/authorization.test.ts +1769 -0
- package/src/plugins/media/__tests__/client-runtime.browser.test.tsx +975 -0
- package/src/plugins/media/__tests__/client-runtime.test.ts +539 -0
- package/src/plugins/media/__tests__/client-runtime.typecheck.tsx +135 -0
- package/src/plugins/media/__tests__/client-sweep.test.tsx +292 -24
- package/src/plugins/media/__tests__/identity-partition.test.tsx +741 -0
- package/src/plugins/media/__tests__/plugin.test.ts +68 -28
- package/src/plugins/media/__tests__/query-key-defs.test.ts +32 -2
- package/src/plugins/media/api/adapters/vercel-blob.ts +84 -8
- package/src/plugins/media/api/getters.ts +6 -6
- package/src/plugins/media/api/index.ts +3 -0
- package/src/plugins/media/api/lifecycle-migrations.ts +11 -0
- package/src/plugins/media/api/mutations.ts +19 -13
- package/src/plugins/media/api/operations.ts +1873 -0
- package/src/plugins/media/api/plugin.ts +211 -899
- package/src/plugins/media/api/query-key-defs.ts +66 -4
- package/src/plugins/media/api/serializers.ts +4 -2
- package/src/plugins/media/api/storage-adapter.ts +22 -4
- package/src/plugins/media/asset-url.ts +14 -0
- package/src/plugins/media/client/components/media-picker/asset-card.tsx +105 -98
- package/src/plugins/media/client/components/media-picker/folder-tree.tsx +82 -60
- package/src/plugins/media/client/components/media-picker/index.tsx +235 -171
- package/src/plugins/media/client/components/media-picker/upload-tab.tsx +2 -10
- package/src/plugins/media/client/components/media-picker/url-tab.tsx +1 -8
- package/src/plugins/media/client/components/pages/library-page.internal.tsx +103 -82
- package/src/plugins/media/client/components/pages/library-page.tsx +4 -2
- package/src/plugins/media/client/components/upload-permission-check.tsx +75 -0
- package/src/plugins/media/client/constants.ts +2 -0
- package/src/plugins/media/client/hooks/media-resource.ts +2 -1
- package/src/plugins/media/client/hooks/use-media.tsx +292 -49
- package/src/plugins/media/client/index.ts +16 -3
- package/src/plugins/media/client/overrides.ts +6 -17
- package/src/plugins/media/client/plugin.tsx +188 -123
- package/src/plugins/media/client/upload.ts +170 -53
- package/src/plugins/media/db.ts +8 -0
- package/src/plugins/media/permissions.ts +61 -0
- package/src/plugins/media/query-keys.ts +63 -19
- package/src/plugins/media/types.ts +8 -2
- package/src/plugins/open-api/__tests__/route-introspection.test.ts +277 -0
- package/src/plugins/open-api/api/generator.ts +49 -8
- package/src/plugins/open-api/api/plugin.ts +36 -14
- package/src/plugins/route-docs/client/components/pages/docs-page.tsx +63 -23
- package/src/plugins/route-docs/client/constants.ts +2 -0
- package/src/plugins/route-docs/client/hooks.ts +23 -13
- package/src/plugins/route-docs/client/index.ts +7 -1
- package/src/plugins/route-docs/client/plugin.tsx +222 -145
- package/src/plugins/route-docs/client/schema.ts +31 -0
- package/src/plugins/route-docs/generator.ts +9 -5
- package/src/plugins/ui-builder/__tests__/client-sweep.test.tsx +427 -48
- package/src/plugins/ui-builder/client/components/page-renderer.tsx +58 -16
- package/src/plugins/ui-builder/client/components/pages/page-builder-page.internal.tsx +47 -26
- package/src/plugins/ui-builder/client/components/pages/page-builder-page.tsx +43 -8
- package/src/plugins/ui-builder/client/components/pages/page-list-page.internal.tsx +38 -19
- package/src/plugins/ui-builder/client/components/pages/page-list-page.tsx +8 -2
- package/src/plugins/ui-builder/client/components/shared/default-error.tsx +2 -1
- package/src/plugins/ui-builder/client/components/shared/page-wrapper.tsx +2 -1
- package/src/plugins/ui-builder/client/constants.ts +2 -0
- package/src/plugins/ui-builder/client/hooks/ui-builder-resource.ts +2 -1
- package/src/plugins/ui-builder/client/index.ts +4 -1
- package/src/plugins/ui-builder/client/overrides.ts +16 -21
- package/src/plugins/ui-builder/client/plugin.tsx +119 -66
- package/src/plugins/ui-builder/client/registry.ts +3 -5
- package/src/plugins/ui-builder/types.ts +7 -4
- package/src/plugins/utils.ts +5 -1
- package/src/react-router/index.tsx +5 -0
- package/src/react-router/layout.ts +43 -0
- package/src/react-router/page.tsx +12 -5
- package/src/react-router/router.tsx +1 -1
- package/src/shared/auth-types.ts +19 -70
- package/src/shared/entry-factories.ts +3 -3
- package/src/shared/initial-identity.ts +73 -0
- package/src/shared/list-state.ts +12 -0
- package/src/shared/types.ts +1 -0
- package/src/tanstack/index.tsx +5 -0
- package/src/tanstack/layout.ts +36 -0
- package/src/tanstack/page.tsx +7 -2
- package/src/tanstack/router.tsx +1 -1
- package/src/tanstack/server.ts +18 -0
- package/src/types.ts +557 -65
- package/dist/shared/stack.B8vdOMnQ.d.cts +0 -329
- package/dist/shared/stack.BISAZ5LX.d.mts +0 -492
- package/dist/shared/stack.BL5PvShn.d.mts +0 -193
- package/dist/shared/stack.Be1QIHEn.d.cts +0 -23
- package/dist/shared/stack.Be1QIHEn.d.mts +0 -23
- package/dist/shared/stack.Be1QIHEn.d.ts +0 -23
- package/dist/shared/stack.BjvOk_Bs.d.cts +0 -492
- package/dist/shared/stack.BozPgbrZ.d.cts +0 -201
- package/dist/shared/stack.BozPgbrZ.d.mts +0 -201
- package/dist/shared/stack.BozPgbrZ.d.ts +0 -201
- package/dist/shared/stack.BqTR6qi2.d.ts +0 -193
- package/dist/shared/stack.BsmDN8r9.d.cts +0 -406
- package/dist/shared/stack.C1ATQ3pd.d.ts +0 -416
- package/dist/shared/stack.C4_gEENS.d.cts +0 -97
- package/dist/shared/stack.C4_gEENS.d.mts +0 -97
- package/dist/shared/stack.C4_gEENS.d.ts +0 -97
- package/dist/shared/stack.C5Y5lViI.d.cts +0 -461
- package/dist/shared/stack.C8SwdUz8.d.ts +0 -461
- package/dist/shared/stack.CBsp9rDM.d.cts +0 -193
- package/dist/shared/stack.CKGjOI3Z.d.cts +0 -840
- package/dist/shared/stack.Cf-DbL1A.d.ts +0 -329
- package/dist/shared/stack.CuI_-z-_.d.cts +0 -560
- package/dist/shared/stack.D2RVkQD8.d.mts +0 -560
- package/dist/shared/stack.DHTvwoNG.d.mts +0 -329
- package/dist/shared/stack.DJaKVY7v.d.cts +0 -76
- package/dist/shared/stack.DJaKVY7v.d.mts +0 -76
- package/dist/shared/stack.DJaKVY7v.d.ts +0 -76
- package/dist/shared/stack.DKZMaVr6.d.cts +0 -416
- package/dist/shared/stack.DOzsgzkY.d.ts +0 -406
- package/dist/shared/stack.DQq8DEIv.d.mts +0 -461
- package/dist/shared/stack.DXrOtuek.d.ts +0 -560
- package/dist/shared/stack.DZHEHd-S.d.mts +0 -840
- package/dist/shared/stack.Dd-8shBE.d.ts +0 -492
- package/dist/shared/stack.EOPVnJrF.d.cts +0 -39
- package/dist/shared/stack.EOPVnJrF.d.mts +0 -39
- package/dist/shared/stack.EOPVnJrF.d.ts +0 -39
- package/dist/shared/stack.NGKtwA6S.d.mts +0 -406
- package/dist/shared/stack.WELCDuMs.d.ts +0 -840
- package/dist/shared/stack.aXdBOJAR.d.cts +0 -173
- package/dist/shared/stack.aXdBOJAR.d.mts +0 -173
- package/dist/shared/stack.aXdBOJAR.d.ts +0 -173
- package/dist/shared/stack.oBokjN_J.d.mts +0 -416
- package/dist/shared/{stack.D18Dq3ve.d.mts → stack.CKc_Bais.d.cts} +8 -8
- package/dist/shared/{stack.D18Dq3ve.d.ts → stack.CKc_Bais.d.mts} +8 -8
- package/dist/shared/{stack.D18Dq3ve.d.cts → stack.CKc_Bais.d.ts} +8 -8
|
@@ -1,272 +1,39 @@
|
|
|
1
1
|
import type { DBAdapter as Adapter } from "@btst/db";
|
|
2
|
-
import { defineBackendPlugin } from "@btst/stack/plugins/api";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
streamText,
|
|
6
|
-
convertToModelMessages,
|
|
7
|
-
stepCountIs,
|
|
8
|
-
type LanguageModel,
|
|
9
|
-
type UIMessage,
|
|
10
|
-
type Tool,
|
|
11
|
-
} from "ai";
|
|
2
|
+
import { createEndpoint, defineBackendPlugin } from "@btst/stack/plugins/api";
|
|
3
|
+
import type { LanguageModel, Tool } from "ai";
|
|
12
4
|
import { aiChatSchema as dbSchema } from "../db";
|
|
13
5
|
import {
|
|
14
6
|
chatRequestSchema,
|
|
15
7
|
createConversationSchema,
|
|
16
8
|
updateConversationSchema,
|
|
17
9
|
} from "../schemas";
|
|
18
|
-
import type { Conversation, ConversationWithMessages, Message } from "../types";
|
|
19
|
-
import { getAllConversations, getConversationById } from "./getters";
|
|
20
10
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export interface AiChatBackendHooks {
|
|
43
|
-
// ============== Authorization Hooks ==============
|
|
44
|
-
// Throw an error to deny access
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Called before processing a chat message. Throw an error to deny access.
|
|
48
|
-
* @param messages - Array of messages being sent
|
|
49
|
-
* @param context - Request context with headers, etc.
|
|
50
|
-
*/
|
|
51
|
-
onBeforeChat?: (
|
|
52
|
-
messages: Array<{ role: string; content: string }>,
|
|
53
|
-
context: ChatApiContext,
|
|
54
|
-
) => Promise<void> | void;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Called before listing conversations. Throw an error to deny access.
|
|
58
|
-
* @param context - Request context with headers, etc.
|
|
59
|
-
*/
|
|
60
|
-
onBeforeListConversations?: (context: ChatApiContext) => Promise<void> | void;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Called before getting a single conversation. Throw an error to deny access.
|
|
64
|
-
* @param conversationId - ID of the conversation being accessed
|
|
65
|
-
* @param context - Request context with headers, etc.
|
|
66
|
-
*/
|
|
67
|
-
onBeforeGetConversation?: (
|
|
68
|
-
conversationId: string,
|
|
69
|
-
context: ChatApiContext,
|
|
70
|
-
) => Promise<void> | void;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Called before creating a conversation. Throw an error to deny access.
|
|
74
|
-
* @param data - Conversation data being created
|
|
75
|
-
* @param context - Request context with headers, etc.
|
|
76
|
-
*/
|
|
77
|
-
onBeforeCreateConversation?: (
|
|
78
|
-
data: { id?: string; title?: string },
|
|
79
|
-
context: ChatApiContext,
|
|
80
|
-
) => Promise<void> | void;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Called before updating a conversation. Throw an error to deny access.
|
|
84
|
-
* @param conversationId - ID of the conversation being updated
|
|
85
|
-
* @param data - Updated conversation data
|
|
86
|
-
* @param context - Request context with headers, etc.
|
|
87
|
-
*/
|
|
88
|
-
onBeforeUpdateConversation?: (
|
|
89
|
-
conversationId: string,
|
|
90
|
-
data: { title?: string },
|
|
91
|
-
context: ChatApiContext,
|
|
92
|
-
) => Promise<void> | void;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Called before deleting a conversation. Throw an error to deny access.
|
|
96
|
-
* @param conversationId - ID of the conversation being deleted
|
|
97
|
-
* @param context - Request context with headers, etc.
|
|
98
|
-
*/
|
|
99
|
-
onBeforeDeleteConversation?: (
|
|
100
|
-
conversationId: string,
|
|
101
|
-
context: ChatApiContext,
|
|
102
|
-
) => Promise<void> | void;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Called after the structural routeName/allowlist validation, with the list
|
|
106
|
-
* of tool names that passed. Return a filtered subset to further restrict
|
|
107
|
-
* which tools the LLM sees, or return [] to suppress all page tools.
|
|
108
|
-
* Throw an Error to abort the entire chat request with a 403 response.
|
|
109
|
-
* Not called when no tools passed the structural validation step.
|
|
110
|
-
*
|
|
111
|
-
* @param toolNames - Names that passed the routeName allowlist check
|
|
112
|
-
* @param routeName - routeName claimed by the request (may be undefined)
|
|
113
|
-
* @param context - Full request context (headers, body, etc.)
|
|
114
|
-
*/
|
|
115
|
-
onBeforeToolsActivated?: (
|
|
116
|
-
toolNames: string[],
|
|
117
|
-
routeName: string | undefined,
|
|
118
|
-
context: ChatApiContext,
|
|
119
|
-
) => Promise<string[]> | string[];
|
|
120
|
-
|
|
121
|
-
// ============== Lifecycle Hooks ==============
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Called after a chat message is processed successfully
|
|
125
|
-
* @param conversationId - ID of the conversation
|
|
126
|
-
* @param messages - Array of messages in the conversation
|
|
127
|
-
* @param context - Request context
|
|
128
|
-
*/
|
|
129
|
-
onAfterChat?: (
|
|
130
|
-
conversationId: string,
|
|
131
|
-
messages: Message[],
|
|
132
|
-
context: ChatApiContext,
|
|
133
|
-
) => Promise<void> | void;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Called after conversations are read successfully
|
|
137
|
-
* @param conversations - Array of conversations that were read
|
|
138
|
-
* @param context - Request context
|
|
139
|
-
*/
|
|
140
|
-
onConversationsRead?: (
|
|
141
|
-
conversations: Conversation[],
|
|
142
|
-
context: ChatApiContext,
|
|
143
|
-
) => Promise<void> | void;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Called after a single conversation is read successfully
|
|
147
|
-
* @param conversation - The conversation with messages
|
|
148
|
-
* @param context - Request context
|
|
149
|
-
*/
|
|
150
|
-
onConversationRead?: (
|
|
151
|
-
conversation: Conversation & { messages: Message[] },
|
|
152
|
-
context: ChatApiContext,
|
|
153
|
-
) => Promise<void> | void;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Called after a conversation is created successfully
|
|
157
|
-
* @param conversation - The created conversation
|
|
158
|
-
* @param context - Request context
|
|
159
|
-
*/
|
|
160
|
-
onConversationCreated?: (
|
|
161
|
-
conversation: Conversation,
|
|
162
|
-
context: ChatApiContext,
|
|
163
|
-
) => Promise<void> | void;
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Called after a conversation is updated successfully
|
|
167
|
-
* @param conversation - The updated conversation
|
|
168
|
-
* @param context - Request context
|
|
169
|
-
*/
|
|
170
|
-
onConversationUpdated?: (
|
|
171
|
-
conversation: Conversation,
|
|
172
|
-
context: ChatApiContext,
|
|
173
|
-
) => Promise<void> | void;
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Called after a conversation is deleted successfully
|
|
177
|
-
* @param conversationId - ID of the deleted conversation
|
|
178
|
-
* @param context - Request context
|
|
179
|
-
*/
|
|
180
|
-
onConversationDeleted?: (
|
|
181
|
-
conversationId: string,
|
|
182
|
-
context: ChatApiContext,
|
|
183
|
-
) => Promise<void> | void;
|
|
184
|
-
|
|
185
|
-
// ============== Error Hooks ==============
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Called when a chat operation fails
|
|
189
|
-
* @param error - The error that occurred
|
|
190
|
-
* @param context - Request context
|
|
191
|
-
*/
|
|
192
|
-
onChatError?: (error: Error, context: ChatApiContext) => Promise<void> | void;
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Called when listing conversations fails
|
|
196
|
-
* @param error - The error that occurred
|
|
197
|
-
* @param context - Request context
|
|
198
|
-
*/
|
|
199
|
-
onListConversationsError?: (
|
|
200
|
-
error: Error,
|
|
201
|
-
context: ChatApiContext,
|
|
202
|
-
) => Promise<void> | void;
|
|
11
|
+
type AiChatAccess,
|
|
12
|
+
type AiChatBackendHooks,
|
|
13
|
+
ConversationOperationInputSchema,
|
|
14
|
+
createAiChatOperations,
|
|
15
|
+
UpdateConversationOperationInputSchema,
|
|
16
|
+
} from "./operations";
|
|
17
|
+
|
|
18
|
+
export type {
|
|
19
|
+
AiChatAccess,
|
|
20
|
+
AiChatBackendHooks,
|
|
21
|
+
ChatApiContext,
|
|
22
|
+
} from "./operations";
|
|
23
|
+
export {
|
|
24
|
+
AI_CHAT_OPERATION_INVENTORY,
|
|
25
|
+
AI_CHAT_RAW_ESCAPE_HATCH_INVENTORY,
|
|
26
|
+
AiChatOperationError,
|
|
27
|
+
ChatOperationInputSchema,
|
|
28
|
+
ConversationOperationInputSchema,
|
|
29
|
+
UpdateConversationOperationInputSchema,
|
|
30
|
+
} from "./operations";
|
|
31
|
+
export { AI_CHAT_LIFECYCLE_HOOK_MIGRATIONS } from "./lifecycle-migrations";
|
|
203
32
|
|
|
204
|
-
/**
|
|
205
|
-
* Called when getting a conversation fails
|
|
206
|
-
* @param error - The error that occurred
|
|
207
|
-
* @param context - Request context
|
|
208
|
-
*/
|
|
209
|
-
onGetConversationError?: (
|
|
210
|
-
error: Error,
|
|
211
|
-
context: ChatApiContext,
|
|
212
|
-
) => Promise<void> | void;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Called when creating a conversation fails
|
|
216
|
-
* @param error - The error that occurred
|
|
217
|
-
* @param context - Request context
|
|
218
|
-
*/
|
|
219
|
-
onCreateConversationError?: (
|
|
220
|
-
error: Error,
|
|
221
|
-
context: ChatApiContext,
|
|
222
|
-
) => Promise<void> | void;
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Called when updating a conversation fails
|
|
226
|
-
* @param error - The error that occurred
|
|
227
|
-
* @param context - Request context
|
|
228
|
-
*/
|
|
229
|
-
onUpdateConversationError?: (
|
|
230
|
-
error: Error,
|
|
231
|
-
context: ChatApiContext,
|
|
232
|
-
) => Promise<void> | void;
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Called when deleting a conversation fails
|
|
236
|
-
* @param error - The error that occurred
|
|
237
|
-
* @param context - Request context
|
|
238
|
-
*/
|
|
239
|
-
onDeleteConversationError?: (
|
|
240
|
-
error: Error,
|
|
241
|
-
context: ChatApiContext,
|
|
242
|
-
) => Promise<void> | void;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Plugin mode for AI Chat
|
|
247
|
-
* - 'authenticated': Conversations persisted with userId (default)
|
|
248
|
-
* - 'public': Stateless chat, no persistence (ideal for public chatbots)
|
|
249
|
-
*/
|
|
250
|
-
export type AiChatMode = "authenticated" | "public";
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Configuration for AI Chat backend plugin
|
|
254
|
-
*/
|
|
255
|
-
/**
|
|
256
|
-
* Extracts only the literal (non-index-signature) keys from a type.
|
|
257
|
-
* For `Record<string, T>` this resolves to `never`, so collision checks are
|
|
258
|
-
* skipped when the tools map is typed with a broad string index.
|
|
259
|
-
*/
|
|
260
33
|
type KnownKeys<T> = {
|
|
261
34
|
[K in keyof T]: string extends K ? never : K;
|
|
262
35
|
}[keyof T];
|
|
263
36
|
|
|
264
|
-
/**
|
|
265
|
-
* Ensures `TClientTools` has no keys that are also literal keys in `TTools`.
|
|
266
|
-
* Colliding keys are mapped to `never`, which produces a compile-time error
|
|
267
|
-
* at the point of the duplicate key. When `TTools` uses a string index
|
|
268
|
-
* signature the check is skipped to avoid false positives.
|
|
269
|
-
*/
|
|
270
37
|
type NoKeyCollision<
|
|
271
38
|
TTools,
|
|
272
39
|
TClientTools extends Record<string, Tool>,
|
|
@@ -274,85 +41,27 @@ type NoKeyCollision<
|
|
|
274
41
|
? TClientTools
|
|
275
42
|
: {
|
|
276
43
|
[K in keyof TClientTools]: K extends KnownKeys<TTools>
|
|
277
|
-
? never
|
|
44
|
+
? never
|
|
278
45
|
: TClientTools[K];
|
|
279
46
|
};
|
|
280
47
|
|
|
48
|
+
/** AI Chat server configuration. */
|
|
281
49
|
export interface AiChatBackendConfig {
|
|
282
|
-
/**
|
|
283
|
-
* The language model to use for chat completions.
|
|
284
|
-
* Supports any model from AI SDK providers (OpenAI, Anthropic, Google, etc.)
|
|
285
|
-
*/
|
|
286
50
|
model: LanguageModel;
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Plugin mode:
|
|
290
|
-
* - 'authenticated': Conversations persisted with userId (requires getUserId)
|
|
291
|
-
* - 'public': Stateless chat, no persistence (ideal for public chatbots)
|
|
292
|
-
* @default 'authenticated'
|
|
293
|
-
*/
|
|
294
|
-
mode?: AiChatMode;
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Extract userId from request context (authenticated mode only).
|
|
298
|
-
* Return null/undefined to deny access in authenticated mode.
|
|
299
|
-
* This function is called for all conversation operations.
|
|
300
|
-
* @example (ctx) => ctx.headers?.get('x-user-id')
|
|
301
|
-
*/
|
|
302
|
-
getUserId?: (
|
|
303
|
-
context: ChatApiContext,
|
|
304
|
-
) => string | null | undefined | Promise<string | null | undefined>;
|
|
305
|
-
|
|
306
51
|
/**
|
|
307
|
-
*
|
|
52
|
+
* Explicit server access policy. Authorized mode persists identity-scoped
|
|
53
|
+
* history and denies missing rules. Public mode exposes only stateless chat.
|
|
54
|
+
* @default "authorized"
|
|
308
55
|
*/
|
|
56
|
+
access?: AiChatAccess;
|
|
309
57
|
systemPrompt?: string;
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Optional tools to make available to the model.
|
|
313
|
-
* Uses AI SDK v5 tool format.
|
|
314
|
-
* @see https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling
|
|
315
|
-
*/
|
|
316
58
|
tools?: Record<string, Tool>;
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Enable route-aware page tools.
|
|
320
|
-
* When true, the server will include tool schemas for client-side page tools
|
|
321
|
-
* (e.g. fillBlogForm, updatePageLayers) based on the availableTools list
|
|
322
|
-
* sent with each request.
|
|
323
|
-
* @default false
|
|
324
|
-
*/
|
|
325
59
|
enablePageTools?: boolean;
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Custom client-side tool schemas for non-BTST pages.
|
|
329
|
-
* Merged with built-in page tool schemas (fillBlogForm, updatePageLayers).
|
|
330
|
-
* Only included when enablePageTools is true and the tool name appears in
|
|
331
|
-
* the availableTools list sent with the request.
|
|
332
|
-
*
|
|
333
|
-
* @example
|
|
334
|
-
* clientToolSchemas: {
|
|
335
|
-
* addToCart: tool({
|
|
336
|
-
* description: "Add current product to cart",
|
|
337
|
-
* parameters: z.object({ quantity: z.number().int().min(1) }),
|
|
338
|
-
* }),
|
|
339
|
-
* }
|
|
340
|
-
*/
|
|
341
60
|
clientToolSchemas?: Record<string, Tool>;
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Optional hooks for customizing plugin behavior
|
|
345
|
-
*/
|
|
346
61
|
hooks?: AiChatBackendHooks;
|
|
347
62
|
}
|
|
348
63
|
|
|
349
|
-
/**
|
|
350
|
-
* AI Chat backend plugin
|
|
351
|
-
* Provides API endpoints for AI-powered chat with conversation history
|
|
352
|
-
* Uses AI SDK v5 for model interactions
|
|
353
|
-
*
|
|
354
|
-
* @param config - Configuration including model, tools, and optional hooks
|
|
355
|
-
*/
|
|
64
|
+
/** AI Chat backend plugin backed by one typed operation catalog. */
|
|
356
65
|
export const aiChatBackendPlugin = <
|
|
357
66
|
TTools extends Record<string, Tool> = Record<never, Tool>,
|
|
358
67
|
TClientTools extends Record<string, Tool> = Record<never, Tool>,
|
|
@@ -361,886 +70,87 @@ export const aiChatBackendPlugin = <
|
|
|
361
70
|
tools?: TTools;
|
|
362
71
|
clientToolSchemas?: NoKeyCollision<TTools, TClientTools>;
|
|
363
72
|
},
|
|
364
|
-
) =>
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
73
|
+
) => {
|
|
74
|
+
const access = config.access ?? "authorized";
|
|
75
|
+
const operationsConfig = {
|
|
76
|
+
...config,
|
|
77
|
+
access,
|
|
78
|
+
tools: config.tools as Record<string, Tool> | undefined,
|
|
79
|
+
clientToolSchemas: config.clientToolSchemas as
|
|
80
|
+
| Record<string, Tool>
|
|
81
|
+
| undefined,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return defineBackendPlugin({
|
|
85
|
+
id: "aiChat",
|
|
368
86
|
dbPlugin: dbSchema,
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
routes: (
|
|
377
|
-
const mode = config.mode ?? "authenticated";
|
|
378
|
-
const isPublicMode = mode === "public";
|
|
379
|
-
|
|
380
|
-
// Helper to extract text content from UIMessage (for conversation titles, etc.)
|
|
381
|
-
const getMessageTextContent = (msg: UIMessage): string => {
|
|
382
|
-
if (msg.parts && Array.isArray(msg.parts)) {
|
|
383
|
-
return msg.parts
|
|
384
|
-
.filter((part: any) => part.type === "text")
|
|
385
|
-
.map((part: any) => part.text)
|
|
386
|
-
.join("");
|
|
387
|
-
}
|
|
388
|
-
return "";
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
// Helper to serialize message parts to JSON (preserves all files)
|
|
392
|
-
const serializeMessageParts = (msg: UIMessage): string => {
|
|
393
|
-
if (msg.parts && Array.isArray(msg.parts)) {
|
|
394
|
-
// Filter to only include text and file parts (images, PDFs, text files, etc.)
|
|
395
|
-
const serializableParts = msg.parts.filter(
|
|
396
|
-
(part: any) => part.type === "text" || part.type === "file",
|
|
397
|
-
);
|
|
398
|
-
return JSON.stringify(serializableParts);
|
|
399
|
-
}
|
|
400
|
-
return JSON.stringify([]);
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
// Helper to get userId in authenticated mode
|
|
404
|
-
// Returns null if no getUserId is configured, or the userId if available
|
|
405
|
-
// Throws if getUserId returns null/undefined (auth required but not provided)
|
|
406
|
-
const resolveUserId = async (
|
|
407
|
-
context: ChatApiContext,
|
|
408
|
-
throwOnMissing: () => never,
|
|
409
|
-
): Promise<string | null> => {
|
|
410
|
-
if (isPublicMode) {
|
|
411
|
-
return null;
|
|
412
|
-
}
|
|
413
|
-
if (!config.getUserId) {
|
|
414
|
-
// If no getUserId is provided, conversations are not user-scoped
|
|
415
|
-
return null;
|
|
416
|
-
}
|
|
417
|
-
const userId = await config.getUserId(context);
|
|
418
|
-
if (!userId) {
|
|
419
|
-
throwOnMissing();
|
|
420
|
-
}
|
|
421
|
-
return userId;
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
// ============== Chat Endpoint ==============
|
|
87
|
+
operationRouteMap: { chat: "startStream" },
|
|
88
|
+
operations: (adapter: Adapter) =>
|
|
89
|
+
createAiChatOperations(adapter, {
|
|
90
|
+
...operationsConfig,
|
|
91
|
+
}),
|
|
92
|
+
|
|
93
|
+
/** HTTP routes bound to the maintained operation inventory. */
|
|
94
|
+
routes: (_adapter: Adapter, _context, operations) => {
|
|
425
95
|
const chat = createEndpoint(
|
|
426
96
|
"/chat",
|
|
427
|
-
{
|
|
428
|
-
|
|
429
|
-
body: chatRequestSchema,
|
|
430
|
-
},
|
|
431
|
-
async (ctx) => {
|
|
432
|
-
const {
|
|
433
|
-
messages: rawMessages,
|
|
434
|
-
conversationId,
|
|
435
|
-
pageContext,
|
|
436
|
-
availableTools,
|
|
437
|
-
routeName,
|
|
438
|
-
} = ctx.body;
|
|
439
|
-
const uiMessages = rawMessages as UIMessage[];
|
|
440
|
-
|
|
441
|
-
const context: ChatApiContext = {
|
|
442
|
-
body: ctx.body,
|
|
443
|
-
headers: ctx.headers,
|
|
444
|
-
request: ctx.request,
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
try {
|
|
448
|
-
// Authorization hook
|
|
449
|
-
if (config.hooks?.onBeforeChat) {
|
|
450
|
-
const messagesForHook = uiMessages.map((msg) => ({
|
|
451
|
-
role: msg.role,
|
|
452
|
-
content: getMessageTextContent(msg),
|
|
453
|
-
}));
|
|
454
|
-
await runHook(
|
|
455
|
-
() => config.hooks!.onBeforeChat!(messagesForHook, context),
|
|
456
|
-
ctx.error,
|
|
457
|
-
"Unauthorized: Cannot start chat",
|
|
458
|
-
);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
const firstMessage = uiMessages[0];
|
|
462
|
-
if (!firstMessage) {
|
|
463
|
-
throw ctx.error(400, {
|
|
464
|
-
message: "At least one message is required",
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
const firstMessageContent = getMessageTextContent(firstMessage);
|
|
468
|
-
|
|
469
|
-
// Convert UIMessages to CoreMessages for streamText
|
|
470
|
-
// In AI SDK v6 this became async — await is a no-op for v5's sync return
|
|
471
|
-
const modelMessages = await convertToModelMessages(uiMessages);
|
|
472
|
-
|
|
473
|
-
// Build system prompt: base config + optional page context
|
|
474
|
-
const pageContextContent =
|
|
475
|
-
pageContext && pageContext.trim()
|
|
476
|
-
? `\n\nCurrent page context:\n${pageContext}`
|
|
477
|
-
: "";
|
|
478
|
-
const systemContent = config.systemPrompt
|
|
479
|
-
? `${config.systemPrompt}${pageContextContent}`
|
|
480
|
-
: pageContextContent || undefined;
|
|
481
|
-
|
|
482
|
-
const messagesWithSystem = systemContent
|
|
483
|
-
? [
|
|
484
|
-
{ role: "system" as const, content: systemContent },
|
|
485
|
-
...modelMessages,
|
|
486
|
-
]
|
|
487
|
-
: modelMessages;
|
|
488
|
-
|
|
489
|
-
// Merge page tool schemas when enablePageTools is on.
|
|
490
|
-
// Built-in schemas are only included when the request's routeName is in
|
|
491
|
-
// the tool's allowlist — this prevents a page from claiming tools that
|
|
492
|
-
// are intended for a different route (e.g. requesting updatePageLayers
|
|
493
|
-
// from a blog page). Consumer clientToolSchemas are trusted as-is.
|
|
494
|
-
const activePageTools: Record<string, Tool> =
|
|
495
|
-
config.enablePageTools &&
|
|
496
|
-
availableTools &&
|
|
497
|
-
availableTools.length > 0
|
|
498
|
-
? (() => {
|
|
499
|
-
const consumerSchemas: Record<string, Tool> =
|
|
500
|
-
(config.clientToolSchemas as Record<string, Tool>) ?? {};
|
|
501
|
-
return Object.fromEntries(
|
|
502
|
-
availableTools
|
|
503
|
-
.filter((name) => {
|
|
504
|
-
// Built-in tool: require routeName to be in its allowlist
|
|
505
|
-
if (name in BUILT_IN_PAGE_TOOL_SCHEMAS) {
|
|
506
|
-
const allowed =
|
|
507
|
-
BUILT_IN_PAGE_TOOL_ROUTE_ALLOWLIST[name];
|
|
508
|
-
return (
|
|
509
|
-
allowed &&
|
|
510
|
-
routeName &&
|
|
511
|
-
allowed.includes(routeName)
|
|
512
|
-
);
|
|
513
|
-
}
|
|
514
|
-
// Consumer-defined tool: allow if schema is registered
|
|
515
|
-
return name in consumerSchemas;
|
|
516
|
-
})
|
|
517
|
-
.map((name) => {
|
|
518
|
-
const schema =
|
|
519
|
-
BUILT_IN_PAGE_TOOL_SCHEMAS[name] ??
|
|
520
|
-
consumerSchemas[name]!;
|
|
521
|
-
return [name, schema];
|
|
522
|
-
}),
|
|
523
|
-
);
|
|
524
|
-
})()
|
|
525
|
-
: {};
|
|
526
|
-
|
|
527
|
-
// Consumer hook: user-level tool authorization.
|
|
528
|
-
// Runs after the structural routeName allowlist check.
|
|
529
|
-
// A thrown Error is caught and returned as a 403 response.
|
|
530
|
-
if (
|
|
531
|
-
config.hooks?.onBeforeToolsActivated &&
|
|
532
|
-
Object.keys(activePageTools).length > 0
|
|
533
|
-
) {
|
|
534
|
-
try {
|
|
535
|
-
const allowed = await config.hooks.onBeforeToolsActivated(
|
|
536
|
-
Object.keys(activePageTools),
|
|
537
|
-
routeName,
|
|
538
|
-
context,
|
|
539
|
-
);
|
|
540
|
-
const allowedSet = new Set(allowed);
|
|
541
|
-
for (const key of Object.keys(activePageTools)) {
|
|
542
|
-
if (!allowedSet.has(key)) {
|
|
543
|
-
delete activePageTools[key];
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
} catch (hookError) {
|
|
547
|
-
throw ctx.error(403, {
|
|
548
|
-
message:
|
|
549
|
-
hookError instanceof Error
|
|
550
|
-
? hookError.message
|
|
551
|
-
: "Unauthorized: Tool activation denied",
|
|
552
|
-
});
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
// Page tools are layered under server-side tools so that a
|
|
557
|
-
// clientToolSchemas entry with the same name as a tool in
|
|
558
|
-
// config.tools never silently drops its `execute` function.
|
|
559
|
-
// Server-side tools always win on collision.
|
|
560
|
-
const mergedTools =
|
|
561
|
-
Object.keys(activePageTools).length > 0
|
|
562
|
-
? { ...activePageTools, ...config.tools }
|
|
563
|
-
: config.tools;
|
|
564
|
-
|
|
565
|
-
// PUBLIC MODE: Stream without persistence
|
|
566
|
-
if (isPublicMode) {
|
|
567
|
-
const result = streamText({
|
|
568
|
-
model: config.model,
|
|
569
|
-
messages: messagesWithSystem,
|
|
570
|
-
tools: mergedTools,
|
|
571
|
-
// Enable multi-step tool calls if tools are configured
|
|
572
|
-
...(mergedTools ? { stopWhen: stepCountIs(5) } : {}),
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
return result.toUIMessageStreamResponse({
|
|
576
|
-
originalMessages: uiMessages,
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// AUTHENTICATED MODE: Persist conversations
|
|
581
|
-
// Get userId if getUserId is configured
|
|
582
|
-
let userId: string | null = null;
|
|
583
|
-
if (config.getUserId) {
|
|
584
|
-
const resolvedUserId = await config.getUserId(context);
|
|
585
|
-
if (!resolvedUserId) {
|
|
586
|
-
throw ctx.error(403, {
|
|
587
|
-
message: "Unauthorized: User authentication required",
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
userId = resolvedUserId;
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
let convId = conversationId;
|
|
594
|
-
|
|
595
|
-
// Create or verify conversation
|
|
596
|
-
if (!convId) {
|
|
597
|
-
const newConv = await adapter.create<Conversation>({
|
|
598
|
-
model: "conversation",
|
|
599
|
-
data: {
|
|
600
|
-
...(userId ? { userId } : {}),
|
|
601
|
-
title: firstMessageContent.slice(0, 50) || "New Conversation",
|
|
602
|
-
createdAt: new Date(),
|
|
603
|
-
updatedAt: new Date(),
|
|
604
|
-
},
|
|
605
|
-
});
|
|
606
|
-
convId = newConv.id;
|
|
607
|
-
} else {
|
|
608
|
-
const existing = await adapter.findMany<Conversation>({
|
|
609
|
-
model: "conversation",
|
|
610
|
-
where: [{ field: "id", value: convId, operator: "eq" }],
|
|
611
|
-
limit: 1,
|
|
612
|
-
});
|
|
613
|
-
if (!existing.length) {
|
|
614
|
-
const newConv = await adapter.create<Conversation>({
|
|
615
|
-
model: "conversation",
|
|
616
|
-
data: {
|
|
617
|
-
id: convId,
|
|
618
|
-
...(userId ? { userId } : {}),
|
|
619
|
-
title:
|
|
620
|
-
firstMessageContent.slice(0, 50) || "New Conversation",
|
|
621
|
-
createdAt: new Date(),
|
|
622
|
-
updatedAt: new Date(),
|
|
623
|
-
} as Conversation,
|
|
624
|
-
});
|
|
625
|
-
convId = newConv.id;
|
|
626
|
-
} else {
|
|
627
|
-
// Verify ownership if userId is set
|
|
628
|
-
const conv = existing[0]!;
|
|
629
|
-
if (userId && conv.userId && conv.userId !== userId) {
|
|
630
|
-
throw ctx.error(403, {
|
|
631
|
-
message: "Unauthorized: Cannot access this conversation",
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
// Sync database messages with client state
|
|
638
|
-
// The client sends all messages for the conversation
|
|
639
|
-
// We need to ensure the DB matches this state before adding the assistant response
|
|
640
|
-
const existingMessages = await adapter.findMany<Message>({
|
|
641
|
-
model: "message",
|
|
642
|
-
where: [
|
|
643
|
-
{
|
|
644
|
-
field: "conversationId",
|
|
645
|
-
value: convId as string,
|
|
646
|
-
operator: "eq",
|
|
647
|
-
},
|
|
648
|
-
],
|
|
649
|
-
sortBy: { field: "createdAt", direction: "asc" },
|
|
650
|
-
});
|
|
651
|
-
|
|
652
|
-
const lastIncomingMessage = uiMessages[uiMessages.length - 1];
|
|
653
|
-
const isNewUserMessage = lastIncomingMessage?.role === "user";
|
|
654
|
-
|
|
655
|
-
// Determine the expected DB count before we add new messages:
|
|
656
|
-
// - If last incoming is a user message: it might be new or existing
|
|
657
|
-
// - Compare with what's in DB to determine if it's a new message or regenerate
|
|
658
|
-
let expectedDbCount: number;
|
|
659
|
-
let shouldAddUserMessage = false;
|
|
660
|
-
|
|
661
|
-
if (isNewUserMessage) {
|
|
662
|
-
// Check if this user message already exists in DB
|
|
663
|
-
// by comparing the last user message in each
|
|
664
|
-
const lastDbUserMessage = [...existingMessages]
|
|
665
|
-
.reverse()
|
|
666
|
-
.find((m) => m.role === "user");
|
|
667
|
-
const incomingUserContent =
|
|
668
|
-
serializeMessageParts(lastIncomingMessage);
|
|
669
|
-
|
|
670
|
-
if (
|
|
671
|
-
lastDbUserMessage &&
|
|
672
|
-
lastDbUserMessage.content === incomingUserContent
|
|
673
|
-
) {
|
|
674
|
-
// The user message already exists - this is a regenerate
|
|
675
|
-
// DB should have all incoming messages (no new user message to add)
|
|
676
|
-
expectedDbCount = uiMessages.length;
|
|
677
|
-
shouldAddUserMessage = false;
|
|
678
|
-
} else {
|
|
679
|
-
// New user message - DB should have incoming count - 1
|
|
680
|
-
expectedDbCount = uiMessages.length - 1;
|
|
681
|
-
shouldAddUserMessage = true;
|
|
682
|
-
}
|
|
683
|
-
} else {
|
|
684
|
-
// Last message is not user (unusual case)
|
|
685
|
-
expectedDbCount = uiMessages.length;
|
|
686
|
-
shouldAddUserMessage = false;
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
// If DB has more messages than expected, delete the excess
|
|
690
|
-
// This handles both edit (truncated history) and retry (regenerating last response)
|
|
691
|
-
// Use a transaction to ensure atomicity - if create fails, deletions are rolled back
|
|
692
|
-
const actualDbCount = existingMessages.length;
|
|
693
|
-
const messagesToDelete =
|
|
694
|
-
actualDbCount > expectedDbCount
|
|
695
|
-
? existingMessages.slice(expectedDbCount)
|
|
696
|
-
: [];
|
|
697
|
-
|
|
698
|
-
// Wrap deletion and creation in a transaction for atomicity
|
|
699
|
-
// This prevents data loss if the create operation fails after deletions
|
|
700
|
-
await adapter.transaction(async (tx) => {
|
|
701
|
-
// Delete excess messages
|
|
702
|
-
for (const msg of messagesToDelete) {
|
|
703
|
-
await tx.delete({
|
|
704
|
-
model: "message",
|
|
705
|
-
where: [{ field: "id", value: msg.id }],
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
// Save user message if it's new
|
|
710
|
-
if (shouldAddUserMessage && lastIncomingMessage) {
|
|
711
|
-
await tx.create<Message>({
|
|
712
|
-
model: "message",
|
|
713
|
-
data: {
|
|
714
|
-
conversationId: convId as string,
|
|
715
|
-
role: "user",
|
|
716
|
-
content: serializeMessageParts(lastIncomingMessage),
|
|
717
|
-
createdAt: new Date(),
|
|
718
|
-
},
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
|
-
});
|
|
722
|
-
|
|
723
|
-
const result = streamText({
|
|
724
|
-
model: config.model,
|
|
725
|
-
messages: messagesWithSystem,
|
|
726
|
-
tools: mergedTools,
|
|
727
|
-
// Enable multi-step tool calls if tools are configured
|
|
728
|
-
...(mergedTools ? { stopWhen: stepCountIs(5) } : {}),
|
|
729
|
-
onFinish: async (completion: { text: string }) => {
|
|
730
|
-
// Wrap in try-catch since this runs after the response is sent
|
|
731
|
-
// and errors would otherwise become unhandled promise rejections
|
|
732
|
-
try {
|
|
733
|
-
// Save assistant message (serialize as parts for consistency)
|
|
734
|
-
const assistantParts = completion.text
|
|
735
|
-
? [{ type: "text", text: completion.text }]
|
|
736
|
-
: [];
|
|
737
|
-
await adapter.create<Message>({
|
|
738
|
-
model: "message",
|
|
739
|
-
data: {
|
|
740
|
-
conversationId: convId as string,
|
|
741
|
-
role: "assistant",
|
|
742
|
-
content: JSON.stringify(assistantParts),
|
|
743
|
-
createdAt: new Date(),
|
|
744
|
-
},
|
|
745
|
-
});
|
|
746
|
-
|
|
747
|
-
// Update conversation timestamp
|
|
748
|
-
await adapter.update({
|
|
749
|
-
model: "conversation",
|
|
750
|
-
where: [{ field: "id", value: convId as string }],
|
|
751
|
-
update: { updatedAt: new Date() },
|
|
752
|
-
});
|
|
753
|
-
|
|
754
|
-
// Lifecycle hook
|
|
755
|
-
if (config.hooks?.onAfterChat) {
|
|
756
|
-
const messages = await adapter.findMany<Message>({
|
|
757
|
-
model: "message",
|
|
758
|
-
where: [
|
|
759
|
-
{
|
|
760
|
-
field: "conversationId",
|
|
761
|
-
value: convId as string,
|
|
762
|
-
operator: "eq",
|
|
763
|
-
},
|
|
764
|
-
],
|
|
765
|
-
sortBy: { field: "createdAt", direction: "asc" },
|
|
766
|
-
});
|
|
767
|
-
await config.hooks.onAfterChat(
|
|
768
|
-
convId as string,
|
|
769
|
-
messages,
|
|
770
|
-
context,
|
|
771
|
-
);
|
|
772
|
-
}
|
|
773
|
-
} catch (error) {
|
|
774
|
-
// Log the error since the response is already sent
|
|
775
|
-
console.error("[ai-chat] Error in onFinish callback:", error);
|
|
776
|
-
// Call error hook if configured
|
|
777
|
-
if (config.hooks?.onChatError) {
|
|
778
|
-
try {
|
|
779
|
-
await config.hooks.onChatError(error as Error, context);
|
|
780
|
-
} catch (hookError) {
|
|
781
|
-
console.error(
|
|
782
|
-
"[ai-chat] Error in onChatError hook:",
|
|
783
|
-
hookError,
|
|
784
|
-
);
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
},
|
|
789
|
-
});
|
|
790
|
-
|
|
791
|
-
// Return the stream response with conversation ID header
|
|
792
|
-
// This allows the client to know which conversation was created/used
|
|
793
|
-
const response = result.toUIMessageStreamResponse({
|
|
794
|
-
originalMessages: uiMessages,
|
|
795
|
-
});
|
|
796
|
-
|
|
797
|
-
// Add the conversation ID header to the response
|
|
798
|
-
const headers = new Headers(response.headers);
|
|
799
|
-
headers.set("X-Conversation-Id", convId as string);
|
|
800
|
-
|
|
801
|
-
return new Response(response.body, {
|
|
802
|
-
status: response.status,
|
|
803
|
-
statusText: response.statusText,
|
|
804
|
-
headers,
|
|
805
|
-
});
|
|
806
|
-
} catch (error) {
|
|
807
|
-
if (config.hooks?.onChatError) {
|
|
808
|
-
await config.hooks.onChatError(error as Error, context);
|
|
809
|
-
}
|
|
810
|
-
throw error;
|
|
811
|
-
}
|
|
812
|
-
},
|
|
813
|
-
);
|
|
814
|
-
|
|
815
|
-
// ============== Create Conversation ==============
|
|
816
|
-
const createConversation = createEndpoint(
|
|
817
|
-
"/chat/conversations",
|
|
818
|
-
{
|
|
819
|
-
method: "POST",
|
|
820
|
-
body: createConversationSchema,
|
|
821
|
-
},
|
|
822
|
-
async (ctx) => {
|
|
823
|
-
// Public mode: conversations are not persisted
|
|
824
|
-
if (isPublicMode) {
|
|
825
|
-
throw ctx.error(404, {
|
|
826
|
-
message: "Conversations not available in public mode",
|
|
827
|
-
});
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
const { id, title } = ctx.body;
|
|
831
|
-
const context: ChatApiContext = {
|
|
832
|
-
body: ctx.body,
|
|
833
|
-
headers: ctx.headers,
|
|
834
|
-
};
|
|
835
|
-
|
|
836
|
-
try {
|
|
837
|
-
// Get userId if configured
|
|
838
|
-
const userId = await resolveUserId(context, () => {
|
|
839
|
-
throw ctx.error(403, {
|
|
840
|
-
message: "Unauthorized: User authentication required",
|
|
841
|
-
});
|
|
842
|
-
});
|
|
843
|
-
|
|
844
|
-
// Authorization hook
|
|
845
|
-
if (config.hooks?.onBeforeCreateConversation) {
|
|
846
|
-
await runHook(
|
|
847
|
-
() =>
|
|
848
|
-
config.hooks!.onBeforeCreateConversation!(
|
|
849
|
-
{ id, title },
|
|
850
|
-
context,
|
|
851
|
-
),
|
|
852
|
-
ctx.error,
|
|
853
|
-
"Unauthorized: Cannot create conversation",
|
|
854
|
-
);
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
const newConv = await adapter.create<Conversation>({
|
|
858
|
-
model: "conversation",
|
|
859
|
-
data: {
|
|
860
|
-
...(id ? { id } : {}),
|
|
861
|
-
...(userId ? { userId } : {}),
|
|
862
|
-
title: title || "New Conversation",
|
|
863
|
-
createdAt: new Date(),
|
|
864
|
-
updatedAt: new Date(),
|
|
865
|
-
} as Conversation,
|
|
866
|
-
});
|
|
867
|
-
|
|
868
|
-
// Lifecycle hook
|
|
869
|
-
if (config.hooks?.onConversationCreated) {
|
|
870
|
-
await config.hooks.onConversationCreated(newConv, context);
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
return newConv;
|
|
874
|
-
} catch (error) {
|
|
875
|
-
if (config.hooks?.onCreateConversationError) {
|
|
876
|
-
await config.hooks.onCreateConversationError(
|
|
877
|
-
error as Error,
|
|
878
|
-
context,
|
|
879
|
-
);
|
|
880
|
-
}
|
|
881
|
-
throw error;
|
|
882
|
-
}
|
|
883
|
-
},
|
|
97
|
+
{ method: "POST", body: chatRequestSchema, requireRequest: true },
|
|
98
|
+
operations.startStream.route((ctx) => ctx.body),
|
|
884
99
|
);
|
|
885
|
-
|
|
886
|
-
// ============== List Conversations ==============
|
|
887
100
|
const listConversations = createEndpoint(
|
|
888
101
|
"/chat/conversations",
|
|
889
|
-
{
|
|
890
|
-
|
|
891
|
-
},
|
|
892
|
-
async (ctx) => {
|
|
893
|
-
// Public mode: return empty list
|
|
894
|
-
if (isPublicMode) {
|
|
895
|
-
return [];
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
const context: ChatApiContext = {
|
|
899
|
-
headers: ctx.headers,
|
|
900
|
-
};
|
|
901
|
-
|
|
902
|
-
try {
|
|
903
|
-
// Get userId if configured
|
|
904
|
-
const userId = await resolveUserId(context, () => {
|
|
905
|
-
throw ctx.error(403, {
|
|
906
|
-
message: "Unauthorized: User authentication required",
|
|
907
|
-
});
|
|
908
|
-
});
|
|
909
|
-
|
|
910
|
-
// Authorization hook
|
|
911
|
-
if (config.hooks?.onBeforeListConversations) {
|
|
912
|
-
await runHook(
|
|
913
|
-
() => config.hooks!.onBeforeListConversations!(context),
|
|
914
|
-
ctx.error,
|
|
915
|
-
"Unauthorized: Cannot list conversations",
|
|
916
|
-
);
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
// Build where conditions - filter by userId if set
|
|
920
|
-
const whereConditions: Array<{
|
|
921
|
-
field: string;
|
|
922
|
-
value: string;
|
|
923
|
-
operator: "eq";
|
|
924
|
-
}> = [];
|
|
925
|
-
if (userId) {
|
|
926
|
-
whereConditions.push({
|
|
927
|
-
field: "userId",
|
|
928
|
-
value: userId,
|
|
929
|
-
operator: "eq",
|
|
930
|
-
});
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
const conversations = await adapter.findMany<Conversation>({
|
|
934
|
-
model: "conversation",
|
|
935
|
-
where: whereConditions.length > 0 ? whereConditions : undefined,
|
|
936
|
-
sortBy: { field: "updatedAt", direction: "desc" },
|
|
937
|
-
});
|
|
938
|
-
|
|
939
|
-
// Lifecycle hook
|
|
940
|
-
if (config.hooks?.onConversationsRead) {
|
|
941
|
-
await config.hooks.onConversationsRead(conversations, context);
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
return conversations;
|
|
945
|
-
} catch (error) {
|
|
946
|
-
if (config.hooks?.onListConversationsError) {
|
|
947
|
-
await config.hooks.onListConversationsError(
|
|
948
|
-
error as Error,
|
|
949
|
-
context,
|
|
950
|
-
);
|
|
951
|
-
}
|
|
952
|
-
throw error;
|
|
953
|
-
}
|
|
954
|
-
},
|
|
102
|
+
{ method: "GET", requireRequest: true },
|
|
103
|
+
operations.listConversations.route(() => ({})),
|
|
955
104
|
);
|
|
956
|
-
|
|
957
|
-
// ============== Get Conversation ==============
|
|
958
105
|
const getConversation = createEndpoint(
|
|
959
106
|
"/chat/conversations/:id",
|
|
960
107
|
{
|
|
961
108
|
method: "GET",
|
|
109
|
+
params: ConversationOperationInputSchema,
|
|
110
|
+
requireRequest: true,
|
|
962
111
|
},
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
const { id } = ctx.params;
|
|
972
|
-
const context: ChatApiContext = {
|
|
973
|
-
params: ctx.params,
|
|
974
|
-
headers: ctx.headers,
|
|
975
|
-
};
|
|
976
|
-
|
|
977
|
-
try {
|
|
978
|
-
// Get userId if configured
|
|
979
|
-
const userId = await resolveUserId(context, () => {
|
|
980
|
-
throw ctx.error(403, {
|
|
981
|
-
message: "Unauthorized: User authentication required",
|
|
982
|
-
});
|
|
983
|
-
});
|
|
984
|
-
|
|
985
|
-
// Authorization hook
|
|
986
|
-
if (config.hooks?.onBeforeGetConversation) {
|
|
987
|
-
await runHook(
|
|
988
|
-
() => config.hooks!.onBeforeGetConversation!(id, context),
|
|
989
|
-
ctx.error,
|
|
990
|
-
"Unauthorized: Cannot get conversation",
|
|
991
|
-
);
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
// Fetch conversation with messages in a single query using join
|
|
995
|
-
const conversations =
|
|
996
|
-
await adapter.findMany<ConversationWithMessages>({
|
|
997
|
-
model: "conversation",
|
|
998
|
-
where: [{ field: "id", value: id, operator: "eq" }],
|
|
999
|
-
limit: 1,
|
|
1000
|
-
join: {
|
|
1001
|
-
message: true,
|
|
1002
|
-
},
|
|
1003
|
-
});
|
|
1004
|
-
|
|
1005
|
-
if (!conversations.length) {
|
|
1006
|
-
throw ctx.error(404, { message: "Conversation not found" });
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
const conversation = conversations[0]!;
|
|
1010
|
-
|
|
1011
|
-
// Verify ownership if userId is set
|
|
1012
|
-
if (
|
|
1013
|
-
userId &&
|
|
1014
|
-
conversation.userId &&
|
|
1015
|
-
conversation.userId !== userId
|
|
1016
|
-
) {
|
|
1017
|
-
throw ctx.error(403, {
|
|
1018
|
-
message: "Unauthorized: Cannot access this conversation",
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
// Sort messages by createdAt and map to result format
|
|
1023
|
-
const messages = (conversation.message || []).sort(
|
|
1024
|
-
(a, b) =>
|
|
1025
|
-
new Date(a.createdAt).getTime() -
|
|
1026
|
-
new Date(b.createdAt).getTime(),
|
|
1027
|
-
);
|
|
1028
|
-
|
|
1029
|
-
const { message: _, ...conversationWithoutJoin } = conversation;
|
|
1030
|
-
const result = {
|
|
1031
|
-
...conversationWithoutJoin,
|
|
1032
|
-
messages,
|
|
1033
|
-
} as Conversation & { messages: Message[] };
|
|
1034
|
-
|
|
1035
|
-
// Lifecycle hook
|
|
1036
|
-
if (config.hooks?.onConversationRead) {
|
|
1037
|
-
await config.hooks.onConversationRead(result, context);
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
return result;
|
|
1041
|
-
} catch (error) {
|
|
1042
|
-
if (config.hooks?.onGetConversationError) {
|
|
1043
|
-
await config.hooks.onGetConversationError(
|
|
1044
|
-
error as Error,
|
|
1045
|
-
context,
|
|
1046
|
-
);
|
|
1047
|
-
}
|
|
1048
|
-
throw error;
|
|
1049
|
-
}
|
|
112
|
+
operations.getConversation.route((ctx) => ctx.params),
|
|
113
|
+
);
|
|
114
|
+
const createConversation = createEndpoint(
|
|
115
|
+
"/chat/conversations",
|
|
116
|
+
{
|
|
117
|
+
method: "POST",
|
|
118
|
+
body: createConversationSchema,
|
|
119
|
+
requireRequest: true,
|
|
1050
120
|
},
|
|
121
|
+
operations.createConversation.route((ctx) => ctx.body),
|
|
1051
122
|
);
|
|
1052
|
-
|
|
1053
|
-
// ============== Update Conversation ==============
|
|
1054
123
|
const updateConversation = createEndpoint(
|
|
1055
124
|
"/chat/conversations/:id",
|
|
1056
125
|
{
|
|
1057
126
|
method: "PUT",
|
|
1058
127
|
body: updateConversationSchema,
|
|
128
|
+
requireRequest: true,
|
|
1059
129
|
},
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
const { id } = ctx.params;
|
|
1069
|
-
const { title } = ctx.body;
|
|
1070
|
-
const context: ChatApiContext = {
|
|
1071
|
-
params: ctx.params,
|
|
1072
|
-
body: ctx.body,
|
|
1073
|
-
headers: ctx.headers,
|
|
1074
|
-
};
|
|
1075
|
-
|
|
1076
|
-
try {
|
|
1077
|
-
// Get userId if configured
|
|
1078
|
-
const userId = await resolveUserId(context, () => {
|
|
1079
|
-
throw ctx.error(403, {
|
|
1080
|
-
message: "Unauthorized: User authentication required",
|
|
1081
|
-
});
|
|
1082
|
-
});
|
|
1083
|
-
|
|
1084
|
-
// Check ownership before update
|
|
1085
|
-
const existing = await adapter.findMany<Conversation>({
|
|
1086
|
-
model: "conversation",
|
|
1087
|
-
where: [{ field: "id", value: id, operator: "eq" }],
|
|
1088
|
-
limit: 1,
|
|
1089
|
-
});
|
|
1090
|
-
|
|
1091
|
-
if (!existing.length) {
|
|
1092
|
-
throw ctx.error(404, { message: "Conversation not found" });
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
const conversation = existing[0]!;
|
|
1096
|
-
if (
|
|
1097
|
-
userId &&
|
|
1098
|
-
conversation.userId &&
|
|
1099
|
-
conversation.userId !== userId
|
|
1100
|
-
) {
|
|
1101
|
-
throw ctx.error(403, {
|
|
1102
|
-
message: "Unauthorized: Cannot update this conversation",
|
|
1103
|
-
});
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
// Authorization hook
|
|
1107
|
-
if (config.hooks?.onBeforeUpdateConversation) {
|
|
1108
|
-
await runHook(
|
|
1109
|
-
() =>
|
|
1110
|
-
config.hooks!.onBeforeUpdateConversation!(
|
|
1111
|
-
id,
|
|
1112
|
-
{ title },
|
|
1113
|
-
context,
|
|
1114
|
-
),
|
|
1115
|
-
ctx.error,
|
|
1116
|
-
"Unauthorized: Cannot update conversation",
|
|
1117
|
-
);
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
const updated = await adapter.update<Conversation>({
|
|
1121
|
-
model: "conversation",
|
|
1122
|
-
where: [{ field: "id", value: id }],
|
|
1123
|
-
update: {
|
|
1124
|
-
...(title !== undefined ? { title } : {}),
|
|
1125
|
-
updatedAt: new Date(),
|
|
1126
|
-
},
|
|
1127
|
-
});
|
|
1128
|
-
|
|
1129
|
-
if (!updated) {
|
|
1130
|
-
throw ctx.error(404, { message: "Conversation not found" });
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
// Lifecycle hook
|
|
1134
|
-
if (config.hooks?.onConversationUpdated) {
|
|
1135
|
-
await config.hooks.onConversationUpdated(updated, context);
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
return updated;
|
|
1139
|
-
} catch (error) {
|
|
1140
|
-
if (config.hooks?.onUpdateConversationError) {
|
|
1141
|
-
await config.hooks.onUpdateConversationError(
|
|
1142
|
-
error as Error,
|
|
1143
|
-
context,
|
|
1144
|
-
);
|
|
1145
|
-
}
|
|
1146
|
-
throw error;
|
|
1147
|
-
}
|
|
1148
|
-
},
|
|
130
|
+
operations.updateConversation.route((ctx) =>
|
|
131
|
+
UpdateConversationOperationInputSchema.parse({
|
|
132
|
+
id: ctx.params.id,
|
|
133
|
+
data: ctx.body,
|
|
134
|
+
}),
|
|
135
|
+
),
|
|
1149
136
|
);
|
|
1150
|
-
|
|
1151
|
-
// ============== Delete Conversation ==============
|
|
1152
137
|
const deleteConversation = createEndpoint(
|
|
1153
138
|
"/chat/conversations/:id",
|
|
1154
|
-
{
|
|
1155
|
-
|
|
1156
|
-
},
|
|
1157
|
-
async (ctx) => {
|
|
1158
|
-
// Public mode: conversations are not persisted
|
|
1159
|
-
if (isPublicMode) {
|
|
1160
|
-
throw ctx.error(404, {
|
|
1161
|
-
message: "Conversations not available in public mode",
|
|
1162
|
-
});
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
const { id } = ctx.params;
|
|
1166
|
-
const context: ChatApiContext = {
|
|
1167
|
-
params: ctx.params,
|
|
1168
|
-
headers: ctx.headers,
|
|
1169
|
-
};
|
|
1170
|
-
|
|
1171
|
-
try {
|
|
1172
|
-
// Get userId if configured
|
|
1173
|
-
const userId = await resolveUserId(context, () => {
|
|
1174
|
-
throw ctx.error(403, {
|
|
1175
|
-
message: "Unauthorized: User authentication required",
|
|
1176
|
-
});
|
|
1177
|
-
});
|
|
1178
|
-
|
|
1179
|
-
// Check ownership before delete
|
|
1180
|
-
const existing = await adapter.findMany<Conversation>({
|
|
1181
|
-
model: "conversation",
|
|
1182
|
-
where: [{ field: "id", value: id, operator: "eq" }],
|
|
1183
|
-
limit: 1,
|
|
1184
|
-
});
|
|
1185
|
-
|
|
1186
|
-
if (!existing.length) {
|
|
1187
|
-
throw ctx.error(404, { message: "Conversation not found" });
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
const conversation = existing[0]!;
|
|
1191
|
-
if (
|
|
1192
|
-
userId &&
|
|
1193
|
-
conversation.userId &&
|
|
1194
|
-
conversation.userId !== userId
|
|
1195
|
-
) {
|
|
1196
|
-
throw ctx.error(403, {
|
|
1197
|
-
message: "Unauthorized: Cannot delete this conversation",
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
// Authorization hook
|
|
1202
|
-
if (config.hooks?.onBeforeDeleteConversation) {
|
|
1203
|
-
await runHook(
|
|
1204
|
-
() => config.hooks!.onBeforeDeleteConversation!(id, context),
|
|
1205
|
-
ctx.error,
|
|
1206
|
-
"Unauthorized: Cannot delete conversation",
|
|
1207
|
-
);
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
// Messages are automatically deleted via cascade (onDelete: "cascade")
|
|
1211
|
-
await adapter.delete({
|
|
1212
|
-
model: "conversation",
|
|
1213
|
-
where: [{ field: "id", value: id }],
|
|
1214
|
-
});
|
|
1215
|
-
|
|
1216
|
-
// Lifecycle hook
|
|
1217
|
-
if (config.hooks?.onConversationDeleted) {
|
|
1218
|
-
await config.hooks.onConversationDeleted(id, context);
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
return { success: true };
|
|
1222
|
-
} catch (error) {
|
|
1223
|
-
if (config.hooks?.onDeleteConversationError) {
|
|
1224
|
-
await config.hooks.onDeleteConversationError(
|
|
1225
|
-
error as Error,
|
|
1226
|
-
context,
|
|
1227
|
-
);
|
|
1228
|
-
}
|
|
1229
|
-
throw error;
|
|
1230
|
-
}
|
|
1231
|
-
},
|
|
139
|
+
{ method: "DELETE", requireRequest: true },
|
|
140
|
+
operations.deleteConversation.route((ctx) => ({ id: ctx.params.id })),
|
|
1232
141
|
);
|
|
1233
142
|
|
|
1234
143
|
return {
|
|
1235
144
|
chat,
|
|
1236
|
-
createConversation,
|
|
1237
145
|
listConversations,
|
|
1238
146
|
getConversation,
|
|
147
|
+
createConversation,
|
|
1239
148
|
updateConversation,
|
|
1240
149
|
deleteConversation,
|
|
1241
|
-
};
|
|
150
|
+
} as const;
|
|
1242
151
|
},
|
|
1243
152
|
});
|
|
153
|
+
};
|
|
1244
154
|
|
|
1245
155
|
export type AiChatApiRouter = ReturnType<
|
|
1246
156
|
ReturnType<typeof aiChatBackendPlugin>["routes"]
|