@querypanel/node-sdk 1.0.50 → 1.0.52

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.d.cts CHANGED
@@ -180,6 +180,7 @@ declare const QueryErrorCode: {
180
180
  readonly SQL_GENERATION_FAILED: "SQL_GENERATION_FAILED";
181
181
  readonly SQL_VALIDATION_FAILED: "SQL_VALIDATION_FAILED";
182
182
  readonly CONTEXT_RETRIEVAL_FAILED: "CONTEXT_RETRIEVAL_FAILED";
183
+ readonly CLARIFICATION_NEEDED: "CLARIFICATION_NEEDED";
183
184
  readonly INTERNAL_ERROR: "INTERNAL_ERROR";
184
185
  readonly AUTHENTICATION_REQUIRED: "AUTHENTICATION_REQUIRED";
185
186
  readonly VALIDATION_ERROR: "VALIDATION_ERROR";
@@ -208,6 +209,10 @@ declare class QueryPipelineError extends Error {
208
209
  * Check if this is any guardrail error (relevance or security)
209
210
  */
210
211
  isGuardrailError(): boolean;
212
+ /**
213
+ * Check if this is a clarification needed error (v2 pipeline)
214
+ */
215
+ isClarificationNeeded(): boolean;
211
216
  }
212
217
 
213
218
  type ParamValue = string | number | boolean | string[] | number[];
@@ -514,6 +519,40 @@ interface AskOptions {
514
519
  * Use this to reuse a previously returned session for follow-up prompts.
515
520
  */
516
521
  querypanelSessionId?: string;
522
+ /**
523
+ * Pipeline version to use for query generation.
524
+ * - "v1" (default): Original query pipeline
525
+ * - "v2": Improved pipeline with intent planning, hybrid retrieval, schema linking, and SQL reflection
526
+ */
527
+ pipeline?: "v1" | "v2";
528
+ }
529
+ /**
530
+ * Intent analysis result from the v2 pipeline.
531
+ */
532
+ interface IntentResult {
533
+ intent: string;
534
+ confidence: number;
535
+ plan: {
536
+ tables: string[];
537
+ operations: string[];
538
+ filters: string[];
539
+ orderBy?: string;
540
+ limit?: number;
541
+ };
542
+ ambiguities: Array<{
543
+ issue: string;
544
+ suggestion: string;
545
+ }>;
546
+ }
547
+ /**
548
+ * Pipeline execution trace with step-level timing.
549
+ */
550
+ interface PipelineTrace {
551
+ totalDurationMs: number;
552
+ steps: Array<{
553
+ step: string;
554
+ durationMs: number;
555
+ }>;
517
556
  }
518
557
  /**
519
558
  * Response returned after executing a query.
@@ -545,6 +584,10 @@ interface AskResponse {
545
584
  target_db?: string;
546
585
  /** QueryPanel session ID for follow-up queries. */
547
586
  querypanelSessionId?: string;
587
+ /** Intent analysis from v2 pipeline. */
588
+ intent?: IntentResult;
589
+ /** Pipeline execution trace from v2 pipeline. */
590
+ trace?: PipelineTrace;
548
591
  }
549
592
  declare function anonymizeResults(rows: Array<Record<string, unknown>>): Array<Record<string, string>>;
550
593
 
@@ -688,6 +731,12 @@ interface ChartModifyOptions {
688
731
  chartMaxRetries?: number;
689
732
  /** Chart generation method: 'vega-lite' or 'vizspec' */
690
733
  chartType?: "vega-lite" | "vizspec";
734
+ /**
735
+ * Pipeline version to use for SQL regeneration.
736
+ * - "v1" (default): Original query pipeline
737
+ * - "v2": Improved pipeline with intent planning, hybrid retrieval, schema linking, and SQL reflection
738
+ */
739
+ pipeline?: "v1" | "v2";
691
740
  }
