@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
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { A as e, B as t, C as n, D as r, E as i, F as a, G as o, H as s, I as c, K as l, L as u, M as d, N as f, O as p, P as m, R as h, S as g, T as _, U as v, V as y, W as b, _ as x, a as S, b as C, c as w, d as T, f as E, g as D, h as O, i as k, j as A, k as j, l as M, m as N, n as P, o as F, p as I, r as L, s as R, t as z, u as B, v as V, w as H, x as U, y as W, z as G } from "./core-b430-tAc.js";
|
|
2
|
+
import "./solvers/highs.node.js";
|
|
3
|
+
import "./solvers/pumpkin.node.js";
|
|
4
|
+
export { f as BoolExpr, m as BoolOp, a as BoolVar, A as Constraint, c as GlobalConstraint, H as LinExpr, z as MockSolver, P as Model, d as QuadExpr, n as Var, _ as abs, u as allowed, h as and, i as at, w as buildIndicatorLinearization, D as buildLpSymbolMaps, G as cumulative, M as deriveBigMForGe, B as deriveBigMForLe, t as disjoint, y as distinct, r as dot, C as expr, x as generateLpString, E as getSolver, s as implies, V as isLpExportResult, R as linearizeModelForMip, I as listAvailableSolvers, p as max, k as maximize, j as min, S as minimize, l as normalizeSense, v as not, b as or, U as parseConstraint, g as parseExpr, N as registerSolver, W as sanitizeIdentifier, O as setDefaultSolver, L as solveBenders, F as solveColumnGeneration, e as sum, T as validateUserBigM, o as xor };
|
|
@@ -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
|
|
|
@@ -129,24 +129,37 @@ Include a sample test case with contradictory named rules, print res.status and
|
|
|
129
129
|
|
|
130
130
|
## 4. Packaging & Deployment Prompts (Single-File HTML, Sharing, Desktop & Mobile)
|
|
131
131
|
|
|
132
|
-
Once a CLI script produces verified results—or directly inside an AI HTML preview—you can package the model as a hosted single-file preview, a zero-network offline `.html` file, or a desktop/mobile app.
|
|
132
|
+
Once a CLI script produces verified results—or directly inside an AI HTML preview—you can package the model as a hosted single-file preview, a lightweight online `.html` file, a zero-network offline `.html` file, or a desktop/mobile app.
|
|
133
|
+
|
|
134
|
+
### Describing Your Target Without Naming Files
|
|
135
|
+
|
|
136
|
+
When your agent already has the WaSHI Agent Skill (`npx skills add ohtaman/washi`) or web access, you do **not** need to memorize or specify filenames or loaders (`dist/washi.js`, `dist/washi.min.js`, `*-inline.js`, `single-html.md`). Just state **where and under what network/runtime conditions** the code should run:
|
|
137
|
+
|
|
138
|
+
| What you want | How to ask naturally | What the agent selects |
|
|
139
|
+
| --- | --- | --- |
|
|
140
|
+
| **Standard project** (Node.js / Vite / Next.js) | *"Build this optimization app in Node.js / Vite with `@ohtaman/washi`."* | `npm install @ohtaman/washi` + standard `import { ... } from "@ohtaman/washi"`. |
|
|
141
|
+
| **Lightweight HTML, no build or server** *(online OK)* | *"Create a lightweight single-file `.html` with no build step or local server that opens directly via `file://` (online OK)."* | CDN `dist/washi.js` (ESM) or `dist/washi.min.js` (IIFE)—no build step and no `*-inline.js` required. |
|
|
142
|
+
| **Zero-network offline HTML** *(air-gapped / airplane mode)* | *"Make a completely offline single-file `.html` that works by double-clicking (`file://`) with zero internet access."* | Single-file Vite build (`references/single-html.md`) embedding WaSHI and gzipped WASM. |
|
|
143
|
+
| **Web chat preview** *(Claude / ChatGPT / Gemini)* | *"Build an interactive visualization for this model using `@ohtaman/washi`."* | CDN imports matching the sandbox's CSP (including `*-inline.js` where `fetch()` is blocked). |
|
|
144
|
+
|
|
145
|
+
Use the explicit prompt templates below when you want to pin a specific output format or when working in an environment without the WaSHI skill or documentation loaded.
|
|
133
146
|
|
|
134
147
|
### Hosted AI Previews & Instant URL Sharing (`*-inline.js` + ESM)
|
|
135
148
|
|
|
136
|
-
Use WaSHI's self-registering inline WASM packs (`solvers/highs-inline.js` and `solvers/pumpkin-inline.js`) via **ESM (`<script type="module">`)** with `{
|
|
149
|
+
Use WaSHI's self-registering inline WASM packs (`solvers/highs-inline.js` and `solvers/pumpkin-inline.js`) via **ESM (`<script type="module">`)** with `{ timeLimit: 5 }`. This single pattern avoids `connect-src 'none'` `.wasm` `fetch()` blocks across **Claude.ai Artifacts**, **ChatGPT / Codex inline visualizations**, **Gemini Canvas**, and **Google Sites**:
|
|
137
150
|
|
|
138
151
|
```text
|
|
139
152
|
Create a self-contained single-file HTML optimization app using @ohtaman/washi via ESM (<script type="module">) and inline WASM packs so it runs with zero .wasm fetch() calls inside hosted AI sandboxes:
|
|
140
|
-
- Import Model, expr, maximize from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
141
|
-
- Import side-effect packs "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
142
|
-
- Pass {
|
|
143
|
-
- Include interactive sliders/inputs, optimal results, and conflict diagnosis via await m.check({ solver: "pumpkin"
|
|
153
|
+
- Import Model, expr, maximize from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.js".
|
|
154
|
+
- Import side-effect packs "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/highs-inline.js" and "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/pumpkin-inline.js" before solving.
|
|
155
|
+
- Pass { timeLimit: 5 } in m.solve(...) and m.check(...), and verify every feasible solve with m.verify().
|
|
156
|
+
- Include interactive sliders/inputs, optimal results, and conflict diagnosis via await m.check({ solver: "pumpkin" }) when infeasible.
|
|
144
157
|
```
|
|
145
158
|
|
|
146
159
|
**Verified sharing workflows by platform**:
|
|
147
|
-
- **Claude.ai Artifacts**: Verified on both edit views and **Publish / Share** links (`*-inline.js`
|
|
148
|
-
- **Gemini Canvas**: Verified with
|
|
149
|
-
- **ChatGPT & Codex**: Verified in inline visualizations (`*-inline.js
|
|
160
|
+
- **Claude.ai Artifacts**: Verified on both edit views and **Publish / Share** links (`*-inline.js`); share the published URL directly or download the `.html` file.
|
|
161
|
+
- **Gemini Canvas**: Verified with default calling-thread ESM (`dist/washi.js`) and with `{ useWorker: true }` via classic `dist/washi.min.js`; click **Publish to Google Sites** for an instant shareable URL, or copy the HTML code.
|
|
162
|
+
- **ChatGPT & Codex**: Verified in inline visualizations (`*-inline.js`; prefer ESM `<script type="module">` over classic `<script>` to avoid dynamic-injection load races); export or copy the `.html` file to share directly or deploy to static hosting.
|
|
150
163
|
- **Antigravity**: The built-in HTML artifact preview omits `'wasm-unsafe-eval'` from its CSP (so WebAssembly cannot compile inside the preview pane); preview via a local server in the built-in browser or open the exported `.html` in Chrome/Safari.
|
|
151
164
|
|
|
152
165
|
### Zero-Server Single-File `.html` Tool (`file://` Double-Click & Zero-Network Offline)
|
|
@@ -155,7 +168,7 @@ For a lightweight CDN-backed `.html` file that opens by double-clicking (`file:/
|
|
|
155
168
|
|
|
156
169
|
```text
|
|
157
170
|
Package this @ohtaman/washi optimization model into a standalone .html file with inline HTML, CSS, and JavaScript so team members can open it directly by double-clicking (file://).
|
|
158
|
-
- Load WaSHI from https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
171
|
+
- Load WaSHI from https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.min.js (global window.Washi).
|
|
159
172
|
- Provide a textarea / CSV file input, a "Solve" button, a table displaying the optimal assignment, and a conflict report using await m.check() if status is "Infeasible".
|
|
160
173
|
- Verify every feasible solve with m.verify().
|
|
161
174
|
```
|
|
@@ -164,22 +177,18 @@ For a **zero-network, completely offline** single-file `.html` bundling `@ohtama
|
|
|
164
177
|
|
|
165
178
|
```text
|
|
166
179
|
Read skills/washi/references/single-html.md (or node_modules/@ohtaman/washi/skills/washi/references/single-html.md) and package this @ohtaman/washi app as a zero-network single-file dist/index.html using Vite + vite-plugin-singlefile + gzipped WASM.
|
|
167
|
-
- Bundle only the required solvers (HiGHS and/or Pumpkin), pass {
|
|
180
|
+
- Bundle only the required solvers (HiGHS and/or Pumpkin), pass { timeLimit: 5 }, and assert m.verify().valid === true.
|
|
168
181
|
- Verify that dist/index.html runs over file:// in headless Chromium with zero external HTTP requests and zero console errors.
|
|
169
182
|
```
|
|
170
183
|
|
|
171
|
-
**`file://`
|
|
172
|
-
|
|
173
|
-
> [!TIP]
|
|
174
|
-
> **When to keep `useWorker: true` (default) vs. `{ useWorker: false }`**:
|
|
175
|
-
> Keep default `useWorker: true` on normal `http(s):` web apps, Gemini Canvas, and Google Sites so solving never freezes the UI, supports immediate `AbortSignal` termination, repaints `onProgress` live, and isolates crashes. Use `{ useWorker: false }` (alongside a `timeLimit` guardrail) only in Worker-restricted sandboxes (Claude Artifacts, ChatGPT/Codex inline visualizations) and offline `file://` builds.
|
|
184
|
+
**`file://` runtime notes**: Loading `washi.min.js` or `dist/washi.js` from an HTTPS CDN runs directly on `file://` with no `*-inline.js` pack. Self-hosted `.wasm` files require `http://` or `https://`, and browser Z3 requires Cross-Origin Isolation. Pass `{ useWorker: true }` in interactive `http(s):` apps when long solves should run off the UI thread; see [Runtime Environments](./runtimes.md) and [Cross-Origin Isolation](./cross-origin.md).
|
|
176
185
|
|
|
177
186
|
### Offline Desktop & Mobile Apps (Vite + Tauri / Capacitor / PWA)
|
|
178
187
|
|
|
179
188
|
```text
|
|
180
189
|
Wrap this Vite + TypeScript @ohtaman/washi application as an offline desktop/mobile app using bundled HiGHS (or { solver: "pumpkin" }) with zero backend server and zero native solver compilation.
|
|
181
190
|
- Keep all solver execution client-side via @ohtaman/washi.
|
|
182
|
-
- Configure Content Security Policy to allow WebAssembly compilation ('wasm-unsafe-eval' in script-src) and Web Workers (worker-src 'self' blob:).
|
|
191
|
+
- Configure Content Security Policy to allow WebAssembly compilation ('wasm-unsafe-eval' in script-src) and, only if using { useWorker: true }, Web Workers (worker-src 'self' blob:).
|
|
183
192
|
```
|
|
184
193
|
|
|
185
194
|
**WebView notes**: Standard Vite builds bundle your solver `.wasm` assets for offline execution in Tauri, Capacitor, and PWAs. Allow `'wasm-unsafe-eval'` in `script-src` (plus `worker-src 'self' blob:` for Web Workers); see [Runtime Environments](./runtimes.md) for a `tauri.conf.json` example.
|
|
@@ -120,9 +120,10 @@ On the first visit, the Service Worker registers and reloads the page once so `w
|
|
|
120
120
|
|
|
121
121
|
## Runtime Check in WaSHI
|
|
122
122
|
|
|
123
|
-
Before initializing Z3 in a browser, WaSHI validates
|
|
123
|
+
Before initializing Z3 in a browser, WaSHI validates these preconditions in order:
|
|
124
124
|
|
|
125
125
|
| Check | Failure Condition | Result |
|
|
126
126
|
| --- | --- | --- |
|
|
127
127
|
| **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. |
|
|
128
128
|
| **Cross-Origin Isolation** | `SharedArrayBuffer` is missing or `window.crossOriginIsolated !== true` | `solve()` / `check()` immediately rejects listing the required `COOP` and `COEP` headers instead of hanging. |
|
|
129
|
+
| **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](../solvers/z3.md)). |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Introduction & Installation
|
|
2
2
|
|
|
3
|
-
**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
|
|
3
|
+
**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.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -44,6 +44,8 @@ npm install glpk.js # Optional: GLPK solver (GPL-3.0)
|
|
|
44
44
|
|
|
45
45
|
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](./cross-origin.md) for server setup.
|
|
46
46
|
|
|
47
|
+
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](./runtimes.md#csp-fetch-free).
|
|
48
|
+
|
|
47
49
|
---
|
|
48
50
|
|
|
49
51
|
## 🚀 Quick Start
|
|
@@ -4,11 +4,11 @@ WaSHI runs across JavaScript and TypeScript runtimes and deployment targets with
|
|
|
4
4
|
|
|
5
5
|
| Target Environment | Entry Point | Worker & Header Notes |
|
|
6
6
|
| --- | --- | --- |
|
|
7
|
-
| **Node.js
|
|
8
|
-
| **Vite, Next.js, Webpack, Rollup** | `@ohtaman/washi` | Runs HiGHS and Pumpkin
|
|
9
|
-
| **Tauri, Capacitor, PWA** | `@ohtaman/washi` (standard Vite build) | Runs offline; allow `'wasm-unsafe-eval'` in `script-src` and `worker-src 'self' blob:`
|
|
10
|
-
| **Browser ESM (`<script type="module">`)** | `dist/
|
|
11
|
-
| **Standalone HTML / CDN (`<script>`)** | `dist/
|
|
7
|
+
| **Node.js, Bun, Deno** | `@ohtaman/washi` (`npm:@ohtaman/washi` in Deno) | Loads bundled `.wasm` from disk; no HTTP headers required. |
|
|
8
|
+
| **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. |
|
|
9
|
+
| **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`). |
|
|
10
|
+
| **Browser ESM (`<script type="module">`)** | `dist/washi.js` | Keep `dist/` files together when self-hosting; use default `useWorker: false` on cross-origin CDNs. |
|
|
11
|
+
| **Standalone HTML / CDN (`<script>`)** | `dist/washi.min.js` | Exposes `window.Washi`; supports cross-origin `{ useWorker: true }` and runs directly on `file://`. |
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
@@ -16,7 +16,7 @@ WaSHI runs across JavaScript and TypeScript runtimes and deployment targets with
|
|
|
16
16
|
|
|
17
17
|
### Node.js
|
|
18
18
|
|
|
19
|
-
WaSHI supports Node.js
|
|
19
|
+
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:
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
22
|
import { Model, expr, maximize } from "@ohtaman/washi";
|
|
@@ -69,7 +69,7 @@ if (m.hasPrimalSolution) {
|
|
|
69
69
|
|
|
70
70
|
### Modern Bundlers & Static Deployment
|
|
71
71
|
|
|
72
|
-
The package root export (`@ohtaman/washi`) resolves `
|
|
72
|
+
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:
|
|
73
73
|
|
|
74
74
|
```typescript
|
|
75
75
|
import { Model, maximize } from "@ohtaman/washi";
|
|
@@ -85,31 +85,34 @@ export async function runOptimization() {
|
|
|
85
85
|
|
|
86
86
|
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.
|
|
87
87
|
|
|
88
|
-
####
|
|
88
|
+
#### Calling-Thread Default & Optional Web Worker Execution
|
|
89
89
|
|
|
90
|
-
In browsers, **HiGHS** and **Pumpkin**
|
|
90
|
+
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.
|
|
91
91
|
|
|
92
|
-
Pass `useWorker:
|
|
92
|
+
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:
|
|
93
93
|
|
|
94
94
|
```typescript
|
|
95
|
-
await m.solve({ useWorker:
|
|
95
|
+
await m.solve({ useWorker: true });
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
#### Customizing WASM Asset URLs
|
|
99
99
|
|
|
100
100
|
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.).
|
|
101
101
|
|
|
102
|
-
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
|
|
102
|
+
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:
|
|
103
103
|
|
|
104
104
|
```typescript
|
|
105
105
|
import { setHighsWasmUrl } from "@ohtaman/washi/solvers/highs";
|
|
106
106
|
import { setPumpkinWasmUrl } from "@ohtaman/washi/solvers/pumpkin";
|
|
107
|
-
import {
|
|
107
|
+
import { registerZ3Solver } from "@ohtaman/washi/solvers/z3"; // Optional Z3 plugin
|
|
108
108
|
|
|
109
109
|
// Option A: Configure globally before solving
|
|
110
110
|
setHighsWasmUrl("/assets/wasm/highs.wasm");
|
|
111
111
|
setPumpkinWasmUrl("/assets/wasm/pumpkin.wasm");
|
|
112
|
-
|
|
112
|
+
registerZ3Solver({
|
|
113
|
+
z3JsUrl: new URL("z3-solver/build/z3-built.js", import.meta.url).href,
|
|
114
|
+
z3WasmUrl: new URL("z3-solver/build/z3-built.wasm", import.meta.url).href,
|
|
115
|
+
});
|
|
113
116
|
|
|
114
117
|
// Option B: Configure per solve / check call
|
|
115
118
|
await m.solve({ wasmUrl: "/assets/wasm/highs.wasm" });
|
|
@@ -152,13 +155,13 @@ export default function OptimizerComponent() {
|
|
|
152
155
|
|
|
153
156
|
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.
|
|
154
157
|
|
|
155
|
-
In `tauri.conf.json`,
|
|
158
|
+
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):
|
|
156
159
|
|
|
157
160
|
```json
|
|
158
161
|
{
|
|
159
162
|
"app": {
|
|
160
163
|
"security": {
|
|
161
|
-
"csp": "default-src 'self'; script-src 'self' 'wasm-unsafe-eval'
|
|
164
|
+
"csp": "default-src 'self'; script-src 'self' 'wasm-unsafe-eval'"
|
|
162
165
|
}
|
|
163
166
|
}
|
|
164
167
|
}
|
|
@@ -174,11 +177,11 @@ Without a bundler, import the pre-built browser ESM module from your own static
|
|
|
174
177
|
|
|
175
178
|
```html
|
|
176
179
|
<script type="module">
|
|
177
|
-
// From an npm CDN (or "./dist/
|
|
178
|
-
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
180
|
+
// From an npm CDN (or "./dist/washi.js" when self-hosted; includes HiGHS and Pumpkin):
|
|
181
|
+
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.js";
|
|
179
182
|
// Optional solver plugins:
|
|
180
|
-
// import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
181
|
-
// import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
183
|
+
// import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/glpk.js";
|
|
184
|
+
// import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/z3.js";
|
|
182
185
|
|
|
183
186
|
const m = new Model("BrowserESM");
|
|
184
187
|
const x = m.integer("x", { lb: 0, ub: 100 });
|
|
@@ -212,11 +215,8 @@ For single-file HTML pages, CodePen, or JSFiddle, load `washi.min.js` via a clas
|
|
|
212
215
|
<h1>WaSHI Browser Optimization</h1>
|
|
213
216
|
<pre id="output">Solving...</pre>
|
|
214
217
|
|
|
215
|
-
<!-- Core WaSHI + bundled HiGHS & Pumpkin (MIT) via CDN (or "./dist/
|
|
216
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
217
|
-
<!-- Optional plugins (load after washi.min.js; auto-register when window.Washi is present): -->
|
|
218
|
-
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/glpk.min.js"></script> -->
|
|
219
|
-
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/z3.min.js"></script> -->
|
|
218
|
+
<!-- Core WaSHI + bundled HiGHS & Pumpkin (MIT) via CDN (or "./dist/washi.min.js" when self-hosted) -->
|
|
219
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.min.js"></script>
|
|
220
220
|
|
|
221
221
|
<script>
|
|
222
222
|
(async () => {
|
|
@@ -243,16 +243,11 @@ For single-file HTML pages, CodePen, or JSFiddle, load `washi.min.js` via a clas
|
|
|
243
243
|
</html>
|
|
244
244
|
```
|
|
245
245
|
|
|
246
|
-
### Cross-Origin CDN Workers
|
|
247
|
-
|
|
248
|
-
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.
|
|
249
|
-
|
|
250
246
|
### Opening Local `.html` Files Directly (`file://`)
|
|
251
247
|
|
|
252
248
|
| Scenario | Behavior & Requirement |
|
|
253
249
|
| --- | --- |
|
|
254
250
|
| **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. |
|
|
255
|
-
| **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. |
|
|
256
251
|
| **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). |
|
|
257
252
|
| **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. |
|
|
258
253
|
|
|
@@ -262,38 +257,37 @@ On standard `http://` and `https://` origins, browsers block direct `new Worker(
|
|
|
262
257
|
|
|
263
258
|
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:
|
|
264
259
|
|
|
265
|
-
### 1. Deploy `dist
|
|
260
|
+
### 1. Deploy `dist/` Intact
|
|
266
261
|
|
|
267
|
-
Copy `node_modules/@ohtaman/washi/dist
|
|
262
|
+
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.
|
|
268
263
|
|
|
269
|
-
| Bundle | Required Files under `dist
|
|
264
|
+
| Bundle | Required Files under `dist/` |
|
|
270
265
|
| --- | --- |
|
|
271
|
-
| **Core** | `washi.js` / `washi.min.js` |
|
|
272
|
-
| **Bundled HiGHS** | `solvers/highs.js`, `solvers/highs.wasm`, `solvers/highs-worker.js`,
|
|
273
|
-
| **Bundled Pumpkin** | `solvers/pumpkin.js`, `solvers/pumpkin.wasm`, `solvers/pumpkin-worker.js`,
|
|
274
|
-
| **Optional GLPK** | `solvers/glpk.js`
|
|
275
|
-
| **Optional Z3** | `solvers/z3.js`
|
|
266
|
+
| **Core** | `washi.js`, `core-*.js` / `washi.min.js` |
|
|
267
|
+
| **Bundled HiGHS** | `solvers/highs.js`, `solvers/highs.wasm`, `solvers/highs-worker.js`, `solvers/highs-*.js`, `core-*.js` |
|
|
268
|
+
| **Bundled Pumpkin** | `solvers/pumpkin.js`, `solvers/pumpkin.wasm`, `solvers/pumpkin-worker.js`, `solvers/pumpkin-*.js`, `core-*.js` |
|
|
269
|
+
| **Optional GLPK** *(unbundled peer)* | `solvers/glpk.js` (requires `glpk.js` resolved via bundler or `<script type="importmap">`) |
|
|
270
|
+
| **Optional Z3** *(unbundled peer)* | `solvers/z3.js` (requires `z3-solver` plus `z3-built.js` & `z3-built.wasm` configured via `registerZ3Solver()`) |
|
|
276
271
|
|
|
277
272
|
### 2. Configure CSP Directives
|
|
278
273
|
|
|
279
274
|
| Directive | Required Value | Purpose |
|
|
280
275
|
| --- | --- | --- |
|
|
281
276
|
| `script-src` | `'wasm-unsafe-eval'` | Allows WebAssembly module compilation. |
|
|
282
|
-
| `worker-src` | `'self' blob:` |
|
|
283
|
-
| `worker-src` (if `blob:` is disallowed) | `'self'` only | Serve `solvers/highs-worker.js` / `solvers/pumpkin-worker.js` from `'self'`, or pass `{ useWorker: false }`. |
|
|
277
|
+
| `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`). |
|
|
284
278
|
|
|
285
279
|
### 3. CSP-Restricted Pages Without `fetch()` (`connect-src 'none'`) {#csp-fetch-free}
|
|
286
280
|
|
|
287
|
-
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'`)
|
|
281
|
+
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.
|
|
288
282
|
|
|
289
|
-
Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtaman/washi/
|
|
283
|
+
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:
|
|
290
284
|
|
|
291
285
|
```html
|
|
292
|
-
<!-- Option A (Recommended): ESM (<script type="module">)
|
|
286
|
+
<!-- Option A (Recommended): ESM (<script type="module">) -->
|
|
293
287
|
<script type="module">
|
|
294
|
-
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
295
|
-
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
296
|
-
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
288
|
+
import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.js";
|
|
289
|
+
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/highs-inline.js";
|
|
290
|
+
import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/pumpkin-inline.js";
|
|
297
291
|
|
|
298
292
|
const m = new Model("CspFreeExample");
|
|
299
293
|
const x = m.integer("x", { lb: 0 });
|
|
@@ -301,13 +295,13 @@ Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtam
|
|
|
301
295
|
m.objective(maximize(expr`30 * ${x} + 50 * ${y}`));
|
|
302
296
|
m.constraint(expr`${x} + 2 * ${y} <= 40`);
|
|
303
297
|
m.constraint(expr`2 * ${x} + ${y} <= 50`);
|
|
304
|
-
await m.solve({
|
|
298
|
+
await m.solve({ timeLimit: 5 }); // Works across all supported AI sandboxes
|
|
305
299
|
</script>
|
|
306
300
|
|
|
307
301
|
<!-- Option B: Classic <script> (prefer Option A in dynamically injected sandboxes) -->
|
|
308
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
309
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
310
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/
|
|
302
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/washi.min.js"></script>
|
|
303
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/highs-inline.js"></script>
|
|
304
|
+
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/solvers/pumpkin-inline.js"></script>
|
|
311
305
|
<script>
|
|
312
306
|
(async () => {
|
|
313
307
|
const { Model, expr, maximize } = Washi;
|
|
@@ -317,31 +311,27 @@ Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtam
|
|
|
317
311
|
m.objective(maximize(expr`30 * ${x} + 50 * ${y}`));
|
|
318
312
|
m.constraint(expr`${x} + 2 * ${y} <= 40`);
|
|
319
313
|
m.constraint(expr`2 * ${x} + ${y} <= 50`);
|
|
320
|
-
await m.solve({
|
|
314
|
+
await m.solve({ timeLimit: 5 }); // Zero fetch(), zero Blob URLs, zero Workers
|
|
321
315
|
})();
|
|
322
316
|
</script>
|
|
323
317
|
```
|
|
324
318
|
|
|
325
319
|
#### Hosted AI Sandbox Compatibility (Empirically Verified)
|
|
326
320
|
|
|
327
|
-
| Environment | `fetch(.wasm)` | `*-inline.js`
|
|
321
|
+
| Environment | `fetch(.wasm)` | `*-inline.js` | `{ useWorker: true }` | Recommended Setup |
|
|
328
322
|
| --- | :---: | :---: | :---: | --- |
|
|
329
|
-
| **Claude.ai Artifacts** *(edit & published links)* | Blocked | Works *(ESM & Classic)* | Blocked | Option A (ESM + `*-inline.js`
|
|
330
|
-
| **ChatGPT Inline Visualization** *(`codex-inline-visualization-*`)* | Blocked | Works *(ESM reliable; Classic can race on cold load)* | Blocked | Option A (ESM + `*-inline.js`
|
|
331
|
-
| **Codex Inline Visualization** *(`codex-sandbox://...`)* | Blocked | Works *(ESM & Classic)* | Blocked | Option A (ESM + `*-inline.js`
|
|
332
|
-
| **Gemini Canvas & Google Sites** *(1-click publish)* | Works | Works *(ESM & Classic)* | Works | Option A works everywhere
|
|
323
|
+
| **Claude.ai Artifacts** *(edit & published links)* | Blocked | Works *(ESM & Classic)* | Blocked | Option A (ESM + `*-inline.js`) |
|
|
324
|
+
| **ChatGPT Inline Visualization** *(`codex-inline-visualization-*`)* | Blocked | Works *(ESM reliable; Classic can race on cold load)* | Blocked | Option A (ESM + `*-inline.js`) |
|
|
325
|
+
| **Codex Inline Visualization** *(`codex-sandbox://...`)* | Blocked | Works *(ESM & Classic)* | Blocked | Option A (ESM + `*-inline.js`) |
|
|
326
|
+
| **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 }` |
|
|
333
327
|
| **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 |
|
|
334
|
-
| **Local Browser `file://`** *(Chrome / Safari)* | Works via HTTPS CDN | Works *(CDN or Vite offline bundle)* |
|
|
328
|
+
| **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) |
|
|
335
329
|
|
|
336
330
|
- **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.
|
|
337
331
|
- **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.
|
|
338
|
-
- **Web Worker mode**:
|
|
332
|
+
- **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).
|
|
339
333
|
- **GLPK & Z3**: **GLPK** (`solvers/glpk.js`) already embeds its WASM inline without `fetch()`. **Z3** requires `SharedArrayBuffer` and Cross-Origin Isolation headers (below).
|
|
340
|
-
|
|
341
|
-
> [!TIP]
|
|
342
|
-
> **Choosing Between `useWorker: true` and `useWorker: false`**:
|
|
343
|
-
> - **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.
|
|
344
|
-
> - **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.
|
|
334
|
+
- **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.
|
|
345
335
|
|
|
346
336
|
### 4. Enable Cross-Origin Isolation (Z3 Only)
|
|
347
337
|
|
package/docs/guide/objectives.md
CHANGED
|
@@ -60,7 +60,7 @@ const status = await m.solve({
|
|
|
60
60
|
| `presolve` | `"on"` \| `"off"` \| `"choose"` | `"choose"` | Controls solver presolve reduction prior to optimization. |
|
|
61
61
|
| `relax` | `boolean` | `false` | Solves the continuous LP relaxation (equivalent to `m.relax()`); supported on HiGHS and GLPK. |
|
|
62
62
|
| `outputFlag` / `verbose` | `boolean` | `false` | Emits internal solver logs (`outputFlag` for HiGHS, `verbose` for GLPK). |
|
|
63
|
-
| `useWorker` | `boolean` | `
|
|
63
|
+
| `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. |
|
|
64
64
|
| `wasmUrl` | `string` | Auto-resolved | Custom URL to load `highs.wasm` or `pumpkin.wasm` in browser deployments. |
|
|
65
65
|
| `signal` | `AbortSignal` | `undefined` | Cancellation signal (`AbortController.signal`); see cancellation limitations below. |
|
|
66
66
|
| `onProgress` | `(e: SolveProgressEvent) => void` | `undefined` | Callback receiving live solver progress snapshots. |
|
|
@@ -159,8 +159,8 @@ console.log("Has incumbent:", m.hasPrimalSolution); // true if an incumbent was
|
|
|
159
159
|
|
|
160
160
|
> [!NOTE]
|
|
161
161
|
> **`AbortSignal` Behavior Across Backends**:
|
|
162
|
-
> - **Asynchronous preemptive cancellation**: On HiGHS and Pumpkin
|
|
163
|
-
> - **Cooperative mid-solve cancellation**:
|
|
162
|
+
> - **Asynchronous preemptive cancellation**: On HiGHS and Pumpkin with browser Web Workers (`useWorker: true`), aborting terminates the worker immediately.
|
|
163
|
+
> - **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.
|
|
164
164
|
> - **Pre-solve cancellation only**: On GLPK and Z3, `AbortSignal` is checked only before starting a solve.
|
|
165
165
|
|
|
166
166
|
### `SolveProgressEvent` Fields
|
|
@@ -487,20 +487,15 @@ To publish your solver as an independent npm package (such as `@my-org/washi-sol
|
|
|
487
487
|
"name": "@my-org/washi-solver-cplex",
|
|
488
488
|
"version": "1.0.0",
|
|
489
489
|
"type": "module",
|
|
490
|
-
"main": "./dist/
|
|
490
|
+
"main": "./dist/index.js",
|
|
491
491
|
"types": "./dist/types/index.d.ts",
|
|
492
492
|
"exports": {
|
|
493
493
|
".": {
|
|
494
494
|
"types": "./dist/types/index.d.ts",
|
|
495
|
-
"
|
|
496
|
-
"default": "./dist/
|
|
495
|
+
"node": "./dist/index.node.js",
|
|
496
|
+
"default": "./dist/index.js"
|
|
497
497
|
},
|
|
498
|
-
"./
|
|
499
|
-
"types": "./dist/types/index.d.ts",
|
|
500
|
-
"import": "./dist/browser/index.js",
|
|
501
|
-
"default": "./dist/browser/index.js"
|
|
502
|
-
},
|
|
503
|
-
"./browser/index.min.js": "./dist/browser/index.min.js"
|
|
498
|
+
"./index.min.js": "./dist/index.min.js"
|
|
504
499
|
},
|
|
505
500
|
"peerDependencies": {
|
|
506
501
|
"@ohtaman/washi": ">=0.8.0"
|
package/docs/solvers/glpk.md
CHANGED
|
@@ -56,6 +56,8 @@ console.log("Objective:", model.objectiveValue); // 40
|
|
|
56
56
|
console.log("Shadow price:", cap.dual); // 2
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
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`).
|
|
60
|
+
|
|
59
61
|
---
|
|
60
62
|
|
|
61
63
|
## Solver Options & Execution Model
|