@thyn-ai/sqai-ai-sdk 0.1.0

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.
@@ -0,0 +1,837 @@
1
+ import { AlgentaWireValue, SQAI, SqaiConfig, SqaiSource, SqaiError } from '@thyn-ai/sqai';
2
+ export { AlgentaWireValue, ComputationBinding, ComputationSpec, ComputeResult, QueryFilterCondition, QueryFilterSpec, QuerySpec, SQAI, SqaiConfig, SqaiError, SqaiPolicy, SqaiSource } from '@thyn-ai/sqai';
3
+ import { Tool } from 'ai';
4
+ import { z } from 'zod';
5
+
6
+ /** Zod v4 schemas for the SQAI AI-SDK tools.
7
+ *
8
+ * These schemas transport; the @thyn-ai/sqai capability contract and policy layer
9
+ * authorize. Field names mirror @thyn-ai/sqai types verbatim (Algenta vocabulary
10
+ * passes through untranslated). No policy key is reachable from any input
11
+ * schema: application policy is configured in code, never by the model.
12
+ */
13
+
14
+ declare const filterConditionSchema: z.ZodObject<{
15
+ column: z.ZodOptional<z.ZodString>;
16
+ op: z.ZodEnum<{
17
+ eq: "eq";
18
+ in: "in";
19
+ gt: "gt";
20
+ gte: "gte";
21
+ lt: "lt";
22
+ lte: "lte";
23
+ is_null: "is_null";
24
+ is_not_null: "is_not_null";
25
+ }>;
26
+ value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
27
+ values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
28
+ }, z.core.$strip>;
29
+ declare const filterSpecSchema: z.ZodObject<{
30
+ time_filter: z.ZodOptional<z.ZodString>;
31
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
32
+ column: z.ZodOptional<z.ZodString>;
33
+ op: z.ZodEnum<{
34
+ eq: "eq";
35
+ in: "in";
36
+ gt: "gt";
37
+ gte: "gte";
38
+ lt: "lt";
39
+ lte: "lte";
40
+ is_null: "is_null";
41
+ is_not_null: "is_not_null";
42
+ }>;
43
+ value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
44
+ values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
45
+ }, z.core.$strip>>>;
46
+ }, z.core.$strip>;
47
+ declare const querySpecSchema: z.ZodObject<{
48
+ metric: z.ZodString;
49
+ aggregation: z.ZodOptional<z.ZodEnum<{
50
+ sum: "sum";
51
+ avg: "avg";
52
+ count: "count";
53
+ min: "min";
54
+ max: "max";
55
+ }>>;
56
+ group_by: z.ZodOptional<z.ZodString>;
57
+ filter: z.ZodOptional<z.ZodObject<{
58
+ time_filter: z.ZodOptional<z.ZodString>;
59
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
60
+ column: z.ZodOptional<z.ZodString>;
61
+ op: z.ZodEnum<{
62
+ eq: "eq";
63
+ in: "in";
64
+ gt: "gt";
65
+ gte: "gte";
66
+ lt: "lt";
67
+ lte: "lte";
68
+ is_null: "is_null";
69
+ is_not_null: "is_not_null";
70
+ }>;
71
+ value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
72
+ values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
73
+ }, z.core.$strip>>>;
74
+ }, z.core.$strip>>;
75
+ limit: z.ZodOptional<z.ZodNumber>;
76
+ order: z.ZodOptional<z.ZodEnum<{
77
+ asc: "asc";
78
+ desc: "desc";
79
+ }>>;
80
+ source: z.ZodOptional<z.ZodString>;
81
+ }, z.core.$strip>;
82
+ declare const algentaWireValueSchema: z.ZodType<AlgentaWireValue>;
83
+ declare const computationBindingSchema: z.ZodUnion<readonly [z.ZodObject<{
84
+ parameter: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
85
+ source: z.ZodString;
86
+ field: z.ZodString;
87
+ filter: z.ZodOptional<z.ZodObject<{
88
+ time_filter: z.ZodOptional<z.ZodString>;
89
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
90
+ column: z.ZodOptional<z.ZodString>;
91
+ op: z.ZodEnum<{
92
+ eq: "eq";
93
+ in: "in";
94
+ gt: "gt";
95
+ gte: "gte";
96
+ lt: "lt";
97
+ lte: "lte";
98
+ is_null: "is_null";
99
+ is_not_null: "is_not_null";
100
+ }>;
101
+ value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
102
+ values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
103
+ }, z.core.$strip>>>;
104
+ }, z.core.$strip>>;
105
+ }, z.core.$strip>, z.ZodObject<{
106
+ parameters: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
107
+ source: z.ZodString;
108
+ fields: z.ZodArray<z.ZodString>;
109
+ filter: z.ZodOptional<z.ZodObject<{
110
+ time_filter: z.ZodOptional<z.ZodString>;
111
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
112
+ column: z.ZodOptional<z.ZodString>;
113
+ op: z.ZodEnum<{
114
+ eq: "eq";
115
+ in: "in";
116
+ gt: "gt";
117
+ gte: "gte";
118
+ lt: "lt";
119
+ lte: "lte";
120
+ is_null: "is_null";
121
+ is_not_null: "is_not_null";
122
+ }>;
123
+ value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
124
+ values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
125
+ }, z.core.$strip>>>;
126
+ }, z.core.$strip>>;
127
+ alignment: z.ZodLiteral<"rowwise">;
128
+ nullPolicy: z.ZodOptional<z.ZodEnum<{
129
+ pairwise: "pairwise";
130
+ preserve: "preserve";
131
+ }>>;
132
+ }, z.core.$strip>]>;
133
+ declare const computationSpecSchema: z.ZodObject<{
134
+ module: z.ZodString;
135
+ function: z.ZodString;
136
+ args: z.ZodDefault<z.ZodArray<z.ZodType<AlgentaWireValue, unknown, z.core.$ZodTypeInternals<AlgentaWireValue, unknown>>>>;
137
+ kwargs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<AlgentaWireValue, unknown, z.core.$ZodTypeInternals<AlgentaWireValue, unknown>>>>;
138
+ bindings: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
139
+ parameter: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
140
+ source: z.ZodString;
141
+ field: z.ZodString;
142
+ filter: z.ZodOptional<z.ZodObject<{
143
+ time_filter: z.ZodOptional<z.ZodString>;
144
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
145
+ column: z.ZodOptional<z.ZodString>;
146
+ op: z.ZodEnum<{
147
+ eq: "eq";
148
+ in: "in";
149
+ gt: "gt";
150
+ gte: "gte";
151
+ lt: "lt";
152
+ lte: "lte";
153
+ is_null: "is_null";
154
+ is_not_null: "is_not_null";
155
+ }>;
156
+ value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
157
+ values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
158
+ }, z.core.$strip>>>;
159
+ }, z.core.$strip>>;
160
+ }, z.core.$strip>, z.ZodObject<{
161
+ parameters: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
162
+ source: z.ZodString;
163
+ fields: z.ZodArray<z.ZodString>;
164
+ filter: z.ZodOptional<z.ZodObject<{
165
+ time_filter: z.ZodOptional<z.ZodString>;
166
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
167
+ column: z.ZodOptional<z.ZodString>;
168
+ op: z.ZodEnum<{
169
+ eq: "eq";
170
+ in: "in";
171
+ gt: "gt";
172
+ gte: "gte";
173
+ lt: "lt";
174
+ lte: "lte";
175
+ is_null: "is_null";
176
+ is_not_null: "is_not_null";
177
+ }>;
178
+ value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
179
+ values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
180
+ }, z.core.$strip>>>;
181
+ }, z.core.$strip>>;
182
+ alignment: z.ZodLiteral<"rowwise">;
183
+ nullPolicy: z.ZodOptional<z.ZodEnum<{
184
+ pairwise: "pairwise";
185
+ preserve: "preserve";
186
+ }>>;
187
+ }, z.core.$strip>]>>>;
188
+ seed: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
189
+ }, z.core.$strip>;
190
+ declare const queryDataInputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
191
+ version: z.ZodLiteral<"1">;
192
+ kind: z.ZodLiteral<"query">;
193
+ spec: z.ZodObject<{
194
+ metric: z.ZodString;
195
+ aggregation: z.ZodOptional<z.ZodEnum<{
196
+ sum: "sum";
197
+ avg: "avg";
198
+ count: "count";
199
+ min: "min";
200
+ max: "max";
201
+ }>>;
202
+ group_by: z.ZodOptional<z.ZodString>;
203
+ filter: z.ZodOptional<z.ZodObject<{
204
+ time_filter: z.ZodOptional<z.ZodString>;
205
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
206
+ column: z.ZodOptional<z.ZodString>;
207
+ op: z.ZodEnum<{
208
+ eq: "eq";
209
+ in: "in";
210
+ gt: "gt";
211
+ gte: "gte";
212
+ lt: "lt";
213
+ lte: "lte";
214
+ is_null: "is_null";
215
+ is_not_null: "is_not_null";
216
+ }>;
217
+ value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
218
+ values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
219
+ }, z.core.$strip>>>;
220
+ }, z.core.$strip>>;
221
+ limit: z.ZodOptional<z.ZodNumber>;
222
+ order: z.ZodOptional<z.ZodEnum<{
223
+ asc: "asc";
224
+ desc: "desc";
225
+ }>>;
226
+ source: z.ZodOptional<z.ZodString>;
227
+ }, z.core.$strip>;
228
+ }, z.core.$strip>, z.ZodObject<{
229
+ version: z.ZodLiteral<"1">;
230
+ kind: z.ZodLiteral<"computation">;
231
+ spec: z.ZodObject<{
232
+ module: z.ZodString;
233
+ function: z.ZodString;
234
+ args: z.ZodDefault<z.ZodArray<z.ZodType<AlgentaWireValue, unknown, z.core.$ZodTypeInternals<AlgentaWireValue, unknown>>>>;
235
+ kwargs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<AlgentaWireValue, unknown, z.core.$ZodTypeInternals<AlgentaWireValue, unknown>>>>;
236
+ bindings: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
237
+ parameter: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
238
+ source: z.ZodString;
239
+ field: z.ZodString;
240
+ filter: z.ZodOptional<z.ZodObject<{
241
+ time_filter: z.ZodOptional<z.ZodString>;
242
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
243
+ column: z.ZodOptional<z.ZodString>;
244
+ op: z.ZodEnum<{
245
+ eq: "eq";
246
+ in: "in";
247
+ gt: "gt";
248
+ gte: "gte";
249
+ lt: "lt";
250
+ lte: "lte";
251
+ is_null: "is_null";
252
+ is_not_null: "is_not_null";
253
+ }>;
254
+ value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
255
+ values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
256
+ }, z.core.$strip>>>;
257
+ }, z.core.$strip>>;
258
+ }, z.core.$strip>, z.ZodObject<{
259
+ parameters: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
260
+ source: z.ZodString;
261
+ fields: z.ZodArray<z.ZodString>;
262
+ filter: z.ZodOptional<z.ZodObject<{
263
+ time_filter: z.ZodOptional<z.ZodString>;
264
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
265
+ column: z.ZodOptional<z.ZodString>;
266
+ op: z.ZodEnum<{
267
+ eq: "eq";
268
+ in: "in";
269
+ gt: "gt";
270
+ gte: "gte";
271
+ lt: "lt";
272
+ lte: "lte";
273
+ is_null: "is_null";
274
+ is_not_null: "is_not_null";
275
+ }>;
276
+ value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
277
+ values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
278
+ }, z.core.$strip>>>;
279
+ }, z.core.$strip>>;
280
+ alignment: z.ZodLiteral<"rowwise">;
281
+ nullPolicy: z.ZodOptional<z.ZodEnum<{
282
+ pairwise: "pairwise";
283
+ preserve: "preserve";
284
+ }>>;
285
+ }, z.core.$strip>]>>>;
286
+ seed: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
287
+ }, z.core.$strip>;
288
+ }, z.core.$strip>], "kind">;
289
+ declare const explainQueryInputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
290
+ version: z.ZodLiteral<"1">;
291
+ kind: z.ZodLiteral<"query">;
292
+ spec: z.ZodObject<{
293
+ metric: z.ZodString;
294
+ aggregation: z.ZodOptional<z.ZodEnum<{
295
+ sum: "sum";
296
+ avg: "avg";
297
+ count: "count";
298
+ min: "min";
299
+ max: "max";
300
+ }>>;
301
+ group_by: z.ZodOptional<z.ZodString>;
302
+ filter: z.ZodOptional<z.ZodObject<{
303
+ time_filter: z.ZodOptional<z.ZodString>;
304
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
305
+ column: z.ZodOptional<z.ZodString>;
306
+ op: z.ZodEnum<{
307
+ eq: "eq";
308
+ in: "in";
309
+ gt: "gt";
310
+ gte: "gte";
311
+ lt: "lt";
312
+ lte: "lte";
313
+ is_null: "is_null";
314
+ is_not_null: "is_not_null";
315
+ }>;
316
+ value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
317
+ values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
318
+ }, z.core.$strip>>>;
319
+ }, z.core.$strip>>;
320
+ limit: z.ZodOptional<z.ZodNumber>;
321
+ order: z.ZodOptional<z.ZodEnum<{
322
+ asc: "asc";
323
+ desc: "desc";
324
+ }>>;
325
+ source: z.ZodOptional<z.ZodString>;
326
+ }, z.core.$strip>;
327
+ }, z.core.$strip>, z.ZodObject<{
328
+ version: z.ZodLiteral<"1">;
329
+ kind: z.ZodLiteral<"computation">;
330
+ spec: z.ZodObject<{
331
+ module: z.ZodString;
332
+ function: z.ZodString;
333
+ args: z.ZodDefault<z.ZodArray<z.ZodType<AlgentaWireValue, unknown, z.core.$ZodTypeInternals<AlgentaWireValue, unknown>>>>;
334
+ kwargs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<AlgentaWireValue, unknown, z.core.$ZodTypeInternals<AlgentaWireValue, unknown>>>>;
335
+ bindings: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
336
+ parameter: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
337
+ source: z.ZodString;
338
+ field: z.ZodString;
339
+ filter: z.ZodOptional<z.ZodObject<{
340
+ time_filter: z.ZodOptional<z.ZodString>;
341
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
342
+ column: z.ZodOptional<z.ZodString>;
343
+ op: z.ZodEnum<{
344
+ eq: "eq";
345
+ in: "in";
346
+ gt: "gt";
347
+ gte: "gte";
348
+ lt: "lt";
349
+ lte: "lte";
350
+ is_null: "is_null";
351
+ is_not_null: "is_not_null";
352
+ }>;
353
+ value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
354
+ values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
355
+ }, z.core.$strip>>>;
356
+ }, z.core.$strip>>;
357
+ }, z.core.$strip>, z.ZodObject<{
358
+ parameters: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
359
+ source: z.ZodString;
360
+ fields: z.ZodArray<z.ZodString>;
361
+ filter: z.ZodOptional<z.ZodObject<{
362
+ time_filter: z.ZodOptional<z.ZodString>;
363
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
364
+ column: z.ZodOptional<z.ZodString>;
365
+ op: z.ZodEnum<{
366
+ eq: "eq";
367
+ in: "in";
368
+ gt: "gt";
369
+ gte: "gte";
370
+ lt: "lt";
371
+ lte: "lte";
372
+ is_null: "is_null";
373
+ is_not_null: "is_not_null";
374
+ }>;
375
+ value: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
376
+ values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
377
+ }, z.core.$strip>>>;
378
+ }, z.core.$strip>>;
379
+ alignment: z.ZodLiteral<"rowwise">;
380
+ nullPolicy: z.ZodOptional<z.ZodEnum<{
381
+ pairwise: "pairwise";
382
+ preserve: "preserve";
383
+ }>>;
384
+ }, z.core.$strip>]>>>;
385
+ seed: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
386
+ }, z.core.$strip>;
387
+ }, z.core.$strip>], "kind">;
388
+ declare const listSourcesInputSchema: z.ZodObject<{
389
+ capabilitySearch: z.ZodOptional<z.ZodString>;
390
+ module: z.ZodOptional<z.ZodString>;
391
+ }, z.core.$strip>;
392
+ /** Resolver candidates pass through loosely typed — upstream owns the shape. */
393
+ declare const candidateSchema: z.ZodObject<{
394
+ source: z.ZodOptional<z.ZodString>;
395
+ column: z.ZodOptional<z.ZodString>;
396
+ role: z.ZodOptional<z.ZodString>;
397
+ confidence: z.ZodOptional<z.ZodNumber>;
398
+ }, z.core.$loose>;
399
+ declare const errorOutputSchema: z.ZodObject<{
400
+ status: z.ZodLiteral<"error">;
401
+ code: z.ZodString;
402
+ message: z.ZodString;
403
+ retryable: z.ZodBoolean;
404
+ request_id: z.ZodNullable<z.ZodString>;
405
+ nearest_matches: z.ZodOptional<z.ZodArray<z.ZodString>>;
406
+ }, z.core.$strip>;
407
+ declare const clarificationOutputSchema: z.ZodObject<{
408
+ status: z.ZodLiteral<"needs_clarification">;
409
+ question: z.ZodString;
410
+ candidates: z.ZodArray<z.ZodObject<{
411
+ source: z.ZodOptional<z.ZodString>;
412
+ column: z.ZodOptional<z.ZodString>;
413
+ role: z.ZodOptional<z.ZodString>;
414
+ confidence: z.ZodOptional<z.ZodNumber>;
415
+ }, z.core.$loose>>;
416
+ explanation: z.ZodArray<z.ZodString>;
417
+ }, z.core.$strip>;
418
+ declare const rejectedOutputSchema: z.ZodObject<{
419
+ status: z.ZodLiteral<"rejected">;
420
+ rejection_reason: z.ZodString;
421
+ candidates: z.ZodArray<z.ZodObject<{
422
+ source: z.ZodOptional<z.ZodString>;
423
+ column: z.ZodOptional<z.ZodString>;
424
+ role: z.ZodOptional<z.ZodString>;
425
+ confidence: z.ZodOptional<z.ZodNumber>;
426
+ }, z.core.$loose>>;
427
+ explanation: z.ZodArray<z.ZodString>;
428
+ }, z.core.$strip>;
429
+ declare const queryOkOutputSchema: z.ZodObject<{
430
+ status: z.ZodLiteral<"ok">;
431
+ kind: z.ZodLiteral<"query">;
432
+ data: z.ZodObject<{
433
+ columns: z.ZodArray<z.ZodString>;
434
+ rows: z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>>>;
435
+ }, z.core.$strip>;
436
+ total_rows: z.ZodNumber;
437
+ returned_rows: z.ZodNumber;
438
+ truncated: z.ZodBoolean;
439
+ result_id: z.ZodOptional<z.ZodString>;
440
+ plan_hash: z.ZodNullable<z.ZodString>;
441
+ schema_revision: z.ZodNullable<z.ZodString>;
442
+ source_name: z.ZodNullable<z.ZodString>;
443
+ intent_signature: z.ZodNullable<z.ZodString>;
444
+ deterministic_scope: z.ZodNullable<z.ZodString>;
445
+ decision_path: z.ZodNullable<z.ZodString>;
446
+ validated: z.ZodNullable<z.ZodBoolean>;
447
+ request_id: z.ZodNullable<z.ZodString>;
448
+ explanation: z.ZodArray<z.ZodString>;
449
+ }, z.core.$strip>;
450
+ declare const determinismEnvelopeSchema: z.ZodObject<{
451
+ runtime_bundle_version: z.ZodString;
452
+ runtime_bundle_sha256: z.ZodString;
453
+ platform: z.ZodString;
454
+ architecture: z.ZodString;
455
+ kernel_build: z.ZodString;
456
+ precision_mode: z.ZodString;
457
+ thread_count: z.ZodNumber;
458
+ seed: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
459
+ input_hash: z.ZodString;
460
+ }, z.core.$strip>;
461
+ declare const bindingProvenanceSchema: z.ZodObject<{
462
+ source_name: z.ZodString;
463
+ fields: z.ZodArray<z.ZodString>;
464
+ schema_revision: z.ZodNullable<z.ZodString>;
465
+ row_count: z.ZodNumber;
466
+ input_hash: z.ZodString;
467
+ }, z.core.$strip>;
468
+ declare const computationOkOutputSchema: z.ZodObject<{
469
+ status: z.ZodLiteral<"ok">;
470
+ kind: z.ZodLiteral<"computation">;
471
+ value: z.ZodType<AlgentaWireValue, unknown, z.core.$ZodTypeInternals<AlgentaWireValue, unknown>>;
472
+ value_type: z.ZodString;
473
+ preview: z.ZodOptional<z.ZodType<AlgentaWireValue, unknown, z.core.$ZodTypeInternals<AlgentaWireValue, unknown>>>;
474
+ element_count: z.ZodOptional<z.ZodNumber>;
475
+ truncated: z.ZodBoolean;
476
+ result_id: z.ZodOptional<z.ZodString>;
477
+ invocation_hash: z.ZodString;
478
+ computation_hash: z.ZodString;
479
+ contract_hash: z.ZodString;
480
+ determinism: z.ZodObject<{
481
+ runtime_bundle_version: z.ZodString;
482
+ runtime_bundle_sha256: z.ZodString;
483
+ platform: z.ZodString;
484
+ architecture: z.ZodString;
485
+ kernel_build: z.ZodString;
486
+ precision_mode: z.ZodString;
487
+ thread_count: z.ZodNumber;
488
+ seed: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
489
+ input_hash: z.ZodString;
490
+ }, z.core.$strip>;
491
+ provenance: z.ZodOptional<z.ZodObject<{
492
+ bindings: z.ZodArray<z.ZodObject<{
493
+ source_name: z.ZodString;
494
+ fields: z.ZodArray<z.ZodString>;
495
+ schema_revision: z.ZodNullable<z.ZodString>;
496
+ row_count: z.ZodNumber;
497
+ input_hash: z.ZodString;
498
+ }, z.core.$strip>>;
499
+ }, z.core.$strip>>;
500
+ latency_ms: z.ZodNumber;
501
+ request_id: z.ZodString;
502
+ }, z.core.$strip>;
503
+ declare const queryDataOutputSchema: z.ZodUnion<readonly [z.ZodObject<{
504
+ status: z.ZodLiteral<"ok">;
505
+ kind: z.ZodLiteral<"query">;
506
+ data: z.ZodObject<{
507
+ columns: z.ZodArray<z.ZodString>;
508
+ rows: z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>>>;
509
+ }, z.core.$strip>;
510
+ total_rows: z.ZodNumber;
511
+ returned_rows: z.ZodNumber;
512
+ truncated: z.ZodBoolean;
513
+ result_id: z.ZodOptional<z.ZodString>;
514
+ plan_hash: z.ZodNullable<z.ZodString>;
515
+ schema_revision: z.ZodNullable<z.ZodString>;
516
+ source_name: z.ZodNullable<z.ZodString>;
517
+ intent_signature: z.ZodNullable<z.ZodString>;
518
+ deterministic_scope: z.ZodNullable<z.ZodString>;
519
+ decision_path: z.ZodNullable<z.ZodString>;
520
+ validated: z.ZodNullable<z.ZodBoolean>;
521
+ request_id: z.ZodNullable<z.ZodString>;
522
+ explanation: z.ZodArray<z.ZodString>;
523
+ }, z.core.$strip>, z.ZodObject<{
524
+ status: z.ZodLiteral<"ok">;
525
+ kind: z.ZodLiteral<"computation">;
526
+ value: z.ZodType<AlgentaWireValue, unknown, z.core.$ZodTypeInternals<AlgentaWireValue, unknown>>;
527
+ value_type: z.ZodString;
528
+ preview: z.ZodOptional<z.ZodType<AlgentaWireValue, unknown, z.core.$ZodTypeInternals<AlgentaWireValue, unknown>>>;
529
+ element_count: z.ZodOptional<z.ZodNumber>;
530
+ truncated: z.ZodBoolean;
531
+ result_id: z.ZodOptional<z.ZodString>;
532
+ invocation_hash: z.ZodString;
533
+ computation_hash: z.ZodString;
534
+ contract_hash: z.ZodString;
535
+ determinism: z.ZodObject<{
536
+ runtime_bundle_version: z.ZodString;
537
+ runtime_bundle_sha256: z.ZodString;
538
+ platform: z.ZodString;
539
+ architecture: z.ZodString;
540
+ kernel_build: z.ZodString;
541
+ precision_mode: z.ZodString;
542
+ thread_count: z.ZodNumber;
543
+ seed: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
544
+ input_hash: z.ZodString;
545
+ }, z.core.$strip>;
546
+ provenance: z.ZodOptional<z.ZodObject<{
547
+ bindings: z.ZodArray<z.ZodObject<{
548
+ source_name: z.ZodString;
549
+ fields: z.ZodArray<z.ZodString>;
550
+ schema_revision: z.ZodNullable<z.ZodString>;
551
+ row_count: z.ZodNumber;
552
+ input_hash: z.ZodString;
553
+ }, z.core.$strip>>;
554
+ }, z.core.$strip>>;
555
+ latency_ms: z.ZodNumber;
556
+ request_id: z.ZodString;
557
+ }, z.core.$strip>, z.ZodObject<{
558
+ status: z.ZodLiteral<"needs_clarification">;
559
+ question: z.ZodString;
560
+ candidates: z.ZodArray<z.ZodObject<{
561
+ source: z.ZodOptional<z.ZodString>;
562
+ column: z.ZodOptional<z.ZodString>;
563
+ role: z.ZodOptional<z.ZodString>;
564
+ confidence: z.ZodOptional<z.ZodNumber>;
565
+ }, z.core.$loose>>;
566
+ explanation: z.ZodArray<z.ZodString>;
567
+ }, z.core.$strip>, z.ZodObject<{
568
+ status: z.ZodLiteral<"rejected">;
569
+ rejection_reason: z.ZodString;
570
+ candidates: z.ZodArray<z.ZodObject<{
571
+ source: z.ZodOptional<z.ZodString>;
572
+ column: z.ZodOptional<z.ZodString>;
573
+ role: z.ZodOptional<z.ZodString>;
574
+ confidence: z.ZodOptional<z.ZodNumber>;
575
+ }, z.core.$loose>>;
576
+ explanation: z.ZodArray<z.ZodString>;
577
+ }, z.core.$strip>, z.ZodObject<{
578
+ status: z.ZodLiteral<"error">;
579
+ code: z.ZodString;
580
+ message: z.ZodString;
581
+ retryable: z.ZodBoolean;
582
+ request_id: z.ZodNullable<z.ZodString>;
583
+ nearest_matches: z.ZodOptional<z.ZodArray<z.ZodString>>;
584
+ }, z.core.$strip>]>;
585
+ declare const sourceListOutputSchema: z.ZodObject<{
586
+ sources: z.ZodArray<z.ZodObject<{
587
+ name: z.ZodString;
588
+ fields: z.ZodArray<z.ZodObject<{
589
+ name: z.ZodString;
590
+ type: z.ZodString;
591
+ ops: z.ZodArray<z.ZodString>;
592
+ }, z.core.$strip>>;
593
+ row_count: z.ZodNullable<z.ZodNumber>;
594
+ schema_revision: z.ZodNullable<z.ZodString>;
595
+ }, z.core.$strip>>;
596
+ }, z.core.$strip>;
597
+ declare const moduleListOutputSchema: z.ZodObject<{
598
+ modules: z.ZodArray<z.ZodObject<{
599
+ name: z.ZodString;
600
+ category: z.ZodString;
601
+ deterministic: z.ZodBoolean;
602
+ function_count: z.ZodNumber;
603
+ sample_functions: z.ZodArray<z.ZodString>;
604
+ }, z.core.$strip>>;
605
+ }, z.core.$strip>;
606
+ declare const functionListOutputSchema: z.ZodObject<{
607
+ functions: z.ZodArray<z.ZodObject<{
608
+ name: z.ZodString;
609
+ signature: z.ZodString;
610
+ params: z.ZodArray<z.ZodObject<{
611
+ name: z.ZodString;
612
+ type: z.ZodString;
613
+ required: z.ZodBoolean;
614
+ }, z.core.$strip>>;
615
+ returns: z.ZodString;
616
+ deterministic: z.ZodBoolean;
617
+ seed_required: z.ZodBoolean;
618
+ }, z.core.$strip>>;
619
+ }, z.core.$strip>;
620
+ declare const listSourcesOutputSchema: z.ZodUnion<readonly [z.ZodObject<{
621
+ sources: z.ZodArray<z.ZodObject<{
622
+ name: z.ZodString;
623
+ fields: z.ZodArray<z.ZodObject<{
624
+ name: z.ZodString;
625
+ type: z.ZodString;
626
+ ops: z.ZodArray<z.ZodString>;
627
+ }, z.core.$strip>>;
628
+ row_count: z.ZodNullable<z.ZodNumber>;
629
+ schema_revision: z.ZodNullable<z.ZodString>;
630
+ }, z.core.$strip>>;
631
+ }, z.core.$strip>, z.ZodObject<{
632
+ modules: z.ZodArray<z.ZodObject<{
633
+ name: z.ZodString;
634
+ category: z.ZodString;
635
+ deterministic: z.ZodBoolean;
636
+ function_count: z.ZodNumber;
637
+ sample_functions: z.ZodArray<z.ZodString>;
638
+ }, z.core.$strip>>;
639
+ }, z.core.$strip>, z.ZodObject<{
640
+ functions: z.ZodArray<z.ZodObject<{
641
+ name: z.ZodString;
642
+ signature: z.ZodString;
643
+ params: z.ZodArray<z.ZodObject<{
644
+ name: z.ZodString;
645
+ type: z.ZodString;
646
+ required: z.ZodBoolean;
647
+ }, z.core.$strip>>;
648
+ returns: z.ZodString;
649
+ deterministic: z.ZodBoolean;
650
+ seed_required: z.ZodBoolean;
651
+ }, z.core.$strip>>;
652
+ }, z.core.$strip>, z.ZodObject<{
653
+ status: z.ZodLiteral<"error">;
654
+ code: z.ZodString;
655
+ message: z.ZodString;
656
+ retryable: z.ZodBoolean;
657
+ request_id: z.ZodNullable<z.ZodString>;
658
+ nearest_matches: z.ZodOptional<z.ZodArray<z.ZodString>>;
659
+ }, z.core.$strip>]>;
660
+ declare const explainQueryOkQueryOutputSchema: z.ZodObject<{
661
+ status: z.ZodLiteral<"ok">;
662
+ kind: z.ZodLiteral<"query">;
663
+ resolved_plan: z.ZodRecord<z.ZodString, z.ZodUnknown>;
664
+ plan: z.ZodArray<z.ZodString>;
665
+ plan_hash: z.ZodNullable<z.ZodString>;
666
+ confidence: z.ZodNumber;
667
+ validated: z.ZodBoolean;
668
+ }, z.core.$strip>;
669
+ declare const explainQueryOkComputationOutputSchema: z.ZodObject<{
670
+ status: z.ZodLiteral<"ok">;
671
+ kind: z.ZodLiteral<"computation">;
672
+ matched_signature: z.ZodString;
673
+ invocation_hash: z.ZodString;
674
+ seed_required: z.ZodBoolean;
675
+ }, z.core.$strip>;
676
+ declare const explainQueryOutputSchema: z.ZodUnion<readonly [z.ZodObject<{
677
+ status: z.ZodLiteral<"ok">;
678
+ kind: z.ZodLiteral<"query">;
679
+ resolved_plan: z.ZodRecord<z.ZodString, z.ZodUnknown>;
680
+ plan: z.ZodArray<z.ZodString>;
681
+ plan_hash: z.ZodNullable<z.ZodString>;
682
+ confidence: z.ZodNumber;
683
+ validated: z.ZodBoolean;
684
+ }, z.core.$strip>, z.ZodObject<{
685
+ status: z.ZodLiteral<"ok">;
686
+ kind: z.ZodLiteral<"computation">;
687
+ matched_signature: z.ZodString;
688
+ invocation_hash: z.ZodString;
689
+ seed_required: z.ZodBoolean;
690
+ }, z.core.$strip>, z.ZodObject<{
691
+ status: z.ZodLiteral<"needs_clarification">;
692
+ question: z.ZodString;
693
+ candidates: z.ZodArray<z.ZodObject<{
694
+ source: z.ZodOptional<z.ZodString>;
695
+ column: z.ZodOptional<z.ZodString>;
696
+ role: z.ZodOptional<z.ZodString>;
697
+ confidence: z.ZodOptional<z.ZodNumber>;
698
+ }, z.core.$loose>>;
699
+ explanation: z.ZodArray<z.ZodString>;
700
+ }, z.core.$strip>, z.ZodObject<{
701
+ status: z.ZodLiteral<"rejected">;
702
+ rejection_reason: z.ZodString;
703
+ candidates: z.ZodArray<z.ZodObject<{
704
+ source: z.ZodOptional<z.ZodString>;
705
+ column: z.ZodOptional<z.ZodString>;
706
+ role: z.ZodOptional<z.ZodString>;
707
+ confidence: z.ZodOptional<z.ZodNumber>;
708
+ }, z.core.$loose>>;
709
+ explanation: z.ZodArray<z.ZodString>;
710
+ }, z.core.$strip>, z.ZodObject<{
711
+ status: z.ZodLiteral<"error">;
712
+ code: z.ZodString;
713
+ message: z.ZodString;
714
+ retryable: z.ZodBoolean;
715
+ request_id: z.ZodNullable<z.ZodString>;
716
+ nearest_matches: z.ZodOptional<z.ZodArray<z.ZodString>>;
717
+ }, z.core.$strip>]>;
718
+ type QueryDataInput = z.infer<typeof queryDataInputSchema>;
719
+ type QueryDataOutput = z.infer<typeof queryDataOutputSchema>;
720
+ type ListSourcesInput = z.infer<typeof listSourcesInputSchema>;
721
+ type ListSourcesOutput = z.infer<typeof listSourcesOutputSchema>;
722
+ type ExplainQueryInput = z.infer<typeof explainQueryInputSchema>;
723
+ type ExplainQueryOutput = z.infer<typeof explainQueryOutputSchema>;
724
+ type ErrorOutput = z.infer<typeof errorOutputSchema>;
725
+ type ClarificationOutput = z.infer<typeof clarificationOutputSchema>;
726
+ type RejectedOutput = z.infer<typeof rejectedOutputSchema>;
727
+
728
+ /** The three SQAI tools for the Vercel AI SDK.
729
+ *
730
+ * listSources — discovery (sources, capability modules, function signatures).
731
+ * queryData — execute one query or computation intent; never throws.
732
+ * explainQuery — dry-run: resolve/verify a query, or validate a computation
733
+ * against the capability contract without executing it.
734
+ */
735
+
736
+ interface SqaiToolsOptions {
737
+ /** Pin every query to this source (spec.source still wins when provided). */
738
+ source?: string;
739
+ defaultLimit?: number;
740
+ maxExecutionRows?: number;
741
+ maxRowsToModel?: number;
742
+ maxCellsToModel?: number;
743
+ maxElementsToModel?: number;
744
+ maxBytesToModel?: number;
745
+ maxOutputBytes?: number;
746
+ }
747
+ /** One SQAI tool: an AI-SDK tool whose execute is always present. */
748
+ type SqaiTool<INPUT, OUTPUT> = Tool<INPUT, OUTPUT> & {
749
+ execute: NonNullable<Tool<INPUT, OUTPUT>["execute"]>;
750
+ };
751
+ /** Index signature keeps this assignable to the AI SDK's ToolSet, so
752
+ * `tools: sqai.tools()` works with no cast. */
753
+ interface SqaiToolSet extends Record<string, Tool> {
754
+ listSources: SqaiTool<ListSourcesInput, ListSourcesOutput>;
755
+ queryData: SqaiTool<QueryDataInput, QueryDataOutput>;
756
+ explainQuery: SqaiTool<QueryDataInput, ExplainQueryOutput>;
757
+ }
758
+ declare function createSqaiTools(toolkit: SQAIToolkit, options?: SqaiToolsOptions): SqaiToolSet;
759
+
760
+ /** SQAIToolkit: an SQAI client plus declarative sources and AI-SDK tools.
761
+ *
762
+ * Sources connect lazily — on first `ready` access or first tool call. The
763
+ * connection promise gets a rejection handler the moment it is created, so a
764
+ * failed connect never surfaces as an unhandled rejection: every tool call
765
+ * reports the stored failure as a structured error result instead. */
766
+
767
+ type SqaiSourceInput = string | Array<Record<string, unknown>> | {
768
+ data: string | Array<Record<string, unknown>>;
769
+ name?: string;
770
+ };
771
+ interface SqaiToolkitConfig extends SqaiConfig {
772
+ /** Sources to connect lazily on first tool call / `ready` access. */
773
+ sources?: SqaiSourceInput[];
774
+ }
775
+ declare class SQAIToolkit {
776
+ readonly client: SQAI;
777
+ private readonly sourceInputs;
778
+ private readyPromise;
779
+ private readyError;
780
+ constructor(config?: SqaiToolkitConfig);
781
+ /** Connected sources; connecting starts on first access. */
782
+ get ready(): Promise<SqaiSource[]>;
783
+ /** The stored connection failure, when `ready` rejected. */
784
+ get connectionError(): SqaiError | null;
785
+ ensureReady(): Promise<SqaiSource[]>;
786
+ connect(source: string | Array<Record<string, unknown>> | Record<string, unknown>, options?: {
787
+ name?: string;
788
+ }): Promise<SqaiSource>;
789
+ tools(options?: SqaiToolsOptions): SqaiToolSet;
790
+ private connectAll;
791
+ }
792
+ declare function createSQAI(config?: SqaiToolkitConfig): SQAIToolkit;
793
+
794
+ /** Model-context shaping: what the model sees is a truncated, well-labeled
795
+ * projection; the full result is stored (subject to maxOutputBytes) and
796
+ * retrievable by result_id. Truncation is always declared, never silent. */
797
+
798
+ type Cell = number | string | boolean | null;
799
+ interface ShapedQueryResult {
800
+ data: {
801
+ columns: string[];
802
+ rows: Cell[][];
803
+ };
804
+ total_rows: number;
805
+ returned_rows: number;
806
+ truncated: boolean;
807
+ }
808
+ interface QueryShapingOptions {
809
+ maxRowsToModel: number;
810
+ maxCellsToModel: number;
811
+ }
812
+ /** Shape a query-plane result (scalar or array of row records) into a compact
813
+ * columns/rows table. Truncation is rows-first, then whole rows are dropped
814
+ * until the cell budget fits — a partial row is never shown. */
815
+ declare function shapeQueryResult(result: unknown, options: QueryShapingOptions): ShapedQueryResult;
816
+ interface ShapedComputationValue {
817
+ value: AlgentaWireValue;
818
+ preview?: AlgentaWireValue;
819
+ element_count?: number;
820
+ truncated: boolean;
821
+ }
822
+ interface ComputationShapingOptions {
823
+ maxElementsToModel: number;
824
+ maxBytesToModel: number;
825
+ }
826
+ /** Shape a computation-plane value for the model context.
827
+ *
828
+ * Scalars pass through. Arrays/matrices surface as a `preview` of leading
829
+ * elements (element_count = full count), halved until the byte budget fits.
830
+ * Objects pass unless they exceed the byte budget — then the model gets only
831
+ * the truncated flag and (from the caller) a result_id. */
832
+ declare function shapeComputationValue(value: AlgentaWireValue, options: ComputationShapingOptions): ShapedComputationValue;
833
+ /** Hard cap on what gets STORED: if the full value's JSON exceeds
834
+ * maxOutputBytes, nothing is stored and there is no result_id. */
835
+ declare function storeWithinCap(value: unknown, maxOutputBytes: number, store: (value: unknown) => string): string | undefined;
836
+
837
+ export { type Cell, type ClarificationOutput, type ComputationShapingOptions, type ErrorOutput, type ExplainQueryInput, type ExplainQueryOutput, type ListSourcesInput, type ListSourcesOutput, type QueryDataInput, type QueryDataOutput, type QueryShapingOptions, type RejectedOutput, SQAIToolkit, type ShapedComputationValue, type ShapedQueryResult, type SqaiSourceInput, type SqaiToolSet, type SqaiToolkitConfig, type SqaiToolsOptions, algentaWireValueSchema, bindingProvenanceSchema, candidateSchema, clarificationOutputSchema, computationBindingSchema, computationOkOutputSchema, computationSpecSchema, createSQAI, createSqaiTools, determinismEnvelopeSchema, errorOutputSchema, explainQueryInputSchema, explainQueryOkComputationOutputSchema, explainQueryOkQueryOutputSchema, explainQueryOutputSchema, filterConditionSchema, filterSpecSchema, functionListOutputSchema, listSourcesInputSchema, listSourcesOutputSchema, moduleListOutputSchema, queryDataInputSchema, queryDataOutputSchema, queryOkOutputSchema, querySpecSchema, rejectedOutputSchema, shapeComputationValue, shapeQueryResult, sourceListOutputSchema, storeWithinCap };