Metadata-Version: 2.4
Name: private-assistant-commons
Version: 6.3.0
Summary: Common utilities and base functionalities for all skills in the Private Assistant ecosystem.
Keywords: 
Author: stkr22
Author-email: stkr22 <stkr22@github.com>
License-Expression: GPL-3.0-only
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Programming Language :: Python
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Topic :: Home Automation
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: pydantic~=2.12.5
Requires-Dist: aiomqtt~=2.5.0
Requires-Dist: pyyaml~=6.0.1
Requires-Dist: rich~=14.2.0
Requires-Dist: pydantic-settings>=2.11.0
Requires-Dist: sqlmodel~=0.0.25
Requires-Dist: asyncpg~=0.31.0
Requires-Python: >=3.12, <3.14
Project-URL: Homepage, https://github.com/stkr22/private-assistant-commons-py
Project-URL: Repository, https://github.com/stkr22/private-assistant-commons-py
Project-URL: Documentation, https://github.com/stkr22/private-assistant-commons-py/tree/main/docs
Project-URL: Issues, https://github.com/stkr22/private-assistant-commons-py/issues
Project-URL: Changelog, https://github.com/stkr22/private-assistant-commons-py/blob/main/CHANGELOG.md
Description-Content-Type: text/markdown

# Private Assistant Commons

[![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-orange.json)](https://github.com/copier-org/copier)
[![Python](https://img.shields.io/badge/Python-3776AB?logo=python&logoColor=fff)](#)
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v0.json)](https://github.com/charliermarsh/ruff)
[![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)


Common utilities and base classes for building distributed voice assistant skills in a Private Assistant ecosystem. This library provides the foundation for creating modular, MQTT-based skills that process voice commands for home automation.

## Key Features

- **BaseSkill Framework**: Abstract base class with distributed processing, certainty-based filtering, and task management
- **MQTT Communication**: Structured message handling using Pydantic models with automatic reconnection
- **Location Awareness**: Support for room-based command routing and targeting
- **Audio Integration**: Configurable alerts and responses through voice bridge system
- **Performance Metrics**: Built-in monitoring with Prometheus export and health checking for production deployments
- **Optional Persistence**: PostgreSQL integration for skills requiring state storage

## Quick Start

### Installation

```bash
pip install private-assistant-commons
```

### Basic Skill Example

```python
from private_assistant_commons import BaseSkill, IntentRequest, IntentType

class LightControlSkill(BaseSkill):
    async def calculate_certainty(self, intent_request: IntentRequest) -> float:
        intent = intent_request.classified_intent
        if intent.intent_type in (IntentType.DEVICE_ON, IntentType.DEVICE_OFF):
            return intent.confidence
        return 0.0

    async def process_request(self, intent_request: IntentRequest) -> None:
        await self.send_response("Lights controlled!", intent_request.client_request)

    async def skill_preparations(self) -> None:
        self.logger.info("Light skill ready")
```

## Documentation

📖 **[Full Documentation](docs/)**

- **[Architecture Guide](docs/architecture.md)** - System design, components, and data flow
- **[Usage Guide](docs/usage.md)** - Examples, patterns, and best practices
- **[API Reference](docs/api-reference.md)** - Complete API documentation

## System Overview

Private Assistant Commons enables building a distributed voice assistant system where:

- **Skills run independently** and decide whether to handle requests based on confidence scores
- **Communication via MQTT** using structured Pydantic messages
- **No central coordinator** - skills compete based on certainty thresholds
- **Room-based targeting** distinguishes command origin from target locations
- **Local deployment** typically on Kubernetes with STT/TTS APIs

## Architecture

```
User Voice → Local Client → Voice Bridge → STT API → MQTT Broker
                                                         ↓
Intent Analysis Engine ← MQTT Broker ← Skills (distributed processing)
                                                         ↓
Voice Bridge ← TTS API ← MQTT Broker ← Skill Responses
       ↓
Local Client → Audio Output
```

Skills inherit from `BaseSkill` and implement:
- `calculate_certainty()` - Confidence scoring for requests
- `process_request()` - Main skill logic
- `skill_preparations()` - Initialization setup

## Development

### Prerequisites

- Python 3.12+
- UV package manager

### Setup

```bash
# Clone and setup environment
git clone <repository-url>
cd private-assistant-commons-py
uv sync --group dev

# Run tests
uv run pytest

# Format and lint
uv run ruff format .
uv run ruff check .

# Type checking
uv run mypy src/
```

### Essential Commands

- `uv sync --group dev` - Install/update dependencies
- `uv run pytest` - Run tests with coverage
- `uv run ruff check .` - Lint code
- `uv run mypy src/` - Type check
- `pre-commit run --all-files` - Run all pre-commit hooks

## License

GNU General Public License v3.0 - see [LICENSE](LICENSE) for details.
