**feat: improve TensorFlow.js compatibility and remove unnecessary patches**

- Removed outdated Node.js v24 compatibility patches for `TextEncoder` and `TextDecoder` in `cli-wrapper.js` and other modules since TensorFlow.js now supports Node.js v24+ natively.
- Introduced a utility module `src/utils/tensorflowUtils.ts` for TensorFlow.js compatibility, defining global `PlatformNode` and related utilities.
- Enhanced `fileSystemStorage.ts` with improved Node.js module loading mechanisms for better compatibility across environments.
- Simplified dependency requirements by reducing the minimum Node.js version to `>=23.0.0`.
- Updated `package.json`, `cli-package/package.json`, and `README.md` versions to `0.9.25`.
- Harmonized `cli-package` and main package dependencies to ensure version alignment.
- Improved global compatibility with TensorFlow.js in mixed Node.js environments.

This update modernizes TensorFlow.js integration, reduces maintenance efforts, and aligns compatibility with current Node.js and TensorFlow.js capabilities.
This commit is contained in:
David Snelling 2025-07-02 16:16:19 -07:00
parent e9f51e1bf3
commit 5edea683c6
20 changed files with 428 additions and 168 deletions

View file

@ -1,14 +1,35 @@
// Type declarations for TensorFlow.js models
/**
* Type definitions for TensorFlow.js compatibility
* This file exports type definitions for TensorFlow.js utilities
*/
// This file is a placeholder for TensorFlow.js model types
// We're using type assertions in the code instead of module declarations
// Define some basic types that might be useful
export interface TensorflowModel {
load(): Promise<any>;
embed(data: string[]): any;
dispose(): void;
// Define the shape of the util object used for TensorFlow.js compatibility
export interface TensorFlowUtilObject {
isFloat32Array: (arr: unknown) => boolean
isTypedArray: (arr: unknown) => boolean
[key: string]: unknown
}
// Export a dummy constant to make this a proper module
export const tensorflowModelsLoaded = true;
// Define the shape of the PlatformNode object that might exist in global
export interface PlatformNodeObject {
isFloat32Array?: (arr: unknown) => boolean
isTypedArray?: (arr: unknown) => boolean
[key: string]: unknown
}
// Define the shape of the tf object that might exist in global
export interface TensorFlowObject {
util?: TensorFlowUtilObject
[key: string]: unknown
}
// Extend the Window and WorkerGlobalScope interfaces to include the importTensorFlow function
declare global {
interface Window {
importTensorFlow?: () => Promise<any>
}
interface WorkerGlobalScope {
importTensorFlow?: () => Promise<any>
}
}