@querypanel/node-sdk 1.2.6 → 1.2.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
@@ -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
@@ -338,10 +338,15 @@ var ClickHouseAdapter = class {
338
338
  return;
339
339
  }
340
340
  const allowedSet = new Set(this.allowedTables);
341
- const tablePattern = /(?:FROM|JOIN)\s+(?:FINAL\s+)?(?:(?:[a-zA-Z_][a-zA-Z0-9_]*)\.)?(["'`]?[a-zA-Z_][a-zA-Z0-9_]*["'`]?)/gi;
341
+ const tablePattern = /\b(FROM|JOIN)\s+(?:FINAL\s+)?(?:(?:[a-zA-Z_][a-zA-Z0-9_]*)\.)?(["'`]?[a-zA-Z_][a-zA-Z0-9_]*["'`]?)/gi;
342
342
  const matches = sql.matchAll(tablePattern);
343
343
  for (const match of matches) {
344
- const table = match[1]?.replace(/["'`]/g, "");
344
+ const clause = match[1]?.toUpperCase();
345
+ const matchIndex = match.index ?? -1;
346
+ if (clause === "JOIN" && matchIndex >= 0 && isArrayJoinClause(sql, matchIndex)) {
347
+ continue;
348
+ }
349
+ const table = match[2]?.replace(/["'`]/g, "");
345
350
  if (table) {
346
351
  if (!allowedSet.has(table)) {
347
352
  throw new Error(
@@ -409,6 +414,11 @@ function normalizeTableFilter2(tables) {
409
414
  }
410
415
  return normalized;
411
416
  }
417
+ function isArrayJoinClause(sql, joinIndex) {
418
+ const beforeJoin = sql.slice(0, joinIndex);
419
+ const previousToken = beforeJoin.trim().split(/\s+/).pop()?.toUpperCase();
420
+ return previousToken === "ARRAY";
421
+ }
412
422
  function transformColumnRow(row) {
413
423
  const unwrappedType = unwrapTypeModifiers(row.type);
414
424
  const column = {
@@ -1788,7 +1798,6 @@ async function ask(client, queryEngine, question, options, signal) {
1788
1798
  let previousSql = options.previousSql;
1789
1799
  const queryEndpoint = options.pipeline === "v2" ? "/v2/query" : "/query";
1790
1800
  while (attempt <= maxRetry) {
1791
- console.log({ lastError, previousSql });
1792
1801
  const databaseName = options.database ?? queryEngine.getDefaultDatabase();
1793
1802
  const metadata = databaseName ? queryEngine.getDatabaseMetadata(databaseName) : void 0;
1794
1803
  let tenantSettings;
@@ -1811,7 +1820,8 @@ async function ask(client, queryEngine, question, options, signal) {
1811
1820
  ...databaseName ? { database: databaseName } : {},
1812
1821
  ...metadata?.dialect ? { dialect: metadata.dialect } : {},
1813
1822
  ...options.model?.trim() ? { model: options.model.trim() } : {},
1814
- ...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
1815
1825
  },
1816
1826
  tenantId,
1817
1827
  options.userId,
@@ -1932,9 +1942,14 @@ async function ask(client, queryEngine, question, options, signal) {
1932
1942
  }
1933
1943
  lastError = error instanceof Error ? error.message : String(error);
1934
1944
  previousSql = queryResponse.data.sql ?? previousSql;
1935
- console.warn(
1936
- `SQL execution failed (attempt ${attempt}/${maxRetry + 1}): ${lastError}. Retrying...`
1937
- );
1945
+ console.warn("SQL execution failed, retrying query generation", {
1946
+ attempt,
1947
+ maxAttempts: maxRetry + 1,
1948
+ error: lastError,
1949
+ sql: queryResponse.data.sql ?? null,
1950
+ paramMetadata,
1951
+ params: paramValues
1952
+ });
1938
1953
  }
1939
1954
  }
1940
1955
  throw new Error("Unexpected error in ask retry loop");
@@ -2160,7 +2175,8 @@ async function modifyChart(client, queryEngine, input, options, signal) {
2160
2175
  ...options?.maxRetry ? { max_retry: options.maxRetry } : {},
2161
2176
  ...tenantSettings ? { tenant_settings: tenantSettings } : {},
2162
2177
  ...databaseName ? { database: databaseName } : {},
2163
- ...metadata?.dialect ? { dialect: metadata.dialect } : {}
2178
+ ...metadata?.dialect ? { dialect: metadata.dialect } : {},
2179
+ debug: options?.debug ?? false
2164
2180
  },
2165
2181
  tenantId,
2166
2182
  options?.userId,
@@ -2541,7 +2557,7 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2541
2557
  * It handles the complete flow: SQL generation → validation → execution → chart generation.
2542
2558
  *
2543
2559
  * @param question - Natural language question (e.g., "Show revenue by country")
2544
- * @param options - Query options including tenantId, database, and retry settings
2560
+ * @param options - Query options including tenantId, database, retry settings, and optional `debug` for engineer-style rationale
2545
2561
  * @param signal - Optional AbortSignal for cancellation
2546
2562
  * @returns Response with SQL, executed data rows, and generated chart
2547
2563
  * @throws {Error} When SQL generation or execution fails after all retries