@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.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
|
|
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
|
|
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
|
@@ -1798,7 +1798,6 @@ async function ask(client, queryEngine, question, options, signal) {
|
|
|
1798
1798
|
let previousSql = options.previousSql;
|
|
1799
1799
|
const queryEndpoint = options.pipeline === "v2" ? "/v2/query" : "/query";
|
|
1800
1800
|
while (attempt <= maxRetry) {
|
|
1801
|
-
console.log({ lastError, previousSql });
|
|
1802
1801
|
const databaseName = options.database ?? queryEngine.getDefaultDatabase();
|
|
1803
1802
|
const metadata = databaseName ? queryEngine.getDatabaseMetadata(databaseName) : void 0;
|
|
1804
1803
|
let tenantSettings;
|
|
@@ -1821,7 +1820,8 @@ async function ask(client, queryEngine, question, options, signal) {
|
|
|
1821
1820
|
...databaseName ? { database: databaseName } : {},
|
|
1822
1821
|
...metadata?.dialect ? { dialect: metadata.dialect } : {},
|
|
1823
1822
|
...options.model?.trim() ? { model: options.model.trim() } : {},
|
|
1824
|
-
...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
|
|
1825
1825
|
},
|
|
1826
1826
|
tenantId,
|
|
1827
1827
|
options.userId,
|
|
@@ -1863,60 +1863,58 @@ async function ask(client, queryEngine, question, options, signal) {
|
|
|
1863
1863
|
specType: chartType,
|
|
1864
1864
|
notes: rows.length === 0 ? "Query returned no rows." : null
|
|
1865
1865
|
};
|
|
1866
|
-
if (
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
chart
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
};
|
|
1919
|
-
}
|
|
1866
|
+
if (chartType === "vizspec") {
|
|
1867
|
+
const vizspecResponse = await client.post(
|
|
1868
|
+
"/vizspec",
|
|
1869
|
+
{
|
|
1870
|
+
question,
|
|
1871
|
+
sql,
|
|
1872
|
+
rationale: queryResponse.data.rationale,
|
|
1873
|
+
fields: execution.fields,
|
|
1874
|
+
rows: anonymizeResults(rows),
|
|
1875
|
+
max_retries: options.chartMaxRetries ?? 3,
|
|
1876
|
+
query_id: queryResponse.data.queryId,
|
|
1877
|
+
...options.supportedChartTypes?.length ? {
|
|
1878
|
+
supported_chart_types: options.supportedChartTypes
|
|
1879
|
+
} : {}
|
|
1880
|
+
},
|
|
1881
|
+
tenantId,
|
|
1882
|
+
options.userId,
|
|
1883
|
+
options.scopes,
|
|
1884
|
+
signal,
|
|
1885
|
+
sessionId
|
|
1886
|
+
);
|
|
1887
|
+
chart = {
|
|
1888
|
+
vizSpec: vizspecResponse.spec,
|
|
1889
|
+
specType: "vizspec",
|
|
1890
|
+
notes: rows.length === 0 ? vizspecResponse.notes ?? "Query returned no rows." : vizspecResponse.notes
|
|
1891
|
+
};
|
|
1892
|
+
} else {
|
|
1893
|
+
const chartResponse = await client.post(
|
|
1894
|
+
"/chart",
|
|
1895
|
+
{
|
|
1896
|
+
question,
|
|
1897
|
+
sql,
|
|
1898
|
+
rationale: queryResponse.data.rationale,
|
|
1899
|
+
fields: execution.fields,
|
|
1900
|
+
rows: anonymizeResults(rows),
|
|
1901
|
+
max_retries: options.chartMaxRetries ?? 3,
|
|
1902
|
+
query_id: queryResponse.data.queryId
|
|
1903
|
+
},
|
|
1904
|
+
tenantId,
|
|
1905
|
+
options.userId,
|
|
1906
|
+
options.scopes,
|
|
1907
|
+
signal,
|
|
1908
|
+
sessionId
|
|
1909
|
+
);
|
|
1910
|
+
chart = {
|
|
1911
|
+
vegaLiteSpec: chartResponse.chart ? {
|
|
1912
|
+
...chartResponse.chart,
|
|
1913
|
+
data: { values: rows }
|
|
1914
|
+
} : null,
|
|
1915
|
+
specType: "vega-lite",
|
|
1916
|
+
notes: rows.length === 0 ? chartResponse.notes ?? "Query returned no rows." : chartResponse.notes
|
|
1917
|
+
};
|
|
1920
1918
|
}
|
|
1921
1919
|
return {
|
|
1922
1920
|
sql,
|
|
@@ -1942,9 +1940,14 @@ async function ask(client, queryEngine, question, options, signal) {
|
|
|
1942
1940
|
}
|
|
1943
1941
|
lastError = error instanceof Error ? error.message : String(error);
|
|
1944
1942
|
previousSql = queryResponse.data.sql ?? previousSql;
|
|
1945
|
-
console.warn(
|
|
1946
|
-
|
|
1947
|
-
|
|
1943
|
+
console.warn("SQL execution failed, retrying query generation", {
|
|
1944
|
+
attempt,
|
|
1945
|
+
maxAttempts: maxRetry + 1,
|
|
1946
|
+
error: lastError,
|
|
1947
|
+
sql: queryResponse.data.sql ?? null,
|
|
1948
|
+
paramMetadata,
|
|
1949
|
+
params: paramValues
|
|
1950
|
+
});
|
|
1948
1951
|
}
|
|
1949
1952
|
}
|
|
1950
1953
|
throw new Error("Unexpected error in ask retry loop");
|
|
@@ -2170,7 +2173,8 @@ async function modifyChart(client, queryEngine, input, options, signal) {
|
|
|
2170
2173
|
...options?.maxRetry ? { max_retry: options.maxRetry } : {},
|
|
2171
2174
|
...tenantSettings ? { tenant_settings: tenantSettings } : {},
|
|
2172
2175
|
...databaseName ? { database: databaseName } : {},
|
|
2173
|
-
...metadata?.dialect ? { dialect: metadata.dialect } : {}
|
|
2176
|
+
...metadata?.dialect ? { dialect: metadata.dialect } : {},
|
|
2177
|
+
debug: options?.debug ?? false
|
|
2174
2178
|
},
|
|
2175
2179
|
tenantId,
|
|
2176
2180
|
options?.userId,
|
|
@@ -2203,64 +2207,62 @@ async function modifyChart(client, queryEngine, input, options, signal) {
|
|
|
2203
2207
|
specType: chartType,
|
|
2204
2208
|
notes: rows.length === 0 ? "Query returned no rows." : null
|
|
2205
2209
|
};
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
chart
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
};
|
|
2263
|
-
}
|
|
2210
|
+
const vizHints = hasVizMods ? buildVizHints(input.vizModifications) : {};
|
|
2211
|
+
const vizHintsForChart = chartType === "vizspec" ? vizHints : stripVizSpecOnlyHints(vizHints);
|
|
2212
|
+
if (chartType === "vizspec") {
|
|
2213
|
+
const vizspecResponse = await client.post(
|
|
2214
|
+
"/vizspec",
|
|
2215
|
+
{
|
|
2216
|
+
question: finalQuestion,
|
|
2217
|
+
sql: finalSql,
|
|
2218
|
+
rationale,
|
|
2219
|
+
fields: execution.fields,
|
|
2220
|
+
rows: anonymizeResults(rows),
|
|
2221
|
+
max_retries: options?.chartMaxRetries ?? 3,
|
|
2222
|
+
query_id: queryId,
|
|
2223
|
+
// Include viz hints for the chart generator
|
|
2224
|
+
...hasVizMods ? { encoding_hints: vizHintsForChart } : {},
|
|
2225
|
+
...options?.supportedChartTypes?.length ? { supported_chart_types: options.supportedChartTypes } : {}
|
|
2226
|
+
},
|
|
2227
|
+
tenantId,
|
|
2228
|
+
options?.userId,
|
|
2229
|
+
options?.scopes,
|
|
2230
|
+
signal,
|
|
2231
|
+
sessionId
|
|
2232
|
+
);
|
|
2233
|
+
chart = {
|
|
2234
|
+
vizSpec: vizspecResponse.spec,
|
|
2235
|
+
specType: "vizspec",
|
|
2236
|
+
notes: rows.length === 0 ? vizspecResponse.notes ?? "Query returned no rows." : vizspecResponse.notes
|
|
2237
|
+
};
|
|
2238
|
+
} else {
|
|
2239
|
+
const chartResponse = await client.post(
|
|
2240
|
+
"/chart",
|
|
2241
|
+
{
|
|
2242
|
+
question: finalQuestion,
|
|
2243
|
+
sql: finalSql,
|
|
2244
|
+
rationale,
|
|
2245
|
+
fields: execution.fields,
|
|
2246
|
+
rows: anonymizeResults(rows),
|
|
2247
|
+
max_retries: options?.chartMaxRetries ?? 3,
|
|
2248
|
+
query_id: queryId,
|
|
2249
|
+
// Include viz hints for the chart generator
|
|
2250
|
+
...hasVizMods ? { encoding_hints: vizHintsForChart } : {}
|
|
2251
|
+
},
|
|
2252
|
+
tenantId,
|
|
2253
|
+
options?.userId,
|
|
2254
|
+
options?.scopes,
|
|
2255
|
+
signal,
|
|
2256
|
+
sessionId
|
|
2257
|
+
);
|
|
2258
|
+
chart = {
|
|
2259
|
+
vegaLiteSpec: chartResponse.chart ? {
|
|
2260
|
+
...chartResponse.chart,
|
|
2261
|
+
data: { values: rows }
|
|
2262
|
+
} : null,
|
|
2263
|
+
specType: "vega-lite",
|
|
2264
|
+
notes: rows.length === 0 ? chartResponse.notes ?? "Query returned no rows." : chartResponse.notes
|
|
2265
|
+
};
|
|
2264
2266
|
}
|
|
2265
2267
|
return {
|
|
2266
2268
|
sql: finalSql,
|
|
@@ -2551,7 +2553,7 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
|
|
|
2551
2553
|
* It handles the complete flow: SQL generation → validation → execution → chart generation.
|
|
2552
2554
|
*
|
|
2553
2555
|
* @param question - Natural language question (e.g., "Show revenue by country")
|
|
2554
|
-
* @param options - Query options including tenantId, database, and
|
|
2556
|
+
* @param options - Query options including tenantId, database, retry settings, and optional `debug` for engineer-style rationale
|
|
2555
2557
|
* @param signal - Optional AbortSignal for cancellation
|
|
2556
2558
|
* @returns Response with SQL, executed data rows, and generated chart
|
|
2557
2559
|
* @throws {Error} When SQL generation or execution fails after all retries
|