@twinsearth/dsh-fang 3.1.12 → 3.1.13

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/client.js CHANGED
@@ -1047,6 +1047,43 @@ window.__ModuleLoader__.load({
1047
1047
  -webkit-app-region:no-drag;user-select:none}
1048
1048
  .fang-web-role[hidden]{display:none}
1049
1049
  .fang-web-role--unknown{visibility:hidden}
1050
+ /* 决策中继:每个会话右侧的待选悬浮按钮 + 从右向左滑出的决策栏(v3.1.13)。 */
1051
+ .fang-relay-fab{position:fixed;right:18px;top:52%;transform:translateY(-50%);z-index:2147482900;display:inline-flex;align-items:center;gap:7px;height:36px;padding:0 12px;border-radius:999px;border:1px solid rgba(200,16,46,.35);background:#fff;color:#C8102E;box-shadow:0 8px 24px -8px rgba(200,16,46,.45);cursor:pointer;font:600 12px/1 -apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei",sans-serif;-webkit-app-region:no-drag;user-select:none}
1052
+ .fang-relay-fab:hover{background:#FFF5F7}
1053
+ .fang-relay-fab[hidden]{display:none}
1054
+ .fang-relay-count{display:inline-flex;align-items:center;justify-content:center;min-width:18px;height:18px;padding:0 5px;border-radius:999px;background:#C8102E;color:#fff;font-size:11px;font-weight:700}
1055
+ .fang-relay-panel{position:fixed;top:0;right:0;bottom:0;width:min(420px,94vw);z-index:2147483000;background:#fff;border-left:1px solid rgba(16,17,20,.12);box-shadow:-18px 0 48px rgba(16,17,20,.18);transform:translateX(102%);transition:transform .22s cubic-bezier(.22,.61,.36,1);display:flex;flex-direction:column;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei",sans-serif;font-size:13px;line-height:1.45;color:#1D1D1F}
1056
+ .fang-relay-panel.is-open{transform:translateX(0)}
1057
+ .fang-relay-backdrop{position:fixed;inset:0;z-index:2147482999;background:rgba(18,19,22,.22);opacity:0;pointer-events:none;transition:opacity .2s ease}
1058
+ .fang-relay-backdrop.is-open{opacity:1;pointer-events:auto}
1059
+ .fang-relay-head{display:flex;align-items:center;gap:8px;padding:14px 16px;border-bottom:1px solid rgba(16,17,20,.08);flex:0 0 auto}
1060
+ .fang-relay-title{font-size:14px;font-weight:700}
1061
+ .fang-relay-sub{font-size:11.5px;color:#86868B}
1062
+ .fang-relay-close{margin-left:auto;width:28px;height:28px;border-radius:8px;border:1px solid rgba(16,17,20,.12);background:#fff;color:#5F6368;cursor:pointer;font-size:15px;line-height:1}
1063
+ .fang-relay-body{flex:1 1 auto;min-height:0;overflow-y:auto;padding:12px 14px 18px;display:flex;flex-direction:column;gap:10px}
1064
+ .fang-relay-empty{font-size:12px;color:#86868B;padding:18px 6px;text-align:center}
1065
+ .fang-relay-ticket{border:1px solid rgba(16,17,20,.1);border-radius:12px;padding:10px 11px;background:#FAFAFC;display:flex;flex-direction:column;gap:7px}
1066
+ .fang-relay-ticket-head{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
1067
+ .fang-relay-level{display:inline-flex;align-items:center;height:18px;padding:0 6px;border-radius:6px;font-size:10.5px;font-weight:700;letter-spacing:.02em;background:#F2F2F5;color:#5F6368}
1068
+ .fang-relay-level--red{background:rgba(200,16,46,.08);color:#C8102E}
1069
+ .fang-relay-level--yellow{background:rgba(180,83,9,.1);color:#B45309}
1070
+ .fang-relay-level--blue{background:rgba(10,107,224,.08);color:#0A6BE0}
1071
+ .fang-relay-level--green{background:rgba(23,128,61,.08);color:#17803D}
1072
+ .fang-relay-ticket-title{font-size:13px;font-weight:600;color:#1D1D1F}
1073
+ .fang-relay-context{font-size:12px;color:#5F6368;white-space:pre-wrap;max-height:96px;overflow:auto;overscroll-behavior:contain}
1074
+ .fang-relay-options{display:flex;flex-direction:column;gap:6px}
1075
+ .fang-relay-option{display:flex;align-items:center;gap:8px;width:100%;text-align:left;border:1px solid rgba(16,17,20,.12);background:#fff;border-radius:9px;padding:8px 10px;cursor:pointer;font:inherit;font-size:12.5px;color:#1D1D1F}
1076
+ .fang-relay-option:hover{border-color:rgba(200,16,46,.4);background:#FFF7F8}
1077
+ .fang-relay-option:disabled{opacity:.55;cursor:default}
1078
+ .fang-relay-key{display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;border-radius:6px;background:#F2F2F5;color:#5F6368;font-weight:700;font-size:11px;flex:0 0 auto}
1079
+ .fang-relay-custom{display:flex;gap:6px;margin-top:2px}
1080
+ .fang-relay-input{flex:1 1 auto;min-width:0;height:32px;border-radius:9px;border:1px solid rgba(16,17,20,.14);padding:0 9px;font:inherit;font-size:12.5px;background:#fff;color:#1D1D1F}
1081
+ .fang-relay-input:focus{outline:2px solid rgba(200,16,46,.25);outline-offset:-1px}
1082
+ .fang-relay-submit{flex:0 0 auto;height:32px;padding:0 11px;border-radius:9px;border:1px solid #C8102E;background:#C8102E;color:#fff;font:600 12.5px/1 inherit;cursor:pointer}
1083
+ .fang-relay-submit:disabled{opacity:.5;cursor:default}
1084
+ .fang-relay-msg{font-size:11.5px;color:#B45309}
1085
+ .fang-relay-error{font-size:11.5px;color:#C8102E}
1086
+ @media (prefers-reduced-motion:reduce){.fang-relay-panel{transition:none}.fang-relay-backdrop{transition:none}}
1050
1087
 
1051
1088
  @media (max-width:760px){
1052
1089
  .fang-console{padding:12px 12px 18px}
@@ -5225,6 +5262,14 @@ window.__ModuleLoader__.load({
5225
5262
  method: 'POST', body: JSON.stringify({ id, option, by: 'fang-inbox' }),
5226
5263
  }))
5227
5264
  },
5265
+ /** v3.1.13:会话内直接输入决定(不要求命中预置选项)。 */
5266
+ resolveCustom(id, text) {
5267
+ const custom = String(text ?? '').trim()
5268
+ if (!custom) return Promise.resolve({ ok: false, error: 'custom-required' })
5269
+ return act('resolve-custom', () => api('/fang/api/decisions/resolve', {
5270
+ method: 'POST', body: JSON.stringify({ id, custom: custom.slice(0, 2000), by: 'fang-relay' }),
5271
+ }))
5272
+ },
5228
5273
  abandon(id) {
5229
5274
  return act('abandon', () => api('/fang/api/decisions/abandon', {
5230
5275
  method: 'POST', body: JSON.stringify({ id, by: 'fang-inbox' }),
@@ -5269,6 +5314,159 @@ window.__ModuleLoader__.load({
5269
5314
  }
5270
5315
  }
5271
5316
 
5317
+ // ── 会话内决策中继(v3.1.13)────────────────────────────────────────
5318
+ // 每个会话右侧悬浮一个「待选」按钮(仅母体角色、仅当该会话有待决策时出现);
5319
+ // 点击从右向左滑出决策栏:预置选项按 A/B/C/D 展示,也可直接输入决定。
5320
+ const RELAY_LEVEL_LABEL = Object.freeze({ red: '红', yellow: '黄', blue: '蓝', green: '绿', gray: '灰' })
5321
+ function relayPendingFor(store, sessionId) {
5322
+ const items = typeof store?.pending === 'function' ? store.pending() : []
5323
+ return (Array.isArray(items) ? items : []).filter((ticket) => {
5324
+ const source = ticket?.source && typeof ticket.source === 'object' ? ticket.source : {}
5325
+ return String(source.sessionId ?? '') === String(sessionId)
5326
+ })
5327
+ }
5328
+ function mountDecisionRelay(host, store, sessionId) {
5329
+ if (typeof document === 'undefined' || !store || !sessionId) return () => {}
5330
+ const doc = host?.ownerDocument ?? document
5331
+ try { injectStyle(doc) } catch { /* style optional */ }
5332
+ const sid = String(sessionId)
5333
+ const state = { open: false, busy: false, error: '', customs: new Map() }
5334
+ let fab = null
5335
+ let countEl = null
5336
+ let panel = null
5337
+ let backdrop = null
5338
+ let unsubscribe = null
5339
+ let keyHandler = null
5340
+ let disposed = false
5341
+ const current = () => relayPendingFor(store, sid)
5342
+ const setOpen = (next) => {
5343
+ state.open = next === true
5344
+ if (panel) panel.classList.toggle('is-open', state.open)
5345
+ if (backdrop) backdrop.classList.toggle('is-open', state.open)
5346
+ if (state.open) render()
5347
+ }
5348
+ const onKey = (event) => {
5349
+ if (state.open && (event.key === 'Escape' || event.key === 'Esc')) { event.stopPropagation(); setOpen(false) }
5350
+ }
5351
+ const submitOption = async (ticket, option) => {
5352
+ if (state.busy) return
5353
+ state.busy = true; state.error = ''
5354
+ render()
5355
+ try {
5356
+ const result = await store.resolve(ticket.id, option?.value)
5357
+ if (result && result.ok === false) state.error = '提交失败:' + String(result.reason ?? result.error ?? 'resolve-failed')
5358
+ else { state.customs.delete(String(ticket.id)); if (typeof store.refresh === 'function') await Promise.resolve(store.refresh()).catch(() => {}) }
5359
+ } catch (error) { state.error = '提交失败:' + String(error?.message ?? error) } finally {
5360
+ state.busy = false
5361
+ render()
5362
+ }
5363
+ }
5364
+ const submitCustom = async (ticket) => {
5365
+ if (state.busy) return
5366
+ const text = String(state.customs.get(String(ticket.id)) ?? '').trim()
5367
+ if (!text) { state.error = '请先输入你的决定'; render(); return }
5368
+ state.busy = true; state.error = ''
5369
+ render()
5370
+ try {
5371
+ if (typeof store.resolveCustom !== 'function') throw new Error('resolve-custom-unavailable')
5372
+ const result = await store.resolveCustom(ticket.id, text)
5373
+ if (result && result.ok === false) state.error = '提交失败:' + String(result.reason ?? result.error ?? 'resolve-failed')
5374
+ else { state.customs.delete(String(ticket.id)); if (typeof store.refresh === 'function') await Promise.resolve(store.refresh()).catch(() => {}) }
5375
+ } catch (error) { state.error = '提交失败:' + String(error?.message ?? error) } finally {
5376
+ state.busy = false
5377
+ render()
5378
+ }
5379
+ }
5380
+ const optionButton = (ticket, option, index) => {
5381
+ const key = index < 26 ? String.fromCharCode(65 + index) : String(index + 1)
5382
+ const label = String(option?.label ?? option?.value ?? '选项')
5383
+ return h('button', {
5384
+ type: 'button', class: 'fang-relay-option', disabled: state.busy || undefined,
5385
+ 'data-option-key': key, title: option?.isRecommended ? ('推荐:' + label) : label,
5386
+ onClick: () => void submitOption(ticket, option),
5387
+ }, h('span', { class: 'fang-relay-key' }, key), h('span', { class: 'fang-relay-option-label' }, label))
5388
+ }
5389
+ const ticketNode = (ticket) => {
5390
+ const level = String(ticket?.level ?? 'gray')
5391
+ const options = Array.isArray(ticket?.options) ? ticket.options : []
5392
+ const id = String(ticket?.id ?? '')
5393
+ const inputValue = state.customs.get(id) ?? ''
5394
+ return h('div', { class: 'fang-relay-ticket', 'data-decision-id': id },
5395
+ h('div', { class: 'fang-relay-ticket-head' },
5396
+ h('span', { class: 'fang-relay-level fang-relay-level--' + level }, RELAY_LEVEL_LABEL[level] ?? level),
5397
+ h('span', { class: 'fang-relay-ticket-title' }, String(ticket?.title ?? '待决策'))),
5398
+ ticket?.context ? h('div', { class: 'fang-relay-context' }, String(ticket.context)) : null,
5399
+ h('div', { class: 'fang-relay-options' },
5400
+ options.length > 0
5401
+ ? options.map((option, index) => optionButton(ticket, option, index))
5402
+ : [h('button', {
5403
+ type: 'button', class: 'fang-relay-option', disabled: state.busy || undefined,
5404
+ onClick: () => void submitOption(ticket, { value: '__ACK__' }),
5405
+ }, h('span', { class: 'fang-relay-key' }, '✓'), h('span', null, '确认收到(ACK)'))]),
5406
+ h('div', { class: 'fang-relay-custom' },
5407
+ h('input', {
5408
+ class: 'fang-relay-input', placeholder: '或输入你的决定…', 'aria-label': '输入决定',
5409
+ value: inputValue,
5410
+ onInput: (event) => state.customs.set(id, String(event.target?.value ?? '')),
5411
+ onKeydown: (event) => { if (event.key === 'Enter' && !event.shiftKey) { event.preventDefault(); void submitCustom(ticket) } },
5412
+ }),
5413
+ h('button', { type: 'button', class: 'fang-relay-submit', disabled: state.busy || undefined, onClick: () => void submitCustom(ticket) }, '提交')))
5414
+ }
5415
+ function render() {
5416
+ if (disposed) return
5417
+ const tickets = current()
5418
+ if (countEl && fab) {
5419
+ countEl.textContent = tickets.length > 99 ? '99+' : String(tickets.length)
5420
+ fab.hidden = tickets.length === 0
5421
+ fab.setAttribute('aria-label', tickets.length > 0 ? `当前会话有 ${tickets.length} 个待决策` : '当前会话没有待决策')
5422
+ }
5423
+ if (!panel) return
5424
+ const head = h('div', { class: 'fang-relay-head' },
5425
+ h('span', { class: 'fang-relay-title' }, '决策中继'),
5426
+ h('span', { class: 'fang-relay-sub' }, `会话 ${short(sid, 10)} · ${tickets.length} 个待选`),
5427
+ h('button', { type: 'button', class: 'fang-relay-close', title: '关闭', 'aria-label': '关闭决策中继', onClick: () => setOpen(false) }, '×'))
5428
+ const body = h('div', { class: 'fang-relay-body' })
5429
+ if (tickets.length === 0) {
5430
+ body.append(h('div', { class: 'fang-relay-empty' }, '当前会话没有待决策;有新的阻塞问题时这里会自动出现。'))
5431
+ } else {
5432
+ for (const ticket of tickets) body.append(ticketNode(ticket))
5433
+ }
5434
+ if (state.error) body.append(h('div', { class: 'fang-relay-error', role: 'alert' }, state.error))
5435
+ panel.replaceChildren(head, body)
5436
+ }
5437
+ const ensureChrome = () => {
5438
+ if (fab || disposed) return
5439
+ countEl = h('span', { class: 'fang-relay-count' }, '0')
5440
+ fab = h('button', {
5441
+ type: 'button', class: 'fang-relay-fab', title: '决策中继:当前会话的待决策',
5442
+ 'aria-label': '打开当前会话决策中继', 'aria-haspopup': 'dialog',
5443
+ }, h('span', { 'aria-hidden': 'true', style: { fontSize: '15px', lineHeight: 1 } }, '◈'), h('span', null, '待选'), countEl)
5444
+ backdrop = h('div', { class: 'fang-relay-backdrop' })
5445
+ panel = h('aside', { class: 'fang-relay-panel', role: 'dialog', 'aria-modal': 'false', 'aria-label': '当前会话决策中继' })
5446
+ doc.body.append(fab, backdrop, panel)
5447
+ fab.addEventListener('click', () => setOpen(!state.open))
5448
+ backdrop.addEventListener('click', () => setOpen(false))
5449
+ keyHandler = onKey
5450
+ doc.addEventListener('keydown', keyHandler, true)
5451
+ unsubscribe = typeof store.subscribe === 'function' ? store.subscribe(render) : null
5452
+ render()
5453
+ }
5454
+ void (async () => {
5455
+ try {
5456
+ const role = await detectWebRole()
5457
+ if (disposed || role !== 'mother') return
5458
+ ensureChrome()
5459
+ } catch { /* 非母体或识别失败:不显示中继 */ }
5460
+ })()
5461
+ return () => {
5462
+ disposed = true
5463
+ if (unsubscribe) { try { unsubscribe() } catch { /* ignore */ } unsubscribe = null }
5464
+ if (keyHandler) { try { doc.removeEventListener('keydown', keyHandler, true) } catch { /* ignore */ } keyHandler = null }
5465
+ for (const node of [fab, backdrop, panel]) { try { node?.remove() } catch { /* ignore */ } }
5466
+ fab = null; backdrop = null; panel = null; countEl = null
5467
+ }
5468
+ }
5469
+
5272
5470
  function mountInboxTitle(host, store) {
5273
5471
  const doc = host.ownerDocument
5274
5472
  injectStyle(doc)
@@ -6120,7 +6318,7 @@ window.__ModuleLoader__.load({
6120
6318
  // ── 插件入口 ──────────────────────────────────────────────────────────
6121
6319
  return {
6122
6320
  mountPanel,
6123
- ...(typeof window !== 'undefined' && window.__FANG_TEST_HOOK__ ? { __renderDecisionMini: renderDecisionMini, __mountWebRoleBadge: mountWebRoleBadge, __detectWebRole: detectWebRole } : {}),
6321
+ ...(typeof window !== 'undefined' && window.__FANG_TEST_HOOK__ ? { __renderDecisionMini: renderDecisionMini, __mountWebRoleBadge: mountWebRoleBadge, __detectWebRole: detectWebRole, __mountDecisionRelay: mountDecisionRelay } : {}),
6124
6322
  inject: ['slots'],
6125
6323
  apply(ctx) {
6126
6324
  const disposers = []
@@ -6178,6 +6376,16 @@ window.__ModuleLoader__.load({
6178
6376
  const inbox = createDecisionInboxStore()
6179
6377
  inbox.start()
6180
6378
  disposers.push(() => { try { inbox.stop() } catch { /* ignore */ } })
6379
+ // v3.1.13:每个会话右侧的决策中继(母体角色且该会话有待决策时显示)。
6380
+ disposers.push(ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({
6381
+ name: 'conversation.session.header.utilities',
6382
+ id: 'fang-decision-relay',
6383
+ order: 60,
6384
+ label: '决策中继',
6385
+ }, (props) => React.createElement(DomMount, {
6386
+ mount: (mountHost) => mountDecisionRelay(mountHost, inbox, String(props?.sessionId ?? '')),
6387
+ style: { display: 'none' },
6388
+ }))))
6181
6389
  openInboxExternally = () => openInbox()
6182
6390
  const tryService = (name) => {
6183
6391
  try { if (ctx && typeof ctx === 'object' && ctx[name]) return ctx[name] } catch { /* ignore */ }
@@ -0,0 +1,46 @@
1
+ # DECISION-RELAY — 会话内决策中继(v3.1.13)
2
+
3
+ ## 目标
4
+
5
+ 决策中心不再只在母体「收件箱」里处理:**每个会话自己**在右侧显示待决策入口,
6
+ 用户在该会话里直接选 A/B/C/D 或输入决定,Agent 收到结果后继续任务。
7
+ 总体界面仍在母体:收件箱(侧栏入口 + 右侧抽屉)保持原样,汇总所有会话/分身的待决策。
8
+
9
+ ## 行为
10
+
11
+ 1. **悬浮入口**:当前会话存在 `pending` 决策时,右侧边缘出现红色「◈ 待选 N」悬浮按钮;
12
+ 没有待决策时不显示(避免干扰)。入口只在**母体 Web** 注册——分身/元宝运行态不显示
13
+ (决策由母体的收件箱统一处理)。
14
+ 2. **从右向左滑出**:点击按钮,决策栏从右侧滑入(`translateX` 过渡 + 遮罩),`Esc` 或点遮罩关闭。
15
+ 3. **按会话过滤**:只显示 `source.sessionId === 当前会话` 的 ticket;其他会话/分身的票留在收件箱。
16
+ 4. **选择或输入**:
17
+ - 预置选项按 **A/B/C/D** 标号显示(超过 4 个继续 E、F…),点击即提交 `option.value`;
18
+ - 直接在输入框写决定(如“按 B 方案,先灰度 10%”),提交后作为 **custom decision**;
19
+ - 无预置选项的 green/ack 票显示「确认收到(ACK)」。
20
+ 5. 提交后按钮计数实时更新;没有待决策时按钮消失,面板提示为空。
21
+
22
+ ## 服务端语义
23
+
24
+ `POST /fang/api/decisions/resolve` 新增可选字段 `custom`:
25
+
26
+ - 仅在**显式**传 `custom` 时生效(不是“任意未知 option 都放过”);
27
+ - 去空白、上限 2000 字符;`resolvedOption = custom`、`resolvedPayload = {custom}`、
28
+ `resolutionNote = custom`、ticket 标记 `customInput: true`;
29
+ - 未传 custom 的未知 option 仍按原逻辑拒绝(`unknown-option`,fail-closed);
30
+ - Agent 的 `request_human_decision` 返回值 `selectedValue` 即用户输入/选项值,据此继续。
31
+
32
+ ## 代码位置
33
+
34
+ | 文件 | 作用 |
35
+ |---|---|
36
+ | `client.js` | `mountDecisionRelay()`:悬浮按钮 + 右滑面板 + A/B/C/D + 自定义输入;slot `conversation.session.header.utilities`;store 新增 `resolveCustom()` |
37
+ | `src/plugins/decision-center.mjs` | `resolve()` 接受 `custom`;`publicTicket` 暴露 `customInput` |
38
+ | `src/plugins/orchestrator.mjs` | `/fang/api/decisions/resolve` 透传 `custom` |
39
+ | `test/decision-relay-dom.test.mjs` | 入口/面板/选项/自定义输入/会话过滤/fork 不挂载 |
40
+ | `test/decision-center.test.mjs` | custom 解析 + 未知 option 仍 fail-closed |
41
+
42
+ ## 边界
43
+
44
+ - 只在母体 Web 的会话里出现;分身 Web 的决策仍在母体收件箱处理。
45
+ - 悬浮按钮依赖 DSH 会话 header utilities 槽与 sessionId 标准属性;DSH 大版本升级需回归对应 DOM 测试。
46
+ - 自定义输入会作为决定原文写入 ticket/审计,注意不要输入密钥等敏感信息。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/dsh-fang",
3
- "version": "3.1.12",
3
+ "version": "3.1.13",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "dsh-Fang (瓮城) — mother/fork plugin development environment for DeepSeek Harness: one readonly mother, a disposable child dsh-Web per task.",
@@ -128,7 +128,7 @@ export const AUDIT = {
128
128
  RUNTIME_ERROR: 'runtime-error',
129
129
  }
130
130
 
131
- export const FANG_VERSION = '3.1.12'
131
+ export const FANG_VERSION = '3.1.13'
132
132
 
133
133
  /**
134
134
  * @typedef {object} ForkInfo
@@ -232,6 +232,7 @@ function publicTicket(ticket) {
232
232
  isBlocking: ticket.isBlocking === true,
233
233
  resolvedBy: ticket.resolvedBy ?? null,
234
234
  resolutionNote: ticket.resolutionNote ?? null,
235
+ customInput: ticket.customInput === true,
235
236
  }
236
237
  }
237
238
 
@@ -726,23 +727,32 @@ export function apply(ctx, config) {
726
727
  ? optionValue
727
728
  : { value: optionValue }
728
729
  const rawValue = String(requested.value ?? requested.id ?? '').trim()
729
- if (!rawValue) return { ok: false, reason: 'option-required', id: ticket.id }
730
- const matched = ticket.options.find((option) => option.value === rawValue || option.id === rawValue)
731
- if (ticket.options.length > 0 && !matched) {
730
+ // v3.1.13:会话内联决策允许“直接输入”代替预置选项。只有显式传 custom 才走这条
731
+ // 路径,避免把误传的任意字符串当成决定;长度上限防注入超长内容。
732
+ const customText = options.custom === undefined || options.custom === null
733
+ ? ''
734
+ : String(options.custom).trim().slice(0, 2000)
735
+ if (!rawValue && !customText) return { ok: false, reason: 'option-required', id: ticket.id }
736
+ const matched = rawValue ? ticket.options.find((option) => option.value === rawValue || option.id === rawValue) : null
737
+ const useCustom = !matched && customText.length > 0
738
+ if (!useCustom && ticket.options.length > 0 && !matched) {
732
739
  return { ok: false, reason: 'unknown-option', id: ticket.id, allowed: ticket.options.map((option) => option.value) }
733
740
  }
734
- if (ticket.options.length === 0 && rawValue !== '__ACK__') {
741
+ if (!useCustom && ticket.options.length === 0 && rawValue !== '__ACK__') {
735
742
  return { ok: false, reason: 'unknown-option', id: ticket.id, allowed: ['__ACK__'] }
736
743
  }
737
- const isAck = ticket.options.length === 0
744
+ const isAck = !useCustom && ticket.options.length === 0
738
745
  ticket.status = 'resolved'
739
746
  ticket.outcome = isAck ? 'acked' : 'resolved'
740
- ticket.resolvedOption = isAck ? null : matched.value
741
- ticket.selectedActionId = isAck ? 'ack' : (matched.id ?? matched.value)
742
- ticket.resolvedPayload = isAck ? null : (requested.payload ?? matched.payload ?? null)
747
+ ticket.resolvedOption = useCustom ? customText : (isAck ? null : matched.value)
748
+ ticket.customInput = useCustom
749
+ ticket.selectedActionId = useCustom ? null : (isAck ? 'ack' : (matched.id ?? matched.value))
750
+ ticket.resolvedPayload = useCustom ? { custom: customText } : (isAck ? null : (requested.payload ?? matched.payload ?? null))
743
751
  ticket.resolvedAt = nowMs()
744
752
  ticket.resolvedBy = options.by === undefined || options.by === null ? null : String(options.by)
745
- ticket.resolutionNote = options.note === undefined || options.note === null ? null : String(options.note)
753
+ ticket.resolutionNote = options.note === undefined || options.note === null
754
+ ? (useCustom ? customText : null)
755
+ : String(options.note)
746
756
  const aiOutcome = recordAiAdoption(ticket, ticket.resolvedOption, ticket.outcome)
747
757
  ticket.rev = nextRevision()
748
758
  settleWaiter(ticket.id, publicTicket(ticket))
@@ -2815,9 +2815,13 @@ export function apply(ctx, config) {
2815
2815
  const out = center.resolveMany(body.ids, { option: body?.option, by: body?.by ?? 'fang-api', note: body?.note })
2816
2816
  return json(res, 200, out)
2817
2817
  }
2818
+ const resolveOptions = { by: body?.by ?? 'fang-api', note: body?.note }
2819
+ // v3.1.13:只有显式传 custom 时才把字段交给服务层;undefined 字段不进
2820
+ // options(旧调用方/测试对 {by,note} 的形状有断言)。
2821
+ if (body?.custom !== undefined) resolveOptions.custom = body.custom
2818
2822
  const out = (body?.actionId !== undefined && typeof center.resolveAction === 'function')
2819
- ? center.resolveAction(body?.id, body.actionId, body?.payload, { by: body?.by ?? 'fang-api', note: body?.note })
2820
- : center.resolve(body?.id, body?.option, { by: body?.by ?? 'fang-api', note: body?.note })
2823
+ ? center.resolveAction(body?.id, body.actionId, body?.payload, resolveOptions)
2824
+ : center.resolve(body?.id, body?.option, resolveOptions)
2821
2825
  const status = out.ok ? 200
2822
2826
  : out.reason === 'not-found' ? 404
2823
2827
  : out.reason === 'option-required' || out.reason === 'unknown-option' ? 400