Commit Graph

15 Commits

Author SHA1 Message Date
CTO
b8f4427f90 fix: OpenRouter API key save fails with network error
All checks were successful
Deploy to VPS / deploy (push) Successful in 40s
The 0004_add_openrouter_provider.sql migration existed but was never
registered in _journal.json, so the 'openrouter' value was missing from
the api_key_provider PostgreSQL enum. Inserting an OpenRouter key threw
a DB error that was unhandled, causing Next.js to return an HTML 500;
the frontend's res.json() then threw, showing "Netzwerkfehler".

Fixes:
- Add 0004_add_openrouter_provider to _journal.json (idx 7) so the
  migration runs on next deploy and registers 'openrouter' in the enum
- Fix null-label duplicate check: use isNull() instead of passing
  undefined to and(), which incorrectly matched all provider keys
- Wrap DB insert in try/catch to return a proper JSON error instead of
  crashing with an unhandled exception

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-15 08:50:26 +00:00
CTO
2caf7d1229 fix: remove broken CROSS JOIN from migration 0005
All checks were successful
Deploy to VPS / deploy (push) Successful in 48s
The CROSS JOIN referenced s.system_prompt which didn't exist in the
VALUES alias, causing the entire migration transaction to fail.
This prevented the skills table from being created at all.

Seed is now handled entirely by migration 0006.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-13 21:30:33 +00:00
CTO
f0a7d6837b fix: use withTenantDb for skills API routes (RLS fix) and seed default skills
All checks were successful
Deploy to VPS / deploy (push) Successful in 40s
All skills API routes were using `db` directly instead of `withTenantDb`,
causing RLS to block all operations since `app.tenant_id` was never set.
This caused "Netzwerkfehler" when creating/reading skills.