692
741
  /**
693
742
  * Response from modifyChart(), extending AskResponse with modification metadata.
@@ -1283,4 +1332,4 @@ declare class QueryPanelSdkAPI {
1283
1332
  }, signal?: AbortSignal): Promise<void>;
1284
1333
  }
1285
1334
 
1286
- export { type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type EncodingHints, type FieldRef, type FieldRefInput, type FieldType, type IngestResponse, type MetricEncoding, type MetricField, type MetricSpec, type PaginatedResponse$1 as PaginatedResponse, type PaginationInfo$1 as PaginationInfo, type PaginationQuery$1 as PaginationQuery, type ParamRecord, type ParamValue, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryErrorCode, QueryErrorCode as QueryErrorCodeType, QueryPanelSdkAPI, QueryPipelineError, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, type SdkSession, type SdkSessionTurn, type SessionGetOptions, type SessionListOptions, type SessionUpdateInput, type SqlModifications, type StackingMode, type TableColumn, type TableEncoding, type TableSpec, type TimeUnit, type ValueFormat, type VizModifications, type VizSpec, type VizSpecGenerateInput, type VizSpecGenerateOptions, type VizSpecGeneratorInput, type VizSpecKind, type VizSpecResponse, type VizSpecResult, anonymizeResults };
1335
+ export { type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type EncodingHints, type FieldRef, type FieldRefInput, type FieldType, type IngestResponse, type IntentResult, type MetricEncoding, type MetricField, type MetricSpec, type PaginatedResponse$1 as PaginatedResponse, type PaginationInfo$1 as PaginationInfo, type PaginationQuery$1 as PaginationQuery, type ParamRecord, type ParamValue, type PipelineTrace, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryErrorCode, QueryErrorCode as QueryErrorCodeType, QueryPanelSdkAPI, QueryPipelineError, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, type SdkSession, type SdkSessionTurn, type SessionGetOptions, type SessionListOptions, type SessionUpdateInput, type SqlModifications, type StackingMode, type TableColumn, type TableEncoding, type TableSpec, type TimeUnit, type ValueFormat, type VizModifications, type VizSpec, type VizSpecGenerateInput, type VizSpecGenerateOptions, type VizSpecGeneratorInput, type VizSpecKind, type VizSpecResponse, type VizSpecResult, anonymizeResults };
package/dist/index.d.ts CHANGED
@@ -180,6 +180,7 @@ declare const QueryErrorCode: {
180
180
  readonly SQL_GENERATION_FAILED: "SQL_GENERATION_FAILED";
181
181
  readonly SQL_VALIDATION_FAILED: "SQL_VALIDATION_FAILED";
182
182
  readonly CONTEXT_RETRIEVAL_FAILED: "CONTEXT_RETRIEVAL_FAILED";
183
+ readonly CLARIFICATION_NEEDED: "CLARIFICATION_NEEDED";
183
184
  readonly INTERNAL_ERROR: "INTERNAL_ERROR";
184
185
  readonly AUTHENTICATION_REQUIRED: "AUTHENTICATION_REQUIRED";
185
186
  readonly VALIDATION_ERROR: "VALIDATION_ERROR";
@@ -208,6 +209,10 @@ declare class QueryPipelineError extends Error {
208
209
  * Check if this is any guardrail error (relevance or security)
209
210
  */
210
211
  isGuardrailError(): boolean;
212
+ /**
213
+ * Check if this is a clarification needed error (v2 pipeline)
214
+ */
215
+ isClarificationNeeded(): boolean;
211
216
  }
212
217
 
213
218
  type ParamValue = string | number | boolean | string[] | number[];
