@master0071/dsh-systemone 0.7.1 → 0.7.2

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 CHANGED
@@ -432,7 +432,7 @@ refs:
432
432
 
433
433
  ## 添加自定义场景
434
434
 
435
- **推荐用图形配置页**:插件 → @master0071/dsh-systemone → systemone → 「自定义场景」卡片,粘贴 JSON 即可。编辑框会实时校验(JSON 语法、`id`/`title`/`questions`、问题类型与选项数量),不通过时保存按钮禁用并给出具体原因;保存后场景库立即重建,新场景的 id 也会自动出现在「固定场景」的候选列表里。
435
+ **推荐用图形配置页**:插件 → @master0071/dsh-systemone → systemone → 「自定义场景」卡片,粘贴 JSON 即可。编辑框会实时校验(JSON 语法、`id`/`title`/`questions`、问题类型与选项数量、`patch` 的目标是否存在),不通过时保存按钮禁用并给出具体原因;保存后场景库立即重建,新场景的 id 也会自动出现在「固定场景」的候选列表里。
436
436
 
437
437
  卡片右上角的**「插入意图识别模板」**会填入下面这个通用意图识别场景,改 `criteria` 即可用。
438
438
 
@@ -440,6 +440,7 @@ refs:
440
440
 
441
441
  覆盖与别名的解析规则:
442
442
 
443
+ - **patch 的目标必须已存在**:内置 11 个场景,或**本数组中更早出现**的自定义场景。宿主按数组顺序登记(与 `indexById` 语义一致),指向不存在或更晚出现的 id 会被**整条跳过**——配置页会提前报“patch 目标不存在”,不必等日志。
443
444
  - **patch 式覆盖**:默认同 `id` 是**整体替换**。只想改一两个字段时,给条目加 `"patch": true` 即可做**字段级合并**——`title`/`description`/`recommendation` 给了才覆盖;`questions` 按 qid 合并(只换给出的字段,如只覆盖某个问题的 `criteria`,其余问题原样保留,新 qid 追加);`derive` 同名覆盖;`aliases` 求并集。例如给 `customer_service` 的部门问题加一个 VIP 通道:
444
445
 
445
446
  ```json
@@ -586,7 +587,7 @@ SystemOne 是「结构化问题 → 概率分布」的决策模型,**不是开
586
587
 
587
588
  ```powershell
588
589
  npm run check # 9 个 lib/*.js 语法检查通过
589
- npm run test # 198 项测试:
590
+ npm run test # 203 项测试:
590
591
  # - 场景库完整性、11 大场景端到端(有断言强制 sample 覆盖全部内置场景)、
591
592
  # 自定义场景合并/覆盖/patch/非法跳过
592
593
  # - params 覆盖语义、确定性、失败路径(无网络、无 Key)
@@ -595,7 +596,8 @@ npm run test # 198 项测试:
595
596
  # 缓存与"改配置即失效"、去重、跳过规则、历史捕获、自动路由、
596
597
  # 路由复用与热失效、失败熔断、卸载)
597
598
  # - 用量台账(累计、跨日、重启后从文件恢复、坏行容错、日限判定)
598
- # - 配置页(场景 JSON 校验、数字范围、保存被拒的冲突/校验区分、
599
+ # - 配置页(场景 JSON 校验、patch 目标存在性与顺序语义、数字范围、
600
+ # 保存被拒的冲突/校验区分、
599
601
  # 三张卡各自保存(提交的 ops 只含本卡字段)、清除 Key 的 unset 语义、
600
602
  # 加载态与"为什么不能保存"的渲染冒烟)
