Files
velum-raycast/src/quick.ts
muena 1843479884 Initial commit: Velum Raycast extension
Pseudonymize-and-AI workflow for handling PII-sensitive text via the
Velum API and Raycast AI. Commands cover end-to-end email summary and
reply, briefing/action-items/structured-data extraction, manual
pseudonymize/depseudonymize on selection or clipboard, and session
management. Includes Raycast 2.0 Beta workarounds for selection capture
and rich-text clipboard.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 06:46:42 +02:00

122 lines
3.2 KiB
TypeScript

import { Clipboard, showHUD, showToast, Toast } from "@raycast/api";
import { getPreferences } from "./preferences";
import {
getActiveSession,
resolveDefaultSession,
updateSessionMapping,
} from "./sessions";
import type { VelumSession } from "./types";
import { localDepseudonymize, pseudonymize } from "./velum";
export async function pseudonymizeQuickText(
text: string,
source: string,
): Promise<void> {
const trimmed = text.trim();
if (!trimmed) {
await showToast({
style: Toast.Style.Failure,
title: `Kein Text in ${source} gefunden`,
});
return;
}
const toast = await showToast({
style: Toast.Style.Animated,
title: "Pseudonymisiere…",
});
try {
const session = await resolveDefaultSession();
const result = await pseudonymize(
trimmed,
session.mapping,
session.entityTypes,
);
const updatedSession = await updateSessionMapping(
session.id,
result.mapping,
result.selected_entity_types,
);
await writeQuickOutput(
result.pseudonymized_text,
updatedSession,
"Pseudonymisierten Text",
);
toast.style = Toast.Style.Success;
toast.title = "Pseudonymisiert";
toast.message = `${result.entity_count} Zuordnungen in ${updatedSession.name}`;
} catch (error) {
toast.style = Toast.Style.Failure;
toast.title = "Pseudonymisierung fehlgeschlagen";
toast.message = error instanceof Error ? error.message : String(error);
}
}
export async function depseudonymizeQuickText(
text: string,
source: string,
): Promise<void> {
const trimmed = text.trim();
if (!trimmed) {
await showToast({
style: Toast.Style.Failure,
title: `Kein Text in ${source} gefunden`,
});
return;
}
const toast = await showToast({
style: Toast.Style.Animated,
title: "Stelle wieder her…",
});
try {
const session = await getActiveSession();
if (Object.keys(session.mapping).length === 0) {
toast.style = Toast.Style.Failure;
toast.title = "Aktive Sitzung hat keine Zuordnungen";
toast.message = session.name;
return;
}
const result = localDepseudonymize(trimmed, session.mapping);
if (result.replacements_made === 0) {
toast.style = Toast.Style.Failure;
toast.title = "Keine Platzhalter ersetzt";
toast.message = `Sitzung: ${session.name}`;
return;
}
await writeQuickOutput(
result.original_text,
session,
"Wiederhergestellten Text",
);
toast.style = Toast.Style.Success;
toast.title = "Wiederhergestellt";
toast.message = `${result.replacements_made} Ersetzungen in ${session.name}`;
} catch (error) {
toast.style = Toast.Style.Failure;
toast.title = "Wiederherstellung fehlgeschlagen";
toast.message = error instanceof Error ? error.message : String(error);
}
}
async function writeQuickOutput(
text: string,
session: VelumSession,
textKind: string,
): Promise<void> {
if (getPreferences().quickOutput === "paste") {
await Clipboard.paste(text);
await showHUD(`${textKind} eingefügt (${session.name})`);
return;
}
await Clipboard.copy(text);
await showHUD(`${textKind} kopiert (${session.name})`);
}