npm package: @magic-ingredients/tiny-brain-core
Description: Stateless AI assistant business logic for MCP servers
Author: Magic Ingredients
Latest version: 0.22.0

# @magic-ingredients/tiny-brain-core

Stateless AI assistant business logic for MCP (Model Context Protocol) servers.

## Overview

This package provides the core business logic for the Tiny Brain AI assistant. It contains pure, stateless functions and services that can be used to build MCP servers or other AI assistant applications.

## Features

- 🧠 **Chat Analysis** - Intent classification, sentiment analysis, complexity scoring
- 💾 **Memory Management** - Fact extraction, knowledge graphs, memory search
- 👤 **Persona System** - Dynamic personality management and learning
- 📋 **Planning Tools** - Task management, phase extraction, plan formatting
- 💭 **Sequential Thinking** - Step-by-step reasoning with consistency checking
- 🎯 **Response Strategy** - Content planning and structure optimization
- ✅ **Response Validation** - Quality checks and validation

## Installation

```bash
npm install @magic-ingredients/tiny-brain-core
```

## Usage

### Services

Services provide high-level APIs for complex operations:

```typescript
import { 
  PersonaService,
  MemoryService,
  PlanningService,
  ChatAnalysisService,
  ThinkingService
} from '@magic-ingredients/tiny-brain-core';

// Create a service with dependencies
const personaService = new PersonaService({
  storage: myStorageAdapter,
  logger: myLogger,
  userId: 'user-123',
  sessionId: 'session-456'
});

// Use the service
const result = await personaService.switchPersona({ 
  personaName: 'professional' 
});
```

### Modules

Modules are pure functions for specific operations:

```typescript
import { 
  IntentClassifier,
  FactExtractor,
  PhaseExtractor 
} from '@magic-ingredients/tiny-brain-core';

// Classify user intent
const intent = await IntentClassifier.classify(
  "How do I set up authentication?"
);

// Extract facts from text
const facts = await FactExtractor.extract(
  "Python was created by Guido van Rossum in 1991"
);
```

### Storage Interface

Implement the `DeploymentStorageAdapter` interface for your storage backend:

```typescript
import { DeploymentStorageAdapter } from '@magic-ingredients/tiny-brain-core';

class MyStorageAdapter implements DeploymentStorageAdapter {
  // Implement required methods
  async getPersona(personaId: string) { /* ... */ }
  async storePersona(persona: PersonaProfile) { /* ... */ }
  // ... other methods
}
```

## Architecture

- **Stateless** - All functions are pure with no internal state
- **Service Pattern** - High-level services coordinate module operations
- **Dependency Injection** - Storage and logging injected via context
- **Type-Safe** - Full TypeScript support with strict typing
- **Test-Driven** - Comprehensive test coverage (68%+)
- **Platform Agnostic** - Runs anywhere TypeScript runs

## Related Packages

- `@magic-ingredients/tiny-brain-local` - Local MCP server implementation
- `@magic-ingredients/tiny-brain-remote` - Cloud deployment implementations

## Contributing

This project follows Test-Driven Development (TDD) principles. All new features must include tests.

## License

MIT © Magic Ingredients