Also fixes the broken seed migration (0005) which referenced a non-existent
column in the CROSS JOIN, preventing default system skills from being inserted.
New migration 0006 properly seeds the 4 default skills with full system prompts.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-13 21:15:24 +00:00
a5e58aa142 Merge pull request 'feat: Dynamic skill selection for analysis (AIIA-98)' (#4) from feat/aiia-98-dynamic-skill-selection into master
All checks were successful
Deploy to VPS / deploy (push) Successful in 46s
2026-04-13 20:44:20 +00:00
Frontend Engineer
aec4a39d10 feat: refactor analysis to use DB-driven skills (AIIA-96)
Replace hardcoded ANALYSIS_MODES lookups with database-driven skill loading:
- Add skills table to Drizzle schema with tenant-scoped, configurable skills
- Add analyses.skill_id FK and structured_result JSONB column
- Refactor runAnalysis()/runAnalysisSync() to resolve skills from DB
- Support skillId, skillSlug, or legacy mode enum (with fallback)
- Add structured data output via generateObject() + jsonSchema() for
  skills with output_type = structured_data
- Update /api/analyses POST to accept skillId/skillSlug alongside mode
- Migration 0005: creates skills table, seeds system skills, backfills

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-13 19:59:52 +00:00
CTO (LegalAI)
27132aa383 feat: add OpenRouter as an AI provider (AIIA-86)
All checks were successful
Deploy to VPS / deploy (push) Successful in 41s
Integrate OpenRouter via its OpenAI-compatible API so users can select
and use OpenRouter models alongside existing Anthropic/OpenAI/Ollama
providers. Adds provider to type system, DB enum, API validation,
buildModel switch, and settings UI.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-12 20:50:20 +00:00
CTO
af219c38d8 fix: register 0004_document_source_scope migration in drizzle journal
All checks were successful
Deploy to VPS / deploy (push) Successful in 31s
The migration file was added by feat/aiia-66-source-selection but was not
registered in _journal.json, so it never runs on deploy. This caused
'source_scope' column-missing errors on document insert.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-10 21:28:11 +00:00
CTO (LegalAI)
d7bdeb7da2 feat: implement AI source selection and toggle for document-based knowledge (AIIA-66)
Add source scope (case/global) to documents, enabling users to select
which uploaded documents the AI considers during analysis. Includes
schema migration, API support, reusable source selection UI component,
and integration into the analyse form.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-10 19:54:23 +00:00
CTO (LegalAI)
b22bdd8425 fix: API key save network error — add ENCRYPTION_KEY env and auto-migrate
The "Netzwerkfehler beim Speichern des Schlüssels" was caused by two issues:
1. ENCRYPTION_KEY env var was not passed to the Docker container, so
   AES-256-GCM encrypt() threw at runtime on every POST/PATCH.
2. The 0003_tenant_api_keys migration was not in the drizzle journal
   and no migration runner existed in the Docker image.

Changes:
- docker-compose.yml: pass ENCRYPTION_KEY to app container
- .env.example: document ENCRYPTION_KEY with generation command
- .gitignore: allow .env.example to be tracked
- Dockerfile: include drizzle/ migrations and entrypoint script
- entrypoint.sh: run migrations before starting the app
- migrate.mjs: runtime migration script using drizzle-orm migrator
- drizzle journal: register 0003_tenant_api_keys migration

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-09 14:28:19 +00:00
CTO (LegalAI)
362627981d feat: implement per-tenant API key management with AES-256-GCM encryption
Add encrypted API key storage for AI providers (Anthropic, OpenAI, Ollama)
with admin-only CRUD endpoints, tenant isolation, and audit logging.

- DB migration: tenant_api_keys table with RLS policy
- AES-256-GCM encryption utility (ENCRYPTION_KEY env var)
- CRUD API: GET/POST /api/settings/api-keys, PATCH/DELETE /api/settings/api-keys/[id]
- Provider integration: getModelForTenant() checks tenant keys before env fallback
- Frontend: API key management section in Einstellungen page
- Audit logging on all key CRUD operations (DSGVO)

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-09 12:08:40 +00:00
CTO (LegalAI)
7b1407268b feat: Generisches Dokument-Upload-System fuer Entscheidungen, Normen und Falldokumente
- Neues documents-Schema mit Mandantentrennung (tenantId), Kategorien (entscheidung/norm/falldokument/sonstiges) und optionaler Verknuepfung zu cases/decisions/normInstruments
- Upload-Library (src/lib/documents/) mit Datei-Upload, PDF/DOCX-Textextraktion und gefilterten Listen
- API-Route POST/GET /api/documents mit RBAC, Audit-Logging und asynchroner Textextraktion
- Wiederverwendbare DokumentUpload-Komponente mit Drag-and-Drop, Fortschrittsanzeige und Dateiliste
- Integration in Fall-Detailseite, Entscheidungs-Detailseite und Normen-Detailseite
- Drizzle-Migration fuer documents-Tabelle mit RLS-konformer Mandantentrennung
- DSGVO: 90-Tage Aufbewahrungsfrist fuer hochgeladene Dokumente

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-09 10:18:56 +00:00
CTO (LegalAI)
7dfbc42b8c feat: contract analysis API improvements and DSGVO compliance updates
Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-09 07:56:01 +00:00
CTO (LegalAI)
78ccf64948 feat: Phase 4 — WebApp-Frontend für Bühnenrecht (AIIA-27)
Complete frontend implementation with Next.js App Router:

- Dashboard with case/analysis/proceeding stats and quick actions
- Normen-Browser with Quellenrang hierarchy and instrument detail
- Entscheidungssuche with full-text search and detail view
- Analysemodus with streaming AI analysis (4 modes: Gutachten, Entscheidung, Vergleich, Risiko)
- Vertragsanalyse with file upload (PDF/DOCX)
- Verfahren overview (BSchGO/ArbGG)
- Auth pages (Login/Register)
- Mandantenfähigkeit: tenant switcher, RBAC-based settings
- Responsive sidebar navigation with Tailwind CSS
- Dashboard layout with session-based auth guard
- Installed missing runtime deps (pdf-parse, mammoth, devDependencies)

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-09 00:23:09 +00:00
CTO (LegalAI)
3c16fdc30f feat: add NV Bühne non-renewal & compensation module (Phase 3.2)
Implement § 61 NV Bühne non-renewal deadline calculation with tiered
protection (standard 31.10., extended 31.07. for 15+ years, special
protection for over-55), tariff-based compensation calculation with
Gagenklassen and Dienstalterszulage, and Spielzeit seasonal logic
(1.8.–31.7. with Probenzeit). Includes DB schema (contracts,
compensationRules, nonRenewalDeadlines), migration, and three API
endpoints under /api/nv-buehne/.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-08 23:25:54 +00:00
CTO (LegalAI)
a7245001ad feat: vollständiges Datenmodell für Normen und Entscheidungen (AIIA-15)
Replaces placeholder schema with full legal data model:
- Normen with temporal versioning (valid_from/valid_to), source rank hierarchy,
  immutable version chains, and norm-to-norm cross-references
- Entscheidungen with structured metadata (Aktenzeichen, Gremium, Leitsatz,
  Tenor, Tatbestand, Entscheidungsgründe), decision-norm links with Stichtag
- NV Bühne Fachgruppen and BSchGO Arbitration Tribunals
- Cases, Analyses, and DSGVO Audit Log
- Mandantentrennung via tenant_id + PostgreSQL Row-Level Security policies
- Initial Drizzle migration and RLS migration

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-08 21:16:40 +00:00