import { Action, ActionPanel, Clipboard, Form, Icon, showToast, Toast, useNavigation, } from "@raycast/api"; import { useEffect, useState } from "react"; import { type Creativity, CREATIVITY_OPTIONS, DEFAULT_MODEL, getLastUsedModel, MODEL_OPTIONS, setLastUsedModel, STRICT_PLACEHOLDER_RULE, } from "./ai"; import { PseudonymizationConfirm } from "./ai-views"; import { getSelectedTextSafely } from "./selection"; import { ContextPicker, type ContextFormValues } from "./context-picker"; import { pseudonymizeInContext } from "./text-context"; import { getActiveSessionId, listSessions, } from "./sessions"; import type { EntityType, VelumSession } from "./types"; import { getEntityTypes, } from "./velum"; function buildBriefingPrompt( pseudonymizedText: string, instructions: string, ): string { const extra = instructions.trim() ? `\n\nZusätzliche Anweisungen des Nutzers:\n${instructions.trim()}` : ""; return [ "Du erhältst pseudonymisierten Text (Stichpunkte, Notizen, Transkript, Whiteboard-Mitschrift).", "Personenbezogene Daten wurden durch Platzhalter wie , , ersetzt.", "", STRICT_PLACEHOLDER_RULE, "", "Aufgabe: Erstelle ein strukturiertes deutschsprachiges Briefing in Markdown mit folgenden Abschnitten:", "- **Kontext**: Worum geht es? Kurzer Absatz.", "- **Teilnehmer**: Beteiligte Platzhalter mit Rolle (falls aus dem Text ableitbar).", "- **Entscheidungen**: Welche Entscheidungen wurden getroffen? Stichpunktliste, jeweils 1 Zeile.", "- **Action Items**: Was ist zu tun? Stichpunktliste mit Verantwortlichem (Platzhalter) und Deadline (falls genannt).", "- **Offene Punkte**: Was bleibt zu klären? Stichpunktliste.", "", 'Wenn ein Abschnitt nicht im Text vorkommt, schreibe „—" als einzigen Inhalt darunter.', "Antworte ausschließlich in Markdown, ohne einleitende Floskeln und ohne Code-Fences (keine ``` Zeilen am Anfang oder Ende).", extra, "", "--- Notizen (pseudonymisiert) ---", pseudonymizedText, "--- Ende ---", ].join("\n"); } type FormValues = ContextFormValues & { text: string; entityTypes: string[]; model: string; creativity: Creativity; instructions: string; }; export default function Command() { const [text, setText] = useState(""); const [sessions, setSessions] = useState([]); const [activeSessionId, setActiveSessionId] = useState(); const [entityTypes, setEntityTypes] = useState([]); const [selectedEntityTypes, setSelectedEntityTypes] = useState([]); const [model, setModel] = useState(DEFAULT_MODEL); const [isLoading, setIsLoading] = useState(true); const { push } = useNavigation(); useEffect(() => { async function load() { const [loadedSessions, activeId, lastModel] = await Promise.all([ listSessions(), getActiveSessionId(), getLastUsedModel(), ]); setSessions(loadedSessions); setActiveSessionId(activeId); setModel(lastModel); const selection = await getSelectedTextSafely(); if (selection && selection.trim()) { setText(selection); } try { const loadedEntityTypes = await getEntityTypes(); setEntityTypes(loadedEntityTypes); setSelectedEntityTypes(loadedEntityTypes); } catch { setEntityTypes([]); } finally { setIsLoading(false); } } load(); }, []); async function loadSelectedText() { const selected = await getSelectedTextSafely(); if (!selected) { await showToast({ style: Toast.Style.Failure, title: "Kein markierter Text gefunden", }); return; } setText(selected); } async function loadClipboardText() { const clipboardText = await Clipboard.readText(); if (!clipboardText) { await showToast({ style: Toast.Style.Failure, title: "Zwischenablage enthält keinen Text", }); return; } setText(clipboardText); } async function handleSubmit(values: FormValues) { const input = values.text.trim(); if (!input) { await showToast({ style: Toast.Style.Failure, title: "Notizen eingeben", }); return; } void setLastUsedModel(values.model); const toast = await showToast({ style: Toast.Style.Animated, title: "Pseudonymisiere…", }); try { const { result: pseudoResult, session: updatedSession } = await pseudonymizeInContext(values, input, values.entityTypes, true); toast.style = Toast.Style.Success; toast.title = "Pseudonymisiert"; toast.message = `${pseudoResult.entity_count} Zuordnungen`; push( , ); } catch (error) { toast.style = Toast.Style.Failure; toast.title = "Pseudonymisierung fehlgeschlagen"; toast.message = error instanceof Error ? error.message : String(error); } } return (
} > {entityTypes.length > 0 ? ( {entityTypes.map((entityType) => ( ))} ) : null} {MODEL_OPTIONS.map((option) => ( ))} {CREATIVITY_OPTIONS.map((value) => ( ))} ); }