@querypanel/node-sdk 1.2.7 → 1.2.9

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
@@ -737,6 +737,11 @@ interface AskOptions {
737
737
  * Sent to `POST /vizspec` as `supported_chart_types`. Omitted allows all standard types.
738
738
  */
739
739
  supportedChartTypes?: ChartType[];
740
+ /**
741
+ * When true, rationale includes engineer-style schema detail (tables, columns).
742
+ * When false (default), rationale is client-safe for end users.
743
+ */
744
+ debug?: boolean;
740
745
  }
741
746
  /**
742
747
  * Intent analysis result from the v2 pipeline.
@@ -961,6 +966,11 @@ interface ChartModifyOptions {
961
966
  * Restrict VizSpec chart types for this call (merged with SDK default from constructor when omitted).
962
967
  */
963
968
  supportedChartTypes?: ChartType[];
969
+ /**
970
+ * When true, rationale includes engineer-style schema detail (tables, columns).
971
+ * When false (default), rationale is client-safe for end users.
972
+ */
973
+ debug?: boolean;
964
974
  }
965
975
  /**
966
976
  * Response from modifyChart(), extending AskResponse with modification metadata.
@@ -1233,7 +1243,7 @@ declare class QueryPanelSdkAPI {
1233
1243
  * It handles the complete flow: SQL generation → validation → execution → chart generation.
1234
1244
  *
1235
1245
  * @param question - Natural language question (e.g., "Show revenue by country")
1236
- * @param options - Query options including tenantId, database, and retry settings
1246
+ * @param options - Query options including tenantId, database, retry settings, and optional `debug` for engineer-style rationale
1237
1247
  * @param signal - Optional AbortSignal for cancellation
1238
1248
  * @returns Response with SQL, executed data rows, and generated chart
1239
1249
  * @throws {Error} When SQL generation or execution fails after all retries
package/dist/index.d.ts CHANGED
@@ -737,6 +737,11 @@ interface AskOptions {
737
737
  * Sent to `POST /vizspec` as `supported_chart_types`. Omitted allows all standard types.
738
738
  */
739
739
  supportedChartTypes?: ChartType[];
740
+ /**
741
+ * When true, rationale includes engineer-style schema detail (tables, columns).
742
+ * When false (default), rationale is client-safe for end users.
743
+ */
744
+ debug?: boolean;
740
745
  }
741
746
  /**
742
747
  * Intent analysis result from the v2 pipeline.
@@ -961,6 +966,11 @@ interface ChartModifyOptions {
961
966
  * Restrict VizSpec chart types for this call (merged with SDK default from constructor when omitted).
962
967
  */
963
968
  supportedChartTypes?: ChartType[];
969
+ /**
970
+ * When true, rationale includes engineer-style schema detail (tables, columns).
971
+ * When false (default), rationale is client-safe for end users.
972
+ */
973
+ debug?: boolean;
964
974
  }
