@querypanel/node-sdk 1.0.53 → 1.0.55

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
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1465,17 +1464,11 @@ function buildModifiedQuestion(originalQuestion, modifications, pipeline) {
1465
1464
  const from = normalizeDateInput(modifications.dateRange.from);
1466
1465
  const to = normalizeDateInput(modifications.dateRange.to);
1467
1466
  if (from && to) {
1468
- hints.push(
1469
- `replace any existing date filters with exact date range from ${from} to ${to} (inclusive, do not add extra days)`
1470
- );
1467
+ hints.push(`change date range to ${from} through ${to}`);
1471
1468
  } else if (from) {
1472
- hints.push(
1473
- `replace any existing date filters with exact start date ${from} (do not shift this date)`
1474
- );
1469
+ hints.push(`change start date to ${from}`);
1475
1470
  } else if (to) {
1476
- hints.push(
1477
- `replace any existing date filters with exact end date ${to} (inclusive, do not add extra days)`
1478
- );
1471
+ hints.push(`change end date to ${to}`);
1479
1472
  }
1480
1473
  } else {
1481
1474
  const parts = [];
@@ -1496,6 +1489,9 @@ function buildModifiedQuestion(originalQuestion, modifications, pipeline) {
1496
1489
  if (hints.length === 0) {
1497
1490
  return originalQuestion;
1498
1491
  }
1492
+ if (pipeline === "v2") {
1493
+ return hints.join(", ");
1494
+ }
1499
1495
  return `${originalQuestion} (${hints.join(", ")})`;
1500
1496
  }
1501
1497
  var START_PARAM_KEY_REGEX = /(^|_)(start|from)(_|$)/i;
@@ -1591,9 +1587,6 @@ function stripVizSpecOnlyHints(hints) {
1591
1587
  const { kind: _kind, ...rest } = hints;
1592
1588
  return rest;
1593
1589
  }
1594
- function isDateRangeOnly(mods) {
1595
- return !!mods.dateRange && !mods.timeGranularity && !mods.additionalInstructions && !mods.customSql;
1596
- }
1597
1590
  function resolveTenantId5(client, tenantId) {
1598
1591
  const resolved = tenantId ?? client.getDefaultTenantId();
1599
1592
  if (!resolved) {
@@ -1606,6 +1599,7 @@ function resolveTenantId5(client, tenantId) {
1606
1599
  async function modifyChart(client, queryEngine, input, options, signal) {
1607
1600
  const tenantId = resolveTenantId5(client, options?.tenantId);
1608
1601
  const sessionId = import_node_crypto4.default.randomUUID();
1602
+ const querypanelSessionId = options?.querypanelSessionId ?? sessionId;
1609
1603
  const chartType = options?.chartType ?? "vega-lite";
1610
1604
  const hasSqlMods = !!input.sqlModifications;
1611
1605
  const hasVizMods = !!input.vizModifications;
@@ -1638,78 +1632,6 @@ async function modifyChart(client, queryEngine, input, options, signal) {
1638
1632
  finalParams = {};
1639
1633
  paramMetadata = [];
1640
1634
  sqlChanged = true;
1641
- } else if (hasSqlMods && options?.pipeline === "v2" && isDateRangeOnly(input.sqlModifications)) {
1642
- let usedFastPath = false;
1643
- try {
1644
- const rewriteResponse = await client.post(
1645
- "/v2/rewrite-datefilter",
1646
- {
1647
- previous_sql: input.sql,
1648
- previous_params: input.params ? Object.entries(input.params).map(([name, value]) => ({
1649
- name,
1650
- value
1651
- })) : [],
1652
- date_range: input.sqlModifications.dateRange,
1653
- question: input.question,
1654
- ...tenantSettings ? { tenant_settings: tenantSettings } : {},
1655
- ...databaseName ? { database: databaseName } : {},
1656
- ...metadata?.dialect ? { dialect: metadata.dialect } : {}
1657
- },
1658
- tenantId,
1659
- options?.userId,
1660
- options?.scopes,
1661
- signal,
1662
- sessionId
1663
- );
1664
- finalSql = rewriteResponse.sql;
1665
- paramMetadata = Array.isArray(rewriteResponse.params) ? rewriteResponse.params : [];
1666
- finalParams = queryEngine.mapGeneratedParams(paramMetadata);
1667
- applyDateRangeOverrides(
1668
- input.sqlModifications?.dateRange,
1669
- finalParams,
1670
- paramMetadata
1671
- );
1672
- rationale = rewriteResponse.rationale;
1673
- queryId = rewriteResponse.queryId;
1674
- sqlChanged = finalSql !== input.sql;
1675
- usedFastPath = true;
1676
- } catch {
1677
- }
1678
- if (!usedFastPath) {
1679
- const modifiedQuestion = buildModifiedQuestion(
1680
- input.question,
1681
- input.sqlModifications,
1682
- "v2"
1683
- );
1684
- finalQuestion = modifiedQuestion;
1685
- const queryResponse = await client.post(
1686
- queryEndpoint,
1687
- {
1688
- question: modifiedQuestion,
1689
- previous_sql: input.sql,
1690
- ...options?.maxRetry ? { max_retry: options.maxRetry } : {},
1691
- ...tenantSettings ? { tenant_settings: tenantSettings } : {},
1692
- ...databaseName ? { database: databaseName } : {},
1693
- ...metadata?.dialect ? { dialect: metadata.dialect } : {}
1694
- },
1695
- tenantId,
1696
- options?.userId,
1697
- options?.scopes,
1698
- signal,
1699
- sessionId
1700
- );
1701
- finalSql = queryResponse.sql;
1702
- paramMetadata = Array.isArray(queryResponse.params) ? queryResponse.params : [];
1703
- finalParams = queryEngine.mapGeneratedParams(paramMetadata);
1704
- applyDateRangeOverrides(
1705
- input.sqlModifications?.dateRange,
1706
- finalParams,
1707
- paramMetadata
1708
- );
1709
- rationale = queryResponse.rationale;
1710
- queryId = queryResponse.queryId;
1711
- sqlChanged = finalSql !== input.sql;
1712
- }
1713
1635
  } else if (hasSqlMods && !hasCustomSql) {
1714
1636
  const modifiedQuestion = buildModifiedQuestion(
1715
1637
  input.question,
@@ -1723,6 +1645,7 @@ async function modifyChart(client, queryEngine, input, options, signal) {
1723
1645
  queryEndpoint,
1724
1646
  {
1725
1647
  question: modifiedQuestion,
1648
+ session_id: querypanelSessionId,
1726
1649
  previous_sql: input.sql,
1727
1650
  ...options?.maxRetry ? { max_retry: options.maxRetry } : {},
1728
1651
  ...tenantSettings ? { tenant_settings: tenantSettings } : {},
@@ -1825,6 +1748,7 @@ async function modifyChart(client, queryEngine, input, options, signal) {
1825
1748
  rationale,
1826
1749
  dialect: metadata?.dialect ?? "unknown",
1827
1750
  queryId,
1751
+ querypanelSessionId,
1828
1752
  rows,
1829
1753
  fields: execution.fields,
1830
1754
  chart,