@ohtaman/washi 0.9.0 → 0.10.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/README.md +9 -10
- package/THIRD_PARTY_LICENSES.md +4 -4
- package/dist/{browser/washi.js → core-b430-tAc.js} +656 -661
- package/dist/solvers/browser-_washi-browser-node-runtime-BOEcR5J2.js +28 -0
- package/dist/solvers/browser-browser-worker-CT6498Is.js +13 -0
- package/dist/{lib/solvers/loader-b5PNpCmX.js → solvers/browser-loader-D21chr4P.js} +12 -23
- package/dist/{lib/solvers/loader-DCtyxsfF.js → solvers/browser-loader-DWFhT0yY.js} +13 -13
- package/dist/solvers/browser-lp-writer-DH_1sdsF.js +115 -0
- package/dist/solvers/glpk.js +310 -0
- package/dist/{lib/solvers/glpk.js → solvers/glpk.node.js} +5 -9
- package/dist/{lib/solvers/__vite-browser-external-oLchLuMx.js → solvers/highs-browser-__vite-browser-external-Cu-Zq4Hm.js} +1 -1
- package/dist/solvers/highs-browser-runtime.js +2410 -0
- package/dist/{lib/solvers → solvers}/highs-node-runtime.js +1 -1
- package/dist/{lib/solvers → solvers}/highs-worker.js +2 -2
- package/dist/{lib/solvers → solvers}/highs.js +64 -70
- package/dist/{browser/solvers/highs-loader-Csn3-0tq.js → solvers/highs.node.js} +520 -138
- package/dist/solvers/node-browser-worker-CN93BPoO.js +54 -0
- package/dist/{lib/solvers/lp-writer-CLScMFbS.js → solvers/node-lp-writer-CqMLgMIk.js} +1 -1
- package/dist/solvers/node-node-runtime-BUlNfXvx.js +10 -0
- package/dist/solvers/node-registry-CrYRRk9q.js +907 -0
- package/dist/solvers/node-types-BGqPkxwu.js +12 -0
- package/dist/{lib/solvers → solvers}/pumpkin-node-runtime.js +1 -1
- package/dist/{browser/solvers → solvers}/pumpkin-worker.js +2 -1
- package/dist/{lib/solvers → solvers}/pumpkin.js +174 -164
- package/dist/solvers/pumpkin.node.js +1228 -0
- package/dist/{lib/solvers → solvers}/z3.js +123 -120
- package/dist/types/core.d.ts +11 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modeler/core.d.ts +14 -0
- package/dist/types/modeler/core.d.ts.map +1 -0
- package/dist/types/modeler/index.d.ts +1 -13
- package/dist/types/modeler/index.d.ts.map +1 -1
- package/dist/types/modeler/model.d.ts +1 -1
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/solvers/browser-worker.d.ts +17 -0
- package/dist/types/modeler/solvers/browser-worker.d.ts.map +1 -0
- package/dist/types/modeler/solvers/glpk/loader.d.ts +2 -2
- package/dist/types/modeler/solvers/glpk/node-runtime.d.ts +5 -0
- package/dist/types/modeler/solvers/glpk/node-runtime.d.ts.map +1 -0
- package/dist/types/modeler/solvers/highs/worker-client.d.ts +5 -5
- package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
- package/dist/types/modeler/solvers/pumpkin/loader.d.ts +0 -4
- package/dist/types/modeler/solvers/pumpkin/loader.d.ts.map +1 -1
- package/dist/types/modeler/solvers/pumpkin/solver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts +4 -3
- package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts.map +1 -1
- package/dist/types/modeler/solvers/types.d.ts +5 -1
- package/dist/types/modeler/solvers/types.d.ts.map +1 -1
- package/dist/types/modeler/solvers/z3/loader.d.ts +3 -8
- package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
- package/dist/types/modeler/solvers/z3/solver.d.ts +3 -2
- package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
- package/dist/types/modeler/types.d.ts +18 -3
- package/dist/types/modeler/types.d.ts.map +1 -1
- package/dist/washi.js +4 -0
- package/dist/washi.min.js +6 -0
- package/dist/washi.node.js +4 -0
- package/docs/getting-started/ai-agents.md +23 -22
- package/docs/getting-started/coding-agents.md +26 -17
- package/docs/getting-started/cross-origin.md +2 -1
- package/docs/getting-started/index.md +3 -1
- package/docs/getting-started/runtimes.md +53 -63
- package/docs/guide/objectives.md +3 -3
- package/docs/solvers/custom-solver.md +4 -9
- package/docs/solvers/glpk.md +2 -0
- package/docs/solvers/highs.md +8 -10
- package/docs/solvers/index.md +1 -1
- package/docs/solvers/pumpkin.md +7 -7
- package/docs/solvers/z3.md +18 -1
- package/llms-full.txt +124 -118
- package/llms.txt +23 -22
- package/package.json +31 -64
- package/skills/washi/SKILL.md +18 -18
- package/skills/washi/references/single-html.md +7 -12
- package/dist/browser/solvers/glpk.js +0 -1263
- package/dist/browser/solvers/glpk.min.js +0 -1
- package/dist/browser/solvers/highs-__vite-browser-external-xcxOpLMD.js +0 -7
- package/dist/browser/solvers/highs-browser-runtime-ccRmE4qj.js +0 -2021
- package/dist/browser/solvers/highs-worker.js +0 -55
- package/dist/browser/solvers/highs.js +0 -1454
- package/dist/browser/solvers/pumpkin-_washi-pumpkin-node-runtime-CEKUDK6d.js +0 -9
- package/dist/browser/solvers/pumpkin-loader-BI3n3dWO.js +0 -401
- package/dist/browser/solvers/pumpkin.js +0 -1796
- package/dist/browser/solvers/z3-built.js +0 -8245
- package/dist/browser/solvers/z3-built.wasm +0 -4
- package/dist/browser/solvers/z3.js +0 -7842
- package/dist/browser/solvers/z3.min.js +0 -5
- package/dist/browser/washi.min.js +0 -6
- package/dist/lib/solvers/highs-browser-runtime.js +0 -2413
- package/dist/lib/solvers/highs.wasm +0 -0
- package/dist/lib/solvers/highs.wasm.LICENSE +0 -21
- package/dist/lib/solvers/pumpkin-worker.js +0 -47
- package/dist/lib/solvers/pumpkin.wasm +0 -0
- package/dist/lib/solvers/pumpkin.wasm.LICENSE +0 -21
- package/dist/lib/solvers/z3-assets.js +0 -1
- package/dist/lib/solvers/z3-built.js +0 -8245
- package/dist/lib/solvers/z3-built.wasm +0 -4
- package/dist/lib/washi.js +0 -5662
- package/dist/types/modeler/solvers/z3/assets.d.ts +0 -11
- package/dist/types/modeler/solvers/z3/assets.d.ts.map +0 -1
- /package/dist/{lib/solvers/embedded-wasm-CSFlLV5N.js → solvers/browser-embedded-wasm-CSFlLV5N.js} +0 -0
- /package/dist/{lib/solvers/registry-CrYRRk9q.js → solvers/browser-registry-CrYRRk9q.js} +0 -0
- /package/dist/{lib/solvers/types-BGqPkxwu.js → solvers/browser-types-BGqPkxwu.js} +0 -0
- /package/dist/{lib/solvers → solvers}/highs-assets.js +0 -0
- /package/dist/{lib/solvers/rolldown-runtime-DtPi1Y-2.js → solvers/highs-browser-rolldown-runtime-DtPi1Y-2.js} +0 -0
- /package/dist/{browser/solvers → solvers}/highs-inline.js +0 -0
- /package/dist/{lib/solvers → solvers}/highs-runtime.js +0 -0
- /package/dist/{lib/solvers → solvers}/highs-worker-factory.js +0 -0
- /package/dist/{browser/solvers → solvers}/highs.wasm +0 -0
- /package/dist/{browser/solvers → solvers}/highs.wasm.LICENSE +0 -0
- /package/dist/{lib/solvers → solvers}/pumpkin-assets.js +0 -0
- /package/dist/{browser/solvers → solvers}/pumpkin-inline.js +0 -0
- /package/dist/{lib/solvers → solvers}/pumpkin-worker-factory.js +0 -0
- /package/dist/{browser/solvers → solvers}/pumpkin.wasm +0 -0
- /package/dist/{browser/solvers → solvers}/pumpkin.wasm.LICENSE +0 -0
package/llms-full.txt
CHANGED
|
@@ -56,51 +56,52 @@ import "@ohtaman/washi/solvers/glpk";
|
|
|
56
56
|
|
|
57
57
|
### Browser ESM & Classic Script Tags
|
|
58
58
|
|
|
59
|
-
Classic `<script>` tags load immediately invoked function expression (`IIFE`) bundles that attach a global namespace to `window` (optional solver plugins
|
|
59
|
+
Classic `<script>` tags load immediately invoked function expression (`IIFE`) bundles that attach a global namespace to `window` (optional `glpk.js` and `z3-solver` peer plugins use ESM with an Import Map or bundler rather than IIFE binaries). Assuming `dist/` is hosted at `./washi/`:
|
|
60
60
|
|
|
61
61
|
| Solver | Browser ESM (`<script type="module">`) | Classic `<script>` IIFE |
|
|
62
62
|
| --- | --- | --- |
|
|
63
63
|
| **Core (HiGHS & Pumpkin)** | `import { Model, expr, maximize } from "./washi/washi.js";` | `<script src="./washi/washi.min.js"></script>` (global `Washi`) |
|
|
64
64
|
| **HiGHS** *(subpath API)* | `import { HighsSolver, setHighsWasmUrl } from "./washi/solvers/highs.js";` | Bundled in `washi.min.js` (pass `{ wasmUrl }` per call) |
|
|
65
|
-
| **HiGHS Inline WASM** *(no `fetch`)* | `import "./washi/solvers/highs-inline.js";` | `<script src="./washi/solvers/highs-inline.js"></script>` (`@ohtaman/washi/
|
|
65
|
+
| **HiGHS Inline WASM** *(no `fetch`)* | `import "./washi/solvers/highs-inline.js";` | `<script src="./washi/solvers/highs-inline.js"></script>` (`@ohtaman/washi/solvers/highs-inline`) |
|
|
66
66
|
| **Pumpkin** *(subpath API)* | `import { PumpkinSolver, setPumpkinWasmUrl } from "./washi/solvers/pumpkin.js";` | Bundled in `washi.min.js` (pass `{ wasmUrl }` per call) |
|
|
67
|
-
| **Pumpkin Inline WASM** *(no `fetch`)* | `import "./washi/solvers/pumpkin-inline.js";` | `<script src="./washi/solvers/pumpkin-inline.js"></script>` (`@ohtaman/washi/
|
|
68
|
-
| **GLPK** *(optional)* | `import "./washi/solvers/glpk.js";`
|
|
69
|
-
| **Z3** *(optional)* | `import "./washi/solvers/z3.js";`
|
|
67
|
+
| **Pumpkin Inline WASM** *(no `fetch`)* | `import "./washi/solvers/pumpkin-inline.js";` | `<script src="./washi/solvers/pumpkin-inline.js"></script>` (`@ohtaman/washi/solvers/pumpkin-inline`) |
|
|
68
|
+
| **GLPK** *(optional peer)* | `import "./washi/solvers/glpk.js";` *(with Import Map for `"glpk.js"`)* | — *(use ESM + Import Map or a bundler)* |
|
|
69
|
+
| **Z3** *(optional peer)* | `import { registerZ3Solver } from "./washi/solvers/z3.js";` *(with Import Map for `"z3-solver"` + `{ z3JsUrl, z3WasmUrl }`)* | — *(use ESM + Import Map or a bundler)* |
|
|
70
70
|
|
|
71
71
|
### WebAssembly Asset & Runtime Rules
|
|
72
72
|
|
|
73
73
|
#### Bundled WASM & Custom Asset URLs
|
|
74
74
|
|
|
75
|
-
- **Automatic resolution**: In Node.js and bundler builds, WaSHI resolves `.wasm` assets under `solvers/` relative to the module with no CDN fallback.
|
|
76
|
-
- **Browser self-hosting**: Deploy `dist
|
|
77
|
-
- **
|
|
75
|
+
- **Automatic resolution**: In Node.js and bundler builds, WaSHI resolves bundled HiGHS and Pumpkin `.wasm` assets under `solvers/` relative to the module with no CDN fallback. Optional `glpk.js` and `z3-solver` (`z3-built.{js,wasm}`) are not bundled in `@ohtaman/washi`.
|
|
76
|
+
- **Browser self-hosting**: Deploy `dist/` intact (entry scripts, `core-*.js` chunks, and `solvers/` runtime/worker/HiGHS+Pumpkin WASM assets). Requests that hit missing URLs or HTML SPA fallbacks fail immediately and report the attempted URL.
|
|
77
|
+
- **Cross-origin ESM vs IIFE**: Cross-origin CDN ESM (`dist/washi.js`) works on callers' threads with default `useWorker: false`, whereas browsers block cross-origin `new Worker(url)` for ESM Workers; use classic `dist/washi.min.js` (or self-host `dist/` same-origin) if you need `{ useWorker: true }`.
|
|
78
|
+
- **Custom browser URLs & Z3 registration**: Call `setHighsWasmUrl(url)` (from `@ohtaman/washi/solvers/highs`) or `setPumpkinWasmUrl(url)` (from `@ohtaman/washi/solvers/pumpkin`), or pass `{ wasmUrl }` to `m.solve()` / `m.check()`. This override is ignored for HiGHS in Node.js, while Pumpkin accepts `file://` URLs in Node.js. For browser **Z3**, configure `registerZ3Solver({ z3JsUrl, z3WasmUrl })` (from `@ohtaman/washi/solvers/z3`, using e.g. `new URL("z3-solver/build/z3-built.*", import.meta.url).href` in Vite/webpack or CDN URLs) or pass `{ z3JsUrl, z3WasmUrl }` per call.
|
|
78
79
|
|
|
79
80
|
#### Fetch-Free Loading in CSP-Restricted Pages (Inline WASM)
|
|
80
81
|
|
|
81
|
-
- **When `fetch()` is blocked (`connect-src 'none'`)**: Hosted AI sandboxes—including **Claude.ai Artifacts** (edit and published links), **ChatGPT inline visualizations**, and **Codex inline visualizations**—allow CDN scripts (`script-src`) while blocking `fetch()` via `connect-src
|
|
82
|
-
- **Dual ESM & Classic `<script>` support (prefer ESM)**: Each `*-inline.js` file has no `import`/`export` statements, so the exact same file works via ESM `import` and classic `<script src="...">`, and default loaders (`washi.js`, `washi.
|
|
82
|
+
- **When `fetch()` is blocked (`connect-src 'none'`)**: Hosted AI sandboxes—including **Claude.ai Artifacts** (edit and published links), **ChatGPT inline visualizations**, and **Codex inline visualizations**—allow CDN scripts (`script-src`) while blocking `fetch()` via `connect-src`. Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtaman/washi/solvers/highs-inline` and `solvers/pumpkin-inline.js` / `@ohtaman/washi/solvers/pumpkin-inline`) **before** your first `solve()`, `check()`, or `warmup*()` call—zero base64 or binary-setter boilerplate is required.
|
|
83
|
+
- **Dual ESM & Classic `<script>` support (prefer ESM)**: Each `*-inline.js` file has no `import`/`export` statements, so the exact same file works via ESM `import` and classic `<script src="...">`, and default loaders (`washi.js`, `washi.node.js`, `washi.min.js`) never reference it. Prefer **ESM (`<script type="module">`)** in dynamically injected sandboxes (such as ChatGPT inline visualizations), where classic `<script src>` tags can race with inline scripts on cold loads.
|
|
83
84
|
- **Initialization semantics**: Load the inline pack **before** the first solver initialization (`solve()`, `check()`, or `warmup*()`). Before first initialization, load order between core (`washi.js` / `washi.min.js`) and `*-inline.js` does not matter. Once a solver's default WASM source is selected on first initialization, WaSHI latches it and does not switch on late pack loads (keeping main-thread and Worker behavior consistent). Explicit `set*WasmUrl()` / `{ wasmUrl }` still override the embedded pack when provided.
|
|
84
|
-
- **
|
|
85
|
+
- **Sandbox notes (`timeLimit`, Workers, & CSP)**: Set a `timeLimit` on main-thread UI solves so long runs do not freeze rendering; if opting into `{ useWorker: true }` on same-origin `http(s):` apps (or via classic `washi.min.js`), `*-inline.js` also transfers embedded bytes via `postMessage` without calling `fetch()`. Embedded previews whose CSP omits `'wasm-unsafe-eval'` (such as Antigravity's HTML artifact preview) cannot compile WebAssembly; open exported HTML in Chrome/Safari or via a local server.
|
|
85
86
|
|
|
86
87
|
```html
|
|
87
|
-
<!-- Recommended: ESM (<script type="module">)
|
|
88
|
+
<!-- Recommended: ESM (<script type="module">) -->
|
|
88
89
|
<!-- Works across Claude Artifacts, ChatGPT/Codex inline visualizations, Gemini Canvas, Google Sites & file:// -->
|
|
89
90
|
<script type="module">
|
|
90
|
-
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
91
|
-
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
92
|
-
// import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
91
|
+
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.js";
|
|
92
|
+
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/highs-inline.js";
|
|
93
|
+
// import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/pumpkin-inline.js";
|
|
93
94
|
|
|
94
95
|
const m = new Model("CspFreeEsm");
|
|
95
96
|
const x = m.integer("x", { lb: 0 });
|
|
96
97
|
m.objective(maximize(x));
|
|
97
98
|
m.constraint(expr`${x} <= 10`, "cap");
|
|
98
|
-
await m.solve({
|
|
99
|
+
await m.solve({ timeLimit: 5 }); // Default calling thread works cross-origin; use same-origin ESM or washi.min.js for { useWorker: true }
|
|
99
100
|
</script>
|
|
100
101
|
|
|
101
102
|
<!-- Classic <script> fallback (prefer ESM above in dynamically injected sandboxes) -->
|
|
102
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
103
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
103
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.min.js"></script>
|
|
104
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/highs-inline.js"></script>
|
|
104
105
|
<script>
|
|
105
106
|
(async () => {
|
|
106
107
|
const { Model, expr, maximize } = Washi;
|
|
@@ -108,7 +109,7 @@ Classic `<script>` tags load immediately invoked function expression (`IIFE`) bu
|
|
|
108
109
|
const x = m.integer("x", { lb: 0 });
|
|
109
110
|
m.objective(maximize(x));
|
|
110
111
|
m.constraint(expr`${x} <= 10`, "cap");
|
|
111
|
-
await m.solve({
|
|
112
|
+
await m.solve({ timeLimit: 5 });
|
|
112
113
|
})();
|
|
113
114
|
</script>
|
|
114
115
|
```
|
|
@@ -124,9 +125,9 @@ Classic `<script>` tags load immediately invoked function expression (`IIFE`) bu
|
|
|
124
125
|
|
|
125
126
|
#### Web Workers & Cancellation (`AbortSignal`)
|
|
126
127
|
|
|
127
|
-
- **Default
|
|
128
|
-
- **Worker cancellation**: Pre-solve cancellation (`signal.aborted`) works on all solvers, and `{ signal }` terminates in-flight HiGHS and Pumpkin Workers immediately.
|
|
129
|
-
- **Main-thread & Node.js cancellation**: HiGHS checks `signal` during `onProgress` callbacks, Pumpkin polls `signal` at search checkpoints, and GLPK/Z3 only check `signal` before starting.
|
|
128
|
+
- **Default Execution (`useWorker: false`)**: HiGHS and Pumpkin run on the calling thread by default in both browsers and Node.js, so `file://`, CSP-restricted environments (`worker-src 'none'`), and sandboxed iframes work without configuration. Pass `{ useWorker: true }` in browser environments to offload interactive UIs or long-running solves to a Web Worker (throws if browser Web Workers are unavailable).
|
|
129
|
+
- **Worker cancellation**: Pre-solve cancellation (`signal.aborted`) works on all solvers, and `{ signal }` with `{ useWorker: true }` terminates in-flight HiGHS and Pumpkin Workers immediately.
|
|
130
|
+
- **Main-thread & Node.js cancellation**: On the default calling thread (`useWorker: false`), HiGHS checks `signal` during `onProgress` callbacks, Pumpkin polls `signal` at search checkpoints, and GLPK/Z3 only check `signal` before starting.
|
|
130
131
|
|
|
131
132
|
#### Solver Capabilities, Options, & Validation Errors
|
|
132
133
|
|
|
@@ -448,7 +449,7 @@ export function verifyNegativePatterns() {
|
|
|
448
449
|
|
|
449
450
|
# Introduction & Installation
|
|
450
451
|
|
|
451
|
-
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) brings Python PuLP-style algebraic modeling to TypeScript and JavaScript. You can write linear, quadratic, and logical expressions with tagged templates (`expr`) and model mathematical optimization and constraint programming problems directly in **Node.js
|
|
452
|
+
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) brings Python PuLP-style algebraic modeling to TypeScript and JavaScript. You can write linear, quadratic, and logical expressions with tagged templates (`expr`) and model mathematical optimization and constraint programming problems directly in **Node.js** and modern browsers.
|
|
452
453
|
|
|
453
454
|
---
|
|
454
455
|
|
|
@@ -488,6 +489,8 @@ npm install glpk.js # Optional: GLPK solver (GPL-3.0)
|
|
|
488
489
|
|
|
489
490
|
In browsers, Z3 requires a Secure Context and Cross-Origin Isolation headers — `Cross-Origin-Opener-Policy` and `Cross-Origin-Embedder-Policy`, abbreviated `COOP`/`COEP`. See [Cross-Origin Isolation](docs/getting-started/cross-origin.md) for server setup.
|
|
490
491
|
|
|
492
|
+
For bundler-free browser or CDN usage (`https://esm.sh/@ohtaman/washi`, `dist/washi.js`, or Gemini Canvas), HiGHS and Pumpkin run out of the box with no extra imports. In `fetch()`-restricted HTML sandboxes (`connect-src 'none'` / `'self'`, such as **Claude.ai Artifacts**, **ChatGPT**, and **Codex**), also load `dist/solvers/highs-inline.js` / `pumpkin-inline.js`—see [Runtime Environments & Deployment](docs/getting-started/runtimes.md#csp-fetch-free).
|
|
493
|
+
|
|
491
494
|
---
|
|
492
495
|
|
|
493
496
|
## 🚀 Quick Start
|
|
@@ -544,11 +547,11 @@ WaSHI runs across JavaScript and TypeScript runtimes and deployment targets with
|
|
|
544
547
|
|
|
545
548
|
| Target Environment | Entry Point | Worker & Header Notes |
|
|
546
549
|
| --- | --- | --- |
|
|
547
|
-
| **Node.js
|
|
548
|
-
| **Vite, Next.js, Webpack, Rollup** | `@ohtaman/washi` | Runs HiGHS and Pumpkin
|
|
549
|
-
| **Tauri, Capacitor, PWA** | `@ohtaman/washi` (standard Vite build) | Runs offline; allow `'wasm-unsafe-eval'` in `script-src` and `worker-src 'self' blob:`
|
|
550
|
-
| **Browser ESM (`<script type="module">`)** | `dist/
|
|
551
|
-
| **Standalone HTML / CDN (`<script>`)** | `dist/
|
|
550
|
+
| **Node.js, Bun, Deno** | `@ohtaman/washi` (`npm:@ohtaman/washi` in Deno) | Loads bundled `.wasm` from disk; no HTTP headers required. |
|
|
551
|
+
| **Vite, Next.js, Webpack, Rollup** | `@ohtaman/washi` | Runs HiGHS and Pumpkin on the calling thread by default (`useWorker: false`); pass `{ useWorker: true }` to offload solves to a Web Worker. |
|
|
552
|
+
| **Tauri, Capacitor, PWA** | `@ohtaman/washi` (standard Vite build) | Runs offline; allow `'wasm-unsafe-eval'` in `script-src` (and `worker-src 'self' blob:` if opting into `{ useWorker: true }`) in your Content Security Policy (`CSP`). |
|
|
553
|
+
| **Browser ESM (`<script type="module">`)** | `dist/washi.js` | Keep `dist/` files together when self-hosting; use default `useWorker: false` on cross-origin CDNs. |
|
|
554
|
+
| **Standalone HTML / CDN (`<script>`)** | `dist/washi.min.js` | Exposes `window.Washi`; supports cross-origin `{ useWorker: true }` and runs directly on `file://`. |
|
|
552
555
|
|
|
553
556
|
---
|
|
554
557
|
|
|
@@ -556,7 +559,7 @@ WaSHI runs across JavaScript and TypeScript runtimes and deployment targets with
|
|
|
556
559
|
|
|
557
560
|
### Node.js
|
|
558
561
|
|
|
559
|
-
WaSHI supports Node.js
|
|
562
|
+
WaSHI supports Node.js with standard ECMAScript Modules (`ESM`). Both bundled WebAssembly engines—HiGHS (default) and Pumpkin (`{ solver: "pumpkin" }`)—load directly from `solvers/` inside the installed package with zero extra imports:
|
|
560
563
|
|
|
561
564
|
```typescript
|
|
562
565
|
import { Model, expr, maximize } from "@ohtaman/washi";
|
|
@@ -609,7 +612,7 @@ if (m.hasPrimalSolution) {
|
|
|
609
612
|
|
|
610
613
|
### Modern Bundlers & Static Deployment
|
|
611
614
|
|
|
612
|
-
The package root export (`@ohtaman/washi`) resolves `
|
|
615
|
+
The package root export (`@ohtaman/washi`) resolves `node` to `./dist/washi.node.js`, `default` (browsers and bundlers) to `./dist/washi.js`, and `types` to `./dist/types/index.d.ts`, sharing one deduped core chunk (`dist/core-*.js`) and one set of `.wasm` binaries:
|
|
613
616
|
|
|
614
617
|
```typescript
|
|
615
618
|
import { Model, maximize } from "@ohtaman/washi";
|
|
@@ -625,31 +628,34 @@ export async function runOptimization() {
|
|
|
625
628
|
|
|
626
629
|
Because the modeler (JS/TS) and bundled solvers (WebAssembly) execute entirely on the client, static builds from `vite build` deploy directly to **GitHub Pages, Cloudflare Pages, Vercel, or Netlify** without a backend server. HiGHS, Pumpkin, and GLPK need no special HTTP headers; for Z3's browser headers, see **Offline, Intranet & Strict CSP Environments** below.
|
|
627
630
|
|
|
628
|
-
####
|
|
631
|
+
#### Calling-Thread Default & Optional Web Worker Execution
|
|
629
632
|
|
|
630
|
-
In browsers, **HiGHS** and **Pumpkin**
|
|
633
|
+
In both browsers and Node.js, **HiGHS** and **Pumpkin** default to `useWorker: false` (executing on the calling thread). This lets `LP`, `MIP`, `QP`, and `CP` solves run out of the box under strict CSP (`worker-src 'none'`), `file://`, and sandboxed iframes without Worker setup.
|
|
631
634
|
|
|
632
|
-
Pass `useWorker:
|
|
635
|
+
Pass `{ useWorker: true }` in interactive browser UIs when you want background Web Worker execution so long solves do not block rendering, UI callbacks repaint live on `onProgress`, and `AbortSignal` can terminate an active solve immediately (throws in Node.js or when browser Web Workers are unavailable). On cross-origin CDN builds, `{ useWorker: true }` automatically bridges Workers with a small ES module `Blob` bootstrap:
|
|
633
636
|
|
|
634
637
|
```typescript
|
|
635
|
-
await m.solve({ useWorker:
|
|
638
|
+
await m.solve({ useWorker: true });
|
|
636
639
|
```
|
|
637
640
|
|
|
638
641
|
#### Customizing WASM Asset URLs
|
|
639
642
|
|
|
640
643
|
By default, WaSHI resolves `solvers/highs.wasm` and `solvers/pumpkin.wasm` relative to the bundle via `import.meta.url`. It **never** falls back to external CDNs (`jsDelivr`, `unpkg`, etc.).
|
|
641
644
|
|
|
642
|
-
If your browser host serves `.wasm` files from a custom path, override the URL globally or per call. For HiGHS, `setHighsWasmUrl()` (from `@ohtaman/washi/solvers/highs`) and `{ wasmUrl }` are browser-only (ignored in Node.js); Pumpkin (`setPumpkinWasmUrl()` from `@ohtaman/washi/solvers/pumpkin`) also accepts `file://` URLs in Node.js
|
|
645
|
+
If your browser host serves `.wasm` files from a custom path, override the URL globally or per call. For HiGHS, `setHighsWasmUrl()` (from `@ohtaman/washi/solvers/highs`) and `{ wasmUrl }` are browser-only (ignored in Node.js); Pumpkin (`setPumpkinWasmUrl()` from `@ohtaman/washi/solvers/pumpkin`) also accepts `file://` URLs in Node.js. For optional **Z3** (`z3-solver`, unbundled peer), configure `registerZ3Solver({ z3JsUrl, z3WasmUrl })` or pass `{ z3JsUrl, z3WasmUrl }` per call:
|
|
643
646
|
|
|
644
647
|
```typescript
|
|
645
648
|
import { setHighsWasmUrl } from "@ohtaman/washi/solvers/highs";
|
|
646
649
|
import { setPumpkinWasmUrl } from "@ohtaman/washi/solvers/pumpkin";
|
|
647
|
-
import {
|
|
650
|
+
import { registerZ3Solver } from "@ohtaman/washi/solvers/z3"; // Optional Z3 plugin
|
|
648
651
|
|
|
649
652
|
// Option A: Configure globally before solving
|
|
650
653
|
setHighsWasmUrl("/assets/wasm/highs.wasm");
|
|
651
654
|
setPumpkinWasmUrl("/assets/wasm/pumpkin.wasm");
|
|
652
|
-
|
|
655
|
+
registerZ3Solver({
|
|
656
|
+
z3JsUrl: new URL("z3-solver/build/z3-built.js", import.meta.url).href,
|
|
657
|
+
z3WasmUrl: new URL("z3-solver/build/z3-built.wasm", import.meta.url).href,
|
|
658
|
+
});
|
|
653
659
|
|
|
654
660
|
// Option B: Configure per solve / check call
|
|
655
661
|
await m.solve({ wasmUrl: "/assets/wasm/highs.wasm" });
|
|
@@ -692,13 +698,13 @@ export default function OptimizerComponent() {
|
|
|
692
698
|
|
|
693
699
|
Standard Vite frontends bundle **HiGHS** and **Pumpkin** as static assets for offline execution. They run in Tauri (`tauri://localhost` or `http://tauri.localhost`), Capacitor mobile WebViews, and offline PWAs with no native solver build step.
|
|
694
700
|
|
|
695
|
-
In `tauri.conf.json`,
|
|
701
|
+
In `tauri.conf.json`, default calling-thread execution only needs `'wasm-unsafe-eval'` in `script-src` (`worker-src` is unnecessary). Include `worker-src 'self' blob:` if your app opts into `{ useWorker: true }` (see the full CSP table below):
|
|
696
702
|
|
|
697
703
|
```json
|
|
698
704
|
{
|
|
699
705
|
"app": {
|
|
700
706
|
"security": {
|
|
701
|
-
"csp": "default-src 'self'; script-src 'self' 'wasm-unsafe-eval'
|
|
707
|
+
"csp": "default-src 'self'; script-src 'self' 'wasm-unsafe-eval'"
|
|
702
708
|
}
|
|
703
709
|
}
|
|
704
710
|
}
|
|
@@ -714,11 +720,11 @@ Without a bundler, import the pre-built browser ESM module from your own static
|
|
|
714
720
|
|
|
715
721
|
```html
|
|
716
722
|
<script type="module">
|
|
717
|
-
// From an npm CDN (or "./dist/
|
|
718
|
-
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
723
|
+
// From an npm CDN (or "./dist/washi.js" when self-hosted; includes HiGHS and Pumpkin):
|
|
724
|
+
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.js";
|
|
719
725
|
// Optional solver plugins:
|
|
720
|
-
// import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
721
|
-
// import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
726
|
+
// import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/glpk.js";
|
|
727
|
+
// import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/z3.js";
|
|
722
728
|
|
|
723
729
|
const m = new Model("BrowserESM");
|
|
724
730
|
const x = m.integer("x", { lb: 0, ub: 100 });
|
|
@@ -752,11 +758,8 @@ For single-file HTML pages, CodePen, or JSFiddle, load `washi.min.js` via a clas
|
|
|
752
758
|
<h1>WaSHI Browser Optimization</h1>
|
|
753
759
|
<pre id="output">Solving...</pre>
|
|
754
760
|
|
|
755
|
-
<!-- Core WaSHI + bundled HiGHS & Pumpkin (MIT) via CDN (or "./dist/
|
|
756
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
757
|
-
<!-- Optional plugins (load after washi.min.js; auto-register when window.Washi is present): -->
|
|
758
|
-
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/glpk.min.js"></script> -->
|
|
759
|
-
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/z3.min.js"></script> -->
|
|
761
|
+
<!-- Core WaSHI + bundled HiGHS & Pumpkin (MIT) via CDN (or "./dist/washi.min.js" when self-hosted) -->
|
|
762
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.min.js"></script>
|
|
760
763
|
|
|
761
764
|
<script>
|
|
762
765
|
(async () => {
|
|
@@ -783,16 +786,11 @@ For single-file HTML pages, CodePen, or JSFiddle, load `washi.min.js` via a clas
|
|
|
783
786
|
</html>
|
|
784
787
|
```
|
|
785
788
|
|
|
786
|
-
### Cross-Origin CDN Workers
|
|
787
|
-
|
|
788
|
-
On standard `http://` and `https://` origins, browsers block direct `new Worker("https://cdn...")` calls. WaSHI automatically bridges cross-origin CDN workers with a small ES module `Blob` bootstrap.
|
|
789
|
-
|
|
790
789
|
### Opening Local `.html` Files Directly (`file://`)
|
|
791
790
|
|
|
792
791
|
| Scenario | Behavior & Requirement |
|
|
793
792
|
| --- | --- |
|
|
794
793
|
| **CDN scripts** | Loading `washi.min.js` from an HTTPS CDN includes both HiGHS and Pumpkin and works by double-clicking a local `.html` file (`file://`) with no local server. |
|
|
795
|
-
| **Opaque origins (`window.origin === "null"`)** | On `file://` pages or sandboxed `<iframe>` embeds without `allow-same-origin`, WaSHI runs HiGHS and Pumpkin on the main thread when `useWorker` is omitted. |
|
|
796
794
|
| **Self-hosted `.wasm` & Z3** | Local `.wasm` files require `http://` or `https://` because browsers block `fetch()` on `file://`. Z3 also requires Cross-Origin Isolation (see below). |
|
|
797
795
|
| **Offline single-file HTML + npm libs** | To bundle `@ohtaman/washi` (HiGHS & Pumpkin) alongside third-party npm packages into one zero-network `index.html` for `file://`, follow [`skills/washi/references/single-html.md`](https://github.com/ohtaman/washi/blob/main/skills/washi/references/single-html.md) inside the `washi` Agent Skill. |
|
|
798
796
|
|
|
@@ -802,38 +800,37 @@ On standard `http://` and `https://` origins, browsers block direct `new Worker(
|
|
|
802
800
|
|
|
803
801
|
WaSHI never phones home or falls back to public CDNs. To self-host in an air-gapped intranet or under a strict `CSP`, configure three areas:
|
|
804
802
|
|
|
805
|
-
### 1. Deploy `dist
|
|
803
|
+
### 1. Deploy `dist/` Intact
|
|
806
804
|
|
|
807
|
-
Copy `node_modules/@ohtaman/washi/dist
|
|
805
|
+
Copy `node_modules/@ohtaman/washi/dist/` to your static origin (keeping `.js` chunks and `solvers/` together). When you opt into `{ useWorker: true }` on same-origin hosting (or cross-origin via classic `washi.min.js`), both ESM bundles and `washi.min.js` spawn `solvers/highs-worker.js` and `solvers/pumpkin-worker.js` as Web Workers, referencing shared chunks under `dist/` and `dist/solvers/` via relative paths. Note that browsers forbid cross-origin module Workers on `dist/washi.js`; keep the default `useWorker: false` for cross-origin CDN ESM or use `dist/washi.min.js` when `{ useWorker: true }` is needed.
|
|
808
806
|
|
|
809
|
-
| Bundle | Required Files under `dist
|
|
807
|
+
| Bundle | Required Files under `dist/` |
|
|
810
808
|
| --- | --- |
|
|
811
|
-
| **Core** | `washi.js` / `washi.min.js` |
|
|
812
|
-
| **Bundled HiGHS** | `solvers/highs.js`, `solvers/highs.wasm`, `solvers/highs-worker.js`,
|
|
813
|
-
| **Bundled Pumpkin** | `solvers/pumpkin.js`, `solvers/pumpkin.wasm`, `solvers/pumpkin-worker.js`,
|
|
814
|
-
| **Optional GLPK** | `solvers/glpk.js`
|
|
815
|
-
| **Optional Z3** | `solvers/z3.js`
|
|
809
|
+
| **Core** | `washi.js`, `core-*.js` / `washi.min.js` |
|
|
810
|
+
| **Bundled HiGHS** | `solvers/highs.js`, `solvers/highs.wasm`, `solvers/highs-worker.js`, `solvers/highs-*.js`, `core-*.js` |
|
|
811
|
+
| **Bundled Pumpkin** | `solvers/pumpkin.js`, `solvers/pumpkin.wasm`, `solvers/pumpkin-worker.js`, `solvers/pumpkin-*.js`, `core-*.js` |
|
|
812
|
+
| **Optional GLPK** *(unbundled peer)* | `solvers/glpk.js` (requires `glpk.js` resolved via bundler or `<script type="importmap">`) |
|
|
813
|
+
| **Optional Z3** *(unbundled peer)* | `solvers/z3.js` (requires `z3-solver` plus `z3-built.js` & `z3-built.wasm` configured via `registerZ3Solver()`) |
|
|
816
814
|
|
|
817
815
|
### 2. Configure CSP Directives
|
|
818
816
|
|
|
819
817
|
| Directive | Required Value | Purpose |
|
|
820
818
|
| --- | --- | --- |
|
|
821
819
|
| `script-src` | `'wasm-unsafe-eval'` | Allows WebAssembly module compilation. |
|
|
822
|
-
| `worker-src` | `'self' blob:` |
|
|
823
|
-
| `worker-src` (if `blob:` is disallowed) | `'self'` only | Serve `solvers/highs-worker.js` / `solvers/pumpkin-worker.js` from `'self'`, or pass `{ useWorker: false }`. |
|
|
820
|
+
| `worker-src` *(only if `{ useWorker: true }`)* | `'self' blob:` | Optional: only needed when opting into Web Workers (`'self'` only is sufficient for same-origin hosting; omitted/`'none'` works with default `useWorker: false`). |
|
|
824
821
|
|
|
825
822
|
### 3. CSP-Restricted Pages Without `fetch()` (`connect-src 'none'`) {#csp-fetch-free}
|
|
826
823
|
|
|
827
|
-
Hosted AI sandboxes—such as **Claude.ai Artifacts** (both edit views and published share links), **ChatGPT inline visualizations**, and **Codex inline visualizations**—allow scripts from CDNs (`script-src`) while blocking `.wasm` `fetch()` (`connect-src 'none'`)
|
|
824
|
+
Hosted AI sandboxes—such as **Claude.ai Artifacts** (both edit views and published share links), **ChatGPT inline visualizations**, and **Codex inline visualizations**—allow scripts from CDNs (`script-src`) while blocking `.wasm` `fetch()` (`connect-src 'none'`). In these environments, default HiGHS and Pumpkin initialization fails because standard bundles fetch `.wasm` files.
|
|
828
825
|
|
|
829
|
-
Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtaman/washi/
|
|
826
|
+
Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtaman/washi/solvers/highs-inline` and `solvers/pumpkin-inline.js` / `@ohtaman/washi/solvers/pumpkin-inline`) **before** your first `solve()`, `check()`, or `warmup*()` call—no manual base64 decoding or binary setter calls are required. Each inline pack contains no `import` or `export` statements, so the exact same file works in both ESM and classic `<script>` mode, and default loaders never reference it:
|
|
830
827
|
|
|
831
828
|
```html
|
|
832
|
-
<!-- Option A (Recommended): ESM (<script type="module">)
|
|
829
|
+
<!-- Option A (Recommended): ESM (<script type="module">) -->
|
|
833
830
|
<script type="module">
|
|
834
|
-
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
835
|
-
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
836
|
-
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
831
|
+
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.js";
|
|
832
|
+
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/highs-inline.js";
|
|
833
|
+
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/pumpkin-inline.js";
|
|
837
834
|
|
|
838
835
|
const m = new Model("CspFreeExample");
|
|
839
836
|
const x = m.integer("x", { lb: 0 });
|
|
@@ -841,13 +838,13 @@ Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtam
|
|
|
841
838
|
m.objective(maximize(expr`30 * ${x} + 50 * ${y}`));
|
|
842
839
|
m.constraint(expr`${x} + 2 * ${y} <= 40`);
|
|
843
840
|
m.constraint(expr`2 * ${x} + ${y} <= 50`);
|
|
844
|
-
await m.solve({
|
|
841
|
+
await m.solve({ timeLimit: 5 }); // Works across all supported AI sandboxes
|
|
845
842
|
</script>
|
|
846
843
|
|
|
847
844
|
<!-- Option B: Classic <script> (prefer Option A in dynamically injected sandboxes) -->
|
|
848
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
849
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
850
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
845
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.min.js"></script>
|
|
846
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/highs-inline.js"></script>
|
|
847
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/pumpkin-inline.js"></script>
|
|
851
848
|
<script>
|
|
852
849
|
(async () => {
|
|
853
850
|
const { Model, expr, maximize } = Washi;
|
|
@@ -857,31 +854,27 @@ Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtam
|
|
|
857
854
|
m.objective(maximize(expr`30 * ${x} + 50 * ${y}`));
|
|
858
855
|
m.constraint(expr`${x} + 2 * ${y} <= 40`);
|
|
859
856
|
m.constraint(expr`2 * ${x} + ${y} <= 50`);
|
|
860
|
-
await m.solve({
|
|
857
|
+
await m.solve({ timeLimit: 5 }); // Zero fetch(), zero Blob URLs, zero Workers
|
|
861
858
|
})();
|
|
862
859
|
</script>
|
|
863
860
|
```
|
|
864
861
|
|
|
865
862
|
#### Hosted AI Sandbox Compatibility (Empirically Verified)
|
|
866
863
|
|
|
867
|
-
| Environment | `fetch(.wasm)` | `*-inline.js`
|
|
864
|
+
| Environment | `fetch(.wasm)` | `*-inline.js` | `{ useWorker: true }` | Recommended Setup |
|
|
868
865
|
| --- | :---: | :---: | :---: | --- |
|
|
869
|
-
| **Claude.ai Artifacts** *(edit & published links)* | Blocked | Works *(ESM & Classic)* | Blocked | Option A (ESM + `*-inline.js`
|
|
870
|
-
| **ChatGPT Inline Visualization** *(`codex-inline-visualization-*`)* | Blocked | Works *(ESM reliable; Classic can race on cold load)* | Blocked | Option A (ESM + `*-inline.js`
|
|
871
|
-
| **Codex Inline Visualization** *(`codex-sandbox://...`)* | Blocked | Works *(ESM & Classic)* | Blocked | Option A (ESM + `*-inline.js`
|
|
872
|
-
| **Gemini Canvas & Google Sites** *(1-click publish)* | Works | Works *(ESM & Classic)* | Works | Option A works everywhere
|
|
866
|
+
| **Claude.ai Artifacts** *(edit & published links)* | Blocked | Works *(ESM & Classic)* | Blocked | Option A (ESM + `*-inline.js`) |
|
|
867
|
+
| **ChatGPT Inline Visualization** *(`codex-inline-visualization-*`)* | Blocked | Works *(ESM reliable; Classic can race on cold load)* | Blocked | Option A (ESM + `*-inline.js`) |
|
|
868
|
+
| **Codex Inline Visualization** *(`codex-sandbox://...`)* | Blocked | Works *(ESM & Classic)* | Blocked | Option A (ESM + `*-inline.js`) |
|
|
869
|
+
| **Gemini Canvas & Google Sites** *(1-click publish)* | Works | Works *(ESM & Classic)* | Works *(Classic `washi.min.js`)* | Option A works everywhere (default `useWorker: false`); use Option B (`washi.min.js`) for `{ useWorker: true }` |
|
|
873
870
|
| **Antigravity HTML Artifact Preview** | Blocked *(CDN blocked)* | Blocked *(CSP omits `'wasm-unsafe-eval'`)* | Blocked | Preview via local server + built-in browser or open `.html` in Chrome/Safari |
|
|
874
|
-
| **Local Browser `file://`** *(Chrome / Safari)* | Works via HTTPS CDN | Works *(CDN or Vite offline bundle)* |
|
|
871
|
+
| **Local Browser `file://`** *(Chrome / Safari)* | Works via HTTPS CDN | Works *(CDN or Vite offline bundle)* | Blocked | CDN Option A or offline [`skills/washi/references/single-html.md`](https://github.com/ohtaman/washi/blob/main/skills/washi/references/single-html.md) |
|
|
875
872
|
|
|
876
873
|
- **Why prefer Option A (ESM) over Option B (Classic `<script>`)**: Sandboxes that dynamically inject HTML into the DOM (such as ChatGPT inline visualizations) may evaluate inline classic `<script>` blocks before external `<script src>` downloads complete or after `window` `load` has already fired. ESM `<script type="module">` `import` statements strictly wait for all dependencies before executing.
|
|
877
874
|
- **Initialization semantics**: Load `*-inline.js` before the first solver initialization (`solve()`, `check()`, or `warmup*()`). Load order between core (`washi.js` / `washi.min.js`) and `*-inline.js` does not matter before first initialization. Once a solver's default WASM source is selected on first initialization, WaSHI latches it and ignores late pack registration so main-thread and Worker behavior stay consistent.
|
|
878
|
-
- **Web Worker mode**:
|
|
875
|
+
- **Web Worker mode**: If you opt into `{ useWorker: true }`, WaSHI transfers the embedded bytes once per Worker instance via `postMessage` so Worker startup does not call `fetch()` (requires `worker-src blob:` or same-origin Workers).
|
|
879
876
|
- **GLPK & Z3**: **GLPK** (`solvers/glpk.js`) already embeds its WASM inline without `fetch()`. **Z3** requires `SharedArrayBuffer` and Cross-Origin Isolation headers (below).
|
|
880
|
-
|
|
881
|
-
> [!TIP]
|
|
882
|
-
> **Choosing Between `useWorker: true` and `useWorker: false`**:
|
|
883
|
-
> - **Use `useWorker: true` (default on standard `http(s):` origins)** for regular web apps, Vite/Next.js bundles, Gemini Canvas, and Google Sites. Running in a Web Worker keeps the browser UI responsive, allows immediate `AbortSignal` worker termination, supports live `onProgress` UI repaints, and isolates solver crashes.
|
|
884
|
-
> - **Use `{ useWorker: false }`** only where Web Workers are disallowed (Claude.ai Artifacts, ChatGPT/Codex inline visualizations, or `file://` pages). Main-thread solving blocks UI painting and user clicks while running, prevents mid-solve `AbortSignal` interruption and live progress updates, and shares the UI thread on crash—so always pass a sensible `timeLimit` (for example, `timeLimit: 5`) and yield a frame before showing a loading spinner.
|
|
877
|
+
- **Main-thread responsiveness**: Set a sensible `timeLimit` (for example, `timeLimit: 5`) and yield a frame before showing a loading spinner for non-trivial main-thread solves; pass `{ useWorker: true }` for slow interactive `http(s):` apps.
|
|
885
878
|
|
|
886
879
|
### 4. Enable Cross-Origin Isolation (Z3 Only)
|
|
887
880
|
|
|
@@ -1011,12 +1004,13 @@ On the first visit, the Service Worker registers and reloads the page once so `w
|
|
|
1011
1004
|
|
|
1012
1005
|
## Runtime Check in WaSHI
|
|
1013
1006
|
|
|
1014
|
-
Before initializing Z3 in a browser, WaSHI validates
|
|
1007
|
+
Before initializing Z3 in a browser, WaSHI validates these preconditions in order:
|
|
1015
1008
|
|
|
1016
1009
|
| Check | Failure Condition | Result |
|
|
1017
1010
|
| --- | --- | --- |
|
|
1018
1011
|
| **Secure Context** | `!window.isSecureContext` and hostname is not `localhost`, `127.0.0.1`, or `[::1]` | `solve()` / `check()` immediately rejects with an HTTPS or `localhost` requirement error. |
|
|
1019
1012
|
| **Cross-Origin Isolation** | `SharedArrayBuffer` is missing or `window.crossOriginIsolated !== true` | `solve()` / `check()` immediately rejects listing the required `COOP` and `COEP` headers instead of hanging. |
|
|
1013
|
+
| **Browser Asset URLs** | `z3JsUrl` or `z3WasmUrl` not configured via `registerZ3Solver()` or per-call options | `solve()` / `check()` immediately rejects with setup examples for bundlers and CDNs (see [Z3 Solver Guide](docs/solvers/z3.md)). |
|
|
1020
1014
|
|
|
1021
1015
|
---
|
|
1022
1016
|
|
|
@@ -1903,7 +1897,7 @@ const status = await m.solve({
|
|
|
1903
1897
|
| `presolve` | `"on"` \| `"off"` \| `"choose"` | `"choose"` | Controls solver presolve reduction prior to optimization. |
|
|
1904
1898
|
| `relax` | `boolean` | `false` | Solves the continuous LP relaxation (equivalent to `m.relax()`); supported on HiGHS and GLPK. |
|
|
1905
1899
|
| `outputFlag` / `verbose` | `boolean` | `false` | Emits internal solver logs (`outputFlag` for HiGHS, `verbose` for GLPK). |
|
|
1906
|
-
| `useWorker` | `boolean` | `
|
|
1900
|
+
| `useWorker` | `boolean` | `false` | Runs HiGHS and Pumpkin in a browser Web Worker when `true`. Omit or set `false` for calling-thread execution; `true` throws in Node.js or when browser Web Workers are unavailable. |
|
|
1907
1901
|
| `wasmUrl` | `string` | Auto-resolved | Custom URL to load `highs.wasm` or `pumpkin.wasm` in browser deployments. |
|
|
1908
1902
|
| `signal` | `AbortSignal` | `undefined` | Cancellation signal (`AbortController.signal`); see cancellation limitations below. |
|
|
1909
1903
|
| `onProgress` | `(e: SolveProgressEvent) => void` | `undefined` | Callback receiving live solver progress snapshots. |
|
|
@@ -2002,8 +1996,8 @@ console.log("Has incumbent:", m.hasPrimalSolution); // true if an incumbent was
|
|
|
2002
1996
|
|
|
2003
1997
|
> [!NOTE]
|
|
2004
1998
|
> **`AbortSignal` Behavior Across Backends**:
|
|
2005
|
-
> - **Asynchronous preemptive cancellation**: On HiGHS and Pumpkin
|
|
2006
|
-
> - **Cooperative mid-solve cancellation**:
|
|
1999
|
+
> - **Asynchronous preemptive cancellation**: On HiGHS and Pumpkin with browser Web Workers (`useWorker: true`), aborting terminates the worker immediately.
|
|
2000
|
+
> - **Cooperative mid-solve cancellation**: By default (`useWorker: false`, Node.js or browser calling thread), aborting inside `onProgress` (and during Pumpkin search checkpoints) stops the active solve cleanly.
|
|
2007
2001
|
> - **Pre-solve cancellation only**: On GLPK and Z3, `AbortSignal` is checked only before starting a solve.
|
|
2008
2002
|
|
|
2009
2003
|
### `SolveProgressEvent` Fields
|
|
@@ -2945,7 +2939,7 @@ WaSHI uses a pluggable solver architecture. You write a model once with the unif
|
|
|
2945
2939
|
| :--- | :--- | :--- | :--- | :--- |
|
|
2946
2940
|
| **[HiGHS](docs/solvers/highs.md)** | **MIT** | **LP, MIP, Convex QP** (continuous, integer, boolean) | Production optimization, operations research, portfolio QP | **Bundled default** (zero extra deps, no extra import; subpath API: `@ohtaman/washi/solvers/highs`) |
|
|
2947
2941
|
| **[Pumpkin](docs/solvers/pumpkin.md)** | **MIT** | **CP, Propositional Logic** (bounded integer & boolean only; no `Continuous`) | Non-overlapping scheduling, CP global constraints, discrete `unsatCore` | **Bundled** (`{ solver: "pumpkin" }`, zero extra deps, no extra import; subpath API: `@ohtaman/washi/solvers/pumpkin`) |
|
|
2948
|
-
| **[Z3](docs/solvers/z3.md)** (`z3-solver`) | **MIT** | **SMT, SAT, LP/MIP** (continuous, integer, boolean) | Logical rules with continuous variables or decimal coefficients, mixed continuous/integer `unsatCore` diagnosis | **Optional peer** (`@ohtaman/washi/solvers/z3`, requires `z3-solver`); browsers require a Secure Context (`HTTPS`/`localhost`)
|
|
2942
|
+
| **[Z3](docs/solvers/z3.md)** (`z3-solver`) | **MIT** | **SMT, SAT, LP/MIP** (continuous, integer, boolean) | Logical rules with continuous variables or decimal coefficients, mixed continuous/integer `unsatCore` diagnosis | **Optional peer** (`@ohtaman/washi/solvers/z3`, requires `z3-solver`); browsers require a Secure Context (`HTTPS`/`localhost`), `COOP`/`COEP` headers, and `registerZ3Solver({ z3JsUrl, z3WasmUrl })` |
|
|
2949
2943
|
| **[GLPK](docs/solvers/glpk.md)** (`glpk.js`) | **GPL-3.0** | **LP, MIP** (continuous, integer) | Academic benchmarks, legacy GLPK compatibility | **Optional peer** (`@ohtaman/washi/solvers/glpk`, requires `glpk.js`; note GPL-3.0 license) |
|
|
2950
2944
|
| **Mock** (`MockSolver`) | **MIT** | *Any* (fixed-response stub) | Fast CI unit tests without loading WebAssembly | **Built-in** (`solver: "mock"` or `new MockSolver(...)`) |
|
|
2951
2945
|
|
|
@@ -2995,7 +2989,7 @@ See [Conflict Diagnosis, Validation & Debugging](docs/guide/unsat-core.md) for f
|
|
|
2995
2989
|
|
|
2996
2990
|
**HiGHS** is an open-source mathematical optimization solver started at the University of Edinburgh ([highs.dev](https://highs.dev/) · [ERGO-Code/HiGHS](https://github.com/ERGO-Code/HiGHS)). It solves Linear Programming (LP), Mixed-Integer Programming (MIP), and convex Quadratic Programming (QP) problems.
|
|
2997
2991
|
|
|
2998
|
-
In `@ohtaman/washi`, HiGHS is the built-in default solver under the MIT license. It ships as a single-threaded WebAssembly binary with zero external dependencies, runs in Node.js and
|
|
2992
|
+
In `@ohtaman/washi`, HiGHS is the built-in default solver under the MIT license. It ships as a single-threaded WebAssembly binary with zero external dependencies, runs on the calling thread by default in both Node.js and browsers (with optional Web Worker execution via `useWorker: true`), and requires no `SharedArrayBuffer` or `COOP`/`COEP` headers (see [Cross-Origin Isolation](docs/getting-started/cross-origin.md)).
|
|
2999
2993
|
|
|
3000
2994
|
---
|
|
3001
2995
|
|
|
@@ -3093,7 +3087,7 @@ Pass execution options into `model.solve()` or the `HighsSolver` constructor. Hi
|
|
|
3093
3087
|
| `presolve` | `"on" \| "off" \| "choose"` | Controls model presolve before optimization. |
|
|
3094
3088
|
| `outputFlag` | `boolean` | Enables internal solver logs (`false` by default). |
|
|
3095
3089
|
| `relax` | `boolean` | Solves the continuous LP relaxation of a MIP model without modifying variable declarations. |
|
|
3096
|
-
| `useWorker` | `boolean` | Runs HiGHS in a browser Web Worker
|
|
3090
|
+
| `useWorker` | `boolean` | Runs HiGHS in a browser Web Worker when `true` (`false` by default in both browsers and Node.js). Passing `useWorker: true` in Node.js or environments without browser Web Workers throws an `Error`. |
|
|
3097
3091
|
| `wasmUrl` | `string` | Overrides the `highs.wasm` asset URL for this call (call `setHighsWasmUrl(null)` to reset to the bundled binary). |
|
|
3098
3092
|
| `signal` | `AbortSignal` | Cancels an in-flight solve. In a browser Web Worker, aborts preemptively and returns the last captured MIP incumbent if available; on the main thread or in Node.js, cancels cooperatively. |
|
|
3099
3093
|
| `onProgress` | `(ev) => void` | Receives live elapsed time, primal objective, dual bound, and gap updates. |
|
|
@@ -3143,9 +3137,7 @@ if (model.hasPrimalSolution) {
|
|
|
3143
3137
|
|
|
3144
3138
|
## Web Worker & WASM Configuration in Browsers
|
|
3145
3139
|
|
|
3146
|
-
In browsers
|
|
3147
|
-
|
|
3148
|
-
To run on the main thread (for example, in environments that restrict Web Workers) or serve `highs.wasm` from a custom path, configure `useWorker`, `setHighsWasmUrl`, or `wasmUrl`:
|
|
3140
|
+
In both browsers and Node.js, HiGHS runs on the calling thread by default (`useWorker: false`), so strict CSP (`worker-src 'none'`), `file://`, and sandboxed iframes work without configuration. To offload interactive UIs or long-running solves to a dedicated browser Web Worker (keeping UI rendering responsive and enabling immediate preemptive `AbortSignal` termination), pass `useWorker: true`, or configure `setHighsWasmUrl` / `wasmUrl` to load `highs.wasm` from a custom path:
|
|
3149
3141
|
|
|
3150
3142
|
```typescript
|
|
3151
3143
|
import { Model, expr, maximize } from "@ohtaman/washi";
|
|
@@ -3158,18 +3150,18 @@ const model = new Model({ solver: "highs" });
|
|
|
3158
3150
|
const x = model.continuous("x", { lb: 0, ub: 10 });
|
|
3159
3151
|
model.objective(maximize(expr`${x}`));
|
|
3160
3152
|
|
|
3161
|
-
// Option 1:
|
|
3162
|
-
await model.solve({ useWorker:
|
|
3153
|
+
// Option 1: Enable a browser Web Worker or override wasmUrl per solve call
|
|
3154
|
+
await model.solve({ useWorker: true, wasmUrl: "/assets/wasm/highs.wasm" });
|
|
3163
3155
|
|
|
3164
3156
|
// Option 2: Configure defaults on a HighsSolver instance
|
|
3165
|
-
const
|
|
3166
|
-
solver: new HighsSolver({ useWorker:
|
|
3157
|
+
const workerModel = new Model({
|
|
3158
|
+
solver: new HighsSolver({ useWorker: true }),
|
|
3167
3159
|
});
|
|
3168
3160
|
```
|
|
3169
3161
|
|
|
3170
3162
|
If `highs.wasm` fails to load or returns an HTML error page, WaSHI throws an error with the attempted URL instead of silently falling back to an external CDN.
|
|
3171
3163
|
|
|
3172
|
-
For CSP-restricted pages where `fetch()` is blocked (`connect-src 'none'`), load the self-registering inline WASM pack (`@ohtaman/washi/
|
|
3164
|
+
For CSP-restricted pages where `fetch()` is blocked (`connect-src 'none'`), load the self-registering inline WASM pack (`@ohtaman/washi/solvers/highs-inline` / `solvers/highs-inline.js`, usable via ESM `import` or a classic `<script>` tag) before the first `solve()` or `warmupHighs()` call—this works without `fetch()` (and also works with `{ useWorker: true }` if `worker-src blob:` is permitted). See [Runtime Environments & Deployment](docs/getting-started/runtimes.md#csp-fetch-free).
|
|
3173
3165
|
|
|
3174
3166
|
---
|
|
3175
3167
|
|
|
@@ -3288,7 +3280,7 @@ Pass execution options into `model.solve()`, `model.check()`, or `new PumpkinSol
|
|
|
3288
3280
|
| Option | Type | Description |
|
|
3289
3281
|
| :--- | :--- | :--- |
|
|
3290
3282
|
| `timeLimit` | `number` | Maximum solve or check time in seconds. |
|
|
3291
|
-
| `useWorker` | `boolean` | Runs Pumpkin in a browser Web Worker
|
|
3283
|
+
| `useWorker` | `boolean` | Runs Pumpkin in a browser Web Worker when `true` (`false` by default in both browsers and Node.js). Passing `useWorker: true` in Node.js or environments without browser Web Workers throws an `Error`. |
|
|
3292
3284
|
| `wasmUrl` | `string \| null` | Overrides the `pumpkin.wasm` asset URL (`null` uses the bundled binary; call `setPumpkinWasmUrl()` to set a global URL). |
|
|
3293
3285
|
| `signal` | `AbortSignal` | Cancels an in-flight call. In a browser Web Worker, aborts preemptively and preserves the last captured incumbent if available; on the main thread or in Node.js, cancels cooperatively at checkpoints. |
|
|
3294
3286
|
| `onProgress` | `(ev) => void` | Receives live elapsed time and incumbent objective updates (`solve()` only; ignored by `check()`). |
|
|
@@ -3340,9 +3332,9 @@ Pumpkin solves **bounded integer and boolean** models only. Unsupported variable
|
|
|
3340
3332
|
|
|
3341
3333
|
## Browser Worker & WASM Hosting
|
|
3342
3334
|
|
|
3343
|
-
|
|
3335
|
+
In both browsers and Node.js, Pumpkin runs on the calling thread by default (`useWorker: false`), so `file://` URLs, CSP-restricted environments (`worker-src 'none'`), and sandboxed iframes work out of the box.
|
|
3344
3336
|
|
|
3345
|
-
To
|
|
3337
|
+
To offload solves to a dedicated browser Web Worker (or serve `pumpkin.wasm` from a custom URL):
|
|
3346
3338
|
|
|
3347
3339
|
```typescript
|
|
3348
3340
|
import { Model, expr, minimize } from "@ohtaman/washi";
|
|
@@ -3355,16 +3347,16 @@ const model = new Model({ solver: "pumpkin" });
|
|
|
3355
3347
|
const x = model.integer("x", { lb: 0, ub: 10 });
|
|
3356
3348
|
model.objective(minimize(expr`${x}`));
|
|
3357
3349
|
|
|
3358
|
-
// Option 1:
|
|
3359
|
-
await model.solve({ useWorker:
|
|
3350
|
+
// Option 1: Opt into browser Web Worker execution for a single call
|
|
3351
|
+
await model.solve({ useWorker: true });
|
|
3360
3352
|
|
|
3361
3353
|
// Option 2: Configure defaults on a PumpkinSolver instance
|
|
3362
|
-
const
|
|
3354
|
+
const workerModel = new Model({ solver: new PumpkinSolver({ useWorker: true }) });
|
|
3363
3355
|
```
|
|
3364
3356
|
|
|
3365
3357
|
If `pumpkin.wasm` fails to load or returns an HTML fallback page, WaSHI throws an error with the attempted URL instead of silently falling back to a CDN.
|
|
3366
3358
|
|
|
3367
|
-
For CSP-restricted pages where `fetch()` is blocked (`connect-src 'none'`), load the self-registering inline WASM pack (`@ohtaman/washi/
|
|
3359
|
+
For CSP-restricted pages where `fetch()` is blocked (`connect-src 'none'`), load the self-registering inline WASM pack (`@ohtaman/washi/solvers/pumpkin-inline` / `solvers/pumpkin-inline.js`, usable via ESM `import` or a classic `<script>` tag) before the first `solve()`, `check()`, or `warmupPumpkin()` call—this works without `fetch()` (and also works with `{ useWorker: true }` if `worker-src blob:` is permitted). See [Runtime Environments & Deployment](docs/getting-started/runtimes.md#csp-fetch-free).
|
|
3368
3360
|
|
|
3369
3361
|
---
|
|
3370
3362
|
|
|
@@ -3464,7 +3456,7 @@ Z3 validates options strictly and throws a runtime `Error` when unsupported opti
|
|
|
3464
3456
|
|
|
3465
3457
|
### Supported Options
|
|
3466
3458
|
|
|
3467
|
-
- `z3JsUrl` / `z3WasmUrl`:
|
|
3459
|
+
- `z3JsUrl` / `z3WasmUrl`: Required in browser environments unless configured via `registerZ3Solver({ z3JsUrl, z3WasmUrl })` (override per call if needed).
|
|
3468
3460
|
- `signal`: `AbortSignal` checked **before** Z3 starts solving (pre-solve cancellation only; it cannot interrupt an active Z3 call).
|
|
3469
3461
|
- `onProgress`: Applies to `solve()` only (ignored by `check()`). Invoked once after `solve()` completes with elapsed time and, when a solution exists, the final objective value.
|
|
3470
3462
|
|
|
@@ -3484,6 +3476,23 @@ In browsers, Z3 uses `SharedArrayBuffer` and Emscripten pthreads. Your page must
|
|
|
3484
3476
|
|
|
3485
3477
|
1. **Secure Context**: Served over `HTTPS` or `localhost`.
|
|
3486
3478
|
2. **Cross-Origin Isolation (`COOP`/`COEP`)**: Document responses must send `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`.
|
|
3479
|
+
3. **Explicit Asset Registration**: `@ohtaman/washi` does not bundle `z3-solver` or `z3-built.{js,wasm}`. Configure browser asset URLs once via `registerZ3Solver({ z3JsUrl, z3WasmUrl })` (Node.js requires zero configuration):
|
|
3480
|
+
|
|
3481
|
+
```typescript
|
|
3482
|
+
import { registerZ3Solver } from "@ohtaman/washi/solvers/z3";
|
|
3483
|
+
|
|
3484
|
+
// Bundlers (Vite dev & build, webpack 5 — no optimizeDeps.exclude needed):
|
|
3485
|
+
registerZ3Solver({
|
|
3486
|
+
z3JsUrl: new URL("z3-solver/build/z3-built.js", import.meta.url).href,
|
|
3487
|
+
z3WasmUrl: new URL("z3-solver/build/z3-built.wasm", import.meta.url).href,
|
|
3488
|
+
});
|
|
3489
|
+
|
|
3490
|
+
// Or explicit CDN / self-hosted static URLs (pair with an Import Map for "z3-solver" if not using a bundler):
|
|
3491
|
+
registerZ3Solver({
|
|
3492
|
+
z3JsUrl: "https://cdn.jsdelivr.net/npm/z3-solver/build/z3-built.js",
|
|
3493
|
+
z3WasmUrl: "https://cdn.jsdelivr.net/npm/z3-solver/build/z3-built.wasm",
|
|
3494
|
+
});
|
|
3495
|
+
```
|
|
3487
3496
|
|
|
3488
3497
|
See the [Cross-Origin Isolation Guide](docs/getting-started/cross-origin.md) for server setup. If you cannot configure these headers and only need bounded integers and booleans, use [Pumpkin](docs/solvers/pumpkin.md) instead.
|
|
3489
3498
|
|
|
@@ -3555,6 +3564,8 @@ console.log("Objective:", model.objectiveValue); // 40
|
|
|
3555
3564
|
console.log("Shadow price:", cap.dual); // 2
|
|
3556
3565
|
```
|
|
3557
3566
|
|
|
3567
|
+
In Node.js and Vite/webpack bundlers, `import "@ohtaman/washi/solvers/glpk"` resolves `glpk.js` automatically. When loading `dist/solvers/glpk.js` directly in HTML without a bundler, map `"glpk.js"` via `<script type="importmap">` (e.g. `https://cdn.jsdelivr.net/npm/glpk.js/+esm` or `https://esm.sh/glpk.js`).
|
|
3568
|
+
|
|
3558
3569
|
---
|
|
3559
3570
|
|
|
3560
3571
|
## Solver Options & Execution Model
|
|
@@ -4096,20 +4107,15 @@ To publish your solver as an independent npm package (such as `@my-org/washi-sol
|
|
|
4096
4107
|
"name": "@my-org/washi-solver-cplex",
|
|
4097
4108
|
"version": "1.0.0",
|
|
4098
4109
|
"type": "module",
|
|
4099
|
-
"main": "./dist/
|
|
4110
|
+
"main": "./dist/index.js",
|
|
4100
4111
|
"types": "./dist/types/index.d.ts",
|
|
4101
4112
|
"exports": {
|
|
4102
4113
|
".": {
|
|
4103
4114
|
"types": "./dist/types/index.d.ts",
|
|
4104
|
-
"
|
|
4105
|
-
"default": "./dist/
|
|
4106
|
-
},
|
|
4107
|
-
"./browser": {
|
|
4108
|
-
"types": "./dist/types/index.d.ts",
|
|
4109
|
-
"import": "./dist/browser/index.js",
|
|
4110
|
-
"default": "./dist/browser/index.js"
|
|
4115
|
+
"node": "./dist/index.node.js",
|
|
4116
|
+
"default": "./dist/index.js"
|
|
4111
4117
|
},
|
|
4112
|
-
"./
|
|
4118
|
+
"./index.min.js": "./dist/index.min.js"
|
|
4113
4119
|
},
|
|
4114
4120
|
"peerDependencies": {
|
|
4115
4121
|
"@ohtaman/washi": ">=0.8.0"
|