**chore(release): bump version to 0.10.0 and refactor project structure**

- Updated version to `0.10.0` in `README.md`, `cli-package/package.json`, and `src/utils/version.ts`.
- Removed `CHANGELOG.md` from the root and `cli-package`, as GitHub auto-generates release notes.
- Refactored `brainy-wrapper.js` to simplify utility methods (`isFloat32Array` and `isTypedArray`) by moving them to instance-level definitions.
- Standardized Node.js version requirement to `>= 24.3.0` across documentation and configuration files.
- Improved `textEncoding.ts` by introducing a unified `Platform` class for cross-environment compatibility (Node.js and browser).
- Restructured scripts:
  - Replaced outdated commands (e.g., `test-cli` -> `test:cli` and `test-all` -> `test:all`) for consistency.
  - Removed changelog updates from `scripts/create-github-release.js` as part of simplification.
- Enhanced `patch-textencoder.js` to also patch `worker.js` for both `TextEncoder` and `TextDecoder`.

This release improves compatibility with Node.js 24, simplifies the deployment/changelog process, and refines text encoding and worker functionalities.
This commit is contained in:
David Snelling 2025-07-07 10:19:04 -07:00
parent 0653d479ef
commit 04a33b9ae8
18 changed files with 183 additions and 292 deletions

View file

@ -1,24 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
## [0.9.37] - 2025-07-04
**Full Changelog**: https://github.com/soulcraft-research/brainy/compare/v0.9.36...v0.9.37
## [0.9.36] - 2025-07-04
**Full Changelog**: https://github.com/soulcraft-research/brainy/commits/v0.9.36
## [0.9.34] - 2024-07-01
This is the initial changelog entry. Future releases will automatically update this file with release notes from GitHub.
### Added
- Auto-generation of release notes for GitHub releases
- Auto-updating of CHANGELOG.md files for both main and CLI packages
- Display of release notes on npmjs.com through the CHANGELOG.md files
### Changed
- Modified deployment scripts to ensure GitHub releases are created with auto-generated notes
- Updated package.json files to include CHANGELOG.md in published packages

View file

