feat: add AI deadline extraction and case summary endpoints (Phase 2J)

Add two Claude API-powered endpoints:
- POST /api/ai/extract-deadlines: accepts PDF upload or JSON text, extracts
  legal deadlines using Claude tool_use for structured output
- POST /api/ai/summarize-case: generates AI summary from case events/deadlines,
  caches result in cases.ai_summary

New files:
- internal/services/ai_service.go: AIService with Anthropic SDK integration
- internal/handlers/ai.go: HTTP handlers for both endpoints
- internal/services/ai_service_test.go: tool schema and serialization tests

Uses anthropic-sdk-go v1.27.1 with Claude Sonnet 4.5. AI service is optional —
endpoints only registered when ANTHROPIC_API_KEY is set.
This commit is contained in:
m
2026-03-25 13:40:27 +01:00
parent 2c16f26448
commit 5758e2c37f
9 changed files with 547 additions and 13 deletions

View File

@@ -11,7 +11,7 @@ import (
"mgit.msbls.de/m/KanzlAI-mGMT/internal/services"
)
func New(db *sqlx.DB, authMW *auth.Middleware) http.Handler {
func New(db *sqlx.DB, authMW *auth.Middleware, anthropicAPIKey string) http.Handler {
mux := http.NewServeMux()
// Services
@@ -24,6 +24,13 @@ func New(db *sqlx.DB, authMW *auth.Middleware) http.Handler {
deadlineRuleSvc := services.NewDeadlineRuleService(db)
calculator := services.NewDeadlineCalculator(holidaySvc)
// AI service (optional — only if API key is configured)
var aiH *handlers.AIHandler
if anthropicAPIKey != "" {
aiSvc := services.NewAIService(anthropicAPIKey, db)
aiH = handlers.NewAIHandler(aiSvc, db)
}
// Middleware
tenantResolver := auth.NewTenantResolver(tenantSvc)
@@ -86,6 +93,12 @@ func New(db *sqlx.DB, authMW *auth.Middleware) http.Handler {
scoped.HandleFunc("PUT /api/appointments/{id}", apptH.Update)
scoped.HandleFunc("DELETE /api/appointments/{id}", apptH.Delete)
// AI endpoints
if aiH != nil {
scoped.HandleFunc("POST /api/ai/extract-deadlines", aiH.ExtractDeadlines)
scoped.HandleFunc("POST /api/ai/summarize-case", aiH.SummarizeCase)
}
// Placeholder routes for future phases
scoped.HandleFunc("GET /api/documents", placeholder("documents"))