@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.cjs CHANGED
@@ -1842,7 +1842,6 @@ async function ask(client, queryEngine, question, options, signal) {
1842
1842
  let previousSql = options.previousSql;
1843
1843
  const queryEndpoint = options.pipeline === "v2" ? "/v2/query" : "/query";
1844
1844
  while (attempt <= maxRetry) {
1845
- console.log({ lastError, previousSql });
1846
1845
  const databaseName = options.database ?? queryEngine.getDefaultDatabase();
1847
1846
  const metadata = databaseName ? queryEngine.getDatabaseMetadata(databaseName) : void 0;
1848
1847
  let tenantSettings;
@@ -1865,7 +1864,8 @@ async function ask(client, queryEngine, question, options, signal) {
1865
1864
  ...databaseName ? { database: databaseName } : {},
1866
1865
  ...metadata?.dialect ? { dialect: metadata.dialect } : {},
1867
1866
  ...options.model?.trim() ? { model: options.model.trim() } : {},
1868
- ...options.pipeline === "v2" && options.systemPrompt?.trim() ? { system_prompt: options.systemPrompt.trim() } : {}
1867
+ ...options.pipeline === "v2" && options.systemPrompt?.trim() ? { system_prompt: options.systemPrompt.trim() } : {},
1868
+ debug: options.debug ?? false
1869
1869
  },
1870
1870
  tenantId,
1871
1871
  options.userId,
@@ -1907,60 +1907,58 @@ async function ask(client, queryEngine, question, options, signal) {
1907
1907
  specType: chartType,
1908
1908
  notes: rows.length === 0 ? "Query returned no rows." : null
1909
1909
  };
1910
- if (rows.length > 0) {
1911
- if (chartType === "vizspec") {
1912
- const vizspecResponse = await client.post(
1913
- "/vizspec",
1914
- {
1915
- question,
1916
- sql,
1917
- rationale: queryResponse.data.rationale,
1918
- fields: execution.fields,
1919
- rows: anonymizeResults(rows),
1920
- max_retries: options.chartMaxRetries ?? 3,
1921
- query_id: queryResponse.data.queryId,
1922
- ...options.supportedChartTypes?.length ? {
1923
- supported_chart_types: options.supportedChartTypes
1924
- } : {}
1925
- },
1926
- tenantId,
1927
- options.userId,
1928
- options.scopes,
1929
- signal,
1930
- sessionId
1931
- );
1932
- chart = {
1933
- vizSpec: vizspecResponse.spec,
1934
- specType: "vizspec",
1935
- notes: vizspecResponse.notes
1936
- };
1937
- } else {
1938
- const chartResponse = await client.post(
1939
- "/chart",
1940
- {
1941
- question,
1942
- sql,
1943
- rationale: queryResponse.data.rationale,
1944
- fields: execution.fields,
1945
- rows: anonymizeResults(rows),
1946
- max_retries: options.chartMaxRetries ?? 3,
1947
- query_id: queryResponse.data.queryId
1948
- },
1949
- tenantId,
1950
- options.userId,
1951
- options.scopes,
1952
- signal,
1953
- sessionId
1954
- );
1955
- chart = {
1956
- vegaLiteSpec: chartResponse.chart ? {
1957
- ...chartResponse.chart,
1958
- data: { values: rows }
1959
- } : null,
1960
- specType: "vega-lite",
1961
- notes: chartResponse.notes
1962
- };
1963
- }
1910
+ if (chartType === "vizspec") {
1911
+ const vizspecResponse = await client.post(
1912
+ "/vizspec",
1913
+ {
1914
+ question,
1915
+ sql,
1916
+ rationale: queryResponse.data.rationale,
1917
+ fields: execution.fields,
1918
+ rows: anonymizeResults(rows),
1919
+ max_retries: options.chartMaxRetries ?? 3,
1920
+ query_id: queryResponse.data.queryId,
1921
+ ...options.supportedChartTypes?.length ? {
1922
+ supported_chart_types: options.supportedChartTypes
1923
+ } : {}
1924
+ },
1925
+ tenantId,
1926
+ options.userId,
1927
+ options.scopes,
1928
+ signal,
1929
+ sessionId
1930
+ );
1931
+ chart = {
1932
+ vizSpec: vizspecResponse.spec,
1933
+ specType: "vizspec",
1934
+ notes: rows.length === 0 ? vizspecResponse.notes ?? "Query returned no rows." : vizspecResponse.notes
1935
+ };
1936
+ } else {
1937
+ const chartResponse = await client.post(
1938
+ "/chart",
1939
+ {
1940
+ question,
1941
+ sql,
1942
+ rationale: queryResponse.data.rationale,
1943
+ fields: execution.fields,
1944
+ rows: anonymizeResults(rows),
1945
+ max_retries: options.chartMaxRetries ?? 3,
1946
+ query_id: queryResponse.data.queryId
1947
+ },
1948
+ tenantId,
1949
+ options.userId,
1950
+ options.scopes,
1951
+ signal,
1952
+ sessionId
1953
+ );
1954
+ chart = {
1955
+ vegaLiteSpec: chartResponse.chart ? {
1956
+ ...chartResponse.chart,
1957
+ data: { values: rows }
1958
+ } : null,
1959
+ specType: "vega-lite",
1960
+ notes: rows.length === 0 ? chartResponse.notes ?? "Query returned no rows." : chartResponse.notes
1961
+ };
1964
1962
  }
1965
1963
  return {
1966
1964
  sql,
@@ -1986,9 +1984,14 @@ async function ask(client, queryEngine, question, options, signal) {
1986
1984
  }
1987
1985
  lastError = error instanceof Error ? error.message : String(error);
1988
1986
  previousSql = queryResponse.data.sql ?? previousSql;
1989
- console.warn(
1990
- `SQL execution failed (attempt ${attempt}/${maxRetry + 1}): ${lastError}. Retrying...`
1991
- );
1987
+ console.warn("SQL execution failed, retrying query generation", {
1988
+ attempt,
1989
+ maxAttempts: maxRetry + 1,
1990
+ error: lastError,
1991
+ sql: queryResponse.data.sql ?? null,
1992
+ paramMetadata,
1993
+ params: paramValues
1994
+ });
1992
1995
  }
1993
1996
  }
1994
1997
  throw new Error("Unexpected error in ask retry loop");
@@ -2214,7 +2217,8 @@ async function modifyChart(client, queryEngine, input, options, signal) {
2214
2217
  ...options?.maxRetry ? { max_retry: options.maxRetry } : {},
2215
2218
  ...tenantSettings ? { tenant_settings: tenantSettings } : {},
2216
2219
  ...databaseName ? { database: databaseName } : {},
2217
- ...metadata?.dialect ? { dialect: metadata.dialect } : {}
2220
+ ...metadata?.dialect ? { dialect: metadata.dialect } : {},
2221
+ debug: options?.debug ?? false
2218
2222
  },
2219
2223
  tenantId,
2220
2224
  options?.userId,
@@ -2247,64 +2251,62 @@ async function modifyChart(client, queryEngine, input, options, signal) {
2247
2251
  specType: chartType,
2248
2252
  notes: rows.length === 0 ? "Query returned no rows." : null
2249
2253
  };
2250
- if (rows.length > 0) {
2251
- const vizHints = hasVizMods ? buildVizHints(input.vizModifications) : {};
2252
- const vizHintsForChart = chartType === "vizspec" ? vizHints : stripVizSpecOnlyHints(vizHints);
2253
- if (chartType === "vizspec") {
2254
- const vizspecResponse = await client.post(
2255
- "/vizspec",
2256
- {
2257
- question: finalQuestion,
2258
- sql: finalSql,
2259
- rationale,
2260
- fields: execution.fields,
2261
- rows: anonymizeResults(rows),
2262
- max_retries: options?.chartMaxRetries ?? 3,
2263
- query_id: queryId,
2264
- // Include viz hints for the chart generator
2265
- ...hasVizMods ? { encoding_hints: vizHintsForChart } : {},
2266
- ...options?.supportedChartTypes?.length ? { supported_chart_types: options.supportedChartTypes } : {}
2267
- },
2268
- tenantId,
2269
- options?.userId,
2270
- options?.scopes,
2271
- signal,
2272
- sessionId
2273
- );
2274
- chart = {
2275
- vizSpec: vizspecResponse.spec,
2276
- specType: "vizspec",
2277
- notes: vizspecResponse.notes
2278
- };
2279
- } else {
2280
- const chartResponse = await client.post(
2281
- "/chart",
2282
- {
2283
- question: finalQuestion,
2284
- sql: finalSql,
2285
- rationale,
2286
- fields: execution.fields,
2287
- rows: anonymizeResults(rows),
2288
- max_retries: options?.chartMaxRetries ?? 3,
2289
- query_id: queryId,
2290
- // Include viz hints for the chart generator
2291
- ...hasVizMods ? { encoding_hints: vizHintsForChart } : {}
2292
- },
2293
- tenantId,
2294
- options?.userId,
2295
- options?.scopes,
2296
- signal,
2297
- sessionId
2298
- );
2299
- chart = {
2300
- vegaLiteSpec: chartResponse.chart ? {
2301
- ...chartResponse.chart,
2302
- data: { values: rows }
2303
- } : null,
2304
- specType: "vega-lite",
2305
- notes: chartResponse.notes
2306
- };
2307
- }
2254
+ const vizHints = hasVizMods ? buildVizHints(input.vizModifications) : {};
2255
+ const vizHintsForChart = chartType === "vizspec" ? vizHints : stripVizSpecOnlyHints(vizHints);
2256
+ if (chartType === "vizspec") {
2257
+ const vizspecResponse = await client.post(
2258
+ "/vizspec",
2259
+ {
2260
+ question: finalQuestion,
2261
+ sql: finalSql,
2262
+ rationale,
2263
+ fields: execution.fields,
2264
+ rows: anonymizeResults(rows),
2265
+ max_retries: options?.chartMaxRetries ?? 3,
2266
+ query_id: queryId,
2267
+ // Include viz hints for the chart generator
2268
+ ...hasVizMods ? { encoding_hints: vizHintsForChart } : {},
2269
+ ...options?.supportedChartTypes?.length ? { supported_chart_types: options.supportedChartTypes } : {}
2270
+ },
2271
+ tenantId,
2272
+ options?.userId,
2273
+ options?.scopes,
2274
+ signal,
2275
+ sessionId
2276
+ );
2277
+ chart = {
2278
+ vizSpec: vizspecResponse.spec,
2279
+ specType: "vizspec",
2280
+ notes: rows.length === 0 ? vizspecResponse.notes ?? "Query returned no rows." : vizspecResponse.notes
2281
+ };
2282
+ } else {
2283
+ const chartResponse = await client.post(
2284
+ "/chart",
2285
+ {
2286
+ question: finalQuestion,
2287
+ sql: finalSql,
2288
+ rationale,
2289
+ fields: execution.fields,
2290
+ rows: anonymizeResults(rows),
2291
+ max_retries: options?.chartMaxRetries ?? 3,
2292
+ query_id: queryId,
2293
+ // Include viz hints for the chart generator
2294
+ ...hasVizMods ? { encoding_hints: vizHintsForChart } : {}
2295
+ },
2296
+ tenantId,
2297
+ options?.userId,
2298
+ options?.scopes,
2299
+ signal,
2300
+ sessionId
2301
+ );
2302
+ chart = {
2303
+ vegaLiteSpec: chartResponse.chart ? {
2304
+ ...chartResponse.chart,
2305
+ data: { values: rows }
2306
+ } : null,
2307
+ specType: "vega-lite",
2308
+ notes: rows.length === 0 ? chartResponse.notes ?? "Query returned no rows." : chartResponse.notes
2309
+ };
2308
2310
  }
2309
2311
  return {
2310
2312
  sql: finalSql,
@@ -2595,7 +2597,7 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2595
2597
  * It handles the complete flow: SQL generation → validation → execution → chart generation.
2596
2598
  *
2597
2599
  * @param question - Natural language question (e.g., "Show revenue by country")
2598
- * @param options - Query options including tenantId, database, and retry settings
2600
+ * @param options - Query options including tenantId, database, retry settings, and optional `debug` for engineer-style rationale
2599
2601
  * @param signal - Optional AbortSignal for cancellation
2600
2602
  * @returns Response with SQL, executed data rows, and generated chart
2601
2603
  * @throws {Error} When SQL generation or execution fails after all retries