@querypanel/node-sdk 1.3.6 → 1.3.8

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
@@ -702,7 +702,7 @@ interface SortSpec {
702
702
  }
703
703
  interface VizSpecBase {
704
704
  version: '1.0';
705
- kind: 'chart' | 'table' | 'metric';
705
+ kind: 'chart' | 'table' | 'metric' | 'map';
706
706
  title?: string;
707
707
  description?: string;
708
708
  data: {
@@ -758,13 +758,32 @@ interface MetricSpec extends VizSpecBase {
758
758
  kind: 'metric';
759
759
  encoding: MetricEncoding;
760
760
  }
761
- type VizSpec = ChartSpec | TableSpec | MetricSpec;
761
+ type MapLocationMode = 'place' | 'latlng';
762
+ interface MapLocation {
763
+ mode: MapLocationMode;
764
+ postalCodeField?: string | null;
765
+ cityField?: string | null;
766
+ latField?: string | null;
767
+ lngField?: string | null;
768
+ }
769
+ interface MapEncoding {
770
+ location: MapLocation;
771
+ country: string;
772
+ colorField?: string | null;
773
+ labelField?: string | null;
774
+ tooltips?: string[] | null;
775
+ }
776
+ interface MapSpec extends VizSpecBase {
777
+ kind: 'map';
778
+ encoding: MapEncoding;
779
+ }
780
+ type VizSpec = ChartSpec | TableSpec | MetricSpec | MapSpec;
762
781
  /**
763
782
  * Encoding hints for vizspec modifications.
764
783
  * These hints guide the LLM to generate specific visualization configurations.
765
784
  */
766
785
  interface EncodingHints {
767
- /** Preferred vizspec kind (chart, table, metric) */
786
+ /** Preferred vizspec kind. A map is chosen by the question ("show them on a map"), not by a hint. */
768
787
  kind?: 'chart' | 'table' | 'metric';
769
788
  /** Preferred chart type (bar, line, area, scatter, pie) */
770
789
  chartType?: ChartType;
@@ -848,6 +867,12 @@ interface AskOptions {
848
867
  previousSql?: string;
849
868
  /** Maximum number of retry attempts on execution failure. */
850
869
  maxRetry?: number;
870
+ /**
871
+ * Also retry (within `maxRetry`) when the query returns no rows, or one row of only zeros/NULLs
872
+ * (what `COUNT(*) ... WHERE status = 'approved'` returns when the data stores 'APPROVE').
873
+ * Only that fact is sent to QueryPanel, never rows or values. Default false.
874
+ */
875
+ retryOnEmptyResult?: boolean;
851
876
  /** Maximum number of retries for chart generation. */
852
877
  chartMaxRetries?: number;
853
878
  /** Choose chart generation method. */
@@ -1030,8 +1055,8 @@ interface SqlModifications {
1030
1055
  * These changes only affect how the chart is rendered.
1031
1056
  */
1032
1057
  interface VizModifications {
1033
- /** Change the VizSpec kind (chart, table, metric). Applies to vizspec only. */
1034
- kind?: VizSpecKind;
1058
+ /** Change the VizSpec kind (chart, table, metric; a map cannot be switched to or from). Applies to vizspec only. */
1059
+ kind?: Exclude<VizSpecKind, "map">;
1035
1060
  /** Change the chart type (line, bar, area, scatter, pie) */
1036
1061
  chartType?: ChartType;
1037
1062
  /** Configure the X axis field and settings */
@@ -1537,7 +1562,7 @@ declare class QueryPanelSdkAPI {
1537
1562
  * @param input - VizSpec generation input with question, SQL, and result data
1538
1563
  * @param options - Optional settings for tenant and retries
1539
1564
  * @param signal - Optional AbortSignal for cancellation
1540
- * @returns VizSpec specification for chart, table, or metric visualization
1565
+ * @returns VizSpec specification for chart, table, metric, or map visualization
1541
1566
  *
1542
1567
  * @example
1543
1568
  * ```typescript
@@ -2168,4 +2193,4 @@ declare class QueryPanelSdkAPI {
2168
2193
  }, signal?: AbortSignal): Promise<SdkDashboard[]>;
2169
2194
  }
2170
2195
 
2171
- export { ALL_VIZ_CHART_TYPES, type ActiveChartBulkGetResponse, type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, BigQueryAdapter, type BigQueryAdapterOptions, type BigQueryClientFn, type BigQueryQueryRequest, type BigQueryQueryResult, CallbackApiClient, type CatalogSchema, type CatalogTable, type CatalogTableType, type ChartBulkGetResponse, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListAllOptions, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DashboardCreateInput, type DashboardForkInput, type DashboardForkUpdateInput, type DashboardListOptions, type DashboardUpdateInput, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type EncodingHints, type FieldRef, type FieldRefInput, type FieldType, type IQueryPanelApi, type IngestResponse, type IntentResult, type ListTablesOptions, 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, type PostgresWireDialect, QueryErrorCode, QueryErrorCode as QueryErrorCodeType, QueryPanelSdkAPI, type QueryPanelSdkAPIOptions, QueryPipelineError, type RequestHandler, type RequestHandlerOptions, type RequestHandlerResult, type SchemaIngestBatchEmbedResponse, type SchemaIngestRequestOptions, type SchemaIntrospection, type SchemaSyncOptions, type SchemaSyncProgressEvent, SchemaTooLargeError, type SdkActiveChart, type SdkChart, type SdkDashboard, type SdkSession, type SdkSessionTurn, type SessionGetOptions, type SessionListOptions, type SessionUpdateInput, type SqlModifications, type StackingMode, type StageSchemaIngestOptions, type StageSchemaIngestResult, type SyncSchemaInBatchesOptions, 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, mapGeneratedParams, normalizeSqlParamsInput, resolveQueryPipeline };
2196
+ export { ALL_VIZ_CHART_TYPES, type ActiveChartBulkGetResponse, type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, BigQueryAdapter, type BigQueryAdapterOptions, type BigQueryClientFn, type BigQueryQueryRequest, type BigQueryQueryResult, CallbackApiClient, type CatalogSchema, type CatalogTable, type CatalogTableType, type ChartBulkGetResponse, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListAllOptions, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DashboardCreateInput, type DashboardForkInput, type DashboardForkUpdateInput, type DashboardListOptions, type DashboardUpdateInput, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type EncodingHints, type FieldRef, type FieldRefInput, type FieldType, type IQueryPanelApi, type IngestResponse, type IntentResult, type ListTablesOptions, type MapEncoding, type MapLocation, type MapLocationMode, type MapSpec, 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, type PostgresWireDialect, QueryErrorCode, QueryErrorCode as QueryErrorCodeType, QueryPanelSdkAPI, type QueryPanelSdkAPIOptions, QueryPipelineError, type RequestHandler, type RequestHandlerOptions, type RequestHandlerResult, type SchemaIngestBatchEmbedResponse, type SchemaIngestRequestOptions, type SchemaIntrospection, type SchemaSyncOptions, type SchemaSyncProgressEvent, SchemaTooLargeError, type SdkActiveChart, type SdkChart, type SdkDashboard, type SdkSession, type SdkSessionTurn, type SessionGetOptions, type SessionListOptions, type SessionUpdateInput, type SqlModifications, type StackingMode, type StageSchemaIngestOptions, type StageSchemaIngestResult, type SyncSchemaInBatchesOptions, 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, mapGeneratedParams, normalizeSqlParamsInput, resolveQueryPipeline };
package/dist/index.d.ts CHANGED
@@ -702,7 +702,7 @@ interface SortSpec {
702
702
  }
703
703
  interface VizSpecBase {
704
704
  version: '1.0';
705
- kind: 'chart' | 'table' | 'metric';
705
+ kind: 'chart' | 'table' | 'metric' | 'map';
706
706
  title?: string;
707
707
  description?: string;
708
708
  data: {
@@ -758,13 +758,32 @@ interface MetricSpec extends VizSpecBase {
758
758
  kind: 'metric';
759
759
  encoding: MetricEncoding;
760
760
  }
761
- type VizSpec = ChartSpec | TableSpec | MetricSpec;
761
+ type MapLocationMode = 'place' | 'latlng';
762
+ interface MapLocation {
763
+ mode: MapLocationMode;
764
+ postalCodeField?: string | null;
765
+ cityField?: string | null;
766
+ latField?: string | null;
767
+ lngField?: string | null;
768
+ }
769
+ interface MapEncoding {
770
+ location: MapLocation;
771
+ country: string;
772
+ colorField?: string | null;
773
+ labelField?: string | null;
774
+ tooltips?: string[] | null;
775
+ }
776
+ interface MapSpec extends VizSpecBase {
777
+ kind: 'map';
778
+ encoding: MapEncoding;
779
+ }
780
+ type VizSpec = ChartSpec | TableSpec | MetricSpec | MapSpec;
762
781
  /**
763
782
  * Encoding hints for vizspec modifications.
764
783
  * These hints guide the LLM to generate specific visualization configurations.
765
784
  */
766
785
  interface EncodingHints {
767
- /** Preferred vizspec kind (chart, table, metric) */
786
+ /** Preferred vizspec kind. A map is chosen by the question ("show them on a map"), not by a hint. */
768
787
  kind?: 'chart' | 'table' | 'metric';
769
788
  /** Preferred chart type (bar, line, area, scatter, pie) */
770
789
  chartType?: ChartType;
@@ -848,6 +867,12 @@ interface AskOptions {
848
867
  previousSql?: string;
849
868
  /** Maximum number of retry attempts on execution failure. */
850
869
  maxRetry?: number;
870
+ /**
871
+ * Also retry (within `maxRetry`) when the query returns no rows, or one row of only zeros/NULLs
872
+ * (what `COUNT(*) ... WHERE status = 'approved'` returns when the data stores 'APPROVE').
873
+ * Only that fact is sent to QueryPanel, never rows or values. Default false.
874
+ */
875
+ retryOnEmptyResult?: boolean;
851
876
  /** Maximum number of retries for chart generation. */
852
877
  chartMaxRetries?: number;
853
878
  /** Choose chart generation method. */
@@ -1030,8 +1055,8 @@ interface SqlModifications {
1030
1055
  * These changes only affect how the chart is rendered.
1031
1056
  */
1032
1057
  interface VizModifications {
1033
- /** Change the VizSpec kind (chart, table, metric). Applies to vizspec only. */
1034
- kind?: VizSpecKind;
1058
+ /** Change the VizSpec kind (chart, table, metric; a map cannot be switched to or from). Applies to vizspec only. */
1059
+ kind?: Exclude<VizSpecKind, "map">;
1035
1060
  /** Change the chart type (line, bar, area, scatter, pie) */
1036
1061
  chartType?: ChartType;
1037
1062
  /** Configure the X axis field and settings */
@@ -1537,7 +1562,7 @@ declare class QueryPanelSdkAPI {
1537
1562
  * @param input - VizSpec generation input with question, SQL, and result data
1538
1563
  * @param options - Optional settings for tenant and retries
1539
1564
  * @param signal - Optional AbortSignal for cancellation
1540
- * @returns VizSpec specification for chart, table, or metric visualization
1565
+ * @returns VizSpec specification for chart, table, metric, or map visualization
1541
1566
  *
1542
1567
  * @example
1543
1568
  * ```typescript
@@ -2168,4 +2193,4 @@ declare class QueryPanelSdkAPI {
2168
2193
  }, signal?: AbortSignal): Promise<SdkDashboard[]>;
2169
2194
  }
2170
2195
 
2171
- export { ALL_VIZ_CHART_TYPES, type ActiveChartBulkGetResponse, type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, BigQueryAdapter, type BigQueryAdapterOptions, type BigQueryClientFn, type BigQueryQueryRequest, type BigQueryQueryResult, CallbackApiClient, type CatalogSchema, type CatalogTable, type CatalogTableType, type ChartBulkGetResponse, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListAllOptions, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DashboardCreateInput, type DashboardForkInput, type DashboardForkUpdateInput, type DashboardListOptions, type DashboardUpdateInput, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type EncodingHints, type FieldRef, type FieldRefInput, type FieldType, type IQueryPanelApi, type IngestResponse, type IntentResult, type ListTablesOptions, 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, type PostgresWireDialect, QueryErrorCode, QueryErrorCode as QueryErrorCodeType, QueryPanelSdkAPI, type QueryPanelSdkAPIOptions, QueryPipelineError, type RequestHandler, type RequestHandlerOptions, type RequestHandlerResult, type SchemaIngestBatchEmbedResponse, type SchemaIngestRequestOptions, type SchemaIntrospection, type SchemaSyncOptions, type SchemaSyncProgressEvent, SchemaTooLargeError, type SdkActiveChart, type SdkChart, type SdkDashboard, type SdkSession, type SdkSessionTurn, type SessionGetOptions, type SessionListOptions, type SessionUpdateInput, type SqlModifications, type StackingMode, type StageSchemaIngestOptions, type StageSchemaIngestResult, type SyncSchemaInBatchesOptions, 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, mapGeneratedParams, normalizeSqlParamsInput, resolveQueryPipeline };
2196
+ export { ALL_VIZ_CHART_TYPES, type ActiveChartBulkGetResponse, type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, BigQueryAdapter, type BigQueryAdapterOptions, type BigQueryClientFn, type BigQueryQueryRequest, type BigQueryQueryResult, CallbackApiClient, type CatalogSchema, type CatalogTable, type CatalogTableType, type ChartBulkGetResponse, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListAllOptions, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DashboardCreateInput, type DashboardForkInput, type DashboardForkUpdateInput, type DashboardListOptions, type DashboardUpdateInput, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type EncodingHints, type FieldRef, type FieldRefInput, type FieldType, type IQueryPanelApi, type IngestResponse, type IntentResult, type ListTablesOptions, type MapEncoding, type MapLocation, type MapLocationMode, type MapSpec, 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, type PostgresWireDialect, QueryErrorCode, QueryErrorCode as QueryErrorCodeType, QueryPanelSdkAPI, type QueryPanelSdkAPIOptions, QueryPipelineError, type RequestHandler, type RequestHandlerOptions, type RequestHandlerResult, type SchemaIngestBatchEmbedResponse, type SchemaIngestRequestOptions, type SchemaIntrospection, type SchemaSyncOptions, type SchemaSyncProgressEvent, SchemaTooLargeError, type SdkActiveChart, type SdkChart, type SdkDashboard, type SdkSession, type SdkSessionTurn, type SessionGetOptions, type SessionListOptions, type SessionUpdateInput, type SqlModifications, type StackingMode, type StageSchemaIngestOptions, type StageSchemaIngestResult, type SyncSchemaInBatchesOptions, 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, mapGeneratedParams, normalizeSqlParamsInput, resolveQueryPipeline };
package/dist/index.js CHANGED
@@ -2444,6 +2444,15 @@ function resolveQueryPipeline(pipeline) {
2444
2444
  }
2445
2445
  return "v2";
2446
2446
  }
2447
+ var EMPTY_RESULT_ERROR = "The query ran but returned no rows (or only zero/NULL values). A filter value probably does not match how the data stores it (case, spelling, codes such as 'APPROVE' vs 'approved'), or a filter is narrower than the question. Check each filter value against the column's documented values and fix it; keep every filter the question asks for.";
2448
+ function isEmptyLikeResult(rows) {
2449
+ if (rows.length === 0) return true;
2450
+ if (rows.length > 1) return false;
2451
+ const row = rows[0];
2452
+ if (!row || typeof row !== "object") return false;
2453
+ const values = Object.values(row);
2454
+ return values.length > 0 && values.every((v) => v === null || v === 0 || v === "0" || v === 0n);
2455
+ }
2447
2456
  async function ask(client, queryEngine, question, options, signal) {
2448
2457
  const tenantId = resolveTenantId5(client, options.tenantId);
2449
2458
  const sessionId = crypto3.randomUUID();
@@ -2526,6 +2535,17 @@ async function ask(client, queryEngine, question, options, signal) {
2526
2535
  tenantId
2527
2536
  );
2528
2537
  const rows = execution.rows ?? [];
2538
+ if (options.retryOnEmptyResult && attempt < maxRetry && isEmptyLikeResult(rows)) {
2539
+ attempt++;
2540
+ lastError = EMPTY_RESULT_ERROR;
2541
+ previousSql = sql;
2542
+ console.warn("Query returned no data, retrying query generation", {
2543
+ attempt,
2544
+ maxAttempts: maxRetry + 1,
2545
+ sql
2546
+ });
2547
+ continue;
2548
+ }
2529
2549
  const chartType = options.chartType ?? "vega-lite";
2530
2550
  let chart = {
2531
2551
  specType: chartType,
@@ -3612,7 +3632,7 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
3612
3632
  * @param input - VizSpec generation input with question, SQL, and result data
3613
3633
  * @param options - Optional settings for tenant and retries
3614
3634
  * @param signal - Optional AbortSignal for cancellation
3615
- * @returns VizSpec specification for chart, table, or metric visualization
3635
+ * @returns VizSpec specification for chart, table, metric, or map visualization
3616
3636
  *
3617
3637
  * @example
3618
3638
  * ```typescript