@querypanel/node-sdk 1.0.39 → 1.0.40

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 CHANGED
@@ -1191,35 +1191,62 @@ async function ask(client, queryEngine, question, options, signal) {
1191
1191
  tenantId
1192
1192
  );
1193
1193
  const rows = execution.rows ?? [];
1194
+ const chartType = options.chartType ?? "vega-lite";
1194
1195
  let chart = {
1195
- vegaLiteSpec: null,
1196
+ specType: chartType,
1196
1197
  notes: rows.length === 0 ? "Query returned no rows." : null
1197
1198
  };
1198
1199
  if (rows.length > 0) {
1199
- const chartResponse = await client.post(
1200
- "/chart",
1201
- {
1202
- question,
1203
- sql: queryResponse.sql,
1204
- rationale: queryResponse.rationale,
1205
- fields: execution.fields,
1206
- rows: anonymizeResults(rows),
1207
- max_retries: options.chartMaxRetries ?? 3,
1208
- query_id: queryResponse.queryId
1209
- },
1210
- tenantId,
1211
- options.userId,
1212
- options.scopes,
1213
- signal,
1214
- sessionId
1215
- );
1216
- chart = {
1217
- vegaLiteSpec: chartResponse.chart ? {
1218
- ...chartResponse.chart,
1219
- data: { values: rows }
1220
- } : null,
1221
- notes: chartResponse.notes
1222
- };
1200
+ if (chartType === "vizspec") {
1201
+ const vizspecResponse = await client.post(
1202
+ "/vizspec",
1203
+ {
1204
+ question,
1205
+ sql: queryResponse.sql,
1206
+ rationale: queryResponse.rationale,
1207
+ fields: execution.fields,
1208
+ rows: anonymizeResults(rows),
1209
+ max_retries: options.chartMaxRetries ?? 3,
1210
+ query_id: queryResponse.queryId
1211
+ },
1212
+ tenantId,
1213
+ options.userId,
1214
+ options.scopes,
1215
+ signal,
1216
+ sessionId
1217
+ );
1218
+ chart = {
1219
+ vizSpec: vizspecResponse.spec,
1220
+ specType: "vizspec",
1221
+ notes: vizspecResponse.notes
1222
+ };
1223
+ } else {
1224
+ const chartResponse = await client.post(
1225
+ "/chart",
1226
+ {
1227
+ question,
1228
+ sql: queryResponse.sql,
1229
+ rationale: queryResponse.rationale,
1230
+ fields: execution.fields,
1231
+ rows: anonymizeResults(rows),
1232
+ max_retries: options.chartMaxRetries ?? 3,
1233
+ query_id: queryResponse.queryId
1234
+ },
1235
+ tenantId,
1236
+ options.userId,
1237
+ options.scopes,
1238
+ signal,
1239
+ sessionId
1240
+ );
1241
+ chart = {
1242
+ vegaLiteSpec: chartResponse.chart ? {
1243
+ ...chartResponse.chart,
1244
+ data: { values: rows }
1245
+ } : null,
1246
+ specType: "vega-lite",
1247
+ notes: chartResponse.notes
1248
+ };
1249
+ }
1223
1250
  }
1224
1251
  return {
1225
1252
  sql: queryResponse.sql,
@@ -1271,6 +1298,39 @@ function anonymizeResults(rows) {
1271
1298
  });
1272
1299
  }
1273
1300
 
1301
+ // src/routes/vizspec.ts
1302
+ async function generateVizSpec(client, input, options, signal) {
1303
+ const tenantId = resolveTenantId5(client, options?.tenantId);
1304
+ const sessionId = crypto.randomUUID();
1305
+ const response = await client.post(
1306
+ "/vizspec",
1307
+ {
1308
+ question: input.question,
1309
+ sql: input.sql,
1310
+ rationale: input.rationale,
1311
+ fields: input.fields,
1312
+ rows: input.rows,
1313
+ max_retries: options?.maxRetries ?? input.max_retries ?? 3,
1314
+ query_id: input.query_id
1315
+ },
1316
+ tenantId,
1317
+ options?.userId,
1318
+ options?.scopes,
1319
+ signal,
1320
+ sessionId
1321
+ );
1322
+ return response;
1323
+ }
1324
+ function resolveTenantId5(client, tenantId) {
1325
+ const resolved = tenantId ?? client.getDefaultTenantId();
1326
+ if (!resolved) {
1327
+ throw new Error(
1328
+ "tenantId is required. Provide it per request or via defaultTenantId option."
1329
+ );
1330
+ }
1331
+ return resolved;
1332
+ }
1333
+
1274
1334
  // src/index.ts
1275
1335
  var QueryPanelSdkAPI = class {
1276
1336
  client;
@@ -1336,6 +1396,15 @@ var QueryPanelSdkAPI = class {
1336
1396
  signal
1337
1397
  );
1338
1398
  }
1399
+ // VizSpec generation
1400
+ async generateVizSpec(input, options, signal) {
1401
+ return await generateVizSpec(
1402
+ this.client,
1403
+ input,
1404
+ options,
1405
+ signal
1406
+ );
1407
+ }
1339
1408
  // Chart CRUD operations
1340
1409
  async createChart(body, options, signal) {
1341
1410
  return await createChart(this.client, body, options, signal);