npcts 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/LICENSE +21 -0
- package/README.md +139 -0
- package/dist/adapters/base.d.ts +13 -0
- package/dist/adapters/base.js +1 -0
- package/dist/adapters/electron/bridge.d.ts +4 -0
- package/dist/adapters/electron/bridge.js +88 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.js +3 -0
- package/dist/core/browser.d.ts +25 -0
- package/dist/core/browser.js +1 -0
- package/dist/core/chat.d.ts +41 -0
- package/dist/core/chat.js +1 -0
- package/dist/core/database.d.ts +56 -0
- package/dist/core/database.js +50 -0
- package/dist/core/files.d.ts +24 -0
- package/dist/core/files.js +15 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.js +10 -0
- package/dist/core/jobs.d.ts +20 -0
- package/dist/core/jobs.js +1 -0
- package/dist/core/layout.d.ts +30 -0
- package/dist/core/layout.js +41 -0
- package/dist/core/stream.d.ts +10 -0
- package/dist/core/stream.js +1 -0
- package/dist/core/types.d.ts +23 -0
- package/dist/core/types.js +1 -0
- package/dist/core/utils.d.ts +19 -0
- package/dist/core/utils.js +19 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +29 -0
- package/dist/ui/chat/components/ChatHeaderBar.d.ts +13 -0
- package/dist/ui/chat/components/ChatHeaderBar.js +32 -0
- package/dist/ui/chat/components/ChatInterface.d.ts +10 -0
- package/dist/ui/chat/components/ChatInterface.js +19 -0
- package/dist/ui/chat/components/ChatMessage.d.ts +7 -0
- package/dist/ui/chat/components/ChatMessage.js +10 -0
- package/dist/ui/chat/components/ChatPane.d.ts +20 -0
- package/dist/ui/chat/components/ChatPane.js +20 -0
- package/dist/ui/chat/components/ChatView.d.ts +10 -0
- package/dist/ui/chat/components/ChatView.js +36 -0
- package/dist/ui/chat/components/ConversationList.d.ts +28 -0
- package/dist/ui/chat/components/ConversationList.js +113 -0
- package/dist/ui/chat/components/InPaneSearchBar.d.ts +12 -0
- package/dist/ui/chat/components/InPaneSearchBar.js +44 -0
- package/dist/ui/chat/components/InputArea.d.ts +7 -0
- package/dist/ui/chat/components/InputArea.js +46 -0
- package/dist/ui/chat/components/MessageAttachments.d.ts +5 -0
- package/dist/ui/chat/components/MessageAttachments.js +6 -0
- package/dist/ui/chat/components/MessageItem.d.ts +28 -0
- package/dist/ui/chat/components/MessageItem.js +43 -0
- package/dist/ui/chat/components/PredictiveTextOverlay.d.ts +10 -0
- package/dist/ui/chat/components/PredictiveTextOverlay.js +75 -0
- package/dist/ui/chat/context/ChatContext.d.ts +33 -0
- package/dist/ui/chat/context/ChatContext.js +157 -0
- package/dist/ui/chat/hooks/useAutoScroll.d.ts +1 -0
- package/dist/ui/chat/hooks/useAutoScroll.js +11 -0
- package/dist/ui/chat/index.d.ts +7 -0
- package/dist/ui/chat/index.js +7 -0
- package/dist/ui/dashboard/ChartWidget.d.ts +18 -0
- package/dist/ui/dashboard/ChartWidget.js +98 -0
- package/dist/ui/dashboard/QueryWidget.d.ts +29 -0
- package/dist/ui/dashboard/QueryWidget.js +117 -0
- package/dist/ui/dashboard/TableWidget.d.ts +14 -0
- package/dist/ui/dashboard/TableWidget.js +117 -0
- package/dist/ui/dashboard/Widget.d.ts +40 -0
- package/dist/ui/dashboard/Widget.js +26 -0
- package/dist/ui/dashboard/WidgetBuilder.d.ts +47 -0
- package/dist/ui/dashboard/WidgetBuilder.js +286 -0
- package/dist/ui/dashboard/WidgetGrid.d.ts +19 -0
- package/dist/ui/dashboard/WidgetGrid.js +11 -0
- package/dist/ui/dashboard/index.d.ts +8 -0
- package/dist/ui/dashboard/index.js +4 -0
- package/dist/ui/dialogs/BrowserUrlDialog.d.ts +8 -0
- package/dist/ui/dialogs/BrowserUrlDialog.js +203 -0
- package/dist/ui/dialogs/index.d.ts +1 -0
- package/dist/ui/dialogs/index.js +1 -0
- package/dist/ui/editors/ImageEditor.d.ts +49 -0
- package/dist/ui/editors/ImageEditor.js +264 -0
- package/dist/ui/editors/index.d.ts +2 -0
- package/dist/ui/editors/index.js +1 -0
- package/dist/ui/execution/ExecutionFilters.d.ts +11 -0
- package/dist/ui/execution/ExecutionFilters.js +27 -0
- package/dist/ui/execution/ExecutionHistoryList.d.ts +19 -0
- package/dist/ui/execution/ExecutionHistoryList.js +35 -0
- package/dist/ui/execution/index.d.ts +3 -0
- package/dist/ui/execution/index.js +2 -0
- package/dist/ui/files/components/FileTree.d.ts +18 -0
- package/dist/ui/files/components/FileTree.js +61 -0
- package/dist/ui/files/components/Sidebar.d.ts +18 -0
- package/dist/ui/files/components/Sidebar.js +67 -0
- package/dist/ui/files/components/index.d.ts +2 -0
- package/dist/ui/files/components/index.js +2 -0
- package/dist/ui/files/context/FileSystemContext.d.ts +23 -0
- package/dist/ui/files/context/FileSystemContext.js +65 -0
- package/dist/ui/files/context/index.d.ts +1 -0
- package/dist/ui/files/context/index.js +1 -0
- package/dist/ui/files/index.d.ts +2 -0
- package/dist/ui/files/index.js +2 -0
- package/dist/ui/hooks/index.d.ts +4 -0
- package/dist/ui/hooks/index.js +3 -0
- package/dist/ui/hooks/useDebounce.d.ts +8 -0
- package/dist/ui/hooks/useDebounce.js +18 -0
- package/dist/ui/hooks/usePaneTracking.d.ts +15 -0
- package/dist/ui/hooks/usePaneTracking.js +20 -0
- package/dist/ui/hooks/useQuery.d.ts +25 -0
- package/dist/ui/hooks/useQuery.js +71 -0
- package/dist/ui/index.d.ts +19 -0
- package/dist/ui/index.js +20 -0
- package/dist/ui/jinx/JinxEditor.d.ts +20 -0
- package/dist/ui/jinx/JinxEditor.js +34 -0
- package/dist/ui/jinx/JinxTree.d.ts +14 -0
- package/dist/ui/jinx/JinxTree.js +65 -0
- package/dist/ui/jinx/index.d.ts +3 -0
- package/dist/ui/jinx/index.js +2 -0
- package/dist/ui/knowledge-graph/KGControls.d.ts +12 -0
- package/dist/ui/knowledge-graph/KGControls.js +21 -0
- package/dist/ui/knowledge-graph/KGStats.d.ts +13 -0
- package/dist/ui/knowledge-graph/KGStats.js +18 -0
- package/dist/ui/knowledge-graph/KnowledgeGraphViewer.d.ts +22 -0
- package/dist/ui/knowledge-graph/KnowledgeGraphViewer.js +16 -0
- package/dist/ui/knowledge-graph/index.d.ts +4 -0
- package/dist/ui/knowledge-graph/index.js +3 -0
- package/dist/ui/layout/components/AppShell.d.ts +8 -0
- package/dist/ui/layout/components/AppShell.js +19 -0
- package/dist/ui/layout/components/ContentPaneContainer.d.ts +8 -0
- package/dist/ui/layout/components/ContentPaneContainer.js +95 -0
- package/dist/ui/layout/components/LayoutNode.d.ts +8 -0
- package/dist/ui/layout/components/LayoutNode.js +12 -0
- package/dist/ui/layout/components/PaneHeader.d.ts +17 -0
- package/dist/ui/layout/components/PaneHeader.js +40 -0
- package/dist/ui/layout/components/SplitView.d.ts +8 -0
- package/dist/ui/layout/components/SplitView.js +51 -0
- package/dist/ui/layout/components/Studio.d.ts +7 -0
- package/dist/ui/layout/components/Studio.js +12 -0
- package/dist/ui/layout/components/contextMenus/BrowserContextMenu.d.ts +13 -0
- package/dist/ui/layout/components/contextMenus/BrowserContextMenu.js +23 -0
- package/dist/ui/layout/components/contextMenus/EditorContextMenu.d.ts +15 -0
- package/dist/ui/layout/components/contextMenus/EditorContextMenu.js +32 -0
- package/dist/ui/layout/components/contextMenus/FileContextMenu.d.ts +15 -0
- package/dist/ui/layout/components/contextMenus/FileContextMenu.js +33 -0
- package/dist/ui/layout/components/contextMenus/PdfContextMenu.d.ts +13 -0
- package/dist/ui/layout/components/contextMenus/PdfContextMenu.js +23 -0
- package/dist/ui/layout/components/contextMenus/index.d.ts +4 -0
- package/dist/ui/layout/components/contextMenus/index.js +4 -0
- package/dist/ui/layout/components/index.d.ts +8 -0
- package/dist/ui/layout/components/index.js +8 -0
- package/dist/ui/layout/components/modals/AIEditModal.d.ts +9 -0
- package/dist/ui/layout/components/modals/AIEditModal.js +33 -0
- package/dist/ui/layout/components/modals/MemoryApprovalModal.d.ts +15 -0
- package/dist/ui/layout/components/modals/MemoryApprovalModal.js +23 -0
- package/dist/ui/layout/components/modals/PromptModal.d.ts +11 -0
- package/dist/ui/layout/components/modals/PromptModal.js +20 -0
- package/dist/ui/layout/components/modals/ResendModal.d.ts +16 -0
- package/dist/ui/layout/components/modals/ResendModal.js +22 -0
- package/dist/ui/layout/components/modals/index.d.ts +4 -0
- package/dist/ui/layout/components/modals/index.js +4 -0
- package/dist/ui/layout/context/LayoutContext.d.ts +32 -0
- package/dist/ui/layout/context/LayoutContext.js +144 -0
- package/dist/ui/layout/index.d.ts +2 -0
- package/dist/ui/layout/index.js +2 -0
- package/dist/ui/markdown/Markdown.d.ts +4 -0
- package/dist/ui/markdown/Markdown.js +4 -0
- package/dist/ui/memory/MemoryFilters.d.ts +12 -0
- package/dist/ui/memory/MemoryFilters.js +23 -0
- package/dist/ui/memory/MemoryList.d.ts +19 -0
- package/dist/ui/memory/MemoryList.js +36 -0
- package/dist/ui/memory/index.d.ts +3 -0
- package/dist/ui/memory/index.js +2 -0
- package/dist/ui/models/ModelCard.d.ts +16 -0
- package/dist/ui/models/ModelCard.js +30 -0
- package/dist/ui/models/ModelSelector.d.ts +13 -0
- package/dist/ui/models/ModelSelector.js +6 -0
- package/dist/ui/models/index.d.ts +3 -0
- package/dist/ui/models/index.js +2 -0
- package/dist/ui/npc/McpServerMenu.d.ts +15 -0
- package/dist/ui/npc/McpServerMenu.js +48 -0
- package/dist/ui/npc/NPCEditor.d.ts +21 -0
- package/dist/ui/npc/NPCEditor.js +17 -0
- package/dist/ui/npc/NPCList.d.ts +19 -0
- package/dist/ui/npc/NPCList.js +28 -0
- package/dist/ui/npc/index.d.ts +3 -0
- package/dist/ui/npc/index.js +2 -0
- package/dist/ui/photo/GalleryGrid.d.ts +25 -0
- package/dist/ui/photo/GalleryGrid.js +46 -0
- package/dist/ui/photo/ImageAdjustmentSliders.d.ts +37 -0
- package/dist/ui/photo/ImageAdjustmentSliders.js +56 -0
- package/dist/ui/photo/ImageLabelingCanvas.d.ts +47 -0
- package/dist/ui/photo/ImageLabelingCanvas.js +174 -0
- package/dist/ui/photo/ImageSourceTabs.d.ts +28 -0
- package/dist/ui/photo/ImageSourceTabs.js +46 -0
- package/dist/ui/photo/LayerPanel.d.ts +87 -0
- package/dist/ui/photo/LayerPanel.js +70 -0
- package/dist/ui/photo/Lightbox.d.ts +12 -0
- package/dist/ui/photo/Lightbox.js +90 -0
- package/dist/ui/photo/index.d.ts +6 -0
- package/dist/ui/photo/index.js +7 -0
- package/dist/ui/primitives/AutosizeTextarea.d.ts +8 -0
- package/dist/ui/primitives/AutosizeTextarea.js +17 -0
- package/dist/ui/primitives/Button.d.ts +7 -0
- package/dist/ui/primitives/Button.js +17 -0
- package/dist/ui/primitives/Card.d.ts +12 -0
- package/dist/ui/primitives/Card.js +8 -0
- package/dist/ui/primitives/Chart.d.ts +34 -0
- package/dist/ui/primitives/Chart.js +140 -0
- package/dist/ui/primitives/ContextMenu.d.ts +17 -0
- package/dist/ui/primitives/ContextMenu.js +33 -0
- package/dist/ui/primitives/DataTable.d.ts +13 -0
- package/dist/ui/primitives/DataTable.js +13 -0
- package/dist/ui/primitives/FileUpload.d.ts +10 -0
- package/dist/ui/primitives/FileUpload.js +24 -0
- package/dist/ui/primitives/ImageGrid.d.ts +21 -0
- package/dist/ui/primitives/ImageGrid.js +29 -0
- package/dist/ui/primitives/Input.d.ts +7 -0
- package/dist/ui/primitives/Input.js +10 -0
- package/dist/ui/primitives/Lightbox.d.ts +12 -0
- package/dist/ui/primitives/Lightbox.js +36 -0
- package/dist/ui/primitives/Modal.d.ts +10 -0
- package/dist/ui/primitives/Modal.js +33 -0
- package/dist/ui/primitives/RangeSlider.d.ts +13 -0
- package/dist/ui/primitives/RangeSlider.js +6 -0
- package/dist/ui/primitives/Select.d.ts +11 -0
- package/dist/ui/primitives/Select.js +10 -0
- package/dist/ui/primitives/Slider.d.ts +13 -0
- package/dist/ui/primitives/Slider.js +8 -0
- package/dist/ui/primitives/SortableList.d.ts +9 -0
- package/dist/ui/primitives/SortableList.js +19 -0
- package/dist/ui/primitives/Spinner.d.ts +2 -0
- package/dist/ui/primitives/Spinner.js +2 -0
- package/dist/ui/primitives/StarRating.d.ts +10 -0
- package/dist/ui/primitives/StarRating.js +10 -0
- package/dist/ui/primitives/Tabs.d.ts +15 -0
- package/dist/ui/primitives/Tabs.js +11 -0
- package/dist/ui/primitives/TagInput.d.ts +10 -0
- package/dist/ui/primitives/TagInput.js +25 -0
- package/dist/ui/primitives/index.d.ts +20 -0
- package/dist/ui/primitives/index.js +19 -0
- package/dist/ui/specialized/DiskUsageAnalyzer.d.ts +12 -0
- package/dist/ui/specialized/DiskUsageAnalyzer.js +38 -0
- package/dist/ui/specialized/OllamaModelManager.d.ts +2 -0
- package/dist/ui/specialized/OllamaModelManager.js +48 -0
- package/dist/ui/specialized/RichTextEditor.d.ts +8 -0
- package/dist/ui/specialized/RichTextEditor.js +64 -0
- package/dist/ui/specialized/SlideCanvas.d.ts +24 -0
- package/dist/ui/specialized/SlideCanvas.js +31 -0
- package/dist/ui/specialized/SpreadsheetGrid.d.ts +18 -0
- package/dist/ui/specialized/SpreadsheetGrid.js +28 -0
- package/dist/ui/specialized/StepEditor.d.ts +12 -0
- package/dist/ui/specialized/StepEditor.js +22 -0
- package/dist/ui/specialized/TerminalEmbed.d.ts +13 -0
- package/dist/ui/specialized/TerminalEmbed.js +50 -0
- package/dist/ui/specialized/index.d.ts +7 -0
- package/dist/ui/specialized/index.js +7 -0
- package/dist/ui/sql/SQLQueryEditor.d.ts +9 -0
- package/dist/ui/sql/SQLQueryEditor.js +10 -0
- package/dist/ui/sql/SQLResultsTable.d.ts +6 -0
- package/dist/ui/sql/SQLResultsTable.js +12 -0
- package/dist/ui/sql/SQLSchemaViewer.d.ts +14 -0
- package/dist/ui/sql/SQLSchemaViewer.js +18 -0
- package/dist/ui/sql/index.d.ts +3 -0
- package/dist/ui/sql/index.js +3 -0
- package/dist/ui/utils/cn.d.ts +1 -0
- package/dist/ui/utils/cn.js +1 -0
- package/dist/ui/utils/fileIcons.d.ts +2 -0
- package/dist/ui/utils/fileIcons.js +24 -0
- package/dist/ui/utils/fileUtils.d.ts +4 -0
- package/dist/ui/utils/fileUtils.js +11 -0
- package/dist/ui/utils/index.d.ts +3 -0
- package/dist/ui/utils/index.js +3 -0
- package/dist/ui/viewers/components/BrowserViewer.d.ts +9 -0
- package/dist/ui/viewers/components/BrowserViewer.js +44 -0
- package/dist/ui/viewers/components/CodeEditor.d.ts +11 -0
- package/dist/ui/viewers/components/CodeEditor.js +115 -0
- package/dist/ui/viewers/components/CsvViewer.d.ts +7 -0
- package/dist/ui/viewers/components/CsvViewer.js +18 -0
- package/dist/ui/viewers/components/ImageViewer.d.ts +7 -0
- package/dist/ui/viewers/components/ImageViewer.js +23 -0
- package/dist/ui/viewers/components/PdfViewer.d.ts +7 -0
- package/dist/ui/viewers/components/PdfViewer.js +29 -0
- package/dist/ui/viewers/components/Terminal.d.ts +7 -0
- package/dist/ui/viewers/components/Terminal.js +31 -0
- package/dist/ui/viewers/components/index.d.ts +6 -0
- package/dist/ui/viewers/components/index.js +6 -0
- package/dist/ui/viewers/index.d.ts +1 -0
- package/dist/ui/viewers/index.js +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { memo } from "react";
|
|
2
|
+
import { Paperclip, Wrench } from "lucide-react";
|
|
3
|
+
export const MessageItem = memo(({ message, isSelected, messageSelectionMode, toggleMessageSelection, handleMessageContextMenu, searchTerm, isCurrentSearchResult, onResendMessage, onCreateBranch, messageIndex, }) => {
|
|
4
|
+
const messageId = message.id || message.timestamp || String(messageIndex);
|
|
5
|
+
return (React.createElement("div", { id: `message-${messageId}`, className: `max-w-[85%] rounded-lg p-3 relative group ${message.role === "user" ? "theme-message-user" : "theme-message-assistant"} ${message.type === "error" ? "theme-message-error theme-border" : ""} ${isSelected ? "ring-2 ring-blue-500" : ""} ${isCurrentSearchResult ? "ring-2 ring-yellow-500" : ""} ${messageSelectionMode ? "cursor-pointer" : ""}`, onClick: () => messageSelectionMode && toggleMessageSelection(messageId), onContextMenu: (e) => handleMessageContextMenu(e, messageId) },
|
|
6
|
+
messageSelectionMode && (React.createElement("div", { className: "absolute top-2 right-2 z-10" },
|
|
7
|
+
React.createElement("input", { type: "checkbox", checked: isSelected, onChange: () => toggleMessageSelection(messageId), className: "w-4 h-4 text-blue-600 bg-gray-700 border-gray-600 rounded focus:ring-blue-500", onClick: (e) => e.stopPropagation() }))),
|
|
8
|
+
message.role === "user" && !messageSelectionMode && onCreateBranch && (React.createElement("div", { className: "absolute top-2 left-2 opacity-0 group-hover:opacity-100 transition-opacity z-10" },
|
|
9
|
+
React.createElement("button", { onClick: (e) => {
|
|
10
|
+
e.stopPropagation();
|
|
11
|
+
onCreateBranch(messageIndex);
|
|
12
|
+
}, className: "p-1 theme-hover rounded-full transition-all", title: "Create branch from here" },
|
|
13
|
+
React.createElement("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2" },
|
|
14
|
+
React.createElement("line", { x1: "6", y1: "3", x2: "6", y2: "15" }),
|
|
15
|
+
React.createElement("circle", { cx: "18", cy: "6", r: "3" }),
|
|
16
|
+
React.createElement("circle", { cx: "6", cy: "18", r: "3" }),
|
|
17
|
+
React.createElement("path", { d: "M18 9a9 9 0 0 1-9 9" }))))),
|
|
18
|
+
message.role === "user" && !messageSelectionMode && onResendMessage && (React.createElement("div", { className: "absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity z-10" },
|
|
19
|
+
React.createElement("button", { onClick: (e) => {
|
|
20
|
+
e.stopPropagation();
|
|
21
|
+
onResendMessage(message);
|
|
22
|
+
}, className: "p-1 theme-hover rounded-full transition-all", title: "Resend" },
|
|
23
|
+
React.createElement("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" },
|
|
24
|
+
React.createElement("polyline", { points: "23 4 23 10 17 10" }),
|
|
25
|
+
React.createElement("path", { d: "M20.49 15a9 9 0 1 1-2.12-9.36L23 10" }))))),
|
|
26
|
+
React.createElement("div", { className: "flex justify-between items-center text-xs theme-text-muted mb-1 opacity-80" },
|
|
27
|
+
React.createElement("span", { className: "font-semibold" }, message.role === "user" ? "You" : (message.npc || "Agent")),
|
|
28
|
+
React.createElement("div", { className: "flex items-center gap-2" },
|
|
29
|
+
message.role !== "user" && message.model && (React.createElement("span", { className: "truncate", title: message.model }, message.model)),
|
|
30
|
+
React.createElement("span", null, message.timestamp ? new Date(message.timestamp).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) : ""))),
|
|
31
|
+
React.createElement("div", { className: "whitespace-pre-wrap break-words" }, message.content),
|
|
32
|
+
(message.attachments?.length || message.tool_calls?.length || message.tool_use_history?.length) ? (React.createElement("div", { className: "mt-2 flex flex-wrap gap-2 text-xs theme-text-muted" },
|
|
33
|
+
message.attachments?.length ? (React.createElement("span", { className: "flex items-center gap-1" },
|
|
34
|
+
React.createElement(Paperclip, { size: 12 }),
|
|
35
|
+
" ",
|
|
36
|
+
message.attachments.length,
|
|
37
|
+
" attachments")) : null,
|
|
38
|
+
(message.tool_calls?.length || message.tool_use_history?.length) ? (React.createElement("span", { className: "flex items-center gap-1" },
|
|
39
|
+
React.createElement(Wrench, { size: 12 }),
|
|
40
|
+
" ",
|
|
41
|
+
(message.tool_calls?.length || 0) + (message.tool_use_history?.length || 0),
|
|
42
|
+
" tool calls")) : null)) : null));
|
|
43
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface Props {
|
|
3
|
+
predictionSuggestion: string;
|
|
4
|
+
predictionTargetElement: HTMLElement | null;
|
|
5
|
+
isPredictiveTextEnabled: boolean;
|
|
6
|
+
setPredictionSuggestion: (value: string) => void;
|
|
7
|
+
setPredictionTargetElement: (el: HTMLElement | null) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const PredictiveTextOverlay: React.FC<Props>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef } from "react";
|
|
2
|
+
export const PredictiveTextOverlay = ({ predictionSuggestion, predictionTargetElement, isPredictiveTextEnabled, setPredictionSuggestion, setPredictionTargetElement, }) => {
|
|
3
|
+
if (!predictionSuggestion || !predictionTargetElement || !isPredictiveTextEnabled) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
const targetRect = predictionTargetElement.getBoundingClientRect();
|
|
7
|
+
const overlayRef = useRef(null);
|
|
8
|
+
const handleAcceptSuggestion = useCallback(() => {
|
|
9
|
+
if (predictionTargetElement && predictionSuggestion) {
|
|
10
|
+
const suggestionToInsert = predictionSuggestion.trim();
|
|
11
|
+
if (predictionTargetElement instanceof HTMLTextAreaElement ||
|
|
12
|
+
predictionTargetElement instanceof HTMLInputElement) {
|
|
13
|
+
const start = predictionTargetElement.selectionStart || 0;
|
|
14
|
+
const end = predictionTargetElement.selectionEnd || 0;
|
|
15
|
+
const value = predictionTargetElement.value;
|
|
16
|
+
predictionTargetElement.value = value.substring(0, start) + suggestionToInsert + value.substring(end);
|
|
17
|
+
predictionTargetElement.selectionStart = predictionTargetElement.selectionEnd = start + suggestionToInsert.length;
|
|
18
|
+
const event = new Event("input", { bubbles: true });
|
|
19
|
+
predictionTargetElement.dispatchEvent(event);
|
|
20
|
+
}
|
|
21
|
+
else if (predictionTargetElement.isContentEditable) {
|
|
22
|
+
const selection = window.getSelection();
|
|
23
|
+
if (selection && selection.rangeCount > 0) {
|
|
24
|
+
const range = selection.getRangeAt(0);
|
|
25
|
+
range.deleteContents();
|
|
26
|
+
range.insertNode(document.createTextNode(suggestionToInsert));
|
|
27
|
+
range.setStart(range.endContainer, range.endOffset);
|
|
28
|
+
range.collapse(true);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
setPredictionSuggestion("");
|
|
32
|
+
setPredictionTargetElement(null);
|
|
33
|
+
}
|
|
34
|
+
}, [predictionSuggestion, predictionTargetElement, setPredictionSuggestion, setPredictionTargetElement]);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const handleOverlayKeyDown = (e) => {
|
|
37
|
+
if (e.key === "Tab" && predictionSuggestion) {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
handleAcceptSuggestion();
|
|
40
|
+
}
|
|
41
|
+
else if (e.key === "Escape") {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
setPredictionSuggestion("");
|
|
44
|
+
setPredictionTargetElement(null);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
document.addEventListener("keydown", handleOverlayKeyDown);
|
|
48
|
+
return () => document.removeEventListener("keydown", handleOverlayKeyDown);
|
|
49
|
+
}, [handleAcceptSuggestion, predictionSuggestion, setPredictionSuggestion, setPredictionTargetElement]);
|
|
50
|
+
const style = {
|
|
51
|
+
position: "fixed",
|
|
52
|
+
left: targetRect.left,
|
|
53
|
+
top: targetRect.bottom + 5,
|
|
54
|
+
zIndex: 1000,
|
|
55
|
+
maxWidth: targetRect.width,
|
|
56
|
+
backgroundColor: "var(--theme-bg-secondary)",
|
|
57
|
+
border: "1px solid var(--theme-border)",
|
|
58
|
+
borderRadius: "4px",
|
|
59
|
+
boxShadow: "0 2px 8px rgba(0,0,0,0.2)",
|
|
60
|
+
padding: "8px",
|
|
61
|
+
color: "var(--theme-text-muted)",
|
|
62
|
+
fontSize: "0.875rem",
|
|
63
|
+
whiteSpace: "pre-wrap",
|
|
64
|
+
cursor: "text",
|
|
65
|
+
};
|
|
66
|
+
return (React.createElement("div", { ref: overlayRef, style: style, onClick: handleAcceptSuggestion },
|
|
67
|
+
predictionSuggestion,
|
|
68
|
+
predictionSuggestion === "Generating..." && (React.createElement("span", { className: "ml-1 inline-block w-1.5 h-1.5 theme-text-muted rounded-full animate-bounce", style: { animationDelay: "0.15s" } })),
|
|
69
|
+
React.createElement("div", { className: "text-xs text-blue-400 mt-1" },
|
|
70
|
+
"Press ",
|
|
71
|
+
React.createElement("span", { className: "font-bold" }, "Tab"),
|
|
72
|
+
" to accept, ",
|
|
73
|
+
React.createElement("span", { className: "font-bold" }, "Esc"),
|
|
74
|
+
" to dismiss.")));
|
|
75
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ChatMessage, ChatSendRequest, Conversation } from "../../../core/chat";
|
|
3
|
+
import type { Attachment } from "../../../core/types";
|
|
4
|
+
import type { AppServices } from "../../../adapters/base";
|
|
5
|
+
import type { ModelInfo } from "../../../core/types";
|
|
6
|
+
type MessageMap = Record<string, ChatMessage[]>;
|
|
7
|
+
interface ChatState {
|
|
8
|
+
conversations: Conversation[];
|
|
9
|
+
messages: MessageMap;
|
|
10
|
+
activeConversationId?: string;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
streaming: boolean;
|
|
13
|
+
error?: string;
|
|
14
|
+
send: (payload: Omit<ChatSendRequest, "conversationId">) => Promise<void>;
|
|
15
|
+
setActiveConversation: (id: string) => void;
|
|
16
|
+
createConversation: (workspacePath?: string) => Promise<void>;
|
|
17
|
+
deleteConversation: (id: string) => Promise<void>;
|
|
18
|
+
deleteMessage: (messageId: string) => Promise<void>;
|
|
19
|
+
refreshMessages: (id: string) => Promise<void>;
|
|
20
|
+
setWorkspacePath: (path?: string) => void;
|
|
21
|
+
workspacePath?: string;
|
|
22
|
+
models?: ModelInfo[];
|
|
23
|
+
attachments: Attachment[];
|
|
24
|
+
setAttachments: React.Dispatch<React.SetStateAction<Attachment[]>>;
|
|
25
|
+
}
|
|
26
|
+
export declare const ChatProvider: React.FC<{
|
|
27
|
+
services: AppServices;
|
|
28
|
+
workspacePath?: string;
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
models?: ModelInfo[];
|
|
31
|
+
}>;
|
|
32
|
+
export declare const useChatContext: () => ChatState;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import React, { createContext, useContext, useEffect, useMemo, useState } from "react";
|
|
2
|
+
const ChatContext = createContext(undefined);
|
|
3
|
+
export const ChatProvider = ({ services, workspacePath, children, models }) => {
|
|
4
|
+
const [conversations, setConversations] = useState([]);
|
|
5
|
+
const [messages, setMessages] = useState({});
|
|
6
|
+
const [activeConversationId, setActiveConversationId] = useState();
|
|
7
|
+
const [loading, setLoading] = useState(false);
|
|
8
|
+
const [streaming, setStreaming] = useState(false);
|
|
9
|
+
const [error, setError] = useState();
|
|
10
|
+
const [attachments, setAttachments] = useState([]);
|
|
11
|
+
const [currentWorkspace, setCurrentWorkspace] = useState(workspacePath);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
setCurrentWorkspace(workspacePath);
|
|
14
|
+
}, [workspacePath]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const load = async () => {
|
|
17
|
+
setLoading(true);
|
|
18
|
+
try {
|
|
19
|
+
const convsRaw = await services.chat.listConversations(currentWorkspace);
|
|
20
|
+
const convs = Array.isArray(convsRaw)
|
|
21
|
+
? convsRaw
|
|
22
|
+
: Array.isArray(convsRaw?.conversations)
|
|
23
|
+
? convsRaw.conversations
|
|
24
|
+
: [];
|
|
25
|
+
setConversations(convs);
|
|
26
|
+
if (!activeConversationId && convs[0]) {
|
|
27
|
+
setActiveConversationId(convs[0].id);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
setError(err instanceof Error ? err.message : "Failed to load conversations");
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
setLoading(false);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
load();
|
|
38
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
39
|
+
}, [currentWorkspace]);
|
|
40
|
+
const refreshMessages = async (id) => {
|
|
41
|
+
try {
|
|
42
|
+
const msgs = await services.chat.listMessages(id);
|
|
43
|
+
setMessages((prev) => ({ ...prev, [id]: msgs }));
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
setError(err instanceof Error ? err.message : "Failed to load messages");
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (activeConversationId) {
|
|
51
|
+
refreshMessages(activeConversationId);
|
|
52
|
+
}
|
|
53
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
|
+
}, [activeConversationId]);
|
|
55
|
+
const send = async (payload) => {
|
|
56
|
+
if (!activeConversationId)
|
|
57
|
+
return;
|
|
58
|
+
setStreaming(Boolean(payload.stream));
|
|
59
|
+
try {
|
|
60
|
+
const result = await services.chat.sendMessage({
|
|
61
|
+
...payload,
|
|
62
|
+
conversationId: activeConversationId,
|
|
63
|
+
});
|
|
64
|
+
if (typeof result?.[Symbol.asyncIterator] === "function") {
|
|
65
|
+
const chunks = [];
|
|
66
|
+
for await (const chunk of result) {
|
|
67
|
+
if (chunk?.delta) {
|
|
68
|
+
chunks.push(chunk.delta);
|
|
69
|
+
setMessages((prev) => {
|
|
70
|
+
const prevMsgs = prev[activeConversationId] || [];
|
|
71
|
+
const last = prevMsgs[prevMsgs.length - 1];
|
|
72
|
+
const partial = last && last.role === "assistant" && last.metadata?.streaming
|
|
73
|
+
? { ...last, content: (last.content || "") + chunk.delta }
|
|
74
|
+
: {
|
|
75
|
+
id: chunk.messageId ?? `stream-${Date.now()}`,
|
|
76
|
+
role: "assistant",
|
|
77
|
+
content: chunk.delta,
|
|
78
|
+
metadata: { streaming: true },
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
...prev,
|
|
82
|
+
[activeConversationId]: [...prevMsgs.filter((m) => m !== last), partial],
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (result) {
|
|
89
|
+
await refreshMessages(activeConversationId);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
setError(err instanceof Error ? err.message : "Failed to send message");
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
setStreaming(false);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const createConversation = async (ws) => {
|
|
100
|
+
const newConv = await services.chat.createConversation(ws ?? currentWorkspace);
|
|
101
|
+
setConversations((prev) => [newConv, ...prev]);
|
|
102
|
+
setActiveConversationId(newConv.id);
|
|
103
|
+
};
|
|
104
|
+
const deleteConversation = async (id) => {
|
|
105
|
+
await services.chat.deleteConversation(id);
|
|
106
|
+
setConversations((prev) => prev.filter((c) => c.id !== id));
|
|
107
|
+
setMessages((prev) => {
|
|
108
|
+
const { [id]: _, ...rest } = prev;
|
|
109
|
+
return rest;
|
|
110
|
+
});
|
|
111
|
+
if (activeConversationId === id) {
|
|
112
|
+
setActiveConversationId(conversations.find((c) => c.id !== id)?.id);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const deleteMessage = async (messageId) => {
|
|
116
|
+
if (!activeConversationId)
|
|
117
|
+
return;
|
|
118
|
+
await services.chat.deleteMessage(activeConversationId, messageId);
|
|
119
|
+
await refreshMessages(activeConversationId);
|
|
120
|
+
};
|
|
121
|
+
const value = useMemo(() => ({
|
|
122
|
+
conversations,
|
|
123
|
+
messages,
|
|
124
|
+
activeConversationId,
|
|
125
|
+
loading,
|
|
126
|
+
streaming,
|
|
127
|
+
error,
|
|
128
|
+
send,
|
|
129
|
+
setActiveConversation: setActiveConversationId,
|
|
130
|
+
createConversation,
|
|
131
|
+
deleteConversation,
|
|
132
|
+
deleteMessage,
|
|
133
|
+
refreshMessages,
|
|
134
|
+
workspacePath: currentWorkspace,
|
|
135
|
+
setWorkspacePath: setCurrentWorkspace,
|
|
136
|
+
models,
|
|
137
|
+
attachments,
|
|
138
|
+
setAttachments,
|
|
139
|
+
}), [
|
|
140
|
+
activeConversationId,
|
|
141
|
+
attachments,
|
|
142
|
+
conversations,
|
|
143
|
+
currentWorkspace,
|
|
144
|
+
error,
|
|
145
|
+
loading,
|
|
146
|
+
messages,
|
|
147
|
+
models,
|
|
148
|
+
streaming,
|
|
149
|
+
]);
|
|
150
|
+
return React.createElement(ChatContext.Provider, { value: value }, children);
|
|
151
|
+
};
|
|
152
|
+
export const useChatContext = () => {
|
|
153
|
+
const ctx = useContext(ChatContext);
|
|
154
|
+
if (!ctx)
|
|
155
|
+
throw new Error("useChatContext must be used within ChatProvider");
|
|
156
|
+
return ctx;
|
|
157
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useAutoScroll: <T extends HTMLElement>(deps?: unknown[]) => import("react").MutableRefObject<T>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
export const useAutoScroll = (deps = []) => {
|
|
3
|
+
const ref = useRef(null);
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
if (ref.current) {
|
|
6
|
+
ref.current.scrollTop = ref.current.scrollHeight;
|
|
7
|
+
}
|
|
8
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
9
|
+
}, deps);
|
|
10
|
+
return ref;
|
|
11
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./components/ChatInterface";
|
|
2
|
+
export * from "./components/ChatView";
|
|
3
|
+
export * from "./components/ChatPane";
|
|
4
|
+
export * from "./components/ConversationList";
|
|
5
|
+
export * from "./components/InputArea";
|
|
6
|
+
export * from "./components/MessageItem";
|
|
7
|
+
export * from "./context/ChatContext";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./components/ChatInterface";
|
|
2
|
+
export * from "./components/ChatView";
|
|
3
|
+
export * from "./components/ChatPane";
|
|
4
|
+
export * from "./components/ConversationList";
|
|
5
|
+
export * from "./components/InputArea";
|
|
6
|
+
export * from "./components/MessageItem";
|
|
7
|
+
export * from "./context/ChatContext";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import 'chartjs-adapter-date-fns';
|
|
3
|
+
export interface ChartConfig {
|
|
4
|
+
x: string;
|
|
5
|
+
y: string;
|
|
6
|
+
type: 'bar' | 'line' | 'scatter';
|
|
7
|
+
groupBy?: string;
|
|
8
|
+
colors?: string[];
|
|
9
|
+
}
|
|
10
|
+
interface ChartWidgetProps {
|
|
11
|
+
data: Record<string, any>[];
|
|
12
|
+
config: ChartConfig;
|
|
13
|
+
height?: number;
|
|
14
|
+
showLegend?: boolean;
|
|
15
|
+
showGrid?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const ChartWidget: React.FC<ChartWidgetProps>;
|
|
18
|
+
export default ChartWidget;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { Line, Bar } from 'react-chartjs-2';
|
|
3
|
+
import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, LineElement, BarElement, Title, Tooltip, Legend, Filler, TimeScale, TimeSeriesScale } from 'chart.js';
|
|
4
|
+
import 'chartjs-adapter-date-fns';
|
|
5
|
+
// Register Chart.js components
|
|
6
|
+
ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, BarElement, Title, Tooltip, Legend, Filler, TimeScale, TimeSeriesScale);
|
|
7
|
+
const defaultColors = [
|
|
8
|
+
'rgba(59, 130, 246, 0.8)', // blue
|
|
9
|
+
'rgba(239, 68, 68, 0.8)', // red
|
|
10
|
+
'rgba(34, 197, 94, 0.8)', // green
|
|
11
|
+
'rgba(245, 158, 11, 0.8)', // amber
|
|
12
|
+
'rgba(139, 92, 246, 0.8)', // purple
|
|
13
|
+
'rgba(236, 72, 153, 0.8)', // pink
|
|
14
|
+
'rgba(20, 184, 166, 0.8)', // teal
|
|
15
|
+
'rgba(249, 115, 22, 0.8)', // orange
|
|
16
|
+
];
|
|
17
|
+
export const ChartWidget = ({ data, config, height = 300, showLegend = true, showGrid = true }) => {
|
|
18
|
+
const chartData = useMemo(() => {
|
|
19
|
+
if (!data || data.length === 0)
|
|
20
|
+
return null;
|
|
21
|
+
// Extract x-axis labels
|
|
22
|
+
const xKey = config.x.includes(' AS ')
|
|
23
|
+
? config.x.split(' AS ')[1].trim()
|
|
24
|
+
: config.x;
|
|
25
|
+
const labels = data.map(row => row[xKey] ?? row[config.x] ?? '');
|
|
26
|
+
// Parse y-axis (can be comma-separated for multiple series)
|
|
27
|
+
const yKeys = config.y.split(',').map(y => {
|
|
28
|
+
const trimmed = y.trim();
|
|
29
|
+
return trimmed.includes(' AS ')
|
|
30
|
+
? trimmed.split(' AS ')[1].trim()
|
|
31
|
+
: trimmed;
|
|
32
|
+
});
|
|
33
|
+
const colors = config.colors || defaultColors;
|
|
34
|
+
const datasets = yKeys.map((yKey, index) => ({
|
|
35
|
+
label: yKey,
|
|
36
|
+
data: data.map(row => {
|
|
37
|
+
const value = row[yKey] ?? row[config.y.split(',')[index]?.trim()];
|
|
38
|
+
return typeof value === 'number' ? value : parseFloat(value) || 0;
|
|
39
|
+
}),
|
|
40
|
+
backgroundColor: colors[index % colors.length],
|
|
41
|
+
borderColor: colors[index % colors.length].replace('0.8', '1'),
|
|
42
|
+
borderWidth: config.type === 'line' ? 2 : 1,
|
|
43
|
+
fill: config.type === 'line' ? false : undefined,
|
|
44
|
+
tension: config.type === 'line' ? 0.3 : undefined,
|
|
45
|
+
}));
|
|
46
|
+
return { labels, datasets };
|
|
47
|
+
}, [data, config]);
|
|
48
|
+
const options = useMemo(() => ({
|
|
49
|
+
responsive: true,
|
|
50
|
+
maintainAspectRatio: false,
|
|
51
|
+
plugins: {
|
|
52
|
+
legend: {
|
|
53
|
+
display: showLegend && chartData && chartData.datasets.length > 1,
|
|
54
|
+
position: 'top',
|
|
55
|
+
labels: {
|
|
56
|
+
color: '#9ca3af',
|
|
57
|
+
font: { size: 11 }
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
tooltip: {
|
|
61
|
+
backgroundColor: 'rgba(17, 24, 39, 0.9)',
|
|
62
|
+
titleColor: '#f3f4f6',
|
|
63
|
+
bodyColor: '#d1d5db',
|
|
64
|
+
borderColor: '#374151',
|
|
65
|
+
borderWidth: 1,
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
scales: {
|
|
69
|
+
x: {
|
|
70
|
+
grid: {
|
|
71
|
+
display: showGrid,
|
|
72
|
+
color: 'rgba(75, 85, 99, 0.3)'
|
|
73
|
+
},
|
|
74
|
+
ticks: {
|
|
75
|
+
color: '#9ca3af',
|
|
76
|
+
font: { size: 10 }
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
y: {
|
|
80
|
+
grid: {
|
|
81
|
+
display: showGrid,
|
|
82
|
+
color: 'rgba(75, 85, 99, 0.3)'
|
|
83
|
+
},
|
|
84
|
+
ticks: {
|
|
85
|
+
color: '#9ca3af',
|
|
86
|
+
font: { size: 10 }
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}), [showLegend, showGrid, chartData]);
|
|
91
|
+
if (!chartData) {
|
|
92
|
+
return (React.createElement("div", { className: "flex items-center justify-center h-full text-gray-500" }, "No data available"));
|
|
93
|
+
}
|
|
94
|
+
const ChartComponent = config.type === 'line' ? Line : Bar;
|
|
95
|
+
return (React.createElement("div", { style: { height } },
|
|
96
|
+
React.createElement(ChartComponent, { data: chartData, options: options })));
|
|
97
|
+
};
|
|
98
|
+
export default ChartWidget;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { DatabaseClient } from '../../core/database';
|
|
3
|
+
export interface QueryWidgetConfig {
|
|
4
|
+
id: string;
|
|
5
|
+
title: string;
|
|
6
|
+
type: 'stat' | 'stat_list' | 'table' | 'chart' | 'line_chart' | 'bar_chart';
|
|
7
|
+
query: string;
|
|
8
|
+
iconName?: string;
|
|
9
|
+
iconColor?: string;
|
|
10
|
+
span?: number;
|
|
11
|
+
chartConfig?: {
|
|
12
|
+
x: string;
|
|
13
|
+
y: string;
|
|
14
|
+
type?: 'line' | 'bar';
|
|
15
|
+
groupBy?: string;
|
|
16
|
+
};
|
|
17
|
+
toggleOptions?: Array<{
|
|
18
|
+
label: string;
|
|
19
|
+
modifier: string;
|
|
20
|
+
}>;
|
|
21
|
+
dataKey?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface QueryWidgetProps {
|
|
24
|
+
config: QueryWidgetConfig;
|
|
25
|
+
client: DatabaseClient;
|
|
26
|
+
icon?: React.ReactNode;
|
|
27
|
+
onContextMenu?: (e: React.MouseEvent, widgetId: string) => void;
|
|
28
|
+
}
|
|
29
|
+
export declare const QueryWidget: React.FC<QueryWidgetProps>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import { Loader } from 'lucide-react';
|
|
3
|
+
import { normalizeQueryResult } from '../../core/database';
|
|
4
|
+
import { Chart } from '../primitives/Chart';
|
|
5
|
+
import { DataTable } from '../primitives/DataTable';
|
|
6
|
+
export const QueryWidget = ({ config, client, icon, onContextMenu }) => {
|
|
7
|
+
const [data, setData] = useState(null);
|
|
8
|
+
const [loading, setLoading] = useState(true);
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
const [activeToggle, setActiveToggle] = useState(config.toggleOptions?.[0] || null);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const fetchData = async () => {
|
|
13
|
+
setLoading(true);
|
|
14
|
+
setError(null);
|
|
15
|
+
try {
|
|
16
|
+
let finalQuery = config.query;
|
|
17
|
+
// Apply toggle modifier if present
|
|
18
|
+
if (activeToggle?.modifier) {
|
|
19
|
+
const baseQuery = config.query.replace(/;$/, '');
|
|
20
|
+
// Simple approach: append WHERE clause or modify existing
|
|
21
|
+
if (baseQuery.toLowerCase().includes('where')) {
|
|
22
|
+
finalQuery = `${baseQuery} AND (${activeToggle.modifier.replace(/^\s*WHERE\s*/i, '')})`;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
finalQuery = `${baseQuery} ${activeToggle.modifier}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const response = await client.executeSQL(finalQuery);
|
|
29
|
+
if (response.error)
|
|
30
|
+
throw new Error(response.error);
|
|
31
|
+
setData(normalizeQueryResult(response));
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
setError(err instanceof Error ? err.message : 'Query failed');
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
setLoading(false);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
fetchData();
|
|
41
|
+
}, [config.query, client, activeToggle]);
|
|
42
|
+
const renderContent = () => {
|
|
43
|
+
if (loading) {
|
|
44
|
+
return (React.createElement("div", { className: "flex items-center justify-center h-full" },
|
|
45
|
+
React.createElement(Loader, { className: "animate-spin text-blue-400", size: 24 })));
|
|
46
|
+
}
|
|
47
|
+
if (error) {
|
|
48
|
+
return React.createElement("div", { className: "text-red-400 p-2 text-xs overflow-auto" }, error);
|
|
49
|
+
}
|
|
50
|
+
if (!data || data.length === 0) {
|
|
51
|
+
return React.createElement("div", { className: "theme-text-secondary text-sm" }, "No data");
|
|
52
|
+
}
|
|
53
|
+
switch (config.type) {
|
|
54
|
+
case 'stat': {
|
|
55
|
+
const value = config.dataKey
|
|
56
|
+
? data[0]?.[config.dataKey]
|
|
57
|
+
: Object.values(data[0] || {})[0];
|
|
58
|
+
return React.createElement("p", { className: "text-3xl font-bold theme-text-primary" }, String(value ?? 'N/A'));
|
|
59
|
+
}
|
|
60
|
+
case 'stat_list': {
|
|
61
|
+
const listData = config.dataKey ? data[config.dataKey] : data;
|
|
62
|
+
if (!Array.isArray(listData)) {
|
|
63
|
+
return React.createElement("div", { className: "text-red-400 text-xs" }, "Data is not an array");
|
|
64
|
+
}
|
|
65
|
+
return (React.createElement("ul", { className: "space-y-1 text-sm theme-text-secondary" }, listData.map((item, i) => {
|
|
66
|
+
const values = Object.values(item);
|
|
67
|
+
return (React.createElement("li", { key: i, className: "flex justify-between" },
|
|
68
|
+
React.createElement("span", null, String(values[0])),
|
|
69
|
+
React.createElement("span", { className: "font-bold" }, String(values[1] ?? ''))));
|
|
70
|
+
})));
|
|
71
|
+
}
|
|
72
|
+
case 'table': {
|
|
73
|
+
const columns = Object.keys(data[0] || {}).map(key => ({
|
|
74
|
+
key,
|
|
75
|
+
header: key
|
|
76
|
+
}));
|
|
77
|
+
return React.createElement(DataTable, { data: data, columns: columns });
|
|
78
|
+
}
|
|
79
|
+
case 'chart':
|
|
80
|
+
case 'line_chart':
|
|
81
|
+
case 'bar_chart': {
|
|
82
|
+
if (!config.chartConfig) {
|
|
83
|
+
return React.createElement("div", { className: "theme-text-secondary text-sm" }, "Chart not configured");
|
|
84
|
+
}
|
|
85
|
+
const chartType = config.chartConfig.type || (config.type.includes('line') ? 'line' : 'bar');
|
|
86
|
+
const dataKeys = Object.keys(data[0] || {});
|
|
87
|
+
// Find x-axis key (handle "AS" aliases)
|
|
88
|
+
const xKey = dataKeys.find(k => k.toLowerCase() === config.chartConfig.x.toLowerCase().split(' as ').pop()?.trim()) || dataKeys[0];
|
|
89
|
+
// Parse y-axis expressions (comma separated)
|
|
90
|
+
const yExpressions = config.chartConfig.y.split(',').map(s => s.trim());
|
|
91
|
+
const datasets = yExpressions.map((yExpr, index) => {
|
|
92
|
+
const yKey = dataKeys.find(k => k.toLowerCase() === yExpr.toLowerCase().split(' as ').pop()?.trim());
|
|
93
|
+
const colors = ['rgba(139, 92, 246, 0.8)', 'rgba(59, 130, 246, 0.8)', 'rgba(250, 204, 21, 0.8)', 'rgba(239, 68, 68, 0.8)', 'rgba(34, 197, 94, 0.8)'];
|
|
94
|
+
return {
|
|
95
|
+
label: yKey || yExpr,
|
|
96
|
+
data: data.map(d => parseFloat(String(d[yKey || ''] ?? 0))),
|
|
97
|
+
color: colors[index % colors.length]
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
const labels = data.map(d => String(d[xKey] ?? ''));
|
|
101
|
+
return (React.createElement("div", { className: "h-full w-full" },
|
|
102
|
+
React.createElement(Chart, { type: chartType, labels: labels, datasets: datasets, height: 200 })));
|
|
103
|
+
}
|
|
104
|
+
default:
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
return (React.createElement("div", { className: "theme-bg-tertiary p-4 rounded-lg flex flex-col h-full", style: { gridColumn: `span ${config.span || 1}` }, onContextMenu: (e) => onContextMenu?.(e, config.id) },
|
|
109
|
+
React.createElement("div", { className: "flex justify-between items-start flex-shrink-0" },
|
|
110
|
+
React.createElement("div", { className: "flex items-center gap-3 mb-2 flex-1" },
|
|
111
|
+
icon && React.createElement("span", { className: config.iconColor || 'text-gray-400' }, icon),
|
|
112
|
+
React.createElement("h4", { className: "font-semibold theme-text-secondary truncate" }, config.title)),
|
|
113
|
+
config.toggleOptions && config.toggleOptions.length > 0 && (React.createElement("div", { className: "flex items-center gap-1" }, config.toggleOptions.map(opt => (React.createElement("button", { key: opt.label, onClick: () => setActiveToggle(opt), className: `px-2 py-0.5 text-xs rounded ${activeToggle?.label === opt.label
|
|
114
|
+
? 'theme-button-primary'
|
|
115
|
+
: 'theme-button theme-hover'}` }, opt.label)))))),
|
|
116
|
+
React.createElement("div", { className: "flex-1 mt-1 overflow-hidden" }, renderContent())));
|
|
117
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface TableWidgetProps {
|
|
3
|
+
data: Record<string, any>[];
|
|
4
|
+
columns?: string[];
|
|
5
|
+
maxHeight?: number;
|
|
6
|
+
sortable?: boolean;
|
|
7
|
+
searchable?: boolean;
|
|
8
|
+
pagination?: boolean;
|
|
9
|
+
pageSize?: number;
|
|
10
|
+
onRowClick?: (row: Record<string, any>, index: number) => void;
|
|
11
|
+
onExport?: (data: Record<string, any>[]) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const TableWidget: React.FC<TableWidgetProps>;
|
|
14
|
+
export default TableWidget;
|