@querypanel/node-sdk 1.0.43 → 1.0.45

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.d.ts CHANGED
@@ -169,6 +169,47 @@ declare class PostgresAdapter implements DatabaseAdapter {
169
169
  introspect(options?: IntrospectOptions): Promise<SchemaIntrospection>;
170
170
  }
171
171
 
172
+ /**
173
+ * Error codes for the query pipeline
174
+ * These match the server-side error codes returned in API responses
175
+ */
176
+ declare const QueryErrorCode: {
177
+ readonly MODERATION_FAILED: "MODERATION_FAILED";
178
+ readonly RELEVANCE_CHECK_FAILED: "RELEVANCE_CHECK_FAILED";
179
+ readonly SECURITY_CHECK_FAILED: "SECURITY_CHECK_FAILED";
180
+ readonly SQL_GENERATION_FAILED: "SQL_GENERATION_FAILED";
181
+ readonly SQL_VALIDATION_FAILED: "SQL_VALIDATION_FAILED";
182
+ readonly CONTEXT_RETRIEVAL_FAILED: "CONTEXT_RETRIEVAL_FAILED";
183
+ readonly INTERNAL_ERROR: "INTERNAL_ERROR";
184
+ readonly AUTHENTICATION_REQUIRED: "AUTHENTICATION_REQUIRED";
185
+ readonly VALIDATION_ERROR: "VALIDATION_ERROR";
186
+ };
187
+ type QueryErrorCode = (typeof QueryErrorCode)[keyof typeof QueryErrorCode];
188
+ /**
189
+ * Error thrown when the query pipeline fails
190
+ */
191
+ declare class QueryPipelineError extends Error {
192
+ readonly code: QueryErrorCode;
193
+ readonly details?: Record<string, unknown> | undefined;
194
+ constructor(message: string, code: QueryErrorCode, details?: Record<string, unknown> | undefined);
195
+ /**
196
+ * Check if this is a moderation error
197
+ */
198
+ isModeration(): boolean;
199
+ /**
200
+ * Check if this is a relevance error (question not related to database)
201
+ */
202
+ isRelevanceError(): boolean;
203
+ /**
204
+ * Check if this is a security error (SQL injection, prompt injection, etc.)
205
+ */
206
+ isSecurityError(): boolean;
207
+ /**
208
+ * Check if this is any guardrail error (relevance or security)
209
+ */
210
+ isGuardrailError(): boolean;
211
+ }
212
+
172
213
  type ParamValue = string | number | boolean | string[] | number[];
173
214
  type ParamRecord = Record<string, ParamValue>;
174
215
 
@@ -208,11 +249,11 @@ interface ChartUpdateInput {
208
249
  spec_type?: 'vega-lite' | 'vizspec';
209
250
  target_db?: string;
210
251
  }
