|
1 | | -import { |
2 | | - AiSettingsPanel, |
3 | | - AnalysisResultsContainer, |
4 | | - ModelSelector, |
5 | | - PromptSuggestions, |
6 | | - QueryControls, |
7 | | - SessionControls, |
8 | | -} from '@sqlrooms/ai'; |
| 1 | +import {AiSettingsPanel, Chat} from '@sqlrooms/ai'; |
9 | 2 | import { |
10 | 3 | Button, |
11 | 4 | Dialog, |
@@ -37,6 +30,7 @@ export const AssistantDrawer: React.FC<{ |
37 | 30 | (s) => s.ai.config.currentSessionId || null, |
38 | 31 | ); |
39 | 32 | const isDataAvailable = useRoomStore((state) => state.room.initialized); |
| 33 | + const updateProvider = useRoomStore((s) => s.aiSettings.updateProvider); |
40 | 34 | const settingsPanelOpen = useDisclosure(); |
41 | 35 | const isAssistantOpen = useRoomStore((state) => state.isAssistantOpen); |
42 | 36 | const setAssistantOpen = useRoomStore((state) => state.setAssistantOpen); |
@@ -66,97 +60,106 @@ export const AssistantDrawer: React.FC<{ |
66 | 60 | </Button> |
67 | 61 | </DrawerClose> |
68 | 62 | </DrawerHeader> |
69 | | - <div className="flex min-h-0 flex-1 flex-col gap-0 overflow-hidden p-4"> |
70 | | - <div className="mb-4 flex items-center justify-between gap-2"> |
71 | | - <SessionControls className="w-full" /> |
72 | | - {currentSessionId && ( |
73 | | - <Dialog |
74 | | - open={settingsPanelOpen.isOpen} |
75 | | - onOpenChange={(open) => { |
76 | | - if (open) { |
77 | | - settingsPanelOpen.onOpen(); |
78 | | - } else { |
79 | | - settingsPanelOpen.onClose(); |
80 | | - } |
81 | | - }} |
82 | | - > |
83 | | - <DialogTrigger asChild> |
84 | | - <Button |
85 | | - variant="outline" |
86 | | - className="hover:bg-accent flex items-center justify-center transition-colors" |
87 | | - title="Configuration" |
88 | | - size="sm" |
89 | | - > |
90 | | - <Settings className="h-4 w-4" /> |
91 | | - </Button> |
92 | | - </DialogTrigger> |
93 | | - <DialogContent className="flex h-[80vh] w-[90vw] max-w-3xl flex-col overflow-hidden"> |
94 | | - <DialogHeader> |
95 | | - <DialogTitle>AI Assistant Settings</DialogTitle> |
96 | | - </DialogHeader> |
97 | | - <Tabs |
98 | | - defaultValue="providers" |
99 | | - className="flex min-h-0 flex-1 flex-col" |
100 | | - > |
101 | | - <TabsList className="grid w-full shrink-0 grid-cols-3"> |
102 | | - <TabsTrigger value="providers">Providers</TabsTrigger> |
103 | | - <TabsTrigger value="models">Models</TabsTrigger> |
104 | | - <TabsTrigger value="parameters">Parameters</TabsTrigger> |
105 | | - </TabsList> |
106 | | - <TabsContent |
107 | | - value="providers" |
108 | | - className="flex-1 overflow-y-auto" |
109 | | - > |
110 | | - <AiSettingsPanel.ProvidersSettings /> |
111 | | - </TabsContent> |
112 | | - <TabsContent |
113 | | - value="models" |
114 | | - className="flex-1 overflow-y-auto" |
| 63 | + <Chat.Root> |
| 64 | + <div className="flex min-h-0 flex-1 flex-col gap-0 overflow-hidden p-4"> |
| 65 | + <div className="mb-4 flex items-center justify-between gap-2"> |
| 66 | + <Chat.Sessions className="w-full" /> |
| 67 | + {currentSessionId && ( |
| 68 | + <Dialog |
| 69 | + open={settingsPanelOpen.isOpen} |
| 70 | + onOpenChange={(open) => { |
| 71 | + if (open) { |
| 72 | + settingsPanelOpen.onOpen(); |
| 73 | + } else { |
| 74 | + settingsPanelOpen.onClose(); |
| 75 | + } |
| 76 | + }} |
| 77 | + > |
| 78 | + <DialogTrigger asChild> |
| 79 | + <Button |
| 80 | + variant="outline" |
| 81 | + className="hover:bg-accent flex items-center justify-center transition-colors" |
| 82 | + title="Configuration" |
| 83 | + size="sm" |
115 | 84 | > |
116 | | - <AiSettingsPanel.ModelsSettings /> |
117 | | - </TabsContent> |
118 | | - <TabsContent |
119 | | - value="parameters" |
120 | | - className="flex-1 overflow-y-auto" |
| 85 | + <Settings className="h-4 w-4" /> |
| 86 | + </Button> |
| 87 | + </DialogTrigger> |
| 88 | + <DialogContent className="flex h-[80vh] w-[90vw] max-w-3xl flex-col overflow-hidden"> |
| 89 | + <DialogHeader> |
| 90 | + <DialogTitle>AI Assistant Settings</DialogTitle> |
| 91 | + </DialogHeader> |
| 92 | + <Tabs |
| 93 | + defaultValue="providers" |
| 94 | + className="flex min-h-0 flex-1 flex-col" |
121 | 95 | > |
122 | | - <AiSettingsPanel.ModelParametersSettings /> |
123 | | - </TabsContent> |
124 | | - </Tabs> |
125 | | - </DialogContent> |
126 | | - </Dialog> |
127 | | - )} |
128 | | - </div> |
129 | | - <div className="print-container grow overflow-auto"> |
130 | | - {!currentSessionId ? ( |
131 | | - <div className="flex h-full w-full flex-col items-center justify-center"> |
132 | | - <p className="text-muted-foreground mt-4"> |
133 | | - No session selected |
134 | | - </p> |
135 | | - </div> |
136 | | - ) : isDataAvailable ? ( |
137 | | - <AnalysisResultsContainer key={currentSessionId} /> |
138 | | - ) : ( |
139 | | - <div className="flex h-full w-full flex-col items-center justify-center"> |
140 | | - <SkeletonPane className="p-4" /> |
141 | | - <p className="text-muted-foreground mt-4"> |
142 | | - Loading database... |
143 | | - </p> |
144 | | - </div> |
145 | | - )} |
146 | | - </div>{' '} |
147 | | - <PromptSuggestions.Container> |
148 | | - <PromptSuggestions.Item text="What questions can I ask to get insights from my data?" /> |
149 | | - <PromptSuggestions.Item text="Show me a summary of the data" /> |
150 | | - <PromptSuggestions.Item text="What are the key trends?" /> |
151 | | - <PromptSuggestions.Item text="Help me understand the data structure" /> |
152 | | - </PromptSuggestions.Container> |
153 | | - <QueryControls placeholder="What would you like to learn about the data?"> |
154 | | - <div className="flex items-center justify-end gap-2"> |
155 | | - <PromptSuggestions.VisibilityToggle /> |
156 | | - <ModelSelector /> |
| 96 | + <TabsList className="grid w-full shrink-0 grid-cols-3"> |
| 97 | + <TabsTrigger value="providers">Providers</TabsTrigger> |
| 98 | + <TabsTrigger value="models">Models</TabsTrigger> |
| 99 | + <TabsTrigger value="parameters"> |
| 100 | + Parameters |
| 101 | + </TabsTrigger> |
| 102 | + </TabsList> |
| 103 | + <TabsContent |
| 104 | + value="providers" |
| 105 | + className="flex-1 overflow-y-auto" |
| 106 | + > |
| 107 | + <AiSettingsPanel.ProvidersSettings /> |
| 108 | + </TabsContent> |
| 109 | + <TabsContent |
| 110 | + value="models" |
| 111 | + className="flex-1 overflow-y-auto" |
| 112 | + > |
| 113 | + <AiSettingsPanel.ModelsSettings /> |
| 114 | + </TabsContent> |
| 115 | + <TabsContent |
| 116 | + value="parameters" |
| 117 | + className="flex-1 overflow-y-auto" |
| 118 | + > |
| 119 | + <AiSettingsPanel.ModelParametersSettings /> |
| 120 | + </TabsContent> |
| 121 | + </Tabs> |
| 122 | + </DialogContent> |
| 123 | + </Dialog> |
| 124 | + )} |
157 | 125 | </div> |
158 | | - </QueryControls> |
159 | | - </div> |
| 126 | + <div className="print-container grow overflow-auto"> |
| 127 | + {!currentSessionId ? ( |
| 128 | + <div className="flex h-full w-full flex-col items-center justify-center"> |
| 129 | + <p className="text-muted-foreground mt-4"> |
| 130 | + No session selected |
| 131 | + </p> |
| 132 | + </div> |
| 133 | + ) : isDataAvailable ? ( |
| 134 | + <Chat.Messages key={currentSessionId} /> |
| 135 | + ) : ( |
| 136 | + <div className="flex h-full w-full flex-col items-center justify-center"> |
| 137 | + <SkeletonPane className="p-4" /> |
| 138 | + <p className="text-muted-foreground mt-4"> |
| 139 | + Loading database... |
| 140 | + </p> |
| 141 | + </div> |
| 142 | + )} |
| 143 | + </div>{' '} |
| 144 | + <Chat.PromptSuggestions> |
| 145 | + <Chat.PromptSuggestions.Item text="What questions can I ask to get insights from my data?" /> |
| 146 | + <Chat.PromptSuggestions.Item text="Show me a summary of the data" /> |
| 147 | + <Chat.PromptSuggestions.Item text="What are the key trends?" /> |
| 148 | + <Chat.PromptSuggestions.Item text="Help me understand the data structure" /> |
| 149 | + </Chat.PromptSuggestions> |
| 150 | + <Chat.Composer placeholder="What would you like to learn about the data?"> |
| 151 | + <Chat.InlineApiKeyInput |
| 152 | + onSaveApiKey={(provider, apiKey) => { |
| 153 | + updateProvider(provider, {apiKey}); |
| 154 | + }} |
| 155 | + /> |
| 156 | + <div className="flex items-center justify-end gap-2"> |
| 157 | + <Chat.PromptSuggestions.VisibilityToggle /> |
| 158 | + <Chat.ModelSelector /> |
| 159 | + </div> |
| 160 | + </Chat.Composer> |
| 161 | + </div> |
| 162 | + </Chat.Root> |
160 | 163 | </div> |
161 | 164 | </DrawerContent> |
162 | 165 | </Drawer> |
|
0 commit comments