@querypanel/node-sdk 1.0.25 → 1.0.27

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
@@ -1,3 +1,11 @@
1
+ import { QueryParams, DataFormat } from '@clickhouse/client';
2
+
3
+ /**
4
+ * Simplified schema types aligned with backend IngestRequest format
5
+ * Following Ousterhout's principle: "Define errors out of existence"
6
+ * - Removed indexes, constraints, foreign keys, statistics
7
+ * - Only collect what the backend needs for vectorization
8
+ */
1
9
  type DatabaseKind = "clickhouse" | "postgres" | string;
2
10
  interface DatabaseIdentifier {
3
11
  kind: DatabaseKind;
@@ -5,66 +13,24 @@ interface DatabaseIdentifier {
5
13
  schema?: string;
6
14
  version?: string;
7
15
  }
8
- interface ColumnStatistics {
9
- compressedBytes?: number;
10
- uncompressedBytes?: number;
11
- distinctValues?: number;
12
- }
13
16
  interface ColumnSchema {
14
17
  name: string;
15
18
  type: string;
16
19
  rawType?: string;
17
- nullable: boolean;
18
- defaultKind?: string;
19
- defaultExpression?: string;
20
- comment?: string;
21
20
  isPrimaryKey: boolean;
22
- isForeignKey: boolean;
23
- foreignKeyTable?: string;
24
- foreignKeyColumn?: string;
25
- maxLength?: number;
26
- precision?: number;
27
- scale?: number;
28
- codec?: string;
29
- ttlExpression?: string;
30
- statistics?: ColumnStatistics;
31
- }
32
- interface IndexSchema {
33
- name: string;
34
- columns: string[];
35
- unique: boolean;
36
- type: string;
37
- definition?: string;
38
- }
39
- interface ConstraintSchema {
40
- name: string;
41
- type: "PRIMARY KEY" | "FOREIGN KEY" | "UNIQUE" | "CHECK" | string;
42
- columns: string[];
43
- referencedTable?: string;
44
- referencedColumns?: string[];
45
- definition?: string;
46
- }
47
- interface TableStatistics {
48
- totalRows?: number;
49
- totalBytes?: number;
50
- uncompressedBytes?: number;
21
+ comment?: string;
51
22
  }
52
23
  interface TableSchema {
53
24
  name: string;
54
25
  schema: string;
55
26
  type: "table" | "view" | string;
56
- engine?: string;
57
27
  comment?: string;
58
- statistics?: TableStatistics;
59
28
  columns: ColumnSchema[];
60
- indexes: IndexSchema[];
61
- constraints: ConstraintSchema[];
62
29
  }
63
30
  interface SchemaIntrospection {
64
31
  db: DatabaseIdentifier;
65
32
  tables: TableSchema[];
66
33
  introspectedAt: string;
67
- metadata?: Record<string, unknown>;
68
34
  }
69
35
  interface IntrospectOptions {
70
36
  /** Optional allow-list of table names to introspect (schema-qualified or bare). */
@@ -108,17 +74,11 @@ interface DatabaseAdapter {
108
74
  close?(): Promise<void>;
109
75
  }
110
76
 
111
- type QueryParams = {
112
- query: string;
113
- format?: string;
114
- };
115
- type ClickHouseSettings = Record<string, unknown>;
116
- type Row = Record<string, unknown>;
117
77
  interface ClickHouseAdapterOptions {
118
78
  /** Optional logical database name used in introspection metadata. */
119
79
  database?: string;
120
80
  /** Override the default response format used for query execution. */
121
- defaultFormat?: QueryParams["format"];
81
+ defaultFormat?: DataFormat;
122
82
  /**
123
83
  * Optional database kind label. Defaults to "clickhouse" but allows
124
84
  * sub-classing/custom branding if needed.
@@ -134,10 +94,12 @@ interface ClickHouseAdapterOptions {
134
94
  type ClickHouseQueryResult = {
135
95
  json: () => Promise<unknown>;
136
96
  };
137
- type ClickHouseClientFn = (params: QueryParams & {
138
- query_params?: Record<string, unknown>;
139
- clickhouse_settings?: ClickHouseSettings;
140
- }) => Promise<ClickHouseQueryResult | Array<Record<string, unknown>> | Row[]>;
97
+ type ClickHouseClientFn = (params: QueryParams) => Promise<ClickHouseQueryResult | Array<Record<string, unknown>> | Record<string, unknown>[]>;
98
+ /**
99
+ * Simplified ClickHouse adapter following IngestRequest format
100
+ * Removed: indexes, constraints, statistics
101
+ * Kept only: tables, columns (name, type, isPrimaryKey, comment)
102
+ */
141
103
  declare class ClickHouseAdapter implements DatabaseAdapter {
142
104
  private readonly clientFn;
143
105
  private readonly databaseName;
@@ -148,11 +110,11 @@ declare class ClickHouseAdapter implements DatabaseAdapter {
148
110
  execute(sql: string, params?: Record<string, string | number | boolean | string[] | number[]>): Promise<DatabaseExecutionResult>;
149
111
  validate(sql: string, params?: Record<string, string | number | boolean | string[] | number[]>): Promise<void>;
150
112
  getDialect(): "clickhouse";
151
- introspect(options?: IntrospectOptions): Promise<SchemaIntrospection>;
152
113
  /**
153
- * Validate that the SQL query only references allowed tables.
154
- * This is a basic validation that extracts table-like patterns from the query.
114
+ * Simplified introspection: only collect table/column metadata for IngestRequest
115
+ * No indexes, constraints, or statistics
155
116
  */
117
+ introspect(options?: IntrospectOptions): Promise<SchemaIntrospection>;
156
118
  private validateQueryTables;
157
119
  close(): Promise<void>;
158
120
  private query;
@@ -179,6 +141,11 @@ interface PostgresAdapterOptions {
179
141
  */
180
142
  allowedTables?: string[];
181
143
  }
144
+ /**
145
+ * Simplified PostgreSQL adapter following IngestRequest format
146
+ * Removed: indexes, constraints, foreign keys, statistics
147
+ * Kept only: tables, columns (name, type, isPrimaryKey, comment)
148
+ */
182
149
  declare class PostgresAdapter implements DatabaseAdapter {
183
150
  private readonly clientFn;
184
151
  private readonly databaseName;
@@ -187,112 +154,24 @@ declare class PostgresAdapter implements DatabaseAdapter {
187
154
  private readonly allowedTables?;
188
155
  constructor(clientFn: PostgresClientFn, options?: PostgresAdapterOptions);
189
156
  execute(sql: string, params?: Record<string, string | number | boolean | string[] | number[]>): Promise<DatabaseExecutionResult>;
190
- /**
191
- * Validate that the SQL query only references allowed tables.
192
- * This is a basic validation that extracts table-like patterns from the query.
193
- */
194
157
  private validateQueryTables;
195
158
  /**
196
159
  * Convert named params to positional array for PostgreSQL
197
160
  * PostgreSQL expects $1, $2, $3 in SQL and an array of values [val1, val2, val3]
198
- *
199
- * Supports two formats:
200
- * 1. Numeric keys: { '1': 'value1', '2': 'value2' } - maps directly to $1, $2
201
- * 2. Named keys: { 'tenant_id': 'value' } - values extracted in alphabetical order
202
- * 3. Mixed: { '1': 'value1', 'tenant_id': 'value' } - numeric keys first, then named keys
203
161
  */
204
162
  private convertNamedToPositionalParams;
205
163
  validate(sql: string, params?: Record<string, string | number | boolean | string[] | number[]>): Promise<void>;
206
164
  getDialect(): "postgres";
165
+ /**
166
+ * Simplified introspection: only collect table/column metadata for IngestRequest
167
+ * No indexes, constraints, or statistics
168
+ */
207
169
  introspect(options?: IntrospectOptions): Promise<SchemaIntrospection>;
208
170
  }
209
171
 
210
172
  type ParamValue = string | number | boolean | string[] | number[];
211
173
  type ParamRecord = Record<string, ParamValue>;
212
- interface ContextDocument {
213
- source?: string;
214
- pageContent: string;
215
- metadata?: Record<string, unknown>;
216
- score?: number;
217
- }
218
- interface ChartEnvelope {
219
- vegaLiteSpec: Record<string, unknown> | null;
220
- notes: string | null;
221
- }
222
- interface AskOptions {
223
- tenantId?: string;
224
- userId?: string;
225
- scopes?: string[];
226
- database?: string;
227
- lastError?: string;
228
- previousSql?: string;
229
- maxRetry?: number;
230
- chartMaxRetries?: number;
231
- disableAutoSync?: boolean;
232
- }
233
- interface AskResponse {
234
- sql: string;
235
- params: ParamRecord;
236
- paramMetadata: Array<Record<string, unknown>>;
237
- rationale?: string;
238
- dialect: string;
239
- queryId?: string;
240
- rows: Array<Record<string, unknown>>;
241
- fields: string[];
242
- chart: ChartEnvelope;
243
- context?: ContextDocument[];
244
- }
245
- interface SchemaSyncOptions {
246
- tenantId?: string;
247
- userId?: string;
248
- scopes?: string[];
249
- tables?: string[];
250
- force?: boolean;
251
- }
252
- interface KnowledgeBaseAnnotation {
253
- id: string;
254
- organization_id: string;
255
- target_identifier: string;
256
- content: string;
257
- created_by: string;
258
- updated_by: string;
259
- created_at: string;
260
- updated_at: string;
261
- }
262
- interface KnowledgeBaseAnnotationInput {
263
- targetIdentifier: string;
264
- content: string;
265
- userId: string;
266
- tenantId?: string;
267
- }
268
- interface KnowledgeBaseChunkTable {
269
- table_name: string;
270
- gold_sql?: Array<{
271
- sql: string;
272
- description?: string;
273
- name?: string;
274
- }>;
275
- glossary?: Array<{
276
- term: string;
277
- definition: string;
278
- }>;
279
- }
280
- interface KnowledgeBaseChunkRequest {
281
- database: string;
282
- dialect: string;
283
- tables: KnowledgeBaseChunkTable[];
284
- tenantId?: string;
285
- }
286
- interface KnowledgeBaseChunksResponse {
287
- success: boolean;
288
- message: string;
289
- chunks: {
290
- total: number;
291
- gold_sql: number;
292
- glossary: number;
293
- chunks_with_annotations: number;
294
- };
295
- }
174
+
296
175
  interface SdkChart {
297
176
  id: string;
298
177
  title: string;
@@ -307,19 +186,7 @@ interface SdkChart {
307
186
  created_at: string | null;
308
187
  updated_at: string | null;
309
188
  active?: boolean;
310
- database?: string | null;
311
- }
312
- interface SdkActiveChart {
313
- id: string;
314
- chart_id: string;
315
- order: number | null;
316
- meta: Record<string, unknown> | null;
317
- organization_id: string | null;
318
- tenant_id: string | null;
319
- user_id: string | null;
320
- created_at: string | null;
321
- updated_at: string | null;
322
- chart?: SdkChart | null;
189
+ target_db?: string | null;
323
190
  }
324
191
  interface ChartCreateInput {
325
192
  title: string;
@@ -328,7 +195,7 @@ interface ChartCreateInput {
328
195
  sql_params?: Record<string, unknown>;
329
196
  vega_lite_spec: Record<string, unknown>;
330
197
  query_id?: string;
331
- database?: string;
198
+ target_db?: string;
332
199
  }
333
200
  interface ChartUpdateInput {
334
201
  title?: string;
@@ -336,17 +203,7 @@ interface ChartUpdateInput {
336
203
  sql?: string;
337
204
  sql_params?: Record<string, unknown>;
338
205
  vega_lite_spec?: Record<string, unknown>;
339
- database?: string;
340
- }
341
- interface ActiveChartCreateInput {
342
- chart_id: string;
343
- order?: number;
344
- meta?: Record<string, unknown>;
345
- }
346
- interface ActiveChartUpdateInput {
347
- chart_id?: string;
348
- order?: number;
349
- meta?: Record<string, unknown>;
206
+ target_db?: string;
350
207
  }
351
208
  interface PaginationQuery {
352
209
  page?: number;
@@ -379,9 +236,33 @@ interface ChartListOptions {
379
236
  updatedTo?: string;
380
237
  includeData?: boolean;
381
238
  }
239
+
240
+ interface SdkActiveChart {
241
+ id: string;
242
+ chart_id: string;
243
+ order: number | null;
244
+ meta: Record<string, unknown> | null;
245
+ organization_id: string | null;
246
+ tenant_id: string | null;
247
+ user_id: string | null;
248
+ created_at: string | null;
249
+ updated_at: string | null;
250
+ chart?: SdkChart | null;
251
+ }
252
+ interface ActiveChartCreateInput {
253
+ chart_id: string;
254
+ order?: number;
255
+ meta?: Record<string, unknown>;
256
+ }
257
+ interface ActiveChartUpdateInput {
258
+ chart_id?: string;
259
+ order?: number;
260
+ meta?: Record<string, unknown>;
261
+ }
382
262
  interface ActiveChartListOptions extends ChartListOptions {
383
263
  withData?: boolean;
384
264
  }
265
+
385
266
  interface IngestResponse {
386
267
  success: boolean;
387
268
  message: string;
@@ -392,24 +273,56 @@ interface IngestResponse {
392
273
  drift_detected?: boolean;
393
274
  skipped?: boolean;
394
275
  }
395
- interface RequestOptions {
276
+ interface SchemaSyncOptions {
396
277
  tenantId?: string;
397
278
  userId?: string;
398
279
  scopes?: string[];
280
+ tables?: string[];
399
281
  }
282
+
283
+ interface ContextDocument {
284
+ source?: string;
285
+ pageContent: string;
286
+ metadata?: Record<string, unknown>;
287
+ score?: number;
288
+ }
289
+ interface ChartEnvelope {
290
+ vegaLiteSpec: Record<string, unknown> | null;
291
+ notes: string | null;
292
+ }
293
+ interface AskOptions {
294
+ tenantId?: string;
295
+ userId?: string;
296
+ scopes?: string[];
297
+ database?: string;
298
+ lastError?: string;
299
+ previousSql?: string;
300
+ maxRetry?: number;
301
+ chartMaxRetries?: number;
302
+ }
303
+ interface AskResponse {
304
+ sql: string;
305
+ params: ParamRecord;
306
+ paramMetadata: Array<Record<string, unknown>>;
307
+ rationale?: string;
308
+ dialect: string;
309
+ queryId?: string;
310
+ rows: Array<Record<string, unknown>>;
311
+ fields: string[];
312
+ chart: ChartEnvelope;
313
+ context?: ContextDocument[];
314
+ attempts?: number;
315
+ }
316
+ declare function anonymizeResults(rows: Array<Record<string, unknown>>): Array<Record<string, string>>;
317
+
318
+ /**
319
+ * Main SDK class - Thin orchestrator
320
+ * Delegates to deep modules (ApiClient, QueryEngine, route modules)
321
+ * Following Ousterhout's principle: "Simple interface hiding complexity"
322
+ */
400
323
  declare class QueryPanelSdkAPI {
401
- private readonly baseUrl;
402
- private readonly privateKey;
403
- private readonly organizationId;
404
- private readonly defaultTenantId?;
405
- private readonly additionalHeaders?;
406
- private readonly fetchImpl;
407
- private cachedPrivateKey?;
408
- private databases;
409
- private databaseMetadata;
410
- private defaultDatabase?;
411
- private lastSyncHashes;
412
- private syncedDatabases;
324
+ private readonly client;
325
+ private readonly queryEngine;
413
326
  constructor(baseUrl: string, privateKey: string, organizationId: string, options?: {
414
327
  defaultTenantId?: string;
415
328
  additionalHeaders?: Record<string, string>;
@@ -429,40 +342,47 @@ declare class QueryPanelSdkAPI {
429
342
  enforceTenantIsolation?: boolean;
430
343
  }): void;
431
344
  attachDatabase(name: string, adapter: DatabaseAdapter): void;
432
- syncSchema(databaseName: string, options: SchemaSyncOptions, signal?: AbortSignal): Promise<IngestResponse>;
433
- ingestKnowledgeBaseChunks(payload: KnowledgeBaseChunkRequest, options?: RequestOptions, signal?: AbortSignal): Promise<KnowledgeBaseChunksResponse>;
434
345
  introspect(databaseName: string, tables?: string[]): Promise<SchemaIntrospection>;
346
+ syncSchema(databaseName: string, options: SchemaSyncOptions, signal?: AbortSignal): Promise<IngestResponse>;
435
347
  ask(question: string, options: AskOptions, signal?: AbortSignal): Promise<AskResponse>;
436
- upsertAnnotation(input: KnowledgeBaseAnnotationInput, options?: RequestOptions, signal?: AbortSignal): Promise<KnowledgeBaseAnnotation>;
437
- listAnnotations(options?: RequestOptions, signal?: AbortSignal): Promise<KnowledgeBaseAnnotation[]>;
438
- getAnnotation(targetIdentifier: string, options?: RequestOptions, signal?: AbortSignal): Promise<KnowledgeBaseAnnotation | null>;
439
- deleteAnnotation(targetIdentifier: string, options?: RequestOptions, signal?: AbortSignal): Promise<void>;
440
- createChart(body: ChartCreateInput, options?: RequestOptions, signal?: AbortSignal): Promise<SdkChart>;
348
+ createChart(body: ChartCreateInput, options?: {
349
+ tenantId?: string;
350
+ userId?: string;
351
+ scopes?: string[];
352
+ }, signal?: AbortSignal): Promise<SdkChart>;
441
353
  listCharts(options?: ChartListOptions, signal?: AbortSignal): Promise<PaginatedResponse<SdkChart>>;
442
- getChart(id: string, options?: RequestOptions, signal?: AbortSignal): Promise<SdkChart>;
443
- updateChart(id: string, body: ChartUpdateInput, options?: RequestOptions, signal?: AbortSignal): Promise<SdkChart>;
444
- deleteChart(id: string, options?: RequestOptions, signal?: AbortSignal): Promise<void>;
445
- createActiveChart(body: ActiveChartCreateInput, options?: RequestOptions, signal?: AbortSignal): Promise<SdkActiveChart>;
354
+ getChart(id: string, options?: {
355
+ tenantId?: string;
356
+ userId?: string;
357
+ scopes?: string[];
358
+ }, signal?: AbortSignal): Promise<SdkChart>;
359
+ updateChart(id: string, body: ChartUpdateInput, options?: {
360
+ tenantId?: string;
361
+ userId?: string;
362
+ scopes?: string[];
363
+ }, signal?: AbortSignal): Promise<SdkChart>;
364
+ deleteChart(id: string, options?: {
365
+ tenantId?: string;
366
+ userId?: string;
367
+ scopes?: string[];
368
+ }, signal?: AbortSignal): Promise<void>;
369
+ createActiveChart(body: ActiveChartCreateInput, options?: {
370
+ tenantId?: string;
371
+ userId?: string;
372
+ scopes?: string[];
373
+ }, signal?: AbortSignal): Promise<SdkActiveChart>;
446
374
  listActiveCharts(options?: ActiveChartListOptions, signal?: AbortSignal): Promise<PaginatedResponse<SdkActiveChart>>;
447
375
  getActiveChart(id: string, options?: ActiveChartListOptions, signal?: AbortSignal): Promise<SdkActiveChart>;
448
- updateActiveChart(id: string, body: ActiveChartUpdateInput, options?: RequestOptions, signal?: AbortSignal): Promise<SdkActiveChart>;
449
- deleteActiveChart(id: string, options?: RequestOptions, signal?: AbortSignal): Promise<void>;
450
- private getDatabase;
451
- private ensureSchemasSynced;
452
- private resolveTenantId;
453
- private headers;
454
- private request;
455
- private get;
456
- private post;
457
- private put;
458
- private delete;
459
- private generateJWT;
460
- private buildSchemaRequest;
461
- private hashSchemaRequest;
462
- private mapGeneratedParams;
463
- private ensureTenantIsolation;
464
- private runSafeQueryOnClient;
376
+ updateActiveChart(id: string, body: ActiveChartUpdateInput, options?: {
377
+ tenantId?: string;
378
+ userId?: string;
379
+ scopes?: string[];
380
+ }, signal?: AbortSignal): Promise<SdkActiveChart>;
381
+ deleteActiveChart(id: string, options?: {
382
+ tenantId?: string;
383
+ userId?: string;
384
+ scopes?: string[];
385
+ }, signal?: AbortSignal): Promise<void>;
465
386
  }
466
- declare function anonymizeResults(rows: Array<Record<string, unknown>>): Array<Record<string, string>>;
467
387
 
468
- export { type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AskOptions, type AskResponse, type ChartCreateInput, type ChartEnvelope, type ChartListOptions, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DatabaseAdapter, type DatabaseDialect, type IngestResponse, type KnowledgeBaseAnnotation, type KnowledgeBaseAnnotationInput, type KnowledgeBaseChunkRequest, type KnowledgeBaseChunkTable, type KnowledgeBaseChunksResponse, type PaginatedResponse, type PaginationInfo, type PaginationQuery, type ParamRecord, type ParamValue, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryPanelSdkAPI, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, anonymizeResults };
388
+ export { type ActiveChartCreateInput, type ActiveChartListOptions, type ActiveChartUpdateInput, type AskOptions, type AskResponse, type ChartCreateInput, type ChartEnvelope, type ChartListOptions, type ChartUpdateInput, ClickHouseAdapter, type ClickHouseAdapterOptions, type ClickHouseClientFn, type ContextDocument, type DatabaseAdapter, type DatabaseDialect, type IngestResponse, type PaginatedResponse, type PaginationInfo, type PaginationQuery, type ParamRecord, type ParamValue, PostgresAdapter, type PostgresAdapterOptions, type PostgresClientFn, QueryPanelSdkAPI, type SchemaIntrospection, type SchemaSyncOptions, type SdkActiveChart, type SdkChart, anonymizeResults };