feat: add intelligent storage auto-detection as default
- Change default storage from 'memory' to 'auto' for smart environment detection - Add 'auto' support to storage type validation and TypeScript types - Browser: auto-selects OPFS → memory fallback - Node.js: auto-selects filesystem → memory fallback - Cloud: auto-detects S3/GCS/R2 → disk → memory fallback - Eliminates need for manual storage configuration in most cases 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
ec8781a976
commit
909e3d3ee0
2 changed files with 5 additions and 5 deletions
|
|
@ -1736,7 +1736,7 @@ export class Brainy<T = any> implements BrainyInterface<T> {
|
||||||
*/
|
*/
|
||||||
private async setupStorage(): Promise<StorageAdapter> {
|
private async setupStorage(): Promise<StorageAdapter> {
|
||||||
const storage = await createStorage({
|
const storage = await createStorage({
|
||||||
type: this.config.storage?.type || 'memory',
|
type: this.config.storage?.type || 'auto',
|
||||||
...this.config.storage?.options
|
...this.config.storage?.options
|
||||||
})
|
})
|
||||||
return storage
|
return storage
|
||||||
|
|
@ -1790,8 +1790,8 @@ export class Brainy<T = any> implements BrainyInterface<T> {
|
||||||
*/
|
*/
|
||||||
private normalizeConfig(config?: BrainyConfig): Required<BrainyConfig> {
|
private normalizeConfig(config?: BrainyConfig): Required<BrainyConfig> {
|
||||||
// Validate storage configuration
|
// Validate storage configuration
|
||||||
if (config?.storage?.type && !['memory', 'filesystem', 'opfs', 'remote'].includes(config.storage.type)) {
|
if (config?.storage?.type && !['auto', 'memory', 'filesystem', 'opfs', 'remote', 's3', 'r2', 'gcs'].includes(config.storage.type)) {
|
||||||
throw new Error(`Invalid storage type: ${config.storage.type}. Must be one of: memory, filesystem, opfs, remote`)
|
throw new Error(`Invalid storage type: ${config.storage.type}. Must be one of: auto, memory, filesystem, opfs, remote, s3, r2, gcs`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate model configuration
|
// Validate model configuration
|
||||||
|
|
@ -1813,7 +1813,7 @@ export class Brainy<T = any> implements BrainyInterface<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
storage: config?.storage || { type: 'memory' },
|
storage: config?.storage || { type: 'auto' },
|
||||||
model: config?.model || { type: 'fast' },
|
model: config?.model || { type: 'fast' },
|
||||||
index: config?.index || {},
|
index: config?.index || {},
|
||||||
cache: config?.cache ?? true,
|
cache: config?.cache ?? true,
|
||||||
|
|
|
||||||
|
|
@ -311,7 +311,7 @@ export type AggregateMetric =
|
||||||
export interface BrainyConfig {
|
export interface BrainyConfig {
|
||||||
// Storage configuration
|
// Storage configuration
|
||||||
storage?: {
|
storage?: {
|
||||||
type: 'memory' | 'filesystem' | 's3' | 'r2' | 'opfs'
|
type: 'auto' | 'memory' | 'filesystem' | 's3' | 'r2' | 'opfs' | 'gcs'
|
||||||
options?: any
|
options?: any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue