@querypanel/node-sdk 1.0.39 → 1.0.41
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/index.cjs +112 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -2
- package/dist/index.d.ts +117 -2
- package/dist/index.js +100 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -179,6 +179,7 @@ interface SdkChart {
|
|
|
179
179
|
sql: string;
|
|
180
180
|
sql_params: Record<string, unknown> | null;
|
|
181
181
|
vega_lite_spec: Record<string, unknown>;
|
|
182
|
+
spec_type?: 'vega-lite' | 'vizspec';
|
|
182
183
|
query_id: string | null;
|
|
183
184
|
organization_id: string | null;
|
|
184
185
|
tenant_id: string | null;
|
|
@@ -194,6 +195,7 @@ interface ChartCreateInput {
|
|
|
194
195
|
sql: string;
|
|
195
196
|
sql_params?: Record<string, unknown>;
|
|
196
197
|
vega_lite_spec: Record<string, unknown>;
|
|
198
|
+
spec_type?: 'vega-lite' | 'vizspec';
|
|
197
199
|
query_id?: string;
|
|
198
200
|
target_db?: string;
|
|
199
201
|
}
|
|
@@ -203,6 +205,7 @@ interface ChartUpdateInput {
|
|
|
203
205
|
sql?: string;
|
|
204
206
|
sql_params?: Record<string, unknown>;
|
|
205
207
|
vega_lite_spec?: Record<string, unknown>;
|
|
208
|
+
spec_type?: 'vega-lite' | 'vizspec';
|
|
206
209
|
target_db?: string;
|
|
207
210
|
}
|
|
208
211
|
interface PaginationQuery {
|
|
@@ -281,6 +284,94 @@ interface SchemaSyncOptions {
|
|
|
281
284
|
forceReindex?: boolean;
|
|
282
285
|
}
|
|
283
286
|
|
|
287
|
+
/**
|
|
288
|
+
* VizSpec types for flexible visualization specifications
|
|
289
|
+
* Supports chart, table, and metric visualizations
|
|
290
|
+
*/
|
|
291
|
+
type FieldType = 'quantitative' | 'temporal' | 'ordinal' | 'nominal' | 'boolean';
|
|
292
|
+
interface ValueFormat {
|
|
293
|
+
style?: 'number' | 'currency' | 'percent' | 'date' | 'time' | 'datetime';
|
|
294
|
+
currency?: string;
|
|
295
|
+
minimumFractionDigits?: number;
|
|
296
|
+
maximumFractionDigits?: number;
|
|
297
|
+
dateStyle?: 'short' | 'medium' | 'long';
|
|
298
|
+
}
|
|
299
|
+
interface FieldRef {
|
|
300
|
+
field: string;
|
|
301
|
+
label?: string;
|
|
302
|
+
type?: FieldType;
|
|
303
|
+
format?: ValueFormat;
|
|
304
|
+
}
|
|
305
|
+
type AggregateOp = 'sum' | 'avg' | 'min' | 'max' | 'count' | 'distinct';
|
|
306
|
+
type TimeUnit = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute';
|
|
307
|
+
interface AxisField extends FieldRef {
|
|
308
|
+
aggregate?: AggregateOp;
|
|
309
|
+
timeUnit?: TimeUnit;
|
|
310
|
+
}
|
|
311
|
+
interface MetricField extends FieldRef {
|
|
312
|
+
aggregate?: AggregateOp;
|
|
313
|
+
}
|
|
314
|
+
interface SortSpec {
|
|
315
|
+
field: string;
|
|
316
|
+
direction?: 'asc' | 'desc';
|
|
317
|
+
}
|
|
318
|
+
interface VizSpecBase {
|
|
319
|
+
version: '1.0';
|
|
320
|
+
kind: 'chart' | 'table' | 'metric';
|
|
321
|
+
title?: string;
|
|
322
|
+
description?: string;
|
|
323
|
+
data: {
|
|
324
|
+
sourceId: string;
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
type ChartType = 'line' | 'bar' | 'area' | 'scatter' | 'pie';
|
|
328
|
+
type StackingMode = 'none' | 'stacked' | 'percent';
|
|
329
|
+
interface ChartEncoding {
|
|
330
|
+
chartType: ChartType;
|
|
331
|
+
x?: AxisField;
|
|
332
|
+
y?: AxisField | AxisField[];
|
|
333
|
+
series?: FieldRef;
|
|
334
|
+
stacking?: StackingMode;
|
|
335
|
+
sort?: SortSpec;
|
|
336
|
+
limit?: number;
|
|
337
|
+
tooltips?: FieldRef[];
|
|
338
|
+
}
|
|
339
|
+
interface ChartSpec extends VizSpecBase {
|
|
340
|
+
kind: 'chart';
|
|
341
|
+
encoding: ChartEncoding;
|
|
342
|
+
}
|
|
343
|
+
type TextAlign = 'left' | 'right' | 'center';
|
|
344
|
+
interface TableColumn extends FieldRef {
|
|
345
|
+
width?: number;
|
|
346
|
+
align?: TextAlign;
|
|
347
|
+
isHidden?: boolean;
|
|
348
|
+
}
|
|
349
|
+
interface TableEncoding {
|
|
350
|
+
columns: TableColumn[];
|
|
351
|
+
sort?: SortSpec;
|
|
352
|
+
limit?: number;
|
|
353
|
+
}
|
|
354
|
+
interface TableSpec extends VizSpecBase {
|
|
355
|
+
kind: 'table';
|
|
356
|
+
encoding: TableEncoding;
|
|
357
|
+
}
|
|
358
|
+
type ComparisonMode = 'delta' | 'deltaPercent' | 'ratio';
|
|
359
|
+
interface MetricTrend {
|
|
360
|
+
timeField: AxisField;
|
|
361
|
+
valueField: MetricField;
|
|
362
|
+
}
|
|
363
|
+
interface MetricEncoding {
|
|
364
|
+
valueField: MetricField;
|
|
365
|
+
comparisonField?: MetricField;
|
|
366
|
+
comparisonMode?: ComparisonMode;
|
|
367
|
+
trend?: MetricTrend;
|
|
368
|
+
}
|
|
369
|
+
interface MetricSpec extends VizSpecBase {
|
|
370
|
+
kind: 'metric';
|
|
371
|
+
encoding: MetricEncoding;
|
|
372
|
+
}
|
|
373
|
+
type VizSpec = ChartSpec | TableSpec | MetricSpec;
|
|
374
|
+
|
|
284
375
|
interface ContextDocument {
|
|
285
376
|
source?: string;
|
|
286
377
|
pageContent: string;
|
|
@@ -288,7 +379,9 @@ interface ContextDocument {
|
|
|
288
379
|
score?: number;
|
|
289
380
|
}
|
|
290
381
|
interface ChartEnvelope {
|
|
291
|
-
vegaLiteSpec
|
|
382
|
+
vegaLiteSpec?: Record<string, unknown> | null;
|
|
383
|
+
vizSpec?: VizSpec | null;
|
|
384
|
+
specType: 'vega-lite' | 'vizspec';
|
|
292
385
|
notes: string | null;
|
|
293
386
|
}
|
|
294
387
|
interface AskOptions {
|
|
@@ -300,6 +393,7 @@ interface AskOptions {
|
|
|
300
393
|
previousSql?: string;
|
|
301
394
|
maxRetry?: number;
|
|
302
395
|
chartMaxRetries?: number;
|
|
396
|
+
chartType?: 'vega-lite' | 'vizspec';
|
|
303
397
|
}
|
|
304
398
|
interface AskResponse {
|
|
305
399
|
sql: string;
|
|
@@ -317,6 +411,26 @@ interface AskResponse {
|
|
|
317
411
|
}
|
|
318
412
|
declare function anonymizeResults(rows: Array<Record<string, unknown>>): Array<Record<string, string>>;
|
|
319
413
|
|
|
414
|
+
interface VizSpecGenerateInput {
|
|
415
|
+
question: string;
|
|
416
|
+
sql: string;
|
|
417
|
+
rationale?: string;
|
|
418
|
+
fields: string[];
|
|
419
|
+
rows: Array<Record<string, unknown>>;
|
|
420
|
+
max_retries?: number;
|
|
421
|
+
query_id?: string;
|
|
422
|
+
}
|
|
423
|
+
interface VizSpecGenerateOptions {
|
|
424
|
+
tenantId?: string;
|
|
425
|
+
userId?: string;
|
|
426
|
+
scopes?: string[];
|
|
427
|
+
maxRetries?: number;
|
|
428
|
+
}
|
|
429
|
+
interface VizSpecResponse {
|
|
430
|
+
spec: VizSpec;
|
|
431
|
+
notes: string | null;
|
|
432
|
+
}
|
|
433
|
+
|
|
320
434
|
/**
|
|
321
435
|
* Main SDK class - Thin orchestrator
|
|
322
436
|
* Delegates to deep modules (ApiClient, QueryEngine, route modules)
|
|
@@ -347,6 +461,7 @@ declare class QueryPanelSdkAPI {
|
|
|
347
461
|
introspect(databaseName: string, tables?: string[]): Promise<SchemaIntrospection>;
|
|
348
462
|
syncSchema(databaseName: string, options: SchemaSyncOptions, signal?: AbortSignal): Promise<IngestResponse>;
|
|
349
463
|
ask(question: string, options: AskOptions, signal?: AbortSignal): Promise<AskResponse>;
|
|
464
|
+
generateVizSpec(input: VizSpecGenerateInput, options?: VizSpecGenerateOptions, signal?: AbortSignal): Promise<VizSpecResponse>;
|
|
350
465
|
createChart(body: ChartCreateInput, options?: {
|
|
351
466
|
tenantId?: string;
|
|
352
467
|
userId?: string;
|
|
@@ -387,4 +502,4 @@ declare class QueryPanelSdkAPI {
|
|
|
387
502
|
}, signal?: AbortSignal): Promise<void>;
|
|
388
503
|
}
|
|
389
504
|
|
|
390
|
-
export { type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AskOptions, type AskResponse, type ChartCreateInput, type ChartEnvelope, type ChartListOptions, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DatabaseAdapter, type DatabaseDialect, type IngestResponse, type PaginatedResponse, type PaginationInfo, type PaginationQuery, type ParamRecord, type ParamValue, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryPanelSdkAPI, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, anonymizeResults };
|
|
505
|
+
export { type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AskOptions, type AskResponse, type AxisField, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListOptions, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DatabaseAdapter, type DatabaseDialect, type FieldRef, type FieldType, type IngestResponse, type MetricEncoding, type MetricField, type MetricSpec, type PaginatedResponse, type PaginationInfo, type PaginationQuery, type ParamRecord, type ParamValue, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryPanelSdkAPI, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, type TableColumn, type TableEncoding, type TableSpec, type VizSpec, type VizSpecGenerateInput, type VizSpecGenerateOptions, type VizSpecResponse, anonymizeResults };
|
package/dist/index.d.ts
CHANGED
|
@@ -179,6 +179,7 @@ interface SdkChart {
|
|
|
179
179
|
sql: string;
|
|
180
180
|
sql_params: Record<string, unknown> | null;
|
|
181
181
|
vega_lite_spec: Record<string, unknown>;
|
|
182
|
+
spec_type?: 'vega-lite' | 'vizspec';
|
|
182
183
|
query_id: string | null;
|
|
183
184
|
organization_id: string | null;
|
|
184
185
|
tenant_id: string | null;
|
|
@@ -194,6 +195,7 @@ interface ChartCreateInput {
|
|
|
194
195
|
sql: string;
|
|
195
196
|
sql_params?: Record<string, unknown>;
|
|
196
197
|
vega_lite_spec: Record<string, unknown>;
|
|
198
|
+
spec_type?: 'vega-lite' | 'vizspec';
|
|
197
199
|
query_id?: string;
|
|
198
200
|
target_db?: string;
|
|
199
201
|
}
|
|
@@ -203,6 +205,7 @@ interface ChartUpdateInput {
|
|
|
203
205
|
sql?: string;
|
|
204
206
|
sql_params?: Record<string, unknown>;
|
|
205
207
|
vega_lite_spec?: Record<string, unknown>;
|
|
208
|
+
spec_type?: 'vega-lite' | 'vizspec';
|
|
206
209
|
target_db?: string;
|
|
207
210
|
}
|
|
208
211
|
interface PaginationQuery {
|
|
@@ -281,6 +284,94 @@ interface SchemaSyncOptions {
|
|
|
281
284
|
forceReindex?: boolean;
|
|
282
285
|
}
|
|
283
286
|
|
|
287
|
+
/**
|
|
288
|
+
* VizSpec types for flexible visualization specifications
|
|
289
|
+
* Supports chart, table, and metric visualizations
|
|
290
|
+
*/
|
|
291
|
+
type FieldType = 'quantitative' | 'temporal' | 'ordinal' | 'nominal' | 'boolean';
|
|
292
|
+
interface ValueFormat {
|
|
293
|
+
style?: 'number' | 'currency' | 'percent' | 'date' | 'time' | 'datetime';
|
|
294
|
+
currency?: string;
|
|
295
|
+
minimumFractionDigits?: number;
|
|
296
|
+
maximumFractionDigits?: number;
|
|
297
|
+
dateStyle?: 'short' | 'medium' | 'long';
|
|
298
|
+
}
|
|
299
|
+
interface FieldRef {
|
|
300
|
+
field: string;
|
|
301
|
+
label?: string;
|
|
302
|
+
type?: FieldType;
|
|
303
|
+
format?: ValueFormat;
|
|
304
|
+
}
|
|
305
|
+
type AggregateOp = 'sum' | 'avg' | 'min' | 'max' | 'count' | 'distinct';
|
|
306
|
+
type TimeUnit = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute';
|
|
307
|
+
interface AxisField extends FieldRef {
|
|
308
|
+
aggregate?: AggregateOp;
|
|
309
|
+
timeUnit?: TimeUnit;
|
|
310
|
+
}
|
|
311
|
+
interface MetricField extends FieldRef {
|
|
312
|
+
aggregate?: AggregateOp;
|
|
313
|
+
}
|
|
314
|
+
interface SortSpec {
|
|
315
|
+
field: string;
|
|
316
|
+
direction?: 'asc' | 'desc';
|
|
317
|
+
}
|
|
318
|
+
interface VizSpecBase {
|
|
319
|
+
version: '1.0';
|
|
320
|
+
kind: 'chart' | 'table' | 'metric';
|
|
321
|
+
title?: string;
|
|
322
|
+
description?: string;
|
|
323
|
+
data: {
|
|
324
|
+
sourceId: string;
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
type ChartType = 'line' | 'bar' | 'area' | 'scatter' | 'pie';
|
|
328
|
+
type StackingMode = 'none' | 'stacked' | 'percent';
|
|
329
|
+
interface ChartEncoding {
|
|
330
|
+
chartType: ChartType;
|
|
331
|
+
x?: AxisField;
|
|
332
|
+
y?: AxisField | AxisField[];
|
|
333
|
+
series?: FieldRef;
|
|
334
|
+
stacking?: StackingMode;
|
|
335
|
+
sort?: SortSpec;
|
|
336
|
+
limit?: number;
|
|
337
|
+
tooltips?: FieldRef[];
|
|
338
|
+
}
|
|
339
|
+
interface ChartSpec extends VizSpecBase {
|
|
340
|
+
kind: 'chart';
|
|
341
|
+
encoding: ChartEncoding;
|
|
342
|
+
}
|
|
343
|
+
type TextAlign = 'left' | 'right' | 'center';
|
|
344
|
+
interface TableColumn extends FieldRef {
|
|
345
|
+
width?: number;
|
|
346
|
+
align?: TextAlign;
|
|
347
|
+
isHidden?: boolean;
|
|
348
|
+
}
|
|
349
|
+
interface TableEncoding {
|
|
350
|
+
columns: TableColumn[];
|
|
351
|
+
sort?: SortSpec;
|
|
352
|
+
limit?: number;
|
|
353
|
+
}
|
|
354
|
+
interface TableSpec extends VizSpecBase {
|
|
355
|
+
kind: 'table';
|
|
356
|
+
encoding: TableEncoding;
|
|
357
|
+
}
|
|
358
|
+
type ComparisonMode = 'delta' | 'deltaPercent' | 'ratio';
|
|
359
|
+
interface MetricTrend {
|
|
360
|
+
timeField: AxisField;
|
|
361
|
+
valueField: MetricField;
|
|
362
|
+
}
|
|
363
|
+
interface MetricEncoding {
|
|
364
|
+
valueField: MetricField;
|
|
365
|
+
comparisonField?: MetricField;
|
|
366
|
+
comparisonMode?: ComparisonMode;
|
|
367
|
+
trend?: MetricTrend;
|
|
368
|
+
}
|
|
369
|
+
interface MetricSpec extends VizSpecBase {
|
|
370
|
+
kind: 'metric';
|
|
371
|
+
encoding: MetricEncoding;
|
|
372
|
+
}
|
|
373
|
+
type VizSpec = ChartSpec | TableSpec | MetricSpec;
|
|
374
|
+
|
|
284
375
|
interface ContextDocument {
|
|
285
376
|
source?: string;
|
|
286
377
|
pageContent: string;
|
|
@@ -288,7 +379,9 @@ interface ContextDocument {
|
|
|
288
379
|
score?: number;
|
|
289
380
|
}
|
|
290
381
|
interface ChartEnvelope {
|
|
291
|
-
vegaLiteSpec
|
|
382
|
+
vegaLiteSpec?: Record<string, unknown> | null;
|
|
383
|
+
vizSpec?: VizSpec | null;
|
|
384
|
+
specType: 'vega-lite' | 'vizspec';
|
|
292
385
|
notes: string | null;
|
|
293
386
|
}
|
|
294
387
|
interface AskOptions {
|
|
@@ -300,6 +393,7 @@ interface AskOptions {
|
|
|
300
393
|
previousSql?: string;
|
|
301
394
|
maxRetry?: number;
|
|
302
395
|
chartMaxRetries?: number;
|
|
396
|
+
chartType?: 'vega-lite' | 'vizspec';
|
|
303
397
|
}
|
|
304
398
|
interface AskResponse {
|
|
305
399
|
sql: string;
|
|
@@ -317,6 +411,26 @@ interface AskResponse {
|
|
|
317
411
|
}
|
|
318
412
|
declare function anonymizeResults(rows: Array<Record<string, unknown>>): Array<Record<string, string>>;
|
|
319
413
|
|
|
414
|
+
interface VizSpecGenerateInput {
|
|
415
|
+
question: string;
|
|
416
|
+
sql: string;
|
|
417
|
+
rationale?: string;
|
|
418
|
+
fields: string[];
|
|
419
|
+
rows: Array<Record<string, unknown>>;
|
|
420
|
+
max_retries?: number;
|
|
421
|
+
query_id?: string;
|
|
422
|
+
}
|
|
423
|
+
interface VizSpecGenerateOptions {
|
|
424
|
+
tenantId?: string;
|
|
425
|
+
userId?: string;
|
|
426
|
+
scopes?: string[];
|
|
427
|
+
maxRetries?: number;
|
|
428
|
+
}
|
|
429
|
+
interface VizSpecResponse {
|
|
430
|
+
spec: VizSpec;
|
|
431
|
+
notes: string | null;
|
|
432
|
+
}
|
|
433
|
+
|
|
320
434
|
/**
|
|
321
435
|
* Main SDK class - Thin orchestrator
|
|
322
436
|
* Delegates to deep modules (ApiClient, QueryEngine, route modules)
|
|
@@ -347,6 +461,7 @@ declare class QueryPanelSdkAPI {
|
|
|
347
461
|
introspect(databaseName: string, tables?: string[]): Promise<SchemaIntrospection>;
|
|
348
462
|
syncSchema(databaseName: string, options: SchemaSyncOptions, signal?: AbortSignal): Promise<IngestResponse>;
|
|
349
463
|
ask(question: string, options: AskOptions, signal?: AbortSignal): Promise<AskResponse>;
|
|
464
|
+
generateVizSpec(input: VizSpecGenerateInput, options?: VizSpecGenerateOptions, signal?: AbortSignal): Promise<VizSpecResponse>;
|
|
350
465
|
createChart(body: ChartCreateInput, options?: {
|
|
351
466
|
tenantId?: string;
|
|
352
467
|
userId?: string;
|
|
@@ -387,4 +502,4 @@ declare class QueryPanelSdkAPI {
|
|
|
387
502
|
}, signal?: AbortSignal): Promise<void>;
|
|
388
503
|
}
|
|
389
504
|
|
|
390
|
-
export { type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AskOptions, type AskResponse, type ChartCreateInput, type ChartEnvelope, type ChartListOptions, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DatabaseAdapter, type DatabaseDialect, type IngestResponse, type PaginatedResponse, type PaginationInfo, type PaginationQuery, type ParamRecord, type ParamValue, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryPanelSdkAPI, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, anonymizeResults };
|
|
505
|
+
export { type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AskOptions, type AskResponse, type AxisField, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListOptions, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DatabaseAdapter, type DatabaseDialect, type FieldRef, type FieldType, type IngestResponse, type MetricEncoding, type MetricField, type MetricSpec, type PaginatedResponse, type PaginationInfo, type PaginationQuery, type ParamRecord, type ParamValue, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryPanelSdkAPI, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, type TableColumn, type TableEncoding, type TableSpec, type VizSpec, type VizSpecGenerateInput, type VizSpecGenerateOptions, type VizSpecResponse, anonymizeResults };
|
package/dist/index.js
CHANGED
|
@@ -525,6 +525,7 @@ function sanitize2(value) {
|
|
|
525
525
|
}
|
|
526
526
|
|
|
527
527
|
// src/core/client.ts
|
|
528
|
+
import crypto from "crypto";
|
|
528
529
|
var ApiClient = class {
|
|
529
530
|
baseUrl;
|
|
530
531
|
privateKey;
|
|
@@ -1063,6 +1064,7 @@ function resolveTenantId2(client, tenantId) {
|
|
|
1063
1064
|
}
|
|
1064
1065
|
|
|
1065
1066
|
// src/routes/ingest.ts
|
|
1067
|
+
import crypto2 from "crypto";
|
|
1066
1068
|
async function syncSchema(client, queryEngine, databaseName, options, signal) {
|
|
1067
1069
|
const tenantId = resolveTenantId3(client, options.tenantId);
|
|
1068
1070
|
const adapter = queryEngine.getDatabase(databaseName);
|
|
@@ -1074,7 +1076,7 @@ async function syncSchema(client, queryEngine, databaseName, options, signal) {
|
|
|
1074
1076
|
if (options.forceReindex) {
|
|
1075
1077
|
payload.force_reindex = true;
|
|
1076
1078
|
}
|
|
1077
|
-
const sessionId =
|
|
1079
|
+
const sessionId = crypto2.randomUUID();
|
|
1078
1080
|
const response = await client.post(
|
|
1079
1081
|
"/ingest",
|
|
1080
1082
|
payload,
|
|
@@ -1123,9 +1125,10 @@ function buildSchemaRequest(databaseName, adapter, introspection, metadata) {
|
|
|
1123
1125
|
}
|
|
1124
1126
|
|
|
1125
1127
|
// src/routes/query.ts
|
|
1128
|
+
import crypto3 from "crypto";
|
|
1126
1129
|
async function ask(client, queryEngine, question, options, signal) {
|
|
1127
1130
|
const tenantId = resolveTenantId4(client, options.tenantId);
|
|
1128
|
-
const sessionId =
|
|
1131
|
+
const sessionId = crypto3.randomUUID();
|
|
1129
1132
|
const maxRetry = options.maxRetry ?? 0;
|
|
1130
1133
|
let attempt = 0;
|
|
1131
1134
|
let lastError = options.lastError;
|
|
@@ -1162,35 +1165,62 @@ async function ask(client, queryEngine, question, options, signal) {
|
|
|
1162
1165
|
tenantId
|
|
1163
1166
|
);
|
|
1164
1167
|
const rows = execution.rows ?? [];
|
|
1168
|
+
const chartType = options.chartType ?? "vega-lite";
|
|
1165
1169
|
let chart = {
|
|
1166
|
-
|
|
1170
|
+
specType: chartType,
|
|
1167
1171
|
notes: rows.length === 0 ? "Query returned no rows." : null
|
|
1168
1172
|
};
|
|
1169
1173
|
if (rows.length > 0) {
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
}
|
|
1174
|
+
if (chartType === "vizspec") {
|
|
1175
|
+
const vizspecResponse = await client.post(
|
|
1176
|
+
"/vizspec",
|
|
1177
|
+
{
|
|
1178
|
+
question,
|
|
1179
|
+
sql: queryResponse.sql,
|
|
1180
|
+
rationale: queryResponse.rationale,
|
|
1181
|
+
fields: execution.fields,
|
|
1182
|
+
rows: anonymizeResults(rows),
|
|
1183
|
+
max_retries: options.chartMaxRetries ?? 3,
|
|
1184
|
+
query_id: queryResponse.queryId
|
|
1185
|
+
},
|
|
1186
|
+
tenantId,
|
|
1187
|
+
options.userId,
|
|
1188
|
+
options.scopes,
|
|
1189
|
+
signal,
|
|
1190
|
+
sessionId
|
|
1191
|
+
);
|
|
1192
|
+
chart = {
|
|
1193
|
+
vizSpec: vizspecResponse.spec,
|
|
1194
|
+
specType: "vizspec",
|
|
1195
|
+
notes: vizspecResponse.notes
|
|
1196
|
+
};
|
|
1197
|
+
} else {
|
|
1198
|
+
const chartResponse = await client.post(
|
|
1199
|
+
"/chart",
|
|
1200
|
+
{
|
|
1201
|
+
question,
|
|
1202
|
+
sql: queryResponse.sql,
|
|
1203
|
+
rationale: queryResponse.rationale,
|
|
1204
|
+
fields: execution.fields,
|
|
1205
|
+
rows: anonymizeResults(rows),
|
|
1206
|
+
max_retries: options.chartMaxRetries ?? 3,
|
|
1207
|
+
query_id: queryResponse.queryId
|
|
1208
|
+
},
|
|
1209
|
+
tenantId,
|
|
1210
|
+
options.userId,
|
|
1211
|
+
options.scopes,
|
|
1212
|
+
signal,
|
|
1213
|
+
sessionId
|
|
1214
|
+
);
|
|
1215
|
+
chart = {
|
|
1216
|
+
vegaLiteSpec: chartResponse.chart ? {
|
|
1217
|
+
...chartResponse.chart,
|
|
1218
|
+
data: { values: rows }
|
|
1219
|
+
} : null,
|
|
1220
|
+
specType: "vega-lite",
|
|
1221
|
+
notes: chartResponse.notes
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1194
1224
|
}
|
|
1195
1225
|
return {
|
|
1196
1226
|
sql: queryResponse.sql,
|
|
@@ -1242,6 +1272,40 @@ function anonymizeResults(rows) {
|
|
|
1242
1272
|
});
|
|
1243
1273
|
}
|
|
1244
1274
|
|
|
1275
|
+
// src/routes/vizspec.ts
|
|
1276
|
+
import crypto4 from "crypto";
|
|
1277
|
+
async function generateVizSpec(client, input, options, signal) {
|
|
1278
|
+
const tenantId = resolveTenantId5(client, options?.tenantId);
|
|
1279
|
+
const sessionId = crypto4.randomUUID();
|
|
1280
|
+
const response = await client.post(
|
|
1281
|
+
"/vizspec",
|
|
1282
|
+
{
|
|
1283
|
+
question: input.question,
|
|
1284
|
+
sql: input.sql,
|
|
1285
|
+
rationale: input.rationale,
|
|
1286
|
+
fields: input.fields,
|
|
1287
|
+
rows: input.rows,
|
|
1288
|
+
max_retries: options?.maxRetries ?? input.max_retries ?? 3,
|
|
1289
|
+
query_id: input.query_id
|
|
1290
|
+
},
|
|
1291
|
+
tenantId,
|
|
1292
|
+
options?.userId,
|
|
1293
|
+
options?.scopes,
|
|
1294
|
+
signal,
|
|
1295
|
+
sessionId
|
|
1296
|
+
);
|
|
1297
|
+
return response;
|
|
1298
|
+
}
|
|
1299
|
+
function resolveTenantId5(client, tenantId) {
|
|
1300
|
+
const resolved = tenantId ?? client.getDefaultTenantId();
|
|
1301
|
+
if (!resolved) {
|
|
1302
|
+
throw new Error(
|
|
1303
|
+
"tenantId is required. Provide it per request or via defaultTenantId option."
|
|
1304
|
+
);
|
|
1305
|
+
}
|
|
1306
|
+
return resolved;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1245
1309
|
// src/index.ts
|
|
1246
1310
|
var QueryPanelSdkAPI = class {
|
|
1247
1311
|
client;
|
|
@@ -1307,6 +1371,15 @@ var QueryPanelSdkAPI = class {
|
|
|
1307
1371
|
signal
|
|
1308
1372
|
);
|
|
1309
1373
|
}
|
|
1374
|
+
// VizSpec generation
|
|
1375
|
+
async generateVizSpec(input, options, signal) {
|
|
1376
|
+
return await generateVizSpec(
|
|
1377
|
+
this.client,
|
|
1378
|
+
input,
|
|
1379
|
+
options,
|
|
1380
|
+
signal
|
|
1381
|
+
);
|
|
1382
|
+
}
|
|
1310
1383
|
// Chart CRUD operations
|
|
1311
1384
|
async createChart(body, options, signal) {
|
|
1312
1385
|
return await createChart(this.client, body, options, signal);
|