v0.11 U6: Bring your own key für die KI-Auswertung (Anthropic, OpenRouter)
Deploy FeWo mit PipelineManager / deploy (push) Successful in 5m11s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 5m11s
- Jeder Mandant verbindet unter „System › KI-Anbindung“ seinen eigenen Zugang: Anbieter (Anthropic oder OpenRouter), API-Schlüssel, Modell für die erste Auswertung und für die Prüfung – keine Modellkennung im Code, kein zentraler Betreiberschlüssel (FEWO_AI_API_KEY entfällt). - Gespeichert im bestehenden TenantService (ai_guest_mail): Schlüssel verschlüsselt, nie wieder angezeigt, nie in Meldungen; Anbieter/Modelle in settings, Prüfergebnis in check_status/check_message/checked_at. - Feste Endpunkte je Anbieter (AiProvider), nicht konfigurierbar. OpenRouter mit response_format json_schema (strict) und provider.require_parameters. - „Verbindung prüfen“ testet beide Modelle. Ein abgelehnter Zugang (401/402/403) schaltet die Auswertung für den Mandanten ab, meldet es im Postfach der Verwaltung; Nachrichten bleiben zur Prüfung im Posteingang. - Zweistufige Extraktion und ihre Sicherheitsregeln unverändert. - Zielarchitektur §3.8, Umsetzungsplan U6, Bericht, Drehbuch, Status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6f9aa46943
commit
6862dec201
20 files changed
+752
-95
No files matched your search
@@ -2,21 +2,24 @@
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Communication\Extraction\AccessRejected;
|
||||
use App\Communication\Extraction\AiAccess;
|
||||
use App\Communication\Extraction\ExtractionFailed;
|
||||
use App\Communication\Extraction\MessageExtractor;
|
||||
use App\Communication\Extraction\RiskAssessment;
|
||||
use App\Enums\BookingTaskKind;
|
||||
use App\Enums\BookingTaskStatus;
|
||||
use App\Enums\FactSource;
|
||||
use App\Enums\InboxMessageKind;
|
||||
use App\Enums\TenantServiceKey;
|
||||
use App\Filament\Pages\AiConnection;
|
||||
use App\Models\Booking;
|
||||
use App\Models\BookingTask;
|
||||
use App\Models\InboundMessage;
|
||||
use App\Models\ServiceUsage;
|
||||
use App\Models\TenantService;
|
||||
use App\Process\CaseLog;
|
||||
use App\Support\Inbox;
|
||||
use App\Support\Settings;
|
||||
use App\Tenancy\TenantFeatures;
|
||||
|
||||
/**
|
||||
* The risk-based two-stage extraction of v0.11 (CH-14, E-035): the small model extracts facts with evidence and
|
||||
@@ -40,8 +43,9 @@ public function handle(InboundMessage $message): string
|
||||
return (string) $message->extraction_status;
|
||||
}
|
||||
|
||||
$apiKey = $this->apiKey();
|
||||
if (! app(TenantFeatures::class)->enabled(TenantServiceKey::AiGuestMail) || $apiKey === null) {
|
||||
// Bring your own key: only the landlord's own, complete and not rejected access is used.
|
||||
$access = AiAccess::for(Settings::tenant());
|
||||
if ($access === null) {
|
||||
$message->update(['extraction_status' => 'disabled']);
|
||||
|
||||
return 'disabled';
|
||||
@@ -49,19 +53,26 @@ public function handle(InboundMessage $message): string
|
||||
|
||||
$record = ['prompt_version' => MessageExtractor::promptVersion()];
|
||||
try {
|
||||
$first = $this->extractor->extract($apiKey, $message, $booking);
|
||||
$first = $this->extractor->extract($access, $message, $booking);
|
||||
$this->meter();
|
||||
$record['first'] = $first;
|
||||
$data = $first['data'];
|
||||
$checked = $this->risk->facts($booking, (string) $message->body, $data);
|
||||
|
||||
if ($this->risk->needsReview($booking, $checked, $data)) {
|
||||
$review = $this->extractor->review($apiKey, $message, $booking, $data);
|
||||
$review = $this->extractor->review($access, $message, $booking, $data);
|
||||
$this->meter();
|
||||
$record['review'] = $review;
|
||||
$data = $review['data'];
|
||||
$checked = $this->markDisagreements($this->risk->facts($booking, (string) $message->body, $data), $first['data']);
|
||||
}
|
||||
} catch (AccessRejected $exception) {
|
||||
// The access is no longer valid: off for this landlord until he saves or checks it again (no retry loop).
|
||||
AiAccess::markInvalid(Settings::tenant(), $exception->getMessage());
|
||||
app(Inbox::class)->post(InboxMessageKind::AiAccessRejected, 'ai-access', 'KI-Anbindung abgelehnt', $exception->getMessage().' Die automatische Auswertung ist ausgeschaltet, bis Sie den Zugang unter System › KI-Anbindung prüfen. Nachrichten liegen im Posteingang.', actionUrl: AiConnection::getUrl());
|
||||
$message->update(['extraction_status' => 'failed', 'extraction' => [...$record, 'error' => $exception->getMessage()]]);
|
||||
|
||||
return 'failed';
|
||||
} catch (ExtractionFailed $exception) {
|
||||
$message->update(['extraction_status' => 'failed', 'extraction' => [...$record, 'error' => $exception->getMessage()]]);
|
||||
CaseLog::record($booking, 'mail_in', 'Automatische Auswertung nicht möglich – bitte die Nachricht selbst lesen', actor: CaseLog::SYSTEM);
|
||||
@@ -168,17 +179,6 @@ private function finish(InboundMessage $message, array $automatic, array $propos
|
||||
$task?->forceFill(['note' => '„'.mb_substr((string) $message->subject, 0, 120).'“ – '.(implode(', ', $parts) ?: 'keine Angaben erkannt').'. Im Posteingang ansehen.'])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* The landlord's own key of the service, otherwise the operator's key of the installation.
|
||||
*/
|
||||
private function apiKey(): ?string
|
||||
{
|
||||
$tenant = Settings::tenant();
|
||||
$own = $tenant === null ? null : TenantService::query()->where('tenant_id', $tenant->id)->where('service', TenantServiceKey::AiGuestMail->value)->first()?->api_key;
|
||||
|
||||
return filled($own) ? (string) $own : (filled(config('fewo.ai.api_key')) ? (string) config('fewo.ai.api_key') : null);
|
||||
}
|
||||
|
||||
private function meter(): void
|
||||
{
|
||||
if (($tenant = Settings::tenant()) !== null) {
|
||||
|
||||
Reference in new issue
Block a user