@databiosphere/findable-ui 49.0.0 → 49.2.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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +26 -0
- package/lib/common/ai/config/types.d.ts +22 -0
- package/lib/common/ai/config/types.js +1 -0
- package/lib/common/ai/constants.d.ts +3 -0
- package/lib/common/ai/constants.js +3 -0
- package/lib/components/Filter/components/FilterLabel/filterLabel.js +1 -1
- package/lib/components/Filter/components/FilterLabel/filterLabel.stories.d.ts +3 -0
- package/lib/components/Filter/components/FilterLabel/filterLabel.stories.js +5 -0
- package/lib/components/Filter/components/Filters/stories/constants.js +21 -1
- package/lib/components/Filter/components/SearchAllFilters/searchAllFilters.styles.js +2 -0
- package/lib/components/Layout/components/Sidebar/components/SidebarTools/sidebarTools.styles.d.ts +4 -0
- package/lib/components/Layout/components/Sidebar/components/SidebarTools/sidebarTools.styles.js +4 -0
- package/lib/components/common/Chip/components/Beta/beta.d.ts +10 -0
- package/lib/components/common/Chip/components/Beta/beta.js +12 -0
- package/lib/components/common/Chip/components/Beta/beta.styles.d.ts +3 -0
- package/lib/components/common/Chip/components/Beta/beta.styles.js +14 -0
- package/lib/components/common/Chip/components/Beta/stories/beta.stories.d.ts +6 -0
- package/lib/components/common/Chip/components/Beta/stories/beta.stories.js +6 -0
- package/lib/components/common/CustomIcon/components/UpArrowIcon/upArrowIcon.d.ts +6 -0
- package/lib/components/common/CustomIcon/components/UpArrowIcon/upArrowIcon.js +8 -0
- package/lib/components/common/Tabs/tabs.js +1 -1
- package/lib/components/common/ToggleButtonGroup/provider/context.d.ts +2 -0
- package/lib/components/common/ToggleButtonGroup/provider/context.js +5 -0
- package/lib/components/common/ToggleButtonGroup/provider/hook.d.ts +7 -0
- package/lib/components/common/ToggleButtonGroup/provider/hook.js +9 -0
- package/lib/components/common/ToggleButtonGroup/provider/provider.d.ts +12 -0
- package/lib/components/common/ToggleButtonGroup/provider/provider.js +22 -0
- package/lib/components/common/ToggleButtonGroup/provider/types.d.ts +9 -0
- package/lib/components/common/ToggleButtonGroup/provider/types.js +1 -0
- package/lib/config/entities.d.ts +2 -0
- package/lib/hooks/ai/useAiRoutes/hook.d.ts +6 -0
- package/lib/hooks/ai/useAiRoutes/hook.js +18 -0
- package/lib/styles/common/mui/drawer.d.ts +9 -0
- package/lib/styles/common/mui/drawer.js +15 -0
- package/lib/styles/common/mui/inputBase.d.ts +13 -0
- package/lib/styles/common/mui/inputBase.js +25 -0
- package/lib/styles/common/mui/stack.d.ts +11 -0
- package/lib/styles/common/mui/stack.js +22 -0
- package/lib/tests/testIds.d.ts +3 -0
- package/lib/tests/testIds.js +3 -0
- package/lib/views/ExploreView/entityList/filters/components/ToggleButtonGroup/toggleButtonGroup.d.ts +6 -0
- package/lib/views/ExploreView/entityList/filters/components/ToggleButtonGroup/toggleButtonGroup.js +17 -0
- package/lib/views/ExploreView/entityList/filters/components/ToggleButtonGroup/toggleButtonGroup.styles.d.ts +6 -0
- package/lib/views/ExploreView/entityList/filters/components/ToggleButtonGroup/toggleButtonGroup.styles.js +23 -0
- package/lib/views/ExploreView/entityList/filters/filters.styles.d.ts +7 -0
- package/lib/views/ExploreView/entityList/filters/filters.styles.js +17 -0
- package/lib/views/ExploreView/exploreView.js +3 -2
- package/lib/views/ResearchView/assistant/assistant.d.ts +6 -0
- package/lib/views/ResearchView/assistant/assistant.js +16 -0
- package/lib/views/ResearchView/assistant/components/Drawer/drawer.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Drawer/drawer.js +15 -0
- package/lib/views/ResearchView/assistant/components/Drawer/drawer.styles.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Drawer/drawer.styles.js +21 -0
- package/lib/views/ResearchView/assistant/components/Drawer/types.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Drawer/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Form/constants.d.ts +3 -0
- package/lib/views/ResearchView/assistant/components/Form/constants.js +3 -0
- package/lib/views/ResearchView/assistant/components/Form/form.d.ts +11 -0
- package/lib/views/ResearchView/assistant/components/Form/form.js +27 -0
- package/lib/views/ResearchView/assistant/components/Form/form.styles.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Form/form.styles.js +7 -0
- package/lib/views/ResearchView/assistant/components/Form/types.d.ts +3 -0
- package/lib/views/ResearchView/assistant/components/Form/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Form/utils.d.ts +16 -0
- package/lib/views/ResearchView/assistant/components/Form/utils.js +41 -0
- package/lib/views/ResearchView/assistant/components/Input/constants.d.ts +2 -0
- package/lib/views/ResearchView/assistant/components/Input/constants.js +14 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/constants.d.ts +7 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/constants.js +7 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/hook.d.ts +6 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/hook.js +32 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/types.d.ts +8 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/utils.d.ts +32 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/utils.js +74 -0
- package/lib/views/ResearchView/assistant/components/Input/input.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Input/input.js +19 -0
- package/lib/views/ResearchView/assistant/components/Input/input.styles.d.ts +8 -0
- package/lib/views/ResearchView/assistant/components/Input/input.styles.js +19 -0
- package/lib/views/ResearchView/assistant/components/Input/stories/input.stories.d.ts +6 -0
- package/lib/views/ResearchView/assistant/components/Input/stories/input.stories.js +11 -0
- package/lib/views/ResearchView/assistant/components/Input/types.d.ts +2 -0
- package/lib/views/ResearchView/assistant/components/Input/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Input/utils.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Input/utils.js +25 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/AssistantMessage/assistantMessage.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/AssistantMessage/assistantMessage.js +15 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/AssistantMessage/types.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/AssistantMessage/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/AssistantMessage/utils.d.ts +13 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/AssistantMessage/utils.js +25 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/ErrorMessage/errorMessage.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/ErrorMessage/errorMessage.js +12 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/ErrorMessage/types.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/ErrorMessage/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/chips.d.ts +3 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/chips.js +10 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/chips.styles.d.ts +3 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/chips.styles.js +26 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/types.d.ts +5 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/promptMessage.d.ts +10 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/promptMessage.js +14 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/types.d.ts +5 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/UserMessage/types.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/UserMessage/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/UserMessage/useMessage.styles.d.ts +5 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/UserMessage/useMessage.styles.js +10 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/UserMessage/userMessage.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/UserMessage/userMessage.js +13 -0
- package/lib/views/ResearchView/assistant/components/Messages/hooks/UseScroll/hook.d.ts +8 -0
- package/lib/views/ResearchView/assistant/components/Messages/hooks/UseScroll/hook.js +20 -0
- package/lib/views/ResearchView/assistant/components/Messages/messages.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Messages/messages.js +16 -0
- package/lib/views/ResearchView/assistant/components/Messages/messages.styles.d.ts +3 -0
- package/lib/views/ResearchView/assistant/components/Messages/messages.styles.js +9 -0
- package/lib/views/ResearchView/assistant/components/Messages/selector/messageSelector.d.ts +17 -0
- package/lib/views/ResearchView/assistant/components/Messages/selector/messageSelector.js +32 -0
- package/lib/views/ResearchView/assistant/components/Messages/selector/types.d.ts +5 -0
- package/lib/views/ResearchView/assistant/components/Messages/selector/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Messages/stories/args.d.ts +3 -0
- package/lib/views/ResearchView/assistant/components/Messages/stories/args.js +109 -0
- package/lib/views/ResearchView/assistant/components/Messages/stories/messages.stories.d.ts +6 -0
- package/lib/views/ResearchView/assistant/components/Messages/stories/messages.stories.js +14 -0
- package/lib/views/ResearchView/assistant/components/Messages/types.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Messages/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/ToggleButtonGroup/stories/toggleButtonGroup.stories.d.ts +6 -0
- package/lib/views/ResearchView/assistant/components/ToggleButtonGroup/stories/toggleButtonGroup.stories.js +12 -0
- package/lib/views/ResearchView/assistant/components/ToggleButtonGroup/toggleButtonGroup.d.ts +6 -0
- package/lib/views/ResearchView/assistant/components/ToggleButtonGroup/toggleButtonGroup.js +16 -0
- package/lib/views/ResearchView/assistant/components/ToggleButtonGroup/toggleButtonGroup.styles.d.ts +6 -0
- package/lib/views/ResearchView/assistant/components/ToggleButtonGroup/toggleButtonGroup.styles.js +20 -0
- package/lib/views/ResearchView/assistant/stories/args.d.ts +4 -0
- package/lib/views/ResearchView/assistant/stories/args.js +30 -0
- package/lib/views/ResearchView/assistant/stories/assistant.stories.d.ts +6 -0
- package/lib/views/ResearchView/assistant/stories/assistant.stories.js +23 -0
- package/lib/views/ResearchView/query/constants.d.ts +5 -0
- package/lib/views/ResearchView/query/constants.js +5 -0
- package/lib/views/ResearchView/query/fetch.d.ts +17 -0
- package/lib/views/ResearchView/query/fetch.js +44 -0
- package/lib/views/ResearchView/researchView.d.ts +10 -0
- package/lib/views/ResearchView/researchView.js +13 -0
- package/lib/views/ResearchView/state/actions/setError/action.d.ts +10 -0
- package/lib/views/ResearchView/state/actions/setError/action.js +17 -0
- package/lib/views/ResearchView/state/actions/setError/dispatch.d.ts +7 -0
- package/lib/views/ResearchView/state/actions/setError/dispatch.js +12 -0
- package/lib/views/ResearchView/state/actions/setError/types.d.ts +14 -0
- package/lib/views/ResearchView/state/actions/setError/types.js +1 -0
- package/lib/views/ResearchView/state/actions/setMessage/action.d.ts +10 -0
- package/lib/views/ResearchView/state/actions/setMessage/action.js +21 -0
- package/lib/views/ResearchView/state/actions/setMessage/dispatch.d.ts +7 -0
- package/lib/views/ResearchView/state/actions/setMessage/dispatch.js +12 -0
- package/lib/views/ResearchView/state/actions/setMessage/types.d.ts +15 -0
- package/lib/views/ResearchView/state/actions/setMessage/types.js +1 -0
- package/lib/views/ResearchView/state/actions/setQuery/action.d.ts +10 -0
- package/lib/views/ResearchView/state/actions/setQuery/action.js +17 -0
- package/lib/views/ResearchView/state/actions/setQuery/dispatch.d.ts +7 -0
- package/lib/views/ResearchView/state/actions/setQuery/dispatch.js +12 -0
- package/lib/views/ResearchView/state/actions/setQuery/types.d.ts +14 -0
- package/lib/views/ResearchView/state/actions/setQuery/types.js +1 -0
- package/lib/views/ResearchView/state/actions/setStatus/action.d.ts +10 -0
- package/lib/views/ResearchView/state/actions/setStatus/action.js +13 -0
- package/lib/views/ResearchView/state/actions/setStatus/dispatch.d.ts +7 -0
- package/lib/views/ResearchView/state/actions/setStatus/dispatch.js +12 -0
- package/lib/views/ResearchView/state/actions/setStatus/types.d.ts +14 -0
- package/lib/views/ResearchView/state/actions/setStatus/types.js +1 -0
- package/lib/views/ResearchView/state/actions/types.d.ts +17 -0
- package/lib/views/ResearchView/state/actions/types.js +10 -0
- package/lib/views/ResearchView/state/constants.d.ts +5 -0
- package/lib/views/ResearchView/state/constants.js +7 -0
- package/lib/views/ResearchView/state/context.d.ts +5 -0
- package/lib/views/ResearchView/state/context.js +9 -0
- package/lib/views/ResearchView/state/guards/guards.d.ts +33 -0
- package/lib/views/ResearchView/state/guards/guards.js +41 -0
- package/lib/views/ResearchView/state/hooks/UseChatDispatch/hook.d.ts +6 -0
- package/lib/views/ResearchView/state/hooks/UseChatDispatch/hook.js +26 -0
- package/lib/views/ResearchView/state/hooks/UseChatDispatch/types.d.ts +10 -0
- package/lib/views/ResearchView/state/hooks/UseChatDispatch/types.js +1 -0
- package/lib/views/ResearchView/state/hooks/UseChatReducer/hook.d.ts +8 -0
- package/lib/views/ResearchView/state/hooks/UseChatReducer/hook.js +12 -0
- package/lib/views/ResearchView/state/hooks/UseChatState/hook.d.ts +7 -0
- package/lib/views/ResearchView/state/hooks/UseChatState/hook.js +11 -0
- package/lib/views/ResearchView/state/initializer/initializer.d.ts +8 -0
- package/lib/views/ResearchView/state/initializer/initializer.js +22 -0
- package/lib/views/ResearchView/state/initializer/types.d.ts +2 -0
- package/lib/views/ResearchView/state/initializer/types.js +1 -0
- package/lib/views/ResearchView/state/provider.d.ts +19 -0
- package/lib/views/ResearchView/state/provider.js +20 -0
- package/lib/views/ResearchView/state/query/context.d.ts +5 -0
- package/lib/views/ResearchView/state/query/context.js +7 -0
- package/lib/views/ResearchView/state/query/hooks/UseQuery/hook.d.ts +6 -0
- package/lib/views/ResearchView/state/query/hooks/UseQuery/hook.js +9 -0
- package/lib/views/ResearchView/state/query/hooks/UseSubmit/hook.d.ts +7 -0
- package/lib/views/ResearchView/state/query/hooks/UseSubmit/hook.js +46 -0
- package/lib/views/ResearchView/state/query/provider.d.ts +13 -0
- package/lib/views/ResearchView/state/query/provider.js +15 -0
- package/lib/views/ResearchView/state/query/types.d.ts +24 -0
- package/lib/views/ResearchView/state/query/types.js +1 -0
- package/lib/views/ResearchView/state/reducer.d.ts +10 -0
- package/lib/views/ResearchView/state/reducer.js +32 -0
- package/lib/views/ResearchView/state/types.d.ts +125 -0
- package/lib/views/ResearchView/state/types.js +22 -0
- package/package.json +1 -1
- package/src/common/ai/config/types.ts +25 -0
- package/src/common/ai/constants.ts +3 -0
- package/src/components/Filter/components/FilterLabel/filterLabel.stories.tsx +6 -0
- package/src/components/Filter/components/FilterLabel/filterLabel.tsx +6 -1
- package/src/components/Filter/components/Filters/stories/constants.ts +25 -1
- package/src/components/Filter/components/SearchAllFilters/searchAllFilters.styles.ts +2 -0
- package/src/components/Layout/components/Sidebar/components/SidebarTools/sidebarTools.styles.ts +4 -0
- package/src/components/common/Chip/components/Beta/beta.styles.ts +15 -0
- package/src/components/common/Chip/components/Beta/beta.tsx +25 -0
- package/src/components/common/Chip/components/Beta/stories/beta.stories.tsx +12 -0
- package/src/components/common/CustomIcon/components/UpArrowIcon/upArrowIcon.tsx +21 -0
- package/src/components/common/Tabs/tabs.tsx +5 -1
- package/src/components/common/ToggleButtonGroup/provider/context.ts +9 -0
- package/src/components/common/ToggleButtonGroup/provider/hook.ts +16 -0
- package/src/components/common/ToggleButtonGroup/provider/provider.tsx +37 -0
- package/src/components/common/ToggleButtonGroup/provider/types.ts +17 -0
- package/src/config/entities.ts +2 -0
- package/src/hooks/ai/useAiRoutes/hook.ts +22 -0
- package/src/styles/common/mui/drawer.ts +24 -0
- package/src/styles/common/mui/inputBase.ts +38 -0
- package/src/styles/common/mui/stack.ts +33 -0
- package/src/tests/testIds.ts +3 -0
- package/src/views/ExploreView/entityList/filters/components/ToggleButtonGroup/toggleButtonGroup.styles.ts +25 -0
- package/src/views/ExploreView/entityList/filters/components/ToggleButtonGroup/toggleButtonGroup.tsx +35 -0
- package/src/views/ExploreView/entityList/filters/filters.styles.ts +19 -0
- package/src/views/ExploreView/exploreView.tsx +16 -12
- package/src/views/ResearchView/assistant/assistant.tsx +28 -0
- package/src/views/ResearchView/assistant/components/Drawer/drawer.styles.ts +24 -0
- package/src/views/ResearchView/assistant/components/Drawer/drawer.tsx +26 -0
- package/src/views/ResearchView/assistant/components/Drawer/types.ts +5 -0
- package/src/views/ResearchView/assistant/components/Form/constants.ts +3 -0
- package/src/views/ResearchView/assistant/components/Form/form.styles.ts +8 -0
- package/src/views/ResearchView/assistant/components/Form/form.tsx +40 -0
- package/src/views/ResearchView/assistant/components/Form/types.ts +9 -0
- package/src/views/ResearchView/assistant/components/Form/utils.ts +51 -0
- package/src/views/ResearchView/assistant/components/Input/constants.ts +16 -0
- package/src/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/constants.ts +7 -0
- package/src/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/hook.ts +45 -0
- package/src/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/types.ts +10 -0
- package/src/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/utils.ts +93 -0
- package/src/views/ResearchView/assistant/components/Input/input.styles.ts +21 -0
- package/src/views/ResearchView/assistant/components/Input/input.tsx +37 -0
- package/src/views/ResearchView/assistant/components/Input/stories/input.stories.tsx +21 -0
- package/src/views/ResearchView/assistant/components/Input/types.ts +3 -0
- package/src/views/ResearchView/assistant/components/Input/utils.ts +34 -0
- package/src/views/ResearchView/assistant/components/Messages/components/AssistantMessage/assistantMessage.tsx +49 -0
- package/src/views/ResearchView/assistant/components/Messages/components/AssistantMessage/types.ts +5 -0
- package/src/views/ResearchView/assistant/components/Messages/components/AssistantMessage/utils.ts +31 -0
- package/src/views/ResearchView/assistant/components/Messages/components/ErrorMessage/errorMessage.tsx +21 -0
- package/src/views/ResearchView/assistant/components/Messages/components/ErrorMessage/types.ts +5 -0
- package/src/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/chips.styles.ts +27 -0
- package/src/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/chips.tsx +31 -0
- package/src/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/types.ts +6 -0
- package/src/views/ResearchView/assistant/components/Messages/components/PromptMessage/promptMessage.tsx +26 -0
- package/src/views/ResearchView/assistant/components/Messages/components/PromptMessage/types.ts +6 -0
- package/src/views/ResearchView/assistant/components/Messages/components/UserMessage/types.ts +5 -0
- package/src/views/ResearchView/assistant/components/Messages/components/UserMessage/useMessage.styles.ts +11 -0
- package/src/views/ResearchView/assistant/components/Messages/components/UserMessage/userMessage.tsx +21 -0
- package/src/views/ResearchView/assistant/components/Messages/hooks/UseScroll/hook.ts +25 -0
- package/src/views/ResearchView/assistant/components/Messages/messages.styles.ts +10 -0
- package/src/views/ResearchView/assistant/components/Messages/messages.tsx +29 -0
- package/src/views/ResearchView/assistant/components/Messages/selector/messageSelector.tsx +37 -0
- package/src/views/ResearchView/assistant/components/Messages/selector/types.ts +6 -0
- package/src/views/ResearchView/assistant/components/Messages/stories/args.ts +115 -0
- package/src/views/ResearchView/assistant/components/Messages/stories/messages.stories.tsx +24 -0
- package/src/views/ResearchView/assistant/components/Messages/types.ts +5 -0
- package/src/views/ResearchView/assistant/components/ToggleButtonGroup/stories/toggleButtonGroup.stories.tsx +22 -0
- package/src/views/ResearchView/assistant/components/ToggleButtonGroup/toggleButtonGroup.styles.ts +22 -0
- package/src/views/ResearchView/assistant/components/ToggleButtonGroup/toggleButtonGroup.tsx +34 -0
- package/src/views/ResearchView/assistant/stories/args.ts +36 -0
- package/src/views/ResearchView/assistant/stories/assistant.stories.tsx +39 -0
- package/src/views/ResearchView/query/constants.ts +5 -0
- package/src/views/ResearchView/query/fetch.ts +58 -0
- package/src/views/ResearchView/researchView.tsx +19 -0
- package/src/views/ResearchView/state/actions/setError/action.ts +22 -0
- package/src/views/ResearchView/state/actions/setError/dispatch.ts +14 -0
- package/src/views/ResearchView/state/actions/setError/types.ts +16 -0
- package/src/views/ResearchView/state/actions/setMessage/action.ts +26 -0
- package/src/views/ResearchView/state/actions/setMessage/dispatch.ts +14 -0
- package/src/views/ResearchView/state/actions/setMessage/types.ts +19 -0
- package/src/views/ResearchView/state/actions/setQuery/action.ts +22 -0
- package/src/views/ResearchView/state/actions/setQuery/dispatch.ts +14 -0
- package/src/views/ResearchView/state/actions/setQuery/types.ts +16 -0
- package/src/views/ResearchView/state/actions/setStatus/action.ts +19 -0
- package/src/views/ResearchView/state/actions/setStatus/dispatch.ts +14 -0
- package/src/views/ResearchView/state/actions/setStatus/types.ts +16 -0
- package/src/views/ResearchView/state/actions/types.ts +23 -0
- package/src/views/ResearchView/state/constants.ts +9 -0
- package/src/views/ResearchView/state/context.ts +11 -0
- package/src/views/ResearchView/state/guards/guards.ts +58 -0
- package/src/views/ResearchView/state/hooks/UseChatDispatch/hook.ts +46 -0
- package/src/views/ResearchView/state/hooks/UseChatDispatch/types.ts +11 -0
- package/src/views/ResearchView/state/hooks/UseChatReducer/hook.ts +15 -0
- package/src/views/ResearchView/state/hooks/UseChatState/hook.ts +14 -0
- package/src/views/ResearchView/state/initializer/initializer.ts +23 -0
- package/src/views/ResearchView/state/initializer/types.ts +3 -0
- package/src/views/ResearchView/state/provider.tsx +34 -0
- package/src/views/ResearchView/state/query/context.ts +9 -0
- package/src/views/ResearchView/state/query/hooks/UseQuery/hook.ts +11 -0
- package/src/views/ResearchView/state/query/hooks/UseSubmit/hook.ts +66 -0
- package/src/views/ResearchView/state/query/provider.tsx +27 -0
- package/src/views/ResearchView/state/query/types.ts +31 -0
- package/src/views/ResearchView/state/reducer.ts +34 -0
- package/src/views/ResearchView/state/types.ts +149 -0
- package/tests/research.assistantMessageUtils.test.ts +149 -0
- package/tests/research.chatState.test.ts +463 -0
- package/tests/research.fetchResponse.test.ts +164 -0
- package/tests/research.queryProvider.test.ts +321 -0
- package/tests/research.useKeyShortCuts.test.ts +254 -0
- package/tests/toggleButtonGroupProvider.test.tsx +125 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { ComponentProps } from "react";
|
|
2
|
+
import { Messages } from "../messages";
|
|
3
|
+
import { AssistantMessage, MESSAGE_TYPE } from "../../../../state/types";
|
|
4
|
+
import { ERROR_MESSAGE } from "../../../../query/constants";
|
|
5
|
+
|
|
6
|
+
export const ARGS: ComponentProps<typeof Messages> = {
|
|
7
|
+
state: {
|
|
8
|
+
messages: [
|
|
9
|
+
{
|
|
10
|
+
createdAt: 1771998382830,
|
|
11
|
+
inputPlaceholder: "Ask about datasets or variables",
|
|
12
|
+
suggestions: [
|
|
13
|
+
{
|
|
14
|
+
label: "GLP-1 effect + smoking in T2D",
|
|
15
|
+
query:
|
|
16
|
+
"I'm studying whether smoking modifies the effect of GLP-1 agonists on glycemic control in T2D patients",
|
|
17
|
+
variant: "CHIP",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
label: "WGS for cardiovascular outcomes",
|
|
21
|
+
query:
|
|
22
|
+
"I'm interested in whole genome sequencing data for cardiovascular outcomes",
|
|
23
|
+
variant: "CHIP",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
label: "RNA-Seq in pancreatic cancer",
|
|
27
|
+
query: "I'm interested in RNA-Seq data for pancreatic cancer",
|
|
28
|
+
variant: "CHIP",
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
text: "Hello! I can help you find datasets across 2,944 studies from AnVIL, BDC, CRDC, and KFDRC. Describe your research question and I'll build a structured plan and find matching data.",
|
|
32
|
+
type: MESSAGE_TYPE.PROMPT,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
createdAt: 1771998382831,
|
|
36
|
+
text: "I'm studying whether smoking modifies the effect of GLP-1 agonists on glycemic control in T2D patients.",
|
|
37
|
+
type: MESSAGE_TYPE.USER,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
createdAt: 1771998382832,
|
|
41
|
+
response: {
|
|
42
|
+
message:
|
|
43
|
+
'The exact term "glycemic control" has very low study counts (1 study each). I\'ve mapped it to the most relevant clinical measurements: "Glycated Hemoglobin" (HbA1c, 9 studies) and "Fasting Glucose" (44 studies), which are the standard markers used to assess glycemic control in diabetes management.',
|
|
44
|
+
query: {
|
|
45
|
+
mentions: [
|
|
46
|
+
{
|
|
47
|
+
exclude: false,
|
|
48
|
+
facet: "focus",
|
|
49
|
+
originalText: "type 2 diabetes",
|
|
50
|
+
values: ["Diabetes Mellitus, Type 2"],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
exclude: false,
|
|
54
|
+
facet: "measurement",
|
|
55
|
+
originalText: "smoking",
|
|
56
|
+
values: [
|
|
57
|
+
"Current Smoking Status",
|
|
58
|
+
"Smoking History",
|
|
59
|
+
"Smoking Status",
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
exclude: false,
|
|
64
|
+
facet: "measurement",
|
|
65
|
+
originalText: "glycemic control",
|
|
66
|
+
values: ["Glycated Hemoglobin", "Fasting Glucose"],
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
type: MESSAGE_TYPE.ASSISTANT,
|
|
72
|
+
} as AssistantMessage,
|
|
73
|
+
{
|
|
74
|
+
createdAt: 1771998382833,
|
|
75
|
+
text: "What about datasets related to GLP-1 agonists and glycemic control in T2D patients?",
|
|
76
|
+
type: MESSAGE_TYPE.USER,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
createdAt: 1771998382834,
|
|
80
|
+
error: ERROR_MESSAGE.RATE_LIMITED,
|
|
81
|
+
type: MESSAGE_TYPE.ERROR,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
createdAt: 1771998382835,
|
|
85
|
+
text: "I'm studying whether smoking modifies the effect of GLP-1 agonists on glycemic control in T2D patients.",
|
|
86
|
+
type: MESSAGE_TYPE.USER,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
createdAt: 1771998382836,
|
|
90
|
+
response: {
|
|
91
|
+
message: "How do you want to split the smoking groups?",
|
|
92
|
+
query: {
|
|
93
|
+
mentions: [
|
|
94
|
+
{
|
|
95
|
+
exclude: false,
|
|
96
|
+
facet: "focus",
|
|
97
|
+
originalText: "lung cancer",
|
|
98
|
+
values: [
|
|
99
|
+
"Lung Neoplasms",
|
|
100
|
+
"Carcinoma, Non-Small-Cell Lung",
|
|
101
|
+
"Adenocarcinoma of Lung",
|
|
102
|
+
"Small Cell Lung Carcinoma",
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
type: MESSAGE_TYPE.ASSISTANT,
|
|
109
|
+
} as AssistantMessage,
|
|
110
|
+
],
|
|
111
|
+
status: {
|
|
112
|
+
loading: false,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Meta, type StoryObj } from "@storybook/nextjs-vite";
|
|
2
|
+
import { Messages } from "../messages";
|
|
3
|
+
import { Box } from "@mui/material";
|
|
4
|
+
import { JSX } from "react";
|
|
5
|
+
import { ARGS } from "./args";
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof Messages> = {
|
|
8
|
+
component: Messages,
|
|
9
|
+
decorators: [
|
|
10
|
+
(Story): JSX.Element => (
|
|
11
|
+
<Box sx={{ width: "412px" }}>
|
|
12
|
+
<Story />
|
|
13
|
+
</Box>
|
|
14
|
+
),
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default meta;
|
|
19
|
+
|
|
20
|
+
type Story = StoryObj<typeof meta>;
|
|
21
|
+
|
|
22
|
+
export const Default: Story = {
|
|
23
|
+
args: ARGS,
|
|
24
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/nextjs-vite";
|
|
2
|
+
import { JSX } from "react";
|
|
3
|
+
import { ToggleButtonGroup } from "../toggleButtonGroup";
|
|
4
|
+
import { ConfigProvider } from "../../../../../../providers/config";
|
|
5
|
+
import { INITIAL_CONFIG } from "../../../stories/args";
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof ToggleButtonGroup> = {
|
|
8
|
+
component: ToggleButtonGroup,
|
|
9
|
+
decorators: [
|
|
10
|
+
(Story): JSX.Element => (
|
|
11
|
+
<ConfigProvider config={INITIAL_CONFIG}>
|
|
12
|
+
<Story />
|
|
13
|
+
</ConfigProvider>
|
|
14
|
+
),
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default meta;
|
|
19
|
+
|
|
20
|
+
type Story = StoryObj<typeof meta>;
|
|
21
|
+
|
|
22
|
+
export const DEFAULT: Story = {};
|
package/src/views/ResearchView/assistant/components/ToggleButtonGroup/toggleButtonGroup.styles.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import styled from "@emotion/styled";
|
|
2
|
+
import { Box, ToggleButtonGroup } from "@mui/material";
|
|
3
|
+
import { PALETTE } from "../../../../../styles/common/constants/palette";
|
|
4
|
+
|
|
5
|
+
export const StyledBox = styled(Box)`
|
|
6
|
+
background-color: ${PALETTE.COMMON_WHITE};
|
|
7
|
+
margin-bottom: -16px;
|
|
8
|
+
padding: 16px;
|
|
9
|
+
z-index: 1;
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
export const StyledToggleButtonGroup = styled(ToggleButtonGroup)`
|
|
13
|
+
.MuiToggleButton-root {
|
|
14
|
+
gap: 4px;
|
|
15
|
+
padding: 6px 16px;
|
|
16
|
+
text-transform: none;
|
|
17
|
+
|
|
18
|
+
&.Mui-disabled {
|
|
19
|
+
color: ${PALETTE.INK_LIGHT};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ToggleButton } from "@mui/material";
|
|
2
|
+
import { JSX } from "react";
|
|
3
|
+
import { StyledBox, StyledToggleButtonGroup } from "./toggleButtonGroup.styles";
|
|
4
|
+
import Link from "next/link";
|
|
5
|
+
import { useAiRoutes } from "../../../../../hooks/ai/useAiRoutes/hook";
|
|
6
|
+
import { Beta } from "../../../../../components/common/Chip/components/Beta/beta";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ToggleButtonGroup component for navigating between ResearchView and ExploreView.
|
|
10
|
+
* @returns ToggleButtonGroup JSX element, or null if routes are not configured.
|
|
11
|
+
*/
|
|
12
|
+
export const ToggleButtonGroup = (): JSX.Element | null => {
|
|
13
|
+
const { routes } = useAiRoutes() || {};
|
|
14
|
+
|
|
15
|
+
if (!routes) return null;
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<StyledBox>
|
|
19
|
+
<StyledToggleButtonGroup exclusive>
|
|
20
|
+
<ToggleButton
|
|
21
|
+
component={Link}
|
|
22
|
+
href={routes.research}
|
|
23
|
+
selected
|
|
24
|
+
value="research"
|
|
25
|
+
>
|
|
26
|
+
Research <Beta />
|
|
27
|
+
</ToggleButton>
|
|
28
|
+
<ToggleButton component={Link} href={routes.search} value="search">
|
|
29
|
+
Search
|
|
30
|
+
</ToggleButton>
|
|
31
|
+
</StyledToggleButtonGroup>
|
|
32
|
+
</StyledBox>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SiteConfig } from "../../../../config/entities";
|
|
2
|
+
import { InitialArgs } from "../../state/initializer/types";
|
|
3
|
+
import { SUGGESTION_VARIANT } from "../../state/types";
|
|
4
|
+
|
|
5
|
+
export const INITIAL_CONFIG = {
|
|
6
|
+
ai: {
|
|
7
|
+
enabled: true,
|
|
8
|
+
routes: { research: "/research", search: "/search" },
|
|
9
|
+
url: "https://findable-chat/api/chat",
|
|
10
|
+
},
|
|
11
|
+
redirectRootToPath: "",
|
|
12
|
+
} as unknown as SiteConfig;
|
|
13
|
+
|
|
14
|
+
export const INITIAL_ARGS: NonNullable<InitialArgs> = {
|
|
15
|
+
inputPlaceholder: "Ask about datasets or variables",
|
|
16
|
+
suggestions: [
|
|
17
|
+
{
|
|
18
|
+
label: "GLP-1 effect + smoking in T2D",
|
|
19
|
+
query:
|
|
20
|
+
"I'm studying whether smoking modifies the effect of GLP-1 agonists on glycemic control in T2D patients",
|
|
21
|
+
variant: SUGGESTION_VARIANT.CHIP,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: "WGS for cardiovascular outcomes",
|
|
25
|
+
query:
|
|
26
|
+
"I'm interested in whole genome sequencing data for cardiovascular outcomes",
|
|
27
|
+
variant: SUGGESTION_VARIANT.CHIP,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
label: "RNA-Seq in pancreatic cancer",
|
|
31
|
+
query: "I'm interested in RNA-Seq data for pancreatic cancer",
|
|
32
|
+
variant: SUGGESTION_VARIANT.CHIP,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
text: "Hello! I can help you find datasets across 2,944 studies from AnVIL, BDC, CRDC, and KFDRC. Describe your research question and I'll build a structured plan and find matching data.",
|
|
36
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Box } from "@mui/material";
|
|
2
|
+
import { type Meta, type StoryObj } from "@storybook/nextjs-vite";
|
|
3
|
+
import { JSX } from "react";
|
|
4
|
+
import { PALETTE } from "../../../../styles/common/constants/palette";
|
|
5
|
+
import { ChatProvider } from "../../state/provider";
|
|
6
|
+
import { Assistant } from "../assistant";
|
|
7
|
+
import { INITIAL_ARGS, INITIAL_CONFIG } from "./args";
|
|
8
|
+
import { ConfigProvider } from "../../../../providers/config";
|
|
9
|
+
|
|
10
|
+
const meta: Meta<typeof Assistant> = {
|
|
11
|
+
component: Assistant,
|
|
12
|
+
decorators: [
|
|
13
|
+
(Story): JSX.Element => (
|
|
14
|
+
<ConfigProvider config={INITIAL_CONFIG}>
|
|
15
|
+
<ChatProvider initialArgs={INITIAL_ARGS} url="https://api.example.com">
|
|
16
|
+
<Box
|
|
17
|
+
sx={{
|
|
18
|
+
backgroundColor: PALETTE.COMMON_WHITE,
|
|
19
|
+
display: "flex",
|
|
20
|
+
flexDirection: "column",
|
|
21
|
+
height: "100vh",
|
|
22
|
+
minHeight: 0,
|
|
23
|
+
width: "412px",
|
|
24
|
+
}}
|
|
25
|
+
>
|
|
26
|
+
<Story />
|
|
27
|
+
</Box>
|
|
28
|
+
</ChatProvider>
|
|
29
|
+
</ConfigProvider>
|
|
30
|
+
),
|
|
31
|
+
],
|
|
32
|
+
parameters: { layout: "none" },
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default meta;
|
|
36
|
+
|
|
37
|
+
type Story = StoryObj<typeof meta>;
|
|
38
|
+
|
|
39
|
+
export const Default: Story = {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ERROR_MESSAGE } from "./constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fetches a response from the given API URL.
|
|
5
|
+
* @param url - Request URL.
|
|
6
|
+
* @param query - Query to send.
|
|
7
|
+
* @param options - Fetch options.
|
|
8
|
+
* @param options.controller - AbortController.
|
|
9
|
+
* @param options.onError - Callback invoked on error.
|
|
10
|
+
* @param options.onSettled - Callback invoked when the request is settled (after success or error).
|
|
11
|
+
* @param options.onSuccess - Callback invoked with response data on success.
|
|
12
|
+
* @returns Promise that resolves when the request completes.
|
|
13
|
+
*/
|
|
14
|
+
export async function fetchResponse<T = unknown>(
|
|
15
|
+
url: string,
|
|
16
|
+
query: string,
|
|
17
|
+
{
|
|
18
|
+
controller,
|
|
19
|
+
onError,
|
|
20
|
+
onSettled,
|
|
21
|
+
onSuccess,
|
|
22
|
+
}: {
|
|
23
|
+
controller: AbortController;
|
|
24
|
+
onError: (error: Error) => void;
|
|
25
|
+
onSettled: () => void;
|
|
26
|
+
onSuccess: (data: T) => void;
|
|
27
|
+
},
|
|
28
|
+
): Promise<T | undefined> {
|
|
29
|
+
const timeout = setTimeout(() => controller.abort(), 90_000);
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const res = await fetch(url, {
|
|
33
|
+
body: JSON.stringify({ query }),
|
|
34
|
+
headers: { "Content-Type": "application/json" },
|
|
35
|
+
method: "POST",
|
|
36
|
+
signal: controller.signal,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const { status } = res;
|
|
40
|
+
|
|
41
|
+
if (status === 429) {
|
|
42
|
+
onError(new Error(ERROR_MESSAGE.RATE_LIMITED));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!res.ok) throw new Error(`${ERROR_MESSAGE.REQUEST_FAILED} (${status})`);
|
|
47
|
+
|
|
48
|
+
const data = await res.json();
|
|
49
|
+
onSuccess(data);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (controller.signal.aborted) return;
|
|
52
|
+
if (error instanceof Error) onError(error);
|
|
53
|
+
else onError(new Error(ERROR_MESSAGE.UNKNOWN));
|
|
54
|
+
} finally {
|
|
55
|
+
clearTimeout(timeout);
|
|
56
|
+
onSettled();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Fragment, JSX } from "react";
|
|
2
|
+
import { Assistant } from "./assistant/assistant";
|
|
3
|
+
import { ChildrenProps } from "../../components/types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Main view for the research assistant feature.
|
|
7
|
+
* Renders the assistant drawer and any related components.
|
|
8
|
+
* @param props - Component props.
|
|
9
|
+
* @param props.children - Children components to be rendered within the research view.
|
|
10
|
+
* @returns The research view component.
|
|
11
|
+
*/
|
|
12
|
+
export const ResearchView = ({ children }: ChildrenProps): JSX.Element => {
|
|
13
|
+
return (
|
|
14
|
+
<Fragment>
|
|
15
|
+
<Assistant />
|
|
16
|
+
{children}
|
|
17
|
+
</Fragment>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ChatState, MESSAGE_TYPE } from "../../types";
|
|
2
|
+
import { SetErrorPayload } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reducer action to set an error message in the chat.
|
|
6
|
+
*
|
|
7
|
+
* @param state - State.
|
|
8
|
+
* @param payload - Payload.
|
|
9
|
+
* @returns State.
|
|
10
|
+
*/
|
|
11
|
+
export function setErrorAction(
|
|
12
|
+
state: ChatState,
|
|
13
|
+
payload: SetErrorPayload,
|
|
14
|
+
): ChatState {
|
|
15
|
+
return {
|
|
16
|
+
...state,
|
|
17
|
+
messages: [
|
|
18
|
+
...state.messages,
|
|
19
|
+
{ createdAt: Date.now(), error: payload.error, type: MESSAGE_TYPE.ERROR },
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ChatActionKind } from "../types";
|
|
2
|
+
import { SetErrorAction, SetErrorPayload } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Action creator for setting an error message in the chat.
|
|
6
|
+
* @param payload - Payload.
|
|
7
|
+
* @returns Action with payload and action type.
|
|
8
|
+
*/
|
|
9
|
+
export function setError(payload: SetErrorPayload): SetErrorAction {
|
|
10
|
+
return {
|
|
11
|
+
payload,
|
|
12
|
+
type: ChatActionKind.SetError,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ChatActionKind } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Action to set an error message in the chat.
|
|
5
|
+
*/
|
|
6
|
+
export interface SetErrorAction {
|
|
7
|
+
payload: SetErrorPayload;
|
|
8
|
+
type: ChatActionKind.SetError;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Payload for the SetError action.
|
|
13
|
+
*/
|
|
14
|
+
export interface SetErrorPayload {
|
|
15
|
+
error: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ChatState, MESSAGE_TYPE } from "../../types";
|
|
2
|
+
import { SetMessagePayload } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reducer action to set a message in the chat.
|
|
6
|
+
*
|
|
7
|
+
* @param state - State.
|
|
8
|
+
* @param payload - Payload.
|
|
9
|
+
* @returns State.
|
|
10
|
+
*/
|
|
11
|
+
export function setMessageAction(
|
|
12
|
+
state: ChatState,
|
|
13
|
+
payload: SetMessagePayload,
|
|
14
|
+
): ChatState {
|
|
15
|
+
return {
|
|
16
|
+
...state,
|
|
17
|
+
messages: [
|
|
18
|
+
...state.messages,
|
|
19
|
+
{
|
|
20
|
+
createdAt: Date.now(),
|
|
21
|
+
response: payload.response,
|
|
22
|
+
type: MESSAGE_TYPE.ASSISTANT,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ChatActionKind } from "../types";
|
|
2
|
+
import { SetMessageAction, SetMessagePayload } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Action creator for setting a message in the chat.
|
|
6
|
+
* @param payload - Payload.
|
|
7
|
+
* @returns Action with payload and action type.
|
|
8
|
+
*/
|
|
9
|
+
export function setMessage(payload: SetMessagePayload): SetMessageAction {
|
|
10
|
+
return {
|
|
11
|
+
payload,
|
|
12
|
+
type: ChatActionKind.SetMessage,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MessageResponse } from "../../types";
|
|
2
|
+
import { ChatActionKind } from "../types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Action to set the message for a chat.
|
|
6
|
+
*/
|
|
7
|
+
export interface SetMessageAction {
|
|
8
|
+
payload: SetMessagePayload;
|
|
9
|
+
type: ChatActionKind.SetMessage;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Payload for the SetMessage action.
|
|
14
|
+
*/
|
|
15
|
+
export interface SetMessagePayload<
|
|
16
|
+
R extends MessageResponse = MessageResponse,
|
|
17
|
+
> {
|
|
18
|
+
response: R;
|
|
19
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ChatState, MESSAGE_TYPE } from "../../types";
|
|
2
|
+
import { SetQueryPayload } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reducer action to set a query in the chat.
|
|
6
|
+
*
|
|
7
|
+
* @param state - State.
|
|
8
|
+
* @param payload - Payload.
|
|
9
|
+
* @returns State.
|
|
10
|
+
*/
|
|
11
|
+
export function setQueryAction(
|
|
12
|
+
state: ChatState,
|
|
13
|
+
payload: SetQueryPayload,
|
|
14
|
+
): ChatState {
|
|
15
|
+
return {
|
|
16
|
+
...state,
|
|
17
|
+
messages: [
|
|
18
|
+
...state.messages,
|
|
19
|
+
{ createdAt: Date.now(), text: payload.query, type: MESSAGE_TYPE.USER },
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ChatActionKind } from "../types";
|
|
2
|
+
import { SetQueryAction, SetQueryPayload } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Action creator for setting a query in the chat.
|
|
6
|
+
* @param payload - Payload.
|
|
7
|
+
* @returns Action with payload and action type.
|
|
8
|
+
*/
|
|
9
|
+
export function setQuery(payload: SetQueryPayload): SetQueryAction {
|
|
10
|
+
return {
|
|
11
|
+
payload,
|
|
12
|
+
type: ChatActionKind.SetQuery,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ChatActionKind } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Action to set the query for a chat.
|
|
5
|
+
*/
|
|
6
|
+
export interface SetQueryAction {
|
|
7
|
+
payload: SetQueryPayload;
|
|
8
|
+
type: ChatActionKind.SetQuery;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Payload for the SetQuery action.
|
|
13
|
+
*/
|
|
14
|
+
export interface SetQueryPayload {
|
|
15
|
+
query: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ChatState } from "../../types";
|
|
2
|
+
import { SetStatusPayload } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reducer action to set the loading status in the chat.
|
|
6
|
+
*
|
|
7
|
+
* @param state - State.
|
|
8
|
+
* @param payload - Payload.
|
|
9
|
+
* @returns State.
|
|
10
|
+
*/
|
|
11
|
+
export function setStatusAction(
|
|
12
|
+
state: ChatState,
|
|
13
|
+
payload: SetStatusPayload,
|
|
14
|
+
): ChatState {
|
|
15
|
+
return {
|
|
16
|
+
...state,
|
|
17
|
+
status: { ...state.status, loading: payload.loading },
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ChatActionKind } from "../types";
|
|
2
|
+
import { SetStatusAction, SetStatusPayload } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Action creator for setting the loading status in the chat.
|
|
6
|
+
* @param payload - Payload.
|
|
7
|
+
* @returns Action with payload and action type.
|
|
8
|
+
*/
|
|
9
|
+
export function setStatus(payload: SetStatusPayload): SetStatusAction {
|
|
10
|
+
return {
|
|
11
|
+
payload,
|
|
12
|
+
type: ChatActionKind.SetStatus,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ChatActionKind } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Action to set the loading status for a chat.
|
|
5
|
+
*/
|
|
6
|
+
export interface SetStatusAction {
|
|
7
|
+
payload: SetStatusPayload;
|
|
8
|
+
type: ChatActionKind.SetStatus;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Payload for the SetStatus action.
|
|
13
|
+
*/
|
|
14
|
+
export interface SetStatusPayload {
|
|
15
|
+
loading: boolean;
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SetErrorAction } from "./setError/types";
|
|
2
|
+
import { SetMessageAction } from "./setMessage/types";
|
|
3
|
+
import { SetQueryAction } from "./setQuery/types";
|
|
4
|
+
import { SetStatusAction } from "./setStatus/types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Union of all Chat actions.
|
|
8
|
+
*/
|
|
9
|
+
export type ChatAction =
|
|
10
|
+
| SetErrorAction
|
|
11
|
+
| SetMessageAction
|
|
12
|
+
| SetQueryAction
|
|
13
|
+
| SetStatusAction;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Action kind identifiers for the Chat reducer.
|
|
17
|
+
*/
|
|
18
|
+
export enum ChatActionKind {
|
|
19
|
+
SetError = "SET_ERROR",
|
|
20
|
+
SetMessage = "SET_MESSAGE",
|
|
21
|
+
SetQuery = "SET_QUERY",
|
|
22
|
+
SetStatus = "SET_STATUS",
|
|
23
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
import { ChatContextValue } from "./types";
|
|
3
|
+
import { INITIAL_STATE } from "./constants";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Context for the Chat state provider.
|
|
7
|
+
*/
|
|
8
|
+
export const ChatContext = createContext<ChatContextValue>({
|
|
9
|
+
dispatch: () => undefined,
|
|
10
|
+
state: INITIAL_STATE,
|
|
11
|
+
});
|