@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.txt
CHANGED
|
@@ -50,51 +50,52 @@ import "@ohtaman/washi/solvers/glpk";
|
|
|
50
50
|
|
|
51
51
|
### Browser ESM & Classic Script Tags
|
|
52
52
|
|
|
53
|
-
Classic `<script>` tags load immediately invoked function expression (`IIFE`) bundles that attach a global namespace to `window` (optional solver plugins
|
|
53
|
+
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/`:
|
|
54
54
|
|
|
55
55
|
| Solver | Browser ESM (`<script type="module">`) | Classic `<script>` IIFE |
|
|
56
56
|
| --- | --- | --- |
|
|
57
57
|
| **Core (HiGHS & Pumpkin)** | `import { Model, expr, maximize } from "./washi/washi.js";` | `<script src="./washi/washi.min.js"></script>` (global `Washi`) |
|
|
58
58
|
| **HiGHS** *(subpath API)* | `import { HighsSolver, setHighsWasmUrl } from "./washi/solvers/highs.js";` | Bundled in `washi.min.js` (pass `{ wasmUrl }` per call) |
|
|
59
|
-
| **HiGHS Inline WASM** *(no `fetch`)* | `import "./washi/solvers/highs-inline.js";` | `<script src="./washi/solvers/highs-inline.js"></script>` (`@ohtaman/washi/
|
|
59
|
+
| **HiGHS Inline WASM** *(no `fetch`)* | `import "./washi/solvers/highs-inline.js";` | `<script src="./washi/solvers/highs-inline.js"></script>` (`@ohtaman/washi/solvers/highs-inline`) |
|
|
60
60
|
| **Pumpkin** *(subpath API)* | `import { PumpkinSolver, setPumpkinWasmUrl } from "./washi/solvers/pumpkin.js";` | Bundled in `washi.min.js` (pass `{ wasmUrl }` per call) |
|
|
61
|
-
| **Pumpkin Inline WASM** *(no `fetch`)* | `import "./washi/solvers/pumpkin-inline.js";` | `<script src="./washi/solvers/pumpkin-inline.js"></script>` (`@ohtaman/washi/
|
|
62
|
-
| **GLPK** *(optional)* | `import "./washi/solvers/glpk.js";`
|
|
63
|
-
| **Z3** *(optional)* | `import "./washi/solvers/z3.js";`
|
|
61
|
+
| **Pumpkin Inline WASM** *(no `fetch`)* | `import "./washi/solvers/pumpkin-inline.js";` | `<script src="./washi/solvers/pumpkin-inline.js"></script>` (`@ohtaman/washi/solvers/pumpkin-inline`) |
|
|
62
|
+
| **GLPK** *(optional peer)* | `import "./washi/solvers/glpk.js";` *(with Import Map for `"glpk.js"`)* | — *(use ESM + Import Map or a bundler)* |
|
|
63
|
+
| **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)* |
|
|
64
64
|
|
|
65
65
|
### WebAssembly Asset & Runtime Rules
|
|
66
66
|
|
|
67
67
|
#### Bundled WASM & Custom Asset URLs
|
|
68
68
|
|
|
69
|
-
- **Automatic resolution**: In Node.js and bundler builds, WaSHI resolves `.wasm` assets under `solvers/` relative to the module with no CDN fallback.
|
|
70
|
-
- **Browser self-hosting**: Deploy `dist
|
|
71
|
-
- **
|
|
69
|
+
- **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`.
|
|
70
|
+
- **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.
|
|
71
|
+
- **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 }`.
|
|
72
|
+
- **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.
|
|
72
73
|
|
|
73
74
|
#### Fetch-Free Loading in CSP-Restricted Pages (Inline WASM)
|
|
74
75
|
|
|
75
|
-
- **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
|
|
76
|
-
- **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.
|
|
76
|
+
- **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.
|
|
77
|
+
- **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.
|
|
77
78
|
- **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.
|
|
78
|
-
- **
|
|
79
|
+
- **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.
|
|
79
80
|
|
|
80
81
|
```html
|
|
81
|
-
<!-- Recommended: ESM (<script type="module">)
|
|
82
|
+
<!-- Recommended: ESM (<script type="module">) -->
|
|
82
83
|
<!-- Works across Claude Artifacts, ChatGPT/Codex inline visualizations, Gemini Canvas, Google Sites & file:// -->
|
|
83
84
|
<script type="module">
|
|
84
|
-
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
85
|
-
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
86
|
-
// import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
85
|
+
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.js";
|
|
86
|
+
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/highs-inline.js";
|
|
87
|
+
// import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/pumpkin-inline.js";
|
|
87
88
|
|
|
88
89
|
const m = new Model("CspFreeEsm");
|
|
89
90
|
const x = m.integer("x", { lb: 0 });
|
|
90
91
|
m.objective(maximize(x));
|
|
91
92
|
m.constraint(expr`${x} <= 10`, "cap");
|
|
92
|
-
await m.solve({
|
|
93
|
+
await m.solve({ timeLimit: 5 }); // Default calling thread works cross-origin; use same-origin ESM or washi.min.js for { useWorker: true }
|
|
93
94
|
</script>
|
|
94
95
|
|
|
95
96
|
<!-- Classic <script> fallback (prefer ESM above in dynamically injected sandboxes) -->
|
|
96
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
97
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
97
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.min.js"></script>
|
|
98
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/highs-inline.js"></script>
|
|
98
99
|
<script>
|
|
99
100
|
(async () => {
|
|
100
101
|
const { Model, expr, maximize } = Washi;
|
|
@@ -102,7 +103,7 @@ Classic `<script>` tags load immediately invoked function expression (`IIFE`) bu
|
|
|
102
103
|
const x = m.integer("x", { lb: 0 });
|
|
103
104
|
m.objective(maximize(x));
|
|
104
105
|
m.constraint(expr`${x} <= 10`, "cap");
|
|
105
|
-
await m.solve({
|
|
106
|
+
await m.solve({ timeLimit: 5 });
|
|
106
107
|
})();
|
|
107
108
|
</script>
|
|
108
109
|
```
|
|
@@ -118,9 +119,9 @@ Classic `<script>` tags load immediately invoked function expression (`IIFE`) bu
|
|
|
118
119
|
|
|
119
120
|
#### Web Workers & Cancellation (`AbortSignal`)
|
|
120
121
|
|
|
121
|
-
- **Default
|
|
122
|
-
- **Worker cancellation**: Pre-solve cancellation (`signal.aborted`) works on all solvers, and `{ signal }` terminates in-flight HiGHS and Pumpkin Workers immediately.
|
|
123
|
-
- **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.
|
|
122
|
+
- **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).
|
|
123
|
+
- **Worker cancellation**: Pre-solve cancellation (`signal.aborted`) works on all solvers, and `{ signal }` with `{ useWorker: true }` terminates in-flight HiGHS and Pumpkin Workers immediately.
|
|
124
|
+
- **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.
|
|
124
125
|
|
|
125
126
|
#### Solver Capabilities, Options, & Validation Errors
|
|
126
127
|
|
package/package.json
CHANGED
|
@@ -1,83 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohtaman/washi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "WaSHI: TypeScript & JavaScript algebraic modeler for Mathematical Optimization & Constraint Programming (LP, MILP, QP, CP, SMT) powered by WebAssembly (HiGHS, Pumpkin, Z3, GLPK)",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/
|
|
7
|
-
"module": "./dist/
|
|
6
|
+
"main": "./dist/washi.js",
|
|
7
|
+
"module": "./dist/washi.js",
|
|
8
8
|
"types": "./dist/types/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/types/index.d.ts",
|
|
12
|
-
"
|
|
13
|
-
"default": "./dist/
|
|
12
|
+
"node": "./dist/washi.node.js",
|
|
13
|
+
"default": "./dist/washi.js"
|
|
14
14
|
},
|
|
15
|
+
"./washi.min.js": "./dist/washi.min.js",
|
|
15
16
|
"./solvers/highs": {
|
|
16
17
|
"types": "./dist/types/modeler/solvers/highs/index.d.ts",
|
|
17
|
-
"
|
|
18
|
-
"default": "./dist/
|
|
18
|
+
"node": "./dist/solvers/highs.node.js",
|
|
19
|
+
"default": "./dist/solvers/highs.js"
|
|
19
20
|
},
|
|
20
|
-
"./solvers/highs.wasm": "./dist/
|
|
21
|
-
"./solvers/
|
|
22
|
-
"types": "./dist/types/modeler/solvers/pumpkin/index.d.ts",
|
|
23
|
-
"import": "./dist/lib/solvers/pumpkin.js",
|
|
24
|
-
"default": "./dist/lib/solvers/pumpkin.js"
|
|
25
|
-
},
|
|
26
|
-
"./solvers/pumpkin.wasm": "./dist/lib/solvers/pumpkin.wasm",
|
|
27
|
-
"./solvers/z3": {
|
|
28
|
-
"types": "./dist/types/modeler/solvers/z3/index.d.ts",
|
|
29
|
-
"import": "./dist/lib/solvers/z3.js",
|
|
30
|
-
"default": "./dist/lib/solvers/z3.js"
|
|
31
|
-
},
|
|
32
|
-
"./solvers/z3-built.js": "./dist/lib/solvers/z3-built.js",
|
|
33
|
-
"./solvers/z3-built.wasm": "./dist/lib/solvers/z3-built.wasm",
|
|
34
|
-
"./solvers/glpk": {
|
|
35
|
-
"types": "./dist/types/modeler/solvers/glpk/index.d.ts",
|
|
36
|
-
"import": "./dist/lib/solvers/glpk.js",
|
|
37
|
-
"default": "./dist/lib/solvers/glpk.js"
|
|
38
|
-
},
|
|
39
|
-
"./browser": {
|
|
40
|
-
"types": "./dist/types/index.d.ts",
|
|
41
|
-
"import": "./dist/browser/washi.js",
|
|
42
|
-
"default": "./dist/browser/washi.js"
|
|
43
|
-
},
|
|
44
|
-
"./browser/washi.min.js": "./dist/browser/washi.min.js",
|
|
45
|
-
"./browser/solvers/highs": {
|
|
46
|
-
"types": "./dist/types/modeler/solvers/highs/index.d.ts",
|
|
47
|
-
"import": "./dist/browser/solvers/highs.js",
|
|
48
|
-
"default": "./dist/browser/solvers/highs.js"
|
|
49
|
-
},
|
|
50
|
-
"./browser/solvers/highs-inline": {
|
|
21
|
+
"./solvers/highs.wasm": "./dist/solvers/highs.wasm",
|
|
22
|
+
"./solvers/highs-inline": {
|
|
51
23
|
"types": "./dist/types/modeler/solvers/inline-pack.d.ts",
|
|
52
|
-
"
|
|
53
|
-
"default": "./dist/browser/solvers/highs-inline.js"
|
|
24
|
+
"default": "./dist/solvers/highs-inline.js"
|
|
54
25
|
},
|
|
55
|
-
"./
|
|
26
|
+
"./solvers/pumpkin": {
|
|
56
27
|
"types": "./dist/types/modeler/solvers/pumpkin/index.d.ts",
|
|
57
|
-
"
|
|
58
|
-
"default": "./dist/
|
|
28
|
+
"node": "./dist/solvers/pumpkin.node.js",
|
|
29
|
+
"default": "./dist/solvers/pumpkin.js"
|
|
59
30
|
},
|
|
60
|
-
"./
|
|
31
|
+
"./solvers/pumpkin.wasm": "./dist/solvers/pumpkin.wasm",
|
|
32
|
+
"./solvers/pumpkin-inline": {
|
|
61
33
|
"types": "./dist/types/modeler/solvers/inline-pack.d.ts",
|
|
62
|
-
"
|
|
63
|
-
"default": "./dist/browser/solvers/pumpkin-inline.js"
|
|
34
|
+
"default": "./dist/solvers/pumpkin-inline.js"
|
|
64
35
|
},
|
|
65
|
-
"./
|
|
36
|
+
"./solvers/z3": {
|
|
66
37
|
"types": "./dist/types/modeler/solvers/z3/index.d.ts",
|
|
67
|
-
"
|
|
68
|
-
"default": "./dist/browser/solvers/z3.js"
|
|
38
|
+
"default": "./dist/solvers/z3.js"
|
|
69
39
|
},
|
|
70
|
-
"./
|
|
71
|
-
"./browser/solvers/glpk": {
|
|
40
|
+
"./solvers/glpk": {
|
|
72
41
|
"types": "./dist/types/modeler/solvers/glpk/index.d.ts",
|
|
73
|
-
"
|
|
74
|
-
"default": "./dist/
|
|
75
|
-
}
|
|
76
|
-
"./browser/solvers/glpk.min.js": "./dist/browser/solvers/glpk.min.js"
|
|
42
|
+
"node": "./dist/solvers/glpk.node.js",
|
|
43
|
+
"default": "./dist/solvers/glpk.js"
|
|
44
|
+
}
|
|
77
45
|
},
|
|
78
46
|
"files": [
|
|
79
|
-
"dist
|
|
80
|
-
"dist/
|
|
47
|
+
"dist/*.js",
|
|
48
|
+
"dist/solvers",
|
|
81
49
|
"dist/types",
|
|
82
50
|
"docs/getting-started/ai-agents.md",
|
|
83
51
|
"docs/getting-started",
|
|
@@ -100,9 +68,9 @@
|
|
|
100
68
|
"build:pumpkin-wasm": "bash scripts/build-pumpkin-wasm.sh",
|
|
101
69
|
"build:demo": "vite build",
|
|
102
70
|
"build:types": "node -e \"import('node:fs').then(fs => fs.rmSync('dist/types', { recursive: true, force: true }))\" && tsc -p tsconfig.lib.json",
|
|
103
|
-
"build:
|
|
71
|
+
"build:dist": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && node scripts/build-dist.mjs",
|
|
104
72
|
"build:llms": "node scripts/generate-llms.mjs",
|
|
105
|
-
"build": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && npm run build:types && npm run build:
|
|
73
|
+
"build": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && npm run build:types && npm run build:dist && npm run build:demo",
|
|
106
74
|
"build:site": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && node scripts/build-site.mjs",
|
|
107
75
|
"docs:dev": "vitepress dev docs",
|
|
108
76
|
"docs:build": "vitepress build docs && node scripts/generate-llms.mjs",
|
|
@@ -110,9 +78,8 @@
|
|
|
110
78
|
"preview": "vite preview",
|
|
111
79
|
"test": "vitest run",
|
|
112
80
|
"test:e2e": "RUN_E2E=1 vitest run test/e2e.test.ts",
|
|
113
|
-
"prepublishOnly": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && npm run build:types && npm run build:
|
|
114
|
-
"
|
|
115
|
-
"test:distribution": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && npm run build:types && npm run build:lib && npm run build:browser && npm run build:llms && node --experimental-vm-modules scripts/check-distribution.mjs",
|
|
81
|
+
"prepublishOnly": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && npm run build:types && npm run build:dist && npm run build:llms",
|
|
82
|
+
"test:distribution": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && npm run build:types && npm run build:dist && npm run build:llms && node --experimental-vm-modules scripts/check-distribution.mjs",
|
|
116
83
|
"test:demo": "BASE_URL=/ npm run build:demo && node scripts/check-demo-browser.mjs",
|
|
117
84
|
"test:site": "npm run build:site && REQUIRE_SITE_DIST=1 vitest run test/site-seo.test.ts",
|
|
118
85
|
"bench": "node scripts/run-benchmarks.mjs"
|
|
@@ -190,6 +157,6 @@
|
|
|
190
157
|
"webpack": "^5.111.1",
|
|
191
158
|
"z3-solver": "^5.2.0"
|
|
192
159
|
},
|
|
193
|
-
"jsdelivr": "./dist/
|
|
194
|
-
"unpkg": "./dist/
|
|
160
|
+
"jsdelivr": "./dist/washi.min.js",
|
|
161
|
+
"unpkg": "./dist/washi.min.js"
|
|
195
162
|
}
|
package/skills/washi/SKILL.md
CHANGED
|
@@ -23,10 +23,11 @@ Select the solver engine and execution method that match the problem class:
|
|
|
23
23
|
| **Decomposition** (`solveColumnGeneration`, `solveBenders`, `m.relax()`) | **HiGHS** (default) or **GLPK** (required for LP duals / `relax: true` in `solveColumnGeneration`, `m.relax()`, and auto-cut `sub.link()`; `Pumpkin` and `Z3` lack LP duals) | Bundled for HiGHS; `import "@ohtaman/washi/solvers/glpk"` for GLPK | `await master.solveColumnGeneration(...)` / `await master.solveBenders(...)` |
|
|
24
24
|
|
|
25
25
|
- **Browser runtime notes**:
|
|
26
|
-
- **HiGHS** and **Pumpkin** load bundled `.wasm`
|
|
26
|
+
- **HiGHS** and **Pumpkin** load bundled `.wasm` assets relative to the bundle (no external CDN fallback) and run on the calling thread by default (`useWorker: false`) across both browsers and Node.js. Pass `{ useWorker: true }` in browsers to offload interactive UIs or long-running solves to a Web Worker (throws in Node.js or when browser Web Workers are unavailable).
|
|
27
27
|
- **HiGHS**, **Pumpkin**, and **GLPK** all run without `COOP`/`COEP` headers (**GLPK** is an optional peer dependency that rejects `useWorker: true`).
|
|
28
|
-
- **Z3** uses `SharedArrayBuffer` pthreads and requires `window.isSecureContext === true
|
|
29
|
-
- **Single-file / CSP-restricted AI sandboxes (blocked `fetch()`)**: Environments such as Claude.ai Artifacts (edit & published links), ChatGPT inline visualizations, and Codex inline visualizations allow CDN scripts (`script-src`) while blocking `fetch()` (`connect-src 'none'`)
|
|
28
|
+
- **Z3** uses `SharedArrayBuffer` pthreads and requires `window.isSecureContext === true`, `window.crossOriginIsolated === true` (`Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`), and explicit browser asset URLs via `registerZ3Solver({ z3JsUrl, z3WasmUrl })` (or per-call options), since `z3-solver` / `z3-built.{js,wasm}` are not bundled inside `@ohtaman/washi`.
|
|
29
|
+
- **Single-file / CSP-restricted AI sandboxes (blocked `fetch()`)**: Environments such as Claude.ai Artifacts (edit & published links), ChatGPT inline visualizations, and Codex inline visualizations allow CDN scripts (`script-src`) while blocking `fetch()` (`connect-src 'none'`). Prefer **ESM `<script type="module">` + `solvers/highs-inline.js` / `solvers/pumpkin-inline.js`** (with a `timeLimit` on non-trivial solves) before the first `solve()` / `check()` call (see Recipe 5 below). Note that embedded previews omitting `'wasm-unsafe-eval'` from `script-src` (such as Antigravity's HTML artifact preview) cannot compile WebAssembly; export `.html` and open in Chrome/Safari or via a local server.
|
|
30
|
+
- **Zero-build online single-file HTML (`file://` or static page)**: When the user asks for a lightweight no-build HTML file that runs online (including double-clicking via `file://`), emit a single `.html` importing `https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.js` (ESM) or `<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.min.js"></script>` (IIFE) with default `useWorker: false`—no build script, local server, or `*-inline.js` pack is required.
|
|
30
31
|
- **Single-file offline HTML + npm packages (`file://`)**: To bundle `@ohtaman/washi` (HiGHS and/or Pumpkin) alongside arbitrary third-party npm packages (React, Chart.js, KaTeX, Tailwind) into one zero-network, double-clickable offline `file://` HTML file using Vite + `vite-plugin-singlefile` + gzipped WASM, follow [`references/single-html.md`](./references/single-html.md) (`node_modules/@ohtaman/washi/skills/washi/references/single-html.md`).
|
|
31
32
|
|
|
32
33
|
---
|
|
@@ -259,17 +260,17 @@ export async function solveAndDiagnoseWithPumpkin() {
|
|
|
259
260
|
|
|
260
261
|
### Recipe 5: Single-File HTML & CSP-Restricted AI Sandboxes (No `fetch`)
|
|
261
262
|
|
|
262
|
-
Hosted AI preview environments—including **Claude.ai Artifacts** (edit and published links), **ChatGPT inline visualizations**, and **Codex inline visualizations**—allow CDN scripts (`script-src`) while blocking `.wasm` `fetch()` (`connect-src 'none'`)
|
|
263
|
+
Hosted AI preview environments—including **Claude.ai Artifacts** (edit and published links), **ChatGPT inline visualizations**, and **Codex inline visualizations**—allow CDN scripts (`script-src`) while blocking `.wasm` `fetch()` (`connect-src 'none'`). Meanwhile, **Gemini Canvas** and **Google Sites** allow both `fetch()` and Web Workers (use classic `dist/washi.min.js` for cross-origin `{ useWorker: true }`, or keep default `useWorker: false` with ESM `dist/washi.js`), while embedded previews that omit `'wasm-unsafe-eval'` from `script-src` (such as Antigravity's HTML artifact preview) cannot run WebAssembly at all.
|
|
263
264
|
|
|
264
|
-
Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtaman/washi/
|
|
265
|
+
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** the first `solve()`, `check()`, or `warmup*()` call—no manual base64 decoding or binary setters are needed, and the same `*-inline.js` file works in both ESM and classic `<script>` mode (use default `useWorker: false` for cross-origin CDN ESM, or `dist/washi.min.js` if you need cross-origin `{ useWorker: true }`):
|
|
265
266
|
|
|
266
267
|
```html
|
|
267
|
-
<!-- Recommended: ESM (<script type="module">)
|
|
268
|
+
<!-- Recommended: ESM (<script type="module">) -->
|
|
268
269
|
<!-- Works across Claude Artifacts, ChatGPT/Codex inline visualizations, Gemini Canvas, Google Sites & file:// -->
|
|
269
270
|
<script type="module">
|
|
270
|
-
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
271
|
-
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
272
|
-
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
271
|
+
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.js";
|
|
272
|
+
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/highs-inline.js";
|
|
273
|
+
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/pumpkin-inline.js";
|
|
273
274
|
|
|
274
275
|
const m = new Model("CspSafeMIP");
|
|
275
276
|
const x = m.integer("x", { lb: 0 });
|
|
@@ -277,18 +278,18 @@ Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtam
|
|
|
277
278
|
m.objective(maximize(expr`30 * ${x} + 50 * ${y}`));
|
|
278
279
|
m.constraint(expr`${x} + 2 * ${y} <= 40`, "wood");
|
|
279
280
|
m.constraint(expr`2 * ${x} + ${y} <= 50`, "labor");
|
|
280
|
-
await m.solve({
|
|
281
|
+
await m.solve({ timeLimit: 5 });
|
|
281
282
|
|
|
282
283
|
const cp = new Model("CspSafeCP", { solver: "pumpkin" });
|
|
283
284
|
const k = cp.integer("k", { lb: 0, ub: 6 });
|
|
284
285
|
cp.objective(maximize(expr`10 * ${k}`));
|
|
285
|
-
await cp.solve({
|
|
286
|
+
await cp.solve({ timeLimit: 5 });
|
|
286
287
|
</script>
|
|
287
288
|
|
|
288
289
|
<!-- Classic <script> fallback (prefer ESM above: dynamically injected sandboxes can race external <script src> tags) -->
|
|
289
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
290
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
291
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
290
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.min.js"></script>
|
|
291
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/highs-inline.js"></script>
|
|
292
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/pumpkin-inline.js"></script>
|
|
292
293
|
<script>
|
|
293
294
|
(async () => {
|
|
294
295
|
const { Model, expr, maximize } = Washi;
|
|
@@ -296,15 +297,14 @@ Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtam
|
|
|
296
297
|
const x = m.integer("x", { lb: 0 });
|
|
297
298
|
m.objective(maximize(x));
|
|
298
299
|
m.constraint(expr`${x} <= 10`, "cap");
|
|
299
|
-
await m.solve({
|
|
300
|
+
await m.solve({ timeLimit: 5 }); // Zero fetch(), zero Blob URLs, zero Workers
|
|
300
301
|
})();
|
|
301
302
|
</script>
|
|
302
303
|
```
|
|
303
304
|
|
|
304
305
|
- **Why ESM (`<script type="module">`) is recommended over Classic `<script>`**: In dynamically injected sandboxes (such as ChatGPT inline visualizations), classic `<script src="...">` tags may race with subsequent inline `<script>` blocks or miss `window` `load`, whereas ESM `import` strictly awaits all module dependencies before running.
|
|
305
|
-
-
|
|
306
|
-
- **
|
|
307
|
-
- **Other solvers**: **GLPK** (`solvers/glpk.js`) already embeds its WASM inline and requires no extra setup (GPL-3.0). **Z3** requires `SharedArrayBuffer` / `COOP`+`COEP` headers and is out of scope for standalone CSP-restricted artifacts.
|
|
306
|
+
- **Initialization semantics without `fetch()`**: Load `*-inline.js` before the first `solve()`, `check()`, or `warmup*()` (order between core and `*-inline.js` before init does not matter; late registration after first init is ignored to keep main-thread and Worker behavior consistent). When `{ useWorker: true }` is enabled, WaSHI passes the embedded bytes via `postMessage` once per Worker instance without calling `fetch()`.
|
|
307
|
+
- **Other solvers**: **GLPK** (`solvers/glpk.js`) is an unbundled optional peer whose `glpk.js` package embeds its own WASM inline. **Z3** requires `z3-solver` (`z3JsUrl` / `z3WasmUrl`) plus `SharedArrayBuffer` / `COOP`+`COEP` headers and is out of scope for standalone CSP-restricted artifacts.
|
|
308
308
|
|
|
309
309
|
---
|
|
310
310
|
|
|
@@ -9,7 +9,7 @@ Build self-contained, single-file `index.html` applications that bundle `@ohtama
|
|
|
9
9
|
A standard `vite-plugin-singlefile` build already inlines JS modules, CSS, web fonts, and images from any npm dependency (`react`, `katex`, `chart.js`, `tailwindcss`, etc.) into one HTML file. WaSHI adds three extra single-file constraints that standard plugins do not handle alone:
|
|
10
10
|
|
|
11
11
|
1. **Blocked `fetch()` on `file://`**: Browsers block relative `fetch("./highs.wasm")` requests on opaque `file://` origins. Embed compressed WASM inside inert `<script type="text/plain">` tags and hydrate via `FileReader.readAsDataURL()` (`data:application/wasm;base64,...`) passed to `setHighsWasmUrl()` / `setPumpkinWasmUrl()`. Avoid `URL.createObjectURL()` because opaque `file://` origins produce restricted `blob:null/...` URLs.
|
|
12
|
-
2. **No external Worker scripts**:
|
|
12
|
+
2. **No external Worker scripts**: WaSHI defaults to calling-thread execution (`useWorker: false`); also intercept WaSHI's internal solver asset and worker-factory modules during bundling so Vite emits zero sidecar `.wasm` or `*-worker.js` files, and `{ useWorker: true }` throws cleanly rather than expecting missing sidecar workers.
|
|
13
13
|
3. **Small file size via gzip**: Raw Base64-encoded `.wasm` in JS swells the HTML past 8.5 MiB and slows script parsing. Gzipping (`level: 9`) into inert `<script type="text/plain" id="washi-wasm-*-gz">` tags shrinks the combined HiGHS + Pumpkin payload to roughly **1.8–2.4 MiB Base64** and decompresses in milliseconds via standard `DecompressionStream("gzip")`.
|
|
14
14
|
|
|
15
15
|
## Supported Solvers & Hard Exclusions
|
|
@@ -20,7 +20,7 @@ A standard `vite-plugin-singlefile` build already inlines JS modules, CSS, web f
|
|
|
20
20
|
- WaSHI decomposition (`benders`, `dantzigWolfe`), `m.verify()`, and arbitrary third-party npm packages
|
|
21
21
|
- **Unsupported in single-file offline HTML**:
|
|
22
22
|
- **Z3** (`@ohtaman/washi/solvers/z3`): Requires `SharedArrayBuffer` pthreads, which demand a secure context (`https://` or `localhost`) and `Cross-Origin-Opener-Policy: same-origin` + `Cross-Origin-Embedder-Policy: require-corp` (`COOP`/`COEP`) response headers. Z3 cannot run over `file://` or in a single headerless HTML file.
|
|
23
|
-
- **GLPK** (`glpk.js`): Optional peer dependency not bundled by default; exclude it in offline single-file builds unless you intentionally install and inline `glpk.js
|
|
23
|
+
- **GLPK** (`glpk.js`): Optional peer dependency not bundled by default; exclude it in offline single-file builds unless you intentionally install and inline `glpk.js`.
|
|
24
24
|
|
|
25
25
|
## Project Setup
|
|
26
26
|
|
|
@@ -107,9 +107,6 @@ export function washiSingleHtmlWasmPlugin(options = {}) {
|
|
|
107
107
|
) {
|
|
108
108
|
return `${VIRTUAL_PREFIX}pumpkin-node-runtime`;
|
|
109
109
|
}
|
|
110
|
-
if (source === "./z3-assets.js" || source.endsWith("/z3-assets.js") || fromSolverDir("z3", "assets")) {
|
|
111
|
-
return `${VIRTUAL_PREFIX}z3-assets`;
|
|
112
|
-
}
|
|
113
110
|
if (source === "z3-solver") {
|
|
114
111
|
return `${VIRTUAL_PREFIX}z3-solver`;
|
|
115
112
|
}
|
|
@@ -132,9 +129,9 @@ export function washiSingleHtmlWasmPlugin(options = {}) {
|
|
|
132
129
|
case "pumpkin-assets":
|
|
133
130
|
return "export function getBundledPumpkinWasmUrl() { return ''; }\n";
|
|
134
131
|
case "highs-worker-factory":
|
|
135
|
-
return "export function createHighsWorker() { throw new Error('Workers are disabled in single-file offline builds; pass { useWorker: false }.'); }\n";
|
|
132
|
+
return "export function createHighsWorker() { throw new Error('Workers are disabled in single-file offline builds; omit useWorker or pass { useWorker: false }.'); }\n";
|
|
136
133
|
case "pumpkin-worker-factory":
|
|
137
|
-
return "export function createPumpkinWorker() { throw new Error('Workers are disabled in single-file offline builds; pass { useWorker: false }.'); }\n";
|
|
134
|
+
return "export function createPumpkinWorker() { throw new Error('Workers are disabled in single-file offline builds; omit useWorker or pass { useWorker: false }.'); }\n";
|
|
138
135
|
case "highs-node-runtime":
|
|
139
136
|
return "export async function loadNodeHighs() { throw new Error('Node runtime is unavailable in browser builds.'); }\n";
|
|
140
137
|
case "pumpkin-node-runtime":
|
|
@@ -142,8 +139,6 @@ export function washiSingleHtmlWasmPlugin(options = {}) {
|
|
|
142
139
|
"export async function readPumpkinWasmFileUrl() { throw new Error('Node runtime is unavailable in browser builds.'); }",
|
|
143
140
|
"export async function readBundledPumpkinWasmBytes() { throw new Error('Node runtime is unavailable in browser builds.'); }",
|
|
144
141
|
].join("\n");
|
|
145
|
-
case "z3-assets":
|
|
146
|
-
return "export function getBundledZ3AssetUrls() { throw new Error('Z3 is unsupported in offline single-file HTML builds (SharedArrayBuffer requires COOP/COEP headers).'); }\n";
|
|
147
142
|
case "z3-solver":
|
|
148
143
|
return "export function init() { throw new Error('Z3 is unsupported in offline single-file HTML builds (SharedArrayBuffer requires COOP/COEP headers).'); }\nexport default { init };\n";
|
|
149
144
|
case "glpk":
|
|
@@ -286,9 +281,9 @@ export function hydrateOfflineWashiSolvers(
|
|
|
286
281
|
}
|
|
287
282
|
```
|
|
288
283
|
|
|
289
|
-
## Step 4: Model, Solve
|
|
284
|
+
## Step 4: Model, Solve, and Verify
|
|
290
285
|
|
|
291
|
-
Always call `await hydrateOfflineWashiSolvers(...)` once before solving, pass `{ useWorker:
|
|
286
|
+
Always call `await hydrateOfflineWashiSolvers(...)` once before solving, do not pass `{ useWorker: true }` (Workers are disabled in single-file offline builds), and assert `m.verify().valid` (never hardcode solver answers in UI state). Because solving runs on the browser main thread, set a sensible `timeLimit` (e.g. `{ timeLimit: 5 }`) for non-trivial MIP/CP models so the UI does not appear frozen and always yields a frame before displaying loading indicators:
|
|
292
287
|
|
|
293
288
|
```ts
|
|
294
289
|
import katex from "katex";
|
|
@@ -305,7 +300,7 @@ async function runOptimization() {
|
|
|
305
300
|
m.constraint(expr`${x} + ${y} <= 7`, "capacity");
|
|
306
301
|
m.objective(maximize(expr`3 * ${x} + 2 * ${y}`));
|
|
307
302
|
|
|
308
|
-
const status = await m.solve(
|
|
303
|
+
const status = await m.solve();
|
|
309
304
|
const report = m.verify();
|
|
310
305
|
if (!report.valid) {
|
|
311
306
|
throw new Error(`Solution verification failed: ${JSON.stringify(report.violations)}`);
|