@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 +9 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +9 -84
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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
|
|
195
|
-
constructor(message: string, code: QueryErrorCode, details?: Record<string, unknown>
|
|
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
|
|
195
|
-
constructor(message: string, code: QueryErrorCode, details?: Record<string, unknown>
|
|
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 = [];
|
|
@@ -1455,6 +1449,9 @@ function buildModifiedQuestion(originalQuestion, modifications, pipeline) {
|
|
|
1455
1449
|
if (hints.length === 0) {
|
|
1456
1450
|
return originalQuestion;
|
|
1457
1451
|
}
|
|
1452
|
+
if (pipeline === "v2") {
|
|
1453
|
+
return hints.join(", ");
|
|
1454
|
+
}
|
|
1458
1455
|
return `${originalQuestion} (${hints.join(", ")})`;
|
|
1459
1456
|
}
|
|
1460
1457
|
var START_PARAM_KEY_REGEX = /(^|_)(start|from)(_|$)/i;
|
|
@@ -1550,9 +1547,6 @@ function stripVizSpecOnlyHints(hints) {
|
|
|
1550
1547
|
const { kind: _kind, ...rest } = hints;
|
|
1551
1548
|
return rest;
|
|
1552
1549
|
}
|
|
1553
|
-
function isDateRangeOnly(mods) {
|
|
1554
|
-
return !!mods.dateRange && !mods.timeGranularity && !mods.additionalInstructions && !mods.customSql;
|
|
1555
|
-
}
|
|
1556
1550
|
function resolveTenantId5(client, tenantId) {
|
|
1557
1551
|
const resolved = tenantId ?? client.getDefaultTenantId();
|
|
1558
1552
|
if (!resolved) {
|
|
@@ -1565,6 +1559,7 @@ function resolveTenantId5(client, tenantId) {
|
|
|
1565
1559
|
async function modifyChart(client, queryEngine, input, options, signal) {
|
|
1566
1560
|
const tenantId = resolveTenantId5(client, options?.tenantId);
|
|
1567
1561
|
const sessionId = crypto4.randomUUID();
|
|
1562
|
+
const querypanelSessionId = options?.querypanelSessionId ?? sessionId;
|
|
1568
1563
|
const chartType = options?.chartType ?? "vega-lite";
|
|
1569
1564
|
const hasSqlMods = !!input.sqlModifications;
|
|
1570
1565
|
const hasVizMods = !!input.vizModifications;
|
|
@@ -1597,78 +1592,6 @@ async function modifyChart(client, queryEngine, input, options, signal) {
|
|
|
1597
1592
|
finalParams = {};
|
|
1598
1593
|
paramMetadata = [];
|
|
1599
1594
|
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
1595
|
} else if (hasSqlMods && !hasCustomSql) {
|
|
1673
1596
|
const modifiedQuestion = buildModifiedQuestion(
|
|
1674
1597
|
input.question,
|
|
@@ -1682,6 +1605,7 @@ async function modifyChart(client, queryEngine, input, options, signal) {
|
|
|
1682
1605
|
queryEndpoint,
|
|
1683
1606
|
{
|
|
1684
1607
|
question: modifiedQuestion,
|
|
1608
|
+
session_id: querypanelSessionId,
|
|
1685
1609
|
previous_sql: input.sql,
|
|
1686
1610
|
...options?.maxRetry ? { max_retry: options.maxRetry } : {},
|
|
1687
1611
|
...tenantSettings ? { tenant_settings: tenantSettings } : {},
|
|
@@ -1784,6 +1708,7 @@ async function modifyChart(client, queryEngine, input, options, signal) {
|
|
|
1784
1708
|
rationale,
|
|
1785
1709
|
dialect: metadata?.dialect ?? "unknown",
|
|
1786
1710
|
queryId,
|
|
1711
|
+
querypanelSessionId,
|
|
1787
1712
|
rows,
|
|
1788
1713
|
fields: execution.fields,
|
|
1789
1714
|
chart,
|