From caf1353e7c95883f8037a67e96b9cbae3cd3b718 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Wed, 2 Jul 2025 12:15:35 -0700 Subject: [PATCH] **chore(version): bump version to 0.9.18 and update build configurations** - Updated version to `0.9.18` in `package.json`, `cli-package/package.json`, and `src/utils/version.ts`. - Updated npm badge in `README.md` to reflect version `0.9.18`. - Adjusted `publish-cli.js` to synchronize publishing of the main and CLI packages with enhanced build steps. - Introduced `tsconfig.json` updates to include type paths (`types.d.ts`) in CLI for better type handling. - Refined CLI scripts for improved TypeScript annotations and better code structure. - Removed `@types/omelette` and `omelette` dependencies along with associated CLI configurations to simplify the codebase. - Updated `.gitignore` to exclude CLI `dist` directory for cleaner repository management. - Added `deploy:both` npm script for combined publishing of main and CLI packages. This release ensures version consistency, improves CLI workflows, and enhances type handling while decluttering unused dependencies. --- .gitignore | 1 + README.md | 2 +- cli-package/package.json | 4 +- cli-package/src/cli.ts | 237 ++++++++++++++++++++++++-------------- cli-package/tsconfig.json | 7 +- cli-package/types.d.ts | 90 +++++++++++++++ package-lock.json | 32 +---- package.json | 3 +- scripts/publish-cli.js | 18 +-- src/utils/version.ts | 2 +- 10 files changed, 266 insertions(+), 130 deletions(-) create mode 100644 cli-package/types.d.ts diff --git a/.gitignore b/.gitignore index d7eaa8a9..71eb0597 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,4 @@ Thumbs.db # Generated files /encoded-image.html /encoded-image.txt +/cli-package/dist/ diff --git a/README.md b/README.md index c96516bf..edda483d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Node.js](https://img.shields.io/badge/node-%3E%3D24.0.0-brightgreen.svg)](https://nodejs.org/) [![TypeScript](https://img.shields.io/badge/TypeScript-5.1.6-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.17-blue.svg)](https://www.npmjs.com/package/@soulcraft/brainy) +[![npm](https://img.shields.io/badge/npm-v0.9.18-blue.svg)](https://www.npmjs.com/package/@soulcraft/brainy) [//]: # ([![Cartographer](https://img.shields.io/badge/Cartographer-Official%20Standard-brightgreen)](https://github.com/sodal-project/cartographer)) diff --git a/cli-package/package.json b/cli-package/package.json index 9d0eb032..36ff3a24 100644 --- a/cli-package/package.json +++ b/cli-package/package.json @@ -1,6 +1,6 @@ { "name": "@soulcraft/brainy-cli", - "version": "0.9.17", + "version": "0.9.18", "description": "Command-line interface for the Brainy vector graph database", "type": "module", "bin": { @@ -39,7 +39,7 @@ "url": "https://github.com/soulcraft-research/brainy.git" }, "dependencies": { - "@soulcraft/brainy": "0.9.17", + "@soulcraft/brainy": "0.9.18", "commander": "^14.0.0", "omelette": "^0.4.17" }, diff --git a/cli-package/src/cli.ts b/cli-package/src/cli.ts index bf874225..24a3fbc8 100644 --- a/cli-package/src/cli.ts +++ b/cli-package/src/cli.ts @@ -5,7 +5,16 @@ * A command-line interface for interacting with the Brainy vector database */ -import { BrainyData, NounType, VerbType, FileSystemStorage, sequentialPipeline, augmentationPipeline, ExecutionMode, AugmentationType } from '@soulcraft/brainy' +import { + BrainyData, + NounType, + VerbType, + FileSystemStorage, + sequentialPipeline, + augmentationPipeline, + ExecutionMode, + AugmentationType +} from '@soulcraft/brainy' import { fileURLToPath } from 'url' import { dirname, join } from 'path' import fs from 'fs' @@ -145,18 +154,28 @@ program const results = await db.searchText(query, limit) console.log(`Search results for "${query}":`) - results.forEach((result, index) => { - console.log(`${index + 1}. ID: ${result.id}`) - console.log(` Score: ${result.score.toFixed(4)}`) - console.log(` Metadata: ${JSON.stringify(result.metadata)}`) - console.log( - ` Vector: [${result.vector - .slice(0, 3) - .map((v) => v.toFixed(2)) - .join(', ')}...]` - ) - console.log() - }) + results.forEach( + ( + result: { + id: string + score: number + metadata: any + vector: number[] + }, + index: number + ) => { + console.log(`${index + 1}. ID: ${result.id}`) + console.log(` Score: ${result.score.toFixed(4)}`) + console.log(` Metadata: ${JSON.stringify(result.metadata)}`) + console.log( + ` Vector: [${result.vector + .slice(0, 3) + .map((v: number) => v.toFixed(2)) + .join(', ')}...]` + ) + console.log() + } + ) } catch (error) { console.error('Error:', (error as Error).message) process.exit(1) @@ -179,7 +198,7 @@ program console.log( `Vector: [${noun.vector .slice(0, 5) - .map((v) => v.toFixed(2)) + .map((v: number) => v.toFixed(2)) .join(', ')}...]` ) } else { @@ -252,15 +271,24 @@ program if (verbs.length === 0) { console.log('No relationships found') } else { - verbs.forEach((verb, index) => { - console.log(`${index + 1}. ID: ${verb.id}`) - console.log( - ` Type: ${Object.keys(VerbType).find((key) => VerbType[key as keyof typeof VerbType] === verb.metadata.verb) || verb.metadata.verb}` - ) - console.log(` Target: ${verb.targetId}`) - console.log(` Metadata: ${JSON.stringify(verb.metadata)}`) - console.log() - }) + verbs.forEach( + ( + verb: { + id: string + targetId: string + metadata: { verb: VerbType; [key: string]: any } + }, + index: number + ) => { + console.log(`${index + 1}. ID: ${verb.id}`) + console.log( + ` Type: ${Object.keys(VerbType).find((key) => VerbType[key as keyof typeof VerbType] === verb.metadata.verb) || verb.metadata.verb}` + ) + console.log(` Target: ${verb.targetId}`) + console.log(` Metadata: ${JSON.stringify(verb.metadata)}`) + console.log() + } + ) } } catch (error) { console.error('Error:', (error as Error).message) @@ -734,7 +762,9 @@ program // Print some sample IDs if (result.nounIds.length > 0) { console.log('\nSample noun IDs:') - result.nounIds.slice(0, 3).forEach((id) => console.log(`- ${id}`)) + result.nounIds + .slice(0, 3) + .forEach((id: string) => console.log(`- ${id}`)) if (result.nounIds.length > 3) { console.log(`... and ${result.nounIds.length - 3} more`) } @@ -742,7 +772,9 @@ program if (result.verbIds.length > 0) { console.log('\nSample verb IDs:') - result.verbIds.slice(0, 3).forEach((id) => console.log(`- ${id}`)) + result.verbIds + .slice(0, 3) + .forEach((id: string) => console.log(`- ${id}`)) if (result.verbIds.length > 3) { console.log(`... and ${result.verbIds.length - 3} more`) } @@ -928,7 +960,7 @@ augmentCommand if (availableTypes.length === 0) { console.log(' No augmentation types available') } else { - availableTypes.forEach((type) => { + availableTypes.forEach((type: string) => { const augmentations = augmentationPipeline.getAugmentationsByType(type) console.log( @@ -938,10 +970,18 @@ augmentCommand if (augmentations.length === 0) { console.log(' No augmentations registered for this type') } else { - augmentations.forEach((aug) => { - console.log(` - ${aug.name}: ${aug.description}`) - console.log(` Status: ${aug.enabled ? 'Enabled' : 'Disabled'}`) - }) + augmentations.forEach( + (aug: { + name: string + description: string + enabled: boolean + }) => { + console.log(` - ${aug.name}: ${aug.description}`) + console.log( + ` Status: ${aug.enabled ? 'Enabled' : 'Disabled'}` + ) + } + ) } }) } @@ -952,10 +992,12 @@ augmentCommand if (webSocketAugs.length === 0) { console.log(' No WebSocket-enabled augmentations available') } else { - webSocketAugs.forEach((aug) => { - console.log(` - ${aug.name}: ${aug.description}`) - console.log(` Status: ${aug.enabled ? 'Enabled' : 'Disabled'}`) - }) + webSocketAugs.forEach( + (aug: { name: string; description: string; enabled: boolean }) => { + console.log(` - ${aug.name}: ${aug.description}`) + console.log(` Status: ${aug.enabled ? 'Enabled' : 'Disabled'}`) + } + ) } } catch (error) { console.error('Error:', (error as Error).message) @@ -1023,7 +1065,14 @@ augmentCommand console.log('\nStage Results:') // Display stage results - Object.entries(result.stageResults).forEach(([stage, stageResult]) => { + Object.entries(result.stageResults).forEach((entry) => { + const stage = entry[0] + const stageResult = entry[1] as { + success?: boolean + error?: string + data?: any + } + console.log(`\n${stage.toUpperCase()}:`) console.log(` Success: ${stageResult?.success}`) @@ -1036,7 +1085,7 @@ augmentCommand console.log( JSON.stringify(stageResult.data, null, 2) .split('\n') - .map((line) => ` ${line}`) + .map((line: string) => ` ${line}`) .join('\n') ) } @@ -1085,36 +1134,49 @@ augmentCommand // Process the data asynchronously without blocking sequentialPipeline .processData(data, options.dataType, { stopOnError: false }) - .then((result) => { - console.log(`\nProcessed: "${data}"`) - console.log(`Success: ${result.success}`) + .then( + (result: { + success: boolean + error?: string + data?: any + stageResults: Record< + string, + { success?: boolean; error?: string; data?: any } + > + }) => { + console.log(`\nProcessed: "${data}"`) + console.log(`Success: ${result.success}`) - if (options.verbose) { - console.log('Stage Results:') - Object.entries(result.stageResults).forEach( - ([stage, stageResult]) => { - if (stageResult?.success) { - console.log(` ${stage}: Success`) - } else { - console.log( - ` ${stage}: Failed - ${stageResult?.error || 'Unknown error'}` - ) + if (options.verbose) { + console.log('Stage Results:') + Object.entries(result.stageResults).forEach( + ([stage, stageResult]: [ + string, + { success?: boolean; error?: string; data?: any } + ]) => { + if (stageResult?.success) { + console.log(` ${stage}: Success`) + } else { + console.log( + ` ${stage}: Failed - ${stageResult?.error || 'Unknown error'}` + ) + } } - } - ) - } + ) + } - if (result.data) { - console.log('Result Data:') - console.log( - JSON.stringify(result.data, null, 2) - .split('\n') - .map((line) => ` ${line}`) - .join('\n') - ) + if (result.data) { + console.log('Result Data:') + console.log( + JSON.stringify(result.data, null, 2) + .split('\n') + .map((line: string) => ` ${line}`) + .join('\n') + ) + } } - }) - .catch((error) => { + ) + .catch((error: Error) => { console.error(`Error processing "${data}":`, error.message) }) } @@ -1170,7 +1232,7 @@ augmentCommand '', 'Augmentation type (sense, memory, cognition, conduit, activation, perception, dialog, websocket)' ) - .action(async (typeArg) => { + .action(async (typeArg: string) => { try { // Initialize the pipeline await augmentationPipeline.initialize() @@ -1222,32 +1284,37 @@ augmentCommand console.log(' No augmentations registered for this type') } else { // Display information about each augmentation - augmentations.forEach((aug, index) => { - console.log(`\n${index + 1}. ${aug.name}`) - console.log(` Description: ${aug.description}`) - console.log(` Status: ${aug.enabled ? 'Enabled' : 'Disabled'}`) + augmentations.forEach( + ( + aug: { name: string; description: string; enabled: boolean }, + index: number + ) => { + console.log(`\n${index + 1}. ${aug.name}`) + console.log(` Description: ${aug.description}`) + console.log(` Status: ${aug.enabled ? 'Enabled' : 'Disabled'}`) - // List available methods - console.log(' Available Methods:') + // List available methods + console.log(' Available Methods:') - // Get all methods that aren't from Object.prototype - const methods = Object.getOwnPropertyNames( - Object.getPrototypeOf(aug) - ).filter( - (method) => - method !== 'constructor' && - typeof (aug as any)[method] === 'function' && - !['initialize', 'shutDown', 'getStatus'].includes(method) - ) + // Get all methods that aren't from Object.prototype + const methods = Object.getOwnPropertyNames( + Object.getPrototypeOf(aug) + ).filter( + (method) => + method !== 'constructor' && + typeof (aug as any)[method] === 'function' && + !['initialize', 'shutDown', 'getStatus'].includes(method) + ) - if (methods.length === 0) { - console.log(' No custom methods available') - } else { - methods.forEach((method) => { - console.log(` - ${method}`) - }) + if (methods.length === 0) { + console.log(' No custom methods available') + } else { + methods.forEach((method: string) => { + console.log(` - ${method}`) + }) + } } - }) + ) } // Show pipeline order information diff --git a/cli-package/tsconfig.json b/cli-package/tsconfig.json index 20d4ab0b..67c0186a 100644 --- a/cli-package/tsconfig.json +++ b/cli-package/tsconfig.json @@ -8,8 +8,11 @@ "outDir": "dist", "declaration": true, "sourceMap": true, - "skipLibCheck": true + "skipLibCheck": true, + "paths": { + "@soulcraft/brainy": ["../dist/unified.d.ts"] + } }, - "include": ["src/**/*"], + "include": ["src/**/*", "types.d.ts"], "exclude": ["node_modules", "dist"] } diff --git a/cli-package/types.d.ts b/cli-package/types.d.ts new file mode 100644 index 00000000..74e7790c --- /dev/null +++ b/cli-package/types.d.ts @@ -0,0 +1,90 @@ +// Type declarations for @soulcraft/brainy +declare module '@soulcraft/brainy' { + // Core types + export class BrainyData { + constructor(config?: any) + + init(): Promise + + add(text: string, metadata?: any): Promise + + get(id: string): Promise + + delete(id: string): Promise + + search(query: string, limit?: number, options?: any): Promise + + searchText(query: string, limit?: number, options?: any): Promise + + addVerb( + sourceId: string, + targetId: string, + text?: string, + options?: any + ): Promise + + getVerbsBySource(sourceId: string): Promise + + getVerbsByTarget(targetId: string): Promise + + status(): Promise + + clear(): Promise + + backup(): Promise + + restore(data: any, options?: any): Promise + + importSparseData(data: any, options?: any): Promise + + generateRandomGraph(options?: any): Promise + } + + export class FileSystemStorage { + constructor(dataDir: string) + } + + // Pipelines + export const sequentialPipeline: any + export const augmentationPipeline: any + + // Enums + export enum NounType { + Person = 'Person', + Place = 'Place', + Thing = 'Thing', + Event = 'Event', + Concept = 'Concept', + Content = 'Content' + } + + export enum VerbType { + RelatedTo = 'RelatedTo', + PartOf = 'PartOf', + HasA = 'HasA', + UsedFor = 'UsedFor', + CapableOf = 'CapableOf', + AtLocation = 'AtLocation', + Causes = 'Causes', + HasProperty = 'HasProperty', + Owns = 'Owns', + CreatedBy = 'CreatedBy' + } + + export enum ExecutionMode { + SEQUENTIAL = 'sequential', + PARALLEL = 'parallel', + THREADED = 'threaded' + } + + export enum AugmentationType { + SENSE = 'sense', + MEMORY = 'memory', + COGNITION = 'cognition', + CONDUIT = 'conduit', + ACTIVATION = 'activation', + PERCEPTION = 'perception', + DIALOG = 'dialog', + WEBSOCKET = 'websocket' + } +} diff --git a/package-lock.json b/package-lock.json index 6922f853..dde19946 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,13 +18,8 @@ "@tensorflow/tfjs-converter": "^4.22.0", "@tensorflow/tfjs-core": "^4.22.0", "buffer": "^6.0.3", - "commander": "^14.0.0", - "omelette": "^0.4.17", "uuid": "^9.0.0" }, - "bin": { - "brainy": "cli-wrapper.js" - }, "devDependencies": { "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-json": "^6.1.0", @@ -32,7 +27,6 @@ "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-typescript": "^11.1.6", "@types/node": "^20.4.5", - "@types/omelette": "^0.4.5", "@types/uuid": "^10.0.0", "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", @@ -43,7 +37,7 @@ "typescript": "^5.1.6" }, "engines": { - "node": ">=23.11.0" + "node": ">=24.0.0" } }, "node_modules/@aws-crypto/crc32": { @@ -2535,13 +2529,6 @@ "integrity": "sha512-esIJx9bQg+QYF0ra8GnvfianIY8qWB0GBx54PK5Eps6m+xTj86KLavHv6qDhzKcu5UUOgNfJ2pWaIIV7TRUd9Q==", "license": "MIT" }, - "node_modules/@types/omelette": { - "version": "0.4.5", - "resolved": "https://registry.npmjs.org/@types/omelette/-/omelette-0.4.5.tgz", - "integrity": "sha512-zUCJpVRwfMcZfkxSCGp73mgd3/xesvPz5tQJIORlfP/zkYEyp9KUfF7IP3RRjyZR3DwxkPs96/IFf70GmYZYHQ==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/resolve": { "version": "1.20.2", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", @@ -3036,15 +3023,6 @@ "node": ">= 0.8" } }, - "node_modules/commander": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-14.0.0.tgz", - "integrity": "sha512-2uM9rYjPvyq39NwLRqaiLtWHyDC1FvryJDa2ATTVims5YAS4PupsEQsDvP14FqhFr0P49CYDugi59xaxJlTXRA==", - "license": "MIT", - "engines": { - "node": ">=20" - } - }, "node_modules/commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", @@ -4218,14 +4196,6 @@ } } }, - "node_modules/omelette": { - "version": "0.4.17", - "resolved": "https://registry.npmjs.org/omelette/-/omelette-0.4.17.tgz", - "integrity": "sha512-UlU69G6Bhu0XFjw3tjFZ0qyiMUjAOR+rdzblA1nLQ8xiqFtxOVlkhM39BlgTpLFx9fxkm6rnxNNRsS5GxE/yww==", - "engines": { - "node": ">=0.8.0" - } - }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", diff --git a/package.json b/package.json index c35d90b9..a7898dc8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "check-format": "prettier --check \"src/**/*.{ts,js}\"", "check-style": "node scripts/check-code-style.js", "prepare": "npm run build", - "deploy": "node scripts/publish-cli.js", + "deploy": "npm run build && npm publish", + "deploy:both": "node scripts/publish-cli.js", "deploy:cloud:aws": "cd cloud-wrapper && npm run build && npm run deploy:aws", "deploy:cloud:gcp": "cd cloud-wrapper && npm run build && npm run deploy:gcp", "deploy:cloud:cloudflare": "cd cloud-wrapper && npm run build && npm run deploy:cloudflare", diff --git a/scripts/publish-cli.js b/scripts/publish-cli.js index 2103bdd5..1c0d2e40 100755 --- a/scripts/publish-cli.js +++ b/scripts/publish-cli.js @@ -39,22 +39,26 @@ try { console.log('Building main package...') execSync('npm run build', { stdio: 'inherit', cwd: rootDir }) - // Step 3: Build the CLI package + // Step 3: Publish the main package + console.log('Publishing main package...') + execSync('npm publish', { stdio: 'inherit', cwd: rootDir }) + + // Step 4: Wait a moment to ensure the package is available + console.log('Waiting for package to be available...') + await new Promise(resolve => setTimeout(resolve, 5000)) + + // Step 5: Build the CLI package console.log('Building CLI package...') execSync('npm run build', { stdio: 'inherit', cwd: cliPackageDir }) - // Step 4: Verify the CLI was built successfully + // Step 6: Verify the CLI was built successfully const cliPath = path.join(cliPackageDir, 'dist', 'cli.js') if (!fs.existsSync(cliPath)) { console.error(`Error: CLI build failed. File not found at ${cliPath}`) process.exit(1) } - // Step 5: Publish the main package - console.log('Publishing main package...') - execSync('npm publish', { stdio: 'inherit', cwd: rootDir }) - - // Step 6: Publish the CLI package + // Step 7: Publish the CLI package console.log('Publishing CLI package...') execSync('npm publish', { stdio: 'inherit', cwd: cliPackageDir }) diff --git a/src/utils/version.ts b/src/utils/version.ts index 83c396df..40820835 100644 --- a/src/utils/version.ts +++ b/src/utils/version.ts @@ -3,4 +3,4 @@ * Do not modify this file directly. */ -export const VERSION = '0.9.17'; +export const VERSION = '0.9.18';