dknowc-dsh 1.0.4 → 1.1.1
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/README.md +9 -4
- package/package.json +2 -2
- package/skills/dknowc-ppt-assistant/README.md +54 -0
- package/skills/dknowc-ppt-assistant/SKILL.md +151 -0
- package/skills/dknowc-ppt-assistant/THIRD_PARTY_NOTICES.md +36 -0
- package/skills/dknowc-ppt-assistant/official-docs/output/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/official-docs/search-results/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/projects/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/references/content-pack.md +55 -0
- package/skills/dknowc-ppt-assistant/references/material_usage.md +51 -0
- package/skills/dknowc-ppt-assistant/references/sample_effect.html +89 -0
- package/skills/dknowc-ppt-assistant/references/sample_search_result.md +48 -0
- package/skills/dknowc-ppt-assistant/references/search_intro.md +79 -0
- package/skills/dknowc-ppt-assistant/references/style-presets.md +126 -0
- package/skills/dknowc-ppt-assistant/references/svg-authoring.md +81 -0
- package/skills/dknowc-ppt-assistant/references/upstream-docs/svg-pipeline.md +842 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/01_cover.svg +28 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/02_quote.svg +38 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/03_origin.svg +96 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/README.md +15 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/design_spec.md +408 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/spec_lock.md +78 -0
- package/skills/dknowc-ppt-assistant/scripts/adapt_mcp_result.py +279 -0
- package/skills/dknowc-ppt-assistant/scripts/check_release.py +106 -0
- package/skills/dknowc-ppt-assistant/scripts/compact_svg_coordinates.py +345 -0
- package/skills/dknowc-ppt-assistant/scripts/config.py +707 -0
- package/skills/dknowc-ppt-assistant/scripts/console_encoding.py +33 -0
- package/skills/dknowc-ppt-assistant/scripts/error_helper.py +434 -0
- package/skills/dknowc-ppt-assistant/scripts/finalize_svg.py +507 -0
- package/skills/dknowc-ppt-assistant/scripts/hyperlink_contract.py +399 -0
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +182 -0
- package/skills/dknowc-ppt-assistant/scripts/language_tags.py +283 -0
- package/skills/dknowc-ppt-assistant/scripts/mcp_direct.py +158 -0
- package/skills/dknowc-ppt-assistant/scripts/native_payloads.py +655 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_animation_presets.json +3440 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_animations.py +3965 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_effects.py +143 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_opc_validation.py +346 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/__init__.py +130 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/LICENSE-APACHE-2.0.txt +202 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/LICENSE-OPEN-XML-SDK-MIT.txt +23 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/NOTICE.md +54 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/presetShapeDefinitions.xml +19898 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/presetShapeSemantics.json +1217 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/shape_type_values.txt +187 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/errors.py +39 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/formula.py +336 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/loader.py +364 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/models.py +201 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/registry.py +270 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantic_hash.py +456 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantics.py +543 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/xml_safety.py +21 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/__init__.py +21 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/animation_import.py +287 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/chart_to_svg.py +2377 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/chartex_to_svg.py +422 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/color_resolver.py +894 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/converter.py +1143 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/custgeom_to_svg.py +165 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/effect_to_svg.py +410 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/emu_units.py +258 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/fill_to_svg.py +816 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/formula_import.py +611 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/hyperlinks.py +93 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/import_diagnostics.py +37 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/ln_to_svg.py +362 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/normalized_chart_svg.py +1217 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/ooxml_loader.py +506 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/pic_to_svg.py +653 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_authoring.py +894 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_registry_to_svg.py +216 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_svg_markup.py +198 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/prstgeom_to_svg.py +162 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/shape_walker.py +556 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/slide_to_svg.py +2002 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/tbl_to_svg.py +1841 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/transition_import.py +201 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/txbody_to_svg.py +1433 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_transitions.py +3153 -0
- package/skills/dknowc-ppt-assistant/scripts/preset_shape_svg.py +450 -0
- package/skills/dknowc-ppt-assistant/scripts/project_utils.py +645 -0
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +183 -0
- package/skills/dknowc-ppt-assistant/scripts/register_template.py +1327 -0
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +1048 -0
- package/skills/dknowc-ppt-assistant/scripts/resource_paths.py +282 -0
- package/skills/dknowc-ppt-assistant/scripts/shape_boolean_svg.py +189 -0
- package/skills/dknowc-ppt-assistant/scripts/slide_roster.py +44 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/__init__.py +12 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/align_embed_images.py +672 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/crop_images.py +370 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/embed_icons.py +564 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/embed_images.py +288 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/fix_image_aspect.py +389 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/flatten_tspan.py +948 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/svg_rect_to_path.py +346 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/__init__.py +15 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/checker.py +7791 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/cli.py +193 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/svg_contracts.py +1121 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/xml_support.py +35 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality_checker.py +59 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/__init__.py +37 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/animation_config.py +1622 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/canvas_contract.py +226 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/__init__.py +1 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/context.py +291 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/converter.py +1980 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/elements.py +5272 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/hyperlinks.py +162 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/paths.py +847 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/styles.py +752 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/text_properties.py +796 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_colors.py +283 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_fonts.py +330 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/utils.py +3555 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/geometry_properties.py +140 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/__init__.py +356 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_data.py +1449 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_style.py +886 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_xml.py +1495 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chartex.py +272 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/fallback_hash.py +161 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula.py +243 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_ast.py +592 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_compiler.py +96 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_omml.py +1049 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_parser.py +2181 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_profile.py +739 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_run_properties.py +234 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/inline_formula.py +311 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_attributes.py +182 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_common.py +806 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_status.py +190 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/table.py +1113 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/workbook.py +216 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/__init__.py +1 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/builder.py +6273 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/cli.py +2059 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/dimensions.py +189 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/discovery.py +120 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/media.py +160 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/narration.py +696 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/notes.py +336 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/slide_xml.py +138 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_structure.py +3457 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_validation.py +1536 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/semantic_markers.py +240 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/shape_boolean.py +1355 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/text_outline.py +1121 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/tspan_flattener.py +64 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/use_expander.py +577 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx.py +21 -0
- package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +336 -0
- package/skills/dknowc-ppt-assistant/scripts/update_spec.py +404 -0
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +142 -0
- package/skills/dknowc-ppt-assistant/workflows/routing.md +38 -0
- package/skills/dknowc-trusted-search/SKILL.md +8 -7
- package/skills/dknowc-trusted-search/scripts/adapt_mcp_result.py +19 -37
- package/skills/dknowc-trusted-search/scripts/deep_query.py +117 -137
- package/skills/dknowc-trusted-search/scripts/render_trace_html.py +27 -22
- package/src/index.js +7 -2
|
@@ -20,10 +20,10 @@ trusted_search 内层(search 模式,需要映射):
|
|
|
20
20
|
(渲染脚本 extract_articles_from_search 只认中文键 data.检索文章)
|
|
21
21
|
knowledge_base_url → knowledgeBase / knowledgeBaseUrl(渲染脚本只认驼峰)
|
|
22
22
|
|
|
23
|
-
deep_query 内层(deep
|
|
24
|
-
|
|
25
|
-
(渲染脚本 extract_articles_from_deep
|
|
26
|
-
|
|
23
|
+
deep_query v3 内层(deep 模式,直通透传):
|
|
24
|
+
{code, msg, data:{searches[], common_articles[], traceId}}
|
|
25
|
+
(渲染脚本 1.1.4+ 的 extract_articles_from_deep 原生解析 v3)
|
|
26
|
+
code=500 转发失败为服务端偶发,透传由调用方重试
|
|
27
27
|
答案不由接口给出,由 Agent 基于材料形成后经 --answer-file 传入
|
|
28
28
|
|
|
29
29
|
用法:
|
|
@@ -88,7 +88,7 @@ def _extract_mcp_text(o: Any) -> Optional[str]:
|
|
|
88
88
|
if isinstance(result, dict):
|
|
89
89
|
return _extract_mcp_text(result)
|
|
90
90
|
# 已是业务 JSON(answer/materials/referenceMaterials 等特征键)
|
|
91
|
-
if any(k in o for k in ("answer", "referenceMaterials", "materials", "检索文章", "progress", "search_meta")):
|
|
91
|
+
if any(k in o for k in ("answer", "referenceMaterials", "materials", "检索文章", "progress", "search_meta", "searches", "common_articles", "code")):
|
|
92
92
|
return json.dumps(o, ensure_ascii=False)
|
|
93
93
|
return None
|
|
94
94
|
|
|
@@ -180,36 +180,18 @@ def _normalize_search(payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
180
180
|
|
|
181
181
|
|
|
182
182
|
def _normalize_deep(payload: Dict[str, Any]) -> Dict[str, Any]:
|
|
183
|
-
"""规范化深度搜索(deep_query
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
"""规范化深度搜索(deep_query v3)返回:透传 v3 的 data.searches/common_articles。
|
|
184
|
+
|
|
185
|
+
v3(2026-08 实测):MCP 内层为 {code, msg, data:{searches[], common_articles[], traceId}}。
|
|
186
|
+
- code=0 成功;code=500 转发失败为服务端偶发问题,原样透传由调用方提示重试
|
|
187
|
+
- searches[]: 每组 {query, areas, result[]},result 为该子查询材料(中文键:
|
|
188
|
+
文章标题/源网址/数据源/发布日期/发布日期可信度/段落)
|
|
189
|
+
- common_articles[]: 多查询公共文章(含 办理地域)
|
|
190
|
+
渲染脚本(1.1.4+)的 extract_articles_from_deep 原生解析该结构,
|
|
191
|
+
此处把内层 JSON 提到顶层(保留 code/msg 供诊断)即可,无需字段映射。
|
|
192
|
+
深度搜索答案仍由 Agent 基于材料综合形成,经 --answer-file 传入渲染。
|
|
186
193
|
"""
|
|
187
194
|
out = dict(payload)
|
|
188
|
-
items: List[Dict[str, Any]] = []
|
|
189
|
-
mats = payload.get("materials")
|
|
190
|
-
if isinstance(mats, list):
|
|
191
|
-
items.extend([m for m in mats if isinstance(m, dict)])
|
|
192
|
-
groups = payload.get("search_groups")
|
|
193
|
-
if isinstance(groups, list):
|
|
194
|
-
for g in groups:
|
|
195
|
-
if isinstance(g, dict) and isinstance(g.get("materials"), list):
|
|
196
|
-
items.extend([m for m in g["materials"] if isinstance(m, dict)])
|
|
197
|
-
elif isinstance(g, dict):
|
|
198
|
-
# search_groups 条目本身可能就是材料(含 title/url 等特征键)
|
|
199
|
-
if any(k in g for k in ("title", "url", "sourceUrl")):
|
|
200
|
-
items.append(g)
|
|
201
|
-
if items:
|
|
202
|
-
# 渲染脚本 extract_articles_from_deep 消费顶层 data.list
|
|
203
|
-
out["data"] = {"list": items}
|
|
204
|
-
# 兼容旧直连 events 形态的防御提取
|
|
205
|
-
if "data" not in out:
|
|
206
|
-
events = payload.get("events")
|
|
207
|
-
if isinstance(events, list):
|
|
208
|
-
out["events"] = events
|
|
209
|
-
kb = payload.get("knowledge_base_url") or payload.get("knowledgeBase") or payload.get("knowledgeBaseUrl")
|
|
210
|
-
if isinstance(kb, str) and kb.strip():
|
|
211
|
-
out["knowledgeBase"] = kb
|
|
212
|
-
out["knowledgeBaseUrl"] = kb
|
|
213
195
|
return out
|
|
214
196
|
|
|
215
197
|
|
|
@@ -221,10 +203,10 @@ def detect_mode(payload: Dict[str, Any]) -> str:
|
|
|
221
203
|
会被误判(materials 为空列表也是 list)。
|
|
222
204
|
"""
|
|
223
205
|
if (
|
|
224
|
-
"
|
|
225
|
-
or isinstance(payload.get("
|
|
226
|
-
or
|
|
227
|
-
or
|
|
206
|
+
isinstance(payload.get("searches"), list)
|
|
207
|
+
or isinstance(payload.get("common_articles"), list)
|
|
208
|
+
or "traceId" in payload
|
|
209
|
+
or "code" in payload
|
|
228
210
|
):
|
|
229
211
|
return "deep"
|
|
230
212
|
if isinstance(payload.get("search_meta"), dict) or (
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""深知可信搜索深度搜索调用脚本。
|
|
3
3
|
|
|
4
|
-
调用 deep-query/
|
|
5
|
-
|
|
4
|
+
调用 deep-query/v3 非流式接口:一次 POST 返回完整 JSON,无 SSE 流式合并步骤。
|
|
5
|
+
适合复杂政策研究、方案设计和多轮查证。
|
|
6
|
+
请求体字段为 query;areas 支持一次传多个地域(逗号分隔),
|
|
7
|
+
服务端按地域自动拆分子查询。返回 data.searches(按子查询分组的材料)、
|
|
8
|
+
data.common_articles(多查询公共文章)与 traceId(链路追踪)。
|
|
6
9
|
"""
|
|
7
10
|
|
|
8
11
|
import argparse
|
|
@@ -14,21 +17,18 @@ import time
|
|
|
14
17
|
import urllib.error
|
|
15
18
|
import urllib.request
|
|
16
19
|
from pathlib import Path
|
|
17
|
-
from typing import Any, Dict,
|
|
20
|
+
from typing import Any, Dict, List, Optional
|
|
18
21
|
|
|
19
22
|
|
|
20
|
-
DEFAULT_ENDPOINT = "https://open.dknowc.cn/api/services/deep-query/
|
|
23
|
+
DEFAULT_ENDPOINT = "https://open.dknowc.cn/api/services/deep-query/v3"
|
|
21
24
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
22
|
-
#
|
|
25
|
+
# 产物根:dsh 会话隔离 <工作区>/dknowc-output/<DSH_SESSION_ID前8位>/;DKNWOC_WS_ROOT 显式优先;无会话回退 _default
|
|
23
26
|
import os as _os
|
|
24
27
|
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
25
28
|
if not _ws:
|
|
26
|
-
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<会话ID前8位>/,
|
|
27
|
-
# 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
|
|
28
29
|
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
29
30
|
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
30
31
|
WS_ROOT = Path(_ws).resolve()
|
|
31
|
-
|
|
32
32
|
SEARCH_RESULTS_DIR = WS_ROOT / "official-docs" / "search-results"
|
|
33
33
|
|
|
34
34
|
|
|
@@ -40,7 +40,7 @@ def resolve_output_json(output_path: str) -> Path:
|
|
|
40
40
|
elif raw_path.parent == Path("."):
|
|
41
41
|
resolved = (SEARCH_RESULTS_DIR / raw_path.name).resolve()
|
|
42
42
|
else:
|
|
43
|
-
resolved = raw_path.resolve()
|
|
43
|
+
resolved = (SKILL_ROOT / raw_path).resolve()
|
|
44
44
|
|
|
45
45
|
if resolved.suffix.lower() != ".json":
|
|
46
46
|
resolved = resolved.with_suffix(".json")
|
|
@@ -58,68 +58,42 @@ def _pick(*values: Optional[str]) -> str:
|
|
|
58
58
|
return ""
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
def
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return
|
|
61
|
+
def _split_areas(value: Optional[str]) -> List[str]:
|
|
62
|
+
"""v3 支持一次传多个地域:按逗号/顿号/分号拆分;单个地域直接使用。"""
|
|
63
|
+
if not value:
|
|
64
|
+
return []
|
|
65
|
+
areas: List[str] = []
|
|
66
|
+
for token in str(value).replace(",", ",").replace("、", ",").replace(";", ",").replace(";", ",").split(","):
|
|
67
|
+
token = token.strip()
|
|
68
|
+
if token and token not in areas:
|
|
69
|
+
areas.append(token)
|
|
70
|
+
return areas
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
def _build_payload(args: argparse.Namespace) -> Dict[str, Any]:
|
|
74
|
-
payload: Dict[str, Any] = {"
|
|
74
|
+
payload: Dict[str, Any] = {"query": args.question}
|
|
75
75
|
|
|
76
|
-
areas = args.area
|
|
76
|
+
areas = _split_areas(args.area)
|
|
77
77
|
if areas:
|
|
78
|
-
payload["areas"] =
|
|
78
|
+
payload["areas"] = areas
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
payload["queryId"] = query_id
|
|
80
|
+
if args.query_id:
|
|
81
|
+
payload["queryId"] = args.query_id
|
|
83
82
|
|
|
84
83
|
return payload
|
|
85
84
|
|
|
86
85
|
|
|
87
|
-
def
|
|
86
|
+
def _post(url: str, api_key: str, payload: Dict[str, Any], timeout: int) -> Dict[str, Any]:
|
|
87
|
+
"""非流式 POST:一次性读取完整 JSON 响应体。"""
|
|
88
88
|
data = json.dumps(payload, ensure_ascii=False).encode("utf-8")
|
|
89
89
|
req = urllib.request.Request(url, data=data, method="POST")
|
|
90
90
|
req.add_header("api-key", api_key)
|
|
91
91
|
req.add_header("Content-Type", "application/json")
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
timings = {"start": time.perf_counter(), "first_event": 0.0, "total": 0.0}
|
|
95
|
-
current_event = "message"
|
|
96
|
-
|
|
93
|
+
started = time.perf_counter()
|
|
97
94
|
try:
|
|
98
95
|
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
99
|
-
|
|
100
|
-
raw_line = resp.readline()
|
|
101
|
-
if not raw_line:
|
|
102
|
-
break
|
|
103
|
-
line = raw_line.decode("utf-8", errors="replace").replace("\x00", "").strip()
|
|
104
|
-
if not line:
|
|
105
|
-
continue
|
|
106
|
-
if line.startswith("event:"):
|
|
107
|
-
current_event = line.split(":", 1)[1].strip() or "message"
|
|
108
|
-
continue
|
|
109
|
-
if not line.startswith("data:"):
|
|
110
|
-
continue
|
|
111
|
-
chunk = line[5:].strip()
|
|
112
|
-
if chunk == "[DONE]":
|
|
113
|
-
break
|
|
114
|
-
try:
|
|
115
|
-
obj = json.loads(chunk)
|
|
116
|
-
except json.JSONDecodeError:
|
|
117
|
-
obj = {"raw": chunk}
|
|
118
|
-
if not timings["first_event"]:
|
|
119
|
-
timings["first_event"] = time.perf_counter() - timings["start"]
|
|
120
|
-
events.append((current_event, obj))
|
|
121
|
-
if current_event == "done":
|
|
122
|
-
break
|
|
96
|
+
text = resp.read().decode("utf-8", errors="replace").replace("\x00", "")
|
|
123
97
|
except urllib.error.HTTPError as e:
|
|
124
98
|
detail = e.read().decode("utf-8", errors="ignore")
|
|
125
99
|
print(f"错误:HTTP {e.code} {detail or e.reason}", file=sys.stderr)
|
|
@@ -130,28 +104,41 @@ def _post_sse(url: str, api_key: str, payload: Dict[str, Any], timeout: int) ->
|
|
|
130
104
|
except socket.timeout:
|
|
131
105
|
print("错误:深度搜索接口请求超时。该接口耗时较长,可适当增大 --timeout。", file=sys.stderr)
|
|
132
106
|
sys.exit(1)
|
|
133
|
-
|
|
134
|
-
timings["total"] = time.perf_counter() - timings["start"]
|
|
135
|
-
|
|
136
|
-
return events, timings
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
def _query_id(events: Iterable[Tuple[str, Dict[str, Any]]]) -> str:
|
|
140
|
-
last = ""
|
|
141
|
-
for _, obj in events:
|
|
142
|
-
value = obj.get("queryId")
|
|
143
|
-
if isinstance(value, str) and value.strip():
|
|
144
|
-
last = value.strip()
|
|
145
|
-
return last
|
|
107
|
+
elapsed = time.perf_counter() - started
|
|
146
108
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return {}
|
|
109
|
+
try:
|
|
110
|
+
body = json.loads(text)
|
|
111
|
+
except json.JSONDecodeError:
|
|
112
|
+
return {"raw": text}
|
|
113
|
+
if isinstance(body, dict):
|
|
114
|
+
body["_elapsedSeconds"] = round(elapsed, 2)
|
|
115
|
+
return body
|
|
116
|
+
return {"data": body, "_elapsedSeconds": round(elapsed, 2)}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _flatten_articles(body: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
120
|
+
"""把 searches[].result 与 common_articles 按源网址去重摊平,供摘要展示。"""
|
|
121
|
+
data = body.get("data") if isinstance(body.get("data"), dict) else {}
|
|
122
|
+
seen: set = set()
|
|
123
|
+
out: List[Dict[str, Any]] = []
|
|
124
|
+
|
|
125
|
+
def add(article: Any) -> None:
|
|
126
|
+
if not isinstance(article, dict):
|
|
127
|
+
return
|
|
128
|
+
key = str(article.get("源网址") or article.get("文章标题") or "")
|
|
129
|
+
if key and key in seen:
|
|
130
|
+
return
|
|
131
|
+
if key:
|
|
132
|
+
seen.add(key)
|
|
133
|
+
out.append(article)
|
|
134
|
+
|
|
135
|
+
for search in data.get("searches") or []:
|
|
136
|
+
if isinstance(search, dict):
|
|
137
|
+
for article in search.get("result") or []:
|
|
138
|
+
add(article)
|
|
139
|
+
for article in data.get("common_articles") or []:
|
|
140
|
+
add(article)
|
|
141
|
+
return out
|
|
155
142
|
|
|
156
143
|
|
|
157
144
|
def _short(text: Any, limit: int = 180) -> str:
|
|
@@ -161,68 +148,67 @@ def _short(text: Any, limit: int = 180) -> str:
|
|
|
161
148
|
return value[:limit].rstrip() + "..."
|
|
162
149
|
|
|
163
150
|
|
|
164
|
-
def _print_summary(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if
|
|
178
|
-
print(f"
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
area =
|
|
200
|
-
|
|
201
|
-
url = vo.get("sourceUrl") or vo.get("url") or ""
|
|
151
|
+
def _print_summary(body: Dict[str, Any], show_materials: int) -> None:
|
|
152
|
+
code = body.get("code")
|
|
153
|
+
msg = body.get("message") or body.get("msg")
|
|
154
|
+
if code not in (0, None) or msg not in ("success", None, ""):
|
|
155
|
+
hint = ";该错误多为服务端转发失败,可稍后重试或调整问题表述" if code == 500 else ""
|
|
156
|
+
print(f"错误:深度搜索接口返回 code={code} {msg or ''}{hint}".strip())
|
|
157
|
+
return
|
|
158
|
+
|
|
159
|
+
data = body.get("data") if isinstance(body.get("data"), dict) else {}
|
|
160
|
+
searches = [s for s in (data.get("searches") or []) if isinstance(s, dict)]
|
|
161
|
+
common = [a for a in (data.get("common_articles") or []) if isinstance(a, dict)]
|
|
162
|
+
|
|
163
|
+
print("深度搜索结果(deep-query/v3 非流式)")
|
|
164
|
+
if body.get("_elapsedSeconds"):
|
|
165
|
+
print(f"总耗时:{body['_elapsedSeconds']:.2f} 秒")
|
|
166
|
+
|
|
167
|
+
if searches:
|
|
168
|
+
print(f"\n子查询分组:共 {len(searches)} 组")
|
|
169
|
+
for s in searches:
|
|
170
|
+
areas = "、".join(str(x) for x in (s.get("areas") or []))
|
|
171
|
+
print(f"- {s.get('query', '')}({areas}):{len(s.get('result') or [])} 篇")
|
|
172
|
+
|
|
173
|
+
articles = _flatten_articles(body)
|
|
174
|
+
if common:
|
|
175
|
+
print(f"\n多查询公共文章:{len(common)} 篇")
|
|
176
|
+
print(f"召回材料(去重后):{len(articles)} 篇")
|
|
177
|
+
if data.get("traceId"):
|
|
178
|
+
print(f"traceId:{data['traceId']}")
|
|
179
|
+
|
|
180
|
+
if articles and show_materials > 0:
|
|
181
|
+
print(f"\n重点材料(前 {min(show_materials, len(articles))} 篇)")
|
|
182
|
+
for idx, item in enumerate(articles[:show_materials], start=1):
|
|
183
|
+
title = item.get("文章标题") or "未命名材料"
|
|
184
|
+
agency = item.get("数据源") or ""
|
|
185
|
+
date = item.get("发布日期") or ""
|
|
186
|
+
area = item.get("办理地域") or ""
|
|
187
|
+
url = item.get("源网址") or ""
|
|
202
188
|
print(f"{idx}. {title}")
|
|
203
|
-
|
|
204
|
-
|
|
189
|
+
meta = [x for x in [agency, area, date] if x]
|
|
190
|
+
if meta:
|
|
191
|
+
print(f" {' | '.join(meta)}")
|
|
192
|
+
paragraphs = item.get("段落") or []
|
|
193
|
+
first_para = next((p.get("内容") for p in paragraphs if isinstance(p, dict) and p.get("内容")), "")
|
|
194
|
+
if first_para:
|
|
195
|
+
print(f" 摘要:{_short(first_para)}")
|
|
205
196
|
if url:
|
|
206
197
|
print(f" 原文:{url}")
|
|
207
198
|
|
|
208
|
-
event_names = [event for event, _ in events]
|
|
209
|
-
if "done" in event_names:
|
|
210
|
-
print("\n状态:检索完成")
|
|
211
|
-
|
|
212
199
|
|
|
213
200
|
def main() -> None:
|
|
214
|
-
parser = argparse.ArgumentParser(description="深知可信搜索 deep-query/
|
|
215
|
-
parser.add_argument("question", help="
|
|
201
|
+
parser = argparse.ArgumentParser(description="深知可信搜索 deep-query/v3 深度搜索调用脚本(非流式)")
|
|
202
|
+
parser.add_argument("question", help="用户复杂问题(请求体字段 query)")
|
|
216
203
|
parser.add_argument("--endpoint", help="覆盖深度搜索接口地址")
|
|
217
|
-
parser.add_argument("--area", help="
|
|
218
|
-
parser.add_argument("--query-id", help="显式传入 queryId
|
|
204
|
+
parser.add_argument("--area", help="办理地域;v3 支持逗号分隔一次传多个地域,服务端按地域拆分子查询")
|
|
205
|
+
parser.add_argument("--query-id", help="显式传入 queryId;默认不传,返回侧以 traceId 做链路追踪")
|
|
219
206
|
parser.add_argument("--show-payload", action="store_true", help="打印请求参数")
|
|
220
207
|
parser.add_argument("--dry-run", action="store_true", help="只打印请求参数,不发起请求")
|
|
221
|
-
parser.add_argument("--
|
|
222
|
-
parser.add_argument("--json-only", action="store_true", help="仅输出结构化 JSON")
|
|
208
|
+
parser.add_argument("--json-only", action="store_true", help="仅输出接口原始 JSON")
|
|
223
209
|
parser.add_argument("--output", "-o", help="深度搜索结果 JSON 文件名,写入 official-docs/search-results/(配合 --json-only 使用)")
|
|
224
|
-
parser.add_argument("--show-materials", type=int, default=5, help="摘要中展示前 N
|
|
225
|
-
parser.add_argument("--timeout", type=int, default=
|
|
210
|
+
parser.add_argument("--show-materials", type=int, default=5, help="摘要中展示前 N 篇材料")
|
|
211
|
+
parser.add_argument("--timeout", type=int, default=300, help="请求超时秒数")
|
|
226
212
|
args = parser.parse_args()
|
|
227
213
|
|
|
228
214
|
endpoint = _pick(
|
|
@@ -246,26 +232,20 @@ def main() -> None:
|
|
|
246
232
|
if args.dry_run:
|
|
247
233
|
return
|
|
248
234
|
|
|
249
|
-
|
|
235
|
+
body = _post(endpoint, api_key, payload, args.timeout)
|
|
250
236
|
|
|
251
237
|
if args.json_only:
|
|
252
|
-
raw_json = json.dumps(
|
|
238
|
+
raw_json = json.dumps(body, ensure_ascii=False, indent=2)
|
|
253
239
|
if args.output:
|
|
254
240
|
output_path = resolve_output_json(args.output)
|
|
255
241
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
256
242
|
output_path.write_text(raw_json, encoding="utf-8")
|
|
257
|
-
print(f"已保存深度搜索结果 JSON:{
|
|
243
|
+
print(f"已保存深度搜索结果 JSON:{output_path.relative_to(SKILL_ROOT)}")
|
|
258
244
|
else:
|
|
259
245
|
print(raw_json)
|
|
260
246
|
return
|
|
261
247
|
|
|
262
|
-
|
|
263
|
-
for event, obj in events:
|
|
264
|
-
print(f"event:{event}")
|
|
265
|
-
print(json.dumps(obj, ensure_ascii=False))
|
|
266
|
-
return
|
|
267
|
-
|
|
268
|
-
_print_summary(events, timings, args.show_materials)
|
|
248
|
+
_print_summary(body, args.show_materials)
|
|
269
249
|
|
|
270
250
|
|
|
271
251
|
if __name__ == "__main__":
|
|
@@ -13,16 +13,13 @@ from typing import Any, Dict, Iterable, List, Optional
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
16
|
-
#
|
|
16
|
+
# 产物根:dsh 会话隔离 <工作区>/dknowc-output/<DSH_SESSION_ID前8位>/;DKNWOC_WS_ROOT 显式优先;无会话回退 _default
|
|
17
17
|
import os as _os
|
|
18
18
|
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
19
19
|
if not _ws:
|
|
20
|
-
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<会话ID前8位>/,
|
|
21
|
-
# 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
|
|
22
20
|
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
23
21
|
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
24
22
|
WS_ROOT = Path(_ws).resolve()
|
|
25
|
-
|
|
26
23
|
SEARCH_RESULTS_DIR = WS_ROOT / "official-docs" / "search-results"
|
|
27
24
|
OUTPUT_DIR = WS_ROOT / "official-docs" / "output"
|
|
28
25
|
|
|
@@ -216,25 +213,33 @@ def extract_articles_from_search(payload: Dict[str, Any]) -> List[Dict[str, Any]
|
|
|
216
213
|
|
|
217
214
|
|
|
218
215
|
def extract_articles_from_deep(payload: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
219
|
-
|
|
220
|
-
if isinstance(events, list):
|
|
221
|
-
for event in events:
|
|
222
|
-
if isinstance(event, list) and len(event) == 2:
|
|
223
|
-
name, obj = event
|
|
224
|
-
elif isinstance(event, dict):
|
|
225
|
-
name, obj = event.get("event"), event
|
|
226
|
-
else:
|
|
227
|
-
continue
|
|
228
|
-
if name == "result" and isinstance(obj, dict):
|
|
229
|
-
data = obj.get("data")
|
|
230
|
-
result_list = data.get("list") if isinstance(data, dict) else None
|
|
231
|
-
if isinstance(result_list, list):
|
|
232
|
-
return [x for x in result_list if isinstance(x, dict)]
|
|
216
|
+
"""深度搜索 deep-query/v3 非流式格式:{"data": {"searches": [{"result": [...]}], "common_articles": [...]}}。"""
|
|
233
217
|
data = payload.get("data")
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
218
|
+
if not isinstance(data, dict):
|
|
219
|
+
return []
|
|
220
|
+
searches = data.get("searches")
|
|
221
|
+
if not isinstance(searches, list):
|
|
222
|
+
return []
|
|
223
|
+
seen: set = set()
|
|
224
|
+
out: List[Dict[str, Any]] = []
|
|
225
|
+
|
|
226
|
+
def _add(article: Any) -> None:
|
|
227
|
+
if not isinstance(article, dict):
|
|
228
|
+
return
|
|
229
|
+
key = str(article.get("源网址") or article.get("文章标题") or "")
|
|
230
|
+
if key and key in seen:
|
|
231
|
+
return
|
|
232
|
+
if key:
|
|
233
|
+
seen.add(key)
|
|
234
|
+
out.append(article)
|
|
235
|
+
|
|
236
|
+
for search in searches:
|
|
237
|
+
if isinstance(search, dict):
|
|
238
|
+
for article in search.get("result") or []:
|
|
239
|
+
_add(article)
|
|
240
|
+
for article in data.get("common_articles") or []:
|
|
241
|
+
_add(article)
|
|
242
|
+
return out
|
|
238
243
|
|
|
239
244
|
|
|
240
245
|
def extract_reference_materials(payload: Dict[str, Any]) -> List[Dict[str, Any]]:
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* dknowc-dsh —— 深知可信办公全家桶 skill provider
|
|
3
3
|
*
|
|
4
|
-
* 把
|
|
5
|
-
* dknowc-official-doc-writer)注册进 dsh 的 `ctx.skills`,使它们出现在
|
|
4
|
+
* 把 4 个内嵌 skill(dknowc-trusted-consulting / dknowc-trusted-search /
|
|
5
|
+
* dknowc-ppt-assistant / dknowc-official-doc-writer)注册进 dsh 的 `ctx.skills`,使它们出现在
|
|
6
6
|
* 会话的 <available_skills> 目录中,可被模型的 `skill` 工具加载。
|
|
7
7
|
*
|
|
8
8
|
* 注册范式对照官方 `@deepseek-ai/dsh-skill-badge`:
|
|
@@ -27,6 +27,11 @@ const SKILLS = [
|
|
|
27
27
|
description:
|
|
28
28
|
'当用户需要检索权威材料、政策法规/标准原文、政策清单、可点击溯源、知识专库、多地域政策素材收集与对比核验、企业补贴与税惠材料核验、合规依据核验,或明确要求深度搜索、深度分析、全面查找、多轮核验、完整调研方案时,使用深知可信搜索。本 skill 负责检索与核验材料,交付直接答案、可点击溯源 HTML 与干净 Markdown;如用户要求把素材写成正式报告、调研报告、分析报告或公文(如"帮我写一份××报告"),应改用深知公文写作。',
|
|
29
29
|
},
|
|
30
|
+
{
|
|
31
|
+
name: 'dknowc-ppt-assistant',
|
|
32
|
+
description:
|
|
33
|
+
'当用户要求制作 PPT、演示文稿、汇报 PPT、课件、宣讲材料、把材料转成 PPT、做幻灯片,或要求可编辑原生 PPT、多版式(16:9/4:3/小红书/竖版/A4)输出时,使用深知可信PPT。约束 SVG 逐页创作 + 确定性编译为原生可编辑 PowerPoint(真实形状/文本/图表/表格,非整页图片);素材检索经深知可信工作台 MCP(trusted_search)全程可溯源,交付 .pptx 与可信溯源核验报告。注意区分:写文字材料/Word/红头用公文写作 skill;只检索材料不成稿用可信搜索 skill。',
|
|
34
|
+
},
|
|
30
35
|
{
|
|
31
36
|
name: 'dknowc-official-doc-writer',
|
|
32
37
|
description:
|