@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 +121 -119
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +121 -119
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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 (
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
chart
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
chart
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
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
|
|
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
|