@twinsearth/dsh-fang 3.1.12 → 3.1.14

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
@@ -450,14 +450,22 @@ window.__ModuleLoader__.load({
450
450
  const role = String(status.body.role ?? 'mother')
451
451
  if (role === 'mother') return 'mother'
452
452
  }
453
- } catch { /* fall through to adapter handshake */ }
454
- // 元主 / 分身:两者都是 fork 角色的 DSH 实例;adapter hello 给出 kind。
453
+ } catch { /* fall through to identity route */ }
454
+ // 元主 / 分身:fork 角色的 adapter 带 Bearer 鉴权,浏览器拿不到 token,
455
+ // 因此用公开只读的 /fang/adapter/identity(v3.1.14 起)。
456
+ try {
457
+ const identity = await api('/fang/adapter/identity')
458
+ if (identity.status === 200 && identity.body) {
459
+ const kind = String(identity.body.kind ?? '')
460
+ if (kind === 'mother' || kind === 'essence' || kind === 'fork') return kind
461
+ }
462
+ } catch { /* fall through to legacy hello */ }
463
+ // 兼容旧宿主(adapter 无 identity 路由):尝试 hello(可能 401),旧运行态按 rt- 前缀兜底。
455
464
  try {
456
465
  const hello = await api('/fang/adapter/hello')
457
466
  if (hello.status === 200 && hello.body) {
458
467
  const kind = String(hello.body.kind ?? '')
459
468
  if (kind === 'mother' || kind === 'essence' || kind === 'fork') return kind
460
- // 旧宿主没有 kind:元宝运行态的 forkId 是 rt-<essenceId>,任务是 task_/标题 id。
461
469
  const taskId = String(hello.body.taskId ?? '')
462
470
  return /^rt-/.test(taskId) ? 'essence' : 'fork'
463
471
  }
@@ -488,6 +496,9 @@ window.__ModuleLoader__.load({
488
496
  if (el.textContent !== label) el.textContent = label
489
497
  if (el.hidden !== hidden) el.hidden = hidden
490
498
  if (el.dataset.fangWebRole !== role) el.dataset.fangWebRole = role
499
+ for (const kind of ['mother', 'essence', 'fork']) {
500
+ el.classList.toggle('fang-web-role--' + kind, role === kind)
501
+ }
491
502
  if (el.title !== title) el.title = title
492
503
  if (el.getAttribute('aria-label') !== title) el.setAttribute('aria-label', title)
493
504
  }
@@ -1041,12 +1052,52 @@ window.__ModuleLoader__.load({
1041
1052
  .live{position:absolute!important;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
1042
1053
  /* Web 端角色徽标:母体 / 元主 / 分身 —— 挂在侧栏品牌词右侧,仅用于识别当前实例身份。 */
1043
1054
  .fang-web-role{display:inline-flex;align-items:center;height:18px;margin-left:7px;padding:0 6px;border-radius:6px;
1044
- border:1px solid rgba(200,16,46,.32);background:rgba(200,16,46,.07);color:#C8102E;
1055
+ border:1px solid transparent;background:transparent;color:#C8102E;
1045
1056
  font-size:11.5px;font-weight:700;letter-spacing:.02em;line-height:1;white-space:nowrap;
1046
1057
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei",sans-serif;vertical-align:middle;
1047
1058
  -webkit-app-region:no-drag;user-select:none}
1059
+ .fang-web-role--mother{border-color:rgba(200,16,46,.32);background:rgba(200,16,46,.07);color:#C8102E}
1060
+ .fang-web-role--essence{border-color:rgba(10,107,224,.32);background:rgba(10,107,224,.08);color:#0A6BE0}
1061
+ .fang-web-role--fork{border-color:rgba(23,128,61,.32);background:rgba(23,128,61,.08);color:#17803D}
1048
1062
  .fang-web-role[hidden]{display:none}
1049
1063
  .fang-web-role--unknown{visibility:hidden}
1064
+ /* 决策中继:每个会话右侧的待选悬浮按钮 + 从右向左滑出的决策栏(v3.1.13)。 */
1065
+ .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}
1066
+ .fang-relay-fab:hover{background:#FFF5F7}
1067
+ .fang-relay-fab[hidden]{display:none}
1068
+ .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}
1069
+ .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}
1070
+ .fang-relay-panel.is-open{transform:translateX(0)}
1071
+ .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}
1072
+ .fang-relay-backdrop.is-open{opacity:1;pointer-events:auto}
1073
+ .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}
1074
+ .fang-relay-title{font-size:14px;font-weight:700}
1075
+ .fang-relay-sub{font-size:11.5px;color:#86868B}
1076
+ .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}
1077
+ .fang-relay-body{flex:1 1 auto;min-height:0;overflow-y:auto;padding:12px 14px 18px;display:flex;flex-direction:column;gap:10px}
1078
+ .fang-relay-empty{font-size:12px;color:#86868B;padding:18px 6px;text-align:center}
1079
+ .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}
1080
+ .fang-relay-ticket-head{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
1081
+ .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}
1082
+ .fang-relay-level--red{background:rgba(200,16,46,.08);color:#C8102E}
1083
+ .fang-relay-level--yellow{background:rgba(180,83,9,.1);color:#B45309}
1084
+ .fang-relay-level--blue{background:rgba(10,107,224,.08);color:#0A6BE0}
1085
+ .fang-relay-level--green{background:rgba(23,128,61,.08);color:#17803D}
1086
+ .fang-relay-ticket-title{font-size:13px;font-weight:600;color:#1D1D1F}
1087
+ .fang-relay-context{font-size:12px;color:#5F6368;white-space:pre-wrap;max-height:96px;overflow:auto;overscroll-behavior:contain}
1088
+ .fang-relay-options{display:flex;flex-direction:column;gap:6px}
1089
+ .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}
1090
+ .fang-relay-option:hover{border-color:rgba(200,16,46,.4);background:#FFF7F8}
1091
+ .fang-relay-option:disabled{opacity:.55;cursor:default}
1092
+ .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}
1093
+ .fang-relay-custom{display:flex;gap:6px;margin-top:2px}
1094
+ .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}
1095
+ .fang-relay-input:focus{outline:2px solid rgba(200,16,46,.25);outline-offset:-1px}
1096
+ .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}
1097
+ .fang-relay-submit:disabled{opacity:.5;cursor:default}
1098
+ .fang-relay-msg{font-size:11.5px;color:#B45309}
1099
+ .fang-relay-error{font-size:11.5px;color:#C8102E}
1100
+ @media (prefers-reduced-motion:reduce){.fang-relay-panel{transition:none}.fang-relay-backdrop{transition:none}}
1050
1101
 
1051
1102
  @media (max-width:760px){
1052
1103
  .fang-console{padding:12px 12px 18px}
@@ -5225,6 +5276,14 @@ window.__ModuleLoader__.load({
5225
5276
  method: 'POST', body: JSON.stringify({ id, option, by: 'fang-inbox' }),
5226
5277
  }))
5227
5278
  },
5279
+ /** v3.1.13:会话内直接输入决定(不要求命中预置选项)。 */
5280
+ resolveCustom(id, text) {
5281
+ const custom = String(text ?? '').trim()
5282
+ if (!custom) return Promise.resolve({ ok: false, error: 'custom-required' })
5283
+ return act('resolve-custom', () => api('/fang/api/decisions/resolve', {
5284
+ method: 'POST', body: JSON.stringify({ id, custom: custom.slice(0, 2000), by: 'fang-relay' }),
5285
+ }))
5286
+ },
5228
5287
  abandon(id) {
5229
5288
  return act('abandon', () => api('/fang/api/decisions/abandon', {
5230
5289
  method: 'POST', body: JSON.stringify({ id, by: 'fang-inbox' }),
@@ -5269,6 +5328,159 @@ window.__ModuleLoader__.load({
5269
5328
  }
5270
5329
  }
5271
5330
 
5331
+ // ── 会话内决策中继(v3.1.13)────────────────────────────────────────
5332
+ // 每个会话右侧悬浮一个「待选」按钮(仅母体角色、仅当该会话有待决策时出现);
5333
+ // 点击从右向左滑出决策栏:预置选项按 A/B/C/D 展示,也可直接输入决定。
5334
+ const RELAY_LEVEL_LABEL = Object.freeze({ red: '红', yellow: '黄', blue: '蓝', green: '绿', gray: '灰' })
5335
+ function relayPendingFor(store, sessionId) {
5336
+ const items = typeof store?.pending === 'function' ? store.pending() : []
5337
+ return (Array.isArray(items) ? items : []).filter((ticket) => {
5338
+ const source = ticket?.source && typeof ticket.source === 'object' ? ticket.source : {}
5339
+ return String(source.sessionId ?? '') === String(sessionId)
5340
+ })
5341
+ }
5342
+ function mountDecisionRelay(host, store, sessionId) {
5343
+ if (typeof document === 'undefined' || !store || !sessionId) return () => {}
5344
+ const doc = host?.ownerDocument ?? document
5345
+ try { injectStyle(doc) } catch { /* style optional */ }
5346
+ const sid = String(sessionId)
5347
+ const state = { open: false, busy: false, error: '', customs: new Map() }
5348
+ let fab = null
5349
+ let countEl = null
5350
+ let panel = null
5351
+ let backdrop = null
5352
+ let unsubscribe = null
5353
+ let keyHandler = null
5354
+ let disposed = false
5355
+ const current = () => relayPendingFor(store, sid)
5356
+ const setOpen = (next) => {
5357
+ state.open = next === true
5358
+ if (panel) panel.classList.toggle('is-open', state.open)
5359
+ if (backdrop) backdrop.classList.toggle('is-open', state.open)
5360
+ if (state.open) render()
5361
+ }
5362
+ const onKey = (event) => {
5363
+ if (state.open && (event.key === 'Escape' || event.key === 'Esc')) { event.stopPropagation(); setOpen(false) }
5364
+ }
5365
+ const submitOption = async (ticket, option) => {
5366
+ if (state.busy) return
5367
+ state.busy = true; state.error = ''
5368
+ render()
5369
+ try {
5370
+ const result = await store.resolve(ticket.id, option?.value)
5371
+ if (result && result.ok === false) state.error = '提交失败:' + String(result.reason ?? result.error ?? 'resolve-failed')
5372
+ else { state.customs.delete(String(ticket.id)); if (typeof store.refresh === 'function') await Promise.resolve(store.refresh()).catch(() => {}) }
5373
+ } catch (error) { state.error = '提交失败:' + String(error?.message ?? error) } finally {
5374
+ state.busy = false
5375
+ render()
5376
+ }
5377
+ }
5378
+ const submitCustom = async (ticket) => {
5379
+ if (state.busy) return
5380
+ const text = String(state.customs.get(String(ticket.id)) ?? '').trim()
5381
+ if (!text) { state.error = '请先输入你的决定'; render(); return }
5382
+ state.busy = true; state.error = ''
5383
+ render()
5384
+ try {
5385
+ if (typeof store.resolveCustom !== 'function') throw new Error('resolve-custom-unavailable')
5386
+ const result = await store.resolveCustom(ticket.id, text)
5387
+ if (result && result.ok === false) state.error = '提交失败:' + String(result.reason ?? result.error ?? 'resolve-failed')
5388
+ else { state.customs.delete(String(ticket.id)); if (typeof store.refresh === 'function') await Promise.resolve(store.refresh()).catch(() => {}) }
5389
+ } catch (error) { state.error = '提交失败:' + String(error?.message ?? error) } finally {
5390
+ state.busy = false
5391
+ render()
5392
+ }
5393
+ }
5394
+ const optionButton = (ticket, option, index) => {
5395
+ const key = index < 26 ? String.fromCharCode(65 + index) : String(index + 1)
5396
+ const label = String(option?.label ?? option?.value ?? '选项')
5397
+ return h('button', {
5398
+ type: 'button', class: 'fang-relay-option', disabled: state.busy || undefined,
5399
+ 'data-option-key': key, title: option?.isRecommended ? ('推荐:' + label) : label,
5400
+ onClick: () => void submitOption(ticket, option),
5401
+ }, h('span', { class: 'fang-relay-key' }, key), h('span', { class: 'fang-relay-option-label' }, label))
5402
+ }
5403
+ const ticketNode = (ticket) => {
5404
+ const level = String(ticket?.level ?? 'gray')
5405
+ const options = Array.isArray(ticket?.options) ? ticket.options : []
5406
+ const id = String(ticket?.id ?? '')
5407
+ const inputValue = state.customs.get(id) ?? ''
5408
+ return h('div', { class: 'fang-relay-ticket', 'data-decision-id': id },
5409
+ h('div', { class: 'fang-relay-ticket-head' },
5410
+ h('span', { class: 'fang-relay-level fang-relay-level--' + level }, RELAY_LEVEL_LABEL[level] ?? level),
5411
+ h('span', { class: 'fang-relay-ticket-title' }, String(ticket?.title ?? '待决策'))),
5412
+ ticket?.context ? h('div', { class: 'fang-relay-context' }, String(ticket.context)) : null,
5413
+ h('div', { class: 'fang-relay-options' },
5414
+ options.length > 0
5415
+ ? options.map((option, index) => optionButton(ticket, option, index))
5416
+ : [h('button', {
5417
+ type: 'button', class: 'fang-relay-option', disabled: state.busy || undefined,
5418
+ onClick: () => void submitOption(ticket, { value: '__ACK__' }),
5419
+ }, h('span', { class: 'fang-relay-key' }, '✓'), h('span', null, '确认收到(ACK)'))]),
5420
+ h('div', { class: 'fang-relay-custom' },
5421
+ h('input', {
5422
+ class: 'fang-relay-input', placeholder: '或输入你的决定…', 'aria-label': '输入决定',
5423
+ value: inputValue,
5424
+ onInput: (event) => state.customs.set(id, String(event.target?.value ?? '')),
5425
+ onKeydown: (event) => { if (event.key === 'Enter' && !event.shiftKey) { event.preventDefault(); void submitCustom(ticket) } },
5426
+ }),
5427
+ h('button', { type: 'button', class: 'fang-relay-submit', disabled: state.busy || undefined, onClick: () => void submitCustom(ticket) }, '提交')))
5428
+ }
5429
+ function render() {
5430
+ if (disposed) return
5431
+ const tickets = current()
5432
+ if (countEl && fab) {
5433
+ countEl.textContent = tickets.length > 99 ? '99+' : String(tickets.length)
5434
+ fab.hidden = tickets.length === 0
5435
+ fab.setAttribute('aria-label', tickets.length > 0 ? `当前会话有 ${tickets.length} 个待决策` : '当前会话没有待决策')
5436
+ }
5437
+ if (!panel) return
5438
+ const head = h('div', { class: 'fang-relay-head' },
5439
+ h('span', { class: 'fang-relay-title' }, '决策中继'),
5440
+ h('span', { class: 'fang-relay-sub' }, `会话 ${short(sid, 10)} · ${tickets.length} 个待选`),
5441
+ h('button', { type: 'button', class: 'fang-relay-close', title: '关闭', 'aria-label': '关闭决策中继', onClick: () => setOpen(false) }, '×'))
5442
+ const body = h('div', { class: 'fang-relay-body' })
5443
+ if (tickets.length === 0) {
5444
+ body.append(h('div', { class: 'fang-relay-empty' }, '当前会话没有待决策;有新的阻塞问题时这里会自动出现。'))
5445
+ } else {
5446
+ for (const ticket of tickets) body.append(ticketNode(ticket))
5447
+ }
5448
+ if (state.error) body.append(h('div', { class: 'fang-relay-error', role: 'alert' }, state.error))
5449
+ panel.replaceChildren(head, body)
5450
+ }
5451
+ const ensureChrome = () => {
5452
+ if (fab || disposed) return
5453
+ countEl = h('span', { class: 'fang-relay-count' }, '0')
5454
+ fab = h('button', {
5455
+ type: 'button', class: 'fang-relay-fab', title: '决策中继:当前会话的待决策',
5456
+ 'aria-label': '打开当前会话决策中继', 'aria-haspopup': 'dialog',
5457
+ }, h('span', { 'aria-hidden': 'true', style: { fontSize: '15px', lineHeight: 1 } }, '◈'), h('span', null, '待选'), countEl)
5458
+ backdrop = h('div', { class: 'fang-relay-backdrop' })
5459
+ panel = h('aside', { class: 'fang-relay-panel', role: 'dialog', 'aria-modal': 'false', 'aria-label': '当前会话决策中继' })
5460
+ doc.body.append(fab, backdrop, panel)
5461
+ fab.addEventListener('click', () => setOpen(!state.open))
5462
+ backdrop.addEventListener('click', () => setOpen(false))
5463
+ keyHandler = onKey
5464
+ doc.addEventListener('keydown', keyHandler, true)
5465
+ unsubscribe = typeof store.subscribe === 'function' ? store.subscribe(render) : null
5466
+ render()
5467
+ }
5468
+ void (async () => {
5469
+ try {
5470
+ const role = await detectWebRole()
5471
+ if (disposed || role !== 'mother') return
5472
+ ensureChrome()
5473
+ } catch { /* 非母体或识别失败:不显示中继 */ }
5474
+ })()
5475
+ return () => {
5476
+ disposed = true
5477
+ if (unsubscribe) { try { unsubscribe() } catch { /* ignore */ } unsubscribe = null }
5478
+ if (keyHandler) { try { doc.removeEventListener('keydown', keyHandler, true) } catch { /* ignore */ } keyHandler = null }
5479
+ for (const node of [fab, backdrop, panel]) { try { node?.remove() } catch { /* ignore */ } }
5480
+ fab = null; backdrop = null; panel = null; countEl = null
5481
+ }
5482
+ }
5483
+
5272
5484
  function mountInboxTitle(host, store) {
5273
5485
  const doc = host.ownerDocument
5274
5486
  injectStyle(doc)
@@ -6120,7 +6332,7 @@ window.__ModuleLoader__.load({
6120
6332
  // ── 插件入口 ──────────────────────────────────────────────────────────
6121
6333
  return {
6122
6334
  mountPanel,
6123
- ...(typeof window !== 'undefined' && window.__FANG_TEST_HOOK__ ? { __renderDecisionMini: renderDecisionMini, __mountWebRoleBadge: mountWebRoleBadge, __detectWebRole: detectWebRole } : {}),
6335
+ ...(typeof window !== 'undefined' && window.__FANG_TEST_HOOK__ ? { __renderDecisionMini: renderDecisionMini, __mountWebRoleBadge: mountWebRoleBadge, __detectWebRole: detectWebRole, __mountDecisionRelay: mountDecisionRelay } : {}),
6124
6336
  inject: ['slots'],
6125
6337
  apply(ctx) {
6126
6338
  const disposers = []
@@ -6178,6 +6390,16 @@ window.__ModuleLoader__.load({
6178
6390
  const inbox = createDecisionInboxStore()
6179
6391
  inbox.start()
6180
6392
  disposers.push(() => { try { inbox.stop() } catch { /* ignore */ } })
6393
+ // v3.1.13:每个会话右侧的决策中继(母体角色且该会话有待决策时显示)。
6394
+ disposers.push(ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({
6395
+ name: 'conversation.session.header.utilities',
6396
+ id: 'fang-decision-relay',
6397
+ order: 60,
6398
+ label: '决策中继',
6399
+ }, (props) => React.createElement(DomMount, {
6400
+ mount: (mountHost) => mountDecisionRelay(mountHost, inbox, String(props?.sessionId ?? '')),
6401
+ style: { display: 'none' },
6402
+ }))))
6181
6403
  openInboxExternally = () => openInbox()
6182
6404
  const tryService = (name) => {
6183
6405
  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.14",
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.14'
132
132
 
133
133
  /**
134
134
  * @typedef {object} ForkInfo
@@ -191,6 +191,7 @@ export const ADAPTER_OP = {
191
191
  /** Adapter HTTP route suffixes (fork side). */
192
192
  export const ADAPTER_ROUTE = {
193
193
  HELLO: '/adapter/hello',
194
+ IDENTITY: '/adapter/identity',
194
195
  STATUS: '/adapter/status',
195
196
  APPROVALS: '/adapter/approvals',
196
197
  AUDIT: '/adapter/audit',
@@ -235,6 +235,18 @@ function readPluginTree(dir) {
235
235
  return { ok: true, files, count: Object.keys(files).length, bytes }
236
236
  }
237
237
 
238
+ /**
239
+ * 角色 → Web 端身份 kind(纯函数,便于测试)。
240
+ * 母体 = mother;元宝运行态 = essence(DSH_FANG_ESSENCE 或 rt- forkId);
241
+ * 其余 fork 实例 = 任务分身。
242
+ * @param {{role?:string, taskId?:string, essence?:boolean}} [input]
243
+ * @returns {'mother'|'essence'|'fork'}
244
+ */
245
+ export function identityKind({ role = 'fork', taskId = '', essence = false } = {}) {
246
+ if (role === 'mother') return 'mother'
247
+ return essence === true || String(taskId ?? '').startsWith('rt-') ? 'essence' : 'fork'
248
+ }
249
+
238
250
  export function apply(ctx, config) {
239
251
  const gate = roleGate('adapter', { logger: ctx.logger })
240
252
  if (!gate.active) return
@@ -654,12 +666,9 @@ export function apply(ctx, config) {
654
666
  const hello = () => ({
655
667
  ok: true,
656
668
  role,
657
- taskId,
658
- // Web 端身份徽标用:母体 / 元主(元宝运行态)/ 分身(任务)。
669
+ taskId, // Web 端身份徽标用:母体 / 元主(元宝运行态)/ 分身(任务)。
659
670
  // 元宝运行态由 orchestrator 注入 DSH_FANG_ESSENCE=1;旧运行态按 rt- 前缀兜底。
660
- kind: role === 'mother'
661
- ? 'mother'
662
- : ((typeof process !== 'undefined' && process.env?.DSH_FANG_ESSENCE === '1') || String(taskId ?? '').startsWith('rt-') ? 'essence' : 'fork'),
671
+ kind: identityKind({ role, taskId, essence: typeof process !== 'undefined' && process.env?.DSH_FANG_ESSENCE === '1' }),
663
672
  version: FANG_VERSION,
664
673
  protocol: ADAPTER_PROTOCOL_VERSION,
665
674
  sessionId,
@@ -684,6 +693,16 @@ export function apply(ctx, config) {
684
693
  }
685
694
  }
686
695
 
696
+ // v3.1.14:Web 端拿不到 adapter Bearer token,身份探测走公开只读路由;
697
+ // 只暴露 role/kind/version,不含 taskId/sessionId/token。
698
+ const identity = () => ({
699
+ ok: true,
700
+ role,
701
+ kind: identityKind({ role, taskId, essence: typeof process !== 'undefined' && process.env?.DSH_FANG_ESSENCE === '1' }),
702
+ version: FANG_VERSION,
703
+ protocol: ADAPTER_PROTOCOL_VERSION,
704
+ })
705
+
687
706
  const approvals = () => {
688
707
  const items = approvalItemsWithOrphans()
689
708
  if (items === null) return { ok: false, code: 'service-unavailable', error: 'service-unavailable', items: [] }
@@ -1207,6 +1226,15 @@ export function apply(ctx, config) {
1207
1226
  }
1208
1227
 
1209
1228
  const registerRoutes = (webServer) => {
1229
+ // v3.1.14:浏览器无法持有 adapter Bearer token;身份探测必须是公开只读路由。
1230
+ // 服务端仍只监听 loopback,且返回值不含 taskId/token(见 identity())。
1231
+ webServer.register({
1232
+ kind: 'exact',
1233
+ path: `${prefix}${ADAPTER_ROUTE.IDENTITY}`,
1234
+ method: 'GET',
1235
+ handler: (req, res) => json(res, 200, identity()),
1236
+ })
1237
+ try { service.routes.push(`${prefix}${ADAPTER_ROUTE.IDENTITY}`) } catch { /* fake ws */ }
1210
1238
  const route = (method, routePath, handler) => {
1211
1239
  webServer.register({
1212
1240
  kind: 'exact',
@@ -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