@stack-spot/ai-chat-widget 0.1.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/dist/StackspotAIWidget.d.ts +13 -0
- package/dist/StackspotAIWidget.d.ts.map +1 -0
- package/dist/StackspotAIWidget.js +32 -0
- package/dist/StackspotAIWidget.js.map +1 -0
- package/dist/chat-interceptors/quick-commands.d.ts +4 -0
- package/dist/chat-interceptors/quick-commands.d.ts.map +1 -0
- package/dist/chat-interceptors/quick-commands.js +11 -0
- package/dist/chat-interceptors/quick-commands.js.map +1 -0
- package/dist/chat-interceptors/send-message.d.ts +4 -0
- package/dist/chat-interceptors/send-message.d.ts.map +1 -0
- package/dist/chat-interceptors/send-message.js +36 -0
- package/dist/chat-interceptors/send-message.js.map +1 -0
- package/dist/components/Accordion.d.ts +10 -0
- package/dist/components/Accordion.d.ts.map +1 -0
- package/dist/components/Accordion.js +46 -0
- package/dist/components/Accordion.js.map +1 -0
- package/dist/components/AdaptiveTextArea.d.ts +10 -0
- package/dist/components/AdaptiveTextArea.d.ts.map +1 -0
- package/dist/components/AdaptiveTextArea.js +28 -0
- package/dist/components/AdaptiveTextArea.js.map +1 -0
- package/dist/components/Code.d.ts +19 -0
- package/dist/components/Code.d.ts.map +1 -0
- package/dist/components/Code.js +112 -0
- package/dist/components/Code.js.map +1 -0
- package/dist/components/Editor.d.ts +9 -0
- package/dist/components/Editor.d.ts.map +1 -0
- package/dist/components/Editor.js +2 -0
- package/dist/components/Editor.js.map +1 -0
- package/dist/components/FadingOverflow.d.ts +12 -0
- package/dist/components/FadingOverflow.d.ts.map +1 -0
- package/dist/components/FadingOverflow.js +216 -0
- package/dist/components/FadingOverflow.js.map +1 -0
- package/dist/components/FallbackBoundary/ErrorBoundary.d.ts +30 -0
- package/dist/components/FallbackBoundary/ErrorBoundary.d.ts.map +1 -0
- package/dist/components/FallbackBoundary/ErrorBoundary.js +38 -0
- package/dist/components/FallbackBoundary/ErrorBoundary.js.map +1 -0
- package/dist/components/FallbackBoundary/Loading.d.ts +2 -0
- package/dist/components/FallbackBoundary/Loading.d.ts.map +1 -0
- package/dist/components/FallbackBoundary/Loading.js +12 -0
- package/dist/components/FallbackBoundary/Loading.js.map +1 -0
- package/dist/components/FallbackBoundary/index.d.ts +6 -0
- package/dist/components/FallbackBoundary/index.d.ts.map +1 -0
- package/dist/components/FallbackBoundary/index.js +9 -0
- package/dist/components/FallbackBoundary/index.js.map +1 -0
- package/dist/components/HistoryList.d.ts +13 -0
- package/dist/components/HistoryList.d.ts.map +1 -0
- package/dist/components/HistoryList.js +4 -0
- package/dist/components/HistoryList.js.map +1 -0
- package/dist/components/IconInput.d.ts +7 -0
- package/dist/components/IconInput.d.ts.map +1 -0
- package/dist/components/IconInput.js +58 -0
- package/dist/components/IconInput.js.map +1 -0
- package/dist/components/Markdown.d.ts +9 -0
- package/dist/components/Markdown.d.ts.map +1 -0
- package/dist/components/Markdown.js +17 -0
- package/dist/components/Markdown.js.map +1 -0
- package/dist/components/OverlayMenu.d.ts +9 -0
- package/dist/components/OverlayMenu.d.ts.map +1 -0
- package/dist/components/OverlayMenu.js +2 -0
- package/dist/components/OverlayMenu.js.map +1 -0
- package/dist/components/ProgressBar.d.ts +11 -0
- package/dist/components/ProgressBar.d.ts.map +1 -0
- package/dist/components/ProgressBar.js +126 -0
- package/dist/components/ProgressBar.js.map +1 -0
- package/dist/components/QuickStartButton.d.ts +8 -0
- package/dist/components/QuickStartButton.d.ts.map +1 -0
- package/dist/components/QuickStartButton.js +40 -0
- package/dist/components/QuickStartButton.js.map +1 -0
- package/dist/components/RightPanelForm.d.ts +5 -0
- package/dist/components/RightPanelForm.d.ts.map +1 -0
- package/dist/components/RightPanelForm.js +45 -0
- package/dist/components/RightPanelForm.js.map +1 -0
- package/dist/components/RightPanelTabs.d.ts +10 -0
- package/dist/components/RightPanelTabs.d.ts.map +1 -0
- package/dist/components/RightPanelTabs.js +20 -0
- package/dist/components/RightPanelTabs.js.map +1 -0
- package/dist/components/TabManager.d.ts +34 -0
- package/dist/components/TabManager.d.ts.map +1 -0
- package/dist/components/TabManager.js +158 -0
- package/dist/components/TabManager.js.map +1 -0
- package/dist/components/Tooltip/Tooltip.d.ts +11 -0
- package/dist/components/Tooltip/Tooltip.d.ts.map +1 -0
- package/dist/components/Tooltip/Tooltip.js +9 -0
- package/dist/components/Tooltip/Tooltip.js.map +1 -0
- package/dist/components/Tooltip/TooltipAPI.d.ts +10 -0
- package/dist/components/Tooltip/TooltipAPI.d.ts.map +1 -0
- package/dist/components/Tooltip/TooltipAPI.js +48 -0
- package/dist/components/Tooltip/TooltipAPI.js.map +1 -0
- package/dist/components/Tooltip/context.d.ts +5 -0
- package/dist/components/Tooltip/context.d.ts.map +1 -0
- package/dist/components/Tooltip/context.js +18 -0
- package/dist/components/Tooltip/context.js.map +1 -0
- package/dist/components/Tooltip/index.d.ts +3 -0
- package/dist/components/Tooltip/index.d.ts.map +1 -0
- package/dist/components/Tooltip/index.js +3 -0
- package/dist/components/Tooltip/index.js.map +1 -0
- package/dist/components/Tooltip/style.d.ts +4 -0
- package/dist/components/Tooltip/style.d.ts.map +1 -0
- package/dist/components/Tooltip/style.js +23 -0
- package/dist/components/Tooltip/style.js.map +1 -0
- package/dist/components/Tooltip/types.d.ts +8 -0
- package/dist/components/Tooltip/types.d.ts.map +1 -0
- package/dist/components/Tooltip/types.js +2 -0
- package/dist/components/Tooltip/types.js.map +1 -0
- package/dist/components/form/DescribedCheckboxGroup.d.ts +3 -0
- package/dist/components/form/DescribedCheckboxGroup.d.ts.map +1 -0
- package/dist/components/form/DescribedCheckboxGroup.js +23 -0
- package/dist/components/form/DescribedCheckboxGroup.js.map +1 -0
- package/dist/components/form/DescribedRadioGroup.d.ts +3 -0
- package/dist/components/form/DescribedRadioGroup.d.ts.map +1 -0
- package/dist/components/form/DescribedRadioGroup.js +18 -0
- package/dist/components/form/DescribedRadioGroup.js.map +1 -0
- package/dist/components/form/styled.d.ts +2 -0
- package/dist/components/form/styled.d.ts.map +1 -0
- package/dist/components/form/styled.js +41 -0
- package/dist/components/form/styled.js.map +1 -0
- package/dist/components/form/types.d.ts +19 -0
- package/dist/components/form/types.d.ts.map +1 -0
- package/dist/components/form/types.js +2 -0
- package/dist/components/form/types.js.map +1 -0
- package/dist/context/AIWidgetProvider.d.ts +4 -0
- package/dist/context/AIWidgetProvider.d.ts.map +1 -0
- package/dist/context/AIWidgetProvider.js +4 -0
- package/dist/context/AIWidgetProvider.js.map +1 -0
- package/dist/context/hooks.d.ts +18 -0
- package/dist/context/hooks.d.ts.map +1 -0
- package/dist/context/hooks.js +82 -0
- package/dist/context/hooks.js.map +1 -0
- package/dist/features.d.ts +13 -0
- package/dist/features.d.ts.map +1 -0
- package/dist/features.js +6 -0
- package/dist/features.js.map +1 -0
- package/dist/hooks/chat-scroll.d.ts +7 -0
- package/dist/hooks/chat-scroll.d.ts.map +1 -0
- package/dist/hooks/chat-scroll.js +15 -0
- package/dist/hooks/chat-scroll.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.css +119 -0
- package/dist/right-panel/DefaultPanel.d.ts +9 -0
- package/dist/right-panel/DefaultPanel.d.ts.map +1 -0
- package/dist/right-panel/DefaultPanel.js +46 -0
- package/dist/right-panel/DefaultPanel.js.map +1 -0
- package/dist/right-panel/RightPanel.d.ts +2 -0
- package/dist/right-panel/RightPanel.d.ts.map +1 -0
- package/dist/right-panel/RightPanel.js +6 -0
- package/dist/right-panel/RightPanel.js.map +1 -0
- package/dist/right-panel/RightPanelProvider.d.ts +13 -0
- package/dist/right-panel/RightPanelProvider.d.ts.map +1 -0
- package/dist/right-panel/RightPanelProvider.js +10 -0
- package/dist/right-panel/RightPanelProvider.js.map +1 -0
- package/dist/right-panel/hooks.d.ts +13 -0
- package/dist/right-panel/hooks.d.ts.map +1 -0
- package/dist/right-panel/hooks.js +39 -0
- package/dist/right-panel/hooks.js.map +1 -0
- package/dist/state/ChatEntry.d.ts +48 -0
- package/dist/state/ChatEntry.d.ts.map +1 -0
- package/dist/state/ChatEntry.js +55 -0
- package/dist/state/ChatEntry.js.map +1 -0
- package/dist/state/ChatState.d.ts +46 -0
- package/dist/state/ChatState.d.ts.map +1 -0
- package/dist/state/ChatState.js +53 -0
- package/dist/state/ChatState.js.map +1 -0
- package/dist/state/ChatTabsController.d.ts +17 -0
- package/dist/state/ChatTabsController.d.ts.map +1 -0
- package/dist/state/ChatTabsController.js +47 -0
- package/dist/state/ChatTabsController.js.map +1 -0
- package/dist/state/ObservableState.d.ts +10 -0
- package/dist/state/ObservableState.d.ts.map +1 -0
- package/dist/state/ObservableState.js +25 -0
- package/dist/state/ObservableState.js.map +1 -0
- package/dist/state/WidgetState.d.ts +19 -0
- package/dist/state/WidgetState.d.ts.map +1 -0
- package/dist/state/WidgetState.js +29 -0
- package/dist/state/WidgetState.js.map +1 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/chat.d.ts +6 -0
- package/dist/utils/chat.d.ts.map +1 -0
- package/dist/utils/chat.js +26 -0
- package/dist/utils/chat.js.map +1 -0
- package/dist/utils/date.d.ts +6 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +38 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/views/Agents.d.ts +2 -0
- package/dist/views/Agents.d.ts.map +1 -0
- package/dist/views/Agents.js +2 -0
- package/dist/views/Agents.js.map +1 -0
- package/dist/views/Chat/AgentInfo.d.ts +6 -0
- package/dist/views/Chat/AgentInfo.d.ts.map +1 -0
- package/dist/views/Chat/AgentInfo.js +7 -0
- package/dist/views/Chat/AgentInfo.js.map +1 -0
- package/dist/views/Chat/ChatMessage.d.ts +6 -0
- package/dist/views/Chat/ChatMessage.d.ts.map +1 -0
- package/dist/views/Chat/ChatMessage.js +61 -0
- package/dist/views/Chat/ChatMessage.js.map +1 -0
- package/dist/views/Chat/ChatMessages.d.ts +7 -0
- package/dist/views/Chat/ChatMessages.d.ts.map +1 -0
- package/dist/views/Chat/ChatMessages.js +12 -0
- package/dist/views/Chat/ChatMessages.js.map +1 -0
- package/dist/views/Chat/index.d.ts +6 -0
- package/dist/views/Chat/index.d.ts.map +1 -0
- package/dist/views/Chat/index.js +8 -0
- package/dist/views/Chat/index.js.map +1 -0
- package/dist/views/Chat/styled.d.ts +2 -0
- package/dist/views/Chat/styled.d.ts.map +1 -0
- package/dist/views/Chat/styled.js +116 -0
- package/dist/views/Chat/styled.js.map +1 -0
- package/dist/views/ChatTabSelection.d.ts +8 -0
- package/dist/views/ChatTabSelection.d.ts.map +1 -0
- package/dist/views/ChatTabSelection.js +45 -0
- package/dist/views/ChatTabSelection.js.map +1 -0
- package/dist/views/Editor.d.ts +2 -0
- package/dist/views/Editor.d.ts.map +1 -0
- package/dist/views/Editor.js +2 -0
- package/dist/views/Editor.js.map +1 -0
- package/dist/views/Home.d.ts +6 -0
- package/dist/views/Home.d.ts.map +1 -0
- package/dist/views/Home.js +68 -0
- package/dist/views/Home.js.map +1 -0
- package/dist/views/KnowledgeSources.d.ts +2 -0
- package/dist/views/KnowledgeSources.d.ts.map +1 -0
- package/dist/views/KnowledgeSources.js +82 -0
- package/dist/views/KnowledgeSources.js.map +1 -0
- package/dist/views/MessageInput/ButtonGroup.d.ts +12 -0
- package/dist/views/MessageInput/ButtonGroup.d.ts.map +1 -0
- package/dist/views/MessageInput/ButtonGroup.js +22 -0
- package/dist/views/MessageInput/ButtonGroup.js.map +1 -0
- package/dist/views/MessageInput/InfoBar.d.ts +2 -0
- package/dist/views/MessageInput/InfoBar.d.ts.map +1 -0
- package/dist/views/MessageInput/InfoBar.js +28 -0
- package/dist/views/MessageInput/InfoBar.js.map +1 -0
- package/dist/views/MessageInput/dictionary.d.ts +2 -0
- package/dist/views/MessageInput/dictionary.d.ts.map +1 -0
- package/dist/views/MessageInput/dictionary.js +35 -0
- package/dist/views/MessageInput/dictionary.js.map +1 -0
- package/dist/views/MessageInput/index.d.ts +7 -0
- package/dist/views/MessageInput/index.d.ts.map +1 -0
- package/dist/views/MessageInput/index.js +43 -0
- package/dist/views/MessageInput/index.js.map +1 -0
- package/dist/views/MessageInput/styled.d.ts +2 -0
- package/dist/views/MessageInput/styled.d.ts.map +1 -0
- package/dist/views/MessageInput/styled.js +195 -0
- package/dist/views/MessageInput/styled.js.map +1 -0
- package/dist/views/MinimizedHeader.d.ts +3 -0
- package/dist/views/MinimizedHeader.d.ts.map +1 -0
- package/dist/views/MinimizedHeader.js +76 -0
- package/dist/views/MinimizedHeader.js.map +1 -0
- package/dist/views/Stacks.d.ts +2 -0
- package/dist/views/Stacks.d.ts.map +1 -0
- package/dist/views/Stacks.js +73 -0
- package/dist/views/Stacks.js.map +1 -0
- package/dist/views/Workspaces.d.ts +2 -0
- package/dist/views/Workspaces.d.ts.map +1 -0
- package/dist/views/Workspaces.js +59 -0
- package/dist/views/Workspaces.js.map +1 -0
- package/package.json +52 -0
- package/src/StackspotAIWidget.tsx +65 -0
- package/src/chat-interceptors/quick-commands.ts +12 -0
- package/src/chat-interceptors/send-message.ts +35 -0
- package/src/components/Accordion.tsx +64 -0
- package/src/components/AdaptiveTextArea.tsx +34 -0
- package/src/components/Code.tsx +201 -0
- package/src/components/Editor.tsx +12 -0
- package/src/components/FadingOverflow.tsx +234 -0
- package/src/components/FallbackBoundary/ErrorBoundary.tsx +48 -0
- package/src/components/FallbackBoundary/Loading.tsx +14 -0
- package/src/components/FallbackBoundary/index.tsx +15 -0
- package/src/components/HistoryList.tsx +16 -0
- package/src/components/IconInput.tsx +70 -0
- package/src/components/Markdown.tsx +53 -0
- package/src/components/OverlayMenu.tsx +10 -0
- package/src/components/ProgressBar.tsx +153 -0
- package/src/components/QuickStartButton.tsx +51 -0
- package/src/components/RightPanelForm.tsx +55 -0
- package/src/components/RightPanelTabs.tsx +39 -0
- package/src/components/TabManager.tsx +223 -0
- package/src/components/Tooltip/Tooltip.tsx +30 -0
- package/src/components/Tooltip/TooltipAPI.ts +46 -0
- package/src/components/Tooltip/context.tsx +24 -0
- package/src/components/Tooltip/index.ts +2 -0
- package/src/components/Tooltip/style.tsx +25 -0
- package/src/components/Tooltip/types.ts +8 -0
- package/src/components/form/DescribedCheckboxGroup.tsx +39 -0
- package/src/components/form/DescribedRadioGroup.tsx +33 -0
- package/src/components/form/styled.ts +41 -0
- package/src/components/form/types.ts +21 -0
- package/src/context/AIWidgetProvider.tsx +6 -0
- package/src/context/hooks.ts +93 -0
- package/src/features.ts +18 -0
- package/src/hooks/chat-scroll.ts +14 -0
- package/src/index.ts +8 -0
- package/src/layout.css +119 -0
- package/src/right-panel/DefaultPanel.tsx +67 -0
- package/src/right-panel/RightPanel.tsx +6 -0
- package/src/right-panel/RightPanelProvider.tsx +20 -0
- package/src/right-panel/hooks.tsx +47 -0
- package/src/state/ChatEntry.ts +95 -0
- package/src/state/ChatState.ts +85 -0
- package/src/state/ChatTabsController.ts +55 -0
- package/src/state/ObservableState.ts +35 -0
- package/src/state/WidgetState.ts +42 -0
- package/src/types.ts +20 -0
- package/src/utils/chat.ts +30 -0
- package/src/utils/date.ts +40 -0
- package/src/views/Agents.tsx +1 -0
- package/src/views/Chat/AgentInfo.tsx +17 -0
- package/src/views/Chat/ChatMessage.tsx +89 -0
- package/src/views/Chat/ChatMessages.tsx +16 -0
- package/src/views/Chat/index.tsx +11 -0
- package/src/views/Chat/styled.ts +116 -0
- package/src/views/ChatTabSelection.tsx +65 -0
- package/src/views/Editor.tsx +1 -0
- package/src/views/Home.tsx +109 -0
- package/src/views/KnowledgeSources.tsx +115 -0
- package/src/views/MessageInput/ButtonGroup.tsx +84 -0
- package/src/views/MessageInput/InfoBar.tsx +69 -0
- package/src/views/MessageInput/dictionary.ts +36 -0
- package/src/views/MessageInput/index.tsx +79 -0
- package/src/views/MessageInput/styled.ts +196 -0
- package/src/views/MinimizedHeader.tsx +94 -0
- package/src/views/Stacks.tsx +104 -0
- package/src/views/Workspaces.tsx +88 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ChevronRight, FaceSmile, KnowledgeSource, Send, Stack, Times, Workspace } from '@citric/icons'
|
|
2
|
+
import { IconButton } from '@citric/ui'
|
|
3
|
+
import { listToClass } from '@stack-spot/portal-theme'
|
|
4
|
+
import { useEffect, useRef } from 'react'
|
|
5
|
+
import { useWidget } from '../../context/hooks'
|
|
6
|
+
import { MessageInputFeatures } from '../../features'
|
|
7
|
+
import { useMessageInputDictionary } from './dictionary'
|
|
8
|
+
|
|
9
|
+
interface ButtonGroupProps {
|
|
10
|
+
features: MessageInputFeatures,
|
|
11
|
+
expanded: boolean,
|
|
12
|
+
setExpanded: React.Dispatch<React.SetStateAction<boolean>>,
|
|
13
|
+
isLoading: boolean,
|
|
14
|
+
onSend: () => void,
|
|
15
|
+
onCancel?: () => void,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ButtonGroup = ({ features, onSend, onCancel, expanded, setExpanded, isLoading }: ButtonGroupProps) => {
|
|
19
|
+
const t = useMessageInputDictionary()
|
|
20
|
+
const widget = useWidget()
|
|
21
|
+
const featureButtonsWidth = useRef<number | undefined>()
|
|
22
|
+
const featureButtons = useRef<HTMLDivElement>(null)
|
|
23
|
+
const hasFeatureButtons = features.agent || features.workspace || features.knowledgeSource || features.stack
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (! featureButtons.current) return
|
|
27
|
+
featureButtonsWidth.current = featureButtons.current.clientWidth
|
|
28
|
+
featureButtons.current.style.width = `${featureButtonsWidth.current}px`
|
|
29
|
+
}, [])
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className="button-group">
|
|
33
|
+
{hasFeatureButtons && <>
|
|
34
|
+
<div
|
|
35
|
+
ref={featureButtons}
|
|
36
|
+
className={listToClass(['feature-buttons', expanded && 'expanded'])}
|
|
37
|
+
style={{ width: expanded ? featureButtonsWidth.current : 0 }}
|
|
38
|
+
>
|
|
39
|
+
{features.agent && (
|
|
40
|
+
<IconButton aria-label={t.agent} title={t.agent} onClick={() => widget.set('isAgentSelectionOpen', true)}>
|
|
41
|
+
<FaceSmile />
|
|
42
|
+
</IconButton>
|
|
43
|
+
)}
|
|
44
|
+
{features.workspace && (
|
|
45
|
+
<IconButton aria-label={t.workspace} title={t.workspace} onClick={() => widget.set('isWorkspaceSelectionOpen', true)}>
|
|
46
|
+
<Workspace />
|
|
47
|
+
</IconButton>
|
|
48
|
+
)}
|
|
49
|
+
{features.knowledgeSource && (
|
|
50
|
+
<IconButton
|
|
51
|
+
aria-label={t.knowledgeSource}
|
|
52
|
+
title={t.knowledgeSource}
|
|
53
|
+
onClick={() => widget.set('isKnowledgeSourceSelectionOpen', true)}
|
|
54
|
+
>
|
|
55
|
+
<KnowledgeSource />
|
|
56
|
+
</IconButton>
|
|
57
|
+
)}
|
|
58
|
+
{features.stack && (
|
|
59
|
+
<IconButton aria-label={t.stack} title={t.stack} onClick={() => widget.set('isStackSelectionOpen', true)}>
|
|
60
|
+
<Stack />
|
|
61
|
+
</IconButton>
|
|
62
|
+
)}
|
|
63
|
+
</div>
|
|
64
|
+
<IconButton
|
|
65
|
+
title={expanded ? t.collapse : t.expand}
|
|
66
|
+
className={listToClass(['expand', !expanded && 'collapsed'])}
|
|
67
|
+
aria-label={expanded ? t.collapse : t.expand}
|
|
68
|
+
onClick={() => setExpanded(v => !v)}
|
|
69
|
+
>
|
|
70
|
+
<ChevronRight />
|
|
71
|
+
</IconButton>
|
|
72
|
+
</>}
|
|
73
|
+
{isLoading ? (
|
|
74
|
+
<IconButton aria-label={t.cancel} onClick={onCancel} className="send" title={t.cancel}>
|
|
75
|
+
<Times />
|
|
76
|
+
</IconButton>
|
|
77
|
+
) : (
|
|
78
|
+
<IconButton aria-label={t.send} onClick={onSend} className="send" title={t.send}>
|
|
79
|
+
<Send />
|
|
80
|
+
</IconButton>
|
|
81
|
+
)}
|
|
82
|
+
</div>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Times, TimesMini } from '@citric/icons'
|
|
2
|
+
import { Badge, IconButton } from '@citric/ui'
|
|
3
|
+
import { ColorPaletteName, listToClass } from '@stack-spot/portal-theme'
|
|
4
|
+
import { useCallback, useMemo } from 'react'
|
|
5
|
+
import { FadingOverflow } from '../../components/FadingOverflow'
|
|
6
|
+
import { useCurrentChat, useCurrentChatState } from '../../context/hooks'
|
|
7
|
+
import { useMessageInputDictionary } from './dictionary'
|
|
8
|
+
|
|
9
|
+
interface InfoBadgeProps {
|
|
10
|
+
label: string,
|
|
11
|
+
color: ColorPaletteName,
|
|
12
|
+
dismiss: string,
|
|
13
|
+
onDismiss: () => void,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const InfoBadge = ({ label, color, dismiss, onDismiss }: InfoBadgeProps) => (
|
|
17
|
+
<Badge appearance="square" palette={color} className="info-badge">
|
|
18
|
+
{label}
|
|
19
|
+
<IconButton onClick={onDismiss} title={dismiss} arial-label={dismiss}><TimesMini /></IconButton>
|
|
20
|
+
</Badge>
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
export const InfoBar = () => {
|
|
24
|
+
const t = useMessageInputDictionary()
|
|
25
|
+
const chat = useCurrentChat()
|
|
26
|
+
const currentStack = useCurrentChatState('stack')
|
|
27
|
+
const currentWorkspace = useCurrentChatState('workspace')
|
|
28
|
+
const currentKnowledgeSources = useCurrentChatState('knowledgeSources')
|
|
29
|
+
const visible = !!(currentStack || currentWorkspace || currentKnowledgeSources?.length)
|
|
30
|
+
const ksToRender = useMemo(() => currentKnowledgeSources?.map(ks => {
|
|
31
|
+
const onDismiss = () => chat.set('knowledgeSources', currentKnowledgeSources.filter(({ id }) => id !== ks.id))
|
|
32
|
+
return <li key={ks.id}><InfoBadge label={ks.label} dismiss={t.removeKS} color="teal" onDismiss={onDismiss} /></li>
|
|
33
|
+
}), [currentKnowledgeSources])
|
|
34
|
+
|
|
35
|
+
const removeAll = useCallback(() => {
|
|
36
|
+
chat.set('knowledgeSources', [])
|
|
37
|
+
chat.set('stack', undefined)
|
|
38
|
+
chat.set('workspace', undefined)
|
|
39
|
+
}, [])
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div className={listToClass(['info-bar', visible && 'visible'])}>
|
|
43
|
+
<div className="space"></div>
|
|
44
|
+
<div className="content">
|
|
45
|
+
<IconButton aria-label={t.removeConfig} title={t.removeConfig} onClick={removeAll}><Times /></IconButton>
|
|
46
|
+
<FadingOverflow className="list-overflow" scroll="arrows" enableHorizontalScrollWithVerticalWheel>
|
|
47
|
+
<ul>
|
|
48
|
+
{currentStack && (
|
|
49
|
+
<li>
|
|
50
|
+
<InfoBadge label={currentStack.label} dismiss={t.removeStack} color="cyan" onDismiss={() => chat.set('stack', undefined)} />
|
|
51
|
+
</li>
|
|
52
|
+
)}
|
|
53
|
+
{currentWorkspace && (
|
|
54
|
+
<li>
|
|
55
|
+
<InfoBadge
|
|
56
|
+
label={currentWorkspace.label}
|
|
57
|
+
dismiss={t.removeWorkspace}
|
|
58
|
+
color="pink"
|
|
59
|
+
onDismiss={() => chat.set('workspace', undefined)}
|
|
60
|
+
/>
|
|
61
|
+
</li>
|
|
62
|
+
)}
|
|
63
|
+
{ksToRender}
|
|
64
|
+
</ul>
|
|
65
|
+
</FadingOverflow>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
|
|
2
|
+
|
|
3
|
+
const dictionary = {
|
|
4
|
+
en: {
|
|
5
|
+
stack: 'Select stack',
|
|
6
|
+
workspace: 'Select workspace',
|
|
7
|
+
knowledgeSource: 'Select knowledge sources',
|
|
8
|
+
agent: 'Select agent',
|
|
9
|
+
collapse: 'Hide buttons',
|
|
10
|
+
expand: 'Show buttons',
|
|
11
|
+
send: 'Send message',
|
|
12
|
+
placeholder: 'Type your prompt',
|
|
13
|
+
cancel: 'Cancel',
|
|
14
|
+
removeConfig: 'Remove all the configuration',
|
|
15
|
+
removeStack: 'Stop using the current stack',
|
|
16
|
+
removeWorkspace: 'Stop using the current workspace',
|
|
17
|
+
removeKS: 'Stop using this knowledge source',
|
|
18
|
+
},
|
|
19
|
+
pt: {
|
|
20
|
+
stack: 'Selecionar stack',
|
|
21
|
+
workspace: 'Selecionar workspace',
|
|
22
|
+
knowledgeSource: 'Selecionar knowledge sources',
|
|
23
|
+
agent: 'Selecionar agente',
|
|
24
|
+
collapse: 'Esconder botões',
|
|
25
|
+
expand: 'Mostrar botões',
|
|
26
|
+
send: 'Enviar mensagem',
|
|
27
|
+
placeholder: 'Digite sua pergunta',
|
|
28
|
+
cancel: 'Cancelar',
|
|
29
|
+
removeConfig: 'Remover todas as configurações',
|
|
30
|
+
removeStack: 'Parar de usar a stack atual',
|
|
31
|
+
removeWorkspace: 'Parar de usar o workspace atual',
|
|
32
|
+
removeKS: 'Parar de usar este knowledge source',
|
|
33
|
+
},
|
|
34
|
+
} satisfies Dictionary
|
|
35
|
+
|
|
36
|
+
export const useMessageInputDictionary = () => useTranslate(dictionary)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { listToClass } from '@stack-spot/portal-theme'
|
|
2
|
+
import { last } from 'lodash'
|
|
3
|
+
import { useCallback, useRef, useState } from 'react'
|
|
4
|
+
import { AdaptiveTextArea } from '../../components/AdaptiveTextArea'
|
|
5
|
+
import { ProgressBar } from '../../components/ProgressBar'
|
|
6
|
+
import { useCurrentChat, useCurrentChatState, useWidgetState } from '../../context/hooks'
|
|
7
|
+
import { MessageInputFeatures } from '../../features'
|
|
8
|
+
import { ChatEntry } from '../../state/ChatEntry'
|
|
9
|
+
import { ButtonGroup } from './ButtonGroup'
|
|
10
|
+
import { useMessageInputDictionary } from './dictionary'
|
|
11
|
+
import { InfoBar } from './InfoBar'
|
|
12
|
+
import { MessageInputBox } from './styled'
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
features: MessageInputFeatures,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const MAX_INPUT_HEIGHT = 300
|
|
19
|
+
const MAX_INPUT_HEIGHT_MINIMIZED = 30
|
|
20
|
+
|
|
21
|
+
export const MessageInput = ({ features }: Props) => {
|
|
22
|
+
const t = useMessageInputDictionary()
|
|
23
|
+
const [focused, setFocused] = useState(false)
|
|
24
|
+
const [expanded, setExpanded] = useState(true)
|
|
25
|
+
const expansionLocked = useRef(false)
|
|
26
|
+
const chat = useCurrentChat()
|
|
27
|
+
const isLoading = useCurrentChatState('isLoading') ?? false
|
|
28
|
+
const value = useCurrentChatState('nextMessage') ?? ''
|
|
29
|
+
const isMinimized = useWidgetState('isMinimized')
|
|
30
|
+
|
|
31
|
+
const onSend = useCallback(async () => {
|
|
32
|
+
const message = chat.get('nextMessage')
|
|
33
|
+
if (!message) return
|
|
34
|
+
chat.pushMessage(ChatEntry.createUserEntry(message))
|
|
35
|
+
chat.set('nextMessage', '')
|
|
36
|
+
setFocused(false)
|
|
37
|
+
}, [chat])
|
|
38
|
+
|
|
39
|
+
const onKeyDown = useCallback((event: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
40
|
+
if (!event.shiftKey && event.key === 'Enter') {
|
|
41
|
+
event.preventDefault()
|
|
42
|
+
onSend()
|
|
43
|
+
}
|
|
44
|
+
}, [onSend])
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<MessageInputBox aria-busy={isLoading} className="message-input">
|
|
48
|
+
<ProgressBar visible={isLoading} shimmer />
|
|
49
|
+
<InfoBar />
|
|
50
|
+
<div className={listToClass(['action-box', focused && 'focused', isLoading && 'disabled'])}>
|
|
51
|
+
<AdaptiveTextArea
|
|
52
|
+
disabled={isLoading}
|
|
53
|
+
placeholder={t.placeholder}
|
|
54
|
+
onChange={e => chat.set('nextMessage', e.target.value)}
|
|
55
|
+
value={value}
|
|
56
|
+
onFocus={() => setFocused(true)}
|
|
57
|
+
onBlur={() => setFocused(false)}
|
|
58
|
+
onKeyDown={onKeyDown}
|
|
59
|
+
onIncreaseSize={() => setExpanded(false)}
|
|
60
|
+
onResetSize={() => !expansionLocked.current && setExpanded(true)}
|
|
61
|
+
maxHeight={isMinimized ? MAX_INPUT_HEIGHT_MINIMIZED : MAX_INPUT_HEIGHT}
|
|
62
|
+
/>
|
|
63
|
+
<ButtonGroup
|
|
64
|
+
features={features}
|
|
65
|
+
onSend={onSend}
|
|
66
|
+
onCancel={() => last(chat.getMessages())?.abort()}
|
|
67
|
+
expanded={expanded}
|
|
68
|
+
isLoading={isLoading}
|
|
69
|
+
setExpanded={(value) => {
|
|
70
|
+
setExpanded(value)
|
|
71
|
+
expansionLocked.current = expanded
|
|
72
|
+
}}
|
|
73
|
+
/>
|
|
74
|
+
</div>
|
|
75
|
+
</MessageInputBox>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { IconButton } from '@citric/ui'
|
|
2
|
+
import { theme } from '@stack-spot/portal-theme'
|
|
3
|
+
import { styled } from 'styled-components'
|
|
4
|
+
|
|
5
|
+
const INFO_BAR_HEIGHT = 42
|
|
6
|
+
const INFO_BAR_DISPLACEMENT = 4
|
|
7
|
+
|
|
8
|
+
export const MessageInputBox = styled.div`
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
|
|
12
|
+
> .info-bar {
|
|
13
|
+
margin-top: 8px;
|
|
14
|
+
position: relative;
|
|
15
|
+
overflow: hidden;
|
|
16
|
+
|
|
17
|
+
&.visible {
|
|
18
|
+
> .space {
|
|
19
|
+
height: ${INFO_BAR_HEIGHT - INFO_BAR_DISPLACEMENT}px;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
> .space {
|
|
24
|
+
height: 0;
|
|
25
|
+
transition: height 0.4s;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
> .content {
|
|
29
|
+
position: absolute;
|
|
30
|
+
top: 0;
|
|
31
|
+
left: 0;
|
|
32
|
+
right: 0;
|
|
33
|
+
border-top-left-radius: 10px;
|
|
34
|
+
border-top-right-radius: 10px;
|
|
35
|
+
height: ${INFO_BAR_HEIGHT}px;
|
|
36
|
+
padding: 0 4px;
|
|
37
|
+
background-color: ${theme.color.light[500]};
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-direction: row;
|
|
40
|
+
align-items: center;
|
|
41
|
+
gap: 6px;
|
|
42
|
+
|
|
43
|
+
.list-overflow {
|
|
44
|
+
max-width: calc(100% - 30px); // close button + gap
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
ul {
|
|
48
|
+
margin: 0;
|
|
49
|
+
padding: 0;
|
|
50
|
+
list-style: none;
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-direction: row;
|
|
53
|
+
align-items: center;
|
|
54
|
+
gap: 6px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.info-badge > span {
|
|
58
|
+
display: flex;
|
|
59
|
+
flex-direction: row;
|
|
60
|
+
align-items: center;
|
|
61
|
+
gap: 4px;
|
|
62
|
+
line-height: 0.75rem;
|
|
63
|
+
white-space: nowrap;
|
|
64
|
+
|
|
65
|
+
${IconButton} {
|
|
66
|
+
padding: 4px 0;
|
|
67
|
+
background: none;
|
|
68
|
+
border: none;
|
|
69
|
+
width: auto;
|
|
70
|
+
height: auto;
|
|
71
|
+
|
|
72
|
+
svg {
|
|
73
|
+
width: auto;
|
|
74
|
+
height: 12px;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.action-box {
|
|
82
|
+
display: flex;
|
|
83
|
+
flex-direction: row;
|
|
84
|
+
gap: 4px;
|
|
85
|
+
align-items: end;
|
|
86
|
+
border-radius: 4px;
|
|
87
|
+
border: 1px solid ${theme.color.light[500]};
|
|
88
|
+
background-color: ${theme.color.light[300]};
|
|
89
|
+
padding: 8px 10px;
|
|
90
|
+
transition: border-color 0.3s, background-color 0.3s;
|
|
91
|
+
|
|
92
|
+
&.focused {
|
|
93
|
+
border-color: ${theme.color.primary[500]};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
&.disabled {
|
|
97
|
+
background-color: ${theme.color.light[500]};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.button-group {
|
|
102
|
+
display: flex;
|
|
103
|
+
flex-direction: row;
|
|
104
|
+
align-items: center;
|
|
105
|
+
gap: 4px;
|
|
106
|
+
margin-bottom: 3px;
|
|
107
|
+
|
|
108
|
+
button {
|
|
109
|
+
border: none;
|
|
110
|
+
border-radius: 2px;
|
|
111
|
+
opacity: 0.6;
|
|
112
|
+
transition: background-color 0.2s, opacity 0.2s;
|
|
113
|
+
background-color: transparent;
|
|
114
|
+
padding: 0;
|
|
115
|
+
|
|
116
|
+
svg {
|
|
117
|
+
fill: ${theme.color.light[700]};
|
|
118
|
+
width: 16px;
|
|
119
|
+
height: 16px;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
&:hover {
|
|
123
|
+
background-color: ${theme.color.light[500]};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
&.send {
|
|
127
|
+
background-color: ${theme.color.inverse[500]};
|
|
128
|
+
&:hover {
|
|
129
|
+
opacity: 1;
|
|
130
|
+
}
|
|
131
|
+
svg {
|
|
132
|
+
fill: ${theme.color.inverse.contrastText};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
&.expand {
|
|
137
|
+
svg {
|
|
138
|
+
transition: transform 0.3s;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
&.collapsed {
|
|
143
|
+
svg {
|
|
144
|
+
transform: rotate(180deg);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.feature-buttons {
|
|
150
|
+
display: flex;
|
|
151
|
+
flex-direction: row;
|
|
152
|
+
align-items: center;
|
|
153
|
+
white-space: nowrap;
|
|
154
|
+
flex-wrap: nowrap;
|
|
155
|
+
transition: width 0.3s;
|
|
156
|
+
gap: 4px;
|
|
157
|
+
overflow-x: hidden;
|
|
158
|
+
|
|
159
|
+
&.expanded {
|
|
160
|
+
/* lets the overflow be hidden only when opened or not animated */
|
|
161
|
+
overflow-x: visible;
|
|
162
|
+
animation: 0.3s overflow-animation;
|
|
163
|
+
@keyframes overflow-animation {
|
|
164
|
+
0% {
|
|
165
|
+
overflow-x: hidden;
|
|
166
|
+
}
|
|
167
|
+
99% {
|
|
168
|
+
overflow-x: hidden;
|
|
169
|
+
}
|
|
170
|
+
100% {
|
|
171
|
+
overflow-x: visible;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
${IconButton} {
|
|
178
|
+
width: 24px;
|
|
179
|
+
height: 24px;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
textarea {
|
|
184
|
+
resize: none;
|
|
185
|
+
border: none;
|
|
186
|
+
flex: 1;
|
|
187
|
+
padding: 0;
|
|
188
|
+
height: 30px;
|
|
189
|
+
padding: 2px 0;
|
|
190
|
+
transition: height 0.3s;
|
|
191
|
+
background-color: transparent;
|
|
192
|
+
&:focus {
|
|
193
|
+
box-shadow: none;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
`
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Text } from '@citric/core'
|
|
2
|
+
import { ChevronDown, Times } from '@citric/icons'
|
|
3
|
+
import { IconButton } from '@citric/ui'
|
|
4
|
+
import { listToClass } from '@stack-spot/portal-theme'
|
|
5
|
+
import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
|
|
6
|
+
import { useCallback, useRef, useState } from 'react'
|
|
7
|
+
import { styled } from 'styled-components'
|
|
8
|
+
import { FadingOverflow } from '../components/FadingOverflow'
|
|
9
|
+
import { useChatState, useChatTabs } from '../context/hooks'
|
|
10
|
+
import { MinimizedActions } from '../types'
|
|
11
|
+
|
|
12
|
+
const Header = styled.header`
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: row;
|
|
15
|
+
align-items: center;
|
|
16
|
+
gap: 18px;
|
|
17
|
+
height: 48px;
|
|
18
|
+
padding: 0 20px;
|
|
19
|
+
max-width: 1200px;
|
|
20
|
+
width: calc(100% - 40px);
|
|
21
|
+
|
|
22
|
+
.title {
|
|
23
|
+
flex: 1;
|
|
24
|
+
white-space: nowrap;
|
|
25
|
+
max-width: calc(100% - 78px); // size of the button-group + gap
|
|
26
|
+
height: 15px; // fixes weird problem where the text has 14px instead of 15px of height
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.button-group {
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: row;
|
|
32
|
+
align-items: center;
|
|
33
|
+
gap: 18px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.collapse {
|
|
37
|
+
background-color: transparent;
|
|
38
|
+
border-color: transparent;
|
|
39
|
+
padding: 0;
|
|
40
|
+
width: auto;
|
|
41
|
+
height: auto;
|
|
42
|
+
transition: transform 0.3s;
|
|
43
|
+
|
|
44
|
+
&.collapsed {
|
|
45
|
+
transform: rotate(-180deg);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`
|
|
49
|
+
|
|
50
|
+
export const MinimizedHeader = ({ onClose, onCollapse, onExpand }: MinimizedActions) => {
|
|
51
|
+
const t = useTranslate(dictionary)
|
|
52
|
+
const { active } = useChatTabs()
|
|
53
|
+
const label = useChatState(active, 'label')
|
|
54
|
+
const [collapsed, setCollapsed] = useState(false)
|
|
55
|
+
const ref = useRef<HTMLElement>(null)
|
|
56
|
+
const showButtons = onClose || onCollapse || onExpand
|
|
57
|
+
|
|
58
|
+
const toggleCollapsed = useCallback(() => {
|
|
59
|
+
if (collapsed) onExpand?.()
|
|
60
|
+
else onCollapse?.()
|
|
61
|
+
setCollapsed(!collapsed)
|
|
62
|
+
}, [collapsed])
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<Header ref={ref} className="minimized-header">
|
|
66
|
+
<FadingOverflow className="title"><Text title={label}>{label}</Text></FadingOverflow>
|
|
67
|
+
{showButtons && <div className="button-group">
|
|
68
|
+
{(onExpand || onCollapse) && <IconButton
|
|
69
|
+
title={collapsed ? t.expand : t.collapse}
|
|
70
|
+
aria-label={collapsed ? t.expand : t.collapse}
|
|
71
|
+
className={listToClass(['collapse', collapsed && 'collapsed'])}
|
|
72
|
+
onClick={toggleCollapsed}
|
|
73
|
+
>
|
|
74
|
+
<ChevronDown />
|
|
75
|
+
</IconButton>}
|
|
76
|
+
{onClose && <IconButton title={t.close} aria-label={t.close} onClick={onClose}><Times /></IconButton>}
|
|
77
|
+
</div>}
|
|
78
|
+
</Header>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const dictionary = {
|
|
83
|
+
en: {
|
|
84
|
+
collapse: 'Minimize',
|
|
85
|
+
expand: 'Expand',
|
|
86
|
+
close: 'Close',
|
|
87
|
+
},
|
|
88
|
+
pt: {
|
|
89
|
+
collapse: 'Minimizar',
|
|
90
|
+
expand: 'Expandir',
|
|
91
|
+
close: 'Fechar',
|
|
92
|
+
},
|
|
93
|
+
} satisfies Dictionary
|
|
94
|
+
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Button } from '@citric/core'
|
|
2
|
+
import { Search } from '@citric/icons'
|
|
3
|
+
import { Placeholder } from '@stack-spot/portal-components/Placeholder'
|
|
4
|
+
import { aiClient } from '@stack-spot/portal-network'
|
|
5
|
+
import { GetAiStackResponse, VisibilityLevelEnum } from '@stack-spot/portal-network/api/ai'
|
|
6
|
+
import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
|
|
7
|
+
import { useEffect, useMemo, useState } from 'react'
|
|
8
|
+
import { DescribedRadioGroup } from '../components/form/DescribedRadioGroup'
|
|
9
|
+
import { IconInput } from '../components/IconInput'
|
|
10
|
+
import { RightPanelTabs } from '../components/RightPanelTabs'
|
|
11
|
+
import { useCurrentChat, useWidget, useWidgetState } from '../context/hooks'
|
|
12
|
+
import { useRightPanel } from '../right-panel/hooks'
|
|
13
|
+
|
|
14
|
+
export const Stacks = () => {
|
|
15
|
+
const t = useTranslate(dictionary)
|
|
16
|
+
const isStackSelectionOpen = useWidgetState('isStackSelectionOpen')
|
|
17
|
+
const { open } = useRightPanel()
|
|
18
|
+
const widget = useWidget()
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (isStackSelectionOpen) open(
|
|
22
|
+
<StacksPanel />,
|
|
23
|
+
{ title: t.title, description: t.description, onClose: () => widget.set('isStackSelectionOpen', false) },
|
|
24
|
+
)
|
|
25
|
+
}, [isStackSelectionOpen, t])
|
|
26
|
+
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const StacksPanel = () => {
|
|
31
|
+
const t = useTranslate(dictionary)
|
|
32
|
+
|
|
33
|
+
return <RightPanelTabs tabs={[
|
|
34
|
+
{ title: t.personal, content: <StacksTab key="personal" visibility="personal" /> },
|
|
35
|
+
{ title: t.shared, content: <StacksTab key="shared" visibility="shared" /> },
|
|
36
|
+
{ title: t.account, content: <StacksTab key="account" visibility="account" /> },
|
|
37
|
+
]} />
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const StacksTab = ({ visibility }: { visibility: VisibilityLevelEnum }) => {
|
|
41
|
+
const t = useTranslate(dictionary)
|
|
42
|
+
const { close } = useRightPanel()
|
|
43
|
+
const chat = useCurrentChat()
|
|
44
|
+
const [filter, setFilter] = useState('')
|
|
45
|
+
const stacks = aiClient.aiStacks.useQuery({ visibility, order: 'a-to-z' })
|
|
46
|
+
const [value, setValue] = useState<GetAiStackResponse | undefined>(stacks.find(s => s.id === chat.get('stack')?.id))
|
|
47
|
+
const filtered = useMemo(
|
|
48
|
+
() => filter ? stacks.filter(s => s === value || s.name.toLocaleLowerCase().includes(filter.toLocaleLowerCase())) : stacks,
|
|
49
|
+
[stacks, filter, value],
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
function submit() {
|
|
53
|
+
if (value) chat.set('stack', { id: value.id, label: value.name })
|
|
54
|
+
close()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
<div className="content">
|
|
60
|
+
<IconInput icon={<Search />} value={filter} onChange={setFilter} className="search" />
|
|
61
|
+
{!!filtered.length && <DescribedRadioGroup
|
|
62
|
+
options={filtered}
|
|
63
|
+
keygen={s => s.id}
|
|
64
|
+
value={value}
|
|
65
|
+
onChange={setValue}
|
|
66
|
+
renderLabel={s => s.name}
|
|
67
|
+
renderDescription={s => s.use_case}
|
|
68
|
+
optionClassName={s => (s === value && filter && !s.name.includes(filter)) ? 'filtered-out' : ''}
|
|
69
|
+
className="option-list"
|
|
70
|
+
/>}
|
|
71
|
+
{!!stacks.length && !filtered.length && <Placeholder title={t.noSearchResults} description={t.noSearchResultsDescription} />}
|
|
72
|
+
{!stacks.length && <Placeholder title={t.noData} description={t.noDataDescription} />}
|
|
73
|
+
</div>
|
|
74
|
+
<Button onClick={submit} disabled={!value}>{t.apply}</Button>
|
|
75
|
+
</>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const dictionary = {
|
|
80
|
+
en: {
|
|
81
|
+
title: 'Stacks AI',
|
|
82
|
+
description: 'By selecting an AI Stack, it will be consulted to generate the answers.',
|
|
83
|
+
personal: 'Personal',
|
|
84
|
+
shared: 'Shared',
|
|
85
|
+
account: 'Account',
|
|
86
|
+
apply: 'Apply',
|
|
87
|
+
noSearchResults: "Your search didn't yield results.",
|
|
88
|
+
noSearchResultsDescription: 'Please, try another search term.',
|
|
89
|
+
noData: 'There are no stacks in this category yet.',
|
|
90
|
+
noDataDescription: 'Use the tabs above to try other categories or use the AI portal to create new stacks.',
|
|
91
|
+
},
|
|
92
|
+
pt: {
|
|
93
|
+
title: 'Stacks AI',
|
|
94
|
+
description: 'Ao selecionar uma Stack AI, ela será consultada para gerar as respostas.',
|
|
95
|
+
personal: 'Pessoal',
|
|
96
|
+
shared: 'Compartilhado',
|
|
97
|
+
account: 'Conta',
|
|
98
|
+
apply: 'Aplicar',
|
|
99
|
+
noSearchResults: 'Sua busca não produziu resultados.',
|
|
100
|
+
noSearchResultsDescription: 'Por favor, tente outra busca.',
|
|
101
|
+
noData: 'Ainda não há stacks nesta categoria.',
|
|
102
|
+
noDataDescription: 'Use as abas acima para tentar outras categorias ou use o Portal AI para criar novas stacks.',
|
|
103
|
+
},
|
|
104
|
+
} satisfies Dictionary
|