This repository has been archived on 2026-02-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
BreakPilot Dev 19855efacc
Some checks failed
Tests / Go Tests (push) Has been cancelled
Tests / Python Tests (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / Go Lint (push) Has been cancelled
Tests / Python Lint (push) Has been cancelled
Tests / Security Scan (push) Has been cancelled
Tests / All Checks Passed (push) Has been cancelled
Security Scanning / Secret Scanning (push) Has been cancelled
Security Scanning / Dependency Vulnerability Scan (push) Has been cancelled
Security Scanning / Go Security Scan (push) Has been cancelled
Security Scanning / Python Security Scan (push) Has been cancelled
Security Scanning / Node.js Security Scan (push) Has been cancelled
Security Scanning / Docker Image Security (push) Has been cancelled
Security Scanning / Security Summary (push) Has been cancelled
CI/CD Pipeline / Go Tests (push) Has been cancelled
CI/CD Pipeline / Python Tests (push) Has been cancelled
CI/CD Pipeline / Website Tests (push) Has been cancelled
CI/CD Pipeline / Linting (push) Has been cancelled
CI/CD Pipeline / Security Scan (push) Has been cancelled
CI/CD Pipeline / Docker Build & Push (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / CI Summary (push) Has been cancelled
ci/woodpecker/manual/build-ci-image Pipeline was successful
ci/woodpecker/manual/main Pipeline failed
feat: BreakPilot PWA - Full codebase (clean push without large binaries)
All services: admin-v2, studio-v2, website, ai-compliance-sdk,
consent-service, klausur-service, voice-service, and infrastructure.
Large PDFs and compiled binaries excluded via .gitignore.
2026-02-11 13:25:58 +01:00

153 lines
5.1 KiB
Python

"""
Voice Session Models
Transient session management - no persistent storage of audio data
DSGVO Compliance:
- Sessions are RAM-only
- Audio chunks are processed and discarded
- Transcripts are encrypted before any storage
"""
from datetime import datetime
from enum import Enum
from typing import Optional, List, Dict, Any
from pydantic import BaseModel, Field
import uuid
class SessionStatus(str, Enum):
"""Voice session status."""
CREATED = "created"
CONNECTED = "connected"
LISTENING = "listening"
PROCESSING = "processing"
RESPONDING = "responding"
PAUSED = "paused"
CLOSED = "closed"
ERROR = "error"
class AudioChunk(BaseModel):
"""
Audio chunk for streaming.
NEVER persisted - only exists in RAM during processing.
"""
sequence: int = Field(..., description="Chunk sequence number")
timestamp_ms: int = Field(..., description="Timestamp in milliseconds")
data: bytes = Field(..., description="PCM audio data (Int16, 24kHz)")
duration_ms: int = Field(default=80, description="Chunk duration in ms")
class Config:
# Exclude from serialization to prevent accidental logging
json_encoders = {
bytes: lambda v: f"<audio:{len(v)} bytes>"
}
class TranscriptMessage(BaseModel):
"""
Transcript message - encrypted before storage.
"""
id: str = Field(default_factory=lambda: str(uuid.uuid4()))
role: str = Field(..., description="'user' or 'assistant'")
content: str = Field(..., description="Transcript text (plaintext in RAM only)")
timestamp: datetime = Field(default_factory=datetime.utcnow)
confidence: Optional[float] = Field(default=None, description="ASR confidence 0-1")
intent: Optional[str] = Field(default=None, description="Detected intent")
encrypted_ref: Optional[str] = Field(default=None, description="Encrypted storage reference")
class Config:
json_schema_extra = {
"example": {
"id": "msg-123",
"role": "user",
"content": "Notiz zu Max: heute wiederholt gestoert",
"timestamp": "2026-01-26T10:30:00Z",
"confidence": 0.95,
"intent": "student_observation",
}
}
class VoiceSession(BaseModel):
"""
Voice session state.
Stored in Valkey with TTL, never in persistent storage.
"""
id: str = Field(default_factory=lambda: str(uuid.uuid4()))
namespace_id: str = Field(..., description="Teacher namespace ID")
key_hash: str = Field(..., description="Hash of client-side encryption key")
status: SessionStatus = Field(default=SessionStatus.CREATED)
created_at: datetime = Field(default_factory=datetime.utcnow)
last_activity: datetime = Field(default_factory=datetime.utcnow)
# Conversation state (transient)
messages: List[TranscriptMessage] = Field(default_factory=list)
pending_tasks: List[str] = Field(default_factory=list, description="Task IDs")
# Audio state (never persisted)
audio_chunks_received: int = Field(default=0)
audio_chunks_processed: int = Field(default=0)
# Metadata (no PII)
device_type: Optional[str] = Field(default=None, description="'pwa' or 'app'")
client_version: Optional[str] = Field(default=None)
def update_activity(self):
"""Update last activity timestamp."""
self.last_activity = datetime.utcnow()
class Config:
json_schema_extra = {
"example": {
"id": "session-abc123",
"namespace_id": "teacher-ns-456",
"key_hash": "sha256:abc...",
"status": "listening",
"created_at": "2026-01-26T10:00:00Z",
"last_activity": "2026-01-26T10:30:00Z",
"messages": [],
"pending_tasks": [],
"audio_chunks_received": 150,
"audio_chunks_processed": 150,
"device_type": "pwa",
}
}
class SessionCreate(BaseModel):
"""Request to create a new voice session."""
namespace_id: str = Field(..., description="Teacher namespace ID")
key_hash: str = Field(..., description="Hash of client-side encryption key")
device_type: Optional[str] = Field(default="pwa")
client_version: Optional[str] = Field(default=None)
class Config:
json_schema_extra = {
"example": {
"namespace_id": "teacher-ns-456",
"key_hash": "sha256:abc123def456...",
"device_type": "pwa",
"client_version": "1.0.0",
}
}
class SessionResponse(BaseModel):
"""Response after session creation."""
id: str
namespace_id: str
status: SessionStatus
created_at: datetime
websocket_url: str = Field(..., description="WebSocket URL for audio streaming")
class Config:
json_schema_extra = {
"example": {
"id": "session-abc123",
"namespace_id": "teacher-ns-456",
"status": "created",
"created_at": "2026-01-26T10:00:00Z",
"websocket_url": "ws://localhost:8091/ws/voice?session_id=session-abc123",
}
}