@btst/stack 1.3.0 → 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.
Files changed (241) hide show
  1. package/README.md +85 -37
  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.cjs +2 -2
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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
  30. 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
  31. 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
  32. 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
  33. 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
  34. 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
  35. 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
  36. 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
  37. 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
  38. 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
  39. 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
  40. 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
  41. 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
  42. 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
  43. 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
  44. 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
  45. 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
  46. 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
  47. 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
  48. package/dist/packages/better-stack/src/plugins/ai-chat/api/plugin.cjs +610 -0
  49. package/dist/packages/better-stack/src/plugins/ai-chat/api/plugin.mjs +608 -0
  50. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-input.cjs +221 -0
  51. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-input.mjs +219 -0
  52. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-interface.cjs +315 -0
  53. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-interface.mjs +313 -0
  54. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-layout.cjs +122 -0
  55. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-layout.mjs +120 -0
  56. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-message.cjs +397 -0
  57. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-message.mjs +391 -0
  58. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-sidebar.cjs +227 -0
  59. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/chat-sidebar.mjs +225 -0
  60. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/loading/chat-page-skeleton.cjs +31 -0
  61. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/loading/chat-page-skeleton.mjs +29 -0
  62. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/loading/index.cjs +11 -0
  63. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/loading/index.mjs +8 -0
  64. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/pages/404-page.cjs +18 -0
  65. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/pages/404-page.mjs +16 -0
  66. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/pages/chat-page.cjs +39 -0
  67. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/pages/chat-page.internal.cjs +22 -0
  68. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/pages/chat-page.internal.mjs +20 -0
  69. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/pages/chat-page.mjs +37 -0
  70. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/shared/default-error.cjs +18 -0
  71. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/shared/default-error.mjs +16 -0
  72. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/shared/error-placeholder.cjs +26 -0
  73. package/dist/packages/better-stack/src/plugins/ai-chat/client/components/shared/error-placeholder.mjs +24 -0
  74. package/dist/packages/better-stack/src/plugins/ai-chat/client/hooks/chat-hooks.cjs +199 -0
  75. package/dist/packages/better-stack/src/plugins/ai-chat/client/hooks/chat-hooks.mjs +191 -0
  76. package/dist/packages/better-stack/src/plugins/ai-chat/client/localization/index.cjs +63 -0
  77. package/dist/packages/better-stack/src/plugins/ai-chat/client/localization/index.mjs +61 -0
  78. package/dist/packages/better-stack/src/plugins/ai-chat/client/overrides.cjs +14 -0
  79. package/dist/packages/better-stack/src/plugins/ai-chat/client/overrides.mjs +11 -0
  80. package/dist/packages/better-stack/src/plugins/ai-chat/client/plugin.cjs +241 -0
  81. package/dist/packages/better-stack/src/plugins/ai-chat/client/plugin.mjs +239 -0
  82. package/dist/packages/better-stack/src/plugins/ai-chat/db.cjs +65 -0
  83. package/dist/packages/better-stack/src/plugins/ai-chat/db.mjs +63 -0
  84. package/dist/packages/better-stack/src/plugins/ai-chat/schemas.cjs +42 -0
  85. package/dist/packages/better-stack/src/plugins/ai-chat/schemas.mjs +38 -0
  86. package/dist/packages/better-stack/src/plugins/blog/api/plugin.cjs +8 -2
  87. package/dist/packages/better-stack/src/plugins/blog/api/plugin.mjs +8 -2
  88. package/dist/packages/better-stack/src/plugins/blog/client/components/pages/post-page.internal.cjs +1 -1
  89. package/dist/packages/better-stack/src/plugins/blog/client/components/pages/post-page.internal.mjs +1 -1
  90. package/dist/packages/better-stack/src/plugins/blog/client/components/shared/markdown-content.cjs +12 -309
  91. package/dist/packages/better-stack/src/plugins/blog/client/components/shared/markdown-content.mjs +13 -303
  92. package/dist/packages/better-stack/src/plugins/blog/client/components/shared/on-this-page.cjs +1 -1
  93. package/dist/packages/better-stack/src/plugins/blog/client/components/shared/on-this-page.mjs +1 -1
  94. package/dist/packages/better-stack/src/plugins/blog/client/components/shared/page-wrapper.cjs +2 -2
  95. package/dist/packages/better-stack/src/plugins/blog/client/components/shared/page-wrapper.mjs +2 -2
  96. package/dist/packages/better-stack/src/plugins/blog/client/components/shared/recent-posts-carousel.cjs +2 -2
  97. package/dist/packages/better-stack/src/plugins/blog/client/components/shared/recent-posts-carousel.mjs +2 -2
  98. package/dist/packages/ui/src/components/alert-dialog.cjs +1 -1
  99. package/dist/packages/ui/src/components/alert-dialog.mjs +1 -1
  100. package/dist/packages/{better-stack/src/plugins/blog/client/components/shared/better-blog-attribution.cjs → ui/src/components/better-stack-attribution.cjs} +3 -3
  101. package/dist/packages/{better-stack/src/plugins/blog/client/components/shared/better-blog-attribution.mjs → ui/src/components/better-stack-attribution.mjs} +3 -3
  102. package/dist/packages/ui/src/components/dialog.cjs +14 -0
  103. package/dist/packages/ui/src/components/dialog.mjs +14 -1
  104. package/dist/packages/ui/src/components/dropdown-menu.cjs +67 -0
  105. package/dist/packages/ui/src/components/dropdown-menu.mjs +62 -0
  106. package/dist/packages/ui/src/components/markdown-content.cjs +306 -0
  107. package/dist/packages/ui/src/components/markdown-content.mjs +297 -0
  108. package/dist/packages/ui/src/components/scroll-area.cjs +63 -0
  109. package/dist/packages/ui/src/components/scroll-area.mjs +60 -0
  110. package/dist/packages/ui/src/components/select.cjs +1 -1
  111. package/dist/packages/ui/src/components/select.mjs +1 -1
  112. package/dist/packages/ui/src/components/sheet.cjs +87 -0
  113. package/dist/packages/ui/src/components/sheet.mjs +69 -0
  114. package/dist/plugins/ai-chat/api/index.cjs +9 -0
  115. package/dist/plugins/ai-chat/api/index.d.cts +9 -0
  116. package/dist/plugins/ai-chat/api/index.d.mts +9 -0
  117. package/dist/plugins/ai-chat/api/index.d.ts +9 -0
  118. package/dist/plugins/ai-chat/api/index.mjs +2 -0
  119. package/dist/plugins/ai-chat/client/components/index.cjs +27 -0
  120. package/dist/plugins/ai-chat/client/components/index.d.cts +30 -0
  121. package/dist/plugins/ai-chat/client/components/index.d.mts +30 -0
  122. package/dist/plugins/ai-chat/client/components/index.d.ts +30 -0
  123. package/dist/plugins/ai-chat/client/components/index.mjs +11 -0
  124. package/dist/plugins/ai-chat/client/hooks/index.cjs +13 -0
  125. package/dist/plugins/ai-chat/client/hooks/index.d.cts +98 -0
  126. package/dist/plugins/ai-chat/client/hooks/index.d.mts +98 -0
  127. package/dist/plugins/ai-chat/client/hooks/index.d.ts +98 -0
  128. package/dist/plugins/ai-chat/client/hooks/index.mjs +1 -0
  129. package/dist/plugins/ai-chat/client/index.cjs +19 -0
  130. package/dist/plugins/ai-chat/client/index.d.cts +327 -0
  131. package/dist/plugins/ai-chat/client/index.d.mts +327 -0
  132. package/dist/plugins/ai-chat/client/index.d.ts +327 -0
  133. package/dist/plugins/ai-chat/client/index.mjs +7 -0
  134. package/dist/plugins/ai-chat/client.css +6 -0
  135. package/dist/plugins/ai-chat/query-keys.cjs +60 -0
  136. package/dist/plugins/ai-chat/query-keys.d.cts +478 -0
  137. package/dist/plugins/ai-chat/query-keys.d.mts +478 -0
  138. package/dist/plugins/ai-chat/query-keys.d.ts +478 -0
  139. package/dist/plugins/ai-chat/query-keys.mjs +58 -0
  140. package/dist/plugins/ai-chat/style.css +19 -0
  141. package/dist/plugins/blog/api/index.d.cts +1 -1
  142. package/dist/plugins/blog/api/index.d.mts +1 -1
  143. package/dist/plugins/blog/api/index.d.ts +1 -1
  144. package/dist/plugins/blog/client/components/shared/markdown-content-styles.css +85 -62
  145. package/dist/plugins/blog/client/hooks/index.d.cts +2 -2
  146. package/dist/plugins/blog/client/hooks/index.d.mts +2 -2
  147. package/dist/plugins/blog/client/hooks/index.d.ts +2 -2
  148. package/dist/plugins/blog/client/index.d.cts +1 -1
  149. package/dist/plugins/blog/client/index.d.mts +1 -1
  150. package/dist/plugins/blog/client/index.d.ts +1 -1
  151. package/dist/plugins/blog/query-keys.d.cts +2 -2
  152. package/dist/plugins/blog/query-keys.d.mts +2 -2
  153. package/dist/plugins/blog/query-keys.d.ts +2 -2
  154. package/dist/shared/stack.Be1QIHEn.d.cts +23 -0
  155. package/dist/shared/stack.Be1QIHEn.d.mts +23 -0
  156. package/dist/shared/stack.Be1QIHEn.d.ts +23 -0
  157. package/dist/shared/stack.DorMi9CZ.d.cts +80 -0
  158. package/dist/shared/stack.DorMi9CZ.d.mts +80 -0
  159. package/dist/shared/stack.DorMi9CZ.d.ts +80 -0
  160. package/package.json +61 -3
  161. package/src/plugins/ai-chat/api/index.ts +2 -0
  162. package/src/plugins/ai-chat/api/plugin.ts +1083 -0
  163. package/src/plugins/ai-chat/client/components/chat-input.tsx +295 -0
  164. package/src/plugins/ai-chat/client/components/chat-interface.tsx +455 -0
  165. package/src/plugins/ai-chat/client/components/chat-layout.tsx +160 -0
  166. package/src/plugins/ai-chat/client/components/chat-message.tsx +505 -0
  167. package/src/plugins/ai-chat/client/components/chat-sidebar.tsx +296 -0
  168. package/src/plugins/ai-chat/client/components/index.ts +16 -0
  169. package/src/plugins/ai-chat/client/components/loading/chat-page-skeleton.tsx +57 -0
  170. package/src/plugins/ai-chat/client/components/loading/index.tsx +11 -0
  171. package/src/plugins/ai-chat/client/components/pages/404-page.tsx +27 -0
  172. package/src/plugins/ai-chat/client/components/pages/chat-page.internal.tsx +31 -0
  173. package/src/plugins/ai-chat/client/components/pages/chat-page.tsx +46 -0
  174. package/src/plugins/ai-chat/client/components/shared/default-error.tsx +28 -0
  175. package/src/plugins/ai-chat/client/components/shared/error-placeholder.tsx +22 -0
  176. package/src/plugins/ai-chat/client/hooks/chat-hooks.tsx +349 -0
  177. package/src/plugins/ai-chat/client/hooks/index.tsx +1 -0
  178. package/src/plugins/ai-chat/client/index.ts +14 -0
  179. package/src/plugins/ai-chat/client/localization/index.ts +156 -0
  180. package/src/plugins/ai-chat/client/overrides.ts +170 -0
  181. package/src/plugins/ai-chat/client/plugin.tsx +449 -0
  182. package/src/plugins/ai-chat/client.css +6 -0
  183. package/src/plugins/ai-chat/db.ts +65 -0
  184. package/src/plugins/ai-chat/query-keys.ts +87 -0
  185. package/src/plugins/ai-chat/schemas.ts +40 -0
  186. package/src/plugins/ai-chat/style.css +19 -0
  187. package/src/plugins/ai-chat/types.ts +29 -0
  188. package/src/plugins/blog/api/plugin.ts +10 -4
  189. package/src/plugins/blog/client/components/pages/post-page.internal.tsx +1 -1
  190. package/src/plugins/blog/client/components/shared/markdown-content-styles.css +85 -62
  191. package/src/plugins/blog/client/components/shared/markdown-content.tsx +19 -427
  192. package/src/plugins/blog/client/components/shared/on-this-page.tsx +1 -1
  193. package/src/plugins/blog/client/components/shared/page-wrapper.tsx +2 -2
  194. package/src/plugins/blog/client/components/shared/recent-posts-carousel.tsx +2 -2
  195. 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
  196. package/src/plugins/blog/client/components/shared/better-blog-attribution.tsx +0 -19
  197. 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
  198. 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
  199. 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
  200. 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
  201. 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
  202. 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
  203. 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
  204. 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
  205. 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
  206. 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
  207. 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
  208. 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
  209. 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
  210. 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
  211. 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
  212. 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
  213. 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
  214. 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
  215. 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
  216. 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
  217. 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
  218. 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
  219. 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
  220. 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
  221. 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
  222. 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
  223. 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
  224. 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
  225. 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
  226. 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
  227. 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
  228. 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
  229. 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
  230. 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
  231. 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
  232. 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
  233. 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
  234. 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
  235. 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
  236. 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
  237. 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
  238. 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
  239. package/dist/shared/{stack.DLhzx1-D.d.ts → stack.CcI4sYJP.d.cts} +1 -1
  240. package/dist/shared/{stack.DLhzx1-D.d.cts → stack.CcI4sYJP.d.mts} +1 -1
  241. package/dist/shared/{stack.DLhzx1-D.d.mts → stack.CcI4sYJP.d.ts} +1 -1