@ -4,16 +4,17 @@
<img src="./brainy.png" alt="Brainy Logo" width="200"/>
</div>
This document contains detailed information for developers working with Brainy, including building, testing, and publishing instructions.
This document contains detailed information for developers working with Brainy, including building, testing, and
publishing instructions.
## Table of Contents
- [Build System](#build-system)
- [Testing](#testing)
- [Testing All Environments](#testing-all-environments)
- [Testing the CLI Package Locally](#testing-the-cli-package-locally)
- [Testing All Environments](#testing-all-environments)
- [Testing the CLI Package Locally](#testing-the-cli-package-locally)
- [Publishing](#publishing)
- [Publishing the CLI Package](#publishing-the-cli-package)
- [Publishing the CLI Package](#publishing-the-cli-package)
- [Development Usage](#development-usage)
- [Node.js 24 Optimizations](#nodejs-24-optimizations)
- [Development Workflow](#development-workflow)
@ -63,14 +64,16 @@ Brainy uses a modern build system that optimizes for both Node.js and browser en
### Testing All Environments
Brainy provides a comprehensive test script that verifies the library works correctly in all supported environments (browser, Node.js, and CLI):
Brainy provides a comprehensive test script that verifies the library works correctly in all supported environments (
browser, Node.js, and CLI):
```bash
# Test the library in all environments
npm run test-all
npm run test:all
```
This script:
1. Builds all packages (main, browser, CLI)
2. Runs Node.js tests (worker tests and unified text encoding test)
3. Starts a local HTTP server and runs browser tests using Puppeteer (headless browser)
@ -84,10 +87,11 @@ Before publishing the CLI package to npm, you can test it locally to ensure it w
```bash
# Test the CLI package locally
npm run test-cli
npm run test:cli
```
This script:
1. Builds the main package
2. Creates a local tarball of the main package
3. Builds the CLI package
@ -115,7 +119,8 @@ npm uninstall -g @soulcraft/brainy-cli
### Publishing the CLI Package
If you need to publish the CLI package to npm, please refer to the [CLI Publishing Guide](docs/publishing-cli.md) for detailed instructions.
If you need to publish the CLI package to npm, please refer to the [CLI Publishing Guide](docs/publishing-cli.md) for
detailed instructions.
## Development Usage
@ -131,15 +136,21 @@ npm run cli generate-random-graph --noun-count 20 --verb-count 40
Brainy takes advantage of several optimizations available in Node.js 24:
1. **Improved Worker Threads Performance**: The multithreading system has been completely rewritten to leverage Node.js 24's enhanced Worker Threads API, resulting in better performance for compute-intensive operations like embedding generation and vector similarity calculations.
1. **Improved Worker Threads Performance**: The multithreading system has been completely rewritten to leverage Node.js
24's enhanced Worker Threads API, resulting in better performance for compute-intensive operations like embedding
generation and vector similarity calculations.
2. **Worker Pool Management**: A sophisticated worker pool system reuses worker threads to minimize the overhead of creating and destroying threads, leading to more efficient resource utilization.
2. **Worker Pool Management**: A sophisticated worker pool system reuses worker threads to minimize the overhead of
creating and destroying threads, leading to more efficient resource utilization.
3. **Dynamic Module Imports**: Uses the new `node:` protocol prefix for importing core modules, which provides better performance and more reliable module resolution.
3. **Dynamic Module Imports**: Uses the new `node:` protocol prefix for importing core modules, which provides better
performance and more reliable module resolution.
4. **ES Modules Optimizations**: Takes advantage of Node.js 24's improved ESM implementation for faster module loading and execution.
4. **ES Modules Optimizations**: Takes advantage of Node.js 24's improved ESM implementation for faster module loading
and execution.
5. **Enhanced Error Handling**: Implements more robust error handling patterns available in Node.js 24 for better stability and debugging.
5. **Enhanced Error Handling**: Implements more robust error handling patterns available in Node.js 24 for better
stability and debugging.
These optimizations are particularly beneficial for:
@ -157,7 +168,8 @@ These optimizations are particularly beneficial for:
## Reporting Issues
We use GitHub issues to track bugs and feature requests. Please use the provided issue templates when creating a new issue:
We use GitHub issues to track bugs and feature requests. Please use the provided issue templates when creating a new
issue:
- [Bug Report Template](.github/ISSUE_TEMPLATE/bug_report.md)
- [Feature Request Template](.github/ISSUE_TEMPLATE/feature_request.md)

View file

@ -4,7 +4,7 @@ The Brainy interactive demo showcases the library's features in a web browser. F
## Prerequisites
- Make sure you have Node.js installed (version 23.0.0 or higher)
- Make sure you have Node.js installed (version 24.3.0 or higher)
- Ensure the project is built (run both `npm run build` and `npm run build:browser`)
## Running the Demo

View file

@ -6,7 +6,7 @@
[![Node.js](https://img.shields.io/badge/node-%3E%3D24.3.0-brightgreen.svg)](https://nodejs.org/)
[![TypeScript](https://img.shields.io/badge/TypeScript-5.4.5-blue.svg)](https://www.typescriptlang.org/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
[![npm](https://img.shields.io/badge/npm-v0.9.37-blue.svg)](https://www.npmjs.com/package/@soulcraft/brainy)
[![npm](https://img.shields.io/badge/npm-v0.10.0-blue.svg)](https://www.npmjs.com/package/@soulcraft/brainy)
[//]: # ([![Cartographer]&#40;https://img.shields.io/badge/Cartographer-Official%20Standard-brightgreen&#41;]&#40;https://github.com/sodal-project/cartographer&#41;)
@ -1248,7 +1248,7 @@ comprehensive [Scaling Strategy](scalingStrategy.md) document.
## Requirements
- Node.js >= 23.0.0
- Node.js >= 24.3.0
## Contributing

View file

@ -1,24 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
## [0.9.37] - 2025-07-04
**Full Changelog**: https://github.com/soulcraft-research/brainy/compare/v0.9.36...v0.9.37
## [0.9.36] - 2025-07-04
**Full Changelog**: https://github.com/soulcraft-research/brainy/commits/v0.9.36
## [0.9.34] - 2024-07-01
This is the initial changelog entry. Future releases will automatically update this file with release notes from GitHub.
### Added
- Auto-generation of release notes for GitHub releases
- Auto-updating of CHANGELOG.md files for both main and CLI packages
- Display of release notes on npmjs.com through the CHANGELOG.md files
### Changed
- Modified deployment scripts to ensure GitHub releases are created with auto-generated notes
- Updated package.json files to include CHANGELOG.md in published packages

View file

@ -47,12 +47,7 @@ brainy generate-random-graph --noun-count 20 --verb-count 30 --clear
## Requirements
- Node.js >= 23.0.0
## Changelog
### 0.9.25
- Completely removed unnecessary compatibility patches for Node.js v24 as they are no longer needed with current TensorFlow.js versions
- Node.js >= 24.3.0
## License

View file

@ -18,22 +18,27 @@ if (
// Define a PlatformNode class that uses the global TextEncoder/TextDecoder directly
class PlatformNode {
constructor() {
// Create a util object with only the necessary methods
this.util = {
isFloat32Array: (arr) =>
!!(
arr instanceof Float32Array ||
(arr &&
Object.prototype.toString.call(arr) === '[object Float32Array]')
),
isTypedArray: (arr) =>
!!(ArrayBuffer.isView(arr) && !(arr instanceof DataView))
}
// Create a util object (empty but kept for compatibility)
this.util = {}
// Initialize TextEncoder/TextDecoder instances directly from global
this.textEncoder = new TextEncoder()
this.textDecoder = new TextDecoder()
}
// Define isFloat32Array directly on the instance
isFloat32Array(arr) {
return !!(
arr instanceof Float32Array ||
(arr &&
Object.prototype.toString.call(arr) === '[object Float32Array]')
)
}
// Define isTypedArray directly on the instance
isTypedArray(arr) {
return !!(ArrayBuffer.isView(arr) && !(arr instanceof DataView))
}
}
// Assign the PlatformNode class to the global object

View file

@ -1,6 +1,6 @@
{
"name": "@soulcraft/brainy-cli",
"version": "0.9.37",
"version": "0.10.0",
"description": "Command-line interface for the Brainy vector graph database",
"type": "module",
"bin": {
@ -9,7 +9,6 @@
"files": [
"cli-wrapper.js",
"README.md",
"CHANGELOG.md",
"dist/cli.js",
"dist/cli.js.map"
],
@ -41,7 +40,7 @@
"url": "git+https://github.com/soulcraft-research/brainy.git"
},
"dependencies": {
"@soulcraft/brainy": "0.9.37",
"@soulcraft/brainy": "0.10.0",
"commander": "^14.0.0",
"omelette": "^0.4.17"
},

View file

@ -28,15 +28,6 @@ export function applyTensorFlowPatch(): void {
constructor() {
// Create a util object with necessary methods and constructors
this.util = {
isFloat32Array: (arr: any) =>
!!(
arr instanceof Float32Array ||
(arr &&
Object.prototype.toString.call(arr) ===
'[object Float32Array]')
),
isTypedArray: (arr: any) =>
!!(ArrayBuffer.isView(arr) && !(arr instanceof DataView)),
// Use native TextEncoder and TextDecoder
TextEncoder: TextEncoder,
TextDecoder: TextDecoder
@ -46,6 +37,21 @@ export function applyTensorFlowPatch(): void {
this.textEncoder = new this.util.TextEncoder()
this.textDecoder = new this.util.TextDecoder()
}
// Define isFloat32Array directly on the instance
isFloat32Array(arr: any) {
return !!(
arr instanceof Float32Array ||
(arr &&
Object.prototype.toString.call(arr) ===
'[object Float32Array]')
)
}
// Define isTypedArray directly on the instance
isTypedArray(arr: any) {
return !!(ArrayBuffer.isView(arr) && !(arr instanceof DataView))
}
}
// Assign the PlatformNode class to the global object

View file

@ -99,9 +99,10 @@
})
async function runWorkerTest(resultDiv) {
// Define a compute-intensive function
// Define a compute-intensive function using a function expression
// This is more compatible with how the worker evaluates the function string
const computeIntensiveFunction = `
function(data) {
function computeTask(data) {
console.log('Worker/Fallback: Starting computation...');
// Simulate a compute-intensive task
@ -114,13 +115,20 @@
const duration = Date.now() - start;
console.log('Worker/Fallback: Computation completed in ' + duration + 'ms');
const globalObj = typeof self !== 'undefined' ? self :
typeof window !== 'undefined' ? window :
{};
return {
result,
duration,
iterations: data.iterations,
webWorkersAvailable: typeof window.Worker !== 'undefined'
webWorkersAvailable: typeof globalObj.Worker !== 'undefined'
};
}
// Return the function itself
computeTask;
`
// Execute the function

View file

@ -6,7 +6,7 @@ This document explains how to publish both the @soulcraft/brainy and @soulcraft/
Before publishing, ensure you have:
1. Node.js >= 23.0.0 installed
1. Node.js >= 24.3.0 installed
2. An npm account with access to the @soulcraft organization
3. Logged in to npm using `npm login`

View file

@ -41,8 +41,8 @@
"lint": "eslint --ext .ts,.js src/",
"lint:fix": "eslint --ext .ts,.js src/ --fix",
"format": "prettier --write \"src/**/*.{ts,js}\"",
"check-format": "prettier --check \"src/**/*.{ts,js}\"",
"check-style": "node scripts/check-code-style.js",
"check:format": "prettier --check \"src/**/*.{ts,js}\"",
"check:style": "node scripts/check-code-style.js",
"prepare": "npm run build",
"deploy": "npm run build && npm publish && node scripts/create-github-release.js",
"deploy:cli": "node scripts/generate-version.js && cd cli-package && npm run build && npm publish",
@ -52,8 +52,8 @@
"deploy:cloud": "echo 'Please use one of the following commands to deploy to a specific cloud provider:' && echo ' npm run deploy:cloud:aws' && echo ' npm run deploy:cloud:gcp' && echo ' npm run deploy:cloud:cloudflare'",
"postinstall": "echo 'Note: If you encounter dependency conflicts with TensorFlow.js packages, please use: npm install --legacy-peer-deps'",
"dry-run": "npm pack --dry-run",
"test-cli": "node scripts/test-cli-locally.js",
"test-all": "node scripts/test-all-environments.js"
"test:cli": "node scripts/test-cli-locally.js",
"test:all": "node scripts/test-all-environments.js"
},
"keywords": [
"vector-database",
@ -93,7 +93,6 @@
"dist/utils/",
"LICENSE",
"README.md",
"CHANGELOG.md",
"brainy.png"
],
"devDependencies": {

View file

@ -81,17 +81,15 @@ try {
console.log(`GitHub release v${version} created successfully!`)
// Update CHANGELOG.md with the release notes
console.log('Updating CHANGELOG.md with release notes...')
execSync('node scripts/update-changelog.js', { stdio: 'inherit', cwd: rootDir })
// GitHub will automatically handle the changelog
console.log('GitHub release created with auto-generated notes')
} catch (error) {
// If the release already exists, this is not a fatal error
if (error.message.includes('already exists')) {
console.log(`GitHub release v${version} already exists, skipping creation.`)
// Still update CHANGELOG.md with the release notes
console.log('Updating CHANGELOG.md with release notes...')
execSync('node scripts/update-changelog.js', { stdio: 'inherit', cwd: rootDir })
// GitHub will automatically handle the changelog
console.log('GitHub release already exists with auto-generated notes')
} else {
console.error('Error creating GitHub release:', error.message)
// Don't exit with error to allow the npm publish to continue

View file

@ -63,6 +63,28 @@ if (fs.existsSync(minifiedJsPath)) {
}
}
// Also patch the worker.js file if it exists
const workerJsPath = path.join(__dirname, '..', 'dist', 'worker.js')
if (fs.existsSync(workerJsPath)) {
console.log(`Reading ${workerJsPath}...`)
const workerContent = fs.readFileSync(workerJsPath, 'utf8')
// Apply the same replacement to the worker file
const patchedWorkerContent = workerContent.replace(pattern, replacement)
// Check if the patch was applied
if (patchedWorkerContent === workerContent) {
console.warn(
'No instances of "new this.util.TextEncoder()" found in the worker file.'
)
} else {
// Write the patched file
console.log('Writing patched worker file...')
fs.writeFileSync(workerJsPath, patchedWorkerContent, 'utf8')
console.log('Worker file patched successfully!')
}
}
// Also patch TextDecoder
console.log('Patching TextDecoder references...')
content = fs.readFileSync(unifiedJsPath, 'utf8')
@ -99,3 +121,21 @@ if (fs.existsSync(minifiedJsPath)) {
console.log('TextDecoder patch applied to minified file successfully!')
}
}
// Patch the worker.js file for TextDecoder as well
if (fs.existsSync(workerJsPath)) {
const workerContent = fs.readFileSync(workerJsPath, 'utf8')
const patchedWorkerDecoderContent = workerContent.replace(
decoderPattern,
decoderReplacement
)
if (patchedWorkerDecoderContent === workerContent) {
console.warn(
'No instances of "new this.util.TextDecoder()" found in the worker file.'
)
} else {
fs.writeFileSync(workerJsPath, patchedWorkerDecoderContent, 'utf8')
console.log('TextDecoder patch applied to worker file successfully!')
}
}

View file

@ -224,7 +224,7 @@ async function runAllTests() {
// Run CLI tests
log('Testing CLI package locally...', colors.yellow)
try {
runCommand('npm run test-cli')
runCommand('npm run test:cli')
log('CLI test completed!', colors.green)
// Run some basic CLI commands to verify functionality
@ -245,7 +245,7 @@ async function runAllTests() {
colors.yellow
)
log(
'You can run the CLI tests separately with: npm run test-cli',
'You can run the CLI tests separately with: npm run test:cli',
colors.yellow
)
}

View file

@ -1,138 +0,0 @@
#!/usr/bin/env node
/**
* Update Changelog Script
*
* This script updates the CHANGELOG.md file with the latest release notes
* from GitHub. It's designed to be called after creating a GitHub release.
*
* The script:
* 1. Gets the current version from package.json
* 2. Fetches the release notes from GitHub for that version
* 3. Updates the CHANGELOG.md file with the new release notes
*
* This ensures that the CHANGELOG.md file is always up-to-date with the
* latest release notes, which will be displayed on npmjs.com.
*/
import { execSync } from 'child_process'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
// Get the directory of the current module
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// Path to the root directory
const rootDir = path.join(__dirname, '..')
// Path to package.json
const packageJsonPath = path.join(rootDir, 'package.json')
// Path to CHANGELOG.md
const changelogPath = path.join(rootDir, 'CHANGELOG.md')
// Read package.json
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
const version = packageJson.version
// Check if GitHub CLI is installed
try {
execSync('gh --version', { stdio: 'ignore' })
} catch (error) {
console.error('Error: GitHub CLI (gh) is not installed or not in PATH')
console.error('Please install it from https://cli.github.com/ and authenticate with `gh auth login`')
process.exit(1)
}
// Fetch release notes from GitHub
try {
console.log(`Fetching release notes for v${version} from GitHub...`)
// Get the release notes using GitHub CLI
const releaseNotes = execSync(
`gh release view v${version} --json body --jq .body`,
{ encoding: 'utf8', cwd: rootDir }
).trim()
// Create or update the CHANGELOG.md file
let changelog = ''
// If CHANGELOG.md exists, read its content
if (fs.existsSync(changelogPath)) {
changelog = fs.readFileSync(changelogPath, 'utf8')
} else {
// Create a new CHANGELOG.md file with a header
changelog = '# Changelog\n\nAll notable changes to this project will be documented in this file.\n\n'
}
// Format the new entry
const date = new Date().toISOString().split('T')[0]
const newEntry = `## [${version}] - ${date}\n\n${releaseNotes}\n\n`
// Check if this version is already in the changelog
if (changelog.includes(`## [${version}]`)) {
// Replace the existing entry
const versionRegex = new RegExp(`## \\[${version}\\].*?(?=## \\[|$)`, 's')
changelog = changelog.replace(versionRegex, newEntry)
} else {
// Add the new entry after the header (before the first version entry)
const firstVersionIndex = changelog.search(/## \[\d+\.\d+\.\d+\]/)
if (firstVersionIndex !== -1) {
// Insert before the first version entry
changelog = changelog.slice(0, firstVersionIndex) + newEntry + changelog.slice(firstVersionIndex)
} else {
// No existing version entries, append to the end
changelog += newEntry
}
}
// Write the updated changelog
fs.writeFileSync(changelogPath, changelog)
console.log(`CHANGELOG.md updated with release notes for v${version}`)
// Also update the CLI package's CHANGELOG.md
const cliChangelogPath = path.join(rootDir, 'cli-package', 'CHANGELOG.md')
// Create or update the CLI CHANGELOG.md file
let cliChangelog = ''
// If CLI CHANGELOG.md exists, read its content
if (fs.existsSync(cliChangelogPath)) {
cliChangelog = fs.readFileSync(cliChangelogPath, 'utf8')
} else {
// Create a new CHANGELOG.md file with a header
cliChangelog = '# Changelog\n\nAll notable changes to this project will be documented in this file.\n\n'
}
// Check if this version is already in the changelog
if (cliChangelog.includes(`## [${version}]`)) {
// Replace the existing entry
const versionRegex = new RegExp(`## \\[${version}\\].*?(?=## \\[|$)`, 's')
cliChangelog = cliChangelog.replace(versionRegex, newEntry)
} else {
// Add the new entry after the header (before the first version entry)
const firstVersionIndex = cliChangelog.search(/## \[\d+\.\d+\.\d+\]/)
if (firstVersionIndex !== -1) {
// Insert before the first version entry
cliChangelog = cliChangelog.slice(0, firstVersionIndex) + newEntry + cliChangelog.slice(firstVersionIndex)
} else {
// No existing version entries, append to the end
cliChangelog += newEntry
}
}
// Write the updated CLI changelog
fs.writeFileSync(cliChangelogPath, cliChangelog)
console.log(`CLI package CHANGELOG.md updated with release notes for v${version}`)
} catch (error) {
console.error('Error updating CHANGELOG.md:', error.message)
// Don't exit with error to allow the process to continue
// process.exit(1)
}

View file

@ -114,54 +114,69 @@ export function getTextDecoder(): IUniversalTextDecoder {
* that uses our text encoding utilities instead of relying on TextEncoder/TextDecoder
*/
export function applyTensorFlowPatch(): void {
// Only apply in Node.js environment
if (
typeof global !== 'undefined' &&
typeof process !== 'undefined' &&
process.versions &&
process.versions.node
) {
try {
// Get encoders/decoders
const encoder = getTextEncoder()
const decoder = getTextDecoder()
try {
// Get encoders/decoders
const encoder = getTextEncoder()
const decoder = getTextDecoder()
// Define a custom PlatformNode class
class PlatformNode {
util: any
textEncoder: any
textDecoder: any
// Define a custom Platform class that works in both Node.js and browser environments
class Platform {
util: any
textEncoder: any
textDecoder: any
constructor() {
// Create a util object with necessary methods and constructors
this.util = {
isFloat32Array: (arr: any) =>
!!(
arr instanceof Float32Array ||
(arr &&
Object.prototype.toString.call(arr) ===
'[object Float32Array]')
),
isTypedArray: (arr: any) =>
!!(ArrayBuffer.isView(arr) && !(arr instanceof DataView)),
// Add TextEncoder and TextDecoder as constructors
TextEncoder: UniversalTextEncoder,
TextDecoder: UniversalTextDecoder
}
// Initialize using the constructors from util
this.textEncoder = new this.util.TextEncoder()
this.textDecoder = new this.util.TextDecoder()
constructor() {
// Create a util object with necessary methods and constructors
this.util = {
// Add TextEncoder and TextDecoder as constructors
TextEncoder: UniversalTextEncoder,
TextDecoder: UniversalTextDecoder
}
// Initialize using the constructors from util
this.textEncoder = new this.util.TextEncoder()
this.textDecoder = new this.util.TextDecoder()
}
// Assign the PlatformNode class to the global object
;(global as any).PlatformNode = PlatformNode
// Define isFloat32Array directly on the instance
isFloat32Array(arr: any) {
return !!(
arr instanceof Float32Array ||
(arr &&
Object.prototype.toString.call(arr) ===
'[object Float32Array]')
)
}
// Also create an instance and assign it to global.platformNode (lowercase p)
;(global as any).platformNode = new PlatformNode()
} catch (error) {
console.warn('Failed to apply TensorFlow.js platform patch:', error)
// Define isTypedArray directly on the instance
isTypedArray(arr: any) {
return !!(ArrayBuffer.isView(arr) && !(arr instanceof DataView))
}
}
// Get the global object in a way that works in both Node.js and browser
const globalObj = typeof global !== 'undefined' ? global :
typeof window !== 'undefined' ? window :
typeof self !== 'undefined' ? self :
{};
// Only apply in Node.js environment
if (
typeof process !== 'undefined' &&
process.versions &&
process.versions.node
) {
// Assign the Platform class to the global object as PlatformNode for Node.js
(globalObj as any).PlatformNode = Platform;
// Also create an instance and assign it to global.platformNode (lowercase p)
(globalObj as any).platformNode = new Platform();
} else if (typeof window !== 'undefined' || typeof self !== 'undefined') {
// In browser environments, we might need to provide similar functionality
// but we'll use a different name to avoid conflicts
(globalObj as any).PlatformBrowser = Platform;
(globalObj as any).platformBrowser = new Platform();
}
} catch (error) {
console.warn('Failed to apply TensorFlow.js platform patch:', error)
}
}

View file

@ -3,4 +3,4 @@
* Do not modify this file directly.
*/
export const VERSION = '0.9.37';
export const VERSION = '0.10.0';