@sqlrooms/ai 0.27.0 → 0.28.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/README.md +95 -412
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/commandTools.d.ts +40 -0
- package/dist/tools/commandTools.d.ts.map +1 -0
- package/dist/tools/commandTools.js +120 -0
- package/dist/tools/commandTools.js.map +1 -0
- package/dist/tools/defaultTools.d.ts +9 -6
- package/dist/tools/defaultTools.d.ts.map +1 -1
- package/dist/tools/defaultTools.js +5 -1
- package/dist/tools/defaultTools.js.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -1,459 +1,142 @@
|
|
|
1
|
-
|
|
1
|
+
High-level AI package for SQLRooms.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package combines:
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
- 📝 **Query History**: Track and manage AI query history
|
|
10
|
-
- 🎯 **Tool Integration**: Framework for AI tools and actions
|
|
5
|
+
- AI slice state/logic (`@sqlrooms/ai-core`)
|
|
6
|
+
- AI settings UI/state (`@sqlrooms/ai-settings`)
|
|
7
|
+
- AI config schemas (`@sqlrooms/ai-config`)
|
|
8
|
+
- SQL query tool helpers (`createDefaultAiTools`, `createQueryTool`)
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
npm install @sqlrooms/ai
|
|
16
|
-
# or
|
|
17
|
-
yarn add @sqlrooms/ai
|
|
18
|
-
```
|
|
10
|
+
Use this package when you want AI chat + tool execution in a SQLRooms app without wiring low-level pieces manually.
|
|
19
11
|
|
|
20
|
-
|
|
12
|
+
## Installation
|
|
21
13
|
|
|
22
14
|
```bash
|
|
23
|
-
npm install @ai-
|
|
15
|
+
npm install @sqlrooms/ai @sqlrooms/room-shell @sqlrooms/duckdb @sqlrooms/ui
|
|
24
16
|
```
|
|
25
17
|
|
|
26
|
-
|
|
18
|
+
## Quick start
|
|
27
19
|
|
|
28
20
|
```tsx
|
|
29
|
-
import {createAiSettingsSlice} from '@sqlrooms/ai';
|
|
30
|
-
|
|
31
|
-
// Create a room store with AI capabilities
|
|
32
|
-
const {roomStore, useRoomStore} = createRoomStore({
|
|
33
|
-
...createAiSettingsSlice({
|
|
34
|
-
config: {
|
|
35
|
-
providers: {
|
|
36
|
-
openai: {
|
|
37
|
-
baseUrl: 'https://api.openai.com/v1',
|
|
38
|
-
apiKey: '',
|
|
39
|
-
models: [
|
|
40
|
-
{
|
|
41
|
-
id: 'gpt-4.1',
|
|
42
|
-
modelName: 'gpt-4.1',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
}),
|
|
47
|
-
});
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
You can also pass a custom model provider to the AiSlice.
|
|
51
|
-
|
|
52
|
-
```tsx
|
|
53
|
-
import {createAiSlice} from '@sqlrooms/ai';
|
|
54
|
-
|
|
55
|
-
// Create a room store with AI capabilities
|
|
56
|
-
const {roomStore, useRoomStore} = createRoomStore({
|
|
57
|
-
...createAiSlice({
|
|
58
|
-
getCustomModel: () => {
|
|
59
|
-
return xai('grok-4');
|
|
60
|
-
},
|
|
61
|
-
...
|
|
62
|
-
}),
|
|
63
|
-
});
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Basic Usage
|
|
67
|
-
|
|
68
|
-
### Setting Up AI Integration
|
|
69
|
-
|
|
70
|
-
```tsx
|
|
71
|
-
import {createAiSlice} from '@sqlrooms/ai';
|
|
72
|
-
import {createRoomStore} from '@sqlrooms/room-shell';
|
|
73
|
-
|
|
74
|
-
// Create a room store with AI capabilities
|
|
75
|
-
const {roomStore, useRoomStore} = createRoomStore({
|
|
76
|
-
// Base room configuration
|
|
77
|
-
...createRoomShellSlice({
|
|
78
|
-
config: {
|
|
79
|
-
// Your room configuration
|
|
80
|
-
},
|
|
81
|
-
}),
|
|
82
|
-
// Add AI settings slice
|
|
83
|
-
...createAiSettingsSlice({
|
|
84
|
-
config: {
|
|
85
|
-
// Your AI settings configuration
|
|
86
|
-
},
|
|
87
|
-
}),
|
|
88
|
-
// Add AI slice
|
|
89
|
-
...createAiSlice({
|
|
90
|
-
initialPrompt: 'What insights can you provide from my data?',
|
|
91
|
-
// Optional: Add custom tools
|
|
92
|
-
tools: {
|
|
93
|
-
// Your custom tools
|
|
94
|
-
},
|
|
95
|
-
// Optional: Custom instructions for the AI
|
|
96
|
-
getInstructions: (tablesSchema) => {
|
|
97
|
-
return `Analyze the following tables: ${tablesSchema.map((t) => t.name).join(', ')}`;
|
|
98
|
-
},
|
|
99
|
-
}),
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
function MyApp() {
|
|
103
|
-
return (
|
|
104
|
-
<RoomStateProvider roomStore={roomStore}>
|
|
105
|
-
<MyDataApp />
|
|
106
|
-
</RoomStateProvider>
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### Advanced Store Configuration
|
|
112
|
-
|
|
113
|
-
For more complex applications, you can combine multiple slices:
|
|
114
|
-
|
|
115
|
-
```tsx
|
|
116
|
-
import {createAiSlice} from '@sqlrooms/ai';
|
|
117
21
|
import {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
22
|
+
AiSettingsSliceState,
|
|
23
|
+
AiSliceState,
|
|
24
|
+
createAiSettingsSlice,
|
|
25
|
+
createAiSlice,
|
|
26
|
+
createDefaultAiInstructions,
|
|
27
|
+
createDefaultAiTools,
|
|
28
|
+
} from '@sqlrooms/ai';
|
|
29
|
+
import {
|
|
30
|
+
createRoomShellSlice,
|
|
31
|
+
createRoomStore,
|
|
32
|
+
RoomShellSliceState,
|
|
33
|
+
} from '@sqlrooms/room-shell';
|
|
122
34
|
|
|
123
|
-
|
|
124
|
-
export type RoomState = RoomState<RoomConfig> &
|
|
125
|
-
AiSliceState &
|
|
126
|
-
SqlEditorSliceState;
|
|
35
|
+
type RoomState = RoomShellSliceState & AiSliceState & AiSettingsSliceState;
|
|
127
36
|
|
|
128
|
-
|
|
129
|
-
export const {roomStore, useRoomStore} = createRoomStore<RoomConfig, RoomState>(
|
|
37
|
+
export const {roomStore, useRoomStore} = createRoomStore<RoomState>(
|
|
130
38
|
(set, get, store) => ({
|
|
131
|
-
// Base room slice
|
|
132
39
|
...createRoomShellSlice({
|
|
133
40
|
config: {
|
|
134
|
-
|
|
135
|
-
},
|
|
136
|
-
}),
|
|
137
|
-
// AI settings slice
|
|
138
|
-
...createAiSettingsSlice({
|
|
139
|
-
config: {
|
|
140
|
-
// Your AI settings configuration
|
|
141
|
-
},
|
|
142
|
-
}),
|
|
143
|
-
// Ai config slice
|
|
144
|
-
...createAiConfigSlice({
|
|
145
|
-
config: {
|
|
146
|
-
// Optional: Pre-configured AI sessions
|
|
147
|
-
sessions: [
|
|
41
|
+
dataSources: [
|
|
148
42
|
{
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
model: 'gpt-4o',
|
|
153
|
-
analysisResults: [],
|
|
154
|
-
createdAt: new Date(),
|
|
43
|
+
type: 'url',
|
|
44
|
+
tableName: 'earthquakes',
|
|
45
|
+
url: 'https://huggingface.co/datasets/sqlrooms/earthquakes/resolve/main/earthquakes.parquet',
|
|
155
46
|
},
|
|
156
47
|
],
|
|
157
|
-
currentSessionId: 'default-session',
|
|
158
48
|
},
|
|
159
|
-
}),
|
|
160
|
-
|
|
49
|
+
})(set, get, store),
|
|
50
|
+
|
|
51
|
+
...createAiSettingsSlice()(set, get, store),
|
|
52
|
+
|
|
161
53
|
...createAiSlice({
|
|
162
|
-
initialPrompt: 'What insights can you provide from my data?',
|
|
163
54
|
tools: {
|
|
164
|
-
|
|
165
|
-
},
|
|
166
|
-
getInstructions: (tablesSchema) => {
|
|
167
|
-
return `Analyze the following tables: ${tablesSchema.map((t) => t.name).join(', ')}`;
|
|
55
|
+
...createDefaultAiTools(store),
|
|
168
56
|
},
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
...createSqlEditorSlice(),
|
|
57
|
+
getInstructions: () => createDefaultAiInstructions(store),
|
|
58
|
+
})(set, get, store),
|
|
172
59
|
}),
|
|
173
60
|
);
|
|
174
61
|
```
|
|
175
62
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
```tsx
|
|
179
|
-
import {QueryControls} from '@sqlrooms/ai';
|
|
180
|
-
|
|
181
|
-
function AiQueryPanel() {
|
|
182
|
-
return (
|
|
183
|
-
<div className="rounded-lg border p-4">
|
|
184
|
-
<h2 className="mb-4 text-xl font-bold">Ask AI</h2>
|
|
185
|
-
<QueryControls
|
|
186
|
-
placeholder="Ask a question about your data..."
|
|
187
|
-
onSubmit={(query) => console.log('Processing query:', query)}
|
|
188
|
-
/>
|
|
189
|
-
</div>
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
### Displaying Analysis Results
|
|
63
|
+
## Render chat UI
|
|
195
64
|
|
|
196
65
|
```tsx
|
|
197
|
-
import {
|
|
66
|
+
import {Chat} from '@sqlrooms/ai';
|
|
67
|
+
import {useRoomStore} from './store';
|
|
198
68
|
|
|
199
|
-
function
|
|
200
|
-
|
|
201
|
-
const currentSession = useRoomStore((state) => state.ai.getCurrentSession());
|
|
202
|
-
const analysisResults = currentSession?.analysisResults || [];
|
|
69
|
+
function AiPanel() {
|
|
70
|
+
const updateProvider = useRoomStore((state) => state.aiSettings.updateProvider);
|
|
203
71
|
|
|
204
72
|
return (
|
|
205
|
-
<
|
|
206
|
-
<
|
|
207
|
-
<
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
73
|
+
<Chat>
|
|
74
|
+
<Chat.Sessions />
|
|
75
|
+
<Chat.Messages />
|
|
76
|
+
<Chat.PromptSuggestions>
|
|
77
|
+
<Chat.PromptSuggestions.Item text="Summarize the available tables" />
|
|
78
|
+
</Chat.PromptSuggestions>
|
|
79
|
+
<Chat.Composer placeholder="Ask a question about your data">
|
|
80
|
+
<Chat.InlineApiKeyInput
|
|
81
|
+
onSaveApiKey={(provider, apiKey) => {
|
|
82
|
+
updateProvider(provider, {apiKey});
|
|
83
|
+
}}
|
|
84
|
+
/>
|
|
85
|
+
<Chat.ModelSelector />
|
|
86
|
+
</Chat.Composer>
|
|
87
|
+
</Chat>
|
|
213
88
|
);
|
|
214
89
|
}
|
|
215
90
|
```
|
|
216
91
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
```tsx
|
|
220
|
-
function AiStatusIndicator() {
|
|
221
|
-
const isRunning = useRoomStore((state) => state.ai.isRunning);
|
|
222
|
-
const prompt = useRoomStore((state) => state.ai.prompt);
|
|
223
|
-
const currentSession = useRoomStore((state) => state.ai.getCurrentSession());
|
|
224
|
-
const lastResult =
|
|
225
|
-
currentSession?.analysisResults[currentSession.analysisResults.length - 1];
|
|
226
|
-
|
|
227
|
-
if (isRunning) {
|
|
228
|
-
return <div>AI is analyzing your data...</div>;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (lastResult?.errorMessage) {
|
|
232
|
-
return <div>Error: {lastResult.errorMessage.message}</div>;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (prompt) {
|
|
236
|
-
return <div>Last query: "{prompt}"</div>;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return <div>Ask AI a question about your data</div>;
|
|
240
|
-
}
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
## AiSlice API Reference
|
|
244
|
-
|
|
245
|
-
The AiSlice provides a comprehensive set of state fields and methods for managing AI interactions in your application.
|
|
246
|
-
|
|
247
|
-
### State Fields
|
|
248
|
-
|
|
249
|
-
#### `prompt`
|
|
250
|
-
|
|
251
|
-
The current prompt text entered by the user for analysis.
|
|
252
|
-
|
|
253
|
-
```tsx
|
|
254
|
-
const prompt = useRoomStore((state) => state.ai.prompt);
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
#### `isRunning`
|
|
258
|
-
|
|
259
|
-
Boolean flag indicating whether an analysis is currently in progress.
|
|
260
|
-
|
|
261
|
-
```tsx
|
|
262
|
-
const isRunning = useRoomStore((state) => state.ai.isRunning);
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
#### `tools`
|
|
266
|
-
|
|
267
|
-
Record of available AI tools that can be used during analysis.
|
|
268
|
-
|
|
269
|
-
```tsx
|
|
270
|
-
const availableTools = useRoomStore((state) => state.ai.tools);
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
#### `abortController`
|
|
274
|
-
|
|
275
|
-
Optional AbortController instance that can be used to cancel an ongoing analysis.
|
|
92
|
+
## Add custom tools
|
|
276
93
|
|
|
277
94
|
```tsx
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
### Methods
|
|
282
|
-
|
|
283
|
-
#### `setPrompt(prompt: string)`
|
|
284
|
-
|
|
285
|
-
Sets the current analysis prompt text.
|
|
286
|
-
|
|
287
|
-
```tsx
|
|
288
|
-
const setPrompt = useRoomStore((state) => state.ai.setPrompt);
|
|
289
|
-
setPrompt('Analyze sales trends for the last quarter');
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
#### `startAnalysis()`
|
|
293
|
-
|
|
294
|
-
Starts the analysis process using the current prompt.
|
|
295
|
-
|
|
296
|
-
```tsx
|
|
297
|
-
const startAnalysis = useRoomStore((state) => state.ai.startAnalysis);
|
|
298
|
-
await startAnalysis();
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
#### `cancelAnalysis()`
|
|
302
|
-
|
|
303
|
-
Cancels any ongoing analysis.
|
|
304
|
-
|
|
305
|
-
```tsx
|
|
306
|
-
const cancelAnalysis = useRoomStore((state) => state.ai.cancelAnalysis);
|
|
307
|
-
cancelAnalysis();
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
#### `setAiModel(modelProvider: string, model: string)`
|
|
311
|
-
|
|
312
|
-
Sets the AI model and provider for the current session.
|
|
313
|
-
|
|
314
|
-
```tsx
|
|
315
|
-
const setModel = useRoomStore((state) => state.ai.setAiModel);
|
|
316
|
-
setModel('openai', 'gpt-4o');
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
#### `createSession(name?: string, modelProvider?: string, model?: string)`
|
|
320
|
-
|
|
321
|
-
Creates a new analysis session with optional name and model settings.
|
|
322
|
-
|
|
323
|
-
```tsx
|
|
324
|
-
const createSession = useRoomStore((state) => state.ai.createSession);
|
|
325
|
-
createSession('Financial Analysis', 'openai', 'gpt-4o');
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
#### `switchSession(sessionId: string)`
|
|
329
|
-
|
|
330
|
-
Switches to a different analysis session by ID.
|
|
331
|
-
|
|
332
|
-
```tsx
|
|
333
|
-
const switchSession = useRoomStore((state) => state.ai.switchSession);
|
|
334
|
-
switchSession('session-123');
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
#### `renameSession(sessionId: string, name: string)`
|
|
338
|
-
|
|
339
|
-
Renames an existing analysis session.
|
|
340
|
-
|
|
341
|
-
```tsx
|
|
342
|
-
const renameSession = useRoomStore((state) => state.ai.renameSession);
|
|
343
|
-
renameSession('session-123', 'Q4 Sales Analysis');
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
#### `deleteSession(sessionId: string)`
|
|
95
|
+
import {z} from 'zod';
|
|
96
|
+
import {createAiSlice, createDefaultAiInstructions, createDefaultAiTools} from '@sqlrooms/ai';
|
|
347
97
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const deleteResult = useRoomStore((state) => state.ai.deleteAnalysisResult);
|
|
369
|
-
deleteResult('session-123', 'result-456');
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
#### `findToolComponent(toolName: string)`
|
|
373
|
-
|
|
374
|
-
Finds the React component associated with a specific tool.
|
|
375
|
-
|
|
376
|
-
```tsx
|
|
377
|
-
const ChartComponent = useRoomStore((state) =>
|
|
378
|
-
state.ai.findToolComponent('chart'),
|
|
379
|
-
);
|
|
98
|
+
// inside createRoomStore(...):
|
|
99
|
+
createAiSlice({
|
|
100
|
+
tools: {
|
|
101
|
+
...createDefaultAiTools(store),
|
|
102
|
+
echo: {
|
|
103
|
+
name: 'echo',
|
|
104
|
+
description: 'Return user text back to the chat',
|
|
105
|
+
parameters: z.object({
|
|
106
|
+
text: z.string(),
|
|
107
|
+
}),
|
|
108
|
+
execute: async ({text}) => ({
|
|
109
|
+
llmResult: {
|
|
110
|
+
success: true,
|
|
111
|
+
details: `Echo: ${text}`,
|
|
112
|
+
},
|
|
113
|
+
}),
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
getInstructions: () => createDefaultAiInstructions(store),
|
|
117
|
+
})(set, get, store);
|
|
380
118
|
```
|
|
381
119
|
|
|
382
|
-
##
|
|
120
|
+
## Use remote endpoint mode
|
|
383
121
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
## Advanced Features
|
|
387
|
-
|
|
388
|
-
- **Custom AI Tools**: Define custom tools for AI to use with the tool() function
|
|
389
|
-
- **Multiple Sessions**: Create and manage multiple analysis sessions for different purposes
|
|
390
|
-
- **Model Selection**: Switch between different AI models and providers
|
|
391
|
-
- **Result Management**: Save, delete, and organize analysis results
|
|
392
|
-
- **Conversation Context**: Maintain context across multiple queries in a session
|
|
393
|
-
- **Feedback Loop**: Collect user feedback to improve AI responses
|
|
394
|
-
|
|
395
|
-
For more information, visit the SQLRooms documentation.
|
|
396
|
-
|
|
397
|
-
## AI Settings Configuration
|
|
398
|
-
|
|
399
|
-
This package now includes comprehensive AI settings components. These components provide a complete set of UI elements for managing AI model configuration, parameters, and usage tracking.
|
|
400
|
-
|
|
401
|
-
### AI Settings Features
|
|
402
|
-
|
|
403
|
-
- **createAiSettingsSlice**: Function to create a Zustand slice for managing AI model configuration with room-shell integration
|
|
404
|
-
- **AiSettingsPanel**: Main configuration panel with modular sub-components for different configuration aspects
|
|
405
|
-
- **ProvidersSettings**: Component for configuring AI providers (OpenAI, Anthropic, etc.) with API keys and base URLs
|
|
406
|
-
- **ModelsSettings**: Component for managing available models and their parameters
|
|
407
|
-
- **ModelParametersSettings**: Component for configuring model parameters like max steps and system instructions
|
|
408
|
-
- **ModelSelector**: Standalone model selector component for quick model switching
|
|
409
|
-
|
|
410
|
-
### AI Settings Usage
|
|
411
|
-
|
|
412
|
-
#### Individual Components
|
|
122
|
+
If you want server-side model calls, set `chatEndPoint` and optional `chatHeaders`:
|
|
413
123
|
|
|
414
124
|
```tsx
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
</AiSettingsPanel>
|
|
427
|
-
|
|
428
|
-
// Standalone model selector
|
|
429
|
-
<Chat.ModelSelector />
|
|
125
|
+
// inside createRoomStore(...):
|
|
126
|
+
...createAiSlice({
|
|
127
|
+
tools: {
|
|
128
|
+
...createDefaultAiTools(store),
|
|
129
|
+
},
|
|
130
|
+
getInstructions: () => createDefaultAiInstructions(store),
|
|
131
|
+
chatEndPoint: '/api/chat',
|
|
132
|
+
chatHeaders: {
|
|
133
|
+
'x-app-name': 'my-sqlrooms-app',
|
|
134
|
+
},
|
|
135
|
+
})(set, get, store),
|
|
430
136
|
```
|
|
431
137
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
#### Core Components
|
|
435
|
-
|
|
436
|
-
- **`AiSettingsPanel`**: Main configuration panel with modular sub-components
|
|
437
|
-
- `AiSettingsPanel.ProvidersSettings`: Configure AI providers (OpenAI, Anthropic, etc.)
|
|
438
|
-
- `AiSettingsPanel.ModelsSettings`: Manage available models and their parameters
|
|
439
|
-
- `AiSettingsPanel.ModelParametersSettings`: Configure model parameters and instructions
|
|
440
|
-
- **`ModelSelector`**: Standalone model selector for quick switching
|
|
441
|
-
|
|
442
|
-
#### Slice Configuration
|
|
443
|
-
|
|
444
|
-
The package uses a slice-based configuration system that integrates with SQLRooms room-shell:
|
|
445
|
-
|
|
446
|
-
- **`createAiSettingsSlice()`**: Creates the AI settings configuration slice for state management
|
|
447
|
-
- **`AiSettingsSliceConfig`**: TypeScript type for configuration schema
|
|
448
|
-
- **`createDefaultAiSettings(providers)`**: Helper to create default configuration with providers
|
|
449
|
-
- **`getApiKey(config, provider, model)`**: Utility to get API key from configuration
|
|
450
|
-
- **`getBaseUrl(config, provider, model)`**: Utility to get base URL from configuration
|
|
451
|
-
|
|
452
|
-
#### Store Integration
|
|
453
|
-
|
|
454
|
-
The AI settings configuration integrates with the main AI slice through helper functions:
|
|
138
|
+
## Related packages
|
|
455
139
|
|
|
456
|
-
-
|
|
457
|
-
-
|
|
458
|
-
-
|
|
459
|
-
- **`getInstructions(tablesSchema)`**: Function to generate system instructions with optional custom instructions
|
|
140
|
+
- `@sqlrooms/ai-core` for lower-level AI slice and chat primitives
|
|
141
|
+
- `@sqlrooms/ai-settings` for settings slice/components only
|
|
142
|
+
- `@sqlrooms/ai-config` for Zod schemas and migrations
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { QueryToolResult } from './tools/query/QueryToolResult';
|
|
6
6
|
export { QueryToolParameters, createQueryTool, getQuerySummary, type QueryToolLlmResult, type QueryToolAdditionalData, type QueryToolOptions, } from './tools/query/queryTool';
|
|
7
|
+
export { createCommandTools, ExecuteCommandToolParameters, ListCommandsToolParameters, } from './tools/commandTools';
|
|
8
|
+
export type { CommandToolDescriptor, CommandToolsOptions, ExecuteCommandToolLlmResult, ListCommandsToolLlmResult, } from './tools/commandTools';
|
|
7
9
|
export { createDefaultAiTools } from './tools/defaultTools';
|
|
8
10
|
export type { DefaultToolsOptions } from './tools/defaultTools';
|
|
9
11
|
export { createDefaultAiInstructions, formatTablesForLLM, } from './tools/defaultInstructions';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAC,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EAAC,mBAAmB,EAAC,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAChE,YAAY,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,6BAA6B,EAAE,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAC,mBAAmB,EAAE,sBAAsB,EAAC,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAC,kBAAkB,EAAE,uBAAuB,EAAC,MAAM,mBAAmB,CAAC;AAC9E,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,2BAA2B,GAC5B,M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AM,qBAAqB,CAAC;AAC7B,YAAY,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAGnE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAC,oBAAoB,EAAC,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAC,6BAA6B,EAAC,MAAM,uBAAuB,CAAC;AAGpE,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AACnD,YAAY,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// Tools
|
|
6
6
|
export { QueryToolResult } from './tools/query/QueryToolResult';
|
|
7
7
|
export { QueryToolParameters, createQueryTool, getQuerySummary, } from './tools/query/queryTool';
|
|
8
|
+
export { createCommandTools, ExecuteCommandToolParameters, ListCommandsToolParameters, } from './tools/commandTools';
|
|
8
9
|
export { createDefaultAiTools } from './tools/defaultTools';
|
|
9
10
|
export { createDefaultAiInstructions, formatTablesForLLM, } from './tools/defaultInstructions';
|
|
10
11
|
// From @sqlrooms/ai-core - State/Logic
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,QAAQ;AACR,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,eAAe,GAIhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAC,oBAAo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C;AAC/C,OAAO,EAAC,IAAI,EAAC,MAAM,mBAAmB,CAAC;AAEvC,2BAA2B;AAC3B,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAG7B,2CAA2C;AAC3C,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAC,6BAA6B,EAAC,MAAM,uBAAuB,CAAC;AAEpE,0CAA0C;AAC1C,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC","sourcesContent":["/**\n * {@include ../README.md}\n * @packageDocumentation\n */\n\n// Tools\nexport {QueryToolResult} from './tools/query/QueryToolResult';\nexport {\n QueryToolParameters,\n createQueryTool,\n getQuerySummary,\n type QueryToolLlmResult,\n type QueryToolAdditionalData,\n type QueryToolOptions,\n} from './tools/query/queryTool';\nexport {createDefaultAiTools} from './tools/defaultTools';\nexport type {DefaultToolsOptions} from './tools/defaultTools';\nexport {\n createDefaultAiInstructions,\n formatTablesForLLM,\n} from './tools/defaultInstructions';\n\n// From @sqlrooms/ai-core - State/Logic\nexport {createAiSlice, useStoreWithAi} from '@sqlrooms/ai-core';\nexport type {AiSliceState} from '@sqlrooms/ai-core';\nexport {useScrollToBottom} from '@sqlrooms/ai-core';\nexport {AiThinkingDots} from '@sqlrooms/ai-core';\nexport {cleanupPendingAnalysisResults, ToolAbortError} from '@sqlrooms/ai-core';\nexport {convertToAiSDKTools, fixIncompleteToolCalls} from '@sqlrooms/ai-core';\nexport {processAgentStream, updateAgentToolCallData} from '@sqlrooms/ai-core';\nexport type {\n AgentStreamResult,\n UIMessageChunk,\n AgentToolCall,\n AgentToolCallAdditionalData,\n} from '@sqlrooms/ai-core';\n\n// From @sqlrooms/ai-core - Components\n// @deprecated Use `Chat.Messages` instead.\nexport {AnalysisResultsContainer} from '@sqlrooms/ai-core';\nexport {AnalysisResult} from '@sqlrooms/ai-core';\nexport {ErrorMessage} from '@sqlrooms/ai-core';\nexport type {ErrorMessageComponentProps} from '@sqlrooms/ai-core';\nexport {PromptSuggestions} from '@sqlrooms/ai-core';\nexport {ModelSelector} from '@sqlrooms/ai-core';\nexport {SessionControls} from '@sqlrooms/ai-core';\nexport {QueryControls} from '@sqlrooms/ai-core';\nexport {DeleteSessionDialog} from '@sqlrooms/ai-core';\nexport {SessionActions} from '@sqlrooms/ai-core';\nexport {SessionDropdown} from '@sqlrooms/ai-core';\nexport {SessionTitle} from '@sqlrooms/ai-core';\nexport type {SessionType} from '@sqlrooms/ai-core';\nexport {ToolErrorMessage} from '@sqlrooms/ai-core';\nexport {ToolCallInfo} from '@sqlrooms/ai-core';\nexport {ReasoningBox} from '@sqlrooms/ai-core';\nexport {Chat} from '@sqlrooms/ai-core';\n\n// From @sqlrooms/ai-config\nexport {\n AiSliceConfig,\n createDefaultAiConfig,\n AiSettingsSliceConfig,\n AnalysisSessionSchema,\n AnalysisResultSchema,\n ErrorMessageSchema,\n} from '@sqlrooms/ai-config';\nexport type {ToolUIPart, UIMessagePart} from '@sqlrooms/ai-config';\n\n// From @sqlrooms/ai-settings - State/Logic\nexport {\n createAiSettingsSlice,\n useStoreWithAiSettings,\n} from '@sqlrooms/ai-settings';\nexport type {AiSettingsSliceState} from '@sqlrooms/ai-settings';\nexport {createDefaultAiSettingsConfig} from '@sqlrooms/ai-settings';\n\n// From @sqlrooms/ai-settings - Components\nexport {AiSettingsPanel} from '@sqlrooms/ai-settings';\nexport {AiProvidersSettings} from '@sqlrooms/ai-settings';\nexport {AiModelsSettings} from '@sqlrooms/ai-settings';\nexport {AiModelParameters} from '@sqlrooms/ai-settings';\nexport {AiModelUsage} from '@sqlrooms/ai-settings';\nexport type {ModelUsageData} from '@sqlrooms/ai-settings';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,QAAQ;AACR,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,eAAe,GAIhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAO9B,OAAO,EAAC,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,6BAA6B,CAAC;AAErC,uCAAuC;AACvC,OAAO,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,6BAA6B,EAAE,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAC,mBAAmB,EAAE,sBAAsB,EAAC,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAC,kBAAkB,EAAE,uBAAuB,EAAC,MAAM,mBAAmB,CAAC;AAQ9E,sCAAsC;AACtC,2CAA2C;AAC3C,OAAO,EAAC,wBAAwB,EAAC,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAC,IAAI,EAAC,MAAM,mBAAmB,CAAC;AAEvC,2BAA2B;AAC3B,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAG7B,2CAA2C;AAC3C,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAC,6BAA6B,EAAC,MAAM,uBAAuB,CAAC;AAEpE,0CAA0C;AAC1C,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC","sourcesContent":["/**\n * {@include ../README.md}\n * @packageDocumentation\n */\n\n// Tools\nexport {QueryToolResult} from './tools/query/QueryToolResult';\nexport {\n QueryToolParameters,\n createQueryTool,\n getQuerySummary,\n type QueryToolLlmResult,\n type QueryToolAdditionalData,\n type QueryToolOptions,\n} from './tools/query/queryTool';\nexport {\n createCommandTools,\n ExecuteCommandToolParameters,\n ListCommandsToolParameters,\n} from './tools/commandTools';\nexport type {\n CommandToolDescriptor,\n CommandToolsOptions,\n ExecuteCommandToolLlmResult,\n ListCommandsToolLlmResult,\n} from './tools/commandTools';\nexport {createDefaultAiTools} from './tools/defaultTools';\nexport type {DefaultToolsOptions} from './tools/defaultTools';\nexport {\n createDefaultAiInstructions,\n formatTablesForLLM,\n} from './tools/defaultInstructions';\n\n// From @sqlrooms/ai-core - State/Logic\nexport {createAiSlice, useStoreWithAi} from '@sqlrooms/ai-core';\nexport type {AiSliceState} from '@sqlrooms/ai-core';\nexport {useScrollToBottom} from '@sqlrooms/ai-core';\nexport {AiThinkingDots} from '@sqlrooms/ai-core';\nexport {cleanupPendingAnalysisResults, ToolAbortError} from '@sqlrooms/ai-core';\nexport {convertToAiSDKTools, fixIncompleteToolCalls} from '@sqlrooms/ai-core';\nexport {processAgentStream, updateAgentToolCallData} from '@sqlrooms/ai-core';\nexport type {\n AgentStreamResult,\n UIMessageChunk,\n AgentToolCall,\n AgentToolCallAdditionalData,\n} from '@sqlrooms/ai-core';\n\n// From @sqlrooms/ai-core - Components\n// @deprecated Use `Chat.Messages` instead.\nexport {AnalysisResultsContainer} from '@sqlrooms/ai-core';\nexport {AnalysisResult} from '@sqlrooms/ai-core';\nexport {ErrorMessage} from '@sqlrooms/ai-core';\nexport type {ErrorMessageComponentProps} from '@sqlrooms/ai-core';\nexport {PromptSuggestions} from '@sqlrooms/ai-core';\nexport {ModelSelector} from '@sqlrooms/ai-core';\nexport {SessionControls} from '@sqlrooms/ai-core';\nexport {QueryControls} from '@sqlrooms/ai-core';\nexport {DeleteSessionDialog} from '@sqlrooms/ai-core';\nexport {SessionActions} from '@sqlrooms/ai-core';\nexport {SessionDropdown} from '@sqlrooms/ai-core';\nexport {SessionTitle} from '@sqlrooms/ai-core';\nexport type {SessionType} from '@sqlrooms/ai-core';\nexport {ToolErrorMessage} from '@sqlrooms/ai-core';\nexport {ToolCallInfo} from '@sqlrooms/ai-core';\nexport {ReasoningBox} from '@sqlrooms/ai-core';\nexport {Chat} from '@sqlrooms/ai-core';\n\n// From @sqlrooms/ai-config\nexport {\n AiSliceConfig,\n createDefaultAiConfig,\n AiSettingsSliceConfig,\n AnalysisSessionSchema,\n AnalysisResultSchema,\n ErrorMessageSchema,\n} from '@sqlrooms/ai-config';\nexport type {ToolUIPart, UIMessagePart} from '@sqlrooms/ai-config';\n\n// From @sqlrooms/ai-settings - State/Logic\nexport {\n createAiSettingsSlice,\n useStoreWithAiSettings,\n} from '@sqlrooms/ai-settings';\nexport type {AiSettingsSliceState} from '@sqlrooms/ai-settings';\nexport {createDefaultAiSettingsConfig} from '@sqlrooms/ai-settings';\n\n// From @sqlrooms/ai-settings - Components\nexport {AiSettingsPanel} from '@sqlrooms/ai-settings';\nexport {AiProvidersSettings} from '@sqlrooms/ai-settings';\nexport {AiModelsSettings} from '@sqlrooms/ai-settings';\nexport {AiModelParameters} from '@sqlrooms/ai-settings';\nexport {AiModelUsage} from '@sqlrooms/ai-settings';\nexport type {ModelUsageData} from '@sqlrooms/ai-settings';\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { OpenAssistantToolSet } from '@openassistant/utils';
|
|
2
|
+
import type { BaseRoomStoreState, RoomCommandDescriptor, StoreApi } from '@sqlrooms/room-shell';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export declare const ListCommandsToolParameters: z.ZodObject<{
|
|
5
|
+
includeInvisible: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
6
|
+
includeDisabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
7
|
+
includeInputSchema: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
export type ListCommandsToolParameters = z.infer<typeof ListCommandsToolParameters>;
|
|
10
|
+
export type CommandToolDescriptor = RoomCommandDescriptor;
|
|
11
|
+
export type ListCommandsToolLlmResult = {
|
|
12
|
+
success: boolean;
|
|
13
|
+
commands?: CommandToolDescriptor[];
|
|
14
|
+
details?: string;
|
|
15
|
+
errorMessage?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare const ExecuteCommandToolParameters: z.ZodObject<{
|
|
18
|
+
commandId: z.ZodString;
|
|
19
|
+
input: z.ZodOptional<z.ZodUnknown>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
export type ExecuteCommandToolParameters = z.infer<typeof ExecuteCommandToolParameters>;
|
|
22
|
+
export type ExecuteCommandToolLlmResult = {
|
|
23
|
+
success: boolean;
|
|
24
|
+
commandId?: string;
|
|
25
|
+
details?: string;
|
|
26
|
+
errorMessage?: string;
|
|
27
|
+
result?: {
|
|
28
|
+
code?: string;
|
|
29
|
+
message?: string;
|
|
30
|
+
data?: unknown;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type CommandToolsOptions = {
|
|
34
|
+
listToolName?: string;
|
|
35
|
+
executeToolName?: string;
|
|
36
|
+
includeInvisibleCommandsByDefault?: boolean;
|
|
37
|
+
includeDisabledCommandsInList?: boolean;
|
|
38
|
+
};
|
|
39
|
+
export declare function createCommandTools<RS extends BaseRoomStoreState>(store: StoreApi<RS>, options?: CommandToolsOptions): OpenAssistantToolSet;
|
|
40
|
+
//# sourceMappingURL=commandTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandTools.d.ts","sourceRoot":"","sources":["../../src/tools/commandTools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAE/D,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,QAAQ,EACT,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,eAAO,MAAM,0BAA0B;;;;iBAsBrC,CAAC;AAEH,MAAM,MAAM,0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object({
|
|
4
|
+
includeInvisible: z
|
|
5
|
+
.boolean()
|
|
6
|
+
.optional()
|
|
7
|
+
.default(false)
|
|
8
|
+
.describe('Whether to include commands hidden from user-facing UIs (default: false).'),
|
|
9
|
+
includeDisabled: z
|
|
10
|
+
.boolean()
|
|
11
|
+
.optional()
|
|
12
|
+
.default(true)
|
|
13
|
+
.describe('Whether to include currently disabled commands (default: true).'),
|
|
14
|
+
includeInputSchema: z
|
|
15
|
+
.boolean()
|
|
16
|
+
.optional()
|
|
17
|
+
.default(true)
|
|
18
|
+
.describe('Whether to include portable input schemas in the listed command descriptors.'),
|
|
19
|
+
});
|
|
20
|
+
export const ExecuteCommandToolParameters = z.object({
|
|
21
|
+
commandId: z.string().describe('The command ID to execute.'),
|
|
22
|
+
input: z
|
|
23
|
+
.unknown()
|
|
24
|
+
.optional()
|
|
25
|
+
.describe('Optional command input. Must satisfy the command input schema.'),
|
|
26
|
+
});
|
|
27
|
+
const DEFAULT_LIST_TOOL_NAME = 'list_commands';
|
|
28
|
+
const DEFAULT_EXECUTE_TOOL_NAME = 'execute_command';
|
|
29
|
+
export function createCommandTools(store, options) {
|
|
30
|
+
const listToolName = options?.listToolName ?? DEFAULT_LIST_TOOL_NAME;
|
|
31
|
+
const executeToolName = options?.executeToolName ?? DEFAULT_EXECUTE_TOOL_NAME;
|
|
32
|
+
return {
|
|
33
|
+
[listToolName]: {
|
|
34
|
+
name: listToolName,
|
|
35
|
+
description: `List available room commands, including whether they are enabled and whether they require input.
|
|
36
|
+
Use this before executing commands so you can pick a valid command ID and understand input expectations.`,
|
|
37
|
+
parameters: ListCommandsToolParameters,
|
|
38
|
+
execute: async (params) => {
|
|
39
|
+
const state = store.getState();
|
|
40
|
+
if (!hasCommandSliceState(state)) {
|
|
41
|
+
return {
|
|
42
|
+
llmResult: {
|
|
43
|
+
success: false,
|
|
44
|
+
errorMessage: 'Command registry is not available in this room.',
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const descriptors = state.commands.listCommands({
|
|
49
|
+
surface: 'ai',
|
|
50
|
+
includeInvisible: params.includeInvisible,
|
|
51
|
+
includeDisabled: params.includeDisabled,
|
|
52
|
+
includeInputSchema: params.includeInputSchema,
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
llmResult: {
|
|
56
|
+
success: true,
|
|
57
|
+
commands: descriptors,
|
|
58
|
+
details: `Found ${descriptors.length} commands.`,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
[executeToolName]: {
|
|
64
|
+
name: executeToolName,
|
|
65
|
+
description: `Execute a room command by ID.
|
|
66
|
+
Call ${listToolName} first to discover valid command IDs and input requirements.`,
|
|
67
|
+
parameters: ExecuteCommandToolParameters,
|
|
68
|
+
execute: async ({ commandId, input }) => {
|
|
69
|
+
const state = store.getState();
|
|
70
|
+
if (!hasCommandSliceState(state)) {
|
|
71
|
+
return {
|
|
72
|
+
llmResult: {
|
|
73
|
+
success: false,
|
|
74
|
+
commandId,
|
|
75
|
+
errorMessage: 'Command registry is not available in this room.',
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (!state.commands.getCommand(commandId)) {
|
|
80
|
+
return {
|
|
81
|
+
llmResult: {
|
|
82
|
+
success: false,
|
|
83
|
+
commandId,
|
|
84
|
+
errorMessage: `Unknown command ID "${commandId}".`,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const result = await state.commands.invokeCommand(commandId, input, {
|
|
89
|
+
surface: 'ai',
|
|
90
|
+
});
|
|
91
|
+
if (result.success) {
|
|
92
|
+
return {
|
|
93
|
+
llmResult: {
|
|
94
|
+
success: true,
|
|
95
|
+
commandId,
|
|
96
|
+
details: `Executed command "${commandId}".`,
|
|
97
|
+
result: {
|
|
98
|
+
code: result.code,
|
|
99
|
+
message: result.message,
|
|
100
|
+
data: result.data,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
llmResult: {
|
|
107
|
+
success: false,
|
|
108
|
+
commandId,
|
|
109
|
+
errorMessage: result.error ?? 'Command execution failed.',
|
|
110
|
+
result: {
|
|
111
|
+
code: result.code,
|
|
112
|
+
message: result.message,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=commandTools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandTools.js","sourceRoot":"","sources":["../../src/tools/commandTools.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAM1D,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC;IACjD,gBAAgB,EAAE,CAAC;SAChB,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,OAAO,CAAC,KAAK,CAAC;SACd,QAAQ,CACP,2EAA2E,CAC5E;IACH,eAAe,EAAE,CAAC;SACf,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,OAAO,CAAC,IAAI,CAAC;SACb,QAAQ,CACP,iEAAiE,CAClE;IACH,kBAAkB,EAAE,CAAC;SAClB,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,OAAO,CAAC,IAAI,CAAC;SACb,QAAQ,CACP,8EAA8E,CAC/E;CACJ,CAAC,CAAC;AAeH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,MAAM,CAAC;IACnD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4BAA4B,CAAC;IAC5D,KAAK,EAAE,CAAC;SACL,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,QAAQ,CAAC,gEAAgE,CAAC;CAC9E,CAA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OpenAssistantToolSet} from '@openassistant/utils';\nimport {hasCommandSliceState} from '@sqlrooms/room-shell';\nimport type {\n BaseRoomStoreState,\n RoomCommandDescriptor,\n StoreApi,\n} from '@sqlrooms/room-shell';\nimport {z} from 'zod';\n\nexport const ListCommandsToolParameters = z.object({\n includeInvisible: z\n .boolean()\n .optional()\n .default(false)\n .describe(\n 'Whether to include commands hidden from user-facing UIs (default: false).',\n ),\n includeDisabled: z\n .boolean()\n .optional()\n .default(true)\n .describe(\n 'Whether to include currently disabled commands (default: true).',\n ),\n includeInputSchema: z\n .boolean()\n .optional()\n .default(true)\n .describe(\n 'Whether to include portable input schemas in the listed command descriptors.',\n ),\n});\n\nexport type ListCommandsToolParameters = z.infer<\n typeof ListCommandsToolParameters\n>;\n\nexport type CommandToolDescriptor = RoomCommandDescriptor;\n\nexport type ListCommandsToolLlmResult = {\n success: boolean;\n commands?: CommandToolDescriptor[];\n details?: string;\n errorMessage?: string;\n};\n\nexport const ExecuteCommandToolParameters = z.object({\n commandId: z.string().describe('The command ID to execute.'),\n input: z\n .unknown()\n .optional()\n .describe('Optional command input. Must satisfy the command input schema.'),\n});\n\nexport type ExecuteCommandToolParameters = z.infer<\n typeof ExecuteCommandToolParameters\n>;\n\nexport type ExecuteCommandToolLlmResult = {\n success: boolean;\n commandId?: string;\n details?: string;\n errorMessage?: string;\n result?: {\n code?: string;\n message?: string;\n data?: unknown;\n };\n};\n\nexport type CommandToolsOptions = {\n listToolName?: string;\n executeToolName?: string;\n includeInvisibleCommandsByDefault?: boolean;\n includeDisabledCommandsInList?: boolean;\n};\n\nconst DEFAULT_LIST_TOOL_NAME = 'list_commands';\nconst DEFAULT_EXECUTE_TOOL_NAME = 'execute_command';\n\nexport function createCommandTools<RS extends BaseRoomStoreState>(\n store: StoreApi<RS>,\n options?: CommandToolsOptions,\n): OpenAssistantToolSet {\n const listToolName = options?.listToolName ?? DEFAULT_LIST_TOOL_NAME;\n const executeToolName = options?.executeToolName ?? DEFAULT_EXECUTE_TOOL_NAME;\n\n return {\n [listToolName]: {\n name: listToolName,\n description: `List available room commands, including whether they are enabled and whether they require input.\nUse this before executing commands so you can pick a valid command ID and understand input expectations.`,\n parameters: ListCommandsToolParameters,\n execute: async (params: ListCommandsToolParameters) => {\n const state = store.getState();\n if (!hasCommandSliceState(state)) {\n return {\n llmResult: {\n success: false,\n errorMessage: 'Command registry is not available in this room.',\n } satisfies ListCommandsToolLlmResult,\n };\n }\n\n const descriptors = state.commands.listCommands({\n surface: 'ai',\n includeInvisible: params.includeInvisible,\n includeDisabled: params.includeDisabled,\n includeInputSchema: params.includeInputSchema,\n });\n\n return {\n llmResult: {\n success: true,\n commands: descriptors,\n details: `Found ${descriptors.length} commands.`,\n } satisfies ListCommandsToolLlmResult,\n };\n },\n },\n [executeToolName]: {\n name: executeToolName,\n description: `Execute a room command by ID.\nCall ${listToolName} first to discover valid command IDs and input requirements.`,\n parameters: ExecuteCommandToolParameters,\n execute: async ({commandId, input}: ExecuteCommandToolParameters) => {\n const state = store.getState();\n if (!hasCommandSliceState(state)) {\n return {\n llmResult: {\n success: false,\n commandId,\n errorMessage: 'Command registry is not available in this room.',\n } satisfies ExecuteCommandToolLlmResult,\n };\n }\n\n if (!state.commands.getCommand(commandId)) {\n return {\n llmResult: {\n success: false,\n commandId,\n errorMessage: `Unknown command ID \"${commandId}\".`,\n } satisfies ExecuteCommandToolLlmResult,\n };\n }\n\n const result = await state.commands.invokeCommand(commandId, input, {\n surface: 'ai',\n });\n if (result.success) {\n return {\n llmResult: {\n success: true,\n commandId,\n details: `Executed command \"${commandId}\".`,\n result: {\n code: result.code,\n message: result.message,\n data: result.data,\n },\n } satisfies ExecuteCommandToolLlmResult,\n };\n }\n return {\n llmResult: {\n success: false,\n commandId,\n errorMessage: result.error ?? 'Command execution failed.',\n result: {\n code: result.code,\n message: result.message,\n },\n } satisfies ExecuteCommandToolLlmResult,\n };\n },\n },\n };\n}\n"]}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { AiSliceState } from '@sqlrooms/ai-core';
|
|
2
|
-
import { DuckDbSliceState } from '@sqlrooms/duckdb';
|
|
3
|
-
import { StoreApi } from '@sqlrooms/room-shell';
|
|
4
|
-
import { QueryToolOptions } from './query/queryTool';
|
|
5
|
-
import { OpenAssistantToolSet } from '@openassistant/utils';
|
|
1
|
+
import type { AiSliceState } from '@sqlrooms/ai-core';
|
|
2
|
+
import type { DuckDbSliceState } from '@sqlrooms/duckdb';
|
|
3
|
+
import type { BaseRoomStoreState, StoreApi } from '@sqlrooms/room-shell';
|
|
4
|
+
import type { QueryToolOptions } from './query/queryTool';
|
|
5
|
+
import type { OpenAssistantToolSet } from '@openassistant/utils';
|
|
6
|
+
import type { CommandToolsOptions } from './commandTools';
|
|
6
7
|
export type DefaultToolsOptions = {
|
|
7
8
|
query?: QueryToolOptions;
|
|
9
|
+
commands?: CommandToolsOptions | false;
|
|
8
10
|
};
|
|
9
11
|
/**
|
|
10
12
|
* Default tools available to the AI assistant for data analysis
|
|
11
13
|
* Includes:
|
|
12
14
|
* - query: Executes SQL queries against DuckDB
|
|
15
|
+
* - list_commands / execute_command: Bridge to room command registry
|
|
13
16
|
*/
|
|
14
|
-
export declare function createDefaultAiTools(store: StoreApi<AiSliceState & DuckDbSliceState>, options?: DefaultToolsOptions): OpenAssistantToolSet;
|
|
17
|
+
export declare function createDefaultAiTools(store: StoreApi<BaseRoomStoreState & AiSliceState & DuckDbSliceState>, options?: DefaultToolsOptions): OpenAssistantToolSet;
|
|
15
18
|
//# sourceMappingURL=defaultTools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultTools.d.ts","sourceRoot":"","sources":["../../src/tools/defaultTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"defaultTools.d.ts","sourceRoot":"","sources":["../../src/tools/defaultTools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAC,kBAAkB,EAAE,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAEvE,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAE/D,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,gBAAgB,CAAC;AAExD,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,QAAQ,CAAC,EAAE,mBAAmB,GAAG,KAAK,CAAC;CACxC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,QAAQ,CAAC,kBAAkB,GAAG,YAAY,GAAG,gBAAgB,CAAC,EACrE,OAAO,CAAC,EAAE,mBAAmB,GAC5B,oBAAoB,CAQtB"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { createQueryTool } from './query/queryTool';
|
|
2
|
+
import { createCommandTools } from './commandTools';
|
|
2
3
|
/**
|
|
3
4
|
* Default tools available to the AI assistant for data analysis
|
|
4
5
|
* Includes:
|
|
5
6
|
* - query: Executes SQL queries against DuckDB
|
|
7
|
+
* - list_commands / execute_command: Bridge to room command registry
|
|
6
8
|
*/
|
|
7
9
|
export function createDefaultAiTools(store, options) {
|
|
8
|
-
const { query } = options || {};
|
|
10
|
+
const { query, commands } = options || {};
|
|
11
|
+
const commandTools = commands === false ? {} : createCommandTools(store, commands || undefined);
|
|
9
12
|
return {
|
|
10
13
|
query: createQueryTool(store, query),
|
|
14
|
+
...commandTools,
|
|
11
15
|
};
|
|
12
16
|
}
|
|
13
17
|
//# sourceMappingURL=defaultTools.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultTools.js","sourceRoot":"","sources":["../../src/tools/defaultTools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,eAAe,
|
|
1
|
+
{"version":3,"file":"defaultTools.js","sourceRoot":"","sources":["../../src/tools/defaultTools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAQlD;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAqE,EACrE,OAA6B;IAE7B,MAAM,EAAC,KAAK,EAAE,QAAQ,EAAC,GAAG,OAAO,IAAI,EAAE,CAAC;IACxC,MAAM,YAAY,GAChB,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC;IAC7E,OAAO;QACL,KAAK,EAAE,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC;QACpC,GAAG,YAAY;KAChB,CAAC;AACJ,CAAC","sourcesContent":["import type {AiSliceState} from '@sqlrooms/ai-core';\nimport type {DuckDbSliceState} from '@sqlrooms/duckdb';\nimport type {BaseRoomStoreState, StoreApi} from '@sqlrooms/room-shell';\nimport {createQueryTool} from './query/queryTool';\nimport type {QueryToolOptions} from './query/queryTool';\nimport type {OpenAssistantToolSet} from '@openassistant/utils';\nimport {createCommandTools} from './commandTools';\nimport type {CommandToolsOptions} from './commandTools';\n\nexport type DefaultToolsOptions = {\n query?: QueryToolOptions;\n commands?: CommandToolsOptions | false;\n};\n\n/**\n * Default tools available to the AI assistant for data analysis\n * Includes:\n * - query: Executes SQL queries against DuckDB\n * - list_commands / execute_command: Bridge to room command registry\n */\nexport function createDefaultAiTools(\n store: StoreApi<BaseRoomStoreState & AiSliceState & DuckDbSliceState>,\n options?: DefaultToolsOptions,\n): OpenAssistantToolSet {\n const {query, commands} = options || {};\n const commandTools =\n commands === false ? {} : createCommandTools(store, commands || undefined);\n return {\n query: createQueryTool(store, query),\n ...commandTools,\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@openassistant/utils": "1.0.0-alpha.0",
|
|
23
|
-
"@sqlrooms/ai-config": "0.
|
|
24
|
-
"@sqlrooms/ai-core": "0.
|
|
25
|
-
"@sqlrooms/ai-settings": "0.
|
|
26
|
-
"@sqlrooms/data-table": "0.
|
|
27
|
-
"@sqlrooms/duckdb": "0.
|
|
28
|
-
"@sqlrooms/room-shell": "0.
|
|
29
|
-
"@sqlrooms/ui": "0.
|
|
23
|
+
"@sqlrooms/ai-config": "0.28.0",
|
|
24
|
+
"@sqlrooms/ai-core": "0.28.0",
|
|
25
|
+
"@sqlrooms/ai-settings": "0.28.0",
|
|
26
|
+
"@sqlrooms/data-table": "0.28.0",
|
|
27
|
+
"@sqlrooms/duckdb": "0.28.0",
|
|
28
|
+
"@sqlrooms/room-shell": "0.28.0",
|
|
29
|
+
"@sqlrooms/ui": "0.28.0",
|
|
30
30
|
"lucide-react": "^0.556.0",
|
|
31
31
|
"zod": "^4.1.8"
|
|
32
32
|
},
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"typecheck": "tsc --noEmit",
|
|
43
43
|
"typedoc": "typedoc"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "dcac54f8adf77240e293c93d224a0ce9fd8142a9"
|
|
46
46
|
}
|