dknowc-dsh 1.3.0 → 1.4.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/README.md +4 -2
- package/package.json +3 -3
- package/skills/dknowc-official-doc-writer/README.md +1 -1
- package/skills/dknowc-official-doc-writer/SKILL.md +26 -6
- package/skills/dknowc-official-doc-writer/reference/sample_trace_report.html +901 -269
- package/skills/dknowc-official-doc-writer/reference/search_guide.md +31 -3
- package/skills/dknowc-official-doc-writer/reference/search_policy.md +14 -1
- package/skills/dknowc-official-doc-writer/reference/task_router.md +1 -1
- package/skills/dknowc-official-doc-writer/scripts/adapt_mcp_result.py +52 -2
- package/skills/dknowc-official-doc-writer/scripts/dkag_search.py +9 -1
- package/skills/dknowc-official-doc-writer/scripts/initialize.py +6 -14
- package/skills/dknowc-official-doc-writer/scripts/mcp_direct.py +1 -1
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +2 -2
- package/skills/dknowc-official-doc-writer/scripts/render_trace_html.py +1317 -607
- package/skills/dknowc-official-doc-writer/scripts/source_note_html.py +140 -4
- package/skills/dknowc-ppt-assistant/SKILL.md +3 -3
- package/skills/dknowc-ppt-assistant/references/material_usage.md +2 -2
- package/skills/dknowc-ppt-assistant/references/sample_trace_report.html +1335 -292
- package/skills/dknowc-ppt-assistant/references/svg-authoring.md +1 -1
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +7 -17
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +99 -60
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +1458 -653
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +2 -2
- package/skills/dknowc-trusted-consulting/README.md +1 -1
- package/skills/dknowc-trusted-consulting/SKILL.md +9 -4
- package/skills/dknowc-trusted-consulting/reference/sample_trace_report.html +672 -307
- package/skills/dknowc-trusted-consulting/scripts/initialize.py +24 -34
- package/skills/dknowc-trusted-consulting/scripts/register_key.mjs +5 -3
- package/skills/dknowc-trusted-consulting/scripts/render_trace_html.py +1647 -729
- package/skills/dknowc-trusted-search/README.md +2 -1
- package/skills/dknowc-trusted-search/SKILL.md +3 -2
- package/skills/dknowc-trusted-search/reference/sample_trace_report.html +1110 -251
- package/skills/dknowc-trusted-search/scripts/initialize.py +2 -3
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +2 -2
- package/skills/dknowc-trusted-search/scripts/render_trace_html.py +1590 -692
- package/skills/dknowc-trusted-search/scripts/trusted_search.py +6 -3
- package/src/index.js +1 -1
- package/skills/dknowc-official-doc-writer/scripts/check_release.py +0 -93
- package/skills/dknowc-ppt-assistant/scripts/check_release.py +0 -106
- package/skills/dknowc-trusted-consulting/scripts/check_release.py +0 -66
- package/skills/dknowc-trusted-search/scripts/check_release.py +0 -79
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
python3 {skillDir}/scripts/svg_quality_checker.py dknowc-projects/<项目名> --quick-generate --stage final --json
|
|
76
76
|
|
|
77
77
|
# 编译导出(quick 模式)
|
|
78
|
-
uv run --with python-pptx --with XlsxWriter python3 {skillDir}/scripts/svg_to_pptx.py dknowc-projects/<项目名> --quick-generate
|
|
78
|
+
uv run --with python-pptx --with XlsxWriter uv run --with python-pptx --with XlsxWriter python3 {skillDir}/scripts/svg_to_pptx.py dknowc-projects/<项目名> --quick-generate
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
质检 errors(exit 1)必须修复后重新导出;warnings 可评估后放行。导出成功后 `.pptx` 写入项目 `exports/`。
|
|
@@ -54,9 +54,8 @@ def _in_dsh() -> bool:
|
|
|
54
54
|
|
|
55
55
|
def check_api_key_config():
|
|
56
56
|
if _in_dsh():
|
|
57
|
-
# dsh 场景:优先插件经 shell-env 注入的 DSH_DKNOWC_API_KEY(与 MCP Bearer
|
|
58
|
-
#
|
|
59
|
-
# 自动持久化后、dsh 重启前的窗口期不误报缺失)。无 Key 仅暂停检索,不阻断纯生成。
|
|
57
|
+
# dsh 场景:优先插件经 shell-env 注入的 DSH_DKNOWC_API_KEY(与 MCP Bearer 同源);
|
|
58
|
+
# 缺失时 ~/.zshrc 兜底。无 Key 仅暂停检索,不阻断纯生成(材料/免检索模式)。
|
|
60
59
|
api_key = os.environ.get("DSH_DKNOWC_API_KEY", "").strip()
|
|
61
60
|
source = "environment"
|
|
62
61
|
if not _looks_like_key(api_key):
|
|
@@ -68,18 +67,9 @@ def check_api_key_config():
|
|
|
68
67
|
except ImportError:
|
|
69
68
|
pass
|
|
70
69
|
if _looks_like_key(api_key):
|
|
71
|
-
return {
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
"api_key_source": source,
|
|
75
|
-
"api_key_hint": None,
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
"api_key_configured": False,
|
|
79
|
-
"api_key_env": API_KEY_ENV,
|
|
80
|
-
"api_key_source": None,
|
|
81
|
-
"api_key_hint": f"未检测到可用的 {API_KEY_ENV}(dsh 主进程环境变量与 ~/.zshrc 中均未找到)。需要先将有效的 API Key 配置到启动 dsh 的环境变量 {API_KEY_ENV}(如 ~/.zshrc),再重启 dsh 或新建会话。仅检索任务受影响,不涉及检索的生成任务可继续。",
|
|
82
|
-
}
|
|
70
|
+
return {"api_key_configured": True, "api_key_env": API_KEY_ENV, "api_key_source": source, "api_key_hint": None}
|
|
71
|
+
return {"api_key_configured": False, "api_key_env": API_KEY_ENV, "api_key_source": None,
|
|
72
|
+
"api_key_hint": f"未检测到可用的 {API_KEY_ENV}(dsh 主进程环境变量与 ~/.zshrc 中均未找到)。需要先将有效的 API Key 配置到启动 dsh 的环境变量 {API_KEY_ENV}(如 ~/.zshrc),再重启 dsh 或新建会话。仅检索任务受影响,不涉及检索的生成任务可继续。"}
|
|
83
73
|
|
|
84
74
|
# 环境变量优先,缺失时从 ~/.zshrc 兜底解析(宿主进程早于 key 写入启动、
|
|
85
75
|
# 或宿主不再加载 ~/.zshrc 导出变量时不误报缺失,与公文写作同源方案)
|
|
@@ -155,8 +145,8 @@ def check_environment():
|
|
|
155
145
|
"也可以先不开通:我基于你手头的材料先把 PPT 做出来,政策和数据的位置先标注「数据待核验」。"
|
|
156
146
|
"想先看看开通后自动生成的核验报告长什么样,我可以发你一份示例看看。"
|
|
157
147
|
)
|
|
158
|
-
# env_message
|
|
159
|
-
#
|
|
148
|
+
# env_message:依赖缺失时给用户的统一话术——用「小组件」等通俗说法(requests/python-pptx 等组件名
|
|
149
|
+
# 对用户无理解价值);就绪时不输出环境话题。多 Python 环境下检测口径以 python_executable 为准。
|
|
160
150
|
missing_basic = [k for k, ok in (("小组件", requests_available),) if not ok]
|
|
161
151
|
missing_compile = 2 - int(python_pptx_available) - int(xlsxwriter_available)
|
|
162
152
|
if blocking_issues or pptx_blocking_issues:
|
|
@@ -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";
|
|
@@ -11,6 +16,20 @@ const DEFAULT_TYPE = "11";
|
|
|
11
16
|
const DEFAULT_SOURCE = "agent";
|
|
12
17
|
const API_KEY_ENV = "DKNOWC_API_KEY";
|
|
13
18
|
const MAAS_PLATFORM_URL = "https://platform.dknowc.cn/auth/#/login";
|
|
19
|
+
const FALLBACK_REGISTER_URL = MAAS_PLATFORM_URL;
|
|
20
|
+
const ZSHRC_START = "# >>> dknowc api key >>>";
|
|
21
|
+
const ZSHRC_END = "# <<< dknowc 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,19 +104,42 @@ async function createNewApiKey(openBase, existingApiKey, name, remark) {
|
|
|
85
104
|
return { result, apiKey };
|
|
86
105
|
}
|
|
87
106
|
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
return p.length === 11 ? `${p.slice(0, 3)}****${p.slice(-4)}` : p;
|
|
107
|
+
function shellSingleQuote(value) {
|
|
108
|
+
return `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
91
109
|
}
|
|
92
110
|
|
|
93
|
-
function
|
|
94
|
-
return
|
|
111
|
+
function escapeRegExp(value) {
|
|
112
|
+
return String(value).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
95
113
|
}
|
|
96
114
|
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
+
}
|
|
101
143
|
}
|
|
102
144
|
|
|
103
145
|
async function main() {
|
|
@@ -110,31 +152,20 @@ async function main() {
|
|
|
110
152
|
console.error("缺少 --phone");
|
|
111
153
|
process.exit(2);
|
|
112
154
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
process.exit(1);
|
|
121
|
-
}
|
|
122
|
-
let result;
|
|
123
|
-
try {
|
|
124
|
-
result = await postJson(`${base}/sendMessage`, {
|
|
125
|
-
phone: args.phone,
|
|
126
|
-
type: "register",
|
|
127
|
-
channel,
|
|
128
|
-
});
|
|
129
|
-
} catch (e) {
|
|
130
|
-
result = { status: false, msg: String((e && e.message) || e) };
|
|
131
|
-
}
|
|
132
|
-
// user_message:给用户的固定话术,Agent 必须原样转述,不得改写后发挥。
|
|
155
|
+
// 渠道细分:sendMessage 与 register 请求体统一携带 SkillHub 渠道码。
|
|
156
|
+
const result = await postJson(`${base}/sendMessage`, {
|
|
157
|
+
phone: args.phone,
|
|
158
|
+
type: "register",
|
|
159
|
+
channel: args.channel && args.channel !== true ? args.channel : DEFAULT_CHANNEL,
|
|
160
|
+
});
|
|
161
|
+
// user_message:给用户的固定话术,Agent 必须原样转述,不得改写后发挥
|
|
133
162
|
let userMessage;
|
|
134
163
|
if (result.status) {
|
|
135
164
|
userMessage = `验证码已发送到 ${maskPhone(args.phone)},请把最新一条短信里的 6 位验证码发我。`;
|
|
165
|
+
} else if (String(result.msg || "").includes("手机号")) {
|
|
166
|
+
userMessage = "这个手机号格式好像不对,麻烦核对一下再发我。";
|
|
136
167
|
} else {
|
|
137
|
-
userMessage = `验证码发送没成功(可能是网络或短信通道问题),可以再试一次;如果连续失败,也可以用网页方式开通:${
|
|
168
|
+
userMessage = `验证码发送没成功(可能是网络或短信通道问题),可以再试一次;如果连续失败,也可以用网页方式开通:${FALLBACK_REGISTER_URL}`;
|
|
138
169
|
}
|
|
139
170
|
console.log(JSON.stringify({ ...result, user_message: userMessage }));
|
|
140
171
|
if (result.status) console.error("验证码已发送(话术见 user_message,请向用户转述后索取 6 位验证码)。");
|
|
@@ -161,11 +192,11 @@ async function main() {
|
|
|
161
192
|
|
|
162
193
|
const result = await postJson(`${base}/register`, payload);
|
|
163
194
|
const data = result.data || {};
|
|
164
|
-
|
|
195
|
+
const ok = Boolean(result.status) && Boolean(data.apiKey);
|
|
196
|
+
let apiKeyToSave = ok ? data.apiKey : "";
|
|
165
197
|
let newKeyCreated = false;
|
|
166
198
|
let newKeyError = null;
|
|
167
|
-
|
|
168
|
-
if (apiKey && args["new-key"]) {
|
|
199
|
+
if (ok && args["new-key"]) {
|
|
169
200
|
const keyName = args["new-key-name"] && args["new-key-name"] !== true
|
|
170
201
|
? args["new-key-name"]
|
|
171
202
|
: payload.apiKeyName;
|
|
@@ -174,53 +205,61 @@ async function main() {
|
|
|
174
205
|
: "由 SkillHub 深知可信搜索按用户要求重新生成";
|
|
175
206
|
const created = await createNewApiKey(
|
|
176
207
|
args["open-base"] && args["open-base"] !== true ? args["open-base"] : DEFAULT_OPEN_BASE,
|
|
177
|
-
apiKey,
|
|
208
|
+
data.apiKey,
|
|
178
209
|
keyName,
|
|
179
210
|
keyRemark,
|
|
180
211
|
);
|
|
181
212
|
if (created.apiKey) {
|
|
182
|
-
|
|
213
|
+
apiKeyToSave = created.apiKey;
|
|
183
214
|
newKeyCreated = true;
|
|
184
215
|
} else {
|
|
185
|
-
//
|
|
216
|
+
// 新建失败:沿用原密钥继续(不中断用户任务),newKeyCreated=false 明确区分新旧
|
|
186
217
|
newKeyError = created.result.errmsg || created.result.msg || "新 API Key 创建失败";
|
|
187
218
|
}
|
|
188
219
|
}
|
|
189
|
-
|
|
220
|
+
const zshrcWrite = ok && apiKeyToSave && !args["no-zshrc"]
|
|
221
|
+
? writeApiKeyToZshrc(apiKeyToSave)
|
|
222
|
+
: { written: false, path: path.join(os.homedir(), ".zshrc"), error: null };
|
|
190
223
|
// user_message:给用户的固定话术,Agent 必须原样转述,不得改写后发挥。
|
|
191
|
-
|
|
224
|
+
// 权益告知(300 次额度 + 实名认证赠金)已前移到开通引导(initialize.guide_message / onboarding_scripts S1),
|
|
225
|
+
// 此处只做轻确认,避免成功节点信息过重导致转述截断。
|
|
192
226
|
let userMessage;
|
|
193
|
-
if (
|
|
194
|
-
userMessage =
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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("验证码")) {
|
|
198
235
|
userMessage = `验证码校验没通过(可能是输入有误或已过期)。请核对 ${maskPhone(args.phone)} 最新一条短信的 6 位验证码重新发我;需要我重新发送一条,直接说一声。`;
|
|
199
236
|
} else {
|
|
200
|
-
userMessage = `开通服务暂时没连上(${result.msg || "网络波动"}),可以稍后再试,或用网页方式开通:${
|
|
201
|
-
}
|
|
202
|
-
if (registered && newKeyError) {
|
|
203
|
-
userMessage += ` 另外你要求的新密钥生成失败(${newKeyError}),已先沿用现有密钥继续,不影响使用;需要的话稍后再重新生成。`;
|
|
237
|
+
userMessage = `开通服务暂时没连上(${result.msg || "网络波动"}),可以稍后再试,或用网页方式开通:${FALLBACK_REGISTER_URL}`;
|
|
204
238
|
}
|
|
205
|
-
|
|
206
239
|
console.log(JSON.stringify({
|
|
207
|
-
status:
|
|
240
|
+
status: ok && Boolean(apiKeyToSave),
|
|
208
241
|
msg: result.msg,
|
|
209
242
|
url: data.url || null,
|
|
210
243
|
existed: Boolean(data.existed),
|
|
211
244
|
keyCreatedByRegister: Boolean(data.keyCreated),
|
|
212
245
|
newKeyRequested: Boolean(args["new-key"]),
|
|
213
246
|
newKeyCreated,
|
|
247
|
+
user_message: userMessage,
|
|
214
248
|
envName: API_KEY_ENV,
|
|
215
|
-
apiKey,
|
|
216
|
-
apiKeyMasked: maskKey(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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。`,
|
|
220
259
|
newKeyError,
|
|
221
|
-
|
|
260
|
+
fallbackRegisterUrl: FALLBACK_REGISTER_URL,
|
|
222
261
|
}));
|
|
223
|
-
process.exit(
|
|
262
|
+
process.exit(ok && Boolean(apiKeyToSave) ? 0 : 1);
|
|
224
263
|
}
|
|
225
264
|
|
|
226
265
|
console.error("用法: node register_key.mjs <send|register> ...");
|