@thyn-ai/sqai 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.
- package/LICENSE +202 -0
- package/dist/index.cjs +1965 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +555 -0
- package/dist/index.d.ts +555 -0
- package/dist/index.js +1925 -0
- package/dist/index.js.map +1 -0
- package/dist/unsafe.cjs +38 -0
- package/dist/unsafe.cjs.map +1 -0
- package/dist/unsafe.d.cts +20 -0
- package/dist/unsafe.d.ts +20 -0
- package/dist/unsafe.js +13 -0
- package/dist/unsafe.js.map +1 -0
- package/package.json +60 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
import { MojoRuntimeConfig, MojoRuntime, QueryResponse, ResolveResponse, Runtime, ResolvedPlan, QueryWithMetadataResponse, VerifyResponse } from 'algenta-sdk';
|
|
2
|
+
export { QueryResponse, ResolveResponse, ResolvedPlan } from 'algenta-sdk';
|
|
3
|
+
|
|
4
|
+
/** Capability contract: the generated, hash-pinned inventory of everything
|
|
5
|
+
* SQAI exposes. Loaded from the vendored contracts/algenta-capabilities.json
|
|
6
|
+
* (synced hash-verified from the decision-engine generator). SQAI keeps no
|
|
7
|
+
* handwritten operation lists — this file is the only authority. */
|
|
8
|
+
interface CapabilitySignatureParam {
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
}
|
|
12
|
+
interface CapabilityEntry {
|
|
13
|
+
name: string;
|
|
14
|
+
category: "query" | "aggregation" | "scalar_math" | "statistical" | "financial" | "datetime" | "vector_matrix" | "transformation" | "simulation" | "unsupported_internal" | "non_deterministic" | "write";
|
|
15
|
+
deterministic: boolean;
|
|
16
|
+
deterministic_when_seeded?: boolean;
|
|
17
|
+
seed_required?: boolean;
|
|
18
|
+
read_only: boolean;
|
|
19
|
+
typescript: boolean;
|
|
20
|
+
python: boolean;
|
|
21
|
+
ai_sdk: boolean;
|
|
22
|
+
summary?: string;
|
|
23
|
+
signature: {
|
|
24
|
+
params: CapabilitySignatureParam[];
|
|
25
|
+
returns: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
interface CapabilityContract {
|
|
29
|
+
schema_version: number;
|
|
30
|
+
algenta_sdk_version: string;
|
|
31
|
+
algenta_core_version: string;
|
|
32
|
+
query_spec_version: string;
|
|
33
|
+
capability_contract_hash: string;
|
|
34
|
+
runtime_bundle: {
|
|
35
|
+
version: string;
|
|
36
|
+
platforms: Record<string, {
|
|
37
|
+
sha256: string;
|
|
38
|
+
url: string;
|
|
39
|
+
}>;
|
|
40
|
+
};
|
|
41
|
+
filter_operators?: string[];
|
|
42
|
+
time_filters?: string[];
|
|
43
|
+
capabilities: CapabilityEntry[];
|
|
44
|
+
}
|
|
45
|
+
interface CapabilityMatch {
|
|
46
|
+
entry: CapabilityEntry;
|
|
47
|
+
score: number;
|
|
48
|
+
}
|
|
49
|
+
/** all-readonly = (read_only AND deterministic) OR
|
|
50
|
+
* (read_only AND deterministic_when_seeded AND seed present) —
|
|
51
|
+
* seed presence is checked at validation time; this predicate answers whether
|
|
52
|
+
* the capability is ever eligible. */
|
|
53
|
+
declare function isReadOnlyEligible(entry: CapabilityEntry): boolean;
|
|
54
|
+
declare class ContractIndex {
|
|
55
|
+
readonly contract: CapabilityContract;
|
|
56
|
+
private readonly byName;
|
|
57
|
+
constructor(contract: CapabilityContract);
|
|
58
|
+
get(name: string): CapabilityEntry | undefined;
|
|
59
|
+
has(name: string): boolean;
|
|
60
|
+
/** Nearest capability names by token-normalized edit affinity — used for
|
|
61
|
+
* unsupported_operation remediation. */
|
|
62
|
+
nearest(name: string, limit?: number): string[];
|
|
63
|
+
search(query: string, limit?: number): CapabilityMatch[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** SQAI_* environment mapping and zero-config mode inference.
|
|
67
|
+
*
|
|
68
|
+
* Inference order (explicit config always overrides):
|
|
69
|
+
* SQAI_ENGINE_URL present -> "self_hosted"
|
|
70
|
+
* SQAI_API_KEY present -> "api"
|
|
71
|
+
* otherwise -> "local"
|
|
72
|
+
*/
|
|
73
|
+
type SqaiMode = "local" | "api" | "self_hosted";
|
|
74
|
+
|
|
75
|
+
/** Application policy: pre-execution validation the model can never override.
|
|
76
|
+
*
|
|
77
|
+
* SQAI validates; Algenta calculates. Package capability = the contract's
|
|
78
|
+
* all-readonly surface; application policy = the subset enabled here; a model
|
|
79
|
+
* request = one operation inside that subset.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
interface SqaiPolicy {
|
|
83
|
+
allowedSources?: string[];
|
|
84
|
+
/** Per-source field allowlist. */
|
|
85
|
+
allowedFields?: Record<string, string[]>;
|
|
86
|
+
/** "all-readonly" (default) or explicit "module.function" ids. */
|
|
87
|
+
allowedFunctions?: "all-readonly" | string[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Embedded trust root for signed managed-runtime bundles.
|
|
91
|
+
*
|
|
92
|
+
* The provisioner only installs bundles whose manifest signature (RS256 —
|
|
93
|
+
* RSASSA-PKCS1-v1_5 + SHA-256 over the exact shipped manifest bytes) verifies
|
|
94
|
+
* against one of these keys. Revocation and rollback protection live here so
|
|
95
|
+
* a single release-process edit rotates the whole trust posture:
|
|
96
|
+
*
|
|
97
|
+
* - TRUSTED_KEYS the accepted verification keys (key_id + PEM)
|
|
98
|
+
* - REVOKED_KEY_IDS key_ids that must never verify again
|
|
99
|
+
* - MIN_ACCEPTED_RUNTIME_VERSION
|
|
100
|
+
* the rollback floor: bundle manifests whose
|
|
101
|
+
* runtime_bundle_version compares below this are
|
|
102
|
+
* rejected (reason `rollback_protected`)
|
|
103
|
+
*
|
|
104
|
+
* Tests (and the release process) can override every value through
|
|
105
|
+
* RuntimeProvisioner options — nothing here is reachable from user input.
|
|
106
|
+
*/
|
|
107
|
+
interface TrustedKey {
|
|
108
|
+
key_id: string;
|
|
109
|
+
algorithm: "RS256";
|
|
110
|
+
public_key_pem: string;
|
|
111
|
+
/** ISO-8601 instant; key is not accepted before it. */
|
|
112
|
+
valid_from?: string;
|
|
113
|
+
/** ISO-8601 instant; key is not accepted after it. */
|
|
114
|
+
valid_to?: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Managed-runtime provisioning: zero-setup for the computation plane.
|
|
118
|
+
*
|
|
119
|
+
* The query plane never touches this module. On first computation-plane call:
|
|
120
|
+
* 1. Reuse a healthy daemon whose version matches the contract pin.
|
|
121
|
+
* 2. Otherwise verify + spawn the installed bundle for this platform.
|
|
122
|
+
* 3. Otherwise download the contract-pinned bundle (tarball sha256 + RS256
|
|
123
|
+
* manifest against the embedded trust root — see runtime/trust.ts and
|
|
124
|
+
* runtime/bundle.ts), extract atomically, spawn.
|
|
125
|
+
*
|
|
126
|
+
* Concurrency hardening: a per-version lock file (`<cacheDir>/<version>.lock`
|
|
127
|
+
* with `{pid, created_at}`) serializes installers across processes — fresh
|
|
128
|
+
* locks are poll-waited (max 90s) while re-checking for a completed install,
|
|
129
|
+
* stale locks (>10 min) are removed. Downloads land in `tmp-<random>` names,
|
|
130
|
+
* verification happens BEFORE extraction, extraction lands in a `tmp-<random>`
|
|
131
|
+
* directory that is atomically renamed into place, and every failure cleans
|
|
132
|
+
* its temp state — a partial install is never left behind.
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
interface RuntimeStatus {
|
|
136
|
+
available: boolean;
|
|
137
|
+
runtime_available: boolean;
|
|
138
|
+
engine: string | null;
|
|
139
|
+
module_count: number;
|
|
140
|
+
platform: string;
|
|
141
|
+
managed: boolean;
|
|
142
|
+
}
|
|
143
|
+
interface ProvisionerOptions {
|
|
144
|
+
contract: CapabilityContract;
|
|
145
|
+
autoInstall: boolean;
|
|
146
|
+
/** Injection points for tests. */
|
|
147
|
+
runtimeFactory?: (config?: MojoRuntimeConfig) => MojoRuntime;
|
|
148
|
+
downloadBundle?: (url: string, destination: string) => Promise<void>;
|
|
149
|
+
/** Bundle cache directory (default: OS user cache — runtimeCacheDir()). */
|
|
150
|
+
cacheDir?: string;
|
|
151
|
+
/** Trust-root overrides (default: the embedded trust root). */
|
|
152
|
+
trustedKeys?: TrustedKey[];
|
|
153
|
+
revokedKeyIds?: string[];
|
|
154
|
+
minAcceptedRuntimeVersion?: string;
|
|
155
|
+
/** Lock policy overrides. */
|
|
156
|
+
lockFreshMs?: number;
|
|
157
|
+
lockWaitTimeoutMs?: number;
|
|
158
|
+
lockPollIntervalMs?: number;
|
|
159
|
+
}
|
|
160
|
+
declare function currentPlatformKey(): string;
|
|
161
|
+
declare function runtimeCacheDir(): string;
|
|
162
|
+
declare class RuntimeProvisioner {
|
|
163
|
+
private readonly options;
|
|
164
|
+
private readonly trustRoot;
|
|
165
|
+
private runtime;
|
|
166
|
+
private ensurePromise;
|
|
167
|
+
constructor(options: ProvisionerOptions);
|
|
168
|
+
/** Lazily resolve a usable runtime; concurrent callers share one attempt. */
|
|
169
|
+
ensure(): Promise<MojoRuntime>;
|
|
170
|
+
status(): Promise<RuntimeStatus>;
|
|
171
|
+
stop(): Promise<void>;
|
|
172
|
+
private newRuntime;
|
|
173
|
+
private cacheDir;
|
|
174
|
+
private doEnsure;
|
|
175
|
+
private provisionError;
|
|
176
|
+
private wrapVerificationError;
|
|
177
|
+
private manifestExpectations;
|
|
178
|
+
/** Verify an existing install if present; returns null when absent/invalid. */
|
|
179
|
+
private verifiedInstallOrNull;
|
|
180
|
+
private acquireLock;
|
|
181
|
+
private lockIsStale;
|
|
182
|
+
/** Serialize installers on `<cacheDir>/<version>.lock`; returns the verified install. */
|
|
183
|
+
private ensureInstalled;
|
|
184
|
+
/** Holder-of-the-lock path: download → verify → extract → atomic rename. */
|
|
185
|
+
private downloadVerifyExtract;
|
|
186
|
+
/** Spawn the installed bundle's daemon through MojoRuntime autoStart. */
|
|
187
|
+
private spawnInstalled;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Public SQAI types.
|
|
191
|
+
*
|
|
192
|
+
* Vocabulary rule: Algenta envelope field names pass through verbatim
|
|
193
|
+
* (plan_hash, schema_revision, intent_signature, deterministic_scope,
|
|
194
|
+
* decision_path, validated, engine_used, ...). SQAI never invents parallel
|
|
195
|
+
* names for the same concept.
|
|
196
|
+
*/
|
|
197
|
+
|
|
198
|
+
/** Contract-derived wire value: everything the computation plane can
|
|
199
|
+
* transport. The wire schema transports; the capability contract authorizes. */
|
|
200
|
+
type AlgentaWireValue = null | boolean | number | string | AlgentaWireValue[] | {
|
|
201
|
+
[key: string]: AlgentaWireValue;
|
|
202
|
+
} | {
|
|
203
|
+
type: "decimal" | "bigint";
|
|
204
|
+
value: string;
|
|
205
|
+
};
|
|
206
|
+
interface SqaiSource {
|
|
207
|
+
name: string;
|
|
208
|
+
source_id: string | null;
|
|
209
|
+
dataset_id: string | null;
|
|
210
|
+
fields: string[];
|
|
211
|
+
typed_fields: Array<{
|
|
212
|
+
name: string;
|
|
213
|
+
type: string;
|
|
214
|
+
}>;
|
|
215
|
+
row_count: number | null;
|
|
216
|
+
schema_revision: string | null;
|
|
217
|
+
status: string;
|
|
218
|
+
}
|
|
219
|
+
interface QueryFilterCondition {
|
|
220
|
+
column?: string;
|
|
221
|
+
dimension_hint?: string;
|
|
222
|
+
op: "eq" | "in" | "gt" | "gte" | "lt" | "lte" | "is_null" | "is_not_null";
|
|
223
|
+
value?: string | number | boolean;
|
|
224
|
+
values?: Array<string | number | boolean>;
|
|
225
|
+
}
|
|
226
|
+
interface QueryFilterSpec {
|
|
227
|
+
time_filter?: string;
|
|
228
|
+
conditions?: QueryFilterCondition[];
|
|
229
|
+
}
|
|
230
|
+
/** The caller/model-authored resolve-spec — Algenta names verbatim. */
|
|
231
|
+
interface QuerySpec {
|
|
232
|
+
metric: string;
|
|
233
|
+
aggregation?: "sum" | "avg" | "count" | "min" | "max";
|
|
234
|
+
group_by?: string;
|
|
235
|
+
filter?: QueryFilterSpec;
|
|
236
|
+
limit?: number;
|
|
237
|
+
order?: "asc" | "desc";
|
|
238
|
+
source_name?: string;
|
|
239
|
+
}
|
|
240
|
+
type ComputationBinding = {
|
|
241
|
+
parameter: string | number;
|
|
242
|
+
source: string;
|
|
243
|
+
field: string;
|
|
244
|
+
filter?: QueryFilterSpec;
|
|
245
|
+
} | {
|
|
246
|
+
parameters: Array<string | number>;
|
|
247
|
+
source: string;
|
|
248
|
+
fields: string[];
|
|
249
|
+
filter?: QueryFilterSpec;
|
|
250
|
+
alignment: "rowwise";
|
|
251
|
+
nullPolicy?: "pairwise" | "preserve";
|
|
252
|
+
};
|
|
253
|
+
interface ComputationSpec {
|
|
254
|
+
module: string;
|
|
255
|
+
function: string;
|
|
256
|
+
args?: AlgentaWireValue[];
|
|
257
|
+
kwargs?: Record<string, AlgentaWireValue>;
|
|
258
|
+
bindings?: ComputationBinding[];
|
|
259
|
+
seed?: number | string;
|
|
260
|
+
}
|
|
261
|
+
type SqaiIntent = {
|
|
262
|
+
version: "1";
|
|
263
|
+
kind: "query";
|
|
264
|
+
spec: QuerySpec;
|
|
265
|
+
} | {
|
|
266
|
+
version: "1";
|
|
267
|
+
kind: "computation";
|
|
268
|
+
spec: ComputationSpec;
|
|
269
|
+
};
|
|
270
|
+
interface DeterminismEnvelope {
|
|
271
|
+
runtime_bundle_version: string;
|
|
272
|
+
runtime_bundle_sha256: string;
|
|
273
|
+
platform: string;
|
|
274
|
+
architecture: string;
|
|
275
|
+
kernel_build: string;
|
|
276
|
+
precision_mode: string;
|
|
277
|
+
thread_count: number;
|
|
278
|
+
seed?: number | string;
|
|
279
|
+
input_hash: string;
|
|
280
|
+
}
|
|
281
|
+
interface BindingProvenance {
|
|
282
|
+
source_name: string;
|
|
283
|
+
fields: string[];
|
|
284
|
+
schema_revision: string | null;
|
|
285
|
+
row_count: number;
|
|
286
|
+
input_hash: string;
|
|
287
|
+
}
|
|
288
|
+
interface ComputeResult {
|
|
289
|
+
status: "ok";
|
|
290
|
+
value: AlgentaWireValue;
|
|
291
|
+
value_type: string;
|
|
292
|
+
module: string;
|
|
293
|
+
function: string;
|
|
294
|
+
seed?: number | string;
|
|
295
|
+
invocation_hash: string;
|
|
296
|
+
computation_hash: string;
|
|
297
|
+
contract_hash: string;
|
|
298
|
+
determinism: DeterminismEnvelope;
|
|
299
|
+
provenance?: {
|
|
300
|
+
bindings: BindingProvenance[];
|
|
301
|
+
};
|
|
302
|
+
latency_ms: number;
|
|
303
|
+
request_id: string;
|
|
304
|
+
}
|
|
305
|
+
type AskOutcome = {
|
|
306
|
+
status: "ok";
|
|
307
|
+
data: QueryResponse;
|
|
308
|
+
resolution: ResolveResponse;
|
|
309
|
+
} | {
|
|
310
|
+
status: "needs_clarification";
|
|
311
|
+
resolution: ResolveResponse;
|
|
312
|
+
} | {
|
|
313
|
+
status: "rejected";
|
|
314
|
+
resolution: ResolveResponse;
|
|
315
|
+
};
|
|
316
|
+
type SqaiOutcome = {
|
|
317
|
+
kind: "query";
|
|
318
|
+
outcome: AskOutcome;
|
|
319
|
+
} | {
|
|
320
|
+
kind: "computation";
|
|
321
|
+
outcome: ComputeResult;
|
|
322
|
+
};
|
|
323
|
+
interface ColumnExtract {
|
|
324
|
+
columns: Record<string, Array<number | null>>;
|
|
325
|
+
row_count: number;
|
|
326
|
+
source_name: string;
|
|
327
|
+
schema_revision: string | null;
|
|
328
|
+
alignment: "rowwise";
|
|
329
|
+
input_hash: string;
|
|
330
|
+
}
|
|
331
|
+
interface SqaiResultRecord {
|
|
332
|
+
result_id: string;
|
|
333
|
+
tenant_id: string | null;
|
|
334
|
+
source_ids: string[];
|
|
335
|
+
created_at: number;
|
|
336
|
+
expires_at: number;
|
|
337
|
+
byte_size: number;
|
|
338
|
+
value: unknown;
|
|
339
|
+
}
|
|
340
|
+
interface ResultStoreConfig {
|
|
341
|
+
ttlMs?: number;
|
|
342
|
+
maxResultCount?: number;
|
|
343
|
+
maxStoredResultBytes?: number;
|
|
344
|
+
maxTenantResultBytes?: number;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** Computation dispatch: delegate a validated computation to Algenta.
|
|
348
|
+
*
|
|
349
|
+
* Local mode → the managed runtime daemon via algenta-sdk's MojoRuntime.
|
|
350
|
+
* self_hosted / api mode → POST {baseUrl}/v1/libraries/execute.
|
|
351
|
+
* SQAI performs no calculation of its own in either path.
|
|
352
|
+
*/
|
|
353
|
+
|
|
354
|
+
type DispatchTarget = {
|
|
355
|
+
kind: "local";
|
|
356
|
+
runtime: MojoRuntime;
|
|
357
|
+
} | {
|
|
358
|
+
kind: "http";
|
|
359
|
+
baseUrl: string;
|
|
360
|
+
apiKey?: string;
|
|
361
|
+
fetchImpl?: typeof fetch;
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
/** The SQAI client: a thin, policy-checked facade over the Algenta runtime.
|
|
365
|
+
*
|
|
366
|
+
* Query plane — connect / resolve / query / verify / ask, in-process.
|
|
367
|
+
* Computation — validate against the capability contract, resolve bindings
|
|
368
|
+
* through the upstream aligned extraction primitive, delegate
|
|
369
|
+
* to the managed runtime, pass results through verbatim.
|
|
370
|
+
*
|
|
371
|
+
* SQAI reimplements nothing: every discrepancy is fixed upstream in Algenta.
|
|
372
|
+
*/
|
|
373
|
+
|
|
374
|
+
interface SqaiConfig {
|
|
375
|
+
mode?: SqaiMode;
|
|
376
|
+
apiKey?: string;
|
|
377
|
+
engineUrl?: string;
|
|
378
|
+
tenantId?: string;
|
|
379
|
+
policy?: SqaiPolicy;
|
|
380
|
+
enforceLimits?: boolean;
|
|
381
|
+
/** Milliseconds. Applies to HTTP transport AND, on the computation plane,
|
|
382
|
+
* rides to the daemon as an enforced per-request timeout (it can lower the
|
|
383
|
+
* daemon's ceiling, never raise it) — never advisory. */
|
|
384
|
+
timeout?: number;
|
|
385
|
+
maxRetries?: number;
|
|
386
|
+
resultStore?: ResultStoreConfig;
|
|
387
|
+
/** BYO substrate (tests). */
|
|
388
|
+
runtime?: Runtime;
|
|
389
|
+
/** BYO computation dispatch target (tests / custom self-hosted engines). */
|
|
390
|
+
computeTarget?: DispatchTarget;
|
|
391
|
+
}
|
|
392
|
+
declare class SQAI {
|
|
393
|
+
readonly mode: SqaiMode;
|
|
394
|
+
private readonly algentaRuntime;
|
|
395
|
+
private readonly rawRuntime;
|
|
396
|
+
private readonly policy;
|
|
397
|
+
private readonly tenantId;
|
|
398
|
+
private readonly engineUrl;
|
|
399
|
+
private readonly apiKey;
|
|
400
|
+
private readonly contractIndex;
|
|
401
|
+
private readonly resultStore;
|
|
402
|
+
private readonly provisioner;
|
|
403
|
+
private readonly configuredTarget;
|
|
404
|
+
private readonly timeoutMs;
|
|
405
|
+
private readonly sources;
|
|
406
|
+
constructor(config?: SqaiConfig);
|
|
407
|
+
connect(source: string | Array<Record<string, unknown>> | Record<string, unknown>, options?: {
|
|
408
|
+
name?: string;
|
|
409
|
+
}): Promise<SqaiSource>;
|
|
410
|
+
listSources(): SqaiSource[];
|
|
411
|
+
resolve(spec: QuerySpec): Promise<ResolveResponse>;
|
|
412
|
+
query(plan: ResolvedPlan | ResolveResponse): Promise<QueryResponse>;
|
|
413
|
+
queryWithMetadata(plan: ResolvedPlan | ResolveResponse): Promise<QueryWithMetadataResponse>;
|
|
414
|
+
verify(plan: ResolvedPlan | ResolveResponse): Promise<VerifyResponse>;
|
|
415
|
+
ask(spec: QuerySpec): Promise<AskOutcome>;
|
|
416
|
+
extractColumns(sourceName: string, columns: string[], options?: {
|
|
417
|
+
filter?: Record<string, unknown>;
|
|
418
|
+
limit?: number;
|
|
419
|
+
nullPolicy?: "pairwise" | "preserve";
|
|
420
|
+
}): Promise<ColumnExtract>;
|
|
421
|
+
compute(spec: ComputationSpec): Promise<ComputeResult>;
|
|
422
|
+
run(intent: SqaiIntent): Promise<SqaiOutcome>;
|
|
423
|
+
capabilities(): CapabilityContract;
|
|
424
|
+
searchCapabilities(query: string, limit?: number): CapabilityMatch[];
|
|
425
|
+
storeResult(value: unknown, sourceIds?: string[]): string;
|
|
426
|
+
getResult(resultId: string): SqaiResultRecord;
|
|
427
|
+
deleteResult(resultId: string): void;
|
|
428
|
+
readonly runtime: {
|
|
429
|
+
status: () => Promise<RuntimeStatus>;
|
|
430
|
+
ensure: () => Promise<void>;
|
|
431
|
+
stop: () => Promise<void>;
|
|
432
|
+
};
|
|
433
|
+
private checkQueryPolicy;
|
|
434
|
+
private dispatchTarget;
|
|
435
|
+
private resolveBindings;
|
|
436
|
+
}
|
|
437
|
+
declare function createSQAI(config?: SqaiConfig): SQAI;
|
|
438
|
+
|
|
439
|
+
/** SQAI failure contract.
|
|
440
|
+
*
|
|
441
|
+
* Algenta error codes pass through verbatim (`source: "algenta"`); SQAI adds
|
|
442
|
+
* its own codes in the same snake_case vocabulary (`source: "sqai"`). A code
|
|
443
|
+
* is never renamed and the same condition never gets two codes.
|
|
444
|
+
*/
|
|
445
|
+
type SqaiErrorSource = "algenta" | "sqai";
|
|
446
|
+
interface SqaiErrorOptions {
|
|
447
|
+
retryable?: boolean;
|
|
448
|
+
requestId?: string | null;
|
|
449
|
+
source?: SqaiErrorSource;
|
|
450
|
+
details?: Record<string, unknown>;
|
|
451
|
+
}
|
|
452
|
+
declare class SqaiError extends Error {
|
|
453
|
+
readonly code: string;
|
|
454
|
+
readonly retryable: boolean;
|
|
455
|
+
readonly requestId: string | null;
|
|
456
|
+
readonly source: SqaiErrorSource;
|
|
457
|
+
readonly details: Record<string, unknown>;
|
|
458
|
+
constructor(code: string, message: string, options?: SqaiErrorOptions);
|
|
459
|
+
toResult(): {
|
|
460
|
+
status: "error";
|
|
461
|
+
code: string;
|
|
462
|
+
message: string;
|
|
463
|
+
retryable: boolean;
|
|
464
|
+
request_id: string | null;
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
/** Codes SQAI adds on top of the Algenta vocabulary. */
|
|
468
|
+
declare const SQAI_ERROR_CODES: readonly ["unsupported_operation", "seed_required", "duplicate_argument_binding", "policy_denied_source", "policy_denied_field", "policy_denied_function", "source_already_registered", "runtime_provision_failed", "daemon_port_conflict", "unsupported_platform", "compute_runtime_unavailable", "result_not_found", "contract_mismatch", "invalid_intent"];
|
|
469
|
+
|
|
470
|
+
/** Two-hash determinism contract.
|
|
471
|
+
*
|
|
472
|
+
* invocation_hash — known BEFORE execution: the normalized operation identity
|
|
473
|
+
* (module, function, args, kwargs, resolved bindings, seed, contract hash,
|
|
474
|
+
* input hashes, declared execution scope). `explainQuery` returns this one.
|
|
475
|
+
*
|
|
476
|
+
* computation_hash — known only AFTER execution: invocation_hash plus the
|
|
477
|
+
* canonically serialized result.
|
|
478
|
+
*
|
|
479
|
+
* Both are domain-separated and rendered with the cross-language canonical
|
|
480
|
+
* JSON (algenta-sdk canonicalJson === algenta-core canonical_json, locked by
|
|
481
|
+
* the upstream conformance suite), so TypeScript and Python produce identical
|
|
482
|
+
* hashes for identical work.
|
|
483
|
+
*/
|
|
484
|
+
|
|
485
|
+
interface InvocationIdentity {
|
|
486
|
+
module: string;
|
|
487
|
+
function: string;
|
|
488
|
+
args: AlgentaWireValue[];
|
|
489
|
+
kwargs: Record<string, AlgentaWireValue>;
|
|
490
|
+
resolved_bindings: Array<{
|
|
491
|
+
parameter: string | number;
|
|
492
|
+
source_name: string;
|
|
493
|
+
fields: string[];
|
|
494
|
+
input_hash: string;
|
|
495
|
+
}>;
|
|
496
|
+
seed: number | string | null;
|
|
497
|
+
contract_hash: string;
|
|
498
|
+
execution_scope: string;
|
|
499
|
+
}
|
|
500
|
+
declare function invocationHash(identity: InvocationIdentity): string;
|
|
501
|
+
declare function computationHash(invocation: string, result: unknown): string;
|
|
502
|
+
|
|
503
|
+
/** Opaque, authorized result store.
|
|
504
|
+
*
|
|
505
|
+
* result_id is random (never derived from tenant/source/schema/hash material),
|
|
506
|
+
* so the identifier is unlinkable and reveals nothing — including whether a
|
|
507
|
+
* result exists. Authorization is enforced through stored tenant metadata:
|
|
508
|
+
* a lookup from the wrong tenant returns the same result_not_found as a
|
|
509
|
+
* missing id.
|
|
510
|
+
*/
|
|
511
|
+
|
|
512
|
+
declare class ResultStore {
|
|
513
|
+
private readonly config;
|
|
514
|
+
private readonly records;
|
|
515
|
+
private totalBytes;
|
|
516
|
+
constructor(config?: ResultStoreConfig);
|
|
517
|
+
store(value: unknown, options: {
|
|
518
|
+
tenantId: string | null;
|
|
519
|
+
sourceIds: string[];
|
|
520
|
+
}): string;
|
|
521
|
+
get(resultId: string, tenantId: string | null): SqaiResultRecord;
|
|
522
|
+
delete(resultId: string, tenantId: string | null): void;
|
|
523
|
+
private tenantBytes;
|
|
524
|
+
private evictExpired;
|
|
525
|
+
private evictOldest;
|
|
526
|
+
private evictOldestForTenant;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Computation-plane validation: dynamic, against the embedded capability
|
|
530
|
+
* contract. The zod wire schema (in @thyn-ai/sqai-ai-sdk) only transports values;
|
|
531
|
+
* everything here authorizes them. SQAI computes nothing — a validated
|
|
532
|
+
* computation is delegated to Algenta verbatim.
|
|
533
|
+
*
|
|
534
|
+
* Argument assembly: every signature parameter is supplied through EXACTLY one
|
|
535
|
+
* of args (positional), kwargs (by name), or bindings (by name or index).
|
|
536
|
+
* Duplicate assignment is `duplicate_argument_binding`; SQAI never silently
|
|
537
|
+
* overwrites an argument.
|
|
538
|
+
*/
|
|
539
|
+
|
|
540
|
+
interface ResolvedBindingValue {
|
|
541
|
+
parameter: string | number;
|
|
542
|
+
values: AlgentaWireValue;
|
|
543
|
+
provenance: BindingProvenance;
|
|
544
|
+
}
|
|
545
|
+
interface ValidatedComputation {
|
|
546
|
+
entry: CapabilityEntry;
|
|
547
|
+
/** Final positional argument vector, ordered by the signature params. */
|
|
548
|
+
argsVector: AlgentaWireValue[];
|
|
549
|
+
seed: number | string | null;
|
|
550
|
+
bindings: ResolvedBindingValue[];
|
|
551
|
+
}
|
|
552
|
+
declare function lookupCapability(index: ContractIndex, module: string, functionName: string): CapabilityEntry;
|
|
553
|
+
declare function validateComputation(spec: ComputationSpec, index: ContractIndex, policy: SqaiPolicy | undefined, resolvedBindings: ResolvedBindingValue[]): ValidatedComputation;
|
|
554
|
+
|
|
555
|
+
export { type AlgentaWireValue, type AskOutcome, type BindingProvenance, type CapabilityContract, type CapabilityEntry, type CapabilityMatch, type ColumnExtract, type ComputationBinding, type ComputationSpec, type ComputeResult, ContractIndex, type DeterminismEnvelope, type InvocationIdentity, type QueryFilterCondition, type QueryFilterSpec, type QuerySpec, type ResolvedBindingValue, ResultStore, type ResultStoreConfig, RuntimeProvisioner, type RuntimeStatus, SQAI, SQAI_ERROR_CODES, type SqaiConfig, SqaiError, type SqaiErrorSource, type SqaiIntent, type SqaiOutcome, type SqaiPolicy, type SqaiResultRecord, type SqaiSource, type ValidatedComputation, computationHash, createSQAI, currentPlatformKey, invocationHash, isReadOnlyEligible, lookupCapability, runtimeCacheDir, validateComputation };
|