@querypanel/node-sdk 1.2.1 → 1.2.3

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 CHANGED
@@ -80,6 +80,44 @@ console.table(response.rows);
80
80
  console.log(response.chart.vegaLiteSpec);
81
81
  ```
82
82
 
83
+ ### Custom system instructions (v2 pipeline)
84
+
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
+
87
+ ```ts
88
+ const response = await qp.ask("Revenue by product", {
89
+ tenantId: "tenant_123",
90
+ database: "analytics",
91
+ pipeline: "v2",
92
+ systemPrompt: "Retention policy: only query data from the last 30 days.",
93
+ });
94
+ ```
95
+
96
+ ### Restricting VizSpec chart types
97
+
98
+ 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).
99
+
100
+ ```ts
101
+ import { QueryPanelSdkAPI, ALL_VIZ_CHART_TYPES, type ChartType } from "@querypanel/sdk";
102
+
103
+ const allowed: ChartType[] = ["line", "bar", "column", "pie"];
104
+
105
+ const qp = new QueryPanelSdkAPI(url, privateKey, workspaceId, {
106
+ supportedChartTypes: allowed,
107
+ });
108
+
109
+ // Or per request:
110
+ await qp.ask("Revenue by month", {
111
+ tenantId: "t1",
112
+ database: "analytics",
113
+ chartType: "vizspec",
114
+ pipeline: "v2",
115
+ supportedChartTypes: allowed,
116
+ });
117
+ ```
118
+
119
+ Use `ALL_VIZ_CHART_TYPES` when you need the full list (for example to derive `allowed` with `.filter(...)`).
120
+
83
121
  ## Session History & Context-Aware Queries
84
122
 
85
123
  The SDK can link related questions into a session so follow-ups like “filter that to Europe” use prior context. The backend generates a QueryPanel session ID for every query and returns it in the response so you can reuse it.
package/dist/index.cjs CHANGED
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ ALL_VIZ_CHART_TYPES: () => ALL_VIZ_CHART_TYPES,
33
34
  BigQueryAdapter: () => BigQueryAdapter,
34
35
  CallbackApiClient: () => CallbackApiClient,
35
36
  ClickHouseAdapter: () => ClickHouseAdapter,
@@ -1765,7 +1766,8 @@ async function ask(client, queryEngine, question, options, signal) {
1765
1766
  ...tenantSettings ? { tenant_settings: tenantSettings } : {},
1766
1767
  ...databaseName ? { database: databaseName } : {},
1767
1768
  ...metadata?.dialect ? { dialect: metadata.dialect } : {},
1768
- ...options.model?.trim() ? { model: options.model.trim() } : {}
1769
+ ...options.model?.trim() ? { model: options.model.trim() } : {},
1770
+ ...options.pipeline === "v2" && options.systemPrompt?.trim() ? { system_prompt: options.systemPrompt.trim() } : {}
1769
1771
  },
1770
1772
  tenantId,
1771
1773
  options.userId,
@@ -1818,7 +1820,10 @@ async function ask(client, queryEngine, question, options, signal) {
1818
1820
  fields: execution.fields,
1819
1821
  rows: anonymizeResults(rows),
1820
1822
  max_retries: options.chartMaxRetries ?? 3,
1821
- query_id: queryResponse.data.queryId
1823
+ query_id: queryResponse.data.queryId,
1824
+ ...options.supportedChartTypes?.length ? {
1825
+ supported_chart_types: options.supportedChartTypes
1826
+ } : {}
1822
1827
  },
1823
1828
  tenantId,
1824
1829
  options.userId,
@@ -2159,7 +2164,8 @@ async function modifyChart(client, queryEngine, input, options, signal) {
2159
2164
  max_retries: options?.chartMaxRetries ?? 3,
2160
2165
  query_id: queryId,
2161
2166
  // Include viz hints for the chart generator
2162
- ...hasVizMods ? { encoding_hints: vizHintsForChart } : {}
2167
+ ...hasVizMods ? { encoding_hints: vizHintsForChart } : {},
2168
+ ...options?.supportedChartTypes?.length ? { supported_chart_types: options.supportedChartTypes } : {}
2163
2169
  },
2164
2170
  tenantId,
2165
2171
  options?.userId,
@@ -2306,7 +2312,8 @@ async function generateVizSpec(client, input, options, signal) {
2306
2312
  rows: input.rows,
2307
2313
  max_retries: options?.maxRetries ?? input.max_retries ?? 3,
2308
2314
  query_id: input.query_id,
2309
- encoding_hints: input.encoding_hints
2315
+ encoding_hints: input.encoding_hints,
2316
+ ...input.supported_chart_types?.length ? { supported_chart_types: input.supported_chart_types } : {}
2310
2317
  },
2311
2318
  tenantId,
2312
2319
  options?.userId,
@@ -2326,10 +2333,21 @@ function resolveTenantId8(client, tenantId) {
2326
2333
  return resolved;
2327
2334
  }
2328
2335
 
2336
+ // src/types/vizspec.ts
2337
+ var ALL_VIZ_CHART_TYPES = [
2338
+ "line",
2339
+ "bar",
2340
+ "column",
2341
+ "area",
2342
+ "scatter",
2343
+ "pie"
2344
+ ];
2345
+
2329
2346
  // src/index.ts
2330
2347
  var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2331
2348
  client;
2332
2349
  queryEngine;
2350
+ supportedChartTypes;
2333
2351
  /**
2334
2352
  * @param workspaceId - Workspace UUID (same value as your org in the dashboard). Passed to the API as JWT claim `organizationId`.
2335
2353
  */
@@ -2347,6 +2365,7 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2347
2365
  });
2348
2366
  }
2349
2367
  this.queryEngine = new QueryEngine();
2368
+ this.supportedChartTypes = options?.supportedChartTypes;
2350
2369
  }
2351
2370
  /**
2352
2371
  * Create an SDK instance that uses a request callback instead of HTTP.
@@ -2383,7 +2402,10 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2383
2402
  const api = new CallbackApiClient(requestHandler, {
2384
2403
  defaultTenantId: options?.defaultTenantId
2385
2404
  });
2386
- return new _QueryPanelSdkAPI("", "", workspaceId, { api });
2405
+ return new _QueryPanelSdkAPI("", "", workspaceId, {
2406
+ api,
2407
+ supportedChartTypes: options?.supportedChartTypes
2408
+ });
2387
2409
  }
2388
2410
  // Database attachment methods
2389
2411
  attachClickhouse(name, clientFn, options) {
@@ -2507,7 +2529,10 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2507
2529
  this.client,
2508
2530
  this.queryEngine,
2509
2531
  question,
2510
- options,
2532
+ {
2533
+ ...options,
2534
+ supportedChartTypes: options.supportedChartTypes ?? this.supportedChartTypes
2535
+ },
2511
2536
  signal
2512
2537
  );
2513
2538
  }
@@ -2579,7 +2604,10 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2579
2604
  async generateVizSpec(input, options, signal) {
2580
2605
  return await generateVizSpec(
2581
2606
  this.client,
2582
- input,
2607
+ {
2608
+ ...input,
2609
+ supported_chart_types: input.supported_chart_types ?? this.supportedChartTypes
2610
+ },
2583
2611
  options,
2584
2612
  signal
2585
2613
  );
@@ -2647,7 +2675,10 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
2647
2675
  this.client,
2648
2676
  this.queryEngine,
2649
2677
  input,
2650
- options,
2678
+ options ? {
2679
+ ...options,
2680
+ supportedChartTypes: options.supportedChartTypes ?? this.supportedChartTypes
2681
+ } : this.supportedChartTypes ? { supportedChartTypes: this.supportedChartTypes } : void 0,
2651
2682
  signal
2652
2683
  );
2653
2684
  }
@@ -3286,6 +3317,7 @@ var QueryPanelSdkAPI = class _QueryPanelSdkAPI {
3286
3317
  };
3287
3318
  // Annotate the CommonJS export names for ESM import in node:
3288
3319
  0 && (module.exports = {
3320
+ ALL_VIZ_CHART_TYPES,
3289
3321
  BigQueryAdapter,
3290
3322
  CallbackApiClient,
3291
3323
  ClickHouseAdapter,