@querypanel/node-sdk 1.3.0-beta.0 → 1.3.0-beta.1
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/README.md +4 -2
- package/dist/index.cjs +15 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -9
- package/dist/index.d.ts +15 -9
- package/dist/index.js +13 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -73,6 +73,7 @@ const response = await qp.ask("Top countries by revenue", {
|
|
|
73
73
|
tenantId: "tenant_123",
|
|
74
74
|
database: "analytics",
|
|
75
75
|
});
|
|
76
|
+
// Defaults to pipeline "v2" (POST /v2/query). Pass pipeline: "v1" only for legacy.
|
|
76
77
|
|
|
77
78
|
console.log(response.sql);
|
|
78
79
|
console.log(response.params);
|
|
@@ -82,17 +83,18 @@ console.log(response.chart.vegaLiteSpec);
|
|
|
82
83
|
|
|
83
84
|
### Custom system instructions (v2 pipeline)
|
|
84
85
|
|
|
85
|
-
If you need to enforce tenant-specific policies that should apply to every query (for example, data retention windows), you can inject additional **system prompt** instructions into the v2 pipeline:
|
|
86
|
+
If you need to enforce tenant-specific policies that should apply to every query (for example, data retention windows), you can inject additional **system prompt** instructions into the v2 pipeline (the default):
|
|
86
87
|
|
|
87
88
|
```ts
|
|
88
89
|
const response = await qp.ask("Revenue by product", {
|
|
89
90
|
tenantId: "tenant_123",
|
|
90
91
|
database: "analytics",
|
|
91
|
-
pipeline: "v2",
|
|
92
92
|
systemPrompt: "Retention policy: only query data from the last 30 days.",
|
|
93
93
|
});
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
+
> **Deprecated:** `pipeline: "v1"` still hits `POST /query` for compatibility. Prefer omitting `pipeline` or passing `"v2"`.
|
|
97
|
+
|
|
96
98
|
### Restricting VizSpec chart types
|
|
97
99
|
|
|
98
100
|
If your UI only supports a subset of VizSpec chart kinds (for example no area or scatter), set **`supportedChartTypes`** on the SDK constructor or on each `ask` / `modifyChart` call. The API’s `/vizspec` step then steers generation toward allowed types only (`line`, `bar`, `column`, `area`, `scatter`, `pie`). This applies whenever you use **`chartType: "vizspec"`** (including the default v2 flow after SQL runs).
|
package/dist/index.cjs
CHANGED
|
@@ -40,7 +40,8 @@ __export(index_exports, {
|
|
|
40
40
|
QueryPipelineError: () => QueryPipelineError,
|
|
41
41
|
anonymizeResults: () => anonymizeResults,
|
|
42
42
|
mapGeneratedParams: () => mapGeneratedParams,
|
|
43
|
-
normalizeSqlParamsInput: () => normalizeSqlParamsInput
|
|
43
|
+
normalizeSqlParamsInput: () => normalizeSqlParamsInput,
|
|
44
|
+
resolveQueryPipeline: () => resolveQueryPipeline
|
|
44
45
|
});
|
|
45
46
|
module.exports = __toCommonJS(index_exports);
|
|
46
47
|
|
|
@@ -1982,6 +1983,9 @@ var import_node_crypto4 = __toESM(require("crypto"), 1);
|
|
|
1982
1983
|
|
|
1983
1984
|
// src/routes/query.ts
|
|
1984
1985
|
var import_node_crypto3 = __toESM(require("crypto"), 1);
|
|
1986
|
+
function resolveQueryPipeline(pipeline) {
|
|
1987
|
+
return pipeline ?? "v2";
|
|
1988
|
+
}
|
|
1985
1989
|
async function ask(client, queryEngine, question, options, signal) {
|
|
1986
1990
|
const tenantId = resolveTenantId5(client, options.tenantId);
|
|
1987
1991
|
const sessionId = import_node_crypto3.default.randomUUID();
|
|
@@ -1990,7 +1994,8 @@ async function ask(client, queryEngine, question, options, signal) {
|
|
|
1990
1994
|
let attempt = 0;
|
|
1991
1995
|
let lastError = options.lastError;
|
|
1992
1996
|
let previousSql = options.previousSql;
|
|
1993
|
-
const
|
|
1997
|
+
const pipeline = resolveQueryPipeline(options.pipeline);
|
|
1998
|
+
const queryEndpoint = pipeline === "v2" ? "/v2/query" : "/query";
|
|
1994
1999
|
while (attempt <= maxRetry) {
|
|
1995
2000
|
const databaseName = options.database ?? queryEngine.getDefaultDatabase();
|
|
1996
2001
|
const metadata = databaseName ? queryEngine.getDatabaseMetadata(databaseName) : void 0;
|
|
@@ -2014,7 +2019,7 @@ async function ask(client, queryEngine, question, options, signal) {
|
|
|
2014
2019
|
...databaseName ? { database: databaseName } : {},
|
|
2015
2020
|
...metadata?.dialect ? { dialect: metadata.dialect } : {},
|
|
2016
2021
|
...options.model?.trim() ? { model: options.model.trim() } : {},
|
|
2017
|
-
...
|
|
2022
|
+
...pipeline === "v2" && options.systemPrompt?.trim() ? { system_prompt: options.systemPrompt.trim() } : {},
|
|
2018
2023
|
debug: options.debug ?? false
|
|
2019
2024
|
},
|
|
2020
2025
|
tenantId,
|
|
@@ -2329,7 +2334,8 @@ async function modifyChart(client, queryEngine, input, options, signal) {
|
|
|
2329
2334
|
const hasSqlMods = !!input.sqlModifications;
|
|
2330
2335
|
const hasVizMods = !!input.vizModifications;
|
|
2331
2336
|
const hasCustomSql = !!input.sqlModifications?.customSql;
|
|
2332
|
-
const
|
|
2337
|
+
const pipeline = resolveQueryPipeline(options?.pipeline);
|
|
2338
|
+
const queryEndpoint = pipeline === "v2" ? "/v2/query" : "/query";
|
|
2333
2339
|
let finalSql = input.sql;
|
|
2334
2340
|
let finalParams = input.params ?? {};
|
|
2335
2341
|
let paramMetadata = [];
|
|
@@ -2361,10 +2367,10 @@ async function modifyChart(client, queryEngine, input, options, signal) {
|
|
|
2361
2367
|
const modifiedQuestion = buildModifiedQuestion(
|
|
2362
2368
|
input.question,
|
|
2363
2369
|
input.sqlModifications,
|
|
2364
|
-
|
|
2370
|
+
pipeline,
|
|
2365
2371
|
hasQuerypanelSessionContext
|
|
2366
2372
|
);
|
|
2367
|
-
if (
|
|
2373
|
+
if (pipeline === "v2") {
|
|
2368
2374
|
finalQuestion = modifiedQuestion;
|
|
2369
2375
|
}
|
|
2370
2376
|
const queryResponse = await client.post(
|
|
@@ -2388,7 +2394,7 @@ async function modifyChart(client, queryEngine, input, options, signal) {
|
|
|
2388
2394
|
finalSql = queryResponse.sql;
|
|
2389
2395
|
paramMetadata = Array.isArray(queryResponse.params) ? queryResponse.params : [];
|
|
2390
2396
|
finalParams = queryEngine.mapGeneratedParams(paramMetadata);
|
|
2391
|
-
if (
|
|
2397
|
+
if (pipeline === "v2") {
|
|
2392
2398
|
applyDateRangeOverrides(
|
|
2393
2399
|
input.sqlModifications?.dateRange,
|
|
2394
2400
|
finalParams,
|
|
@@ -3631,6 +3637,7 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
|
|
|
3631
3637
|
QueryPipelineError,
|
|
3632
3638
|
anonymizeResults,
|
|
3633
3639
|
mapGeneratedParams,
|
|
3634
|
-
normalizeSqlParamsInput
|
|
3640
|
+
normalizeSqlParamsInput,
|
|
3641
|
+
resolveQueryPipeline
|
|
3635
3642
|
});
|
|
3636
3643
|
//# sourceMappingURL=index.cjs.map
|