@gravity-ui/aikit 0.0.1
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/LICENSE +21 -0
- package/README.md +190 -0
- package/dist/.storybook/theme.d.ts +6 -0
- package/dist/.storybook/theme.js +28 -0
- package/dist/package.json +111 -0
- package/dist/src/components/atoms/ActionButton/ActionButton.d.ts +47 -0
- package/dist/src/components/atoms/ActionButton/ActionButton.js +34 -0
- package/dist/src/components/atoms/ActionButton/__stories__/ActionButton.stories.d.ts +8 -0
- package/dist/src/components/atoms/ActionButton/__stories__/ActionButton.stories.js +48 -0
- package/dist/src/components/atoms/ActionButton/index.d.ts +2 -0
- package/dist/src/components/atoms/ActionButton/index.js +1 -0
- package/dist/src/components/atoms/Alert/__stories__/Alert.stories.d.ts +9 -0
- package/dist/src/components/atoms/Alert/__stories__/Alert.stories.js +56 -0
- package/dist/src/components/atoms/Alert/index.d.ts +13 -0
- package/dist/src/components/atoms/Alert/index.js +25 -0
- package/dist/src/components/atoms/ChatDate/ChatDate.d.ts +19 -0
- package/dist/src/components/atoms/ChatDate/ChatDate.js +24 -0
- package/dist/src/components/atoms/ChatDate/__stories__/ChatDate.stories.d.ts +16 -0
- package/dist/src/components/atoms/ChatDate/__stories__/ChatDate.stories.js +83 -0
- package/dist/src/components/atoms/ChatDate/i18n/en.json +8 -0
- package/dist/src/components/atoms/ChatDate/i18n/index.d.ts +13 -0
- package/dist/src/components/atoms/ChatDate/i18n/index.js +5 -0
- package/dist/src/components/atoms/ChatDate/i18n/ru.json +10 -0
- package/dist/src/components/atoms/ChatDate/index.d.ts +1 -0
- package/dist/src/components/atoms/ChatDate/index.js +1 -0
- package/dist/src/components/atoms/ContextIndicator/__stories__/ContextIndicator.stories.d.ts +17 -0
- package/dist/src/components/atoms/ContextIndicator/__stories__/ContextIndicator.stories.js +72 -0
- package/dist/src/components/atoms/ContextIndicator/index.d.ts +19 -0
- package/dist/src/components/atoms/ContextIndicator/index.js +16 -0
- package/dist/src/components/atoms/ContextIndicator/utils.d.ts +1 -0
- package/dist/src/components/atoms/ContextIndicator/utils.js +9 -0
- package/dist/src/components/atoms/ContextItem/__stories__/ContextItem.stories.d.ts +6 -0
- package/dist/src/components/atoms/ContextItem/__stories__/ContextItem.stories.js +32 -0
- package/dist/src/components/atoms/ContextItem/index.d.ts +9 -0
- package/dist/src/components/atoms/ContextItem/index.js +8 -0
- package/dist/src/components/atoms/DiffStat/__stories__/DiffStat.stories.d.ts +7 -0
- package/dist/src/components/atoms/DiffStat/__stories__/DiffStat.stories.js +45 -0
- package/dist/src/components/atoms/DiffStat/index.d.ts +8 -0
- package/dist/src/components/atoms/DiffStat/index.js +8 -0
- package/dist/src/components/atoms/Disclaimer/Disclaimer.d.ts +19 -0
- package/dist/src/components/atoms/Disclaimer/Disclaimer.js +15 -0
- package/dist/src/components/atoms/Disclaimer/__stories__/Disclaimer.stories.d.ts +8 -0
- package/dist/src/components/atoms/Disclaimer/__stories__/Disclaimer.stories.js +32 -0
- package/dist/src/components/atoms/Disclaimer/index.d.ts +1 -0
- package/dist/src/components/atoms/Disclaimer/index.js +1 -0
- package/dist/src/components/atoms/InlineCitation/index.d.ts +1 -0
- package/dist/src/components/atoms/InlineCitation/index.js +1 -0
- package/dist/src/components/atoms/Loader/Loader.d.ts +9 -0
- package/dist/src/components/atoms/Loader/Loader.js +11 -0
- package/dist/src/components/atoms/Loader/__stories__/Loader.stories.d.ts +8 -0
- package/dist/src/components/atoms/Loader/__stories__/Loader.stories.js +47 -0
- package/dist/src/components/atoms/Loader/index.d.ts +1 -0
- package/dist/src/components/atoms/Loader/index.js +1 -0
- package/dist/src/components/atoms/MarkdownRenderer/MarkdownRenderer.d.ts +10 -0
- package/dist/src/components/atoms/MarkdownRenderer/MarkdownRenderer.js +24 -0
- package/dist/src/components/atoms/MarkdownRenderer/__stories__/MarkdownRenderer.stories.d.ts +6 -0
- package/dist/src/components/atoms/MarkdownRenderer/__stories__/MarkdownRenderer.stories.js +49 -0
- package/dist/src/components/atoms/MarkdownRenderer/index.d.ts +1 -0
- package/dist/src/components/atoms/MarkdownRenderer/index.js +1 -0
- package/dist/src/components/atoms/MessageBalloon/__stories__/MessageBalloon.stories.d.ts +6 -0
- package/dist/src/components/atoms/MessageBalloon/__stories__/MessageBalloon.stories.js +32 -0
- package/dist/src/components/atoms/MessageBalloon/index.d.ts +7 -0
- package/dist/src/components/atoms/MessageBalloon/index.js +8 -0
- package/dist/src/components/atoms/Shimmer/__stories__/Shimmer.stories.d.ts +5 -0
- package/dist/src/components/atoms/Shimmer/__stories__/Shimmer.stories.js +28 -0
- package/dist/src/components/atoms/Shimmer/index.d.ts +6 -0
- package/dist/src/components/atoms/Shimmer/index.js +8 -0
- package/dist/src/components/atoms/SubmitButton/SubmitButton.d.ts +37 -0
- package/dist/src/components/atoms/SubmitButton/SubmitButton.js +33 -0
- package/dist/src/components/atoms/SubmitButton/__stories__/SubmitButton.stories.d.ts +12 -0
- package/dist/src/components/atoms/SubmitButton/__stories__/SubmitButton.stories.js +95 -0
- package/dist/src/components/atoms/SubmitButton/i18n/en.json +3 -0
- package/dist/src/components/atoms/SubmitButton/i18n/index.d.ts +13 -0
- package/dist/src/components/atoms/SubmitButton/i18n/index.js +5 -0
- package/dist/src/components/atoms/SubmitButton/i18n/ru.json +3 -0
- package/dist/src/components/atoms/SubmitButton/index.d.ts +1 -0
- package/dist/src/components/atoms/SubmitButton/index.js +1 -0
- package/dist/src/components/atoms/ToolIndicator/__stories__/ToolIndicator.stories.d.ts +9 -0
- package/dist/src/components/atoms/ToolIndicator/__stories__/ToolIndicator.stories.js +34 -0
- package/dist/src/components/atoms/ToolIndicator/index.d.ts +7 -0
- package/dist/src/components/atoms/ToolIndicator/index.js +26 -0
- package/dist/src/components/atoms/index.d.ts +14 -0
- package/dist/src/components/atoms/index.js +15 -0
- package/dist/src/components/index.d.ts +5 -0
- package/dist/src/components/index.js +6 -0
- package/dist/src/components/molecules/BaseMessage/__stories__/BaseMessage.stories.d.ts +8 -0
- package/dist/src/components/molecules/BaseMessage/__stories__/BaseMessage.stories.js +66 -0
- package/dist/src/components/molecules/BaseMessage/i18n/en.json +8 -0
- package/dist/src/components/molecules/BaseMessage/i18n/index.d.ts +13 -0
- package/dist/src/components/molecules/BaseMessage/i18n/index.js +5 -0
- package/dist/src/components/molecules/BaseMessage/i18n/ru.json +8 -0
- package/dist/src/components/molecules/BaseMessage/index.d.ts +11 -0
- package/dist/src/components/molecules/BaseMessage/index.js +48 -0
- package/dist/src/components/molecules/ButtonGroup/__stories__/ButtonGroup.stories.d.ts +6 -0
- package/dist/src/components/molecules/ButtonGroup/__stories__/ButtonGroup.stories.js +44 -0
- package/dist/src/components/molecules/ButtonGroup/index.d.ts +8 -0
- package/dist/src/components/molecules/ButtonGroup/index.js +8 -0
- package/dist/src/components/molecules/InputContext/index.d.ts +1 -0
- package/dist/src/components/molecules/InputContext/index.js +1 -0
- package/dist/src/components/molecules/PromptInputBody/PromptInputBody.d.ts +39 -0
- package/dist/src/components/molecules/PromptInputBody/PromptInputBody.js +26 -0
- package/dist/src/components/molecules/PromptInputBody/__stories__/PromptInputBody.stories.d.ts +11 -0
- package/dist/src/components/molecules/PromptInputBody/__stories__/PromptInputBody.stories.js +62 -0
- package/dist/src/components/molecules/PromptInputBody/index.d.ts +1 -0
- package/dist/src/components/molecules/PromptInputBody/index.js +1 -0
- package/dist/src/components/molecules/PromptInputFooter/PromptInputFooter.d.ts +39 -0
- package/dist/src/components/molecules/PromptInputFooter/PromptInputFooter.js +26 -0
- package/dist/src/components/molecules/PromptInputFooter/__stories__/PromptInputFooter.stories.d.ts +11 -0
- package/dist/src/components/molecules/PromptInputFooter/__stories__/PromptInputFooter.stories.js +96 -0
- package/dist/src/components/molecules/PromptInputFooter/i18n/en.json +5 -0
- package/dist/src/components/molecules/PromptInputFooter/i18n/index.d.ts +13 -0
- package/dist/src/components/molecules/PromptInputFooter/i18n/index.js +5 -0
- package/dist/src/components/molecules/PromptInputFooter/i18n/ru.json +5 -0
- package/dist/src/components/molecules/PromptInputFooter/index.d.ts +1 -0
- package/dist/src/components/molecules/PromptInputFooter/index.js +1 -0
- package/dist/src/components/molecules/PromptInputHeader/PromptInputHeader.d.ts +39 -0
- package/dist/src/components/molecules/PromptInputHeader/PromptInputHeader.js +28 -0
- package/dist/src/components/molecules/PromptInputHeader/__stories__/PromptInputHeader.stories.d.ts +13 -0
- package/dist/src/components/molecules/PromptInputHeader/__stories__/PromptInputHeader.stories.js +103 -0
- package/dist/src/components/molecules/PromptInputHeader/index.d.ts +1 -0
- package/dist/src/components/molecules/PromptInputHeader/index.js +1 -0
- package/dist/src/components/molecules/PromptInputPanel/PromptInputPanel.d.ts +20 -0
- package/dist/src/components/molecules/PromptInputPanel/PromptInputPanel.js +14 -0
- package/dist/src/components/molecules/PromptInputPanel/__stories__/PromptInputPanel.stories.d.ts +8 -0
- package/dist/src/components/molecules/PromptInputPanel/__stories__/PromptInputPanel.stories.js +38 -0
- package/dist/src/components/molecules/PromptInputPanel/index.d.ts +2 -0
- package/dist/src/components/molecules/PromptInputPanel/index.js +1 -0
- package/dist/src/components/molecules/Suggestions/Suggestions.d.ts +37 -0
- package/dist/src/components/molecules/Suggestions/Suggestions.js +27 -0
- package/dist/src/components/molecules/Suggestions/__stories__/Suggestions.stories.d.ts +19 -0
- package/dist/src/components/molecules/Suggestions/__stories__/Suggestions.stories.js +143 -0
- package/dist/src/components/molecules/Suggestions/index.d.ts +1 -0
- package/dist/src/components/molecules/Suggestions/index.js +1 -0
- package/dist/src/components/molecules/Tabs/Tabs.d.ts +15 -0
- package/dist/src/components/molecules/Tabs/Tabs.js +24 -0
- package/dist/src/components/molecules/Tabs/__stories__/Tabs.stories.d.ts +9 -0
- package/dist/src/components/molecules/Tabs/__stories__/Tabs.stories.js +103 -0
- package/dist/src/components/molecules/Tabs/i18n/en.json +3 -0
- package/dist/src/components/molecules/Tabs/i18n/index.d.ts +13 -0
- package/dist/src/components/molecules/Tabs/i18n/index.js +5 -0
- package/dist/src/components/molecules/Tabs/i18n/ru.json +3 -0
- package/dist/src/components/molecules/Tabs/index.d.ts +1 -0
- package/dist/src/components/molecules/Tabs/index.js +1 -0
- package/dist/src/components/molecules/ToolFooter/__stories__/ToolFooter.stories.d.ts +7 -0
- package/dist/src/components/molecules/ToolFooter/__stories__/ToolFooter.stories.js +58 -0
- package/dist/src/components/molecules/ToolFooter/index.d.ts +3 -0
- package/dist/src/components/molecules/ToolFooter/index.js +10 -0
- package/dist/src/components/molecules/ToolHeader/__stories__/ToolHeader.stories.d.ts +7 -0
- package/dist/src/components/molecules/ToolHeader/__stories__/ToolHeader.stories.js +55 -0
- package/dist/src/components/molecules/ToolHeader/index.d.ts +3 -0
- package/dist/src/components/molecules/ToolHeader/index.js +19 -0
- package/dist/src/components/molecules/index.d.ts +11 -0
- package/dist/src/components/molecules/index.js +12 -0
- package/dist/src/components/organisms/AssistantMessage/AssistantMessage.d.ts +14 -0
- package/dist/src/components/organisms/AssistantMessage/AssistantMessage.js +31 -0
- package/dist/src/components/organisms/AssistantMessage/__stories__/AssistantMessage.stories.d.ts +13 -0
- package/dist/src/components/organisms/AssistantMessage/__stories__/AssistantMessage.stories.js +151 -0
- package/dist/src/components/organisms/AssistantMessage/defaultMessageTypeRegistry.d.ts +3 -0
- package/dist/src/components/organisms/AssistantMessage/defaultMessageTypeRegistry.js +18 -0
- package/dist/src/components/organisms/AssistantMessage/index.d.ts +1 -0
- package/dist/src/components/organisms/AssistantMessage/index.js +1 -0
- package/dist/src/components/organisms/Header/Header.d.ts +9 -0
- package/dist/src/components/organisms/Header/Header.js +65 -0
- package/dist/src/components/organisms/Header/__stories__/Header.stories.d.ts +13 -0
- package/dist/src/components/organisms/Header/__stories__/Header.stories.js +130 -0
- package/dist/src/components/organisms/Header/i18n/en.json +7 -0
- package/dist/src/components/organisms/Header/i18n/index.d.ts +13 -0
- package/dist/src/components/organisms/Header/i18n/index.js +5 -0
- package/dist/src/components/organisms/Header/i18n/ru.json +7 -0
- package/dist/src/components/organisms/Header/index.d.ts +4 -0
- package/dist/src/components/organisms/Header/index.js +6 -0
- package/dist/src/components/organisms/Header/types.d.ts +23 -0
- package/dist/src/components/organisms/Header/types.js +7 -0
- package/dist/src/components/organisms/Header/useHeader.d.ts +21 -0
- package/dist/src/components/organisms/Header/useHeader.js +71 -0
- package/dist/src/components/organisms/MessageList/ErrorAlert.d.ts +6 -0
- package/dist/src/components/organisms/MessageList/ErrorAlert.js +15 -0
- package/dist/src/components/organisms/MessageList/MessageList.d.ts +20 -0
- package/dist/src/components/organisms/MessageList/MessageList.js +21 -0
- package/dist/src/components/organisms/MessageList/__stories__/MessageList.stories.d.ts +22 -0
- package/dist/src/components/organisms/MessageList/__stories__/MessageList.stories.js +168 -0
- package/dist/src/components/organisms/MessageList/i18n/en.json +4 -0
- package/dist/src/components/organisms/MessageList/i18n/index.d.ts +13 -0
- package/dist/src/components/organisms/MessageList/i18n/index.js +5 -0
- package/dist/src/components/organisms/MessageList/i18n/ru.json +4 -0
- package/dist/src/components/organisms/MessageList/index.d.ts +1 -0
- package/dist/src/components/organisms/MessageList/index.js +1 -0
- package/dist/src/components/organisms/PromptInput/PromptInput.d.ts +44 -0
- package/dist/src/components/organisms/PromptInput/PromptInput.js +38 -0
- package/dist/src/components/organisms/PromptInput/PromptInputFull.d.ts +26 -0
- package/dist/src/components/organisms/PromptInput/PromptInputFull.js +25 -0
- package/dist/src/components/organisms/PromptInput/PromptInputSimple.d.ts +24 -0
- package/dist/src/components/organisms/PromptInput/PromptInputSimple.js +21 -0
- package/dist/src/components/organisms/PromptInput/PromptInputWithPanels.d.ts +24 -0
- package/dist/src/components/organisms/PromptInput/PromptInputWithPanels.js +19 -0
- package/dist/src/components/organisms/PromptInput/PromptInputWithSuggestions.d.ts +22 -0
- package/dist/src/components/organisms/PromptInput/PromptInputWithSuggestions.js +16 -0
- package/dist/src/components/organisms/PromptInput/__stories__/PromptInput.stories.d.ts +18 -0
- package/dist/src/components/organisms/PromptInput/__stories__/PromptInput.stories.js +278 -0
- package/dist/src/components/organisms/PromptInput/index.d.ts +8 -0
- package/dist/src/components/organisms/PromptInput/index.js +7 -0
- package/dist/src/components/organisms/PromptInput/types.d.ts +72 -0
- package/dist/src/components/organisms/PromptInput/types.js +1 -0
- package/dist/src/components/organisms/PromptInput/useDelayedUnmount.d.ts +8 -0
- package/dist/src/components/organisms/PromptInput/useDelayedUnmount.js +26 -0
- package/dist/src/components/organisms/PromptInput/usePromptInput.d.ts +52 -0
- package/dist/src/components/organisms/PromptInput/usePromptInput.js +102 -0
- package/dist/src/components/organisms/ThinkingMessage/__stories__/ThinkingMessage.stories.d.ts +12 -0
- package/dist/src/components/organisms/ThinkingMessage/__stories__/ThinkingMessage.stories.js +107 -0
- package/dist/src/components/organisms/ThinkingMessage/i18n/en.json +4 -0
- package/dist/src/components/organisms/ThinkingMessage/i18n/index.d.ts +13 -0
- package/dist/src/components/organisms/ThinkingMessage/i18n/index.js +5 -0
- package/dist/src/components/organisms/ThinkingMessage/i18n/ru.json +4 -0
- package/dist/src/components/organisms/ThinkingMessage/index.d.ts +24 -0
- package/dist/src/components/organisms/ThinkingMessage/index.js +34 -0
- package/dist/src/components/organisms/ThinkingMessage/useThinkingMessage.d.ts +18 -0
- package/dist/src/components/organisms/ThinkingMessage/useThinkingMessage.js +23 -0
- package/dist/src/components/organisms/ToolMessage/__stories__/ToolMessage.stories.d.ts +11 -0
- package/dist/src/components/organisms/ToolMessage/__stories__/ToolMessage.stories.js +70 -0
- package/dist/src/components/organisms/ToolMessage/i18n/en.json +9 -0
- package/dist/src/components/organisms/ToolMessage/i18n/index.d.ts +13 -0
- package/dist/src/components/organisms/ToolMessage/i18n/index.js +5 -0
- package/dist/src/components/organisms/ToolMessage/i18n/ru.json +9 -0
- package/dist/src/components/organisms/ToolMessage/index.d.ts +3 -0
- package/dist/src/components/organisms/ToolMessage/index.js +12 -0
- package/dist/src/components/organisms/UserMessage/__stories__/UserMessage.stories.d.ts +7 -0
- package/dist/src/components/organisms/UserMessage/__stories__/UserMessage.stories.js +70 -0
- package/dist/src/components/organisms/UserMessage/index.d.ts +13 -0
- package/dist/src/components/organisms/UserMessage/index.js +12 -0
- package/dist/src/components/organisms/index.d.ts +7 -0
- package/dist/src/components/organisms/index.js +8 -0
- package/dist/src/components/pages/ChatContainer/ChatContainer.d.ts +10 -0
- package/dist/src/components/pages/ChatContainer/ChatContainer.js +110 -0
- package/dist/src/components/pages/ChatContainer/__stories__/ChatContainer.stories.d.ts +53 -0
- package/dist/src/components/pages/ChatContainer/__stories__/ChatContainer.stories.js +707 -0
- package/dist/src/components/pages/ChatContainer/i18n/en.json +10 -0
- package/dist/src/components/pages/ChatContainer/i18n/index.d.ts +13 -0
- package/dist/src/components/pages/ChatContainer/i18n/index.js +5 -0
- package/dist/src/components/pages/ChatContainer/i18n/ru.json +10 -0
- package/dist/src/components/pages/ChatContainer/index.d.ts +2 -0
- package/dist/src/components/pages/ChatContainer/index.js +1 -0
- package/dist/src/components/pages/ChatContainer/types.d.ts +143 -0
- package/dist/src/components/pages/ChatContainer/types.js +1 -0
- package/dist/src/components/pages/ChatContainer/useChatContainer.d.ts +20 -0
- package/dist/src/components/pages/ChatContainer/useChatContainer.js +77 -0
- package/dist/src/components/pages/index.d.ts +1 -0
- package/dist/src/components/pages/index.js +2 -0
- package/dist/src/components/templates/ChatContent/ChatContent.d.ts +29 -0
- package/dist/src/components/templates/ChatContent/ChatContent.js +19 -0
- package/dist/src/components/templates/ChatContent/__stories__/ChatContent.stories.d.ts +14 -0
- package/dist/src/components/templates/ChatContent/__stories__/ChatContent.stories.js +315 -0
- package/dist/src/components/templates/ChatContent/index.d.ts +1 -0
- package/dist/src/components/templates/ChatContent/index.js +1 -0
- package/dist/src/components/templates/EmptyContainer/EmptyContainer.d.ts +57 -0
- package/dist/src/components/templates/EmptyContainer/EmptyContainer.js +26 -0
- package/dist/src/components/templates/EmptyContainer/__stories__/EmptyContainer.stories.d.ts +20 -0
- package/dist/src/components/templates/EmptyContainer/__stories__/EmptyContainer.stories.js +250 -0
- package/dist/src/components/templates/EmptyContainer/i18n/en.json +3 -0
- package/dist/src/components/templates/EmptyContainer/i18n/index.d.ts +13 -0
- package/dist/src/components/templates/EmptyContainer/i18n/index.js +5 -0
- package/dist/src/components/templates/EmptyContainer/i18n/ru.json +3 -0
- package/dist/src/components/templates/EmptyContainer/index.d.ts +1 -0
- package/dist/src/components/templates/EmptyContainer/index.js +1 -0
- package/dist/src/components/templates/History/ChatItem.d.ts +17 -0
- package/dist/src/components/templates/History/ChatItem.js +18 -0
- package/dist/src/components/templates/History/DateHeaderItem.d.ts +12 -0
- package/dist/src/components/templates/History/DateHeaderItem.js +12 -0
- package/dist/src/components/templates/History/History.d.ts +46 -0
- package/dist/src/components/templates/History/History.js +16 -0
- package/dist/src/components/templates/History/HistoryList.d.ts +43 -0
- package/dist/src/components/templates/History/HistoryList.js +87 -0
- package/dist/src/components/templates/History/__stories__/History.stories.d.ts +17 -0
- package/dist/src/components/templates/History/__stories__/History.stories.js +281 -0
- package/dist/src/components/templates/History/i18n/en.json +7 -0
- package/dist/src/components/templates/History/i18n/index.d.ts +13 -0
- package/dist/src/components/templates/History/i18n/index.js +5 -0
- package/dist/src/components/templates/History/i18n/ru.json +7 -0
- package/dist/src/components/templates/History/index.d.ts +8 -0
- package/dist/src/components/templates/History/index.js +4 -0
- package/dist/src/components/templates/index.d.ts +3 -0
- package/dist/src/components/templates/index.js +4 -0
- package/dist/src/constants/index.d.ts +1 -0
- package/dist/src/constants/index.js +1 -0
- package/dist/src/demo/ContentWrapper/ContentWrapper.d.ts +7 -0
- package/dist/src/demo/ContentWrapper/ContentWrapper.js +7 -0
- package/dist/src/demo/ContentWrapper/index.d.ts +1 -0
- package/dist/src/demo/ContentWrapper/index.js +1 -0
- package/dist/src/demo/DocsDecorator/DocsDecorator.d.ts +6 -0
- package/dist/src/demo/DocsDecorator/DocsDecorator.js +12 -0
- package/dist/src/demo/DocsDecorator/ThemeContext.d.ts +2 -0
- package/dist/src/demo/DocsDecorator/ThemeContext.js +2 -0
- package/dist/src/demo/Showcase/Showcase.d.ts +9 -0
- package/dist/src/demo/Showcase/Showcase.js +7 -0
- package/dist/src/demo/Showcase/index.d.ts +1 -0
- package/dist/src/demo/Showcase/index.js +1 -0
- package/dist/src/demo/ShowcaseItem/ShowcaseItem.d.ts +7 -0
- package/dist/src/demo/ShowcaseItem/ShowcaseItem.js +7 -0
- package/dist/src/demo/ShowcaseItem/index.d.ts +1 -0
- package/dist/src/demo/ShowcaseItem/index.js +1 -0
- package/dist/src/demo/SwapArea/SwapArea.d.ts +2 -0
- package/dist/src/demo/SwapArea/SwapArea.js +7 -0
- package/dist/src/demo/SwapArea/index.d.ts +1 -0
- package/dist/src/demo/SwapArea/index.js +1 -0
- package/dist/src/hooks/index.d.ts +2 -0
- package/dist/src/hooks/index.js +2 -0
- package/dist/src/hooks/useDateFormatter/index.d.ts +34 -0
- package/dist/src/hooks/useDateFormatter/index.js +101 -0
- package/dist/src/hooks/useToolMessage.d.ts +11 -0
- package/dist/src/hooks/useToolMessage.js +96 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +19 -0
- package/dist/src/types/chat.d.ts +17 -0
- package/dist/src/types/chat.js +1 -0
- package/dist/src/types/common.d.ts +7 -0
- package/dist/src/types/common.js +1 -0
- package/dist/src/types/index.d.ts +4 -0
- package/dist/src/types/index.js +4 -0
- package/dist/src/types/messages.d.ts +62 -0
- package/dist/src/types/messages.js +1 -0
- package/dist/src/types/tool.d.ts +34 -0
- package/dist/src/types/tool.js +1 -0
- package/dist/src/utils/chatUtils.d.ts +23 -0
- package/dist/src/utils/chatUtils.js +43 -0
- package/dist/src/utils/cn.d.ts +11 -0
- package/dist/src/utils/cn.js +12 -0
- package/dist/src/utils/index.d.ts +4 -0
- package/dist/src/utils/index.js +5 -0
- package/dist/src/utils/messageTypeRegistry.d.ts +13 -0
- package/dist/src/utils/messageTypeRegistry.js +16 -0
- package/dist/src/utils/messageUtils.d.ts +4 -0
- package/dist/src/utils/messageUtils.js +25 -0
- package/dist/src/utils/validation.d.ts +16 -0
- package/dist/src/utils/validation.js +24 -0
- package/package.json +111 -0
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { Sparkles } from '@gravity-ui/icons';
|
|
5
|
+
import { Icon } from '@gravity-ui/uikit';
|
|
6
|
+
import { ChatContainer } from '..';
|
|
7
|
+
import { ContentWrapper } from '../../../../demo/ContentWrapper';
|
|
8
|
+
import MDXDocs from './Docs.mdx';
|
|
9
|
+
export default {
|
|
10
|
+
title: 'pages/ChatContainer',
|
|
11
|
+
component: ChatContainer,
|
|
12
|
+
parameters: {
|
|
13
|
+
docs: {
|
|
14
|
+
page: MDXDocs,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const defaultDecorators = [
|
|
19
|
+
(Story) => (_jsx(ContentWrapper, { height: "800px", width: "600px", children: _jsx(Story, {}) })),
|
|
20
|
+
];
|
|
21
|
+
// Mock data
|
|
22
|
+
const mockSuggestions = [
|
|
23
|
+
{
|
|
24
|
+
id: '1',
|
|
25
|
+
content: 'Explain quantum computing in simple terms',
|
|
26
|
+
label: 'Quantum Computing',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: '2',
|
|
30
|
+
content: 'Write a poem about nature',
|
|
31
|
+
label: 'Creative Writing',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: '3',
|
|
35
|
+
content: 'Help me debug my JavaScript code',
|
|
36
|
+
label: 'Debug Code',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: '4',
|
|
40
|
+
content: 'Summarize recent AI developments',
|
|
41
|
+
label: 'AI News',
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
const mockChats = [
|
|
45
|
+
{
|
|
46
|
+
id: '1',
|
|
47
|
+
name: 'Quantum Computing Discussion',
|
|
48
|
+
createTime: new Date(Date.now() - 1000 * 60 * 60).toISOString(),
|
|
49
|
+
lastMessage: 'Thanks for explaining quantum entanglement!',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: '2',
|
|
53
|
+
name: 'Poetry Writing Session',
|
|
54
|
+
createTime: new Date(Date.now() - 1000 * 60 * 60 * 24).toISOString(),
|
|
55
|
+
lastMessage: 'That was a beautiful poem about autumn.',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: '3',
|
|
59
|
+
name: 'Code Debugging Help',
|
|
60
|
+
createTime: new Date(Date.now() - 1000 * 60 * 60 * 24 * 2).toISOString(),
|
|
61
|
+
lastMessage: 'The bug was in the async function.',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: '4',
|
|
65
|
+
name: 'AI News Summary',
|
|
66
|
+
createTime: new Date(Date.now() - 1000 * 60 * 60 * 24 * 3).toISOString(),
|
|
67
|
+
lastMessage: 'Thanks for the comprehensive summary!',
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
/**
|
|
71
|
+
* Mock messages for different chats
|
|
72
|
+
* Each chat has its own conversation history
|
|
73
|
+
* Keys correspond to chat IDs from mockChats
|
|
74
|
+
*/
|
|
75
|
+
const mockChatMessages = {
|
|
76
|
+
'1': [
|
|
77
|
+
{
|
|
78
|
+
id: '1-1',
|
|
79
|
+
role: 'user',
|
|
80
|
+
content: 'What is quantum computing?',
|
|
81
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 60).toISOString(),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: '1-2',
|
|
85
|
+
role: 'assistant',
|
|
86
|
+
content: 'Quantum computing is a revolutionary approach to computation that leverages the principles of quantum mechanics. Unlike classical computers that use bits (0 or 1), quantum computers use quantum bits or "qubits" that can exist in multiple states simultaneously through a phenomenon called superposition.\n\nKey concepts include:\n1. **Superposition**: Qubits can be in multiple states at once\n2. **Entanglement**: Qubits can be correlated in ways that classical bits cannot\n3. **Quantum Interference**: Used to amplify correct answers and cancel out wrong ones',
|
|
87
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 59).toISOString(),
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
id: '1-3',
|
|
91
|
+
role: 'user',
|
|
92
|
+
content: 'Can you explain quantum entanglement in simple terms?',
|
|
93
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 58).toISOString(),
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: '1-4',
|
|
97
|
+
role: 'assistant',
|
|
98
|
+
content: 'Quantum entanglement is like having two magic coins that are mysteriously connected. When you flip one coin and it lands on heads, the other coin - no matter how far away - will instantly land on tails (or vice versa).\n\nIn quantum physics terms:\n- Two particles become "entangled" and share a quantum state\n- Measuring one particle instantly affects the other\n- This happens regardless of the distance between them\n- Einstein called it "spooky action at a distance"\n\nThis phenomenon is fundamental to quantum computing and quantum communication technologies.',
|
|
99
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 57).toISOString(),
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
'2': [
|
|
103
|
+
{
|
|
104
|
+
id: '2-1',
|
|
105
|
+
role: 'user',
|
|
106
|
+
content: 'Write a poem about autumn leaves',
|
|
107
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24).toISOString(),
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
id: '2-2',
|
|
111
|
+
role: 'assistant',
|
|
112
|
+
content: "Golden whispers fall from trees,\nDancing softly on the breeze,\nCrimsons, ambers, russet bright,\nPainting pathways with their light.\n\nNature's canvas, rich and warm,\nBefore the coming winter storm,\nEach leaf a story, each one told,\nOf seasons passing, growing old.",
|
|
113
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24 + 60000).toISOString(),
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
id: '2-3',
|
|
117
|
+
role: 'user',
|
|
118
|
+
content: 'That was beautiful! Can you write one about winter snow?',
|
|
119
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24 + 120000).toISOString(),
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
id: '2-4',
|
|
123
|
+
role: 'assistant',
|
|
124
|
+
content: "Snowflakes drift from silent skies,\nBlankets white before our eyes,\nCrystal diamonds, soft and pure,\nWinter's gentle signature.\n\nFrosted windows, frozen streams,\nLandscapes wrapped in silver dreams,\nQuiet peace in cold embrace,\nNature sleeps in gentle grace.",
|
|
125
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24 + 180000).toISOString(),
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
'3': [
|
|
129
|
+
{
|
|
130
|
+
id: '3-1',
|
|
131
|
+
role: 'user',
|
|
132
|
+
content: "I have a bug in my async function. It's not waiting for the promise to resolve.",
|
|
133
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24 * 2).toISOString(),
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
id: '3-2',
|
|
137
|
+
role: 'assistant',
|
|
138
|
+
content: "Let's debug this step by step. The most common issues with async/await are:\n\n1. **Missing await keyword**: Make sure you're using `await` before the promise\n2. **Function not marked as async**: The function must be declared with `async` keyword\n3. **Promise not being returned**: Ensure the function returns a promise\n\nCan you share your code? Here's a common pattern:\n\n```javascript\nasync function fetchData() {\n const result = await fetch('/api/data');\n const data = await result.json();\n return data;\n}\n```",
|
|
139
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24 * 2 + 60000).toISOString(),
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: '3-3',
|
|
143
|
+
role: 'user',
|
|
144
|
+
content: 'Oh! I forgot to mark the parent function as async. That was the issue. Thanks!',
|
|
145
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24 * 2 + 120000).toISOString(),
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: '3-4',
|
|
149
|
+
role: 'assistant',
|
|
150
|
+
content: "Great! That's a very common mistake. Remember: to use `await`, the containing function must be `async`. Also, if you're using `await` in a callback (like in `.map()` or `.forEach()`), make sure to make the callback function async too. Happy coding!",
|
|
151
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24 * 2 + 180000).toISOString(),
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
'4': [
|
|
155
|
+
{
|
|
156
|
+
id: '4-1',
|
|
157
|
+
role: 'user',
|
|
158
|
+
content: 'What are the latest developments in AI?',
|
|
159
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24 * 3).toISOString(),
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
id: '4-2',
|
|
163
|
+
role: 'assistant',
|
|
164
|
+
content: 'Recent AI developments include:\n\n**Large Language Models**\n- More efficient training methods\n- Better reasoning capabilities\n- Multimodal models (text, image, audio)\n\n**Computer Vision**\n- Improved object detection and segmentation\n- Real-time video analysis\n- 3D reconstruction from 2D images\n\n**AI Safety**\n- Constitutional AI and alignment research\n- Better interpretability tools\n- Red-teaming and safety testing\n\n**Edge AI**\n- Running models on mobile devices\n- Reduced latency for real-time applications\n- Privacy-preserving local inference',
|
|
165
|
+
timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24 * 3 + 60000).toISOString(),
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
};
|
|
169
|
+
// Default messages for first chat
|
|
170
|
+
const mockMessages = mockChatMessages['1'];
|
|
171
|
+
/**
|
|
172
|
+
* Create message actions with handlers
|
|
173
|
+
* @param messageId - Message identifier
|
|
174
|
+
* @param role - Message role (user or assistant)
|
|
175
|
+
* @returns Array of message actions
|
|
176
|
+
*/
|
|
177
|
+
const createMessageActions = (messageId, role) => {
|
|
178
|
+
const actions = [
|
|
179
|
+
{
|
|
180
|
+
type: 'copy',
|
|
181
|
+
onClick: () => console.log(`Copy message ${messageId}`),
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
if (role === 'user') {
|
|
185
|
+
actions.push({
|
|
186
|
+
type: 'edit',
|
|
187
|
+
onClick: () => console.log(`Edit message ${messageId}`),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
if (role === 'assistant') {
|
|
191
|
+
actions.push({
|
|
192
|
+
type: 'like',
|
|
193
|
+
onClick: () => console.log(`Like message ${messageId}`),
|
|
194
|
+
}, {
|
|
195
|
+
type: 'unlike',
|
|
196
|
+
onClick: () => console.log(`Unlike message ${messageId}`),
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return actions;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Add actions to messages
|
|
203
|
+
* @param messages - Array of messages
|
|
204
|
+
* @returns Array of messages with actions added
|
|
205
|
+
*/
|
|
206
|
+
const addActionsToMessages = (messages) => {
|
|
207
|
+
return messages.map((msg) => (Object.assign(Object.assign({}, msg), { actions: createMessageActions(msg.id || 'unknown', msg.role) })));
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Playground story for interactive testing
|
|
211
|
+
*/
|
|
212
|
+
export const Playground = {
|
|
213
|
+
args: {
|
|
214
|
+
messages: [],
|
|
215
|
+
chats: mockChats,
|
|
216
|
+
showHistory: true,
|
|
217
|
+
showNewChat: true,
|
|
218
|
+
showClose: false,
|
|
219
|
+
welcomeConfig: {
|
|
220
|
+
title: 'Welcome to AI Chat',
|
|
221
|
+
description: 'Start a conversation by typing a message or selecting a suggestion.',
|
|
222
|
+
suggestionTitle: 'Try asking:',
|
|
223
|
+
suggestions: mockSuggestions,
|
|
224
|
+
},
|
|
225
|
+
showActionsOnHover: true,
|
|
226
|
+
},
|
|
227
|
+
render: (args) => {
|
|
228
|
+
const initialChat = mockChats[0];
|
|
229
|
+
const [messages, setMessages] = useState(addActionsToMessages(mockChatMessages[initialChat.id] || []));
|
|
230
|
+
const [status, setStatus] = useState('ready');
|
|
231
|
+
const [activeChat, setActiveChat] = useState(initialChat);
|
|
232
|
+
const handleSendMessage = async (data) => {
|
|
233
|
+
const userMessage = {
|
|
234
|
+
id: Date.now().toString(),
|
|
235
|
+
role: 'user',
|
|
236
|
+
content: data.content,
|
|
237
|
+
timestamp: new Date().toISOString(),
|
|
238
|
+
actions: createMessageActions(Date.now().toString(), 'user'),
|
|
239
|
+
};
|
|
240
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
241
|
+
// Simulate streaming
|
|
242
|
+
setStatus('streaming');
|
|
243
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
244
|
+
const assistantMessageId = (Date.now() + 1).toString();
|
|
245
|
+
const assistantMessage = {
|
|
246
|
+
id: assistantMessageId,
|
|
247
|
+
role: 'assistant',
|
|
248
|
+
content: `This is a mock response to: "${data.content}". In a real application, this would be a streamed response from an AI model.`,
|
|
249
|
+
timestamp: new Date().toISOString(),
|
|
250
|
+
actions: createMessageActions(assistantMessageId, 'assistant'),
|
|
251
|
+
};
|
|
252
|
+
setMessages((prev) => [...prev, assistantMessage]);
|
|
253
|
+
setStatus('ready');
|
|
254
|
+
};
|
|
255
|
+
const handleSelectChat = (chat) => {
|
|
256
|
+
setActiveChat(chat);
|
|
257
|
+
// Load messages for selected chat
|
|
258
|
+
const chatMessages = mockChatMessages[chat.id] || [];
|
|
259
|
+
setMessages(addActionsToMessages(chatMessages));
|
|
260
|
+
};
|
|
261
|
+
const handleCreateChat = () => {
|
|
262
|
+
setActiveChat(null);
|
|
263
|
+
setMessages([]);
|
|
264
|
+
};
|
|
265
|
+
return (_jsx(ChatContainer, Object.assign({}, args, { messages: messages, activeChat: activeChat, onSendMessage: handleSendMessage, onSelectChat: handleSelectChat, onCreateChat: handleCreateChat, status: status })));
|
|
266
|
+
},
|
|
267
|
+
decorators: defaultDecorators,
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* Empty state with welcome screen
|
|
271
|
+
*/
|
|
272
|
+
export const EmptyState = {
|
|
273
|
+
args: {
|
|
274
|
+
messages: [],
|
|
275
|
+
welcomeConfig: {
|
|
276
|
+
image: _jsx(Icon, { data: Sparkles, size: 48 }),
|
|
277
|
+
title: 'Welcome to AI Chat',
|
|
278
|
+
description: 'Start a conversation by typing a message or selecting a suggestion.',
|
|
279
|
+
suggestionTitle: 'Try asking:',
|
|
280
|
+
suggestions: mockSuggestions,
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
render: (args) => {
|
|
284
|
+
const [messages, setMessages] = useState([]);
|
|
285
|
+
const handleSendMessage = async (data) => {
|
|
286
|
+
const userMessage = {
|
|
287
|
+
id: Date.now().toString(),
|
|
288
|
+
role: 'user',
|
|
289
|
+
content: data.content,
|
|
290
|
+
};
|
|
291
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
292
|
+
};
|
|
293
|
+
return _jsx(ChatContainer, Object.assign({}, args, { messages: messages, onSendMessage: handleSendMessage }));
|
|
294
|
+
},
|
|
295
|
+
decorators: defaultDecorators,
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* State with messages
|
|
299
|
+
*/
|
|
300
|
+
export const WithMessages = {
|
|
301
|
+
args: {
|
|
302
|
+
messages: mockMessages,
|
|
303
|
+
chats: mockChats,
|
|
304
|
+
activeChat: mockChats[0],
|
|
305
|
+
showActionsOnHover: true,
|
|
306
|
+
},
|
|
307
|
+
render: (args) => {
|
|
308
|
+
const [messages, setMessages] = useState(addActionsToMessages(args.messages || []));
|
|
309
|
+
const handleSendMessage = async (data) => {
|
|
310
|
+
const userMessageId = Date.now().toString();
|
|
311
|
+
const userMessage = {
|
|
312
|
+
id: userMessageId,
|
|
313
|
+
role: 'user',
|
|
314
|
+
content: data.content,
|
|
315
|
+
actions: createMessageActions(userMessageId, 'user'),
|
|
316
|
+
};
|
|
317
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
318
|
+
};
|
|
319
|
+
return _jsx(ChatContainer, Object.assign({}, args, { messages: messages, onSendMessage: handleSendMessage }));
|
|
320
|
+
},
|
|
321
|
+
decorators: defaultDecorators,
|
|
322
|
+
};
|
|
323
|
+
/**
|
|
324
|
+
* With streaming
|
|
325
|
+
*/
|
|
326
|
+
export const WithStreaming = {
|
|
327
|
+
args: {
|
|
328
|
+
messages: mockMessages,
|
|
329
|
+
showActionsOnHover: true,
|
|
330
|
+
},
|
|
331
|
+
render: (args) => {
|
|
332
|
+
const [messages, setMessages] = useState(addActionsToMessages(args.messages || []));
|
|
333
|
+
const [status, setStatus] = useState('ready');
|
|
334
|
+
const handleSendMessage = async (data) => {
|
|
335
|
+
const userMessageId = Date.now().toString();
|
|
336
|
+
const userMessage = {
|
|
337
|
+
id: userMessageId,
|
|
338
|
+
role: 'user',
|
|
339
|
+
content: data.content,
|
|
340
|
+
actions: createMessageActions(userMessageId, 'user'),
|
|
341
|
+
};
|
|
342
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
343
|
+
// Simulate streaming
|
|
344
|
+
setStatus('streaming');
|
|
345
|
+
const assistantMessageId = (Date.now() + 1).toString();
|
|
346
|
+
const fullResponse = 'This is a simulated streaming response. In a real application, this text would appear word by word as it streams from the AI model. Streaming provides a better user experience for long responses.';
|
|
347
|
+
// Add empty message
|
|
348
|
+
setMessages((prev) => [
|
|
349
|
+
...prev,
|
|
350
|
+
{
|
|
351
|
+
id: assistantMessageId,
|
|
352
|
+
role: 'assistant',
|
|
353
|
+
content: '',
|
|
354
|
+
actions: createMessageActions(assistantMessageId, 'assistant'),
|
|
355
|
+
},
|
|
356
|
+
]);
|
|
357
|
+
// Simulate word-by-word streaming
|
|
358
|
+
const words = fullResponse.split(' ');
|
|
359
|
+
for (let i = 0; i < words.length; i++) {
|
|
360
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
361
|
+
const currentText = words.slice(0, i + 1).join(' ');
|
|
362
|
+
setMessages((prev) => prev.map((msg) => msg.id === assistantMessageId ? Object.assign(Object.assign({}, msg), { content: currentText }) : msg));
|
|
363
|
+
}
|
|
364
|
+
setStatus('ready');
|
|
365
|
+
};
|
|
366
|
+
const handleCancel = async () => {
|
|
367
|
+
setStatus('ready');
|
|
368
|
+
};
|
|
369
|
+
return (_jsx(ChatContainer, Object.assign({}, args, { messages: messages, onSendMessage: handleSendMessage, onCancel: handleCancel, status: status })));
|
|
370
|
+
},
|
|
371
|
+
decorators: defaultDecorators,
|
|
372
|
+
};
|
|
373
|
+
/**
|
|
374
|
+
* With history
|
|
375
|
+
*/
|
|
376
|
+
export const WithHistory = {
|
|
377
|
+
args: {
|
|
378
|
+
messages: mockMessages,
|
|
379
|
+
chats: mockChats,
|
|
380
|
+
activeChat: mockChats[0],
|
|
381
|
+
showHistory: true,
|
|
382
|
+
showActionsOnHover: true,
|
|
383
|
+
},
|
|
384
|
+
render: (args) => {
|
|
385
|
+
const [messages, setMessages] = useState(addActionsToMessages(args.messages || []));
|
|
386
|
+
const [chats, setChats] = useState(args.chats || []);
|
|
387
|
+
const [activeChat, setActiveChat] = useState(args.activeChat || null);
|
|
388
|
+
const handleSendMessage = async (data) => {
|
|
389
|
+
const userMessageId = Date.now().toString();
|
|
390
|
+
const userMessage = {
|
|
391
|
+
id: userMessageId,
|
|
392
|
+
role: 'user',
|
|
393
|
+
content: data.content,
|
|
394
|
+
actions: createMessageActions(userMessageId, 'user'),
|
|
395
|
+
};
|
|
396
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
397
|
+
};
|
|
398
|
+
const handleSelectChat = (chat) => {
|
|
399
|
+
setActiveChat(chat);
|
|
400
|
+
// Load messages for selected chat
|
|
401
|
+
const chatMessages = mockChatMessages[chat.id] || [];
|
|
402
|
+
setMessages(addActionsToMessages(chatMessages));
|
|
403
|
+
};
|
|
404
|
+
const handleCreateChat = () => {
|
|
405
|
+
const newChat = {
|
|
406
|
+
id: Date.now().toString(),
|
|
407
|
+
name: 'New Chat',
|
|
408
|
+
createTime: new Date().toISOString(),
|
|
409
|
+
};
|
|
410
|
+
setChats((prev) => [newChat, ...prev]);
|
|
411
|
+
setActiveChat(newChat);
|
|
412
|
+
setMessages([]);
|
|
413
|
+
};
|
|
414
|
+
const handleDeleteChat = (chat) => {
|
|
415
|
+
setChats((prev) => prev.filter((c) => c.id !== chat.id));
|
|
416
|
+
if ((activeChat === null || activeChat === void 0 ? void 0 : activeChat.id) === chat.id) {
|
|
417
|
+
setActiveChat(null);
|
|
418
|
+
setMessages([]);
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
return (_jsx(ChatContainer, Object.assign({}, args, { messages: messages, chats: chats, activeChat: activeChat, onSendMessage: handleSendMessage, onSelectChat: handleSelectChat, onCreateChat: handleCreateChat, onDeleteChat: handleDeleteChat })));
|
|
422
|
+
},
|
|
423
|
+
decorators: defaultDecorators,
|
|
424
|
+
};
|
|
425
|
+
/**
|
|
426
|
+
* With custom i18n configuration
|
|
427
|
+
*/
|
|
428
|
+
export const WithI18nConfig = {
|
|
429
|
+
args: {
|
|
430
|
+
messages: [],
|
|
431
|
+
i18nConfig: {
|
|
432
|
+
header: {
|
|
433
|
+
defaultTitle: 'My Custom AI Assistant',
|
|
434
|
+
},
|
|
435
|
+
emptyState: {
|
|
436
|
+
title: 'Hello!',
|
|
437
|
+
description: 'How can I help you today?',
|
|
438
|
+
suggestionsTitle: 'Quick actions:',
|
|
439
|
+
},
|
|
440
|
+
promptInput: {
|
|
441
|
+
placeholder: 'Ask me anything...',
|
|
442
|
+
},
|
|
443
|
+
disclaimer: {
|
|
444
|
+
text: 'Custom disclaimer text here.',
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
welcomeConfig: {
|
|
448
|
+
suggestions: mockSuggestions.slice(0, 2),
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
render: (args) => {
|
|
452
|
+
const [messages, setMessages] = useState([]);
|
|
453
|
+
const handleSendMessage = async (data) => {
|
|
454
|
+
const userMessage = {
|
|
455
|
+
id: Date.now().toString(),
|
|
456
|
+
role: 'user',
|
|
457
|
+
content: data.content,
|
|
458
|
+
};
|
|
459
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
460
|
+
};
|
|
461
|
+
return _jsx(ChatContainer, Object.assign({}, args, { messages: messages, onSendMessage: handleSendMessage }));
|
|
462
|
+
},
|
|
463
|
+
decorators: defaultDecorators,
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
* With component props override
|
|
467
|
+
*/
|
|
468
|
+
export const WithComponentPropsOverride = {
|
|
469
|
+
args: {
|
|
470
|
+
messages: mockMessages,
|
|
471
|
+
headerProps: {
|
|
472
|
+
titlePosition: 'center',
|
|
473
|
+
},
|
|
474
|
+
promptInputProps: {
|
|
475
|
+
view: 'full',
|
|
476
|
+
maxLength: 2000,
|
|
477
|
+
},
|
|
478
|
+
historyProps: {
|
|
479
|
+
groupBy: 'none',
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
render: (args) => {
|
|
483
|
+
const [messages, setMessages] = useState(args.messages || []);
|
|
484
|
+
const handleSendMessage = async (data) => {
|
|
485
|
+
const userMessage = {
|
|
486
|
+
id: Date.now().toString(),
|
|
487
|
+
role: 'user',
|
|
488
|
+
content: data.content,
|
|
489
|
+
};
|
|
490
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
491
|
+
};
|
|
492
|
+
return _jsx(ChatContainer, Object.assign({}, args, { messages: messages, onSendMessage: handleSendMessage }));
|
|
493
|
+
},
|
|
494
|
+
decorators: defaultDecorators,
|
|
495
|
+
};
|
|
496
|
+
/**
|
|
497
|
+
* With context items
|
|
498
|
+
*/
|
|
499
|
+
export const WithContextItems = {
|
|
500
|
+
args: {
|
|
501
|
+
messages: mockMessages,
|
|
502
|
+
promptInputProps: {
|
|
503
|
+
view: 'full',
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
render: (args) => {
|
|
507
|
+
const [messages, setMessages] = useState(args.messages || []);
|
|
508
|
+
const [contextItems, setContextItems] = useState([
|
|
509
|
+
{ id: '1', content: 'ChatContainer.tsx', onRemove: () => { } },
|
|
510
|
+
{ id: '2', content: 'types.ts', onRemove: () => { } },
|
|
511
|
+
{ id: '3', content: 'README.md', onRemove: () => { } },
|
|
512
|
+
]);
|
|
513
|
+
const handleSendMessage = async (data) => {
|
|
514
|
+
const userMessage = {
|
|
515
|
+
id: Date.now().toString(),
|
|
516
|
+
role: 'user',
|
|
517
|
+
content: data.content,
|
|
518
|
+
};
|
|
519
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
520
|
+
};
|
|
521
|
+
const handleRemoveContext = (id) => {
|
|
522
|
+
setContextItems((prev) => prev.filter((item) => item.id !== id));
|
|
523
|
+
};
|
|
524
|
+
return (_jsx(ChatContainer, Object.assign({}, args, { messages: messages, onSendMessage: handleSendMessage, contextItems: contextItems.map((item) => (Object.assign(Object.assign({}, item), { onRemove: () => handleRemoveContext(item.id) }))) })));
|
|
525
|
+
},
|
|
526
|
+
decorators: defaultDecorators,
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* With context items and indicator
|
|
530
|
+
*/
|
|
531
|
+
export const WithContextItemsAndIndicator = {
|
|
532
|
+
args: {
|
|
533
|
+
messages: mockMessages,
|
|
534
|
+
promptInputProps: {
|
|
535
|
+
view: 'full',
|
|
536
|
+
headerProps: {
|
|
537
|
+
showContextIndicator: true,
|
|
538
|
+
contextIndicatorProps: {
|
|
539
|
+
type: 'percent',
|
|
540
|
+
usedContext: 75,
|
|
541
|
+
},
|
|
542
|
+
},
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
render: (args) => {
|
|
546
|
+
const [messages, setMessages] = useState(args.messages || []);
|
|
547
|
+
const [contextItems, setContextItems] = useState([
|
|
548
|
+
{ id: '1', content: 'file.tsx', onRemove: () => { } },
|
|
549
|
+
{ id: '2', content: 'component.tsx', onRemove: () => { } },
|
|
550
|
+
]);
|
|
551
|
+
const handleSendMessage = async (data) => {
|
|
552
|
+
const userMessage = {
|
|
553
|
+
id: Date.now().toString(),
|
|
554
|
+
role: 'user',
|
|
555
|
+
content: data.content,
|
|
556
|
+
};
|
|
557
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
558
|
+
};
|
|
559
|
+
const handleRemoveContext = (id) => {
|
|
560
|
+
setContextItems((prev) => prev.filter((item) => item.id !== id));
|
|
561
|
+
};
|
|
562
|
+
return (_jsx(ChatContainer, Object.assign({}, args, { messages: messages, onSendMessage: handleSendMessage, contextItems: contextItems.map((item) => (Object.assign(Object.assign({}, item), { onRemove: () => handleRemoveContext(item.id) }))) })));
|
|
563
|
+
},
|
|
564
|
+
decorators: defaultDecorators,
|
|
565
|
+
};
|
|
566
|
+
/**
|
|
567
|
+
* With loading state
|
|
568
|
+
*/
|
|
569
|
+
export const LoadingState = {
|
|
570
|
+
args: {
|
|
571
|
+
messages: addActionsToMessages(mockMessages),
|
|
572
|
+
status: 'submitted',
|
|
573
|
+
showActionsOnHover: true,
|
|
574
|
+
},
|
|
575
|
+
render: (args) => {
|
|
576
|
+
return _jsx(ChatContainer, Object.assign({}, args, { onSendMessage: async () => { } }));
|
|
577
|
+
},
|
|
578
|
+
decorators: defaultDecorators,
|
|
579
|
+
};
|
|
580
|
+
/**
|
|
581
|
+
* With error
|
|
582
|
+
*/
|
|
583
|
+
export const ErrorState = {
|
|
584
|
+
args: {
|
|
585
|
+
messages: addActionsToMessages(mockMessages),
|
|
586
|
+
status: 'error',
|
|
587
|
+
error: new Error('Failed to send message. Please try again.'),
|
|
588
|
+
showActionsOnHover: true,
|
|
589
|
+
},
|
|
590
|
+
render: (args) => {
|
|
591
|
+
const [messages, setMessages] = useState(args.messages || []);
|
|
592
|
+
const handleSendMessage = async (data) => {
|
|
593
|
+
const userMessageId = Date.now().toString();
|
|
594
|
+
const userMessage = {
|
|
595
|
+
id: userMessageId,
|
|
596
|
+
role: 'user',
|
|
597
|
+
content: data.content,
|
|
598
|
+
actions: createMessageActions(userMessageId, 'user'),
|
|
599
|
+
};
|
|
600
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
601
|
+
};
|
|
602
|
+
return _jsx(ChatContainer, Object.assign({}, args, { messages: messages, onSendMessage: handleSendMessage }));
|
|
603
|
+
},
|
|
604
|
+
decorators: defaultDecorators,
|
|
605
|
+
};
|
|
606
|
+
/**
|
|
607
|
+
* Full example with realistic streaming via fetch API
|
|
608
|
+
*/
|
|
609
|
+
export const FullStreamingExample = {
|
|
610
|
+
args: {
|
|
611
|
+
messages: [],
|
|
612
|
+
chats: mockChats,
|
|
613
|
+
activeChat: mockChats[0],
|
|
614
|
+
showHistory: true,
|
|
615
|
+
showNewChat: true,
|
|
616
|
+
welcomeConfig: {
|
|
617
|
+
image: _jsx(Icon, { data: Sparkles, size: 48 }),
|
|
618
|
+
title: 'AI Streaming Chat',
|
|
619
|
+
description: 'Experience real-time streaming responses',
|
|
620
|
+
suggestionTitle: 'Try these prompts:',
|
|
621
|
+
suggestions: mockSuggestions,
|
|
622
|
+
},
|
|
623
|
+
showActionsOnHover: true,
|
|
624
|
+
},
|
|
625
|
+
render: (args) => {
|
|
626
|
+
const initialChat = mockChats[0];
|
|
627
|
+
const [messages, setMessages] = useState(addActionsToMessages(mockChatMessages[initialChat.id] || []));
|
|
628
|
+
const [activeChat, setActiveChat] = useState(initialChat);
|
|
629
|
+
const [status, setStatus] = useState('ready');
|
|
630
|
+
const [controller, setController] = useState(null);
|
|
631
|
+
const handleSendMessage = async (data) => {
|
|
632
|
+
// Add user message
|
|
633
|
+
const userMessageId = Date.now().toString();
|
|
634
|
+
const userMessage = {
|
|
635
|
+
id: userMessageId,
|
|
636
|
+
role: 'user',
|
|
637
|
+
content: data.content,
|
|
638
|
+
timestamp: new Date().toISOString(),
|
|
639
|
+
actions: createMessageActions(userMessageId, 'user'),
|
|
640
|
+
};
|
|
641
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
642
|
+
// Start streaming
|
|
643
|
+
setStatus('streaming');
|
|
644
|
+
const abortController = new AbortController();
|
|
645
|
+
setController(abortController);
|
|
646
|
+
try {
|
|
647
|
+
// In real app, this would be a fetch to API
|
|
648
|
+
// const response = await fetch('/api/chat/stream', {
|
|
649
|
+
// method: 'POST',
|
|
650
|
+
// headers: {'Content-Type': 'application/json'},
|
|
651
|
+
// body: JSON.stringify({message: data.content}),
|
|
652
|
+
// signal: abortController.signal,
|
|
653
|
+
// });
|
|
654
|
+
// Simulate streaming for demo
|
|
655
|
+
const assistantMessageId = (Date.now() + 1).toString();
|
|
656
|
+
const fullResponse = `This is a detailed response to your question: "${data.content}"\n\nIn a production environment, this text would be streamed from an AI model in real-time. The streaming provides several benefits:\n\n1. **Better User Experience**: Users see the response as it's being generated\n2. **Lower Perceived Latency**: The wait feels shorter when content appears incrementally\n3. **Ability to Cancel**: Users can stop generation if they have enough information\n4. **Resource Efficiency**: Responses can be processed as they arrive\n\nThe implementation would use Server-Sent Events (SSE) or streaming fetch API to receive chunks of text from the backend, updating the message content in real-time.`;
|
|
657
|
+
// Create empty assistant message
|
|
658
|
+
setMessages((prev) => [
|
|
659
|
+
...prev,
|
|
660
|
+
{
|
|
661
|
+
id: assistantMessageId,
|
|
662
|
+
role: 'assistant',
|
|
663
|
+
content: '',
|
|
664
|
+
timestamp: new Date().toISOString(),
|
|
665
|
+
actions: createMessageActions(assistantMessageId, 'assistant'),
|
|
666
|
+
},
|
|
667
|
+
]);
|
|
668
|
+
// Simulate word-by-word streaming
|
|
669
|
+
const words = fullResponse.split(' ');
|
|
670
|
+
for (let i = 0; i < words.length; i++) {
|
|
671
|
+
if (abortController.signal.aborted) {
|
|
672
|
+
break;
|
|
673
|
+
}
|
|
674
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
675
|
+
const currentText = words.slice(0, i + 1).join(' ');
|
|
676
|
+
setMessages((prev) => prev.map((msg) => msg.id === assistantMessageId ? Object.assign(Object.assign({}, msg), { content: currentText }) : msg));
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
catch (error) {
|
|
680
|
+
if (error.name !== 'AbortError') {
|
|
681
|
+
// In real app, error handling would be here
|
|
682
|
+
// console.error('Streaming error:', error);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
finally {
|
|
686
|
+
setStatus('ready');
|
|
687
|
+
setController(null);
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
const handleCancel = async () => {
|
|
691
|
+
controller === null || controller === void 0 ? void 0 : controller.abort();
|
|
692
|
+
setStatus('ready');
|
|
693
|
+
};
|
|
694
|
+
const handleSelectChat = (chat) => {
|
|
695
|
+
setActiveChat(chat);
|
|
696
|
+
// Load messages for selected chat
|
|
697
|
+
const chatMessages = mockChatMessages[chat.id] || [];
|
|
698
|
+
setMessages(addActionsToMessages(chatMessages));
|
|
699
|
+
};
|
|
700
|
+
const handleCreateChat = () => {
|
|
701
|
+
setActiveChat(null);
|
|
702
|
+
setMessages([]);
|
|
703
|
+
};
|
|
704
|
+
return (_jsx(ChatContainer, Object.assign({}, args, { messages: messages, activeChat: activeChat, onSendMessage: handleSendMessage, onCancel: handleCancel, onSelectChat: handleSelectChat, onCreateChat: handleCreateChat, status: status })));
|
|
705
|
+
},
|
|
706
|
+
decorators: defaultDecorators,
|
|
707
|
+
};
|