@caldrix-ai/caldrix 0.5.0 → 0.7.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/CHANGELOG.md +21 -0
- package/README.md +64 -9
- package/dist/index.d.ts +70 -4
- package/dist/index.js +1 -1
- package/dist/worker.js +1 -1
- package/host/caldrix_web.d.ts +36 -15
- package/host/caldrix_web.js +1 -1
- package/host/caldrix_web_bg.wasm +0 -0
- package/host/caldrix_web_bg.wasm.d.ts +6 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,27 @@
|
|
|
3
3
|
Format after [Keep a Changelog](https://keepachangelog.com/); versions are independent semver, tagged
|
|
4
4
|
`caldrix-js-v<version>`.
|
|
5
5
|
|
|
6
|
+
## 0.7.0 — 2026-11-05
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- `Caldrix.fit(facts, opts?)` and its types `QuantFacts`, `FitOptions` and `FitResult`: whether a GGUF file would load in this tab, on which tier and at what context (`maxContext`, and `contextClamp` when the default context is clamped), from the facts recorded for it (its size, dimensions, `general.file_type` and tensor table), fetching nothing: no Hub listing, no range and no file. It runs `check`'s option checks, probe and tier choice and the precheck a load of the file runs, with the file's header replaced by the facts; a tensor type this build does not run is an `architecture` refusal naming it. It never rejects; an abort is `kind: "fetch"`. A facts admit is never a load guarantee: `check` and `load` judge the file's own header at the pinned commit. Run in headless Chromium against the loopback hub's tiny fixtures on the wasm tier and on the WebGPU tier on SwiftShader (a CPU), where the fit agreed with a load of the same file and made no request to the hub (`inferno/WEB-VERIFICATION.md` entry 24). Not run: facts the nightly recorded for a real repo; a real adapter.
|
|
11
|
+
|
|
12
|
+
## 0.6.0 — 2026-11-05
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- `LoadOptions.file` and `CheckOptions.file`: the GGUF file to load from a repo id, by name. `Caldrix.load("owner/name", { file: "model-Q4_K_M.gguf" })` loads a GGUF file from a Hub repo, fetched at the listing's resolved commit and checked against the listed size; its config, tokenizer and chat template come from the file's own metadata, and the weights stay quantized. Without `file`, a GGUF repo is a `request` error naming the candidate files (`mmproj*` and sharded files never are). Run in headless Chromium against the loopback hub's tiny fixtures on the wasm tier and on the WebGPU tier on SwiftShader (a CPU), and off-browser, on lavapipe, for a rope-scaled model and for row kernels past 65535 rows (`inferno/WEB-VERIFICATION.md` entry 22). Not run: any real GGUF repo by id in a browser; Llama 3.2 or any 128k-vocabulary model in a browser.
|
|
17
|
+
- A GGUF file's LFS sha256, from the Hub listing, pins its digest (else the Hub's `X-Linked-Etag`, as for safetensors); a mismatch is a `digest` error naming the listing's pin.
|
|
18
|
+
- `Caldrix.load` of a repo that ships `vocab.json` and `merges.txt` (class `Qwen2Tokenizer` or `GPT2Tokenizer`) and neither `tokenizer.json` nor `tokenizer.model` converts the tokenizer in the browser and loads; a pair inferno cannot reproduce exactly, or of another class, is still refused by name before any weight byte (pinned by the host's and the worker's unit tests, not by a browser test); the load ran in headless Chromium on a synthetic tiny model through the loopback hub on the wasm tier and on the WebGPU tier on SwiftShader (a CPU); no real slow-BPE model has run in a browser — the browser engine runs Llama-family models only, and the accepted references are Qwen2 and Qwen3 models (`inferno/WEB-VERIFICATION.md` records nothing for them).
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- A default context (no `maxContext`) whose fit does not stay 64 MiB under the wasm32 heap's 4 GiB ceiling is clamped on both tiers to the largest multiple of 256 whose fit does, even when its own context fits the ceiling (an explicit `maxContext` is held to the ceiling itself; the margin covers the fit's stated, unmeasured terms and is itself unmeasured until a real model runs the clamp in a browser), and `doctor()` carries `maxContext` and `contextClamp` on both tiers (before, on WebGPU only). The precheck's fit counts the host's own placement memory, so every model's needed bytes grow.
|
|
23
|
+
- The quantized row kernels on the WebGPU tier dispatch on a 2D workgroup grid past 65535 rows, so a model whose head has more rows than that (a 128k vocabulary) no longer exceeds the dimension limit; run on lavapipe only (entry 22), on no real adapter.
|
|
24
|
+
- A dense GGUF (`F32`, `F16`, `BF16`) defaults to an f32 plan, the form its reference runs.
|
|
25
|
+
- A GGUF that lists `rope_freqs.weight` has that tensor's data read before any weight byte: the header read stays the header's alone, and when the tensor lies past it, its extent (at most 512 bytes) is fetched as a second range at the same commit; an extent past the cap or the file is a `validate` refusal and is never fetched. The precheck reads the divisors from it, and both tiers apply them to the rope table (entry 22, a synthetic model, off-browser). The second range is covered by unit tests only: no browser run has read one (the loopback fixtures list no `rope_freqs.weight`).
|
|
26
|
+
|
|
6
27
|
## 0.5.0 — 2026-11-04
|
|
7
28
|
|
|
8
29
|
### Added
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ This page states only what `inferno/WEB-VERIFICATION.md` records (in
|
|
|
8
8
|
the Caldrix repository, which is private, so you cannot open it), what the package's own tests run in
|
|
9
9
|
CI, and what the source does.
|
|
10
10
|
|
|
11
|
-
<!-- host-commit:
|
|
11
|
+
<!-- host-commit: 9c3270795c6361d27a96697c482075a19f9d0482 -->
|
|
12
12
|
|
|
13
13
|
The compiled host in `host/` is built from the `caldrix-web` crate at the commit in the marker above.
|
|
14
14
|
The release workflow overwrites that marker with the commit it builds; the value in a source checkout
|
|
@@ -41,6 +41,7 @@ The API, as the package's declarations have it:
|
|
|
41
41
|
class Caldrix {
|
|
42
42
|
static load(model: string, opts?: LoadOptions): Promise<Engine>;
|
|
43
43
|
static check(model: string, opts?: CheckOptions): Promise<CheckResult>;
|
|
44
|
+
static fit(facts: QuantFacts, opts?: FitOptions): Promise<FitResult>;
|
|
44
45
|
}
|
|
45
46
|
class Engine {
|
|
46
47
|
chat(messages: ChatMessage[], opts?: GenerateOptions): AsyncIterable<Delta>;
|
|
@@ -75,6 +76,7 @@ interface LoadOptions {
|
|
|
75
76
|
offline?: boolean;
|
|
76
77
|
onProgress?: (p: { file: string; loaded: number; total: number | null; repo: string; revision: string; provenance?: string }) => void;
|
|
77
78
|
hubBaseUrl?: string;
|
|
79
|
+
file?: string;
|
|
78
80
|
dtype?: "f32" | "bf16";
|
|
79
81
|
maxContext?: number;
|
|
80
82
|
storage?: "auto" | "f32";
|
|
@@ -90,9 +92,17 @@ interface LoadOptions {
|
|
|
90
92
|
under `"auto"` is placed as any alias: WebGPU is probed first, and a refusal of the same kinds falls
|
|
91
93
|
back to wasm.
|
|
92
94
|
- **Quantized aliases**: `smollm2-instruct:q4_K_M` and `smollm2-instruct:q8_0` are one GGUF file each.
|
|
93
|
-
A load reads the file's header with a range request first
|
|
95
|
+
A load reads the file's header with a range request first (and `rope_freqs.weight`'s small extent as a second
|
|
96
|
+
range when it lies past the header), then verifies the whole file against the
|
|
94
97
|
alias's pinned sha256 before parsing it. Both tiers have their kernels (see "What has run, and where");
|
|
95
98
|
on the WebGPU tier the weights stay in their blocks and `doctor().storage` is `"blocks"`.
|
|
99
|
+
- **`file`**: the GGUF file to load from a repo id, by its name at the repo's top level (`"model-Q4_K_M.gguf"`). A repo
|
|
100
|
+
whose listing has no `config.json` with safetensors weights, and a GGUF file at its top level, is a GGUF repo, and loading it without `file` is a
|
|
101
|
+
`request` error that names the candidate files (`mmproj*` files and sharded `-NNNNN-of-NNNNN.gguf` files are never
|
|
102
|
+
candidates). The file is fetched at the listing's resolved commit and checked against the listed size and, when the
|
|
103
|
+
listing carries one, its LFS sha256 (else the Hub's `X-Linked-Etag`); the config, tokenizer and chat template come
|
|
104
|
+
from the file's own metadata, and a `config.json` in the repo is ignored. The weights stay in their blocks. A dense
|
|
105
|
+
GGUF (`F32`, `F16`, `BF16`) defaults to an f32 plan. `file` on an alias or a safetensors repo is a `request` error.
|
|
96
106
|
- **`storage`**: the WebGPU tier's weight storage. `"auto"` stores the block GEMM weights as f16 when the
|
|
97
107
|
adapter has `shader-f16`; `"f32"` keeps them f32 on any adapter. `storage: "f32"` on a quantized alias
|
|
98
108
|
is satisfied: nothing is narrowed, and the weights stay in their blocks. `doctor().storage` reports it
|
|
@@ -100,14 +110,14 @@ interface LoadOptions {
|
|
|
100
110
|
- **`hubBaseUrl`**: where the model files and, for a repo id, the Hub listing (`/api/models/…`) are fetched from (default `https://huggingface.co`); a mirror serving only files loads aliases but not repo ids. `offline`
|
|
101
111
|
uses only the browser's cache and fails with `fetch` for a file it lacks.
|
|
102
112
|
- **`assets`**: where the package's own files come from; see "Network" below.
|
|
103
|
-
- **`doctor()`** reports the tier that runs, `device`, `dtype`, `storage`, `adapter`,
|
|
113
|
+
- **`doctor()`** reports the tier that runs, `device`, `dtype`, `storage`, `adapter`, `maxContext` and `contextClamp`, where each model file came from and whether its digest was checked, `assets` (the
|
|
104
114
|
source and URL of the worker and the `.wasm`: `bundle`, `cdn` or `page`), `aliases` (every alias
|
|
105
115
|
this build loads, each with its `format`, `safetensors` or `gguf`), `provenance` (a densified load's `model:` line, `null` for a model read as it lies), `note` (an nf4 repo's 4-bit note, `null` otherwise), and `why`.
|
|
106
116
|
|
|
107
117
|
## Checking a model before loading it
|
|
108
118
|
|
|
109
119
|
```ts
|
|
110
|
-
type CheckOptions = Pick<LoadOptions, "backend" | "dtype" | "maxContext" | "storage" | "hubBaseUrl" | "signal" | "assets">;
|
|
120
|
+
type CheckOptions = Pick<LoadOptions, "backend" | "dtype" | "maxContext" | "storage" | "hubBaseUrl" | "file" | "signal" | "assets">;
|
|
111
121
|
type CheckResult = { ok: true; backend: "webgpu" | "wasm" } | { ok: false; kind: Kind; message: string };
|
|
112
122
|
|
|
113
123
|
const r = await Caldrix.check("smollm2-instruct");
|
|
@@ -121,7 +131,8 @@ and `assets`, so it starts the same worker and `.wasm` the load would, under the
|
|
|
121
131
|
it runs the same option checks, the same probe and the same tier choice. Its worker then runs the
|
|
122
132
|
load only until the tier is settled: for a repo id the Hub listing (for a LoRA adapter repo, its
|
|
123
133
|
`adapter_config.json` and its base's Hub listing too), then `config.json` and the safetensors index
|
|
124
|
-
(for a GGUF
|
|
134
|
+
(for a GGUF file, an alias's or one named by `file`, the file's header range instead, and
|
|
135
|
+
`rope_freqs.weight`'s extent, at most 512 bytes, as a second range when it lies past the header), the same precheck as `load`, and on the WebGPU
|
|
125
136
|
tier the device open, after which the device is destroyed and the worker ends. It never fetches a
|
|
126
137
|
tokenizer file or a weight, sends no `onProgress` events, and is never `offline`.
|
|
127
138
|
|
|
@@ -139,6 +150,46 @@ through `signal` (`checking <model> was aborted`), so a load might still succeed
|
|
|
139
150
|
for the package's own files applies as on a load (off with `assets.fallback: false`), warned once per check on
|
|
140
151
|
the console. The files a check fetches are written to the cache, and a later load reuses them.
|
|
141
152
|
|
|
153
|
+
## Fitting a GGUF file from its recorded facts
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
type FitOptions = Pick<CheckOptions, "backend" | "maxContext" | "signal" | "assets">;
|
|
157
|
+
type FitResult = { ok: true; backend: "webgpu" | "wasm"; maxContext: number | null; contextClamp: NonNullable<DoctorReport["contextClamp"]> | null } | { ok: false; kind: Kind; message: string };
|
|
158
|
+
|
|
159
|
+
// `facts` is a `QuantFacts`: what the nightly records for one GGUF file of a repo.
|
|
160
|
+
const r = await Caldrix.fit(facts);
|
|
161
|
+
if (r.ok) console.log(`a load would run on ${r.backend} at context ${r.maxContext}`);
|
|
162
|
+
else if (r.kind !== "fetch") console.log(`a load would be refused: ${r.message}`);
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
`Caldrix.fit` says whether a GGUF file would load in this tab, on which tier and at what context,
|
|
166
|
+
from the facts recorded for it (`QuantFacts`: the file's name, size and digest, its architecture and
|
|
167
|
+
dimensions, the element count per tensor type, the base model (`base_model`), `general.file_type`, and the tensor table, each
|
|
168
|
+
tensor's name, type and dims), and it fetches nothing: no Hub listing, no range and no file. It takes
|
|
169
|
+
`check`'s tier and context options and `assets`, runs the same option checks, probe and tier choice,
|
|
170
|
+
and in its worker the same precheck a load of the file runs, with the file's header replaced by the
|
|
171
|
+
facts; on the WebGPU tier it opens the device and destroys it again, and under `backend: "auto"` a
|
|
172
|
+
WebGPU refusal answers wasm as `check`'s does. `{ ok: true }` carries the tier, `maxContext` (the
|
|
173
|
+
context a load would plan) and `contextClamp` (the clamp's line when the default context was
|
|
174
|
+
clamped, else `null`), as a load's `doctor()` reports them.
|
|
175
|
+
|
|
176
|
+
A caller holding a larger record (the nightly's `web-quants.json` entry, say) passes only these keys:
|
|
177
|
+
an unknown key is refused as `validate`, so a page projects each entry onto them. `fit` answers the
|
|
178
|
+
default weight storage for the tier; `FitOptions` has no `storage`, so a page that loads a dense file
|
|
179
|
+
with `storage: "f32"` gets `fit`'s answer for the default storage (quantized files are unaffected).
|
|
180
|
+
|
|
181
|
+
The tensor types `fit` admits are the ones this build runs: a tensor of any other type is
|
|
182
|
+
`{ ok: false, kind: "architecture" }`, its name and type in the message. Facts that are not a plain
|
|
183
|
+
object, or are past the size a fit takes once serialised, are `request`; facts the host refuses (an
|
|
184
|
+
unknown or missing key, a table past the GGUF reader's caps) are `validate`; a file past this tab's
|
|
185
|
+
limits is `fit`, and a worker that cannot start or answers out of protocol is `backend`. `fit` never rejects; `kind: "fetch"` (an abort through `signal`, `the fit was
|
|
186
|
+
aborted`) leaves the answer unknown.
|
|
187
|
+
|
|
188
|
+
A facts admit is never a load guarantee. `check` and `load` judge the file's own header at the commit
|
|
189
|
+
the listing pins, and the facts cannot show what only the file holds: the values of
|
|
190
|
+
`rope_freqs.weight`, a missing `attention.layer_norm_rms_epsilon`, or a tensor whose bytes or element
|
|
191
|
+
count disagree with the table. Facts recorded from an older commit of a repo answer for that file.
|
|
192
|
+
|
|
142
193
|
## Constrained decoding
|
|
143
194
|
|
|
144
195
|
```ts
|
|
@@ -176,7 +227,7 @@ one of the strings and stops. `{ json: <schema> }` yields a JSON value matching
|
|
|
176
227
|
## What has run, and where
|
|
177
228
|
|
|
178
229
|
Only these model runs are recorded (`inferno/WEB-VERIFICATION.md`, entries 5, 8 and 9, entries 10,
|
|
179
|
-
11, 12 and 14 for the quantized aliases,
|
|
230
|
+
11, 12 and 14 for the quantized aliases, entries 16 and 17 for the adapter and nf4 repos, entry 22 for a GGUF file in a repo, and entry 24 for `Caldrix.fit`); nothing
|
|
180
231
|
else is claimed.
|
|
181
232
|
|
|
182
233
|
- **Model:** SmolLM2-135M-Instruct, one prompt, 8 greedy tokens; the adapter and nf4 repos below add a
|
|
@@ -199,14 +250,18 @@ else is claimed.
|
|
|
199
250
|
- quantized aliases: off-browser at the desk on both tiers (`inferno/WEB-VERIFICATION.md` entries 10 and 11); in headless Chromium through `Caldrix.load` on both tiers on the pinned files, WebGPU on Dawn/SwiftShader, a CPU (entry 12); on the operator's Mac through `Caldrix.load` on both tiers, WebGPU on the Mac's own adapter, vendor `apple`, architecture `metal-3`, token-exact (entry 14).
|
|
200
251
|
- adapter and nf4 repos by id (a LoRA adapter over SmolLM2-135M-Instruct, and SmolLM2-360M-Instruct's bitsandbytes nf4 repo, each at a pinned sha): off-browser at the desk on both tiers (`inferno/WEB-VERIFICATION.md` entry 16: wasm both pairs and WebGPU the LoRA pair token-exact, the f32 plan at f32 weight storage; the WebGPU nf4 pair stopped at lavapipe's storage-buffer binding limit); in headless Chromium through `Caldrix.load` by repo id on both tiers, both pairs token-exact, the f32 plan at f32 weight storage, WebGPU on Dawn/SwiftShader, a CPU (entry 17).
|
|
201
252
|
- `Caldrix.check`: in headless Chromium against the loopback hub (`inferno/WEB-VERIFICATION.md` entry 20): on a repo id, check and load agreed on the wasm tier and, under `--enable-unsafe-webgpu`, on the WebGPU tier on Dawn/SwiftShader, a CPU, and the check fetched no tokenizer file and no weight; an index past the wasm ceiling checked as `fit`, an unknown repo id as `fetch`.
|
|
202
|
-
-
|
|
253
|
+
- a GGUF file in a repo by name (`file`): in headless Chromium through `Caldrix.load` against the loopback hub's tiny fixtures, on the wasm tier and on the WebGPU tier on Dawn/SwiftShader, a CPU, token-exact to the test harness's own tokens, with the name selecting the file, a digest mismatch refused as `digest`, and a header context past the wasm32 heap clamped and reported by `doctor`; off-browser, a rope-scaled quantized model token-exact on both tiers and the quantized row kernels past the grid dimension limit on lavapipe, a CPU (`inferno/WEB-VERIFICATION.md` entry 22).
|
|
254
|
+
- `Caldrix.fit`: in headless Chromium against the loopback hub's tiny fixtures, on the wasm tier and on the WebGPU tier on Dawn/SwiftShader, a CPU: the committed facts of the hub's Q8_0 file and of its long-context copy answered `ok` with the tier, and the `maxContext` and `contextClamp` a load of that file reported in `doctor()`, with no request to the hub; the facts with one tensor's type changed to one this build lacks answered `architecture` naming it; off-browser, the fit from facts equals the fit from the header on every tiny fixture (`inferno/WEB-VERIFICATION.md` entry 24).
|
|
255
|
+
- **Not run:** any real GGUF repo by id in a browser; Llama 3.2 or any model with a 128k vocabulary in a browser; a 2D-grid dispatch on a real adapter (the WebGPU row kernels past the grid dimension limit ran on lavapipe only); the WebGPU heap clamp in a browser; any other WebGPU adapter or GPU; a headed browser; the browser stages inside a sandbox; the scalar
|
|
203
256
|
(non-SIMD) wasm spelling in a browser; real-Hub digest behaviour (the runs used a loopback Hub stand-in); a real Hub listing for a repo id
|
|
204
257
|
(the loopback hub served the pinned snapshots); any browser other than Playwright's headless Chromium; any other model;
|
|
205
258
|
`Caldrix.check` against a real adapter's buffer limit (its unit tests only), against the real Hub, or in any other
|
|
206
|
-
browser or on any other device. No performance figure is recorded
|
|
259
|
+
browser or on any other device; `Caldrix.fit` on facts the nightly recorded for a real repo, or on a real adapter. No performance figure is recorded
|
|
207
260
|
or claimed.
|
|
208
261
|
|
|
209
|
-
## The
|
|
262
|
+
## The default context
|
|
263
|
+
|
|
264
|
+
On both tiers, a default context whose fit does not stay 64 MiB under the wasm32 heap's 4 GiB ceiling is clamped to the largest multiple of 256 whose fit does (a margin for the fit's stated, unmeasured terms; the margin itself is not yet measured; an explicit `maxContext` is held to the ceiling itself), and on WebGPU the smaller of that and the grid bound applies (`doctor()` reports it as above). The heap clamp ran in a browser on the wasm tier only, on a tiny fixture with a very large header context; on the WebGPU tier that run printed only the grid clamp (`inferno/WEB-VERIFICATION.md` entry 22).
|
|
210
265
|
|
|
211
266
|
Without `maxContext`, the WebGPU tier clamps the context so the attention kernel's grid stays within
|
|
212
267
|
`maxComputeWorkgroupsPerDimension`. At the standard 65535 workgroups per dimension, SmolLM2's 8192
|
package/dist/index.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ interface HostDoctor {
|
|
|
61
61
|
revision: string | null;
|
|
62
62
|
source: null;
|
|
63
63
|
line: string;
|
|
64
|
-
/**
|
|
64
|
+
/** The host's, on both tiers: the context the model was loaded at, and the clamp's line (`null` otherwise) when the default was clamped (to the prefill bound on WebGPU, to the wasm32 heap on either). */
|
|
65
65
|
maxContext?: number;
|
|
66
66
|
contextClamp?: string | null;
|
|
67
67
|
/** The worker's: the weights' storage form on WebGPU (`blocks` for a quantized model; `null` on wasm). */
|
|
@@ -110,6 +110,12 @@ interface LoadOptions {
|
|
|
110
110
|
provenance?: string;
|
|
111
111
|
}) => void;
|
|
112
112
|
hubBaseUrl?: string;
|
|
113
|
+
/**
|
|
114
|
+
* The GGUF file to load from a Hub repo id whose repo lists GGUF files (a name in the repo's top
|
|
115
|
+
* level, as `"model-Q4_K_M.gguf"`). Required for such a repo, whose refusal lists the choices;
|
|
116
|
+
* refused for an alias and for any other repo.
|
|
117
|
+
*/
|
|
118
|
+
file?: string;
|
|
113
119
|
dtype?: "f32" | "bf16";
|
|
114
120
|
maxContext?: number;
|
|
115
121
|
/**
|
|
@@ -204,7 +210,7 @@ type GenerateOptions = GenerationOptions & {
|
|
|
204
210
|
* What `Caldrix.check` takes: the options that decide the tier and the files the check reads, and
|
|
205
211
|
* `assets`, so the check starts the same worker and `.wasm` (and the same fallback rule) as the load.
|
|
206
212
|
*/
|
|
207
|
-
type CheckOptions = Pick<LoadOptions, "backend" | "dtype" | "maxContext" | "storage" | "hubBaseUrl" | "signal" | "assets">;
|
|
213
|
+
type CheckOptions = Pick<LoadOptions, "backend" | "dtype" | "maxContext" | "storage" | "hubBaseUrl" | "file" | "signal" | "assets">;
|
|
208
214
|
/**
|
|
209
215
|
* `Caldrix.check`'s answer: the tier a load of the model would end on in this tab, or why it would be
|
|
210
216
|
* refused. `kind: "fetch"` (a file could not be fetched, or the check was aborted) leaves it unknown.
|
|
@@ -217,6 +223,53 @@ type CheckResult = {
|
|
|
217
223
|
kind: Kind;
|
|
218
224
|
message: string;
|
|
219
225
|
};
|
|
226
|
+
/**
|
|
227
|
+
* A GGUF file's facts as the nightly records them for each quant it promotes: the file, its size and
|
|
228
|
+
* digest, the architecture and dimensions read from its header, the element count per tensor type,
|
|
229
|
+
* the base model, the header's `general.file_type`, and the tensor table (`[name, type, dims]`).
|
|
230
|
+
*/
|
|
231
|
+
interface QuantFacts {
|
|
232
|
+
file: string;
|
|
233
|
+
bytes: number;
|
|
234
|
+
sha256: string;
|
|
235
|
+
arch: string;
|
|
236
|
+
dims: {
|
|
237
|
+
hidden: number;
|
|
238
|
+
n_layers: number;
|
|
239
|
+
n_heads: number;
|
|
240
|
+
n_kv_heads: number;
|
|
241
|
+
head_dim: number;
|
|
242
|
+
ffn: number;
|
|
243
|
+
vocab: number;
|
|
244
|
+
context_length: number;
|
|
245
|
+
/** 1 when the file has no `output.weight` (the head is the embedding), else 0. */
|
|
246
|
+
tied: number;
|
|
247
|
+
};
|
|
248
|
+
/** Tensor type name to element count. */
|
|
249
|
+
elements: Record<string, number>;
|
|
250
|
+
base_model: string | null;
|
|
251
|
+
/** `general.file_type`, `null` when the header states none. */
|
|
252
|
+
file_type: number | null;
|
|
253
|
+
/** `[name, type name, dims]` of every tensor, in header order. */
|
|
254
|
+
tensors: [string, string, number[]][];
|
|
255
|
+
}
|
|
256
|
+
/** What `Caldrix.fit` takes: the tier and context options of a check, and its `signal` and `assets`. */
|
|
257
|
+
type FitOptions = Pick<CheckOptions, "backend" | "maxContext" | "signal" | "assets">;
|
|
258
|
+
/**
|
|
259
|
+
* `Caldrix.fit`'s answer: the tier a load of the file would end on in this tab, and the context it
|
|
260
|
+
* would be loaded at (`maxContext`, and `contextClamp`, the clamp's line when the default was
|
|
261
|
+
* clamped), or why it would be refused. `kind: "fetch"` (the fit was aborted) leaves it unknown.
|
|
262
|
+
*/
|
|
263
|
+
type FitResult = {
|
|
264
|
+
ok: true;
|
|
265
|
+
backend: "webgpu" | "wasm";
|
|
266
|
+
maxContext: number | null;
|
|
267
|
+
contextClamp: NonNullable<DoctorReport["contextClamp"]> | null;
|
|
268
|
+
} | {
|
|
269
|
+
ok: false;
|
|
270
|
+
kind: Kind;
|
|
271
|
+
message: string;
|
|
272
|
+
};
|
|
220
273
|
declare class Caldrix {
|
|
221
274
|
/** Load a model, a built-in alias or a Hub repo id (`owner/name[@revision]`), into its own worker. */
|
|
222
275
|
static load(model: string, opts?: LoadOptions): Promise<Engine>;
|
|
@@ -225,12 +278,25 @@ declare class Caldrix {
|
|
|
225
278
|
* loading it: the same option checks, probe and tier choice as `load`, then the worker runs the
|
|
226
279
|
* load only until its tier is settled (the Hub listing for a repo id, and for a LoRA adapter repo
|
|
227
280
|
* its `adapter_config.json` and its base's listing; `config.json` and the safetensors index, or a
|
|
228
|
-
* GGUF
|
|
281
|
+
* GGUF file's header range and, when it lies past that, `rope_freqs.weight`'s extent; the precheck; on WebGPU the device open, destroyed again). It fetches
|
|
229
282
|
* no tokenizer file and no weight. `assets` starts the same worker and `.wasm` the load would.
|
|
230
283
|
* Never rejects: every refusal is `{ ok: false, kind, message }`, and an abort is `kind: "fetch"`,
|
|
231
284
|
* the answer unknown.
|
|
232
285
|
*/
|
|
233
286
|
static check(model: string, opts?: CheckOptions): Promise<CheckResult>;
|
|
287
|
+
/**
|
|
288
|
+
* Whether a GGUF file would load in this tab, from the facts the nightly recorded for it, without
|
|
289
|
+
* fetching a byte of it: the same tier choice as `check` (on WebGPU the precheck and the device
|
|
290
|
+
* open, destroyed again; under `auto` a refusal of either moves the answer to wasm), with the
|
|
291
|
+
* file's head replaced by `facts`. No listing, range or file is fetched. Answers the tier and the
|
|
292
|
+
* context a load would plan (`maxContext`, and `contextClamp` when the default was clamped). A
|
|
293
|
+
* facts admit is no load guarantee: `check` and `load` judge the file's own header. Never
|
|
294
|
+
* rejects: every refusal is `{ ok: false, kind, message }` (`request` for `facts` that are not a
|
|
295
|
+
* plain object or past `FACTS_MAX_BYTES` once serialised, `validate` for facts the host refuses,
|
|
296
|
+
* `architecture` for a tensor type this build does not run, `fit` for a miss), and an abort is
|
|
297
|
+
* `kind: "fetch"`, the answer unknown.
|
|
298
|
+
*/
|
|
299
|
+
static fit(facts: QuantFacts, opts?: FitOptions): Promise<FitResult>;
|
|
234
300
|
}
|
|
235
301
|
declare class Engine {
|
|
236
302
|
#private;
|
|
@@ -299,4 +365,4 @@ interface Capabilities {
|
|
|
299
365
|
}
|
|
300
366
|
declare function probe(): Promise<Capabilities>;
|
|
301
367
|
|
|
302
|
-
export { type AssetSource, Caldrix, CaldrixError, type Capabilities, type ChatMessage, type CheckOptions, type CheckResult, type Delta, type DoctorReport, Engine, type GenerateOptions, type GenerationOptions, type Kind, type LoadOptions, probe };
|
|
368
|
+
export { type AssetSource, Caldrix, CaldrixError, type Capabilities, type ChatMessage, type CheckOptions, type CheckResult, type Delta, type DoctorReport, Engine, type FitOptions, type FitResult, type GenerateOptions, type GenerationOptions, type Kind, type LoadOptions, type QuantFacts, probe };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as F,b as i,d as _}from"./chunk-PZGTLL5H.js";function W(e){return typeof e=="object"&&e!==null}function V(e){return W(e)&&typeof e.token=="number"&&typeof e.text=="string"&&typeof e.done=="boolean"&&(e.finishReason===null||e.finishReason==="stop"||e.finishReason==="length"||e.finishReason==="abort")&&typeof e.promptTokens=="number"&&typeof e.completionTokens=="number"&&typeof e.cachedTokens=="number"&&(e.logprobs===void 0||Array.isArray(e.logprobs)&&e.logprobs.every(t=>W(t)&&typeof t.token=="number"&&typeof t.logprob=="number"))}function Q(e){return!W(e)||typeof e.url!="string"?!1:e.failed===void 0||W(e.failed)&&typeof e.failed.url=="string"&&typeof e.failed.reason=="string"}function L(e){if(!W(e)||typeof e.id!="number")return!1;switch(e.type){case"ready":return e.id===0&&typeof e.url=="string";case"host":return Q(e.hostWasm);case"progress":return typeof e.file=="string"&&typeof e.loaded=="number"&&(e.total===null||typeof e.total=="number")&&typeof e.repo=="string"&&typeof e.revision=="string"&&(e.provenance===void 0||typeof e.provenance=="string");case"loaded":return W(e.doctor)&&W(e.sources)&&(e.fallback===void 0||typeof e.fallback=="string")&&Object.values(e.sources).every(t=>W(t)&&(t.source==="cache"||t.source==="network")&&typeof t.verified=="boolean");case"checked":return e.backend==="webgpu"||e.backend==="wasm";case"delta":return V(e.delta);case"result":return"value"in e;case"error":return F(e.kind)&&typeof e.message=="string"&&(e.fatal===void 0||typeof e.fatal=="string");default:return!1}}function w(e){let t;try{t=JSON.stringify(e)??String(e)}catch{t=String(e)}return t.length>200&&(t=`${t.slice(0,200)}...`),new i("backend",`the worker sent a malformed message: ${t}`)}var C=(...e)=>new Uint8Array(e),Z={simd:C(0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11),relaxedSimd:C(0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,15,1,13,0,65,1,253,15,65,2,253,15,253,128,2,11),bulkMemory:C(0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,3,1,0,1,10,14,1,12,0,65,0,65,0,65,0,252,10,0,0,11),threads:C(0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11),memory64:C(0,97,115,109,1,0,0,0,5,3,1,4,1),tailCall:C(0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,6,1,4,0,18,0,11),exceptions:C(0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,16,1,14,0,2,105,31,64,1,3,0,0,11,0,11,26,11)};function j(){let e={};for(let[t,n]of Object.entries(Z))e[t]=WebAssembly.validate(n);return e}var Y=1e3,S=Symbol("timed out");async function N(e){let t,n=new Promise(r=>{t=setTimeout(()=>r(S),Y)});try{return await Promise.race([e,n])}finally{clearTimeout(t)}}var J=e=>e instanceof Error?e.message:String(e);function H(){let e=globalThis.navigator;return typeof e=="object"&&e!==null?e:{}}function E(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function ee(){let e={available:!1,maxTextureSize:null,floatColorBuffer:null};try{let t=null;if(typeof OffscreenCanvas<"u"?t=new OffscreenCanvas(1,1):typeof document<"u"&&(t=document.createElement("canvas")),t===null)return e;let n=t,r=n.getContext("webgl2"),o=r??n.getContext("webgl");if(!o)return e;let a=E(o.getParameter(o.MAX_TEXTURE_SIZE)),l=o.getExtension(r?"EXT_color_buffer_float":"WEBGL_color_buffer_float")!==null;return o.getExtension("WEBGL_lose_context")?.loseContext(),{available:!0,maxTextureSize:a,floatColorBuffer:l}}catch{return e}}async function te(e){let t=e.info??{};if(!e.info&&typeof e.requestAdapterInfo=="function")try{t=await e.requestAdapterInfo()}catch{t={}}let n={},r=[];if(e.limits)for(let o in e.limits){let a=e.limits[o];typeof a=="number"?(n[o]=a,Number.isSafeInteger(a)||r.push(`${o} = ${a} (not a safe integer)`)):typeof a!="function"&&r.push(`${o} = ${JSON.stringify(a)??String(a)} (not a number)`)}return{vendor:t.vendor??"",architecture:t.architecture??"",device:t.device??"",description:t.description??"",features:e.features?[...e.features]:[],limits:n,unrepresentable:r}}async function re(){let e=H().gpu;if(!e||typeof e.requestAdapter!="function")return{webgpu:null,available:!1,reason:"no navigator.gpu"};let t;try{let r=await N(e.requestAdapter());if(r===S)return{webgpu:null,available:!1,reason:"requestAdapter timed out"};t=r}catch(r){return{webgpu:null,available:!1,reason:`requestAdapter failed: ${J(r)}`}}if(!t)return{webgpu:null,available:!1,reason:"requestAdapter returned null"};let n=await te(t);try{let r=await N(t.requestDevice());if(r===S)return{webgpu:n,available:!1,reason:"requestDevice timed out"};r.destroy?.()}catch(r){return{webgpu:n,available:!1,reason:`requestDevice refused: ${J(r)}`}}return{webgpu:n,available:!0}}function ne(e){return e.webgpu.available&&e.webgpu.built?"webgpu":"wasm"}function oe(e,t,n){let r=e.webgpu?.unrepresentable??[],o=r.length>0?`; adapter limits ${r.join(", ")}: the host reads them as missing`:"";return se(e,t,n)+o}function se(e,t,n){if(n==="webgpu"){let o=e.webgpu,a=o.features.includes("shader-f16")?" with shader-f16":"";return`WebGPU adapter present (${o.vendor} ${o.architecture})${a}: webgpu`}let r=e.wasm.simd?"with simd128":"without simd128";return e.webgpu===null?`no WebGPU adapter (${t.reason??"unavailable"}): wasm ${r}`:`WebGPU adapter present but unusable (${t.reason}): wasm ${r}`}async function O(){let e=H(),t=await re(),n={wasm:j(),threads:{sharedArrayBuffer:typeof SharedArrayBuffer<"u",crossOriginIsolated:globalThis.crossOriginIsolated===!0,hardwareConcurrency:E(e.hardwareConcurrency)},webgl:ee(),webgpu:t.webgpu,memory:{deviceMemoryGiB:E(e.deviceMemory)},tiers:{webgpu:t.available?{available:!0,built:!0}:{available:!1,built:!0,reason:t.reason},webgl:{available:!1,built:!1,reason:"not built"},wasm:{available:!0,built:!0}}};n.tiers.webgl.available=n.webgl.available;let r=ne(n.tiers);return{...n,chosen:r,why:oe(n,t,r)}}function K(e){let t=e.webgpu===null?null:{vendor:e.webgpu.vendor,architecture:e.webgpu.architecture,device:e.webgpu.device,description:e.webgpu.description,features:e.webgpu.features,limits:Object.fromEntries(Object.entries(e.webgpu.limits).filter(([,n])=>Number.isSafeInteger(n)))};return JSON.stringify({wasm:{simd:e.wasm.simd,relaxedSimd:e.wasm.relaxedSimd,bulkMemory:e.wasm.bulkMemory,threads:e.wasm.threads,memory64:e.wasm.memory64,tailCall:e.wasm.tailCall,exceptions:e.wasm.exceptions},threads:{sharedArrayBuffer:e.threads.sharedArrayBuffer,crossOriginIsolated:e.threads.crossOriginIsolated,hardwareConcurrency:e.threads.hardwareConcurrency},webgpu:t,memory:{deviceMemoryGiB:e.memory.deviceMemoryGiB}})}var ae="https://huggingface.co";function ie(e){return typeof location<"u"?new URL(String(e),location.href):new URL(String(e))}var le="https://cdn.jsdelivr.net/npm/@caldrix-ai/caldrix@0.5.0/";function I(e){return e instanceof Error?e.message:String(e)}function D(e,t){if(t!==void 0){if(typeof t!="string"&&!(t instanceof URL))throw new i("request",`assets.${e} is a string or a URL, not ${typeof t}`);try{return typeof location<"u"?new URL(t,location.href):new URL(t)}catch{throw new i("request",`assets.${e} ${JSON.stringify(String(t))} is not a URL`)}}}function ue(e,t){let n=G(e,t),r=null,o=()=>{r!==null&&URL.revokeObjectURL(r),r=null};try{return!n&&!t?{worker:new Worker(new URL("./worker.js",import.meta.url),{type:"module"}),revoke:o,literal:!0}:n?(r=URL.createObjectURL(new Blob([`import ${JSON.stringify(e.href)};`],{type:"text/javascript"})),{worker:new Worker(r,{type:"module"}),revoke:o}):{worker:new Worker(e,{type:"module"}),revoke:o}}catch(a){throw o(),a}}function de(e){return typeof location<"u"&&e.origin!==location.origin}function G(e,t){return de(e)&&(t||e.protocol==="http:"||e.protocol==="https:")}function P(e){return!e.chosen&&!G(e.url,!1)?`the package's worker (dist/worker.js as the page's bundler emitted it, or ${e.url.href} unbundled)`:`the engine's worker from ${e.url.href}${G(e.url,e.chosen)?" (through a same-origin shim)":""}`}var U=class{constructor(t){this.reason=t}reason};function ce(e,t,n){return new Promise((r,o)=>{let a;try{a=ue(e.url,e.chosen)}catch(c){o(new U(`the page could not construct it: ${I(c)}`));return}let{worker:l,revoke:m}=a,u=()=>d(n()),d=(c,s=e.url)=>{if(m(),l.onmessage=null,l.onerror=null,t?.removeEventListener("abort",u),c===null)return r({worker:l,url:s});l.terminate(),o(c)};t?.addEventListener("abort",u,{once:!0}),l.onerror=c=>d(new U(c.message||"it did not load")),l.onmessage=c=>{let s=c.data;if(!L(s)||s.id!==0)return d(w(s));if(s.type==="ready")return a.literal?URL.canParse(s.url)?d(null,new URL(s.url)):d(w(s)):d(null);if(s.type==="error")return d(new U(s.message));d(w(s))}})}async function fe(e,t,n,r){let o=[];for(let d of e)try{let{worker:c,url:s}=await ce(d,n,r),b=o[0];return{worker:c,used:d,url:s,...b!==void 0?{failed:{what:P(b.t),reason:b.reason}}:{}}}catch(c){if(!(c instanceof U))throw c;o.push({t:d,reason:c.reason})}let[a,l]=o;if(a!==void 0&&l!==void 0){let d=l.t.url.origin;throw new i("backend",`${P(a.t)} did not start (${a.reason}), nor from the CDN fallback ${l.t.url.href} (${l.reason}); serve dist/ and host/ beside the bundle, set assets.worker to where the page serves them, or allow ${d} in the page's Content-Security-Policy (worker-src blob: for the same-origin shim that starts it, script-src ${d} for the modules it imports, connect-src ${d} for the .wasm)`)}let m=a,u=t&&m.t.source==="bundle"?"; the CDN fallback is off (assets.fallback is false)":"";throw new i("backend",`${P(m.t)} did not start: ${m.reason}${u}; caldrix.js runs inference in a Web Worker and has no main-thread mode`)}function pe(e,t,n){let r=n!==void 0?`, and with it the host .wasm from ${n}`:"";return`${e.what} did not start (${e.reason}); it was loaded from the CDN fallback ${t}${r}`}function be(e){return`the host .wasm could not be fetched from ${e.failed.url} (${e.failed.reason}); it was fetched from the CDN fallback ${e.url}`}function X(e){console.warn(`caldrix.js: ${e}. Serve dist/ and host/ beside the bundle or set assets.worker/assets.hostWasm; assets.fallback: false turns the fallback off.`)}function me(e){let t={text:e.text,token:e.token,done:e.done};return e.logprobs!==void 0&&(t.logprobs=e.logprobs),e.done&&(e.finishReason!==null&&(t.finishReason=e.finishReason),t.usage={promptTokens:e.promptTokens,completionTokens:e.completionTokens,cachedTokens:e.cachedTokens}),t}async function z(e,t,n){let r=t.backend??"auto";if(r==="webgl")throw new i("backend","the webgl backend is not built");if(r!=="auto"&&r!=="webgpu"&&r!=="wasm")throw new i("request",`backend ${JSON.stringify(r)} is not auto, webgpu, wasm or webgl`);if(typeof e!="string"||e==="")throw new i("request","load takes a model alias or a Hub repo id (owner/name[@revision]), a non-empty string");let o=D("worker",t.assets?.worker),a=D("hostWasm",t.assets?.hostWasm),l=t.assets?.fallback??!0;if(typeof l!="boolean")throw new i("request",`assets.fallback is true or false, not ${JSON.stringify(l)}`);let m=D("cdn",t.assets?.cdn)??new URL(le);m.pathname.endsWith("/")||(m.pathname+="/");let u=[o!==void 0?{url:o,chosen:!0,source:"page"}:{url:ie(new URL("./worker.js",import.meta.url)),chosen:!1,source:"bundle"}];l&&o===void 0&&u.push({url:new URL("dist/worker.js",m),chosen:!0,source:"cdn"});let d=l&&a===void 0?new URL("host/caldrix_web_bg.wasm",m).href:void 0,c=t.storage??"auto";if(c!=="auto"&&c!=="f32")throw new i("request",`storage ${JSON.stringify(c)} is not auto or f32`);if(r==="wasm"&&c==="f32")throw new i("request",`storage "f32" is the WebGPU tier's weight storage; backend "wasm" takes none`);if(t.hubBaseUrl!==void 0){let h=t.hubBaseUrl,x=!1;if(typeof h=="string")try{let M=new URL(h);x=M.protocol==="http:"||M.protocol==="https:"}catch{x=!1}if(!x)throw new i("request",`hubBaseUrl must be an absolute http(s) URL, not ${JSON.stringify(h).slice(0,80)}`)}let s=()=>new i("fetch",`${n?"checking":"loading"} ${e} was aborted`),b=t.signal;if(b?.aborted)throw s();let f=await O(),g,v;if(r==="auto"&&t.dtype==="bf16"&&f.chosen==="webgpu")g="wasm",v=`bf16 requested: wasm (the WebGPU tier runs the f32 plan only); ${f.why}`;else if(r==="auto")g=f.chosen,v=f.why;else if(r==="webgpu"){if(!f.tiers.webgpu.available)throw new i("backend",`backend "webgpu" was asked for, but the probe found no usable WebGPU adapter: ${f.tiers.webgpu.reason??f.why}`);g="webgpu",v=`backend "webgpu" asked for; ${f.why}`}else g="wasm",v=`backend "wasm" asked for; ${f.why}`;let p=f.webgpu?.unrepresentable??[];if(b?.aborted)throw s();let k=await fe(u,!l,b,s),{worker:R}=k,$=k.url,A={id:1,type:"load",model:e,probeJson:K(f),request:{backend:g,...t.dtype!==void 0?{dtype:t.dtype}:{},...t.maxContext!==void 0?{maxContext:t.maxContext}:{},...g==="webgpu"&&c==="f32"?{f16:!1}:{}},...r==="auto"&&g==="webgpu"?{auto:!0}:{},...n?{check:!0}:{},offline:t.offline??!1,hubBaseUrl:t.hubBaseUrl??ae,...a!==void 0?{hostWasm:a.href}:{},...d!==void 0?{cdnWasm:d}:{}},y={worker:R,used:k.used,workerUrl:$,caps:f,why:v,hostWasm:a,request:A,signal:b,aborted:s,fellBack:null,wasm:null,noted:h=>y.fellBack===null?h:new i(h.kind,`${h.message} (after a CDN fallback: ${y.fellBack})`,h.missing),host:h=>y.wasm!==null?!1:(y.wasm=h,h.failed!==void 0&&(y.fellBack=be({...h,failed:h.failed}),X(y.fellBack)),!0),workerError:h=>{let x=h.kind==="probe"&&p.length>0?`; the browser gave ${p.join(", ")}, which the host reads as missing`:"";return new i(h.kind,h.message+x)}};if(k.failed!==void 0&&(y.fellBack=pe(k.failed,$.href,a===void 0?d:void 0),X(y.fellBack)),b?.aborted)throw R.terminate(),y.noted(s());return y}function B(e){return e instanceof i?{ok:!1,kind:e.kind,message:e.message}:{ok:!1,kind:"backend",message:I(e)}}var q=class{static async load(t,n={}){let r=await z(t,n,!1),{worker:o,workerUrl:a,signal:l,request:m,hostWasm:u,caps:d}=r;return new Promise((c,s)=>{let b=()=>g(r.aborted()),f=()=>{o.onmessage=null,o.onerror=null,l?.removeEventListener("abort",b)},g=v=>{f(),o.terminate(),s(r.noted(v))};if(l?.addEventListener("abort",b,{once:!0}),l?.aborted)return g(r.aborted());o.onerror=v=>g(new i("backend",`the engine's worker from ${a.href} failed: ${v.message||"it did not start"}`)),o.onmessage=v=>{let p=v.data;if(!L(p)||p.id!==m.id)return g(w(p));switch(p.type){case"host":return r.host(p.hostWasm)?void 0:g(w(p));case"progress":try{n.onProgress?.({file:p.file,loaded:p.loaded,total:p.total,repo:p.repo,revision:p.revision,...p.provenance!==void 0?{provenance:p.provenance}:{}})}catch(k){g(k instanceof i?k:new i("request",`onProgress threw: ${I(k)}`))}return;case"loaded":{let k=r.wasm;if(k===null)return g(w(p));f();let R=r.used.source,$=u!==void 0||R==="page"&&k.failed===void 0?"page":k.failed!==void 0||R==="cdn"?"cdn":"bundle",A={worker:{source:R,url:a.href},hostWasm:{source:$,url:k.url}},y={...p.doctor,source:p.sources,why:p.fallback!==void 0?`${p.fallback}; ${d.why}`:r.why,assets:A};c(new T(o,y));return}case"error":return g(r.workerError(p));default:return g(w(p))}},o.postMessage(m)})}static async check(t,n={}){let r;try{let u=n??{};r=await z(t,{...u.backend!==void 0?{backend:u.backend}:{},...u.dtype!==void 0?{dtype:u.dtype}:{},...u.maxContext!==void 0?{maxContext:u.maxContext}:{},...u.storage!==void 0?{storage:u.storage}:{},...u.hubBaseUrl!==void 0?{hubBaseUrl:u.hubBaseUrl}:{},...u.signal!==void 0?{signal:u.signal}:{},...u.assets!==void 0?{assets:u.assets}:{}},!0)}catch(u){return B(u)}let{worker:o,workerUrl:a,signal:l,request:m}=r;return new Promise(u=>{let d=()=>s(r.aborted()),c=b=>{o.onmessage=null,o.onerror=null,l?.removeEventListener("abort",d),o.terminate(),u(b)},s=b=>c(B(r.noted(b)));if(l?.addEventListener("abort",d,{once:!0}),l?.aborted)return s(r.aborted());o.onerror=b=>s(new i("backend",`the engine's worker from ${a.href} failed: ${b.message||"it did not start"}`)),o.onmessage=b=>{let f=b.data;if(!L(f)||f.id!==m.id)return s(w(f));switch(f.type){case"host":return r.host(f.hostWasm)?void 0:s(w(f));case"progress":return;case"checked":return r.wasm===null?s(w(f)):c({ok:!0,backend:f.backend});case"error":return s(r.workerError(f));default:return s(w(f))}};try{o.postMessage(m)}catch(b){c(B(b))}})}},T=class{#r;#n;#l=2;#t=!1;#e=null;#i=!1;#o=null;constructor(t,n){this.#r=t,this.#n=n,t.onmessage=r=>this.#d(r.data),t.onerror=r=>this.#a(new i("backend",`the engine's worker failed: ${r.message||"it stopped"}`))}chat(t,n={}){return this.#s(),this.#u({messages:t},n)}complete(t,n={}){this.#s();let r;if(typeof t=="string")r={text:t};else if(typeof t=="object"&&t!==null){let o=t;if(o.text!==void 0&&o.ids!==void 0)throw new i("request","complete takes exactly one of text and ids, not both");if(!Array.isArray(o.ids))throw new i("request","complete takes exactly one of text and ids");r={ids:o.ids}}else throw new i("request","complete takes exactly one of text and ids");return this.#u(r,n)}doctor(){this.#s();let t=Object.fromEntries(Object.entries(this.#n.source).map(([a,l])=>[a,{...l}])),{worker:n,hostWasm:r}=this.#n.assets,o=this.#n.aliases.map(a=>({...a}));return{...this.#n,source:t,aliases:o,assets:{worker:{...n},hostWasm:{...r}}}}dispose(){if(!this.#t){this.#t=!0;try{this.#r.postMessage({id:this.#l++,type:"dispose"})}catch{}this.#r.terminate(),this.#o?.sink(new i("request","the engine was disposed"))}}#s(){if(this.#t)throw new i("request","the engine was disposed; load a new one");if(this.#e)throw this.#e}#a(t){this.#e||this.#t||(this.#e=t,this.#r.terminate(),this.#o?.sink(t))}#d(t){if(this.#t||this.#e)return;if(!L(t))return this.#a(w(t));let n=this.#o;if(n===null||t.id!==n.id)return this.#a(w(t));switch(t.type){case"delta":return n.sink(me(t.delta));case"error":return t.fatal!==void 0&&(this.#e=_(t.fatal)),n.sink(new i(t.kind,t.message));default:return this.#a(w(t))}}async*#u(t,n){if(this.#s(),this.#i)throw new i("request","a generation is already running on this engine");let{signal:r,...o}=n;if(r?.aborted){yield{text:"",done:!0,finishReason:"abort",usage:{promptTokens:0,completionTokens:0,cachedTokens:0}};return}this.#i=!0;let a=this.#l++,l=[],m=null;this.#o={id:a,sink:s=>{l.push(s),m?.()}};let u=()=>{!this.#t&&!this.#e&&this.#r.postMessage({id:a,type:"abort"})},d=!1,c=async()=>{for(;l.length===0;)await new Promise(s=>m=s);return m=null,l.shift()};try{for(this.#r.postMessage({id:a,type:"generate",prompt:t,options:o}),r?.addEventListener("abort",u,{once:!0});;){let s=await c();if(s instanceof i)throw d=!0,s;if(s.done&&(d=!0),yield s,s.done)return}}finally{if(r?.removeEventListener("abort",u),!d)try{for(u();!(this.#t||this.#e);){let s=await c();if(s instanceof i||s.done)break}}catch{}this.#o=null,this.#i=!1}}};export{q as Caldrix,i as CaldrixError,T as Engine,O as probe};
|
|
1
|
+
import{a as N,b as i,d as J}from"./chunk-PZGTLL5H.js";function v(e){return typeof e=="object"&&e!==null}function te(e){return v(e)&&typeof e.token=="number"&&typeof e.text=="string"&&typeof e.done=="boolean"&&(e.finishReason===null||e.finishReason==="stop"||e.finishReason==="length"||e.finishReason==="abort")&&typeof e.promptTokens=="number"&&typeof e.completionTokens=="number"&&typeof e.cachedTokens=="number"&&(e.logprobs===void 0||Array.isArray(e.logprobs)&&e.logprobs.every(t=>v(t)&&typeof t.token=="number"&&typeof t.logprob=="number"))}function re(e){return!v(e)||typeof e.url!="string"?!1:e.failed===void 0||v(e.failed)&&typeof e.failed.url=="string"&&typeof e.failed.reason=="string"}function T(e){if(!v(e)||typeof e.id!="number")return!1;switch(e.type){case"ready":return e.id===0&&typeof e.url=="string";case"host":return re(e.hostWasm);case"progress":return typeof e.file=="string"&&typeof e.loaded=="number"&&(e.total===null||typeof e.total=="number")&&typeof e.repo=="string"&&typeof e.revision=="string"&&(e.provenance===void 0||typeof e.provenance=="string");case"loaded":return v(e.doctor)&&v(e.sources)&&(e.fallback===void 0||typeof e.fallback=="string")&&Object.values(e.sources).every(t=>v(t)&&(t.source==="cache"||t.source==="network")&&typeof t.verified=="boolean");case"checked":return e.backend==="webgpu"||e.backend==="wasm";case"fitted":return(e.backend==="webgpu"||e.backend==="wasm")&&(e.maxContext===null||typeof e.maxContext=="number")&&(e.contextClamp===null||typeof e.contextClamp=="string");case"delta":return te(e.delta);case"result":return"value"in e;case"error":return N(e.kind)&&typeof e.message=="string"&&(e.fatal===void 0||typeof e.fatal=="string");default:return!1}}function w(e){let t;try{t=JSON.stringify(e)??String(e)}catch{t=String(e)}return t.length>200&&(t=`${t.slice(0,200)}...`),new i("backend",`the worker sent a malformed message: ${t}`)}var C=(...e)=>new Uint8Array(e),ne={simd:C(0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11),relaxedSimd:C(0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,15,1,13,0,65,1,253,15,65,2,253,15,253,128,2,11),bulkMemory:C(0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,3,1,0,1,10,14,1,12,0,65,0,65,0,65,0,252,10,0,0,11),threads:C(0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11),memory64:C(0,97,115,109,1,0,0,0,5,3,1,4,1),tailCall:C(0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,6,1,4,0,18,0,11),exceptions:C(0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,16,1,14,0,2,105,31,64,1,3,0,0,11,0,11,26,11)};function H(){let e={};for(let[t,o]of Object.entries(ne))e[t]=WebAssembly.validate(o);return e}var oe=1e3,D=Symbol("timed out");async function K(e){let t,o=new Promise(n=>{t=setTimeout(()=>n(D),oe)});try{return await Promise.race([e,o])}finally{clearTimeout(t)}}var X=e=>e instanceof Error?e.message:String(e);function Q(){let e=globalThis.navigator;return typeof e=="object"&&e!==null?e:{}}function P(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function se(){let e={available:!1,maxTextureSize:null,floatColorBuffer:null};try{let t=null;if(typeof OffscreenCanvas<"u"?t=new OffscreenCanvas(1,1):typeof document<"u"&&(t=document.createElement("canvas")),t===null)return e;let o=t,n=o.getContext("webgl2"),r=n??o.getContext("webgl");if(!r)return e;let s=P(r.getParameter(r.MAX_TEXTURE_SIZE)),l=r.getExtension(n?"EXT_color_buffer_float":"WEBGL_color_buffer_float")!==null;return r.getExtension("WEBGL_lose_context")?.loseContext(),{available:!0,maxTextureSize:s,floatColorBuffer:l}}catch{return e}}async function ae(e){let t=e.info??{};if(!e.info&&typeof e.requestAdapterInfo=="function")try{t=await e.requestAdapterInfo()}catch{t={}}let o={},n=[];if(e.limits)for(let r in e.limits){let s=e.limits[r];typeof s=="number"?(o[r]=s,Number.isSafeInteger(s)||n.push(`${r} = ${s} (not a safe integer)`)):typeof s!="function"&&n.push(`${r} = ${JSON.stringify(s)??String(s)} (not a number)`)}return{vendor:t.vendor??"",architecture:t.architecture??"",device:t.device??"",description:t.description??"",features:e.features?[...e.features]:[],limits:o,unrepresentable:n}}async function ie(){let e=Q().gpu;if(!e||typeof e.requestAdapter!="function")return{webgpu:null,available:!1,reason:"no navigator.gpu"};let t;try{let n=await K(e.requestAdapter());if(n===D)return{webgpu:null,available:!1,reason:"requestAdapter timed out"};t=n}catch(n){return{webgpu:null,available:!1,reason:`requestAdapter failed: ${X(n)}`}}if(!t)return{webgpu:null,available:!1,reason:"requestAdapter returned null"};let o=await ae(t);try{let n=await K(t.requestDevice());if(n===D)return{webgpu:o,available:!1,reason:"requestDevice timed out"};n.destroy?.()}catch(n){return{webgpu:o,available:!1,reason:`requestDevice refused: ${X(n)}`}}return{webgpu:o,available:!0}}function le(e){return e.webgpu.available&&e.webgpu.built?"webgpu":"wasm"}function ue(e,t,o){let n=e.webgpu?.unrepresentable??[],r=n.length>0?`; adapter limits ${n.join(", ")}: the host reads them as missing`:"";return de(e,t,o)+r}function de(e,t,o){if(o==="webgpu"){let r=e.webgpu,s=r.features.includes("shader-f16")?" with shader-f16":"";return`WebGPU adapter present (${r.vendor} ${r.architecture})${s}: webgpu`}let n=e.wasm.simd?"with simd128":"without simd128";return e.webgpu===null?`no WebGPU adapter (${t.reason??"unavailable"}): wasm ${n}`:`WebGPU adapter present but unusable (${t.reason}): wasm ${n}`}async function G(){let e=Q(),t=await ie(),o={wasm:H(),threads:{sharedArrayBuffer:typeof SharedArrayBuffer<"u",crossOriginIsolated:globalThis.crossOriginIsolated===!0,hardwareConcurrency:P(e.hardwareConcurrency)},webgl:se(),webgpu:t.webgpu,memory:{deviceMemoryGiB:P(e.deviceMemory)},tiers:{webgpu:t.available?{available:!0,built:!0}:{available:!1,built:!0,reason:t.reason},webgl:{available:!1,built:!1,reason:"not built"},wasm:{available:!0,built:!0}}};o.tiers.webgl.available=o.webgl.available;let n=le(o.tiers);return{...o,chosen:n,why:ue(o,t,n)}}function z(e){let t=e.webgpu===null?null:{vendor:e.webgpu.vendor,architecture:e.webgpu.architecture,device:e.webgpu.device,description:e.webgpu.description,features:e.webgpu.features,limits:Object.fromEntries(Object.entries(e.webgpu.limits).filter(([,o])=>Number.isSafeInteger(o)))};return JSON.stringify({wasm:{simd:e.wasm.simd,relaxedSimd:e.wasm.relaxedSimd,bulkMemory:e.wasm.bulkMemory,threads:e.wasm.threads,memory64:e.wasm.memory64,tailCall:e.wasm.tailCall,exceptions:e.wasm.exceptions},threads:{sharedArrayBuffer:e.threads.sharedArrayBuffer,crossOriginIsolated:e.threads.crossOriginIsolated,hardwareConcurrency:e.threads.hardwareConcurrency},webgpu:t,memory:{deviceMemoryGiB:e.memory.deviceMemoryGiB}})}var ce="https://huggingface.co";function fe(e){return typeof location<"u"?new URL(String(e),location.href):new URL(String(e))}var pe="https://cdn.jsdelivr.net/npm/@caldrix-ai/caldrix@0.7.0/";function S(e){return e instanceof Error?e.message:String(e)}function F(e,t){if(t!==void 0){if(typeof t!="string"&&!(t instanceof URL))throw new i("request",`assets.${e} is a string or a URL, not ${typeof t}`);try{return typeof location<"u"?new URL(t,location.href):new URL(t)}catch{throw new i("request",`assets.${e} ${JSON.stringify(String(t))} is not a URL`)}}}function be(e,t){let o=_(e,t),n=null,r=()=>{n!==null&&URL.revokeObjectURL(n),n=null};try{return!o&&!t?{worker:new Worker(new URL("./worker.js",import.meta.url),{type:"module"}),revoke:r,literal:!0}:o?(n=URL.createObjectURL(new Blob([`import ${JSON.stringify(e.href)};`],{type:"text/javascript"})),{worker:new Worker(n,{type:"module"}),revoke:r}):{worker:new Worker(e,{type:"module"}),revoke:r}}catch(s){throw r(),s}}function me(e){return typeof location<"u"&&e.origin!==location.origin}function _(e,t){return me(e)&&(t||e.protocol==="http:"||e.protocol==="https:")}function q(e){return!e.chosen&&!_(e.url,!1)?`the package's worker (dist/worker.js as the page's bundler emitted it, or ${e.url.href} unbundled)`:`the engine's worker from ${e.url.href}${_(e.url,e.chosen)?" (through a same-origin shim)":""}`}var R=class{constructor(t){this.reason=t}reason};function ge(e,t,o){return new Promise((n,r)=>{let s;try{s=be(e.url,e.chosen)}catch(u){r(new R(`the page could not construct it: ${S(u)}`));return}let{worker:l,revoke:c}=s,b=()=>d(o()),d=(u,a=e.url)=>{if(c(),l.onmessage=null,l.onerror=null,t?.removeEventListener("abort",b),u===null)return n({worker:l,url:a});l.terminate(),r(u)};t?.addEventListener("abort",b,{once:!0}),l.onerror=u=>d(new R(u.message||"it did not load")),l.onmessage=u=>{let a=u.data;if(!T(a)||a.id!==0)return d(w(a));if(a.type==="ready")return s.literal?URL.canParse(a.url)?d(null,new URL(a.url)):d(w(a)):d(null);if(a.type==="error")return d(new R(a.message));d(w(a))}})}async function he(e,t,o,n){let r=[];for(let d of e)try{let{worker:u,url:a}=await ge(d,o,n),f=r[0];return{worker:u,used:d,url:a,...f!==void 0?{failed:{what:q(f.t),reason:f.reason}}:{}}}catch(u){if(!(u instanceof R))throw u;r.push({t:d,reason:u.reason})}let[s,l]=r;if(s!==void 0&&l!==void 0){let d=l.t.url.origin;throw new i("backend",`${q(s.t)} did not start (${s.reason}), nor from the CDN fallback ${l.t.url.href} (${l.reason}); serve dist/ and host/ beside the bundle, set assets.worker to where the page serves them, or allow ${d} in the page's Content-Security-Policy (worker-src blob: for the same-origin shim that starts it, script-src ${d} for the modules it imports, connect-src ${d} for the .wasm)`)}let c=s,b=t&&c.t.source==="bundle"?"; the CDN fallback is off (assets.fallback is false)":"";throw new i("backend",`${q(c.t)} did not start: ${c.reason}${b}; caldrix.js runs inference in a Web Worker and has no main-thread mode`)}function we(e,t,o){let n=o!==void 0?`, and with it the host .wasm from ${o}`:"";return`${e.what} did not start (${e.reason}); it was loaded from the CDN fallback ${t}${n}`}function ke(e){return`the host .wasm could not be fetched from ${e.failed.url} (${e.failed.reason}); it was fetched from the CDN fallback ${e.url}`}function V(e){console.warn(`caldrix.js: ${e}. Serve dist/ and host/ beside the bundle or set assets.worker/assets.hostWasm; assets.fallback: false turns the fallback off.`)}function ye(e){let t={text:e.text,token:e.token,done:e.done};return e.logprobs!==void 0&&(t.logprobs=e.logprobs),e.done&&(e.finishReason!==null&&(t.finishReason=e.finishReason),t.usage={promptTokens:e.promptTokens,completionTokens:e.completionTokens,cachedTokens:e.cachedTokens}),t}var Y=4<<20;async function B(e,t){let o=t.backend??"auto";if(o==="webgl")throw new i("backend","the webgl backend is not built");if(o!=="auto"&&o!=="webgpu"&&o!=="wasm")throw new i("request",`backend ${JSON.stringify(o)} is not auto, webgpu, wasm or webgl`);let n=e.kind==="fit"?"":e.model;if(e.kind!=="fit"&&(typeof n!="string"||n===""))throw new i("request","load takes a model alias or a Hub repo id (owner/name[@revision]), a non-empty string");if(t.file!==void 0&&(typeof t.file!="string"||t.file===""))throw new i("request",`file is the name of a GGUF file in the repo, a non-empty string, not ${JSON.stringify(t.file)?.slice(0,80)}`);let r=F("worker",t.assets?.worker),s=F("hostWasm",t.assets?.hostWasm),l=t.assets?.fallback??!0;if(typeof l!="boolean")throw new i("request",`assets.fallback is true or false, not ${JSON.stringify(l)}`);let c=F("cdn",t.assets?.cdn)??new URL(pe);c.pathname.endsWith("/")||(c.pathname+="/");let b=[r!==void 0?{url:r,chosen:!0,source:"page"}:{url:fe(new URL("./worker.js",import.meta.url)),chosen:!1,source:"bundle"}];l&&r===void 0&&b.push({url:new URL("dist/worker.js",c),chosen:!0,source:"cdn"});let d=l&&s===void 0?new URL("host/caldrix_web_bg.wasm",c).href:void 0,u=t.storage??"auto";if(u!=="auto"&&u!=="f32")throw new i("request",`storage ${JSON.stringify(u)} is not auto or f32`);if(o==="wasm"&&u==="f32")throw new i("request",`storage "f32" is the WebGPU tier's weight storage; backend "wasm" takes none`);if(t.hubBaseUrl!==void 0){let g=t.hubBaseUrl,U=!1;if(typeof g=="string")try{let j=new URL(g);U=j.protocol==="http:"||j.protocol==="https:"}catch{U=!1}if(!U)throw new i("request",`hubBaseUrl must be an absolute http(s) URL, not ${JSON.stringify(g).slice(0,80)}`)}let a=()=>new i("fetch",e.kind==="fit"?"the fit was aborted":`${e.kind==="check"?"checking":"loading"} ${n} was aborted`),f=t.signal;if(f?.aborted)throw a();let h=await G(),m,y;if(o==="auto"&&t.dtype==="bf16"&&h.chosen==="webgpu")m="wasm",y=`bf16 requested: wasm (the WebGPU tier runs the f32 plan only); ${h.why}`;else if(o==="auto")m=h.chosen,y=h.why;else if(o==="webgpu"){if(!h.tiers.webgpu.available)throw new i("backend",`backend "webgpu" was asked for, but the probe found no usable WebGPU adapter: ${h.tiers.webgpu.reason??h.why}`);m="webgpu",y=`backend "webgpu" asked for; ${h.why}`}else m="wasm",y=`backend "wasm" asked for; ${h.why}`;let p=h.webgpu?.unrepresentable??[];if(f?.aborted)throw a();let k=await he(b,!l,f,a),{worker:W}=k,$=k.url,L=o==="auto"&&m==="webgpu"?{auto:!0}:{},O={...s!==void 0?{hostWasm:s.href}:{},...d!==void 0?{cdnWasm:d}:{}},I=z(h),ee=e.kind==="fit"?{id:1,type:"fit",facts:e.facts,backend:m,...L,...t.maxContext!==void 0?{maxContext:t.maxContext}:{},probeJson:I,...O}:{id:1,type:"load",model:e.model,...t.file!==void 0?{file:t.file}:{},probeJson:I,request:{backend:m,...t.dtype!==void 0?{dtype:t.dtype}:{},...t.maxContext!==void 0?{maxContext:t.maxContext}:{},...m==="webgpu"&&u==="f32"?{f16:!1}:{}},...L,...e.kind==="check"?{check:!0}:{},offline:t.offline??!1,hubBaseUrl:t.hubBaseUrl??ce,...O},x={worker:W,used:k.used,workerUrl:$,caps:h,why:y,hostWasm:s,request:ee,signal:f,aborted:a,fellBack:null,wasm:null,noted:g=>x.fellBack===null?g:new i(g.kind,`${g.message} (after a CDN fallback: ${x.fellBack})`,g.missing),host:g=>x.wasm!==null?!1:(x.wasm=g,g.failed!==void 0&&(x.fellBack=ke({...g,failed:g.failed}),V(x.fellBack)),!0),workerError:g=>{let U=g.kind==="probe"&&p.length>0?`; the browser gave ${p.join(", ")}, which the host reads as missing`:"";return new i(g.kind,g.message+U)}};if(k.failed!==void 0&&(x.fellBack=we(k.failed,$.href,s===void 0?d:void 0),V(x.fellBack)),f?.aborted)throw W.terminate(),x.noted(a());return x}function A(e){return e instanceof i?{ok:!1,kind:e.kind,message:e.message}:{ok:!1,kind:"backend",message:S(e)}}function Z(e,t,o){let{worker:n,workerUrl:r,signal:s,request:l}=e;return new Promise(c=>{let b=()=>u(e.aborted()),d=a=>{n.onmessage=null,n.onerror=null,s?.removeEventListener("abort",b),n.terminate(),c(a)},u=a=>d(A(e.noted(a)));if(s?.addEventListener("abort",b,{once:!0}),s?.aborted)return u(e.aborted());n.onerror=a=>u(new i("backend",`the engine's worker from ${r.href} failed: ${a.message||"it did not start"}`)),n.onmessage=a=>{let f=a.data;if(!T(f)||f.id!==l.id)return u(w(f));if(f.type==="host")return e.host(f.hostWasm)?void 0:u(w(f));if(f.type!=="progress")return f.type==="error"?u(e.workerError(f)):f.type!==t?u(w(f)):e.wasm===null?u(w(f)):d(o(f))};try{n.postMessage(l)}catch(a){d(A(a))}})}var M=class{static async load(t,o={}){let n=await B({kind:"load",model:t},o),{worker:r,workerUrl:s,signal:l,request:c,hostWasm:b,caps:d}=n;return new Promise((u,a)=>{let f=()=>m(n.aborted()),h=()=>{r.onmessage=null,r.onerror=null,l?.removeEventListener("abort",f)},m=y=>{h(),r.terminate(),a(n.noted(y))};if(l?.addEventListener("abort",f,{once:!0}),l?.aborted)return m(n.aborted());r.onerror=y=>m(new i("backend",`the engine's worker from ${s.href} failed: ${y.message||"it did not start"}`)),r.onmessage=y=>{let p=y.data;if(!T(p)||p.id!==c.id)return m(w(p));switch(p.type){case"host":return n.host(p.hostWasm)?void 0:m(w(p));case"progress":try{o.onProgress?.({file:p.file,loaded:p.loaded,total:p.total,repo:p.repo,revision:p.revision,...p.provenance!==void 0?{provenance:p.provenance}:{}})}catch(k){m(k instanceof i?k:new i("request",`onProgress threw: ${S(k)}`))}return;case"loaded":{let k=n.wasm;if(k===null)return m(w(p));h();let W=n.used.source,$=b!==void 0||W==="page"&&k.failed===void 0?"page":k.failed!==void 0||W==="cdn"?"cdn":"bundle",L={worker:{source:W,url:s.href},hostWasm:{source:$,url:k.url}},O={...p.doctor,source:p.sources,why:p.fallback!==void 0?`${p.fallback}; ${d.why}`:n.why,assets:L};u(new E(r,O));return}case"error":return m(n.workerError(p));default:return m(w(p))}},r.postMessage(c)})}static async check(t,o={}){let n;try{let r=o??{};n=await B({kind:"check",model:t},{...r.backend!==void 0?{backend:r.backend}:{},...r.dtype!==void 0?{dtype:r.dtype}:{},...r.maxContext!==void 0?{maxContext:r.maxContext}:{},...r.storage!==void 0?{storage:r.storage}:{},...r.hubBaseUrl!==void 0?{hubBaseUrl:r.hubBaseUrl}:{},...r.file!==void 0?{file:r.file}:{},...r.signal!==void 0?{signal:r.signal}:{},...r.assets!==void 0?{assets:r.assets}:{}})}catch(r){return A(r)}return Z(n,"checked",r=>({ok:!0,backend:r.backend}))}static async fit(t,o={}){let n;try{let r=typeof t=="object"&&t!==null?Object.getPrototypeOf(t):void 0;if(r!==Object.prototype&&r!==null)throw new i("request","fit takes a GGUF file's recorded facts, a plain object");let s;try{s=JSON.stringify(t)}catch(b){throw new i("request",`the facts do not serialise: ${S(b)}`)}if(typeof s!="string")throw new i("request","the facts do not serialise to a JSON string");let l=new TextEncoder().encode(s).byteLength;if(l>Y)throw new i("request",`the facts are ${l} bytes once serialised, past the ${Y} a fit takes`);let c=o??{};n=await B({kind:"fit",facts:s},{...c.backend!==void 0?{backend:c.backend}:{},...c.maxContext!==void 0?{maxContext:c.maxContext}:{},...c.signal!==void 0?{signal:c.signal}:{},...c.assets!==void 0?{assets:c.assets}:{}})}catch(r){return A(r)}return Z(n,"fitted",r=>({ok:!0,backend:r.backend,maxContext:r.maxContext,contextClamp:r.contextClamp}))}},E=class{#r;#n;#l=2;#t=!1;#e=null;#i=!1;#o=null;constructor(t,o){this.#r=t,this.#n=o,t.onmessage=n=>this.#d(n.data),t.onerror=n=>this.#a(new i("backend",`the engine's worker failed: ${n.message||"it stopped"}`))}chat(t,o={}){return this.#s(),this.#u({messages:t},o)}complete(t,o={}){this.#s();let n;if(typeof t=="string")n={text:t};else if(typeof t=="object"&&t!==null){let r=t;if(r.text!==void 0&&r.ids!==void 0)throw new i("request","complete takes exactly one of text and ids, not both");if(!Array.isArray(r.ids))throw new i("request","complete takes exactly one of text and ids");n={ids:r.ids}}else throw new i("request","complete takes exactly one of text and ids");return this.#u(n,o)}doctor(){this.#s();let t=Object.fromEntries(Object.entries(this.#n.source).map(([s,l])=>[s,{...l}])),{worker:o,hostWasm:n}=this.#n.assets,r=this.#n.aliases.map(s=>({...s}));return{...this.#n,source:t,aliases:r,assets:{worker:{...o},hostWasm:{...n}}}}dispose(){if(!this.#t){this.#t=!0;try{this.#r.postMessage({id:this.#l++,type:"dispose"})}catch{}this.#r.terminate(),this.#o?.sink(new i("request","the engine was disposed"))}}#s(){if(this.#t)throw new i("request","the engine was disposed; load a new one");if(this.#e)throw this.#e}#a(t){this.#e||this.#t||(this.#e=t,this.#r.terminate(),this.#o?.sink(t))}#d(t){if(this.#t||this.#e)return;if(!T(t))return this.#a(w(t));let o=this.#o;if(o===null||t.id!==o.id)return this.#a(w(t));switch(t.type){case"delta":return o.sink(ye(t.delta));case"error":return t.fatal!==void 0&&(this.#e=J(t.fatal)),o.sink(new i(t.kind,t.message));default:return this.#a(w(t))}}async*#u(t,o){if(this.#s(),this.#i)throw new i("request","a generation is already running on this engine");let{signal:n,...r}=o;if(n?.aborted){yield{text:"",done:!0,finishReason:"abort",usage:{promptTokens:0,completionTokens:0,cachedTokens:0}};return}this.#i=!0;let s=this.#l++,l=[],c=null;this.#o={id:s,sink:a=>{l.push(a),c?.()}};let b=()=>{!this.#t&&!this.#e&&this.#r.postMessage({id:s,type:"abort"})},d=!1,u=async()=>{for(;l.length===0;)await new Promise(a=>c=a);return c=null,l.shift()};try{for(this.#r.postMessage({id:s,type:"generate",prompt:t,options:r}),n?.addEventListener("abort",b,{once:!0});;){let a=await u();if(a instanceof i)throw d=!0,a;if(a.done&&(d=!0),yield a,a.done)return}}finally{if(n?.removeEventListener("abort",b),!d)try{for(b();!(this.#t||this.#e);){let a=await u();if(a instanceof i||a.done)break}}catch{}this.#o=null,this.#i=!1}}};export{M as Caldrix,i as CaldrixError,E as Engine,G as probe};
|
package/dist/worker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as l,c as O,d as te}from"./chunk-PZGTLL5H.js";var Qe="caldrix.js",Se="x-caldrix-verified",he="x-caldrix-absent";function et(t){return[...new Uint8Array(t)].map(r=>r.toString(16).padStart(2,"0")).join("")}function tt(t){return t.trim().replace(/^W\//,"").replace(/^"|"$/g,"").toLowerCase()}function D(t){return t instanceof Error?t.message:String(t)}function Y(t,r){if(r===""||r==="."||r===".."||/[/\\?#]/.test(r)||/%[0-9a-fA-F]{2}/.test(r)||/[\u0000-\u001f\u007f]/.test(r))throw new l("validate",`${t} ${JSON.stringify(r)} is not a single safe path segment`);return encodeURIComponent(r)}function Le(t){return new l("backend",`${t} is not available; caldrix.js needs a secure context`)}function Ue(t,r,s,e){let n=t.split("/").map(c=>Y("repo",c)).join("/");return`${e.endsWith("/")?e.slice(0,-1):e}/${n}/resolve/${Y("revision",r)}/${Y("file",s)}`}function rt(t,r,s){let e=t.split("/").map(c=>Y("repo",c)).join("/"),n=s.endsWith("/")?s.slice(0,-1):s,u=r===null?"":`/revision/${r.split("/").map(c=>Y("revision",c)).join("%2F")}`;return`${n}/api/models/${e}${u}?blobs=true`}async function pe(t){if(typeof caches>"u")throw Le("caches");try{return await caches.open(Qe)}catch(r){throw new l("backend",`opening the cache for ${t} failed: ${D(r)}`)}}async function de(t){if(typeof crypto>"u"||!crypto.subtle)throw Le("crypto.subtle");return et(await crypto.subtle.digest("SHA-256",t))}function Ce(t){return new l("fetch",`${t} is not in the cache and offline is set`,"offline-uncached")}async function Be(t,r,s,e){let n=Ue(t,r,s,e.hubBaseUrl),u=await pe(s),c;try{c=await u.match(n)}catch(x){throw new l("backend",`reading ${s} from the cache failed: ${D(x)}`)}let i=x=>new l("fetch",`fetching ${s} failed: HTTP 404${x}`,"not-found");if(c&&c.headers.get(he)==="1"){if(e.rememberAbsent)throw i(" (remembered from an earlier load)");c=void 0}let d=!1;if(c){let x=new Uint8Array(await c.arrayBuffer());if(e.sha256===void 0)return{bytes:x,source:"cache",verified:c.headers.get(Se)==="1",cached:!0};if(await de(x)===e.sha256)return{bytes:x,source:"cache",verified:!0,cached:!0};d=!0;try{await u.delete(n)}catch{}}if(e.offline&&d)throw new l("fetch",`${s}: the cached copy fails the alias's sha256 pin and offline is set`,"offline-uncached");if(e.offline)throw Ce(s);let p=(x,z)=>new l("fetch",`fetching ${s} ${x}`,z),w=()=>{if(e.signal?.aborted)throw p("was aborted")},y;try{y=await fetch(n,{signal:e.signal})}catch(x){throw p(e.signal?.aborted?"was aborted":`failed: ${D(x)}`)}if(y.status===404&&e.rememberAbsent){try{await u.put(n,new Response(null,{headers:{[he]:"1"}}))}catch{}throw i("")}if(!y.ok||!y.body)throw p(`failed: HTTP ${y.status}`,y.status===404?"not-found":void 0);let W=y.headers.get("x-linked-etag"),b=y.headers.get("content-length"),o=b!==null&&/^\d+$/.test(b.trim())?Number(b):null,a=[],g=0,m=y.body.getReader();try{for(;;){let x;try{x=await m.read()}catch(z){throw p(e.signal?.aborted?"was aborted":`failed: ${D(z)}`)}if(x.done)break;if(a.push(x.value),g+=x.value.byteLength,e.bytes!==void 0&&g>e.bytes)throw new l("fetch",`${s}: the body passed its pinned size, ${e.bytes} bytes`);e.onProgress?.({file:s,loaded:g,total:o})}}finally{m.cancel().catch(()=>{})}if(w(),o!==null&&o!==g&&!y.headers.get("content-encoding"))throw p(`failed: Content-Length is ${o} but ${g} bytes arrived`);let h=new Uint8Array(g),v=0;for(let x of a)h.set(x,v),v+=x.byteLength;e.onProgress?.({file:s,loaded:g,total:o});let E=!1,L=null;if(e.sha256!==void 0){if(L=await de(h),L!==e.sha256)throw new l("digest",`${s}: sha256 is ${L} but the alias pins ${e.sha256}`);E=!0}if(W!==null){let x=tt(W);if(L??=await de(h),x!==L)throw new l("digest",`${s}: sha256 is ${L} but the Hub's X-Linked-Etag is ${x}`);E=!0}w();try{await u.put(n,new Response(h,{headers:{[Se]:E?"1":"0"}}))}catch{return{bytes:h,source:"network",verified:E,cached:!1}}return{bytes:h,source:"network",verified:E,cached:!0}}async function Oe(t,r,s,e,n){if(!Number.isSafeInteger(e)||e<=0)throw new l("request",`a range of ${e} bytes of ${s} is not a positive integer`);let u=Ue(t,r,s,n.hubBaseUrl),c=await pe(s),i;try{i=await c.match(u)}catch(b){throw new l("backend",`reading ${s} from the cache failed: ${D(b)}`)}if(i&&i.headers.get(he)!=="1"){let b=new Uint8Array(await i.arrayBuffer());if(b.byteLength>=e)return b.slice(0,e)}if(n.offline)throw Ce(s);let d=b=>new l("fetch",`fetching the first ${e} bytes of ${s} ${b}`),p;try{p=await fetch(u,{headers:{Range:`bytes=0-${e-1}`},signal:n.signal})}catch(b){throw d(n.signal?.aborted?"was aborted":`failed: ${D(b)}`)}if(p.status!==206&&p.status!==200||!p.body)throw d(`failed: HTTP ${p.status}`);let w=new Uint8Array(e),y=0,W=p.body.getReader();try{for(;;){let b;try{b=await W.read()}catch(a){throw d(n.signal?.aborted?"was aborted":`failed: ${D(a)}`)}if(b.done)break;let o=Math.min(b.value.byteLength,e-y);if(w.set(b.value.subarray(0,o),y),y+=b.value.byteLength,y>e||p.status===200&&y===e)break}}finally{W.cancel().catch(()=>{})}if(n.signal?.aborted)throw d("was aborted");if(y<e)throw d(`failed: the HTTP ${p.status} answer carried ${y} bytes, not the ${e} asked for`);if(p.status===206&&y>e)throw d(`failed: the HTTP 206 answer carried more than the ${e} bytes asked for`);return w}var Ge=262144;async function Te(t,r,s){let e=rt(t,r,s.hubBaseUrl),n=`the Hub listing of ${t}`,u=await pe(n);if(s.offline){let a;try{a=await u.match(e)}catch(g){throw new l("backend",`reading ${n} from the cache failed: ${D(g)}`)}if(!a)throw new l("fetch",`${n} is not in the cache and offline is set`,"offline-uncached");return{bytes:new Uint8Array(await a.arrayBuffer()),source:"cache"}}let c=a=>new l("fetch",`fetching ${n} ${a}`),i;try{i=await fetch(e,{signal:s.signal})}catch(a){throw c(s.signal?.aborted?"was aborted":`failed: ${D(a)}`)}let d=a=>{throw i.body?.cancel().catch(()=>{}),a},p=new URL(s.hubBaseUrl).origin;i.url&&new URL(i.url).origin!==p&&d(new l("fetch",`${n} was redirected off ${p} (to ${i.url})`)),i.status===401&&d(new l("fetch",`${t}: the Hub answered HTTP 401 for its listing: the repo does not exist, or it is private (the browser build sends no token; the caldrix CLI reads HF_TOKEN)`,"not-found")),i.status===404&&d(new l("fetch",`${t}${r?"@"+r:""}: no such repo or revision on the Hub (HTTP 404)`,"not-found")),(!i.ok||!i.body)&&d(c(`failed: HTTP ${i.status}`));let w=[],y=0,W=i.body.getReader();try{for(;;){let a;try{a=await W.read()}catch(g){throw c(s.signal?.aborted?"was aborted":`failed: ${D(g)}`)}if(a.done)break;if(y+=a.value.byteLength,y>Ge)throw new l("validate",`${n} passed the 256 KiB (${Ge}-byte) cap`);w.push(a.value)}}finally{W.cancel().catch(()=>{})}if(s.signal?.aborted)throw c("was aborted");let b=new Uint8Array(y),o=0;for(let a of w)b.set(a,o),o+=a.byteLength;try{await u.put(e,new Response(b))}catch{}return{bytes:b,source:"network"}}var ge=null,V=null;function be(t){return t instanceof Error?t.message:String(t)}async function me(){return await import("../host/caldrix_web.js")}function nt(t){let r=globalThis.location?.href;return(r!==void 0?new URL(String(t),r):new URL(String(t))).href}async function De(t){let r;try{r=await fetch(t)}catch(s){throw new Error(be(s))}if(!r.ok)throw new Error(`${r.status} ${r.statusText}`.trim());return r}async function we(t,r){if(ge===null){let s=await me(),e=t??nt(new URL("../host/caldrix_web_bg.wasm",import.meta.url)),n,u;try{n=await De(e),u={url:e}}catch(c){let i=be(c);if(r===void 0||r===e)throw new l("backend",`the browser host's .wasm could not be fetched from ${e} (${i}); serve host/ beside dist/ or set assets.hostWasm to where the page serves it`);try{n=await De(r)}catch(d){let p=new URL(r).origin;throw new l("backend",`the browser host's .wasm could not be fetched from ${e} (${i}) nor from the CDN fallback ${r} (${be(d)}); serve host/ beside dist/, set assets.hostWasm to where the page serves it, or allow ${p} in the page's Content-Security-Policy (connect-src ${p}, the .wasm is fetched)`)}u={url:r,failed:{url:e,reason:i}}}await s.default({module_or_path:n}),ge=s,V=u}return ge}async function Fe(t,r,s){let e=await we(r,s);return new e.CaldrixWeb(t)}function He(){if(V===null)throw new l("backend","the browser host is not open");return{...V,...V.failed!==void 0?{failed:{...V.failed}}:{}}}async function _e(){return(await we()).CaldrixWeb}async function Ne(t,r){let s=await we(),e;try{let{instance:c}=await WebAssembly.instantiate(r,{env:{memory:s.CaldrixWeb.memory()}});e=c.exports}catch(c){throw new l("backend",`instantiating the emitted module failed: ${c instanceof Error?c.message:String(c)}`)}let{step:n,prefill:u}=e;if(typeof n!="function"||typeof u!="function")throw new l("backend","the emitted module does not export step and prefill");if(t.attach(n,u),t.argsPtr()===0)throw new l("backend","the host reports no model loaded after load")}var M={MAP_READ:1,COPY_SRC:4,COPY_DST:8,UNIFORM:64,STORAGE:128},st=1,ot=["maxStorageBufferBindingSize","maxBufferSize","maxComputeWorkgroupsPerDimension","maxStorageBuffersPerShaderStage"],qe=(t,r)=>Number.isSafeInteger(t)&&t>=0&&t<r,ze=t=>Number.isSafeInteger(t)&&t>=0;function it(t,r){let s=n=>new l("backend",`the host's WebGPU program is malformed: ${n}`),e;try{e=JSON.parse(t)}catch(n){throw s(n instanceof Error?n.message:String(n))}if(typeof e!="object"||e===null||!Array.isArray(e.kernels)||!Array.isArray(e.buffers))throw s("no kernels or buffers");if(e.kernels.forEach((n,u)=>{if(!(typeof n?.symbol=="string"&&typeof n.entry=="string"&&Array.isArray(n.buffers)&&n.buffers.every(i=>i==="f32"||i==="f16"||i==="u32")&&ze(n.scalars)))throw s(`kernel ${u}`)}),e.buffers.forEach((n,u)=>{if(!(typeof n?.word=="string"&&ze(n.bytes)&&(n.storage==="f32"||n.storage==="f16"||n.storage==="blocks")&&typeof n.placed=="boolean"))throw s(`buffer ${u}`)}),!qe(e.act,e.buffers.length))throw s("act is no buffer");if(!qe(e.logits,e.buffers.length))throw s("logits is no buffer");if(!Array.isArray(r)||r.length!==e.kernels.length||!r.every(n=>typeof n=="string"))throw s(`${e.kernels.length} kernels but ${Array.isArray(r)?r.length:"no"} WGSL sources`);return e}function at(t,r){let s=[],e=c=>new l("backend",`the host's launch words are malformed: ${c}`),n=0,u=(c,i)=>{if(n+c>t.length)throw e(`launch ${s.length} ends inside its ${i}`);let d=t.subarray(n,n+c);return n+=c,d};for(;n<t.length;){let c=u(1,"kernel")[0],i=r.kernels[c];if(i===void 0)throw e(`launch ${s.length} names kernel ${c}; the program has ${r.kernels.length}`);let d=Array.from(u(u(1,"buffer count")[0],"buffers"));if(d.length!==i.buffers.length)throw e(`a launch of ${i.symbol} binds ${d.length} buffers; the kernel declares ${i.buffers.length}`);let p=d.find(b=>b>=r.buffers.length);if(p!==void 0)throw e(`a launch of ${i.symbol} binds buffer ${p}; the program has ${r.buffers.length}`);let[w,y]=u(2,"grid"),W=u(u(1,"uniform count")[0],"uniform").slice();if(W.length===0!=(i.scalars===0))throw e(`a launch of ${i.symbol} carries ${W.length} uniform words; the kernel declares ${i.scalars} scalars`);s.push({kernel:c,buffers:d,x:w,y,uniform:W})}return s}var J=t=>t instanceof Error?t.message:String(t),ye=class{constructor(r,s,e,n,u,c,i,d){this.adapter=r;this.description=s;this.host=e;this.device=n;this.program=u;this.pipelines=c;this.buffers=i;this.staging=d;n.lost.then(p=>{let w=`the WebGPU device was lost: ${p.message||p.reason||"no message"}`;!this.#e&&this.#t===null&&(this.#t=w),this.#r?.(w)})}adapter;description;host;device;program;pipelines;buffers;staging;#t=null;#e=!1;#r=null;#n=new Set;get failure(){return this.#t}get storage(){let r=s=>this.program.buffers.some(e=>e.storage===s);return r("f16")?"f16":r("blocks")?"blocks":"f32"}async run(r,s){if(this.#e)throw new l("request","the WebGPU runtime was destroyed (the engine was disposed)");if(this.failure!==null)throw this.#o(this.failure),te(this.failure);let e;try{e=at(r,this.program);let d=this.program.buffers[this.program.act];if(s.byteLength>d.bytes)throw new l("backend",`actIn is ${s.byteLength} bytes; the program's ${d.word} is ${d.bytes}`)}catch(d){throw this.#s(J(d),!1)}let n=this.device,u=[],c,i=new Promise((d,p)=>{this.#r=w=>p(new Error(w))});i.catch(()=>null);try{n.pushErrorScope("validation"),n.pushErrorScope("out-of-memory"),n.pushErrorScope("internal");let d=3,p=async()=>{let o=n.popErrorScope(),a=n.popErrorScope(),g=n.popErrorScope();d=0;let[m,h,v]=await Promise.all([o,a,g]);return h?`out of memory: ${h.message}`:v?`validation: ${v.message}`:m?`an internal error: ${m.message}`:null},w,y;try{s.byteLength>0&&n.queue.writeBuffer(this.buffers[this.program.act],0,s);let o=e.map(h=>{let v=h.buffers.map((E,L)=>({binding:L,resource:{buffer:this.buffers[E]}}));if(h.uniform.length>0){let E=n.createBuffer({size:h.uniform.byteLength,usage:M.UNIFORM|M.COPY_DST});u.push(E),this.#n.add(E),n.queue.writeBuffer(E,0,h.uniform),v.push({binding:h.buffers.length,resource:{buffer:E}})}return n.createBindGroup({layout:this.pipelines[h.kernel].getBindGroupLayout(0),entries:v})}),a=n.createCommandEncoder(),g=a.beginComputePass();e.forEach((h,v)=>{g.setPipeline(this.pipelines[h.kernel]),g.setBindGroup(0,o[v]),g.dispatchWorkgroups(h.x,h.y,1)}),g.end();let m=this.buffers[this.program.logits];a.copyBufferToBuffer(m,0,this.staging,0,m.size),n.queue.submit([a.finish()]),w=p(),y=this.staging.mapAsync(st),w.catch(()=>null),y.catch(()=>null)}finally{for(;d-- >0;)n.popErrorScope().catch(()=>null)}if(this.failure!==null)throw new Error(this.failure);let W=await Promise.race([w,i]);if(this.#e)throw new l("request","the engine was disposed during a WebGPU call");if(W!==null)throw new Error(`the device reported ${W}`);try{await Promise.race([y,i])}catch(o){throw this.#e?new l("request","the engine was disposed during a WebGPU call"):new Error(`mapping the logits readback failed: ${J(o)}`)}if(this.#e)throw new l("request","the engine was disposed during a WebGPU call");let b=this.program.buffers[this.program.logits].bytes;c=new Uint8Array(this.staging.getMappedRange(0,this.staging.size).slice(0,b)),this.staging.unmap()}catch(d){throw d instanceof l&&d.kind==="request"?d:this.#s(J(d))}finally{this.#r=null;for(let d of u)this.#n.delete(d),this.#e||d.destroy()}this.host.writeLogits(c)}#s(r,s=!0){return this.#e?new l("request","the engine was disposed during a WebGPU call"):(s&&(this.#t??=r),this.#o(r)??new l("backend",r))}#o(r){try{this.host.failLaunch(r)}catch(s){let e=O(s);if(e.kind==="backend")return e}return null}destroy(){if(!this.#e){this.#e=!0,this.#r?.("the engine was disposed during a WebGPU call");for(let r of[...this.buffers,this.staging,...this.#n])try{r.destroy()}catch{}this.#n.clear();try{this.device.destroy()}catch{}}}};function lt(t,r){let s=t.limits[r];return typeof s=="number"?s:void 0}function ct(){return globalThis.navigator?.gpu}async function Ie(t,r,s=ct()){let e=p=>new l("backend",p);if(!s)throw e("the worker has no navigator.gpu, though the page's probe found a WebGPU adapter");let n;try{n=await s.requestAdapter()}catch(p){throw e(`the worker's requestAdapter failed: ${J(p)}`)}if(!n)throw e("the worker's requestAdapter returned null, though the page's probe found an adapter");if(r&&!n.features.has("shader-f16"))throw e("the host's precheck chose f16 weight storage, but the worker's adapter has no shader-f16");let u={};for(let p of ot){let w=lt(n,p),y=t.webgpu?.limits[p];if(y!==void 0&&(w===void 0||w<y))throw e(`the worker's adapter offers ${p} ${w??"none"}; the host prechecked against the probe's ${y}`);w!==void 0&&(u[p]=w)}let c;try{c=await n.requestDevice({requiredFeatures:r?["shader-f16"]:[],requiredLimits:u})}catch(p){throw e(`requestDevice refused${r?" shader-f16 with":""} the program's limits: ${J(p)}`)}let i=n.info??{};if(!n.info&&typeof n.requestAdapterInfo=="function")try{i=await n.requestAdapterInfo()}catch{i={}}let d=!1;return{device:c,f16:r,adapter:{vendor:i.vendor??"",architecture:i.architecture??""},description:i.description??"",destroy:()=>{if(!d){d=!0;try{c.destroy()}catch{}}}}}async function je(t,r,s){let e=i=>new l("backend",i),n=r.device,u=[],c=()=>{for(let i of u)i.destroy();r.destroy()};try{let i=it(s.program,s.kernels),d=i.buffers.some(W=>W.storage==="f16");if(d!==r.f16)throw e(`the program stores weights ${d?"f16":"f32"}, but the device was opened for ${r.f16?"f16":"f32"} storage`);let p=[];for(let[W,b]of i.kernels.entries()){n.pushErrorScope("validation"),n.pushErrorScope("internal");let o=null,a=null;try{let h=n.createShaderModule({code:s.kernels[W],label:b.symbol});o=n.createComputePipeline({label:b.symbol,layout:"auto",compute:{module:h,entryPoint:b.entry}})}catch(h){a=h}let g=await n.popErrorScope(),m=await n.popErrorScope()??g;if(m)throw e(`kernel ${b.symbol}: creating its pipeline: ${m.message}`);if(o===null)throw e(`kernel ${b.symbol}: creating its pipeline: ${J(a)}`);p.push(o)}for(let[W,b]of i.buffers.entries()){n.pushErrorScope("validation"),n.pushErrorScope("out-of-memory");let o=null;try{let m=n.createBuffer({size:Math.max(4,Math.ceil(b.bytes/4)*4),usage:M.STORAGE|M.COPY_SRC|M.COPY_DST,label:b.word});if(u.push(m),b.placed){let h=t.bufferBytes(W);if(h.byteLength!==b.bytes)throw new l("backend",`buffer ${b.word}: bufferBytes gave ${h.byteLength} bytes; the buffer is ${b.bytes} at ${b.storage} storage`);if(h.byteLength%4!==0)throw new l("backend",`buffer ${b.word}: ${h.byteLength} bytes are not whole 4-byte words`);n.queue.writeBuffer(m,0,h)}}catch(m){o=m}let a=await n.popErrorScope(),g=await n.popErrorScope();if(o!==null)throw o instanceof l?o:O(o);if(a)throw e(`buffer ${b.word} (${b.bytes} bytes): out of memory: ${a.message}`);if(g)throw e(`buffer ${b.word} (${b.bytes} bytes): ${g.message}`)}let w=u[i.logits],y=n.createBuffer({size:w.size,usage:M.MAP_READ|M.COPY_DST,label:"logits readback"});return new ye({...r.adapter},r.description,t,n,i,p,u,y)}catch(i){throw c(),i}}var ut=4194304,$e=["tokenizer.json","tokenizer.model","added_tokens.json","tokenizer_config.json","chat_template.jinja"],[X,ne,xe,Me,Je]=$e;function re(t,r,s){return r!==null&&!(t===ne||t===xe)&&r.siblings.some(n=>n.name===t)?r:s}var ke=(t,r)=>new l("validate",`${t}@${r} has neither tokenizer.json nor tokenizer.model`),ft="the model has no tokenizer.json, and ";function Ke(t,r,s){let e=O(t);return e.kind!=="validate"||!e.message.startsWith(ft)?t:new l("validate",`${r}@${s}: ${e.message}`,e.missing)}var ve="adapter_model.safetensors",dt=["fit","request","probe"];function Ze(){return new Promise(t=>{let r=new MessageChannel;r.port1.onmessage=()=>{r.port1.close(),t()},r.port2.postMessage(0)})}function ht(t,r,s){if(t!=="")return t;let e=[r,s].filter(n=>n!=="");return e.length>0?e.join(" "):"unnamed adapter"}async function Ye(t,r,s){let e,n;try{e=s.kind==="prefill"?t.resolve("prefill",s.n):t.resolve("step",s.pos),n=t.actIn(s.kind==="prefill"?s.n:1)}catch(u){try{t.failLaunch(O(u).message)}catch{}throw u}await r.run(e,n)}async function pt(t,r,s,e){if(await Ye(t,r,s),!!e.launched())for(t.finishStart();;){if(!await e.between())return;let n=t.beginNext();if("delta"in n){e.delta(JSON.parse(n.delta));return}if(await Ye(t,r,n.launch),!e.launched())return;let u=JSON.parse(t.finishNext());if(e.delta(u),u.done)return}}function Ve(t,r){let s=null,e=null,n=!1,u=null,c=!1,i=[],d=o=>{let a={...o.doctor(),aliases:i.map(E=>({...E}))};if(e===null)return{...a,storage:null,adapter:null};let g=e.adapter,m=`webgpu (${ht(e.description,g.vendor,g.architecture)})`,h=`backend webgpu on ${a.device}`,v=a.line.startsWith(h)?`backend webgpu on ${m}${a.line.slice(h.length)}`:a.line;return{...a,device:m,line:v,storage:e.storage,adapter:{...g}}},p=new l("request","the engine was disposed during its load"),w=()=>{if(c)throw p};async function y(o){if(s!==null||n)throw new l("request","this engine already has a model loaded");n=!0;let a=null;try{a=await t.openHost(o.probeJson,o.hostWasm,o.cdnWasm),r({id:o.id,type:"host",hostWasm:t.wasmUsed()}),w();let g=await t.hostClass(),m=g.resolveModel(o.model);i=g.listAliases();let h=m.kind==="alias"?m:null,v=null;if(m.kind==="repo"){let f=await t.fetchListing(m.repo,m.revision,{hubBaseUrl:o.hubBaseUrl,offline:o.offline});w(),v=JSON.parse(g.parseListing(f.bytes))}let E=v!==null?v.id:m.repo,L;if(v!==null)L=v.sha;else if(h!==null)L=h.revision;else throw new l("backend","internal invariant broken: a repo id reached the file fetches without its Hub listing");let x={},z,se={repo:E,revision:L,listing:v},oe=f=>({repo:f.id,revision:f.sha,listing:f}),ie=(f,$)=>{let k=f.siblings.find(P=>P.name===$);if(k===void 0)throw new l("validate",`${f.id}@${f.sha} has no ${$}`);return k.size},_=async(f,$,k,P)=>{let F;if(f.listing!==null){if(k&&!f.listing.siblings.some(R=>R.name===$))return null;F={bytes:ie(f.listing,$)}}try{let R=await t.fetchFile(f.repo,f.revision,$,{hubBaseUrl:o.hubBaseUrl,offline:o.offline,rememberAbsent:f.listing===null&&k,...F??{},...P??{},onProgress:I=>r({id:o.id,type:"progress",file:I.file,loaded:I.loaded,total:I.total,repo:f.repo,revision:f.revision,...z!==void 0?{provenance:z}:{}})});return w(),x[$]={source:R.source,verified:R.verified},R.bytes}catch(R){if(k&&R instanceof l&&R.missing==="not-found")return null;throw R}},Q=async(f,$,k)=>await _(f,$,!1,k),Pe=(f,$,k)=>_(oe(f),$,k),Ae={},T=a,Z,ee;if(h!==null&&h.format==="gguf"){let f=P=>t.fetchRange(E,L,h.file,P,{hubBaseUrl:o.hubBaseUrl,offline:o.offline}),$=await f(Math.min(ut,h.bytes));w();for(let P=g.ggufHeaderNeed($,h.bytes);P!==0;P=g.ggufHeaderNeed($,h.bytes))$=await f(P),w();let k=$;Z=P=>T.precheckGguf(k,h.bytes,P),ee=async(P,F)=>{let R=await Q(se,h.file,{sha256:h.sha256,bytes:h.bytes});return F?T.loadWebGpuGguf(R,P):T.loadGguf(R,P)}}else{let f=null,$=v;if(v!==null&&v.shape==="adapter"){let G=`${v.id}@${v.sha}`,j=await Pe(v,"adapter_config.json",!1),A=JSON.parse(g.adapterBase(j,G)),C=U=>{let S=O(U);return S===p||S.message.startsWith(G)?S:new l(S.kind,`${G} names base ${A.repo}: ${S.message}`,S.missing)},B=v.siblings.some(U=>U.name===X);try{let U=await t.fetchListing(A.repo,A.revision,{hubBaseUrl:o.hubBaseUrl,offline:o.offline});w(),$=JSON.parse(g.parseBaseListing(U.bytes,G,B))}catch(U){throw C(U)}f={listing:v,config:j,bytes:ie(v,ve)}}let k=$,P=k!==null?oe(k):se,F=G=>k!==null?oe(re(G,f?.listing??null,k)):se,R=await Q(P,"config.json"),I=await _(P,"model.safetensors.index.json",!0),ce=g.weightFiles(I);if(k!==null){let G=re(X,f?.listing??null,k);if(G.tokenizer===null)throw ke(G.id,G.sha);if(f!==null){let A=f.listing,C=new Set(["adapter_config.json",ve,...$e.filter(S=>re(S,A,k)===A)]),U=["config.json",...I!==null?["model.safetensors.index.json"]:[],...ce,...$e.filter(S=>re(S,A,k)===k)].find(S=>C.has(S));if(U!==void 0)throw new l("validate",`${U} is required from both ${A.id}@${A.sha} (the adapter) and ${k.id}@${k.sha} (its base); a file is fetched from one repo only`)}let j=0;for(let A of ce)j+=ie(k,A);Ae={weightBytes:j,...f!==null?{adapterBytes:f.bytes,baseRepo:k.id,baseRevision:k.sha}:{}}}Z=G=>T.precheck(R,I,G,f?.config),ee=async(G,j)=>{let A=F(X),C,B;if(A.listing!==null){let H=A.listing.tokenizer;if(H===null)throw ke(A.repo,A.revision);C=H,B=await Q(A,H)}else if(C=X,B=await _(A,X,!0),B===null&&(C=ne,B=await _(A,ne,!0)),B===null)throw ke(A.repo,A.revision);let U=C===ne?await _(F(xe),xe,!0):null,S=await _(F(Me),Me,!0),ue=await _(F(Je),Je,!0);try{T.checkTokenizer(R,C,B,U,S,ue)}catch(H){throw Ke(H,A.repo,A.revision)}let fe=[];for(let H of ce)fe.push(await Q(P,H));let Ee=f!==null?[await Pe(f.listing,ve,!1)]:void 0,Re=f?.config;try{return j?T.loadWebGpu(R,C,B,U,S,ue,fe,G,Re,Ee):T.load(R,C,B,U,S,ue,fe,G,Re,Ee)}catch(H){throw Ke(H,A.repo,A.revision)}}}let N={...o.request,repo:E,revision:L,...v!==null&&v.id!==m.repo?{resolvedFrom:m.repo}:{},...Ae},ae,q=null,Xe=()=>{let f={...N,backend:"wasm"};delete f.f16,N=f},le=f=>{let $=JSON.parse(f).provenance;z=typeof $=="string"?$:void 0},We=f=>{Xe();try{le(Z(JSON.stringify(N)))}catch($){let k=O($);throw new l(k.kind,`${k.message} (backend "auto": WebGPU refused first: ${f.message})`)}ae=`webgpu refused: ${f.message}; wasm serves this load`};if(N.backend==="webgpu"){let f=null,$=null;try{f=Z(JSON.stringify(N)),$=JSON.parse(f)}catch(k){let P=O(k);if(!(o.auto===!0&&dt.includes(P.kind)))throw P;We(P)}if($!==null){try{q=await t.openDevice(JSON.parse(o.probeJson),$.f16===!0)}catch(k){let P=O(k);if(o.auto!==!0)throw P;We(P)}q!==null&&le(f)}}else le(Z(JSON.stringify(N)));if(o.check===!0){q?.destroy(),q=null,w(),a=null,T.dispose(),r({id:o.id,type:"checked",backend:N.backend}),t.close();return}try{w();let f=JSON.stringify(N);if(q!==null){let $=await ee(f,!0),k=q;q=null,e=await t.openRuntime(T,k,$)}else await t.instantiate(T,await ee(f,!1))}finally{q?.destroy()}w(),s=a,r({id:o.id,type:"loaded",doctor:d(a),sources:x,...ae!==void 0?{fallback:ae}:{}})}catch(g){if(e?.destroy(),e=null,a!==null&&s!==a)try{a.dispose()}catch{}throw g}finally{n=!1}}async function W(o,a,g,m){let h;"messages"in o.prompt?h=a.startChatSplit(JSON.stringify(o.prompt.messages),m):"text"in o.prompt?h=a.startCompleteSplit(o.prompt.text,null,m):h=a.startCompleteSplit(null,Uint32Array.from(o.prompt.ids),m),await pt(a,g,h,{launched:()=>!c,between:async()=>(await Ze(),!c),delta:v=>r({id:o.id,type:"delta",delta:v})})}async function b(o){if(u!==null)throw new l("request","a generation is already running on this engine");if(s===null)throw new l("request","no model is loaded");let a=s,g=JSON.stringify(o.options);if(e!==null){if(e.failure!==null)throw te(e.failure);u=o.id;try{return await W(o,a,e,g)}catch(m){if(c)return;throw m}finally{u=null}}u=o.id;try{for(("messages"in o.prompt)?a.startChat(JSON.stringify(o.prompt.messages),g):("text"in o.prompt)?a.startComplete(o.prompt.text,null,g):a.startComplete(null,Uint32Array.from(o.prompt.ids),g);;){if(await Ze(),c)return;let m=JSON.parse(a.next());if(r({id:o.id,type:"delta",delta:m}),m.done)return}}finally{u=null}}return async o=>{try{switch(o.type){case"load":return await y(o);case"generate":return await b(o);case"abort":u===o.id&&s?.abort();return;case"doctor":if(s===null)throw new l("request","no model is loaded");r({id:o.id,type:"result",value:d(s)});return;case"dispose":c=!0,e?.destroy(),e=null,s?.dispose(),s=null,r({id:o.id,type:"result",value:null}),t.close();return}}catch(a){if(c)return;let g=O(a),m=e?.failure??null;r({id:o.id,type:"error",kind:g.kind,message:g.message,...m!==null?{fatal:m}:{}})}}}var K=globalThis,gt=Ve({openHost:Fe,wasmUsed:He,hostClass:_e,instantiate:Ne,openDevice:(t,r)=>Ie(t,r),openRuntime:je,fetchFile:Be,fetchListing:Te,fetchRange:Oe,close:()=>K.close()},t=>K.postMessage(t));K.onmessage=t=>{gt(t.data)};me().then(()=>K.postMessage({id:0,type:"ready",url:K.location.href}),t=>K.postMessage({id:0,type:"error",kind:"backend",message:`the browser host's glue (host/caldrix_web.js, beside dist/worker.js) did not load (${t instanceof Error?t.message:String(t)})`}));
|
|
1
|
+
import{b as a,c as D,d as ne}from"./chunk-PZGTLL5H.js";var lt="caldrix.js",Be="x-caldrix-verified",ge="x-caldrix-absent";function ut(t){return[...new Uint8Array(t)].map(r=>r.toString(16).padStart(2,"0")).join("")}function ct(t){return t.trim().replace(/^W\//,"").replace(/^"|"$/g,"").toLowerCase()}function _(t){return t instanceof Error?t.message:String(t)}function V(t,r){if(r===""||r==="."||r===".."||/[/\\?#]/.test(r)||/%[0-9a-fA-F]{2}/.test(r)||/[\u0000-\u001f\u007f]/.test(r))throw new a("validate",`${t} ${JSON.stringify(r)} is not a single safe path segment`);return encodeURIComponent(r)}function Oe(t){return new a("backend",`${t} is not available; caldrix.js needs a secure context`)}function Fe(t,r,i,e){let n=t.split("/").map(u=>V("repo",u)).join("/");return`${e.endsWith("/")?e.slice(0,-1):e}/${n}/resolve/${V("revision",r)}/${V("file",i)}`}function ft(t,r,i){let e=t.split("/").map(u=>V("repo",u)).join("/"),n=i.endsWith("/")?i.slice(0,-1):i,o=r===null?"":`/revision/${r.split("/").map(u=>V("revision",u)).join("%2F")}`;return`${n}/api/models/${e}${o}?blobs=true`}async function be(t){if(typeof caches>"u")throw Oe("caches");try{return await caches.open(lt)}catch(r){throw new a("backend",`opening the cache for ${t} failed: ${_(r)}`)}}async function pe(t){if(typeof crypto>"u"||!crypto.subtle)throw Oe("crypto.subtle");return ut(await crypto.subtle.digest("SHA-256",t))}function De(t){return new a("fetch",`${t} is not in the cache and offline is set`,"offline-uncached")}async function He(t,r,i,e){let n=Fe(t,r,i,e.hubBaseUrl),o=await be(i),u;try{u=await o.match(n)}catch(x){throw new a("backend",`reading ${i} from the cache failed: ${_(x)}`)}let l=x=>new a("fetch",`fetching ${i} failed: HTTP 404${x}`,"not-found");if(u&&u.headers.get(ge)==="1"){if(e.rememberAbsent)throw l(" (remembered from an earlier load)");u=void 0}let g=!1;if(u){let x=new Uint8Array(await u.arrayBuffer());if(e.sha256===void 0)return{bytes:x,source:"cache",verified:u.headers.get(Be)==="1",cached:!0};if(await pe(x)===e.sha256)return{bytes:x,source:"cache",verified:!0,cached:!0};g=!0;try{await o.delete(n)}catch{}}if(e.offline&&g)throw new a("fetch",`${i}: the cached copy fails the ${e.pinnedBy??"alias"}'s sha256 pin and offline is set`,"offline-uncached");if(e.offline)throw De(i);let m=(x,j)=>new a("fetch",`fetching ${i} ${x}`,j),f=()=>{if(e.signal?.aborted)throw m("was aborted")},y;try{y=await fetch(n,{signal:e.signal})}catch(x){throw m(e.signal?.aborted?"was aborted":`failed: ${_(x)}`)}if(y.status===404&&e.rememberAbsent){try{await o.put(n,new Response(null,{headers:{[ge]:"1"}}))}catch{}throw l("")}if(!y.ok||!y.body)throw m(`failed: HTTP ${y.status}`,y.status===404?"not-found":void 0);let P=y.headers.get("x-linked-etag"),w=y.headers.get("content-length"),v=w!==null&&/^\d+$/.test(w.trim())?Number(w):null,s=[],c=0,b=y.body.getReader();try{for(;;){let x;try{x=await b.read()}catch(j){throw m(e.signal?.aborted?"was aborted":`failed: ${_(j)}`)}if(x.done)break;if(s.push(x.value),c+=x.value.byteLength,e.bytes!==void 0&&c>e.bytes)throw new a("fetch",`${i}: the body passed its pinned size, ${e.bytes} bytes`);e.onProgress?.({file:i,loaded:c,total:v})}}finally{b.cancel().catch(()=>{})}if(f(),v!==null&&v!==c&&!y.headers.get("content-encoding"))throw m(`failed: Content-Length is ${v} but ${c} bytes arrived`);let d=new Uint8Array(c),k=0;for(let x of s)d.set(x,k),k+=x.byteLength;e.onProgress?.({file:i,loaded:c,total:v});let h=!1,C=null;if(e.sha256!==void 0){if(C=await pe(d),C!==e.sha256)throw new a("digest",`${i}: sha256 is ${C} but the ${e.pinnedBy??"alias"} pins ${e.sha256}`);h=!0}if(P!==null){let x=ct(P);if(C??=await pe(d),x!==C)throw new a("digest",`${i}: sha256 is ${C} but the Hub's X-Linked-Etag is ${x}`);h=!0}f();try{await o.put(n,new Response(d,{headers:{[Be]:h?"1":"0"}}))}catch{return{bytes:d,source:"network",verified:h,cached:!1}}return{bytes:d,source:"network",verified:h,cached:!0}}async function qe(t,r,i,e,n,o=0){if(!Number.isSafeInteger(e)||e<=0)throw new a("request",`a range of ${e} bytes of ${i} is not a positive integer`);if(!Number.isSafeInteger(o)||o<0||!Number.isSafeInteger(o+e))throw new a("request",`a range from byte ${o} of ${i} is not a non-negative integer`);let u=Fe(t,r,i,n.hubBaseUrl),l=await be(i),g;try{g=await l.match(u)}catch(s){throw new a("backend",`reading ${i} from the cache failed: ${_(s)}`)}if(g&&g.headers.get(ge)!=="1"){let s=new Uint8Array(await g.arrayBuffer());if(s.byteLength>=o+e)return s.slice(o,o+e)}if(n.offline)throw De(i);let m=o===0?`the first ${e} bytes`:`${e} bytes from byte ${o}`,f=s=>new a("fetch",`fetching ${m} of ${i} ${s}`),y;try{y=await fetch(u,{headers:{Range:`bytes=${o}-${o+e-1}`},signal:n.signal})}catch(s){throw f(n.signal?.aborted?"was aborted":`failed: ${_(s)}`)}if(y.status!==206&&y.status!==200||!y.body)throw f(`failed: HTTP ${y.status}`);if(y.status===200&&o!==0)throw y.body.cancel().catch(()=>{}),f("failed: the server answered HTTP 200 (the whole file) to a range past its head");let P=new Uint8Array(e),w=0,v=y.body.getReader();try{for(;;){let s;try{s=await v.read()}catch(b){throw f(n.signal?.aborted?"was aborted":`failed: ${_(b)}`)}if(s.done)break;let c=Math.min(s.value.byteLength,e-w);if(P.set(s.value.subarray(0,c),w),w+=s.value.byteLength,w>e||y.status===200&&w===e)break}}finally{v.cancel().catch(()=>{})}if(n.signal?.aborted)throw f("was aborted");if(w<e)throw f(`failed: the HTTP ${y.status} answer carried ${w} bytes, not the ${e} asked for`);if(y.status===206&&w>e)throw f(`failed: the HTTP 206 answer carried more than the ${e} bytes asked for`);return P}var Te=262144;async function Ne(t,r,i){let e=ft(t,r,i.hubBaseUrl),n=`the Hub listing of ${t}`,o=await be(n);if(i.offline){let s;try{s=await o.match(e)}catch(c){throw new a("backend",`reading ${n} from the cache failed: ${_(c)}`)}if(!s)throw new a("fetch",`${n} is not in the cache and offline is set`,"offline-uncached");return{bytes:new Uint8Array(await s.arrayBuffer()),source:"cache"}}let u=s=>new a("fetch",`fetching ${n} ${s}`),l;try{l=await fetch(e,{signal:i.signal})}catch(s){throw u(i.signal?.aborted?"was aborted":`failed: ${_(s)}`)}let g=s=>{throw l.body?.cancel().catch(()=>{}),s},m=new URL(i.hubBaseUrl).origin;l.url&&new URL(l.url).origin!==m&&g(new a("fetch",`${n} was redirected off ${m} (to ${l.url})`)),l.status===401&&g(new a("fetch",`${t}: the Hub answered HTTP 401 for its listing: the repo does not exist, or it is private (the browser build sends no token; the caldrix CLI reads HF_TOKEN)`,"not-found")),l.status===404&&g(new a("fetch",`${t}${r?"@"+r:""}: no such repo or revision on the Hub (HTTP 404)`,"not-found")),(!l.ok||!l.body)&&g(u(`failed: HTTP ${l.status}`));let f=[],y=0,P=l.body.getReader();try{for(;;){let s;try{s=await P.read()}catch(c){throw u(i.signal?.aborted?"was aborted":`failed: ${_(c)}`)}if(s.done)break;if(y+=s.value.byteLength,y>Te)throw new a("validate",`${n} passed the 256 KiB (${Te}-byte) cap`);f.push(s.value)}}finally{P.cancel().catch(()=>{})}if(i.signal?.aborted)throw u("was aborted");let w=new Uint8Array(y),v=0;for(let s of f)w.set(s,v),v+=s.byteLength;try{await o.put(e,new Response(w))}catch{}return{bytes:w,source:"network"}}var me=null,X=null;function we(t){return t instanceof Error?t.message:String(t)}async function ye(){return await import("../host/caldrix_web.js")}function dt(t){let r=globalThis.location?.href;return(r!==void 0?new URL(String(t),r):new URL(String(t))).href}async function _e(t){let r;try{r=await fetch(t)}catch(i){throw new Error(we(i))}if(!r.ok)throw new Error(`${r.status} ${r.statusText}`.trim());return r}async function ke(t,r){if(me===null){let i=await ye(),e=t??dt(new URL("../host/caldrix_web_bg.wasm",import.meta.url)),n,o;try{n=await _e(e),o={url:e}}catch(u){let l=we(u);if(r===void 0||r===e)throw new a("backend",`the browser host's .wasm could not be fetched from ${e} (${l}); serve host/ beside dist/ or set assets.hostWasm to where the page serves it`);try{n=await _e(r)}catch(g){let m=new URL(r).origin;throw new a("backend",`the browser host's .wasm could not be fetched from ${e} (${l}) nor from the CDN fallback ${r} (${we(g)}); serve host/ beside dist/, set assets.hostWasm to where the page serves it, or allow ${m} in the page's Content-Security-Policy (connect-src ${m}, the .wasm is fetched)`)}o={url:r,failed:{url:e,reason:l}}}await i.default({module_or_path:n}),me=i,X=o}return me}async function Ie(t,r,i){let e=await ke(r,i);return new e.CaldrixWeb(t)}function ze(){if(X===null)throw new a("backend","the browser host is not open");return{...X,...X.failed!==void 0?{failed:{...X.failed}}:{}}}async function je(){return(await ke()).CaldrixWeb}async function Me(t,r){let i=await ke(),e;try{let{instance:u}=await WebAssembly.instantiate(r,{env:{memory:i.CaldrixWeb.memory()}});e=u.exports}catch(u){throw new a("backend",`instantiating the emitted module failed: ${u instanceof Error?u.message:String(u)}`)}let{step:n,prefill:o}=e;if(typeof n!="function"||typeof o!="function")throw new a("backend","the emitted module does not export step and prefill");if(t.attach(n,o),t.argsPtr()===0)throw new a("backend","the host reports no model loaded after load")}var z={MAP_READ:1,COPY_SRC:4,COPY_DST:8,UNIFORM:64,STORAGE:128},ht=1,pt=["maxStorageBufferBindingSize","maxBufferSize","maxComputeWorkgroupsPerDimension","maxStorageBuffersPerShaderStage"],Je=(t,r)=>Number.isSafeInteger(t)&&t>=0&&t<r,Ke=t=>Number.isSafeInteger(t)&&t>=0;function gt(t,r){let i=n=>new a("backend",`the host's WebGPU program is malformed: ${n}`),e;try{e=JSON.parse(t)}catch(n){throw i(n instanceof Error?n.message:String(n))}if(typeof e!="object"||e===null||!Array.isArray(e.kernels)||!Array.isArray(e.buffers))throw i("no kernels or buffers");if(e.kernels.forEach((n,o)=>{if(!(typeof n?.symbol=="string"&&typeof n.entry=="string"&&Array.isArray(n.buffers)&&n.buffers.every(l=>l==="f32"||l==="f16"||l==="u32")&&Ke(n.scalars)))throw i(`kernel ${o}`)}),e.buffers.forEach((n,o)=>{if(!(typeof n?.word=="string"&&Ke(n.bytes)&&(n.storage==="f32"||n.storage==="f16"||n.storage==="blocks")&&typeof n.placed=="boolean"))throw i(`buffer ${o}`)}),!Je(e.act,e.buffers.length))throw i("act is no buffer");if(!Je(e.logits,e.buffers.length))throw i("logits is no buffer");if(!Array.isArray(r)||r.length!==e.kernels.length||!r.every(n=>typeof n=="string"))throw i(`${e.kernels.length} kernels but ${Array.isArray(r)?r.length:"no"} WGSL sources`);return e}function bt(t,r){let i=[],e=u=>new a("backend",`the host's launch words are malformed: ${u}`),n=0,o=(u,l)=>{if(n+u>t.length)throw e(`launch ${i.length} ends inside its ${l}`);let g=t.subarray(n,n+u);return n+=u,g};for(;n<t.length;){let u=o(1,"kernel")[0],l=r.kernels[u];if(l===void 0)throw e(`launch ${i.length} names kernel ${u}; the program has ${r.kernels.length}`);let g=Array.from(o(o(1,"buffer count")[0],"buffers"));if(g.length!==l.buffers.length)throw e(`a launch of ${l.symbol} binds ${g.length} buffers; the kernel declares ${l.buffers.length}`);let m=g.find(w=>w>=r.buffers.length);if(m!==void 0)throw e(`a launch of ${l.symbol} binds buffer ${m}; the program has ${r.buffers.length}`);let[f,y]=o(2,"grid"),P=o(o(1,"uniform count")[0],"uniform").slice();if(P.length===0!=(l.scalars===0))throw e(`a launch of ${l.symbol} carries ${P.length} uniform words; the kernel declares ${l.scalars} scalars`);i.push({kernel:u,buffers:g,x:f,y,uniform:P})}return i}var J=t=>t instanceof Error?t.message:String(t),$e=class{constructor(r,i,e,n,o,u,l,g){this.adapter=r;this.description=i;this.host=e;this.device=n;this.program=o;this.pipelines=u;this.buffers=l;this.staging=g;n.lost.then(m=>{let f=`the WebGPU device was lost: ${m.message||m.reason||"no message"}`;!this.#e&&this.#t===null&&(this.#t=f),this.#r?.(f)})}adapter;description;host;device;program;pipelines;buffers;staging;#t=null;#e=!1;#r=null;#n=new Set;get failure(){return this.#t}get storage(){let r=i=>this.program.buffers.some(e=>e.storage===i);return r("f16")?"f16":r("blocks")?"blocks":"f32"}async run(r,i){if(this.#e)throw new a("request","the WebGPU runtime was destroyed (the engine was disposed)");if(this.failure!==null)throw this.#i(this.failure),ne(this.failure);let e;try{e=bt(r,this.program);let g=this.program.buffers[this.program.act];if(i.byteLength>g.bytes)throw new a("backend",`actIn is ${i.byteLength} bytes; the program's ${g.word} is ${g.bytes}`)}catch(g){throw this.#s(J(g),!1)}let n=this.device,o=[],u,l=new Promise((g,m)=>{this.#r=f=>m(new Error(f))});l.catch(()=>null);try{n.pushErrorScope("validation"),n.pushErrorScope("out-of-memory"),n.pushErrorScope("internal");let g=3,m=async()=>{let v=n.popErrorScope(),s=n.popErrorScope(),c=n.popErrorScope();g=0;let[b,d,k]=await Promise.all([v,s,c]);return d?`out of memory: ${d.message}`:k?`validation: ${k.message}`:b?`an internal error: ${b.message}`:null},f,y;try{i.byteLength>0&&n.queue.writeBuffer(this.buffers[this.program.act],0,i);let v=e.map(d=>{let k=d.buffers.map((h,C)=>({binding:C,resource:{buffer:this.buffers[h]}}));if(d.uniform.length>0){let h=n.createBuffer({size:d.uniform.byteLength,usage:z.UNIFORM|z.COPY_DST});o.push(h),this.#n.add(h),n.queue.writeBuffer(h,0,d.uniform),k.push({binding:d.buffers.length,resource:{buffer:h}})}return n.createBindGroup({layout:this.pipelines[d.kernel].getBindGroupLayout(0),entries:k})}),s=n.createCommandEncoder(),c=s.beginComputePass();e.forEach((d,k)=>{c.setPipeline(this.pipelines[d.kernel]),c.setBindGroup(0,v[k]),c.dispatchWorkgroups(d.x,d.y,1)}),c.end();let b=this.buffers[this.program.logits];s.copyBufferToBuffer(b,0,this.staging,0,b.size),n.queue.submit([s.finish()]),f=m(),y=this.staging.mapAsync(ht),f.catch(()=>null),y.catch(()=>null)}finally{for(;g-- >0;)n.popErrorScope().catch(()=>null)}if(this.failure!==null)throw new Error(this.failure);let P=await Promise.race([f,l]);if(this.#e)throw new a("request","the engine was disposed during a WebGPU call");if(P!==null)throw new Error(`the device reported ${P}`);try{await Promise.race([y,l])}catch(v){throw this.#e?new a("request","the engine was disposed during a WebGPU call"):new Error(`mapping the logits readback failed: ${J(v)}`)}if(this.#e)throw new a("request","the engine was disposed during a WebGPU call");let w=this.program.buffers[this.program.logits].bytes;u=new Uint8Array(this.staging.getMappedRange(0,this.staging.size).slice(0,w)),this.staging.unmap()}catch(g){throw g instanceof a&&g.kind==="request"?g:this.#s(J(g))}finally{this.#r=null;for(let g of o)this.#n.delete(g),this.#e||g.destroy()}this.host.writeLogits(u)}#s(r,i=!0){return this.#e?new a("request","the engine was disposed during a WebGPU call"):(i&&(this.#t??=r),this.#i(r)??new a("backend",r))}#i(r){try{this.host.failLaunch(r)}catch(i){let e=D(i);if(e.kind==="backend")return e}return null}destroy(){if(!this.#e){this.#e=!0,this.#r?.("the engine was disposed during a WebGPU call");for(let r of[...this.buffers,this.staging,...this.#n])try{r.destroy()}catch{}this.#n.clear();try{this.device.destroy()}catch{}}}};function mt(t,r){let i=t.limits[r];return typeof i=="number"?i:void 0}function wt(){return globalThis.navigator?.gpu}async function Ze(t,r,i=wt()){let e=m=>new a("backend",m);if(!i)throw e("the worker has no navigator.gpu, though the page's probe found a WebGPU adapter");let n;try{n=await i.requestAdapter()}catch(m){throw e(`the worker's requestAdapter failed: ${J(m)}`)}if(!n)throw e("the worker's requestAdapter returned null, though the page's probe found an adapter");if(r&&!n.features.has("shader-f16"))throw e("the host's precheck chose f16 weight storage, but the worker's adapter has no shader-f16");let o={};for(let m of pt){let f=mt(n,m),y=t.webgpu?.limits[m];if(y!==void 0&&(f===void 0||f<y))throw e(`the worker's adapter offers ${m} ${f??"none"}; the host prechecked against the probe's ${y}`);f!==void 0&&(o[m]=f)}let u;try{u=await n.requestDevice({requiredFeatures:r?["shader-f16"]:[],requiredLimits:o})}catch(m){throw e(`requestDevice refused${r?" shader-f16 with":""} the program's limits: ${J(m)}`)}let l=n.info??{};if(!n.info&&typeof n.requestAdapterInfo=="function")try{l=await n.requestAdapterInfo()}catch{l={}}let g=!1;return{device:u,f16:r,adapter:{vendor:l.vendor??"",architecture:l.architecture??""},description:l.description??"",destroy:()=>{if(!g){g=!0;try{u.destroy()}catch{}}}}}async function Ye(t,r,i){let e=l=>new a("backend",l),n=r.device,o=[],u=()=>{for(let l of o)l.destroy();r.destroy()};try{let l=gt(i.program,i.kernels),g=l.buffers.some(P=>P.storage==="f16");if(g!==r.f16)throw e(`the program stores weights ${g?"f16":"f32"}, but the device was opened for ${r.f16?"f16":"f32"} storage`);let m=[];for(let[P,w]of l.kernels.entries()){n.pushErrorScope("validation"),n.pushErrorScope("internal");let v=null,s=null;try{let d=n.createShaderModule({code:i.kernels[P],label:w.symbol});v=n.createComputePipeline({label:w.symbol,layout:"auto",compute:{module:d,entryPoint:w.entry}})}catch(d){s=d}let c=await n.popErrorScope(),b=await n.popErrorScope()??c;if(b)throw e(`kernel ${w.symbol}: creating its pipeline: ${b.message}`);if(v===null)throw e(`kernel ${w.symbol}: creating its pipeline: ${J(s)}`);m.push(v)}for(let[P,w]of l.buffers.entries()){n.pushErrorScope("validation"),n.pushErrorScope("out-of-memory");let v=null;try{let b=n.createBuffer({size:Math.max(4,Math.ceil(w.bytes/4)*4),usage:z.STORAGE|z.COPY_SRC|z.COPY_DST,label:w.word});if(o.push(b),w.placed){let d=t.bufferBytes(P);if(d.byteLength!==w.bytes)throw new a("backend",`buffer ${w.word}: bufferBytes gave ${d.byteLength} bytes; the buffer is ${w.bytes} at ${w.storage} storage`);if(d.byteLength%4!==0)throw new a("backend",`buffer ${w.word}: ${d.byteLength} bytes are not whole 4-byte words`);n.queue.writeBuffer(b,0,d)}}catch(b){v=b}let s=await n.popErrorScope(),c=await n.popErrorScope();if(v!==null)throw v instanceof a?v:D(v);if(s)throw e(`buffer ${w.word} (${w.bytes} bytes): out of memory: ${s.message}`);if(c)throw e(`buffer ${w.word} (${w.bytes} bytes): ${c.message}`)}let f=o[l.logits],y=n.createBuffer({size:f.size,usage:z.MAP_READ|z.COPY_DST,label:"logits readback"});return new $e({...r.adapter},r.description,t,n,l,m,o,y)}catch(l){throw u(),l}}var yt=4194304,Ae=["tokenizer.json","tokenizer.model","vocab.json","merges.txt","added_tokens.json","tokenizer_config.json","chat_template.jinja"],[K,Pe,ie,We,Ee,Ve,Xe]=Ae;function se(t,r,i){return r!==null&&!(t===Pe||t===ie||t===We||t===Ee)&&r.siblings.some(n=>n.name===t)?r:i}var ve=(t,r)=>new a("validate",`${t}@${r} has no tokenizer.json, tokenizer.model, or vocab.json and merges.txt`),kt="the model has no tokenizer.json, and ";function Qe(t,r,i){let e=D(t);return e.kind!=="validate"||!e.message.startsWith(kt)?t:new a("validate",`${r}@${i}: ${e.message}`,e.missing)}var xe="adapter_model.safetensors",$t=["fit","request","probe"],et=8,tt=64;function ot(t){let r=Array.from(t);return r.length>tt?`${r.slice(0,tt).join("")}\u2026`:t}function rt(t){let r=t.slice(0,et).map(ot).join(", ");return t.length>et?`${r}, \u2026`:r}function nt(){return new Promise(t=>{let r=new MessageChannel;r.port1.onmessage=()=>{r.port1.close(),t()},r.port2.postMessage(0)})}function vt(t,r,i){if(t!=="")return t;let e=[r,i].filter(n=>n!=="");return e.length>0?e.join(" "):"unnamed adapter"}async function st(t,r,i){let e,n;try{e=i.kind==="prefill"?t.resolve("prefill",i.n):t.resolve("step",i.pos),n=t.actIn(i.kind==="prefill"?i.n:1)}catch(o){try{t.failLaunch(D(o).message)}catch{}throw o}await r.run(e,n)}async function xt(t,r,i,e){if(await st(t,r,i),!!e.launched())for(t.finishStart();;){if(!await e.between())return;let n=t.beginNext();if("delta"in n){e.delta(JSON.parse(n.delta));return}if(await st(t,r,n.launch),!e.launched())return;let o=JSON.parse(t.finishNext());if(e.delta(o),o.done)return}}async function it(t,r,i,e,n){let o=m=>{let f={...i,backend:"wasm"};delete f.f16;let y;try{y=r(JSON.stringify(f))}catch(P){let w=D(P);throw new a(w.kind,`${w.message} (backend "auto": WebGPU refused first: ${m.message})`)}return{request:f,settled:y,device:null,fallback:`webgpu refused: ${m.message}; wasm serves this load`}};if(i.backend!=="webgpu")return{request:i,settled:r(JSON.stringify(i)),device:null};let u,l;try{u=r(JSON.stringify(i)),l=JSON.parse(u)}catch(m){let f=D(m);if(!(e&&$t.includes(f.kind)))throw f;return o(f)}let g;try{g=await t.openDevice(JSON.parse(n),l.f16===!0)}catch(m){let f=D(m);if(!e)throw f;return o(f)}return{request:i,settled:u,device:g}}function at(t,r){let i=null,e=null,n=!1,o=null,u=!1,l=[],g=s=>{let c={...s.doctor(),aliases:l.map(C=>({...C}))};if(e===null)return{...c,storage:null,adapter:null};let b=e.adapter,d=`webgpu (${vt(e.description,b.vendor,b.architecture)})`,k=`backend webgpu on ${c.device}`,h=c.line.startsWith(k)?`backend webgpu on ${d}${c.line.slice(k.length)}`:c.line;return{...c,device:d,line:h,storage:e.storage,adapter:{...b}}},m=new a("request","the engine was disposed during its load"),f=()=>{if(u)throw m};async function y(s){if(i!==null||n)throw new a("request","this engine already has a model loaded");n=!0;let c=null;try{c=await t.openHost(s.probeJson,s.hostWasm,s.cdnWasm),r({id:s.id,type:"host",hostWasm:t.wasmUsed()}),f();let b=await t.hostClass(),d=b.resolveModel(s.model);l=b.listAliases();let k=d.kind==="alias"?d:null,h=null;if(d.kind==="repo"){let p=await t.fetchListing(d.repo,d.revision,{hubBaseUrl:s.hubBaseUrl,offline:s.offline});f(),h=JSON.parse(b.parseListing(p.bytes))}if(s.file!==void 0&&h?.shape!=="gguf")throw new a("request",`file names a GGUF file in a repo that lists GGUF files; ${h!==null?`${h.id}@${h.sha}`:s.model} is not one`);let C=h!==null?h.id:d.repo,x;if(h!==null)x=h.sha;else if(k!==null)x=k.revision;else throw new a("backend","internal invariant broken: a repo id reached the file fetches without its Hub listing");let j={},oe,ae={repo:C,revision:x,listing:h},le=p=>({repo:p.id,revision:p.sha,listing:p}),ue=(p,W)=>{let $=p.siblings.find(T=>T.name===W);if($===void 0)throw new a("validate",`${p.id}@${p.sha} has no ${W}`);return $.size},H=async(p,W,$,T,E)=>{let S;if(p.listing!==null){if($&&!p.listing.siblings.some(R=>R.name===W))return null;S={bytes:ue(p.listing,W)}}try{let R=await t.fetchFile(p.repo,p.revision,W,{hubBaseUrl:s.hubBaseUrl,offline:s.offline,rememberAbsent:p.listing===null&&$,...S??{},...T??{},...E!==void 0?{pinnedBy:E}:{},onProgress:F=>r({id:s.id,type:"progress",file:F.file,loaded:F.loaded,total:F.total,repo:p.repo,revision:p.revision,...oe!==void 0?{provenance:oe}:{}})});return f(),j[W]={source:R.source,verified:R.verified},R.bytes}catch(R){if($&&R instanceof a&&R.missing==="not-found")return null;throw R}},Y=async(p,W,$,T)=>await H(p,W,!1,$,T),Re=(p,W,$)=>H(le(p),W,$),Se={},q=c,ce,Q,ee=null;if(k!==null&&k.format==="gguf")ee={file:k.file,bytes:k.bytes,sha256:k.sha256,pinnedBy:"alias"};else if(h!==null&&h.shape==="gguf"){let p=h.gguf_files??[];if(s.file===void 0)throw new a("request",`${h.id}@${h.sha} lists GGUF files; name one with the file option: ${rt(p)}`);if(!p.includes(s.file))throw new a("request",`${ot(s.file)} is not a GGUF file ${h.id}@${h.sha} offers; the choices are: ${rt(p)}`);let W=h.siblings.find($=>$.name===s.file);if(W===void 0)throw new a("validate",`${h.id}@${h.sha} has no ${s.file}`);ee={file:s.file,bytes:W.size,...W.sha256?{sha256:W.sha256}:{},pinnedBy:"listing"}}if(ee!==null){let p=ee,W=(E,S=0)=>t.fetchRange(C,x,p.file,E,{hubBaseUrl:s.hubBaseUrl,offline:s.offline},S),T=await(async()=>{let E=await W(Math.min(yt,p.bytes));f();for(let F=b.ggufHeaderNeed(E,p.bytes);F!==0;F=b.ggufHeaderNeed(E,p.bytes))E=await W(F),f();let S=b.ggufRopeFreqsExtent(E,p.bytes);if(S===void 0||S[0]+S[1]<=E.byteLength)return{head:E};let R=await W(S[1],S[0]);return f(),{head:E,rope:R}})();ce=E=>{if(T===null)throw new a("backend","internal invariant broken: a GGUF precheck after its head was released");return q.precheckGguf(T.head,p.bytes,E,T.rope)},Q=async(E,S)=>{T=null;let R=await Y(ae,p.file,{bytes:p.bytes,...p.sha256!==void 0?{sha256:p.sha256}:{}},p.pinnedBy);return S?q.loadWebGpuGguf(R,E):q.loadGguf(R,E)}}else{let p=null,W=h;if(h!==null&&h.shape==="adapter"){let L=`${h.id}@${h.sha}`,I=await Re(h,"adapter_config.json",!1),A=JSON.parse(b.adapterBase(I,L)),O=G=>{let U=D(G);return U===m||U.message.startsWith(L)?U:new a(U.kind,`${L} names base ${A.repo}: ${U.message}`,U.missing)},B=h.siblings.some(G=>G.name===K);try{let G=await t.fetchListing(A.repo,A.revision,{hubBaseUrl:s.hubBaseUrl,offline:s.offline});f(),W=JSON.parse(b.parseBaseListing(G.bytes,L,B))}catch(G){throw O(G)}p={listing:h,config:I,bytes:ue(h,xe)}}let $=W,T=$!==null?le($):ae,E=L=>$!==null?le(se(L,p?.listing??null,$)):ae,S=await Y(T,"config.json"),R=await H(T,"model.safetensors.index.json",!0),F=b.weightFiles(R);if($!==null){let L=se(K,p?.listing??null,$);if(L.tokenizer===null)throw ve(L.id,L.sha);if(p!==null){let A=p.listing,O=new Set(["adapter_config.json",xe,...Ae.filter(U=>se(U,A,$)===A)]),G=["config.json",...R!==null?["model.safetensors.index.json"]:[],...F,...Ae.filter(U=>se(U,A,$)===$)].find(U=>O.has(U));if(G!==void 0)throw new a("validate",`${G} is required from both ${A.id}@${A.sha} (the adapter) and ${$.id}@${$.sha} (its base); a file is fetched from one repo only`)}let I=0;for(let A of F)I+=ue($,A);Se={weightBytes:I,...p!==null?{adapterBytes:p.bytes,baseRepo:$.id,baseRevision:$.sha}:{}}}ce=L=>q.precheck(S,R,L,p?.config),Q=async(L,I)=>{let A=E(K),O,B,G=null;if(A.listing!==null){let N=A.listing.tokenizer;if(N===null)throw ve(A.repo,A.revision);O=N,B=await Y(A,N),N===ie&&(G=await Y(A,We))}else if(O=K,B=await H(A,K,!0),B===null&&(O=Pe,B=await H(A,Pe,!0)),B===null&&(O=ie,B=await H(A,ie,!0),B!==null&&(G=await H(A,We,!0)),G===null&&(B=null)),B===null)throw ve(A.repo,A.revision);let U=O!==K?await H(E(Ee),Ee,!0):null,fe=await H(E(Ve),Ve,!0),de=await H(E(Xe),Xe,!0);try{q.checkTokenizer(S,O,B,G,U,fe,de)}catch(N){throw Qe(N,A.repo,A.revision)}let he=[];for(let N of F)he.push(await Y(T,N));let Ue=p!==null?[await Re(p.listing,xe,!1)]:void 0,Le=p?.config;try{return I?q.loadWebGpu(S,O,B,G,U,fe,de,he,L,Le,Ue):q.load(S,O,B,G,U,fe,de,he,L,Le,Ue)}catch(N){throw Qe(N,A.repo,A.revision)}}}let te={...s.request,repo:C,revision:x,...h!==null&&h.id!==d.repo?{resolvedFrom:d.repo}:{},...Se},re=await it(t,ce,te,s.auto===!0,s.probeJson);te=re.request;let Ge=re.fallback,M=re.device,Ce=JSON.parse(re.settled).provenance;if(oe=typeof Ce=="string"?Ce:void 0,s.check===!0){M?.destroy(),M=null,f(),c=null,q.dispose(),r({id:s.id,type:"checked",backend:te.backend}),t.close();return}try{f();let p=JSON.stringify(te);if(M!==null){let W=await Q(p,!0),$=M;M=null,e=await t.openRuntime(q,$,W)}else await t.instantiate(q,await Q(p,!1))}finally{M?.destroy()}f(),i=c,r({id:s.id,type:"loaded",doctor:g(c),sources:j,...Ge!==void 0?{fallback:Ge}:{}})}catch(b){if(e?.destroy(),e=null,c!==null&&i!==c)try{c.dispose()}catch{}throw b}finally{n=!1}}async function P(s){if(i!==null||n)throw new a("request","this engine already has a model loaded");n=!0;let c=null;try{c=await t.openHost(s.probeJson,s.hostWasm,s.cdnWasm),r({id:s.id,type:"host",hostWasm:t.wasmUsed()}),f();let b=c,d={backend:s.backend,...s.maxContext!==void 0?{maxContext:s.maxContext}:{}},k=await it(t,C=>b.precheckFacts(s.facts,C),d,s.auto===!0,s.probeJson);k.device?.destroy(),f();let h=JSON.parse(k.settled);c=null,b.dispose(),r({id:s.id,type:"fitted",backend:k.request.backend,maxContext:typeof h.maxContext=="number"?h.maxContext:null,contextClamp:typeof h.contextClamp=="string"?h.contextClamp:null}),t.close()}catch(b){if(c!==null)try{c.dispose()}catch{}throw b}finally{n=!1}}async function w(s,c,b,d){let k;"messages"in s.prompt?k=c.startChatSplit(JSON.stringify(s.prompt.messages),d):"text"in s.prompt?k=c.startCompleteSplit(s.prompt.text,null,d):k=c.startCompleteSplit(null,Uint32Array.from(s.prompt.ids),d),await xt(c,b,k,{launched:()=>!u,between:async()=>(await nt(),!u),delta:h=>r({id:s.id,type:"delta",delta:h})})}async function v(s){if(o!==null)throw new a("request","a generation is already running on this engine");if(i===null)throw new a("request","no model is loaded");let c=i,b=JSON.stringify(s.options);if(e!==null){if(e.failure!==null)throw ne(e.failure);o=s.id;try{return await w(s,c,e,b)}catch(d){if(u)return;throw d}finally{o=null}}o=s.id;try{for(("messages"in s.prompt)?c.startChat(JSON.stringify(s.prompt.messages),b):("text"in s.prompt)?c.startComplete(s.prompt.text,null,b):c.startComplete(null,Uint32Array.from(s.prompt.ids),b);;){if(await nt(),u)return;let d=JSON.parse(c.next());if(r({id:s.id,type:"delta",delta:d}),d.done)return}}finally{o=null}}return async s=>{try{switch(s.type){case"load":return await y(s);case"fit":return await P(s);case"generate":return await v(s);case"abort":o===s.id&&i?.abort();return;case"doctor":if(i===null)throw new a("request","no model is loaded");r({id:s.id,type:"result",value:g(i)});return;case"dispose":u=!0,e?.destroy(),e=null,i?.dispose(),i=null,r({id:s.id,type:"result",value:null}),t.close();return}}catch(c){if(u)return;let b=D(c),d=e?.failure??null;r({id:s.id,type:"error",kind:b.kind,message:b.message,...d!==null?{fatal:d}:{}})}}}var Z=globalThis,At=at({openHost:Ie,wasmUsed:ze,hostClass:je,instantiate:Me,openDevice:(t,r)=>Ze(t,r),openRuntime:Ye,fetchFile:He,fetchListing:Ne,fetchRange:qe,close:()=>Z.close()},t=>Z.postMessage(t));Z.onmessage=t=>{At(t.data)};ye().then(()=>Z.postMessage({id:0,type:"ready",url:Z.location.href}),t=>Z.postMessage({id:0,type:"error",kind:"backend",message:`the browser host's glue (host/caldrix_web.js, beside dist/worker.js) did not load (${t instanceof Error?t.message:String(t)})`}));
|
package/host/caldrix_web.d.ts
CHANGED
|
@@ -31,11 +31,11 @@ export class CaldrixWeb {
|
|
|
31
31
|
*/
|
|
32
32
|
bufferBytes(index: number): Uint8Array;
|
|
33
33
|
/**
|
|
34
|
-
* Builds the tokenizer as [`CaldrixWeb::load`] would from its first
|
|
34
|
+
* Builds the tokenizer as [`CaldrixWeb::load`] would from its first seven arguments, and drops
|
|
35
35
|
* it: called once the tokenizer files are fetched, before the first weight shard, so a refused
|
|
36
36
|
* tokenizer costs no weight byte. Refuses exactly what `load` refuses for the tokenizer.
|
|
37
37
|
*/
|
|
38
|
-
checkTokenizer(config_json: Uint8Array, tokenizer_file: string, tokenizer: Uint8Array, added_tokens?: Uint8Array | null, tokenizer_config?: Uint8Array | null, chat_template?: Uint8Array | null): void;
|
|
38
|
+
checkTokenizer(config_json: Uint8Array, tokenizer_file: string, tokenizer: Uint8Array, merges?: Uint8Array | null, added_tokens?: Uint8Array | null, tokenizer_config?: Uint8Array | null, chat_template?: Uint8Array | null): void;
|
|
39
39
|
/**
|
|
40
40
|
* Releases the host's heap and everything it holds; every later call (but `dispose` and `abort`,
|
|
41
41
|
* no-ops, and `argsPtr`, then `0`) is a `request` refusal rather than a use of a freed
|
|
@@ -75,9 +75,17 @@ export class CaldrixWeb {
|
|
|
75
75
|
/**
|
|
76
76
|
* How much of a GGUF file's head the page reads next: `0` when `prefix` holds the whole
|
|
77
77
|
* header, else the next range's length (doubling, capped at `file_bytes`). The page's first
|
|
78
|
-
* range is `HEADER_FIRST_RANGE` (4 MiB) or the whole file when smaller.
|
|
78
|
+
* range is `HEADER_FIRST_RANGE` (4 MiB) or the whole file when smaller. The header alone:
|
|
79
|
+
* `rope_freqs.weight`'s data is [`CaldrixWeb::gguf_rope_freqs_extent`]'s.
|
|
79
80
|
*/
|
|
80
81
|
static ggufHeaderNeed(prefix: Uint8Array, file_bytes: number): number;
|
|
82
|
+
/**
|
|
83
|
+
* Where `rope_freqs.weight`'s data lies in a GGUF file, `[offset, length]`, from a `prefix`
|
|
84
|
+
* whose header parses; `undefined` when the header lists no such tensor. A hostile extent
|
|
85
|
+
* (past 512 bytes, overflowing, or past `file_bytes`) is a `validate` refusal. The page reads
|
|
86
|
+
* it as a second range when it ends past `prefix`, and passes it to `precheckGguf`.
|
|
87
|
+
*/
|
|
88
|
+
static ggufRopeFreqsExtent(prefix: Uint8Array, file_bytes: number): Float64Array | undefined;
|
|
81
89
|
/**
|
|
82
90
|
* Every alias the browser build knows: `[{ name, format }]`, `format` `"safetensors"` or
|
|
83
91
|
* `"gguf"` (what `resolveAlias` answers for that name).
|
|
@@ -108,7 +116,7 @@ export class CaldrixWeb {
|
|
|
108
116
|
* sources in the same index order. Nothing is attached: the split-phase calls drive it. The
|
|
109
117
|
* adapter arguments and the densified path are [`CaldrixWeb::load`]'s, at the plan dtype f32.
|
|
110
118
|
*/
|
|
111
|
-
loadWebGpu(config_json: Uint8Array, tokenizer_file: string, tokenizer: Uint8Array, added_tokens: Uint8Array | null | undefined, tokenizer_config: Uint8Array | null | undefined, chat_template: Uint8Array | null | undefined, files: Array<any>, request_json: string, adapter_config?: Uint8Array | null, adapter_files?: Array<any> | null): any;
|
|
119
|
+
loadWebGpu(config_json: Uint8Array, tokenizer_file: string, tokenizer: Uint8Array, merges: Uint8Array | null | undefined, added_tokens: Uint8Array | null | undefined, tokenizer_config: Uint8Array | null | undefined, chat_template: Uint8Array | null | undefined, files: Array<any>, request_json: string, adapter_config?: Uint8Array | null, adapter_files?: Array<any> | null): any;
|
|
112
120
|
/**
|
|
113
121
|
* Prechecks again on the real bytes, imports, lowers and places into the host's heap; returns
|
|
114
122
|
* the module bytes for the page to instantiate over [`memory`]. With `adapter_config` and
|
|
@@ -116,10 +124,12 @@ export class CaldrixWeb {
|
|
|
116
124
|
* bitsandbytes nf4 repo), the model is imported densified at the request's plan dtype, then
|
|
117
125
|
* prechecked over the imported dense descriptor and the files' real lengths, lowered and
|
|
118
126
|
* placed tensor by tensor; the base's files and the adapter's are freed before this returns.
|
|
119
|
-
* `tokenizer_file` names what `tokenizer` holds: `tokenizer.json`,
|
|
120
|
-
* the repo's `
|
|
127
|
+
* `tokenizer_file` names what `tokenizer` holds: `tokenizer.json`, `tokenizer.model`, or
|
|
128
|
+
* `vocab.json` (with the repo's `merges.txt` as `merges`, required with it and refused with
|
|
129
|
+
* anything else); a `tokenizer.model` or `vocab.json` repo's `added_tokens.json` is
|
|
130
|
+
* `added_tokens`, when it has one. Any other file is refused.
|
|
121
131
|
*/
|
|
122
|
-
load(config_json: Uint8Array, tokenizer_file: string, tokenizer: Uint8Array, added_tokens: Uint8Array | null | undefined, tokenizer_config: Uint8Array | null | undefined, chat_template: Uint8Array | null | undefined, files: Array<any>, request_json: string, adapter_config?: Uint8Array | null, adapter_files?: Array<any> | null): Uint8Array;
|
|
132
|
+
load(config_json: Uint8Array, tokenizer_file: string, tokenizer: Uint8Array, merges: Uint8Array | null | undefined, added_tokens: Uint8Array | null | undefined, tokenizer_config: Uint8Array | null | undefined, chat_template: Uint8Array | null | undefined, files: Array<any>, request_json: string, adapter_config?: Uint8Array | null, adapter_files?: Array<any> | null): Uint8Array;
|
|
123
133
|
/**
|
|
124
134
|
* Where the module writes each logits row: [`Placed::logits`], `0` when nothing is loaded. For
|
|
125
135
|
* a test page that reads the row from [`CaldrixWeb::memory`]; the product never reads it.
|
|
@@ -144,15 +154,24 @@ export class CaldrixWeb {
|
|
|
144
154
|
static parseBaseListing(bytes: Uint8Array, adapter_at: string, adapter_has_tokenizer: boolean): string;
|
|
145
155
|
/**
|
|
146
156
|
* The Hub's listing bytes, parsed, gated refused and the shape decided; answers the JSON
|
|
147
|
-
* `{"id","sha","shape":"model"|"adapter","tokenizer","siblings":[{"name","size"}]}` (never
|
|
148
|
-
* gated); `tokenizer` is the file a load reads, `"tokenizer.json"`, `"tokenizer.model"
|
|
157
|
+
* `{"id","sha","shape":"model"|"adapter"|"gguf","tokenizer","siblings":[{"name","size","sha256"}],"gguf_files"}` (never
|
|
158
|
+
* gated); `tokenizer` is the file a load reads, `"tokenizer.json"`, `"tokenizer.model"`,
|
|
159
|
+
* `"vocab.json"` (with `merges.txt`) or `null`; `sha256` is the lower-case 64-hex LFS digest or
|
|
160
|
+
* `null`; `gguf_files` names the choosable GGUF files (`[]` unless the shape is `"gguf"`).
|
|
149
161
|
*/
|
|
150
162
|
static parseListing(bytes: Uint8Array): string;
|
|
163
|
+
/**
|
|
164
|
+
* [`CaldrixWeb::precheck_gguf`] from a GGUF file's recorded facts (the nightly's JSON) in
|
|
165
|
+
* place of its head: no byte of the file is read. A facts admit is no load guarantee.
|
|
166
|
+
*/
|
|
167
|
+
precheckFacts(facts_json: string, request_json: string): any;
|
|
151
168
|
/**
|
|
152
169
|
* [`CaldrixWeb::precheck`] over a GGUF file's head: `header` is enough of it for the header
|
|
153
|
-
* to parse ([`CaldrixWeb::gguf_header_need`] answers 0), `file_bytes` the
|
|
170
|
+
* to parse ([`CaldrixWeb::gguf_header_need`] answers 0), `file_bytes` the file's pinned size.
|
|
171
|
+
* `rope_freqs`, when given, is exactly the extent [`CaldrixWeb::gguf_rope_freqs_extent`]
|
|
172
|
+
* named (the page's second range), read in place of `header` there.
|
|
154
173
|
*/
|
|
155
|
-
precheckGguf(header: Uint8Array, file_bytes: number, request_json: string): any;
|
|
174
|
+
precheckGguf(header: Uint8Array, file_bytes: number, request_json: string, rope_freqs?: Uint8Array | null): any;
|
|
156
175
|
/**
|
|
157
176
|
* Checks a model before any download. `adapter_config` is an adapter repo's
|
|
158
177
|
* `adapter_config.json` (then the request names `weightBytes` and `adapterBytes`); with it, or
|
|
@@ -200,7 +219,7 @@ export interface InitOutput {
|
|
|
200
219
|
readonly caldrixweb_attach: (a: number, b: number, c: number, d: number) => void;
|
|
201
220
|
readonly caldrixweb_beginNext: (a: number, b: number) => void;
|
|
202
221
|
readonly caldrixweb_bufferBytes: (a: number, b: number, c: number) => void;
|
|
203
|
-
readonly caldrixweb_checkTokenizer: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number) => void;
|
|
222
|
+
readonly caldrixweb_checkTokenizer: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number) => void;
|
|
204
223
|
readonly caldrixweb_dispose: (a: number) => void;
|
|
205
224
|
readonly caldrixweb_doctor: (a: number, b: number) => void;
|
|
206
225
|
readonly caldrixweb_encode: (a: number, b: number, c: number, d: number) => void;
|
|
@@ -209,11 +228,12 @@ export interface InitOutput {
|
|
|
209
228
|
readonly caldrixweb_finishStart: (a: number, b: number) => void;
|
|
210
229
|
readonly caldrixweb_ggufHeaderFirstRange: () => number;
|
|
211
230
|
readonly caldrixweb_ggufHeaderNeed: (a: number, b: number, c: number, d: number) => void;
|
|
231
|
+
readonly caldrixweb_ggufRopeFreqsExtent: (a: number, b: number, c: number, d: number) => void;
|
|
212
232
|
readonly caldrixweb_listAliases: (a: number) => void;
|
|
213
233
|
readonly caldrixweb_listingCap: () => number;
|
|
214
|
-
readonly caldrixweb_load: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number) => void;
|
|
234
|
+
readonly caldrixweb_load: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number, u: number, v: number) => void;
|
|
215
235
|
readonly caldrixweb_loadGguf: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
216
|
-
readonly caldrixweb_loadWebGpu: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number) => void;
|
|
236
|
+
readonly caldrixweb_loadWebGpu: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number, u: number, v: number) => void;
|
|
217
237
|
readonly caldrixweb_loadWebGpuGguf: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
218
238
|
readonly caldrixweb_logitsPtr: (a: number, b: number) => void;
|
|
219
239
|
readonly caldrixweb_memory: () => number;
|
|
@@ -222,7 +242,8 @@ export interface InitOutput {
|
|
|
222
242
|
readonly caldrixweb_parseBaseListing: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
223
243
|
readonly caldrixweb_parseListing: (a: number, b: number, c: number) => void;
|
|
224
244
|
readonly caldrixweb_precheck: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
|
|
225
|
-
readonly
|
|
245
|
+
readonly caldrixweb_precheckFacts: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
246
|
+
readonly caldrixweb_precheckGguf: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
226
247
|
readonly caldrixweb_resolve: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
227
248
|
readonly caldrixweb_resolveAlias: (a: number, b: number, c: number) => void;
|
|
228
249
|
readonly caldrixweb_resolveModel: (a: number, b: number, c: number) => void;
|
package/host/caldrix_web.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class Q{__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,tt.unregister(this),e}free(){const e=this.__destroy_into_raw();t.__wbg_caldrixweb_free(e,0)}abort(){t.caldrixweb_abort(this.__wbg_ptr)}actIn(e){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_actIn(o,this.__wbg_ptr,e);var n=i().getInt32(o+0,!0),_=i().getInt32(o+4,!0),r=i().getInt32(o+8,!0);if(r)throw g(_);return g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}static adapterBase(e,n){let _,r;try{const u=t.__wbindgen_add_to_stack_pointer(-16),y=l(e,t.__wbindgen_export),I=c,m=f(n,t.__wbindgen_export,t.__wbindgen_export2),k=c;t.caldrixweb_adapterBase(u,y,I,m,k);var o=i().getInt32(u+0,!0),s=i().getInt32(u+4,!0),d=i().getInt32(u+8,!0),w=i().getInt32(u+12,!0),p=o,b=s;if(w)throw p=0,b=0,g(d);return _=p,r=b,L(p,b)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_export4(_,r,1)}}argsPtr(){return t.caldrixweb_argsPtr(this.__wbg_ptr)>>>0}attach(e,n){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_attach(o,this.__wbg_ptr,h(e),h(n));var _=i().getInt32(o+0,!0),r=i().getInt32(o+4,!0);if(r)throw g(_)}finally{t.__wbindgen_add_to_stack_pointer(16)}}beginNext(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_beginNext(r,this.__wbg_ptr);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return g(e)}finally{t.__wbindgen_add_to_stack_pointer(16)}}bufferBytes(e){try{const o=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_bufferBytes(o,this.__wbg_ptr,e);var n=i().getInt32(o+0,!0),_=i().getInt32(o+4,!0),r=i().getInt32(o+8,!0);if(r)throw g(_);return g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}checkTokenizer(e,n,_,r,o,s){try{const k=t.__wbindgen_add_to_stack_pointer(-16),A=l(e,t.__wbindgen_export),T=c,C=f(n,t.__wbindgen_export,t.__wbindgen_export2),O=c,U=l(_,t.__wbindgen_export),F=c;var d=v(r)?0:l(r,t.__wbindgen_export),w=c,p=v(o)?0:l(o,t.__wbindgen_export),b=c,u=v(s)?0:l(s,t.__wbindgen_export),y=c;t.caldrixweb_checkTokenizer(k,this.__wbg_ptr,A,T,C,O,U,F,d,w,p,b,u,y);var I=i().getInt32(k+0,!0),m=i().getInt32(k+4,!0);if(m)throw g(I)}finally{t.__wbindgen_add_to_stack_pointer(16)}}dispose(){t.caldrixweb_dispose(this.__wbg_ptr)}doctor(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_doctor(r,this.__wbg_ptr);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return g(e)}finally{t.__wbindgen_add_to_stack_pointer(16)}}encode(e){try{const o=t.__wbindgen_add_to_stack_pointer(-16),s=f(e,t.__wbindgen_export,t.__wbindgen_export2),d=c;t.caldrixweb_encode(o,this.__wbg_ptr,s,d);var n=i().getInt32(o+0,!0),_=i().getInt32(o+4,!0),r=i().getInt32(o+8,!0);if(r)throw g(_);return g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}failLaunch(e){try{const r=t.__wbindgen_add_to_stack_pointer(-16),o=f(e,t.__wbindgen_export,t.__wbindgen_export2),s=c;t.caldrixweb_failLaunch(r,this.__wbg_ptr,o,s);var n=i().getInt32(r+0,!0),_=i().getInt32(r+4,!0);if(_)throw g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}finishNext(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_finishNext(r,this.__wbg_ptr);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return g(e)}finally{t.__wbindgen_add_to_stack_pointer(16)}}finishStart(){try{const _=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_finishStart(_,this.__wbg_ptr);var e=i().getInt32(_+0,!0),n=i().getInt32(_+4,!0);if(n)throw g(e)}finally{t.__wbindgen_add_to_stack_pointer(16)}}static ggufHeaderFirstRange(){return t.caldrixweb_ggufHeaderFirstRange()}static ggufHeaderNeed(e,n){try{const s=t.__wbindgen_add_to_stack_pointer(-16),d=l(e,t.__wbindgen_export),w=c;t.caldrixweb_ggufHeaderNeed(s,d,w,n);var _=i().getFloat64(s+0,!0),r=i().getInt32(s+8,!0),o=i().getInt32(s+12,!0);if(o)throw g(r);return _}finally{t.__wbindgen_add_to_stack_pointer(16)}}static listAliases(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_listAliases(r);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return g(e)}finally{t.__wbindgen_add_to_stack_pointer(16)}}static listingCap(){return t.caldrixweb_listingCap()}loadGguf(e,n){try{const s=t.__wbindgen_add_to_stack_pointer(-16),d=l(e,t.__wbindgen_export),w=c,p=f(n,t.__wbindgen_export,t.__wbindgen_export2),b=c;t.caldrixweb_loadGguf(s,this.__wbg_ptr,d,w,p,b);var _=i().getInt32(s+0,!0),r=i().getInt32(s+4,!0),o=i().getInt32(s+8,!0);if(o)throw g(r);return g(_)}finally{t.__wbindgen_add_to_stack_pointer(16)}}loadWebGpuGguf(e,n){try{const s=t.__wbindgen_add_to_stack_pointer(-16),d=l(e,t.__wbindgen_export),w=c,p=f(n,t.__wbindgen_export,t.__wbindgen_export2),b=c;t.caldrixweb_loadWebGpuGguf(s,this.__wbg_ptr,d,w,p,b);var _=i().getInt32(s+0,!0),r=i().getInt32(s+4,!0),o=i().getInt32(s+8,!0);if(o)throw g(r);return g(_)}finally{t.__wbindgen_add_to_stack_pointer(16)}}loadWebGpu(e,n,_,r,o,s,d,w,p,b){try{const W=t.__wbindgen_add_to_stack_pointer(-16),P=l(e,t.__wbindgen_export),V=c,H=f(n,t.__wbindgen_export,t.__wbindgen_export2),z=c,$=l(_,t.__wbindgen_export),q=c;var u=v(r)?0:l(r,t.__wbindgen_export),y=c,I=v(o)?0:l(o,t.__wbindgen_export),m=c,k=v(s)?0:l(s,t.__wbindgen_export),A=c;const X=f(w,t.__wbindgen_export,t.__wbindgen_export2),Y=c;var T=v(p)?0:l(p,t.__wbindgen_export),C=c;t.caldrixweb_loadWebGpu(W,this.__wbg_ptr,P,V,H,z,$,q,u,y,I,m,k,A,h(d),X,Y,T,C,v(b)?0:h(b));var O=i().getInt32(W+0,!0),U=i().getInt32(W+4,!0),F=i().getInt32(W+8,!0);if(F)throw g(U);return g(O)}finally{t.__wbindgen_add_to_stack_pointer(16)}}load(e,n,_,r,o,s,d,w,p,b){try{const W=t.__wbindgen_add_to_stack_pointer(-16),P=l(e,t.__wbindgen_export),V=c,H=f(n,t.__wbindgen_export,t.__wbindgen_export2),z=c,$=l(_,t.__wbindgen_export),q=c;var u=v(r)?0:l(r,t.__wbindgen_export),y=c,I=v(o)?0:l(o,t.__wbindgen_export),m=c,k=v(s)?0:l(s,t.__wbindgen_export),A=c;const X=f(w,t.__wbindgen_export,t.__wbindgen_export2),Y=c;var T=v(p)?0:l(p,t.__wbindgen_export),C=c;t.caldrixweb_load(W,this.__wbg_ptr,P,V,H,z,$,q,u,y,I,m,k,A,h(d),X,Y,T,C,v(b)?0:h(b));var O=i().getInt32(W+0,!0),U=i().getInt32(W+4,!0),F=i().getInt32(W+8,!0);if(F)throw g(U);return g(O)}finally{t.__wbindgen_add_to_stack_pointer(16)}}logitsPtr(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_logitsPtr(r,this.__wbg_ptr);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return e>>>0}finally{t.__wbindgen_add_to_stack_pointer(16)}}static memory(){const e=t.caldrixweb_memory();return g(e)}constructor(e){try{const o=t.__wbindgen_add_to_stack_pointer(-16),s=f(e,t.__wbindgen_export,t.__wbindgen_export2),d=c;t.caldrixweb_new(o,s,d);var n=i().getInt32(o+0,!0),_=i().getInt32(o+4,!0),r=i().getInt32(o+8,!0);if(r)throw g(_);return this.__wbg_ptr=n,tt.register(this,this.__wbg_ptr,this),this}finally{t.__wbindgen_add_to_stack_pointer(16)}}next(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_next(r,this.__wbg_ptr);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return g(e)}finally{t.__wbindgen_add_to_stack_pointer(16)}}static parseBaseListing(e,n,_){let r,o;try{const y=t.__wbindgen_add_to_stack_pointer(-16),I=l(e,t.__wbindgen_export),m=c,k=f(n,t.__wbindgen_export,t.__wbindgen_export2),A=c;t.caldrixweb_parseBaseListing(y,I,m,k,A,_);var s=i().getInt32(y+0,!0),d=i().getInt32(y+4,!0),w=i().getInt32(y+8,!0),p=i().getInt32(y+12,!0),b=s,u=d;if(p)throw b=0,u=0,g(w);return r=b,o=u,L(b,u)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_export4(r,o,1)}}static parseListing(e){let n,_;try{const b=t.__wbindgen_add_to_stack_pointer(-16),u=l(e,t.__wbindgen_export),y=c;t.caldrixweb_parseListing(b,u,y);var r=i().getInt32(b+0,!0),o=i().getInt32(b+4,!0),s=i().getInt32(b+8,!0),d=i().getInt32(b+12,!0),w=r,p=o;if(d)throw w=0,p=0,g(s);return n=w,_=p,L(w,p)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_export4(n,_,1)}}precheckGguf(e,n,_){try{const d=t.__wbindgen_add_to_stack_pointer(-16),w=l(e,t.__wbindgen_export),p=c,b=f(_,t.__wbindgen_export,t.__wbindgen_export2),u=c;t.caldrixweb_precheckGguf(d,this.__wbg_ptr,w,p,n,b,u);var r=i().getInt32(d+0,!0),o=i().getInt32(d+4,!0),s=i().getInt32(d+8,!0);if(s)throw g(o);return g(r)}finally{t.__wbindgen_add_to_stack_pointer(16)}}precheck(e,n,_,r){try{const y=t.__wbindgen_add_to_stack_pointer(-16),I=l(e,t.__wbindgen_export),m=c;var o=v(n)?0:l(n,t.__wbindgen_export),s=c;const k=f(_,t.__wbindgen_export,t.__wbindgen_export2),A=c;var d=v(r)?0:l(r,t.__wbindgen_export),w=c;t.caldrixweb_precheck(y,this.__wbg_ptr,I,m,o,s,k,A,d,w);var p=i().getInt32(y+0,!0),b=i().getInt32(y+4,!0),u=i().getInt32(y+8,!0);if(u)throw g(b);return g(p)}finally{t.__wbindgen_add_to_stack_pointer(16)}}static resolveAlias(e){try{const o=t.__wbindgen_add_to_stack_pointer(-16),s=f(e,t.__wbindgen_export,t.__wbindgen_export2),d=c;t.caldrixweb_resolveAlias(o,s,d);var n=i().getInt32(o+0,!0),_=i().getInt32(o+4,!0),r=i().getInt32(o+8,!0);if(r)throw g(_);return g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}static resolveModel(e){try{const o=t.__wbindgen_add_to_stack_pointer(-16),s=f(e,t.__wbindgen_export,t.__wbindgen_export2),d=c;t.caldrixweb_resolveModel(o,s,d);var n=i().getInt32(o+0,!0),_=i().getInt32(o+4,!0),r=i().getInt32(o+8,!0);if(r)throw g(_);return g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}resolve(e,n){try{const s=t.__wbindgen_add_to_stack_pointer(-16),d=f(e,t.__wbindgen_export,t.__wbindgen_export2),w=c;t.caldrixweb_resolve(s,this.__wbg_ptr,d,w,n);var _=i().getInt32(s+0,!0),r=i().getInt32(s+4,!0),o=i().getInt32(s+8,!0);if(o)throw g(r);return g(_)}finally{t.__wbindgen_add_to_stack_pointer(16)}}startChatSplit(e,n){try{const s=t.__wbindgen_add_to_stack_pointer(-16),d=f(e,t.__wbindgen_export,t.__wbindgen_export2),w=c,p=f(n,t.__wbindgen_export,t.__wbindgen_export2),b=c;t.caldrixweb_startChatSplit(s,this.__wbg_ptr,d,w,p,b);var _=i().getInt32(s+0,!0),r=i().getInt32(s+4,!0),o=i().getInt32(s+8,!0);if(o)throw g(r);return g(_)}finally{t.__wbindgen_add_to_stack_pointer(16)}}startChat(e,n){try{const s=t.__wbindgen_add_to_stack_pointer(-16),d=f(e,t.__wbindgen_export,t.__wbindgen_export2),w=c,p=f(n,t.__wbindgen_export,t.__wbindgen_export2),b=c;t.caldrixweb_startChat(s,this.__wbg_ptr,d,w,p,b);var _=i().getInt32(s+0,!0),r=i().getInt32(s+4,!0),o=i().getInt32(s+8,!0);if(o)throw g(r);return _>>>0}finally{t.__wbindgen_add_to_stack_pointer(16)}}startCompleteSplit(e,n,_){try{const u=t.__wbindgen_add_to_stack_pointer(-16);var r=v(e)?0:f(e,t.__wbindgen_export,t.__wbindgen_export2),o=c,s=v(n)?0:nt(n,t.__wbindgen_export),d=c;const y=f(_,t.__wbindgen_export,t.__wbindgen_export2),I=c;t.caldrixweb_startCompleteSplit(u,this.__wbg_ptr,r,o,s,d,y,I);var w=i().getInt32(u+0,!0),p=i().getInt32(u+4,!0),b=i().getInt32(u+8,!0);if(b)throw g(p);return g(w)}finally{t.__wbindgen_add_to_stack_pointer(16)}}startComplete(e,n,_){try{const u=t.__wbindgen_add_to_stack_pointer(-16);var r=v(e)?0:f(e,t.__wbindgen_export,t.__wbindgen_export2),o=c,s=v(n)?0:nt(n,t.__wbindgen_export),d=c;const y=f(_,t.__wbindgen_export,t.__wbindgen_export2),I=c;t.caldrixweb_startComplete(u,this.__wbg_ptr,r,o,s,d,y,I);var w=i().getInt32(u+0,!0),p=i().getInt32(u+4,!0),b=i().getInt32(u+8,!0);if(b)throw g(p);return w>>>0}finally{t.__wbindgen_add_to_stack_pointer(16)}}vocab(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_vocab(r,this.__wbg_ptr);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return e>>>0}finally{t.__wbindgen_add_to_stack_pointer(16)}}static weightFiles(e){try{const d=t.__wbindgen_add_to_stack_pointer(-16);var n=v(e)?0:l(e,t.__wbindgen_export),_=c;t.caldrixweb_weightFiles(d,n,_);var r=i().getInt32(d+0,!0),o=i().getInt32(d+4,!0),s=i().getInt32(d+8,!0);if(s)throw g(o);return g(r)}finally{t.__wbindgen_add_to_stack_pointer(16)}}writeLogits(e){try{const r=t.__wbindgen_add_to_stack_pointer(-16),o=l(e,t.__wbindgen_export),s=c;t.caldrixweb_writeLogits(r,this.__wbg_ptr,o,s);var n=i().getInt32(r+0,!0),_=i().getInt32(r+4,!0);if(_)throw g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}}Symbol.dispose&&(Q.prototype[Symbol.dispose]=Q.prototype.free);function Z(){return{__proto__:null,"./caldrix_web_bg.js":{__proto__:null,__wbg___wbindgen_memory_caa4a6165639c8b5:function(){const e=t.memory;return h(e)},__wbg___wbindgen_number_get_2e0e7dee9f701a71:function(e,n){const _=x(n),r=typeof _=="number"?_:void 0;i().setFloat64(e+8,v(r)?0:r,!0),i().setInt32(e+0,!v(r),!0)},__wbg___wbindgen_string_get_0380ccaa2f57f0d9:function(e,n){const _=x(n),r=typeof _=="string"?_:void 0;var o=v(r)?0:f(r,t.__wbindgen_export,t.__wbindgen_export2),s=c;i().setInt32(e+4,s,!0),i().setInt32(e+0,o,!0)},__wbg___wbindgen_throw_41e9ee4f547fc59a:function(e,n){throw new Error(L(e,n))},__wbg_call_1875a20c43a36133:function(){return D(function(e,n,_,r){const o=x(e).call(x(n),x(_),x(r));return h(o)},arguments)},__wbg_call_187d372bd5fdd4aa:function(){return D(function(e,n,_){const r=x(e).call(x(n),x(_));return h(r)},arguments)},__wbg_getRandomValues_a608c4436c19407a:function(){return D(function(e,n){globalThis.crypto.getRandomValues(J(e,n))},arguments)},__wbg_get_unchecked_288889d017702237:function(e,n){const _=x(e)[n>>>0];return h(_)},__wbg_instanceof_Error_80a725f81f2e102d:function(e){let n;try{n=x(e)instanceof Error}catch{n=!1}return n},__wbg_instanceof_Uint8Array_828cef2aaacafc31:function(e){let n;try{n=x(e)instanceof Uint8Array}catch{n=!1}return n},__wbg_length_7f3c00c40364105e:function(e){return x(e).length},__wbg_length_d4bdea10311bd9cf:function(e){return x(e).length},__wbg_message_5f8387f0c32b90a7:function(e){const n=x(e).message;return h(n)},__wbg_new_617a8cdb8bb1130e:function(){const e=new Object;return h(e)},__wbg_new_ee2291f50781bf1d:function(){const e=new Array;return h(e)},__wbg_new_from_slice_37a3c3a194266cb8:function(e,n){const _=new Uint32Array(it(e,n));return h(_)},__wbg_new_from_slice_9a868026ffa4208a:function(e,n){const _=new Uint8Array(J(e,n));return h(_)},__wbg_prototypesetcall_bc27214492979395:function(e,n,_){Uint8Array.prototype.set.call(J(e,n),x(_))},__wbg_push_2baf45db356cf468:function(e,n){return x(e).push(x(n))},__wbg_set_145a351398b48c65:function(){return D(function(e,n,_){return Reflect.set(x(e),x(n),x(_))},arguments)},__wbindgen_generic_0000000000000001:function(e){return h(e)},__wbindgen_generic_0000000000000002:function(e,n){const _=L(e,n);return h(_)},__wbindgen_object_drop_ref:function(e){g(e)}}}}const tt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(a=>t.__wbg_caldrixweb_free(a,1));function h(a){B===R.length&&R.push(R.length+1);const e=B;return B=R[e],R[e]=a,e}function _t(a){a<1028||(R[a]=B,B=a)}function it(a,e){return a=a>>>0,et().subarray(a/4,a/4+e)}function J(a,e){return a=a>>>0,M().subarray(a/1,a/1+e)}let S=null;function i(){return(S===null||S.buffer.detached===!0||S.buffer.detached===void 0&&S.buffer!==t.memory.buffer)&&(S=new DataView(t.memory.buffer)),S}function L(a,e){return ot(a>>>0,e)}let j=null;function et(){return(j===null||j.byteLength===0)&&(j=new Uint32Array(t.memory.buffer)),j}let E=null;function M(){return(E===null||E.byteLength===0)&&(E=new Uint8Array(t.memory.buffer)),E}function x(a){return R[a]}function D(a,e){try{return a.apply(this,e)}catch(n){t.__wbindgen_export3(h(n))}}let R=new Array(1024).fill(void 0);R.push(void 0,null,!0,!1);let B=R.length;function v(a){return a==null}function nt(a,e){const n=e(a.length*4,4)>>>0;return et().set(a,n/4),c=a.length,n}function l(a,e){const n=e(a.length*1,1)>>>0;return M().set(a,n/1),c=a.length,n}function f(a,e,n){if(n===void 0){const d=G.encode(a),w=e(d.length,1)>>>0;return M().subarray(w,w+d.length).set(d),c=d.length,w}let _=a.length,r=e(_,1)>>>0;const o=M();let s=0;for(;s<_;s++){const d=a.charCodeAt(s);if(d>127)break;o[r+s]=d}if(s!==_){s!==0&&(a=a.slice(s)),r=n(r,_,_=s+a.length*3,1)>>>0;const d=M().subarray(r+s,r+_),w=G.encodeInto(a,d);s+=w.written,r=n(r,_,s,1)>>>0}return c=s,r}function g(a){const e=x(a);return _t(a),e}let N=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});N.decode();const at=2146435072;let K=0;function ot(a,e){return K+=e,K>=at&&(N=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),N.decode(),K=e),N.decode(M().subarray(a,a+e))}const G=new TextEncoder;"encodeInto"in G||(G.encodeInto=function(a,e){const n=G.encode(a);return e.set(n),{read:a.length,written:n.length}});let c=0,st,ct,t;function rt(a,e){return ct=a,t=a.exports,st=e,S=null,j=null,E=null,t}async function dt(a,e){if(typeof Response=="function"&&a instanceof Response){if(!a.ok)throw new Error(`failed to fetch Wasm: ${a.status} ${a.statusText} fetching '${a.url}'`);if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(a,e)}catch(r){if(n(a.type)&&a.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",r);else throw r}const _=await a.arrayBuffer();return await WebAssembly.instantiate(_,e)}else{const _=await WebAssembly.instantiate(a,e);return _ instanceof WebAssembly.Instance?{instance:_,module:a}:_}function n(_){switch(_){case"basic":case"cors":case"default":return!0}return!1}}function gt(a){if(t!==void 0)return t;a!==void 0&&(Object.getPrototypeOf(a)===Object.prototype?{module:a}=a:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));const e=Z();a instanceof WebAssembly.Module||(a=new WebAssembly.Module(a));const n=new WebAssembly.Instance(a,e);return rt(n,a)}async function wt(a){if(t!==void 0)return t;a!==void 0&&(Object.getPrototypeOf(a)===Object.prototype?{module_or_path:a}=a:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),a===void 0&&(a=new URL("caldrix_web_bg.wasm",import.meta.url));const e=Z();(typeof a=="string"||typeof Request=="function"&&a instanceof Request||typeof URL=="function"&&a instanceof URL)&&(a=fetch(a));const{instance:n,module:_}=await dt(await a,e);return rt(n,_)}export{Q as CaldrixWeb,wt as default,gt as initSync};
|
|
1
|
+
class nt{__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,_t.unregister(this),e}free(){const e=this.__destroy_into_raw();t.__wbg_caldrixweb_free(e,0)}abort(){t.caldrixweb_abort(this.__wbg_ptr)}actIn(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_actIn(s,this.__wbg_ptr,e);var n=i().getInt32(s+0,!0),_=i().getInt32(s+4,!0),r=i().getInt32(s+8,!0);if(r)throw g(_);return g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}static adapterBase(e,n){let _,r;try{const l=t.__wbindgen_add_to_stack_pointer(-16),y=u(e,t.__wbindgen_export),I=c,k=f(n,t.__wbindgen_export,t.__wbindgen_export2),m=c;t.caldrixweb_adapterBase(l,y,I,k,m);var s=i().getInt32(l+0,!0),o=i().getInt32(l+4,!0),d=i().getInt32(l+8,!0),b=i().getInt32(l+12,!0),p=s,w=o;if(b)throw p=0,w=0,g(d);return _=p,r=w,G(p,w)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_export4(_,r,1)}}argsPtr(){return t.caldrixweb_argsPtr(this.__wbg_ptr)>>>0}attach(e,n){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_attach(s,this.__wbg_ptr,h(e),h(n));var _=i().getInt32(s+0,!0),r=i().getInt32(s+4,!0);if(r)throw g(_)}finally{t.__wbindgen_add_to_stack_pointer(16)}}beginNext(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_beginNext(r,this.__wbg_ptr);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return g(e)}finally{t.__wbindgen_add_to_stack_pointer(16)}}bufferBytes(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_bufferBytes(s,this.__wbg_ptr,e);var n=i().getInt32(s+0,!0),_=i().getInt32(s+4,!0),r=i().getInt32(s+8,!0);if(r)throw g(_);return g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}checkTokenizer(e,n,_,r,s,o,d){try{const R=t.__wbindgen_add_to_stack_pointer(-16),C=u(e,t.__wbindgen_export),L=c,O=f(n,t.__wbindgen_export,t.__wbindgen_export2),U=c,E=u(_,t.__wbindgen_export),j=c;var b=v(r)?0:u(r,t.__wbindgen_export),p=c,w=v(s)?0:u(s,t.__wbindgen_export),l=c,y=v(o)?0:u(o,t.__wbindgen_export),I=c,k=v(d)?0:u(d,t.__wbindgen_export),m=c;t.caldrixweb_checkTokenizer(R,this.__wbg_ptr,C,L,O,U,E,j,b,p,w,l,y,I,k,m);var A=i().getInt32(R+0,!0),T=i().getInt32(R+4,!0);if(T)throw g(A)}finally{t.__wbindgen_add_to_stack_pointer(16)}}dispose(){t.caldrixweb_dispose(this.__wbg_ptr)}doctor(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_doctor(r,this.__wbg_ptr);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return g(e)}finally{t.__wbindgen_add_to_stack_pointer(16)}}encode(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16),o=f(e,t.__wbindgen_export,t.__wbindgen_export2),d=c;t.caldrixweb_encode(s,this.__wbg_ptr,o,d);var n=i().getInt32(s+0,!0),_=i().getInt32(s+4,!0),r=i().getInt32(s+8,!0);if(r)throw g(_);return g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}failLaunch(e){try{const r=t.__wbindgen_add_to_stack_pointer(-16),s=f(e,t.__wbindgen_export,t.__wbindgen_export2),o=c;t.caldrixweb_failLaunch(r,this.__wbg_ptr,s,o);var n=i().getInt32(r+0,!0),_=i().getInt32(r+4,!0);if(_)throw g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}finishNext(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_finishNext(r,this.__wbg_ptr);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return g(e)}finally{t.__wbindgen_add_to_stack_pointer(16)}}finishStart(){try{const _=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_finishStart(_,this.__wbg_ptr);var e=i().getInt32(_+0,!0),n=i().getInt32(_+4,!0);if(n)throw g(e)}finally{t.__wbindgen_add_to_stack_pointer(16)}}static ggufHeaderFirstRange(){return t.caldrixweb_ggufHeaderFirstRange()}static ggufHeaderNeed(e,n){try{const o=t.__wbindgen_add_to_stack_pointer(-16),d=u(e,t.__wbindgen_export),b=c;t.caldrixweb_ggufHeaderNeed(o,d,b,n);var _=i().getFloat64(o+0,!0),r=i().getInt32(o+8,!0),s=i().getInt32(o+12,!0);if(s)throw g(r);return _}finally{t.__wbindgen_add_to_stack_pointer(16)}}static ggufRopeFreqsExtent(e,n){try{const d=t.__wbindgen_add_to_stack_pointer(-16),b=u(e,t.__wbindgen_export),p=c;t.caldrixweb_ggufRopeFreqsExtent(d,b,p,n);var _=i().getInt32(d+0,!0),r=i().getInt32(d+4,!0),s=i().getInt32(d+8,!0),o=i().getInt32(d+12,!0);if(o)throw g(s);let w;return _!==0&&(w=ct(_,r).slice(),t.__wbindgen_export4(_,r*8,8)),w}finally{t.__wbindgen_add_to_stack_pointer(16)}}static listAliases(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_listAliases(r);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return g(e)}finally{t.__wbindgen_add_to_stack_pointer(16)}}static listingCap(){return t.caldrixweb_listingCap()}loadGguf(e,n){try{const o=t.__wbindgen_add_to_stack_pointer(-16),d=u(e,t.__wbindgen_export),b=c,p=f(n,t.__wbindgen_export,t.__wbindgen_export2),w=c;t.caldrixweb_loadGguf(o,this.__wbg_ptr,d,b,p,w);var _=i().getInt32(o+0,!0),r=i().getInt32(o+4,!0),s=i().getInt32(o+8,!0);if(s)throw g(r);return g(_)}finally{t.__wbindgen_add_to_stack_pointer(16)}}loadWebGpuGguf(e,n){try{const o=t.__wbindgen_add_to_stack_pointer(-16),d=u(e,t.__wbindgen_export),b=c,p=f(n,t.__wbindgen_export,t.__wbindgen_export2),w=c;t.caldrixweb_loadWebGpuGguf(o,this.__wbg_ptr,d,b,p,w);var _=i().getInt32(o+0,!0),r=i().getInt32(o+4,!0),s=i().getInt32(o+8,!0);if(s)throw g(r);return g(_)}finally{t.__wbindgen_add_to_stack_pointer(16)}}loadWebGpu(e,n,_,r,s,o,d,b,p,w,l){try{const W=t.__wbindgen_add_to_stack_pointer(-16),q=u(e,t.__wbindgen_export),$=c,X=f(n,t.__wbindgen_export,t.__wbindgen_export2),Y=c,J=u(_,t.__wbindgen_export),K=c;var y=v(r)?0:u(r,t.__wbindgen_export),I=c,k=v(s)?0:u(s,t.__wbindgen_export),m=c,A=v(o)?0:u(o,t.__wbindgen_export),T=c,R=v(d)?0:u(d,t.__wbindgen_export),C=c;const Q=f(p,t.__wbindgen_export,t.__wbindgen_export2),Z=c;var L=v(w)?0:u(w,t.__wbindgen_export),O=c;t.caldrixweb_loadWebGpu(W,this.__wbg_ptr,q,$,X,Y,J,K,y,I,k,m,A,T,R,C,h(b),Q,Z,L,O,v(l)?0:h(l));var U=i().getInt32(W+0,!0),E=i().getInt32(W+4,!0),j=i().getInt32(W+8,!0);if(j)throw g(E);return g(U)}finally{t.__wbindgen_add_to_stack_pointer(16)}}load(e,n,_,r,s,o,d,b,p,w,l){try{const W=t.__wbindgen_add_to_stack_pointer(-16),q=u(e,t.__wbindgen_export),$=c,X=f(n,t.__wbindgen_export,t.__wbindgen_export2),Y=c,J=u(_,t.__wbindgen_export),K=c;var y=v(r)?0:u(r,t.__wbindgen_export),I=c,k=v(s)?0:u(s,t.__wbindgen_export),m=c,A=v(o)?0:u(o,t.__wbindgen_export),T=c,R=v(d)?0:u(d,t.__wbindgen_export),C=c;const Q=f(p,t.__wbindgen_export,t.__wbindgen_export2),Z=c;var L=v(w)?0:u(w,t.__wbindgen_export),O=c;t.caldrixweb_load(W,this.__wbg_ptr,q,$,X,Y,J,K,y,I,k,m,A,T,R,C,h(b),Q,Z,L,O,v(l)?0:h(l));var U=i().getInt32(W+0,!0),E=i().getInt32(W+4,!0),j=i().getInt32(W+8,!0);if(j)throw g(E);return g(U)}finally{t.__wbindgen_add_to_stack_pointer(16)}}logitsPtr(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_logitsPtr(r,this.__wbg_ptr);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return e>>>0}finally{t.__wbindgen_add_to_stack_pointer(16)}}static memory(){const e=t.caldrixweb_memory();return g(e)}constructor(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16),o=f(e,t.__wbindgen_export,t.__wbindgen_export2),d=c;t.caldrixweb_new(s,o,d);var n=i().getInt32(s+0,!0),_=i().getInt32(s+4,!0),r=i().getInt32(s+8,!0);if(r)throw g(_);return this.__wbg_ptr=n,_t.register(this,this.__wbg_ptr,this),this}finally{t.__wbindgen_add_to_stack_pointer(16)}}next(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_next(r,this.__wbg_ptr);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return g(e)}finally{t.__wbindgen_add_to_stack_pointer(16)}}static parseBaseListing(e,n,_){let r,s;try{const y=t.__wbindgen_add_to_stack_pointer(-16),I=u(e,t.__wbindgen_export),k=c,m=f(n,t.__wbindgen_export,t.__wbindgen_export2),A=c;t.caldrixweb_parseBaseListing(y,I,k,m,A,_);var o=i().getInt32(y+0,!0),d=i().getInt32(y+4,!0),b=i().getInt32(y+8,!0),p=i().getInt32(y+12,!0),w=o,l=d;if(p)throw w=0,l=0,g(b);return r=w,s=l,G(w,l)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_export4(r,s,1)}}static parseListing(e){let n,_;try{const w=t.__wbindgen_add_to_stack_pointer(-16),l=u(e,t.__wbindgen_export),y=c;t.caldrixweb_parseListing(w,l,y);var r=i().getInt32(w+0,!0),s=i().getInt32(w+4,!0),o=i().getInt32(w+8,!0),d=i().getInt32(w+12,!0),b=r,p=s;if(d)throw b=0,p=0,g(o);return n=b,_=p,G(b,p)}finally{t.__wbindgen_add_to_stack_pointer(16),t.__wbindgen_export4(n,_,1)}}precheckFacts(e,n){try{const o=t.__wbindgen_add_to_stack_pointer(-16),d=f(e,t.__wbindgen_export,t.__wbindgen_export2),b=c,p=f(n,t.__wbindgen_export,t.__wbindgen_export2),w=c;t.caldrixweb_precheckFacts(o,this.__wbg_ptr,d,b,p,w);var _=i().getInt32(o+0,!0),r=i().getInt32(o+4,!0),s=i().getInt32(o+8,!0);if(s)throw g(r);return g(_)}finally{t.__wbindgen_add_to_stack_pointer(16)}}precheckGguf(e,n,_,r){try{const w=t.__wbindgen_add_to_stack_pointer(-16),l=u(e,t.__wbindgen_export),y=c,I=f(_,t.__wbindgen_export,t.__wbindgen_export2),k=c;var s=v(r)?0:u(r,t.__wbindgen_export),o=c;t.caldrixweb_precheckGguf(w,this.__wbg_ptr,l,y,n,I,k,s,o);var d=i().getInt32(w+0,!0),b=i().getInt32(w+4,!0),p=i().getInt32(w+8,!0);if(p)throw g(b);return g(d)}finally{t.__wbindgen_add_to_stack_pointer(16)}}precheck(e,n,_,r){try{const y=t.__wbindgen_add_to_stack_pointer(-16),I=u(e,t.__wbindgen_export),k=c;var s=v(n)?0:u(n,t.__wbindgen_export),o=c;const m=f(_,t.__wbindgen_export,t.__wbindgen_export2),A=c;var d=v(r)?0:u(r,t.__wbindgen_export),b=c;t.caldrixweb_precheck(y,this.__wbg_ptr,I,k,s,o,m,A,d,b);var p=i().getInt32(y+0,!0),w=i().getInt32(y+4,!0),l=i().getInt32(y+8,!0);if(l)throw g(w);return g(p)}finally{t.__wbindgen_add_to_stack_pointer(16)}}static resolveAlias(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16),o=f(e,t.__wbindgen_export,t.__wbindgen_export2),d=c;t.caldrixweb_resolveAlias(s,o,d);var n=i().getInt32(s+0,!0),_=i().getInt32(s+4,!0),r=i().getInt32(s+8,!0);if(r)throw g(_);return g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}static resolveModel(e){try{const s=t.__wbindgen_add_to_stack_pointer(-16),o=f(e,t.__wbindgen_export,t.__wbindgen_export2),d=c;t.caldrixweb_resolveModel(s,o,d);var n=i().getInt32(s+0,!0),_=i().getInt32(s+4,!0),r=i().getInt32(s+8,!0);if(r)throw g(_);return g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}resolve(e,n){try{const o=t.__wbindgen_add_to_stack_pointer(-16),d=f(e,t.__wbindgen_export,t.__wbindgen_export2),b=c;t.caldrixweb_resolve(o,this.__wbg_ptr,d,b,n);var _=i().getInt32(o+0,!0),r=i().getInt32(o+4,!0),s=i().getInt32(o+8,!0);if(s)throw g(r);return g(_)}finally{t.__wbindgen_add_to_stack_pointer(16)}}startChatSplit(e,n){try{const o=t.__wbindgen_add_to_stack_pointer(-16),d=f(e,t.__wbindgen_export,t.__wbindgen_export2),b=c,p=f(n,t.__wbindgen_export,t.__wbindgen_export2),w=c;t.caldrixweb_startChatSplit(o,this.__wbg_ptr,d,b,p,w);var _=i().getInt32(o+0,!0),r=i().getInt32(o+4,!0),s=i().getInt32(o+8,!0);if(s)throw g(r);return g(_)}finally{t.__wbindgen_add_to_stack_pointer(16)}}startChat(e,n){try{const o=t.__wbindgen_add_to_stack_pointer(-16),d=f(e,t.__wbindgen_export,t.__wbindgen_export2),b=c,p=f(n,t.__wbindgen_export,t.__wbindgen_export2),w=c;t.caldrixweb_startChat(o,this.__wbg_ptr,d,b,p,w);var _=i().getInt32(o+0,!0),r=i().getInt32(o+4,!0),s=i().getInt32(o+8,!0);if(s)throw g(r);return _>>>0}finally{t.__wbindgen_add_to_stack_pointer(16)}}startCompleteSplit(e,n,_){try{const l=t.__wbindgen_add_to_stack_pointer(-16);var r=v(e)?0:f(e,t.__wbindgen_export,t.__wbindgen_export2),s=c,o=v(n)?0:at(n,t.__wbindgen_export),d=c;const y=f(_,t.__wbindgen_export,t.__wbindgen_export2),I=c;t.caldrixweb_startCompleteSplit(l,this.__wbg_ptr,r,s,o,d,y,I);var b=i().getInt32(l+0,!0),p=i().getInt32(l+4,!0),w=i().getInt32(l+8,!0);if(w)throw g(p);return g(b)}finally{t.__wbindgen_add_to_stack_pointer(16)}}startComplete(e,n,_){try{const l=t.__wbindgen_add_to_stack_pointer(-16);var r=v(e)?0:f(e,t.__wbindgen_export,t.__wbindgen_export2),s=c,o=v(n)?0:at(n,t.__wbindgen_export),d=c;const y=f(_,t.__wbindgen_export,t.__wbindgen_export2),I=c;t.caldrixweb_startComplete(l,this.__wbg_ptr,r,s,o,d,y,I);var b=i().getInt32(l+0,!0),p=i().getInt32(l+4,!0),w=i().getInt32(l+8,!0);if(w)throw g(p);return b>>>0}finally{t.__wbindgen_add_to_stack_pointer(16)}}vocab(){try{const r=t.__wbindgen_add_to_stack_pointer(-16);t.caldrixweb_vocab(r,this.__wbg_ptr);var e=i().getInt32(r+0,!0),n=i().getInt32(r+4,!0),_=i().getInt32(r+8,!0);if(_)throw g(n);return e>>>0}finally{t.__wbindgen_add_to_stack_pointer(16)}}static weightFiles(e){try{const d=t.__wbindgen_add_to_stack_pointer(-16);var n=v(e)?0:u(e,t.__wbindgen_export),_=c;t.caldrixweb_weightFiles(d,n,_);var r=i().getInt32(d+0,!0),s=i().getInt32(d+4,!0),o=i().getInt32(d+8,!0);if(o)throw g(s);return g(r)}finally{t.__wbindgen_add_to_stack_pointer(16)}}writeLogits(e){try{const r=t.__wbindgen_add_to_stack_pointer(-16),s=u(e,t.__wbindgen_export),o=c;t.caldrixweb_writeLogits(r,this.__wbg_ptr,s,o);var n=i().getInt32(r+0,!0),_=i().getInt32(r+4,!0);if(_)throw g(n)}finally{t.__wbindgen_add_to_stack_pointer(16)}}}Symbol.dispose&&(nt.prototype[Symbol.dispose]=nt.prototype.free);function rt(){return{__proto__:null,"./caldrix_web_bg.js":{__proto__:null,__wbg___wbindgen_memory_caa4a6165639c8b5:function(){const e=t.memory;return h(e)},__wbg___wbindgen_number_get_2e0e7dee9f701a71:function(e,n){const _=x(n),r=typeof _=="number"?_:void 0;i().setFloat64(e+8,v(r)?0:r,!0),i().setInt32(e+0,!v(r),!0)},__wbg___wbindgen_string_get_0380ccaa2f57f0d9:function(e,n){const _=x(n),r=typeof _=="string"?_:void 0;var s=v(r)?0:f(r,t.__wbindgen_export,t.__wbindgen_export2),o=c;i().setInt32(e+4,o,!0),i().setInt32(e+0,s,!0)},__wbg___wbindgen_throw_41e9ee4f547fc59a:function(e,n){throw new Error(G(e,n))},__wbg_call_1875a20c43a36133:function(){return H(function(e,n,_,r){const s=x(e).call(x(n),x(_),x(r));return h(s)},arguments)},__wbg_call_187d372bd5fdd4aa:function(){return H(function(e,n,_){const r=x(e).call(x(n),x(_));return h(r)},arguments)},__wbg_getRandomValues_a608c4436c19407a:function(){return H(function(e,n){globalThis.crypto.getRandomValues(tt(e,n))},arguments)},__wbg_get_unchecked_288889d017702237:function(e,n){const _=x(e)[n>>>0];return h(_)},__wbg_instanceof_Error_80a725f81f2e102d:function(e){let n;try{n=x(e)instanceof Error}catch{n=!1}return n},__wbg_instanceof_Uint8Array_828cef2aaacafc31:function(e){let n;try{n=x(e)instanceof Uint8Array}catch{n=!1}return n},__wbg_length_7f3c00c40364105e:function(e){return x(e).length},__wbg_length_d4bdea10311bd9cf:function(e){return x(e).length},__wbg_message_5f8387f0c32b90a7:function(e){const n=x(e).message;return h(n)},__wbg_new_617a8cdb8bb1130e:function(){const e=new Object;return h(e)},__wbg_new_ee2291f50781bf1d:function(){const e=new Array;return h(e)},__wbg_new_from_slice_37a3c3a194266cb8:function(e,n){const _=new Uint32Array(dt(e,n));return h(_)},__wbg_new_from_slice_9a868026ffa4208a:function(e,n){const _=new Uint8Array(tt(e,n));return h(_)},__wbg_prototypesetcall_bc27214492979395:function(e,n,_){Uint8Array.prototype.set.call(tt(e,n),x(_))},__wbg_push_2baf45db356cf468:function(e,n){return x(e).push(x(n))},__wbg_set_145a351398b48c65:function(){return H(function(e,n,_){return Reflect.set(x(e),x(n),x(_))},arguments)},__wbindgen_generic_0000000000000001:function(e){return h(e)},__wbindgen_generic_0000000000000002:function(e,n){const _=G(e,n);return h(_)},__wbindgen_object_drop_ref:function(e){g(e)}}}}const _t=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(a=>t.__wbg_caldrixweb_free(a,1));function h(a){P===F.length&&F.push(F.length+1);const e=P;return P=F[e],F[e]=a,e}function st(a){a<1028||(F[a]=P,P=a)}function ct(a,e){return a=a>>>0,gt().subarray(a/8,a/8+e)}function dt(a,e){return a=a>>>0,it().subarray(a/4,a/4+e)}function tt(a,e){return a=a>>>0,S().subarray(a/1,a/1+e)}let M=null;function i(){return(M===null||M.buffer.detached===!0||M.buffer.detached===void 0&&M.buffer!==t.memory.buffer)&&(M=new DataView(t.memory.buffer)),M}let B=null;function gt(){return(B===null||B.byteLength===0)&&(B=new Float64Array(t.memory.buffer)),B}function G(a,e){return bt(a>>>0,e)}let D=null;function it(){return(D===null||D.byteLength===0)&&(D=new Uint32Array(t.memory.buffer)),D}let N=null;function S(){return(N===null||N.byteLength===0)&&(N=new Uint8Array(t.memory.buffer)),N}function x(a){return F[a]}function H(a,e){try{return a.apply(this,e)}catch(n){t.__wbindgen_export3(h(n))}}let F=new Array(1024).fill(void 0);F.push(void 0,null,!0,!1);let P=F.length;function v(a){return a==null}function at(a,e){const n=e(a.length*4,4)>>>0;return it().set(a,n/4),c=a.length,n}function u(a,e){const n=e(a.length*1,1)>>>0;return S().set(a,n/1),c=a.length,n}function f(a,e,n){if(n===void 0){const d=V.encode(a),b=e(d.length,1)>>>0;return S().subarray(b,b+d.length).set(d),c=d.length,b}let _=a.length,r=e(_,1)>>>0;const s=S();let o=0;for(;o<_;o++){const d=a.charCodeAt(o);if(d>127)break;s[r+o]=d}if(o!==_){o!==0&&(a=a.slice(o)),r=n(r,_,_=o+a.length*3,1)>>>0;const d=S().subarray(r+o,r+_),b=V.encodeInto(a,d);o+=b.written,r=n(r,_,o,1)>>>0}return c=o,r}function g(a){const e=x(a);return st(a),e}let z=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});z.decode();const wt=2146435072;let et=0;function bt(a,e){return et+=e,et>=wt&&(z=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),z.decode(),et=e),z.decode(S().subarray(a,a+e))}const V=new TextEncoder;"encodeInto"in V||(V.encodeInto=function(a,e){const n=V.encode(a);return e.set(n),{read:a.length,written:n.length}});let c=0,pt,ut,t;function ot(a,e){return ut=a,t=a.exports,pt=e,M=null,B=null,D=null,N=null,t}async function lt(a,e){if(typeof Response=="function"&&a instanceof Response){if(!a.ok)throw new Error(`failed to fetch Wasm: ${a.status} ${a.statusText} fetching '${a.url}'`);if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(a,e)}catch(r){if(n(a.type)&&a.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",r);else throw r}const _=await a.arrayBuffer();return await WebAssembly.instantiate(_,e)}else{const _=await WebAssembly.instantiate(a,e);return _ instanceof WebAssembly.Instance?{instance:_,module:a}:_}function n(_){switch(_){case"basic":case"cors":case"default":return!0}return!1}}function ft(a){if(t!==void 0)return t;a!==void 0&&(Object.getPrototypeOf(a)===Object.prototype?{module:a}=a:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));const e=rt();a instanceof WebAssembly.Module||(a=new WebAssembly.Module(a));const n=new WebAssembly.Instance(a,e);return ot(n,a)}async function vt(a){if(t!==void 0)return t;a!==void 0&&(Object.getPrototypeOf(a)===Object.prototype?{module_or_path:a}=a:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),a===void 0&&(a=new URL("caldrix_web_bg.wasm",import.meta.url));const e=rt();(typeof a=="string"||typeof Request=="function"&&a instanceof Request||typeof URL=="function"&&a instanceof URL)&&(a=fetch(a));const{instance:n,module:_}=await lt(await a,e);return ot(n,_)}export{nt as CaldrixWeb,vt as default,ft as initSync};
|
package/host/caldrix_web_bg.wasm
CHANGED
|
Binary file
|
|
@@ -9,7 +9,7 @@ export const caldrixweb_argsPtr: (a: number) => number;
|
|
|
9
9
|
export const caldrixweb_attach: (a: number, b: number, c: number, d: number) => void;
|
|
10
10
|
export const caldrixweb_beginNext: (a: number, b: number) => void;
|
|
11
11
|
export const caldrixweb_bufferBytes: (a: number, b: number, c: number) => void;
|
|
12
|
-
export const caldrixweb_checkTokenizer: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number) => void;
|
|
12
|
+
export const caldrixweb_checkTokenizer: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number) => void;
|
|
13
13
|
export const caldrixweb_dispose: (a: number) => void;
|
|
14
14
|
export const caldrixweb_doctor: (a: number, b: number) => void;
|
|
15
15
|
export const caldrixweb_encode: (a: number, b: number, c: number, d: number) => void;
|
|
@@ -18,11 +18,12 @@ export const caldrixweb_finishNext: (a: number, b: number) => void;
|
|
|
18
18
|
export const caldrixweb_finishStart: (a: number, b: number) => void;
|
|
19
19
|
export const caldrixweb_ggufHeaderFirstRange: () => number;
|
|
20
20
|
export const caldrixweb_ggufHeaderNeed: (a: number, b: number, c: number, d: number) => void;
|
|
21
|
+
export const caldrixweb_ggufRopeFreqsExtent: (a: number, b: number, c: number, d: number) => void;
|
|
21
22
|
export const caldrixweb_listAliases: (a: number) => void;
|
|
22
23
|
export const caldrixweb_listingCap: () => number;
|
|
23
|
-
export const caldrixweb_load: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number) => void;
|
|
24
|
+
export const caldrixweb_load: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number, u: number, v: number) => void;
|
|
24
25
|
export const caldrixweb_loadGguf: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
25
|
-
export const caldrixweb_loadWebGpu: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number) => void;
|
|
26
|
+
export const caldrixweb_loadWebGpu: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number, u: number, v: number) => void;
|
|
26
27
|
export const caldrixweb_loadWebGpuGguf: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
27
28
|
export const caldrixweb_logitsPtr: (a: number, b: number) => void;
|
|
28
29
|
export const caldrixweb_memory: () => number;
|
|
@@ -31,7 +32,8 @@ export const caldrixweb_next: (a: number, b: number) => void;
|
|
|
31
32
|
export const caldrixweb_parseBaseListing: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
32
33
|
export const caldrixweb_parseListing: (a: number, b: number, c: number) => void;
|
|
33
34
|
export const caldrixweb_precheck: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
|
|
34
|
-
export const
|
|
35
|
+
export const caldrixweb_precheckFacts: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
36
|
+
export const caldrixweb_precheckGguf: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
35
37
|
export const caldrixweb_resolve: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
36
38
|
export const caldrixweb_resolveAlias: (a: number, b: number, c: number) => void;
|
|
37
39
|
export const caldrixweb_resolveModel: (a: number, b: number, c: number) => void;
|
package/package.json
CHANGED