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,7 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""深知可信咨询
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
"""深知可信咨询 dsh 版初始化检查。
|
|
3
|
+
|
|
4
|
+
API Key 解析(dsh 场景三级):
|
|
5
|
+
1. 插件经 shell-env 显式注入的 DSH_DKNOWC_API_KEY——来源为 dsh 主进程环境变量
|
|
6
|
+
DKNOWC_API_KEY(dsh 安全机制会清理名字含 KEY 的隐式环境变量,子进程读不到
|
|
7
|
+
原始 DKNOWC_API_KEY,MCP Bearer 与主进程同源);
|
|
8
|
+
2. 进程环境变量 DKNOWC_API_KEY(本地裸跑 / 临时前缀注入);
|
|
9
|
+
3. ~/.zshrc 兜底解析——注册成功后 register_key.mjs 会自动把 Key 持久化到
|
|
10
|
+
~/.zshrc,dsh 主进程在该写入之后、重启之前的窗口期内环境变量还没有它,
|
|
11
|
+
此时不应误报缺失(api_key.py 同源逻辑)。
|
|
12
|
+
不读取、不写入本地 config.ini 中的 Key。
|
|
5
13
|
"""
|
|
6
14
|
|
|
7
15
|
import json
|
|
@@ -18,44 +26,64 @@ def _looks_like_key(value: str) -> bool:
|
|
|
18
26
|
|
|
19
27
|
|
|
20
28
|
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
|
-
"""
|
|
29
|
+
"""dsh 环境标志:dsh 的 bash 工具会注入 DSH_SHELL=1。"""
|
|
28
30
|
return os.environ.get("DSH_SHELL") == "1"
|
|
29
31
|
|
|
30
32
|
|
|
33
|
+
def _resolve_zshrc_key() -> tuple[str, str]:
|
|
34
|
+
"""从 ~/.zshrc 解析已持久化的 Key(api_key.py 同源兜底)。"""
|
|
35
|
+
try:
|
|
36
|
+
from api_key import resolve_api_key
|
|
37
|
+
return resolve_api_key()
|
|
38
|
+
except ImportError:
|
|
39
|
+
return "", ""
|
|
40
|
+
|
|
41
|
+
|
|
31
42
|
def check_api_key_config():
|
|
32
43
|
if _in_dsh():
|
|
33
|
-
# dsh
|
|
44
|
+
# dsh 场景:优先插件注入的 DSH_DKNOWC_API_KEY(与 MCP Bearer 同源)
|
|
34
45
|
api_key = os.environ.get("DSH_DKNOWC_API_KEY", "").strip()
|
|
46
|
+
source = "environment"
|
|
47
|
+
note = "dsh 场景:接口经深知可信工作台 MCP 转接(credible_chat),API Key 由 dsh 主进程环境变量 DKNOWC_API_KEY 提供(经 shell-env 显式注入为 DSH_DKNOWC_API_KEY)。"
|
|
48
|
+
if not _looks_like_key(api_key):
|
|
49
|
+
# 兜底:本地裸跑前缀注入 / ~/.zshrc 持久化(注册自动写入后、dsh 重启前)
|
|
50
|
+
api_key2, source2 = _resolve_zshrc_key()
|
|
51
|
+
if _looks_like_key(api_key2):
|
|
52
|
+
api_key, source = api_key2, source2
|
|
53
|
+
note = (
|
|
54
|
+
"dsh 场景:Key 已持久化在 ~/.zshrc(api_key_source=zshrc)。"
|
|
55
|
+
"当前 dsh 主进程环境变量尚未加载该 Key——本会话的 MCP Bearer 认证在启动时已冻结,"
|
|
56
|
+
"请经 scripts/mcp_direct.py 直调完成当前任务(脚本会自动从 ~/.zshrc 解析 Key);"
|
|
57
|
+
"重启 dsh 或新开会话后自动恢复正常 MCP 转接。"
|
|
58
|
+
)
|
|
35
59
|
if _looks_like_key(api_key):
|
|
36
60
|
return {
|
|
37
61
|
"api_key_configured": True,
|
|
38
|
-
"api_key_env": "
|
|
39
|
-
"api_key_source":
|
|
62
|
+
"api_key_env": f"{API_KEY_ENV} (DSH_DKNOWC_API_KEY)" if source == "environment" else API_KEY_ENV,
|
|
63
|
+
"api_key_source": source,
|
|
40
64
|
"api_key_hint": None,
|
|
41
65
|
"search_ready": True,
|
|
42
|
-
"search_note":
|
|
66
|
+
"search_note": note,
|
|
43
67
|
}
|
|
44
68
|
return {
|
|
45
69
|
"api_key_configured": False,
|
|
46
70
|
"api_key_env": API_KEY_ENV,
|
|
47
71
|
"api_key_source": None,
|
|
48
|
-
"api_key_hint": f"未检测到可用的 {API_KEY_ENV}(dsh
|
|
72
|
+
"api_key_hint": f"未检测到可用的 {API_KEY_ENV}(dsh 主进程环境变量与 ~/.zshrc 中均未找到)。需要先将有效的 API Key 配置到启动 dsh 的环境变量 {API_KEY_ENV}(如 ~/.zshrc),再重启 dsh 或新建会话。",
|
|
49
73
|
"search_ready": False,
|
|
50
|
-
"search_note": f"
|
|
74
|
+
"search_note": f"当前未检测到可用的 {API_KEY_ENV},暂时无法获取深知可信内容。",
|
|
51
75
|
}
|
|
52
76
|
|
|
53
|
-
|
|
77
|
+
# 非 dsh 场景:环境变量优先,缺失时从 ~/.zshrc 兜底解析(与母版同源)
|
|
78
|
+
api_key, source = _resolve_zshrc_key()
|
|
79
|
+
if not _looks_like_key(api_key):
|
|
80
|
+
api_key = os.environ.get(API_KEY_ENV, "").strip()
|
|
81
|
+
source = "environment" if api_key else ""
|
|
54
82
|
if _looks_like_key(api_key):
|
|
55
83
|
return {
|
|
56
84
|
"api_key_configured": True,
|
|
57
85
|
"api_key_env": API_KEY_ENV,
|
|
58
|
-
"api_key_source":
|
|
86
|
+
"api_key_source": source,
|
|
59
87
|
"api_key_hint": None,
|
|
60
88
|
"search_ready": True,
|
|
61
89
|
"search_note": None,
|
|
@@ -65,7 +93,7 @@ def check_api_key_config():
|
|
|
65
93
|
"api_key_configured": False,
|
|
66
94
|
"api_key_env": API_KEY_ENV,
|
|
67
95
|
"api_key_source": None,
|
|
68
|
-
"api_key_hint": f"本 Skill 需要通过环境变量 {API_KEY_ENV}
|
|
96
|
+
"api_key_hint": f"本 Skill 需要通过环境变量 {API_KEY_ENV} 调用深知可信统一接口获取可信内容,当前环境变量与 ~/.zshrc 中均未找到有效 Key。请先注册或登录深知可信智能 MaaS 账号获取 API Key,再注入该环境变量。",
|
|
69
97
|
"search_ready": False,
|
|
70
98
|
"search_note": f"当前未检测到可用的 {API_KEY_ENV},暂时无法获取深知可信内容。",
|
|
71
99
|
}
|
|
@@ -77,11 +105,27 @@ def main():
|
|
|
77
105
|
if not status["api_key_configured"]:
|
|
78
106
|
blocking_issues.append("api_key_missing")
|
|
79
107
|
|
|
108
|
+
# guide_message:需要可信咨询但 Key 未配置时给用户的引导话术(S1 三段式:价值 / 权益+开通方式 / 退路+样例钩子)。
|
|
109
|
+
# Agent 优先原样转述本话术;完整话术库见 reference/onboarding_scripts.md。
|
|
110
|
+
guide_message = None
|
|
111
|
+
if not status["api_key_configured"]:
|
|
112
|
+
guide_message = (
|
|
113
|
+
"这个问题涉及具体的办事条件和金额口径,凭记忆回答容易过时或者记错地区差异,"
|
|
114
|
+
"答错了会影响办事和决策。开通可信咨询后,答案基于权威文件库原文,"
|
|
115
|
+
"条件、金额、办理路径都带出处、可点开核验。\n"
|
|
116
|
+
"开通是免费的:自带 300 次可信咨询额度,完成实名认证还能再领 100 元体验金。"
|
|
117
|
+
"只需手机号收一次验证码——两步、约 10 秒,不用去网站,剩下的我来办;"
|
|
118
|
+
"手机号仅用于本次验证,不会有营销骚扰。\n"
|
|
119
|
+
"也可以先不开通:我按已有知识先答,并明确标注“未联网核验、口径可能过期”。"
|
|
120
|
+
"想先看看开通后生成的核验报告长什么样,我可以发你一份示例看看。"
|
|
121
|
+
)
|
|
122
|
+
|
|
80
123
|
print(json.dumps({
|
|
81
124
|
**status,
|
|
82
125
|
"blocking_issues": blocking_issues,
|
|
83
126
|
"ready": not blocking_issues,
|
|
84
|
-
"
|
|
127
|
+
"guide_message": guide_message,
|
|
128
|
+
"maas_platform_url": "https://platform.dknowc.cn/auth/#/login",
|
|
85
129
|
}, ensure_ascii=False, indent=2))
|
|
86
130
|
|
|
87
131
|
|
|
@@ -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,15 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// MaaS key bootstrap helper for
|
|
3
|
-
// It only requests/returns a key for the current task and never writes local files.
|
|
2
|
+
// MaaS key bootstrap helper for SkillHub Public.
|
|
4
3
|
// node register_key.mjs send --phone <phone>
|
|
5
|
-
// node register_key.mjs register --phone <phone> --vcode <code> [--new-key]
|
|
4
|
+
// node register_key.mjs register --phone <phone> --vcode <code> [--new-key] [--no-zshrc]
|
|
5
|
+
//
|
|
6
|
+
// 注册成功后自动把 Key 写入 ~/.zshrc 标记块(--no-zshrc 跳过);配合 api_key.py
|
|
7
|
+
// 的 zshrc 兜底解析,写入后无需重启宿主即生效。
|
|
8
|
+
// 各分支输出 user_message:给用户的固定话术,Agent 必须原样转述,不得改写后发挥
|
|
9
|
+
// (话术库见 reference/onboarding_scripts.md;手机号一律脱敏显示)。
|
|
10
|
+
|
|
11
|
+
import fs from "node:fs";
|
|
12
|
+
import os from "node:os";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
|
|
15
|
+
const ZSHRC_START = "# >>> dknowc trusted consulting api key >>>";
|
|
16
|
+
const ZSHRC_END = "# <<< dknowc trusted consulting api key <<<";
|
|
17
|
+
// 早期版本遗留的标记块名(本 Skill 历史上无其他块名,保留机制以备后续变更)
|
|
18
|
+
const LEGACY_BLOCKS = [
|
|
19
|
+
["# >>> dknowc api key >>>", "# <<< dknowc api key <<<"],
|
|
20
|
+
];
|
|
6
21
|
|
|
7
22
|
const DEFAULT_BASE = "https://platform.dknowc.cn/auth/home/userAuto";
|
|
8
23
|
const DEFAULT_OPEN_BASE = "https://open.dknowc.cn";
|
|
9
24
|
const DEFAULT_CHANNEL = "46A3BA1D-3E1A-4E8C-BD50-A6DCBEE1DB05";
|
|
10
25
|
const DEFAULT_SOURCE = "agent";
|
|
11
26
|
const API_KEY_ENV = "DKNOWC_API_KEY";
|
|
12
|
-
const
|
|
27
|
+
const LOGIN_URL = "https://platform.dknowc.cn/auth/#/login";
|
|
13
28
|
|
|
14
29
|
function parseArgs(argv) {
|
|
15
30
|
const out = { _: [] };
|
|
@@ -31,6 +46,12 @@ function parseArgs(argv) {
|
|
|
31
46
|
return out;
|
|
32
47
|
}
|
|
33
48
|
|
|
49
|
+
function maskPhone(phone) {
|
|
50
|
+
const p = String(phone || "");
|
|
51
|
+
if (p.length < 7) return "***";
|
|
52
|
+
return `${p.slice(0, 3)}****${p.slice(-4)}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
34
55
|
async function postJson(url, payload, headers = {}) {
|
|
35
56
|
const controller = new AbortController();
|
|
36
57
|
const timer = setTimeout(() => controller.abort(), 30000);
|
|
@@ -84,6 +105,48 @@ async function createNewApiKey(openBase, existingApiKey, name, remark) {
|
|
|
84
105
|
return { result, apiKey };
|
|
85
106
|
}
|
|
86
107
|
|
|
108
|
+
function escapeRegExp(value) {
|
|
109
|
+
return String(value).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function shellSingleQuote(value) {
|
|
113
|
+
return `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function writeApiKeyToZshrc(apiKey) {
|
|
117
|
+
const zshrcPath = path.join(os.homedir(), ".zshrc");
|
|
118
|
+
const block = [
|
|
119
|
+
ZSHRC_START,
|
|
120
|
+
`export ${API_KEY_ENV}=${shellSingleQuote(apiKey)}`,
|
|
121
|
+
ZSHRC_END,
|
|
122
|
+
"",
|
|
123
|
+
].join("\n");
|
|
124
|
+
let existing = "";
|
|
125
|
+
try {
|
|
126
|
+
existing = fs.existsSync(zshrcPath) ? fs.readFileSync(zshrcPath, "utf8") : "";
|
|
127
|
+
} catch (e) {
|
|
128
|
+
return { written: false, path: zshrcPath, error: e && e.message ? e.message : String(e) };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 清理早期版本遗留的标记块(含空块),再写入当前标准块
|
|
132
|
+
for (const [start, end] of LEGACY_BLOCKS) {
|
|
133
|
+
const legacy = new RegExp(`${escapeRegExp(start)}[\\s\\S]*?${escapeRegExp(end)}\\n?`, "m");
|
|
134
|
+
existing = existing.replace(legacy, "");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const pattern = new RegExp(`${escapeRegExp(ZSHRC_START)}[\\s\\S]*?${escapeRegExp(ZSHRC_END)}\\n?`, "m");
|
|
138
|
+
const next = pattern.test(existing)
|
|
139
|
+
? existing.replace(pattern, block)
|
|
140
|
+
: `${existing}${existing && !existing.endsWith("\n") ? "\n" : ""}${block}`;
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
fs.writeFileSync(zshrcPath, next, { encoding: "utf8", mode: 0o600 });
|
|
144
|
+
return { written: true, path: zshrcPath, error: null };
|
|
145
|
+
} catch (e) {
|
|
146
|
+
return { written: false, path: zshrcPath, error: e && e.message ? e.message : String(e) };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
87
150
|
function maskKey(apiKey) {
|
|
88
151
|
if (!apiKey) return null;
|
|
89
152
|
if (apiKey.length <= 12) return "***";
|
|
@@ -100,13 +163,20 @@ async function main() {
|
|
|
100
163
|
console.error("缺少 --phone");
|
|
101
164
|
process.exit(2);
|
|
102
165
|
}
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
166
|
+
const channel = args.channel && args.channel !== true ? args.channel : DEFAULT_CHANNEL;
|
|
167
|
+
const r = await postJson(`${base}/sendMessage`, { phone: args.phone, type: "register", channel });
|
|
168
|
+
// user_message:给用户的固定话术,Agent 必须原样转述,不得改写后发挥
|
|
169
|
+
let userMessage;
|
|
170
|
+
if (r.status) {
|
|
171
|
+
userMessage = `验证码已发送到 ${maskPhone(args.phone)},请把最新一条短信里的 6 位验证码发我。`;
|
|
172
|
+
} else if (String(r.msg || "").includes("手机号")) {
|
|
173
|
+
userMessage = "这个手机号格式好像不对,麻烦核对一下再发我。";
|
|
174
|
+
} else {
|
|
175
|
+
userMessage = `验证码发送没成功(可能是网络或短信通道问题),可以再试一次;如果连续失败,也可以用网页方式开通:${LOGIN_URL}`;
|
|
176
|
+
}
|
|
177
|
+
console.log(JSON.stringify({ ...r, user_message: userMessage }));
|
|
178
|
+
if (r.status) console.error("验证码已发送(话术见 user_message,请向用户转述后索取 6 位验证码)。");
|
|
179
|
+
process.exit(r.status ? 0 : 1);
|
|
110
180
|
}
|
|
111
181
|
|
|
112
182
|
if (cmd === "register") {
|
|
@@ -126,9 +196,9 @@ async function main() {
|
|
|
126
196
|
source: args.source && args.source !== true ? args.source : DEFAULT_SOURCE,
|
|
127
197
|
};
|
|
128
198
|
|
|
129
|
-
const
|
|
130
|
-
const data =
|
|
131
|
-
let apiKey =
|
|
199
|
+
const r = await postJson(`${base}/register`, payload);
|
|
200
|
+
const data = r.data || {};
|
|
201
|
+
let apiKey = r.status && data.apiKey ? data.apiKey : "";
|
|
132
202
|
let newKeyCreated = false;
|
|
133
203
|
let newKeyError = null;
|
|
134
204
|
|
|
@@ -149,28 +219,57 @@ async function main() {
|
|
|
149
219
|
apiKey = created.apiKey;
|
|
150
220
|
newKeyCreated = true;
|
|
151
221
|
} else {
|
|
152
|
-
|
|
222
|
+
// 新建 Key 失败:沿用现有密钥继续,如实告知,不把旧 Key 冒充新 Key
|
|
153
223
|
newKeyError = created.result.errmsg || created.result.msg || "新 API Key 创建失败";
|
|
154
224
|
}
|
|
155
225
|
}
|
|
156
226
|
|
|
227
|
+
// 注册成功自动持久化到 ~/.zshrc 标记块(--no-zshrc 跳过);
|
|
228
|
+
// 配合 api_key.py 兜底解析,写入后无需重启宿主即生效。
|
|
229
|
+
const zshrcWrite = apiKey && !args["no-zshrc"]
|
|
230
|
+
? writeApiKeyToZshrc(apiKey)
|
|
231
|
+
: { written: false, path: path.join(os.homedir(), ".zshrc"), error: null };
|
|
232
|
+
|
|
233
|
+
// user_message:给用户的固定话术,Agent 必须原样转述,不得改写后发挥。
|
|
234
|
+
// 权益(300 次额度 + 实名认证赠金)已在引导开通时告知,此处只做额度到账的轻确认。
|
|
235
|
+
let userMessage;
|
|
236
|
+
if (apiKey) {
|
|
237
|
+
userMessage = Boolean(data.existed)
|
|
238
|
+
? `这个手机号之前开通过,已直接找回原来的密钥和额度,不用重新注册。我马上开始查询。`
|
|
239
|
+
: `开通成功,访问密钥已写入本机,300 次免费咨询额度已生效。我马上开始查询。`;
|
|
240
|
+
if (newKeyError) {
|
|
241
|
+
userMessage += ` 另外你要求的新密钥生成失败(${newKeyError}),已先沿用现有密钥继续,不影响使用;需要的话稍后再重新生成。`;
|
|
242
|
+
}
|
|
243
|
+
} else if (String(r.msg || "").includes("验证码")) {
|
|
244
|
+
userMessage = `验证码校验没通过(可能是输入有误或已过期)。请核对 ${maskPhone(args.phone)} 最新一条短信的 6 位验证码重新发我;需要我重新发送一条,直接说一声。`;
|
|
245
|
+
} else {
|
|
246
|
+
userMessage = `开通服务暂时没连上(${r.msg || "网络波动"}),可以稍后再试,或用网页方式开通:${LOGIN_URL}`;
|
|
247
|
+
}
|
|
248
|
+
|
|
157
249
|
console.log(JSON.stringify({
|
|
158
|
-
status: Boolean(apiKey)
|
|
159
|
-
msg:
|
|
250
|
+
status: Boolean(apiKey),
|
|
251
|
+
msg: r.msg,
|
|
160
252
|
url: data.url || null,
|
|
161
253
|
existed: Boolean(data.existed),
|
|
162
254
|
keyCreatedByRegister: Boolean(data.keyCreated),
|
|
163
255
|
newKeyRequested: Boolean(args["new-key"]),
|
|
164
256
|
newKeyCreated,
|
|
257
|
+
user_message: userMessage,
|
|
165
258
|
envName: API_KEY_ENV,
|
|
166
259
|
apiKey,
|
|
167
260
|
apiKeyMasked: maskKey(apiKey),
|
|
168
|
-
currentTaskOnly:
|
|
169
|
-
|
|
170
|
-
|
|
261
|
+
currentTaskOnly: false,
|
|
262
|
+
envWriteRequired: false,
|
|
263
|
+
envWriteTarget: zshrcWrite.path,
|
|
264
|
+
envWriteSucceeded: Boolean(zshrcWrite.written),
|
|
265
|
+
envWriteError: zshrcWrite.error || null,
|
|
266
|
+
persistInstruction: zshrcWrite.written
|
|
267
|
+
? `密钥已自动写入 ~/.zshrc 标记块(${API_KEY_ENV}),配合 api_key.py 兜底解析,无需重启即生效;不要重复写入。`
|
|
268
|
+
: `本次未写入 ~/.zshrc${args["no-zshrc"] ? "(--no-zshrc)" : "(写入失败,见 envWriteError)"};如需持久化,把 ${API_KEY_ENV} 写入 ~/.zshrc 标记块后无需重启即生效。`,
|
|
269
|
+
fallbackRegisterUrl: LOGIN_URL,
|
|
171
270
|
newKeyError,
|
|
172
271
|
}));
|
|
173
|
-
process.exit(apiKey
|
|
272
|
+
process.exit(apiKey ? 0 : 1);
|
|
174
273
|
}
|
|
175
274
|
|
|
176
275
|
console.error("用法: node register_key.mjs <send|register> ...");
|