dknowc-dsh 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/skills/dknowc-official-doc-writer/README.md +15 -38
- package/skills/dknowc-official-doc-writer/SKILL.md +111 -218
- package/skills/dknowc-official-doc-writer/reference/local_memory_guide.md +53 -0
- package/skills/dknowc-official-doc-writer/reference/material_usage_guidance.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/onboarding_scripts.md +132 -0
- package/skills/dknowc-official-doc-writer/reference/output_guide.md +4 -4
- package/skills/dknowc-official-doc-writer/reference/review_checklist.md +16 -16
- package/skills/dknowc-official-doc-writer/reference/revision_workflow.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/sample_search_result.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/sample_trace_report.html +226 -76
- package/skills/dknowc-official-doc-writer/reference/search_guide.md +35 -32
- package/skills/dknowc-official-doc-writer/reference/search_intro.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/search_policy.md +12 -12
- package/skills/dknowc-official-doc-writer/reference/standards/01_report.md +3 -2
- package/skills/dknowc-official-doc-writer/reference/standards/02_qingshi.md +3 -2
- package/skills/dknowc-official-doc-writer/reference/standards/03_pifu.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/04_tongzhi.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/standards/05_yijian.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/06_han.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/standards/08_tongbao.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/09_tonggao.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/10_gonggao.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/11_fuhan_approve.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/12_fuhan_objection.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/13_reminder.md +3 -3
- package/skills/dknowc-official-doc-writer/reference/standards/14_generic.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/16_decision.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/18_order.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/19_gazette.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/standards/20_motion.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/22_application.md +2 -2
- package/skills/dknowc-official-doc-writer/reference/standards/23_publicity.md +1 -1
- package/skills/dknowc-official-doc-writer/reference/task_router.md +10 -10
- package/skills/dknowc-official-doc-writer/scripts/api_key.py +41 -0
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +31 -6
- package/skills/dknowc-official-doc-writer/scripts/format_document.py +30 -26
- package/skills/dknowc-official-doc-writer/scripts/initialize.py +48 -18
- package/skills/dknowc-official-doc-writer/scripts/local_memory.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/mcp_direct.py +8 -0
- package/skills/dknowc-official-doc-writer/scripts/merge_search_results.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/outline_reference.py +7 -11
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +49 -8
- package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +220 -125
- package/skills/dknowc-official-doc-writer/scripts/review_document.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +34 -44
- package/skills/dknowc-official-doc-writer/scripts/template_generator.py +3 -3
- package/skills/dknowc-ppt-assistant/README.md +4 -4
- package/skills/dknowc-ppt-assistant/SKILL.md +16 -20
- package/skills/dknowc-ppt-assistant/references/content-pack.md +3 -3
- package/skills/dknowc-ppt-assistant/references/material_usage.md +9 -6
- package/skills/dknowc-ppt-assistant/references/onboarding_scripts.md +120 -0
- package/skills/dknowc-ppt-assistant/references/sample_search_result.md +1 -1
- package/skills/dknowc-ppt-assistant/references/sample_trace_report.html +500 -0
- package/skills/dknowc-ppt-assistant/references/search_intro.md +1 -1
- package/skills/dknowc-ppt-assistant/scripts/api_key.py +41 -0
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +54 -13
- package/skills/dknowc-ppt-assistant/scripts/mcp_direct.py +8 -0
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +56 -9
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +260 -118
- package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +65 -15
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +8 -8
- package/skills/dknowc-ppt-assistant/workflows/routing.md +1 -1
- package/skills/dknowc-trusted-consulting/README.md +8 -9
- package/skills/dknowc-trusted-consulting/SKILL.md +47 -32
- package/skills/dknowc-trusted-consulting/reference/consult_intro.md +3 -35
- package/skills/dknowc-trusted-consulting/reference/onboarding_scripts.md +132 -0
- package/skills/dknowc-trusted-consulting/reference/sample_trace_report.html +105 -60
- package/skills/dknowc-trusted-consulting/scripts/api_key.py +41 -0
- package/skills/dknowc-trusted-consulting/scripts/gov_chat.py +39 -19
- package/skills/dknowc-trusted-consulting/scripts/initialize.py +64 -20
- package/skills/dknowc-trusted-consulting/scripts/mcp_direct.py +8 -0
- package/skills/dknowc-trusted-consulting/scripts/register_key.mjs +120 -21
- package/skills/dknowc-trusted-consulting/scripts/render_trace_html.py +165 -161
- package/skills/dknowc-trusted-search/README.md +1 -1
- package/skills/dknowc-trusted-search/SKILL.md +32 -33
- package/skills/dknowc-trusted-search/reference/onboarding_scripts.md +132 -0
- package/skills/dknowc-trusted-search/reference/sample_trace_report.html +108 -52
- package/skills/dknowc-trusted-search/scripts/api_key.py +41 -0
- package/skills/dknowc-trusted-search/scripts/deep_query.py +81 -9
- package/skills/dknowc-trusted-search/scripts/initialize.py +65 -17
- package/skills/dknowc-trusted-search/scripts/mcp_direct.py +8 -0
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +111 -24
- package/skills/dknowc-trusted-search/scripts/render_policy_visualization.py +2 -3
- package/skills/dknowc-trusted-search/scripts/render_trace_html.py +298 -226
- package/skills/dknowc-trusted-search/scripts/trusted_search.py +80 -11
- package/src/index.js +3 -3
- package/skills/dknowc-official-doc-writer/official-docs/input/mcp_intro_content.md +0 -61
- package/skills/dknowc-trusted-search/reference/search_intro.md +0 -79
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
2
|
+
"""溯源核验报告渲染器:把可信搜索/深度搜索结果 JSON + 最终答案渲染为单文件可核验 HTML。
|
|
3
3
|
|
|
4
4
|
报告定位:不止展示"材料从哪来"(溯源),更要传达"我们查过了,可以交付"(核验)。
|
|
5
5
|
三个核验层次:
|
|
6
|
-
- 报告级:核验报告单(依据溯源 /
|
|
6
|
+
- 报告级:核验报告单(依据溯源 / 引用对应 / 材料新旧 / 材料构成 / 交付前检查)
|
|
7
7
|
- 材料级:每条来源卡核验链标记(摘录可比对 + 原文可打开 + 知识专库可回溯)
|
|
8
8
|
- 引用级:正文角标与来源卡一一绑定,未绑定角标红色警示
|
|
9
9
|
|
|
10
10
|
诚实原则:脚本真实计算的结果才打勾;政策现行效力等无法自动判定项归入
|
|
11
11
|
"建议人工复核";self_check 未传入时显示"未记录",不假装通过。
|
|
12
|
+
核验单只考核被答案引用的材料;引用材料缺原文链接但知识专库可回看时视为可回看(温和提示)。
|
|
12
13
|
|
|
13
14
|
输入:trusted_search.py / deep_query.py 的 --json-only 输出(official-docs/search-results/)
|
|
14
15
|
+ --answer-file 最终答案(关键结论带 [1][2] 角标);可选 --self-check-file 传入答案自检结果。
|
|
15
|
-
布局:深色顶栏 +
|
|
16
|
-
|
|
16
|
+
布局:深色顶栏 + 报告身份章 + 左栏答案分节卡片 + 右栏核验材料面板(检索分组筛选/搜索);
|
|
17
|
+
原文原段身份标注与超行折叠、标题链、高可信徽标、未引用召回分组、
|
|
18
|
+
打印归档模式、移动端"正文表述↔原文原段"对照弹层。
|
|
17
19
|
"""
|
|
18
20
|
|
|
19
21
|
from __future__ import annotations
|
|
@@ -29,10 +31,12 @@ from typing import Any, Dict, List, Optional, Tuple
|
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
32
|
-
#
|
|
34
|
+
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
33
35
|
import os as _os
|
|
34
36
|
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
35
37
|
if not _ws:
|
|
38
|
+
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<DSH_SESSION_ID前8位>/,
|
|
39
|
+
# 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
|
|
36
40
|
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
37
41
|
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
38
42
|
WS_ROOT = Path(_ws).resolve()
|
|
@@ -224,8 +228,9 @@ def content_segments(item: Dict[str, Any]) -> List[Dict[str, str]]:
|
|
|
224
228
|
def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict[str, str]] = None) -> Dict[str, str]:
|
|
225
229
|
vo = item.get("vo") if isinstance(item.get("vo"), dict) else {}
|
|
226
230
|
segment = segment or {}
|
|
231
|
+
# segment 的 id 是文章内段落序号(每篇各自从 1 起),不是材料角标号,不得用作材料 id,
|
|
232
|
+
# 否则多篇材料的段落 id 同为 "1" 会互相冲突,导致角标绑定错乱。
|
|
227
233
|
explicit_id = first_str(
|
|
228
|
-
segment.get("id"),
|
|
229
234
|
item.get("角标"),
|
|
230
235
|
item.get("编号"),
|
|
231
236
|
item.get("index"),
|
|
@@ -268,11 +273,33 @@ def source_from_article(item: Dict[str, Any], index: int, segment: Optional[Dict
|
|
|
268
273
|
"url": first_str(item.get("sourceUrl"), item.get("source_url"), item.get("源网址"), item.get("原文链接"), item.get("url"), item.get("原文"), vo.get("sourceUrl"), vo.get("url")),
|
|
269
274
|
"policy_url": first_str(item.get("policyUrl"), item.get("policy_url"), item.get("知识专库原文"), vo.get("policyUrl")),
|
|
270
275
|
"excerpt": segment.get("text") or paragraph_text(item),
|
|
271
|
-
"section": first_str(
|
|
276
|
+
"section": first_str(item.get("正文对应"), item.get("section"), item.get("支撑")),
|
|
272
277
|
"kind": first_str(item.get("类型"), item.get("type"), item.get("素材类型"), vo.get("typeName"), "材料"),
|
|
273
278
|
"verify_note": first_str(item.get("核验"), item.get("verification"), item.get("核验说明")),
|
|
274
279
|
"area": first_str(item.get("intentionArea"), item.get("area"), item.get("地域")),
|
|
275
280
|
}
|
|
281
|
+
# 原文位置标题链:接口返回的段落标题即该段在原文件中的章节位置(自带层级,以 > 分隔),
|
|
282
|
+
# 统一转为 › 展示;悬停 title 提供含文章标题的完整链。段落标题与文章标题相同时只留一级。
|
|
283
|
+
# 一篇材料多段时取首个非空段落标题作位置(材料一篇一卡,不按段落拆卡,防止角标错位)。
|
|
284
|
+
seg_title = ""
|
|
285
|
+
for seg in content_segments(item):
|
|
286
|
+
if first_str(seg.get("title")):
|
|
287
|
+
seg_title = first_str(seg.get("title"))
|
|
288
|
+
break
|
|
289
|
+
seg_title = re.sub(r"\s*>\s*", " › ", seg_title).strip("› ").strip()
|
|
290
|
+
if seg_title and seg_title != source["title"]:
|
|
291
|
+
source["doc_section"] = seg_title
|
|
292
|
+
source["chain_full"] = f"{source['title']} › {seg_title}"
|
|
293
|
+
else:
|
|
294
|
+
source["doc_section"] = ""
|
|
295
|
+
source["chain_full"] = ""
|
|
296
|
+
# 所属搜索条件(多路检索分组)与引用状态(未引用=接口召回但正文未采用)
|
|
297
|
+
source["search_key"] = first_str(item.get("搜索条件"), item.get("search_key"))
|
|
298
|
+
source["used"] = item.get("已引用", item.get("used", True))
|
|
299
|
+
if not isinstance(source["used"], bool):
|
|
300
|
+
source["used"] = True
|
|
301
|
+
# 发布日期可信度(实测:「高」=模型治理入库、标题模型精抽;「较高」=门户抓取、标题规则提取)
|
|
302
|
+
source["conf"] = first_str(item.get("发布日期可信度"), item.get("可信度"), item.get("confidence"))
|
|
276
303
|
key, label, css = normalize_kind(source["kind"])
|
|
277
304
|
source["type_key"] = key
|
|
278
305
|
source["type_label"] = label
|
|
@@ -291,7 +318,10 @@ def extract_articles_from_search(payload: Dict[str, Any]) -> List[Dict[str, Any]
|
|
|
291
318
|
|
|
292
319
|
|
|
293
320
|
def extract_articles_from_deep(payload: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
294
|
-
"""深度搜索 deep-query/v3 非流式格式:{"data": {"searches": [{"result": [...]}], "common_articles": [...]}}。
|
|
321
|
+
"""深度搜索 deep-query/v3 非流式格式:{"data": {"searches": [{"result": [...]}], "common_articles": [...]}}。
|
|
322
|
+
|
|
323
|
+
按源网址去重摊平;为每篇材料注入"搜索条件"(子查询的地域·查询词),供材料面板检索分组筛选。
|
|
324
|
+
"""
|
|
295
325
|
data = payload.get("data")
|
|
296
326
|
if not isinstance(data, dict):
|
|
297
327
|
return []
|
|
@@ -301,7 +331,7 @@ def extract_articles_from_deep(payload: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
|
301
331
|
seen: set = set()
|
|
302
332
|
out: List[Dict[str, Any]] = []
|
|
303
333
|
|
|
304
|
-
def _add(article: Any) -> None:
|
|
334
|
+
def _add(article: Any, search_key: str) -> None:
|
|
305
335
|
if not isinstance(article, dict):
|
|
306
336
|
return
|
|
307
337
|
key = str(article.get("源网址") or article.get("文章标题") or "")
|
|
@@ -309,14 +339,20 @@ def extract_articles_from_deep(payload: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
|
309
339
|
return
|
|
310
340
|
if key:
|
|
311
341
|
seen.add(key)
|
|
342
|
+
if search_key and not article.get("搜索条件"):
|
|
343
|
+
article["搜索条件"] = search_key
|
|
312
344
|
out.append(article)
|
|
313
345
|
|
|
314
346
|
for search in searches:
|
|
315
|
-
if isinstance(search, dict):
|
|
316
|
-
|
|
317
|
-
|
|
347
|
+
if not isinstance(search, dict):
|
|
348
|
+
continue
|
|
349
|
+
areas = "、".join(str(a) for a in (search.get("areas") or []))
|
|
350
|
+
query = str(search.get("query") or "").strip()
|
|
351
|
+
label = f"{areas}·{query[:14]}" if areas else query[:18]
|
|
352
|
+
for article in search.get("result") or []:
|
|
353
|
+
_add(article, label)
|
|
318
354
|
for article in data.get("common_articles") or []:
|
|
319
|
-
_add(article)
|
|
355
|
+
_add(article, "")
|
|
320
356
|
return out
|
|
321
357
|
|
|
322
358
|
|
|
@@ -335,26 +371,17 @@ def extract_sources(payload: Dict[str, Any]) -> List[Dict[str, str]]:
|
|
|
335
371
|
|
|
336
372
|
sources: List[Dict[str, str]] = []
|
|
337
373
|
seen = set()
|
|
338
|
-
used_ids = set()
|
|
339
|
-
next_seq = 1
|
|
340
374
|
for item in raw_sources:
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
if not source["id"] or source["id"] in used_ids:
|
|
352
|
-
while str(next_seq) in used_ids:
|
|
353
|
-
next_seq += 1
|
|
354
|
-
source["id"] = str(next_seq)
|
|
355
|
-
used_ids.add(source["id"])
|
|
356
|
-
next_seq = max(next_seq, int(source["id"]) if source["id"].isdigit() else next_seq) + 1
|
|
357
|
-
sources.append(source)
|
|
375
|
+
# 一篇材料一张卡:段落合并为摘录(paragraph_text 拼接全部段落),不按段落拆卡——
|
|
376
|
+
# 溯源 JSON 的 materials 与正文角标按"材料"粒度一一对应,拆段会使编号错位。
|
|
377
|
+
source = source_from_article(item, len(sources) + 1)
|
|
378
|
+
key = (source["id"], source["title"], source["url"], source["excerpt"][:80])
|
|
379
|
+
if key in seen:
|
|
380
|
+
continue
|
|
381
|
+
seen.add(key)
|
|
382
|
+
if not source["id"]:
|
|
383
|
+
source["id"] = str(len(sources) + 1)
|
|
384
|
+
sources.append(source)
|
|
358
385
|
return sources
|
|
359
386
|
|
|
360
387
|
|
|
@@ -449,7 +476,6 @@ SELF_CHECK_LABELS.update({
|
|
|
449
476
|
"事实有据": "事实有据", "角标绑定": "角标绑定", "答案一致": "答案一致",
|
|
450
477
|
"时效确认": "时效确认", "无未核验断言": "无未核验断言",
|
|
451
478
|
})
|
|
452
|
-
SELF_CHECK_SUMMARY = "/".join(label for _, label in SELF_CHECK_ITEMS)
|
|
453
479
|
|
|
454
480
|
|
|
455
481
|
def classify_check_value(raw: Any) -> Tuple[str, str]:
|
|
@@ -483,28 +509,22 @@ def normalize_self_check(raw: Any) -> Optional[Dict[str, Tuple[str, str]]]:
|
|
|
483
509
|
|
|
484
510
|
def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Dict[str, Any],
|
|
485
511
|
generated_at: Optional[datetime] = None) -> Dict[str, Any]:
|
|
486
|
-
"""核验报告单数据。只计算脚本真实可得的结果,不虚构通过。
|
|
487
|
-
|
|
488
|
-
依据溯源只考核**被答案引用**的素材:未引用素材属备查信息,缺链接不影响核验结论;
|
|
489
|
-
引用素材缺原文链接但知识专库可回看时视为可回看(温和提示,不判失败)。
|
|
490
|
-
"""
|
|
512
|
+
"""核验报告单数据。只计算脚本真实可得的结果,不虚构通过。"""
|
|
491
513
|
generated_at = generated_at or datetime.now()
|
|
492
514
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
kb_view = bool(
|
|
499
|
-
|
|
500
|
-
# ① 依据溯源(仅考核被引用素材):摘录可比对 + 原文链接可打开;缺链但知识专库可回看视为可回看
|
|
515
|
+
# ① 依据溯源:摘录可比对 + 原文链接/知识专库可回看。
|
|
516
|
+
# 只统计被正文引用的材料——未引用召回材料未进入正文核验流程,其缺链在自身卡片上如实标注,
|
|
517
|
+
# 不应拖累"正文依据可交付"的报告级结论。
|
|
518
|
+
# 被引用材料缺原文链接但知识专库可回看时视为可回看(温和提示,不判失败)。
|
|
519
|
+
cited_sources = [s for s in sources if s.get("used", True)]
|
|
520
|
+
kb_view = bool(extract_knowledge_bases(payload))
|
|
501
521
|
missing_links = [s["title"] for s in cited_sources if not s.get("has_link") and not kb_view]
|
|
502
522
|
missing_excerpts = [s["title"] for s in cited_sources if not (s.get("excerpt") or "").strip()]
|
|
503
523
|
kb_only = sum(1 for s in cited_sources if not s.get("has_link") and kb_view)
|
|
504
|
-
|
|
505
|
-
trace_passed = trace_total - len(set(missing_links) | set(missing_excerpts))
|
|
524
|
+
trace_passed = len(cited_sources) - len(set(missing_links) | set(missing_excerpts))
|
|
506
525
|
|
|
507
526
|
# ② 引用绑定:正文角标与来源卡一一对应(按角标出现次数计,与用户在正文中数到的一致)
|
|
527
|
+
cited = citation_ids(answer)
|
|
508
528
|
all_marks = re.findall(r"\[(\d+)\]", answer)
|
|
509
529
|
source_ids = {s["id"] for s in sources}
|
|
510
530
|
unbound_ids = [cid for cid in cited if cid not in source_ids]
|
|
@@ -528,7 +548,7 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
528
548
|
for s in sources:
|
|
529
549
|
coverage[s.get("type_key", "material")] = coverage.get(s.get("type_key", "material"), 0) + 1
|
|
530
550
|
|
|
531
|
-
# ⑤
|
|
551
|
+
# ⑤ 成稿自检:由溯源 JSON 的 self_check 传入,未传入如实显示未记录
|
|
532
552
|
self_check_raw = None
|
|
533
553
|
for holder in (payload, payload.get("content") if isinstance(payload.get("content"), dict) else {}):
|
|
534
554
|
self_check_raw = self_check_raw or holder.get("selfCheck") or holder.get("self_check")
|
|
@@ -544,30 +564,29 @@ def compute_verification(answer: str, sources: List[Dict[str, str]], payload: Di
|
|
|
544
564
|
# 政策效力:无法自动判定现行效力,列出建议人工复核
|
|
545
565
|
policy_count = coverage.get("policy", 0)
|
|
546
566
|
|
|
547
|
-
trace_ok =
|
|
567
|
+
trace_ok = cited_sources and trace_passed == len(cited_sources)
|
|
548
568
|
binding_ok = (not unbound) and not no_citation
|
|
549
569
|
overall_passed = trace_ok and binding_ok
|
|
550
570
|
|
|
551
571
|
reasons = []
|
|
552
|
-
if not
|
|
553
|
-
reasons.append("
|
|
572
|
+
if not sources:
|
|
573
|
+
reasons.append("没有找到来源材料")
|
|
554
574
|
if no_citation:
|
|
555
|
-
reasons.append("
|
|
575
|
+
reasons.append("正文里没有来源角标,对不上材料")
|
|
556
576
|
if missing_links:
|
|
557
|
-
reasons.append(f"{len(missing_links)}
|
|
577
|
+
reasons.append(f"{len(missing_links)} 条引用材料暂缺原文链接(可先交付、建议后续补链)")
|
|
558
578
|
if unbound:
|
|
559
|
-
reasons.append(f"{len(unbound)}
|
|
579
|
+
reasons.append(f"有 {len(unbound)} 处角标找不到对应材料")
|
|
560
580
|
if self_check["status"] == "fail":
|
|
561
|
-
reasons.append("
|
|
581
|
+
reasons.append("交付前检查有没过的项")
|
|
562
582
|
|
|
563
583
|
return {
|
|
564
584
|
"overall": {
|
|
565
585
|
"passed": overall_passed,
|
|
566
|
-
"label": "
|
|
586
|
+
"label": "核验完成,正文依据逐条对过原文" if overall_passed else "核验未完全通过",
|
|
567
587
|
"reasons": reasons,
|
|
568
588
|
},
|
|
569
|
-
"traceability": {"total":
|
|
570
|
-
"uncited_total": len(uncited_sources), "kb_only": kb_only,
|
|
589
|
+
"traceability": {"total": len(cited_sources), "passed": trace_passed, "kb_only": kb_only,
|
|
571
590
|
"missing_links": missing_links, "missing_excerpts": missing_excerpts},
|
|
572
591
|
"binding": {"total": len(all_marks), "bound": len(all_marks) - len(unbound), "unbound": unbound_ids, "no_citation": no_citation},
|
|
573
592
|
"freshness": freshness,
|
|
@@ -785,64 +804,65 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
785
804
|
tr = v["traceability"]
|
|
786
805
|
if not tr["total"]:
|
|
787
806
|
tr_html = ('<div class="vi"><span class="s fail">✗ 依据溯源 0/0</span>'
|
|
788
|
-
'<span class="d"
|
|
807
|
+
'<span class="d">未识别到来源材料</span></div>')
|
|
789
808
|
elif tr["passed"] == tr["total"]:
|
|
790
809
|
kb_note = f",其中 {tr.get('kb_only', 0)} 条经知识专库回看" if tr.get("kb_only") else ""
|
|
791
810
|
tr_html = (f'<div class="vi"><span class="s ok">✓ 依据溯源 {tr["passed"]}/{tr["total"]}</span>'
|
|
792
|
-
f'<span class="d"
|
|
811
|
+
f'<span class="d">每条引用材料可回看原文{esc(kb_note)}</span></div>')
|
|
793
812
|
else:
|
|
794
813
|
tr_html = (f'<div class="vi"><span class="s warn">◐ 依据溯源 {tr["passed"]}/{tr["total"]}</span>'
|
|
795
|
-
f'<span class="d">{tr["total"] - tr["passed"]}
|
|
814
|
+
f'<span class="d">{tr["total"] - tr["passed"]} 条引用材料暂缺原文链接,可先交付、建议后续补链</span></div>')
|
|
796
815
|
|
|
797
816
|
bd = v["binding"]
|
|
798
817
|
if bd.get("no_citation"):
|
|
799
|
-
bd_html = (f'<div class="vi"><span class="s fail">✗
|
|
800
|
-
f'<span class="d"
|
|
818
|
+
bd_html = (f'<div class="vi"><span class="s fail">✗ 引用对应 0/0</span>'
|
|
819
|
+
f'<span class="d">正文里没有来源角标,{v["traceability"]["total"]} 条材料对不上正文</span></div>')
|
|
801
820
|
elif not bd["total"]:
|
|
802
|
-
bd_html = '<div class="vi"><span class="s none">—
|
|
821
|
+
bd_html = '<div class="vi"><span class="s none">— 引用对应 0/0</span><span class="d">正文里没有来源角标</span></div>'
|
|
803
822
|
elif not bd["unbound"]:
|
|
804
|
-
bd_html = (f'<div class="vi"><span class="s ok">✓
|
|
805
|
-
f'<span class="d"
|
|
823
|
+
bd_html = (f'<div class="vi"><span class="s ok">✓ 引用对应 {bd["bound"]}/{bd["total"]}</span>'
|
|
824
|
+
f'<span class="d">正文每处 [n] 都能找到对应材料</span></div>')
|
|
806
825
|
else:
|
|
807
826
|
unbound_text = "、".join(f"[{esc(x)}]" for x in bd["unbound"][:8])
|
|
808
|
-
bd_html = (f'<div class="vi"><span class="s fail">✗
|
|
809
|
-
f'<span class="d"
|
|
827
|
+
bd_html = (f'<div class="vi"><span class="s fail">✗ 引用对应 {bd["bound"]}/{bd["total"]}</span>'
|
|
828
|
+
f'<span class="d">对不上的角标 {unbound_text}</span></div>')
|
|
810
829
|
|
|
811
830
|
fr = v["freshness"]
|
|
812
831
|
if fr:
|
|
813
832
|
rng = f"{fr['min'][0]}-{fr['min'][1]:02d}~{fr['max'][0]}-{fr['max'][1]:02d}"
|
|
814
|
-
old = f"({fr['old_count']}
|
|
815
|
-
fr_html = f'<div class="vi"><span class="s ok">✓
|
|
833
|
+
old = f"({fr['old_count']} 条年头较久,按参考口径使用)" if fr["old_count"] else ""
|
|
834
|
+
fr_html = f'<div class="vi"><span class="s ok">✓ 材料新旧 已核</span><span class="d">材料日期 {esc(rng)}{esc(old)}</span></div>'
|
|
816
835
|
else:
|
|
817
|
-
fr_html = '<div class="vi"><span class="s none">—
|
|
836
|
+
fr_html = '<div class="vi"><span class="s none">— 材料新旧 未记录</span><span class="d">材料没标发布日期</span></div>'
|
|
818
837
|
|
|
819
838
|
cov = v["coverage"]
|
|
820
839
|
parts = [f"{KIND_CATALOG[k][0]} {cov[k]}" for k in ("policy", "data", "case", "reference") if cov.get(k)]
|
|
821
840
|
cov_state = "ok" if cov.get("policy") or cov.get("data") or cov.get("case") else "none"
|
|
822
|
-
cov_html = (f'<div class="vi"><span class="s {cov_state}">{"✓" if cov_state == "ok" else "—"}
|
|
823
|
-
f'<span class="d">{esc(" · ".join(parts)) if parts else "
|
|
841
|
+
cov_html = (f'<div class="vi"><span class="s {cov_state}">{"✓" if cov_state == "ok" else "—"} 材料构成</span>'
|
|
842
|
+
f'<span class="d">{esc(" · ".join(parts)) if parts else "材料没标类型"}</span></div>')
|
|
824
843
|
|
|
825
844
|
sc = v["self_check"]
|
|
826
845
|
if sc["status"] == "pass":
|
|
827
846
|
notes = ";".join(note for _, note in sc["items"].values() if note)
|
|
828
847
|
title_attr = f' title="{esc(notes)}"' if notes else ""
|
|
829
|
-
|
|
830
|
-
|
|
848
|
+
item_names = "、".join(sc["items"].keys()) if sc["items"] else "、".join(label for _, label in SELF_CHECK_ITEMS)
|
|
849
|
+
sc_html = (f'<div class="vi"><span class="s ok"{title_attr}>✓ 交付前检查 {sc["passed"]}/{sc["total"]}</span>'
|
|
850
|
+
f'<span class="d">{esc(item_names)}{esc(" · 悬停查看说明" if notes else "")}</span></div>')
|
|
831
851
|
elif sc["status"] == "fail":
|
|
832
852
|
failed_parts = []
|
|
833
853
|
for label, (status, note) in sc["items"].items():
|
|
834
854
|
if status != "pass":
|
|
835
855
|
suffix = f"({note[:40]}…)" if len(note) > 40 else (f"({note})" if note else "")
|
|
836
856
|
failed_parts.append(label + suffix)
|
|
837
|
-
sc_html = (f'<div class="vi"><span class="s fail">✗
|
|
838
|
-
f'<span class="d"
|
|
857
|
+
sc_html = (f'<div class="vi"><span class="s fail">✗ 交付前检查 {sc["passed"]}/{sc["total"]}</span>'
|
|
858
|
+
f'<span class="d">没过的项:{esc("、".join(failed_parts))}</span></div>')
|
|
839
859
|
else:
|
|
840
|
-
sc_html = '<div class="vi"><span class="s none">—
|
|
860
|
+
sc_html = '<div class="vi"><span class="s none">— 交付前检查 未记录</span><span class="d">本次溯源 JSON 没写入检查结果</span></div>'
|
|
841
861
|
|
|
842
862
|
manual = ""
|
|
843
863
|
if v["policy_count"]:
|
|
844
|
-
manual = (f'<div class="vi"><span class="s man">◐
|
|
845
|
-
f'<span class="d">{v["policy_count"]}
|
|
864
|
+
manual = (f'<div class="vi"><span class="s man">◐ 现行效力</span>'
|
|
865
|
+
f'<span class="d">{v["policy_count"]} 份政策文件建议按官方发布确认是否现行有效</span></div>')
|
|
846
866
|
|
|
847
867
|
return f"""
|
|
848
868
|
<div class="verify {state}">
|
|
@@ -851,7 +871,7 @@ def render_verify_panel(v: Dict[str, Any]) -> str:
|
|
|
851
871
|
<div class="v-grid">
|
|
852
872
|
{tr_html}{bd_html}{fr_html}{cov_html}{sc_html}{manual}
|
|
853
873
|
</div>
|
|
854
|
-
<div class="v-note"
|
|
874
|
+
<div class="v-note">核验方式:先用深知可信搜索找权威来源,再把正文每处依据和原文逐条比对(都能点开原文回看),最后做了交付前五项检查。政策是否现行有效,以官方发布为准。{manual_checks_html}</div>
|
|
855
875
|
</div>"""
|
|
856
876
|
|
|
857
877
|
|
|
@@ -893,142 +913,104 @@ def render_section_cards(sections: List[Dict[str, Any]], sources: List[Dict[str,
|
|
|
893
913
|
return "\n".join(cards)
|
|
894
914
|
|
|
895
915
|
|
|
896
|
-
def renumber_citations(answer: str, sources: List[Dict[str, str]]) -> Tuple[str, List[Dict[str, str]]]:
|
|
897
|
-
"""把答案角标按首次出现顺序重排为 [1][2][3]…,来源卡同步重编号。
|
|
898
|
-
|
|
899
|
-
被引用的来源按新编号排在前面(编号与正文角标一一对应);
|
|
900
|
-
未引用来源移入"未引用素材"备查组,不占角标编号(锚点用独立 panel_id)。
|
|
901
|
-
"""
|
|
902
|
-
cited_order = citation_ids(answer)
|
|
903
|
-
if not cited_order:
|
|
904
|
-
for s in sources:
|
|
905
|
-
s.setdefault("cited", False)
|
|
906
|
-
s.setdefault("panel_id", s["id"])
|
|
907
|
-
return answer, sources
|
|
908
|
-
mapping = {old: str(new) for new, old in enumerate(cited_order, start=1)}
|
|
909
|
-
answer = re.sub(r"\[(\d+)\]", lambda m: "[" + mapping.get(m.group(1), m.group(1)) + "]", answer)
|
|
910
|
-
by_old: Dict[str, Dict[str, str]] = {}
|
|
911
|
-
for s in sources:
|
|
912
|
-
by_old.setdefault(s["id"], s)
|
|
913
|
-
cited_sorted: List[Dict[str, str]] = []
|
|
914
|
-
for old in cited_order:
|
|
915
|
-
s = by_old.get(old)
|
|
916
|
-
if s is None:
|
|
917
|
-
continue
|
|
918
|
-
s2 = dict(s)
|
|
919
|
-
s2["id"] = mapping[old]
|
|
920
|
-
s2["cited"] = True
|
|
921
|
-
s2["panel_id"] = mapping[old]
|
|
922
|
-
cited_sorted.append(s2)
|
|
923
|
-
next_panel = len(mapping)
|
|
924
|
-
rest: List[Dict[str, str]] = []
|
|
925
|
-
for s in sources:
|
|
926
|
-
if s["id"] in mapping:
|
|
927
|
-
continue
|
|
928
|
-
next_panel += 1
|
|
929
|
-
s2 = dict(s)
|
|
930
|
-
s2["cited"] = False
|
|
931
|
-
# 备查卡的 id 一并改为面板锚点号,避免旧编号与重排后的角标空间撞号
|
|
932
|
-
s2["id"] = str(next_panel)
|
|
933
|
-
s2["panel_id"] = str(next_panel)
|
|
934
|
-
rest.append(s2)
|
|
935
|
-
return answer, cited_sorted + rest
|
|
936
|
-
|
|
937
|
-
|
|
938
916
|
def render_source_card(source: Dict[str, str]) -> str:
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
vk = '<span class="sc-vk none">备查</span>'
|
|
917
|
+
if not source.get("used", True):
|
|
918
|
+
# 未引用召回材料:不标"已核验"(未进入正文核验流程),只标可否查看
|
|
919
|
+
vk = ('<span class="sc-vk" style="color:var(--muted)">可查看原文</span>' if source.get("has_link")
|
|
920
|
+
else '<span class="sc-vk warn">待补链接</span>')
|
|
944
921
|
note_html = ""
|
|
922
|
+
elif source.get("verified"):
|
|
923
|
+
note = source.get("verify_note") or "摘录可比对,原文链接与知识专库可回看"
|
|
924
|
+
vk = f'<span class="sc-vk ok" title="{esc(note)}">✓ 已核验</span>'
|
|
925
|
+
note_html = f'<div class="sc-vnote">{esc(short(note, 90))}</div>' if source.get("verify_note") else ""
|
|
945
926
|
else:
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
vk = f'<span class="sc-vk ok" title="{esc(note)}">✓ 已核验</span>'
|
|
950
|
-
note_html = f'<div class="sc-vnote">{esc(short(note, 90))}</div>' if source.get("verify_note") else ""
|
|
951
|
-
else:
|
|
952
|
-
reason = "原文链接待补" if not source.get("has_link") else "摘录待补"
|
|
953
|
-
vk = f'<span class="sc-vk warn">◐ {reason}</span>'
|
|
954
|
-
note_html = ""
|
|
927
|
+
reason = "待补原文链接" if not source.get("has_link") else "待补摘录"
|
|
928
|
+
vk = f'<span class="sc-vk warn">◐ {reason}</span>'
|
|
929
|
+
note_html = ""
|
|
955
930
|
links = render_source_links(source.get("url"), source.get("policy_url", ""))
|
|
956
931
|
meta = " | ".join(v for v in [source.get("agency"), source.get("date"), source.get("area")] if v)
|
|
932
|
+
# 标题链:这段摘录在原文件中的章节标题(接口段落标题),悬停可见含文章标题的完整链
|
|
933
|
+
chain_html = (f'<div class="sc-chain" title="{esc("原文中的位置:" + source["chain_full"])}">'
|
|
934
|
+
f'标题:{esc(source["doc_section"])}</div>') if source.get("doc_section") else ""
|
|
957
935
|
section_html = f'<div class="sc-section">支撑:{esc(source["section"])}</div>' if source.get("section") else ""
|
|
958
|
-
|
|
936
|
+
# 高可信徽标:仅"发布日期可信度=高"(模型治理入库、标题模型精抽)的材料;"较高"(门户抓取)不标。
|
|
937
|
+
# 原文原段身份由摘录上方的"▍ 原文原段(非 AI 生成)"标注行承担,不在卡片头部重复挂标签。
|
|
938
|
+
conf_badge = ""
|
|
939
|
+
if source.get("conf") == "高":
|
|
940
|
+
conf_badge = ('<span class="sc-conf" title="发布日期可信度:高。内容经模型治理入库,'
|
|
941
|
+
'标题为模型从原文动态抽取,非规则提取">高可信</span>')
|
|
942
|
+
excerpt_tag = '<div class="sc-extag">▍ 原文原段(非 AI 生成)</div>'
|
|
943
|
+
# 已引用材料显示角标编号;未引用召回材料显示"未引用"灰标(不占正文角标号)
|
|
944
|
+
id_html = f'<span class="sc-id">[{esc(source["id"])}]</span>' if source.get("used", True) else '<span class="sc-unused">未引用</span>'
|
|
945
|
+
unused_attr = "" if source.get("used", True) else ' data-unused="1"'
|
|
959
946
|
return (
|
|
960
|
-
f'<article class="scard {source["type_css"]}" id="src-{esc(
|
|
947
|
+
f'<article class="scard {source["type_css"]}" id="src-{esc(source["id"])}" data-type="{esc(source["type_key"])}" data-cite-id="{esc(source["id"])}" data-search="{esc(source.get("search_key", ""))}"{unused_attr}>'
|
|
961
948
|
f'<div class="sc-head">{id_html}'
|
|
962
|
-
f'<span class="sc-type">{esc(source["type_label"])}</span>{vk}</div>'
|
|
949
|
+
f'<span class="sc-type">{esc(source["type_label"])}</span>{conf_badge}{vk}</div>'
|
|
963
950
|
f'<h4>{esc(source.get("title"))}</h4>'
|
|
964
951
|
f'<div class="sc-meta">{esc(meta)}</div>'
|
|
965
|
-
f'{section_html}{note_html}'
|
|
952
|
+
f'{chain_html}{section_html}{note_html}'
|
|
953
|
+
f'{excerpt_tag}'
|
|
966
954
|
f'{render_excerpt_html(source.get("excerpt") or "接口返回中未识别到可展示的摘录。")}'
|
|
955
|
+
f'<div class="sc-more" role="button" tabindex="0"></div>'
|
|
967
956
|
f'{links}</article>'
|
|
968
957
|
)
|
|
969
958
|
|
|
970
959
|
|
|
971
|
-
def render_sources_panel(sources: List[Dict[str, str]], used: List[str]
|
|
960
|
+
def render_sources_panel(sources: List[Dict[str, str]], used: List[str]) -> str:
|
|
972
961
|
if not sources:
|
|
973
962
|
return '<aside class="sources"><h3>核验材料</h3><p class="empty">接口返回中未识别到可展示的材料。</p></aside>'
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
uncited = [s for s in sources if s["id"] not in used_set]
|
|
963
|
+
cited_cards = [render_source_card(s) for s in sources if s.get("used", True)]
|
|
964
|
+
uncited = [s for s in sources if not s.get("used", True)]
|
|
977
965
|
uncited_html = ""
|
|
978
966
|
if uncited:
|
|
979
967
|
uncited_cards = "".join(render_source_card(s) for s in uncited)
|
|
980
968
|
# 不用 <details> 折叠:部分宿主(WorkBuddy 等)的 HTML 预览服务会改写折叠区导致卡片丢失
|
|
981
969
|
uncited_html = (
|
|
982
970
|
'<div class="uncited-group"><div class="ug-title">未引用素材('
|
|
983
|
-
f'{len(uncited)}
|
|
971
|
+
f'{len(uncited)} 条 · 接口召回但正文未采用,供比对参考)</div>'
|
|
984
972
|
f'<div class="uncited-list">{uncited_cards}</div></div>'
|
|
985
973
|
)
|
|
986
|
-
verified_count = sum(1 for s in sources if s
|
|
987
|
-
|
|
974
|
+
verified_count = sum(1 for s in sources if s.get("verified"))
|
|
975
|
+
# 筛选维度 = 检索分组(多路检索时按来源分组,如"北京·AI政策/北京·产业数据"):胶囊样式沿用类型筛选样式,单选 + 全部。
|
|
976
|
+
# 类型不再作为筛选维度(卡片徽章已展示类型,且类型为模型主观标注)。
|
|
977
|
+
conds: List[Tuple[str, int]] = []
|
|
978
|
+
for s in sources:
|
|
979
|
+
key = s.get("search_key", "")
|
|
980
|
+
if not key:
|
|
981
|
+
continue
|
|
982
|
+
for i, (name, count) in enumerate(conds):
|
|
983
|
+
if name == key:
|
|
984
|
+
conds[i] = (name, count + 1)
|
|
985
|
+
break
|
|
986
|
+
else:
|
|
987
|
+
conds.append((key, 1))
|
|
988
988
|
filters_html = ""
|
|
989
|
-
if len(
|
|
990
|
-
buttons = ['<button class="on" data-
|
|
991
|
-
for
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
989
|
+
if len(conds) >= 2 or uncited:
|
|
990
|
+
buttons = ['<button class="on" data-cond="" type="button">全部</button>']
|
|
991
|
+
for name, count in conds:
|
|
992
|
+
buttons.append(f'<button data-cond="{esc(name)}" type="button">{esc(name)}({count})</button>')
|
|
993
|
+
if uncited:
|
|
994
|
+
buttons.append(f'<button data-cond="__unused__" type="button">未引用({len(uncited)})</button>')
|
|
995
|
+
filters_html = f'<div class="filters" role="group" aria-label="按检索分组筛选">{"".join(buttons)}</div>'
|
|
996
|
+
# "已核验"徽章只统计已引用材料(未引用召回未进入正文核验流程,不计入)
|
|
997
|
+
cited_sources = [s for s in sources if s.get("used", True)]
|
|
998
|
+
cited_verified = sum(1 for s in cited_sources if s.get("verified"))
|
|
999
|
+
badge = "全部已核验" if cited_sources and cited_verified == len(cited_sources) else f"{cited_verified}/{len(cited_sources)} 已核验"
|
|
997
1000
|
return (
|
|
998
1001
|
'<aside class="sources" id="sources-panel" aria-label="核验材料面板">'
|
|
999
1002
|
'<a class="back-doc" href="#doc-top">↑ 返回核验报告单</a>'
|
|
1000
|
-
f'<h3
|
|
1003
|
+
f'<h3>核验材料(已引用 {len(cited_cards)} 条 · {esc(badge)})</h3>'
|
|
1001
1004
|
'<div class="src-tip">点击正文角标 [1] 定位材料原文并核对</div>'
|
|
1002
1005
|
f'{filters_html}'
|
|
1003
1006
|
'<input class="src-search" type="search" placeholder="搜索标题 / 来源 / 摘录…" aria-label="搜索来源">'
|
|
1004
1007
|
f'<div class="src-list">{"".join(cited_cards)}{uncited_html}</div>'
|
|
1005
|
-
f'{kb_zone}'
|
|
1006
1008
|
'</aside>'
|
|
1007
1009
|
)
|
|
1008
1010
|
|
|
1009
1011
|
|
|
1010
|
-
def render_kb_zone(kb_urls: List[str], kb_labels: List[str], source_count: int) -> str:
|
|
1011
|
-
if not kb_urls:
|
|
1012
|
-
return ""
|
|
1013
|
-
chips = []
|
|
1014
|
-
for index, url in enumerate(kb_urls):
|
|
1015
|
-
label = kb_labels[index] if index < len(kb_labels) else "相关搜索来源"
|
|
1016
|
-
chips.append(
|
|
1017
|
-
f'<a class="kb-chip" href="{esc(url)}" target="_blank" rel="noopener">'
|
|
1018
|
-
f'<span class="kb-label">{esc(label)}</span>'
|
|
1019
|
-
f'<span class="kb-count">{"原始召回" if index else f"{source_count} 条来源"} · 可回看</span>'
|
|
1020
|
-
'<span class="kb-arrow">打开 ↗</span></a>'
|
|
1021
|
-
)
|
|
1022
|
-
return (
|
|
1023
|
-
'<div class="kb-zone"><div class="kb-title">原始召回存档(深知知识专库)</div>'
|
|
1024
|
-
'<div class="kb-desc">以下链接可回看每次搜索的完整召回结果(含未写入正文的材料);'
|
|
1025
|
-
'原文页面改版或下线时可回看当时召回的快照。逐条材料的核验请点击来源卡上的"查看原文"直达官方页面。</div>'
|
|
1026
|
-
f'<div class="kb-list">{"".join(chips)}</div></div>'
|
|
1027
|
-
)
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
1012
|
def safe_output_filename(question: str, timestamp: datetime, fallback: str = "dknowc_search_trace",
|
|
1031
|
-
suffix_ext: str = ".html", label: str = "_
|
|
1013
|
+
suffix_ext: str = ".html", label: str = "_溯源核验报告") -> str:
|
|
1032
1014
|
raw = question.strip() or fallback
|
|
1033
1015
|
normalized = re.sub(r"\s+", "_", raw)
|
|
1034
1016
|
normalized = re.sub(r"[\\/:*?\"<>|#%&{}$!@`+=;',。、?!:;“”‘’()()【】《》\[\]]+", "", normalized)
|
|
@@ -1040,6 +1022,45 @@ def safe_output_filename(question: str, timestamp: datetime, fallback: str = "dk
|
|
|
1040
1022
|
return f"{stem}{label}_{suffix}{suffix_ext}"
|
|
1041
1023
|
|
|
1042
1024
|
|
|
1025
|
+
def renumber_citations(answer: str, sources: List[Dict[str, str]]) -> Tuple[str, List[Dict[str, str]]]:
|
|
1026
|
+
"""把答案角标按首次出现顺序重排为 [1][2][3]…,材料卡同步重编号。
|
|
1027
|
+
|
|
1028
|
+
被引用的材料按新编号排在前面(编号与正文角标一一对应,used=True);
|
|
1029
|
+
未引用召回材料移入"未引用素材"分组(used=False,不占角标编号,锚点用独立递增号)。
|
|
1030
|
+
"""
|
|
1031
|
+
cited_order = citation_ids(answer)
|
|
1032
|
+
if not cited_order:
|
|
1033
|
+
for s in sources:
|
|
1034
|
+
s["used"] = False
|
|
1035
|
+
return answer, sources
|
|
1036
|
+
mapping = {old: str(new) for new, old in enumerate(cited_order, start=1)}
|
|
1037
|
+
answer = re.sub(r"\[(\d+)\]", lambda m: "[" + mapping.get(m.group(1), m.group(1)) + "]", answer)
|
|
1038
|
+
by_old: Dict[str, Dict[str, str]] = {}
|
|
1039
|
+
for s in sources:
|
|
1040
|
+
by_old.setdefault(s["id"], s)
|
|
1041
|
+
cited_sorted: List[Dict[str, str]] = []
|
|
1042
|
+
for old in cited_order:
|
|
1043
|
+
s = by_old.get(old)
|
|
1044
|
+
if s is None:
|
|
1045
|
+
continue
|
|
1046
|
+
s2 = dict(s)
|
|
1047
|
+
s2["id"] = mapping[old]
|
|
1048
|
+
s2["used"] = True
|
|
1049
|
+
cited_sorted.append(s2)
|
|
1050
|
+
next_panel = len(mapping)
|
|
1051
|
+
rest: List[Dict[str, str]] = []
|
|
1052
|
+
for s in sources:
|
|
1053
|
+
if s["id"] in mapping:
|
|
1054
|
+
continue
|
|
1055
|
+
next_panel += 1
|
|
1056
|
+
s2 = dict(s)
|
|
1057
|
+
s2["used"] = False
|
|
1058
|
+
# 未引用材料 id 一并改为面板锚点号,避免旧编号与重排后的角标空间撞号
|
|
1059
|
+
s2["id"] = str(next_panel)
|
|
1060
|
+
rest.append(s2)
|
|
1061
|
+
return answer, cited_sorted + rest
|
|
1062
|
+
|
|
1063
|
+
|
|
1043
1064
|
def render_html(payload: Dict[str, Any], title: str, answer_override: str = "", question_override: str = "",
|
|
1044
1065
|
generated_at: Optional[datetime] = None) -> str:
|
|
1045
1066
|
payload = unwrap(payload)
|
|
@@ -1048,14 +1069,13 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
1048
1069
|
answer, sources = renumber_citations(answer, sources)
|
|
1049
1070
|
used = citation_ids(answer)
|
|
1050
1071
|
used_set = set(used)
|
|
1051
|
-
#
|
|
1072
|
+
# 卡片级核验标记与核验单口径对齐:被引用材料缺原文链接但知识专库可回看 → 视为已核验
|
|
1073
|
+
kb_urls_for_cards = extract_knowledge_bases(payload)
|
|
1052
1074
|
for s in sources:
|
|
1053
|
-
if s
|
|
1075
|
+
if s.get("used", True) and not s.get("verified") and kb_urls_for_cards:
|
|
1054
1076
|
if (s.get("excerpt") or "").strip():
|
|
1055
1077
|
s["verified"] = True
|
|
1056
1078
|
s["verify_note"] = s.get("verify_note") or "原文链接暂缺,可经知识专库回看核验"
|
|
1057
|
-
kb_urls = extract_knowledge_bases(payload)
|
|
1058
|
-
kb_labels = payload.get("knowledgeBaseLabels") if isinstance(payload.get("knowledgeBaseLabels"), list) else []
|
|
1059
1079
|
generated_at = generated_at or datetime.now()
|
|
1060
1080
|
generated = generated_at.strftime("%Y-%m-%d %H:%M")
|
|
1061
1081
|
|
|
@@ -1071,7 +1091,6 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
1071
1091
|
blocks, _ = parse_answer_blocks(answer, {s["id"] for s in sources})
|
|
1072
1092
|
doc_title, sections = group_sections(blocks)
|
|
1073
1093
|
display_title = doc_title or title
|
|
1074
|
-
kb_zone = render_kb_zone(kb_urls, kb_labels, len(sources))
|
|
1075
1094
|
|
|
1076
1095
|
cov = verification["coverage"]
|
|
1077
1096
|
meta_bits = []
|
|
@@ -1088,7 +1107,7 @@ def render_html(payload: Dict[str, Any], title: str, answer_override: str = "",
|
|
|
1088
1107
|
<head>
|
|
1089
1108
|
<meta charset="utf-8">
|
|
1090
1109
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
1091
|
-
<title>{esc(display_title)} ·
|
|
1110
|
+
<title>{esc(display_title)} · 溯源核验报告</title>
|
|
1092
1111
|
<style>
|
|
1093
1112
|
:root{{
|
|
1094
1113
|
--navy:#0b1f3a; --ink:#172236; --muted:#667085; --line:#dce4ef; --line-strong:#b9c6d9;
|
|
@@ -1112,6 +1131,9 @@ a{{color:var(--brand)}}
|
|
|
1112
1131
|
/* 左栏 */
|
|
1113
1132
|
.report{{min-width:0}}
|
|
1114
1133
|
.r-head{{padding:22px 26px;background:#fff;border:1px solid var(--line);border-radius:12px;margin-bottom:16px;text-align:center}}
|
|
1134
|
+
.r-badge{{display:inline-flex;align-items:center;gap:14px;margin:0 0 6px;color:var(--navy);
|
|
1135
|
+
font-size:16px;font-weight:800;letter-spacing:7px;text-indent:7px;line-height:1.5}}
|
|
1136
|
+
.r-badge::before,.r-badge::after{{content:"";width:64px;border-top:1px solid var(--line-strong)}}
|
|
1115
1137
|
.r-head h1{{margin:0 0 8px;font-size:22px;color:var(--navy);line-height:1.5}}
|
|
1116
1138
|
.r-head .sub{{color:var(--muted);font-size:12.5px}}
|
|
1117
1139
|
.warn-box{{margin:0 0 16px;padding:13px 16px;border:1.5px solid var(--danger);border-radius:10px;
|
|
@@ -1127,6 +1149,7 @@ a{{color:var(--brand)}}
|
|
|
1127
1149
|
padding:1px 8px;letter-spacing:2px;flex:none}}
|
|
1128
1150
|
.v-stamp.bad{{border-color:var(--danger);color:var(--danger)}}
|
|
1129
1151
|
.v-reasons{{margin-top:6px;font-size:12.5px;color:var(--danger)}}
|
|
1152
|
+
.v-reasons.note{{color:var(--warn)}}
|
|
1130
1153
|
.v-grid{{display:grid;grid-template-columns:1fr 1fr;gap:4px 20px;margin-top:10px}}
|
|
1131
1154
|
.vi{{display:flex;gap:7px;align-items:baseline;font-size:12.5px;color:#35445c;line-height:1.7;min-width:0}}
|
|
1132
1155
|
.vi .s{{font-weight:800;flex:none}}
|
|
@@ -1194,6 +1217,8 @@ code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
|
1194
1217
|
.filters button{{border:1px solid var(--line);border-radius:999px;background:#fff;color:var(--muted);
|
|
1195
1218
|
padding:3px 11px;font-size:12px;cursor:pointer}}
|
|
1196
1219
|
.filters button.on{{background:var(--brand);border-color:var(--brand);color:#fff;font-weight:700}}
|
|
1220
|
+
.sc-unused{{font-size:10.5px;font-weight:800;color:var(--muted);background:#eef1f6;border-radius:4px;
|
|
1221
|
+
padding:1px 7px;flex:none}}
|
|
1197
1222
|
.src-search{{width:100%;padding:7px 10px;border:1px solid var(--line);border-radius:7px;font-size:12.5px;margin-bottom:12px}}
|
|
1198
1223
|
.scard{{border:1px solid var(--line);border-left-width:3px;border-radius:10px;padding:11px 13px;margin-bottom:10px;
|
|
1199
1224
|
background:#fff;transition:box-shadow .25s}}
|
|
@@ -1212,9 +1237,10 @@ code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
|
1212
1237
|
.scard.cas .sc-type{{background:var(--case-soft);color:var(--case)}}
|
|
1213
1238
|
.sc-vk{{margin-left:auto;font-size:11px;font-weight:800;color:var(--ok)}}
|
|
1214
1239
|
.sc-vk.warn{{color:var(--warn)}}
|
|
1215
|
-
.sc-
|
|
1216
|
-
|
|
1217
|
-
.
|
|
1240
|
+
.sc-conf{{font-size:10.5px;font-weight:800;color:#8a5a00;background:var(--case-soft);border:1px solid #e8c98a;
|
|
1241
|
+
border-radius:4px;padding:0 7px;flex:none}}
|
|
1242
|
+
.sc-extag{{margin-top:8px;padding-top:7px;border-top:1px dashed var(--line-strong);font-size:11px;color:#0b6e4f;font-weight:700}}
|
|
1243
|
+
.sc-chain{{font-size:11.5px;color:var(--brand);margin-top:3px;font-weight:600;line-height:1.6;cursor:help}}
|
|
1218
1244
|
.scard h4{{margin:0 0 4px;font-size:13px;color:var(--navy);line-height:1.55}}
|
|
1219
1245
|
.sc-meta{{font-size:11.5px;color:var(--muted)}}
|
|
1220
1246
|
.sc-section{{font-size:11.5px;color:var(--brand);margin-top:3px;font-weight:600}}
|
|
@@ -1222,6 +1248,10 @@ code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
|
1222
1248
|
.sc-excerpt{{margin:7px 0;padding:9px 10px;border-radius:7px;background:#f8fafc;color:#42566f;font-size:12px;line-height:1.7;
|
|
1223
1249
|
display:-webkit-box;-webkit-line-clamp:4;-webkit-box-orient:vertical;overflow:hidden;cursor:pointer}}
|
|
1224
1250
|
.scard.open .sc-excerpt{{display:block;-webkit-line-clamp:unset}}
|
|
1251
|
+
.sc-more{{display:none;margin:-3px 2px 4px;text-align:right;font-size:11px;color:var(--brand);font-weight:700;cursor:pointer;user-select:none}}
|
|
1252
|
+
.scard.clampable .sc-more{{display:block}}
|
|
1253
|
+
.scard.clampable .sc-more::before{{content:"展开全文 ▾"}}
|
|
1254
|
+
.scard.clampable.open .sc-more::before{{content:"收起 ▴"}}
|
|
1225
1255
|
.sc-excerpt.rich{{overflow-x:auto}}
|
|
1226
1256
|
.sc-excerpt.rich table{{width:max-content;min-width:100%;border-collapse:collapse;background:#fff;font-size:12px}}
|
|
1227
1257
|
.sc-excerpt.rich td,.sc-excerpt.rich th{{min-width:92px;max-width:220px;padding:7px 8px;border:1px solid var(--line);
|
|
@@ -1233,17 +1263,6 @@ code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
|
1233
1263
|
.uncited-group{{margin-top:12px;border-top:1px dashed var(--line-strong);padding-top:10px}}
|
|
1234
1264
|
.ug-title{{font-size:12.5px;color:var(--muted);font-weight:700;line-height:1.6}}
|
|
1235
1265
|
.uncited-group .uncited-list{{margin-top:10px}}
|
|
1236
|
-
/* 知识专库 */
|
|
1237
|
-
.kb-zone{{margin-top:14px;border-top:1px dashed var(--line-strong);padding-top:12px}}
|
|
1238
|
-
.kb-title{{font-size:12.5px;font-weight:800;color:var(--navy)}}
|
|
1239
|
-
.kb-desc{{font-size:11.3px;color:var(--muted);line-height:1.65;margin:3px 0 8px}}
|
|
1240
|
-
.kb-list{{display:flex;flex-direction:column;gap:7px}}
|
|
1241
|
-
.kb-chip{{display:flex;align-items:center;gap:8px;padding:7px 10px;border:1px solid var(--line);border-radius:8px;
|
|
1242
|
-
background:#fbfcfe;text-decoration:none;font-size:11.5px}}
|
|
1243
|
-
.kb-chip:hover{{border-color:var(--brand);background:var(--brand-soft)}}
|
|
1244
|
-
.kb-label{{font-weight:700;color:#374151;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}}
|
|
1245
|
-
.kb-count{{padding-left:8px;border-left:1px solid var(--line);color:var(--muted);white-space:nowrap}}
|
|
1246
|
-
.kb-arrow{{margin-left:auto;color:var(--brand);font-weight:700;white-space:nowrap}}
|
|
1247
1266
|
.empty{{color:var(--muted)}}
|
|
1248
1267
|
.foot{{text-align:center;color:var(--muted);font-size:11.5px;padding:16px 0 4px;line-height:1.8}}
|
|
1249
1268
|
@media (max-width:1020px){{
|
|
@@ -1261,6 +1280,8 @@ code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
|
1261
1280
|
.layout{{grid-template-columns:1fr;padding:12px 10px 40px;gap:14px}}
|
|
1262
1281
|
.topbar{{padding:8px 12px;font-size:12px;gap:4px;flex-wrap:wrap}}
|
|
1263
1282
|
.topbar .tags span{{font-size:10.5px;padding:1px 8px;margin-left:4px}}
|
|
1283
|
+
.r-badge{{font-size:13.5px;letter-spacing:6px;text-indent:6px;gap:10px}}
|
|
1284
|
+
.r-badge::before,.r-badge::after{{width:40px}}
|
|
1264
1285
|
.r-head{{padding:16px 14px;border-radius:10px}}
|
|
1265
1286
|
.r-head h1{{font-size:18px}}
|
|
1266
1287
|
.r-head .sub{{font-size:11.5px;line-height:1.6}}
|
|
@@ -1283,9 +1304,9 @@ code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
|
1283
1304
|
.ev-chip summary{{font-size:11px}}
|
|
1284
1305
|
.sources{{padding:12px;border-radius:10px}}
|
|
1285
1306
|
.scard{{padding:10px 11px}}
|
|
1307
|
+
.sc-extag{{font-size:10.5px}}
|
|
1308
|
+
.sc-chain{{font-size:11px}}
|
|
1286
1309
|
.sc-excerpt{{font-size:11.5px}}
|
|
1287
|
-
.kb-chip{{flex-wrap:wrap}}
|
|
1288
|
-
.kb-label{{white-space:normal}}
|
|
1289
1310
|
.mobile-nav{{display:block;margin:0 0 14px;padding:11px 14px;border:1.5px solid var(--brand);
|
|
1290
1311
|
border-radius:10px;background:var(--brand-soft);color:var(--brand);font-weight:800;
|
|
1291
1312
|
font-size:13.5px;text-decoration:none;text-align:center}}
|
|
@@ -1306,6 +1327,16 @@ code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
|
1306
1327
|
font-size:12.5px;font-weight:700;padding:5px 14px;cursor:pointer}}
|
|
1307
1328
|
.sheet .scard{{box-shadow:none;margin-bottom:0}}
|
|
1308
1329
|
.sheet .sc-excerpt{{display:block;-webkit-line-clamp:unset;cursor:auto}}
|
|
1330
|
+
/* 正文表述 ↔ 原文原段 对照区(弹层顶部) */
|
|
1331
|
+
.cmp{{margin:0 0 10px;border:1px solid var(--line);border-radius:10px;overflow:hidden}}
|
|
1332
|
+
.cmp-tag{{font-size:11px;font-weight:800;padding:3px 10px}}
|
|
1333
|
+
.cmp-side{{padding:9px 12px;font-size:12.8px;line-height:1.7}}
|
|
1334
|
+
.cmp-side p{{margin:0}}
|
|
1335
|
+
.cmp-ai{{background:#fbfcfe;color:#374151}}
|
|
1336
|
+
.cmp-ai .cmp-tag{{background:#eef1f6;color:var(--ref)}}
|
|
1337
|
+
.cmp-src{{background:#f4faf7;color:#2f4a3e;border-top:1px dashed var(--line-strong)}}
|
|
1338
|
+
.cmp-src .cmp-tag{{background:var(--policy-soft);color:#0b6e4f}}
|
|
1339
|
+
.cmp-src .sc-excerpt{{display:block;-webkit-line-clamp:unset;background:#fff;cursor:auto;font-size:12px;padding:8px 10px;margin:0}}
|
|
1309
1340
|
}}
|
|
1310
1341
|
@media print{{
|
|
1311
1342
|
.topbar,.filters,.src-search{{display:none!important}}
|
|
@@ -1323,7 +1354,7 @@ code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
|
1323
1354
|
<body>
|
|
1324
1355
|
|
|
1325
1356
|
<header class="topbar">
|
|
1326
|
-
<div class="tb-title">{esc(display_title)} ·
|
|
1357
|
+
<div class="tb-title">{esc(display_title)} · 溯源核验报告</div>
|
|
1327
1358
|
<div class="tags">
|
|
1328
1359
|
<span>生成于 {esc(generated)}</span>
|
|
1329
1360
|
<span>素材来源:深知可信搜索</span>
|
|
@@ -1333,22 +1364,23 @@ code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
|
1333
1364
|
<div class="layout">
|
|
1334
1365
|
<main class="report" aria-label="核验报告正文">
|
|
1335
1366
|
<div class="r-head" id="doc-top">
|
|
1367
|
+
<div class="r-badge">溯源核验报告</div>
|
|
1336
1368
|
<h1>{esc(display_title)}</h1>
|
|
1337
1369
|
<div class="sub">{esc(meta_line)}</div>
|
|
1338
1370
|
</div>
|
|
1339
1371
|
{citation_warning}
|
|
1340
1372
|
{render_verify_panel(verification)}
|
|
1341
|
-
<a class="mobile-nav" href="#sources-panel">查看核验材料({len(
|
|
1373
|
+
<a class="mobile-nav" href="#sources-panel">查看核验材料({len(sources)} 条 · 点击角标可定位原文)↓</a>
|
|
1342
1374
|
{render_section_cards(sections, sources)}
|
|
1343
|
-
<div class="foot">深知可信搜索(法律、政策、标准)·
|
|
1375
|
+
<div class="foot">深知可信搜索(法律、政策、标准)· 溯源核验报告 | 内容由 AI 生成,仅供参考,政策现行效力以官方发布为准</div>
|
|
1344
1376
|
</main>
|
|
1345
|
-
{render_sources_panel(sources, used
|
|
1377
|
+
{render_sources_panel(sources, used)}
|
|
1346
1378
|
</div>
|
|
1347
1379
|
|
|
1348
1380
|
<div class="sheet-mask" aria-hidden="true"></div>
|
|
1349
1381
|
<div class="sheet" role="dialog" aria-label="核验材料">
|
|
1350
1382
|
<div class="sheet-grab"></div>
|
|
1351
|
-
<div class="sheet-head"><b
|
|
1383
|
+
<div class="sheet-head"><b>依据对照</b><button class="sheet-close" type="button">收起</button></div>
|
|
1352
1384
|
<div class="sheet-body"></div>
|
|
1353
1385
|
</div>
|
|
1354
1386
|
|
|
@@ -1362,20 +1394,41 @@ code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
|
1362
1394
|
if (id) byId[id] = c;
|
|
1363
1395
|
}});
|
|
1364
1396
|
|
|
1365
|
-
/*
|
|
1397
|
+
/* 移动端底部弹层:点角标就地展示"正文表述 ↔ 原文原段"对照 + 材料卡,不打断正文阅读 */
|
|
1366
1398
|
var sheet = document.querySelector(".sheet");
|
|
1367
1399
|
var mask = document.querySelector(".sheet-mask");
|
|
1368
1400
|
function isMobile() {{
|
|
1369
1401
|
return window.matchMedia("(max-width:680px)").matches;
|
|
1370
1402
|
}}
|
|
1371
|
-
function
|
|
1403
|
+
function escHtml(s) {{
|
|
1404
|
+
var d = document.createElement("div");
|
|
1405
|
+
d.textContent = s;
|
|
1406
|
+
return d.innerHTML;
|
|
1407
|
+
}}
|
|
1408
|
+
function sentenceOf(el) {{
|
|
1409
|
+
var para = el && el.closest ? el.closest(".doc-block,.doc-item") : null;
|
|
1410
|
+
return para && para.querySelector("p") ? para.querySelector("p").innerText.trim() : "";
|
|
1411
|
+
}}
|
|
1412
|
+
function openSheet(card, sentence) {{
|
|
1372
1413
|
if (!sheet) return;
|
|
1373
1414
|
var body = sheet.querySelector(".sheet-body");
|
|
1415
|
+
body.innerHTML = "";
|
|
1416
|
+
if (sentence) {{
|
|
1417
|
+
var excerpt = card.querySelector(".sc-excerpt");
|
|
1418
|
+
var cmp = document.createElement("div");
|
|
1419
|
+
cmp.className = "cmp";
|
|
1420
|
+
cmp.innerHTML =
|
|
1421
|
+
'<div class="cmp-side cmp-ai"><div class="cmp-tag">正文表述(AI 生成)</div><p>' + escHtml(sentence) + '</p></div>' +
|
|
1422
|
+
'<div class="cmp-side cmp-src"><div class="cmp-tag">原文原段(非 AI 生成)</div>' +
|
|
1423
|
+
'<div class="sc-excerpt">' + (excerpt ? excerpt.innerHTML : "") + '</div></div>';
|
|
1424
|
+
body.appendChild(cmp);
|
|
1425
|
+
}}
|
|
1374
1426
|
var clone = card.cloneNode(true);
|
|
1375
1427
|
clone.removeAttribute("id");
|
|
1376
1428
|
clone.classList.remove("hide");
|
|
1377
1429
|
clone.classList.add("open");
|
|
1378
|
-
|
|
1430
|
+
var sheetMore = clone.querySelector(".sc-more");
|
|
1431
|
+
if (sheetMore) sheetMore.remove();
|
|
1379
1432
|
body.appendChild(clone);
|
|
1380
1433
|
sheet.classList.add("show");
|
|
1381
1434
|
mask.classList.add("show");
|
|
@@ -1406,7 +1459,7 @@ code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
|
1406
1459
|
return;
|
|
1407
1460
|
}}
|
|
1408
1461
|
if (isMobile()) {{
|
|
1409
|
-
openSheet(card);
|
|
1462
|
+
openSheet(card, sentenceOf(btn));
|
|
1410
1463
|
return;
|
|
1411
1464
|
}}
|
|
1412
1465
|
card.classList.remove("hide", "open");
|
|
@@ -1416,25 +1469,42 @@ code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
|
1416
1469
|
}});
|
|
1417
1470
|
}});
|
|
1418
1471
|
|
|
1419
|
-
/*
|
|
1472
|
+
/* 摘录点击展开/收起:内容被截断(超出 4 行)的卡片显示"展开全文"引导,
|
|
1473
|
+
未截断的短摘录不显示,避免误导 */
|
|
1420
1474
|
cards.forEach(function (c) {{
|
|
1421
1475
|
var ex = c.querySelector(".sc-excerpt");
|
|
1422
1476
|
if (!ex) return;
|
|
1477
|
+
if (ex.scrollHeight > ex.clientHeight + 4) c.classList.add("clampable");
|
|
1478
|
+
var more = c.querySelector(".sc-more");
|
|
1479
|
+
function toggleExcerpt() {{ c.classList.toggle("open"); }}
|
|
1423
1480
|
ex.addEventListener("click", function (e) {{
|
|
1424
1481
|
if (e.target.closest("a")) return;
|
|
1425
|
-
|
|
1482
|
+
toggleExcerpt();
|
|
1426
1483
|
}});
|
|
1484
|
+
if (more) {{
|
|
1485
|
+
more.addEventListener("click", toggleExcerpt);
|
|
1486
|
+
more.addEventListener("keydown", function (e) {{
|
|
1487
|
+
if (e.key === "Enter" || e.key === " ") {{ e.preventDefault(); toggleExcerpt(); }}
|
|
1488
|
+
}});
|
|
1489
|
+
}}
|
|
1427
1490
|
}});
|
|
1428
1491
|
|
|
1429
|
-
/* 证据 chips
|
|
1492
|
+
/* 证据 chips(灰框):桌面端点击就地展开并高亮右栏来源卡;手机端不就地展开,点击直接弹出底部材料弹层。
|
|
1493
|
+
展开锁定:浏览器(Chrome 系)对 <details> 展开会自动滚动露出内容、收起时滚动位置会被回夹,
|
|
1494
|
+
点击时锁定滚动位置并在展开/收起后滚回,消除页面"轻微滚动"感。 */
|
|
1430
1495
|
document.querySelectorAll(".ev-chip").forEach(function (chip) {{
|
|
1431
1496
|
var summary = chip.querySelector("summary");
|
|
1432
1497
|
if (summary) {{
|
|
1433
1498
|
summary.addEventListener("click", function (e) {{
|
|
1434
|
-
if (
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1499
|
+
if (isMobile()) {{
|
|
1500
|
+
e.preventDefault();
|
|
1501
|
+
var card = byId[chip.getAttribute("data-cite")];
|
|
1502
|
+
if (card) openSheet(card, sentenceOf(chip));
|
|
1503
|
+
return;
|
|
1504
|
+
}}
|
|
1505
|
+
var y = window.scrollY;
|
|
1506
|
+
var restore = function () {{ window.scrollTo(0, y); }};
|
|
1507
|
+
requestAnimationFrame(function () {{ restore(); requestAnimationFrame(restore); }});
|
|
1438
1508
|
}});
|
|
1439
1509
|
}}
|
|
1440
1510
|
chip.addEventListener("toggle", function () {{
|
|
@@ -1447,21 +1517,23 @@ code{{padding:1px 5px;border-radius:4px;background:#f3f4f6;color:#374151;
|
|
|
1447
1517
|
}});
|
|
1448
1518
|
}});
|
|
1449
1519
|
|
|
1450
|
-
/*
|
|
1451
|
-
var
|
|
1520
|
+
/* 检索分组筛选(单选 + 全部 + 未引用,胶囊样式)+ 关键字搜索叠加 */
|
|
1521
|
+
var cond = "";
|
|
1452
1522
|
var kw = "";
|
|
1453
1523
|
function apply() {{
|
|
1454
1524
|
cards.forEach(function (c) {{
|
|
1455
|
-
var
|
|
1525
|
+
var okCond = !cond;
|
|
1526
|
+
if (cond === "__unused__") okCond = c.getAttribute("data-unused") === "1";
|
|
1527
|
+
else if (cond) okCond = c.getAttribute("data-search") === cond;
|
|
1456
1528
|
var okKw = !kw || (c.textContent || "").toLowerCase().indexOf(kw) !== -1;
|
|
1457
|
-
c.classList.toggle("hide", !(
|
|
1529
|
+
c.classList.toggle("hide", !(okCond && okKw));
|
|
1458
1530
|
}});
|
|
1459
1531
|
}}
|
|
1460
1532
|
document.querySelectorAll(".filters button").forEach(function (b) {{
|
|
1461
1533
|
b.addEventListener("click", function () {{
|
|
1462
1534
|
document.querySelectorAll(".filters button").forEach(function (x) {{ x.classList.remove("on"); }});
|
|
1463
1535
|
b.classList.add("on");
|
|
1464
|
-
|
|
1536
|
+
cond = b.getAttribute("data-cond") || "";
|
|
1465
1537
|
apply();
|
|
1466
1538
|
}});
|
|
1467
1539
|
}});
|
|
@@ -1492,10 +1564,10 @@ def align_sources_to_answer(answer: str, sources: List[Dict[str, str]]) -> List[
|
|
|
1492
1564
|
|
|
1493
1565
|
|
|
1494
1566
|
def main() -> None:
|
|
1495
|
-
parser = argparse.ArgumentParser(description="
|
|
1567
|
+
parser = argparse.ArgumentParser(description="生成溯源核验报告 HTML")
|
|
1496
1568
|
parser.add_argument("input_json", help="trusted_search.py / deep_query.py 的 --json-only 输出 JSON")
|
|
1497
|
-
parser.add_argument("--output", help="输出 HTML 文件名(official-docs/output/);不传时按问题自动生成《标题_
|
|
1498
|
-
parser.add_argument("--title", default="
|
|
1569
|
+
parser.add_argument("--output", help="输出 HTML 文件名(official-docs/output/);不传时按问题自动生成《标题_溯源核验报告_时间戳.html》")
|
|
1570
|
+
parser.add_argument("--title", default="溯源核验报告", help="页面标题")
|
|
1499
1571
|
parser.add_argument("--answer-file", help="最终答案文件(关键结论带 [1][2] 角标)。复杂任务综合后必须传入,确保 HTML 展示的答案与交付一致。")
|
|
1500
1572
|
parser.add_argument("--clean-md-output", help="输出干净 Markdown 路径;内容来自同一份最终答案,并移除 [1]、【1】等溯源角标。")
|
|
1501
1573
|
parser.add_argument("--question", default="", help="用户原始问题,用于自动生成文件名。")
|