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,16 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""深知可信搜索 SkillHub / WorkBuddy public 版初始化检查。
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
API Key 读取:优先进程环境变量 DKNOWC_API_KEY,缺失时从 ~/.zshrc 兜底解析
|
|
5
|
+
(宿主进程早于 key 写入启动、或宿主安全更新后不再加载 zshrc 导出变量时不误报缺失)。
|
|
6
|
+
注册脚本 register_key.mjs 注册成功后会自动把 Key 写入 ~/.zshrc 标记块,本检查直读该文件,
|
|
7
|
+
无需重启宿主。不读取、不写入本地 config.ini 中的 Key。
|
|
5
8
|
"""
|
|
6
9
|
|
|
7
10
|
import json
|
|
8
11
|
import os
|
|
12
|
+
import shutil
|
|
13
|
+
import sys
|
|
14
|
+
from pathlib import Path
|
|
9
15
|
|
|
10
16
|
|
|
11
17
|
API_KEY_ENV = "DKNOWC_API_KEY"
|
|
18
|
+
MAAS_PLATFORM_URL = "https://platform.dknowc.cn/auth/#/login"
|
|
12
19
|
PLACEHOLDER_KEYS = {"", "your_api_key_here", "你的深知可信搜索 API Key", "你的深知搜索 API Key"}
|
|
13
20
|
|
|
21
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
22
|
+
|
|
14
23
|
|
|
15
24
|
def _looks_like_key(value: str) -> bool:
|
|
16
25
|
value = (value or "").strip()
|
|
@@ -18,44 +27,62 @@ def _looks_like_key(value: str) -> bool:
|
|
|
18
27
|
|
|
19
28
|
|
|
20
29
|
def _in_dsh() -> bool:
|
|
21
|
-
"""dsh 环境标志:dsh 的 bash 工具会注入 DSH_SHELL=1。
|
|
22
|
-
|
|
23
|
-
dsh 场景下,脚本子进程无法隐式继承 DKNOWC_API_KEY(dsh 安全机制会清理
|
|
24
|
-
名字含 KEY 的环境变量),但 dsh 插件会通过 shell-env 显式通道把该 Key
|
|
25
|
-
注入为 DSH_DKNOWC_API_KEY。因此检查 DSH_DKNOWC_API_KEY 即可真实判断
|
|
26
|
-
"dsh 主进程环境变量是否已配置 DKNOWC_API_KEY"。
|
|
27
|
-
"""
|
|
30
|
+
"""dsh 环境标志:dsh 的 bash 工具会注入 DSH_SHELL=1。"""
|
|
28
31
|
return os.environ.get("DSH_SHELL") == "1"
|
|
29
32
|
|
|
30
33
|
|
|
31
34
|
def check_api_key_config():
|
|
35
|
+
# dsh 场景:优先插件经 shell-env 注入的 DSH_DKNOWC_API_KEY(与 MCP Bearer 同源,
|
|
36
|
+
# 来源为 dsh 主进程环境变量 DKNOWC_API_KEY);缺失时本地环境变量 / ~/.zshrc 兜底
|
|
37
|
+
# (注册成功自动持久化后、dsh 重启前的窗口期不误报缺失)。
|
|
32
38
|
if _in_dsh():
|
|
33
|
-
# dsh 场景:读取插件注入的 DSH_DKNOWC_API_KEY(来源为 dsh 主进程的 DKNOWC_API_KEY)
|
|
34
39
|
api_key = os.environ.get("DSH_DKNOWC_API_KEY", "").strip()
|
|
40
|
+
source = "environment"
|
|
41
|
+
if not _looks_like_key(api_key):
|
|
42
|
+
try:
|
|
43
|
+
from api_key import resolve_api_key
|
|
44
|
+
api_key2, source2 = resolve_api_key()
|
|
45
|
+
if _looks_like_key(api_key2):
|
|
46
|
+
api_key, source = api_key2, source2
|
|
47
|
+
except ImportError:
|
|
48
|
+
pass
|
|
35
49
|
if _looks_like_key(api_key):
|
|
50
|
+
note = None
|
|
51
|
+
if source == "zshrc":
|
|
52
|
+
note = ("dsh 场景:Key 已持久化在 ~/.zshrc。当前 dsh 主进程环境变量尚未加载该 Key——"
|
|
53
|
+
"本会话的 MCP Bearer 认证在启动时已冻结,请经 scripts/mcp_direct.py 直调完成当前任务"
|
|
54
|
+
"(脚本会自动从 ~/.zshrc 解析 Key);重启 dsh 或新开会话后自动恢复正常 MCP 转接。")
|
|
36
55
|
return {
|
|
37
56
|
"api_key_configured": True,
|
|
38
|
-
"api_key_env":
|
|
39
|
-
"api_key_source":
|
|
57
|
+
"api_key_env": API_KEY_ENV,
|
|
58
|
+
"api_key_source": source,
|
|
40
59
|
"api_key_hint": None,
|
|
41
60
|
"search_ready": True,
|
|
42
|
-
"search_note":
|
|
61
|
+
"search_note": note,
|
|
43
62
|
}
|
|
44
63
|
return {
|
|
45
64
|
"api_key_configured": False,
|
|
46
65
|
"api_key_env": API_KEY_ENV,
|
|
47
66
|
"api_key_source": None,
|
|
48
|
-
"api_key_hint": f"未检测到可用的 {API_KEY_ENV}(dsh
|
|
67
|
+
"api_key_hint": f"未检测到可用的 {API_KEY_ENV}(dsh 主进程环境变量与 ~/.zshrc 中均未找到)。需要先将有效的 API Key 配置到启动 dsh 的环境变量 {API_KEY_ENV}(如 ~/.zshrc),再重启 dsh 或新建会话。",
|
|
49
68
|
"search_ready": False,
|
|
50
|
-
"search_note": f"当前缺少 {API_KEY_ENV}
|
|
69
|
+
"search_note": f"当前缺少 {API_KEY_ENV},暂时不能查询政策法规、办事流程、标准依据和可信溯源内容。",
|
|
51
70
|
}
|
|
52
71
|
|
|
53
|
-
|
|
72
|
+
# 环境变量优先,缺失时从 ~/.zshrc 兜底解析
|
|
73
|
+
api_key = ""
|
|
74
|
+
source = ""
|
|
75
|
+
try:
|
|
76
|
+
from api_key import resolve_api_key
|
|
77
|
+
api_key, source = resolve_api_key()
|
|
78
|
+
except ImportError:
|
|
79
|
+
api_key = os.environ.get(API_KEY_ENV, "").strip()
|
|
80
|
+
source = "environment" if api_key else ""
|
|
54
81
|
if _looks_like_key(api_key):
|
|
55
82
|
return {
|
|
56
83
|
"api_key_configured": True,
|
|
57
84
|
"api_key_env": API_KEY_ENV,
|
|
58
|
-
"api_key_source": "environment",
|
|
85
|
+
"api_key_source": source or "environment",
|
|
59
86
|
"api_key_hint": None,
|
|
60
87
|
"search_ready": True,
|
|
61
88
|
"search_note": None,
|
|
@@ -77,11 +104,32 @@ def main():
|
|
|
77
104
|
if not status["api_key_configured"]:
|
|
78
105
|
blocking_issues.append("api_key_missing")
|
|
79
106
|
|
|
107
|
+
# node 运行时只影响注册链路(register_key.mjs),检索本身用 python3 即可,不作为阻断项。
|
|
108
|
+
node_available = shutil.which("node") is not None
|
|
109
|
+
|
|
80
110
|
print(json.dumps({
|
|
81
111
|
**status,
|
|
112
|
+
"python_executable": sys.executable,
|
|
113
|
+
"node_available": node_available,
|
|
82
114
|
"blocking_issues": blocking_issues,
|
|
83
115
|
"ready": not blocking_issues,
|
|
84
|
-
|
|
116
|
+
# guide_message:需要检索但 Key 未配置时给用户的引导话术(S1 三段式:价值 / 开通方式 / 退路+样例钩子)。
|
|
117
|
+
# Agent 在检索方向确认后向用户转述本话术(可结合任务补充上下文),要素不得删改。
|
|
118
|
+
"guide_message": None if status["api_key_configured"] else (
|
|
119
|
+
"这个问题涉及政策口径和具体数字——普通搜索结果来源杂、无法核验,凭印象答政策名和数字,口径错了会影响你的判断和决策。"
|
|
120
|
+
"开通权威检索后,每条政策、数据都带原文出处、可点开核验,还会附一份可点击的溯源报告。\n"
|
|
121
|
+
"开通是免费的:自带 300 次权威检索额度,完成实名认证还能再领 100 元体验金。"
|
|
122
|
+
"只需手机号收一次验证码——两步、约 10 秒,不用去网站,剩下的我来办;手机号仅用于本次验证,不会有营销骚扰。\n"
|
|
123
|
+
"也可以先不开通:我先基于已有知识给你一版初步回答,涉及政策口径、数字的地方逐条标注\"依据待核验\","
|
|
124
|
+
"并说明未联网检索、口径可能过期。想先看看开通后检索结果和溯源报告长什么样,我可以发你示例看看。"
|
|
125
|
+
),
|
|
126
|
+
# env_message:注册所需运行环境缺失时给用户的统一话术——不暴露组件名(node 对用户无意义);
|
|
127
|
+
# 就绪时不输出任何环境话题。完整场景话术见 reference/onboarding_scripts.md S6。
|
|
128
|
+
"env_message": (
|
|
129
|
+
"检测到本机开通检索还差一个小程序环境(约 1 分钟,只装一次),我现在装好可以吗?"
|
|
130
|
+
if not node_available else None
|
|
131
|
+
),
|
|
132
|
+
"maas_platform_url": MAAS_PLATFORM_URL,
|
|
85
133
|
}, ensure_ascii=False, indent=2))
|
|
86
134
|
|
|
87
135
|
|
|
@@ -119,6 +119,14 @@ def main() -> int:
|
|
|
119
119
|
args = parser.parse_args()
|
|
120
120
|
|
|
121
121
|
api_key = os.environ.get(API_KEY_ENV, "").strip()
|
|
122
|
+
if not api_key:
|
|
123
|
+
# dsh 兜底:注册成功后 Key 已自动写入 ~/.zshrc(register_key.mjs 持久化),
|
|
124
|
+
# 本进程环境变量可能未注入——从 ~/.zshrc 解析(api_key.py 同源逻辑)。
|
|
125
|
+
try:
|
|
126
|
+
from api_key import resolve_api_key
|
|
127
|
+
api_key, _src = resolve_api_key()
|
|
128
|
+
except ImportError:
|
|
129
|
+
pass
|
|
122
130
|
if not api_key:
|
|
123
131
|
print(f"错误:缺少环境变量 {API_KEY_ENV}(请用 DKNOWC_API_KEY=<key> 前缀赋值方式传入)。", file=sys.stderr)
|
|
124
132
|
return 2
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// MaaS
|
|
3
|
-
//
|
|
4
|
-
// node register_key.mjs
|
|
5
|
-
//
|
|
2
|
+
// 国内 MaaS headless 注册助手(供 skillhub skill 调用;纯 node,内置 fetch,无三方依赖)。
|
|
3
|
+
// node register_key.mjs [--base URL] send --phone <p>
|
|
4
|
+
// node register_key.mjs [--base URL] register --phone <p> --vcode <c> [--type 11] [--organ ..] [--name ..] [--channel ..] [--source ..] [--password ..] [--new-key] [--no-zshrc]
|
|
5
|
+
// 无需 cookie / 加密 / 登录态。注册成功后自动把 API Key 写入 ~/.zshrc 标记块(--no-zshrc 跳过);
|
|
6
|
+
// 业务脚本从 ~/.zshrc 直读,无需重启宿主。默认打生产,--base 可切测试环境。
|
|
7
|
+
|
|
8
|
+
import fs from "fs";
|
|
9
|
+
import os from "os";
|
|
10
|
+
import path from "path";
|
|
6
11
|
|
|
7
12
|
const DEFAULT_BASE = "https://platform.dknowc.cn/auth/home/userAuto";
|
|
8
13
|
const DEFAULT_OPEN_BASE = "https://open.dknowc.cn";
|
|
@@ -10,7 +15,21 @@ const DEFAULT_CHANNEL = "46A3BA1D-3E1A-4E8C-BD50-A6DCBEE1DB05";
|
|
|
10
15
|
const DEFAULT_TYPE = "11";
|
|
11
16
|
const DEFAULT_SOURCE = "agent";
|
|
12
17
|
const API_KEY_ENV = "DKNOWC_API_KEY";
|
|
13
|
-
const MAAS_PLATFORM_URL = "https://platform.dknowc.cn/";
|
|
18
|
+
const MAAS_PLATFORM_URL = "https://platform.dknowc.cn/auth/#/login";
|
|
19
|
+
const FALLBACK_REGISTER_URL = MAAS_PLATFORM_URL;
|
|
20
|
+
const ZSHRC_START = "# >>> dknowc trusted search api key >>>";
|
|
21
|
+
const ZSHRC_END = "# <<< dknowc trusted search api key <<<";
|
|
22
|
+
|
|
23
|
+
function maskPhone(phone) {
|
|
24
|
+
const p = String(phone || "");
|
|
25
|
+
return p.length >= 7 ? `${p.slice(0, 3)}****${p.slice(-4)}` : p;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function maskKey(apiKey) {
|
|
29
|
+
if (!apiKey) return null;
|
|
30
|
+
if (apiKey.length <= 12) return "***";
|
|
31
|
+
return `${apiKey.slice(0, 7)}...${apiKey.slice(-4)}`;
|
|
32
|
+
}
|
|
14
33
|
|
|
15
34
|
function parseArgs(argv) {
|
|
16
35
|
const out = { _: [] };
|
|
@@ -85,10 +104,42 @@ async function createNewApiKey(openBase, existingApiKey, name, remark) {
|
|
|
85
104
|
return { result, apiKey };
|
|
86
105
|
}
|
|
87
106
|
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
107
|
+
function shellSingleQuote(value) {
|
|
108
|
+
return `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function escapeRegExp(value) {
|
|
112
|
+
return String(value).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function writeApiKeyToZshrc(apiKey) {
|
|
116
|
+
const zshrcPath = path.join(os.homedir(), ".zshrc");
|
|
117
|
+
const block = [
|
|
118
|
+
ZSHRC_START,
|
|
119
|
+
`export ${API_KEY_ENV}=${shellSingleQuote(apiKey)}`,
|
|
120
|
+
ZSHRC_END,
|
|
121
|
+
"",
|
|
122
|
+
].join("\n");
|
|
123
|
+
let existing = "";
|
|
124
|
+
try {
|
|
125
|
+
existing = fs.existsSync(zshrcPath) ? fs.readFileSync(zshrcPath, "utf8") : "";
|
|
126
|
+
} catch (error) {
|
|
127
|
+
const msg = error && error.message ? error.message : String(error);
|
|
128
|
+
return { written: false, path: zshrcPath, error: msg };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const pattern = new RegExp(`${escapeRegExp(ZSHRC_START)}[\\s\\S]*?${escapeRegExp(ZSHRC_END)}\\n?`, "m");
|
|
132
|
+
const next = pattern.test(existing)
|
|
133
|
+
? existing.replace(pattern, block)
|
|
134
|
+
: `${existing}${existing && !existing.endsWith("\n") ? "\n" : ""}${block}`;
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
fs.writeFileSync(zshrcPath, next, { encoding: "utf8", mode: 0o600 });
|
|
138
|
+
return { written: true, path: zshrcPath, error: null };
|
|
139
|
+
} catch (error) {
|
|
140
|
+
const msg = error && error.message ? error.message : String(error);
|
|
141
|
+
return { written: false, path: zshrcPath, error: msg };
|
|
142
|
+
}
|
|
92
143
|
}
|
|
93
144
|
|
|
94
145
|
async function main() {
|
|
@@ -101,12 +152,23 @@ async function main() {
|
|
|
101
152
|
console.error("缺少 --phone");
|
|
102
153
|
process.exit(2);
|
|
103
154
|
}
|
|
155
|
+
// 渠道细分:sendMessage 与 register 请求体统一携带 SkillHub 渠道码。
|
|
104
156
|
const result = await postJson(`${base}/sendMessage`, {
|
|
105
157
|
phone: args.phone,
|
|
106
158
|
type: "register",
|
|
107
159
|
channel: args.channel && args.channel !== true ? args.channel : DEFAULT_CHANNEL,
|
|
108
160
|
});
|
|
109
|
-
|
|
161
|
+
// user_message:给用户的固定话术,Agent 必须原样转述,不得改写后发挥
|
|
162
|
+
let userMessage;
|
|
163
|
+
if (result.status) {
|
|
164
|
+
userMessage = `验证码已发送到 ${maskPhone(args.phone)},请把最新一条短信里的 6 位验证码发我。`;
|
|
165
|
+
} else if (String(result.msg || "").includes("手机号")) {
|
|
166
|
+
userMessage = "这个手机号格式好像不对,麻烦核对一下再发我。";
|
|
167
|
+
} else {
|
|
168
|
+
userMessage = `验证码发送没成功(可能是网络或短信通道问题),可以再试一次;如果连续失败,也可以用网页方式开通:${FALLBACK_REGISTER_URL}`;
|
|
169
|
+
}
|
|
170
|
+
console.log(JSON.stringify({ ...result, user_message: userMessage }));
|
|
171
|
+
if (result.status) console.error("验证码已发送(话术见 user_message,请向用户转述后索取 6 位验证码)。");
|
|
110
172
|
process.exit(result.status ? 0 : 1);
|
|
111
173
|
}
|
|
112
174
|
|
|
@@ -130,11 +192,11 @@ async function main() {
|
|
|
130
192
|
|
|
131
193
|
const result = await postJson(`${base}/register`, payload);
|
|
132
194
|
const data = result.data || {};
|
|
133
|
-
|
|
195
|
+
const ok = Boolean(result.status) && Boolean(data.apiKey);
|
|
196
|
+
let apiKeyToSave = ok ? data.apiKey : "";
|
|
134
197
|
let newKeyCreated = false;
|
|
135
198
|
let newKeyError = null;
|
|
136
|
-
|
|
137
|
-
if (apiKey && args["new-key"]) {
|
|
199
|
+
if (ok && args["new-key"]) {
|
|
138
200
|
const keyName = args["new-key-name"] && args["new-key-name"] !== true
|
|
139
201
|
? args["new-key-name"]
|
|
140
202
|
: payload.apiKeyName;
|
|
@@ -143,36 +205,61 @@ async function main() {
|
|
|
143
205
|
: "由 SkillHub 深知可信搜索按用户要求重新生成";
|
|
144
206
|
const created = await createNewApiKey(
|
|
145
207
|
args["open-base"] && args["open-base"] !== true ? args["open-base"] : DEFAULT_OPEN_BASE,
|
|
146
|
-
apiKey,
|
|
208
|
+
data.apiKey,
|
|
147
209
|
keyName,
|
|
148
210
|
keyRemark,
|
|
149
211
|
);
|
|
150
212
|
if (created.apiKey) {
|
|
151
|
-
|
|
213
|
+
apiKeyToSave = created.apiKey;
|
|
152
214
|
newKeyCreated = true;
|
|
153
215
|
} else {
|
|
154
|
-
|
|
216
|
+
// 新建失败:沿用原密钥继续(不中断用户任务),newKeyCreated=false 明确区分新旧
|
|
155
217
|
newKeyError = created.result.errmsg || created.result.msg || "新 API Key 创建失败";
|
|
156
218
|
}
|
|
157
219
|
}
|
|
158
|
-
|
|
220
|
+
const zshrcWrite = ok && apiKeyToSave && !args["no-zshrc"]
|
|
221
|
+
? writeApiKeyToZshrc(apiKeyToSave)
|
|
222
|
+
: { written: false, path: path.join(os.homedir(), ".zshrc"), error: null };
|
|
223
|
+
// user_message:给用户的固定话术,Agent 必须原样转述,不得改写后发挥。
|
|
224
|
+
// 权益告知(300 次额度 + 实名认证赠金)已前移到开通引导(initialize.guide_message / onboarding_scripts S1),
|
|
225
|
+
// 此处只做轻确认,避免成功节点信息过重导致转述截断。
|
|
226
|
+
let userMessage;
|
|
227
|
+
if (ok && apiKeyToSave) {
|
|
228
|
+
userMessage = Boolean(data.existed)
|
|
229
|
+
? `这个手机号之前开通过,已直接找回原来的密钥和额度,不用重新注册。我马上开始检索。`
|
|
230
|
+
: `开通成功,访问密钥已写入本机,300 次免费检索额度已生效。我马上开始检索。`;
|
|
231
|
+
if (newKeyError) {
|
|
232
|
+
userMessage += ` 另外你要求的新密钥生成失败(${newKeyError}),已先沿用现有密钥继续,不影响使用;需要的话稍后再重新生成。`;
|
|
233
|
+
}
|
|
234
|
+
} else if (String(result.msg || "").includes("验证码")) {
|
|
235
|
+
userMessage = `验证码校验没通过(可能是输入有误或已过期)。请核对 ${maskPhone(args.phone)} 最新一条短信的 6 位验证码重新发我;需要我重新发送一条,直接说一声。`;
|
|
236
|
+
} else {
|
|
237
|
+
userMessage = `开通服务暂时没连上(${result.msg || "网络波动"}),可以稍后再试,或用网页方式开通:${FALLBACK_REGISTER_URL}`;
|
|
238
|
+
}
|
|
159
239
|
console.log(JSON.stringify({
|
|
160
|
-
status: Boolean(
|
|
240
|
+
status: ok && Boolean(apiKeyToSave),
|
|
161
241
|
msg: result.msg,
|
|
162
242
|
url: data.url || null,
|
|
163
243
|
existed: Boolean(data.existed),
|
|
164
244
|
keyCreatedByRegister: Boolean(data.keyCreated),
|
|
165
245
|
newKeyRequested: Boolean(args["new-key"]),
|
|
166
246
|
newKeyCreated,
|
|
247
|
+
user_message: userMessage,
|
|
167
248
|
envName: API_KEY_ENV,
|
|
168
|
-
apiKey,
|
|
169
|
-
apiKeyMasked: maskKey(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
249
|
+
apiKey: apiKeyToSave,
|
|
250
|
+
apiKeyMasked: maskKey(apiKeyToSave),
|
|
251
|
+
envWriteRequired: false,
|
|
252
|
+
envWriteTarget: zshrcWrite.path,
|
|
253
|
+
envWriteSucceeded: Boolean(zshrcWrite.written),
|
|
254
|
+
envWriteError: zshrcWrite.error,
|
|
255
|
+
envWriteInstruction: zshrcWrite.written
|
|
256
|
+
? `已写入 ${zshrcWrite.path};脚本直读该文件,无需重启宿主。当前任务可继续使用返回的 apiKey。`
|
|
257
|
+
: `未能写入 ${zshrcWrite.path},请由 Agent 或平台密钥配置将返回的 apiKey 写入环境变量 ${API_KEY_ENV}。`,
|
|
258
|
+
currentSessionInstruction: `当前任务继续执行初始化时,请用本次返回的 apiKey 临时注入环境变量 ${API_KEY_ENV},不得向用户展示完整 Key。`,
|
|
173
259
|
newKeyError,
|
|
260
|
+
fallbackRegisterUrl: FALLBACK_REGISTER_URL,
|
|
174
261
|
}));
|
|
175
|
-
process.exit(
|
|
262
|
+
process.exit(ok && Boolean(apiKeyToSave) ? 0 : 1);
|
|
176
263
|
}
|
|
177
264
|
|
|
178
265
|
console.error("用法: node register_key.mjs <send|register> ...");
|
|
@@ -20,16 +20,15 @@ from typing import Any, Dict, Iterable, List, Optional, Tuple
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
23
|
-
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到
|
|
23
|
+
# 工作区根:dsh 场景通过环境变量 DKNWOC_WS_ROOT 指向会话工作区,未设置时回退到 cwd
|
|
24
24
|
import os as _os
|
|
25
25
|
_ws = _os.environ.get("DKNWOC_WS_ROOT")
|
|
26
26
|
if not _ws:
|
|
27
|
-
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output
|
|
27
|
+
# dsh 会话隔离:每会话独立产物目录 <工作区>/dknowc-output/<DSH_SESSION_ID前8位>/,
|
|
28
28
|
# 多会话共用同一工作区时互不混杂;非 dsh 环境回退为工作区本身。
|
|
29
29
|
_sid = _os.environ.get("DSH_SESSION_ID", "")
|
|
30
30
|
_ws = str(Path(_os.getcwd()) / "dknowc-output" / (_sid[:8] if _sid else "_default"))
|
|
31
31
|
WS_ROOT = Path(_ws).resolve()
|
|
32
|
-
|
|
33
32
|
SEARCH_RESULTS_DIR = WS_ROOT / "official-docs" / "search-results"
|
|
34
33
|
OUTPUT_DIR = WS_ROOT / "official-docs" / "output"
|
|
35
34
|
|