211
- interface PaginationQuery {
252
+ interface PaginationQuery$1 {
212
253
  page?: number;
213
254
  limit?: number;
214
255
  }
215
- interface PaginationInfo {
256
+ interface PaginationInfo$1 {
216
257
  page: number;
217
258
  limit: number;
218
259
  total: number;
@@ -220,15 +261,15 @@ interface PaginationInfo {
220
261
  hasNext: boolean;
221
262
  hasPrev: boolean;
222
263
  }
223
- interface PaginatedResponse<T> {
264
+ interface PaginatedResponse$1<T> {
224
265
  data: T[];
225
- pagination: PaginationInfo;
266
+ pagination: PaginationInfo$1;
226
267
  }
227
268
  interface ChartListOptions {
228
269
  tenantId?: string;
229
270
  userId?: string;
230
271
  scopes?: string[];
231
- pagination?: PaginationQuery;
272
+ pagination?: PaginationQuery$1;
232
273
  sortBy?: "title" | "user_id" | "created_at" | "updated_at";
233
274
  sortDir?: "asc" | "desc";
234
275
  title?: string;
@@ -372,42 +413,90 @@ interface MetricSpec extends VizSpecBase {
372
413
  }
373
414
  type VizSpec = ChartSpec | TableSpec | MetricSpec;
374
415
 
416
+ /**
417
+ * Context document returned by the query pipeline.
418
+ */
375
419
  interface ContextDocument {
420
+ /** Optional source identifier for the document. */
376
421
  source?: string;
422
+ /** Raw document content or excerpt. */
377
423
  pageContent: string;
424
+ /** Additional metadata attached to the document. */
378
425
  metadata?: Record<string, unknown>;
426
+ /** Optional relevance score from retrieval. */
379
427
  score?: number;
380
428
  }
429
+ /**
430
+ * Chart payload returned with query results.
431
+ */
381
432
  interface ChartEnvelope {
433
+ /** Vega-Lite spec when specType is "vega-lite". */
382
434
  vegaLiteSpec?: Record<string, unknown> | null;
435
+ /** VizSpec payload when specType is "vizspec". */
383
436
  vizSpec?: VizSpec | null;
384
- specType: 'vega-lite' | 'vizspec';
437
+ /** Chart specification type. */
438
+ specType: "vega-lite" | "vizspec";
439
+ /** Optional chart generation notes or errors. */
385
440
  notes: string | null;
386
441
  }
442
+ /**
443
+ * Configuration options for query generation.
444
+ */
387
445
  interface AskOptions {
446
+ /** Tenant identifier for scoped access. */
388
447
  tenantId?: string;
448
+ /** Optional user identifier for audit/telemetry. */
389
449
  userId?: string;
450
+ /** Optional scopes to include in the auth token. */
390
451
  scopes?: string[];
452
+ /** Override the default database name. */
391
453
  database?: string;
454
+ /** Previous error message for retry context. */
392
455
  lastError?: string;
456
+ /** Previous SQL statement for retry context. */
393
457
  previousSql?: string;
458
+ /** Maximum number of retry attempts on execution failure. */
394
459
  maxRetry?: number;
460
+ /** Maximum number of retries for chart generation. */
395
461
  chartMaxRetries?: number;
396
- chartType?: 'vega-lite' | 'vizspec';
462
+ /** Choose chart generation method. */
463
+ chartType?: "vega-lite" | "vizspec";
464
+ /**
465
+ * QueryPanel session ID for context-aware follow-ups.
466
+ * Use this to reuse a previously returned session for follow-up prompts.
467
+ */
468
+ querypanelSessionId?: string;
397
469
  }
470
+ /**
471
+ * Response returned after executing a query.
472
+ */
398
473
  interface AskResponse {
474
+ /** Generated SQL statement. */
399
475
  sql: string;
476
+ /** Parameter values for the generated SQL. */
400
477
  params: ParamRecord;
478
+ /** Raw parameter metadata from the backend. */
401
479
  paramMetadata: Array<Record<string, unknown>>;
480
+ /** Optional reasoning for SQL generation. */
402
481
  rationale?: string;
482
+ /** SQL dialect selected by the backend. */
403
483
  dialect: string;
484
+ /** Optional query identifier for traceability. */
404
485
  queryId?: string;
486
+ /** Result rows returned by the query execution. */
405
487
  rows: Array<Record<string, unknown>>;
488
+ /** Column names for returned rows. */
406
489
  fields: string[];
490
+ /** Generated chart payload. */
407
491
  chart: ChartEnvelope;
492
+ /** Optional context documents used for query generation. */
408
493
  context?: ContextDocument[];
494
+ /** Number of attempts used for execution. */
409
495
  attempts?: number;
496
+ /** Target database name resolved by the backend or engine. */
410
497
  target_db?: string;
498
+ /** QueryPanel session ID for follow-up queries. */
499
+ querypanelSessionId?: string;
411
500
  }
412
501
  declare function anonymizeResults(rows: Array<Record<string, unknown>>): Array<Record<string, string>>;
413
502
 
@@ -563,6 +652,93 @@ interface ChartModifyResponse extends AskResponse {
563
652
  };
564
653
  }
565
654
 
655
+ /**
656
+ * A single session turn containing the question and optional SQL output.
657
+ */
658
+ interface SdkSessionTurn {
659
+ id: string;
660
+ session_id: string;
661
+ turn_index: number;
662
+ question: string;
663
+ sql: string | null;
664
+ rationale: string | null;
665
+ row_count: number | null;
666
+ fields: string[] | null;
667
+ error: string | null;
668
+ created_at: string;
669
+ }
670
+ /**
671
+ * Session metadata with optional turn history.
672
+ */
673
+ interface SdkSession {
674
+ id: string;
675
+ session_id: string;
676
+ organization_id: string;
677
+ tenant_id: string | null;
678
+ user_id: string | null;
679
+ title: string | null;
680
+ created_at: string;
681
+ updated_at: string;
682
+ turns?: SdkSessionTurn[];
683
+ }
684
+ /**
685
+ * Fields allowed when updating a session.
686
+ */
687
+ interface SessionUpdateInput {
688
+ title?: string;
689
+ }
690
+ /**
691
+ * Pagination settings for list endpoints.
692
+ */
693
+ interface PaginationQuery {
694
+ page?: number;
695
+ limit?: number;
696
+ }
697
+ /**
698
+ * Pagination metadata returned by list endpoints.
699
+ */
700
+ interface PaginationInfo {
701
+ page: number;
702
+ limit: number;
703
+ total: number;
704
+ totalPages: number;
705
+ hasNext: boolean;
706
+ hasPrev: boolean;
707
+ }
708
+ /**
709
+ * Generic paginated response wrapper.
710
+ */
711
+ interface PaginatedResponse<T> {
712
+ data: T[];
713
+ pagination: PaginationInfo;
714
+ }
715
+ /**
716
+ * Options for listing sessions with filters and pagination.
717
+ */
718
+ interface SessionListOptions {
719
+ tenantId?: string;
720
+ userId?: string;
721
+ scopes?: string[];
722
+ pagination?: PaginationQuery;
723
+ sortBy?: "title" | "user_id" | "created_at" | "updated_at";
724
+ sortDir?: "asc" | "desc";
725
+ title?: string;
726
+ userFilter?: string;
727
+ createdFrom?: string;
728
+ createdTo?: string;
729
+ updatedFrom?: string;
730
+ updatedTo?: string;
731
+ }
732
+ /**
733
+ * Options for retrieving a session.
734
+ */
735
+ interface SessionGetOptions {
736
+ tenantId?: string;
737
+ userId?: string;
738
+ scopes?: string[];
739
+ includeTurns?: boolean;
740
+ }
741
+
566
742
  interface VizSpecGenerateInput {
567
743
  question: string;
568
744
  sql: string;
@@ -659,6 +835,7 @@ declare class QueryPanelSdkAPI {
659
835
  * console.log(result.sql); // Generated SQL
660
836
  * console.log(result.rows); // Query results
661
837
  * console.log(result.chart); // Vega-Lite chart spec
838
+ * console.log(result.querypanelSessionId); // Use for follow-ups
662
839
  *
663
840
  * // With automatic SQL repair on failure
664
841
  * const result = await qp.ask("Show monthly trends", {
@@ -802,7 +979,81 @@ declare class QueryPanelSdkAPI {
802
979
  * });
803
980
  * ```
804
981
  */
805
- listCharts(options?: ChartListOptions, signal?: AbortSignal): Promise<PaginatedResponse<SdkChart>>;
982
+ listCharts(options?: ChartListOptions, signal?: AbortSignal): Promise<PaginatedResponse$1<SdkChart>>;
983
+ /**
984
+ * Lists query sessions with pagination and filtering.
985
+ *
986
+ * @param options - Filtering, pagination, and sort options
987
+ * @param signal - Optional AbortSignal for cancellation
988
+ * @returns Paginated list of sessions
989
+ *
990
+ * @example
991
+ * ```typescript
992
+ * const sessions = await qp.listSessions({
993
+ * tenantId: "tenant_123",
994
+ * pagination: { page: 1, limit: 20 },
995
+ * sortBy: "updated_at",
996
+ * });
997
+ * ```
998
+ */
999
+ listSessions(options?: SessionListOptions, signal?: AbortSignal): Promise<PaginatedResponse<SdkSession>>;
1000
+ /**
1001
+ * Retrieves a session by session_id with optional turn history.
1002
+ *
1003
+ * @param sessionId - QueryPanel session identifier used in ask()
1004
+ * @param options - Tenant, user, scopes, and includeTurns flag
1005
+ * @param signal - Optional AbortSignal for cancellation
1006
+ * @returns Session metadata with optional turns
1007
+ *
1008
+ * @example
1009
+ * ```typescript
1010
+ * const session = await qp.getSession("session_123", {
1011
+ * tenantId: "tenant_123",
1012
+ * includeTurns: true,
1013
+ * });
1014
+ * ```
1015
+ */
1016
+ getSession(sessionId: string, options?: SessionGetOptions, signal?: AbortSignal): Promise<SdkSession>;
1017
+ /**
1018
+ * Updates session metadata (title).
1019
+ *
1020
+ * @param sessionId - QueryPanel session identifier to update
1021
+ * @param body - Fields to update
1022
+ * @param options - Tenant, user, and scope options
1023
+ * @param signal - Optional AbortSignal for cancellation
1024
+ * @returns Updated session
1025
+ *
1026
+ * @example
1027
+ * ```typescript
1028
+ * const updated = await qp.updateSession(
1029
+ * "session_123",
1030
+ * { title: "Q4 Revenue Analysis" },
1031
+ * { tenantId: "tenant_123" },
1032
+ * );
1033
+ * ```
1034
+ */
1035
+ updateSession(sessionId: string, body: SessionUpdateInput, options?: {
1036
+ tenantId?: string;
1037
+ userId?: string;
1038
+ scopes?: string[];
1039
+ }, signal?: AbortSignal): Promise<SdkSession>;
1040
+ /**
1041
+ * Deletes a session and its turn history.
1042
+ *
1043
+ * @param sessionId - QueryPanel session identifier to delete
1044
+ * @param options - Tenant, user, and scope options
1045
+ * @param signal - Optional AbortSignal for cancellation
1046
+ *
1047
+ * @example
1048
+ * ```typescript
1049
+ * await qp.deleteSession("session_123", { tenantId: "tenant_123" });
1050
+ * ```
1051
+ */
1052
+ deleteSession(sessionId: string, options?: {
1053
+ tenantId?: string;
1054
+ userId?: string;
1055
+ scopes?: string[];
1056
+ }, signal?: AbortSignal): Promise<void>;
806
1057
  /**
807
1058
  * Retrieves a single chart by ID with live data.
808
1059
  *
@@ -914,7 +1165,7 @@ declare class QueryPanelSdkAPI {
914
1165
  * });
915
1166
  * ```
916
1167
  */
917
- listActiveCharts(options?: ActiveChartListOptions, signal?: AbortSignal): Promise<PaginatedResponse<SdkActiveChart>>;
1168
+ listActiveCharts(options?: ActiveChartListOptions, signal?: AbortSignal): Promise<PaginatedResponse$1<SdkActiveChart>>;
918
1169
  /**
919
1170
  * Retrieves a single active chart by ID.
920
1171
  *
@@ -977,4 +1228,4 @@ declare class QueryPanelSdkAPI {
977
1228
  }, signal?: AbortSignal): Promise<void>;
978
1229
  }
979
1230
 
980
- export { type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type FieldRef, type FieldRefInput, type FieldType, type IngestResponse, type MetricEncoding, type MetricField, type MetricSpec, type PaginatedResponse, type PaginationInfo, type PaginationQuery, type ParamRecord, type ParamValue, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryPanelSdkAPI, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, type SqlModifications, type StackingMode, type TableColumn, type TableEncoding, type TableSpec, type TimeUnit, type VizModifications, type VizSpec, type VizSpecGenerateInput, type VizSpecGenerateOptions, type VizSpecResponse, anonymizeResults };
1231
+ export { type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AggregateOp, type AskOptions, type AskResponse, type AxisField, type AxisFieldInput, type ChartCreateInput, type ChartEncoding, type ChartEnvelope, type ChartListOptions, type ChartModifyInput, type ChartModifyOptions, type ChartModifyResponse, type ChartSpec, type ChartType, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DatabaseAdapter, type DatabaseDialect, type DateRangeInput, type FieldRef, type FieldRefInput, type FieldType, type IngestResponse, type MetricEncoding, type MetricField, type MetricSpec, type PaginatedResponse$1 as PaginatedResponse, type PaginationInfo$1 as PaginationInfo, type PaginationQuery$1 as PaginationQuery, type ParamRecord, type ParamValue, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryErrorCode, QueryErrorCode as QueryErrorCodeType, QueryPanelSdkAPI, QueryPipelineError, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, type SdkSession, type SdkSessionTurn, type SessionGetOptions, type SessionListOptions, type SessionUpdateInput, type SqlModifications, type StackingMode, type TableColumn, type TableEncoding, type TableSpec, type TimeUnit, type VizModifications, type VizSpec, type VizSpecGenerateInput, type VizSpecGenerateOptions, type VizSpecResponse, anonymizeResults };