@btst/stack 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -37
- package/dist/node_modules/.pnpm/{@radix-ui_react-alert-dialog@1.1.15_@types_react-dom@19.2.2_@types_react@19.2.2__@types_ec789942cd38340bd7362c09e7d34384 → @radix-ui_react-alert-dialog@1.1.15_@types_react-dom@19.2.3_@types_react@19.2.6__@types_4f58c757aa677e233cf96d60fda2f1da}/node_modules/@radix-ui/react-alert-dialog/dist/index.cjs +2 -2
- package/dist/node_modules/.pnpm/{@radix-ui_react-alert-dialog@1.1.15_@types_react-dom@19.2.2_@types_react@19.2.2__@types_ec789942cd38340bd7362c09e7d34384 → @radix-ui_react-alert-dialog@1.1.15_@types_react-dom@19.2.3_@types_react@19.2.6__@types_4f58c757aa677e233cf96d60fda2f1da}/node_modules/@radix-ui/react-alert-dialog/dist/index.mjs +2 -2
- package/dist/node_modules/.pnpm/{@radix-ui_react-arrow@1.1.7_@types_react-dom@19.2.2_@types_react@19.2.2__@types_react@1_9e04309f365863673e44407648bb0cb6 → @radix-ui_react-arrow@1.1.7_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@1_35df44f6d87656c1401686c91d770dbb}/node_modules/@radix-ui/react-arrow/dist/index.cjs +1 -1
- package/dist/node_modules/.pnpm/{@radix-ui_react-arrow@1.1.7_@types_react-dom@19.2.2_@types_react@19.2.2__@types_react@1_9e04309f365863673e44407648bb0cb6 → @radix-ui_react-arrow@1.1.7_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@1_35df44f6d87656c1401686c91d770dbb}/node_modules/@radix-ui/react-arrow/dist/index.mjs +1 -1
- package/dist/node_modules/.pnpm/{@radix-ui_react-collection@1.1.7_@types_react-dom@19.2.2_@types_react@19.2.2__@types_re_6d7c277722b3619c9ee7e64e9a822c45 → @radix-ui_react-collection@1.1.7_@types_react-dom@19.2.3_@types_react@19.2.6__@types_re_59aa5e150e70a3e7bfb1567148b021b5}/node_modules/@radix-ui/react-collection/dist/index.cjs +2 -2
- package/dist/node_modules/.pnpm/{@radix-ui_react-collection@1.1.7_@types_react-dom@19.2.2_@types_react@19.2.2__@types_re_6d7c277722b3619c9ee7e64e9a822c45 → @radix-ui_react-collection@1.1.7_@types_react-dom@19.2.3_@types_react@19.2.6__@types_re_59aa5e150e70a3e7bfb1567148b021b5}/node_modules/@radix-ui/react-collection/dist/index.mjs +2 -2
- package/dist/node_modules/.pnpm/{@radix-ui_react-dismissable-layer@1.1.11_@types_react-dom@19.2.2_@types_react@19.2.2__@_ca5522e5d45d4722cb9eb5ce53defa61 → @radix-ui_react-dismissable-layer@1.1.11_@types_react-dom@19.2.3_@types_react@19.2.6__@_9ee1db7daf927866cf505b31d40047ad}/node_modules/@radix-ui/react-dismissable-layer/dist/index.cjs +4 -4
- package/dist/node_modules/.pnpm/{@radix-ui_react-dismissable-layer@1.1.11_@types_react-dom@19.2.2_@types_react@19.2.2__@_ca5522e5d45d4722cb9eb5ce53defa61 → @radix-ui_react-dismissable-layer@1.1.11_@types_react-dom@19.2.3_@types_react@19.2.6__@_9ee1db7daf927866cf505b31d40047ad}/node_modules/@radix-ui/react-dismissable-layer/dist/index.mjs +4 -4
- package/dist/node_modules/.pnpm/@radix-ui_react-dropdown-menu@2.1.16_@types_react-dom@19.2.3_@types_react@19.2.6__@type_a50051c7210b6fbd5be09388bda08578/node_modules/@radix-ui/react-dropdown-menu/dist/index.cjs +282 -0
- package/dist/node_modules/.pnpm/@radix-ui_react-dropdown-menu@2.1.16_@types_react-dom@19.2.3_@types_react@19.2.6__@type_a50051c7210b6fbd5be09388bda08578/node_modules/@radix-ui/react-dropdown-menu/dist/index.mjs +247 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-focus-scope@1.1.7_@types_react-dom@19.2.2_@types_react@19.2.2__@types_r_93de389b3f622f9f764acc8e59ec80c0 → @radix-ui_react-focus-scope@1.1.7_@types_react-dom@19.2.3_@types_react@19.2.6__@types_r_0a31b7f987af9482d13505312e1a1be9}/node_modules/@radix-ui/react-focus-scope/dist/index.cjs +3 -3
- package/dist/node_modules/.pnpm/{@radix-ui_react-focus-scope@1.1.7_@types_react-dom@19.2.2_@types_react@19.2.2__@types_r_93de389b3f622f9f764acc8e59ec80c0 → @radix-ui_react-focus-scope@1.1.7_@types_react-dom@19.2.3_@types_react@19.2.6__@types_r_0a31b7f987af9482d13505312e1a1be9}/node_modules/@radix-ui/react-focus-scope/dist/index.mjs +3 -3
- package/dist/node_modules/.pnpm/{@radix-ui_react-id@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-id@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-id/dist/index.cjs +1 -1
- package/dist/node_modules/.pnpm/{@radix-ui_react-id@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-id@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-id/dist/index.mjs +1 -1
- package/dist/node_modules/.pnpm/@radix-ui_react-menu@2.1.16_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@1_82ed1fcd848b6984d9291a784d477cf4/node_modules/@radix-ui/react-menu/dist/index.cjs +845 -0
- package/dist/node_modules/.pnpm/@radix-ui_react-menu@2.1.16_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@1_82ed1fcd848b6984d9291a784d477cf4/node_modules/@radix-ui/react-menu/dist/index.mjs +799 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-popper@1.2.8_@types_react-dom@19.2.2_@types_react@19.2.2__@types_react@_d6285b8269ea5d6b59b300f5be279a0c → @radix-ui_react-popper@1.2.8_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@_7ac2caae1e39f9ba93d5015614525161}/node_modules/@radix-ui/react-popper/dist/index.cjs +7 -7
- package/dist/node_modules/.pnpm/{@radix-ui_react-popper@1.2.8_@types_react-dom@19.2.2_@types_react@19.2.2__@types_react@_d6285b8269ea5d6b59b300f5be279a0c → @radix-ui_react-popper@1.2.8_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@_7ac2caae1e39f9ba93d5015614525161}/node_modules/@radix-ui/react-popper/dist/index.mjs +7 -7
- package/dist/node_modules/.pnpm/{@radix-ui_react-portal@1.1.9_@types_react-dom@19.2.2_@types_react@19.2.2__@types_react@_478b3d5dd4afab1a3dcce7ed1748cb95 → @radix-ui_react-portal@1.1.9_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@_1bb4e0f97f86496802d28a2e74e2a8b9}/node_modules/@radix-ui/react-portal/dist/index.cjs +2 -2
- package/dist/node_modules/.pnpm/{@radix-ui_react-portal@1.1.9_@types_react-dom@19.2.2_@types_react@19.2.2__@types_react@_478b3d5dd4afab1a3dcce7ed1748cb95 → @radix-ui_react-portal@1.1.9_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@_1bb4e0f97f86496802d28a2e74e2a8b9}/node_modules/@radix-ui/react-portal/dist/index.mjs +2 -2
- package/dist/node_modules/.pnpm/@radix-ui_react-presence@1.1.5_@types_react-dom@19.2.3_@types_react@19.2.6__@types_reac_90f8e5c12233caef3399d5fd66452a13/node_modules/@radix-ui/react-presence/dist/index.cjs +147 -0
- package/dist/node_modules/.pnpm/@radix-ui_react-presence@1.1.5_@types_react-dom@19.2.3_@types_react@19.2.6__@types_reac_90f8e5c12233caef3399d5fd66452a13/node_modules/@radix-ui/react-presence/dist/index.mjs +131 -0
- package/dist/node_modules/.pnpm/@radix-ui_react-roving-focus@1.1.11_@types_react-dom@19.2.3_@types_react@19.2.6__@types_fe1151d1f393bbc1072b24a86dff3a23/node_modules/@radix-ui/react-roving-focus/dist/index.cjs +244 -0
- package/dist/node_modules/.pnpm/@radix-ui_react-roving-focus@1.1.11_@types_react-dom@19.2.3_@types_react@19.2.6__@types_fe1151d1f393bbc1072b24a86dff3a23/node_modules/@radix-ui/react-roving-focus/dist/index.mjs +224 -0
- package/dist/node_modules/.pnpm/@radix-ui_react-scroll-area@1.2.10_@types_react-dom@19.2.3_@types_react@19.2.6__@types__e3f7735e9b444a10b3bbfd9fe97d44d0/node_modules/@radix-ui/react-scroll-area/dist/index.cjs +742 -0
- package/dist/node_modules/.pnpm/@radix-ui_react-scroll-area@1.2.10_@types_react-dom@19.2.3_@types_react@19.2.6__@types__e3f7735e9b444a10b3bbfd9fe97d44d0/node_modules/@radix-ui/react-scroll-area/dist/index.mjs +719 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-select@2.2.6_@types_react-dom@19.2.2_@types_react@19.2.2__@types_react@_802c3d414c85063bee785fcc98a39c07 → @radix-ui_react-select@2.2.6_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@_38dc681bb1f2bcfeb5249d8ca2bc01f5}/node_modules/@radix-ui/react-select/dist/index.cjs +17 -17
- package/dist/node_modules/.pnpm/{@radix-ui_react-select@2.2.6_@types_react-dom@19.2.2_@types_react@19.2.2__@types_react@_802c3d414c85063bee785fcc98a39c07 → @radix-ui_react-select@2.2.6_@types_react-dom@19.2.3_@types_react@19.2.6__@types_react@_38dc681bb1f2bcfeb5249d8ca2bc01f5}/node_modules/@radix-ui/react-select/dist/index.mjs +17 -17
- package/dist/node_modules/.pnpm/{@radix-ui_react-use-controllable-state@1.2.2_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-use-controllable-state@1.2.2_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs +1 -1
- package/dist/node_modules/.pnpm/{@radix-ui_react-use-controllable-state@1.2.2_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-use-controllable-state@1.2.2_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-use-controllable-state/dist/index.mjs +1 -1
- package/dist/node_modules/.pnpm/{@radix-ui_react-use-escape-keydown@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-use-escape-keydown@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-use-escape-keydown/dist/index.cjs +1 -1
- package/dist/node_modules/.pnpm/{@radix-ui_react-use-escape-keydown@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-use-escape-keydown@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-use-escape-keydown/dist/index.mjs +1 -1
- package/dist/node_modules/.pnpm/{@radix-ui_react-use-size@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-use-size@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-use-size/dist/index.cjs +1 -1
- package/dist/node_modules/.pnpm/{@radix-ui_react-use-size@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-use-size@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-use-size/dist/index.mjs +1 -1
- package/dist/node_modules/.pnpm/{@radix-ui_react-visually-hidden@1.2.3_@types_react-dom@19.2.2_@types_react@19.2.2__@typ_a84e98a44624c31e835a98d4b8b0c30d → @radix-ui_react-visually-hidden@1.2.3_@types_react-dom@19.2.3_@types_react@19.2.6__@typ_f453379bbd5a4932ec515167f81be42a}/node_modules/@radix-ui/react-visually-hidden/dist/index.cjs +1 -1
- package/dist/node_modules/.pnpm/{@radix-ui_react-visually-hidden@1.2.3_@types_react-dom@19.2.2_@types_react@19.2.2__@typ_a84e98a44624c31e835a98d4b8b0c30d → @radix-ui_react-visually-hidden@1.2.3_@types_react-dom@19.2.3_@types_react@19.2.6__@typ_f453379bbd5a4932ec515167f81be42a}/node_modules/@radix-ui/react-visually-hidden/dist/index.mjs +1 -1
- package/dist/node_modules/.pnpm/{react-remove-scroll-bar@2.3.8_@types_react@19.2.2_react@19.2.0 → react-remove-scroll-bar@2.3.8_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll-bar/dist/es2015/component.cjs +1 -1
- package/dist/node_modules/.pnpm/{react-remove-scroll-bar@2.3.8_@types_react@19.2.2_react@19.2.0 → react-remove-scroll-bar@2.3.8_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll-bar/dist/es2015/component.mjs +1 -1
- package/dist/node_modules/.pnpm/{react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0 → react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll/dist/es2015/SideEffect.cjs +2 -2
- package/dist/node_modules/.pnpm/{react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0 → react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll/dist/es2015/SideEffect.mjs +2 -2
- package/dist/node_modules/.pnpm/{react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0 → react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll/dist/es2015/UI.cjs +2 -2
- package/dist/node_modules/.pnpm/{react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0 → react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll/dist/es2015/UI.mjs +2 -2
- package/dist/node_modules/.pnpm/{react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0 → react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll/dist/es2015/medium.cjs +1 -1
- package/dist/node_modules/.pnpm/{react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0 → react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll/dist/es2015/medium.mjs +1 -1
- package/dist/node_modules/.pnpm/react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0/node_modules/react-remove-scroll/dist/es2015/sidecar.cjs +9 -0
- package/dist/node_modules/.pnpm/{react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0 → react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll/dist/es2015/sidecar.mjs +1 -1
- package/dist/packages/better-stack/src/plugins/ai-chat/api/plugin.cjs +610 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/api/plugin.mjs +608 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-input.cjs +221 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-input.mjs +219 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-interface.cjs +315 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-interface.mjs +313 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-layout.cjs +122 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-layout.mjs +120 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-message.cjs +397 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-message.mjs +391 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-sidebar.cjs +227 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-sidebar.mjs +225 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/loading/chat-page-skeleton.cjs +31 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/loading/chat-page-skeleton.mjs +29 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/loading/index.cjs +11 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/loading/index.mjs +8 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/pages/404-page.cjs +18 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/pages/404-page.mjs +16 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/pages/chat-page.cjs +39 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/pages/chat-page.internal.cjs +22 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/pages/chat-page.internal.mjs +20 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/pages/chat-page.mjs +37 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/shared/default-error.cjs +18 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/shared/default-error.mjs +16 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/shared/error-placeholder.cjs +26 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/components/shared/error-placeholder.mjs +24 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/hooks/chat-hooks.cjs +199 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/hooks/chat-hooks.mjs +191 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/localization/index.cjs +63 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/localization/index.mjs +61 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/overrides.cjs +14 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/overrides.mjs +11 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/plugin.cjs +241 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/client/plugin.mjs +239 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/db.cjs +65 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/db.mjs +63 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/schemas.cjs +42 -0
- package/dist/packages/better-stack/src/plugins/ai-chat/schemas.mjs +38 -0
- package/dist/packages/better-stack/src/plugins/blog/client/components/shared/markdown-content.cjs +12 -309
- package/dist/packages/better-stack/src/plugins/blog/client/components/shared/markdown-content.mjs +13 -303
- package/dist/packages/better-stack/src/plugins/blog/client/components/shared/page-wrapper.cjs +2 -2
- package/dist/packages/better-stack/src/plugins/blog/client/components/shared/page-wrapper.mjs +2 -2
- package/dist/packages/ui/src/components/alert-dialog.cjs +1 -1
- package/dist/packages/ui/src/components/alert-dialog.mjs +1 -1
- package/dist/packages/{better-stack/src/plugins/blog/client/components/shared/better-blog-attribution.cjs → ui/src/components/better-stack-attribution.cjs} +3 -3
- package/dist/packages/{better-stack/src/plugins/blog/client/components/shared/better-blog-attribution.mjs → ui/src/components/better-stack-attribution.mjs} +3 -3
- package/dist/packages/ui/src/components/dialog.cjs +14 -0
- package/dist/packages/ui/src/components/dialog.mjs +14 -1
- package/dist/packages/ui/src/components/dropdown-menu.cjs +67 -0
- package/dist/packages/ui/src/components/dropdown-menu.mjs +62 -0
- package/dist/packages/ui/src/components/markdown-content.cjs +306 -0
- package/dist/packages/ui/src/components/markdown-content.mjs +297 -0
- package/dist/packages/ui/src/components/scroll-area.cjs +63 -0
- package/dist/packages/ui/src/components/scroll-area.mjs +60 -0
- package/dist/packages/ui/src/components/select.cjs +1 -1
- package/dist/packages/ui/src/components/select.mjs +1 -1
- package/dist/packages/ui/src/components/sheet.cjs +87 -0
- package/dist/packages/ui/src/components/sheet.mjs +69 -0
- package/dist/plugins/ai-chat/api/index.cjs +9 -0
- package/dist/plugins/ai-chat/api/index.d.cts +9 -0
- package/dist/plugins/ai-chat/api/index.d.mts +9 -0
- package/dist/plugins/ai-chat/api/index.d.ts +9 -0
- package/dist/plugins/ai-chat/api/index.mjs +2 -0
- package/dist/plugins/ai-chat/client/components/index.cjs +27 -0
- package/dist/plugins/ai-chat/client/components/index.d.cts +30 -0
- package/dist/plugins/ai-chat/client/components/index.d.mts +30 -0
- package/dist/plugins/ai-chat/client/components/index.d.ts +30 -0
- package/dist/plugins/ai-chat/client/components/index.mjs +11 -0
- package/dist/plugins/ai-chat/client/hooks/index.cjs +13 -0
- package/dist/plugins/ai-chat/client/hooks/index.d.cts +98 -0
- package/dist/plugins/ai-chat/client/hooks/index.d.mts +98 -0
- package/dist/plugins/ai-chat/client/hooks/index.d.ts +98 -0
- package/dist/plugins/ai-chat/client/hooks/index.mjs +1 -0
- package/dist/plugins/ai-chat/client/index.cjs +19 -0
- package/dist/plugins/ai-chat/client/index.d.cts +327 -0
- package/dist/plugins/ai-chat/client/index.d.mts +327 -0
- package/dist/plugins/ai-chat/client/index.d.ts +327 -0
- package/dist/plugins/ai-chat/client/index.mjs +7 -0
- package/dist/plugins/ai-chat/client.css +6 -0
- package/dist/plugins/ai-chat/query-keys.cjs +60 -0
- package/dist/plugins/ai-chat/query-keys.d.cts +478 -0
- package/dist/plugins/ai-chat/query-keys.d.mts +478 -0
- package/dist/plugins/ai-chat/query-keys.d.ts +478 -0
- package/dist/plugins/ai-chat/query-keys.mjs +58 -0
- package/dist/plugins/ai-chat/style.css +19 -0
- package/dist/plugins/blog/api/index.d.cts +1 -1
- package/dist/plugins/blog/api/index.d.mts +1 -1
- package/dist/plugins/blog/api/index.d.ts +1 -1
- package/dist/plugins/blog/client/components/shared/markdown-content-styles.css +85 -62
- package/dist/plugins/blog/client/hooks/index.d.cts +4 -4
- package/dist/plugins/blog/client/hooks/index.d.mts +4 -4
- package/dist/plugins/blog/client/hooks/index.d.ts +4 -4
- package/dist/plugins/blog/client/index.d.cts +1 -1
- package/dist/plugins/blog/client/index.d.mts +1 -1
- package/dist/plugins/blog/client/index.d.ts +1 -1
- package/dist/plugins/blog/query-keys.d.cts +7 -7
- package/dist/plugins/blog/query-keys.d.mts +7 -7
- package/dist/plugins/blog/query-keys.d.ts +7 -7
- package/dist/shared/stack.Be1QIHEn.d.cts +23 -0
- package/dist/shared/stack.Be1QIHEn.d.mts +23 -0
- package/dist/shared/stack.Be1QIHEn.d.ts +23 -0
- package/dist/shared/stack.DorMi9CZ.d.cts +80 -0
- package/dist/shared/stack.DorMi9CZ.d.mts +80 -0
- package/dist/shared/stack.DorMi9CZ.d.ts +80 -0
- package/package.json +59 -1
- package/src/plugins/ai-chat/api/index.ts +2 -0
- package/src/plugins/ai-chat/api/plugin.ts +1083 -0
- package/src/plugins/ai-chat/client/components/chat-input.tsx +295 -0
- package/src/plugins/ai-chat/client/components/chat-interface.tsx +455 -0
- package/src/plugins/ai-chat/client/components/chat-layout.tsx +160 -0
- package/src/plugins/ai-chat/client/components/chat-message.tsx +505 -0
- package/src/plugins/ai-chat/client/components/chat-sidebar.tsx +296 -0
- package/src/plugins/ai-chat/client/components/index.ts +16 -0
- package/src/plugins/ai-chat/client/components/loading/chat-page-skeleton.tsx +57 -0
- package/src/plugins/ai-chat/client/components/loading/index.tsx +11 -0
- package/src/plugins/ai-chat/client/components/pages/404-page.tsx +27 -0
- package/src/plugins/ai-chat/client/components/pages/chat-page.internal.tsx +31 -0
- package/src/plugins/ai-chat/client/components/pages/chat-page.tsx +46 -0
- package/src/plugins/ai-chat/client/components/shared/default-error.tsx +28 -0
- package/src/plugins/ai-chat/client/components/shared/error-placeholder.tsx +22 -0
- package/src/plugins/ai-chat/client/hooks/chat-hooks.tsx +349 -0
- package/src/plugins/ai-chat/client/hooks/index.tsx +1 -0
- package/src/plugins/ai-chat/client/index.ts +14 -0
- package/src/plugins/ai-chat/client/localization/index.ts +156 -0
- package/src/plugins/ai-chat/client/overrides.ts +170 -0
- package/src/plugins/ai-chat/client/plugin.tsx +449 -0
- package/src/plugins/ai-chat/client.css +6 -0
- package/src/plugins/ai-chat/db.ts +65 -0
- package/src/plugins/ai-chat/query-keys.ts +87 -0
- package/src/plugins/ai-chat/schemas.ts +40 -0
- package/src/plugins/ai-chat/style.css +19 -0
- package/src/plugins/ai-chat/types.ts +29 -0
- package/src/plugins/blog/client/components/shared/markdown-content-styles.css +85 -62
- package/src/plugins/blog/client/components/shared/markdown-content.tsx +19 -427
- package/src/plugins/blog/client/components/shared/page-wrapper.tsx +2 -2
- package/dist/node_modules/.pnpm/react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0/node_modules/react-remove-scroll/dist/es2015/sidecar.cjs +0 -9
- package/src/plugins/blog/client/components/shared/better-blog-attribution.tsx +0 -19
- package/dist/node_modules/.pnpm/{@radix-ui_react-compose-refs@1.1.2_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-compose-refs@1.1.2_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-compose-refs/dist/index.cjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-compose-refs@1.1.2_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-compose-refs@1.1.2_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-compose-refs/dist/index.mjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-context@1.1.2_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-context@1.1.2_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-context/dist/index.cjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-context@1.1.2_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-context@1.1.2_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-context/dist/index.mjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-direction@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-direction@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-direction/dist/index.cjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-direction@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-direction@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-direction/dist/index.mjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-focus-guards@1.1.3_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-focus-guards@1.1.3_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-focus-guards/dist/index.cjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-focus-guards@1.1.3_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-focus-guards@1.1.3_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-focus-guards/dist/index.mjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-primitive@2.1.3_@types_react-dom@19.2.2_@types_react@19.2.2__@types_rea_bdc15f10281778271ffcbe8dd3cd491e → @radix-ui_react-primitive@2.1.3_@types_react-dom@19.2.3_@types_react@19.2.6__@types_rea_a92a69cb1cb39305138539e4fa72f596}/node_modules/@radix-ui/react-primitive/dist/index.cjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-primitive@2.1.3_@types_react-dom@19.2.2_@types_react@19.2.2__@types_rea_bdc15f10281778271ffcbe8dd3cd491e → @radix-ui_react-primitive@2.1.3_@types_react-dom@19.2.3_@types_react@19.2.6__@types_rea_a92a69cb1cb39305138539e4fa72f596}/node_modules/@radix-ui/react-primitive/dist/index.mjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-use-callback-ref@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-use-callback-ref@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-use-callback-ref/dist/index.cjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-use-callback-ref@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-use-callback-ref@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-use-callback-ref/dist/index.mjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-use-layout-effect@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-use-layout-effect@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-use-layout-effect/dist/index.cjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-use-layout-effect@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-use-layout-effect@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-use-layout-effect/dist/index.mjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-use-previous@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-use-previous@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-use-previous/dist/index.cjs +0 -0
- package/dist/node_modules/.pnpm/{@radix-ui_react-use-previous@1.1.1_@types_react@19.2.2_react@19.2.0 → @radix-ui_react-use-previous@1.1.1_@types_react@19.2.6_react@19.2.0}/node_modules/@radix-ui/react-use-previous/dist/index.mjs +0 -0
- package/dist/node_modules/.pnpm/{react-remove-scroll-bar@2.3.8_@types_react@19.2.2_react@19.2.0 → react-remove-scroll-bar@2.3.8_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll-bar/dist/es2015/constants.cjs +0 -0
- package/dist/node_modules/.pnpm/{react-remove-scroll-bar@2.3.8_@types_react@19.2.2_react@19.2.0 → react-remove-scroll-bar@2.3.8_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll-bar/dist/es2015/constants.mjs +0 -0
- package/dist/node_modules/.pnpm/{react-remove-scroll-bar@2.3.8_@types_react@19.2.2_react@19.2.0 → react-remove-scroll-bar@2.3.8_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll-bar/dist/es2015/utils.cjs +0 -0
- package/dist/node_modules/.pnpm/{react-remove-scroll-bar@2.3.8_@types_react@19.2.2_react@19.2.0 → react-remove-scroll-bar@2.3.8_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll-bar/dist/es2015/utils.mjs +0 -0
- package/dist/node_modules/.pnpm/{react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0 → react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll/dist/es2015/Combination.cjs +0 -0
- package/dist/node_modules/.pnpm/{react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0 → react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll/dist/es2015/Combination.mjs +0 -0
- package/dist/node_modules/.pnpm/{react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0 → react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.cjs +0 -0
- package/dist/node_modules/.pnpm/{react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0 → react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.mjs +0 -0
- package/dist/node_modules/.pnpm/{react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0 → react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll/dist/es2015/handleScroll.cjs +0 -0
- package/dist/node_modules/.pnpm/{react-remove-scroll@2.7.1_@types_react@19.2.2_react@19.2.0 → react-remove-scroll@2.7.1_@types_react@19.2.6_react@19.2.0}/node_modules/react-remove-scroll/dist/es2015/handleScroll.mjs +0 -0
- package/dist/node_modules/.pnpm/{react-style-singleton@2.2.3_@types_react@19.2.2_react@19.2.0 → react-style-singleton@2.2.3_@types_react@19.2.6_react@19.2.0}/node_modules/react-style-singleton/dist/es2015/component.cjs +0 -0
- package/dist/node_modules/.pnpm/{react-style-singleton@2.2.3_@types_react@19.2.2_react@19.2.0 → react-style-singleton@2.2.3_@types_react@19.2.6_react@19.2.0}/node_modules/react-style-singleton/dist/es2015/component.mjs +0 -0
- package/dist/node_modules/.pnpm/{react-style-singleton@2.2.3_@types_react@19.2.2_react@19.2.0 → react-style-singleton@2.2.3_@types_react@19.2.6_react@19.2.0}/node_modules/react-style-singleton/dist/es2015/hook.cjs +0 -0
- package/dist/node_modules/.pnpm/{react-style-singleton@2.2.3_@types_react@19.2.2_react@19.2.0 → react-style-singleton@2.2.3_@types_react@19.2.6_react@19.2.0}/node_modules/react-style-singleton/dist/es2015/hook.mjs +0 -0
- package/dist/node_modules/.pnpm/{react-style-singleton@2.2.3_@types_react@19.2.2_react@19.2.0 → react-style-singleton@2.2.3_@types_react@19.2.6_react@19.2.0}/node_modules/react-style-singleton/dist/es2015/singleton.cjs +0 -0
- package/dist/node_modules/.pnpm/{react-style-singleton@2.2.3_@types_react@19.2.2_react@19.2.0 → react-style-singleton@2.2.3_@types_react@19.2.6_react@19.2.0}/node_modules/react-style-singleton/dist/es2015/singleton.mjs +0 -0
- package/dist/node_modules/.pnpm/{use-callback-ref@1.3.3_@types_react@19.2.2_react@19.2.0 → use-callback-ref@1.3.3_@types_react@19.2.6_react@19.2.0}/node_modules/use-callback-ref/dist/es2015/assignRef.cjs +0 -0
- package/dist/node_modules/.pnpm/{use-callback-ref@1.3.3_@types_react@19.2.2_react@19.2.0 → use-callback-ref@1.3.3_@types_react@19.2.6_react@19.2.0}/node_modules/use-callback-ref/dist/es2015/assignRef.mjs +0 -0
- package/dist/node_modules/.pnpm/{use-callback-ref@1.3.3_@types_react@19.2.2_react@19.2.0 → use-callback-ref@1.3.3_@types_react@19.2.6_react@19.2.0}/node_modules/use-callback-ref/dist/es2015/useMergeRef.cjs +0 -0
- package/dist/node_modules/.pnpm/{use-callback-ref@1.3.3_@types_react@19.2.2_react@19.2.0 → use-callback-ref@1.3.3_@types_react@19.2.6_react@19.2.0}/node_modules/use-callback-ref/dist/es2015/useMergeRef.mjs +0 -0
- package/dist/node_modules/.pnpm/{use-callback-ref@1.3.3_@types_react@19.2.2_react@19.2.0 → use-callback-ref@1.3.3_@types_react@19.2.6_react@19.2.0}/node_modules/use-callback-ref/dist/es2015/useRef.cjs +0 -0
- package/dist/node_modules/.pnpm/{use-callback-ref@1.3.3_@types_react@19.2.2_react@19.2.0 → use-callback-ref@1.3.3_@types_react@19.2.6_react@19.2.0}/node_modules/use-callback-ref/dist/es2015/useRef.mjs +0 -0
- package/dist/node_modules/.pnpm/{use-sidecar@1.1.3_@types_react@19.2.2_react@19.2.0 → use-sidecar@1.1.3_@types_react@19.2.6_react@19.2.0}/node_modules/use-sidecar/dist/es2015/exports.cjs +0 -0
- package/dist/node_modules/.pnpm/{use-sidecar@1.1.3_@types_react@19.2.2_react@19.2.0 → use-sidecar@1.1.3_@types_react@19.2.6_react@19.2.0}/node_modules/use-sidecar/dist/es2015/exports.mjs +0 -0
- package/dist/node_modules/.pnpm/{use-sidecar@1.1.3_@types_react@19.2.2_react@19.2.0 → use-sidecar@1.1.3_@types_react@19.2.6_react@19.2.0}/node_modules/use-sidecar/dist/es2015/medium.cjs +0 -0
- package/dist/node_modules/.pnpm/{use-sidecar@1.1.3_@types_react@19.2.2_react@19.2.0 → use-sidecar@1.1.3_@types_react@19.2.6_react@19.2.0}/node_modules/use-sidecar/dist/es2015/medium.mjs +0 -0
- package/dist/shared/{stack.CbuN2zVV.d.ts → stack.CcI4sYJP.d.cts} +3 -3
- package/dist/shared/{stack.CbuN2zVV.d.cts → stack.CcI4sYJP.d.mts} +3 -3
- package/dist/shared/{stack.CbuN2zVV.d.mts → stack.CcI4sYJP.d.ts} +3 -3
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
import { defineBackendPlugin, createEndpoint } from '@btst/stack/plugins/api';
|
|
2
|
+
import { convertToModelMessages, streamText, stepCountIs } from 'ai';
|
|
3
|
+
import { aiChatSchema } from '../db.mjs';
|
|
4
|
+
import { chatRequestSchema, createConversationSchema, updateConversationSchema } from '../schemas.mjs';
|
|
5
|
+
|
|
6
|
+
const aiChatBackendPlugin = (config) => defineBackendPlugin({
|
|
7
|
+
name: "ai-chat",
|
|
8
|
+
// Always include db schema - in public mode we just don't use it
|
|
9
|
+
dbPlugin: aiChatSchema,
|
|
10
|
+
routes: (adapter) => {
|
|
11
|
+
const mode = config.mode ?? "authenticated";
|
|
12
|
+
const isPublicMode = mode === "public";
|
|
13
|
+
const getMessageTextContent = (msg) => {
|
|
14
|
+
if (msg.parts && Array.isArray(msg.parts)) {
|
|
15
|
+
return msg.parts.filter((part) => part.type === "text").map((part) => part.text).join("");
|
|
16
|
+
}
|
|
17
|
+
return "";
|
|
18
|
+
};
|
|
19
|
+
const serializeMessageParts = (msg) => {
|
|
20
|
+
if (msg.parts && Array.isArray(msg.parts)) {
|
|
21
|
+
const serializableParts = msg.parts.filter(
|
|
22
|
+
(part) => part.type === "text" || part.type === "file"
|
|
23
|
+
);
|
|
24
|
+
return JSON.stringify(serializableParts);
|
|
25
|
+
}
|
|
26
|
+
return JSON.stringify([]);
|
|
27
|
+
};
|
|
28
|
+
const resolveUserId = async (context, throwOnMissing) => {
|
|
29
|
+
if (isPublicMode) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
if (!config.getUserId) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const userId = await config.getUserId(context);
|
|
36
|
+
if (!userId) {
|
|
37
|
+
throwOnMissing();
|
|
38
|
+
}
|
|
39
|
+
return userId;
|
|
40
|
+
};
|
|
41
|
+
const chat = createEndpoint(
|
|
42
|
+
"/chat",
|
|
43
|
+
{
|
|
44
|
+
method: "POST",
|
|
45
|
+
body: chatRequestSchema
|
|
46
|
+
},
|
|
47
|
+
async (ctx) => {
|
|
48
|
+
const { messages: rawMessages, conversationId } = ctx.body;
|
|
49
|
+
const uiMessages = rawMessages;
|
|
50
|
+
const context = {
|
|
51
|
+
body: ctx.body,
|
|
52
|
+
headers: ctx.headers,
|
|
53
|
+
request: ctx.request
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
if (config.hooks?.onBeforeChat) {
|
|
57
|
+
const messagesForHook = uiMessages.map((msg) => ({
|
|
58
|
+
role: msg.role,
|
|
59
|
+
content: getMessageTextContent(msg)
|
|
60
|
+
}));
|
|
61
|
+
const canChat = await config.hooks.onBeforeChat(
|
|
62
|
+
messagesForHook,
|
|
63
|
+
context
|
|
64
|
+
);
|
|
65
|
+
if (!canChat) {
|
|
66
|
+
throw ctx.error(403, {
|
|
67
|
+
message: "Unauthorized: Cannot start chat"
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const firstMessage = uiMessages[0];
|
|
72
|
+
if (!firstMessage) {
|
|
73
|
+
throw ctx.error(400, {
|
|
74
|
+
message: "At least one message is required"
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const firstMessageContent = getMessageTextContent(firstMessage);
|
|
78
|
+
const modelMessages = convertToModelMessages(uiMessages);
|
|
79
|
+
const messagesWithSystem = config.systemPrompt ? [
|
|
80
|
+
{ role: "system", content: config.systemPrompt },
|
|
81
|
+
...modelMessages
|
|
82
|
+
] : modelMessages;
|
|
83
|
+
if (isPublicMode) {
|
|
84
|
+
const result2 = streamText({
|
|
85
|
+
model: config.model,
|
|
86
|
+
messages: messagesWithSystem,
|
|
87
|
+
tools: config.tools,
|
|
88
|
+
// Enable multi-step tool calls if tools are configured
|
|
89
|
+
...config.tools ? { stopWhen: stepCountIs(5) } : {}
|
|
90
|
+
});
|
|
91
|
+
return result2.toUIMessageStreamResponse({
|
|
92
|
+
originalMessages: uiMessages
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
let userId = null;
|
|
96
|
+
if (config.getUserId) {
|
|
97
|
+
const resolvedUserId = await config.getUserId(context);
|
|
98
|
+
if (!resolvedUserId) {
|
|
99
|
+
throw ctx.error(403, {
|
|
100
|
+
message: "Unauthorized: User authentication required"
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
userId = resolvedUserId;
|
|
104
|
+
}
|
|
105
|
+
let convId = conversationId;
|
|
106
|
+
if (!convId) {
|
|
107
|
+
const newConv = await adapter.create({
|
|
108
|
+
model: "conversation",
|
|
109
|
+
data: {
|
|
110
|
+
...userId ? { userId } : {},
|
|
111
|
+
title: firstMessageContent.slice(0, 50) || "New Conversation",
|
|
112
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
113
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
convId = newConv.id;
|
|
117
|
+
} else {
|
|
118
|
+
const existing = await adapter.findMany({
|
|
119
|
+
model: "conversation",
|
|
120
|
+
where: [{ field: "id", value: convId, operator: "eq" }],
|
|
121
|
+
limit: 1
|
|
122
|
+
});
|
|
123
|
+
if (!existing.length) {
|
|
124
|
+
const newConv = await adapter.create({
|
|
125
|
+
model: "conversation",
|
|
126
|
+
data: {
|
|
127
|
+
id: convId,
|
|
128
|
+
...userId ? { userId } : {},
|
|
129
|
+
title: firstMessageContent.slice(0, 50) || "New Conversation",
|
|
130
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
131
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
convId = newConv.id;
|
|
135
|
+
} else {
|
|
136
|
+
const conv = existing[0];
|
|
137
|
+
if (userId && conv.userId && conv.userId !== userId) {
|
|
138
|
+
throw ctx.error(403, {
|
|
139
|
+
message: "Unauthorized: Cannot access this conversation"
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const existingMessages = await adapter.findMany({
|
|
145
|
+
model: "message",
|
|
146
|
+
where: [
|
|
147
|
+
{
|
|
148
|
+
field: "conversationId",
|
|
149
|
+
value: convId,
|
|
150
|
+
operator: "eq"
|
|
151
|
+
}
|
|
152
|
+
],
|
|
153
|
+
sortBy: { field: "createdAt", direction: "asc" }
|
|
154
|
+
});
|
|
155
|
+
const lastIncomingMessage = uiMessages[uiMessages.length - 1];
|
|
156
|
+
const isNewUserMessage = lastIncomingMessage?.role === "user";
|
|
157
|
+
let expectedDbCount;
|
|
158
|
+
let shouldAddUserMessage = false;
|
|
159
|
+
if (isNewUserMessage) {
|
|
160
|
+
const lastDbUserMessage = [...existingMessages].reverse().find((m) => m.role === "user");
|
|
161
|
+
const incomingUserContent = serializeMessageParts(lastIncomingMessage);
|
|
162
|
+
if (lastDbUserMessage && lastDbUserMessage.content === incomingUserContent) {
|
|
163
|
+
expectedDbCount = uiMessages.length;
|
|
164
|
+
shouldAddUserMessage = false;
|
|
165
|
+
} else {
|
|
166
|
+
expectedDbCount = uiMessages.length - 1;
|
|
167
|
+
shouldAddUserMessage = true;
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
expectedDbCount = uiMessages.length;
|
|
171
|
+
shouldAddUserMessage = false;
|
|
172
|
+
}
|
|
173
|
+
const actualDbCount = existingMessages.length;
|
|
174
|
+
const messagesToDelete = actualDbCount > expectedDbCount ? existingMessages.slice(expectedDbCount) : [];
|
|
175
|
+
await adapter.transaction(async (tx) => {
|
|
176
|
+
for (const msg of messagesToDelete) {
|
|
177
|
+
await tx.delete({
|
|
178
|
+
model: "message",
|
|
179
|
+
where: [{ field: "id", value: msg.id }]
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (shouldAddUserMessage && lastIncomingMessage) {
|
|
183
|
+
await tx.create({
|
|
184
|
+
model: "message",
|
|
185
|
+
data: {
|
|
186
|
+
conversationId: convId,
|
|
187
|
+
role: "user",
|
|
188
|
+
content: serializeMessageParts(lastIncomingMessage),
|
|
189
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
const result = streamText({
|
|
195
|
+
model: config.model,
|
|
196
|
+
messages: messagesWithSystem,
|
|
197
|
+
tools: config.tools,
|
|
198
|
+
// Enable multi-step tool calls if tools are configured
|
|
199
|
+
...config.tools ? { stopWhen: stepCountIs(5) } : {},
|
|
200
|
+
onFinish: async (completion) => {
|
|
201
|
+
try {
|
|
202
|
+
const assistantParts = completion.text ? [{ type: "text", text: completion.text }] : [];
|
|
203
|
+
await adapter.create({
|
|
204
|
+
model: "message",
|
|
205
|
+
data: {
|
|
206
|
+
conversationId: convId,
|
|
207
|
+
role: "assistant",
|
|
208
|
+
content: JSON.stringify(assistantParts),
|
|
209
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
await adapter.update({
|
|
213
|
+
model: "conversation",
|
|
214
|
+
where: [{ field: "id", value: convId }],
|
|
215
|
+
update: { updatedAt: /* @__PURE__ */ new Date() }
|
|
216
|
+
});
|
|
217
|
+
if (config.hooks?.onAfterChat) {
|
|
218
|
+
const messages = await adapter.findMany({
|
|
219
|
+
model: "message",
|
|
220
|
+
where: [
|
|
221
|
+
{
|
|
222
|
+
field: "conversationId",
|
|
223
|
+
value: convId,
|
|
224
|
+
operator: "eq"
|
|
225
|
+
}
|
|
226
|
+
],
|
|
227
|
+
sortBy: { field: "createdAt", direction: "asc" }
|
|
228
|
+
});
|
|
229
|
+
await config.hooks.onAfterChat(
|
|
230
|
+
convId,
|
|
231
|
+
messages,
|
|
232
|
+
context
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
} catch (error) {
|
|
236
|
+
console.error("[ai-chat] Error in onFinish callback:", error);
|
|
237
|
+
if (config.hooks?.onChatError) {
|
|
238
|
+
try {
|
|
239
|
+
await config.hooks.onChatError(error, context);
|
|
240
|
+
} catch (hookError) {
|
|
241
|
+
console.error(
|
|
242
|
+
"[ai-chat] Error in onChatError hook:",
|
|
243
|
+
hookError
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
const response = result.toUIMessageStreamResponse({
|
|
251
|
+
originalMessages: uiMessages
|
|
252
|
+
});
|
|
253
|
+
const headers = new Headers(response.headers);
|
|
254
|
+
headers.set("X-Conversation-Id", convId);
|
|
255
|
+
return new Response(response.body, {
|
|
256
|
+
status: response.status,
|
|
257
|
+
statusText: response.statusText,
|
|
258
|
+
headers
|
|
259
|
+
});
|
|
260
|
+
} catch (error) {
|
|
261
|
+
if (config.hooks?.onChatError) {
|
|
262
|
+
await config.hooks.onChatError(error, context);
|
|
263
|
+
}
|
|
264
|
+
throw error;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
const createConversation = createEndpoint(
|
|
269
|
+
"/chat/conversations",
|
|
270
|
+
{
|
|
271
|
+
method: "POST",
|
|
272
|
+
body: createConversationSchema
|
|
273
|
+
},
|
|
274
|
+
async (ctx) => {
|
|
275
|
+
if (isPublicMode) {
|
|
276
|
+
throw ctx.error(404, {
|
|
277
|
+
message: "Conversations not available in public mode"
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
const { id, title } = ctx.body;
|
|
281
|
+
const context = {
|
|
282
|
+
body: ctx.body,
|
|
283
|
+
headers: ctx.headers
|
|
284
|
+
};
|
|
285
|
+
try {
|
|
286
|
+
const userId = await resolveUserId(context, () => {
|
|
287
|
+
throw ctx.error(403, {
|
|
288
|
+
message: "Unauthorized: User authentication required"
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
if (config.hooks?.onBeforeCreateConversation) {
|
|
292
|
+
const canCreate = await config.hooks.onBeforeCreateConversation(
|
|
293
|
+
{ id, title },
|
|
294
|
+
context
|
|
295
|
+
);
|
|
296
|
+
if (!canCreate) {
|
|
297
|
+
throw ctx.error(403, {
|
|
298
|
+
message: "Unauthorized: Cannot create conversation"
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const newConv = await adapter.create({
|
|
303
|
+
model: "conversation",
|
|
304
|
+
data: {
|
|
305
|
+
...id ? { id } : {},
|
|
306
|
+
...userId ? { userId } : {},
|
|
307
|
+
title: title || "New Conversation",
|
|
308
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
309
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
if (config.hooks?.onConversationCreated) {
|
|
313
|
+
await config.hooks.onConversationCreated(newConv, context);
|
|
314
|
+
}
|
|
315
|
+
return newConv;
|
|
316
|
+
} catch (error) {
|
|
317
|
+
if (config.hooks?.onCreateConversationError) {
|
|
318
|
+
await config.hooks.onCreateConversationError(
|
|
319
|
+
error,
|
|
320
|
+
context
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
throw error;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
);
|
|
327
|
+
const listConversations = createEndpoint(
|
|
328
|
+
"/chat/conversations",
|
|
329
|
+
{
|
|
330
|
+
method: "GET"
|
|
331
|
+
},
|
|
332
|
+
async (ctx) => {
|
|
333
|
+
if (isPublicMode) {
|
|
334
|
+
return [];
|
|
335
|
+
}
|
|
336
|
+
const context = {
|
|
337
|
+
headers: ctx.headers
|
|
338
|
+
};
|
|
339
|
+
try {
|
|
340
|
+
const userId = await resolveUserId(context, () => {
|
|
341
|
+
throw ctx.error(403, {
|
|
342
|
+
message: "Unauthorized: User authentication required"
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
if (config.hooks?.onBeforeListConversations) {
|
|
346
|
+
const canList = await config.hooks.onBeforeListConversations(context);
|
|
347
|
+
if (!canList) {
|
|
348
|
+
throw ctx.error(403, {
|
|
349
|
+
message: "Unauthorized: Cannot list conversations"
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
const whereConditions = [];
|
|
354
|
+
if (userId) {
|
|
355
|
+
whereConditions.push({
|
|
356
|
+
field: "userId",
|
|
357
|
+
value: userId,
|
|
358
|
+
operator: "eq"
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
const conversations = await adapter.findMany({
|
|
362
|
+
model: "conversation",
|
|
363
|
+
where: whereConditions.length > 0 ? whereConditions : void 0,
|
|
364
|
+
sortBy: { field: "updatedAt", direction: "desc" }
|
|
365
|
+
});
|
|
366
|
+
if (config.hooks?.onConversationsRead) {
|
|
367
|
+
await config.hooks.onConversationsRead(conversations, context);
|
|
368
|
+
}
|
|
369
|
+
return conversations;
|
|
370
|
+
} catch (error) {
|
|
371
|
+
if (config.hooks?.onListConversationsError) {
|
|
372
|
+
await config.hooks.onListConversationsError(
|
|
373
|
+
error,
|
|
374
|
+
context
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
throw error;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
);
|
|
381
|
+
const getConversation = createEndpoint(
|
|
382
|
+
"/chat/conversations/:id",
|
|
383
|
+
{
|
|
384
|
+
method: "GET"
|
|
385
|
+
},
|
|
386
|
+
async (ctx) => {
|
|
387
|
+
if (isPublicMode) {
|
|
388
|
+
throw ctx.error(404, {
|
|
389
|
+
message: "Conversations not available in public mode"
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
const { id } = ctx.params;
|
|
393
|
+
const context = {
|
|
394
|
+
params: ctx.params,
|
|
395
|
+
headers: ctx.headers
|
|
396
|
+
};
|
|
397
|
+
try {
|
|
398
|
+
const userId = await resolveUserId(context, () => {
|
|
399
|
+
throw ctx.error(403, {
|
|
400
|
+
message: "Unauthorized: User authentication required"
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
if (config.hooks?.onBeforeGetConversation) {
|
|
404
|
+
const canGet = await config.hooks.onBeforeGetConversation(
|
|
405
|
+
id,
|
|
406
|
+
context
|
|
407
|
+
);
|
|
408
|
+
if (!canGet) {
|
|
409
|
+
throw ctx.error(403, {
|
|
410
|
+
message: "Unauthorized: Cannot get conversation"
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const conversations = await adapter.findMany({
|
|
415
|
+
model: "conversation",
|
|
416
|
+
where: [{ field: "id", value: id, operator: "eq" }],
|
|
417
|
+
limit: 1,
|
|
418
|
+
join: {
|
|
419
|
+
message: true
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
if (!conversations.length) {
|
|
423
|
+
throw ctx.error(404, { message: "Conversation not found" });
|
|
424
|
+
}
|
|
425
|
+
const conversation = conversations[0];
|
|
426
|
+
if (userId && conversation.userId && conversation.userId !== userId) {
|
|
427
|
+
throw ctx.error(403, {
|
|
428
|
+
message: "Unauthorized: Cannot access this conversation"
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
const messages = (conversation.message || []).sort(
|
|
432
|
+
(a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()
|
|
433
|
+
);
|
|
434
|
+
const { message: _, ...conversationWithoutJoin } = conversation;
|
|
435
|
+
const result = {
|
|
436
|
+
...conversationWithoutJoin,
|
|
437
|
+
messages
|
|
438
|
+
};
|
|
439
|
+
if (config.hooks?.onConversationRead) {
|
|
440
|
+
await config.hooks.onConversationRead(result, context);
|
|
441
|
+
}
|
|
442
|
+
return result;
|
|
443
|
+
} catch (error) {
|
|
444
|
+
if (config.hooks?.onGetConversationError) {
|
|
445
|
+
await config.hooks.onGetConversationError(
|
|
446
|
+
error,
|
|
447
|
+
context
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
throw error;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
);
|
|
454
|
+
const updateConversation = createEndpoint(
|
|
455
|
+
"/chat/conversations/:id",
|
|
456
|
+
{
|
|
457
|
+
method: "PUT",
|
|
458
|
+
body: updateConversationSchema
|
|
459
|
+
},
|
|
460
|
+
async (ctx) => {
|
|
461
|
+
if (isPublicMode) {
|
|
462
|
+
throw ctx.error(404, {
|
|
463
|
+
message: "Conversations not available in public mode"
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
const { id } = ctx.params;
|
|
467
|
+
const { title } = ctx.body;
|
|
468
|
+
const context = {
|
|
469
|
+
params: ctx.params,
|
|
470
|
+
body: ctx.body,
|
|
471
|
+
headers: ctx.headers
|
|
472
|
+
};
|
|
473
|
+
try {
|
|
474
|
+
const userId = await resolveUserId(context, () => {
|
|
475
|
+
throw ctx.error(403, {
|
|
476
|
+
message: "Unauthorized: User authentication required"
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
const existing = await adapter.findMany({
|
|
480
|
+
model: "conversation",
|
|
481
|
+
where: [{ field: "id", value: id, operator: "eq" }],
|
|
482
|
+
limit: 1
|
|
483
|
+
});
|
|
484
|
+
if (!existing.length) {
|
|
485
|
+
throw ctx.error(404, { message: "Conversation not found" });
|
|
486
|
+
}
|
|
487
|
+
const conversation = existing[0];
|
|
488
|
+
if (userId && conversation.userId && conversation.userId !== userId) {
|
|
489
|
+
throw ctx.error(403, {
|
|
490
|
+
message: "Unauthorized: Cannot update this conversation"
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
if (config.hooks?.onBeforeUpdateConversation) {
|
|
494
|
+
const canUpdate = await config.hooks.onBeforeUpdateConversation(
|
|
495
|
+
id,
|
|
496
|
+
{ title },
|
|
497
|
+
context
|
|
498
|
+
);
|
|
499
|
+
if (!canUpdate) {
|
|
500
|
+
throw ctx.error(403, {
|
|
501
|
+
message: "Unauthorized: Cannot update conversation"
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
const updated = await adapter.update({
|
|
506
|
+
model: "conversation",
|
|
507
|
+
where: [{ field: "id", value: id }],
|
|
508
|
+
update: {
|
|
509
|
+
...title !== void 0 ? { title } : {},
|
|
510
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
if (!updated) {
|
|
514
|
+
throw ctx.error(404, { message: "Conversation not found" });
|
|
515
|
+
}
|
|
516
|
+
if (config.hooks?.onConversationUpdated) {
|
|
517
|
+
await config.hooks.onConversationUpdated(updated, context);
|
|
518
|
+
}
|
|
519
|
+
return updated;
|
|
520
|
+
} catch (error) {
|
|
521
|
+
if (config.hooks?.onUpdateConversationError) {
|
|
522
|
+
await config.hooks.onUpdateConversationError(
|
|
523
|
+
error,
|
|
524
|
+
context
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
throw error;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
);
|
|
531
|
+
const deleteConversation = createEndpoint(
|
|
532
|
+
"/chat/conversations/:id",
|
|
533
|
+
{
|
|
534
|
+
method: "DELETE"
|
|
535
|
+
},
|
|
536
|
+
async (ctx) => {
|
|
537
|
+
if (isPublicMode) {
|
|
538
|
+
throw ctx.error(404, {
|
|
539
|
+
message: "Conversations not available in public mode"
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
const { id } = ctx.params;
|
|
543
|
+
const context = {
|
|
544
|
+
params: ctx.params,
|
|
545
|
+
headers: ctx.headers
|
|
546
|
+
};
|
|
547
|
+
try {
|
|
548
|
+
const userId = await resolveUserId(context, () => {
|
|
549
|
+
throw ctx.error(403, {
|
|
550
|
+
message: "Unauthorized: User authentication required"
|
|
551
|
+
});
|
|
552
|
+
});
|
|
553
|
+
const existing = await adapter.findMany({
|
|
554
|
+
model: "conversation",
|
|
555
|
+
where: [{ field: "id", value: id, operator: "eq" }],
|
|
556
|
+
limit: 1
|
|
557
|
+
});
|
|
558
|
+
if (!existing.length) {
|
|
559
|
+
throw ctx.error(404, { message: "Conversation not found" });
|
|
560
|
+
}
|
|
561
|
+
const conversation = existing[0];
|
|
562
|
+
if (userId && conversation.userId && conversation.userId !== userId) {
|
|
563
|
+
throw ctx.error(403, {
|
|
564
|
+
message: "Unauthorized: Cannot delete this conversation"
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
if (config.hooks?.onBeforeDeleteConversation) {
|
|
568
|
+
const canDelete = await config.hooks.onBeforeDeleteConversation(
|
|
569
|
+
id,
|
|
570
|
+
context
|
|
571
|
+
);
|
|
572
|
+
if (!canDelete) {
|
|
573
|
+
throw ctx.error(403, {
|
|
574
|
+
message: "Unauthorized: Cannot delete conversation"
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
await adapter.delete({
|
|
579
|
+
model: "conversation",
|
|
580
|
+
where: [{ field: "id", value: id }]
|
|
581
|
+
});
|
|
582
|
+
if (config.hooks?.onConversationDeleted) {
|
|
583
|
+
await config.hooks.onConversationDeleted(id, context);
|
|
584
|
+
}
|
|
585
|
+
return { success: true };
|
|
586
|
+
} catch (error) {
|
|
587
|
+
if (config.hooks?.onDeleteConversationError) {
|
|
588
|
+
await config.hooks.onDeleteConversationError(
|
|
589
|
+
error,
|
|
590
|
+
context
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
throw error;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
);
|
|
597
|
+
return {
|
|
598
|
+
chat,
|
|
599
|
+
createConversation,
|
|
600
|
+
listConversations,
|
|
601
|
+
getConversation,
|
|
602
|
+
updateConversation,
|
|
603
|
+
deleteConversation
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
export { aiChatBackendPlugin };
|