tempest-react-sdk 0.31.1 → 0.32.1
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/README.md +2 -0
- package/bin/lib/design/collect.mjs +103 -0
- package/bin/lib/design/findings.mjs +70 -0
- package/bin/lib/design/functions.mjs +188 -0
- package/bin/lib/design/functions.test.mjs +127 -0
- package/bin/lib/design/index.mjs +80 -0
- package/bin/lib/design/index.test.mjs +129 -0
- package/bin/lib/design/markers.mjs +76 -0
- package/bin/lib/design/markers.test.mjs +60 -0
- package/bin/lib/design/mask.mjs +209 -0
- package/bin/lib/design/mask.test.mjs +69 -0
- package/bin/lib/design/scan.mjs +229 -0
- package/bin/lib/design/scan.test.mjs +218 -0
- package/bin/lib/doctor/doctor.e2e.test.mjs +79 -2
- package/bin/tempest.mjs +83 -3
- package/dist/imaging/canvas.cjs +2 -0
- package/dist/imaging/canvas.cjs.map +1 -0
- package/dist/imaging/canvas.js +23 -0
- package/dist/imaging/canvas.js.map +1 -0
- package/dist/imaging/compress.cjs +2 -0
- package/dist/imaging/compress.cjs.map +1 -0
- package/dist/imaging/compress.js +43 -0
- package/dist/imaging/compress.js.map +1 -0
- package/dist/imaging/decode.cjs +2 -0
- package/dist/imaging/decode.cjs.map +1 -0
- package/dist/imaging/decode.js +42 -0
- package/dist/imaging/decode.js.map +1 -0
- package/dist/imaging/encode.cjs +2 -0
- package/dist/imaging/encode.cjs.map +1 -0
- package/dist/imaging/encode.js +48 -0
- package/dist/imaging/encode.js.map +1 -0
- package/dist/imaging/exceptions.cjs +2 -0
- package/dist/imaging/exceptions.cjs.map +1 -0
- package/dist/imaging/exceptions.js +26 -0
- package/dist/imaging/exceptions.js.map +1 -0
- package/dist/imaging/thumbnails.cjs +2 -0
- package/dist/imaging/thumbnails.cjs.map +1 -0
- package/dist/imaging/thumbnails.js +34 -0
- package/dist/imaging/thumbnails.js.map +1 -0
- package/dist/imaging/transform.cjs +2 -0
- package/dist/imaging/transform.cjs.map +1 -0
- package/dist/imaging/transform.js +97 -0
- package/dist/imaging/transform.js.map +1 -0
- package/dist/imaging/use-image-processing.cjs +2 -0
- package/dist/imaging/use-image-processing.cjs.map +1 -0
- package/dist/imaging/use-image-processing.js +45 -0
- package/dist/imaging/use-image-processing.js.map +1 -0
- package/dist/imaging.cjs +1 -0
- package/dist/imaging.d.ts +541 -0
- package/dist/imaging.js +9 -0
- package/dist/tabular/assets.cjs +2 -0
- package/dist/tabular/assets.cjs.map +1 -0
- package/dist/tabular/assets.js +19 -0
- package/dist/tabular/assets.js.map +1 -0
- package/dist/tabular/cache.cjs +2 -0
- package/dist/tabular/cache.cjs.map +1 -0
- package/dist/tabular/cache.js +48 -0
- package/dist/tabular/cache.js.map +1 -0
- package/dist/tabular/exceptions.cjs +2 -0
- package/dist/tabular/exceptions.cjs.map +1 -0
- package/dist/tabular/exceptions.js +30 -0
- package/dist/tabular/exceptions.js.map +1 -0
- package/dist/tabular/manifest.cjs +2 -0
- package/dist/tabular/manifest.cjs.map +1 -0
- package/dist/tabular/manifest.js +42 -0
- package/dist/tabular/manifest.js.map +1 -0
- package/dist/tabular/predictor.cjs +2 -0
- package/dist/tabular/predictor.cjs.map +1 -0
- package/dist/tabular/predictor.js +111 -0
- package/dist/tabular/predictor.js.map +1 -0
- package/dist/tabular/use-tabular-predictor.cjs +2 -0
- package/dist/tabular/use-tabular-predictor.cjs.map +1 -0
- package/dist/tabular/use-tabular-predictor.js +51 -0
- package/dist/tabular/use-tabular-predictor.js.map +1 -0
- package/dist/tabular.cjs +1 -0
- package/dist/tabular.d.ts +509 -0
- package/dist/tabular.js +7 -0
- package/package.json +11 -1
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store model bytes without downloading them.
|
|
3
|
+
*
|
|
4
|
+
* For an app that already has the bytes — from a file input, or from a
|
|
5
|
+
* bundle it unpacked — and wants the next load to find them cached.
|
|
6
|
+
*
|
|
7
|
+
* @param url The URL to key the entry under.
|
|
8
|
+
* @param bytes The model bytes.
|
|
9
|
+
* @param cacheName Cache Storage bucket name.
|
|
10
|
+
* @returns `true` when the entry was stored, `false` without Cache Storage.
|
|
11
|
+
*/
|
|
12
|
+
export declare function cacheModelBytes(url: string, bytes: Uint8Array, cacheName?: string): Promise<boolean>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Drop cached models.
|
|
16
|
+
*
|
|
17
|
+
* @param url A specific model to evict; omit to delete the whole bucket.
|
|
18
|
+
* @param cacheName Cache Storage bucket name.
|
|
19
|
+
* @returns `true` when something was deleted.
|
|
20
|
+
*/
|
|
21
|
+
export declare function clearModelCache(url?: string, cacheName?: string): Promise<boolean>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Point ONNX Runtime Web at locally served WebAssembly binaries.
|
|
25
|
+
*
|
|
26
|
+
* Call once, before creating any predictor.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* configureOrtAssets("/ort/");
|
|
31
|
+
* const predictor = await TabularPredictor.create("/models/classifier.onnx");
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param basePath Directory the binaries are served from, with a trailing
|
|
35
|
+
* slash. Copy them there at build time — for Vite, from
|
|
36
|
+
* `node_modules/onnxruntime-web/dist/`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function configureOrtAssets(basePath: string): void;
|
|
39
|
+
|
|
40
|
+
/** Cache Storage bucket used when the caller does not name one. */
|
|
41
|
+
export declare const DEFAULT_MODEL_CACHE = "tempest-tabular-models";
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Execution providers used when the caller does not choose.
|
|
45
|
+
*
|
|
46
|
+
* WebAssembly only, and deliberately: scikit-learn graphs are `ai.onnx.ml`
|
|
47
|
+
* operators, which the WebGPU backend does not implement. There is no
|
|
48
|
+
* speed left on the table here — a 10-tree forest predicts a row in about
|
|
49
|
+
* 0.05 ms in Chromium.
|
|
50
|
+
*/
|
|
51
|
+
export declare const DEFAULT_TABULAR_PROVIDERS: readonly string[];
|
|
52
|
+
|
|
53
|
+
/** The package manifest, as written by `edge_pipeline`. */
|
|
54
|
+
export declare interface EdgeManifest {
|
|
55
|
+
readonly schema_version: number;
|
|
56
|
+
readonly name: string;
|
|
57
|
+
readonly version: string;
|
|
58
|
+
readonly created_at: string;
|
|
59
|
+
readonly sdk_version: string;
|
|
60
|
+
readonly estimator: string;
|
|
61
|
+
readonly model: ManifestModelFile;
|
|
62
|
+
readonly input: ManifestInput;
|
|
63
|
+
readonly output: ManifestOutput;
|
|
64
|
+
readonly verified: boolean | null;
|
|
65
|
+
/** Absent on packages built straight from a fitted estimator. */
|
|
66
|
+
readonly source?: ManifestSource;
|
|
67
|
+
readonly baseline_file: string | null;
|
|
68
|
+
readonly baseline_samples: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** One row of feature values, in the column order the model was trained on. */
|
|
72
|
+
export declare type FeatureRow = readonly number[];
|
|
73
|
+
|
|
74
|
+
/** The rows do not match what the model expects. */
|
|
75
|
+
export declare class FeatureShapeError extends TabularError {
|
|
76
|
+
constructor(message: string, options?: ErrorOptions);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Read a package's manifest.
|
|
81
|
+
*
|
|
82
|
+
* Cheap: it is a few hundred bytes, so an app can check for a new version
|
|
83
|
+
* without downloading a model it may already have.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const manifest = await fetchEdgeManifest("/models/risk/");
|
|
88
|
+
* if (manifest.version !== localStorage.getItem("risk-version")) {
|
|
89
|
+
* // a new model was published
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @param directoryUrl URL of the package directory, with or without a
|
|
94
|
+
* trailing slash. A full URL to the manifest file also works.
|
|
95
|
+
* @param requestInit `fetch` options.
|
|
96
|
+
* @returns The parsed manifest.
|
|
97
|
+
* @throws {@link ModelFetchError} when the manifest cannot be read, or when
|
|
98
|
+
* its `schema_version` is newer than this reader understands — loading it
|
|
99
|
+
* anyway would risk misreading the field that defines column order.
|
|
100
|
+
*/
|
|
101
|
+
export declare function fetchEdgeManifest(directoryUrl: string, requestInit?: RequestInit): Promise<EdgeManifest>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Fetch the model bytes, preferring the on-device copy.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const bytes = await fetchModelBytes("/models/classifier-v3.onnx");
|
|
109
|
+
* const predictor = await TabularPredictor.create(bytes);
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @param url Where the model lives.
|
|
113
|
+
* @param options Cache bucket, revalidation and `fetch` options.
|
|
114
|
+
* @returns The model bytes.
|
|
115
|
+
* @throws {@link ModelFetchError} when the model is neither cached nor
|
|
116
|
+
* reachable — which is the "offline and never warmed" case, and the
|
|
117
|
+
* message says so.
|
|
118
|
+
*/
|
|
119
|
+
export declare function fetchModelBytes(url: string, options?: ModelCacheOptions): Promise<Uint8Array>;
|
|
120
|
+
|
|
121
|
+
/** The session ran but its outputs could not be read. */
|
|
122
|
+
export declare class InferenceError extends TabularError {
|
|
123
|
+
constructor(message: string, options?: ErrorOptions);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Whether a model is already on the device.
|
|
128
|
+
*
|
|
129
|
+
* Useful for showing "available offline" in the UI, and for deciding
|
|
130
|
+
* whether to prefetch on a metered connection.
|
|
131
|
+
*
|
|
132
|
+
* @param url The model URL.
|
|
133
|
+
* @param cacheName Cache Storage bucket name.
|
|
134
|
+
* @returns `true` when the bytes are cached.
|
|
135
|
+
*/
|
|
136
|
+
export declare function isModelCached(url: string, cacheName?: string): Promise<boolean>;
|
|
137
|
+
|
|
138
|
+
/** A package loaded and ready to answer. */
|
|
139
|
+
export declare interface LoadedEdgePackage {
|
|
140
|
+
/** What was published. */
|
|
141
|
+
readonly manifest: EdgeManifest;
|
|
142
|
+
/** The running model. */
|
|
143
|
+
readonly predictor: TabularPredictor;
|
|
144
|
+
/** Column order the rows must follow. */
|
|
145
|
+
readonly featureNames: readonly string[];
|
|
146
|
+
/** Class names behind each probability column. */
|
|
147
|
+
readonly classes: readonly string[];
|
|
148
|
+
/**
|
|
149
|
+
* Map a prediction's scores onto class names.
|
|
150
|
+
*
|
|
151
|
+
* @param probabilities One row of scores.
|
|
152
|
+
* @returns Name/score pairs, highest first.
|
|
153
|
+
*/
|
|
154
|
+
readonly explain: (probabilities: readonly number[]) => {
|
|
155
|
+
name: string;
|
|
156
|
+
score: number;
|
|
157
|
+
}[];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Load a whole edge package: manifest, model, and the names to read it by.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* const pkg = await loadEdgePackage("/models/risk/");
|
|
166
|
+
*
|
|
167
|
+
* console.log(pkg.featureNames); // ["age", "income", "tenure", "score", "visits"]
|
|
168
|
+
*
|
|
169
|
+
* const { probabilities } = await pkg.predictor.predict([[41, 5200, 3, 0.82, 12]]);
|
|
170
|
+
* console.log(pkg.explain(probabilities[0]!)); // [{ name: "approved", score: 0.91 }, ...]
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @param directoryUrl URL of the package directory.
|
|
174
|
+
* @param options Predictor options plus caching.
|
|
175
|
+
* @returns The loaded package.
|
|
176
|
+
* @throws {@link ModelFetchError} when the manifest or model cannot be read.
|
|
177
|
+
*/
|
|
178
|
+
export declare function loadEdgePackage(directoryUrl: string, options?: LoadEdgePackageOptions): Promise<LoadedEdgePackage>;
|
|
179
|
+
|
|
180
|
+
/** Options for {@link loadEdgePackage}. */
|
|
181
|
+
export declare interface LoadEdgePackageOptions extends TabularPredictorOptions {
|
|
182
|
+
/** Cache the model bytes for offline use. `true` by default. */
|
|
183
|
+
readonly cache?: boolean | ModelCacheOptions;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Fixed filename inside a package directory. */
|
|
187
|
+
export declare const MANIFEST_FILENAME = "manifest.json";
|
|
188
|
+
|
|
189
|
+
/** What the graph expects per row. */
|
|
190
|
+
export declare interface ManifestInput {
|
|
191
|
+
readonly name: string;
|
|
192
|
+
readonly features: number;
|
|
193
|
+
/** Column order used at training time. */
|
|
194
|
+
readonly feature_names: readonly string[];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** The graph file and how to check you got it whole. */
|
|
198
|
+
export declare interface ManifestModelFile {
|
|
199
|
+
readonly file: string;
|
|
200
|
+
readonly sha256: string;
|
|
201
|
+
readonly bytes: number;
|
|
202
|
+
readonly gzip_file: string | null;
|
|
203
|
+
readonly gzip_bytes: number | null;
|
|
204
|
+
readonly opset: number;
|
|
205
|
+
readonly dtype: string;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** What the graph answers. */
|
|
209
|
+
export declare interface ManifestOutput {
|
|
210
|
+
readonly is_classifier: boolean;
|
|
211
|
+
readonly label_output: string;
|
|
212
|
+
readonly probability_output: string | null;
|
|
213
|
+
/** Class labels in score-column order. */
|
|
214
|
+
readonly classes: readonly string[];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Where the packaged model came from, when it came from an existing
|
|
219
|
+
* artifact.
|
|
220
|
+
*
|
|
221
|
+
* Present when the package was built with `edge_pipeline_from_pickle`: the
|
|
222
|
+
* `.pkl` never reaches the browser (a pickle is a Python program, not
|
|
223
|
+
* data), but its name and digest travel in the manifest, so a model
|
|
224
|
+
* answering in a tab can be traced back to the file that produced it.
|
|
225
|
+
*/
|
|
226
|
+
export declare interface ManifestSource {
|
|
227
|
+
readonly file: string;
|
|
228
|
+
readonly kind: string;
|
|
229
|
+
readonly sha256: string;
|
|
230
|
+
readonly bytes: number;
|
|
231
|
+
readonly sklearn_version: string;
|
|
232
|
+
readonly warnings: readonly string[];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Options for {@link fetchModelBytes}. */
|
|
236
|
+
export declare interface ModelCacheOptions {
|
|
237
|
+
/** Cache Storage bucket name. */
|
|
238
|
+
readonly cacheName?: string;
|
|
239
|
+
/**
|
|
240
|
+
* Go to the network first and fall back to the cache.
|
|
241
|
+
*
|
|
242
|
+
* For a URL that serves "whatever is current" rather than a pinned
|
|
243
|
+
* version. Costs a round trip on every load when online.
|
|
244
|
+
*/
|
|
245
|
+
readonly revalidate?: boolean;
|
|
246
|
+
/** `fetch` options, e.g. credentials for a private model endpoint. */
|
|
247
|
+
readonly requestInit?: RequestInit;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The model bytes could not be fetched or read from the cache.
|
|
252
|
+
*
|
|
253
|
+
* Distinct from {@link ModelLoadError}: this one means the app is offline
|
|
254
|
+
* and nothing was cached, which is a deployment problem, not a model
|
|
255
|
+
* problem.
|
|
256
|
+
*/
|
|
257
|
+
export declare class ModelFetchError extends TabularError {
|
|
258
|
+
constructor(message: string, options?: ErrorOptions);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** The model bytes could not be loaded into a session. */
|
|
262
|
+
export declare class ModelLoadError extends TabularError {
|
|
263
|
+
constructor(message: string, options?: ErrorOptions);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* The WebAssembly binaries ONNX Runtime Web may request.
|
|
268
|
+
*
|
|
269
|
+
* Which one is fetched depends on the browser's threading and SIMD support,
|
|
270
|
+
* so an app that must work everywhere ships all of them. Chromium with the
|
|
271
|
+
* default entry point fetched the `jsep` build.
|
|
272
|
+
*/
|
|
273
|
+
export declare const ORT_WASM_ASSETS: readonly string[];
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* The URLs a service worker should precache for offline inference.
|
|
277
|
+
*
|
|
278
|
+
* The model file is not included: it is cached by
|
|
279
|
+
* {@link fetchModelBytes} on first use, under its own bucket.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```ts
|
|
283
|
+
* installPrecache([...ortAssetUrls("/ort/"), "/index.html"]);
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
286
|
+
* @param basePath Directory the binaries are served from.
|
|
287
|
+
* @returns Absolute-from-root URLs for every runtime asset.
|
|
288
|
+
*/
|
|
289
|
+
export declare function ortAssetUrls(basePath: string): string[];
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* A predicted class label.
|
|
293
|
+
*
|
|
294
|
+
* scikit-learn classifiers export an int64 label tensor, which ONNX Runtime
|
|
295
|
+
* Web surfaces as `bigint`. Those are converted to `number` — a class index
|
|
296
|
+
* never approaches `Number.MAX_SAFE_INTEGER`, and leaving `bigint` in the
|
|
297
|
+
* result would break `JSON.stringify` and every `=== 1` comparison a caller
|
|
298
|
+
* writes. A model trained on string labels keeps them as strings.
|
|
299
|
+
*/
|
|
300
|
+
export declare type PredictedLabel = number | string;
|
|
301
|
+
|
|
302
|
+
/** Manifest schema version this reader was written against. */
|
|
303
|
+
export declare const SUPPORTED_MANIFEST_SCHEMA = 1;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Errors thrown by the tabular inference module.
|
|
307
|
+
*
|
|
308
|
+
* Each one exists because the underlying failure is unreadable on its own:
|
|
309
|
+
* ONNX Runtime reports a missing operator registration, and the actual cause
|
|
310
|
+
* is an import path chosen three files away.
|
|
311
|
+
*
|
|
312
|
+
* Every subclass sets `name` to a **literal** string rather than to
|
|
313
|
+
* `new.target.name`. Measured in a real build: the minifier renames the
|
|
314
|
+
* class, so the derived form ships as `error.name === "t"` — useless in a
|
|
315
|
+
* log and in any consumer that branches on the name.
|
|
316
|
+
*/
|
|
317
|
+
/** Base class for every error this module throws. */
|
|
318
|
+
export declare class TabularError extends Error {
|
|
319
|
+
constructor(message: string, options?: ErrorOptions);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Types for browser inference over tabular models exported from scikit-learn.
|
|
324
|
+
*/
|
|
325
|
+
/** Anything `InferenceSession.create` accepts as a model. */
|
|
326
|
+
export declare type TabularModelSource = string | ArrayBufferLike | Uint8Array;
|
|
327
|
+
|
|
328
|
+
/** One batch of predictions. */
|
|
329
|
+
export declare interface TabularPrediction {
|
|
330
|
+
/** Predicted class or regressed value per row. */
|
|
331
|
+
readonly labels: readonly PredictedLabel[];
|
|
332
|
+
/** Class scores per row; empty for a regressor. */
|
|
333
|
+
readonly probabilities: readonly (readonly number[])[];
|
|
334
|
+
/** Rows predicted. */
|
|
335
|
+
readonly numRows: number;
|
|
336
|
+
/** Wall-clock inference duration in milliseconds. */
|
|
337
|
+
readonly ms: number;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* A loaded tabular model, ready to answer.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* const predictor = await TabularPredictor.create("/models/classifier.onnx");
|
|
346
|
+
* const { labels, probabilities } = await predictor.predict([[5.1, 3.5, 1.4, 0.2]]);
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
export declare class TabularPredictor {
|
|
350
|
+
private readonly session;
|
|
351
|
+
/** What is loaded and how it is configured. */
|
|
352
|
+
readonly info: TabularPredictorInfo;
|
|
353
|
+
private constructor();
|
|
354
|
+
/**
|
|
355
|
+
* Load a model and describe its graph.
|
|
356
|
+
*
|
|
357
|
+
* @param source A URL string, or the model bytes (which is what an
|
|
358
|
+
* offline app passes, having read them from the cache).
|
|
359
|
+
* @param options Providers, warm-up and pass-through session options.
|
|
360
|
+
* @throws {@link UnsupportedGraphError} when the runtime build lacks the
|
|
361
|
+
* `ai.onnx.ml` operators — the WebGPU entry point does.
|
|
362
|
+
* @throws {@link ModelLoadError} for any other load failure.
|
|
363
|
+
*/
|
|
364
|
+
static create(source: TabularModelSource, options?: TabularPredictorOptions): Promise<TabularPredictor>;
|
|
365
|
+
/**
|
|
366
|
+
* Run one throwaway inference so the first real call is not the slow one.
|
|
367
|
+
*
|
|
368
|
+
* Skipped when the graph does not declare a feature count, since there
|
|
369
|
+
* is no shape to synthesise. Failures are swallowed: a warm-up that
|
|
370
|
+
* cannot run is not a reason to refuse to serve.
|
|
371
|
+
*/
|
|
372
|
+
warmUp(): Promise<void>;
|
|
373
|
+
/**
|
|
374
|
+
* Predict for a batch of rows.
|
|
375
|
+
*
|
|
376
|
+
* @param rows One array of feature values per row, in training column
|
|
377
|
+
* order. A single row is still wrapped: `[[...]]`.
|
|
378
|
+
* @returns Labels, class scores when the model produces them, and the
|
|
379
|
+
* call's duration.
|
|
380
|
+
* @throws {@link FeatureShapeError} when the batch is empty, ragged, or
|
|
381
|
+
* the wrong width — checked here so the failure names the mismatch
|
|
382
|
+
* instead of surfacing as an opaque runtime error.
|
|
383
|
+
* @throws {@link InferenceError} when the session runs but its outputs
|
|
384
|
+
* cannot be read.
|
|
385
|
+
*/
|
|
386
|
+
predict(rows: readonly FeatureRow[]): Promise<TabularPrediction>;
|
|
387
|
+
/**
|
|
388
|
+
* Release the session's memory.
|
|
389
|
+
*
|
|
390
|
+
* Worth calling on a route that swaps models: the WebAssembly heap does
|
|
391
|
+
* not shrink on garbage collection alone.
|
|
392
|
+
*/
|
|
393
|
+
dispose(): Promise<void>;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** What a loaded predictor is, and how it is configured. */
|
|
397
|
+
export declare interface TabularPredictorInfo {
|
|
398
|
+
/** Graph input name. Not a constant: exporters choose it. */
|
|
399
|
+
readonly inputName: string;
|
|
400
|
+
/** Features per row, or `null` when the graph does not declare it. */
|
|
401
|
+
readonly numFeatures: number | null;
|
|
402
|
+
/** Every graph output, in order. */
|
|
403
|
+
readonly outputNames: readonly string[];
|
|
404
|
+
/** The output holding predicted classes or regressed values. */
|
|
405
|
+
readonly labelOutput: string;
|
|
406
|
+
/** The output holding class scores, when the graph produces them. */
|
|
407
|
+
readonly probabilityOutput: string | null;
|
|
408
|
+
/** Whether a score output was found. */
|
|
409
|
+
readonly isClassifier: boolean;
|
|
410
|
+
/** Execution providers actually in use. */
|
|
411
|
+
readonly providers: readonly string[];
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** Options for {@link TabularPredictor.create}. */
|
|
415
|
+
export declare interface TabularPredictorOptions {
|
|
416
|
+
/**
|
|
417
|
+
* Execution providers in preference order.
|
|
418
|
+
*
|
|
419
|
+
* Defaults to `["wasm"]`, and that is not a placeholder: scikit-learn
|
|
420
|
+
* graphs are built from `ai.onnx.ml` operators (`TreeEnsembleClassifier`,
|
|
421
|
+
* `LinearClassifier`, `Scaler`), which only the WebAssembly backend
|
|
422
|
+
* implements.
|
|
423
|
+
*/
|
|
424
|
+
readonly providers?: readonly string[];
|
|
425
|
+
/**
|
|
426
|
+
* Run one throwaway inference at creation, so the first real prediction
|
|
427
|
+
* does not pay for allocation and kernel selection.
|
|
428
|
+
*/
|
|
429
|
+
readonly warmup?: boolean;
|
|
430
|
+
/** Session options forwarded verbatim to ONNX Runtime Web. */
|
|
431
|
+
readonly sessionOptions?: Record<string, unknown>;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** Lifecycle of the model behind the hook. */
|
|
435
|
+
export declare type TabularPredictorStatus = "idle" | "loading" | "ready" | "error";
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* The runtime has no kernels for this graph's operators.
|
|
439
|
+
*
|
|
440
|
+
* Measured, and the reason this class exists: importing
|
|
441
|
+
* `onnxruntime-web/webgpu` loads a WebAssembly build without the
|
|
442
|
+
* `ai.onnx.ml` domain, so creating a session over any scikit-learn export
|
|
443
|
+
* fails with `No Op registered for TreeEnsembleClassifier`. The message
|
|
444
|
+
* names the fix, because the raw error points at the model instead of at
|
|
445
|
+
* the import.
|
|
446
|
+
*/
|
|
447
|
+
export declare class UnsupportedGraphError extends TabularError {
|
|
448
|
+
constructor(message: string, options?: ErrorOptions);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Load a tabular model and keep it for the component's lifetime.
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```tsx
|
|
456
|
+
* function RiskWidget() {
|
|
457
|
+
* const { predict, isReady } = useTabularPredictor("/models/risk-v3.onnx");
|
|
458
|
+
* const [score, setScore] = useState<number | null>(null);
|
|
459
|
+
*
|
|
460
|
+
* async function onSubmit(features: number[]) {
|
|
461
|
+
* const { probabilities } = await predict([features]);
|
|
462
|
+
* setScore(probabilities[0]?.[1] ?? null);
|
|
463
|
+
* }
|
|
464
|
+
*
|
|
465
|
+
* return <button disabled={!isReady} onClick={() => onSubmit([1, 2, 3, 4])}>Score</button>;
|
|
466
|
+
* }
|
|
467
|
+
* ```
|
|
468
|
+
*
|
|
469
|
+
* @param source Model URL, or the bytes when the app already has them.
|
|
470
|
+
* Pass `null` to hold off loading (a gate, a lazy tab).
|
|
471
|
+
* @param options Predictor options plus caching.
|
|
472
|
+
* @returns The predictor, its status, and a `predict` bound to it.
|
|
473
|
+
*/
|
|
474
|
+
export declare function useTabularPredictor(source: TabularModelSource | null, options?: UseTabularPredictorOptions): UseTabularPredictorResult;
|
|
475
|
+
|
|
476
|
+
/** Options for {@link useTabularPredictor}. */
|
|
477
|
+
export declare interface UseTabularPredictorOptions extends TabularPredictorOptions {
|
|
478
|
+
/**
|
|
479
|
+
* Cache the model bytes on the device, so later loads work offline.
|
|
480
|
+
*
|
|
481
|
+
* On by default when the source is a URL: an app that runs inference in
|
|
482
|
+
* the browser almost always wants it to keep working without a network,
|
|
483
|
+
* and the failure mode of not caching only shows up in a tunnel.
|
|
484
|
+
*/
|
|
485
|
+
readonly cache?: boolean | ModelCacheOptions;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/** What {@link useTabularPredictor} returns. */
|
|
489
|
+
export declare interface UseTabularPredictorResult {
|
|
490
|
+
/** The loaded predictor, or `null` while loading or on error. */
|
|
491
|
+
readonly predictor: TabularPredictor | null;
|
|
492
|
+
/** Where the load is. */
|
|
493
|
+
readonly status: TabularPredictorStatus;
|
|
494
|
+
/** Why the load failed. */
|
|
495
|
+
readonly error: Error | null;
|
|
496
|
+
/** Whether the model is loaded and can answer. */
|
|
497
|
+
readonly isReady: boolean;
|
|
498
|
+
/**
|
|
499
|
+
* Predict for a batch of rows.
|
|
500
|
+
*
|
|
501
|
+
* @throws When called before the model is ready — awaiting `isReady`
|
|
502
|
+
* is the caller's job, and a silent empty result would hide the bug.
|
|
503
|
+
*/
|
|
504
|
+
readonly predict: (rows: readonly FeatureRow[]) => Promise<TabularPrediction>;
|
|
505
|
+
/** Load the model again, e.g. after a failure or a new version. */
|
|
506
|
+
readonly reload: () => void;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export { }
|
package/dist/tabular.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ORT_WASM_ASSETS as e, configureOrtAssets as t, ortAssetUrls as n } from "./tabular/assets.js";
|
|
2
|
+
import { FeatureShapeError as r, InferenceError as i, ModelFetchError as a, ModelLoadError as o, TabularError as s, UnsupportedGraphError as c } from "./tabular/exceptions.js";
|
|
3
|
+
import { DEFAULT_MODEL_CACHE as l, cacheModelBytes as u, clearModelCache as d, fetchModelBytes as f, isModelCached as p } from "./tabular/cache.js";
|
|
4
|
+
import { DEFAULT_TABULAR_PROVIDERS as m, TabularPredictor as h } from "./tabular/predictor.js";
|
|
5
|
+
import { MANIFEST_FILENAME as g, SUPPORTED_MANIFEST_SCHEMA as _, fetchEdgeManifest as v, loadEdgePackage as y } from "./tabular/manifest.js";
|
|
6
|
+
import { useTabularPredictor as b } from "./tabular/use-tabular-predictor.js";
|
|
7
|
+
export { l as DEFAULT_MODEL_CACHE, m as DEFAULT_TABULAR_PROVIDERS, r as FeatureShapeError, i as InferenceError, g as MANIFEST_FILENAME, a as ModelFetchError, o as ModelLoadError, e as ORT_WASM_ASSETS, _ as SUPPORTED_MANIFEST_SCHEMA, s as TabularError, h as TabularPredictor, c as UnsupportedGraphError, u as cacheModelBytes, d as clearModelCache, t as configureOrtAssets, v as fetchEdgeManifest, f as fetchModelBytes, p as isModelCached, y as loadEdgePackage, n as ortAssetUrls, b as useTabularPredictor };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tempest-react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.1",
|
|
4
4
|
"description": "SDK público da Tempest com componentes, hooks e integrações para projetos React.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -70,6 +70,16 @@
|
|
|
70
70
|
"import": "./dist/editor.js",
|
|
71
71
|
"require": "./dist/editor.cjs"
|
|
72
72
|
},
|
|
73
|
+
"./imaging": {
|
|
74
|
+
"types": "./dist/imaging.d.ts",
|
|
75
|
+
"import": "./dist/imaging.js",
|
|
76
|
+
"require": "./dist/imaging.cjs"
|
|
77
|
+
},
|
|
78
|
+
"./tabular": {
|
|
79
|
+
"types": "./dist/tabular.d.ts",
|
|
80
|
+
"import": "./dist/tabular.js",
|
|
81
|
+
"require": "./dist/tabular.cjs"
|
|
82
|
+
},
|
|
73
83
|
"./vision": {
|
|
74
84
|
"types": "./dist/vision.d.ts",
|
|
75
85
|
"import": "./dist/vision.js",
|