@outsidedata/dolex 6.0.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/mcp/index.js +5 -5
- package/dist/src/mcp/index.js.map +1 -1
- package/dist/src/mcp/tools/drop-columns.d.ts.map +1 -1
- package/dist/src/mcp/tools/drop-columns.js +8 -21
- package/dist/src/mcp/tools/drop-columns.js.map +1 -1
- package/dist/src/mcp/tools/export-html.d.ts.map +1 -1
- package/dist/src/mcp/tools/export-html.js +10 -28
- package/dist/src/mcp/tools/export-html.js.map +1 -1
- package/dist/src/mcp/tools/list-transforms.d.ts.map +1 -1
- package/dist/src/mcp/tools/list-transforms.js +14 -29
- package/dist/src/mcp/tools/list-transforms.js.map +1 -1
- package/dist/src/mcp/tools/promote-columns.d.ts.map +1 -1
- package/dist/src/mcp/tools/promote-columns.js +8 -25
- package/dist/src/mcp/tools/promote-columns.js.map +1 -1
- package/dist/src/mcp/tools/refine-cli.d.ts.map +1 -1
- package/dist/src/mcp/tools/refine-cli.js +8 -39
- package/dist/src/mcp/tools/refine-cli.js.map +1 -1
- package/dist/src/mcp/tools/refine.d.ts.map +1 -1
- package/dist/src/mcp/tools/refine.js +1 -12
- package/dist/src/mcp/tools/refine.js.map +1 -1
- package/dist/src/mcp/tools/screenshot.d.ts.map +1 -1
- package/dist/src/mcp/tools/screenshot.js +4 -14
- package/dist/src/mcp/tools/screenshot.js.map +1 -1
- package/dist/src/mcp/tools/shared.d.ts +55 -1
- package/dist/src/mcp/tools/shared.d.ts.map +1 -1
- package/dist/src/mcp/tools/shared.js +89 -0
- package/dist/src/mcp/tools/shared.js.map +1 -1
- package/dist/src/mcp/tools/sources.d.ts +0 -3
- package/dist/src/mcp/tools/sources.d.ts.map +1 -1
- package/dist/src/mcp/tools/sources.js +59 -8
- package/dist/src/mcp/tools/sources.js.map +1 -1
- package/dist/src/mcp/tools/transform-data.d.ts.map +1 -1
- package/dist/src/mcp/tools/transform-data.js +11 -31
- package/dist/src/mcp/tools/transform-data.js.map +1 -1
- package/dist/src/mcp/tools/visualize-cli.d.ts.map +1 -1
- package/dist/src/mcp/tools/visualize-cli.js +23 -113
- package/dist/src/mcp/tools/visualize-cli.js.map +1 -1
- package/dist/src/mcp/tools/visualize.d.ts.map +1 -1
- package/dist/src/mcp/tools/visualize.js +13 -49
- package/dist/src/mcp/tools/visualize.js.map +1 -1
- package/package.json +1 -1
- package/src/mcp/index.ts +5 -5
- package/src/mcp/tools/drop-columns.ts +8 -21
- package/src/mcp/tools/export-html.ts +9 -26
- package/src/mcp/tools/list-transforms.ts +14 -31
- package/src/mcp/tools/promote-columns.ts +7 -28
- package/src/mcp/tools/refine-cli.ts +7 -41
- package/src/mcp/tools/refine.ts +1 -14
- package/src/mcp/tools/screenshot.ts +4 -13
- package/src/mcp/tools/shared.ts +127 -0
- package/src/mcp/tools/sources.ts +56 -12
- package/src/mcp/tools/transform-data.ts +24 -47
- package/src/mcp/tools/visualize-cli.ts +27 -123
- package/src/mcp/tools/visualize.ts +16 -54
|
@@ -10,18 +10,13 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { z } from 'zod';
|
|
13
|
-
import {
|
|
14
|
-
import { dirname } from 'path';
|
|
15
|
-
import type { VisualizeInput, VisualizeOutput, DataColumn, VisualizationSpec } from '../../types.js';
|
|
16
|
-
import { isCompoundSpec } from '../../types.js';
|
|
13
|
+
import type { VisualizeInput, VisualizeOutput } from '../../types.js';
|
|
17
14
|
import { ALL_PALETTE_NAMES } from './sql-schemas.js';
|
|
18
|
-
import { buildChartHtml, isHtmlPatternSupported } from '../../renderers/html/index.js';
|
|
19
|
-
import { shouldCompound, buildCompoundSpec } from '../../renderers/html/compound.js';
|
|
20
|
-
import { buildCompoundHtml } from '../../renderers/html/builders/compound.js';
|
|
21
|
-
import { specStore } from '../spec-store.js';
|
|
22
15
|
import { getResult } from './result-cache.js';
|
|
23
|
-
import {
|
|
24
|
-
|
|
16
|
+
import {
|
|
17
|
+
errorResponse, resolveData, isErrorResponse, writeHtmlToDisk,
|
|
18
|
+
} from './shared.js';
|
|
19
|
+
import { columnsSchema, dataShapeHintsSchema, handleVisualizeCore } from './visualize.js';
|
|
25
20
|
|
|
26
21
|
export const visualizeCliInputSchema = z.object({
|
|
27
22
|
data: z.array(z.record(z.any())).optional().describe('Array of data rows to visualize. Optional if resultId or sourceId+sql is provided.'),
|
|
@@ -53,126 +48,35 @@ export function handleVisualizeCli(
|
|
|
53
48
|
selectPatterns: (input: VisualizeInput) => VisualizeOutput,
|
|
54
49
|
deps?: { sourceManager?: any },
|
|
55
50
|
) {
|
|
56
|
-
|
|
57
|
-
let data = args.data;
|
|
58
|
-
let queryMeta: { truncated?: boolean; totalSourceRows?: number } | undefined;
|
|
59
|
-
|
|
60
|
-
// Path 1: sourceId + sql → server-side query
|
|
61
|
-
if (args.sourceId && args.sql) {
|
|
62
|
-
if (!deps?.sourceManager) {
|
|
63
|
-
return errorResponse('Source manager not available.');
|
|
64
|
-
}
|
|
65
|
-
const result = await deps.sourceManager.querySql(args.sourceId, args.sql);
|
|
66
|
-
if (!result.ok) {
|
|
67
|
-
return errorResponse(result.error);
|
|
68
|
-
}
|
|
69
|
-
data = result.rows;
|
|
70
|
-
queryMeta = { truncated: result.truncated, totalSourceRows: result.totalRows };
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Path 2: resultId → cached query result
|
|
74
|
-
if (!data && args.resultId) {
|
|
75
|
-
const cached = getResult(args.resultId);
|
|
76
|
-
if (!cached) {
|
|
77
|
-
return errorResponse(`Result "${args.resultId}" not found or expired. Re-run query_data to get a new resultId.`);
|
|
78
|
-
}
|
|
79
|
-
data = cached.rows;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (!data || data.length === 0) {
|
|
83
|
-
return errorResponse('No data provided. Pass data array, resultId from query_data, or sourceId + sql.');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const notes: string[] = [];
|
|
87
|
-
const columns = (args.columns as DataColumn[]) || inferColumns(data);
|
|
88
|
-
const maxAlternativeChartTypes = args.maxAlternativeChartTypes ?? 2;
|
|
89
|
-
|
|
90
|
-
const input: VisualizeInput = {
|
|
91
|
-
data,
|
|
92
|
-
intent: args.intent,
|
|
93
|
-
columns,
|
|
94
|
-
dataShapeHints: args.dataShapeHints,
|
|
95
|
-
forcePattern: args.pattern,
|
|
96
|
-
geoLevel: args.geoLevel,
|
|
97
|
-
geoRegion: args.geoRegion,
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const result = selectPatterns(input);
|
|
101
|
-
const alternatives = result.alternatives.slice(0, maxAlternativeChartTypes);
|
|
51
|
+
const core = handleVisualizeCore(selectPatterns, 'visualize_cli_only');
|
|
102
52
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
finalSpec = compoundSpec;
|
|
122
|
-
} else if (hasHtmlBuilder) {
|
|
123
|
-
outputHtml = buildChartHtml(spec);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const alternativesMap = new Map<string, VisualizationSpec>();
|
|
127
|
-
for (const alt of alternatives) {
|
|
128
|
-
alternativesMap.set(alt.pattern, alt.spec);
|
|
129
|
-
}
|
|
130
|
-
const specId = specStore.save(finalSpec, columns, alternativesMap, data);
|
|
131
|
-
|
|
132
|
-
// Write HTML to disk
|
|
133
|
-
let writeResult: string;
|
|
134
|
-
if (outputHtml) {
|
|
135
|
-
try {
|
|
136
|
-
mkdirSync(dirname(args.writeTo), { recursive: true });
|
|
137
|
-
writeFileSync(args.writeTo, outputHtml, 'utf-8');
|
|
138
|
-
writeResult = `Wrote ${outputHtml.length} bytes to ${args.writeTo}`;
|
|
139
|
-
} catch (err) {
|
|
140
|
-
return errorResponse(`Failed to write to ${args.writeTo}: ${err instanceof Error ? err.message : String(err)}`);
|
|
141
|
-
}
|
|
53
|
+
return async (args: z.infer<typeof visualizeCliInputSchema>) => {
|
|
54
|
+
const resolved = await resolveData(args, { sourceManager: deps?.sourceManager, getResult });
|
|
55
|
+
if (isErrorResponse(resolved)) return resolved;
|
|
56
|
+
|
|
57
|
+
const coreResult = core(resolved.data, args, resolved.queryMeta, resolved.extraMeta);
|
|
58
|
+
|
|
59
|
+
// Extract the text response body and add write info
|
|
60
|
+
const textContent = coreResult.content.find((c: any) => c.type === 'text');
|
|
61
|
+
if (!textContent) return errorResponse('Unexpected error: no text content from core');
|
|
62
|
+
const body = JSON.parse(textContent.text);
|
|
63
|
+
|
|
64
|
+
// Write HTML to disk from structuredContent (if present)
|
|
65
|
+
const html = (coreResult as any).structuredContent?.html;
|
|
66
|
+
if (html) {
|
|
67
|
+
const writeResult = writeHtmlToDisk(html, args.writeTo);
|
|
68
|
+
if (!writeResult.ok) return errorResponse(writeResult.error);
|
|
69
|
+
body.writeTo = args.writeTo;
|
|
70
|
+
body.writeResult = writeResult.message;
|
|
142
71
|
} else {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const compactResponse: Record<string, any> = {
|
|
147
|
-
specId,
|
|
148
|
-
writeTo: args.writeTo,
|
|
149
|
-
writeResult,
|
|
150
|
-
...(notes.length > 0 ? { notes } : {}),
|
|
151
|
-
recommended: {
|
|
152
|
-
pattern: result.recommended.pattern,
|
|
153
|
-
title: spec.title,
|
|
154
|
-
reasoning: result.recommended.reasoning,
|
|
155
|
-
},
|
|
156
|
-
alternatives: alternatives.map(a => ({
|
|
157
|
-
pattern: a.pattern,
|
|
158
|
-
reasoning: a.reasoning,
|
|
159
|
-
})),
|
|
160
|
-
dataShape: {
|
|
161
|
-
rowCount: data.length,
|
|
162
|
-
columnCount: columns.length,
|
|
163
|
-
...(queryMeta?.truncated ? { truncated: true, totalSourceRows: queryMeta.totalSourceRows } : {}),
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
if (isCompoundSpec(finalSpec)) {
|
|
168
|
-
compactResponse.compound = true;
|
|
72
|
+
body.writeTo = args.writeTo;
|
|
73
|
+
body.writeResult = `No HTML builder for pattern "${body.recommended?.pattern}"`;
|
|
169
74
|
}
|
|
170
75
|
|
|
171
|
-
// CLI tools NEVER return structuredContent - just text
|
|
172
76
|
return {
|
|
173
77
|
content: [{
|
|
174
78
|
type: 'text' as const,
|
|
175
|
-
text: JSON.stringify(
|
|
79
|
+
text: JSON.stringify(body, null, 2),
|
|
176
80
|
}],
|
|
177
81
|
};
|
|
178
82
|
};
|
|
@@ -11,12 +11,14 @@ import { z } from 'zod';
|
|
|
11
11
|
import type { VisualizeInput, VisualizeOutput, DataColumn, VisualizationSpec } from '../../types.js';
|
|
12
12
|
import { isCompoundSpec } from '../../types.js';
|
|
13
13
|
import { ALL_PALETTE_NAMES } from './sql-schemas.js';
|
|
14
|
-
import {
|
|
14
|
+
import { isHtmlPatternSupported } from '../../renderers/html/index.js';
|
|
15
15
|
import { shouldCompound, buildCompoundSpec } from '../../renderers/html/compound.js';
|
|
16
|
-
import { buildCompoundHtml } from '../../renderers/html/builders/compound.js';
|
|
17
16
|
import { specStore } from '../spec-store.js';
|
|
18
17
|
import { getResult } from './result-cache.js';
|
|
19
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
errorResponse, inferColumns, applyColorPreferences, buildOutputHtml,
|
|
20
|
+
resolveData, isErrorResponse,
|
|
21
|
+
} from './shared.js';
|
|
20
22
|
import { logOperation } from './operation-log.js';
|
|
21
23
|
import type { OperationMeta } from './operation-log.js';
|
|
22
24
|
|
|
@@ -122,17 +124,12 @@ export function handleVisualizeCore(
|
|
|
122
124
|
const spec = result.recommended.spec;
|
|
123
125
|
if (args.title) spec.title = args.title;
|
|
124
126
|
if (args.subtitle) spec.config = { ...spec.config, subtitle: args.subtitle };
|
|
125
|
-
const hasHtmlBuilder = spec && isHtmlPatternSupported(spec.pattern);
|
|
126
127
|
|
|
127
|
-
let outputHtml: string | undefined;
|
|
128
128
|
let finalSpec: VisualizationSpec | import('../../types.js').CompoundVisualizationSpec = spec;
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
outputHtml = buildCompoundHtml(compoundSpec);
|
|
132
|
-
finalSpec = compoundSpec;
|
|
133
|
-
} else if (hasHtmlBuilder) {
|
|
134
|
-
outputHtml = buildChartHtml(spec);
|
|
129
|
+
if (isHtmlPatternSupported(spec.pattern) && shouldCompound(spec, { compound: args.includeDataTable })) {
|
|
130
|
+
finalSpec = buildCompoundSpec(spec, columns);
|
|
135
131
|
}
|
|
132
|
+
const outputHtml = buildOutputHtml(finalSpec);
|
|
136
133
|
|
|
137
134
|
const alternativesMap = new Map<string, VisualizationSpec>();
|
|
138
135
|
for (const alt of alternatives) {
|
|
@@ -213,55 +210,20 @@ export function handleVisualize(
|
|
|
213
210
|
const core = handleVisualizeCore(selectPatterns);
|
|
214
211
|
|
|
215
212
|
return async (args: z.infer<typeof visualizeInputSchema>) => {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
// Path 1: sourceId + sql → server-side query
|
|
221
|
-
if (args.sourceId && args.sql) {
|
|
222
|
-
if (!deps?.sourceManager) {
|
|
223
|
-
return errorResponse('Source manager not available.');
|
|
224
|
-
}
|
|
225
|
-
const start = Date.now();
|
|
226
|
-
const source = deps.sourceManager.get?.(args.sourceId);
|
|
227
|
-
const sourceType = source?.type;
|
|
228
|
-
|
|
229
|
-
const result = await deps.sourceManager.querySql(args.sourceId, args.sql);
|
|
230
|
-
if (!result.ok) {
|
|
213
|
+
const resolved = await resolveData(args, { sourceManager: deps?.sourceManager, getResult });
|
|
214
|
+
if (isErrorResponse(resolved)) {
|
|
215
|
+
if (args.sourceId && args.sql) {
|
|
231
216
|
logOperation({
|
|
232
217
|
toolName: 'visualize',
|
|
233
|
-
timestamp:
|
|
234
|
-
durationMs:
|
|
218
|
+
timestamp: Date.now(),
|
|
219
|
+
durationMs: 0,
|
|
235
220
|
success: false,
|
|
236
|
-
meta: {
|
|
237
|
-
sqlPreview: args.sql.slice(0, 200),
|
|
238
|
-
sourceType,
|
|
239
|
-
error: result.error,
|
|
240
|
-
},
|
|
221
|
+
meta: { sqlPreview: args.sql.slice(0, 200), error: 'Data resolution failed' },
|
|
241
222
|
});
|
|
242
|
-
return errorResponse(result.error);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
data = result.rows;
|
|
246
|
-
queryMeta = { truncated: result.truncated, totalSourceRows: result.totalRows };
|
|
247
|
-
extraMeta = { sqlPreview: args.sql.slice(0, 200), sourceType };
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Path 2: resultId → cached query result
|
|
251
|
-
if (!data && args.resultId) {
|
|
252
|
-
const cached = getResult(args.resultId);
|
|
253
|
-
if (!cached) {
|
|
254
|
-
return errorResponse(`Result "${args.resultId}" not found or expired. Re-run query_data to get a new resultId.`);
|
|
255
223
|
}
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Path 3: inline data (already in args.data)
|
|
260
|
-
|
|
261
|
-
if (!data || data.length === 0) {
|
|
262
|
-
return errorResponse('No data provided. Pass data array, resultId from query_data, or sourceId + sql.');
|
|
224
|
+
return resolved;
|
|
263
225
|
}
|
|
264
226
|
|
|
265
|
-
return core(data, args, queryMeta, extraMeta);
|
|
227
|
+
return core(resolved.data, args, resolved.queryMeta, resolved.extraMeta);
|
|
266
228
|
};
|
|
267
229
|
}
|