llama-web-bridge 0.0.0-stage → 0.1.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Jhin Lee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,208 @@
1
- # Temporary Holding Version
1
+ # llama-web-bridge
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Reusable llama.cpp web bridge runtime (JS + WASM).
4
+
5
+ This repository provides:
6
+
7
+ - `src/llama_webgpu_core.cpp` (native bridge core; it includes its parts from
8
+ `src/core/`)
9
+ - `js/src/llama_webgpu_bridge.js` (JS runtime wrapper entry; its modules live
10
+ under `js/src/`)
11
+ - `js/llama_webgpu_bridge.js` (generated bundled browser ESM wrapper)
12
+ - `js/llama_webgpu_bridge.d.ts` (public TypeScript declaration asset)
13
+ - `docs/api.md` (public JavaScript API reference)
14
+ - `CMakeLists.txt` for Emscripten builds
15
+
16
+ ## Install via npm
17
+
18
+ ```bash
19
+ npm install llama-web-bridge
20
+ ```
21
+
22
+ ```js
23
+ import { LlamaWebGpuBridge } from 'llama-web-bridge';
24
+
25
+ const bridge = new LlamaWebGpuBridge();
26
+ ```
27
+
28
+ The package entry point includes TypeScript declarations and exports
29
+ `enableBridgeWorkerHost` for custom worker bootstraps. Vite production builds
30
+ and webpack 5 can emit the default worker and core assets alongside your app.
31
+
32
+ Threaded cores need cross-origin isolation. Serve your app with the following
33
+ response headers.
34
+
35
+ ```http
36
+ Cross-Origin-Opener-Policy: same-origin
37
+ Cross-Origin-Embedder-Policy: require-corp
38
+ ```
39
+
40
+ If the page cannot be isolated, construct the bridge with
41
+ `{ allowSingleThreadCore: true }` to select the single-thread variants. They
42
+ use one CPU thread and can still offload layers to WebGPU. If you use CSP,
43
+ allow `'self'`, `blob:`, and the asset origin in `worker-src`. See
44
+ [deployment requirements](docs/api.md#browser-and-asset-requirements) for
45
+ cross-origin assets and the other CSP directives.
46
+
47
+ ### Bundler configuration
48
+
49
+ In Vite 7 dev, add this setting to `vite.config.ts` so the bridge module stays
50
+ beside its worker and core files.
51
+
52
+ ```ts
53
+ export default {
54
+ optimizeDeps: { exclude: ['llama-web-bridge'] },
55
+ };
56
+ ```
57
+
58
+ If your bundler does not emit `new URL(..., import.meta.url)` assets, as with
59
+ standalone esbuild, serve the package's `dist/` runtime files together at a
60
+ static URL. Pass `{ assetBaseUrl: '/webgpu-bridge/' }` if that is where they are
61
+ served. The base can also be an absolute CDN directory URL. Explicit per-file
62
+ URLs take precedence.
63
+
64
+ ### Custom core factory
65
+
66
+ The package exports the worker at `llama-web-bridge/worker` and core factories at
67
+ `llama-web-bridge/core`, `llama-web-bridge/core-mem64`,
68
+ `llama-web-bridge/core-st`, and `llama-web-bridge/core-mem64-st`. Each core
69
+ subpath has a matching `.wasm` subpath. Providing a factory selects the direct
70
+ runtime. Pass the matching Wasm URL explicitly so the factory can find the
71
+ binary even when the bundler renames it.
72
+
73
+ ```js
74
+ import { LlamaWebGpuBridge } from 'llama-web-bridge';
75
+ import createCore from 'llama-web-bridge/core-st';
76
+
77
+ const bridge = new LlamaWebGpuBridge({
78
+ allowSingleThreadCore: true,
79
+ coreModuleFactory: createCore,
80
+ wasmUrl: new URL('llama-web-bridge/core-st.wasm', import.meta.url).href,
81
+ });
82
+ ```
83
+
84
+ ### CDN modules
85
+
86
+ You can import the same package from jsDelivr or unpkg in a browser module.
87
+ Replace `<version>` with a published npm version. The same isolation and CSP
88
+ rules apply.
89
+
90
+ ```html
91
+ <script type="module">
92
+ import { LlamaWebGpuBridge } from 'https://cdn.jsdelivr.net/npm/llama-web-bridge@<version>/dist/llama_webgpu_bridge.js';
93
+
94
+ const bridge = new LlamaWebGpuBridge();
95
+ </script>
96
+ ```
97
+
98
+ ### 0.x compatibility
99
+
100
+ npm versions mirror unsuffixed stable bridge asset tags (`v0.1.X` becomes
101
+ `0.1.X`). During `0.x`, any release may change the JavaScript API. See
102
+ [CHANGELOG.md](CHANGELOG.md) for changes. Strict SemVer starts at `1.0.0`.
103
+
104
+ ## Public API
105
+
106
+ See the [LlamaWebGpuBridge reference](docs/api.md) for model loading, generation,
107
+ embeddings, state persistence, diagnostics, and browser deployment. The
108
+ published browser assets include `llama_webgpu_bridge.d.ts`.
109
+
110
+ ## Build
111
+
112
+ Use Node.js and the Emscripten SDK version listed in the
113
+ [local build guide](CONTRIBUTING.md#local-build). Check out llama.cpp at the tag
114
+ in `llama_cpp.version`.
115
+
116
+ ```bash
117
+ npm ci
118
+ npm run check:js
119
+ ./scripts/build/build_bridge.sh
120
+ ```
121
+
122
+ The default build produces the bridge JS, worker and declarations alongside
123
+ the threaded wasm32 core. Enable memory64 with `WEBGPU_BRIDGE_BUILD_MEM64=1`
124
+ and single-thread cores with `WEBGPU_BRIDGE_BUILD_SINGLE_THREAD=1`. Keep the
125
+ 1 MiB stack default unless real-model smokes qualify a smaller stack. Threaded
126
+ cores cap requested thread counts to their compiled pthread pool. See the
127
+ [build recipe and outputs](CONTRIBUTING.md#validate-outputs) for details.
128
+
129
+ ## Capabilities
130
+
131
+ - **Single-thread cores and JS-backed staging.** Use single-thread cores on
132
+ non-isolated pages. WebKit defaults to JS-backed staging on a supported
133
+ core. On Apple Safari before version 27, the default cap is one GPU layer,
134
+ including on full-offload requests.
135
+ [Staging API](docs/api.md#js-backed-model-staging) ·
136
+ [Browser measurements](docs/single_thread.md)
137
+ - **Multimodal embeddings.** Pool ordered text, image, and audio parts with
138
+ compatible models and projectors. Probe the active runtime with
139
+ `getEmbeddingCapabilities()`.
140
+ [API](docs/api.md#embeddings) · [BF16 CPU results](docs/multimodal_embeddings.md) ·
141
+ [Qualification command](CONTRIBUTING.md#multimodal-embedding-qualification)
142
+ - **State persistence.** Save and restore a session in either runtime. Use
143
+ `stateSaveBytes` and `stateLoadBytes` for durable browser storage.
144
+ [State API](docs/api.md#state-persistence)
145
+ - **Text-to-speech.** Probe Qwen3-TTS support before synthesizing PCM or
146
+ streaming audio chunks. The validated model pair uses memory64.
147
+ [TTS API](docs/api.md#text-to-speech) ·
148
+ [Real-model smoke](scripts/smoke/text_to_speech.mjs)
149
+ - **Decision heads.** Load a compatible head for an encoder and run decision
150
+ sequences. Head handles belong to the active core.
151
+ [Decision API](docs/api.md#decision-heads) · [Smoke](scripts/smoke/decision.mjs)
152
+ - **LoRA adapters.** Load and apply compatible adapters to a loaded model.
153
+ [LoRA API](docs/api.md#lora-adapters) · [Smoke](scripts/smoke/lora_adapter.mjs)
154
+
155
+ ## CI and releases
156
+
157
+ [CI](.github/workflows/ci.yml) checks the pinned llama.cpp commit and builds
158
+ threaded and single-thread cores for wasm32 and memory64. Browser smokes cover
159
+ npm packaging, state persistence, cross-origin assets, shared-core staging,
160
+ resume integrity, core abort recovery and release, remote fetch, multimodal
161
+ completion, grammar, next-token scoring, and tiny speculative decoding.
162
+ [Current pin qualification](docs/v100_qualification.md)
163
+
164
+ ```bash
165
+ npm run check:js
166
+ node scripts/ci/verify_ci_reliability.mjs
167
+ ```
168
+
169
+ The maintainer dispatches the candidate build, hosted qualification, and
170
+ immutable asset publication in order. Asset publication uses the
171
+ `WEBGPU_BRIDGE_ASSETS_PAT` environment secret. The separate
172
+ [`publish_npm.yml`](.github/workflows/publish_npm.yml) workflow stages the exact
173
+ qualified release bytes and publishes using npm Trusted Publishing.
174
+ [CI guardrails](CONTRIBUTING.md#agent-workflow-guardrails) ·
175
+ [Asset publish process](CONTRIBUTING.md#publish-process)
176
+
177
+ ## Published CDN assets
178
+
179
+ Use one pinned [asset release](https://github.com/leehack/llama-web-bridge-assets/releases)
180
+ tag for the bridge, worker, and cores. For CORS, CORP, and CSP on cross-origin
181
+ deployments, see [browser requirements](docs/api.md#browser-and-asset-requirements).
182
+
183
+ - `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@<tag>/llama_webgpu_bridge.js`
184
+ - `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@<tag>/llama_webgpu_bridge_worker.js`
185
+ - `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@<tag>/llama_webgpu_bridge.d.ts`
186
+ - `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@<tag>/llama_webgpu_core.js`
187
+ - `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@<tag>/llama_webgpu_core.wasm`
188
+
189
+ When `WEBGPU_BRIDGE_BUILD_MEM64=1`, the assets repo also publishes optional
190
+ memory64 core artifacts:
191
+
192
+ - `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@<tag>/llama_webgpu_core_mem64.js`
193
+ - `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@<tag>/llama_webgpu_core_mem64.wasm`
194
+
195
+ When `WEBGPU_BRIDGE_BUILD_SINGLE_THREAD=1` (and `WEBGPU_BRIDGE_BUILD_MEM64=1`), the assets repo also publishes single-thread (`_st`) core artifacts:
196
+
197
+ - `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@<tag>/llama_webgpu_core_st.js`
198
+ - `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@<tag>/llama_webgpu_core_st.wasm`
199
+ - `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@<tag>/llama_webgpu_core_mem64_st.js`
200
+ - `https://cdn.jsdelivr.net/gh/leehack/llama-web-bridge-assets@<tag>/llama_webgpu_core_mem64_st.wasm`
201
+
202
+ ## Maintainer docs
203
+
204
+ - [CONTRIBUTING.md](CONTRIBUTING.md) covers build recipes, runnable smokes, CI
205
+ guardrails, and asset publishing.
206
+ - [AGENTS.md](AGENTS.md) covers agent workflow and change boundaries.
207
+ - [API reference](docs/api.md) and [browser measurements](docs/single_thread.md)
208
+ cover integration and runtime behavior.