@btst/stack 3.0.0-rc.2 → 3.0.0-rc.3
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.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.B8PG21zX.d.mts +764 -0
- package/dist/shared/stack.BFP_9pRX.d.cts +707 -0
- package/dist/shared/{stack.DzwZw-Ck.d.cts → stack.BGzgFx3R.d.cts} +2 -2
- 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.BMmvEBH_.d.ts +118 -0
- package/dist/shared/stack.BOZRaVpu.d.cts +1184 -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.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.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.BuxUQqL8.d.ts +408 -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.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.CX83YNuS.d.cts +408 -0
- 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.oVIdV7XS.d.mts → stack.CjCSDfWy.d.mts} +2 -2
- 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.CvlC5kqe.d.cts +331 -0
- package/dist/shared/stack.CxKc9evq.d.ts +23 -0
- package/dist/shared/stack.CyalJ0j6.d.ts +764 -0
- package/dist/shared/stack.D6Pg-ufX.d.cts +764 -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.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.DlBoNqYu.d.ts +1184 -0
- 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.DseBJmGF.d.ts → stack.Dpg_JjIo.d.ts} +2 -2
- package/dist/shared/stack.Dvy7FmaA.d.mts +1184 -0
- package/dist/shared/stack.DxHPKr2R.d.mts +436 -0
- package/dist/shared/stack.Egr3RWhA.d.mts +408 -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.v2O65JqF.d.cts +351 -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.Csi-4Mgz.d.cts} +1 -1
- package/dist/shared/{stack.D18Dq3ve.d.ts → stack.Csi-4Mgz.d.mts} +1 -1
- package/dist/shared/{stack.D18Dq3ve.d.cts → stack.Csi-4Mgz.d.ts} +1 -1
|
@@ -0,0 +1,2051 @@
|
|
|
1
|
+
import { createMemoryAdapter } from "@btst/adapter-memory";
|
|
2
|
+
import { type DatabaseDefinition, type DBAdapter, defineDb } from "@btst/db";
|
|
3
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { createBackendStack } from "../../../api";
|
|
6
|
+
import { defineAuthorization } from "../../../authorization";
|
|
7
|
+
import { createServerAuth } from "../../../authorization/server";
|
|
8
|
+
import {
|
|
9
|
+
aiChatBackendPlugin,
|
|
10
|
+
AI_CHAT_LIFECYCLE_HOOK_MIGRATIONS,
|
|
11
|
+
AI_CHAT_OPERATION_INVENTORY,
|
|
12
|
+
AI_CHAT_RAW_ESCAPE_HATCH_INVENTORY,
|
|
13
|
+
} from "../api";
|
|
14
|
+
import { aiChatPermissions } from "../permissions";
|
|
15
|
+
import type { Conversation, Message } from "../types";
|
|
16
|
+
|
|
17
|
+
const { streamText } = vi.hoisted(() => ({
|
|
18
|
+
streamText: vi.fn(() => ({
|
|
19
|
+
toUIMessageStreamResponse: () => new Response("stream", { status: 200 }),
|
|
20
|
+
})),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
vi.mock("ai", async (importOriginal) => ({
|
|
24
|
+
...(await importOriginal<typeof import("ai")>()),
|
|
25
|
+
convertToModelMessages: (messages: unknown) => messages,
|
|
26
|
+
stepCountIs: () => () => false,
|
|
27
|
+
streamText,
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
type Identity = { id: string; role: "user" | "admin" };
|
|
31
|
+
|
|
32
|
+
const fullAuthorization = defineAuthorization({
|
|
33
|
+
identity: z.object({ id: z.string(), role: z.enum(["user", "admin"]) }),
|
|
34
|
+
permissions: [aiChatPermissions] as const,
|
|
35
|
+
rules: ({ aiChat }) => {
|
|
36
|
+
const owns = ({
|
|
37
|
+
identity,
|
|
38
|
+
facts,
|
|
39
|
+
}: {
|
|
40
|
+
identity: Identity | null;
|
|
41
|
+
facts: { ownerId?: string };
|
|
42
|
+
}) => identity?.role === "admin" || identity?.id === facts.ownerId;
|
|
43
|
+
return [
|
|
44
|
+
aiChat.conversation.read.when(({ identity, facts }) =>
|
|
45
|
+
facts.scope === "collection"
|
|
46
|
+
? identity !== null
|
|
47
|
+
: owns({ identity, facts }),
|
|
48
|
+
),
|
|
49
|
+
aiChat.conversation.create.when(({ identity }) => identity !== null),
|
|
50
|
+
aiChat.conversation.update.when(owns),
|
|
51
|
+
aiChat.conversation.delete.when(owns),
|
|
52
|
+
aiChat.message.send.when(({ identity, facts }) =>
|
|
53
|
+
facts.createsConversation
|
|
54
|
+
? identity !== null
|
|
55
|
+
: owns({ identity, facts }),
|
|
56
|
+
),
|
|
57
|
+
aiChat.message.edit.when(owns),
|
|
58
|
+
aiChat.message.retry.when(owns),
|
|
59
|
+
aiChat.attachment.send.when(owns),
|
|
60
|
+
aiChat.tool.activate.when(owns),
|
|
61
|
+
aiChat.stream.start.when(({ identity, facts }) =>
|
|
62
|
+
facts.createsConversation
|
|
63
|
+
? identity !== null
|
|
64
|
+
: owns({ identity, facts }),
|
|
65
|
+
),
|
|
66
|
+
];
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
function request(
|
|
71
|
+
path: string,
|
|
72
|
+
options?: { method?: string; identity?: Identity; body?: unknown },
|
|
73
|
+
) {
|
|
74
|
+
const headers = new Headers();
|
|
75
|
+
if (options?.identity) {
|
|
76
|
+
headers.set("x-user-id", options.identity.id);
|
|
77
|
+
headers.set("x-user-role", options.identity.role);
|
|
78
|
+
}
|
|
79
|
+
if (options?.body !== undefined)
|
|
80
|
+
headers.set("content-type", "application/json");
|
|
81
|
+
return new Request(`http://localhost/api${path}`, {
|
|
82
|
+
method: options?.method ?? "GET",
|
|
83
|
+
headers,
|
|
84
|
+
...(options?.body === undefined
|
|
85
|
+
? {}
|
|
86
|
+
: { body: JSON.stringify(options.body) }),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const model = {} as never;
|
|
91
|
+
const memory = (db: DatabaseDefinition) => createMemoryAdapter(db)({});
|
|
92
|
+
const databaseLikeMemory = (db: DatabaseDefinition): DBAdapter => ({
|
|
93
|
+
...createMemoryAdapter(db)({}),
|
|
94
|
+
id: "database-like-memory-test",
|
|
95
|
+
});
|
|
96
|
+
const owner = { id: "owner-1", role: "user" } as const;
|
|
97
|
+
const viewer = { id: "viewer-1", role: "user" } as const;
|
|
98
|
+
const admin = { id: "admin-1", role: "admin" } as const;
|
|
99
|
+
const messageBody = {
|
|
100
|
+
messages: [
|
|
101
|
+
{ id: "message-1", role: "user", parts: [{ type: "text", text: "Hi" }] },
|
|
102
|
+
],
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
function backend(options?: {
|
|
106
|
+
access?: "authorized" | "public";
|
|
107
|
+
authorization?: typeof fullAuthorization;
|
|
108
|
+
adapter?: (db: DatabaseDefinition) => DBAdapter;
|
|
109
|
+
hooks?: Parameters<typeof aiChatBackendPlugin>[0]["hooks"];
|
|
110
|
+
enablePageTools?: boolean;
|
|
111
|
+
tools?: Parameters<typeof aiChatBackendPlugin>[0]["tools"];
|
|
112
|
+
getIdentity?: (
|
|
113
|
+
request: Request,
|
|
114
|
+
) => Identity | null | Promise<Identity | null>;
|
|
115
|
+
}) {
|
|
116
|
+
return createBackendStack({
|
|
117
|
+
basePath: "/api",
|
|
118
|
+
plugins: {
|
|
119
|
+
aiChat: aiChatBackendPlugin({
|
|
120
|
+
model,
|
|
121
|
+
access: options?.access ?? "authorized",
|
|
122
|
+
enablePageTools: options?.enablePageTools,
|
|
123
|
+
hooks: options?.hooks,
|
|
124
|
+
tools: options?.tools,
|
|
125
|
+
}),
|
|
126
|
+
},
|
|
127
|
+
adapter: options?.adapter ?? memory,
|
|
128
|
+
auth: createServerAuth({
|
|
129
|
+
authorization: options?.authorization ?? fullAuthorization,
|
|
130
|
+
getIdentity: ({ request }) =>
|
|
131
|
+
options?.getIdentity
|
|
132
|
+
? options.getIdentity(request)
|
|
133
|
+
: (() => {
|
|
134
|
+
const id = request.headers.get("x-user-id");
|
|
135
|
+
const role = request.headers.get("x-user-role");
|
|
136
|
+
return id && (role === "user" || role === "admin")
|
|
137
|
+
? { id, role: role as "user" | "admin" }
|
|
138
|
+
: null;
|
|
139
|
+
})(),
|
|
140
|
+
}),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function seedConversation(
|
|
145
|
+
app: ReturnType<typeof backend>,
|
|
146
|
+
userId: string = owner.id,
|
|
147
|
+
title = "Private",
|
|
148
|
+
) {
|
|
149
|
+
const now = new Date("2026-01-01T00:00:00.000Z");
|
|
150
|
+
return app.adapter.create<Conversation>({
|
|
151
|
+
model: "conversation",
|
|
152
|
+
data: { userId, title, createdAt: now, updatedAt: now },
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function seedMessage(
|
|
157
|
+
app: ReturnType<typeof backend>,
|
|
158
|
+
conversationId: string,
|
|
159
|
+
role: Message["role"],
|
|
160
|
+
parts: readonly Record<string, unknown>[],
|
|
161
|
+
) {
|
|
162
|
+
return app.adapter.create<Message>({
|
|
163
|
+
model: "message",
|
|
164
|
+
data: {
|
|
165
|
+
conversationId,
|
|
166
|
+
role,
|
|
167
|
+
content: JSON.stringify(parts),
|
|
168
|
+
createdAt: new Date(),
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
describe("AI Chat operation authorization", () => {
|
|
174
|
+
beforeEach(() => streamText.mockClear());
|
|
175
|
+
|
|
176
|
+
it("publishes one executable inventory for every maintained transport", () => {
|
|
177
|
+
const plugin = aiChatBackendPlugin({ model });
|
|
178
|
+
const adapter = createMemoryAdapter(defineDb({}).use(plugin.dbPlugin))({});
|
|
179
|
+
const operations = plugin.operations?.(adapter);
|
|
180
|
+
expect(Object.keys(operations ?? {}).sort()).toEqual([
|
|
181
|
+
"createConversation",
|
|
182
|
+
"deleteConversation",
|
|
183
|
+
"getConversation",
|
|
184
|
+
"listConversations",
|
|
185
|
+
"startStream",
|
|
186
|
+
"updateConversation",
|
|
187
|
+
]);
|
|
188
|
+
expect(AI_CHAT_OPERATION_INVENTORY.startStream).toMatchObject({
|
|
189
|
+
http: "POST /chat",
|
|
190
|
+
request: "forRequest(request).operations.aiChat.startStream",
|
|
191
|
+
trusted: "trusted.aiChat.startStream",
|
|
192
|
+
publicSemantics: [
|
|
193
|
+
"stream.start",
|
|
194
|
+
"message.send",
|
|
195
|
+
"message.edit",
|
|
196
|
+
"message.retry",
|
|
197
|
+
"attachment.send",
|
|
198
|
+
"tool.activate",
|
|
199
|
+
],
|
|
200
|
+
publicWhenConfigured: true,
|
|
201
|
+
});
|
|
202
|
+
expect(AI_CHAT_RAW_ESCAPE_HATCH_INVENTORY).toEqual([
|
|
203
|
+
"@btst/stack/plugins/ai-chat/api#getAllConversations",
|
|
204
|
+
"@btst/stack/plugins/ai-chat/api#getConversationById",
|
|
205
|
+
]);
|
|
206
|
+
expect(Object.keys(AI_CHAT_LIFECYCLE_HOOK_MIGRATIONS)).toHaveLength(12);
|
|
207
|
+
expect(Object.values(AI_CHAT_LIFECYCLE_HOOK_MIGRATIONS)).toEqual([
|
|
208
|
+
"onBeforeActivateTools",
|
|
209
|
+
"onAfterListConversations",
|
|
210
|
+
"onAfterGetConversation",
|
|
211
|
+
"onAfterCreateConversation",
|
|
212
|
+
"onAfterUpdateConversation",
|
|
213
|
+
"onAfterDeleteConversation",
|
|
214
|
+
"onErrorChat",
|
|
215
|
+
"onErrorListConversations",
|
|
216
|
+
"onErrorGetConversation",
|
|
217
|
+
"onErrorCreateConversation",
|
|
218
|
+
"onErrorUpdateConversation",
|
|
219
|
+
"onErrorDeleteConversation",
|
|
220
|
+
]);
|
|
221
|
+
expect(operations?.startStream.resultMode).toBe("passthrough");
|
|
222
|
+
expect(operations?.listConversations.resultMode).toBe("immutable");
|
|
223
|
+
expect(operations?.listConversations.access).toBe("authorized");
|
|
224
|
+
const publicPlugin = aiChatBackendPlugin({ model, access: "public" });
|
|
225
|
+
const publicAdapter = createMemoryAdapter(
|
|
226
|
+
defineDb({}).use(publicPlugin.dbPlugin),
|
|
227
|
+
)({});
|
|
228
|
+
const publicOperations = publicPlugin.operations?.(publicAdapter);
|
|
229
|
+
expect(publicOperations?.startStream.access).toBe("public");
|
|
230
|
+
expect(publicOperations?.listConversations.access).toBe("authorized");
|
|
231
|
+
expect(() =>
|
|
232
|
+
aiChatPermissions.message.retry({
|
|
233
|
+
conversationId: "conversation-1",
|
|
234
|
+
messageId: 42 as never,
|
|
235
|
+
}),
|
|
236
|
+
).toThrow();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("keeps explicit public chat cold-anonymous while history remains unavailable", async () => {
|
|
240
|
+
const before = vi.fn();
|
|
241
|
+
const app = backend({
|
|
242
|
+
access: "public",
|
|
243
|
+
hooks: { onBeforeChat: before },
|
|
244
|
+
getIdentity: () => {
|
|
245
|
+
throw new Error("public chat must stay cold-anonymous");
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
const response = await app.handler(
|
|
249
|
+
request("/chat", { method: "POST", body: messageBody }),
|
|
250
|
+
);
|
|
251
|
+
expect(response.status).toBe(200);
|
|
252
|
+
expect(await response.text()).toBe("stream");
|
|
253
|
+
expect(before).toHaveBeenCalledOnce();
|
|
254
|
+
expect(streamText).toHaveBeenCalledOnce();
|
|
255
|
+
expect((await app.handler(request("/chat/conversations"))).status).toBe(
|
|
256
|
+
404,
|
|
257
|
+
);
|
|
258
|
+
await expect(
|
|
259
|
+
app
|
|
260
|
+
.forRequest(request("/public-history"))
|
|
261
|
+
.operations.aiChat.listConversations({}),
|
|
262
|
+
).rejects.toMatchObject({
|
|
263
|
+
statusCode: 404,
|
|
264
|
+
code: "HISTORY_UNAVAILABLE",
|
|
265
|
+
});
|
|
266
|
+
await expect(
|
|
267
|
+
app.trusted.aiChat.createConversation({ title: "Unavailable" }),
|
|
268
|
+
).rejects.toMatchObject({
|
|
269
|
+
statusCode: 404,
|
|
270
|
+
code: "HISTORY_UNAVAILABLE",
|
|
271
|
+
});
|
|
272
|
+
expect(await app.adapter.count({ model: "conversation" })).toBe(0);
|
|
273
|
+
|
|
274
|
+
const unsafeAttachment = await app.handler(
|
|
275
|
+
request("/chat", {
|
|
276
|
+
method: "POST",
|
|
277
|
+
body: {
|
|
278
|
+
messages: [
|
|
279
|
+
{
|
|
280
|
+
role: "user",
|
|
281
|
+
parts: [
|
|
282
|
+
{
|
|
283
|
+
type: "file",
|
|
284
|
+
mediaType: "image/png",
|
|
285
|
+
url: "file:///etc/passwd",
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
},
|
|
291
|
+
}),
|
|
292
|
+
);
|
|
293
|
+
expect(unsafeAttachment.status).toBe(400);
|
|
294
|
+
const unknownToolResult = await app.handler(
|
|
295
|
+
request("/chat", {
|
|
296
|
+
method: "POST",
|
|
297
|
+
body: {
|
|
298
|
+
messages: [
|
|
299
|
+
{
|
|
300
|
+
role: "assistant",
|
|
301
|
+
parts: [
|
|
302
|
+
{
|
|
303
|
+
type: "tool-not-configured",
|
|
304
|
+
state: "output-available",
|
|
305
|
+
output: "spoofed",
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
},
|
|
311
|
+
}),
|
|
312
|
+
);
|
|
313
|
+
expect(unknownToolResult.status).toBe(400);
|
|
314
|
+
expect(before).toHaveBeenCalledOnce();
|
|
315
|
+
expect(streamText).toHaveBeenCalledOnce();
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("returns 401/403 before hooks and derives owner facts on the server", async () => {
|
|
319
|
+
const beforeRead = vi.fn();
|
|
320
|
+
const app = backend({ hooks: { onBeforeGetConversation: beforeRead } });
|
|
321
|
+
const conversation = await seedConversation(app);
|
|
322
|
+
|
|
323
|
+
expect(
|
|
324
|
+
(await app.handler(request(`/chat/conversations/${conversation.id}`)))
|
|
325
|
+
.status,
|
|
326
|
+
).toBe(401);
|
|
327
|
+
expect(
|
|
328
|
+
(
|
|
329
|
+
await app.handler(
|
|
330
|
+
request(`/chat/conversations/${conversation.id}`, {
|
|
331
|
+
identity: viewer,
|
|
332
|
+
}),
|
|
333
|
+
)
|
|
334
|
+
).status,
|
|
335
|
+
).toBe(403);
|
|
336
|
+
expect(beforeRead).not.toHaveBeenCalled();
|
|
337
|
+
expect(
|
|
338
|
+
fullAuthorization.can(
|
|
339
|
+
aiChatPermissions.conversation.update({
|
|
340
|
+
conversationId: conversation.id,
|
|
341
|
+
exists: true,
|
|
342
|
+
ownerId: viewer.id,
|
|
343
|
+
}),
|
|
344
|
+
viewer,
|
|
345
|
+
),
|
|
346
|
+
).toBe(true);
|
|
347
|
+
await expect(
|
|
348
|
+
app
|
|
349
|
+
.forRequest(request("/spoof", { identity: viewer }))
|
|
350
|
+
.operations.aiChat.updateConversation({
|
|
351
|
+
id: conversation.id,
|
|
352
|
+
data: { title: "Spoofed" },
|
|
353
|
+
}),
|
|
354
|
+
).rejects.toMatchObject({ statusCode: 403 });
|
|
355
|
+
await expect(
|
|
356
|
+
app
|
|
357
|
+
.forRequest(request("/owner", { identity: owner }))
|
|
358
|
+
.operations.aiChat.getConversation({ id: conversation.id }),
|
|
359
|
+
).resolves.toMatchObject({ id: conversation.id, userId: owner.id });
|
|
360
|
+
await expect(
|
|
361
|
+
app
|
|
362
|
+
.forRequest(request("/admin", { identity: admin }))
|
|
363
|
+
.operations.aiChat.getConversation({ id: conversation.id }),
|
|
364
|
+
).resolves.toMatchObject({ id: conversation.id });
|
|
365
|
+
expect(beforeRead).toHaveBeenCalledTimes(2);
|
|
366
|
+
await expect(
|
|
367
|
+
app
|
|
368
|
+
.forRequest(request("/owner", { identity: owner }))
|
|
369
|
+
.operations.aiChat.updateConversation({
|
|
370
|
+
id: conversation.id,
|
|
371
|
+
data: { title: "Renamed by owner" },
|
|
372
|
+
}),
|
|
373
|
+
).resolves.toMatchObject({
|
|
374
|
+
id: conversation.id,
|
|
375
|
+
title: "Renamed by owner",
|
|
376
|
+
});
|
|
377
|
+
await expect(
|
|
378
|
+
app
|
|
379
|
+
.forRequest(request("/owner", { identity: owner }))
|
|
380
|
+
.operations.aiChat.deleteConversation({ id: conversation.id }),
|
|
381
|
+
).resolves.toEqual({ success: true });
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("keeps ordinary HTTP results JSON-serialized and programmatic results immutable", async () => {
|
|
385
|
+
const app = backend();
|
|
386
|
+
const httpResponse = await app.handler(
|
|
387
|
+
request("/chat/conversations", {
|
|
388
|
+
method: "POST",
|
|
389
|
+
identity: owner,
|
|
390
|
+
body: { title: "HTTP conversation" },
|
|
391
|
+
}),
|
|
392
|
+
);
|
|
393
|
+
expect(httpResponse.status).toBe(200);
|
|
394
|
+
await expect(httpResponse.json()).resolves.toMatchObject({
|
|
395
|
+
title: "HTTP conversation",
|
|
396
|
+
userId: owner.id,
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
const result = await app
|
|
400
|
+
.forRequest(request("/create", { identity: owner }))
|
|
401
|
+
.operations.aiChat.createConversation({ title: "Request conversation" });
|
|
402
|
+
expect(result).toMatchObject({ title: "Request conversation" });
|
|
403
|
+
expect(Object.isFrozen(result)).toBe(true);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it.each(["http", "request", "trusted"] as const)(
|
|
407
|
+
"invokes every renamed history result phase through %s execution",
|
|
408
|
+
async (transport) => {
|
|
409
|
+
const phases: string[] = [];
|
|
410
|
+
const app = backend({
|
|
411
|
+
hooks: {
|
|
412
|
+
onAfterListConversations: () => {
|
|
413
|
+
phases.push("list");
|
|
414
|
+
},
|
|
415
|
+
onAfterGetConversation: () => {
|
|
416
|
+
phases.push("get");
|
|
417
|
+
},
|
|
418
|
+
onAfterCreateConversation: () => {
|
|
419
|
+
phases.push("create");
|
|
420
|
+
},
|
|
421
|
+
onAfterUpdateConversation: () => {
|
|
422
|
+
phases.push("update");
|
|
423
|
+
},
|
|
424
|
+
onAfterDeleteConversation: () => {
|
|
425
|
+
phases.push("delete");
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
const target = await seedConversation(app);
|
|
430
|
+
|
|
431
|
+
if (transport === "http") {
|
|
432
|
+
const responses = [
|
|
433
|
+
await app.handler(
|
|
434
|
+
request("/chat/conversations", { identity: owner }),
|
|
435
|
+
),
|
|
436
|
+
await app.handler(
|
|
437
|
+
request(`/chat/conversations/${target.id}`, { identity: owner }),
|
|
438
|
+
),
|
|
439
|
+
await app.handler(
|
|
440
|
+
request("/chat/conversations", {
|
|
441
|
+
method: "POST",
|
|
442
|
+
identity: owner,
|
|
443
|
+
body: { title: "Created" },
|
|
444
|
+
}),
|
|
445
|
+
),
|
|
446
|
+
await app.handler(
|
|
447
|
+
request(`/chat/conversations/${target.id}`, {
|
|
448
|
+
method: "PUT",
|
|
449
|
+
identity: owner,
|
|
450
|
+
body: { title: "Updated" },
|
|
451
|
+
}),
|
|
452
|
+
),
|
|
453
|
+
await app.handler(
|
|
454
|
+
request(`/chat/conversations/${target.id}`, {
|
|
455
|
+
method: "DELETE",
|
|
456
|
+
identity: owner,
|
|
457
|
+
}),
|
|
458
|
+
),
|
|
459
|
+
];
|
|
460
|
+
expect(responses.map((response) => response.status)).toEqual([
|
|
461
|
+
200, 200, 200, 200, 200,
|
|
462
|
+
]);
|
|
463
|
+
} else if (transport === "request") {
|
|
464
|
+
const api = app.forRequest(request("/lifecycle", { identity: owner }))
|
|
465
|
+
.operations.aiChat;
|
|
466
|
+
await api.listConversations({});
|
|
467
|
+
await api.getConversation({ id: target.id });
|
|
468
|
+
await api.createConversation({ title: "Created" });
|
|
469
|
+
await api.updateConversation({
|
|
470
|
+
id: target.id,
|
|
471
|
+
data: { title: "Updated" },
|
|
472
|
+
});
|
|
473
|
+
await api.deleteConversation({ id: target.id });
|
|
474
|
+
} else {
|
|
475
|
+
await app.trusted.aiChat.listConversations({});
|
|
476
|
+
await app.trusted.aiChat.getConversation({ id: target.id });
|
|
477
|
+
await app.trusted.aiChat.createConversation({ title: "Created" });
|
|
478
|
+
await app.trusted.aiChat.updateConversation({
|
|
479
|
+
id: target.id,
|
|
480
|
+
data: { title: "Updated" },
|
|
481
|
+
});
|
|
482
|
+
await app.trusted.aiChat.deleteConversation({ id: target.id });
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
expect(phases).toEqual(["list", "get", "create", "update", "delete"]);
|
|
486
|
+
},
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
it.each(["http", "request", "trusted"] as const)(
|
|
490
|
+
"invokes every renamed history error phase through %s execution",
|
|
491
|
+
async (transport) => {
|
|
492
|
+
const phases: string[] = [];
|
|
493
|
+
const fail = (phase: string) => () => {
|
|
494
|
+
phases.push(`before:${phase}`);
|
|
495
|
+
throw new Error(`${phase} rejected`);
|
|
496
|
+
};
|
|
497
|
+
const observe = (phase: string) => (error: Error) => {
|
|
498
|
+
phases.push(`error:${phase}:${error.message}`);
|
|
499
|
+
};
|
|
500
|
+
const app = backend({
|
|
501
|
+
hooks: {
|
|
502
|
+
onBeforeListConversations: fail("list"),
|
|
503
|
+
onErrorListConversations: observe("list"),
|
|
504
|
+
onBeforeGetConversation: fail("get"),
|
|
505
|
+
onErrorGetConversation: observe("get"),
|
|
506
|
+
onBeforeCreateConversation: fail("create"),
|
|
507
|
+
onErrorCreateConversation: observe("create"),
|
|
508
|
+
onBeforeUpdateConversation: fail("update"),
|
|
509
|
+
onErrorUpdateConversation: observe("update"),
|
|
510
|
+
onBeforeDeleteConversation: fail("delete"),
|
|
511
|
+
onErrorDeleteConversation: observe("delete"),
|
|
512
|
+
},
|
|
513
|
+
});
|
|
514
|
+
const target = await seedConversation(app);
|
|
515
|
+
|
|
516
|
+
if (transport === "http") {
|
|
517
|
+
const responses = [
|
|
518
|
+
await app.handler(
|
|
519
|
+
request("/chat/conversations", { identity: owner }),
|
|
520
|
+
),
|
|
521
|
+
await app.handler(
|
|
522
|
+
request(`/chat/conversations/${target.id}`, { identity: owner }),
|
|
523
|
+
),
|
|
524
|
+
await app.handler(
|
|
525
|
+
request("/chat/conversations", {
|
|
526
|
+
method: "POST",
|
|
527
|
+
identity: owner,
|
|
528
|
+
body: { title: "Rejected" },
|
|
529
|
+
}),
|
|
530
|
+
),
|
|
531
|
+
await app.handler(
|
|
532
|
+
request(`/chat/conversations/${target.id}`, {
|
|
533
|
+
method: "PUT",
|
|
534
|
+
identity: owner,
|
|
535
|
+
body: { title: "Rejected" },
|
|
536
|
+
}),
|
|
537
|
+
),
|
|
538
|
+
await app.handler(
|
|
539
|
+
request(`/chat/conversations/${target.id}`, {
|
|
540
|
+
method: "DELETE",
|
|
541
|
+
identity: owner,
|
|
542
|
+
}),
|
|
543
|
+
),
|
|
544
|
+
];
|
|
545
|
+
expect(responses.map((response) => response.status)).toEqual([
|
|
546
|
+
403, 403, 403, 403, 403,
|
|
547
|
+
]);
|
|
548
|
+
} else {
|
|
549
|
+
const api =
|
|
550
|
+
transport === "request"
|
|
551
|
+
? app.forRequest(request("/lifecycle", { identity: owner }))
|
|
552
|
+
.operations.aiChat
|
|
553
|
+
: app.trusted.aiChat;
|
|
554
|
+
for (const operation of [
|
|
555
|
+
() => api.listConversations({}),
|
|
556
|
+
() => api.getConversation({ id: target.id }),
|
|
557
|
+
() => api.createConversation({ title: "Rejected" }),
|
|
558
|
+
() =>
|
|
559
|
+
api.updateConversation({
|
|
560
|
+
id: target.id,
|
|
561
|
+
data: { title: "Rejected" },
|
|
562
|
+
}),
|
|
563
|
+
() => api.deleteConversation({ id: target.id }),
|
|
564
|
+
]) {
|
|
565
|
+
await expect(operation()).rejects.toMatchObject({ statusCode: 403 });
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
expect(phases).toEqual([
|
|
570
|
+
"before:list",
|
|
571
|
+
"error:list:list rejected",
|
|
572
|
+
"before:get",
|
|
573
|
+
"error:get:get rejected",
|
|
574
|
+
"before:create",
|
|
575
|
+
"error:create:create rejected",
|
|
576
|
+
"before:update",
|
|
577
|
+
"error:update:update rejected",
|
|
578
|
+
"before:delete",
|
|
579
|
+
"error:delete:delete rejected",
|
|
580
|
+
]);
|
|
581
|
+
},
|
|
582
|
+
);
|
|
583
|
+
|
|
584
|
+
it.each(["http", "request", "trusted"] as const)(
|
|
585
|
+
"keeps explicit tool activation filtering on %s execution",
|
|
586
|
+
async (transport) => {
|
|
587
|
+
const activated = vi.fn(() => [] as const);
|
|
588
|
+
const app = backend({
|
|
589
|
+
enablePageTools: true,
|
|
590
|
+
hooks: { onBeforeActivateTools: activated },
|
|
591
|
+
});
|
|
592
|
+
const conversation = await seedConversation(app);
|
|
593
|
+
const input = {
|
|
594
|
+
...messageBody,
|
|
595
|
+
conversationId: conversation.id,
|
|
596
|
+
availableTools: ["fillBlogForm"],
|
|
597
|
+
routeName: "newPost",
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
if (transport === "http") {
|
|
601
|
+
const response = await app.handler(
|
|
602
|
+
request("/chat", {
|
|
603
|
+
method: "POST",
|
|
604
|
+
identity: owner,
|
|
605
|
+
body: input,
|
|
606
|
+
}),
|
|
607
|
+
);
|
|
608
|
+
expect(response.status).toBe(200);
|
|
609
|
+
} else if (transport === "request") {
|
|
610
|
+
await expect(
|
|
611
|
+
app
|
|
612
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
613
|
+
.operations.aiChat.startStream(input),
|
|
614
|
+
).resolves.toBeInstanceOf(Response);
|
|
615
|
+
} else {
|
|
616
|
+
await expect(
|
|
617
|
+
app.trusted.aiChat.startStream({
|
|
618
|
+
...input,
|
|
619
|
+
trustedUserId: owner.id,
|
|
620
|
+
}),
|
|
621
|
+
).resolves.toBeInstanceOf(Response);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
expect(activated).toHaveBeenCalledWith(
|
|
625
|
+
["fillBlogForm"],
|
|
626
|
+
"newPost",
|
|
627
|
+
expect.any(Object),
|
|
628
|
+
);
|
|
629
|
+
expect(streamText).toHaveBeenLastCalledWith(
|
|
630
|
+
expect.not.objectContaining({ tools: expect.anything() }),
|
|
631
|
+
);
|
|
632
|
+
},
|
|
633
|
+
);
|
|
634
|
+
|
|
635
|
+
it("preserves validation, fact, authorization, lifecycle, and domain ordering", async () => {
|
|
636
|
+
const events: string[] = [];
|
|
637
|
+
let rejectBefore = false;
|
|
638
|
+
const orderedAuthorization = defineAuthorization({
|
|
639
|
+
identity: z.object({ id: z.string(), role: z.enum(["user", "admin"]) }),
|
|
640
|
+
permissions: [aiChatPermissions] as const,
|
|
641
|
+
rules: ({ aiChat }) => [
|
|
642
|
+
aiChat.conversation.update.when(({ facts }) => {
|
|
643
|
+
events.push(`authorize:${facts.exists}`);
|
|
644
|
+
return true;
|
|
645
|
+
}),
|
|
646
|
+
],
|
|
647
|
+
});
|
|
648
|
+
const app = backend({
|
|
649
|
+
authorization: orderedAuthorization as typeof fullAuthorization,
|
|
650
|
+
hooks: {
|
|
651
|
+
onBeforeUpdateConversation: (_id, _data, context) => {
|
|
652
|
+
events.push(`before:${context.facts.exists}`);
|
|
653
|
+
if (rejectBefore) throw new Error("before rejected");
|
|
654
|
+
},
|
|
655
|
+
onAfterUpdateConversation: (conversation) => {
|
|
656
|
+
events.push(`after:${conversation.title}`);
|
|
657
|
+
},
|
|
658
|
+
onErrorUpdateConversation: (error) => {
|
|
659
|
+
events.push(`error:${error.message}`);
|
|
660
|
+
},
|
|
661
|
+
},
|
|
662
|
+
});
|
|
663
|
+
const conversation = await seedConversation(app);
|
|
664
|
+
|
|
665
|
+
await expect(
|
|
666
|
+
app
|
|
667
|
+
.forRequest(request("/invalid", { identity: owner }))
|
|
668
|
+
.operations.aiChat.updateConversation({
|
|
669
|
+
id: conversation.id,
|
|
670
|
+
data: { title: "" },
|
|
671
|
+
}),
|
|
672
|
+
).rejects.toBeDefined();
|
|
673
|
+
expect(events).toEqual([]);
|
|
674
|
+
|
|
675
|
+
await app
|
|
676
|
+
.forRequest(request("/valid", { identity: owner }))
|
|
677
|
+
.operations.aiChat.updateConversation({
|
|
678
|
+
id: conversation.id,
|
|
679
|
+
data: { title: "Request update" },
|
|
680
|
+
});
|
|
681
|
+
expect(events).toEqual([
|
|
682
|
+
"authorize:true",
|
|
683
|
+
"before:true",
|
|
684
|
+
"after:Request update",
|
|
685
|
+
]);
|
|
686
|
+
await expect(
|
|
687
|
+
app.adapter.findOne<Conversation>({
|
|
688
|
+
model: "conversation",
|
|
689
|
+
where: [{ field: "id", value: conversation.id }],
|
|
690
|
+
}),
|
|
691
|
+
).resolves.toMatchObject({ title: "Request update" });
|
|
692
|
+
|
|
693
|
+
events.length = 0;
|
|
694
|
+
await app.trusted.aiChat.updateConversation({
|
|
695
|
+
id: conversation.id,
|
|
696
|
+
data: { title: "Trusted update" },
|
|
697
|
+
});
|
|
698
|
+
expect(events).toEqual(["before:true", "after:Trusted update"]);
|
|
699
|
+
await expect(
|
|
700
|
+
app.adapter.findOne<Conversation>({
|
|
701
|
+
model: "conversation",
|
|
702
|
+
where: [{ field: "id", value: conversation.id }],
|
|
703
|
+
}),
|
|
704
|
+
).resolves.toMatchObject({ title: "Trusted update" });
|
|
705
|
+
|
|
706
|
+
events.length = 0;
|
|
707
|
+
rejectBefore = true;
|
|
708
|
+
await expect(
|
|
709
|
+
app
|
|
710
|
+
.forRequest(request("/rejected", { identity: owner }))
|
|
711
|
+
.operations.aiChat.updateConversation({
|
|
712
|
+
id: conversation.id,
|
|
713
|
+
data: { title: "Rejected update" },
|
|
714
|
+
}),
|
|
715
|
+
).rejects.toMatchObject({ statusCode: 403, message: "before rejected" });
|
|
716
|
+
expect(events).toEqual([
|
|
717
|
+
"authorize:true",
|
|
718
|
+
"before:true",
|
|
719
|
+
"error:before rejected",
|
|
720
|
+
]);
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
it("keeps collection scoping server-only and partitions owner histories", async () => {
|
|
724
|
+
const app = backend();
|
|
725
|
+
await seedConversation(app, owner.id, "Owner");
|
|
726
|
+
await seedConversation(app, viewer.id, "Viewer");
|
|
727
|
+
await expect(
|
|
728
|
+
app
|
|
729
|
+
.forRequest(request("/owner", { identity: owner }))
|
|
730
|
+
.operations.aiChat.listConversations({}),
|
|
731
|
+
).resolves.toEqual([
|
|
732
|
+
expect.objectContaining({ title: "Owner", userId: owner.id }),
|
|
733
|
+
]);
|
|
734
|
+
await expect(
|
|
735
|
+
app
|
|
736
|
+
.forRequest(request("/admin", { identity: admin }))
|
|
737
|
+
.operations.aiChat.listConversations({}),
|
|
738
|
+
).resolves.toHaveLength(0);
|
|
739
|
+
|
|
740
|
+
const anonymousCollection = defineAuthorization({
|
|
741
|
+
identity: z.object({ id: z.string(), role: z.enum(["user", "admin"]) }),
|
|
742
|
+
permissions: [aiChatPermissions] as const,
|
|
743
|
+
rules: ({ aiChat }) => [aiChat.conversation.read.allow()],
|
|
744
|
+
});
|
|
745
|
+
const anonymousApp = backend({
|
|
746
|
+
authorization: anonymousCollection as typeof fullAuthorization,
|
|
747
|
+
});
|
|
748
|
+
await seedConversation(anonymousApp, owner.id, "Never public");
|
|
749
|
+
await expect(
|
|
750
|
+
anonymousApp
|
|
751
|
+
.forRequest(request("/anonymous"))
|
|
752
|
+
.operations.aiChat.listConversations({}),
|
|
753
|
+
).resolves.toEqual([]);
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
it("preserves ownerless history when no request authorization is configured", async () => {
|
|
757
|
+
const app = createBackendStack({
|
|
758
|
+
basePath: "/api",
|
|
759
|
+
plugins: { aiChat: aiChatBackendPlugin({ model }) },
|
|
760
|
+
adapter: memory,
|
|
761
|
+
});
|
|
762
|
+
const created = await app.handler(
|
|
763
|
+
request("/chat/conversations", {
|
|
764
|
+
method: "POST",
|
|
765
|
+
body: { title: "Ownerless" },
|
|
766
|
+
}),
|
|
767
|
+
);
|
|
768
|
+
expect(created.status).toBe(200);
|
|
769
|
+
await expect(created.json()).resolves.toMatchObject({
|
|
770
|
+
title: "Ownerless",
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
const listed = await app.handler(request("/chat/conversations"));
|
|
774
|
+
expect(listed.status).toBe(200);
|
|
775
|
+
await expect(listed.json()).resolves.toEqual([
|
|
776
|
+
expect.objectContaining({ title: "Ownerless" }),
|
|
777
|
+
]);
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
it("fails closed before stream hooks or writes without isolated transactions", async () => {
|
|
781
|
+
const before = vi.fn();
|
|
782
|
+
const app = backend({
|
|
783
|
+
adapter: databaseLikeMemory,
|
|
784
|
+
hooks: { onBeforeChat: before },
|
|
785
|
+
});
|
|
786
|
+
const adapterConfig = app.adapter.options?.adapterConfig;
|
|
787
|
+
expect(adapterConfig).toBeDefined();
|
|
788
|
+
if (!adapterConfig) throw new Error("Missing adapter config");
|
|
789
|
+
adapterConfig.transaction = false;
|
|
790
|
+
|
|
791
|
+
await expect(
|
|
792
|
+
app
|
|
793
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
794
|
+
.operations.aiChat.startStream(messageBody),
|
|
795
|
+
).rejects.toMatchObject({
|
|
796
|
+
statusCode: 500,
|
|
797
|
+
code: "ATOMIC_TRANSACTION_REQUIRED",
|
|
798
|
+
});
|
|
799
|
+
expect(before).not.toHaveBeenCalled();
|
|
800
|
+
expect(streamText).not.toHaveBeenCalled();
|
|
801
|
+
expect(await app.adapter.count({ model: "conversation" })).toBe(0);
|
|
802
|
+
expect(await app.adapter.count({ model: "message" })).toBe(0);
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
it("fails closed before completion writes if transaction isolation disappears", async () => {
|
|
806
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
807
|
+
const onErrorChat = vi.fn();
|
|
808
|
+
const app = backend({
|
|
809
|
+
adapter: databaseLikeMemory,
|
|
810
|
+
hooks: { onErrorChat },
|
|
811
|
+
});
|
|
812
|
+
await app
|
|
813
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
814
|
+
.operations.aiChat.startStream(messageBody);
|
|
815
|
+
const finish = (
|
|
816
|
+
streamText.mock.calls as unknown as Array<
|
|
817
|
+
[
|
|
818
|
+
{
|
|
819
|
+
onFinish: (completion: { text: string }) => Promise<void>;
|
|
820
|
+
},
|
|
821
|
+
]
|
|
822
|
+
>
|
|
823
|
+
)[0]?.[0].onFinish;
|
|
824
|
+
expect(finish).toBeDefined();
|
|
825
|
+
if (!finish) throw new Error("Missing stream completion callback");
|
|
826
|
+
const adapterConfig = app.adapter.options?.adapterConfig;
|
|
827
|
+
expect(adapterConfig).toBeDefined();
|
|
828
|
+
if (!adapterConfig) throw new Error("Missing adapter config");
|
|
829
|
+
adapterConfig.transaction = false;
|
|
830
|
+
|
|
831
|
+
await finish({ text: "unsafe answer" });
|
|
832
|
+
|
|
833
|
+
expect(
|
|
834
|
+
await app.adapter.count({
|
|
835
|
+
model: "message",
|
|
836
|
+
where: [{ field: "role", value: "assistant", operator: "eq" }],
|
|
837
|
+
}),
|
|
838
|
+
).toBe(0);
|
|
839
|
+
expect(onErrorChat).toHaveBeenCalledWith(
|
|
840
|
+
expect.objectContaining({ code: "ATOMIC_TRANSACTION_REQUIRED" }),
|
|
841
|
+
expect.any(Object),
|
|
842
|
+
);
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
it("does not let stream.start bypass a denied exact send permission", async () => {
|
|
846
|
+
const streamOnly = defineAuthorization({
|
|
847
|
+
identity: z.object({ id: z.string(), role: z.enum(["user", "admin"]) }),
|
|
848
|
+
permissions: [aiChatPermissions] as const,
|
|
849
|
+
rules: ({ aiChat }) => [
|
|
850
|
+
aiChat.stream.start.allow(),
|
|
851
|
+
aiChat.conversation.create.allow(),
|
|
852
|
+
aiChat.message.send.when(() => false),
|
|
853
|
+
],
|
|
854
|
+
});
|
|
855
|
+
const before = vi.fn();
|
|
856
|
+
const app = backend({
|
|
857
|
+
authorization: streamOnly as typeof fullAuthorization,
|
|
858
|
+
hooks: { onBeforeChat: before },
|
|
859
|
+
});
|
|
860
|
+
await expect(
|
|
861
|
+
app
|
|
862
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
863
|
+
.operations.aiChat.startStream(messageBody),
|
|
864
|
+
).rejects.toMatchObject({ statusCode: 403 });
|
|
865
|
+
expect(before).not.toHaveBeenCalled();
|
|
866
|
+
expect(streamText).not.toHaveBeenCalled();
|
|
867
|
+
expect(await app.adapter.count({ model: "conversation" })).toBe(0);
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
it("preauthorizes retry and edit with server-resolved message ids", async () => {
|
|
871
|
+
const observed: Array<{ intent: string; messageId?: string }> = [];
|
|
872
|
+
const exact = defineAuthorization({
|
|
873
|
+
identity: z.object({ id: z.string(), role: z.enum(["user", "admin"]) }),
|
|
874
|
+
permissions: [aiChatPermissions] as const,
|
|
875
|
+
rules: ({ aiChat }) => [
|
|
876
|
+
aiChat.stream.start.allow(),
|
|
877
|
+
aiChat.message.retry.when(({ facts }) => {
|
|
878
|
+
observed.push({ intent: "retry", messageId: facts.messageId });
|
|
879
|
+
return false;
|
|
880
|
+
}),
|
|
881
|
+
aiChat.message.edit.when(({ facts }) => {
|
|
882
|
+
observed.push({ intent: "edit", messageId: facts.messageId });
|
|
883
|
+
return false;
|
|
884
|
+
}),
|
|
885
|
+
],
|
|
886
|
+
});
|
|
887
|
+
const before = vi.fn();
|
|
888
|
+
const app = backend({
|
|
889
|
+
authorization: exact as typeof fullAuthorization,
|
|
890
|
+
hooks: { onBeforeChat: before },
|
|
891
|
+
});
|
|
892
|
+
const conversation = await seedConversation(app);
|
|
893
|
+
const firstUser = await seedMessage(app, conversation.id, "user", [
|
|
894
|
+
{ type: "text", text: "Original" },
|
|
895
|
+
]);
|
|
896
|
+
await seedMessage(app, conversation.id, "assistant", [
|
|
897
|
+
{ type: "text", text: "First answer" },
|
|
898
|
+
]);
|
|
899
|
+
const latestUser = await seedMessage(app, conversation.id, "user", [
|
|
900
|
+
{ type: "text", text: "Latest" },
|
|
901
|
+
]);
|
|
902
|
+
await seedMessage(app, conversation.id, "assistant", [
|
|
903
|
+
{ type: "text", text: "Latest answer" },
|
|
904
|
+
]);
|
|
905
|
+
|
|
906
|
+
await expect(
|
|
907
|
+
app
|
|
908
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
909
|
+
.operations.aiChat.startStream({
|
|
910
|
+
conversationId: conversation.id,
|
|
911
|
+
messages: [
|
|
912
|
+
{
|
|
913
|
+
id: "spoofed-1",
|
|
914
|
+
role: "user",
|
|
915
|
+
parts: [{ type: "text", text: "Original" }],
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
id: "spoofed-2",
|
|
919
|
+
role: "assistant",
|
|
920
|
+
parts: [{ type: "text", text: "First answer" }],
|
|
921
|
+
},
|
|
922
|
+
{
|
|
923
|
+
id: "spoofed-3",
|
|
924
|
+
role: "user",
|
|
925
|
+
parts: [{ type: "text", text: "Latest" }],
|
|
926
|
+
},
|
|
927
|
+
],
|
|
928
|
+
}),
|
|
929
|
+
).rejects.toMatchObject({ statusCode: 403 });
|
|
930
|
+
await expect(
|
|
931
|
+
app
|
|
932
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
933
|
+
.operations.aiChat.startStream({
|
|
934
|
+
conversationId: conversation.id,
|
|
935
|
+
messages: [
|
|
936
|
+
{
|
|
937
|
+
id: "browser-controlled-id",
|
|
938
|
+
role: "user",
|
|
939
|
+
parts: [{ type: "text", text: "Edited first" }],
|
|
940
|
+
},
|
|
941
|
+
],
|
|
942
|
+
}),
|
|
943
|
+
).rejects.toMatchObject({ statusCode: 403 });
|
|
944
|
+
|
|
945
|
+
expect(observed).toEqual([
|
|
946
|
+
{ intent: "retry", messageId: latestUser.id },
|
|
947
|
+
{ intent: "edit", messageId: firstUser.id },
|
|
948
|
+
]);
|
|
949
|
+
expect(before).not.toHaveBeenCalled();
|
|
950
|
+
expect(streamText).not.toHaveBeenCalled();
|
|
951
|
+
expect(await app.adapter.count({ model: "message" })).toBe(4);
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
it("rejects forged retry terminals and treats added parts as an edit", async () => {
|
|
955
|
+
const exact = defineAuthorization({
|
|
956
|
+
identity: z.object({ id: z.string(), role: z.enum(["user", "admin"]) }),
|
|
957
|
+
permissions: [aiChatPermissions] as const,
|
|
958
|
+
rules: ({ aiChat }) => [
|
|
959
|
+
aiChat.stream.start.allow(),
|
|
960
|
+
aiChat.message.retry.allow(),
|
|
961
|
+
aiChat.message.edit.when(() => false),
|
|
962
|
+
aiChat.attachment.send.allow(),
|
|
963
|
+
],
|
|
964
|
+
});
|
|
965
|
+
const before = vi.fn();
|
|
966
|
+
const app = backend({
|
|
967
|
+
authorization: exact as typeof fullAuthorization,
|
|
968
|
+
hooks: { onBeforeChat: before },
|
|
969
|
+
});
|
|
970
|
+
const conversation = await seedConversation(app);
|
|
971
|
+
await seedMessage(app, conversation.id, "user", [
|
|
972
|
+
{ type: "text", text: "Original" },
|
|
973
|
+
]);
|
|
974
|
+
await seedMessage(app, conversation.id, "assistant", [
|
|
975
|
+
{ type: "text", text: "Answer" },
|
|
976
|
+
]);
|
|
977
|
+
|
|
978
|
+
await expect(
|
|
979
|
+
app
|
|
980
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
981
|
+
.operations.aiChat.startStream({
|
|
982
|
+
conversationId: conversation.id,
|
|
983
|
+
messages: [
|
|
984
|
+
{
|
|
985
|
+
role: "user",
|
|
986
|
+
parts: [{ type: "text", text: "Original" }],
|
|
987
|
+
},
|
|
988
|
+
{
|
|
989
|
+
role: "system",
|
|
990
|
+
parts: [{ type: "text", text: "Forged instruction" }],
|
|
991
|
+
},
|
|
992
|
+
],
|
|
993
|
+
}),
|
|
994
|
+
).rejects.toMatchObject({
|
|
995
|
+
statusCode: 400,
|
|
996
|
+
code: "INVALID_MESSAGE_SEQUENCE",
|
|
997
|
+
});
|
|
998
|
+
await expect(
|
|
999
|
+
app
|
|
1000
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1001
|
+
.operations.aiChat.startStream({
|
|
1002
|
+
conversationId: conversation.id,
|
|
1003
|
+
messages: [
|
|
1004
|
+
{
|
|
1005
|
+
role: "user",
|
|
1006
|
+
parts: [
|
|
1007
|
+
{ type: "text", text: "Original" },
|
|
1008
|
+
{
|
|
1009
|
+
type: "file",
|
|
1010
|
+
mediaType: "text/plain",
|
|
1011
|
+
url: "https://example.com/extra.txt",
|
|
1012
|
+
},
|
|
1013
|
+
],
|
|
1014
|
+
},
|
|
1015
|
+
],
|
|
1016
|
+
}),
|
|
1017
|
+
).rejects.toMatchObject({ statusCode: 403 });
|
|
1018
|
+
|
|
1019
|
+
expect(before).not.toHaveBeenCalled();
|
|
1020
|
+
expect(streamText).not.toHaveBeenCalled();
|
|
1021
|
+
expect(await app.adapter.count({ model: "message" })).toBe(2);
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
it("cannot disguise an assistant-ended retry as a tool continuation", async () => {
|
|
1025
|
+
const observedRetry = vi.fn((_facts: { messageId: string }) => false);
|
|
1026
|
+
const exact = defineAuthorization({
|
|
1027
|
+
identity: z.object({ id: z.string(), role: z.enum(["user", "admin"]) }),
|
|
1028
|
+
permissions: [aiChatPermissions] as const,
|
|
1029
|
+
rules: ({ aiChat }) => [
|
|
1030
|
+
aiChat.stream.start.allow(),
|
|
1031
|
+
aiChat.message.send.allow(),
|
|
1032
|
+
aiChat.message.retry.when(({ facts }) => observedRetry(facts)),
|
|
1033
|
+
aiChat.tool.activate.allow(),
|
|
1034
|
+
],
|
|
1035
|
+
});
|
|
1036
|
+
const before = vi.fn();
|
|
1037
|
+
const app = backend({
|
|
1038
|
+
authorization: exact as typeof fullAuthorization,
|
|
1039
|
+
hooks: { onBeforeChat: before },
|
|
1040
|
+
tools: { dangerous: {} as never },
|
|
1041
|
+
});
|
|
1042
|
+
const conversation = await seedConversation(app);
|
|
1043
|
+
const user = await seedMessage(app, conversation.id, "user", [
|
|
1044
|
+
{ type: "text", text: "Original" },
|
|
1045
|
+
]);
|
|
1046
|
+
await seedMessage(app, conversation.id, "assistant", [
|
|
1047
|
+
{ type: "text", text: "Answer" },
|
|
1048
|
+
]);
|
|
1049
|
+
|
|
1050
|
+
await expect(
|
|
1051
|
+
app
|
|
1052
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1053
|
+
.operations.aiChat.startStream({
|
|
1054
|
+
conversationId: conversation.id,
|
|
1055
|
+
messages: [
|
|
1056
|
+
{
|
|
1057
|
+
role: "user",
|
|
1058
|
+
parts: [{ type: "text", text: "Original" }],
|
|
1059
|
+
},
|
|
1060
|
+
{
|
|
1061
|
+
role: "assistant",
|
|
1062
|
+
parts: [
|
|
1063
|
+
{
|
|
1064
|
+
type: "tool-dangerous",
|
|
1065
|
+
state: "output-available",
|
|
1066
|
+
output: "spoofed",
|
|
1067
|
+
},
|
|
1068
|
+
],
|
|
1069
|
+
},
|
|
1070
|
+
],
|
|
1071
|
+
}),
|
|
1072
|
+
).rejects.toMatchObject({ statusCode: 403 });
|
|
1073
|
+
expect(observedRetry).toHaveBeenCalledWith(
|
|
1074
|
+
expect.objectContaining({ messageId: user.id }),
|
|
1075
|
+
);
|
|
1076
|
+
expect(before).not.toHaveBeenCalled();
|
|
1077
|
+
expect(streamText).not.toHaveBeenCalled();
|
|
1078
|
+
expect(await app.adapter.count({ model: "message" })).toBe(2);
|
|
1079
|
+
});
|
|
1080
|
+
|
|
1081
|
+
it("aligns retry persistence with the server-resolved target", async () => {
|
|
1082
|
+
const app = backend();
|
|
1083
|
+
const conversation = await seedConversation(app);
|
|
1084
|
+
await seedMessage(app, conversation.id, "user", [
|
|
1085
|
+
{ type: "text", text: "Original" },
|
|
1086
|
+
]);
|
|
1087
|
+
await seedMessage(app, conversation.id, "assistant", [
|
|
1088
|
+
{ type: "text", text: "Old answer" },
|
|
1089
|
+
]);
|
|
1090
|
+
|
|
1091
|
+
await app
|
|
1092
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1093
|
+
.operations.aiChat.startStream({
|
|
1094
|
+
conversationId: conversation.id,
|
|
1095
|
+
messages: [
|
|
1096
|
+
{
|
|
1097
|
+
role: "user",
|
|
1098
|
+
parts: [{ type: "text", text: "Original" }],
|
|
1099
|
+
},
|
|
1100
|
+
{
|
|
1101
|
+
role: "assistant",
|
|
1102
|
+
parts: [{ type: "text", text: "Old answer" }],
|
|
1103
|
+
},
|
|
1104
|
+
],
|
|
1105
|
+
});
|
|
1106
|
+
|
|
1107
|
+
const messages = await app.adapter.findMany<Message>({ model: "message" });
|
|
1108
|
+
expect(messages).toHaveLength(1);
|
|
1109
|
+
expect(messages[0]?.role).toBe("user");
|
|
1110
|
+
});
|
|
1111
|
+
|
|
1112
|
+
it("accepts the next user message after persisted tool-continuation rows", async () => {
|
|
1113
|
+
const app = backend();
|
|
1114
|
+
const conversation = await seedConversation(app);
|
|
1115
|
+
await seedMessage(app, conversation.id, "user", [
|
|
1116
|
+
{ type: "text", text: "Inspect" },
|
|
1117
|
+
]);
|
|
1118
|
+
await seedMessage(app, conversation.id, "assistant", []);
|
|
1119
|
+
await seedMessage(app, conversation.id, "assistant", [
|
|
1120
|
+
{ type: "text", text: "Inspection complete" },
|
|
1121
|
+
]);
|
|
1122
|
+
|
|
1123
|
+
await expect(
|
|
1124
|
+
app
|
|
1125
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1126
|
+
.operations.aiChat.startStream({
|
|
1127
|
+
conversationId: conversation.id,
|
|
1128
|
+
messages: [
|
|
1129
|
+
{
|
|
1130
|
+
role: "user",
|
|
1131
|
+
parts: [{ type: "text", text: "Inspect" }],
|
|
1132
|
+
},
|
|
1133
|
+
{
|
|
1134
|
+
role: "assistant",
|
|
1135
|
+
parts: [
|
|
1136
|
+
{
|
|
1137
|
+
type: "tool-inspect",
|
|
1138
|
+
state: "output-available",
|
|
1139
|
+
output: "done",
|
|
1140
|
+
},
|
|
1141
|
+
{ type: "text", text: "Inspection complete" },
|
|
1142
|
+
],
|
|
1143
|
+
},
|
|
1144
|
+
{
|
|
1145
|
+
role: "user",
|
|
1146
|
+
parts: [{ type: "text", text: "What next?" }],
|
|
1147
|
+
},
|
|
1148
|
+
],
|
|
1149
|
+
}),
|
|
1150
|
+
).resolves.toBeInstanceOf(Response);
|
|
1151
|
+
|
|
1152
|
+
const messages = await app.adapter.findMany<Message>({
|
|
1153
|
+
model: "message",
|
|
1154
|
+
sortBy: { field: "createdAt", direction: "asc" },
|
|
1155
|
+
});
|
|
1156
|
+
expect(messages).toHaveLength(4);
|
|
1157
|
+
expect(messages.at(-1)).toMatchObject({
|
|
1158
|
+
role: "user",
|
|
1159
|
+
content: '[{"type":"text","text":"What next?"}]',
|
|
1160
|
+
});
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
it("keeps generated persistence ids authoritative over client message ids", async () => {
|
|
1164
|
+
const app = backend();
|
|
1165
|
+
await app
|
|
1166
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1167
|
+
.operations.aiChat.startStream(messageBody);
|
|
1168
|
+
|
|
1169
|
+
const messages = await app.adapter.findMany<Message>({ model: "message" });
|
|
1170
|
+
expect(messages).toHaveLength(1);
|
|
1171
|
+
expect(messages[0]?.role).toBe("user");
|
|
1172
|
+
expect(messages[0]?.id).not.toBe("message-1");
|
|
1173
|
+
});
|
|
1174
|
+
|
|
1175
|
+
it.each([
|
|
1176
|
+
{
|
|
1177
|
+
name: "attachment",
|
|
1178
|
+
permission: "attachment" as const,
|
|
1179
|
+
body: {
|
|
1180
|
+
messages: [
|
|
1181
|
+
{
|
|
1182
|
+
id: "message-1",
|
|
1183
|
+
role: "user" as const,
|
|
1184
|
+
parts: [
|
|
1185
|
+
{ type: "text", text: "Inspect" },
|
|
1186
|
+
{
|
|
1187
|
+
type: "file",
|
|
1188
|
+
mediaType: "image/png",
|
|
1189
|
+
url: "https://example.com/image.png",
|
|
1190
|
+
},
|
|
1191
|
+
],
|
|
1192
|
+
},
|
|
1193
|
+
],
|
|
1194
|
+
},
|
|
1195
|
+
tools: undefined,
|
|
1196
|
+
},
|
|
1197
|
+
{
|
|
1198
|
+
name: "tool",
|
|
1199
|
+
permission: "tool" as const,
|
|
1200
|
+
body: messageBody,
|
|
1201
|
+
tools: { dangerous: {} as never },
|
|
1202
|
+
},
|
|
1203
|
+
])(
|
|
1204
|
+
"denies exact $name permission before side effects",
|
|
1205
|
+
async ({ permission, body, tools }) => {
|
|
1206
|
+
const exact = defineAuthorization({
|
|
1207
|
+
identity: z.object({ id: z.string(), role: z.enum(["user", "admin"]) }),
|
|
1208
|
+
permissions: [aiChatPermissions] as const,
|
|
1209
|
+
rules: ({ aiChat }) => [
|
|
1210
|
+
aiChat.stream.start.allow(),
|
|
1211
|
+
aiChat.conversation.create.allow(),
|
|
1212
|
+
aiChat.message.send.allow(),
|
|
1213
|
+
aiChat.attachment.send.when(() => permission !== "attachment"),
|
|
1214
|
+
aiChat.tool.activate.when(() => permission !== "tool"),
|
|
1215
|
+
],
|
|
1216
|
+
});
|
|
1217
|
+
const before = vi.fn();
|
|
1218
|
+
const app = backend({
|
|
1219
|
+
authorization: exact as typeof fullAuthorization,
|
|
1220
|
+
hooks: { onBeforeChat: before },
|
|
1221
|
+
tools,
|
|
1222
|
+
});
|
|
1223
|
+
await expect(
|
|
1224
|
+
app
|
|
1225
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1226
|
+
.operations.aiChat.startStream(body),
|
|
1227
|
+
).rejects.toMatchObject({ statusCode: 403 });
|
|
1228
|
+
expect(before).not.toHaveBeenCalled();
|
|
1229
|
+
expect(streamText).not.toHaveBeenCalled();
|
|
1230
|
+
expect(await app.adapter.count({ model: "conversation" })).toBe(0);
|
|
1231
|
+
},
|
|
1232
|
+
);
|
|
1233
|
+
|
|
1234
|
+
it("rejects chat payload safety failures before identity and lifecycle", async () => {
|
|
1235
|
+
const getIdentity = vi.fn(async () => owner);
|
|
1236
|
+
const before = vi.fn();
|
|
1237
|
+
const onError = vi.fn();
|
|
1238
|
+
const app = backend({
|
|
1239
|
+
getIdentity,
|
|
1240
|
+
hooks: { onBeforeChat: before, onErrorChat: onError },
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
await expect(
|
|
1244
|
+
app
|
|
1245
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1246
|
+
.operations.aiChat.startStream({ messages: [] }),
|
|
1247
|
+
).rejects.toMatchObject({ statusCode: 400, code: "EMPTY_CHAT" });
|
|
1248
|
+
await expect(
|
|
1249
|
+
app
|
|
1250
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1251
|
+
.operations.aiChat.startStream({
|
|
1252
|
+
messages: [
|
|
1253
|
+
{
|
|
1254
|
+
role: "user",
|
|
1255
|
+
parts: [
|
|
1256
|
+
{
|
|
1257
|
+
type: "file",
|
|
1258
|
+
mediaType: "text/plain",
|
|
1259
|
+
url: "file:///private.txt",
|
|
1260
|
+
},
|
|
1261
|
+
],
|
|
1262
|
+
},
|
|
1263
|
+
],
|
|
1264
|
+
}),
|
|
1265
|
+
).rejects.toMatchObject({
|
|
1266
|
+
statusCode: 400,
|
|
1267
|
+
code: "INVALID_ATTACHMENT_URL",
|
|
1268
|
+
});
|
|
1269
|
+
|
|
1270
|
+
expect(getIdentity).not.toHaveBeenCalled();
|
|
1271
|
+
expect(before).not.toHaveBeenCalled();
|
|
1272
|
+
expect(onError).not.toHaveBeenCalled();
|
|
1273
|
+
expect(streamText).not.toHaveBeenCalled();
|
|
1274
|
+
});
|
|
1275
|
+
|
|
1276
|
+
it("rejects a stale tool continuation after a newer persisted user message", async () => {
|
|
1277
|
+
const before = vi.fn();
|
|
1278
|
+
const app = backend({
|
|
1279
|
+
hooks: { onBeforeChat: before },
|
|
1280
|
+
tools: { inspect: {} as never },
|
|
1281
|
+
});
|
|
1282
|
+
const conversation = await seedConversation(app);
|
|
1283
|
+
await seedMessage(app, conversation.id, "user", [
|
|
1284
|
+
{ type: "text", text: "First" },
|
|
1285
|
+
]);
|
|
1286
|
+
await seedMessage(app, conversation.id, "assistant", [
|
|
1287
|
+
{ type: "text", text: "First answer" },
|
|
1288
|
+
]);
|
|
1289
|
+
await seedMessage(app, conversation.id, "user", [
|
|
1290
|
+
{ type: "text", text: "Newer" },
|
|
1291
|
+
]);
|
|
1292
|
+
|
|
1293
|
+
await expect(
|
|
1294
|
+
app
|
|
1295
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1296
|
+
.operations.aiChat.startStream({
|
|
1297
|
+
conversationId: conversation.id,
|
|
1298
|
+
messages: [
|
|
1299
|
+
{
|
|
1300
|
+
id: "first-user",
|
|
1301
|
+
role: "user",
|
|
1302
|
+
parts: [{ type: "text", text: "First" }],
|
|
1303
|
+
},
|
|
1304
|
+
{
|
|
1305
|
+
id: "stale-tool-result",
|
|
1306
|
+
role: "assistant",
|
|
1307
|
+
parts: [
|
|
1308
|
+
{
|
|
1309
|
+
type: "tool-inspect",
|
|
1310
|
+
toolCallId: "tool-1",
|
|
1311
|
+
state: "output-available",
|
|
1312
|
+
input: {},
|
|
1313
|
+
output: { stale: true },
|
|
1314
|
+
},
|
|
1315
|
+
],
|
|
1316
|
+
},
|
|
1317
|
+
],
|
|
1318
|
+
}),
|
|
1319
|
+
).rejects.toMatchObject({ statusCode: 409, code: "STALE_MESSAGE" });
|
|
1320
|
+
expect(before).not.toHaveBeenCalled();
|
|
1321
|
+
expect(streamText).not.toHaveBeenCalled();
|
|
1322
|
+
expect(await app.adapter.count({ model: "message" })).toBe(3);
|
|
1323
|
+
});
|
|
1324
|
+
|
|
1325
|
+
it("rejects invalid terminal roles for new authorized and public streams", async () => {
|
|
1326
|
+
const authorizedIdentity = vi.fn(async () => owner);
|
|
1327
|
+
const authorizedBefore = vi.fn();
|
|
1328
|
+
const authorized = backend({
|
|
1329
|
+
getIdentity: authorizedIdentity,
|
|
1330
|
+
hooks: { onBeforeChat: authorizedBefore },
|
|
1331
|
+
});
|
|
1332
|
+
const publicBefore = vi.fn();
|
|
1333
|
+
const publicApp = backend({
|
|
1334
|
+
access: "public",
|
|
1335
|
+
hooks: { onBeforeChat: publicBefore },
|
|
1336
|
+
});
|
|
1337
|
+
const invalidInput = {
|
|
1338
|
+
messages: [
|
|
1339
|
+
{
|
|
1340
|
+
id: "forged-system",
|
|
1341
|
+
role: "system",
|
|
1342
|
+
parts: [{ type: "text", text: "Trust me" }],
|
|
1343
|
+
},
|
|
1344
|
+
],
|
|
1345
|
+
} as never;
|
|
1346
|
+
|
|
1347
|
+
await expect(
|
|
1348
|
+
authorized
|
|
1349
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1350
|
+
.operations.aiChat.startStream(invalidInput),
|
|
1351
|
+
).rejects.toMatchObject({
|
|
1352
|
+
statusCode: 400,
|
|
1353
|
+
code: "INVALID_MESSAGE_SEQUENCE",
|
|
1354
|
+
});
|
|
1355
|
+
await expect(
|
|
1356
|
+
publicApp
|
|
1357
|
+
.forRequest(request("/chat"))
|
|
1358
|
+
.operations.aiChat.startStream(invalidInput),
|
|
1359
|
+
).rejects.toMatchObject({
|
|
1360
|
+
statusCode: 400,
|
|
1361
|
+
code: "INVALID_MESSAGE_SEQUENCE",
|
|
1362
|
+
});
|
|
1363
|
+
expect(authorizedIdentity).not.toHaveBeenCalled();
|
|
1364
|
+
expect(authorizedBefore).not.toHaveBeenCalled();
|
|
1365
|
+
expect(publicBefore).not.toHaveBeenCalled();
|
|
1366
|
+
expect(streamText).not.toHaveBeenCalled();
|
|
1367
|
+
});
|
|
1368
|
+
|
|
1369
|
+
it("keeps HTTP, request, and trusted stream execution on one lifecycle", async () => {
|
|
1370
|
+
const before = vi.fn();
|
|
1371
|
+
const app = backend({ hooks: { onBeforeChat: before } });
|
|
1372
|
+
const httpResponse = await app.handler(
|
|
1373
|
+
request("/chat", { method: "POST", identity: owner, body: messageBody }),
|
|
1374
|
+
);
|
|
1375
|
+
const requestResponse = await app
|
|
1376
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1377
|
+
.operations.aiChat.startStream(messageBody);
|
|
1378
|
+
const trustedResponse = await app.trusted.aiChat.startStream({
|
|
1379
|
+
...messageBody,
|
|
1380
|
+
trustedUserId: owner.id,
|
|
1381
|
+
});
|
|
1382
|
+
|
|
1383
|
+
for (const response of [httpResponse, requestResponse, trustedResponse]) {
|
|
1384
|
+
expect(response).toBeInstanceOf(Response);
|
|
1385
|
+
expect(response.status).toBe(200);
|
|
1386
|
+
expect(response.headers.get("x-conversation-id")).toBeTruthy();
|
|
1387
|
+
}
|
|
1388
|
+
expect(before).toHaveBeenCalledTimes(3);
|
|
1389
|
+
expect(streamText).toHaveBeenCalledTimes(3);
|
|
1390
|
+
expect(await app.adapter.count({ model: "conversation" })).toBe(3);
|
|
1391
|
+
expect(await app.adapter.count({ model: "message" })).toBe(3);
|
|
1392
|
+
});
|
|
1393
|
+
|
|
1394
|
+
it("normalizes plain before-hook denials across every stream transport", async () => {
|
|
1395
|
+
const before = vi.fn(() => {
|
|
1396
|
+
throw new Error("Rate limit exceeded");
|
|
1397
|
+
});
|
|
1398
|
+
const app = backend({
|
|
1399
|
+
access: "public",
|
|
1400
|
+
hooks: { onBeforeChat: before },
|
|
1401
|
+
});
|
|
1402
|
+
|
|
1403
|
+
const httpResponse = await app.handler(
|
|
1404
|
+
request("/chat", { method: "POST", body: messageBody }),
|
|
1405
|
+
);
|
|
1406
|
+
expect(httpResponse.status).toBe(403);
|
|
1407
|
+
expect(await httpResponse.json()).toMatchObject({
|
|
1408
|
+
message: "Rate limit exceeded",
|
|
1409
|
+
code: "HOOK_DENIED",
|
|
1410
|
+
});
|
|
1411
|
+
await expect(
|
|
1412
|
+
app
|
|
1413
|
+
.forRequest(request("/chat"))
|
|
1414
|
+
.operations.aiChat.startStream(messageBody),
|
|
1415
|
+
).rejects.toMatchObject({
|
|
1416
|
+
statusCode: 403,
|
|
1417
|
+
message: "Rate limit exceeded",
|
|
1418
|
+
code: "HOOK_DENIED",
|
|
1419
|
+
});
|
|
1420
|
+
await expect(
|
|
1421
|
+
app.trusted.aiChat.startStream(messageBody),
|
|
1422
|
+
).rejects.toMatchObject({
|
|
1423
|
+
statusCode: 403,
|
|
1424
|
+
message: "Rate limit exceeded",
|
|
1425
|
+
code: "HOOK_DENIED",
|
|
1426
|
+
});
|
|
1427
|
+
|
|
1428
|
+
expect(before).toHaveBeenCalledTimes(3);
|
|
1429
|
+
expect(streamText).not.toHaveBeenCalled();
|
|
1430
|
+
expect(await app.adapter.count({ model: "conversation" })).toBe(0);
|
|
1431
|
+
expect(await app.adapter.count({ model: "message" })).toBe(0);
|
|
1432
|
+
});
|
|
1433
|
+
|
|
1434
|
+
it("reports asynchronous provider failures for every stream transport", async () => {
|
|
1435
|
+
const onErrorChat = vi.fn();
|
|
1436
|
+
const app = backend({ hooks: { onErrorChat } });
|
|
1437
|
+
await app.handler(
|
|
1438
|
+
request("/chat", { method: "POST", identity: owner, body: messageBody }),
|
|
1439
|
+
);
|
|
1440
|
+
await app
|
|
1441
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1442
|
+
.operations.aiChat.startStream(messageBody);
|
|
1443
|
+
await app.trusted.aiChat.startStream({
|
|
1444
|
+
...messageBody,
|
|
1445
|
+
trustedUserId: owner.id,
|
|
1446
|
+
});
|
|
1447
|
+
|
|
1448
|
+
for (const [options] of streamText.mock.calls as unknown as Array<
|
|
1449
|
+
[{ onError: (event: { error: unknown }) => Promise<void> }]
|
|
1450
|
+
>) {
|
|
1451
|
+
await options.onError({ error: new Error("provider failed") });
|
|
1452
|
+
}
|
|
1453
|
+
expect(onErrorChat).toHaveBeenCalledTimes(3);
|
|
1454
|
+
for (const [error] of onErrorChat.mock.calls) {
|
|
1455
|
+
expect(error).toMatchObject({ message: "provider failed" });
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
|
|
1459
|
+
it("rechecks authoritative stream state before hooks, persistence, and provider work", async () => {
|
|
1460
|
+
let app: ReturnType<typeof backend>;
|
|
1461
|
+
let conversation: Conversation | undefined;
|
|
1462
|
+
const before = vi.fn();
|
|
1463
|
+
const onError = vi.fn();
|
|
1464
|
+
app = backend({
|
|
1465
|
+
hooks: { onBeforeChat: before, onErrorChat: onError },
|
|
1466
|
+
getIdentity: async () => {
|
|
1467
|
+
if (conversation) {
|
|
1468
|
+
await app.adapter.update({
|
|
1469
|
+
model: "conversation",
|
|
1470
|
+
where: [{ field: "id", value: conversation.id }],
|
|
1471
|
+
update: { updatedAt: new Date() },
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
return owner;
|
|
1475
|
+
},
|
|
1476
|
+
});
|
|
1477
|
+
conversation = await seedConversation(app);
|
|
1478
|
+
|
|
1479
|
+
await expect(
|
|
1480
|
+
app
|
|
1481
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1482
|
+
.operations.aiChat.startStream({
|
|
1483
|
+
...messageBody,
|
|
1484
|
+
conversationId: conversation.id,
|
|
1485
|
+
}),
|
|
1486
|
+
).rejects.toMatchObject({ statusCode: 409, code: "STALE_CONVERSATION" });
|
|
1487
|
+
expect(before).not.toHaveBeenCalled();
|
|
1488
|
+
expect(streamText).not.toHaveBeenCalled();
|
|
1489
|
+
expect(await app.adapter.count({ model: "message" })).toBe(0);
|
|
1490
|
+
expect(onError).toHaveBeenCalledOnce();
|
|
1491
|
+
});
|
|
1492
|
+
|
|
1493
|
+
it("rechecks a missing requested conversation before entering hooks", async () => {
|
|
1494
|
+
let app: ReturnType<typeof backend>;
|
|
1495
|
+
let inserted = false;
|
|
1496
|
+
const before = vi.fn();
|
|
1497
|
+
app = backend({
|
|
1498
|
+
hooks: { onBeforeChat: before },
|
|
1499
|
+
getIdentity: async () => {
|
|
1500
|
+
if (!inserted) {
|
|
1501
|
+
inserted = true;
|
|
1502
|
+
const now = new Date();
|
|
1503
|
+
await app.adapter.create<Conversation>({
|
|
1504
|
+
model: "conversation",
|
|
1505
|
+
forceAllowId: true,
|
|
1506
|
+
data: {
|
|
1507
|
+
id: "claimed-conversation",
|
|
1508
|
+
userId: viewer.id,
|
|
1509
|
+
title: "Claimed concurrently",
|
|
1510
|
+
createdAt: now,
|
|
1511
|
+
updatedAt: now,
|
|
1512
|
+
} as Conversation,
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
return owner;
|
|
1516
|
+
},
|
|
1517
|
+
});
|
|
1518
|
+
|
|
1519
|
+
await expect(
|
|
1520
|
+
app
|
|
1521
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1522
|
+
.operations.aiChat.startStream({
|
|
1523
|
+
...messageBody,
|
|
1524
|
+
conversationId: "claimed-conversation",
|
|
1525
|
+
}),
|
|
1526
|
+
).rejects.toMatchObject({ statusCode: 409, code: "STALE_CONVERSATION" });
|
|
1527
|
+
expect(before).not.toHaveBeenCalled();
|
|
1528
|
+
expect(streamText).not.toHaveBeenCalled();
|
|
1529
|
+
expect(await app.adapter.count({ model: "message" })).toBe(0);
|
|
1530
|
+
});
|
|
1531
|
+
|
|
1532
|
+
it("atomically claims a caller-selected missing conversation before hooks", async () => {
|
|
1533
|
+
let arrivals = 0;
|
|
1534
|
+
let releaseIdentities: (() => void) | undefined;
|
|
1535
|
+
const identityBarrier = new Promise<void>((resolve) => {
|
|
1536
|
+
releaseIdentities = resolve;
|
|
1537
|
+
});
|
|
1538
|
+
const before = vi.fn();
|
|
1539
|
+
const app = backend({
|
|
1540
|
+
hooks: { onBeforeChat: before },
|
|
1541
|
+
getIdentity: async () => {
|
|
1542
|
+
arrivals += 1;
|
|
1543
|
+
if (arrivals === 2) releaseIdentities?.();
|
|
1544
|
+
await identityBarrier;
|
|
1545
|
+
return owner;
|
|
1546
|
+
},
|
|
1547
|
+
});
|
|
1548
|
+
const input = {
|
|
1549
|
+
...messageBody,
|
|
1550
|
+
conversationId: "caller-selected-conversation",
|
|
1551
|
+
};
|
|
1552
|
+
|
|
1553
|
+
const results = await Promise.allSettled([
|
|
1554
|
+
app
|
|
1555
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1556
|
+
.operations.aiChat.startStream(input),
|
|
1557
|
+
app
|
|
1558
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1559
|
+
.operations.aiChat.startStream(input),
|
|
1560
|
+
]);
|
|
1561
|
+
|
|
1562
|
+
expect(
|
|
1563
|
+
results.filter((result) => result.status === "fulfilled"),
|
|
1564
|
+
).toHaveLength(1);
|
|
1565
|
+
expect(
|
|
1566
|
+
results.filter((result) => result.status === "rejected"),
|
|
1567
|
+
).toHaveLength(1);
|
|
1568
|
+
expect(before).toHaveBeenCalledOnce();
|
|
1569
|
+
expect(streamText).toHaveBeenCalledOnce();
|
|
1570
|
+
expect(
|
|
1571
|
+
await app.adapter.count({
|
|
1572
|
+
model: "conversation",
|
|
1573
|
+
where: [
|
|
1574
|
+
{
|
|
1575
|
+
field: "id",
|
|
1576
|
+
value: input.conversationId,
|
|
1577
|
+
operator: "eq",
|
|
1578
|
+
},
|
|
1579
|
+
],
|
|
1580
|
+
}),
|
|
1581
|
+
).toBe(1);
|
|
1582
|
+
expect(await app.adapter.count({ model: "message" })).toBe(1);
|
|
1583
|
+
});
|
|
1584
|
+
|
|
1585
|
+
it("atomically claims one authoritative snapshot for concurrent streams", async () => {
|
|
1586
|
+
let arrivals = 0;
|
|
1587
|
+
let releaseIdentities: (() => void) | undefined;
|
|
1588
|
+
const identityBarrier = new Promise<void>((resolve) => {
|
|
1589
|
+
releaseIdentities = resolve;
|
|
1590
|
+
});
|
|
1591
|
+
const before = vi.fn();
|
|
1592
|
+
const app = backend({
|
|
1593
|
+
hooks: { onBeforeChat: before },
|
|
1594
|
+
getIdentity: async () => {
|
|
1595
|
+
arrivals += 1;
|
|
1596
|
+
if (arrivals === 2) releaseIdentities?.();
|
|
1597
|
+
await identityBarrier;
|
|
1598
|
+
return owner;
|
|
1599
|
+
},
|
|
1600
|
+
});
|
|
1601
|
+
const conversation = await seedConversation(app);
|
|
1602
|
+
const input = { ...messageBody, conversationId: conversation.id };
|
|
1603
|
+
|
|
1604
|
+
const results = await Promise.allSettled([
|
|
1605
|
+
app
|
|
1606
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1607
|
+
.operations.aiChat.startStream(input),
|
|
1608
|
+
app
|
|
1609
|
+
.forRequest(request("/chat", { identity: owner }))
|
|
1610
|
+
.operations.aiChat.startStream(input),
|
|
1611
|
+
]);
|
|
1612
|
+
|
|
1613
|
+
expect(
|
|
1614
|
+
results.filter((result) => result.status === "fulfilled"),
|
|
1615
|
+
).toHaveLength(1);
|
|
1616
|
+
const rejected = results.find((result) => result.status === "rejected");
|
|
1617
|
+
expect(rejected).toMatchObject({
|
|
1618
|
+
status: "rejected",
|
|
1619
|
+
reason: expect.objectContaining({
|
|
1620
|
+
statusCode: 409,
|
|
1621
|
+
code: "STALE_CONVERSATION",
|
|
1622
|
+
}),
|
|
1623
|
+
});
|
|
1624
|
+
expect(before).toHaveBeenCalledOnce();
|
|
1625
|
+
expect(streamText).toHaveBeenCalledOnce();
|
|
1626
|
+
expect(await app.adapter.count({ model: "message" })).toBe(1);
|
|
1627
|
+
});
|
|
1628
|
+
|
|
1629
|
+
it("queues a same-conversation stream until raw-memory rollback finishes", async () => {
|
|
1630
|
+
let enteredHook: (() => void) | undefined;
|
|
1631
|
+
const hookEntered = new Promise<void>((resolve) => {
|
|
1632
|
+
enteredHook = resolve;
|
|
1633
|
+
});
|
|
1634
|
+
let releaseHook: (() => void) | undefined;
|
|
1635
|
+
const hookBarrier = new Promise<void>((resolve) => {
|
|
1636
|
+
releaseHook = resolve;
|
|
1637
|
+
});
|
|
1638
|
+
let hookCalls = 0;
|
|
1639
|
+
const before = vi.fn(async () => {
|
|
1640
|
+
hookCalls += 1;
|
|
1641
|
+
if (hookCalls !== 1) return;
|
|
1642
|
+
enteredHook?.();
|
|
1643
|
+
await hookBarrier;
|
|
1644
|
+
throw new Error("reject first stream");
|
|
1645
|
+
});
|
|
1646
|
+
const app = backend({ hooks: { onBeforeChat: before } });
|
|
1647
|
+
const conversation = await seedConversation(app);
|
|
1648
|
+
const input = { ...messageBody, conversationId: conversation.id };
|
|
1649
|
+
|
|
1650
|
+
const rejectedStream = app
|
|
1651
|
+
.forRequest(request("/first", { identity: owner }))
|
|
1652
|
+
.operations.aiChat.startStream(input);
|
|
1653
|
+
await hookEntered;
|
|
1654
|
+
let overlapSettled = false;
|
|
1655
|
+
const overlappingStream = app
|
|
1656
|
+
.forRequest(request("/overlap", { identity: owner }))
|
|
1657
|
+
.operations.aiChat.startStream(input)
|
|
1658
|
+
.then((response) => {
|
|
1659
|
+
overlapSettled = true;
|
|
1660
|
+
return response;
|
|
1661
|
+
});
|
|
1662
|
+
await Promise.resolve();
|
|
1663
|
+
await Promise.resolve();
|
|
1664
|
+
expect(before).toHaveBeenCalledOnce();
|
|
1665
|
+
expect(overlapSettled).toBe(false);
|
|
1666
|
+
|
|
1667
|
+
releaseHook?.();
|
|
1668
|
+
await expect(rejectedStream).rejects.toMatchObject({
|
|
1669
|
+
statusCode: 403,
|
|
1670
|
+
code: "HOOK_DENIED",
|
|
1671
|
+
});
|
|
1672
|
+
await expect(overlappingStream).resolves.toBeInstanceOf(Response);
|
|
1673
|
+
expect(before).toHaveBeenCalledTimes(2);
|
|
1674
|
+
expect(await app.adapter.count({ model: "message" })).toBe(1);
|
|
1675
|
+
});
|
|
1676
|
+
|
|
1677
|
+
it("serializes raw-memory rollbacks across all history writes", async () => {
|
|
1678
|
+
let enteredFirstHook: (() => void) | undefined;
|
|
1679
|
+
const firstHookEntered = new Promise<void>((resolve) => {
|
|
1680
|
+
enteredFirstHook = resolve;
|
|
1681
|
+
});
|
|
1682
|
+
let releaseFirstHook: (() => void) | undefined;
|
|
1683
|
+
const firstHookBarrier = new Promise<void>((resolve) => {
|
|
1684
|
+
releaseFirstHook = resolve;
|
|
1685
|
+
});
|
|
1686
|
+
let hookCalls = 0;
|
|
1687
|
+
const before = vi.fn(async () => {
|
|
1688
|
+
hookCalls += 1;
|
|
1689
|
+
if (hookCalls !== 1) return;
|
|
1690
|
+
enteredFirstHook?.();
|
|
1691
|
+
await firstHookBarrier;
|
|
1692
|
+
throw new Error("roll back first conversation");
|
|
1693
|
+
});
|
|
1694
|
+
const app = backend({ hooks: { onBeforeChat: before } });
|
|
1695
|
+
const firstConversation = await seedConversation(app, owner.id, "First");
|
|
1696
|
+
const secondConversation = await seedConversation(app, owner.id, "Second");
|
|
1697
|
+
|
|
1698
|
+
const rejectedStream = app
|
|
1699
|
+
.forRequest(request("/first", { identity: owner }))
|
|
1700
|
+
.operations.aiChat.startStream({
|
|
1701
|
+
...messageBody,
|
|
1702
|
+
conversationId: firstConversation.id,
|
|
1703
|
+
});
|
|
1704
|
+
await firstHookEntered;
|
|
1705
|
+
const successfulStream = app
|
|
1706
|
+
.forRequest(request("/second", { identity: owner }))
|
|
1707
|
+
.operations.aiChat.startStream({
|
|
1708
|
+
...messageBody,
|
|
1709
|
+
conversationId: secondConversation.id,
|
|
1710
|
+
});
|
|
1711
|
+
let createSettled = false;
|
|
1712
|
+
const createdConversation = app
|
|
1713
|
+
.forRequest(request("/create", { identity: owner }))
|
|
1714
|
+
.operations.aiChat.createConversation({
|
|
1715
|
+
title: "Created during rollback",
|
|
1716
|
+
})
|
|
1717
|
+
.then((conversation) => {
|
|
1718
|
+
createSettled = true;
|
|
1719
|
+
return conversation;
|
|
1720
|
+
});
|
|
1721
|
+
let rawWriteSettled = false;
|
|
1722
|
+
const rawNow = new Date();
|
|
1723
|
+
const rawConversation = app.adapter
|
|
1724
|
+
.create<Conversation>({
|
|
1725
|
+
model: "conversation",
|
|
1726
|
+
data: {
|
|
1727
|
+
userId: owner.id,
|
|
1728
|
+
title: "Raw write during rollback",
|
|
1729
|
+
createdAt: rawNow,
|
|
1730
|
+
updatedAt: rawNow,
|
|
1731
|
+
},
|
|
1732
|
+
})
|
|
1733
|
+
.then((conversation) => {
|
|
1734
|
+
rawWriteSettled = true;
|
|
1735
|
+
return conversation;
|
|
1736
|
+
});
|
|
1737
|
+
await Promise.resolve();
|
|
1738
|
+
await Promise.resolve();
|
|
1739
|
+
expect(before).toHaveBeenCalledOnce();
|
|
1740
|
+
expect(createSettled).toBe(false);
|
|
1741
|
+
expect(rawWriteSettled).toBe(false);
|
|
1742
|
+
|
|
1743
|
+
releaseFirstHook?.();
|
|
1744
|
+
await expect(rejectedStream).rejects.toMatchObject({
|
|
1745
|
+
statusCode: 403,
|
|
1746
|
+
code: "HOOK_DENIED",
|
|
1747
|
+
});
|
|
1748
|
+
await expect(successfulStream).resolves.toBeInstanceOf(Response);
|
|
1749
|
+
await expect(createdConversation).resolves.toMatchObject({
|
|
1750
|
+
title: "Created during rollback",
|
|
1751
|
+
});
|
|
1752
|
+
await expect(rawConversation).resolves.toMatchObject({
|
|
1753
|
+
title: "Raw write during rollback",
|
|
1754
|
+
});
|
|
1755
|
+
expect(before).toHaveBeenCalledTimes(2);
|
|
1756
|
+
expect(
|
|
1757
|
+
await app.adapter.count({
|
|
1758
|
+
model: "message",
|
|
1759
|
+
where: [
|
|
1760
|
+
{
|
|
1761
|
+
field: "conversationId",
|
|
1762
|
+
value: firstConversation.id,
|
|
1763
|
+
operator: "eq",
|
|
1764
|
+
},
|
|
1765
|
+
],
|
|
1766
|
+
}),
|
|
1767
|
+
).toBe(0);
|
|
1768
|
+
expect(
|
|
1769
|
+
await app.adapter.count({
|
|
1770
|
+
model: "message",
|
|
1771
|
+
where: [
|
|
1772
|
+
{
|
|
1773
|
+
field: "conversationId",
|
|
1774
|
+
value: secondConversation.id,
|
|
1775
|
+
operator: "eq",
|
|
1776
|
+
},
|
|
1777
|
+
],
|
|
1778
|
+
}),
|
|
1779
|
+
).toBe(1);
|
|
1780
|
+
});
|
|
1781
|
+
|
|
1782
|
+
it("allows AI Chat history operations to re-enter raw-memory hooks", async () => {
|
|
1783
|
+
let app: ReturnType<typeof backend>;
|
|
1784
|
+
const before = vi.fn(async () => {
|
|
1785
|
+
await app.trusted.aiChat.createConversation({
|
|
1786
|
+
title: "Created from stream hook",
|
|
1787
|
+
});
|
|
1788
|
+
});
|
|
1789
|
+
app = backend({ hooks: { onBeforeChat: before } });
|
|
1790
|
+
const conversation = await seedConversation(app);
|
|
1791
|
+
let settled = false;
|
|
1792
|
+
const stream = app.trusted.aiChat
|
|
1793
|
+
.startStream({
|
|
1794
|
+
...messageBody,
|
|
1795
|
+
conversationId: conversation.id,
|
|
1796
|
+
trustedUserId: owner.id,
|
|
1797
|
+
})
|
|
1798
|
+
.then((response) => {
|
|
1799
|
+
settled = true;
|
|
1800
|
+
return response;
|
|
1801
|
+
});
|
|
1802
|
+
await vi.waitFor(() => expect(settled).toBe(true), { timeout: 1_000 });
|
|
1803
|
+
await expect(stream).resolves.toBeInstanceOf(Response);
|
|
1804
|
+
expect(before).toHaveBeenCalledOnce();
|
|
1805
|
+
expect(
|
|
1806
|
+
await app.adapter.count({
|
|
1807
|
+
model: "conversation",
|
|
1808
|
+
where: [
|
|
1809
|
+
{
|
|
1810
|
+
field: "title",
|
|
1811
|
+
value: "Created from stream hook",
|
|
1812
|
+
operator: "eq",
|
|
1813
|
+
},
|
|
1814
|
+
],
|
|
1815
|
+
}),
|
|
1816
|
+
).toBe(1);
|
|
1817
|
+
});
|
|
1818
|
+
|
|
1819
|
+
it("rolls back a caught nested history after-hook failure", async () => {
|
|
1820
|
+
let app: ReturnType<typeof backend>;
|
|
1821
|
+
const afterCreate = vi.fn(() => {
|
|
1822
|
+
throw new Error("reject nested after hook");
|
|
1823
|
+
});
|
|
1824
|
+
const before = vi.fn(async () => {
|
|
1825
|
+
try {
|
|
1826
|
+
await app.trusted.aiChat.createConversation({
|
|
1827
|
+
title: "Nested failed conversation",
|
|
1828
|
+
});
|
|
1829
|
+
} catch {
|
|
1830
|
+
// The outer hook intentionally handles the nested operation error.
|
|
1831
|
+
}
|
|
1832
|
+
});
|
|
1833
|
+
app = backend({
|
|
1834
|
+
hooks: {
|
|
1835
|
+
onBeforeChat: before,
|
|
1836
|
+
onAfterCreateConversation: afterCreate,
|
|
1837
|
+
},
|
|
1838
|
+
});
|
|
1839
|
+
const conversation = await seedConversation(app);
|
|
1840
|
+
|
|
1841
|
+
await expect(
|
|
1842
|
+
app.trusted.aiChat.startStream({
|
|
1843
|
+
...messageBody,
|
|
1844
|
+
conversationId: conversation.id,
|
|
1845
|
+
trustedUserId: owner.id,
|
|
1846
|
+
}),
|
|
1847
|
+
).rejects.toMatchObject({ message: "reject nested after hook" });
|
|
1848
|
+
expect(before).toHaveBeenCalledOnce();
|
|
1849
|
+
expect(afterCreate).toHaveBeenCalledOnce();
|
|
1850
|
+
expect(await app.adapter.count({ model: "message" })).toBe(0);
|
|
1851
|
+
expect(
|
|
1852
|
+
await app.adapter.count({
|
|
1853
|
+
model: "conversation",
|
|
1854
|
+
where: [
|
|
1855
|
+
{
|
|
1856
|
+
field: "title",
|
|
1857
|
+
value: "Nested failed conversation",
|
|
1858
|
+
operator: "eq",
|
|
1859
|
+
},
|
|
1860
|
+
],
|
|
1861
|
+
}),
|
|
1862
|
+
).toBe(0);
|
|
1863
|
+
});
|
|
1864
|
+
|
|
1865
|
+
it("serializes concurrent raw-memory rename and delete lifecycle hooks", async () => {
|
|
1866
|
+
let enterUpdate: (() => void) | undefined;
|
|
1867
|
+
const updateEntered = new Promise<void>((resolve) => {
|
|
1868
|
+
enterUpdate = resolve;
|
|
1869
|
+
});
|
|
1870
|
+
let releaseUpdate: (() => void) | undefined;
|
|
1871
|
+
const updateBarrier = new Promise<void>((resolve) => {
|
|
1872
|
+
releaseUpdate = resolve;
|
|
1873
|
+
});
|
|
1874
|
+
let enterDelete: (() => void) | undefined;
|
|
1875
|
+
const deleteEntered = new Promise<void>((resolve) => {
|
|
1876
|
+
enterDelete = resolve;
|
|
1877
|
+
});
|
|
1878
|
+
let releaseDelete: (() => void) | undefined;
|
|
1879
|
+
const deleteBarrier = new Promise<void>((resolve) => {
|
|
1880
|
+
releaseDelete = resolve;
|
|
1881
|
+
});
|
|
1882
|
+
const beforeUpdate = vi.fn(async () => {
|
|
1883
|
+
enterUpdate?.();
|
|
1884
|
+
await updateBarrier;
|
|
1885
|
+
});
|
|
1886
|
+
const beforeDelete = vi.fn(async () => {
|
|
1887
|
+
enterDelete?.();
|
|
1888
|
+
await deleteBarrier;
|
|
1889
|
+
});
|
|
1890
|
+
const app = backend({
|
|
1891
|
+
hooks: {
|
|
1892
|
+
onBeforeUpdateConversation: beforeUpdate,
|
|
1893
|
+
onBeforeDeleteConversation: beforeDelete,
|
|
1894
|
+
},
|
|
1895
|
+
});
|
|
1896
|
+
const updateTarget = await seedConversation(app, owner.id, "Update target");
|
|
1897
|
+
const deleteTarget = await seedConversation(app, owner.id, "Delete target");
|
|
1898
|
+
|
|
1899
|
+
const firstUpdate = app
|
|
1900
|
+
.forRequest(request("/update-1", { identity: owner }))
|
|
1901
|
+
.operations.aiChat.updateConversation({
|
|
1902
|
+
id: updateTarget.id,
|
|
1903
|
+
data: { title: "First update" },
|
|
1904
|
+
});
|
|
1905
|
+
await updateEntered;
|
|
1906
|
+
let secondUpdateSettled = false;
|
|
1907
|
+
const secondUpdate = app
|
|
1908
|
+
.forRequest(request("/update-2", { identity: owner }))
|
|
1909
|
+
.operations.aiChat.updateConversation({
|
|
1910
|
+
id: updateTarget.id,
|
|
1911
|
+
data: { title: "Second update" },
|
|
1912
|
+
})
|
|
1913
|
+
.then((conversation) => {
|
|
1914
|
+
secondUpdateSettled = true;
|
|
1915
|
+
return conversation;
|
|
1916
|
+
});
|
|
1917
|
+
await Promise.resolve();
|
|
1918
|
+
await Promise.resolve();
|
|
1919
|
+
expect(beforeUpdate).toHaveBeenCalledOnce();
|
|
1920
|
+
expect(secondUpdateSettled).toBe(false);
|
|
1921
|
+
releaseUpdate?.();
|
|
1922
|
+
await expect(firstUpdate).resolves.toMatchObject({ title: "First update" });
|
|
1923
|
+
await expect(secondUpdate).resolves.toMatchObject({
|
|
1924
|
+
title: "Second update",
|
|
1925
|
+
});
|
|
1926
|
+
expect(beforeUpdate).toHaveBeenCalledTimes(2);
|
|
1927
|
+
|
|
1928
|
+
const firstDelete = app
|
|
1929
|
+
.forRequest(request("/delete-1", { identity: owner }))
|
|
1930
|
+
.operations.aiChat.deleteConversation({ id: deleteTarget.id });
|
|
1931
|
+
await deleteEntered;
|
|
1932
|
+
let secondDeleteSettled = false;
|
|
1933
|
+
const secondDelete = app
|
|
1934
|
+
.forRequest(request("/delete-2", { identity: owner }))
|
|
1935
|
+
.operations.aiChat.deleteConversation({ id: deleteTarget.id })
|
|
1936
|
+
.finally(() => {
|
|
1937
|
+
secondDeleteSettled = true;
|
|
1938
|
+
});
|
|
1939
|
+
await Promise.resolve();
|
|
1940
|
+
await Promise.resolve();
|
|
1941
|
+
expect(beforeDelete).toHaveBeenCalledOnce();
|
|
1942
|
+
expect(secondDeleteSettled).toBe(false);
|
|
1943
|
+
releaseDelete?.();
|
|
1944
|
+
await expect(firstDelete).resolves.toEqual({ success: true });
|
|
1945
|
+
await expect(secondDelete).rejects.toMatchObject({
|
|
1946
|
+
statusCode: 403,
|
|
1947
|
+
code: "FORBIDDEN",
|
|
1948
|
+
});
|
|
1949
|
+
expect(beforeDelete).toHaveBeenCalledOnce();
|
|
1950
|
+
});
|
|
1951
|
+
|
|
1952
|
+
it("does not persist a stale completion after a newer stream claim", async () => {
|
|
1953
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
1954
|
+
const onErrorChat = vi.fn();
|
|
1955
|
+
const app = backend({ hooks: { onErrorChat } });
|
|
1956
|
+
const conversation = await seedConversation(app);
|
|
1957
|
+
const input = { ...messageBody, conversationId: conversation.id };
|
|
1958
|
+
|
|
1959
|
+
await app
|
|
1960
|
+
.forRequest(request("/first", { identity: owner }))
|
|
1961
|
+
.operations.aiChat.startStream(input);
|
|
1962
|
+
const streamCalls = streamText.mock.calls as unknown as Array<
|
|
1963
|
+
[
|
|
1964
|
+
{
|
|
1965
|
+
onFinish: (completion: { text: string }) => Promise<void>;
|
|
1966
|
+
},
|
|
1967
|
+
]
|
|
1968
|
+
>;
|
|
1969
|
+
const firstFinish = streamCalls[0]?.[0].onFinish;
|
|
1970
|
+
await app
|
|
1971
|
+
.forRequest(request("/second", { identity: owner }))
|
|
1972
|
+
.operations.aiChat.startStream(input);
|
|
1973
|
+
const secondFinish = streamCalls[1]?.[0].onFinish;
|
|
1974
|
+
|
|
1975
|
+
await firstFinish?.({ text: "stale answer" });
|
|
1976
|
+
expect(
|
|
1977
|
+
await app.adapter.count({
|
|
1978
|
+
model: "message",
|
|
1979
|
+
where: [{ field: "role", value: "assistant", operator: "eq" }],
|
|
1980
|
+
}),
|
|
1981
|
+
).toBe(0);
|
|
1982
|
+
expect(onErrorChat).toHaveBeenCalledOnce();
|
|
1983
|
+
|
|
1984
|
+
await secondFinish?.({ text: "current answer" });
|
|
1985
|
+
const assistants = await app.adapter.findMany<Message>({
|
|
1986
|
+
model: "message",
|
|
1987
|
+
where: [{ field: "role", value: "assistant", operator: "eq" }],
|
|
1988
|
+
});
|
|
1989
|
+
expect(assistants).toHaveLength(1);
|
|
1990
|
+
expect(assistants[0]?.content).toContain("current answer");
|
|
1991
|
+
expect(assistants[0]?.content).not.toContain("stale answer");
|
|
1992
|
+
});
|
|
1993
|
+
|
|
1994
|
+
it("denies missing rules and propagates identity resolver failures", async () => {
|
|
1995
|
+
const missing = defineAuthorization({
|
|
1996
|
+
identity: z.object({ id: z.string(), role: z.enum(["user", "admin"]) }),
|
|
1997
|
+
permissions: [aiChatPermissions] as const,
|
|
1998
|
+
rules: () => [],
|
|
1999
|
+
});
|
|
2000
|
+
const before = vi.fn();
|
|
2001
|
+
const missingApp = backend({
|
|
2002
|
+
authorization: missing as typeof fullAuthorization,
|
|
2003
|
+
hooks: { onBeforeCreateConversation: before },
|
|
2004
|
+
});
|
|
2005
|
+
await expect(
|
|
2006
|
+
missingApp
|
|
2007
|
+
.forRequest(request("/create", { identity: owner }))
|
|
2008
|
+
.operations.aiChat.createConversation({ title: "Missing" }),
|
|
2009
|
+
).rejects.toMatchObject({ statusCode: 403 });
|
|
2010
|
+
|
|
2011
|
+
const identityApp = backend({
|
|
2012
|
+
hooks: { onBeforeCreateConversation: before },
|
|
2013
|
+
getIdentity: () => {
|
|
2014
|
+
throw new Error("identity unavailable");
|
|
2015
|
+
},
|
|
2016
|
+
});
|
|
2017
|
+
await expect(
|
|
2018
|
+
identityApp
|
|
2019
|
+
.forRequest(request("/create", { identity: owner }))
|
|
2020
|
+
.operations.aiChat.createConversation({ title: "Identity error" }),
|
|
2021
|
+
).rejects.toThrow("identity unavailable");
|
|
2022
|
+
expect(before).not.toHaveBeenCalled();
|
|
2023
|
+
});
|
|
2024
|
+
|
|
2025
|
+
it("propagates rule failures and keeps trusted calls in the lifecycle", async () => {
|
|
2026
|
+
const failing = defineAuthorization({
|
|
2027
|
+
identity: z.object({ id: z.string(), role: z.enum(["user", "admin"]) }),
|
|
2028
|
+
permissions: [aiChatPermissions] as const,
|
|
2029
|
+
rules: ({ aiChat }) => [
|
|
2030
|
+
aiChat.conversation.create.when(() => {
|
|
2031
|
+
throw new Error("policy unavailable");
|
|
2032
|
+
}),
|
|
2033
|
+
],
|
|
2034
|
+
});
|
|
2035
|
+
const before = vi.fn();
|
|
2036
|
+
const app = backend({
|
|
2037
|
+
authorization: failing as typeof fullAuthorization,
|
|
2038
|
+
hooks: { onBeforeCreateConversation: before },
|
|
2039
|
+
});
|
|
2040
|
+
await expect(
|
|
2041
|
+
app
|
|
2042
|
+
.forRequest(request("/create", { identity: owner }))
|
|
2043
|
+
.operations.aiChat.createConversation({ title: "Denied" }),
|
|
2044
|
+
).rejects.toThrow("policy unavailable");
|
|
2045
|
+
expect(before).not.toHaveBeenCalled();
|
|
2046
|
+
await expect(
|
|
2047
|
+
app.trusted.aiChat.createConversation({ title: "Trusted" }),
|
|
2048
|
+
).resolves.toMatchObject({ title: "Trusted" });
|
|
2049
|
+
expect(before).toHaveBeenCalledOnce();
|
|
2050
|
+
});
|
|
2051
|
+
});
|