mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-25 17:30:56 +08:00
Every user-visible string in the web UI now goes through t() from web/src/i18n. The English source text is the key, so a missing entry falls back to English and nothing breaks; Turkish lives in one flat file, web/src/i18n/locales/tr.json (about 2,600 entries). The locale is chosen once per page load: a saved choice, else the browser language, else English. Switching (new Language toggle under Preferences) stores the choice and reloads, so t() also works in module constants, helpers and toasts without hooks. Also: - hard-coded zh-CN / implicit date locales now follow the UI language - sentences assembled from fragments became single templates - "Toujours autoriser" in approval records is now English - upload.test.mjs stubs the new @/i18n import Values sent to the API or compared in code, agent prompts, and backend messages are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
669 lines
27 KiB
TypeScript
669 lines
27 KiB
TypeScript
"use client";
|
|
"use no memo";
|
|
|
|
import * as React from "react";
|
|
import {
|
|
Background,
|
|
BackgroundVariant,
|
|
Controls,
|
|
type Edge as RFEdge,
|
|
Handle,
|
|
MarkerType,
|
|
MiniMap,
|
|
type Node as RFNode,
|
|
type NodeProps,
|
|
Panel,
|
|
Position,
|
|
ReactFlow,
|
|
ReactFlowProvider,
|
|
useEdgesState,
|
|
useNodesState,
|
|
} from "@xyflow/react";
|
|
import "@xyflow/react/dist/style.css";
|
|
import {
|
|
Bug,
|
|
Compass,
|
|
Flag,
|
|
FlaskConical,
|
|
Layers,
|
|
Lightbulb,
|
|
type LucideIcon,
|
|
Target,
|
|
} from "lucide-react";
|
|
|
|
import { cn } from "@/lib/utils";
|
|
import { intlLocale, t } from "@/i18n";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { StatusBadge } from "@/components/status-badge";
|
|
import { ScrollArea } from "@/components/ui/scroll-area";
|
|
import {
|
|
Sheet,
|
|
SheetContent,
|
|
SheetHeader,
|
|
SheetTitle,
|
|
} from "@/components/ui/sheet";
|
|
import { toneClasses, type Tone } from "@/lib/status";
|
|
import type { Edge, ExploreKind, TaskNode } from "@/lib/types";
|
|
|
|
export const relLabel: Record<string, string> = {
|
|
spawns: t("spawns"),
|
|
derived_from: t("intent chain"),
|
|
yields: t("yields"),
|
|
proves: t("proves"),
|
|
};
|
|
|
|
export const relColor: Record<string, string> = {
|
|
spawns: "#10b981",
|
|
derived_from: "#6366f1",
|
|
yields: "#f59e0b",
|
|
proves: "#ef4444",
|
|
};
|
|
|
|
type TypeMeta = {
|
|
label: string;
|
|
icon: LucideIcon;
|
|
iconBg: string;
|
|
chip: string;
|
|
hex: string;
|
|
};
|
|
|
|
const typeMeta: Record<ExploreKind, TypeMeta> = {
|
|
task: { label: t("Root task"), icon: Flag, iconBg: "bg-slate-500", chip: "bg-slate-500/15 text-slate-600 dark:text-slate-300", hex: "#64748b" },
|
|
begin: { label: t("Start"), icon: Flag, iconBg: "bg-slate-500", chip: "bg-slate-500/15 text-slate-600 dark:text-slate-300", hex: "#64748b" },
|
|
goal: { label: t("Goal"), icon: Target, iconBg: "bg-emerald-500", chip: "bg-emerald-500/15 text-emerald-600 dark:text-emerald-400", hex: "#10b981" },
|
|
hint: { label: t("Hint"), icon: Lightbulb, iconBg: "bg-violet-500", chip: "bg-violet-500/15 text-violet-600 dark:text-violet-400", hex: "#8b5cf6" },
|
|
intent: { label: t("Intent"), icon: Compass, iconBg: "bg-blue-500", chip: "bg-blue-500/15 text-blue-600 dark:text-blue-400", hex: "#3b82f6" },
|
|
fact: { label: t("Fact"), icon: FlaskConical, iconBg: "bg-amber-500", chip: "bg-amber-500/15 text-amber-600 dark:text-amber-400", hex: "#f59e0b" },
|
|
finding: { label: t("Vulnerability"), icon: Bug, iconBg: "bg-rose-500", chip: "bg-rose-500/15 text-rose-600 dark:text-rose-400", hex: "#f43f5e" },
|
|
digest: { label: t("Digest"), icon: Layers, iconBg: "bg-teal-500", chip: "bg-teal-500/15 text-teal-600 dark:text-teal-400", hex: "#14b8a6" },
|
|
};
|
|
|
|
// The task root is an origin fact (kind='fact', state='origin'); render it as "Start".
|
|
function viewKind(n: TaskNode): ExploreKind {
|
|
return n.type === "fact" && n.state === "origin" ? "begin" : n.type;
|
|
}
|
|
|
|
function prioTone(p: number): Tone {
|
|
return p >= 8 ? "red" : p >= 5 ? "amber" : "slate";
|
|
}
|
|
|
|
const summaryFields: Record<ExploreKind, string[]> = {
|
|
task: ["summary", "description"],
|
|
begin: ["summary", "description"],
|
|
goal: ["text"],
|
|
hint: [],
|
|
intent: ["summary"],
|
|
fact: ["summary"],
|
|
finding: ["name", "summary"],
|
|
digest: ["body"],
|
|
};
|
|
|
|
function nodeSummary(n: TaskNode): string {
|
|
const raw = n.payload ?? "";
|
|
const fields = summaryFields[viewKind(n)] ?? [];
|
|
if (fields.length && raw.trim()) {
|
|
try {
|
|
const obj: unknown = JSON.parse(raw);
|
|
if (obj && typeof obj === "object") {
|
|
for (const f of fields) {
|
|
const v = (obj as Record<string, unknown>)[f];
|
|
if (typeof v === "string" && v.trim()) return v;
|
|
}
|
|
}
|
|
} catch {
|
|
/* not JSON: show as-is */
|
|
}
|
|
}
|
|
return raw;
|
|
}
|
|
|
|
// digestMemberIds reads the fact/intent ids a digest folds from its payload
|
|
// (member_ids.{facts,intents}); ids are numbers in JSON, node ids are strings.
|
|
function digestMemberIds(n: TaskNode): string[] {
|
|
if (n.type !== "digest" || !n.payload) return [];
|
|
try {
|
|
const p = JSON.parse(n.payload) as {
|
|
member_ids?: { facts?: Array<string | number>; intents?: Array<string | number> };
|
|
};
|
|
return [...(p.member_ids?.facts ?? []), ...(p.member_ids?.intents ?? [])].map(String);
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
// collapseDigestGraph contracts each active digest's covered members into the
|
|
// digest super-node: the members are dropped from the rendered set and every
|
|
// edge touching a member is rewired onto its digest (member→member internal
|
|
// edges collapse to a self-loop and are dropped; the resulting edges are
|
|
// deduped by src+rel+dst). covers edges are structural and never drawn.
|
|
// Superseded digests (no covers edges) are dropped entirely. A graph with no
|
|
// active digest passes through unchanged. The full node list is kept by the
|
|
// caller so the detail drawer can still resolve a folded member by id.
|
|
function collapseDigestGraph(nodes: TaskNode[], edges: Edge[]): { viewNodes: TaskNode[]; viewEdges: Edge[] } {
|
|
const activeDigests = new Set(
|
|
nodes.filter((n) => n.type === "digest" && n.state === "active").map((n) => n.id),
|
|
);
|
|
const memberToDigest = new Map<string, string>();
|
|
for (const e of edges) {
|
|
if (e.rel === "covers" && activeDigests.has(e.src)) memberToDigest.set(e.dst, e.src);
|
|
}
|
|
const viewNodes = nodes.filter((n) =>
|
|
n.type === "digest" ? n.state === "active" : !memberToDigest.has(n.id),
|
|
);
|
|
const remap = (id: string) => memberToDigest.get(id) ?? id;
|
|
const seen = new Set<string>();
|
|
const rewired: Edge[] = [];
|
|
// src+dst of every rewired yields edge, so the inverse derived_from can be dropped.
|
|
const produced = new Set<string>();
|
|
for (const e of edges) {
|
|
if (e.rel === "covers") continue;
|
|
const src = remap(e.src);
|
|
const dst = remap(e.dst);
|
|
if (src === dst) continue;
|
|
const key = `${src} |