[9] MCP-Brücke zur offenen App: KI-Zugriff (opt-in, Sitzungsschlüssel), gemeinsame Werkzeugliste, Protokoll und Pause
dossier-cli mcp --app spricht MCP über stdio und lauscht auf 127.0.0.1; die App verbindet sich nur mit „KI-Zugriff erlauben“ als WebSocket-Client (gegenseitige HMAC-Anmeldung). Werkzeuge für Datei und App aus einer Liste (core/aiToolDefs.ts, core/aiTools.ts), run_command über die Kern-Befehle, jede Änderung ein Undo-Schritt „KI: <werkzeug>“, KI-Protokoll mit Pause.
This commit is contained in:
25 files changed
+1594
-119
No files matched your search
@@ -0,0 +1,47 @@
|
||||
// [9] Einstellungen → Allgemein → KI-Zugriff: Schalter (aus per Vorgabe), Sitzungsschlüssel und die
|
||||
// Zeile für den MCP-Client. Rein darstellend (Werte über Props), damit sie auch im nativen
|
||||
// Einstellungs-Fenster läuft (Sync-Brücke, `native/settingsWindow.ts`).
|
||||
|
||||
import { t } from "../i18n";
|
||||
|
||||
/** Was die Einstellungen vom KI-Zugriff zeigen (über die Fenstergrenze serialisierbar). */
|
||||
export interface AiAccessView {
|
||||
enabled: boolean;
|
||||
token: string;
|
||||
port: number;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export function aiBridgeCommandLine(v: Pick<AiAccessView, "token" | "port">): string {
|
||||
const port = v.port === 7979 ? "" : ` --port ${v.port}`;
|
||||
return `dossier-cli mcp --app${port} --token ${v.token}`;
|
||||
}
|
||||
|
||||
export function AiAccessSection({ view, onChange }: { view: AiAccessView; onChange: (on: boolean) => void }) {
|
||||
const copy = (text: string) => void navigator.clipboard?.writeText(text).catch(() => {});
|
||||
return (
|
||||
<section className="imp-section" data-testid="ai-access">
|
||||
<div className="imp-section-title">{t("settings.section.ai")}</div>
|
||||
<label className="settings-check">
|
||||
<input type="checkbox" checked={view.enabled} onChange={(e) => onChange(e.target.checked)} />
|
||||
{t("settings.ai.enable")}
|
||||
</label>
|
||||
<div className="imp-note">{t("settings.ai.hint")}</div>
|
||||
{view.enabled && (
|
||||
<>
|
||||
<span className="settings-field-label">{t("settings.ai.token")}</span>
|
||||
<div className="ai-token-row">
|
||||
<input className="ai-token" readOnly value={view.token} data-testid="ai-token" onFocus={(e) => e.currentTarget.select()} />
|
||||
<button type="button" onClick={() => copy(view.token)}>{t("settings.ai.copy")}</button>
|
||||
</div>
|
||||
<span className="settings-field-label">{t("settings.ai.command")}</span>
|
||||
<div className="ai-token-row">
|
||||
<code className="ai-cmd">{aiBridgeCommandLine(view)}</code>
|
||||
<button type="button" onClick={() => copy(aiBridgeCommandLine(view))}>{t("settings.ai.copy")}</button>
|
||||
</div>
|
||||
<div className="imp-note" data-testid="ai-status">{t(`settings.ai.status.${view.status}`)}</div>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// [9] Kleines Protokoll der KI-Aufrufe (unten links, nur solange „KI-Zugriff erlauben“ an ist):
|
||||
// Verbindungsstand, Schalter „KI pausieren“, die letzten Aufrufe (Änderungen hervorgehoben).
|
||||
|
||||
import { useState } from "react";
|
||||
import { t } from "../i18n";
|
||||
import { clearAiLog, setAiPaused, useAiAccess } from "../state/aiAccess";
|
||||
|
||||
const time = (ms: number) => new Date(ms).toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit", second: "2-digit" });
|
||||
|
||||
export function AiActivityPanel() {
|
||||
const ai = useAiAccess();
|
||||
const [open, setOpen] = useState(true);
|
||||
if (!ai.enabled) return null;
|
||||
const changes = ai.log.filter((e) => e.mutating && e.ok).length;
|
||||
return (
|
||||
<div className={`ai-activity${ai.paused ? " is-paused" : ""}`} data-testid="ai-activity" role="region" aria-label={t("ai.activity.title")}>
|
||||
<div className="ai-activity-head">
|
||||
<span className={`ai-dot ai-dot-${ai.status}`} title={t(`settings.ai.status.${ai.status}`)} />
|
||||
<button type="button" className="ai-activity-title" onClick={() => setOpen(!open)} aria-expanded={open}>
|
||||
{t("ai.activity.title")} {changes > 0 && <span className="ai-count">{changes}</span>}
|
||||
</button>
|
||||
<label className="ai-pause">
|
||||
<input type="checkbox" checked={ai.paused} onChange={(e) => setAiPaused(e.target.checked)} data-testid="ai-pause" />
|
||||
{t("ai.activity.pause")}
|
||||
</label>
|
||||
</div>
|
||||
{open && (
|
||||
<>
|
||||
{ai.log.length === 0 ? (
|
||||
<div className="ai-activity-empty">{t("ai.activity.empty")}</div>
|
||||
) : (
|
||||
<ul className="ai-activity-log" data-testid="ai-log">
|
||||
{ai.log.slice(0, 12).map((e, i) => (
|
||||
<li key={`${e.at}-${i}`} className={`${e.ok ? "" : "is-error"}${e.mutating ? " is-change" : ""}`} title={e.note}>
|
||||
<span className="ai-time">{time(e.at)}</span>
|
||||
<span className="ai-tool">{e.tool}</span>
|
||||
{e.mutating && <span className="ai-tag">{t("ai.activity.change")}</span>}
|
||||
{!e.ok && <span className="ai-tag">{t("ai.activity.error")}</span>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{ai.log.length > 0 && (
|
||||
<button type="button" className="ai-activity-clear" onClick={clearAiLog}>
|
||||
{t("ai.activity.clear")}
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { t, type TranslationKey } from "../i18n";
|
||||
import { ACCENT_SWATCHES } from "../theme/accents";
|
||||
import { ColorHexField } from "./ColorHexField";
|
||||
import { LayoutMenu } from "./LayoutMenu";
|
||||
import { AiAccessSection, type AiAccessView } from "./AiAccessSection";
|
||||
import { APP_VERSION } from "./TopBar";
|
||||
import type { LayoutState } from "../panels/types";
|
||||
import type { ThemeMode } from "../theme/themeMode";
|
||||
@@ -79,6 +80,9 @@ export interface SettingsDialogProps {
|
||||
/** Offline-Modus: sperrt alle entfernten Abrufe (Materialbibliothek, swisstopo, OSM). */
|
||||
offline: boolean;
|
||||
onOfflineChange: (offline: boolean) => void;
|
||||
/** [9] KI-Zugriff (MCP-Brücke): Stand und Schalter; ohne Angabe keine Sektion. */
|
||||
aiAccess?: AiAccessView;
|
||||
onAiAccessChange?: (on: boolean) => void;
|
||||
/** Arbeitsumgebung (Fenster-/Dock-Layouts) — LayoutMenu wird HIER gerendert
|
||||
* (nicht mehr als vorgefertigtes ReactNode hereingereicht: JSX ist über eine
|
||||
* Fenstergrenze nicht serialisierbar, s. `windowed`). */
|
||||
@@ -124,6 +128,8 @@ export function SettingsDialog({
|
||||
onScaleLineWeightsChange,
|
||||
offline,
|
||||
onOfflineChange,
|
||||
aiAccess,
|
||||
onAiAccessChange,
|
||||
layout,
|
||||
onApplyLayout,
|
||||
onAliasOverridesChange,
|
||||
@@ -232,6 +238,8 @@ export function SettingsDialog({
|
||||
<div className="imp-note">{t("settings.offline.hint")}</div>
|
||||
</section>
|
||||
|
||||
{aiAccess && onAiAccessChange && <AiAccessSection view={aiAccess} onChange={onAiAccessChange} />}
|
||||
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("settings.section.display")}</div>
|
||||
<span className="settings-field-label">{t("settings.theme")}</span>
|
||||
|
||||
Reference in new issue
Block a user