@thyn-ai/sqai 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +24 -24
- package/dist/index.d.cts +303 -165
- package/dist/index.d.ts +303 -165
- package/dist/index.js +24 -24
- package/dist/unsafe.cjs +0 -3
- package/dist/unsafe.d.cts +3 -7
- package/dist/unsafe.d.ts +3 -7
- package/dist/unsafe.js +0 -2
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { MojoRuntimeConfig, MojoRuntime, QueryResponse, ResolveResponse, Runtime, ResolvedPlan, QueryWithMetadataResponse, VerifyResponse } from 'algenta-sdk';
|
|
2
|
-
export { QueryResponse, ResolveResponse, ResolvedPlan } from 'algenta-sdk';
|
|
3
|
-
|
|
4
1
|
/** Capability contract: the generated, hash-pinned inventory of everything
|
|
5
|
-
* SQAI exposes. Loaded from the vendored
|
|
6
|
-
* (synced hash-verified from the generator). SQAI keeps no
|
|
2
|
+
* SQAI exposes. Loaded from the vendored capability contract. SQAI keeps no
|
|
7
3
|
* handwritten operation lists — this file is the only authority. */
|
|
8
4
|
interface CapabilitySignatureParam {
|
|
9
5
|
name: string;
|
|
@@ -73,7 +69,7 @@ type SqaiMode = "local" | "api" | "deployment";
|
|
|
73
69
|
|
|
74
70
|
/** Application policy: pre-execution validation the model can never override.
|
|
75
71
|
*
|
|
76
|
-
* SQAI validates;
|
|
72
|
+
* SQAI validates; the managed runtime calculates. Package capability = the contract's
|
|
77
73
|
* all-readonly surface; application policy = the subset enabled here; a model
|
|
78
74
|
* request = one operation inside that subset.
|
|
79
75
|
*/
|
|
@@ -86,147 +82,7 @@ interface SqaiPolicy {
|
|
|
86
82
|
allowedFunctions?: "all-readonly" | string[];
|
|
87
83
|
}
|
|
88
84
|
|
|
89
|
-
/** Embedded trust root for signed managed-runtime bundles.
|
|
90
|
-
*
|
|
91
|
-
* The provisioner only installs bundles whose manifest signature (RS256 —
|
|
92
|
-
* RSASSA-PKCS1-v1_5 + SHA-256 over the exact shipped manifest bytes) verifies
|
|
93
|
-
* against one of these keys. Revocation and rollback protection live here so
|
|
94
|
-
* a single release-process edit rotates the whole trust posture:
|
|
95
|
-
*
|
|
96
|
-
* - TRUSTED_KEYS the accepted verification keys (key_id + PEM)
|
|
97
|
-
* - REVOKED_KEY_IDS key_ids that must never verify again
|
|
98
|
-
* - MIN_ACCEPTED_RUNTIME_VERSION
|
|
99
|
-
* the rollback floor: bundle manifests whose
|
|
100
|
-
* runtime_bundle_version compares below this are
|
|
101
|
-
* rejected (reason `rollback_protected`)
|
|
102
|
-
*
|
|
103
|
-
* Tests (and the release process) can override every value through
|
|
104
|
-
* RuntimeProvisioner options — nothing here is reachable from user input.
|
|
105
|
-
*/
|
|
106
|
-
interface TrustedKey {
|
|
107
|
-
key_id: string;
|
|
108
|
-
algorithm: "RS256";
|
|
109
|
-
public_key_pem: string;
|
|
110
|
-
/** ISO-8601 instant; key is not accepted before it. */
|
|
111
|
-
valid_from?: string;
|
|
112
|
-
/** ISO-8601 instant; key is not accepted after it. */
|
|
113
|
-
valid_to?: string;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** Managed-runtime provisioning: zero-setup for the computation plane.
|
|
117
|
-
*
|
|
118
|
-
* The query plane never touches this module. On first computation-plane call:
|
|
119
|
-
* 1. Reuse a healthy daemon whose version matches the contract pin.
|
|
120
|
-
* 2. Otherwise verify + spawn the installed bundle for this platform.
|
|
121
|
-
* 3. Otherwise download the contract-pinned bundle (tarball sha256 + RS256
|
|
122
|
-
* manifest against the embedded trust root — see runtime/trust.ts and
|
|
123
|
-
* runtime/bundle.ts), extract atomically, spawn.
|
|
124
|
-
*
|
|
125
|
-
* Concurrency hardening: a per-version lock file (`<cacheDir>/<version>.lock`
|
|
126
|
-
* with `{pid, created_at}`) serializes installers across processes — fresh
|
|
127
|
-
* locks are poll-waited (max 90s) while re-checking for a completed install,
|
|
128
|
-
* stale locks (>10 min) are removed. Downloads land in `tmp-<random>` names,
|
|
129
|
-
* verification happens BEFORE extraction, extraction lands in a `tmp-<random>`
|
|
130
|
-
* directory that is atomically renamed into place, and every failure cleans
|
|
131
|
-
* its temp state — a partial install is never left behind.
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
|
-
interface RuntimeStatus {
|
|
135
|
-
available: boolean;
|
|
136
|
-
runtime_available: boolean;
|
|
137
|
-
engine: string | null;
|
|
138
|
-
module_count: number;
|
|
139
|
-
platform: string;
|
|
140
|
-
managed: boolean;
|
|
141
|
-
}
|
|
142
|
-
/** A runtime bundle resolved for a specific module filter (build-on-provision). */
|
|
143
|
-
interface FilteredBundle {
|
|
144
|
-
url: string;
|
|
145
|
-
sha256: string;
|
|
146
|
-
version: string;
|
|
147
|
-
cacheKey: string;
|
|
148
|
-
}
|
|
149
|
-
interface ProvisionerOptions {
|
|
150
|
-
contract: CapabilityContract;
|
|
151
|
-
autoInstall: boolean;
|
|
152
|
-
/**
|
|
153
|
-
* Build-on-provision: the developer's module filter. All 4,762 functions are
|
|
154
|
-
* available in the contract; only the selected modules are compiled + installed.
|
|
155
|
-
* Empty/undefined → the default pinned bundle (contract.runtime_bundle).
|
|
156
|
-
*/
|
|
157
|
-
runtimeModules?: string[];
|
|
158
|
-
/** Build service that compiles a bundle for an exact filter (POST /v1/runtime/build). */
|
|
159
|
-
buildServiceUrl?: string;
|
|
160
|
-
/** Injection points for tests. */
|
|
161
|
-
runtimeFactory?: (config?: MojoRuntimeConfig) => MojoRuntime;
|
|
162
|
-
downloadBundle?: (url: string, destination: string) => Promise<void>;
|
|
163
|
-
/** Resolve a filtered bundle (default: POST to buildServiceUrl). Test injection. */
|
|
164
|
-
resolveFilteredBundle?: (modules: string[], platformKey: string) => Promise<FilteredBundle>;
|
|
165
|
-
/** Bundle cache directory (default: OS user cache — runtimeCacheDir()). */
|
|
166
|
-
cacheDir?: string;
|
|
167
|
-
/** Trust-root overrides (default: the embedded trust root). */
|
|
168
|
-
trustedKeys?: TrustedKey[];
|
|
169
|
-
revokedKeyIds?: string[];
|
|
170
|
-
minAcceptedRuntimeVersion?: string;
|
|
171
|
-
/** Lock policy overrides. */
|
|
172
|
-
lockFreshMs?: number;
|
|
173
|
-
lockWaitTimeoutMs?: number;
|
|
174
|
-
lockPollIntervalMs?: number;
|
|
175
|
-
}
|
|
176
|
-
declare function currentPlatformKey(): string;
|
|
177
|
-
declare function runtimeCacheDir(): string;
|
|
178
|
-
declare class RuntimeProvisioner {
|
|
179
|
-
private readonly options;
|
|
180
|
-
private readonly trustRoot;
|
|
181
|
-
private runtime;
|
|
182
|
-
private ensurePromise;
|
|
183
|
-
constructor(options: ProvisionerOptions);
|
|
184
|
-
/** Lazily resolve a usable runtime; concurrent callers share one attempt. */
|
|
185
|
-
ensure(): Promise<MojoRuntime>;
|
|
186
|
-
status(): Promise<RuntimeStatus>;
|
|
187
|
-
stop(): Promise<void>;
|
|
188
|
-
private newRuntime;
|
|
189
|
-
private ensureLocalLoginKey;
|
|
190
|
-
private cacheDir;
|
|
191
|
-
/** Normalized module filter (sorted, unique, non-empty) or null for the default bundle. */
|
|
192
|
-
private filterModules;
|
|
193
|
-
/** Ask the build service to compile + sign a bundle for exactly these modules. */
|
|
194
|
-
private resolveFilteredBundle;
|
|
195
|
-
/**
|
|
196
|
-
* The filter's cache key, computed IDENTICALLY to the build service
|
|
197
|
-
* (sha256("mods|platform|version")[:20], mods = sorted+unique, comma-joined).
|
|
198
|
-
* Lets the reuse fast-path find an already-running filtered daemon without a
|
|
199
|
-
* build-service round-trip. The build service's returned key is authoritative
|
|
200
|
-
* for install; this only has to match for the reuse optimization to hit.
|
|
201
|
-
*/
|
|
202
|
-
private localCacheKey;
|
|
203
|
-
/**
|
|
204
|
-
* Deterministic per-filter daemon endpoint so a filtered runtime never collides
|
|
205
|
-
* with the default (or another filter's) daemon on the shared default socket.
|
|
206
|
-
*/
|
|
207
|
-
private filterEndpoint;
|
|
208
|
-
private static readonly DAEMON_ENDPOINT_ENV;
|
|
209
|
-
/** Point the about-to-be-spawned daemon at a filter-specific socket/port/dir. */
|
|
210
|
-
private applyDaemonEndpointEnv;
|
|
211
|
-
private restoreEnv;
|
|
212
|
-
private doEnsure;
|
|
213
|
-
private provisionError;
|
|
214
|
-
private wrapVerificationError;
|
|
215
|
-
private manifestExpectations;
|
|
216
|
-
/** Verify an existing install if present; returns null when absent/invalid. */
|
|
217
|
-
private verifiedInstallOrNull;
|
|
218
|
-
private acquireLock;
|
|
219
|
-
private lockIsStale;
|
|
220
|
-
/** Serialize installers on `<cacheDir>/<installKey>.lock`; returns the verified install. */
|
|
221
|
-
private ensureInstalled;
|
|
222
|
-
/** Holder-of-the-lock path: download → verify → extract → atomic rename. */
|
|
223
|
-
private downloadVerifyExtract;
|
|
224
|
-
/** Spawn the installed bundle's daemon through MojoRuntime autoStart. */
|
|
225
|
-
private spawnInstalled;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
85
|
/** Public SQAI types. */
|
|
229
|
-
|
|
230
86
|
/** Contract-derived wire value: everything the computation plane can
|
|
231
87
|
* transport. The wire schema transports; the capability contract authorizes. */
|
|
232
88
|
type SqaiValue = null | boolean | number | string | SqaiValue[] | {
|
|
@@ -327,7 +183,132 @@ interface QueryFilterSpec {
|
|
|
327
183
|
time_filter?: string;
|
|
328
184
|
conditions?: QueryFilterCondition[];
|
|
329
185
|
}
|
|
330
|
-
|
|
186
|
+
interface QueryCandidate {
|
|
187
|
+
source: string;
|
|
188
|
+
column: string;
|
|
189
|
+
role: string;
|
|
190
|
+
magnitude?: string | null;
|
|
191
|
+
formula?: string | null;
|
|
192
|
+
confidence: number;
|
|
193
|
+
score_components?: Record<string, number>;
|
|
194
|
+
notes?: string[];
|
|
195
|
+
}
|
|
196
|
+
interface ResolvedPlan {
|
|
197
|
+
source_name: string;
|
|
198
|
+
metric_column: string;
|
|
199
|
+
aggregation: string;
|
|
200
|
+
group_column?: string | null;
|
|
201
|
+
join_path?: Record<string, unknown> | null;
|
|
202
|
+
filter?: QueryFilterSpec | null;
|
|
203
|
+
limit?: number | null;
|
|
204
|
+
order?: string;
|
|
205
|
+
constraints?: Record<string, unknown>;
|
|
206
|
+
schema_revision: string;
|
|
207
|
+
}
|
|
208
|
+
interface ResolveResponse {
|
|
209
|
+
resolved_plan?: ResolvedPlan | null;
|
|
210
|
+
confidence: number;
|
|
211
|
+
plan: string[];
|
|
212
|
+
explanation: string[];
|
|
213
|
+
resolved_column: string;
|
|
214
|
+
resolved_role: string;
|
|
215
|
+
resolved_source: string;
|
|
216
|
+
candidates: QueryCandidate[];
|
|
217
|
+
source_scores: Record<string, number>;
|
|
218
|
+
latency_ms: number;
|
|
219
|
+
decision_path: string;
|
|
220
|
+
plan_hash?: string | null;
|
|
221
|
+
schema_revision: string;
|
|
222
|
+
validated: boolean;
|
|
223
|
+
deterministic_scope: string;
|
|
224
|
+
confidence_source: string;
|
|
225
|
+
clarification_required?: boolean;
|
|
226
|
+
rejection_reason?: string | null;
|
|
227
|
+
request_id?: string | null;
|
|
228
|
+
intent_signature: string;
|
|
229
|
+
source_set?: string[];
|
|
230
|
+
join_path?: Array<Record<string, unknown>>;
|
|
231
|
+
planner_mode?: string | null;
|
|
232
|
+
}
|
|
233
|
+
interface QueryResponse {
|
|
234
|
+
query_id: string;
|
|
235
|
+
result: unknown;
|
|
236
|
+
result_type: string;
|
|
237
|
+
confidence: number;
|
|
238
|
+
plan: string[];
|
|
239
|
+
resolved_column: string;
|
|
240
|
+
resolved_role: string;
|
|
241
|
+
resolved_source: string;
|
|
242
|
+
row_count: number;
|
|
243
|
+
candidates: QueryCandidate[];
|
|
244
|
+
source_scores: Record<string, number>;
|
|
245
|
+
ambiguous: boolean;
|
|
246
|
+
exact_spec: boolean;
|
|
247
|
+
explanation: string[];
|
|
248
|
+
latency_ms: number;
|
|
249
|
+
decision_path: string;
|
|
250
|
+
plan_hash: string;
|
|
251
|
+
schema_revision?: string | null;
|
|
252
|
+
validated: boolean;
|
|
253
|
+
deterministic_scope: string;
|
|
254
|
+
confidence_source: string;
|
|
255
|
+
clarification_required?: boolean;
|
|
256
|
+
rejection_reason?: string | null;
|
|
257
|
+
request_id?: string | null;
|
|
258
|
+
source_set?: string[];
|
|
259
|
+
join_path?: Array<Record<string, unknown>>;
|
|
260
|
+
planner_mode?: string | null;
|
|
261
|
+
}
|
|
262
|
+
interface QueryExecutionMetadata {
|
|
263
|
+
request_id?: string | null;
|
|
264
|
+
latency_ms?: number | null;
|
|
265
|
+
tokens_in?: number | null;
|
|
266
|
+
tokens_out?: number | null;
|
|
267
|
+
cost_usd?: number | null;
|
|
268
|
+
cache_hit?: boolean | null;
|
|
269
|
+
}
|
|
270
|
+
interface QueryWithMetadataResponse {
|
|
271
|
+
data: QueryResponse;
|
|
272
|
+
metadata: QueryExecutionMetadata;
|
|
273
|
+
headers?: Record<string, string> | null;
|
|
274
|
+
}
|
|
275
|
+
interface VerifyResponse {
|
|
276
|
+
valid: boolean;
|
|
277
|
+
errors: string[];
|
|
278
|
+
suggestions: string[];
|
|
279
|
+
resolved: Record<string, string>;
|
|
280
|
+
valid_dimensions?: string[];
|
|
281
|
+
valid_measures?: string[];
|
|
282
|
+
source_behavior?: string;
|
|
283
|
+
latency_ms: number;
|
|
284
|
+
verified?: boolean;
|
|
285
|
+
request_id?: string | null;
|
|
286
|
+
schema_revision?: string | null;
|
|
287
|
+
plan_hash?: string | null;
|
|
288
|
+
verification_mode?: string;
|
|
289
|
+
rejection_reason?: string | null;
|
|
290
|
+
}
|
|
291
|
+
interface SourceRegistrationResponse {
|
|
292
|
+
source_id?: string | null;
|
|
293
|
+
dataset_id?: string | null;
|
|
294
|
+
name?: string | null;
|
|
295
|
+
dataset_name?: string | null;
|
|
296
|
+
status: string;
|
|
297
|
+
ingest_mode?: string | null;
|
|
298
|
+
schema?: Record<string, unknown> | null;
|
|
299
|
+
source_schema?: Record<string, unknown> | null;
|
|
300
|
+
planner_cache_hit?: boolean | null;
|
|
301
|
+
planner_schema_revision?: string | null;
|
|
302
|
+
planner_prewarm_ms?: number | null;
|
|
303
|
+
latency_ms?: number | null;
|
|
304
|
+
row_count?: number | null;
|
|
305
|
+
typed_fields?: Array<{
|
|
306
|
+
name: string;
|
|
307
|
+
type: string;
|
|
308
|
+
}> | null;
|
|
309
|
+
[key: string]: unknown;
|
|
310
|
+
}
|
|
311
|
+
/** The caller/model-authored resolve-spec. */
|
|
331
312
|
interface QuerySpec {
|
|
332
313
|
metric: string;
|
|
333
314
|
aggregation?: "sum" | "avg" | "count" | "min" | "max";
|
|
@@ -444,16 +425,23 @@ interface ResultStoreConfig {
|
|
|
444
425
|
maxTenantResultBytes?: number;
|
|
445
426
|
}
|
|
446
427
|
|
|
447
|
-
/** Computation dispatch: delegate a validated computation to
|
|
428
|
+
/** Computation dispatch: delegate a validated computation to the runtime.
|
|
448
429
|
*
|
|
449
|
-
* Local mode → the managed runtime daemon via algenta-sdk's MojoRuntime.
|
|
450
430
|
* deployment / api mode → POST {baseUrl}/v1/libraries/execute.
|
|
451
431
|
* SQAI performs no calculation of its own in either path.
|
|
452
432
|
*/
|
|
453
433
|
|
|
434
|
+
interface LocalComputeRuntime {
|
|
435
|
+
execute(module: string, functionName: string, args?: SqaiValue, requestId?: string, timeoutSeconds?: number): Promise<{
|
|
436
|
+
result: unknown;
|
|
437
|
+
latency_ms: number;
|
|
438
|
+
engine_used: string;
|
|
439
|
+
request_id?: string | null;
|
|
440
|
+
}>;
|
|
441
|
+
}
|
|
454
442
|
type DispatchTarget = {
|
|
455
443
|
kind: "local";
|
|
456
|
-
runtime:
|
|
444
|
+
runtime: LocalComputeRuntime;
|
|
457
445
|
} | {
|
|
458
446
|
kind: "http";
|
|
459
447
|
baseUrl: string;
|
|
@@ -461,14 +449,165 @@ type DispatchTarget = {
|
|
|
461
449
|
fetchImpl?: typeof fetch;
|
|
462
450
|
};
|
|
463
451
|
|
|
464
|
-
/**
|
|
452
|
+
/** Embedded trust root for signed managed-runtime bundles.
|
|
453
|
+
*
|
|
454
|
+
* The provisioner only installs bundles whose manifest signature (RS256 —
|
|
455
|
+
* RSASSA-PKCS1-v1_5 + SHA-256 over the exact shipped manifest bytes) verifies
|
|
456
|
+
* against one of these keys. Revocation and rollback protection live here so
|
|
457
|
+
* a single release-process edit rotates the whole trust posture:
|
|
458
|
+
*
|
|
459
|
+
* - TRUSTED_KEYS the accepted verification keys (key_id + PEM)
|
|
460
|
+
* - REVOKED_KEY_IDS key_ids that must never verify again
|
|
461
|
+
* - MIN_ACCEPTED_RUNTIME_VERSION
|
|
462
|
+
* the rollback floor: bundle manifests whose
|
|
463
|
+
* runtime_bundle_version compares below this are
|
|
464
|
+
* rejected (reason `rollback_protected`)
|
|
465
|
+
*
|
|
466
|
+
* Tests (and the release process) can override every value through
|
|
467
|
+
* RuntimeProvisioner options — nothing here is reachable from user input.
|
|
468
|
+
*/
|
|
469
|
+
interface TrustedKey {
|
|
470
|
+
key_id: string;
|
|
471
|
+
algorithm: "RS256";
|
|
472
|
+
public_key_pem: string;
|
|
473
|
+
/** ISO-8601 instant; key is not accepted before it. */
|
|
474
|
+
valid_from?: string;
|
|
475
|
+
/** ISO-8601 instant; key is not accepted after it. */
|
|
476
|
+
valid_to?: string;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/** Managed-runtime provisioning: zero-setup for the computation plane.
|
|
480
|
+
*
|
|
481
|
+
* The query plane never touches this module. On first computation-plane call:
|
|
482
|
+
* 1. Reuse a healthy daemon whose version matches the contract pin.
|
|
483
|
+
* 2. Otherwise verify + spawn the installed bundle for this platform.
|
|
484
|
+
* 3. Otherwise download the contract-pinned bundle (tarball sha256 + RS256
|
|
485
|
+
* manifest against the embedded trust root — see runtime/trust.ts and
|
|
486
|
+
* runtime/bundle.ts), extract atomically, spawn.
|
|
487
|
+
*
|
|
488
|
+
* Concurrency hardening: a per-version lock file (`<cacheDir>/<version>.lock`
|
|
489
|
+
* with `{pid, created_at}`) serializes installers across processes — fresh
|
|
490
|
+
* locks are poll-waited (max 90s) while re-checking for a completed install,
|
|
491
|
+
* stale locks (>10 min) are removed. Downloads land in `tmp-<random>` names,
|
|
492
|
+
* verification happens BEFORE extraction, extraction lands in a `tmp-<random>`
|
|
493
|
+
* directory that is atomically renamed into place, and every failure cleans
|
|
494
|
+
* its temp state — a partial install is never left behind.
|
|
495
|
+
*/
|
|
496
|
+
|
|
497
|
+
interface RuntimeStatus {
|
|
498
|
+
available: boolean;
|
|
499
|
+
runtime_available: boolean;
|
|
500
|
+
engine: string | null;
|
|
501
|
+
module_count: number;
|
|
502
|
+
platform: string;
|
|
503
|
+
managed: boolean;
|
|
504
|
+
}
|
|
505
|
+
interface ManagedRuntimeConfig {
|
|
506
|
+
mode?: "local";
|
|
507
|
+
tcpAddress?: string;
|
|
508
|
+
timeout?: number;
|
|
509
|
+
autoStart?: boolean;
|
|
510
|
+
daemonCommand?: string[];
|
|
511
|
+
}
|
|
512
|
+
interface ManagedRuntime extends LocalComputeRuntime {
|
|
513
|
+
health(): Promise<{
|
|
514
|
+
runtime_available: boolean;
|
|
515
|
+
engine: string;
|
|
516
|
+
module_count: number;
|
|
517
|
+
}>;
|
|
518
|
+
}
|
|
519
|
+
/** A runtime bundle resolved for a specific module filter (build-on-provision). */
|
|
520
|
+
interface FilteredBundle {
|
|
521
|
+
url: string;
|
|
522
|
+
sha256: string;
|
|
523
|
+
version: string;
|
|
524
|
+
cacheKey: string;
|
|
525
|
+
}
|
|
526
|
+
interface ProvisionerOptions {
|
|
527
|
+
contract: CapabilityContract;
|
|
528
|
+
autoInstall: boolean;
|
|
529
|
+
/**
|
|
530
|
+
* Build-on-provision: the developer's module filter. All 4,762 functions are
|
|
531
|
+
* available in the contract; only the selected modules are compiled + installed.
|
|
532
|
+
* Empty/undefined → the default pinned bundle (contract.runtime_bundle).
|
|
533
|
+
*/
|
|
534
|
+
runtimeModules?: string[];
|
|
535
|
+
/** Build service that compiles a bundle for an exact filter (POST /v1/runtime/build). */
|
|
536
|
+
buildServiceUrl?: string;
|
|
537
|
+
/** Injection points for tests. */
|
|
538
|
+
runtimeFactory?: (config?: ManagedRuntimeConfig) => ManagedRuntime;
|
|
539
|
+
downloadBundle?: (url: string, destination: string) => Promise<void>;
|
|
540
|
+
/** Resolve a filtered bundle (default: POST to buildServiceUrl). Test injection. */
|
|
541
|
+
resolveFilteredBundle?: (modules: string[], platformKey: string) => Promise<FilteredBundle>;
|
|
542
|
+
/** Bundle cache directory (default: OS user cache — runtimeCacheDir()). */
|
|
543
|
+
cacheDir?: string;
|
|
544
|
+
/** Trust-root overrides (default: the embedded trust root). */
|
|
545
|
+
trustedKeys?: TrustedKey[];
|
|
546
|
+
revokedKeyIds?: string[];
|
|
547
|
+
minAcceptedRuntimeVersion?: string;
|
|
548
|
+
/** Lock policy overrides. */
|
|
549
|
+
lockFreshMs?: number;
|
|
550
|
+
lockWaitTimeoutMs?: number;
|
|
551
|
+
lockPollIntervalMs?: number;
|
|
552
|
+
}
|
|
553
|
+
declare function currentPlatformKey(): string;
|
|
554
|
+
declare function runtimeCacheDir(): string;
|
|
555
|
+
declare class RuntimeProvisioner {
|
|
556
|
+
private readonly options;
|
|
557
|
+
private readonly trustRoot;
|
|
558
|
+
private runtime;
|
|
559
|
+
private ensurePromise;
|
|
560
|
+
constructor(options: ProvisionerOptions);
|
|
561
|
+
/** Lazily resolve a usable runtime; concurrent callers share one attempt. */
|
|
562
|
+
ensure(): Promise<ManagedRuntime>;
|
|
563
|
+
status(): Promise<RuntimeStatus>;
|
|
564
|
+
stop(): Promise<void>;
|
|
565
|
+
private newRuntime;
|
|
566
|
+
private ensureLocalLoginKey;
|
|
567
|
+
private cacheDir;
|
|
568
|
+
/** Normalized module filter (sorted, unique, non-empty) or null for the default bundle. */
|
|
569
|
+
private filterModules;
|
|
570
|
+
/** Ask the build service to compile + sign a bundle for exactly these modules. */
|
|
571
|
+
private resolveFilteredBundle;
|
|
572
|
+
/**
|
|
573
|
+
* The filter's cache key, computed IDENTICALLY to the build service
|
|
574
|
+
* (sha256("mods|platform|version")[:20], mods = sorted+unique, comma-joined).
|
|
575
|
+
* Lets the reuse fast-path find an already-running filtered daemon without a
|
|
576
|
+
* build-service round-trip. The build service's returned key is authoritative
|
|
577
|
+
* for install; this only has to match for the reuse optimization to hit.
|
|
578
|
+
*/
|
|
579
|
+
private localCacheKey;
|
|
580
|
+
/**
|
|
581
|
+
* Deterministic per-filter daemon endpoint so a filtered runtime never collides
|
|
582
|
+
* with the default (or another filter's) daemon on the shared default socket.
|
|
583
|
+
*/
|
|
584
|
+
private filterEndpoint;
|
|
585
|
+
private static readonly DAEMON_ENDPOINT_ENV;
|
|
586
|
+
/** Point the about-to-be-spawned daemon at a filter-specific socket/port/dir. */
|
|
587
|
+
private applyDaemonEndpointEnv;
|
|
588
|
+
private restoreEnv;
|
|
589
|
+
private doEnsure;
|
|
590
|
+
private provisionError;
|
|
591
|
+
private wrapVerificationError;
|
|
592
|
+
private manifestExpectations;
|
|
593
|
+
/** Verify an existing install if present; returns null when absent/invalid. */
|
|
594
|
+
private verifiedInstallOrNull;
|
|
595
|
+
private acquireLock;
|
|
596
|
+
private lockIsStale;
|
|
597
|
+
/** Serialize installers on `<cacheDir>/<installKey>.lock`; returns the verified install. */
|
|
598
|
+
private ensureInstalled;
|
|
599
|
+
/** Holder-of-the-lock path: download → verify → extract → atomic rename. */
|
|
600
|
+
private downloadVerifyExtract;
|
|
601
|
+
/** Spawn the installed bundle's daemon through managed runtime auto-start. */
|
|
602
|
+
private spawnInstalled;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/** The SQAI client: a thin, policy-checked facade over the runtime.
|
|
465
606
|
*
|
|
466
607
|
* Query plane — connect / resolve / query / verify / ask, in-process.
|
|
467
608
|
* Computation — validate against the capability contract, resolve bindings
|
|
468
609
|
* through the upstream aligned extraction primitive, delegate
|
|
469
610
|
* to the managed runtime, pass results through verbatim.
|
|
470
|
-
*
|
|
471
|
-
* SQAI reimplements nothing: every discrepancy is fixed upstream in Algenta.
|
|
472
611
|
*/
|
|
473
612
|
|
|
474
613
|
interface SqaiConfig {
|
|
@@ -494,14 +633,14 @@ interface SqaiConfig {
|
|
|
494
633
|
runtimeModules?: string[];
|
|
495
634
|
/** Build service endpoint for filtered bundles. Env: SQAI_BUILD_SERVICE_URL. */
|
|
496
635
|
buildServiceUrl?: string;
|
|
497
|
-
/** BYO
|
|
498
|
-
runtime?:
|
|
636
|
+
/** BYO runtime (tests / custom SQAI deployments). */
|
|
637
|
+
runtime?: unknown;
|
|
499
638
|
/** BYO computation dispatch target (tests / custom SQAI deployments). */
|
|
500
639
|
computeTarget?: DispatchTarget;
|
|
501
640
|
}
|
|
502
641
|
declare class SQAI {
|
|
503
642
|
readonly mode: SqaiMode;
|
|
504
|
-
private readonly
|
|
643
|
+
private readonly runtimeClient;
|
|
505
644
|
private readonly rawRuntime;
|
|
506
645
|
private readonly policy;
|
|
507
646
|
private readonly tenantId;
|
|
@@ -595,9 +734,8 @@ declare const SQAI_ERROR_CODES: readonly ["unsupported_operation", "seed_require
|
|
|
595
734
|
* canonically serialized result.
|
|
596
735
|
*
|
|
597
736
|
* Both are domain-separated and rendered with the cross-language canonical
|
|
598
|
-
* JSON
|
|
599
|
-
*
|
|
600
|
-
* hashes for identical work.
|
|
737
|
+
* JSON locked by the upstream conformance suite, so TypeScript and Python
|
|
738
|
+
* produce identical hashes for identical work.
|
|
601
739
|
*/
|
|
602
740
|
|
|
603
741
|
interface InvocationIdentity {
|
|
@@ -649,9 +787,9 @@ declare class ResultStore {
|
|
|
649
787
|
*
|
|
650
788
|
* Authenticates via the shared accounts portal (OAuth 2.0 device grant, RFC 8628), resolves-or-creates
|
|
651
789
|
* the caller's org on the free `sqai_developer` tier, and mints a control-plane API key. The key is
|
|
652
|
-
* cached under ~/.sqai and handed to the local runtime daemon
|
|
790
|
+
* cached under ~/.sqai and handed to the local runtime daemon, which exchanges it
|
|
653
791
|
* once for a platform-signed, device-bound offline license — then everything runs locally, no query-time
|
|
654
|
-
* network.
|
|
792
|
+
* network.
|
|
655
793
|
*
|
|
656
794
|
* Free forever on 1 machine. Paid tiers (sqai_pro / sqai_team) add devices/seats/commercial use via the
|
|
657
795
|
* accounts billing portal — never a cloud service. Login is licensing-only; no data leaves the machine.
|
|
@@ -659,7 +797,7 @@ declare class ResultStore {
|
|
|
659
797
|
declare class LoginError extends Error {
|
|
660
798
|
}
|
|
661
799
|
declare function sqaiHome(): string;
|
|
662
|
-
/** Resolve the SQAI API key for the runtime: $SQAI_API_KEY
|
|
800
|
+
/** Resolve the SQAI API key for the runtime: $SQAI_API_KEY, legacy env, else the cached key. */
|
|
663
801
|
declare function readCachedApiKey(): Promise<string | undefined>;
|
|
664
802
|
interface LoginResult {
|
|
665
803
|
device_id: string;
|
|
@@ -676,8 +814,8 @@ declare function logout(): void;
|
|
|
676
814
|
|
|
677
815
|
/** Computation-plane validation: dynamic, against the embedded capability
|
|
678
816
|
* contract. The zod wire schema (in @thyn-ai/sqai-ai-sdk) only transports values;
|
|
679
|
-
* everything here authorizes them. SQAI computes nothing
|
|
680
|
-
* computation is delegated to
|
|
817
|
+
* everything here authorizes them. SQAI computes nothing; a validated
|
|
818
|
+
* computation is delegated to the managed runtime verbatim.
|
|
681
819
|
*
|
|
682
820
|
* Argument assembly: every signature parameter is supplied through EXACTLY one
|
|
683
821
|
* of args (positional), kwargs (by name), or bindings (by name or index).
|
|
@@ -700,4 +838,4 @@ interface ValidatedComputation {
|
|
|
700
838
|
declare function lookupCapability(index: ContractIndex, module: string, functionName: string): CapabilityEntry;
|
|
701
839
|
declare function validateComputation(spec: ComputationSpec, index: ContractIndex, policy: SqaiPolicy | undefined, resolvedBindings: ResolvedBindingValue[]): ValidatedComputation;
|
|
702
840
|
|
|
703
|
-
export { type AskOutcome, type BindingProvenance, type CapabilityContract, type CapabilityEntry, type CapabilityMatch, type ColumnExtract, type ComputationBinding, type ComputationSpec, type ComputeResult, ContractIndex, type DeterminismEnvelope, type InvocationIdentity, LoginError, type LoginResult, type QueryFilterCondition, type QueryFilterSpec, type QuerySpec, type ResolvedBindingValue, ResultStore, type ResultStoreConfig, RuntimeProvisioner, type RuntimeStatus, SQAI, SQAI_CONNECTOR_TYPES, SQAI_CONNECTOR_TYPE_ALIASES, SQAI_ERROR_CODES, type SqaiConfig, type SqaiConnectorBrowseResult, type SqaiConnectorConfig, type SqaiConnectorCreateRequest, type SqaiConnectorInfo, type SqaiConnectorListResult, type SqaiConnectorPreview, type SqaiConnectorTestResult, type SqaiConnectorType, type SqaiConnectorUpdateRequest, SqaiError, type SqaiErrorSource, type SqaiIntent, type SqaiManagedConnectOptions, type SqaiOutcome, type SqaiPolicy, type SqaiResultRecord, type SqaiSource, type SqaiValue, type ValidatedComputation, computationHash, createSQAI, currentPlatformKey, invocationHash, isReadOnlyEligible, login, logout, lookupCapability, readCachedApiKey, runtimeCacheDir, sqaiHome, validateComputation };
|
|
841
|
+
export { type AskOutcome, type BindingProvenance, type CapabilityContract, type CapabilityEntry, type CapabilityMatch, type ColumnExtract, type ComputationBinding, type ComputationSpec, type ComputeResult, ContractIndex, type DeterminismEnvelope, type InvocationIdentity, LoginError, type LoginResult, type QueryFilterCondition, type QueryFilterSpec, type QueryResponse, type QuerySpec, type QueryWithMetadataResponse, type ResolveResponse, type ResolvedBindingValue, type ResolvedPlan, ResultStore, type ResultStoreConfig, RuntimeProvisioner, type RuntimeStatus, SQAI, SQAI_CONNECTOR_TYPES, SQAI_CONNECTOR_TYPE_ALIASES, SQAI_ERROR_CODES, type SourceRegistrationResponse, type SqaiConfig, type SqaiConnectorBrowseResult, type SqaiConnectorConfig, type SqaiConnectorCreateRequest, type SqaiConnectorInfo, type SqaiConnectorListResult, type SqaiConnectorPreview, type SqaiConnectorTestResult, type SqaiConnectorType, type SqaiConnectorUpdateRequest, SqaiError, type SqaiErrorSource, type SqaiIntent, type SqaiManagedConnectOptions, type SqaiOutcome, type SqaiPolicy, type SqaiResultRecord, type SqaiSource, type SqaiValue, type ValidatedComputation, type VerifyResponse, computationHash, createSQAI, currentPlatformKey, invocationHash, isReadOnlyEligible, login, logout, lookupCapability, readCachedApiKey, runtimeCacheDir, sqaiHome, validateComputation };
|