dsh-vod-devkit 0.5.5 → 0.5.8
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/lib/index.js +85 -9
- package/package.json +2 -1
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 形态纪律(与 vod-devkit MCP 侧一致):
|
|
5
5
|
* - 插件=引擎的客户端,只走 HTTPS,不 import 任何引擎模块
|
|
6
|
-
* - 纯采集形态:submit / 本地账本查询 /
|
|
6
|
+
* - 纯采集形态:submit / 本地账本查询 / 自述 / 技能披露×2 / 版本检查,共 6 工具
|
|
7
7
|
* - 写操作默认走 dsh 审批通道(tools/pre-execute → kind:'ask')
|
|
8
8
|
* - voiceId = f(source, content, 调用级nonce):同调用幂等、跨调用保声量
|
|
9
9
|
* - key 缺失/401 → 自动 POST /external/token 零字段令牌 → 落本地 → 重试一次
|
|
@@ -24,7 +24,13 @@ const DATA_DIR = join(PKG_DIR, 'data');
|
|
|
24
24
|
// 运行时状态路径可用 VOD_DSH_RUNTIME 覆盖(测试隔离/企业数据驻留用;
|
|
25
25
|
// 2026-11-11 实锤:dsh/test 直写仓内 dsh/data/runtime.json,本地账本被测试
|
|
26
26
|
// 灌到 128 条——测试必须能指到 tmp,不能再共用真实账本)
|
|
27
|
+
// 运行时状态默认写在包目录 data/ 下(历史形态,存量账本不迁移)。
|
|
28
|
+
// 但包目录在只读安装形态(全局共享 node_modules / pnpm store / 容器只读挂载)下
|
|
29
|
+
// 不可写——落盘失败=本地账本与归因记忆全丢,且只有提交时才会发现。
|
|
30
|
+
// 修法:写入失败一次性回退到 <dsh home>/data/ 并告警;VOD_DSH_RUNTIME 仍最高优先。
|
|
27
31
|
const RUNTIME = process.env.VOD_DSH_RUNTIME || join(DATA_DIR, 'runtime.json');
|
|
32
|
+
const FALLBACK_RUNTIME = join(homedir(), '.dsh', 'data', 'vod-devkit-runtime.json');
|
|
33
|
+
let runtimePath = RUNTIME; // 运行期可变:写入失败后切到 fallback
|
|
28
34
|
const API_PREFIX = '/rest/developer/manager/hdvodmngservice/v1';
|
|
29
35
|
const HOARD_PATH = `${API_PREFIX}/external/voices`; // V16 囤积端点(批量/不触发 LLM/结构化回执)
|
|
30
36
|
const SUBMIT_PATH = `${API_PREFIX}/external/voice/submit`; // 旧单条端点:仅 404 回落使用 // V16 已切换:主路径 HOARD_PATH(囤积),本路径仅 404 回落(见 docs/decisions.md D-dsh-4)
|
|
@@ -52,7 +58,11 @@ function readCfg(v, fallback) {
|
|
|
52
58
|
|
|
53
59
|
// ── 本地账本:每次文件读改写,只动目标键(防内存合并回写陈旧配置) ──
|
|
54
60
|
function loadRuntime() {
|
|
55
|
-
try { return JSON.parse(readFileSync(
|
|
61
|
+
try { return JSON.parse(readFileSync(runtimePath, 'utf8')); } catch { return {}; }
|
|
62
|
+
}
|
|
63
|
+
function _writeRuntime(target, next) {
|
|
64
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
65
|
+
writeFileSync(target, JSON.stringify(next, null, 2));
|
|
56
66
|
}
|
|
57
67
|
function saveRuntime(patch) {
|
|
58
68
|
const rt = loadRuntime();
|
|
@@ -60,8 +70,15 @@ function saveRuntime(patch) {
|
|
|
60
70
|
if (Array.isArray(next.submissions) && next.submissions.length > LEDGER_CAP) {
|
|
61
71
|
next.submissions = next.submissions.slice(-LEDGER_CAP);
|
|
62
72
|
}
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
try {
|
|
74
|
+
_writeRuntime(runtimePath, next);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
if (runtimePath === FALLBACK_RUNTIME) throw err; // 两处都不可写=真故障,不静默
|
|
77
|
+
console.warn(`[dsh-vod-devkit] 包目录不可写(${runtimePath}:${String(err).slice(0, 80)})`
|
|
78
|
+
+ `——运行时状态改落 ${FALLBACK_RUNTIME}(本地账本换位置,跨版本不互通)`);
|
|
79
|
+
_writeRuntime(FALLBACK_RUNTIME, next);
|
|
80
|
+
runtimePath = FALLBACK_RUNTIME;
|
|
81
|
+
}
|
|
65
82
|
}
|
|
66
83
|
function ledgerAppend(entries) {
|
|
67
84
|
const rt = loadRuntime();
|
|
@@ -162,6 +179,42 @@ async function loadMeta(cfg, signal) {
|
|
|
162
179
|
return _metaCache?.data || emptyMeta();
|
|
163
180
|
}
|
|
164
181
|
|
|
182
|
+
// 品牌俗称表(与 vod_mcp/attribution.py BRAND_ALIASES 同一份口径):
|
|
183
|
+
// 只放**无法从登记名规则派生**且用户口语高频的品牌名(码道=CodeArts 中文品牌)。
|
|
184
|
+
const BRAND_ALIASES = {
|
|
185
|
+
CodeArts: ['码道', '华为云码道'],
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const LATIN_RUN = /[A-Za-z][A-Za-z0-9 ._-]*[A-Za-z0-9]|[A-Za-z]/g;
|
|
189
|
+
const isAscii = (s) => [...String(s)].every((c) => c.charCodeAt(0) < 128);
|
|
190
|
+
|
|
191
|
+
// 从单个登记名派生可用写法(与 Python _derive_aliases 逐条同源):
|
|
192
|
+
// 原名 / 去空格 / 拉丁核心段(≥3)/ 非全大写混写名的 lower·capitalize 变体。
|
|
193
|
+
// 全大写缩写(OBS/CCE)不生成小写变体——否则 obs://bucket、/obs/bin 会被误命中(S93 铁律)。
|
|
194
|
+
function deriveAliases(name) {
|
|
195
|
+
const raw = String(name || '').trim();
|
|
196
|
+
if (!raw) return [];
|
|
197
|
+
const out = [raw];
|
|
198
|
+
const compact = raw.replace(/\s+/g, '');
|
|
199
|
+
if (compact && compact !== raw) out.push(compact);
|
|
200
|
+
const runs = (raw.match(LATIN_RUN) || []).map((r) => r.trim()).filter((r) => r.length >= 3);
|
|
201
|
+
if (runs.length) {
|
|
202
|
+
out.push(...runs);
|
|
203
|
+
if (raw.includes(' ')) {
|
|
204
|
+
const head = (runs[0].split(/\s+/)[0] || runs[0]);
|
|
205
|
+
if (head.length >= 3) out.push(head);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
for (const run of runs) {
|
|
209
|
+
if (run.length <= 8 && isAscii(run) && run !== run.toUpperCase()) {
|
|
210
|
+
for (const v of [run.toLowerCase(), run.charAt(0).toUpperCase() + run.slice(1).toLowerCase()]) {
|
|
211
|
+
if (v !== run) out.push(v);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return [...new Set(out.filter(Boolean))];
|
|
216
|
+
}
|
|
217
|
+
|
|
165
218
|
export function buildAliasIndex(meta = {}) {
|
|
166
219
|
const products = (meta.products || []).map(String).filter(Boolean);
|
|
167
220
|
const catalog = meta.catalog || [];
|
|
@@ -170,12 +223,13 @@ export function buildAliasIndex(meta = {}) {
|
|
|
170
223
|
const name = String(it?.name || '').trim();
|
|
171
224
|
if (name) idByLower.set(name.toLowerCase(), it.id != null ? String(it.id) : null);
|
|
172
225
|
}
|
|
173
|
-
const canon = new Map(); // lower(name) -> {label,id,aliases:Set,brand}
|
|
226
|
+
const canon = new Map(); // lower(name) -> {label,id,aliases:Set,brand,derived:Set}
|
|
174
227
|
const slot = (nm, brand) => {
|
|
175
228
|
const key = String(nm).trim().toLowerCase();
|
|
176
229
|
let cur = canon.get(key);
|
|
177
230
|
if (!cur) {
|
|
178
|
-
cur = { label: String(nm).trim(), id: null, aliases: new Set(),
|
|
231
|
+
cur = { label: String(nm).trim(), id: null, aliases: new Set(),
|
|
232
|
+
brand: !!brand, derived: new Set() };
|
|
179
233
|
canon.set(key, cur);
|
|
180
234
|
} else if (brand && !cur.brand) {
|
|
181
235
|
cur.label = String(nm).trim();
|
|
@@ -186,6 +240,19 @@ export function buildAliasIndex(meta = {}) {
|
|
|
186
240
|
};
|
|
187
241
|
products.forEach((p) => slot(p, true)); // 展示名优先成标签
|
|
188
242
|
catalog.forEach((it) => { if (it?.name) slot(it.name, false); });
|
|
243
|
+
// 规则派生(对齐 Python:每条登记名派生多种写法,派生的允许大小写不敏感)
|
|
244
|
+
for (const s of canon.values()) {
|
|
245
|
+
for (const d of deriveAliases(s.label)) {
|
|
246
|
+
s.aliases.add(d);
|
|
247
|
+
if (d !== s.label) s.derived.add(d);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
// 品牌俗称:目标产品不在本次名录(引擎换库)就不落地,宁可丢俗称也不错归
|
|
251
|
+
for (const [target, words] of Object.entries(BRAND_ALIASES)) {
|
|
252
|
+
const s = canon.get(target.toLowerCase());
|
|
253
|
+
if (!s) continue;
|
|
254
|
+
for (const w of words) if (w) s.aliases.add(String(w).trim());
|
|
255
|
+
}
|
|
189
256
|
for (const [key, list] of Object.entries(meta.nameAliases || {})) {
|
|
190
257
|
const aliases = (list || []).map(String).filter(Boolean);
|
|
191
258
|
let target = canon.get(String(key).toLowerCase());
|
|
@@ -230,7 +297,9 @@ export function buildAliasIndex(meta = {}) {
|
|
|
230
297
|
const key = `${s.label.toLowerCase()}\u0000${alias}`; // 大小写敏感:留住 MaaS/Maas
|
|
231
298
|
if (!alias || seen.has(key)) continue;
|
|
232
299
|
seen.add(key);
|
|
233
|
-
|
|
300
|
+
// caseless:派生写法才允许大小写不敏感;全大写缩写永不(对齐 Python)
|
|
301
|
+
const caseless = s.derived.has(alias) && alias !== alias.toUpperCase();
|
|
302
|
+
entries.push({ product: s.label, id: s.id, alias, caseless });
|
|
234
303
|
}
|
|
235
304
|
}
|
|
236
305
|
entries.sort((a, b) => b.alias.length - a.alias.length);
|
|
@@ -257,7 +326,7 @@ export function matchProducts(text, index) {
|
|
|
257
326
|
let i = 0;
|
|
258
327
|
while ((i = t.indexOf(alias, i)) >= 0) { spans.push([i, i + alias.length]); i += 1; }
|
|
259
328
|
} else {
|
|
260
|
-
const exact = alias.length < ATTR_SHORT_ALIAS;
|
|
329
|
+
const exact = !e.caseless && alias.length < ATTR_SHORT_ALIAS;
|
|
261
330
|
const hay = exact ? t : t.toLowerCase();
|
|
262
331
|
const needle = exact ? alias : alias.toLowerCase();
|
|
263
332
|
let i = 0;
|
|
@@ -270,7 +339,14 @@ export function matchProducts(text, index) {
|
|
|
270
339
|
if (ATTR_BOUNDARY.test(n)) afterOk = false;
|
|
271
340
|
else if (n === '.' && j + 1 < hay.length && /[A-Za-z0-9]/.test(hay[j + 1])) afterOk = false;
|
|
272
341
|
}
|
|
273
|
-
if (beforeOk && afterOk)
|
|
342
|
+
if (beforeOk && afterOk) {
|
|
343
|
+
// URL/路径上下文不是产品提及:obs://bucket、/obs/bin、a@obs(对齐 Python)
|
|
344
|
+
const prev = i > 0 ? hay[i - 1] : '';
|
|
345
|
+
const nxt = j < hay.length ? hay[j] : '';
|
|
346
|
+
const prevBad = ['/', '\\', '.', '@'].includes(prev);
|
|
347
|
+
const nxtBad = [':', '/', '\\'].includes(nxt);
|
|
348
|
+
if (!prevBad && !nxtBad) spans.push([i, j]);
|
|
349
|
+
}
|
|
274
350
|
i += 1;
|
|
275
351
|
}
|
|
276
352
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-vod-devkit",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
4
4
|
"description": "VOD user-voice collection tools for DeepSeek Harness (dsh). Thin shell over the VOD external HTTP API — mirrors vod-devkit (MCP) collect semantics.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"./package.json": "./package.json"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
|
+
"test": "node --test test/*.test.mjs",
|
|
49
50
|
"build-client": "esbuild src/client.jsx --jsx=automatic --format=cjs --minify --outfile=/tmp/client-cjs.js && python3 scripts/wrap_client.py"
|
|
50
51
|
}
|
|
51
52
|
}
|