642 lines
34 KiB
JavaScript
642 lines
34 KiB
JavaScript
import { getEarthLocale } from "./i18n.js";
|
||
|
||
const SERIES_STROKES = [
|
||
"#5cc8ff",
|
||
"#fbbf24",
|
||
"#34d399",
|
||
"#c084fc",
|
||
"#f87171",
|
||
"#93c5fd",
|
||
];
|
||
|
||
const t = (zh, en) => (getEarthLocale() === "en-US" ? en : zh);
|
||
|
||
export function escapeWorkbenchHtml(val) {
|
||
return String(val ?? "").replace(/[&<>"']/g, (ch) => ({
|
||
"&": "&",
|
||
"<": "<",
|
||
">": ">",
|
||
'"': """,
|
||
"'": "'",
|
||
})[ch]);
|
||
}
|
||
|
||
export const REGISTERED_WORKBENCH_BLOCKS = new Set([
|
||
"comparison_matrix",
|
||
"trend_corridor",
|
||
"causal_brief",
|
||
"impact_topology",
|
||
"evidence_drawer",
|
||
"executive_onepager",
|
||
]);
|
||
|
||
function renderCitationPills(evidenceIds = [], turnId = "", activeEvidenceId = null) {
|
||
const cleanIds = Array.isArray(evidenceIds)
|
||
? evidenceIds.filter((id, idx, arr) => Boolean(id) && arr.indexOf(id) === idx)
|
||
: [];
|
||
if (!cleanIds.length) return "";
|
||
return `<span class="wb-inline-citations">${cleanIds
|
||
.map((eid) => {
|
||
const isActive = activeEvidenceId === eid;
|
||
return `<button type="button" class="copilot-source-pill wb-cite-pill ${isActive ? "is-active" : ""}" data-copilot-evidence="${escapeWorkbenchHtml(eid)}" data-turn-id="${escapeWorkbenchHtml(turnId)}" aria-pressed="${String(isActive)}" title="${escapeWorkbenchHtml(t(`查看证据源 ${eid}`, `Inspect source ${eid}`))}">
|
||
<span class="material-symbols-rounded copilot-source-pill__icon" aria-hidden="true">verified</span>
|
||
<span class="copilot-source-pill__text">${escapeWorkbenchHtml(eid)}</span>
|
||
</button>`;
|
||
})
|
||
.join("")}</span>`;
|
||
}
|
||
|
||
function renderComparisonMatrixBlock(block, { turnId = "", activeEvidenceId = null, matrixModeOverride = null } = {}) {
|
||
const data = block.data || {};
|
||
const rows = Array.isArray(data.rows) ? data.rows : [];
|
||
const isEn = getEarthLocale() === "en-US";
|
||
const mode = matrixModeOverride || data.display_mode || "bars";
|
||
const rpi = Number.isFinite(Number(data.rpi_percent)) ? Number(data.rpi_percent) : null;
|
||
|
||
const rpiBadge = rpi !== null
|
||
? `<span class="wb-kpi-pill" title="${escapeWorkbenchHtml(t("双边相对算力平价 (CN / US)", "Bilateral Relative Parity Index (CN / US)"))}">RPI ${escapeWorkbenchHtml(rpi.toFixed(1))}%</span>`
|
||
: "";
|
||
|
||
const modeSwitchBtn = `<button type="button" class="wb-mini-btn" data-wb-matrix-toggle="${mode === "table" ? "bars" : "table"}" data-turn-id="${escapeWorkbenchHtml(turnId)}" title="${escapeWorkbenchHtml(mode === "table" ? t("切换为比例条视图", "Switch to bar chart") : t("切换为数据表视图", "Switch to data table"))}">
|
||
<span class="material-symbols-rounded" aria-hidden="true">${mode === "table" ? "bar_chart" : "table_chart"}</span>
|
||
<span>${escapeWorkbenchHtml(mode === "table" ? t("比例图", "Bars") : t("数据表", "Table"))}</span>
|
||
</button>`;
|
||
|
||
let bodyHtml = "";
|
||
const entityColHeader = isEn
|
||
? (data.entity_column_label_en || "Country / Region")
|
||
: (data.entity_column_label || "国家 / 区域");
|
||
if (mode === "table") {
|
||
bodyHtml = `<div class="wb-table-wrap">
|
||
<table class="wb-table">
|
||
<thead>
|
||
<tr>
|
||
<th scope="col">${escapeWorkbenchHtml(entityColHeader)}</th>
|
||
<th scope="col">${escapeWorkbenchHtml(t("年份 / 窗口", "Period"))}</th>
|
||
<th scope="col">${escapeWorkbenchHtml(t("核验数值", "Verified Value"))}</th>
|
||
<th scope="col">${escapeWorkbenchHtml(t("出处", "Source"))}</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
${rows
|
||
.map((r) => {
|
||
const label = isEn ? (r.label_en || r.label || r.code) : (r.label || r.code);
|
||
const missingLabel = data.replay_supported === false
|
||
? (r.formatted || t("不支持完整重放", "Replay Unsupported"))
|
||
: t("暂无同口径披露", "Not Disclosed");
|
||
const valCell = r.is_missing
|
||
? `<span class="wb-missing-tag" title="${escapeWorkbenchHtml(r.missing_reason || "")}">${escapeWorkbenchHtml(missingLabel)}</span>`
|
||
: `<strong>${escapeWorkbenchHtml(r.formatted)}</strong>`;
|
||
return `<tr class="${r.is_missing ? "is-missing" : ""}">
|
||
<td><span class="wb-code-tag">${escapeWorkbenchHtml(r.code)}</span> ${escapeWorkbenchHtml(label)}</td>
|
||
<td class="wb-tabular">${escapeWorkbenchHtml(r.year ?? "—")}</td>
|
||
<td class="wb-tabular">${valCell}</td>
|
||
<td>${r.evidence_id ? renderCitationPills([r.evidence_id], turnId, activeEvidenceId) : "—"}</td>
|
||
</tr>`;
|
||
})
|
||
.join("")}
|
||
</tbody>
|
||
</table>
|
||
</div>`;
|
||
} else {
|
||
bodyHtml = `<div class="wb-matrix-bars">
|
||
${rows
|
||
.map((r, idx) => {
|
||
const label = isEn ? (r.label_en || r.label || r.code) : (r.label || r.code);
|
||
const pct = Math.max(0, Math.min(100, Number(r.bar_pct || 0)));
|
||
const color = r.code === "CN" ? "#fbbf24" : r.code === "US" ? "#5cc8ff" : SERIES_STROKES[idx % SERIES_STROKES.length];
|
||
const missingLabel = data.replay_supported === false
|
||
? (r.formatted || t("不支持完整重放", "Replay Unsupported"))
|
||
: t("暂无同口径公开发布值", "No uniform disclosure");
|
||
return `<div class="wb-matrix-row ${r.is_missing ? "is-missing" : ""}" title="${escapeWorkbenchHtml(r.missing_reason || "")}">
|
||
<div class="wb-matrix-row__top">
|
||
<span class="wb-matrix-row__name">
|
||
<span class="wb-code-tag">${escapeWorkbenchHtml(r.code)}</span>
|
||
<span>${escapeWorkbenchHtml(label)}</span>
|
||
${r.year ? `<small class="wb-matrix-row__year">${escapeWorkbenchHtml(r.year)}</small>` : ""}
|
||
</span>
|
||
<span class="wb-matrix-row__val wb-tabular">
|
||
${r.is_missing
|
||
? `<span class="wb-missing-tag">${escapeWorkbenchHtml(missingLabel)}</span>`
|
||
: `<strong>${escapeWorkbenchHtml(r.formatted)}</strong>`}
|
||
${r.evidence_id ? renderCitationPills([r.evidence_id], turnId, activeEvidenceId) : ""}
|
||
</span>
|
||
</div>
|
||
<div class="wb-matrix-track" aria-hidden="true">
|
||
${r.is_missing
|
||
? `<div class="wb-matrix-fill wb-matrix-fill--missing"></div>`
|
||
: `<div class="wb-matrix-fill" style="width:${pct.toFixed(1)}%;background:${color};"></div>`}
|
||
</div>
|
||
</div>`;
|
||
})
|
||
.join("")}
|
||
</div>`;
|
||
}
|
||
|
||
const title = isEn ? (block.title_en || block.title) : block.title;
|
||
return `<section class="wb-block wb-block--matrix" data-block-id="${escapeWorkbenchHtml(block.block_id)}" data-block-type="comparison_matrix">
|
||
<header class="wb-block__header">
|
||
<div class="wb-block__title-wrap">
|
||
<span class="material-symbols-rounded wb-block__icon" aria-hidden="true">equalizer</span>
|
||
<h5 class="wb-block__title">${escapeWorkbenchHtml(title)}</h5>
|
||
${rpiBadge}
|
||
</div>
|
||
<div class="wb-block__actions">${modeSwitchBtn}</div>
|
||
</header>
|
||
<div class="wb-block__body">${bodyHtml}</div>
|
||
</section>`;
|
||
}
|
||
|
||
/**
|
||
* Builds non-interpolated SVG path segments and explicit dashed gap connectors.
|
||
* Missing years (`is_gap === true` or `value === null`) NEVER receive synthetic interpolated lines.
|
||
*/
|
||
export function buildCorridorGeometry(points = [], { width = 312, height = 92, padX = 16, padY = 14, maxVal = 100 } = {}) {
|
||
if (!Array.isArray(points) || points.length === 0) {
|
||
return { solidPaths: [], gapSegments: [], dots: [] };
|
||
}
|
||
const safeMax = maxVal > 0 ? maxVal : 100;
|
||
const spanCount = Math.max(1, points.length - 1);
|
||
const plotW = Math.max(20, width - padX * 2);
|
||
const plotH = Math.max(20, height - padY * 2);
|
||
|
||
const coords = points.map((pt, idx) => {
|
||
const x = points.length === 1 ? width / 2 : padX + (idx / spanCount) * plotW;
|
||
const isGap = Boolean(pt?.is_gap || pt?.value === null || pt?.value === undefined || !Number.isFinite(Number(pt.value)));
|
||
const y = isGap ? null : padY + plotH - (Math.max(0, Number(pt.value)) / safeMax) * plotH;
|
||
return {
|
||
idx,
|
||
year: pt?.year,
|
||
value: isGap ? null : Number(pt.value),
|
||
isGap,
|
||
x: Number(x.toFixed(1)),
|
||
y: y === null ? null : Number(y.toFixed(1)),
|
||
};
|
||
});
|
||
|
||
const solidPaths = [];
|
||
let currentSegment = [];
|
||
for (const c of coords) {
|
||
if (!c.isGap && c.y !== null) {
|
||
currentSegment.push(c);
|
||
} else if (currentSegment.length) {
|
||
if (currentSegment.length >= 2) {
|
||
solidPaths.push(
|
||
currentSegment.map((p, i) => `${i === 0 ? "M" : "L"}${p.x},${p.y}`).join(" "),
|
||
);
|
||
}
|
||
currentSegment = [];
|
||
}
|
||
}
|
||
if (currentSegment.length >= 2) {
|
||
solidPaths.push(
|
||
currentSegment.map((p, i) => `${i === 0 ? "M" : "L"}${p.x},${p.y}`).join(" "),
|
||
);
|
||
}
|
||
|
||
// Record explicit gap spans (drawn only as baseline gap brackets, never value-interpolating lines)
|
||
const gapSegments = [];
|
||
for (const c of coords) {
|
||
if (c.isGap) {
|
||
gapSegments.push({ year: c.year, x: c.x, yTop: padY + 4, yBottom: padY + plotH });
|
||
}
|
||
}
|
||
|
||
const dots = coords.filter((c) => !c.isGap && c.y !== null);
|
||
return { solidPaths, gapSegments, dots, baselineY: padY + plotH };
|
||
}
|
||
|
||
function renderTrendCorridorBlock(block, { collapsedOverride } = {}) {
|
||
const data = block.data || {};
|
||
const isEn = getEarthLocale() === "en-US";
|
||
const title = isEn ? (block.title_en || block.title) : block.title;
|
||
const years = Array.isArray(data.years) ? data.years : [];
|
||
const series = Array.isArray(data.series) ? data.series : [];
|
||
const isCollapsed = collapsedOverride !== undefined ? collapsedOverride : Boolean(block.collapsed);
|
||
|
||
let maxVal = 0;
|
||
let hasAnyGap = false;
|
||
for (const s of series) {
|
||
for (const pt of s.points || []) {
|
||
if (pt.is_gap || pt.value === null || pt.value === undefined) {
|
||
hasAnyGap = true;
|
||
} else if (Number.isFinite(Number(pt.value))) {
|
||
maxVal = Math.max(maxVal, Number(pt.value));
|
||
}
|
||
}
|
||
}
|
||
if (maxVal <= 0) maxVal = 100;
|
||
|
||
const svgW = 320;
|
||
const svgH = 98;
|
||
const seriesVisuals = series.map((s, idx) => {
|
||
const color = s.code === "CN" ? "#fbbf24" : s.code === "US" ? "#5cc8ff" : SERIES_STROKES[idx % SERIES_STROKES.length];
|
||
const geom = buildCorridorGeometry(s.points || [], { width: svgW, height: svgH, maxVal: maxVal * 1.08 });
|
||
return { ...s, color, geom };
|
||
});
|
||
|
||
const gapMarkers = seriesVisuals[0]?.geom?.gapSegments || [];
|
||
const innovation = data.innovation_summary;
|
||
const innovLine = innovation && Number.isFinite(Number(innovation.latest_gap))
|
||
? t(
|
||
`AI 创新指数分差收窄至 ${Number(innovation.latest_gap).toFixed(2)} 分`,
|
||
`AI innovation index gap narrowed to ${Number(innovation.latest_gap).toFixed(2)}`,
|
||
)
|
||
: "";
|
||
|
||
const bodyHtml = (data.replay_supported === false || !years.length || !seriesVisuals.length)
|
||
? `<p class="wb-empty-note">${escapeWorkbenchHtml(data.replay_notice || t("不支持完整重放:当前历史记录缺少冻结走势快照。", "Full replay unsupported: historical trajectory snapshot missing."))}</p>`
|
||
: `<div class="wb-corridor-legend">
|
||
${seriesVisuals
|
||
.map((s) => {
|
||
const pts = (s.points || []).filter((p) => !p.is_gap && p.value !== null);
|
||
const lastPt = pts[pts.length - 1];
|
||
const lbl = isEn ? (s.label_en || s.label || s.code) : (s.label || s.code);
|
||
return `<span class="wb-corridor-legend__item">
|
||
<i class="wb-corridor-legend__swatch" style="background:${s.color};"></i>
|
||
<span>${escapeWorkbenchHtml(lbl)}</span>
|
||
${lastPt ? `<strong class="wb-tabular">${escapeWorkbenchHtml(`${lastPt.value}${data.unit || ""}`)}</strong>` : ""}
|
||
</span>`;
|
||
})
|
||
.join("")}
|
||
</div>
|
||
<svg class="wb-corridor-svg" viewBox="0 0 ${svgW} ${svgH}" role="img" aria-label="${escapeWorkbenchHtml(title)}">
|
||
<line x1="16" y1="84" x2="304" y2="84" stroke="rgba(197,220,242,0.16)" stroke-width="1" />
|
||
<line x1="16" y1="49" x2="304" y2="49" stroke="rgba(197,220,242,0.08)" stroke-dasharray="2 3" stroke-width="1" />
|
||
${gapMarkers
|
||
.map(
|
||
(g) => `<g class="wb-corridor__gap-marker">
|
||
<line x1="${g.x}" y1="${g.yTop}" x2="${g.x}" y2="${g.yBottom}" stroke="rgba(251,191,36,0.35)" stroke-dasharray="3 3" stroke-width="1.2" />
|
||
<text x="${g.x}" y="${g.yTop + 8}" text-anchor="middle" fill="#fcd34d" font-size="8.5">${escapeWorkbenchHtml(t("留白", "GAP"))}</text>
|
||
</g>`,
|
||
)
|
||
.join("")}
|
||
${seriesVisuals
|
||
.map(
|
||
(s) => `<g data-series-code="${escapeWorkbenchHtml(s.code)}">
|
||
${s.geom.solidPaths
|
||
.map(
|
||
(d) => `<path d="${d}" fill="none" stroke="${s.color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />`,
|
||
)
|
||
.join("")}
|
||
${s.geom.dots
|
||
.map(
|
||
(pt) => `<circle cx="${pt.x}" cy="${pt.y}" r="2.9" fill="${s.color}" stroke="rgba(8,18,32,0.9)" stroke-width="1"><title>${escapeWorkbenchHtml(`${s.code} ${pt.year}: ${pt.value}${data.unit || ""}`)}</title></circle>`,
|
||
)
|
||
.join("")}
|
||
</g>`,
|
||
)
|
||
.join("")}
|
||
</svg>
|
||
<div class="wb-corridor-years wb-tabular">
|
||
<span>${escapeWorkbenchHtml(years[0] ?? "")}</span>
|
||
${years.length > 2 ? `<span>${escapeWorkbenchHtml(years[Math.floor(years.length / 2)] ?? "")}</span>` : ""}
|
||
<span>${escapeWorkbenchHtml(years[years.length - 1] ?? "")}</span>
|
||
</div>
|
||
${hasAnyGap ? `<p class="wb-corridor-note">${escapeWorkbenchHtml(t("注:缺失年份严格中断连线并做虚线留白标记,不执行跨年线性插值。", "Note: Undisclosed years break trajectory lines explicitly; no cross-year interpolation is performed."))}</p>` : ""}
|
||
${innovLine ? `<div class="wb-corridor-badge"><span class="material-symbols-rounded" aria-hidden="true">auto_graph</span><span>${escapeWorkbenchHtml(innovLine)}</span></div>` : ""}`;
|
||
|
||
return `<section class="wb-block wb-block--corridor ${isCollapsed ? "is-collapsed" : ""}" data-block-id="${escapeWorkbenchHtml(block.block_id)}" data-block-type="trend_corridor">
|
||
<header class="wb-block__header">
|
||
<div class="wb-block__title-wrap">
|
||
<span class="material-symbols-rounded wb-block__icon" aria-hidden="true">timeline</span>
|
||
<h5 class="wb-block__title">${escapeWorkbenchHtml(title)}</h5>
|
||
</div>
|
||
<button type="button" class="wb-mini-btn" data-wb-collapse-toggle="${escapeWorkbenchHtml(block.block_id)}" aria-expanded="${String(!isCollapsed)}" title="${escapeWorkbenchHtml(isCollapsed ? t("展开趋势走廊", "Expand corridor") : t("收起趋势走廊", "Collapse corridor"))}">
|
||
<span class="material-symbols-rounded" aria-hidden="true">${isCollapsed ? "expand_more" : "expand_less"}</span>
|
||
</button>
|
||
</header>
|
||
${isCollapsed ? "" : `<div class="wb-block__body">${bodyHtml}</div>`}
|
||
</section>`;
|
||
}
|
||
|
||
function renderCausalBriefBlock(block, { turnId = "", activeEvidenceId = null } = {}) {
|
||
const data = block.data || {};
|
||
const isEn = getEarthLocale() === "en-US";
|
||
const title = isEn ? (block.title_en || block.title) : block.title;
|
||
const mathItems = Array.isArray(data.math_decomposition) ? data.math_decomposition : [];
|
||
const causalItems = Array.isArray(data.causal_candidates) ? data.causal_candidates : [];
|
||
const leverItems = Array.isArray(data.counter_evidence_and_levers) ? data.counter_evidence_and_levers : [];
|
||
const unknownGaps = Array.isArray(data.unknown_gaps) ? data.unknown_gaps : [];
|
||
|
||
const renderGroup = (badgeText, badgeClass, items) => {
|
||
if (!items.length) return "";
|
||
return `<div class="wb-causal-group">
|
||
<div class="wb-causal-group__tag ${badgeClass}">${escapeWorkbenchHtml(badgeText)}</div>
|
||
<ul class="wb-causal-list">
|
||
${items
|
||
.map((item) => {
|
||
const itemTitle = item.formula_label || item.label || "";
|
||
return `<li class="wb-causal-item">
|
||
${itemTitle ? `<strong>${escapeWorkbenchHtml(itemTitle)}:</strong>` : ""}
|
||
<span>${escapeWorkbenchHtml(item.detail || "")}</span>
|
||
${renderCitationPills(item.evidence_ids, turnId, activeEvidenceId)}
|
||
</li>`;
|
||
})
|
||
.join("")}
|
||
</ul>
|
||
</div>`;
|
||
};
|
||
|
||
return `<section class="wb-block wb-block--causal" data-block-id="${escapeWorkbenchHtml(block.block_id)}" data-block-type="causal_brief">
|
||
<header class="wb-block__header">
|
||
<div class="wb-block__title-wrap">
|
||
<span class="material-symbols-rounded wb-block__icon" aria-hidden="true">psychology_alt</span>
|
||
<h5 class="wb-block__title">${escapeWorkbenchHtml(title)}</h5>
|
||
</div>
|
||
</header>
|
||
<div class="wb-block__body">
|
||
${data.executive_assertion ? `<p class="wb-assertion">${escapeWorkbenchHtml(data.executive_assertion)}</p>` : ""}
|
||
${renderGroup(t("分母数学分解(恒等关系统计)", "Mathematical Decomposition"), "is-math", mathItems)}
|
||
${renderGroup(t("已核验事实与成因研判", "Verified Facts & Causal Drivers"), "is-fact", causalItems)}
|
||
${renderGroup(t("反证校验与结构韧性支点", "Counter-Evidence & Structural Levers"), "is-lever", leverItems)}
|
||
${unknownGaps.length ? `<div class="wb-causal-group">
|
||
<div class="wb-causal-group__tag is-gap">${escapeWorkbenchHtml(t("待核查边界与证据留白", "Unverified Boundaries & Open Gaps"))}</div>
|
||
<ul class="wb-causal-list wb-causal-list--gaps">
|
||
${unknownGaps.map((gap) => `<li>${escapeWorkbenchHtml(gap)}</li>`).join("")}
|
||
</ul>
|
||
</div>` : ""}
|
||
</div>
|
||
</section>`;
|
||
}
|
||
|
||
function renderImpactTopologyBlock(block) {
|
||
const data = block.data || {};
|
||
const isEn = getEarthLocale() === "en-US";
|
||
const title = isEn ? (block.title_en || block.title) : block.title;
|
||
|
||
if (data.topology_kind === "compute_hubs") {
|
||
const hubs = Array.isArray(data.hubs) ? data.hubs : [];
|
||
return `<section class="wb-block wb-block--topology" data-block-id="${escapeWorkbenchHtml(block.block_id)}" data-block-type="impact_topology">
|
||
<header class="wb-block__header">
|
||
<div class="wb-block__title-wrap">
|
||
<span class="material-symbols-rounded wb-block__icon" aria-hidden="true">hub</span>
|
||
<h5 class="wb-block__title">${escapeWorkbenchHtml(title)}</h5>
|
||
</div>
|
||
</header>
|
||
<div class="wb-block__body">
|
||
${data.network_layer_notice ? `<div class="wb-topology-notice">${escapeWorkbenchHtml(data.network_layer_notice)}</div>` : ""}
|
||
<div class="wb-hubs-grid">
|
||
${hubs
|
||
.map(
|
||
(h) => `<button type="button" class="wb-hub-chip" data-wb-focus-entity="${escapeWorkbenchHtml(h.id || "CN")}" title="${escapeWorkbenchHtml(h.name || "")}">
|
||
<span class="wb-hub-chip__name">${escapeWorkbenchHtml(h.name || h.id)}</span>
|
||
<span class="wb-hub-chip__meta">${escapeWorkbenchHtml(h.role || "")}${h.target_pue ? ` · PUE≤${escapeWorkbenchHtml(h.target_pue)}` : ""}</span>
|
||
</button>`,
|
||
)
|
||
.join("")}
|
||
</div>
|
||
</div>
|
||
</section>`;
|
||
}
|
||
|
||
if (data.topology_kind && data.topology_kind !== "bgp_incident") {
|
||
const metrics = Array.isArray(data.telemetry_metrics) ? data.telemetry_metrics : [];
|
||
const chips = Array.isArray(data.focus_chips) ? data.focus_chips : [];
|
||
const related = Array.isArray(data.related_entities) ? data.related_entities : [];
|
||
const statusLabels = {
|
||
telemetry_online: t("在线遥测", "Telemetry Online"),
|
||
standby_or_empty: t("空载 / 待命", "Standby / Empty"),
|
||
incident_active: t("活跃异动", "Active Alert"),
|
||
quiet: t("静默稳态", "Quiet"),
|
||
incomplete_snapshot: t("快照缺失", "Incomplete Snapshot"),
|
||
};
|
||
const statusText = statusLabels[data.status] || data.status;
|
||
return `<section class="wb-block wb-block--topology" data-block-id="${escapeWorkbenchHtml(block.block_id)}" data-block-type="impact_topology">
|
||
<header class="wb-block__header">
|
||
<div class="wb-block__title-wrap">
|
||
<span class="material-symbols-rounded wb-block__icon" aria-hidden="true">hub</span>
|
||
<h5 class="wb-block__title">${escapeWorkbenchHtml(title)}</h5>
|
||
</div>
|
||
${statusText ? `<span class="wb-kpi-pill">${escapeWorkbenchHtml(statusText)}</span>` : ""}
|
||
</header>
|
||
<div class="wb-block__body">
|
||
${data.network_layer_notice ? `<div class="wb-topology-notice">
|
||
<span class="material-symbols-rounded" aria-hidden="true">layers</span>
|
||
<span>${escapeWorkbenchHtml(data.network_layer_notice)}</span>
|
||
</div>` : ""}
|
||
${metrics.length ? `<div class="wb-topology-kv">
|
||
${metrics
|
||
.map(
|
||
(m) => `<div><span class="wb-topology-kv__k">${escapeWorkbenchHtml(m.label || "")}</span><span class="wb-topology-kv__v wb-tabular">${escapeWorkbenchHtml(m.value ?? "—")}</span></div>`,
|
||
)
|
||
.join("")}
|
||
</div>` : ""}
|
||
${chips.length ? `<div class="wb-hubs-grid">
|
||
${chips
|
||
.map(
|
||
(c) => `<button type="button" class="wb-hub-chip" data-wb-focus-entity="${escapeWorkbenchHtml(c.id || c.label || "")}" title="${escapeWorkbenchHtml(c.label || "")}">
|
||
<span class="wb-hub-chip__name">${escapeWorkbenchHtml(c.label || c.id || "")}</span>
|
||
${c.meta ? `<span class="wb-hub-chip__meta">${escapeWorkbenchHtml(c.meta)}</span>` : ""}
|
||
</button>`,
|
||
)
|
||
.join("")}
|
||
</div>` : (related.length ? `<div class="wb-hubs-grid">
|
||
${related
|
||
.map(
|
||
(ent) => `<button type="button" class="wb-hub-chip" data-wb-focus-entity="${escapeWorkbenchHtml(ent)}"><span class="wb-hub-chip__name">${escapeWorkbenchHtml(ent)}</span></button>`,
|
||
)
|
||
.join("")}
|
||
</div>` : "")}
|
||
</div>
|
||
</section>`;
|
||
}
|
||
|
||
const asns = Array.isArray(data.measured_asns) ? data.measured_asns : [];
|
||
const prefixes = Array.isArray(data.affected_prefixes) ? data.affected_prefixes : [];
|
||
const collectors = Array.isArray(data.collector_vantage_points) ? data.collector_vantage_points : [];
|
||
const cableClues = Array.isArray(data.candidate_proximity_cables) ? data.candidate_proximity_cables : [];
|
||
const timeline = Array.isArray(data.timeline) ? data.timeline : [];
|
||
|
||
const cableStatusText = data.physical_cable_state === "candidate_proximity_unconfirmed"
|
||
? t("候选邻近线索(未经独立海缆断纤/光功率告警证实)", "Candidate proximity clue (unconfirmed by optical telemetry)")
|
||
: t("未知(无独立海底光缆故障遥测,不排除亦不直接归咎物理断缆)", "Unknown (no independent subsea cable fault telemetry)");
|
||
|
||
return `<section class="wb-block wb-block--topology" data-block-id="${escapeWorkbenchHtml(block.block_id)}" data-block-type="impact_topology">
|
||
<header class="wb-block__header">
|
||
<div class="wb-block__title-wrap">
|
||
<span class="material-symbols-rounded wb-block__icon" aria-hidden="true">alt_route</span>
|
||
<h5 class="wb-block__title">${escapeWorkbenchHtml(title)}</h5>
|
||
</div>
|
||
<span class="wb-kpi-pill">${escapeWorkbenchHtml(data.severity || "info")} · ${escapeWorkbenchHtml(data.status || "observed")}</span>
|
||
</header>
|
||
<div class="wb-block__body">
|
||
<div class="wb-topology-notice wb-topology-notice--warn">
|
||
<span class="material-symbols-rounded" aria-hidden="true">layers</span>
|
||
<span>${escapeWorkbenchHtml(data.network_layer_notice || t("控制面逻辑 AS 路由传播关系 ≠ 海底物理光缆走向", "Logical AS routing propagation != physical subsea cable path"))}</span>
|
||
</div>
|
||
<div class="wb-topology-kv">
|
||
<div><span class="wb-topology-kv__k">${escapeWorkbenchHtml(t("涉事自治系统", "Measured ASNs"))}</span><span class="wb-topology-kv__v wb-tabular">${escapeWorkbenchHtml(asns.join(", ") || t("未记录", "None"))}</span></div>
|
||
<div><span class="wb-topology-kv__k">${escapeWorkbenchHtml(t("受波及前缀", "Affected Prefixes"))}</span><span class="wb-topology-kv__v wb-tabular">${escapeWorkbenchHtml(prefixes.join(", ") || t("未记录", "None"))}</span></div>
|
||
<div><span class="wb-topology-kv__k">${escapeWorkbenchHtml(t("观测采集点", "Route Collectors"))}</span><span class="wb-topology-kv__v wb-tabular">${escapeWorkbenchHtml(collectors.join(", ") || t("全局聚合", "Aggregated"))}</span></div>
|
||
<div><span class="wb-topology-kv__k">${escapeWorkbenchHtml(t("海底光缆物理状态", "Physical Cable State"))}</span><span class="wb-topology-kv__v is-caution">${escapeWorkbenchHtml(cableStatusText)}</span></div>
|
||
</div>
|
||
${cableClues.length ? `<div class="wb-cable-clues">
|
||
<span class="wb-cable-clues__label">${escapeWorkbenchHtml(t("邻近海缆候选线索:", "Proximity cable clues:"))}</span>
|
||
<ul>${cableClues.map((c) => `<li>${escapeWorkbenchHtml(c)}</li>`).join("")}</ul>
|
||
</div>` : ""}
|
||
${timeline.length ? `<div class="wb-timeline">
|
||
${timeline
|
||
.map(
|
||
(step) => `<div class="wb-timeline__item is-${escapeWorkbenchHtml(step.state || "pending")}">
|
||
<span class="wb-timeline__dot" aria-hidden="true"></span>
|
||
<span class="wb-timeline__label">${escapeWorkbenchHtml(step.label)}</span>
|
||
<span class="wb-timeline__ts wb-tabular">${escapeWorkbenchHtml(step.timestamp)}</span>
|
||
</div>`,
|
||
)
|
||
.join("")}
|
||
</div>` : ""}
|
||
</div>
|
||
</section>`;
|
||
}
|
||
|
||
function renderEvidenceDrawerBlock(block, { collapsedOverride } = {}) {
|
||
const data = block.data || {};
|
||
const isEn = getEarthLocale() === "en-US";
|
||
const title = isEn ? (block.title_en || block.title) : block.title;
|
||
const items = Array.isArray(data.items) ? data.items : [];
|
||
const withheld = Array.isArray(data.withheld_source_ids) ? data.withheld_source_ids : [];
|
||
const isCollapsed = collapsedOverride !== undefined ? collapsedOverride : Boolean(block.collapsed);
|
||
|
||
return `<section class="wb-block wb-block--evidence ${isCollapsed ? "is-collapsed" : ""}" data-block-id="${escapeWorkbenchHtml(block.block_id)}" data-block-type="evidence_drawer">
|
||
<header class="wb-block__header">
|
||
<div class="wb-block__title-wrap">
|
||
<span class="material-symbols-rounded wb-block__icon" aria-hidden="true">menu_book</span>
|
||
<h5 class="wb-block__title">${escapeWorkbenchHtml(title)}</h5>
|
||
${withheld.length ? `<span class="wb-withheld-tag" title="${escapeWorkbenchHtml(withheld.join(", "))}">${escapeWorkbenchHtml(t(`已隔离 ${withheld.length} 份事后来源`, `${withheld.length} post-cutoff withheld`))}</span>` : ""}
|
||
</div>
|
||
<button type="button" class="wb-mini-btn" data-wb-collapse-toggle="${escapeWorkbenchHtml(block.block_id)}" aria-expanded="${String(!isCollapsed)}" title="${escapeWorkbenchHtml(isCollapsed ? t("展开证据抽屉", "Expand evidence drawer") : t("收起证据抽屉", "Collapse evidence drawer"))}">
|
||
<span>${escapeWorkbenchHtml(isCollapsed ? t("展开", "Show") : t("收起", "Hide"))}</span>
|
||
<span class="material-symbols-rounded" aria-hidden="true">${isCollapsed ? "expand_more" : "expand_less"}</span>
|
||
</button>
|
||
</header>
|
||
${isCollapsed ? "" : `<div class="wb-block__body">
|
||
${items.length
|
||
? `<ul class="wb-evidence-list">
|
||
${items
|
||
.map((ev) => {
|
||
const safeUrl = /^https:\/\//i.test(ev.url || "") ? ev.url : "";
|
||
const metaParts = [ev.publisher, ev.published_at, ev.locator].filter(Boolean).join(" · ");
|
||
return `<li class="wb-evidence-item">
|
||
<div class="wb-evidence-item__top">
|
||
<span class="wb-code-tag">${escapeWorkbenchHtml(ev.evidence_id)}</span>
|
||
<strong class="wb-evidence-item__title">${escapeWorkbenchHtml(ev.title)}</strong>
|
||
${ev.sha256_prefix ? `<code class="wb-hash-tag" title="SHA-256">#${escapeWorkbenchHtml(ev.sha256_prefix.slice(0, 8))}</code>` : ""}
|
||
</div>
|
||
<div class="wb-evidence-item__meta">
|
||
<span>${escapeWorkbenchHtml(metaParts)}</span>
|
||
${safeUrl ? `<a class="copilot-source-card__link" href="${escapeWorkbenchHtml(safeUrl)}" target="_blank" rel="noopener noreferrer">${escapeWorkbenchHtml(t("原文", "Source"))} ↗</a>` : ""}
|
||
</div>
|
||
</li>`;
|
||
})
|
||
.join("")}
|
||
</ul>`
|
||
: `<p class="wb-empty-note">${escapeWorkbenchHtml(t("当前时间截点下暂无可展示的核验文献记录。", "No verified sources available within the selected cutoff."))}</p>`}
|
||
</div>`}
|
||
</section>`;
|
||
}
|
||
|
||
function renderExecutiveOnepagerBlock(block) {
|
||
const data = block.data || {};
|
||
const isEn = getEarthLocale() === "en-US";
|
||
const title = isEn ? (block.title_en || block.title) : block.title;
|
||
const metrics = Array.isArray(data.key_metrics) ? data.key_metrics : [];
|
||
const takeaways = Array.isArray(data.core_takeaways) ? data.core_takeaways : [];
|
||
const boundaries = Array.isArray(data.boundary_notes) ? data.boundary_notes : [];
|
||
|
||
return `<section class="wb-block wb-block--onepager" data-block-id="${escapeWorkbenchHtml(block.block_id)}" data-block-type="executive_onepager">
|
||
<header class="wb-block__header">
|
||
<div class="wb-block__title-wrap">
|
||
<span class="material-symbols-rounded wb-block__icon" aria-hidden="true">summarize</span>
|
||
<h5 class="wb-block__title">${escapeWorkbenchHtml(title)}</h5>
|
||
</div>
|
||
${data.revision_tag ? `<span class="wb-kpi-pill">${escapeWorkbenchHtml(data.revision_tag)}</span>` : ""}
|
||
</header>
|
||
<div class="wb-block__body wb-onepager">
|
||
<h4 class="wb-onepager__headline">${escapeWorkbenchHtml(data.headline || title)}</h4>
|
||
${data.scope_line ? `<div class="wb-onepager__scope">${escapeWorkbenchHtml(data.scope_line)}</div>` : ""}
|
||
${data.executive_assertion ? `<p class="wb-assertion">${escapeWorkbenchHtml(data.executive_assertion)}</p>` : ""}
|
||
${metrics.length ? `<div class="wb-onepager__metrics">
|
||
${metrics.map((m) => `<span class="wb-onepager__metric wb-tabular">${escapeWorkbenchHtml(m)}</span>`).join("")}
|
||
</div>` : ""}
|
||
${takeaways.length ? `<div class="wb-onepager__section">
|
||
<div class="wb-onepager__label">${escapeWorkbenchHtml(t("核心研判要点", "Core Takeaways"))}</div>
|
||
<ul class="wb-causal-list">${takeaways.map((tk) => `<li>${escapeWorkbenchHtml(tk)}</li>`).join("")}</ul>
|
||
</div>` : ""}
|
||
${boundaries.length ? `<div class="wb-onepager__section">
|
||
<div class="wb-onepager__label">${escapeWorkbenchHtml(t("口径边界与留白说明", "Scope & Boundary Notes"))}</div>
|
||
<ul class="wb-causal-list wb-causal-list--gaps">${boundaries.map((b) => `<li>${escapeWorkbenchHtml(b)}</li>`).join("")}</ul>
|
||
</div>` : ""}
|
||
</div>
|
||
</section>`;
|
||
}
|
||
|
||
export function renderWorkbenchBlock(block, options = {}) {
|
||
if (!block || !REGISTERED_WORKBENCH_BLOCKS.has(block.block_type)) {
|
||
return "";
|
||
}
|
||
switch (block.block_type) {
|
||
case "comparison_matrix":
|
||
return renderComparisonMatrixBlock(block, options);
|
||
case "trend_corridor":
|
||
return renderTrendCorridorBlock(block, options);
|
||
case "causal_brief":
|
||
return renderCausalBriefBlock(block, options);
|
||
case "impact_topology":
|
||
return renderImpactTopologyBlock(block, options);
|
||
case "evidence_drawer":
|
||
return renderEvidenceDrawerBlock(block, options);
|
||
case "executive_onepager":
|
||
return renderExecutiveOnepagerBlock(block, options);
|
||
default:
|
||
return "";
|
||
}
|
||
}
|
||
|
||
export function renderViewSpecWorkbench(viewSpec, {
|
||
turnId = "",
|
||
activeEvidenceId = null,
|
||
matrixModeOverride = null,
|
||
collapsedMap = {},
|
||
compact = false,
|
||
} = {}) {
|
||
if (!viewSpec || !Array.isArray(viewSpec.blocks) || viewSpec.blocks.length === 0) {
|
||
return "";
|
||
}
|
||
const isEn = getEarthLocale() === "en-US";
|
||
const presets = Array.isArray(viewSpec.available_presets) ? viewSpec.available_presets : [];
|
||
const activePreset = viewSpec.active_preset || "default";
|
||
|
||
const presetBar = !compact && presets.length
|
||
? `<div class="wb-preset-bar" role="tablist" aria-label="${escapeWorkbenchHtml(t("零 Token 视图投影切换", "Zero-token view presets"))}">
|
||
${presets
|
||
.map((p) => {
|
||
const isActive = p.id === activePreset;
|
||
const lbl = isEn ? (p.label_en || p.label) : p.label;
|
||
return `<button type="button" role="tab" aria-selected="${String(isActive)}" class="wb-preset-chip ${isActive ? "is-active" : ""}" data-wb-preset="${escapeWorkbenchHtml(p.id)}" data-turn-id="${escapeWorkbenchHtml(turnId)}">${escapeWorkbenchHtml(lbl)}</button>`;
|
||
})
|
||
.join("")}
|
||
</div>`
|
||
: "";
|
||
|
||
const blocksHtml = viewSpec.blocks
|
||
.map((blk) =>
|
||
renderWorkbenchBlock(blk, {
|
||
turnId,
|
||
activeEvidenceId,
|
||
matrixModeOverride: blk.block_type === "comparison_matrix" ? matrixModeOverride : null,
|
||
collapsedOverride: Object.prototype.hasOwnProperty.call(collapsedMap, blk.block_id)
|
||
? collapsedMap[blk.block_id]
|
||
: undefined,
|
||
}),
|
||
)
|
||
.join("");
|
||
|
||
return `<div class="wb-surface ${compact ? "wb-surface--compact" : ""}" data-view-id="${escapeWorkbenchHtml(viewSpec.view_id || "")}">
|
||
${viewSpec.is_drill ? `<div class="wb-drill-banner"><span class="material-symbols-rounded" aria-hidden="true">science</span><span>${escapeWorkbenchHtml(t("[演练档案] 历史教学复盘样板 · 与实时运行态严格隔离", "[Drill Archive] Historical replay sample · Isolated from live telemetry"))}</span></div>` : ""}
|
||
${viewSpec.replay_supported === false ? `<div class="wb-replay-warning-banner" role="note"><span class="material-symbols-rounded" aria-hidden="true">warning</span><span>${escapeWorkbenchHtml(viewSpec.replay_notice || t("不支持完整重放:当前历史记录缺少冻结数据快照,仅保留原始文字结论。", "Full replay unsupported: historical data snapshot missing; narrative preserved only."))}</span></div>` : ""}
|
||
${presetBar}
|
||
<div class="wb-blocks">${blocksHtml}</div>
|
||
</div>`;
|
||
}
|