@sqlrooms/ai 0.26.1-rc.7 → 0.27.0-rc.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.md +1 -1
- 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/defaultInstructions.d.ts +2 -1
- package/dist/tools/defaultInstructions.d.ts.map +1 -1
- package/dist/tools/defaultInstructions.js +14 -10
- package/dist/tools/defaultInstructions.js.map +1 -1
- package/dist/tools/query/queryTool.d.ts +1 -1
- package/dist/tools/query/queryTool.d.ts.map +1 -1
- package/dist/tools/query/queryTool.js +4 -19
- package/dist/tools/query/queryTool.js.map +1 -1
- package/package.json +11 -18
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright 2025
|
|
3
|
+
Copyright 2025 SQLRooms Contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export { processAgentStream, updateAgentToolCallData } from '@sqlrooms/ai-core';
|
|
|
18
18
|
export type { AgentStreamResult, UIMessageChunk, AgentToolCall, AgentToolCallAdditionalData, } from '@sqlrooms/ai-core';
|
|
19
19
|
export { AnalysisResultsContainer } from '@sqlrooms/ai-core';
|
|
20
20
|
export { AnalysisResult } from '@sqlrooms/ai-core';
|
|
21
|
+
export { ErrorMessage } from '@sqlrooms/ai-core';
|
|
22
|
+
export type { ErrorMessageComponentProps } from '@sqlrooms/ai-core';
|
|
21
23
|
export { PromptSuggestions } from '@sqlrooms/ai-core';
|
|
22
24
|
export { ModelSelector } from '@sqlrooms/ai-core';
|
|
23
25
|
export { SessionControls } from '@sqlrooms/ai-core';
|
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,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,6BAA6B,EAAE,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAChF,OAAO,EACL,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAC,kBAAkB,EAAE,uBAAuB,EAAC,MAAM,mBAAmB,CAAC;AAC9E,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAC,wBAAwB,EAAC,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;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AC;AACxD,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AACnD,YAAY,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export { processAgentStream, updateAgentToolCallData } from '@sqlrooms/ai-core';
|
|
|
18
18
|
// From @sqlrooms/ai-core - Components
|
|
19
19
|
export { AnalysisResultsContainer } from '@sqlrooms/ai-core';
|
|
20
20
|
export { AnalysisResult } from '@sqlrooms/ai-core';
|
|
21
|
+
export { ErrorMessage } from '@sqlrooms/ai-core';
|
|
21
22
|
export { PromptSuggestions } from '@sqlrooms/ai-core';
|
|
22
23
|
export { ModelSelector } from '@sqlrooms/ai-core';
|
|
23
24
|
export { SessionControls } from '@sqlrooms/ai-core';
|
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,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,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,6BAA6B,EAAE,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAChF,OAAO,EACL,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,mBA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,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 {useAiChat} from '@sqlrooms/ai-core';\nexport {AiThinkingDots} from '@sqlrooms/ai-core';\nexport {cleanupPendingAnalysisResults, ToolAbortError} from '@sqlrooms/ai-core';\nexport {\n convertToAiSDKTools,\n completeIncompleteToolCalls,\n} 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\nexport {AnalysisResultsContainer} from '@sqlrooms/ai-core';\nexport {AnalysisResult} 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';\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,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,SA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uB,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 {useAiChat} from '@sqlrooms/ai-core';\nexport {AiThinkingDots} from '@sqlrooms/ai-core';\nexport {cleanupPendingAnalysisResults, ToolAbortError} from '@sqlrooms/ai-core';\nexport {\n convertToAiSDKTools,\n completeIncompleteToolCalls,\n} 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\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';\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"]}
|
|
@@ -4,9 +4,10 @@ import { StoreApi } from '@sqlrooms/room-shell';
|
|
|
4
4
|
/**
|
|
5
5
|
* Formats table schema information in a clean, LLM-friendly format
|
|
6
6
|
* @param tables Array of DataTable objects from the DuckDB state
|
|
7
|
+
* @param currentDatabase The current local database name to filter by
|
|
7
8
|
* @returns Formatted string representation of table schemas
|
|
8
9
|
*/
|
|
9
|
-
export declare function formatTablesForLLM(tables: DataTable[]): string;
|
|
10
|
+
export declare function formatTablesForLLM(tables: DataTable[], currentDatabase?: string): string;
|
|
10
11
|
/**
|
|
11
12
|
* Returns the default system instructions for the AI assistant
|
|
12
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultInstructions.d.ts","sourceRoot":"","sources":["../../src/tools/defaultInstructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAC,gBAAgB,EAAE,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAE9C
|
|
1
|
+
{"version":3,"file":"defaultInstructions.d.ts","sourceRoot":"","sources":["../../src/tools/defaultInstructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAC,gBAAgB,EAAE,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAE9C;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,SAAS,EAAE,EACnB,eAAe,CAAC,EAAE,MAAM,GACvB,MAAM,CAuCR;AA4DD;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,QAAQ,CAAC,YAAY,GAAG,gBAAgB,CAAC,GAC/C,MAAM,CAKR"}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Formats table schema information in a clean, LLM-friendly format
|
|
3
3
|
* @param tables Array of DataTable objects from the DuckDB state
|
|
4
|
+
* @param currentDatabase The current local database name to filter by
|
|
4
5
|
* @returns Formatted string representation of table schemas
|
|
5
6
|
*/
|
|
6
|
-
export function formatTablesForLLM(tables) {
|
|
7
|
+
export function formatTablesForLLM(tables, currentDatabase) {
|
|
7
8
|
if (!tables || tables.length === 0) {
|
|
8
9
|
return 'No tables available in the database.';
|
|
9
10
|
}
|
|
10
11
|
return tables
|
|
11
12
|
.filter((table) => {
|
|
12
13
|
const schemaName = table.table?.schema || table.schema;
|
|
13
|
-
|
|
14
|
+
const databaseName = table.table?.database || table.database;
|
|
15
|
+
// Only include tables from 'main' schema and the current local database
|
|
16
|
+
// This excludes tables from attached databases (MotherDuck, Iceberg, knowledge base, etc.)
|
|
17
|
+
const isMainSchema = !schemaName || schemaName === 'main';
|
|
18
|
+
const isLocalDatabase = !databaseName || databaseName === currentDatabase;
|
|
19
|
+
return isMainSchema && isLocalDatabase;
|
|
14
20
|
})
|
|
15
21
|
.map((table) => {
|
|
16
22
|
const tableName = table.table?.table || table.tableName;
|
|
@@ -20,14 +26,10 @@ export function formatTablesForLLM(tables) {
|
|
|
20
26
|
: tableName;
|
|
21
27
|
// Build table header with metadata
|
|
22
28
|
const header = [fullTableName];
|
|
23
|
-
if (table.isView)
|
|
24
|
-
header.push('(view)');
|
|
25
29
|
if (table.rowCount !== undefined)
|
|
26
30
|
header.push(`[${table.rowCount.toLocaleString()} rows]`);
|
|
27
31
|
// Format columns with proper indentation
|
|
28
|
-
const columns = table.columns
|
|
29
|
-
.map((col) => ` ${col.name}: ${col.type}`)
|
|
30
|
-
.join('\n');
|
|
32
|
+
const columns = table.columns.map((col) => ` ${col.name}`).join('\n');
|
|
31
33
|
// Add comment if available
|
|
32
34
|
const comment = table.comment ? ` # ${table.comment}` : '';
|
|
33
35
|
return `${header.join(' ')}\n${columns}${comment ? '\n' + comment : ''}`;
|
|
@@ -88,14 +90,16 @@ For your final answer:
|
|
|
88
90
|
* If no sample rows provided: Never fabricate data. Direct users to the table component for actual results.
|
|
89
91
|
* If sample rows provided: Use them to enhance your analysis, but always direct users to the table component for complete results.
|
|
90
92
|
|
|
91
|
-
Available tables in the
|
|
93
|
+
Available tables in the local databases (format: tableName [rowCount] followed by indented columns):
|
|
92
94
|
|
|
93
95
|
`;
|
|
94
96
|
/**
|
|
95
97
|
* Returns the default system instructions for the AI assistant
|
|
96
98
|
*/
|
|
97
99
|
export function createDefaultAiInstructions(store) {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
+
const dbState = store.getState().db;
|
|
101
|
+
const tables = dbState.tables;
|
|
102
|
+
const currentDatabase = dbState.currentDatabase;
|
|
103
|
+
return `${DEFAULT_INSTRUCTIONS}\n${formatTablesForLLM(tables, currentDatabase)}`;
|
|
100
104
|
}
|
|
101
105
|
//# sourceMappingURL=defaultInstructions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultInstructions.js","sourceRoot":"","sources":["../../src/tools/defaultInstructions.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"defaultInstructions.js","sourceRoot":"","sources":["../../src/tools/defaultInstructions.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAmB,EACnB,eAAwB;IAExB,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnC,OAAO,sCAAsC,CAAC;IAChD,CAAC;IAED,OAAO,MAAM;SACV,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QAChB,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,EAAE,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;QACvD,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,EAAE,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC;QAE7D,wEAAwE;QACxE,2FAA2F;QAC3F,MAAM,YAAY,GAAG,CAAC,UAAU,IAAI,UAAU,KAAK,MAAM,CAAC;QAC1D,MAAM,eAAe,GAAG,CAAC,YAAY,IAAI,YAAY,KAAK,eAAe,CAAC;QAE1E,OAAO,YAAY,IAAI,eAAe,CAAC;IACzC,CA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BAA2B,CACzC,KAAgD;IAEhD,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;IACpC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAChD,OAAO,GAAG,oBAAoB,KAAK,kBAAkB,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,CAAC;AACnF,CAAC","sourcesContent":["import {AiSliceState} from '@sqlrooms/ai-core';\nimport {DuckDbSliceState, DataTable} from '@sqlrooms/duckdb';\nimport {StoreApi} from '@sqlrooms/room-shell';\n\n/**\n * Formats table schema information in a clean, LLM-friendly format\n * @param tables Array of DataTable objects from the DuckDB state\n * @param currentDatabase The current local database name to filter by\n * @returns Formatted string representation of table schemas\n */\nexport function formatTablesForLLM(\n tables: DataTable[],\n currentDatabase?: string,\n): string {\n if (!tables || tables.length === 0) {\n return 'No tables available in the database.';\n }\n\n return tables\n .filter((table) => {\n const schemaName = table.table?.schema || table.schema;\n const databaseName = table.table?.database || table.database;\n\n // Only include tables from 'main' schema and the current local database\n // This excludes tables from attached databases (MotherDuck, Iceberg, knowledge base, etc.)\n const isMainSchema = !schemaName || schemaName === 'main';\n const isLocalDatabase = !databaseName || databaseName === currentDatabase;\n\n return isMainSchema && isLocalDatabase;\n })\n .map((table) => {\n const tableName = table.table?.table || table.tableName;\n const schemaName = table.table?.schema || table.schema;\n const fullTableName =\n schemaName && schemaName !== 'main'\n ? `${schemaName}.${tableName}`\n : tableName;\n\n // Build table header with metadata\n const header = [fullTableName];\n if (table.rowCount !== undefined)\n header.push(`[${table.rowCount.toLocaleString()} rows]`);\n\n // Format columns with proper indentation\n const columns = table.columns.map((col) => ` ${col.name}`).join('\\n');\n\n // Add comment if available\n const comment = table.comment ? ` # ${table.comment}` : '';\n\n return `${header.join(' ')}\\n${columns}${comment ? '\\n' + comment : ''}`;\n })\n .join('\\n\\n');\n}\n\n/**\n * System prompt template for the AI assistant that provides instructions for:\n * - Using DuckDB-specific SQL syntax and functions\n * - Handling query results and error cases\n * - Creating visualizations with VegaLite\n * - Formatting final answers\n */\nconst DEFAULT_INSTRUCTIONS = `\nYou are analyzing tables in DuckDB database in the context of a room.\n\nInstructions for analysis:\n- When using 'query' tool, please assign parameter 'type' with value 'query'\n- Use DuckDB-specific SQL syntax and functions (not Oracle, PostgreSQL, or other SQL dialects)\n- Some key DuckDB-specific functions to use:\n * regexp_matches() for regex (not regexp_like)\n * strftime() for date formatting (not to_char)\n * list_aggregate() for array operations\n * unnest() for array expansion\n * regr_sxy()\n * corr()\n * skewness()\n- Please always try to use SQL queries to answer users questions\n- Please run tool calls sequentially, don't run multiple tool calls in parallel\n- IMPORTANT: Do not list out raw query results in your response. Instead:\n * Describe the results in natural language\n * Provide summary statistics\n * Use comparisons and relative terms\n * Include only the most relevant values if necessary\n- Break down complex problems into smaller steps\n- Use \"SUMMARIZE table_name\"for quick overview of the table\n- Please don't modify data\n- IMPORTANT: When you receive an error response from a tool call (where success: false):\n * Stop making any further tool calls immediately\n * Return a final answer that includes the error message\n * Explain what went wrong and suggest possible fixes if applicable\n\nWhen creating visualizations:\n- Follow VegaLite syntax\n- Choose appropriate chart types based on the data and analysis goals\n- Use clear titles and axis labels\n- Consider color schemes for better readability\n- Add meaningful tooltips when relevant\n- Format numbers and dates appropriately\n- Use aggregations when dealing with large datasets\n\nFor your final answer:\n- Provide an explanation for how you got it\n- Explain your reasoning step by step\n- Include relevant statistics or metrics\n- For each prompt, please always provide the final answer.\n- IMPORTANT: Query tool results may include sample rows (firstRows) or may be empty:\n * If no sample rows provided: Never fabricate data. Direct users to the table component for actual results.\n * If sample rows provided: Use them to enhance your analysis, but always direct users to the table component for complete results.\n\nAvailable tables in the local databases (format: tableName [rowCount] followed by indented columns):\n\n`;\n\n/**\n * Returns the default system instructions for the AI assistant\n */\nexport function createDefaultAiInstructions(\n store: StoreApi<AiSliceState & DuckDbSliceState>,\n): string {\n const dbState = store.getState().db;\n const tables = dbState.tables;\n const currentDatabase = dbState.currentDatabase;\n return `${DEFAULT_INSTRUCTIONS}\\n${formatTablesForLLM(tables, currentDatabase)}`;\n}\n"]}
|
|
@@ -70,5 +70,5 @@ export declare function createQueryTool(store: StoreApi<AiSliceState & DuckDbSli
|
|
|
70
70
|
* @param sqlQuery - SQL SELECT query to analyze
|
|
71
71
|
* @returns Summary statistics as JSON object, or null if the query is not a SELECT statement or if summary generation fails
|
|
72
72
|
*/
|
|
73
|
-
export declare function getQuerySummary(connector: DuckDbConnector, sqlQuery: string): Promise<Record<string, unknown>[] | null>;
|
|
73
|
+
export declare function getQuerySummary(connector: DuckDbConnector, sqlQuery: string, abortSignal?: AbortSignal): Promise<Record<string, unknown>[] | null>;
|
|
74
74
|
//# sourceMappingURL=queryTool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryTool.d.ts","sourceRoot":"","sources":["../../../src/tools/query/queryTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAEL,eAAe,EACf,gBAAgB,EAEjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD,eAAO,MAAM,mBAAmB;;;;iBAI9B,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEtE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE;QACL,IAAI,EAAE,OAAO,CAAC;QACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC;QAC1C,SAAS,CAAC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C;QACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,IAAI,CAAC;QAC1C,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;KACvC,CAAC;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,0BAA0B,CAAC,EAAE,MAAM,CAAC;CACrC,CAAC;AAEF,wBAAgB,eAAe,CAC7B,KAAK,EAAE,QAAQ,CAAC,YAAY,GAAG,gBAAgB,CAAC,EAChD,OAAO,CAAC,EAAE,gBAAgB;;;;;;;;sBAcd,mBAAmB,YACjB;QAAC,WAAW,CAAC,EAAE,WAAW,CAAA;KAAC;;;;;;;;;;;;;;;;;;;;;;;;;EAsF1C;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,SAAS,EAAE,eAAe,EAC1B,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,WAAW,6CAkB1B"}
|
|
@@ -18,10 +18,6 @@ If a query fails, please don't try to run it again with the same syntax.`,
|
|
|
18
18
|
const { type, sqlQuery } = params;
|
|
19
19
|
const abortSignal = options?.abortSignal;
|
|
20
20
|
try {
|
|
21
|
-
// Check if aborted before starting
|
|
22
|
-
if (abortSignal?.aborted) {
|
|
23
|
-
throw new Error('Query execution was aborted');
|
|
24
|
-
}
|
|
25
21
|
const connector = await store.getState().db.getConnector();
|
|
26
22
|
const parsedQuery = await store.getState().db.sqlSelectToJson(sqlQuery);
|
|
27
23
|
if (parsedQuery.error &&
|
|
@@ -39,23 +35,12 @@ If a query fails, please don't try to run it again with the same syntax.`,
|
|
|
39
35
|
throw new Error('Query is not a valid SELECT statement');
|
|
40
36
|
}
|
|
41
37
|
}
|
|
42
|
-
|
|
43
|
-
if (abortSignal?.aborted) {
|
|
44
|
-
throw new Error('Query execution was aborted');
|
|
45
|
-
}
|
|
46
|
-
const result = await connector.query(sqlQuery);
|
|
47
|
-
// Check if aborted after query execution
|
|
48
|
-
if (abortSignal?.aborted) {
|
|
49
|
-
throw new Error('Query execution was aborted');
|
|
50
|
-
}
|
|
38
|
+
const result = await connector.query(sqlQuery, { signal: abortSignal });
|
|
51
39
|
const summaryData = await (async () => {
|
|
52
40
|
if (!autoSummary)
|
|
53
41
|
return null;
|
|
54
42
|
if (parsedQuery.error)
|
|
55
43
|
return null;
|
|
56
|
-
// Check if aborted before generating summary
|
|
57
|
-
if (abortSignal?.aborted)
|
|
58
|
-
return null;
|
|
59
44
|
const lastNode = parsedQuery.statements[parsedQuery.statements.length - 1]?.node;
|
|
60
45
|
// Only get summary if the last statement isn't already a SUMMARIZE query
|
|
61
46
|
if (lastNode?.type === 'SELECT_NODE' &&
|
|
@@ -66,7 +51,7 @@ If a query fails, please don't try to run it again with the same syntax.`,
|
|
|
66
51
|
const lastStatement = statements[statements.length - 1];
|
|
67
52
|
if (!lastStatement)
|
|
68
53
|
return null;
|
|
69
|
-
return await getQuerySummary(connector, lastStatement);
|
|
54
|
+
return await getQuerySummary(connector, lastStatement, abortSignal);
|
|
70
55
|
})();
|
|
71
56
|
// Conditionally get rows of the result as a json object based on numberOfRowsToShareWithLLM
|
|
72
57
|
const firstRows = numberOfRowsToShareWithLLM > 0
|
|
@@ -106,14 +91,14 @@ If a query fails, please don't try to run it again with the same syntax.`,
|
|
|
106
91
|
* @param sqlQuery - SQL SELECT query to analyze
|
|
107
92
|
* @returns Summary statistics as JSON object, or null if the query is not a SELECT statement or if summary generation fails
|
|
108
93
|
*/
|
|
109
|
-
export async function getQuerySummary(connector, sqlQuery) {
|
|
94
|
+
export async function getQuerySummary(connector, sqlQuery, abortSignal) {
|
|
110
95
|
if (!sqlQuery.toLowerCase().trim().startsWith('select')) {
|
|
111
96
|
return null;
|
|
112
97
|
}
|
|
113
98
|
try {
|
|
114
99
|
const summaryResult = await connector.query(`SUMMARIZE (
|
|
115
100
|
${sqlQuery}
|
|
116
|
-
)
|
|
101
|
+
)`, { signal: abortSignal });
|
|
117
102
|
return arrowTableToJson(summaryResult);
|
|
118
103
|
}
|
|
119
104
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryTool.js","sourceRoot":"","sources":["../../../src/tools/query/queryTool.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAGhB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC;AA0BH,MAAM,UAAU,eAAe,CAC7B,KAAgD,EAChD,OAA0B;IAE1B,MAAM,EACJ,QAAQ,GAAG,IAAI,EACf,WAAW,GAAG,KAAK,EACnB,0BAA0B,GAAG,CAAC,GAC/B,GAAG,OAAO,IAAI,EAAE,CAAC;IAClB,OAAO;QACL,IAAI,EAAE,OAAO;QACb,WAAW,EAAE;;yEAEwD;QACrE,UAAU,EAAE,mBAAmB;QAC/B,OAAO,EAAE,KAAK,EACZ,MAA2B,EAC3B,OAAqC,EACrC,EAAE;YACF,MAAM,EAAC,IAAI,EAAE,QAAQ,EAAC,GAAG,MAAM,CAAC;YAChC,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,C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AAC,KAAK,CACzC;QACE,QAAQ;MACV,EACA,EAAC,MAAM,EAAE,WAAW,EAAC,CACtB,CAAC;QACF,OAAO,gBAAgB,CAAC,aAAa,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;QAC/D,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import {AiSliceState} from '@sqlrooms/ai-core';\nimport {\n arrowTableToJson,\n DuckDbConnector,\n DuckDbSliceState,\n splitSqlStatements,\n} from '@sqlrooms/duckdb';\nimport type {StoreApi} from '@sqlrooms/room-shell';\nimport {z} from 'zod';\nimport {QueryToolResult} from './QueryToolResult';\n\nexport const QueryToolParameters = z.object({\n type: z.literal('query'),\n sqlQuery: z.string(),\n reasoning: z.string(),\n});\n\nexport type QueryToolParameters = z.infer<typeof QueryToolParameters>;\n\nexport type QueryToolLlmResult = {\n success: boolean;\n data?: {\n type: 'query';\n summary: Record<string, unknown>[] | null;\n firstRows?: Record<string, unknown>[];\n };\n details?: string;\n errorMessage?: string;\n};\n\nexport type QueryToolAdditionalData = {\n title: string;\n sqlQuery: string;\n};\n\nexport type QueryToolOptions = {\n readOnly?: boolean;\n autoSummary?: boolean;\n numberOfRowsToShareWithLLM?: number;\n};\n\nexport function createQueryTool(\n store: StoreApi<AiSliceState & DuckDbSliceState>,\n options?: QueryToolOptions,\n) {\n const {\n readOnly = true,\n autoSummary = false,\n numberOfRowsToShareWithLLM = 0,\n } = options || {};\n return {\n name: 'query',\n description: `A tool for running SQL queries on the tables in the database.\nPlease only run one query at a time.\nIf a query fails, please don't try to run it again with the same syntax.`,\n parameters: QueryToolParameters,\n execute: async (\n params: QueryToolParameters,\n options?: {abortSignal?: AbortSignal},\n ) => {\n const {type, sqlQuery} = params;\n const abortSignal = options?.abortSignal;\n\n try {\n const connector = await store.getState().db.getConnector();\n const parsedQuery = await store.getState().db.sqlSelectToJson(sqlQuery);\n\n if (\n parsedQuery.error &&\n // Only SELECT statements can be serialized to json, so we ignore not implemented errors\n parsedQuery.error_type !== 'not implemented'\n ) {\n throw new Error(parsedQuery.error_message);\n }\n\n if (readOnly) {\n if (parsedQuery.error) {\n throw new Error(\n `Query is not a valid SELECT statement: ${parsedQuery.error_message}`,\n );\n }\n if (\n parsedQuery.statements.length !== 1 || // only one statement allowed\n parsedQuery.statements[0]?.node.type !== 'SELECT_NODE' // only SELECT statements allowed\n ) {\n throw new Error('Query is not a valid SELECT statement');\n }\n }\n\n const result = await connector.query(sqlQuery, {signal: abortSignal});\n\n const summaryData = await (async () => {\n if (!autoSummary) return null;\n if (parsedQuery.error) return null;\n\n const lastNode =\n parsedQuery.statements[parsedQuery.statements.length - 1]?.node;\n\n // Only get summary if the last statement isn't already a SUMMARIZE query\n if (\n lastNode?.type === 'SELECT_NODE' &&\n lastNode?.from_table?.show_type === 'SUMMARY'\n ) {\n return arrowTableToJson(result);\n }\n const statements = splitSqlStatements(sqlQuery);\n const lastStatement = statements[statements.length - 1];\n if (!lastStatement) return null;\n return await getQuerySummary(connector, lastStatement, abortSignal);\n })();\n\n // Conditionally get rows of the result as a json object based on numberOfRowsToShareWithLLM\n const firstRows =\n numberOfRowsToShareWithLLM > 0\n ? arrowTableToJson(result.slice(0, numberOfRowsToShareWithLLM))\n : [];\n\n return {\n llmResult: {\n success: true,\n data: {\n type,\n summary: summaryData,\n ...(numberOfRowsToShareWithLLM > 0 ? {firstRows} : {}),\n },\n },\n additionalData: {\n title: 'Query Result',\n sqlQuery,\n },\n };\n } catch (error) {\n return {\n llmResult: {\n success: false,\n details: 'Query execution failed.',\n errorMessage:\n error instanceof Error ? error.message : 'Unknown error',\n },\n };\n }\n },\n component: QueryToolResult,\n };\n}\n\n/**\n * Generates summary statistics for a SQL query result\n * @param connector - DuckDB connection instance\n * @param sqlQuery - SQL SELECT query to analyze\n * @returns Summary statistics as JSON object, or null if the query is not a SELECT statement or if summary generation fails\n */\nexport async function getQuerySummary(\n connector: DuckDbConnector,\n sqlQuery: string,\n abortSignal?: AbortSignal,\n) {\n if (!sqlQuery.toLowerCase().trim().startsWith('select')) {\n return null;\n }\n\n try {\n const summaryResult = await connector.query(\n `SUMMARIZE (\n ${sqlQuery}\n )`,\n {signal: abortSignal},\n );\n return arrowTableToJson(summaryResult);\n } catch (error) {\n console.warn('Failed to get summary for query. Error:', error);\n return null;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0-rc.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"sideEffects": false,
|
|
9
|
-
"author": "
|
|
9
|
+
"author": "SQLRooms Contributors",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
@@ -20,21 +20,14 @@
|
|
|
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.
|
|
30
|
-
"
|
|
31
|
-
"ai": "^5.0.44",
|
|
32
|
-
"immer": "^11.0.1",
|
|
33
|
-
"lucide-react": "^0.555.0",
|
|
34
|
-
"react-markdown": "^10.1.0",
|
|
35
|
-
"recharts": "^2.12.7",
|
|
36
|
-
"rehype-raw": "^7.0.0",
|
|
37
|
-
"remark-gfm": "^4.0.0",
|
|
23
|
+
"@sqlrooms/ai-config": "0.27.0-rc.0",
|
|
24
|
+
"@sqlrooms/ai-core": "0.27.0-rc.0",
|
|
25
|
+
"@sqlrooms/ai-settings": "0.27.0-rc.0",
|
|
26
|
+
"@sqlrooms/data-table": "0.27.0-rc.0",
|
|
27
|
+
"@sqlrooms/duckdb": "0.27.0-rc.0",
|
|
28
|
+
"@sqlrooms/room-shell": "0.27.0-rc.0",
|
|
29
|
+
"@sqlrooms/ui": "0.27.0-rc.0",
|
|
30
|
+
"lucide-react": "^0.556.0",
|
|
38
31
|
"zod": "^4.1.8"
|
|
39
32
|
},
|
|
40
33
|
"peerDependencies": {
|
|
@@ -49,5 +42,5 @@
|
|
|
49
42
|
"typecheck": "tsc --noEmit",
|
|
50
43
|
"typedoc": "typedoc"
|
|
51
44
|
},
|
|
52
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "ceafff23c197b8188040f8c93baf4e7d3dd4b081"
|
|
53
46
|
}
|