Repository navigation
Description
Parent: #534
Goal
Investigate an explicit, opt-in browser/WASM adapter for TypeChat's TypeScript JSON validator while preserving the existing Node.js backend and validation guarantees.
This tracks investigation and a possible isolated-branch prototype, not a commitment to ship browser support or merge an experimental compiler into main.
Starting evidence
A feasibility probe on 2026-11-23 used TypeChat at dddb7f7, Node.js 24.22.1, and esbuild 0.28.2:
- The stock TypeScript 7.0.2 backend still failed browser bundling because of Node-specific compiler dependencies.
- Excluding the optional Node-only
undiciproxy dependency allowed core/custom-validator and core/Zod browser probes to pass seven cases each. This did not test browser proxy support. - A test-only API/virtual-filesystem/transport adapter retained TypeChat's validation logic and passed eight real-browser cases using matching
typescriptand@typescript/typescript-wasip1-wasmpackages at7.1.0-dev.20261030.1. These covered valid and invalid data, malformed JSON, repair, and invalid-schema rejection before any model call. No Node globals or live model calls were used. - The WASM artifact measured 52,616,552 bytes, or 13,359,431 bytes gzipped, in addition to the JavaScript bundle.
The upstream implementation is microsoft/TypeScript#64174. Its WASM host and artifacts are explicitly experimental. A package being published, or a new TypeScript version being released, does not by itself establish a stable WASM API.
These are feasibility results, not full compatibility certification. Main has since incorporated #471; any maintained prototype must start from updated main and retain that behavior too.
Investigation scope
- Prefer an isolated branch for any maintained prototype. Keep browser support opt-in and avoid changing the default Node.js entry points, dependencies, or behavior.
- Compare a dedicated browser entry point/asynchronous factory with explicit compiler-transport injection. Replace the test-only compatibility bridge with a reviewable design; do not assume an export-map change alone is sufficient.
- Define asynchronous WASM loading, exact compiler/artifact version matching, resource cleanup, and explicit initialization/version/load errors.
- Keep the optional Node-only proxy bundling concern separate from compiler-adapter logic. Do not silently ignore proxy configuration or broadly stub Node APIs.
- Use deterministic offline tests for valid and invalid values, nested structures and unions, existing enum behavior, malformed JSON, disabled/successful/exhausted repair, and schema-preflight failure before model execution. Compare supported behavior with the equivalent native compiler and the current Node baseline, recording any differences.
- Measure download size, cold/warm initialization, validation time, and memory use for representative schemas. Document the browser/version matrix actually tested and propose practical budgets for review.
Investigation deliverables
- A reproducible isolated prototype and test commands, or a clear explanation of remaining blockers.
- A proposed API, asset-loading/lifecycle design, and dependency upgrade/rollback strategy.
- Compatibility results, measured costs, and documented unsupported scenarios.
- A go/no-go recommendation and explicit criteria for a separately reviewed mainline implementation.
Before any later merge, require the relevant upstream WASM API/artifacts to be sufficiently stable and supported, or an explicit owner decision to maintain an experimental integration. Also require Node/CJS/ESM compatibility, browser regression coverage, preserved validation/error behavior, and acceptable measured costs. A prototype remaining quiet for a while is not sufficient evidence by itself.
Non-goals
Do not replace the default Node backend, weaken validation, add silent fallback to a different validator, or claim blanket browser support for interactive utilities, proxy configurations, or every program-translation API. This issue does not authorize an automated implementation run or merging. Completing this investigation alone does not resolve #534.
Activity
typechat/tscannot be bundled for the browser:node:moduleimport in the public validator entrypoint #534