601
603
  ```
package/lib/client.js CHANGED
@@ -42,7 +42,7 @@ window.__ModuleLoader__.load({
42
42
  tabCustom: '自定义场景',
43
43
  tabCustomHint: '用 JSON 定义自己的场景(含「通用意图识别」)。保存后场景库立即重建,无需重启。',
44
44
  customScenarios: '场景定义(JSON 数组)',
45
- customScenariosHint: '同 id 默认整体覆盖内置场景;加 "patch": true 则只改给出的字段。留空 [] 表示只用内置 11 个。每个场景最多 16 个问题,choice 选项 2~26 个。',
45
+ customScenariosHint: '同 id 默认整体覆盖内置场景;加 "patch": true 则只改给出的字段。patch 的目标必须是内置场景,或本数组中更早出现的自定义场景。留空 [] 表示只用内置 11 个。每个场景最多 16 个问题,choice 选项 2~26 个。',
46
46
  customScenariosPlaceholder: '[\n {\n "id": "intent",\n "title": "通用意图识别",\n "questions": {\n "intent": {\n "type": "choice",\n "instructions": "用户最想做什么?",\n "criteria": { "query": "查询", "action": "执行操作", "chat": "闲聊" }\n }\n }\n }\n]',
47
47
  insertTemplate: '插入意图识别模板',
48
48
  jsonEmpty: '(空 = 只用内置场景)',
@@ -137,7 +137,7 @@ window.__ModuleLoader__.load({
137
137
  tabCustom: 'Custom scenarios',
138
138
  tabCustomHint: 'Define your own scenarios in JSON (including general intent recognition). Saving rebuilds the library immediately.',
139
139
  customScenarios: 'Scenario definitions (JSON array)',
140
- customScenariosHint: 'An id matching a built-in overrides it; add "patch": true to merge only the given fields. Empty [] keeps only the 11 built-ins. Max 16 questions per scenario, 2~26 choice options.',
140
+ customScenariosHint: 'An id matching a built-in overrides it; add "patch": true to merge only the given fields. A patch target must be a built-in, or a custom scenario declared earlier in this array. Empty [] keeps only the 11 built-ins. Max 16 questions per scenario, 2~26 choice options.',
141
141
  customScenariosPlaceholder: '[\n {\n "id": "intent",\n "title": "General intent",\n "questions": {\n "intent": {\n "type": "choice",\n "instructions": "What does the user want?",\n "criteria": { "query": "Look up", "action": "Do something", "chat": "Small talk" }\n }\n }\n }\n]',
142
142
  insertTemplate: 'Insert intent template',
143
143
  jsonEmpty: '(empty = built-in scenarios only)',
@@ -359,8 +359,9 @@ window.__ModuleLoader__.load({
359
359
  * 客户端侧校验自定义场景 JSON。
360
360
  *
361
361
  * 只做「能立刻发现」的检查:JSON 语法 + 每条的 id/title/questions 与
362
- * 问题类型/选项数量。宿主侧 `resolveScenarios` 还会做一遍同样的校验,
363
- * 语义问题(非法条目)宿主会跳过并写入日志;这里提前拦住,用户不必去翻日志。
362
+ * 问题类型/选项数量,以及 `patch` 的目标是否存在。宿主侧 `resolveScenarios`
363
+ * 还会做一遍同样的校验,语义问题(非法条目)宿主会跳过并写入日志;
364
+ * 这里提前拦住,用户不必去翻日志。
364
365
  *
365
366
  * @param {string} text - 编辑框里的原始文本
366
367
  * @returns {{ ok: boolean, error?: string, ids: string[], count: number }}
@@ -378,6 +379,9 @@ window.__ModuleLoader__.load({
378
379
  if (!Array.isArray(parsed)) return { ok: false, error: 'notArray', ids: [], count: 0 }
379
380
 
380
381
  const ids = []
382
+ // patch 只能改「已有」场景:内置 11 个,或本数组里**更早**出现的自定义条目。
383
+ // 与宿主 `resolveScenarios` 的 indexById 语义一致(内置先行、按数组顺序登记)。
384
+ const known = new Set(SCENARIO_OPTIONS.map((option) => option.id.toLowerCase()))
381
385
  for (let i = 0; i < parsed.length; i += 1) {
382
386
  const spec = parsed[i]
383
387
  const at = i + 1
@@ -387,6 +391,11 @@ window.__ModuleLoader__.load({
387
391
  const issues = []
388
392
  const isPatch = spec.patch === true
389
393
  if (typeof spec.id !== 'string' || spec.id.trim() === '') issues.push('缺少 id')
394
+ // 目标不存在时宿主会整条跳过(只写日志),界面若仍报「JSON 有效」,
395
+ // 用户会以为改好了——所以这里必须提前拦住。
396
+ else if (isPatch && !known.has(spec.id.trim().toLowerCase())) {
397
+ issues.push('patch 目标不存在(只能是内置场景,或本数组中更早出现的自定义场景)')
398
+ }
390
399
  if (!isPatch && (typeof spec.title !== 'string' || spec.title.trim() === '')) issues.push('缺少 title')
391
400
  const questions = spec.questions
392
401
  if (!isPatch || questions !== undefined) {
@@ -442,7 +451,11 @@ window.__ModuleLoader__.load({
442
451
  if (issues.length > 0) {
443
452
  return { ok: false, error: `issues:${at}:${spec.id ?? '?'}:${issues.join(';')}`, ids, count: 0 }
444
453
  }
445
- if (typeof spec.id === 'string') ids.push(spec.id.trim())
454
+ if (typeof spec.id === 'string') {
455
+ ids.push(spec.id.trim())
456
+ // 后续条目的 patch 可以指向它(与宿主按顺序登记一致)
457
+ known.add(spec.id.trim().toLowerCase())
458
+ }
446
459
  }
447
460
  return { ok: true, ids, count: ids.length }
448
461
  }
@@ -1112,6 +1125,7 @@ window.__ModuleLoader__.load({
1112
1125
  numberErrorFor,
1113
1126
  saveResultText,
1114
1127
  cardOps,
1128
+ SCENARIO_OPTIONS,
1115
1129
  SERVICE_FIELDS,
1116
1130
  CUSTOM_FIELDS,
1117
1131
  AUTO_FIELDS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@master0071/dsh-systemone",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "DeepSeek Harness 插件:将 SystemOne 决策模型(默认云知声 u2-decision,可切换提供商)接入软件开发、需求预检、客服、内容审核、路由、销售线索、风控、招聘、数据治理、教育、需求变更等 11 大业务场景,为 Agent 返回带概率分布的决策与处置建议。",
5
5
  "license": "MIT",
6
6
  "type": "module",