v0.11 U6: risikobasierte KI-Extraktion von Gast- und Portalnachrichten
- Kleines Modell (claude-haiku-5-5) extrahiert Fakten mit Belegstelle und Konfidenz; programmatische Prüfung (Gültigkeit, Belegstelle im Original, Widerspruch zum gespeicherten Wert oder in der Nachricht, Plausibilität, Kritikalität nach Feld und Phase). Widerspruch oder fehlgeschlagene Prüfung → Prüfmodell (claude-opus-5-5, serverseitiger Fallback bei Ablehnung) unabhängig von der Konfidenz; solche Fakten nie automatisch. - Nur geprüfte, bisher fehlende Angaben gehen an den Fakteneingang (Quelle „llm“); Zeitraum/Personen nur als Änderungswunsch (M06); Rest als Vorschlag im Posteingang („Vorschläge übernehmen“). - Versionierte Prompts mit Platzhaltern, JSON-Schema mit eigener Validierung und einer Wiederholung; Ausfall/Ablehnung → sicherer Rückfall zur Vermieterin. HTTP-Client, kein SDK (laut Plan). - Dienst „KI: Gästekommunikation“ verdrahtet, standardmäßig aus; Schlüssel je Mandant oder FEWO_AI_API_KEY; Verbrauch in service_usages. - messages:extract alle fünf Minuten; ai:evaluate misst Fehlwerte und übersehene Angaben getrennt (M05). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dff9e2344e
commit
4170e3bd29
18 files changed
+1130
-7
No files matched your search
@@ -2,11 +2,13 @@
|
||||
|
||||
namespace App\Filament\Resources\InboundMessages;
|
||||
|
||||
use App\Actions\ContributeCaseFacts;
|
||||
use App\Actions\CreateReservation;
|
||||
use App\Actions\RequestCaseData;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\BookingTaskKind;
|
||||
use App\Enums\BookingTaskStatus;
|
||||
use App\Enums\FactSource;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Filament\Concerns\FollowsAdminMode;
|
||||
use App\Filament\Resources\Bookings\BookingResource;
|
||||
@@ -18,10 +20,12 @@
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\CaseLog;
|
||||
use App\Process\CaseRequirements;
|
||||
use BackedEnum;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
@@ -111,6 +115,14 @@ public static function table(Table $table): Table
|
||||
TextEntry::make('from')->label('Von')->state(fn (InboundMessage $record): string => trim(($record->from_name ? $record->from_name.' · ' : '').$record->from_address)),
|
||||
TextEntry::make('hints_text')->label('Hinweise')->state(fn (InboundMessage $record): string => collect((array) $record->hints)->map(fn (array $hint): string => $hint['reference'].': '.$hint['why'])->implode(' · ') ?: 'keine')
|
||||
->visible(fn (InboundMessage $record): bool => $record->status === InboundMessage::NEEDS_REVIEW),
|
||||
TextEntry::make('proposals_text')->label('Erkannte Angaben (KI-Vorschläge)')
|
||||
->state(fn (InboundMessage $record): HtmlString => new HtmlString(collect((array) ($record->extraction['proposed'] ?? []))
|
||||
->map(fn (array $fact): string => e(CaseRequirements::label($fact['field']).': „'.$fact['value'].'“').($fact['problems'] !== [] ? ' <em>('.e(implode(', ', $fact['problems'])).')</em>' : ' <em>(unsicher)</em>'))
|
||||
->implode('<br>') ?: '–'))
|
||||
->visible(fn (InboundMessage $record): bool => ($record->extraction['proposed'] ?? []) !== []),
|
||||
TextEntry::make('applied_text')->label('Automatisch übernommen')
|
||||
->state(fn (InboundMessage $record): string => collect((array) ($record->extraction['applied'] ?? []))->map(fn (array $fact): string => CaseRequirements::label($fact['field']).': „'.$fact['value'].'“')->implode(' · '))
|
||||
->visible(fn (InboundMessage $record): bool => ($record->extraction['applied'] ?? []) !== []),
|
||||
TextEntry::make('body_text')->label('Nachricht')->state(fn (InboundMessage $record): HtmlString => new HtmlString(nl2br(e((string) $record->body)))),
|
||||
]),
|
||||
Action::make('assign')->label('Vorgang zuordnen')->icon(Heroicon::OutlinedLink)
|
||||
@@ -158,6 +170,25 @@ public static function table(Table $table): Table
|
||||
$record->update(['status' => InboundMessage::PROCESSED, 'booking_id' => $booking->id, 'match_reason' => 'new_request', 'processed_at' => now()]);
|
||||
Notification::make()->title('Anfrage '.$booking->reference.' angelegt')->success()->send();
|
||||
}),
|
||||
Action::make('applyProposals')->label('Vorschläge übernehmen')->icon(Heroicon::OutlinedCheckBadge)
|
||||
->visible(fn (InboundMessage $record): bool => $record->booking_id !== null && ($record->extraction['proposed'] ?? []) !== [])
|
||||
->modalDescription('Nur übernehmen, was Sie in der Nachricht selbst geprüft haben. Zeitraum und Personenzahl ändern Sie über „Buchung ändern“ bzw. ein neues Angebot.')
|
||||
->schema([
|
||||
CheckboxList::make('fields')->label('Angaben')->required()
|
||||
->options(fn (InboundMessage $record): array => collect((array) ($record->extraction['proposed'] ?? []))
|
||||
->reject(fn (array $fact): bool => in_array($fact['field'], ContributeCaseFacts::STAY_FIELDS, true))
|
||||
->mapWithKeys(fn (array $fact): array => [$fact['field'] => CaseRequirements::label($fact['field']).': „'.$fact['value'].'“'])->all()),
|
||||
])
|
||||
->action(function (InboundMessage $record, array $data, ContributeCaseFacts $facts): void {
|
||||
$chosen = collect((array) ($record->extraction['proposed'] ?? []))->whereIn('field', $data['fields']);
|
||||
$result = $facts->handle($record->booking, $chosen->mapWithKeys(fn (array $fact): array => [$fact['field'] => $fact['value']])->all(), FactSource::Landlord, [
|
||||
'inbound_message_id' => $record->id,
|
||||
'reference' => 'message-landlord:'.$record->id,
|
||||
'evidence' => $chosen->mapWithKeys(fn (array $fact): array => [$fact['field'] => $fact['evidence']])->all(),
|
||||
]);
|
||||
$record->update(['extraction' => [...(array) $record->extraction, 'proposed' => collect((array) ($record->extraction['proposed'] ?? []))->whereNotIn('field', $data['fields'])->values()->all()]]);
|
||||
Notification::make()->title('Übernommen')->body($result->summary())->success()->send();
|
||||
}),
|
||||
ActionGroup::make([
|
||||
Action::make('done')->label('Als erledigt markieren')->icon(Heroicon::OutlinedCheck)
|
||||
->visible(fn (InboundMessage $record): bool => $record->status === InboundMessage::ASSIGNED)
|
||||
|
||||
Reference in new issue
Block a user