chore(8.0): collapse dead defensive guards + redundant polyfills

Follow-up to the browser/cloud/threading sweep — everything that was guarding
against unreachable runtimes is now dead.

cacheManager.ts: Environment enum + this.environment field removed (only NODE
was reachable). StorageType narrowed to MEMORY + FILESYSTEM. navigator.deviceMemory
and performance.memory paths in detectOptimalCacheSize + detectAvailableMemory
deleted; node:os is the sole source. environmentConfig keeps the index signature
for future per-runtime tuning but only the node slot is wired.

Dead 'typeof window === undefined' guards (the check is always true on 8.0):
paramValidation, structuredLogger, mutex, brainy.ts stats block, and
networkTransport ws-dynamic-import all collapsed. IntegrationLoader's inverse
guard ('!== undefined' returning 'browser') deleted. mutex's createMutex default
type simplified from "(typeof window === 'undefined' ? 'file' : 'memory')" to
plain 'file'.

Redundant TextEncoder/TextDecoder polyfills: Node 22+ ships both as globals.
src/utils/textEncoding.ts deleted (applyTensorFlowPatch was named for a defunct
dep and only re-assigned globals already present). setup.ts collapsed to an
empty stable import target. unified.ts loses its applyTensorFlowPatch re-export.

modelAutoConfig.getModelPath() loses the unreachable trailing fallback now
that isNode() is effectively the only branch the function ever takes.

jsonProcessing.ts left unchanged — its 'typeof document' checks are value-shape
guards on the parsed JSON, not environment detection.
This commit is contained in:
David Snelling 2026-06-09 16:46:16 -07:00
parent 266715aeee
commit 42159f2bd7
11 changed files with 121 additions and 397 deletions

View file

@ -1,31 +1,12 @@
/**
* Brainy Setup - Minimal Polyfills
* Brainy Setup
*
* ARCHITECTURE:
* Brainy uses Candle WASM (Rust-based) for embeddings.
* No transformers.js or ONNX Runtime dependency, no hacks required.
* Brainy 8.0 runs only on Node-like runtimes (Node.js 22+, Bun, Deno). All
* supported runtimes ship `TextEncoder` and `TextDecoder` as global built-ins,
* so no polyfills are required.
*
* This file provides minimal polyfills for cross-environment compatibility:
* - TextEncoder/TextDecoder for older environments
*
* BENEFITS:
* - Clean codebase with no workarounds
* - Works everywhere: Node.js, Bun, Bun --compile, browsers, Deno
* - No platform-specific binaries
* - Model bundled in package (no runtime downloads)
* This module is intentionally side-effect-only and currently empty. It is kept
* as a stable import target in case future runtime initialization is needed.
*/
// ============================================================================
// TextEncoder/TextDecoder Polyfills
// ============================================================================
const globalObj = globalThis ?? global ?? self
if (globalObj) {
if (!globalObj.TextEncoder) globalObj.TextEncoder = TextEncoder
if (!globalObj.TextDecoder) globalObj.TextDecoder = TextDecoder
;(globalObj as any).__TextEncoder__ = TextEncoder
;(globalObj as any).__TextDecoder__ = TextDecoder
}
import { applyTensorFlowPatch } from './utils/textEncoding.js'
applyTensorFlowPatch()
export {}