@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,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from '@citric/core';
|
|
3
|
+
import { Search } from '@citric/icons';
|
|
4
|
+
import { Placeholder } from '@stack-spot/portal-components/Placeholder';
|
|
5
|
+
import { workspaceClient } from '@stack-spot/portal-network';
|
|
6
|
+
import { useTranslate } from '@stack-spot/portal-translate';
|
|
7
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
8
|
+
import { DescribedRadioGroup } from '../components/form/DescribedRadioGroup.js';
|
|
9
|
+
import { IconInput } from '../components/IconInput.js';
|
|
10
|
+
import { RightPanelForm } from '../components/RightPanelForm.js';
|
|
11
|
+
import { useCurrentChat, useWidget, useWidgetState } from '../context/hooks.js';
|
|
12
|
+
import { useRightPanel } from '../right-panel/hooks.js';
|
|
13
|
+
export const Workspaces = () => {
|
|
14
|
+
const t = useTranslate(dictionary);
|
|
15
|
+
const isWorkspaceSelectionOpen = useWidgetState('isWorkspaceSelectionOpen');
|
|
16
|
+
const { open } = useRightPanel();
|
|
17
|
+
const widget = useWidget();
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (isWorkspaceSelectionOpen)
|
|
20
|
+
open(_jsx(RightPanelForm, { children: _jsx(WorkspacesPanel, {}) }), { title: t.title, description: t.description, onClose: () => widget.set('isWorkspaceSelectionOpen', false) });
|
|
21
|
+
}, [isWorkspaceSelectionOpen, t]);
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
24
|
+
const WorkspacesPanel = () => {
|
|
25
|
+
const t = useTranslate(dictionary);
|
|
26
|
+
const { close } = useRightPanel();
|
|
27
|
+
const chat = useCurrentChat();
|
|
28
|
+
const [filter, setFilter] = useState('');
|
|
29
|
+
const workspaces = workspaceClient.workspaces.useQuery({ aclOnly: false });
|
|
30
|
+
const [value, setValue] = useState(workspaces.find(w => w.id === chat.get('workspace')?.id));
|
|
31
|
+
const filtered = useMemo(() => filter ? workspaces.filter(w => w === value || w.name.toLocaleLowerCase().includes(filter.toLocaleLowerCase())) : workspaces, [workspaces, filter, value]);
|
|
32
|
+
function submit() {
|
|
33
|
+
if (value)
|
|
34
|
+
chat.set('workspace', { id: value.id, label: value.name });
|
|
35
|
+
close();
|
|
36
|
+
}
|
|
37
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "content", children: [_jsx(IconInput, { icon: _jsx(Search, {}), value: filter, onChange: setFilter, className: "search" }), !!filtered.length && _jsx(DescribedRadioGroup, { options: filtered, keygen: w => w.id, value: value, onChange: setValue, renderLabel: w => w.name, renderDescription: w => w.description, optionClassName: w => (w === value && filter && !w.name.includes(filter)) ? 'filtered-out' : '', className: "option-list" }), !!workspaces.length && !filtered.length && _jsx(Placeholder, { title: t.noSearchResults, description: t.noSearchResultsDescription }), !workspaces.length && _jsx(Placeholder, { title: t.noData, description: t.noDataDescription })] }), _jsx(Button, { onClick: submit, disabled: !value, children: t.apply })] }));
|
|
38
|
+
};
|
|
39
|
+
const dictionary = {
|
|
40
|
+
en: {
|
|
41
|
+
title: 'Workspaces',
|
|
42
|
+
description: 'By selecting a workspace, its Knowledge Sources (KSs) will be consulted to generate the answers.',
|
|
43
|
+
apply: 'Apply',
|
|
44
|
+
noSearchResults: "Your search didn't yield results.",
|
|
45
|
+
noSearchResultsDescription: 'Please, try another search term.',
|
|
46
|
+
noData: 'There are no workspaces yet.',
|
|
47
|
+
noDataDescription: 'Use the AI portal to create new workspaces.',
|
|
48
|
+
},
|
|
49
|
+
pt: {
|
|
50
|
+
title: 'Workspaces',
|
|
51
|
+
description: 'Ao selecionar um workspace, seus Knowledge Sources (KSs) serão consultados para gerar as respostas.',
|
|
52
|
+
apply: 'Aplicar',
|
|
53
|
+
noSearchResults: 'Sua busca não produziu resultados',
|
|
54
|
+
noSearchResultsDescription: 'Por favor, tente outra busca.',
|
|
55
|
+
noData: 'Ainda não há workspace.',
|
|
56
|
+
noDataDescription: 'Use o Portal AI para criar novos workspaces.',
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=Workspaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Workspaces.js","sourceRoot":"","sources":["../../src/views/Workspaces.tsx"],"names":[],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stack-spot/ai-chat-widget",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"@citric/core": "^6.0.0",
|
|
9
|
+
"@citric/icons": "^5.4.0 || ^6.0.0",
|
|
10
|
+
"@citric/ui": "^5.4.0 || ^6.0.0",
|
|
11
|
+
"@stack-spot/portal-components": "^2.6.1",
|
|
12
|
+
"@stack-spot/portal-network": "^0.40.0",
|
|
13
|
+
"@stack-spot/portal-theme": "^1.0.0",
|
|
14
|
+
"@stack-spot/portal-translate": "^1.1.0",
|
|
15
|
+
"lodash": "^4.17.0",
|
|
16
|
+
"react": "^18.2.0",
|
|
17
|
+
"react-dom": "^18.2.0",
|
|
18
|
+
"styled-components": "6.1.10"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/lodash": "^4.14.202",
|
|
22
|
+
"@types/react": "^18.2.37",
|
|
23
|
+
"@types/react-dom": "^18.2.15",
|
|
24
|
+
"@types/react-syntax-highlighter": "^15.5.13",
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
26
|
+
"@typescript-eslint/parser": "^6.10.0",
|
|
27
|
+
"cpy-cli": "^5.0.0",
|
|
28
|
+
"eslint": "^8.53.0",
|
|
29
|
+
"eslint-plugin-filenames": "^1.3.2",
|
|
30
|
+
"eslint-plugin-import": "^2.29.0",
|
|
31
|
+
"eslint-plugin-lodash": "^7.4.0",
|
|
32
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
33
|
+
"eslint-plugin-react": "^7.33.2",
|
|
34
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
35
|
+
"react": "18.2.0",
|
|
36
|
+
"react-dom": "18.2.0",
|
|
37
|
+
"rimraf": "^5.0.7",
|
|
38
|
+
"styled-components": "6.1.10",
|
|
39
|
+
"tsc-esm-fix": "^2.20.26",
|
|
40
|
+
"typescript": "^5.2.2"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"react-markdown": "^9.0.1",
|
|
44
|
+
"react-syntax-highlighter": "^15.5.0",
|
|
45
|
+
"remark-gfm": "^4.0.0",
|
|
46
|
+
"ulid": "^2.3.0"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "rimraf dist && tsc && tsc-esm-fix --target='dist' && cpy src/layout.css dist --flat",
|
|
50
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { listToClass } from '@stack-spot/portal-theme'
|
|
2
|
+
import { useMemo, useRef } from 'react'
|
|
3
|
+
import { quickCommandInterceptor } from './chat-interceptors/quick-commands'
|
|
4
|
+
import { sendMessageInterceptor } from './chat-interceptors/send-message'
|
|
5
|
+
import { TooltipProvider } from './components/Tooltip'
|
|
6
|
+
import { useCurrentChatMessages, useFirstChat, useWidgetState } from './context/hooks'
|
|
7
|
+
import { AIWidgetFeatures, defaultFeatures } from './features'
|
|
8
|
+
import './layout.css'
|
|
9
|
+
import { RightPanel } from './right-panel/RightPanel'
|
|
10
|
+
import { RightPanelProvider } from './right-panel/RightPanelProvider'
|
|
11
|
+
import { MessageInterceptor } from './state/ChatState'
|
|
12
|
+
import { MinimizedActions } from './types'
|
|
13
|
+
import { Chat } from './views/Chat'
|
|
14
|
+
import { ChatTabSelection } from './views/ChatTabSelection'
|
|
15
|
+
import { Home } from './views/Home'
|
|
16
|
+
import { KnowledgeSources } from './views/KnowledgeSources'
|
|
17
|
+
import { MessageInput } from './views/MessageInput'
|
|
18
|
+
import { MinimizedHeader } from './views/MinimizedHeader'
|
|
19
|
+
import { Stacks } from './views/Stacks'
|
|
20
|
+
import { Workspaces } from './views/Workspaces'
|
|
21
|
+
|
|
22
|
+
export interface AIWidgetProps {
|
|
23
|
+
features?: AIWidgetFeatures,
|
|
24
|
+
username: string,
|
|
25
|
+
interceptors?: MessageInterceptor[],
|
|
26
|
+
children?: React.ReactNode,
|
|
27
|
+
minimizedActions?: MinimizedActions,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const StackspotAIWidget = (
|
|
31
|
+
{ username, features = defaultFeatures, interceptors: userInterceptors = [], minimizedActions = {}, children }: AIWidgetProps,
|
|
32
|
+
) => {
|
|
33
|
+
const interceptors: MessageInterceptor[] = useMemo(() => [...userInterceptors, quickCommandInterceptor, sendMessageInterceptor], [])
|
|
34
|
+
useFirstChat(interceptors)
|
|
35
|
+
const rightPanelRef = useRef<HTMLDivElement>(null)
|
|
36
|
+
const chatWindowRef = useRef<HTMLDivElement>(null)
|
|
37
|
+
const currentChat = useCurrentChatMessages()
|
|
38
|
+
const isMinimized = useWidgetState('isMinimized')
|
|
39
|
+
const isCurrentChatEmpty = currentChat.length === 0
|
|
40
|
+
|
|
41
|
+
return useMemo(() => (
|
|
42
|
+
<TooltipProvider>
|
|
43
|
+
<RightPanelProvider chatWindow={chatWindowRef} panel={rightPanelRef}>
|
|
44
|
+
<div className={listToClass(['ai-chat-widget', isMinimized && 'minimized'])}>
|
|
45
|
+
<div className="chat-window" ref={chatWindowRef}>
|
|
46
|
+
{isMinimized
|
|
47
|
+
? <MinimizedHeader {...minimizedActions} />
|
|
48
|
+
: <ChatTabSelection history={features?.chatHistory} interceptors={interceptors}/>
|
|
49
|
+
}
|
|
50
|
+
<div className="chat-container">
|
|
51
|
+
<div className="chat-content">
|
|
52
|
+
{isCurrentChatEmpty ? (children ?? <Home username={username} />) : <Chat username={username} />}
|
|
53
|
+
</div>
|
|
54
|
+
<MessageInput features={features} />
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
<Stacks />
|
|
58
|
+
<Workspaces />
|
|
59
|
+
<KnowledgeSources />
|
|
60
|
+
{!isMinimized && <div className="chat-right-panel" ref={rightPanelRef}><RightPanel /></div>}
|
|
61
|
+
</div>
|
|
62
|
+
</RightPanelProvider>
|
|
63
|
+
</TooltipProvider>
|
|
64
|
+
), [isCurrentChatEmpty, features, username, isMinimized])
|
|
65
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChatEntry } from '../state/ChatEntry'
|
|
2
|
+
import { ChatState } from '../state/ChatState'
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
+
export function quickCommandInterceptor(entry: ChatEntry, _chat: ChatState) {
|
|
6
|
+
const { agent, content } = entry.getValue()
|
|
7
|
+
if (agent !== 'user') return
|
|
8
|
+
if (content.startsWith('/')) {
|
|
9
|
+
alert('Quick commands are not yet supported!') /* todo */
|
|
10
|
+
return false // by returning false, the next interceptor are not run. i.e. the message is not sent to the AI agent.
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { aiClient, StackspotAPIError } from '@stack-spot/portal-network'
|
|
2
|
+
import { ChatEntry } from '../state/ChatEntry'
|
|
3
|
+
import { ChatState } from '../state/ChatState'
|
|
4
|
+
import { buildConversationContext } from '../utils/chat'
|
|
5
|
+
|
|
6
|
+
export async function sendMessageInterceptor(entry: ChatEntry, chat: ChatState) {
|
|
7
|
+
const { agent, content } = entry.getValue()
|
|
8
|
+
if (agent !== 'user') return
|
|
9
|
+
const context = buildConversationContext(chat)
|
|
10
|
+
chat.set('isLoading', true)
|
|
11
|
+
// if this is the first message, let's rename the chat.
|
|
12
|
+
if (chat.getMessages().length === 1) {
|
|
13
|
+
chat.set('label', content)
|
|
14
|
+
}
|
|
15
|
+
const stream = aiClient.sendChatMessage({ context, user_prompt: content })
|
|
16
|
+
const botEntry = ChatEntry.createStreamedBotEntry(() => stream.cancel())
|
|
17
|
+
chat.pushMessage(botEntry)
|
|
18
|
+
stream.onChange(value => botEntry.setValue({
|
|
19
|
+
agent: 'bot',
|
|
20
|
+
type: 'md',
|
|
21
|
+
content: value.answer ?? '',
|
|
22
|
+
messageId: value.message_id ?? undefined,
|
|
23
|
+
updated: new Date().toISOString(),
|
|
24
|
+
}))
|
|
25
|
+
try {
|
|
26
|
+
await stream.getValue()
|
|
27
|
+
} catch (error: any) {
|
|
28
|
+
botEntry.setValue({
|
|
29
|
+
...botEntry.getValue(),
|
|
30
|
+
error: error instanceof StackspotAPIError ? error.translate() : (error.message ?? `${error}`),
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
botEntry.finish()
|
|
34
|
+
chat.set('isLoading', false)
|
|
35
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* Copiar do EDP ou usar o AnimatedHeight da lib de components */
|
|
2
|
+
|
|
3
|
+
import { ChevronDown } from '@citric/icons'
|
|
4
|
+
import { IconButton } from '@citric/ui'
|
|
5
|
+
import { AnimatedHeight } from '@stack-spot/portal-components/AnimatedHeight'
|
|
6
|
+
import { WithStyle } from '@stack-spot/portal-theme'
|
|
7
|
+
import React, { useState } from 'react'
|
|
8
|
+
import { styled } from 'styled-components'
|
|
9
|
+
import { WithChildren } from '../types'
|
|
10
|
+
|
|
11
|
+
interface Props extends WithStyle, Required<WithChildren> {
|
|
12
|
+
header: React.ReactNode,
|
|
13
|
+
startExpanded?: boolean,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const StyledAccordion = styled.div`
|
|
17
|
+
> header {
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: row;
|
|
20
|
+
justify-content: space-between;
|
|
21
|
+
align-items: center;
|
|
22
|
+
padding: 10px;
|
|
23
|
+
|
|
24
|
+
> button {
|
|
25
|
+
transition: transform 0.3s ease-out;
|
|
26
|
+
background: transparent;
|
|
27
|
+
border: none;
|
|
28
|
+
padding: 0;
|
|
29
|
+
|
|
30
|
+
&:hover {
|
|
31
|
+
background: transparent;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
svg {
|
|
35
|
+
width: 16px;
|
|
36
|
+
height: 16px;
|
|
37
|
+
margin: 4px;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&.expanded > button {
|
|
42
|
+
transform: rotate(180deg);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
> .accordion-content {
|
|
47
|
+
padding: 10px;
|
|
48
|
+
}
|
|
49
|
+
`
|
|
50
|
+
|
|
51
|
+
export const Accordion = ({ children, header, className, startExpanded, style }: Props) => {
|
|
52
|
+
const [expanded, setExpanded] = useState(startExpanded)
|
|
53
|
+
return (
|
|
54
|
+
<AnimatedHeight style={style} className={className}>
|
|
55
|
+
<StyledAccordion>
|
|
56
|
+
<header className={expanded ? 'expanded' : ''}>
|
|
57
|
+
{header}
|
|
58
|
+
<IconButton onClick={() => setExpanded(v => !v)}><ChevronDown /></IconButton>
|
|
59
|
+
</header>
|
|
60
|
+
{expanded ? <div className="accordion-content">{children}</div> : null}
|
|
61
|
+
</StyledAccordion>
|
|
62
|
+
</AnimatedHeight>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Textarea } from '@citric/core'
|
|
2
|
+
import { useEffect, useRef } from 'react'
|
|
3
|
+
import { PropsOf } from '../types'
|
|
4
|
+
|
|
5
|
+
interface Props extends PropsOf<typeof Textarea> {
|
|
6
|
+
onIncreaseSize?: () => void,
|
|
7
|
+
onResetSize?: () => void,
|
|
8
|
+
maxHeight?: number,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const AdaptiveTextArea = ({ value, onIncreaseSize, onResetSize, maxHeight, style, ...props }: Props) => {
|
|
12
|
+
const ref = useRef<HTMLTextAreaElement>(null)
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!ref.current) return
|
|
16
|
+
const height = ref.current.clientHeight
|
|
17
|
+
const scroll = ref.current.scrollHeight
|
|
18
|
+
if (!maxHeight || height < maxHeight) {
|
|
19
|
+
ref.current.style.overflowY = 'hidden'
|
|
20
|
+
if (height < scroll) {
|
|
21
|
+
ref.current.style.height = `${scroll}px`
|
|
22
|
+
onIncreaseSize?.()
|
|
23
|
+
}
|
|
24
|
+
} else if (maxHeight) {
|
|
25
|
+
ref.current.style.overflowY = 'auto'
|
|
26
|
+
}
|
|
27
|
+
if (!value) {
|
|
28
|
+
ref.current.style.height = ''
|
|
29
|
+
onResetSize?.()
|
|
30
|
+
}
|
|
31
|
+
}, [value, maxHeight])
|
|
32
|
+
|
|
33
|
+
return <Textarea {...props} ref={ref} value={value} style={{ ...style, maxHeight }} />
|
|
34
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copied from the extension's webview.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AddCode, ChevronDoubleDown, Copy } from '@citric/icons'
|
|
6
|
+
import { IconButton } from '@citric/ui'
|
|
7
|
+
import { theme, useThemeKind } from '@stack-spot/portal-theme'
|
|
8
|
+
import { Dictionary, useTranslate } from '@stack-spot/portal-translate'
|
|
9
|
+
import { CSSProperties } from 'react'
|
|
10
|
+
import { ExtraProps } from 'react-markdown'
|
|
11
|
+
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
|
|
12
|
+
import { materialDark, vs } from 'react-syntax-highlighter/dist/esm/styles/prism'
|
|
13
|
+
import styled from 'styled-components'
|
|
14
|
+
import { WithChildren } from '../types'
|
|
15
|
+
|
|
16
|
+
export type CodeAction = (
|
|
17
|
+
code: string,
|
|
18
|
+
language: string,
|
|
19
|
+
) => void
|
|
20
|
+
|
|
21
|
+
type CodeProps = React.ClassAttributes<HTMLElement>
|
|
22
|
+
& React.HTMLAttributes<HTMLElement>
|
|
23
|
+
& ExtraProps
|
|
24
|
+
& { messageId?: string }
|
|
25
|
+
|
|
26
|
+
export interface Props extends WithChildren {
|
|
27
|
+
showActionBar?: boolean,
|
|
28
|
+
onInsertCode?: CodeAction,
|
|
29
|
+
onNewFile?: CodeAction,
|
|
30
|
+
onCopyCode?: CodeAction,
|
|
31
|
+
language?: string,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const CodeBox = styled.code`
|
|
35
|
+
background: ${theme.color.light[500]};
|
|
36
|
+
border-radius: 6px;
|
|
37
|
+
overflow: hidden;
|
|
38
|
+
|
|
39
|
+
.highlighter {
|
|
40
|
+
margin: 0 !important;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
code {
|
|
44
|
+
font-size: 13px !important;
|
|
45
|
+
font-family: Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace !important;
|
|
46
|
+
background-color: transparent !important;
|
|
47
|
+
|
|
48
|
+
.linenumber {
|
|
49
|
+
color: ${theme.color.light.contrastText} !important;
|
|
50
|
+
opacity: 0.6;
|
|
51
|
+
min-width: 20px !important;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.action-bar {
|
|
56
|
+
display: flex;
|
|
57
|
+
flex-direction: row;
|
|
58
|
+
justify-content: flex-end;
|
|
59
|
+
background: ${theme.color.light[600]};
|
|
60
|
+
padding: 4px 6px;
|
|
61
|
+
border-top-left-radius: 6px;
|
|
62
|
+
border-top-right-radius: 6px;
|
|
63
|
+
|
|
64
|
+
button {
|
|
65
|
+
background: transparent;
|
|
66
|
+
border: none;
|
|
67
|
+
opacity: 0.75;
|
|
68
|
+
transition: opacity 0.2s;
|
|
69
|
+
|
|
70
|
+
&:hover {
|
|
71
|
+
opacity: 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
&.light {
|
|
77
|
+
border: 1px solid rgb(221, 221, 221);
|
|
78
|
+
|
|
79
|
+
> div {
|
|
80
|
+
border: none !important;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.action-bar {
|
|
84
|
+
background: rgba(0, 0, 0, 0.1);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
`
|
|
88
|
+
|
|
89
|
+
const lineNumbersStyle: CSSProperties = {
|
|
90
|
+
userSelect: 'none',
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const Code = ({
|
|
94
|
+
className,
|
|
95
|
+
onInsertCode,
|
|
96
|
+
onNewFile,
|
|
97
|
+
onCopyCode,
|
|
98
|
+
language,
|
|
99
|
+
children,
|
|
100
|
+
showActionBar,
|
|
101
|
+
...props
|
|
102
|
+
}: Pick<CodeProps, 'className' | 'messageId'> & Props) => {
|
|
103
|
+
const t = useTranslate(dictionary)
|
|
104
|
+
const themeKind = useThemeKind()
|
|
105
|
+
const match = /language-(\w+)/.exec(className || '')
|
|
106
|
+
const computedLanguage = language ?? (match ?? [])[1]?.toLowerCase() ?? 'txt'
|
|
107
|
+
const content = String(children ?? '').replaceAll(/\n\t/g, '\n').trim()
|
|
108
|
+
|
|
109
|
+
function onClickInsert() {
|
|
110
|
+
onInsertCode?.(content, computedLanguage)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function onClickNewFile() {
|
|
114
|
+
onNewFile?.(content, computedLanguage)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function onClickCopy() {
|
|
118
|
+
onCopyCode?.(content, computedLanguage)
|
|
119
|
+
// try-catch because the client may not support `navigator.clipboard`. Example: Chromium Embedded Browser (CEF).
|
|
120
|
+
try {
|
|
121
|
+
navigator.clipboard.writeText(content)
|
|
122
|
+
} catch { /* empty */ }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (children === undefined) return <></>
|
|
126
|
+
if (!(/language-(\w+)/.exec(className || ''))) {
|
|
127
|
+
return (
|
|
128
|
+
<code {...props} className={className}>
|
|
129
|
+
{children}
|
|
130
|
+
</code>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<CodeBox className={['code-box', themeKind].join(' ')}>
|
|
136
|
+
{showActionBar && (
|
|
137
|
+
<div className="action-bar" role="toolbar">
|
|
138
|
+
<IconButton
|
|
139
|
+
aria-label={t.copy}
|
|
140
|
+
title={t.copy}
|
|
141
|
+
onClick={onClickCopy}
|
|
142
|
+
style={{ position: 'relative' }}
|
|
143
|
+
>
|
|
144
|
+
<Copy />
|
|
145
|
+
</IconButton>
|
|
146
|
+
{onInsertCode
|
|
147
|
+
? (
|
|
148
|
+
<IconButton
|
|
149
|
+
aria-label={t.insert}
|
|
150
|
+
title={t.insert}
|
|
151
|
+
onClick={onClickInsert}
|
|
152
|
+
style={{ position: 'relative' }}
|
|
153
|
+
>
|
|
154
|
+
<ChevronDoubleDown style={{ transform: 'rotate(90deg)' }} />
|
|
155
|
+
</IconButton>
|
|
156
|
+
)
|
|
157
|
+
: null}
|
|
158
|
+
{onNewFile
|
|
159
|
+
? (
|
|
160
|
+
<IconButton
|
|
161
|
+
aria-label={t.newFile}
|
|
162
|
+
title={t.newFile}
|
|
163
|
+
onClick={onClickNewFile}
|
|
164
|
+
style={{ position: 'relative' }}
|
|
165
|
+
>
|
|
166
|
+
<AddCode />
|
|
167
|
+
</IconButton>
|
|
168
|
+
)
|
|
169
|
+
: null}
|
|
170
|
+
</div>
|
|
171
|
+
)}
|
|
172
|
+
<div>
|
|
173
|
+
<SyntaxHighlighter
|
|
174
|
+
{...props}
|
|
175
|
+
className="highlighter"
|
|
176
|
+
style={themeKind === 'dark' ? materialDark : vs}
|
|
177
|
+
language={computedLanguage}
|
|
178
|
+
PreTag="div"
|
|
179
|
+
showLineNumbers={true}
|
|
180
|
+
lineNumberContainerStyle={lineNumbersStyle}
|
|
181
|
+
lineNumberStyle={lineNumbersStyle}
|
|
182
|
+
>
|
|
183
|
+
{content}
|
|
184
|
+
</SyntaxHighlighter>
|
|
185
|
+
</div>
|
|
186
|
+
</CodeBox>
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const dictionary = {
|
|
191
|
+
en: {
|
|
192
|
+
copy: 'Copy code to the clipboard',
|
|
193
|
+
insert: 'Inject code into editor',
|
|
194
|
+
newFile: 'Creates a new file with this code as its content',
|
|
195
|
+
},
|
|
196
|
+
pt: {
|
|
197
|
+
copy: 'Copiar código para a área de transferência',
|
|
198
|
+
insert: 'Inserir código no editor',
|
|
199
|
+
newFile: 'Criar um novo arquivo com este código como conteúdo',
|
|
200
|
+
},
|
|
201
|
+
} satisfies Dictionary
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* eslint-disable no-empty-pattern */
|
|
2
|
+
/* Copiar do portal AI? */
|
|
3
|
+
import { WithStyle } from '@stack-spot/portal-theme'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
interface Props extends WithStyle {
|
|
7
|
+
value: string,
|
|
8
|
+
onChange: (value: string) => void,
|
|
9
|
+
language: string,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const Editor = ({}: Props) => null
|