@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,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AssistantMessage,
|
|
3
|
+
ErrorMessage,
|
|
4
|
+
Message,
|
|
5
|
+
MESSAGE_TYPE,
|
|
6
|
+
MessageResponse,
|
|
7
|
+
PromptMessage,
|
|
8
|
+
UserMessage,
|
|
9
|
+
} from "../types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns true if the message is an assistant message.
|
|
13
|
+
* @param message - Chat message.
|
|
14
|
+
* @returns True if the message is an assistant message.
|
|
15
|
+
*/
|
|
16
|
+
export function isAssistantMessage<R extends MessageResponse = MessageResponse>(
|
|
17
|
+
message: Message<R>,
|
|
18
|
+
): message is AssistantMessage<R> {
|
|
19
|
+
return message.type === MESSAGE_TYPE.ASSISTANT;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns true if the message is an error message.
|
|
24
|
+
* @param message - Chat message.
|
|
25
|
+
* @returns True if the message is an error message.
|
|
26
|
+
*/
|
|
27
|
+
export function isErrorMessage(message: Message): message is ErrorMessage {
|
|
28
|
+
return message.type === MESSAGE_TYPE.ERROR;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns true if the message is the initial prompt message.
|
|
33
|
+
* @param message - Chat message.
|
|
34
|
+
* @returns True if the message is the initial prompt message.
|
|
35
|
+
*/
|
|
36
|
+
export function isInitialPromptMessage(
|
|
37
|
+
message: Message,
|
|
38
|
+
): message is PromptMessage & { initial: true } {
|
|
39
|
+
return isPromptMessage(message) && message.initial === true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns true if the message is a prompt message.
|
|
44
|
+
* @param message - Chat message.
|
|
45
|
+
* @returns True if the message is a prompt message.
|
|
46
|
+
*/
|
|
47
|
+
export function isPromptMessage(message: Message): message is PromptMessage {
|
|
48
|
+
return message.type === MESSAGE_TYPE.PROMPT;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Returns true if the message is a user message.
|
|
53
|
+
* @param message - Chat message.
|
|
54
|
+
* @returns True if the message is a user message.
|
|
55
|
+
*/
|
|
56
|
+
export function isUserMessage(message: Message): message is UserMessage {
|
|
57
|
+
return message.type === MESSAGE_TYPE.USER;
|
|
58
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useCallback, useContext } from "react";
|
|
2
|
+
import { setError } from "../../actions/setError/dispatch";
|
|
3
|
+
import { setMessage } from "../../actions/setMessage/dispatch";
|
|
4
|
+
import { setQuery } from "../../actions/setQuery/dispatch";
|
|
5
|
+
import { setStatus } from "../../actions/setStatus/dispatch";
|
|
6
|
+
import { ChatContext } from "../../context";
|
|
7
|
+
import { MessageResponse } from "../../types";
|
|
8
|
+
import { UseChatDispatch } from "./types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hook to dispatch Chat actions.
|
|
12
|
+
* @returns Object containing action dispatch functions.
|
|
13
|
+
*/
|
|
14
|
+
export const useChatDispatch = (): UseChatDispatch => {
|
|
15
|
+
const { dispatch } = useContext(ChatContext);
|
|
16
|
+
|
|
17
|
+
const onSetError = useCallback(
|
|
18
|
+
(error: string) => {
|
|
19
|
+
dispatch(setError({ error }));
|
|
20
|
+
},
|
|
21
|
+
[dispatch],
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const onSetMessage = useCallback(
|
|
25
|
+
<R extends MessageResponse>(response: R) => {
|
|
26
|
+
dispatch(setMessage({ response }));
|
|
27
|
+
},
|
|
28
|
+
[dispatch],
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const onSetQuery = useCallback(
|
|
32
|
+
(query: string) => {
|
|
33
|
+
dispatch(setQuery({ query }));
|
|
34
|
+
},
|
|
35
|
+
[dispatch],
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const onSetStatus = useCallback(
|
|
39
|
+
(loading: boolean) => {
|
|
40
|
+
dispatch(setStatus({ loading }));
|
|
41
|
+
},
|
|
42
|
+
[dispatch],
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return { onSetError, onSetMessage, onSetQuery, onSetStatus };
|
|
46
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MessageResponse } from "../../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Return type for the useChatDispatch hook.
|
|
5
|
+
*/
|
|
6
|
+
export interface UseChatDispatch {
|
|
7
|
+
onSetError: (error: string) => void;
|
|
8
|
+
onSetMessage: <R extends MessageResponse>(response: R) => void;
|
|
9
|
+
onSetQuery: (query: string) => void;
|
|
10
|
+
onSetStatus: (loading: boolean) => void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useReducer } from "react";
|
|
2
|
+
import { initializer } from "../../initializer/initializer";
|
|
3
|
+
import { InitialArgs } from "../../initializer/types";
|
|
4
|
+
import { chatReducer } from "../../reducer";
|
|
5
|
+
import { ChatContextValue } from "../../types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hook that manages the chat reducer with initial state from config.
|
|
9
|
+
* @param initialArgs - Initial arguments for the chat state.
|
|
10
|
+
* @returns Chat context value with dispatch and state.
|
|
11
|
+
*/
|
|
12
|
+
export const useChatReducer = (initialArgs?: InitialArgs): ChatContextValue => {
|
|
13
|
+
const [state, dispatch] = useReducer(chatReducer, initialArgs, initializer);
|
|
14
|
+
return { dispatch, state };
|
|
15
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { ChatContext } from "../../context";
|
|
3
|
+
import { ChatContextValue } from "../../types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook to access Chat state.
|
|
7
|
+
*
|
|
8
|
+
* @returns Chat state.
|
|
9
|
+
*/
|
|
10
|
+
export const useChatState = (): Pick<ChatContextValue, "state"> => {
|
|
11
|
+
const { state } = useContext(ChatContext);
|
|
12
|
+
|
|
13
|
+
return { state };
|
|
14
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { INITIAL_STATE } from "../constants";
|
|
2
|
+
import { ChatState, MESSAGE_TYPE } from "../types";
|
|
3
|
+
import { InitialArgs } from "./types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Initializer function for the chat reducer, returning initial state.
|
|
7
|
+
* @param initialArgs - Initial arguments.
|
|
8
|
+
* @returns The initialized chat state.
|
|
9
|
+
*/
|
|
10
|
+
export function initializer(initialArgs?: InitialArgs): ChatState {
|
|
11
|
+
if (!initialArgs) return INITIAL_STATE;
|
|
12
|
+
return {
|
|
13
|
+
...INITIAL_STATE,
|
|
14
|
+
messages: [
|
|
15
|
+
{
|
|
16
|
+
...initialArgs,
|
|
17
|
+
createdAt: Date.now(),
|
|
18
|
+
initial: true,
|
|
19
|
+
type: MESSAGE_TYPE.PROMPT,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { JSX, ReactNode } from "react";
|
|
2
|
+
import { ChatContext } from "./context";
|
|
3
|
+
import { useChatReducer } from "./hooks/UseChatReducer/hook";
|
|
4
|
+
import { InitialArgs } from "./initializer/types";
|
|
5
|
+
import { QueryProvider } from "./query/provider";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Provider for Chat state.
|
|
9
|
+
* Manages chat state such as query and response data.
|
|
10
|
+
* Nests QueryProvider to own the fetch lifecycle for query submission.
|
|
11
|
+
*
|
|
12
|
+
* @param props - Props.
|
|
13
|
+
* @param props.children - Children.
|
|
14
|
+
* @param props.initialArgs - Initial arguments.
|
|
15
|
+
* @param props.url - URL for the query endpoint.
|
|
16
|
+
*
|
|
17
|
+
* @returns A context provider wrapping the given children.
|
|
18
|
+
*/
|
|
19
|
+
export function ChatProvider({
|
|
20
|
+
children,
|
|
21
|
+
initialArgs,
|
|
22
|
+
url,
|
|
23
|
+
}: {
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
initialArgs?: InitialArgs;
|
|
26
|
+
url: string;
|
|
27
|
+
}): JSX.Element {
|
|
28
|
+
const reducer = useChatReducer(initialArgs);
|
|
29
|
+
return (
|
|
30
|
+
<ChatContext.Provider value={reducer}>
|
|
31
|
+
<QueryProvider url={url}>{children}</QueryProvider>
|
|
32
|
+
</ChatContext.Provider>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { QueryContext } from "../../context";
|
|
3
|
+
import { QueryContextValue } from "../../types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook to access query submission from the QueryProvider.
|
|
7
|
+
* @returns Query context value with onSubmit.
|
|
8
|
+
*/
|
|
9
|
+
export const useQuery = (): QueryContextValue => {
|
|
10
|
+
return useContext(QueryContext);
|
|
11
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { FormEvent, useCallback, useRef } from "react";
|
|
2
|
+
import { fetchResponse } from "../../../../query/fetch";
|
|
3
|
+
import { useChatDispatch } from "../../../hooks/UseChatDispatch/hook";
|
|
4
|
+
import { MessageResponse } from "../../../types";
|
|
5
|
+
import {
|
|
6
|
+
OnSubmitOptions,
|
|
7
|
+
OnSubmitPayload,
|
|
8
|
+
QueryContextValue,
|
|
9
|
+
} from "../../types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Hook that manages query submission and abort lifecycle.
|
|
13
|
+
* @param url - The API URL to send queries to.
|
|
14
|
+
* @returns Object containing the onSubmit handler.
|
|
15
|
+
*/
|
|
16
|
+
export const useSubmit = (url: string): Pick<QueryContextValue, "onSubmit"> => {
|
|
17
|
+
const abortRef = useRef<AbortController>(null);
|
|
18
|
+
const dispatch = useChatDispatch();
|
|
19
|
+
|
|
20
|
+
const onSubmit = useCallback(
|
|
21
|
+
async (
|
|
22
|
+
e: FormEvent<HTMLFormElement>,
|
|
23
|
+
payload: OnSubmitPayload,
|
|
24
|
+
options: OnSubmitOptions,
|
|
25
|
+
): Promise<void> => {
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
|
|
28
|
+
if (options.status.loading) return;
|
|
29
|
+
|
|
30
|
+
const { query } = payload;
|
|
31
|
+
if (!query) return;
|
|
32
|
+
|
|
33
|
+
const form = e.currentTarget;
|
|
34
|
+
|
|
35
|
+
// Dispatch query and loading state.
|
|
36
|
+
dispatch.onSetQuery(query);
|
|
37
|
+
dispatch.onSetStatus(true);
|
|
38
|
+
form.reset();
|
|
39
|
+
options.onMutate?.(form, query);
|
|
40
|
+
|
|
41
|
+
// Abort any in-flight request.
|
|
42
|
+
abortRef.current?.abort();
|
|
43
|
+
const controller = new AbortController();
|
|
44
|
+
abortRef.current = controller;
|
|
45
|
+
|
|
46
|
+
await fetchResponse(url, query, {
|
|
47
|
+
controller,
|
|
48
|
+
onError: (error) => {
|
|
49
|
+
dispatch.onSetError(error.message);
|
|
50
|
+
options.onError?.(error);
|
|
51
|
+
},
|
|
52
|
+
onSettled: () => {
|
|
53
|
+
dispatch.onSetStatus(false);
|
|
54
|
+
options.onSettled?.(form);
|
|
55
|
+
},
|
|
56
|
+
onSuccess: (data) => {
|
|
57
|
+
dispatch.onSetMessage(data as MessageResponse);
|
|
58
|
+
options.onSuccess?.(data);
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
[dispatch, url],
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return { onSubmit };
|
|
66
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { JSX, ReactNode } from "react";
|
|
2
|
+
import { QueryContext } from "./context";
|
|
3
|
+
import { useSubmit } from "./hooks/UseSubmit/hook";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Provider that owns the fetch lifecycle for query submission.
|
|
7
|
+
* Persists across page navigation so in-flight requests are not aborted.
|
|
8
|
+
* @param props - Props.
|
|
9
|
+
* @param props.children - Children.
|
|
10
|
+
* @param props.url - URL for the query endpoint.
|
|
11
|
+
* @returns A context provider wrapping the given children.
|
|
12
|
+
*/
|
|
13
|
+
export function QueryProvider({
|
|
14
|
+
children,
|
|
15
|
+
url,
|
|
16
|
+
}: {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
url: string;
|
|
19
|
+
}): JSX.Element {
|
|
20
|
+
const { onSubmit } = useSubmit(url);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<QueryContext.Provider value={{ onSubmit }}>
|
|
24
|
+
{children}
|
|
25
|
+
</QueryContext.Provider>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FormEvent } from "react";
|
|
2
|
+
import { Status } from "../types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for the onSubmit action.
|
|
6
|
+
*/
|
|
7
|
+
export interface OnSubmitOptions {
|
|
8
|
+
onError?: (error: Error) => void;
|
|
9
|
+
onMutate?: (form: HTMLFormElement, query: string) => void;
|
|
10
|
+
onSettled?: (form: HTMLFormElement) => void;
|
|
11
|
+
onSuccess?: (data: unknown) => void;
|
|
12
|
+
status: Status;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Payload for the onSubmit action.
|
|
17
|
+
*/
|
|
18
|
+
export interface OnSubmitPayload {
|
|
19
|
+
query: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Context value for the QueryProvider.
|
|
24
|
+
*/
|
|
25
|
+
export interface QueryContextValue {
|
|
26
|
+
onSubmit: (
|
|
27
|
+
e: FormEvent<HTMLFormElement>,
|
|
28
|
+
payload: OnSubmitPayload,
|
|
29
|
+
options: OnSubmitOptions,
|
|
30
|
+
) => Promise<void>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { setErrorAction } from "./actions/setError/action";
|
|
2
|
+
import { setMessageAction } from "./actions/setMessage/action";
|
|
3
|
+
import { setQueryAction } from "./actions/setQuery/action";
|
|
4
|
+
import { setStatusAction } from "./actions/setStatus/action";
|
|
5
|
+
import { ChatAction, ChatActionKind } from "./actions/types";
|
|
6
|
+
import { ChatState } from "./types";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Reducer for the Chat state.
|
|
10
|
+
*
|
|
11
|
+
* @param state - State.
|
|
12
|
+
* @param action - Action.
|
|
13
|
+
* @returns State.
|
|
14
|
+
*/
|
|
15
|
+
export function chatReducer(state: ChatState, action: ChatAction): ChatState {
|
|
16
|
+
const { payload, type } = action;
|
|
17
|
+
switch (type) {
|
|
18
|
+
case ChatActionKind.SetError: {
|
|
19
|
+
return setErrorAction(state, payload);
|
|
20
|
+
}
|
|
21
|
+
case ChatActionKind.SetMessage: {
|
|
22
|
+
return setMessageAction(state, payload);
|
|
23
|
+
}
|
|
24
|
+
case ChatActionKind.SetQuery: {
|
|
25
|
+
return setQueryAction(state, payload);
|
|
26
|
+
}
|
|
27
|
+
case ChatActionKind.SetStatus: {
|
|
28
|
+
return setStatusAction(state, payload);
|
|
29
|
+
}
|
|
30
|
+
default: {
|
|
31
|
+
return state;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Dispatch } from "react";
|
|
2
|
+
import { ChatAction } from "./actions/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Assistant message in the chat.
|
|
6
|
+
*/
|
|
7
|
+
export interface AssistantMessage<
|
|
8
|
+
R extends MessageResponse = MessageResponse,
|
|
9
|
+
> extends BaseMessage {
|
|
10
|
+
response: R;
|
|
11
|
+
type: MESSAGE_TYPE.ASSISTANT;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Base message type for chat messages.
|
|
16
|
+
*/
|
|
17
|
+
export interface BaseMessage {
|
|
18
|
+
createdAt: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Context value for the Chat state provider.
|
|
23
|
+
*/
|
|
24
|
+
export interface ChatContextValue {
|
|
25
|
+
dispatch: Dispatch<ChatAction>;
|
|
26
|
+
state: ChatState;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* State for the Chat feature.
|
|
31
|
+
*/
|
|
32
|
+
export interface ChatState {
|
|
33
|
+
messages: Message[];
|
|
34
|
+
status: Status;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Error message in the chat.
|
|
39
|
+
*/
|
|
40
|
+
export interface ErrorMessage extends BaseMessage {
|
|
41
|
+
error: string;
|
|
42
|
+
type: MESSAGE_TYPE.ERROR;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Intent values for the research API response.
|
|
47
|
+
*/
|
|
48
|
+
export const INTENT = {
|
|
49
|
+
AUTO: "auto",
|
|
50
|
+
} as const;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Intent type for the research API response.
|
|
54
|
+
*/
|
|
55
|
+
export type Intent = (typeof INTENT)[keyof typeof INTENT] | (string & {});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Union type for messages in the chat.
|
|
59
|
+
*/
|
|
60
|
+
export type Message<R extends MessageResponse = MessageResponse> =
|
|
61
|
+
| AssistantMessage<R>
|
|
62
|
+
| ErrorMessage
|
|
63
|
+
| PromptMessage
|
|
64
|
+
| UserMessage;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Message types for the chat.
|
|
68
|
+
*/
|
|
69
|
+
export enum MESSAGE_TYPE {
|
|
70
|
+
ASSISTANT = "ASSISTANT",
|
|
71
|
+
ERROR = "ERROR",
|
|
72
|
+
PROMPT = "PROMPT",
|
|
73
|
+
USER = "USER",
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Mention extracted from the user query.
|
|
78
|
+
*/
|
|
79
|
+
export interface Mention {
|
|
80
|
+
exclude: boolean;
|
|
81
|
+
facet: string;
|
|
82
|
+
originalText: string;
|
|
83
|
+
values: string[];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Response from the research API.
|
|
88
|
+
*/
|
|
89
|
+
export interface MessageResponse {
|
|
90
|
+
intent: Intent;
|
|
91
|
+
message: string | null;
|
|
92
|
+
query: {
|
|
93
|
+
mentions: Mention[];
|
|
94
|
+
message: string | null;
|
|
95
|
+
};
|
|
96
|
+
timing: {
|
|
97
|
+
lookupMs: number;
|
|
98
|
+
pipelineMs: number;
|
|
99
|
+
totalMs: number;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Prompt message in the chat, initiated by the system.
|
|
105
|
+
*/
|
|
106
|
+
export interface PromptMessage extends BaseMessage {
|
|
107
|
+
initial?: boolean;
|
|
108
|
+
inputPlaceholder?: string;
|
|
109
|
+
suggestions?: PromptSuggestion[];
|
|
110
|
+
text: string;
|
|
111
|
+
type: MESSAGE_TYPE.PROMPT;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Suggestion within a prompt message.
|
|
116
|
+
*/
|
|
117
|
+
export interface PromptSuggestion {
|
|
118
|
+
label: string;
|
|
119
|
+
query: string;
|
|
120
|
+
variant: SuggestionVariant;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Status of the chat interaction, such as loading state.
|
|
125
|
+
*/
|
|
126
|
+
export interface Status {
|
|
127
|
+
loading: boolean;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Suggestion variant values for rendering suggestions.
|
|
132
|
+
*/
|
|
133
|
+
export const SUGGESTION_VARIANT = {
|
|
134
|
+
CHIP: "CHIP",
|
|
135
|
+
} as const;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Suggestion variant type.
|
|
139
|
+
*/
|
|
140
|
+
export type SuggestionVariant =
|
|
141
|
+
(typeof SUGGESTION_VARIANT)[keyof typeof SUGGESTION_VARIANT];
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* User message in the chat.
|
|
145
|
+
*/
|
|
146
|
+
export interface UserMessage extends BaseMessage {
|
|
147
|
+
text: string;
|
|
148
|
+
type: MESSAGE_TYPE.USER;
|
|
149
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getMappings,
|
|
3
|
+
getMentions,
|
|
4
|
+
} from "../src/views/ResearchView/assistant/components/Messages/components/AssistantMessage/utils";
|
|
5
|
+
import {
|
|
6
|
+
AssistantMessage,
|
|
7
|
+
MESSAGE_TYPE,
|
|
8
|
+
} from "../src/views/ResearchView/state/types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a mock AssistantMessage with the given mentions.
|
|
12
|
+
* @param mentions - Array of mention objects.
|
|
13
|
+
* @returns A mock AssistantMessage.
|
|
14
|
+
*/
|
|
15
|
+
function mockMessage(
|
|
16
|
+
mentions: AssistantMessage["response"]["query"]["mentions"],
|
|
17
|
+
): AssistantMessage {
|
|
18
|
+
return {
|
|
19
|
+
createdAt: Date.now(),
|
|
20
|
+
response: {
|
|
21
|
+
intent: "auto",
|
|
22
|
+
message: null,
|
|
23
|
+
query: {
|
|
24
|
+
mentions,
|
|
25
|
+
message: null,
|
|
26
|
+
},
|
|
27
|
+
timing: {
|
|
28
|
+
lookupMs: 0,
|
|
29
|
+
pipelineMs: 0,
|
|
30
|
+
totalMs: 0,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
type: MESSAGE_TYPE.ASSISTANT,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe("getMappings", () => {
|
|
38
|
+
it("returns empty string for empty mentions", () => {
|
|
39
|
+
expect(getMappings(mockMessage([]))).toBe("");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("formats a single mention", () => {
|
|
43
|
+
const message = mockMessage([
|
|
44
|
+
{
|
|
45
|
+
exclude: false,
|
|
46
|
+
facet: "disease",
|
|
47
|
+
originalText: "T2D",
|
|
48
|
+
values: ["T2D"],
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
51
|
+
expect(getMappings(message)).toBe("disease: T2D");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("formats a mention with multiple values", () => {
|
|
55
|
+
const message = mockMessage([
|
|
56
|
+
{
|
|
57
|
+
exclude: false,
|
|
58
|
+
facet: "disease",
|
|
59
|
+
originalText: "cancer",
|
|
60
|
+
values: ["lung cancer", "breast cancer"],
|
|
61
|
+
},
|
|
62
|
+
]);
|
|
63
|
+
expect(getMappings(message)).toBe("disease: lung cancer, breast cancer");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("groups mentions by facet", () => {
|
|
67
|
+
const message = mockMessage([
|
|
68
|
+
{
|
|
69
|
+
exclude: false,
|
|
70
|
+
facet: "disease",
|
|
71
|
+
originalText: "T2D",
|
|
72
|
+
values: ["T2D"],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
exclude: false,
|
|
76
|
+
facet: "disease",
|
|
77
|
+
originalText: "T1D",
|
|
78
|
+
values: ["T1D"],
|
|
79
|
+
},
|
|
80
|
+
]);
|
|
81
|
+
expect(getMappings(message)).toBe("disease: T2D, T1D");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("separates different facets with slashes", () => {
|
|
85
|
+
const message = mockMessage([
|
|
86
|
+
{
|
|
87
|
+
exclude: false,
|
|
88
|
+
facet: "disease",
|
|
89
|
+
originalText: "T2D",
|
|
90
|
+
values: ["T2D"],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
exclude: false,
|
|
94
|
+
facet: "data_type",
|
|
95
|
+
originalText: "WGS",
|
|
96
|
+
values: ["WGS"],
|
|
97
|
+
},
|
|
98
|
+
]);
|
|
99
|
+
expect(getMappings(message)).toBe("disease: T2D / data_type: WGS");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("marks excluded facets", () => {
|
|
103
|
+
const message = mockMessage([
|
|
104
|
+
{
|
|
105
|
+
exclude: true,
|
|
106
|
+
facet: "disease",
|
|
107
|
+
originalText: "T2D",
|
|
108
|
+
values: ["T2D"],
|
|
109
|
+
},
|
|
110
|
+
]);
|
|
111
|
+
expect(getMappings(message)).toBe("disease (exclude): T2D");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("getMentions", () => {
|
|
116
|
+
it("returns empty string for empty mentions", () => {
|
|
117
|
+
expect(getMentions(mockMessage([]))).toBe("");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("returns original text for a single mention", () => {
|
|
121
|
+
const message = mockMessage([
|
|
122
|
+
{
|
|
123
|
+
exclude: false,
|
|
124
|
+
facet: "disease",
|
|
125
|
+
originalText: "T2D",
|
|
126
|
+
values: ["T2D"],
|
|
127
|
+
},
|
|
128
|
+
]);
|
|
129
|
+
expect(getMentions(message)).toBe("T2D");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("joins multiple mentions with commas", () => {
|
|
133
|
+
const message = mockMessage([
|
|
134
|
+
{
|
|
135
|
+
exclude: false,
|
|
136
|
+
facet: "disease",
|
|
137
|
+
originalText: "T2D",
|
|
138
|
+
values: ["T2D"],
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
exclude: false,
|
|
142
|
+
facet: "data_type",
|
|
143
|
+
originalText: "WGS",
|
|
144
|
+
values: ["WGS"],
|
|
145
|
+
},
|
|
146
|
+
]);
|
|
147
|
+
expect(getMentions(message)).toBe("T2D, WGS");
|
|
148
|
+
});
|
|
149
|
+
});
|