feat: review text hits and release false-positive mappings
This commit is contained in:
@@ -21,7 +21,8 @@ import {
|
||||
import { PseudonymizationConfirm } from "./ai-views";
|
||||
import { getSelectedTextSafely } from "./selection";
|
||||
import { ContextPicker, type ContextFormValues } from "./context-picker";
|
||||
import { pseudonymizeInContext } from "./text-context";
|
||||
import { prepareTextInContext } from "./text-context";
|
||||
import { TextHitReview } from "./text-hit-review";
|
||||
import {
|
||||
getActiveSessionId,
|
||||
listSessions,
|
||||
@@ -151,30 +152,29 @@ export default function Command() {
|
||||
});
|
||||
|
||||
try {
|
||||
const { result: pseudoResult, session: updatedSession } =
|
||||
await pseudonymizeInContext(values, input, values.entityTypes, true);
|
||||
|
||||
const prepared = await prepareTextInContext(values, input, values.entityTypes);
|
||||
toast.style = Toast.Style.Success;
|
||||
toast.title = "Pseudonymisiert";
|
||||
toast.message = `${pseudoResult.entity_count} Zuordnungen`;
|
||||
|
||||
push(
|
||||
<PseudonymizationConfirm
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={values.model}
|
||||
creativity={values.creativity}
|
||||
instructions={values.instructions}
|
||||
buildPrompt={buildBriefingPrompt}
|
||||
labels={{
|
||||
pageHeading: "Briefing",
|
||||
runningLabel: "KI erstellt Briefing …",
|
||||
failureTitle: "Briefing fehlgeschlagen",
|
||||
copyTitle: "Briefing kopieren",
|
||||
pasteTitle: "Briefing einfügen",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
toast.title = "Treffer zur Prüfung bereit";
|
||||
toast.message = `${prepared.raw.spans.length} Treffer prüfen`;
|
||||
push(<TextHitReview prepared={prepared} forAi onConfirmed={async (pseudoResult, updatedSession) => {
|
||||
push(
|
||||
<PseudonymizationConfirm
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={values.model}
|
||||
creativity={values.creativity}
|
||||
instructions={values.instructions}
|
||||
buildPrompt={buildBriefingPrompt}
|
||||
labels={{
|
||||
pageHeading: "Briefing",
|
||||
runningLabel: "KI erstellt Briefing …",
|
||||
failureTitle: "Briefing fehlgeschlagen",
|
||||
copyTitle: "Briefing kopieren",
|
||||
pasteTitle: "Briefing einfügen",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
}} />);
|
||||
} catch (error) {
|
||||
toast.style = Toast.Style.Failure;
|
||||
toast.title = "Pseudonymisierung fehlgeschlagen";
|
||||
|
||||
@@ -21,7 +21,8 @@ import {
|
||||
import { PseudonymizationConfirm } from "./ai-views";
|
||||
import { getSelectedTextSafely } from "./selection";
|
||||
import { ContextPicker, type ContextFormValues } from "./context-picker";
|
||||
import { pseudonymizeInContext } from "./text-context";
|
||||
import { prepareTextInContext } from "./text-context";
|
||||
import { TextHitReview } from "./text-hit-review";
|
||||
import {
|
||||
getActiveSessionId,
|
||||
listSessions,
|
||||
@@ -156,30 +157,29 @@ export default function Command() {
|
||||
});
|
||||
|
||||
try {
|
||||
const { result: pseudoResult, session: updatedSession } =
|
||||
await pseudonymizeInContext(values, input, values.entityTypes, true);
|
||||
|
||||
const prepared = await prepareTextInContext(values, input, values.entityTypes);
|
||||
toast.style = Toast.Style.Success;
|
||||
toast.title = "Pseudonymisiert";
|
||||
toast.message = `${pseudoResult.entity_count} Zuordnungen`;
|
||||
|
||||
push(
|
||||
<PseudonymizationConfirm
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={values.model}
|
||||
creativity={values.creativity}
|
||||
instructions={values.instructions}
|
||||
buildPrompt={buildActionItemsPrompt}
|
||||
labels={{
|
||||
pageHeading: "Action Items",
|
||||
runningLabel: "KI extrahiert Action Items …",
|
||||
failureTitle: "Extraktion fehlgeschlagen",
|
||||
copyTitle: "Action Items kopieren",
|
||||
pasteTitle: "Action Items einfügen",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
toast.title = "Treffer zur Prüfung bereit";
|
||||
toast.message = `${prepared.raw.spans.length} Treffer prüfen`;
|
||||
push(<TextHitReview prepared={prepared} forAi onConfirmed={async (pseudoResult, updatedSession) => {
|
||||
push(
|
||||
<PseudonymizationConfirm
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={values.model}
|
||||
creativity={values.creativity}
|
||||
instructions={values.instructions}
|
||||
buildPrompt={buildActionItemsPrompt}
|
||||
labels={{
|
||||
pageHeading: "Action Items",
|
||||
runningLabel: "KI extrahiert Action Items …",
|
||||
failureTitle: "Extraktion fehlgeschlagen",
|
||||
copyTitle: "Action Items kopieren",
|
||||
pasteTitle: "Action Items einfügen",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
}} />);
|
||||
} catch (error) {
|
||||
toast.style = Toast.Style.Failure;
|
||||
toast.title = "Pseudonymisierung fehlgeschlagen";
|
||||
|
||||
@@ -21,7 +21,8 @@ import {
|
||||
import { PseudonymizationConfirm } from "./ai-views";
|
||||
import { getSelectedTextSafely } from "./selection";
|
||||
import { ContextPicker, type ContextFormValues } from "./context-picker";
|
||||
import { pseudonymizeInContext } from "./text-context";
|
||||
import { prepareTextInContext } from "./text-context";
|
||||
import { TextHitReview } from "./text-hit-review";
|
||||
import {
|
||||
getActiveSessionId,
|
||||
listSessions,
|
||||
@@ -184,46 +185,45 @@ export default function Command() {
|
||||
});
|
||||
|
||||
try {
|
||||
const { result: pseudoResult, session: updatedSession } =
|
||||
await pseudonymizeInContext(values, input, values.entityTypes, true);
|
||||
|
||||
const prepared = await prepareTextInContext(values, input, values.entityTypes);
|
||||
toast.style = Toast.Style.Success;
|
||||
toast.title = "Pseudonymisiert";
|
||||
toast.message = `${pseudoResult.entity_count} Zuordnungen`;
|
||||
toast.title = "Treffer zur Prüfung bereit";
|
||||
toast.message = `${prepared.raw.spans.length} Treffer prüfen`;
|
||||
push(<TextHitReview prepared={prepared} forAi onConfirmed={async (pseudoResult, updatedSession) => {
|
||||
const schema = values.schema;
|
||||
const format = values.format;
|
||||
const buildPrompt = (pseudonymizedText: string, instructions: string) =>
|
||||
buildStructuredDataPrompt({
|
||||
pseudonymizedText,
|
||||
instructions,
|
||||
schema,
|
||||
format,
|
||||
});
|
||||
|
||||
const schema = values.schema;
|
||||
const format = values.format;
|
||||
const buildPrompt = (pseudonymizedText: string, instructions: string) =>
|
||||
buildStructuredDataPrompt({
|
||||
pseudonymizedText,
|
||||
instructions,
|
||||
schema,
|
||||
format,
|
||||
});
|
||||
|
||||
push(
|
||||
<PseudonymizationConfirm
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={values.model}
|
||||
creativity={values.creativity}
|
||||
instructions={values.instructions}
|
||||
buildPrompt={buildPrompt}
|
||||
labels={{
|
||||
pageHeading:
|
||||
format === "json" ? "Strukturierte Daten (JSON)" : "Tabelle",
|
||||
runningLabel:
|
||||
format === "json"
|
||||
? "KI extrahiert Daten (JSON) …"
|
||||
: "KI extrahiert Tabelle …",
|
||||
failureTitle: "Extraktion fehlgeschlagen",
|
||||
copyTitle:
|
||||
format === "json" ? "JSON kopieren" : "Markdown-Tabelle kopieren",
|
||||
pasteTitle:
|
||||
format === "json" ? "JSON einfügen" : "Tabelle einfügen",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
push(
|
||||
<PseudonymizationConfirm
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={values.model}
|
||||
creativity={values.creativity}
|
||||
instructions={values.instructions}
|
||||
buildPrompt={buildPrompt}
|
||||
labels={{
|
||||
pageHeading:
|
||||
format === "json" ? "Strukturierte Daten (JSON)" : "Tabelle",
|
||||
runningLabel:
|
||||
format === "json"
|
||||
? "KI extrahiert Daten (JSON) …"
|
||||
: "KI extrahiert Tabelle …",
|
||||
failureTitle: "Extraktion fehlgeschlagen",
|
||||
copyTitle:
|
||||
format === "json" ? "JSON kopieren" : "Markdown-Tabelle kopieren",
|
||||
pasteTitle:
|
||||
format === "json" ? "JSON einfügen" : "Tabelle einfügen",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
}} />);
|
||||
} catch (error) {
|
||||
toast.style = Toast.Style.Failure;
|
||||
toast.title = "Pseudonymisierung fehlgeschlagen";
|
||||
|
||||
@@ -2,6 +2,7 @@ import { promises as fs } from "node:fs";
|
||||
import { basename, dirname, join } from "node:path";
|
||||
import type { PlaceholderMapping } from "../types";
|
||||
import { canonicalPerson } from "./project-review";
|
||||
import { mappingForRestoration, mappingRoot } from "./mapping-groups";
|
||||
import {
|
||||
createRun, digest, isMarkdownFile, isRestorableDocument, listRuns, loadProjectWhitelist, publishProjectCopies,
|
||||
replaceProjectFilesInPlace, resolveWithin, restorePath, restoreText,
|
||||
@@ -18,17 +19,7 @@ export type RevisionPlan = {
|
||||
};
|
||||
|
||||
function existingRoot(key: string, mapping: PlaceholderMapping): string {
|
||||
const seen = new Set<string>();
|
||||
let current = key;
|
||||
while (mapping[current]?.merged_into) {
|
||||
if (seen.has(current)) throw new Error("Zyklische Personen-Zuordnung.");
|
||||
seen.add(current);
|
||||
current = mapping[current].merged_into!;
|
||||
if (!mapping[current] || mapping[current].type !== "PERSON") {
|
||||
throw new Error("Personen-Zuordnung verweist auf ein ungültiges Ziel.");
|
||||
}
|
||||
}
|
||||
return current;
|
||||
return mappingRoot(key, mapping);
|
||||
}
|
||||
|
||||
/** Build a single direct substitution for each changed placeholder; no replacement chains. */
|
||||
@@ -61,16 +52,17 @@ export function planProjectRevision(
|
||||
}
|
||||
const mapping: PlaceholderMapping = {};
|
||||
const replacements: PlaceholderMapping = {};
|
||||
const restoration = mappingForRestoration(previous);
|
||||
const merged: string[] = [];
|
||||
for (const [key, entry] of Object.entries(previous)) {
|
||||
const oldRoot = entry.type === "PERSON" ? existingRoot(key, previous) : key;
|
||||
const oldRoot = existingRoot(key, previous);
|
||||
if (releaseSet.has(key)) {
|
||||
// A canonical placeholder can stand for several spelling variants. Its
|
||||
// visible text restores to the canonical original; every variant is excluded.
|
||||
replacements[key] = { original: entry.original, type: entry.type };
|
||||
replacements[key] = { original: restoration[key].original, type: entry.type };
|
||||
continue;
|
||||
}
|
||||
const finalRoot = entry.type === "PERSON" ? canonicalPerson(oldRoot, merges) : key;
|
||||
const finalRoot = entry.type === "PERSON" ? canonicalPerson(oldRoot, merges) : oldRoot;
|
||||
mapping[key] = { ...entry };
|
||||
if (entry.type === "PERSON") {
|
||||
if (finalRoot === key) delete mapping[key].merged_into;
|
||||
@@ -173,8 +165,10 @@ export async function reviseProjectRun(args: {
|
||||
replacementAttempted = true;
|
||||
await replaceProjectFilesInPlace(previous.projectPath, directory, run.files);
|
||||
} else {
|
||||
publishedCopyPath = await publishProjectCopies(run, directory);
|
||||
run.copyPath = publishedCopyPath;
|
||||
if (run.files.length) {
|
||||
publishedCopyPath = await publishProjectCopies(run, directory);
|
||||
run.copyPath = publishedCopyPath;
|
||||
}
|
||||
await saveRun(directory, run);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
deleteSession,
|
||||
getActiveSessionId,
|
||||
listSessions,
|
||||
releaseSessionMappingGroup,
|
||||
renameSession,
|
||||
setActiveSession,
|
||||
} from "./sessions";
|
||||
@@ -149,7 +150,13 @@ export default function Command() {
|
||||
<Action.Push
|
||||
title="Übersetzungstabelle anzeigen"
|
||||
icon={Icon.List}
|
||||
target={<TranslationTable title={session.name} mapping={session.mapping} />}
|
||||
target={<TranslationTable title={session.name} mapping={session.mapping}
|
||||
removeDescription="Die gesamte Gruppe wird aus der Sitzung entfernt und künftig dort nicht mehr vorgeschlagen. Bereits kopierte oder eingefügte Texte werden nicht rückwirkend geändert."
|
||||
onRemove={async (root) => {
|
||||
const updated = await releaseSessionMappingGroup(session.id, root);
|
||||
await reload();
|
||||
return updated.mapping;
|
||||
}} />}
|
||||
/>
|
||||
<Action
|
||||
title="Als Aktive Sitzung Setzen"
|
||||
|
||||
11
src/project-mapping-actions.ts
Normal file
11
src/project-mapping-actions.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { listRuns } from "./lib/velum-project";
|
||||
import { reviseProjectRun } from "./lib/project-revision";
|
||||
import { depseudonymizeDocument } from "./velum";
|
||||
|
||||
/** Release the whole alias group and update the latest saved project files. */
|
||||
export async function releaseProjectMapping(projectPath: string, placeholder: string) {
|
||||
const latest = (await listRuns(projectPath))[0];
|
||||
if (!latest) throw new Error("Projektstand nicht gefunden.");
|
||||
return reviseProjectRun({ previous: latest.run, previousDirectory: latest.directory,
|
||||
release: new Set([placeholder]), merges: {}, rewriteDocument: depseudonymizeDocument });
|
||||
}
|
||||
@@ -22,7 +22,8 @@ import { PseudonymizationConfirm } from "./ai-views";
|
||||
import { getPreferences } from "./preferences";
|
||||
import { getSelectedTextSafely } from "./selection";
|
||||
import { ContextPicker, type ContextFormValues } from "./context-picker";
|
||||
import { pseudonymizeInContext } from "./text-context";
|
||||
import { prepareTextInContext } from "./text-context";
|
||||
import { TextHitReview } from "./text-hit-review";
|
||||
import {
|
||||
getActiveSessionId,
|
||||
listSessions,
|
||||
@@ -216,30 +217,29 @@ export default function Command() {
|
||||
});
|
||||
|
||||
try {
|
||||
const { result: pseudoResult, session: updatedSession } =
|
||||
await pseudonymizeInContext(values, input, values.entityTypes, true);
|
||||
|
||||
const prepared = await prepareTextInContext(values, input, values.entityTypes);
|
||||
toast.style = Toast.Style.Success;
|
||||
toast.title = "Pseudonymisiert";
|
||||
toast.message = `${pseudoResult.entity_count} Zuordnungen`;
|
||||
|
||||
push(
|
||||
<PseudonymizationConfirm
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={values.model}
|
||||
creativity={values.creativity}
|
||||
instructions={values.instructions}
|
||||
buildPrompt={buildPrompt}
|
||||
labels={{
|
||||
pageHeading: "Steering-Update",
|
||||
runningLabel: "KI erstellt Steering-Update …",
|
||||
failureTitle: "Steering-Update fehlgeschlagen",
|
||||
copyTitle: "Steering-Update kopieren",
|
||||
pasteTitle: "Steering-Update einfügen",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
toast.title = "Treffer zur Prüfung bereit";
|
||||
toast.message = `${prepared.raw.spans.length} Treffer prüfen`;
|
||||
push(<TextHitReview prepared={prepared} forAi onConfirmed={async (pseudoResult, updatedSession) => {
|
||||
push(
|
||||
<PseudonymizationConfirm
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={values.model}
|
||||
creativity={values.creativity}
|
||||
instructions={values.instructions}
|
||||
buildPrompt={buildPrompt}
|
||||
labels={{
|
||||
pageHeading: "Steering-Update",
|
||||
runningLabel: "KI erstellt Steering-Update …",
|
||||
failureTitle: "Steering-Update fehlgeschlagen",
|
||||
copyTitle: "Steering-Update kopieren",
|
||||
pasteTitle: "Steering-Update einfügen",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
}} />);
|
||||
} catch (error) {
|
||||
toast.style = Toast.Style.Failure;
|
||||
toast.title = "Pseudonymisierung fehlgeschlagen";
|
||||
|
||||
@@ -289,10 +289,13 @@ function HitReview(props: { root: string; rules: ProjectRule[]; whitelist: Proje
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (inPlace && !(await confirmAlert({
|
||||
title: "Originaldateien ersetzen?",
|
||||
message: "Die gewählten Dateien und gegebenenfalls ihre Namen werden im Projektordner ersetzt. Die Originale werden vorher außerhalb des Projekts gesichert. PDF-Dateien werden als DOCX ausgegeben.",
|
||||
primaryAction: { title: "Originaldateien ersetzen", style: Alert.ActionStyle.Destructive },
|
||||
if (!(await confirmAlert({
|
||||
title: inPlace ? "Geprüfte Auswahl anwenden und Originaldateien ersetzen?" : "Geprüfte Auswahl als Kopien erstellen?",
|
||||
message: `${selectedGroups.size} von ${groups.length} Begriffen in ${props.preview.drafts.length} neuen oder geänderten Dateien werden maskiert. ${groups.length - selectedGroups.size} abgewählte Begriffe werden als Projektausnahmen gespeichert. ${inPlace
|
||||
? "Die Originale und gegebenenfalls ihre Namen werden im Projektordner ersetzt und vorher außerhalb gesichert. PDF-Dateien werden als DOCX ausgegeben."
|
||||
: "Die pseudonymisierten Kopien werden neben dem Projektordner gespeichert."}`,
|
||||
primaryAction: { title: inPlace ? "Originaldateien ersetzen" : "Kopien erstellen",
|
||||
style: inPlace ? Alert.ActionStyle.Destructive : Alert.ActionStyle.Default },
|
||||
}))) return;
|
||||
setBusy(true);
|
||||
const toast = await showToast({ style: Toast.Style.Animated,
|
||||
|
||||
@@ -21,7 +21,8 @@ import {
|
||||
} from "./ui";
|
||||
import { getEntityTypes } from "./velum";
|
||||
import { ContextPicker, type ContextFormValues } from "./context-picker";
|
||||
import { pseudonymizeInContext } from "./text-context";
|
||||
import { prepareTextInContext } from "./text-context";
|
||||
import { TextHitReview } from "./text-hit-review";
|
||||
import { getPreferences } from "./preferences";
|
||||
|
||||
type FormValues = ContextFormValues & {
|
||||
@@ -109,21 +110,23 @@ export default function Command(props: { initialSource?: "selection" | "clipboar
|
||||
});
|
||||
|
||||
try {
|
||||
const { result, session } = await pseudonymizeInContext(values, input, values.entityTypes);
|
||||
|
||||
const prepared = await prepareTextInContext(values, input, values.entityTypes);
|
||||
toast.style = Toast.Style.Success;
|
||||
toast.title = "Pseudonymisiert";
|
||||
toast.message = `${result.entity_count} Zuordnungen in ${session.name}`;
|
||||
|
||||
if (props.autoOutput) {
|
||||
if (getPreferences().quickOutput === "paste") {
|
||||
await Clipboard.paste(result.pseudonymized_text);
|
||||
await showHUD(`Pseudonymisierten Text eingefügt (${session.name})`);
|
||||
toast.title = "Treffer zur Prüfung bereit";
|
||||
toast.message = `${prepared.raw.spans.length} Treffer prüfen`;
|
||||
push(<TextHitReview prepared={prepared} onConfirmed={async (result, session) => {
|
||||
if (props.autoOutput) {
|
||||
if (getPreferences().quickOutput === "paste") {
|
||||
await Clipboard.paste(result.pseudonymized_text);
|
||||
await showHUD(`Pseudonymisierten Text eingefügt (${session.name})`);
|
||||
} else {
|
||||
await Clipboard.copy(result.pseudonymized_text);
|
||||
await showHUD(`Pseudonymisierten Text kopiert (${session.name})`);
|
||||
}
|
||||
} else {
|
||||
await Clipboard.copy(result.pseudonymized_text);
|
||||
await showHUD(`Pseudonymisierten Text kopiert (${session.name})`);
|
||||
push(<PseudonymizeResult result={result} session={session} />);
|
||||
}
|
||||
} else push(<PseudonymizeResult result={result} session={session} />);
|
||||
}} />);
|
||||
} catch (error) {
|
||||
toast.style = Toast.Style.Failure;
|
||||
toast.title = "Pseudonymisierung fehlgeschlagen";
|
||||
|
||||
@@ -12,7 +12,8 @@ import {
|
||||
} from "@raycast/api";
|
||||
import { getSelectedTextSafely } from "./selection";
|
||||
import { ContextPicker, type ContextFormValues } from "./context-picker";
|
||||
import { pseudonymizeInContext } from "./text-context";
|
||||
import { prepareTextInContext } from "./text-context";
|
||||
import { TextHitReview } from "./text-hit-review";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
CREATIVITY_OPTIONS,
|
||||
@@ -183,26 +184,25 @@ export default function Command() {
|
||||
});
|
||||
|
||||
try {
|
||||
const { result: pseudoResult, session: updatedSession } =
|
||||
await pseudonymizeInContext(values, input, values.entityTypes, true);
|
||||
|
||||
const prepared = await prepareTextInContext(values, input, values.entityTypes);
|
||||
toast.style = Toast.Style.Success;
|
||||
toast.title = "Pseudonymisiert";
|
||||
toast.message = `${pseudoResult.entity_count} Zuordnungen`;
|
||||
|
||||
push(
|
||||
<ConfirmReply
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={model}
|
||||
creativity={creativity}
|
||||
greeting={greeting}
|
||||
signOff={signOff}
|
||||
userFullName={userFullName}
|
||||
instructions={values.instructions}
|
||||
disclosure={disclosure}
|
||||
/>,
|
||||
);
|
||||
toast.title = "Treffer zur Prüfung bereit";
|
||||
toast.message = `${prepared.raw.spans.length} Treffer prüfen`;
|
||||
push(<TextHitReview prepared={prepared} forAi onConfirmed={async (pseudoResult, updatedSession) => {
|
||||
push(
|
||||
<ConfirmReply
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={model}
|
||||
creativity={creativity}
|
||||
greeting={greeting}
|
||||
signOff={signOff}
|
||||
userFullName={userFullName}
|
||||
instructions={values.instructions}
|
||||
disclosure={disclosure}
|
||||
/>,
|
||||
);
|
||||
}} />);
|
||||
} catch (error) {
|
||||
toast.style = Toast.Style.Failure;
|
||||
toast.title = "Pseudonymisierung fehlgeschlagen";
|
||||
|
||||
@@ -11,6 +11,7 @@ import { canonicalPerson, mergePeople } from "./lib/project-review";
|
||||
import { planProjectRevision, reviseProjectRun } from "./lib/project-revision";
|
||||
import { TranslationTable } from "./show-translation-tables";
|
||||
import { detachMappingGroup, mappingForRestoration, mergeMappingGroups } from "./lib/mapping-groups";
|
||||
import { releaseProjectMapping } from "./project-mapping-actions";
|
||||
|
||||
type SavedRun = { run: ProjectRun; directory: string };
|
||||
type RestoreDecision = MappingEntry | null;
|
||||
@@ -454,6 +455,12 @@ export default function Command() {
|
||||
(current) => detachMappingGroup(current, key));
|
||||
await refresh();
|
||||
return updated.mapping;
|
||||
}}
|
||||
removeDescription="Die gesamte Gruppe wird als Projektausnahme gespeichert. Der aktuelle Projektstand und seine Dateien werden korrigiert; bei Überschreiben wird zuvor eine Sicherung erstellt."
|
||||
onRemove={async (root) => {
|
||||
const revised = await releaseProjectMapping(run.projectPath, root);
|
||||
await refresh();
|
||||
return revised.run.mapping;
|
||||
}} />} />
|
||||
<Action title="Pseudonymisierte Kopien im Finder anzeigen" icon={Icon.Folder}
|
||||
onAction={() => showInFinder(runCopiesPath(run, directory))} />
|
||||
|
||||
@@ -2,6 +2,8 @@ import { LocalStorage } from "@raycast/api";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { getPreferences } from "./preferences";
|
||||
import type { PlaceholderMapping, VelumSession } from "./types";
|
||||
import { mappingRoot } from "./lib/mapping-groups";
|
||||
import { whitelistKey } from "./lib/project-whitelist";
|
||||
|
||||
const SESSIONS_STORAGE_KEY = "velum.sessions.v1";
|
||||
const ACTIVE_SESSION_STORAGE_KEY = "velum.sessions.active.v1";
|
||||
@@ -85,6 +87,7 @@ export async function updateSessionMapping(
|
||||
id: string,
|
||||
mapping: PlaceholderMapping,
|
||||
entityTypes?: string[],
|
||||
excludedTerms?: VelumSession["excludedTerms"],
|
||||
): Promise<VelumSession> {
|
||||
const sessions = await listSessions();
|
||||
const timestamp = nowIso();
|
||||
@@ -98,6 +101,7 @@ export async function updateSessionMapping(
|
||||
updatedAt: timestamp,
|
||||
mapping,
|
||||
entityTypes,
|
||||
excludedTerms,
|
||||
};
|
||||
await saveSessions([created, ...sessions]);
|
||||
return created;
|
||||
@@ -107,6 +111,7 @@ export async function updateSessionMapping(
|
||||
...sessions[index],
|
||||
mapping,
|
||||
entityTypes,
|
||||
excludedTerms: excludedTerms ?? sessions[index].excludedTerms,
|
||||
updatedAt: timestamp,
|
||||
};
|
||||
const next = [...sessions];
|
||||
@@ -115,6 +120,18 @@ export async function updateSessionMapping(
|
||||
return updated;
|
||||
}
|
||||
|
||||
export async function releaseSessionMappingGroup(id: string, root: string): Promise<VelumSession> {
|
||||
const session = await getSession(id);
|
||||
if (!session) throw new Error("Sitzung nicht gefunden.");
|
||||
if (!session.mapping[root]) throw new Error("Zuordnung nicht gefunden. Bitte die Ansicht aktualisieren.");
|
||||
const removed = Object.keys(session.mapping).filter((key) => mappingRoot(key, session.mapping) === root);
|
||||
const mapping = Object.fromEntries(Object.entries(session.mapping).filter(([key]) => !removed.includes(key)));
|
||||
const excludedTerms = [...new Map([...(session.excludedTerms ?? []),
|
||||
...removed.map((key) => ({ type: session.mapping[key].type, original: session.mapping[key].original }))]
|
||||
.map((entry) => [whitelistKey(entry), entry])).values()];
|
||||
return updateSessionMapping(id, mapping, session.entityTypes, excludedTerms);
|
||||
}
|
||||
|
||||
export async function renameSession(id: string, name: string): Promise<void> {
|
||||
const sessions = await listSessions();
|
||||
await saveSessions(
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import {
|
||||
Action,
|
||||
ActionPanel,
|
||||
Alert,
|
||||
confirmAlert,
|
||||
Form,
|
||||
Icon,
|
||||
List,
|
||||
@@ -11,8 +13,9 @@ import {
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { addProjectMappingEntry, canonicalProjectPath, listAllRuns, prepareManualMappingEntry, updateProjectMapping } from "./lib/velum-project";
|
||||
import { detachMappingGroup, mappingRoot, mergeMappingGroups } from "./lib/mapping-groups";
|
||||
import { getSession, listSessions, updateSessionMapping } from "./sessions";
|
||||
import { getSession, listSessions, releaseSessionMappingGroup, updateSessionMapping } from "./sessions";
|
||||
import type { PlaceholderMapping } from "./types";
|
||||
import { releaseProjectMapping } from "./project-mapping-actions";
|
||||
|
||||
type TableSource = {
|
||||
id: string;
|
||||
@@ -55,12 +58,16 @@ export function TranslationTable({
|
||||
onAdd,
|
||||
onMerge,
|
||||
onDetach,
|
||||
onRemove,
|
||||
removeDescription,
|
||||
}: {
|
||||
title: string;
|
||||
mapping: PlaceholderMapping;
|
||||
onAdd?: (input: ManualEntry) => Promise<PlaceholderMapping>;
|
||||
onMerge?: (source: string, target: string) => Promise<PlaceholderMapping>;
|
||||
onDetach?: (key: string) => Promise<PlaceholderMapping>;
|
||||
onRemove?: (root: string) => Promise<PlaceholderMapping>;
|
||||
removeDescription?: string;
|
||||
}) {
|
||||
const { push, pop } = useNavigation();
|
||||
const [visibleMapping, setVisibleMapping] = useState(mapping);
|
||||
@@ -88,6 +95,14 @@ export function TranslationTable({
|
||||
return false;
|
||||
} finally { setBusy(false); }
|
||||
}
|
||||
async function remove(root: string, members: string[]) {
|
||||
if (!onRemove || !(await confirmAlert({
|
||||
title: `${members.length} Zuordnung${members.length === 1 ? "" : "en"} als False Positive freigeben?`,
|
||||
message: removeDescription ?? "Diese Zuordnungen werden entfernt und als Ausnahmen gespeichert.",
|
||||
primaryAction: { title: "Freigeben", style: Alert.ActionStyle.Destructive },
|
||||
}))) return;
|
||||
await change(() => onRemove(root), "False Positive freigegeben");
|
||||
}
|
||||
|
||||
return (
|
||||
<List
|
||||
@@ -141,6 +156,8 @@ export function TranslationTable({
|
||||
<Action key={target} title={`${visibleMapping[target].original} · ${target}`}
|
||||
onAction={() => change(() => onMerge(placeholder, target), "Zuordnungen zusammengefasst")} />)}
|
||||
</ActionPanel.Submenu>}
|
||||
{onRemove && <Action title="False Positive freigeben" icon={Icon.XMarkCircle}
|
||||
onAction={() => remove(placeholder, members)} />}
|
||||
<Action.CopyToClipboard
|
||||
title="Platzhalter kopieren"
|
||||
content={placeholder}
|
||||
@@ -243,6 +260,12 @@ export default function Command() {
|
||||
await refresh();
|
||||
return run.mapping;
|
||||
}}
|
||||
removeDescription="Die gesamte Gruppe wird als Projektausnahme gespeichert. Der aktuelle Projektstand und seine Dateien werden korrigiert; bei Überschreiben wird zuvor eine Sicherung erstellt."
|
||||
onRemove={async (root) => {
|
||||
const revised = await releaseProjectMapping(source.id, root);
|
||||
await refresh();
|
||||
return revised.run.mapping;
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
@@ -296,6 +319,12 @@ export default function Command() {
|
||||
await refresh();
|
||||
return updated.mapping;
|
||||
}}
|
||||
removeDescription="Die gesamte Gruppe wird aus der Sitzung entfernt und künftig dort nicht mehr vorgeschlagen. Bereits kopierte oder eingefügte Texte werden nicht rückwirkend geändert."
|
||||
onRemove={async (root) => {
|
||||
const updated = await releaseSessionMappingGroup(source.id, root);
|
||||
await refresh();
|
||||
return updated.mapping;
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -15,7 +15,8 @@ import { markdownToHtml, maybeCloseRaycast } from "./ai-views";
|
||||
import { copyRichText } from "./rich-clipboard";
|
||||
import { getSelectedTextSafely } from "./selection";
|
||||
import { ContextPicker, type ContextFormValues } from "./context-picker";
|
||||
import { pseudonymizeInContext } from "./text-context";
|
||||
import { prepareTextInContext } from "./text-context";
|
||||
import { TextHitReview } from "./text-hit-review";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
getActiveSessionId,
|
||||
@@ -129,22 +130,21 @@ export default function Command() {
|
||||
});
|
||||
|
||||
try {
|
||||
const { result: pseudoResult, session: updatedSession } =
|
||||
await pseudonymizeInContext(values, input, values.entityTypes, true);
|
||||
|
||||
const prepared = await prepareTextInContext(values, input, values.entityTypes);
|
||||
toast.style = Toast.Style.Success;
|
||||
toast.title = "Pseudonymisiert";
|
||||
toast.message = `${pseudoResult.entity_count} Zuordnungen`;
|
||||
|
||||
push(
|
||||
<ConfirmPseudonymized
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={values.model}
|
||||
creativity={values.creativity}
|
||||
instructions={values.instructions}
|
||||
/>,
|
||||
);
|
||||
toast.title = "Treffer zur Prüfung bereit";
|
||||
toast.message = `${prepared.raw.spans.length} Treffer prüfen`;
|
||||
push(<TextHitReview prepared={prepared} forAi onConfirmed={async (pseudoResult, updatedSession) => {
|
||||
push(
|
||||
<ConfirmPseudonymized
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={values.model}
|
||||
creativity={values.creativity}
|
||||
instructions={values.instructions}
|
||||
/>,
|
||||
);
|
||||
}} />);
|
||||
} catch (error) {
|
||||
toast.style = Toast.Style.Failure;
|
||||
toast.title = "Pseudonymisierung fehlgeschlagen";
|
||||
|
||||
@@ -21,7 +21,8 @@ import {
|
||||
import { PseudonymizationConfirm } from "./ai-views";
|
||||
import { getSelectedTextSafely } from "./selection";
|
||||
import { ContextPicker, type ContextFormValues } from "./context-picker";
|
||||
import { pseudonymizeInContext } from "./text-context";
|
||||
import { prepareTextInContext } from "./text-context";
|
||||
import { TextHitReview } from "./text-hit-review";
|
||||
import {
|
||||
getActiveSessionId,
|
||||
listSessions,
|
||||
@@ -182,30 +183,29 @@ export default function Command() {
|
||||
});
|
||||
|
||||
try {
|
||||
const { result: pseudoResult, session: updatedSession } =
|
||||
await pseudonymizeInContext(values, input, values.entityTypes, true);
|
||||
|
||||
const prepared = await prepareTextInContext(values, input, values.entityTypes);
|
||||
toast.style = Toast.Style.Success;
|
||||
toast.title = "Pseudonymisiert";
|
||||
toast.message = `${pseudoResult.entity_count} Zuordnungen`;
|
||||
|
||||
push(
|
||||
<PseudonymizationConfirm
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={values.model}
|
||||
creativity={values.creativity}
|
||||
instructions={values.instructions}
|
||||
buildPrompt={buildMeetingNotesPrompt}
|
||||
labels={{
|
||||
pageHeading: "Meeting-Zusammenfassung",
|
||||
runningLabel: "KI strukturiert Meeting-Notizen …",
|
||||
failureTitle: "Zusammenfassung fehlgeschlagen",
|
||||
copyTitle: "Zusammenfassung kopieren",
|
||||
pasteTitle: "Zusammenfassung einfügen",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
toast.title = "Treffer zur Prüfung bereit";
|
||||
toast.message = `${prepared.raw.spans.length} Treffer prüfen`;
|
||||
push(<TextHitReview prepared={prepared} forAi onConfirmed={async (pseudoResult, updatedSession) => {
|
||||
push(
|
||||
<PseudonymizationConfirm
|
||||
session={updatedSession}
|
||||
pseudonymizedText={pseudoResult.pseudonymized_text}
|
||||
model={values.model}
|
||||
creativity={values.creativity}
|
||||
instructions={values.instructions}
|
||||
buildPrompt={buildMeetingNotesPrompt}
|
||||
labels={{
|
||||
pageHeading: "Meeting-Zusammenfassung",
|
||||
runningLabel: "KI strukturiert Meeting-Notizen …",
|
||||
failureTitle: "Zusammenfassung fehlgeschlagen",
|
||||
copyTitle: "Zusammenfassung kopieren",
|
||||
pasteTitle: "Zusammenfassung einfügen",
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
}} />);
|
||||
} catch (error) {
|
||||
toast.style = Toast.Style.Failure;
|
||||
toast.title = "Pseudonymisierung fehlgeschlagen";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { promises as fs } from "node:fs";
|
||||
import { canonicalProjectPath, createRun, forceMasks, listRuns, loadProjectRules,
|
||||
loadProjectWhitelist, replaceSpans, saveRun, toUtf16Offsets, updateProjectMapping, whitelistKey } from "./lib/velum-project";
|
||||
loadProjectWhitelist, replaceSpans, saveProjectWhitelist, saveRun, toUtf16Offsets, updateProjectMapping, whitelistKey } from "./lib/velum-project";
|
||||
import { mappingForRestoration } from "./lib/mapping-groups";
|
||||
import type { ProjectWhitelistEntry } from "./lib/velum-project";
|
||||
import { CHOOSE_CONTEXT_ID, NEW_PROJECT_ID, type ContextFormValues } from "./context-values";
|
||||
@@ -41,6 +41,104 @@ export function applyProjectWhitelist(text: string, response: PseudonymizeRespon
|
||||
};
|
||||
}
|
||||
|
||||
export type PreparedText = {
|
||||
text: string;
|
||||
raw: PseudonymizeResponse;
|
||||
previous: PlaceholderMapping;
|
||||
exclusions: ProjectWhitelistEntry[];
|
||||
selected: string;
|
||||
projectPath?: string;
|
||||
projectName?: string;
|
||||
};
|
||||
|
||||
/** The local API may propose hits, but this step never stores mappings or starts a cloud request. */
|
||||
export async function prepareTextInContext(values: ContextFormValues, text: string,
|
||||
entityTypes: EntityType[], request: typeof pseudonymize = pseudonymize): Promise<PreparedText> {
|
||||
const selected = values.sessionId;
|
||||
if (!selected || selected === CHOOSE_CONTEXT_ID) throw new Error("Bitte ein Projekt oder eine Sitzung wählen.");
|
||||
if (selected === NEW_PROJECT_ID || selected.startsWith("project:")) {
|
||||
const folder = selected === NEW_PROJECT_ID ? values.newProjectPath?.[0] : selected.slice("project:".length);
|
||||
if (!folder || !(await fs.stat(folder).catch(() => undefined))?.isDirectory()) {
|
||||
throw new Error("Bitte einen vorhandenen Projektordner wählen.");
|
||||
}
|
||||
const path = canonicalProjectPath(folder);
|
||||
const latest = (await listRuns(path))[0];
|
||||
if (selected === NEW_PROJECT_ID && latest) {
|
||||
throw new Error("Für diesen Ordner besteht bereits ein Projekt. Bitte es in der Liste wählen.");
|
||||
}
|
||||
if (selected !== NEW_PROJECT_ID && !latest) throw new Error("Projektstand nicht gefunden. Bitte die Liste aktualisieren.");
|
||||
const [rules, exclusions] = await Promise.all([loadProjectRules(path), loadProjectWhitelist(path)]);
|
||||
const excluded = new Set(exclusions.map(whitelistKey));
|
||||
const masks = forceMasks(rules.filter((rule) => !excluded.has(whitelistKey({ type: rule.type, original: rule.value }))));
|
||||
const previous = latest?.run.mapping ?? {};
|
||||
const raw = applyProjectWhitelist(text, await request(text, previous, entityTypes, masks), previous, exclusions);
|
||||
if (!raw.spans.length && raw.pseudonymized_text !== text) {
|
||||
throw new Error("Die Analyse lieferte Maskierungen ohne überprüfbare Treffer. Es wurde nichts gespeichert.");
|
||||
}
|
||||
return { text, raw, previous, exclusions, selected, projectPath: path,
|
||||
projectName: latest?.run.projectName ?? path.split("/").filter(Boolean).at(-1) ?? path };
|
||||
}
|
||||
const session = selected === NEW_SESSION_ID ? undefined : await getSession(selected);
|
||||
if (selected !== NEW_SESSION_ID && !session) throw new Error("Sitzung nicht gefunden. Bitte die Liste aktualisieren.");
|
||||
const previous = session?.mapping ?? {};
|
||||
const exclusions = session?.excludedTerms ?? [];
|
||||
const raw = applyProjectWhitelist(text, await request(text, previous, entityTypes), previous, exclusions);
|
||||
if (!raw.spans.length && raw.pseudonymized_text !== text) {
|
||||
throw new Error("Die Analyse lieferte Maskierungen ohne überprüfbare Treffer. Es wurde nichts gespeichert.");
|
||||
}
|
||||
return { text, raw, previous, exclusions, selected };
|
||||
}
|
||||
|
||||
/** Commit only the explicitly selected hits; rejected terms become context-specific exceptions. */
|
||||
export async function commitPreparedText(prepared: PreparedText, selectedHits: Set<number>, forAi = false):
|
||||
Promise<{ result: PseudonymizeResponse; session: VelumSession }> {
|
||||
const accepted = prepared.raw.spans.filter((_, index) => selectedHits.has(index));
|
||||
const rejected = prepared.raw.spans.filter((_, index) => !selectedHits.has(index));
|
||||
const spans = toUtf16Offsets(prepared.text, accepted).map((span, index) => ({ ...span, id: String(index) }));
|
||||
const known = projectMapping(prepared.previous);
|
||||
const preview = projectMapping(prepared.raw.mapping);
|
||||
const active = new Set(accepted.map((span) => span.placeholder.replace(/^<|>$/g, "")));
|
||||
const mapping: PlaceholderMapping = { ...known };
|
||||
for (const key of active) {
|
||||
const entry = preview[key];
|
||||
if (!entry) throw new Error(`Zuordnung für ${key} fehlt. Es wurde nichts gespeichert.`);
|
||||
mapping[key] = entry;
|
||||
}
|
||||
const raw: PseudonymizeResponse = { ...prepared.raw, spans: accepted,
|
||||
mapping, entity_count: active.size,
|
||||
pseudonymized_text: replaceSpans(prepared.text, spans, new Set(spans.map((span) => span.id))) };
|
||||
const result = forAi ? normalizePseudonymizeResponse(raw) : raw;
|
||||
const additions = rejected.map(({ type, original }) => ({ type, original }));
|
||||
const exclusions = [...new Map([...prepared.exclusions, ...additions]
|
||||
.map((item) => [whitelistKey(item), item])).values()];
|
||||
if (prepared.projectPath) {
|
||||
const path = prepared.projectPath;
|
||||
const latest = (await listRuns(path))[0];
|
||||
if (prepared.selected === NEW_PROJECT_ID ? Boolean(latest)
|
||||
: !latest || JSON.stringify(latest.run.mapping) !== JSON.stringify(prepared.previous)) {
|
||||
throw new Error("Der Projektstand wurde inzwischen geändert. Bitte erneut analysieren.");
|
||||
}
|
||||
if (latest) {
|
||||
await updateProjectMapping(path, () => mapping);
|
||||
} else {
|
||||
const created = await createRun(path);
|
||||
created.run.mapping = mapping;
|
||||
await saveRun(created.directory, created.run);
|
||||
}
|
||||
if (additions.length) await saveProjectWhitelist(path, exclusions);
|
||||
return { result, session: resultSession(path, prepared.projectName ?? path,
|
||||
mappingForRestoration(result.mapping), result.selected_entity_types) };
|
||||
}
|
||||
const session = prepared.selected === NEW_SESSION_ID ? await createSession() : await getSession(prepared.selected);
|
||||
if (!session) throw new Error("Sitzung nicht gefunden. Bitte erneut analysieren.");
|
||||
if (prepared.selected !== NEW_SESSION_ID && JSON.stringify(session.mapping) !== JSON.stringify(prepared.previous)) {
|
||||
throw new Error("Die Sitzung wurde inzwischen geändert. Bitte erneut analysieren.");
|
||||
}
|
||||
const saved = await updateSessionMapping(session.id, result.mapping, result.selected_entity_types, exclusions);
|
||||
await setActiveSession(saved.id);
|
||||
return { result, session: { ...saved, mapping: mappingForRestoration(saved.mapping) } };
|
||||
}
|
||||
|
||||
/** A text command must use the context explicitly selected in its form. */
|
||||
export async function pseudonymizeInContext(values: ContextFormValues, text: string,
|
||||
entityTypes: EntityType[], forAi = false,
|
||||
|
||||
72
src/text-hit-review.tsx
Normal file
72
src/text-hit-review.tsx
Normal file
@@ -0,0 +1,72 @@
|
||||
import { Action, ActionPanel, Icon, List, showToast, Toast } from "@raycast/api";
|
||||
import { useMemo, useState } from "react";
|
||||
import { groupReviewHits } from "./lib/project-review";
|
||||
import { commitPreparedText, type PreparedText } from "./text-context";
|
||||
import type { PseudonymizeResponse, VelumSession } from "./types";
|
||||
|
||||
export function TextHitReview(props: { prepared: PreparedText; forAi?: boolean;
|
||||
onConfirmed: (result: PseudonymizeResponse, session: VelumSession) => Promise<void> | void }) {
|
||||
const [selected, setSelected] = useState<Set<number>>(
|
||||
() => new Set(props.prepared.raw.spans.map((_, index) => index)));
|
||||
const [busy, setBusy] = useState(false);
|
||||
const groups = useMemo(() => groupReviewHits(props.prepared.raw.spans.map((span, index) => ({
|
||||
...span, id: String(index),
|
||||
}))), [props.prepared]);
|
||||
const byType = new Map<string, typeof groups>();
|
||||
for (const group of groups) {
|
||||
if (!byType.has(group.type)) byType.set(group.type, []);
|
||||
byType.get(group.type)!.push(group);
|
||||
}
|
||||
async function confirm() {
|
||||
if (busy) return;
|
||||
setBusy(true);
|
||||
const toast = await showToast({ style: Toast.Style.Animated, title: "Auswahl wird übernommen" });
|
||||
try {
|
||||
const { result, session } = await commitPreparedText(props.prepared, selected, props.forAi);
|
||||
toast.style = Toast.Style.Success;
|
||||
toast.title = "Auswahl übernommen";
|
||||
toast.message = `${selected.size} Treffer bestätigt`;
|
||||
await props.onConfirmed(result, session);
|
||||
} catch (error) {
|
||||
toast.style = Toast.Style.Failure;
|
||||
toast.title = "Auswahl nicht übernommen";
|
||||
toast.message = error instanceof Error ? error.message : String(error);
|
||||
} finally { setBusy(false); }
|
||||
}
|
||||
function toggle(ids: number[]) {
|
||||
setSelected((current) => {
|
||||
const next = new Set(current);
|
||||
const all = ids.every((id) => next.has(id));
|
||||
for (const id of ids) { if (all) next.delete(id); else next.add(id); }
|
||||
return next;
|
||||
});
|
||||
}
|
||||
return <List isLoading={busy} isShowingDetail navigationTitle="Treffer vor Pseudonymisierung prüfen"
|
||||
searchBarPlaceholder="Begriff, Kategorie oder Platzhalter suchen">
|
||||
<List.Section title="Abschluss">
|
||||
<List.Item icon={Icon.CheckCircle} title="Auswahl bestätigen"
|
||||
subtitle={`${selected.size} von ${props.prepared.raw.spans.length} Treffern werden maskiert · Abgewählte werden als Ausnahme gespeichert`}
|
||||
detail={<List.Item.Detail markdown="Prüfe die erkannten Begriffe unten. Klicke auf einen Treffer, um ihn ab- oder wieder anzuwählen. Erst mit **Auswahl bestätigen** werden die Zuordnungen gespeichert und der nächste Schritt gestartet." />}
|
||||
actions={<ActionPanel><Action title="Auswahl bestätigen und fortfahren" icon={Icon.CheckCircle} onAction={confirm} /></ActionPanel>} />
|
||||
</List.Section>
|
||||
{[...byType].map(([type, typeGroups]) => <List.Section key={type} title={`${type} · ${typeGroups.length} Begriffe`}>
|
||||
{typeGroups.map((group) => {
|
||||
const ids = group.hits.map((hit) => Number(hit.id));
|
||||
const all = ids.every((id) => selected.has(id));
|
||||
const first = group.hits[0];
|
||||
const start = Math.max(0, first.start - 90);
|
||||
const end = Math.min([...props.prepared.text].length, first.end + 90);
|
||||
const context = [...props.prepared.text].slice(start, end).join("");
|
||||
return <List.Item key={group.key} icon={all ? Icon.CheckCircle : Icon.Circle}
|
||||
title={`${group.original} → ${group.placeholder}`}
|
||||
subtitle={group.hits.length > 1 ? `${group.hits.length} Vorkommen` : undefined}
|
||||
detail={<List.Item.Detail markdown={`**Kontext**\n\n${context.replace(/`/g, "'")}`} />}
|
||||
actions={<ActionPanel>
|
||||
<Action title={all ? "Nicht maskieren" : "Maskieren"} icon={all ? Icon.XMarkCircle : Icon.CheckCircle}
|
||||
onAction={() => toggle(ids)} />
|
||||
<Action title="Auswahl bestätigen und fortfahren" icon={Icon.CheckCircle} onAction={confirm} />
|
||||
</ActionPanel>} />;
|
||||
})}
|
||||
</List.Section>)}
|
||||
</List>;
|
||||
}
|
||||
@@ -35,6 +35,7 @@ export type VelumSession = {
|
||||
updatedAt: string;
|
||||
mapping: PlaceholderMapping;
|
||||
entityTypes?: EntityType[];
|
||||
excludedTerms?: Array<{ type: string; original: string }>;
|
||||
};
|
||||
|
||||
export type QuickOutput = "copy" | "paste";
|
||||
|
||||
Reference in New Issue
Block a user