Commit 51d3073
fix(embeddings): local embeddings on OpenCode Desktop / Electron (#195)
Two bugs broke /ctx-embed on Electron, both confirmed at source against
@huggingface/transformers 4.2.0 and reproduced+verified on plain Node:
1. Device selection. When we inject our own ORT via Symbol.for("onnxruntime")
(the Electron WASM path for #78), transformers skips its device-registration
branch, leaving supportedDevices=[]. With no device option it defaults to
"cpu" under IS_NODE_ENV, fails the supportedDevices.includes("cpu") check,
and throws 'Unsupported device: "cpu". Should be one of: .'. Pass
device:"auto" on the injected path: deviceToExecutionProviders("auto")
returns supportedDevices verbatim WITHOUT the membership check, so ORT-web
uses its own default (wasm) EP. Native Node/Bun is untouched (no device opt).
The reporter's fix (delete the injection) would regress #78; this keeps it.
2. WASM path resolution. require.resolve("onnxruntime-web/package.json") throws
ERR_PACKAGE_PATH_NOT_EXPORTED because the package's exports map doesn't expose
./package.json, so wasmPaths fell back to a CDN/blob URL Node's ESM loader
rejects. Resolve the main export ('.') and take its dirname (always exported,
lands in dist/).
Repro at scripts/experiments/issue-195-repro.mjs (gitignored): no-device throws
the exact reported error; device:"auto" + fixed wasmPaths => OK (dims=384).
Thanks @Treeed for the source-grounded report.
Co-authored-by: Alfonso [Magic Context] <288211368+alfonso-magic-context@users.noreply.github.com>1 parent 881b831 commit 51d3073
1 file changed
Lines changed: 22 additions & 4 deletions
Lines changed: 22 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
175 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
176 | 182 | | |
177 | 183 | | |
178 | 184 | | |
| |||
226 | 232 | | |
227 | 233 | | |
228 | 234 | | |
229 | | - | |
| 235 | + | |
230 | 236 | | |
231 | 237 | | |
232 | 238 | | |
| |||
421 | 427 | | |
422 | 428 | | |
423 | 429 | | |
424 | | - | |
| 430 | + | |
425 | 431 | | |
426 | 432 | | |
427 | 433 | | |
| |||
490 | 496 | | |
491 | 497 | | |
492 | 498 | | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
493 | 510 | | |
494 | 511 | | |
495 | 512 | | |
| 513 | + | |
496 | 514 | | |
497 | 515 | | |
498 | 516 | | |
| |||
0 commit comments