965
975
  /**
966
976
  * Response from modifyChart(), extending AskResponse with modification metadata.
@@ -1233,7 +1243,7 @@ declare class QueryPanelSdkAPI {
1233
1243
  * It handles the complete flow: SQL generation → validation → execution → chart generation.
1234
1244
  *
1235
1245
  * @param question - Natural language question (e.g., "Show revenue by country")
1236
- * @param options - Query options including tenantId, database, and retry settings
1246
+ * @param options - Query options including tenantId, database, retry settings, and optional `debug` for engineer-style rationale
1237
1247
  * @param signal - Optional AbortSignal for cancellation
1238
1248
  * @returns Response with SQL, executed data rows, and generated chart
1239
1249
  * @throws {Error} When SQL generation or execution fails after all retries
package/dist/index.js CHANGED
@@ -1798,7 +1798,6 @@ async function ask(client, queryEngine, question, options, signal) {
1798
1798
  let previousSql = options.previousSql;
1799
1799
  const queryEndpoint = options.pipeline === "v2" ? "/v2/query" : "/query";
1800
1800
  while (attempt <= maxRetry) {
1801
- console.log({ lastError, previousSql });
1802
1801
  const databaseName = options.database ?? queryEngine.getDefaultDatabase();
1803
1802
  const metadata = databaseName ? queryEngine.getDatabaseMetadata(databaseName) : void 0;
1804
1803
  let tenantSettings;
@@ -1821,7 +1820,8 @@ async function ask(client, queryEngine, question, options, signal) {
1821
1820
  ...databaseName ? { database: databaseName } : {},
1822
1821
  ...metadata?.dialect ? { dialect: metadata.dialect } : {},
1823
1822
  ...options.model?.trim() ? { model: options.model.trim() } : {},
1824
- ...options.pipeline === "v2" && options.systemPrompt?.trim() ? { system_prompt: options.systemPrompt.trim() } : {}
1823
+ ...options.pipeline === "v2" && options.systemPrompt?.trim() ? { system_prompt: options.systemPrompt.trim() } : {},
1824
+ debug: options.debug ?? false
1825
1825
  },
1826
1826
  tenantId,
1827
1827
  options.userId,
@@ -1863,60 +1863,58 @@ async function ask(client, queryEngine, question, options, signal) {
1863
1863
  specType: chartType,
1864
1864
  notes: rows.length === 0 ? "Query returned no rows." : null
1865
1865
  };
1866
- if (rows.length > 0) {
1867
- if (chartType === "vizspec") {
1868
- const vizspecResponse = await client.post(
1869
- "/vizspec",
1870
- {
1871
- question,
1872
- sql,
1873
- rationale: queryResponse.data.rationale,
1874
- fields: execution.fields,
1875
- rows: anonymizeResults(rows),
1876
- max_retries: options.chartMaxRetries ?? 3,
1877
- query_id: queryResponse.data.queryId,
1878
- ...options.supportedChartTypes?.length ? {
1879
- supported_chart_types: options.supportedChartTypes
1880
- } : {}
1881
- },
1882
- tenantId,
1883
- options.userId,
1884
- options.scopes,
1885
- signal,
1886
- sessionId
1887
- );
1888
- chart = {
1889
- vizSpec: vizspecResponse.spec,
1890
- specType: "vizspec",
1891
- notes: vizspecResponse.notes
1892
- };
1893
- } else {
1894
- const chartResponse = await client.post(
1895
- "/chart",
1896
- {
1897
- question,
1898
- sql,
1899
- rationale: queryResponse.data.rationale,
1900
- fields: execution.fields,
1901
- rows: anonymizeResults(rows),
1902
- max_retries: options.chartMaxRetries ?? 3,
1903
- query_id: queryResponse.data.queryId
1904
- },
1905
- tenantId,
1906
- options.userId,
1907
- options.scopes,
1908
- signal,
1909
- sessionId
1910
- );
1911
- chart = {
1912
- vegaLiteSpec: chartResponse.chart ? {
1913
- ...chartResponse.chart,
1914
- data: { values: rows }
1915
- } : null,
1916
- specType: "vega-lite",
1917
- notes: chartResponse.notes
1918
- };
1919
- }
1866
+ if (chartType === "vizspec") {
1867
+ const vizspecResponse = await client.post(
1868
+ "/vizspec",
1869
+ {
1870
+ question,
1871
+ sql,
1872
+ rationale: queryResponse.data.rationale,
1873
+ fields: execution.fields,
1874
+ rows: anonymizeResults(rows),
1875
+ max_retries: options.chartMaxRetries ?? 3,
1876
+ query_id: queryResponse.data.queryId,
1877
+ ...options.supportedChartTypes?.length ? {
1878
+ supported_chart_types: options.supportedChartTypes
1879
+ } : {}
1880
+ },
1881
+ tenantId,
1882
+ options.userId,
1883
+ options.scopes,
1884
+ signal,
1885
+ sessionId
1886
+ );
1887
+ chart = {
1888
+ vizSpec: vizspecResponse.spec,
1889
+ specType: "vizspec",
1890
+ notes: rows.length === 0 ? vizspecResponse.notes ?? "Query returned no rows." : vizspecResponse.notes
1891
+ };
1892
+ } else {
1893
+ const chartResponse = await client.post(
1894
+ "/chart",
1895
+ {
1896
+ question,
1897
+ sql,
1898
+ rationale: queryResponse.data.rationale,
1899
+ fields: execution.fields,
1900
+ rows: anonymizeResults(rows),
1901
+ max_retries: options.chartMaxRetries ?? 3,
1902
+ query_id: queryResponse.data.queryId
1903
+ },
1904
+ tenantId,
1905
+ options.userId,
1906
+ options.scopes,
1907
+ signal,
1908
+ sessionId
1909
+ );
1910
+ chart = {
1911
+ vegaLiteSpec: chartResponse.chart ? {
1912
+ ...chartResponse.chart,
1913
+ data: { values: rows }
1914
+ } : null,
1915
+ specType: "vega-lite",
1916
+ notes: rows.length === 0 ? chartResponse.notes ?? "Query returned no rows." : chartResponse.notes
1917
+ };
1920
1918
  }
1921
1919
  return {
1922
1920
  sql,
@@ -1942,9 +1940,14 @@ async function ask(client, queryEngine, question, options, signal) {
1942
1940
  }
1943
1941
  lastError = error instanceof Error ? error.message : String(error);
1944
1942
  previousSql = queryResponse.data.sql ?? previousSql;
1945
- console.warn(
1946
- `SQL execution failed (attempt ${attempt}/${maxRetry + 1}): ${lastError}. Retrying...`
1947
- );
1943
+ console.warn("SQL execution failed, retrying query generation", {
1944
+ attempt,
1945
+ maxAttempts: maxRetry + 1,
1946
+ error: lastError,
1947
+ sql: queryResponse.data.sql ?? null,
1948
+ paramMetadata,
1949
+ params: paramValues
1950
+ });
1948
1951
  }
1949
1952
  }
1950
1953
  throw new Error("Unexpected error in ask retry loop");
@@ -2170,7 +2173,8 @@ async function modifyChart(client, queryEngine, input, options, signal) {
2170
2173
  ...options?.maxRetry ? { max_retry: options.maxRetry } : {},
2171
2174
  ...tenantSettings ? { tenant_settings: tenantSettings } : {},
2172
2175
  ...databaseName ? { database: databaseName } : {},
2173
- ...metadata?.dialect ? { dialect: metadata.dialect } : {}
2176
+ ...metadata?.dialect ? { dialect: metadata.dialect } : {},
2177
+ debug: options?.debug ?? false
2174
2178
  },
2175
2179
  tenantId,
2176
2180
  options?.userId,
@@ -2203,64 +2207,62 @@ async function modifyChart(client, queryEngine, input, options, signal) {
2203
2207
  specType: chartType,
2204
2208
  notes: rows.length === 0 ? "Query returned no rows." : null
2205
2209
  };
2206
- if (rows.length > 0) {
2207
- const vizHints = hasVizMods ? buildVizHints(input.vizModifications) : {};
2208
- const vizHintsForChart = chartType === "vizspec" ? vizHints : stripVizSpecOnlyHints(vizHints);
2209
- if (chartType === "vizspec") {
2210
- const vizspecResponse = await client.post(
2211
- "/vizspec",
2212
- {
2213
- question: finalQuestion,
2214
- sql: finalSql,
2215
- rationale,
2216
- fields: execution.fields,
2217
- rows: anonymizeResults(rows),
2218
- max_retries: options?.chartMaxRetries ?? 3,
2219
- query_id: queryId,
2220
- // Include viz hints for the chart generator
2221
- ...hasVizMods ? { encoding_hints: vizHintsForChart } : {},
2222
- ...options?.supportedChartTypes?.length ? { supported_chart_types: options.supportedChartTypes } : {}
2223
- },
2224
- tenantId,
2225
- options?.userId,
2226
- options?.scopes,
2227
- signal,
2228
- sessionId
2229
- );
2230
- chart = {
2231
- vizSpec: vizspecResponse.spec,
2232
- specType: "vizspec",
2233
- notes: vizspecResponse.notes
2234
- };
2235
- } else {
2236
- const chartResponse = await client.post(
2237
- "/chart",
2238
- {
2239
- question: finalQuestion,
2240
- sql: finalSql,
2241
- rationale,
2242
- fields: execution.fields,
2243
- rows: anonymizeResults(rows),
2244
- max_retries: options?.chartMaxRetries ?? 3,
2245
- query_id: queryId,
2246
- // Include viz hints for the chart generator
2247
- ...hasVizMods ? { encoding_hints: vizHintsForChart } : {}
2248
- },
2249
- tenantId,
2250
- options?.userId,
2251
- options?.scopes,
2252
- signal,
2253
- sessionId
2254
- );
2255
- chart = {
2256
- vegaLiteSpec: chartResponse.chart ? {
2257
- ...chartResponse.chart,
2258
- data: { values: rows }
2259
- } : null,
2260
- specType: "vega-lite",
2261
- notes: chartResponse.notes
2262
- };
2263
- }
2210
+ const vizHints = hasVizMods ? buildVizHints(input.vizModifications) : {};
2211
+ const vizHintsForChart = chartType === "vizspec" ? vizHints : stripVizSpecOnlyHints(vizHints);
2212
+ if (chartType === "vizspec") {
2213
+ const vizspecResponse = await client.post(
2214
+ "/vizspec",
2215
+ {
2216
+ question: finalQuestion,
2217
+ sql: finalSql,
2218
+ rationale,
2219
+ fields: execution.fields,
2220
+ rows: anonymizeResults(rows),
2221
+ max_retries: options?.chartMaxRetries ?? 3,
2222
+ query_id: queryId,
2223
+ // Include viz hints for the chart generator
2224
+ ...hasVizMods ? { encoding_hints: vizHintsForChart } : {},
2225
+ ...options?.supportedChartTypes?.length ? { supported_chart_types: options.supportedChartTypes } : {}
2226
+ },
2227
+ tenantId,
2228
+ options?.userId,
2229
+ options?.scopes,
2230
+ signal,
2231
+ sessionId
2232
+ );
2233
+ chart = {
2234
+ vizSpec: vizspecResponse.spec,
2235
+ specType: "vizspec",
2236
+ notes: rows.length === 0 ? vizspecResponse.notes ?? "Query returned no rows." : vizspecResponse.notes
2237
+ };
2238
+ } else {
2239
+ const chartResponse = await client.post(
2240
+ "/chart",
2241
+ {
2242
+ question: finalQuestion,
2243
+ sql: finalSql,
2244
+ rationale,
2245
+ fields: execution.fields,
2246
+ rows: anonymizeResults(rows),
2247
+ max_retries: options?.chartMaxRetries ?? 3,
2248
+ query_id: queryId,
2249
+ // Include viz hints for the chart generator
2250
+ ...hasVizMods ? { encoding_hints: vizHintsForChart } : {}
2251
+ },
2252
+ tenantId,
2253
+ options?.userId,
2254
+ options?.scopes,
2255
+ signal,
2256
+ sessionId
2257
+ );
2258
+ chart = {
2259
+ vegaLiteSpec: chartResponse.chart ? {
2260
+ ...chartResponse.chart,
2261
+ data: { values: rows }
2262
+ } : null,
2263
+ specType: "vega-lite",
2264
+ notes: rows.length === 0 ? chartResponse.notes ?? "Query returned no rows." : chartResponse.notes
2265
+ };
2264
2266
  }
2265
2267
  return {
2266
2268
  sql: finalSql,
@@ -2551,7 +2553,7 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2551
2553
  * It handles the complete flow: SQL generation → validation → execution → chart generation.
2552
2554
  *
2553
2555
  * @param question - Natural language question (e.g., "Show revenue by country")
2554
- * @param options - Query options including tenantId, database, and retry settings
2556
+ * @param options - Query options including tenantId, database, retry settings, and optional `debug` for engineer-style rationale
2555
2557
  * @param signal - Optional AbortSignal for cancellation
2556
2558
  * @returns Response with SQL, executed data rows, and generated chart
2557
2559
  * @throws {Error} When SQL generation or execution fails after all retries