@querypanel/node-sdk 1.0.53 → 1.0.54

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
@@ -191,8 +191,8 @@ type QueryErrorCode = (typeof QueryErrorCode)[keyof typeof QueryErrorCode];
191
191
  */
192
192
  declare class QueryPipelineError extends Error {
193
193
  readonly code: QueryErrorCode;
194
- readonly details?: Record<string, unknown> | undefined;
195
- constructor(message: string, code: QueryErrorCode, details?: Record<string, unknown> | undefined);
194
+ readonly details?: Record<string, unknown>;
195
+ constructor(message: string, code: QueryErrorCode, details?: Record<string, unknown>);
196
196
  /**
197
197
  * Check if this is a moderation error
198
198
  */
@@ -737,6 +737,12 @@ interface ChartModifyOptions {
737
737
  * - "v2": Improved pipeline with intent planning, hybrid retrieval, schema linking, and SQL reflection
738
738
  */
739
739
  pipeline?: "v1" | "v2";
740
+ /**
741
+ * QueryPanel session ID for context-aware follow-ups.
742
+ * Pass the querypanelSessionId from a previous ask() response
743
+ * to preserve conversation history when modifying charts.
744
+ */
745
+ querypanelSessionId?: string;
740
746
  }
741
747
  /**
742
748
  * Response from modifyChart(), extending AskResponse with modification metadata.
package/dist/index.d.ts CHANGED
@@ -191,8 +191,8 @@ type QueryErrorCode = (typeof QueryErrorCode)[keyof typeof QueryErrorCode];
191
191
  */
192
192
  declare class QueryPipelineError extends Error {
193
193
  readonly code: QueryErrorCode;
194
- readonly details?: Record<string, unknown> | undefined;
195
- constructor(message: string, code: QueryErrorCode, details?: Record<string, unknown> | undefined);
194
+ readonly details?: Record<string, unknown>;
195
+ constructor(message: string, code: QueryErrorCode, details?: Record<string, unknown>);
196
196
  /**
197
197
  * Check if this is a moderation error
198
198
  */
@@ -737,6 +737,12 @@ interface ChartModifyOptions {
737
737
  * - "v2": Improved pipeline with intent planning, hybrid retrieval, schema linking, and SQL reflection
738
738
  */
739
739
  pipeline?: "v1" | "v2";
740
+ /**
741
+ * QueryPanel session ID for context-aware follow-ups.
742
+ * Pass the querypanelSessionId from a previous ask() response
743
+ * to preserve conversation history when modifying charts.
744
+ */
745
+ querypanelSessionId?: string;
740
746
  }
741
747
  /**
742
748
  * Response from modifyChart(), extending AskResponse with modification metadata.
package/dist/index.js CHANGED
@@ -1424,17 +1424,11 @@ function buildModifiedQuestion(originalQuestion, modifications, pipeline) {
1424
1424
  const from = normalizeDateInput(modifications.dateRange.from);
1425
1425
  const to = normalizeDateInput(modifications.dateRange.to);
1426
1426
  if (from && to) {
1427
- hints.push(
1428
- `replace any existing date filters with exact date range from ${from} to ${to} (inclusive, do not add extra days)`
1429
- );
1427
+ hints.push(`change date range to ${from} through ${to}`);
1430
1428
  } else if (from) {
1431
- hints.push(
1432
- `replace any existing date filters with exact start date ${from} (do not shift this date)`
1433
- );
1429
+ hints.push(`change start date to ${from}`);
1434
1430
  } else if (to) {
1435
- hints.push(
1436
- `replace any existing date filters with exact end date ${to} (inclusive, do not add extra days)`
1437
- );
1431
+ hints.push(`change end date to ${to}`);
1438
1432
  }
1439
1433
  } else {
1440
1434
  const parts = [];
@@ -1550,9 +1544,6 @@ function stripVizSpecOnlyHints(hints) {
1550
1544
  const { kind: _kind, ...rest } = hints;
1551
1545
  return rest;
1552
1546
  }
1553
- function isDateRangeOnly(mods) {
1554
- return !!mods.dateRange && !mods.timeGranularity && !mods.additionalInstructions && !mods.customSql;
1555
- }
1556
1547
  function resolveTenantId5(client, tenantId) {
1557
1548
  const resolved = tenantId ?? client.getDefaultTenantId();
1558
1549
  if (!resolved) {
@@ -1565,6 +1556,7 @@ function resolveTenantId5(client, tenantId) {
1565
1556
  async function modifyChart(client, queryEngine, input, options, signal) {
1566
1557
  const tenantId = resolveTenantId5(client, options?.tenantId);
1567
1558
  const sessionId = crypto4.randomUUID();
1559
+ const querypanelSessionId = options?.querypanelSessionId ?? sessionId;
1568
1560
  const chartType = options?.chartType ?? "vega-lite";
1569
1561
  const hasSqlMods = !!input.sqlModifications;
1570
1562
  const hasVizMods = !!input.vizModifications;
@@ -1597,78 +1589,6 @@ async function modifyChart(client, queryEngine, input, options, signal) {
1597
1589
  finalParams = {};
1598
1590
  paramMetadata = [];
1599
1591
  sqlChanged = true;
1600
- } else if (hasSqlMods && options?.pipeline === "v2" && isDateRangeOnly(input.sqlModifications)) {
1601
- let usedFastPath = false;
1602
- try {
1603
- const rewriteResponse = await client.post(
1604
- "/v2/rewrite-datefilter",
1605
- {
1606
- previous_sql: input.sql,
1607
- previous_params: input.params ? Object.entries(input.params).map(([name, value]) => ({
1608
- name,
1609
- value
1610
- })) : [],
1611
- date_range: input.sqlModifications.dateRange,
1612
- question: input.question,
1613
- ...tenantSettings ? { tenant_settings: tenantSettings } : {},
1614
- ...databaseName ? { database: databaseName } : {},
1615
- ...metadata?.dialect ? { dialect: metadata.dialect } : {}
1616
- },
1617
- tenantId,
1618
- options?.userId,
1619
- options?.scopes,
1620
- signal,
1621
- sessionId
1622
- );
1623
- finalSql = rewriteResponse.sql;
1624
- paramMetadata = Array.isArray(rewriteResponse.params) ? rewriteResponse.params : [];
1625
- finalParams = queryEngine.mapGeneratedParams(paramMetadata);
1626
- applyDateRangeOverrides(
1627
- input.sqlModifications?.dateRange,
1628
- finalParams,
1629
- paramMetadata
1630
- );
1631
- rationale = rewriteResponse.rationale;
1632
- queryId = rewriteResponse.queryId;
1633
- sqlChanged = finalSql !== input.sql;
1634
- usedFastPath = true;
1635
- } catch {
1636
- }
1637
- if (!usedFastPath) {
1638
- const modifiedQuestion = buildModifiedQuestion(
1639
- input.question,
1640
- input.sqlModifications,
1641
- "v2"
1642
- );
1643
- finalQuestion = modifiedQuestion;
1644
- const queryResponse = await client.post(
1645
- queryEndpoint,
1646
- {
1647
- question: modifiedQuestion,
1648
- previous_sql: input.sql,
1649
- ...options?.maxRetry ? { max_retry: options.maxRetry } : {},
1650
- ...tenantSettings ? { tenant_settings: tenantSettings } : {},
1651
- ...databaseName ? { database: databaseName } : {},
1652
- ...metadata?.dialect ? { dialect: metadata.dialect } : {}
1653
- },
1654
- tenantId,
1655
- options?.userId,
1656
- options?.scopes,
1657
- signal,
1658
- sessionId
1659
- );
1660
- finalSql = queryResponse.sql;
1661
- paramMetadata = Array.isArray(queryResponse.params) ? queryResponse.params : [];
1662
- finalParams = queryEngine.mapGeneratedParams(paramMetadata);
1663
- applyDateRangeOverrides(
1664
- input.sqlModifications?.dateRange,
1665
- finalParams,
1666
- paramMetadata
1667
- );
1668
- rationale = queryResponse.rationale;
1669
- queryId = queryResponse.queryId;
1670
- sqlChanged = finalSql !== input.sql;
1671
- }
1672
1592
  } else if (hasSqlMods && !hasCustomSql) {
1673
1593
  const modifiedQuestion = buildModifiedQuestion(
1674
1594
  input.question,
@@ -1682,6 +1602,7 @@ async function modifyChart(client, queryEngine, input, options, signal) {
1682
1602
  queryEndpoint,
1683
1603
  {
1684
1604
  question: modifiedQuestion,
1605
+ session_id: querypanelSessionId,
1685
1606
  previous_sql: input.sql,
1686
1607
  ...options?.maxRetry ? { max_retry: options.maxRetry } : {},
1687
1608
  ...tenantSettings ? { tenant_settings: tenantSettings } : {},
@@ -1784,6 +1705,7 @@ async function modifyChart(client, queryEngine, input, options, signal) {
1784
1705
  rationale,
1785
1706
  dialect: metadata?.dialect ?? "unknown",
1786
1707
  queryId,
1708
+ querypanelSessionId,
1787
1709
  rows,
1788
1710
  fields: execution.fields,
1789
1711
  chart,