@@ -514,6 +519,40 @@ interface AskOptions {
514
519
  * Use this to reuse a previously returned session for follow-up prompts.
515
520
  */
516
521
  querypanelSessionId?: string;
522
+ /**
523
+ * Pipeline version to use for query generation.
524
+ * - "v1" (default): Original query pipeline
525
+ * - "v2": Improved pipeline with intent planning, hybrid retrieval, schema linking, and SQL reflection
526
+ */
527
+ pipeline?: "v1" | "v2";
528
+ }
529
+ /**
530
+ * Intent analysis result from the v2 pipeline.
531
+ */
532
+ interface IntentResult {
533
+ intent: string;
534
+ confidence: number;
535
+ plan: {
536
+ tables: string[];
537
+ operations: string[];
538
+ filters: string[];
539
+ orderBy?: string;
540
+ limit?: number;
541
+ };
542
+ ambiguities: Array<{
543
+ issue: string;
544
+ suggestion: string;
545
+ }>;
546
+ }
547
+ /**
548
+ * Pipeline execution trace with step-level timing.
549
+ */
550
+ interface PipelineTrace {
551
+ totalDurationMs: number;
552
+ steps: Array<{
553
+ step: string;
554
+ durationMs: number;
555
+ }>;
517
556
  }
518
557
  /**
519
558
  * Response returned after executing a query.
@@ -545,6 +584,10 @@ interface AskResponse {
545
584
  target_db?: string;
546
585
  /** QueryPanel session ID for follow-up queries. */
547
586
  querypanelSessionId?: string;
587
+ /** Intent analysis from v2 pipeline. */
588
+ intent?: IntentResult;
589
+ /** Pipeline execution trace from v2 pipeline. */
590
+ trace?: PipelineTrace;
548
591
  }
549
592
  declare function anonymizeResults(rows: Array<Record<string, unknown>>): Array<Record<string, string>>;
550
593
 
@@ -688,6 +731,12 @@ interface ChartModifyOptions {
688
731
  chartMaxRetries?: number;
689
732
  /** Chart generation method: 'vega-lite' or 'vizspec' */
690
733
  chartType?: "vega-lite" | "vizspec";
734
+ /**
735
+ * Pipeline version to use for SQL regeneration.
736
+ * - "v1" (default): Original query pipeline
737
+ * - "v2": Improved pipeline with intent planning, hybrid retrieval, schema linking, and SQL reflection
738
+ */
739
+ pipeline?: "v1" | "v2";
691
740
  }
692
741
  /**
693
742
  * Response from modifyChart(), extending AskResponse with modification metadata.
@@ -1283,4 +1332,4 @@ declare class QueryPanelSdkAPI {
1283
1332
  }, signal?: AbortSignal): Promise<void>;
1284
1333
  }
1285
1334
 
1286
- export { type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type EncodingHints, type FieldRef, type FieldRefInput, type FieldType, type IngestResponse, type MetricEncoding, type MetricField, type MetricSpec, type PaginatedResponse$1 as PaginatedResponse, type PaginationInfo$1 as PaginationInfo, type PaginationQuery$1 as PaginationQuery, type ParamRecord, type ParamValue, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryErrorCode, QueryErrorCode as QueryErrorCodeType, QueryPanelSdkAPI, QueryPipelineError, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, type SdkSession, type SdkSessionTurn, type SessionGetOptions, type SessionListOptions, type SessionUpdateInput, type SqlModifications, type StackingMode, type TableColumn, type TableEncoding, type TableSpec, type TimeUnit, type ValueFormat, type VizModifications, type VizSpec, type VizSpecGenerateInput, type VizSpecGenerateOptions, type VizSpecGeneratorInput, type VizSpecKind, type VizSpecResponse, type VizSpecResult, anonymizeResults };
1335
+ export { type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type EncodingHints, type FieldRef, type FieldRefInput, type FieldType, type IngestResponse, type IntentResult, type MetricEncoding, type MetricField, type MetricSpec, type PaginatedResponse$1 as PaginatedResponse, type PaginationInfo$1 as PaginationInfo, type PaginationQuery$1 as PaginationQuery, type ParamRecord, type ParamValue, type PipelineTrace, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryErrorCode, QueryErrorCode as QueryErrorCodeType, QueryPanelSdkAPI, QueryPipelineError, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, type SdkSession, type SdkSessionTurn, type SessionGetOptions, type SessionListOptions, type SessionUpdateInput, type SqlModifications, type StackingMode, type TableColumn, type TableEncoding, type TableSpec, type TimeUnit, type ValueFormat, type VizModifications, type VizSpec, type VizSpecGenerateInput, type VizSpecGenerateOptions, type VizSpecGeneratorInput, type VizSpecKind, type VizSpecResponse, type VizSpecResult, anonymizeResults };
package/dist/index.js CHANGED
@@ -888,6 +888,8 @@ var QueryErrorCode = {
888
888
  SQL_VALIDATION_FAILED: "SQL_VALIDATION_FAILED",
889
889
  // Context retrieval errors
890
890
  CONTEXT_RETRIEVAL_FAILED: "CONTEXT_RETRIEVAL_FAILED",
891
+ // Clarification errors (v2)
892
+ CLARIFICATION_NEEDED: "CLARIFICATION_NEEDED",
891
893
  // General errors
892
894
  INTERNAL_ERROR: "INTERNAL_ERROR",
893
895
  AUTHENTICATION_REQUIRED: "AUTHENTICATION_REQUIRED",
@@ -924,6 +926,12 @@ var QueryPipelineError = class extends Error {
924
926
  isGuardrailError() {
925
927
  return this.isRelevanceError() || this.isSecurityError();
926
928
  }
929
+ /**
930
+ * Check if this is a clarification needed error (v2 pipeline)
931
+ */
932
+ isClarificationNeeded() {
933
+ return this.code === QueryErrorCode.CLARIFICATION_NEEDED;
934
+ }
927
935
  };