@@ -0,0 +1,315 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ const jsxRuntime = require('react/jsx-runtime');
5
+ const react = require('@ai-sdk/react');
6
+ const React = require('react');
7
+ const reactQuery = require('@tanstack/react-query');
8
+ const chatMessage = require('./chat-message.cjs');
9
+ const chatInput = require('./chat-input.cjs');
10
+ const betterStackAttribution = require('../../../../../../ui/src/components/better-stack-attribution.cjs');
11
+ const scrollArea = require('../../../../../../ui/src/components/scroll-area.cjs');
12
+ const ai = require('ai');
13
+ const utils = require('../../../../../../ui/src/lib/utils.cjs');
14
+ const context = require('@btst/stack/context');
15
+ const index = require('../localization/index.cjs');
16
+ const client = require('@btst/stack/plugins/client');
17
+ const plugins_aiChat_queryKeys = require('../../../../../../../plugins/ai-chat/query-keys.cjs');
18
+ const chatHooks = require('../hooks/chat-hooks.cjs');
19
+
20
+ function ChatInterface({
21
+ apiPath = "/api/chat",
22
+ initialMessages,
23
+ id,
24
+ variant = "full",
25
+ className
26
+ }) {
27
+ const {
28
+ navigate,
29
+ localization: customLocalization,
30
+ apiBaseURL,
31
+ apiBasePath,
32
+ headers,
33
+ mode,
34
+ showAttribution
35
+ } = context.usePluginOverrides(
36
+ "ai-chat",
37
+ { showAttribution: true }
38
+ );
39
+ const basePath = context.useBasePath();
40
+ const isPublicMode = mode === "public";
41
+ const localization = { ...index.AI_CHAT_LOCALIZATION, ...customLocalization };
42
+ const queryClient = reactQuery.useQueryClient();
43
+ const conversationsListQueryKey = React.useMemo(() => {
44
+ if (isPublicMode) return ["ai-chat", "disabled"];
45
+ const client$1 = client.createApiClient({
46
+ baseURL: apiBaseURL,
47
+ basePath: apiBasePath
48
+ });
49
+ const queries = plugins_aiChat_queryKeys.createAiChatQueryKeys(client$1, headers);
50
+ return queries.conversations.list().queryKey;
51
+ }, [apiBaseURL, apiBasePath, headers, isPublicMode]);
52
+ const [currentConversationId, setCurrentConversationId] = React.useState(isPublicMode ? void 0 : id);
53
+ const isFirstMessageSentRef = React.useRef(false);
54
+ const hasNavigatedRef = React.useRef(false);
55
+ React.useEffect(() => {
56
+ if (!isPublicMode) {
57
+ setCurrentConversationId(id);
58
+ isFirstMessageSentRef.current = false;
59
+ hasNavigatedRef.current = false;
60
+ }
61
+ }, [id, isPublicMode]);
62
+ const { conversation, isLoading: isLoadingConversation } = chatHooks.useConversation(
63
+ id,
64
+ { enabled: !!id && !isPublicMode }
65
+ );
66
+ const { conversations } = chatHooks.useConversations({ enabled: !isPublicMode });
67
+ const conversationIdRef = React.useRef(
68
+ isPublicMode ? void 0 : id
69
+ );
70
+ React.useEffect(() => {
71
+ if (!isPublicMode) {
72
+ conversationIdRef.current = currentConversationId;
73
+ }
74
+ }, [currentConversationId, isPublicMode]);
75
+ const editMessagesRef = React.useRef(null);
76
+ const transport = React.useMemo(
77
+ () => new ai.DefaultChatTransport({
78
+ api: apiPath,
79
+ // In public mode, don't send conversationId
80
+ body: isPublicMode ? void 0 : () => ({ conversationId: conversationIdRef.current }),
81
+ // Handle edit operations by using truncated messages from the ref
82
+ prepareSendMessagesRequest: ({ messages: hookMessages }) => {
83
+ if (editMessagesRef.current !== null) {
84
+ const newUserMessage = hookMessages[hookMessages.length - 1];
85
+ const messagesToSend = [...editMessagesRef.current];
86
+ if (newUserMessage) {
87
+ messagesToSend.push(newUserMessage);
88
+ }
89
+ editMessagesRef.current = null;
90
+ return {
91
+ body: {
92
+ messages: messagesToSend,
93
+ conversationId: conversationIdRef.current
94
+ }
95
+ };
96
+ }
97
+ return {
98
+ body: {
99
+ messages: hookMessages,
100
+ conversationId: conversationIdRef.current
101
+ }
102
+ };
103
+ }
104
+ }),
105
+ [apiPath, isPublicMode]
106
+ );
107
+ const { messages, sendMessage, status, error, setMessages, regenerate } = react.useChat({
108
+ transport,
109
+ onError: (err) => {
110
+ console.error("useChat onError:", err);
111
+ },
112
+ onFinish: async () => {
113
+ if (isPublicMode) return;
114
+ await queryClient.invalidateQueries({
115
+ queryKey: conversationsListQueryKey
116
+ });
117
+ if (isFirstMessageSentRef.current && !id && !hasNavigatedRef.current) {
118
+ hasNavigatedRef.current = true;
119
+ await queryClient.refetchQueries({
120
+ queryKey: conversationsListQueryKey
121
+ });
122
+ const cachedConversations = queryClient.getQueryData(conversationsListQueryKey);
123
+ if (cachedConversations && cachedConversations.length > 0) {
124
+ const newConversation = cachedConversations[0];
125
+ if (newConversation) {
126
+ setCurrentConversationId(newConversation.id);
127
+ conversationIdRef.current = newConversation.id;
128
+ const newUrl = `${basePath}/chat/${newConversation.id}`;
129
+ if (typeof window !== "undefined") {
130
+ window.history.replaceState(
131
+ { ...window.history.state },
132
+ "",
133
+ newUrl
134
+ );
135
+ }
136
+ }
137
+ }
138
+ }
139
+ }
140
+ });
141
+ React.useEffect(() => {
142
+ if (conversation?.messages && conversation.messages.length > 0 && messages.length === 0) {
143
+ const uiMessages = conversation.messages.filter((m) => m.role !== "data").map((m) => {
144
+ let parts;
145
+ try {
146
+ const parsed = JSON.parse(m.content);
147
+ if (Array.isArray(parsed)) {
148
+ parts = parsed;
149
+ } else {
150
+ parts = [{ type: "text", text: m.content }];
151
+ }
152
+ } catch {
153
+ parts = [{ type: "text", text: m.content }];
154
+ }
155
+ return {
156
+ id: m.id,
157
+ role: m.role,
158
+ parts
159
+ };
160
+ });
161
+ setMessages(uiMessages);
162
+ }
163
+ }, [conversation, messages.length, setMessages]);
164
+ React.useEffect(() => {
165
+ if (initialMessages && initialMessages.length > 0 && messages.length === 0) {
166
+ setMessages(initialMessages);
167
+ }
168
+ }, [initialMessages, setMessages, messages.length]);
169
+ const [input, setInput] = React.useState("");
170
+ const [attachedFiles, setAttachedFiles] = React.useState([]);
171
+ const scrollRef = React.useRef(null);
172
+ React.useEffect(() => {
173
+ if (scrollRef.current) {
174
+ const scrollElement = scrollRef.current.querySelector(
175
+ "[data-radix-scroll-area-viewport]"
176
+ );
177
+ if (scrollElement) {
178
+ scrollElement.scrollTop = scrollElement.scrollHeight;
179
+ }
180
+ }
181
+ }, [messages]);
182
+ const handleInputChange = (e) => {
183
+ setInput(e.target.value);
184
+ };
185
+ const handleSubmit = async (e, files) => {
186
+ e.preventDefault();
187
+ const text = input.trim();
188
+ if (!text && (!files || files.length === 0)) return;
189
+ if (!isPublicMode && !id && messages.length === 0) {
190
+ isFirstMessageSentRef.current = true;
191
+ }
192
+ const savedInput = input;
193
+ const savedFiles = files ? [...files] : [];
194
+ setInput("");
195
+ setAttachedFiles([]);
196
+ try {
197
+ if (files && files.length > 0) {
198
+ const fileUIParts = files.map((file) => ({
199
+ type: "file",
200
+ mediaType: file.mediaType,
201
+ url: file.url,
202
+ filename: file.filename
203
+ }));
204
+ await sendMessage({
205
+ text: text || "",
206
+ // AI SDK requires text, even if empty
207
+ files: fileUIParts
208
+ });
209
+ } else {
210
+ await sendMessage({ text });
211
+ }
212
+ } catch (error2) {
213
+ setInput(savedInput);
214
+ setAttachedFiles(savedFiles);
215
+ console.error("Error sending message:", error2);
216
+ }
217
+ };
218
+ const isLoading = status === "streaming" || status === "submitted";
219
+ const handleRetry = React.useCallback(() => {
220
+ regenerate();
221
+ }, [regenerate]);
222
+ const [pendingEdit, setPendingEdit] = React.useState(null);
223
+ React.useEffect(() => {
224
+ if (pendingEdit && messages.length === pendingEdit.expectedLength) {
225
+ const textToSend = pendingEdit.text;
226
+ setPendingEdit(null);
227
+ sendMessage({ text: textToSend });
228
+ }
229
+ }, [messages.length, pendingEdit, sendMessage]);
230
+ const handleEditMessage = React.useCallback(
231
+ (messageId, newText) => {
232
+ const messageIndex = messages.findIndex((m) => m.id === messageId);
233
+ if (messageIndex === -1) return;
234
+ const messageToEdit = messages[messageIndex];
235
+ if (!messageToEdit || messageToEdit.role !== "user") return;
236
+ const truncatedMessages = messages.slice(0, messageIndex);
237
+ editMessagesRef.current = truncatedMessages;
238
+ setPendingEdit({ text: newText, expectedLength: messageIndex });
239
+ setMessages(truncatedMessages);
240
+ },
241
+ [messages, setMessages]
242
+ );
243
+ const isWidget = variant === "widget";
244
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
245
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
246
+ "div",
247
+ {
248
+ className: utils.cn(
249
+ "flex flex-col h-full w-full bg-background",
250
+ isWidget && "rounded-xl",
251
+ className
252
+ ),
253
+ "data-testid": "chat-interface",
254
+ children: /* @__PURE__ */ jsxRuntime.jsx(scrollArea.ScrollArea, { ref: scrollRef, className: "flex-1 h-full", children: /* @__PURE__ */ jsxRuntime.jsxs(
255
+ "div",
256
+ {
257
+ className: utils.cn(
258
+ "flex flex-col p-4",
259
+ isWidget ? "max-w-full" : "max-w-3xl mx-auto w-full"
260
+ ),
261
+ children: [
262
+ messages.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col items-center justify-center h-full min-h-[300px] text-muted-foreground", children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: localization.CHAT_EMPTY_STATE }) }) : messages.map((m, index) => /* @__PURE__ */ jsxRuntime.jsx(
263
+ chatMessage.ChatMessage,
264
+ {
265
+ message: m,
266
+ isStreaming: status === "streaming" && m.id === messages[messages.length - 1]?.id && m.role === "assistant",
267
+ variant: isWidget ? "compact" : "default",
268
+ onRetry: (
269
+ // Only show retry on the last assistant message
270
+ m.role === "assistant" && index === messages.length - 1 ? handleRetry : void 0
271
+ ),
272
+ onEdit: (
273
+ // Allow editing user messages
274
+ m.role === "user" ? (newText) => handleEditMessage(m.id, newText) : void 0
275
+ ),
276
+ isRetrying: isLoading && m.role === "assistant"
277
+ },
278
+ m.id || `msg-${index}`
279
+ )),
280
+ isLoading && messages[messages.length - 1]?.role !== "assistant" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-2 text-muted-foreground text-sm py-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-pulse", children: localization.CHAT_LOADING }) }),
281
+ error && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-2 text-destructive text-sm py-4 px-3 bg-destructive/10 rounded-md", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: localization.CHAT_ERROR }) })
282
+ ]
283
+ }
284
+ ) })
285
+ }
286
+ ) }),
287
+ /* @__PURE__ */ jsxRuntime.jsx(
288
+ "div",
289
+ {
290
+ className: utils.cn(
291
+ "border-t bg-background p-4",
292
+ isWidget ? "px-3 py-3" : "px-4"
293
+ ),
294
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: utils.cn(!isWidget && "max-w-3xl mx-auto"), children: [
295
+ /* @__PURE__ */ jsxRuntime.jsx(
296
+ chatInput.ChatInput,
297
+ {
298
+ input,
299
+ handleInputChange,
300
+ handleSubmit,
301
+ isLoading,
302
+ placeholder: localization.CHAT_PLACEHOLDER,
303
+ variant: isWidget ? "compact" : "default",
304
+ onFilesAttached: setAttachedFiles,
305
+ attachedFiles
306
+ }
307
+ ),
308
+ showAttribution && /* @__PURE__ */ jsxRuntime.jsx(betterStackAttribution.BetterStackAttribution, {})
309
+ ] })
310
+ }
311
+ )
312
+ ] });
313
+ }
314
+
315
+ exports.ChatInterface = ChatInterface;
@@ -0,0 +1,313 @@
1
+ "use client";
2
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
3
+ import { useChat } from '@ai-sdk/react';
4
+ import { useMemo, useState, useRef, useEffect, useCallback } from 'react';
5
+ import { useQueryClient } from '@tanstack/react-query';
6
+ import { ChatMessage } from './chat-message.mjs';
7
+ import { ChatInput } from './chat-input.mjs';
8
+ import { BetterStackAttribution } from '../../../../../../ui/src/components/better-stack-attribution.mjs';
9
+ import { ScrollArea } from '../../../../../../ui/src/components/scroll-area.mjs';
10
+ import { DefaultChatTransport } from 'ai';
11
+ import { cn } from '../../../../../../ui/src/lib/utils.mjs';
12
+ import { usePluginOverrides, useBasePath } from '@btst/stack/context';
13
+ import { AI_CHAT_LOCALIZATION } from '../localization/index.mjs';
14
+ import { createApiClient } from '@btst/stack/plugins/client';
15
+ import { createAiChatQueryKeys } from '../../../../../../../plugins/ai-chat/query-keys.mjs';
16
+ import { useConversation, useConversations } from '../hooks/chat-hooks.mjs';
17
+
18
+ function ChatInterface({
19
+ apiPath = "/api/chat",
20
+ initialMessages,
21
+ id,
22
+ variant = "full",
23
+ className
24
+ }) {
25
+ const {
26
+ navigate,
27
+ localization: customLocalization,
28
+ apiBaseURL,
29
+ apiBasePath,
30
+ headers,
31
+ mode,
32
+ showAttribution
33
+ } = usePluginOverrides(
34
+ "ai-chat",
35
+ { showAttribution: true }
36
+ );
37
+ const basePath = useBasePath();
38
+ const isPublicMode = mode === "public";
39
+ const localization = { ...AI_CHAT_LOCALIZATION, ...customLocalization };
40
+ const queryClient = useQueryClient();
41
+ const conversationsListQueryKey = useMemo(() => {
42
+ if (isPublicMode) return ["ai-chat", "disabled"];
43
+ const client = createApiClient({
44
+ baseURL: apiBaseURL,
45
+ basePath: apiBasePath
46
+ });
47
+ const queries = createAiChatQueryKeys(client, headers);
48
+ return queries.conversations.list().queryKey;
49
+ }, [apiBaseURL, apiBasePath, headers, isPublicMode]);
50
+ const [currentConversationId, setCurrentConversationId] = useState(isPublicMode ? void 0 : id);
51
+ const isFirstMessageSentRef = useRef(false);
52
+ const hasNavigatedRef = useRef(false);
53
+ useEffect(() => {
54
+ if (!isPublicMode) {
55
+ setCurrentConversationId(id);
56
+ isFirstMessageSentRef.current = false;
57
+ hasNavigatedRef.current = false;
58
+ }
59
+ }, [id, isPublicMode]);
60
+ const { conversation, isLoading: isLoadingConversation } = useConversation(
61
+ id,
62
+ { enabled: !!id && !isPublicMode }
63
+ );
64
+ const { conversations } = useConversations({ enabled: !isPublicMode });
65
+ const conversationIdRef = useRef(
66
+ isPublicMode ? void 0 : id
67
+ );
68
+ useEffect(() => {
69
+ if (!isPublicMode) {
70
+ conversationIdRef.current = currentConversationId;
71
+ }
72
+ }, [currentConversationId, isPublicMode]);
73
+ const editMessagesRef = useRef(null);
74
+ const transport = useMemo(
75
+ () => new DefaultChatTransport({
76
+ api: apiPath,
77
+ // In public mode, don't send conversationId
78
+ body: isPublicMode ? void 0 : () => ({ conversationId: conversationIdRef.current }),
79
+ // Handle edit operations by using truncated messages from the ref
80
+ prepareSendMessagesRequest: ({ messages: hookMessages }) => {
81
+ if (editMessagesRef.current !== null) {
82
+ const newUserMessage = hookMessages[hookMessages.length - 1];
83
+ const messagesToSend = [...editMessagesRef.current];
84
+ if (newUserMessage) {
85
+ messagesToSend.push(newUserMessage);
86
+ }
87
+ editMessagesRef.current = null;
88
+ return {
89
+ body: {
90
+ messages: messagesToSend,
91
+ conversationId: conversationIdRef.current
92
+ }
93
+ };
94
+ }
95
+ return {
96
+ body: {
97
+ messages: hookMessages,
98
+ conversationId: conversationIdRef.current
99
+ }
100
+ };
101
+ }
102
+ }),
103
+ [apiPath, isPublicMode]
104
+ );
105
+ const { messages, sendMessage, status, error, setMessages, regenerate } = useChat({
106
+ transport,
107
+ onError: (err) => {
108
+ console.error("useChat onError:", err);
109
+ },
110
+ onFinish: async () => {
111
+ if (isPublicMode) return;
112
+ await queryClient.invalidateQueries({
113
+ queryKey: conversationsListQueryKey
114
+ });
115
+ if (isFirstMessageSentRef.current && !id && !hasNavigatedRef.current) {
116
+ hasNavigatedRef.current = true;
117
+ await queryClient.refetchQueries({
118
+ queryKey: conversationsListQueryKey
119
+ });
120
+ const cachedConversations = queryClient.getQueryData(conversationsListQueryKey);
121
+ if (cachedConversations && cachedConversations.length > 0) {
122
+ const newConversation = cachedConversations[0];
123
+ if (newConversation) {
124
+ setCurrentConversationId(newConversation.id);
125
+ conversationIdRef.current = newConversation.id;
126
+ const newUrl = `${basePath}/chat/${newConversation.id}`;
127
+ if (typeof window !== "undefined") {
128
+ window.history.replaceState(
129
+ { ...window.history.state },
130
+ "",
131
+ newUrl
132
+ );
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+ });
139
+ useEffect(() => {
140
+ if (conversation?.messages && conversation.messages.length > 0 && messages.length === 0) {
141
+ const uiMessages = conversation.messages.filter((m) => m.role !== "data").map((m) => {
142
+ let parts;
143
+ try {
144
+ const parsed = JSON.parse(m.content);
145
+ if (Array.isArray(parsed)) {
146
+ parts = parsed;
147
+ } else {
148
+ parts = [{ type: "text", text: m.content }];
149
+ }
150
+ } catch {
151
+ parts = [{ type: "text", text: m.content }];
152
+ }
153
+ return {
154
+ id: m.id,
155
+ role: m.role,
156
+ parts
157
+ };
158
+ });
159
+ setMessages(uiMessages);
160
+ }
161
+ }, [conversation, messages.length, setMessages]);
162
+ useEffect(() => {
163
+ if (initialMessages && initialMessages.length > 0 && messages.length === 0) {
164
+ setMessages(initialMessages);
165
+ }
166
+ }, [initialMessages, setMessages, messages.length]);
167
+ const [input, setInput] = useState("");
168
+ const [attachedFiles, setAttachedFiles] = useState([]);
169
+ const scrollRef = useRef(null);
170
+ useEffect(() => {
171
+ if (scrollRef.current) {
172
+ const scrollElement = scrollRef.current.querySelector(
173
+ "[data-radix-scroll-area-viewport]"
174
+ );
175
+ if (scrollElement) {
176
+ scrollElement.scrollTop = scrollElement.scrollHeight;
177
+ }
178
+ }
179
+ }, [messages]);
180
+ const handleInputChange = (e) => {
181
+ setInput(e.target.value);
182
+ };
183
+ const handleSubmit = async (e, files) => {
184
+ e.preventDefault();
185
+ const text = input.trim();
186
+ if (!text && (!files || files.length === 0)) return;
187
+ if (!isPublicMode && !id && messages.length === 0) {
188
+ isFirstMessageSentRef.current = true;
189
+ }
190
+ const savedInput = input;
191
+ const savedFiles = files ? [...files] : [];
192
+ setInput("");
193
+ setAttachedFiles([]);
194
+ try {
195
+ if (files && files.length > 0) {
196
+ const fileUIParts = files.map((file) => ({
197
+ type: "file",
198
+ mediaType: file.mediaType,
199
+ url: file.url,
200
+ filename: file.filename
201
+ }));
202
+ await sendMessage({
203
+ text: text || "",
204
+ // AI SDK requires text, even if empty
205
+ files: fileUIParts
206
+ });
207
+ } else {
208
+ await sendMessage({ text });
209
+ }
210
+ } catch (error2) {
211
+ setInput(savedInput);
212
+ setAttachedFiles(savedFiles);
213
+ console.error("Error sending message:", error2);
214
+ }
215
+ };
216
+ const isLoading = status === "streaming" || status === "submitted";
217
+ const handleRetry = useCallback(() => {
218
+ regenerate();
219
+ }, [regenerate]);
220
+ const [pendingEdit, setPendingEdit] = useState(null);
221
+ useEffect(() => {
222
+ if (pendingEdit && messages.length === pendingEdit.expectedLength) {
223
+ const textToSend = pendingEdit.text;
224
+ setPendingEdit(null);
225
+ sendMessage({ text: textToSend });
226
+ }
227
+ }, [messages.length, pendingEdit, sendMessage]);
228
+ const handleEditMessage = useCallback(
229
+ (messageId, newText) => {
230
+ const messageIndex = messages.findIndex((m) => m.id === messageId);
231
+ if (messageIndex === -1) return;
232
+ const messageToEdit = messages[messageIndex];
233
+ if (!messageToEdit || messageToEdit.role !== "user") return;
234
+ const truncatedMessages = messages.slice(0, messageIndex);
235
+ editMessagesRef.current = truncatedMessages;
236
+ setPendingEdit({ text: newText, expectedLength: messageIndex });
237
+ setMessages(truncatedMessages);
238
+ },
239
+ [messages, setMessages]
240
+ );
241
+ const isWidget = variant === "widget";
242
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
243
+ /* @__PURE__ */ jsx("div", { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
244
+ "div",
245
+ {
246
+ className: cn(
247
+ "flex flex-col h-full w-full bg-background",
248
+ isWidget && "rounded-xl",
249
+ className
250
+ ),
251
+ "data-testid": "chat-interface",
252
+ children: /* @__PURE__ */ jsx(ScrollArea, { ref: scrollRef, className: "flex-1 h-full", children: /* @__PURE__ */ jsxs(
253
+ "div",
254
+ {
255
+ className: cn(
256
+ "flex flex-col p-4",
257
+ isWidget ? "max-w-full" : "max-w-3xl mx-auto w-full"
258
+ ),
259
+ children: [
260
+ messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center justify-center h-full min-h-[300px] text-muted-foreground", children: /* @__PURE__ */ jsx("p", { children: localization.CHAT_EMPTY_STATE }) }) : messages.map((m, index) => /* @__PURE__ */ jsx(
261
+ ChatMessage,
262
+ {
263
+ message: m,
264
+ isStreaming: status === "streaming" && m.id === messages[messages.length - 1]?.id && m.role === "assistant",
265
+ variant: isWidget ? "compact" : "default",
266
+ onRetry: (
267
+ // Only show retry on the last assistant message
268
+ m.role === "assistant" && index === messages.length - 1 ? handleRetry : void 0
269
+ ),
270
+ onEdit: (
271
+ // Allow editing user messages
272
+ m.role === "user" ? (newText) => handleEditMessage(m.id, newText) : void 0
273
+ ),
274
+ isRetrying: isLoading && m.role === "assistant"
275
+ },
276
+ m.id || `msg-${index}`
277
+ )),
278
+ isLoading && messages[messages.length - 1]?.role !== "assistant" && /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2 text-muted-foreground text-sm py-4", children: /* @__PURE__ */ jsx("div", { className: "animate-pulse", children: localization.CHAT_LOADING }) }),
279
+ error && /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2 text-destructive text-sm py-4 px-3 bg-destructive/10 rounded-md", children: /* @__PURE__ */ jsx("span", { children: localization.CHAT_ERROR }) })
280
+ ]
281
+ }
282
+ ) })
283
+ }
284
+ ) }),
285
+ /* @__PURE__ */ jsx(
286
+ "div",
287
+ {
288
+ className: cn(
289
+ "border-t bg-background p-4",
290
+ isWidget ? "px-3 py-3" : "px-4"
291
+ ),
292
+ children: /* @__PURE__ */ jsxs("div", { className: cn(!isWidget && "max-w-3xl mx-auto"), children: [
293
+ /* @__PURE__ */ jsx(
294
+ ChatInput,
295
+ {
296
+ input,
297
+ handleInputChange,
298
+ handleSubmit,
299
+ isLoading,
300
+ placeholder: localization.CHAT_PLACEHOLDER,
301
+ variant: isWidget ? "compact" : "default",
302
+ onFilesAttached: setAttachedFiles,
303
+ attachedFiles
304
+ }
305
+ ),
306
+ showAttribution && /* @__PURE__ */ jsx(BetterStackAttribution, {})
307
+ ] })
308
+ }
309
+ )
310
+ ] });
311
+ }
312
+
313
+ export { ChatInterface };