928
936
 
929
937
  // src/routes/charts.ts
@@ -1235,6 +1243,7 @@ async function ask(client, queryEngine, question, options, signal) {
1235
1243
  let attempt = 0;
1236
1244
  let lastError = options.lastError;
1237
1245
  let previousSql = options.previousSql;
1246
+ const queryEndpoint = options.pipeline === "v2" ? "/v2/query" : "/query";
1238
1247
  while (attempt <= maxRetry) {
1239
1248
  console.log({ lastError, previousSql });
1240
1249
  const databaseName = options.database ?? queryEngine.getDefaultDatabase();
@@ -1248,7 +1257,7 @@ async function ask(client, queryEngine, question, options, signal) {
1248
1257
  };
1249
1258
  }
1250
1259
  const queryResponse = await client.postWithHeaders(
1251
- "/query",
1260
+ queryEndpoint,
1252
1261
  {
1253
1262
  question,
1254
1263
  ...querypanelSessionId ? { session_id: querypanelSessionId } : {},
@@ -1364,7 +1373,9 @@ async function ask(client, queryEngine, question, options, signal) {
1364
1373
  context: queryResponse.data.context,
1365
1374
  attempts: attempt + 1,
1366
1375
  target_db: dbName,
1367
- querypanelSessionId: responseSessionId ?? void 0
1376
+ querypanelSessionId: responseSessionId ?? void 0,
1377
+ intent: queryResponse.data.intent,
1378
+ trace: queryResponse.data.trace
1368
1379
  };
1369
1380
  } catch (error) {
1370
1381
  attempt++;
@@ -1476,6 +1487,7 @@ async function modifyChart(client, queryEngine, input, options, signal) {
1476
1487
  const hasSqlMods = !!input.sqlModifications;
1477
1488
  const hasVizMods = !!input.vizModifications;
1478
1489
  const hasCustomSql = !!input.sqlModifications?.customSql;
1490
+ const queryEndpoint = options?.pipeline === "v2" ? "/v2/query" : "/query";
1479
1491
  let finalSql = input.sql;
1480
1492
  let finalParams = input.params ?? {};
1481
1493
  let paramMetadata = [];
@@ -1508,7 +1520,7 @@ async function modifyChart(client, queryEngine, input, options, signal) {
1508
1520
  input.sqlModifications
1509
1521
  );
1510
1522
  const queryResponse = await client.post(
1511
- "/query",
1523
+ queryEndpoint,
1512
1524
  {
1513
1525
  question: modifiedQuestion,
1514
1526
  previous_sql: input.sql,