@restregular/dsh-memory 0.14.0 → 0.14.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/CHANGELOG.md +12 -0
- package/README.md +3 -2
- package/lib/client.js +434 -44
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
本项目的版本记录。安装 id 与 npm 版本一一对应。
|
|
4
4
|
|
|
5
|
+
## 0.14.2 — 修复轨迹 callId 解析,审计页签不再全空;行内有审计图标
|
|
6
|
+
|
|
7
|
+
- **根因**:Trajectory 把 `trajectoryVirtualRecordKey()` 的结果写入 `data-trajectory-row-key`,而该函数会先 `encodeURIComponent`,DOM 上实际是 `tool%00call%00<callId>`。旧解析按原始 `\0call\0` 分隔符找,永远拿不到 callId,详情页签就用空锚点查询,所以无论点哪条记录都没有审计内容;行徽标也因此从不出现。现在先 `decodeURIComponent` 再解析,并剥掉 `\0summary\0<kind>` 后缀;未编码的旧格式也继续兼容。
|
|
8
|
+
- **轨迹行图标**:有记忆审计的调用行左侧显示产品年轮线条图标(12px、`fill:none`、1.3 描边、跟随 currentColor),点击直接打开该调用的记忆审计;没有审计的行不显示。图标用 `shell.overlay` 固定定位,不插轨迹表格 DOM。
|
|
9
|
+
- 回归测试:编码 key / 未编码 key / collapsed summary 后缀;详情页签能拿到 call-1;行标记只命中 call-1、不命中 call-2。
|
|
10
|
+
|
|
11
|
+
## 0.14.1 — 移除头部入口,记忆视图内滚,轨迹详情加审计页签
|
|
12
|
+
|
|
13
|
+
- **移除会话头部的「记忆审计」按钮**:入口收敛到会话内的「记忆」视图和轨迹详情页签,不再占用标题行。
|
|
14
|
+
- **记忆视图不再撑高外层**:视图声明 `data-conversation-composer-overlay`,与 Trajectory 用同一套壳层机制把 viewArea 压成固定高度;审计列表在自己的滚动容器里滚动,外层会话界面不需要跟着滚。底部为浮动 composer 预留高度。
|
|
15
|
+
- **轨迹详情新增「记忆审计」页签**:Trajectory 没有页签级 slot,所以页签按钮和面板放在 `shell.overlay` 里,用 fixed 定位贴着右侧详情面板(页签行预留 96px,不改 React 管理的 DOM)。点击后展示该记录的 callId 对应审计事件,底部按钮跳到本会话记忆审计面板;没有 callId 的记录明确提示无法精确过滤。选择器用 CSS Modules 稳定后缀(`_details` / `_detailTabs` / `_detailBody`),失配时静默隐藏。
|
|
16
|
+
|
|
5
17
|
## 0.14.0 — 记忆审计与会话轨迹互相精准跳转
|
|
6
18
|
|
|
7
19
|
- **审计可定位到轨迹**:审计详情新增「在轨迹中定位」。条目上的 `operationId`(记忆工具调用、触发召回的工具调用)直接作为 Trajectory 的 callId 深链;没有 `operationId` 的按轮/步事件请求新增的 `GET /memory/api/anchor`,由 Host 在会话事件窗口里找该 turn/step 的第一个 `tool/call`。找不到时只切到轨迹页,不伪造锚点。
|
package/README.md
CHANGED
|
@@ -375,9 +375,10 @@ GET /memory/api/anchor?session=<id>&turn=<n>&step=<n>&callId=<optional>
|
|
|
375
375
|
|
|
376
376
|
DSH 自带的 Trajectory 面板是一个**纯投影**:它只声明 `conversation.trajectory.images` 一个子槽,没有行/列扩展点,选中状态也只存在组件内部。因此插件不能直接往轨迹表格里插审计行。当前采用的是一条不碰轨迹 React 树的组合:
|
|
377
377
|
|
|
378
|
-
- **轨迹 → 记忆审计**:Trajectory
|
|
378
|
+
- **轨迹 → 记忆审计**:Trajectory 的选中行带有 `data-trajectory-row-key`。注意它在 DOM 上经过 `encodeURIComponent`(工具行实际是 `tool%00call%00<callId>`),插件会先解码再取 callId。有审计的调用行左侧会显示产品年轮线条图标;选中行右侧另有「记忆 N」徽标,点击按 `op:<callId>` 打开审计。
|
|
379
|
+
- **轨迹详情页签**:点击轨迹里的任意记录后,右侧详情面板的页签行会多出一个「记忆审计」页签(用 `shell.overlay` 贴着详情面板,不改轨迹的 React 树)。它展示该记录 callId 对应的审计事件,底部按钮直接打开本会话的记忆审计面板;没有 callId 的记录明确提示无法精确过滤。
|
|
379
380
|
- **记忆审计 → 轨迹**:审计详情里的「在轨迹中定位」把条目上的 `operationId`(记忆工具调用、触发召回的工具调用)交给 Trajectory 的 `openView('trajectory', callId)`。没有 `operationId` 的按轮/步事件先请求 `/anchor`,由 Host 从会话事件窗口里找该 turn/step 的第一个 `tool/call`;找不到就只切到轨迹页,不伪造定位。
|
|
380
|
-
- **会话内的「记忆」视图**:与 Chat / 轨迹同一个 view ring,按当前会话展示审计;它直接使用宿主传给每个 view 的 `openView
|
|
381
|
+
- **会话内的「记忆」视图**:与 Chat / 轨迹同一个 view ring,按当前会话展示审计;它直接使用宿主传给每个 view 的 `openView`,因此跳转是官方支持路径。它声明 `data-conversation-composer-overlay` 让壳层压住外层滚动,审计列表在自己的滚动容器里滚动,外层界面不需要跟着滚。主面板不在 view ring 内,通过 `conversation.session` 注册的 per-session store 调同一个 action;拿不到时退化为打开会话/轨迹页。
|
|
381
382
|
- 记忆工具调用(`memory_save/search/list/get/forget`)本身会额外留一条 `stage: tool_call` 的审计锚点:即使自动召回关闭,也能从这条记录精确跳回轨迹里的那次调用。
|
|
382
383
|
|
|
383
384
|
`/anchor` 只返回 `{ callId, tool?, turn?, step?, reason }`,不返回工具参数、消息正文或记忆内容;找不到会话/工具时 `callId` 为 `null` 并给出稳定 `reason`。
|
package/lib/client.js
CHANGED
|
@@ -445,15 +445,42 @@ window.__ModuleLoader__.load({
|
|
|
445
445
|
'.mem-view-head b{font-size:14px}',
|
|
446
446
|
'.mem-view-head .muted{font-size:11.5px;color:var(--dsw-alias-label-secondary)}',
|
|
447
447
|
'.mem-view-head .spacer{flex:1}',
|
|
448
|
+
// 记忆视图自己占满 viewArea,并声明 composer overlay:壳层会把 viewArea
|
|
449
|
+
// 压成 flex:1 1 0 / min-height:0,滚动只发生在审计列表里,外层不再跟着滚。
|
|
450
|
+
'.mem-view{display:flex;flex-direction:column;gap:10px;padding:12px 14px calc(var(--dsh-composer-height,152px) + 14px);min-height:0;height:100%;box-sizing:border-box;overflow:hidden;color:var(--dsw-alias-label-primary)}',
|
|
448
451
|
'.mem-view-body{min-height:0;flex:1;display:flex;flex-direction:column;overflow:hidden}',
|
|
449
|
-
'.mem-view .audit{height:
|
|
450
|
-
|
|
451
|
-
'.mem-
|
|
452
|
-
|
|
452
|
+
'.mem-view .audit{height:100%;max-height:none;min-height:0;flex:1;overflow:hidden}',
|
|
453
|
+
'.mem-view .audit-split{min-height:0}',
|
|
454
|
+
'.mem-view .audit-detail{max-height:100%}',
|
|
455
|
+
// 轨迹详情面板的「记忆审计」页签。Trajectory 没有行级/页签级 slot,所以
|
|
456
|
+
// 按钮和面板都放在 shell.overlay 里用 fixed 定位贴着详情面板;不在 React
|
|
457
|
+
// 管理的 tabs 行里插 DOM,避免被轨迹的重渲染清掉。
|
|
458
|
+
'.mem-traj-audit-tab{position:fixed;z-index:71;box-sizing:border-box;display:flex;align-items:center;justify-content:center;height:26px;padding:0 8px;border:0;border-bottom:2px solid transparent;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-tertiary);font-size:13px;font-weight:500;line-height:16px;white-space:nowrap;cursor:pointer;pointer-events:auto}',
|
|
459
|
+
'.mem-traj-audit-tab:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}',
|
|
460
|
+
'.mem-traj-audit-tab.on{color:var(--dsw-alias-state-business-primary);border-bottom-color:var(--dsw-alias-state-business-primary)}',
|
|
461
|
+
'.mem-traj-audit-pane{position:fixed;z-index:72;box-sizing:border-box;display:flex;flex-direction:column;overflow:hidden;border-left:.5px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);pointer-events:auto}',
|
|
462
|
+
'.mem-traj-audit-pane-head{display:flex;align-items:center;gap:8px;flex:none;padding:8px 10px;border-bottom:.5px solid var(--dsw-alias-border-l1)}',
|
|
463
|
+
'.mem-traj-audit-pane-head b{font-size:12px}',
|
|
464
|
+
'.mem-traj-audit-pane-head .spacer{flex:1}',
|
|
465
|
+
'.mem-traj-audit-pane-body{flex:1;min-height:0;overflow:auto;padding:6px 10px 10px;display:flex;flex-direction:column;gap:6px}',
|
|
466
|
+
'.mem-traj-audit-pane-foot{flex:none;display:flex;gap:6px;align-items:center;padding:8px 10px;border-top:.5px solid var(--dsw-alias-border-l1)}',
|
|
467
|
+
'.mem-traj-audit-pane-foot .spacer{flex:1}',
|
|
468
|
+
'.mem-traj-audit-row{display:flex;flex-direction:column;gap:4px;text-align:left;width:100%;box-sizing:border-box;padding:7px 8px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;background:var(--dsw-alias-bg-layer-1);cursor:pointer;color:inherit;font-size:11.5px}',
|
|
469
|
+
'.mem-traj-audit-row:hover{border-color:var(--dsw-alias-brand-primary)}',
|
|
470
|
+
'.mem-traj-audit-row-top{display:flex;align-items:center;gap:6px;min-width:0}',
|
|
471
|
+
'.mem-traj-audit-row-top .t{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:10px;color:var(--dsw-alias-label-secondary);flex:none}',
|
|
472
|
+
'.mem-traj-audit-row-top .ch{font-weight:600;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
473
|
+
'.mem-traj-audit-row-meta{font-size:10.5px;color:var(--dsw-alias-label-secondary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
474
|
+
'.mem-traj-audit-row-ids{display:flex;flex-wrap:wrap;gap:3px;max-height:44px;overflow:hidden}',
|
|
475
|
+
'.mem-traj-audit-empty{padding:16px 8px;color:var(--dsw-alias-label-secondary);font-size:11.5px;line-height:1.6}',
|
|
453
476
|
// 轨迹行上的记忆徽标:fixed 定位在选中行右侧,不改轨迹表格结构。
|
|
454
477
|
'.mem-traj-chip{position:fixed;z-index:70;display:inline-flex;align-items:center;gap:4px;height:20px;padding:0 7px;border:1px solid color-mix(in srgb,var(--dsw-alias-brand-primary) 42%,var(--dsw-alias-border-l1));border-radius:999px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-brand-primary);font-size:10px;line-height:1;cursor:pointer;box-shadow:0 2px 8px rgba(0,0,0,.18);white-space:nowrap}',
|
|
455
478
|
'.mem-traj-chip:hover{background:color-mix(in srgb,var(--dsw-alias-brand-primary) 10%,var(--dsw-alias-bg-layer-1))}',
|
|
456
479
|
'.mem-traj-chip .dot{width:5px;height:5px;border-radius:50%;background:currentColor}',
|
|
480
|
+
// 轨迹行左侧的线条图标标记(年轮)。只做指示,点击直接打开该调用的审计。
|
|
481
|
+
'.mem-traj-mark{position:fixed;z-index:69;box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;padding:0;border:0;border-radius:4px;background:transparent;color:color-mix(in srgb,var(--dsw-alias-brand-primary) 74%,var(--dsw-alias-label-secondary));cursor:pointer;pointer-events:auto;opacity:.9}',
|
|
482
|
+
'.mem-traj-mark:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-brand-primary);opacity:1}',
|
|
483
|
+
'.mem-traj-mark:focus-visible{outline:1px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}',
|
|
457
484
|
'@media (max-width:900px){.memp .audit-split.has-detail{grid-template-columns:minmax(0,1fr)}.memp .audit-row{grid-template-columns:54px 120px 120px minmax(100px,1fr) 96px 100px 80px}.memp .audit-table-head{grid-template-columns:54px 120px 120px minmax(100px,1fr) 96px 100px 80px}}',
|
|
458
485
|
'@media (max-width:620px){.memp .audit-stats{grid-template-columns:repeat(2,minmax(0,1fr))}.memp .audit-table-head{display:none}.memp .audit-row{display:flex;flex-wrap:wrap;gap:4px 8px}.memp .audit-row .col-trigger,.memp .audit-row .col-budget{display:none}.memp .audit-row .col-nums{margin-left:auto}.memp .audit-row .col-time{order:1}.memp .audit-row .col-channel{order:2}.memp .audit-row .col-delivery{order:3}.memp .audit-row .col-outcome{order:4;margin-left:auto}.memp .audit-filter-row input[type=text],.memp .audit-filter-row input[type=search]{max-width:none;flex:1}.memp .audit{height:calc(100vh - 150px);max-height:calc(100vh - 150px)}.memp .audit-detail{max-height:calc(100vh - 280px)}}',
|
|
459
486
|
].join('')
|
|
@@ -2134,25 +2161,24 @@ window.__ModuleLoader__.load({
|
|
|
2134
2161
|
return signalCall !== '' ? signalCall : undefined
|
|
2135
2162
|
}
|
|
2136
2163
|
|
|
2137
|
-
/**
|
|
2164
|
+
/**
|
|
2165
|
+
* Trajectory 的行 key 形如 `tool\0call\0<callId>`,但 DOM 上看到的是
|
|
2166
|
+
* `trajectoryVirtualRecordKey()` 返回的 **URI 编码**(`tool%00call%00callId`)。
|
|
2167
|
+
* 必须 decode 一次再解析;collapsed summary 还会追加 `\0summary\0<kind>`。
|
|
2168
|
+
*/
|
|
2138
2169
|
function trajectoryRowCallId(row) {
|
|
2139
2170
|
try {
|
|
2140
|
-
const
|
|
2141
|
-
if (typeof
|
|
2171
|
+
const raw = row && typeof row.getAttribute === 'function' ? row.getAttribute('data-trajectory-row-key') : ''
|
|
2172
|
+
if (typeof raw !== 'string' || raw === '') return undefined
|
|
2173
|
+
let key = raw
|
|
2174
|
+
try { key = decodeURIComponent(raw) } catch { /* 不是合法编码时按原文解析 */ }
|
|
2142
2175
|
const sep = '\u0000call\u0000'
|
|
2143
2176
|
const at = key.indexOf(sep)
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
function selectedTrajectoryCallId() {
|
|
2151
|
-
try {
|
|
2152
|
-
const row = typeof document !== 'undefined'
|
|
2153
|
-
? document.querySelector('tr[data-selected="true"][data-trajectory-row-key]')
|
|
2154
|
-
: null
|
|
2155
|
-
return row === null ? undefined : trajectoryRowCallId(row)
|
|
2177
|
+
if (at < 0) return undefined
|
|
2178
|
+
const rest = key.slice(at + sep.length)
|
|
2179
|
+
const cut = rest.indexOf('\u0000')
|
|
2180
|
+
const callId = cut < 0 ? rest : rest.slice(0, cut)
|
|
2181
|
+
return callId === '' ? undefined : callId
|
|
2156
2182
|
} catch {
|
|
2157
2183
|
return undefined
|
|
2158
2184
|
}
|
|
@@ -3577,7 +3603,12 @@ window.__ModuleLoader__.load({
|
|
|
3577
3603
|
if (typeof openView === 'function') openView('trajectory', focus)
|
|
3578
3604
|
} catch { /* 视图不可用时保持在本页 */ }
|
|
3579
3605
|
}
|
|
3580
|
-
return h('div', {
|
|
3606
|
+
return h('div', {
|
|
3607
|
+
className: 'memp mem-view',
|
|
3608
|
+
// 让宿主把 composer 浮起来、把 viewArea 压成固定高度(与 Trajectory 同一机制),
|
|
3609
|
+
// 否则外层 scrollBody 会滚动,审计列表拿不到自己的滚动视口。
|
|
3610
|
+
'data-conversation-composer-overlay': '',
|
|
3611
|
+
},
|
|
3581
3612
|
h('div', { className: 'mem-view-head' },
|
|
3582
3613
|
h('b', null, '记忆审计'),
|
|
3583
3614
|
h('span', { className: 'muted' }, '本会话的注入评估、投递与记忆工具调用;选中一条可在轨迹里精确定位。'),
|
|
@@ -3600,21 +3631,6 @@ window.__ModuleLoader__.load({
|
|
|
3600
3631
|
)
|
|
3601
3632
|
}
|
|
3602
3633
|
|
|
3603
|
-
/** 会话头部的入口:有选中轨迹行时自动带上 callId,直接落到那组审计。 */
|
|
3604
|
-
function MemoryHeaderAction({ sessionId }) {
|
|
3605
|
-
return h('button', {
|
|
3606
|
-
className: 'mem-head-btn',
|
|
3607
|
-
title: '查看本会话的记忆审计(若轨迹里选中了工具行,会定位到该调用)',
|
|
3608
|
-
onClick: () => {
|
|
3609
|
-
const callId = selectedTrajectoryCallId()
|
|
3610
|
-
openMemoryAuditPanel({
|
|
3611
|
-
sessionId,
|
|
3612
|
-
...(callId !== undefined ? { callId } : {}),
|
|
3613
|
-
})
|
|
3614
|
-
},
|
|
3615
|
-
}, '记忆审计')
|
|
3616
|
-
}
|
|
3617
|
-
|
|
3618
3634
|
/**
|
|
3619
3635
|
* Trajectory 行上的记忆徽标。
|
|
3620
3636
|
*
|
|
@@ -3713,6 +3729,372 @@ window.__ModuleLoader__.load({
|
|
|
3713
3729
|
}, h('span', { className: 'dot' }), `记忆 ${badge.entries.length}`)
|
|
3714
3730
|
}
|
|
3715
3731
|
|
|
3732
|
+
/** 轨迹行左侧的「产品线条图标」标记:有记忆审计的调用才显示。 */
|
|
3733
|
+
function TrajectoryMemoryMarks() {
|
|
3734
|
+
const [marks, setMarks] = React.useState([])
|
|
3735
|
+
const cacheRef = React.useRef(new Map())
|
|
3736
|
+
React.useEffect(() => {
|
|
3737
|
+
let disposed = false
|
|
3738
|
+
let raf = 0
|
|
3739
|
+
const rafFn = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : ((fn) => setTimeout(fn, 16))
|
|
3740
|
+
const cancelFn = typeof cancelAnimationFrame === 'function' ? cancelAnimationFrame : ((id) => clearTimeout(id))
|
|
3741
|
+
const same = (a, b) => a.length === b.length && a.every((mark, index) => {
|
|
3742
|
+
const other = b[index]
|
|
3743
|
+
return other !== undefined
|
|
3744
|
+
&& mark.callId === other.callId
|
|
3745
|
+
&& Math.abs(mark.top - other.top) < 1
|
|
3746
|
+
&& Math.abs(mark.left - other.left) < 1
|
|
3747
|
+
&& mark.count === other.count
|
|
3748
|
+
})
|
|
3749
|
+
const tick = () => {
|
|
3750
|
+
try {
|
|
3751
|
+
if (disposed || typeof document === 'undefined' || typeof window === 'undefined') return
|
|
3752
|
+
const sessionId = currentSessionId()
|
|
3753
|
+
if (sessionId === undefined) { setMarks([]); return }
|
|
3754
|
+
const rows = [...document.querySelectorAll('tr[data-trajectory-row-key]')]
|
|
3755
|
+
if (rows.length === 0) { setMarks([]); return }
|
|
3756
|
+
const visible = new Map()
|
|
3757
|
+
for (const row of rows) {
|
|
3758
|
+
const callId = trajectoryRowCallId(row)
|
|
3759
|
+
if (callId === undefined) continue
|
|
3760
|
+
const rect = row.getBoundingClientRect()
|
|
3761
|
+
if (rect.bottom < 0 || rect.top > window.innerHeight || rect.height <= 0) continue
|
|
3762
|
+
visible.set(callId, rect)
|
|
3763
|
+
}
|
|
3764
|
+
if (visible.size === 0) { setMarks([]); return }
|
|
3765
|
+
const cached = cacheRef.current.get(sessionId)
|
|
3766
|
+
const now = Date.now()
|
|
3767
|
+
if (cached && cached.pending === true) return
|
|
3768
|
+
if (!cached || now - cached.at > 3000) {
|
|
3769
|
+
cacheRef.current.set(sessionId, { at: now, pending: true, byOp: new Map() })
|
|
3770
|
+
api(`audit?session=${encodeURIComponent(sessionId)}&limit=200`)
|
|
3771
|
+
.then((value) => {
|
|
3772
|
+
const byOp = new Map()
|
|
3773
|
+
const entries = value && Array.isArray(value.entries) ? value.entries : []
|
|
3774
|
+
for (const entry of entries) {
|
|
3775
|
+
const callId = auditEntryCallId(entry)
|
|
3776
|
+
if (callId !== undefined) byOp.set(callId, (byOp.get(callId) ?? 0) + 1)
|
|
3777
|
+
}
|
|
3778
|
+
cacheRef.current.set(sessionId, { at: Date.now(), pending: false, byOp })
|
|
3779
|
+
if (!disposed) schedule()
|
|
3780
|
+
})
|
|
3781
|
+
.catch(() => {
|
|
3782
|
+
cacheRef.current.set(sessionId, { at: Date.now(), pending: false, byOp: new Map() })
|
|
3783
|
+
})
|
|
3784
|
+
if (!cached) return
|
|
3785
|
+
}
|
|
3786
|
+
const byOp = cached && cached.byOp instanceof Map ? cached.byOp : null
|
|
3787
|
+
if (byOp === null) return
|
|
3788
|
+
const next = []
|
|
3789
|
+
for (const [callId, rect] of visible) {
|
|
3790
|
+
const count = byOp.get(callId)
|
|
3791
|
+
if (count === undefined) continue
|
|
3792
|
+
next.push({
|
|
3793
|
+
callId,
|
|
3794
|
+
count,
|
|
3795
|
+
top: Math.max(2, rect.top + (rect.height - 16) / 2),
|
|
3796
|
+
left: Math.max(2, rect.left + 22),
|
|
3797
|
+
sessionId,
|
|
3798
|
+
})
|
|
3799
|
+
}
|
|
3800
|
+
setMarks((prev) => same(prev, next) ? prev : next)
|
|
3801
|
+
} catch { /* 观察失败:保持现状 */ }
|
|
3802
|
+
}
|
|
3803
|
+
const schedule = () => {
|
|
3804
|
+
if (disposed || raf !== 0) return
|
|
3805
|
+
raf = rafFn(() => { raf = 0; tick() })
|
|
3806
|
+
}
|
|
3807
|
+
let observer = null
|
|
3808
|
+
try {
|
|
3809
|
+
observer = new MutationObserver(schedule)
|
|
3810
|
+
observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['data-selected'] })
|
|
3811
|
+
} catch { observer = null }
|
|
3812
|
+
const onScroll = () => schedule()
|
|
3813
|
+
let timer = null
|
|
3814
|
+
try {
|
|
3815
|
+
window.addEventListener('scroll', onScroll, true)
|
|
3816
|
+
window.addEventListener('resize', onScroll)
|
|
3817
|
+
timer = setInterval(tick, 800)
|
|
3818
|
+
} catch { /* 非浏览器环境 */ }
|
|
3819
|
+
schedule()
|
|
3820
|
+
return () => {
|
|
3821
|
+
disposed = true
|
|
3822
|
+
if (raf !== 0) cancelFn(raf)
|
|
3823
|
+
if (timer !== null) clearInterval(timer)
|
|
3824
|
+
try { observer?.disconnect() } catch { /* 已断开 */ }
|
|
3825
|
+
try {
|
|
3826
|
+
window.removeEventListener('scroll', onScroll, true)
|
|
3827
|
+
window.removeEventListener('resize', onScroll)
|
|
3828
|
+
} catch { /* 非浏览器环境 */ }
|
|
3829
|
+
}
|
|
3830
|
+
}, [])
|
|
3831
|
+
if (marks.length === 0) return null
|
|
3832
|
+
return h(React.Fragment, null, marks.map((mark) => h('button', {
|
|
3833
|
+
key: `${mark.sessionId}:${mark.callId}`,
|
|
3834
|
+
className: 'mem-traj-mark',
|
|
3835
|
+
style: { top: mark.top, left: mark.left },
|
|
3836
|
+
title: `这次调用有 ${mark.count} 条记忆审计;点击在记忆面板里查看`,
|
|
3837
|
+
onClick: (event) => {
|
|
3838
|
+
try { event.stopPropagation() } catch { /* 忽略 */ }
|
|
3839
|
+
openMemoryAuditPanel({ sessionId: mark.sessionId, callId: mark.callId })
|
|
3840
|
+
},
|
|
3841
|
+
}, h('svg', { width: 12, height: 12, viewBox: NAV_VIEW_BOX, fill: 'none', 'aria-hidden': 'true' },
|
|
3842
|
+
h('rect', { ...NAV_FRAME, fill: 'none', stroke: 'currentColor', strokeWidth: 1.3 }),
|
|
3843
|
+
h('path', { d: NAV_RING, fill: 'none', stroke: 'currentColor', strokeWidth: 1.3, strokeLinecap: 'round', strokeLinejoin: 'round' }),
|
|
3844
|
+
))))
|
|
3845
|
+
}
|
|
3846
|
+
|
|
3847
|
+
/**
|
|
3848
|
+
* 轨迹详情面板里的「记忆审计」页签。
|
|
3849
|
+
*
|
|
3850
|
+
* Trajectory 的详情页签是包内私有的 `detailTabs` 数组,没有给插件留 slot。
|
|
3851
|
+
* 这里不在 React 管理的 `<div data-slot>` 里插节点(会被重渲染清掉),而是:
|
|
3852
|
+
* 1. 给详情页签行加 `padding-right` 预留 96px;
|
|
3853
|
+
* 2. 在 `shell.overlay` 里用 fixed 定位渲染一个页签按钮,贴在保留区;
|
|
3854
|
+
* 3. 点开后用 fixed 覆盖详情正文区域,展示这条记录的审计;
|
|
3855
|
+
* 4. 页签/面板的位置随滚动、resize、详情切换重新测量。
|
|
3856
|
+
* 选择器全部用 CSS Modules 的稳定后缀(`_details` / `_detailTabs` / `_detailBody`),
|
|
3857
|
+
* 失配时什么都不显示,不影响轨迹本身。
|
|
3858
|
+
*/
|
|
3859
|
+
function TrajectoryDetailAudit() {
|
|
3860
|
+
const [layout, setLayout] = React.useState({
|
|
3861
|
+
visible: false, tabTop: 0, tabLeft: 0, tabWidth: 88, paneTop: 0, paneLeft: 0, paneWidth: 0, paneHeight: 0,
|
|
3862
|
+
})
|
|
3863
|
+
const [open, setOpen] = React.useState(false)
|
|
3864
|
+
const [callId, setCallId] = React.useState(undefined)
|
|
3865
|
+
const [sessionId, setSessionId] = React.useState(undefined)
|
|
3866
|
+
const [entries, setEntries] = React.useState([])
|
|
3867
|
+
const [loading, setLoading] = React.useState(false)
|
|
3868
|
+
const [error, setError] = React.useState('')
|
|
3869
|
+
const layoutRef = React.useRef(layout)
|
|
3870
|
+
const openRef = React.useRef(false)
|
|
3871
|
+
const keyRef = React.useRef('')
|
|
3872
|
+
const cacheRef = React.useRef(new Map())
|
|
3873
|
+
const setOpenBoth = (value) => { openRef.current = value; setOpen(value) }
|
|
3874
|
+
|
|
3875
|
+
const loadAudit = (sid, cid) => {
|
|
3876
|
+
const key = `${sid}|${cid}`
|
|
3877
|
+
const cached = cacheRef.current.get(key)
|
|
3878
|
+
if (cached && cached.pending === true) return
|
|
3879
|
+
if (cached && Date.now() - cached.at < 4000) {
|
|
3880
|
+
setEntries(cached.entries)
|
|
3881
|
+
setLoading(false)
|
|
3882
|
+
setError('')
|
|
3883
|
+
return
|
|
3884
|
+
}
|
|
3885
|
+
cacheRef.current.set(key, { at: Date.now(), pending: true, entries: [] })
|
|
3886
|
+
setLoading(true)
|
|
3887
|
+
setError('')
|
|
3888
|
+
api(`audit?session=${encodeURIComponent(sid)}&operation=${encodeURIComponent(cid)}&limit=50`)
|
|
3889
|
+
.then((value) => {
|
|
3890
|
+
const list = value && Array.isArray(value.entries) ? value.entries : []
|
|
3891
|
+
cacheRef.current.set(key, { at: Date.now(), pending: false, entries: list })
|
|
3892
|
+
if (keyRef.current === key) { setEntries(list); setLoading(false) }
|
|
3893
|
+
})
|
|
3894
|
+
.catch((reason) => {
|
|
3895
|
+
cacheRef.current.set(key, { at: Date.now(), pending: false, entries: [] })
|
|
3896
|
+
if (keyRef.current === key) { setEntries([]); setLoading(false); setError(String(reason?.message || reason)) }
|
|
3897
|
+
})
|
|
3898
|
+
}
|
|
3899
|
+
|
|
3900
|
+
React.useEffect(() => {
|
|
3901
|
+
let disposed = false
|
|
3902
|
+
let raf = 0
|
|
3903
|
+
const rafFn = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : ((fn) => setTimeout(fn, 16))
|
|
3904
|
+
const cancelFn = typeof cancelAnimationFrame === 'function' ? cancelAnimationFrame : ((id) => clearTimeout(id))
|
|
3905
|
+
const apply = (next) => {
|
|
3906
|
+
const prev = layoutRef.current
|
|
3907
|
+
if (prev.visible === next.visible
|
|
3908
|
+
&& Math.abs(prev.tabTop - next.tabTop) < 1
|
|
3909
|
+
&& Math.abs(prev.tabLeft - next.tabLeft) < 1
|
|
3910
|
+
&& Math.abs(prev.paneTop - next.paneTop) < 1
|
|
3911
|
+
&& Math.abs(prev.paneLeft - next.paneLeft) < 1
|
|
3912
|
+
&& Math.abs(prev.paneWidth - next.paneWidth) < 1
|
|
3913
|
+
&& Math.abs(prev.paneHeight - next.paneHeight) < 1) return
|
|
3914
|
+
layoutRef.current = next
|
|
3915
|
+
setLayout(next)
|
|
3916
|
+
}
|
|
3917
|
+
const hide = () => {
|
|
3918
|
+
apply({ visible: false, tabTop: 0, tabLeft: 0, tabWidth: 88, paneTop: 0, paneLeft: 0, paneWidth: 0, paneHeight: 0 })
|
|
3919
|
+
keyRef.current = ''
|
|
3920
|
+
}
|
|
3921
|
+
const tick = () => {
|
|
3922
|
+
try {
|
|
3923
|
+
if (disposed || typeof document === 'undefined' || typeof window === 'undefined') return
|
|
3924
|
+
const details = document.querySelector('[class*="_details"]')
|
|
3925
|
+
if (details === null) { hide(); return }
|
|
3926
|
+
const tabs = details.querySelector('[class*="_detailTabs"]')
|
|
3927
|
+
const body = details.querySelector('[class*="_detailBody"]')
|
|
3928
|
+
const row = document.querySelector('tr[data-selected="true"][data-trajectory-row-key]')
|
|
3929
|
+
if (tabs === null || body === null || row === null) { hide(); return }
|
|
3930
|
+
const detailsRect = details.getBoundingClientRect()
|
|
3931
|
+
const tabsRect = tabs.getBoundingClientRect()
|
|
3932
|
+
if (detailsRect.width < 220 || detailsRect.height < 120 || tabsRect.height === 0) { hide(); return }
|
|
3933
|
+
const sid = currentSessionId()
|
|
3934
|
+
if (sid === undefined) { hide(); return }
|
|
3935
|
+
// 给受 React 管理的 tabs 行留出右侧空位;只改 style,不动 DOM 结构。
|
|
3936
|
+
if (tabs.style.paddingRight !== '96px') tabs.style.paddingRight = '96px'
|
|
3937
|
+
const cid = trajectoryRowCallId(row)
|
|
3938
|
+
const key = `${sid}|${cid ?? ''}`
|
|
3939
|
+
if (key !== keyRef.current) {
|
|
3940
|
+
keyRef.current = key
|
|
3941
|
+
setCallId(cid)
|
|
3942
|
+
setSessionId(sid)
|
|
3943
|
+
setOpenBoth(false)
|
|
3944
|
+
if (cid === undefined) {
|
|
3945
|
+
setEntries([])
|
|
3946
|
+
setLoading(false)
|
|
3947
|
+
setError('')
|
|
3948
|
+
} else {
|
|
3949
|
+
loadAudit(sid, cid)
|
|
3950
|
+
}
|
|
3951
|
+
}
|
|
3952
|
+
const tabWidth = 88
|
|
3953
|
+
const tabTop = tabsRect.top + 4
|
|
3954
|
+
const tabLeft = Math.max(0, tabsRect.right - tabWidth - 4)
|
|
3955
|
+
const paneTop = tabsRect.bottom
|
|
3956
|
+
const paneLeft = detailsRect.left
|
|
3957
|
+
const paneWidth = detailsRect.width
|
|
3958
|
+
// 轨迹会把 composer 浮在面板底部;审计面板停在 composer 上沿,
|
|
3959
|
+
// 避免把输入框盖住(composer 不存在/隐藏时退回面板底边)。
|
|
3960
|
+
const composerSeat = document.querySelector('[class*="_composerSeat"]')
|
|
3961
|
+
const composerRect = composerSeat ? composerSeat.getBoundingClientRect() : null
|
|
3962
|
+
const paneBottom = composerRect !== null && composerRect.height > 0
|
|
3963
|
+
? Math.min(detailsRect.bottom, composerRect.top)
|
|
3964
|
+
: detailsRect.bottom
|
|
3965
|
+
const paneHeight = Math.max(0, paneBottom - tabsRect.bottom)
|
|
3966
|
+
apply({ visible: true, tabTop, tabLeft, tabWidth, paneTop, paneLeft, paneWidth, paneHeight })
|
|
3967
|
+
} catch { /* 观察失败:保持现状 */ }
|
|
3968
|
+
}
|
|
3969
|
+
const schedule = () => {
|
|
3970
|
+
if (disposed || raf !== 0) return
|
|
3971
|
+
raf = rafFn(() => { raf = 0; tick() })
|
|
3972
|
+
}
|
|
3973
|
+
let observer = null
|
|
3974
|
+
try {
|
|
3975
|
+
observer = new MutationObserver(schedule)
|
|
3976
|
+
observer.observe(document.body, {
|
|
3977
|
+
childList: true,
|
|
3978
|
+
subtree: true,
|
|
3979
|
+
attributes: true,
|
|
3980
|
+
attributeFilter: ['data-selected', 'class', 'style'],
|
|
3981
|
+
})
|
|
3982
|
+
} catch { observer = null }
|
|
3983
|
+
const onScroll = () => schedule()
|
|
3984
|
+
let timer = null
|
|
3985
|
+
try {
|
|
3986
|
+
window.addEventListener('scroll', onScroll, true)
|
|
3987
|
+
window.addEventListener('resize', onScroll)
|
|
3988
|
+
timer = setInterval(tick, 700)
|
|
3989
|
+
} catch { /* 非浏览器环境 */ }
|
|
3990
|
+
const onDocClick = (event) => {
|
|
3991
|
+
try {
|
|
3992
|
+
const target = event.target
|
|
3993
|
+
if (!target || typeof target.closest !== 'function') return
|
|
3994
|
+
if (target.closest('.mem-traj-audit-tab') || target.closest('.mem-traj-audit-pane')) return
|
|
3995
|
+
if (target.closest('[class*="_detailTab"]')) setOpenBoth(false)
|
|
3996
|
+
} catch { /* 忽略 */ }
|
|
3997
|
+
}
|
|
3998
|
+
try { document.addEventListener('click', onDocClick, true) } catch { /* 忽略 */ }
|
|
3999
|
+
schedule()
|
|
4000
|
+
return () => {
|
|
4001
|
+
disposed = true
|
|
4002
|
+
if (raf !== 0) cancelFn(raf)
|
|
4003
|
+
if (timer !== null) clearInterval(timer)
|
|
4004
|
+
try { observer?.disconnect() } catch { /* 已断开 */ }
|
|
4005
|
+
try {
|
|
4006
|
+
window.removeEventListener('scroll', onScroll, true)
|
|
4007
|
+
window.removeEventListener('resize', onScroll)
|
|
4008
|
+
document.removeEventListener('click', onDocClick, true)
|
|
4009
|
+
} catch { /* 非浏览器环境 */ }
|
|
4010
|
+
}
|
|
4011
|
+
}, [])
|
|
4012
|
+
|
|
4013
|
+
if (!layout.visible) return null
|
|
4014
|
+
const toggle = () => setOpenBoth(!openRef.current)
|
|
4015
|
+
const close = () => setOpenBoth(false)
|
|
4016
|
+
const openInPanel = (entryId) => {
|
|
4017
|
+
openMemoryAuditPanel({
|
|
4018
|
+
sessionId,
|
|
4019
|
+
...(callId !== undefined ? { callId } : {}),
|
|
4020
|
+
...(entryId !== undefined ? { entryId } : {}),
|
|
4021
|
+
})
|
|
4022
|
+
}
|
|
4023
|
+
const rowView = (entry) => {
|
|
4024
|
+
const ids = entry.selected && Array.isArray(entry.selected.contentIds) ? entry.selected.contentIds : []
|
|
4025
|
+
const outcome = auditOutcomeMeta(entry.outcome)
|
|
4026
|
+
return h('button', {
|
|
4027
|
+
key: entry.id,
|
|
4028
|
+
className: 'mem-traj-audit-row',
|
|
4029
|
+
title: `${fmtTime(entry.at)} · ${entry.trigger || entry.stage || ''}`,
|
|
4030
|
+
onClick: () => openInPanel(entry.id),
|
|
4031
|
+
},
|
|
4032
|
+
h('div', { className: 'mem-traj-audit-row-top' },
|
|
4033
|
+
h('span', { className: 't' }, shortTime(entry.at)),
|
|
4034
|
+
h('span', { className: 'ch' }, `${auditChannelLabel(entry.channel)} · ${entry.kind || 'event'}`),
|
|
4035
|
+
h('span', { className: 'spacer' }),
|
|
4036
|
+
h('span', { className: `audit-pill ${outcome.tone}` }, outcome.label),
|
|
4037
|
+
),
|
|
4038
|
+
h('div', { className: 'mem-traj-audit-row-meta' },
|
|
4039
|
+
`${entry.trigger || '—'}${entry.stage ? ` / ${entry.stage}` : ''}`
|
|
4040
|
+
+ (entry.delivery ? ` · ${auditDeliveryMeta(entry).label}` : '')
|
|
4041
|
+
+ (entry.candidates !== undefined ? ` · 候选 ${entry.candidates}` : '')
|
|
4042
|
+
+ (entry.selected && entry.selected.count !== undefined ? ` · 选中 ${entry.selected.count}` : ''),
|
|
4043
|
+
),
|
|
4044
|
+
ids.length > 0
|
|
4045
|
+
? h('div', { className: 'mem-traj-audit-row-ids' },
|
|
4046
|
+
ids.slice(0, 4).map((id) => h('span', { className: 'audit-id', key: id }, String(id).length > 14 ? `${String(id).slice(0, 10)}…` : String(id))),
|
|
4047
|
+
ids.length > 4 ? h('span', { className: 'audit-id-sub' }, `+${ids.length - 4}`) : null,
|
|
4048
|
+
)
|
|
4049
|
+
: null,
|
|
4050
|
+
)
|
|
4051
|
+
}
|
|
4052
|
+
return h(React.Fragment, null,
|
|
4053
|
+
h('button', {
|
|
4054
|
+
className: 'mem-traj-audit-tab' + (open ? ' on' : ''),
|
|
4055
|
+
style: { top: layout.tabTop, left: layout.tabLeft, width: layout.tabWidth },
|
|
4056
|
+
title: callId === undefined ? '这条记录没有 callId 锚点,可打开本会话记忆审计' : `查看这次调用的记忆审计(${callId})`,
|
|
4057
|
+
onClick: toggle,
|
|
4058
|
+
}, `记忆审计${entries.length > 0 ? ` ${entries.length}` : ''}`),
|
|
4059
|
+
open
|
|
4060
|
+
? h('div', {
|
|
4061
|
+
className: 'memp mem-traj-audit-pane',
|
|
4062
|
+
style: {
|
|
4063
|
+
top: layout.paneTop,
|
|
4064
|
+
left: layout.paneLeft,
|
|
4065
|
+
width: layout.paneWidth,
|
|
4066
|
+
height: layout.paneHeight,
|
|
4067
|
+
},
|
|
4068
|
+
},
|
|
4069
|
+
h('div', { className: 'mem-traj-audit-pane-head' },
|
|
4070
|
+
h('b', null, '记忆审计'),
|
|
4071
|
+
callId !== undefined ? h('span', { className: 'mono', title: callId }, callId.length > 20 ? `${callId.slice(0, 18)}…` : callId) : null,
|
|
4072
|
+
h('span', { className: 'spacer' }),
|
|
4073
|
+
h('button', { className: 'linkbtn', onClick: close }, '返回轨迹'),
|
|
4074
|
+
),
|
|
4075
|
+
h('div', { className: 'mem-traj-audit-pane-body' },
|
|
4076
|
+
loading
|
|
4077
|
+
? h('div', { className: 'mem-traj-audit-empty' }, '加载审计…')
|
|
4078
|
+
: error
|
|
4079
|
+
? h('div', { className: 'mem-traj-audit-empty' }, `加载失败:${error}`)
|
|
4080
|
+
: entries.length === 0
|
|
4081
|
+
? h('div', { className: 'mem-traj-audit-empty' },
|
|
4082
|
+
callId === undefined
|
|
4083
|
+
? '这条轨迹记录没有 callId 锚点,无法精确过滤;可以打开本会话记忆审计,按轮次/步骤查找。'
|
|
4084
|
+
: '这次调用没有记忆审计记录(可能发生在审计开启前,或已被容量策略淘汰)。',
|
|
4085
|
+
)
|
|
4086
|
+
: entries.map(rowView),
|
|
4087
|
+
),
|
|
4088
|
+
h('div', { className: 'mem-traj-audit-pane-foot' },
|
|
4089
|
+
h('span', { className: 'muted' }, entries.length > 0 ? `${entries.length} 条` : ''),
|
|
4090
|
+
h('span', { className: 'spacer' }),
|
|
4091
|
+
h('button', { onClick: () => openInPanel(entries[0]?.id) }, '打开本会话记忆审计'),
|
|
4092
|
+
),
|
|
4093
|
+
)
|
|
4094
|
+
: null,
|
|
4095
|
+
)
|
|
4096
|
+
}
|
|
4097
|
+
|
|
3716
4098
|
const inject = ['slots']
|
|
3717
4099
|
|
|
3718
4100
|
/** 侧栏入口打开的主界面页面(整块可滚动,内容就是面板本体)。 */
|
|
@@ -3857,15 +4239,13 @@ window.__ModuleLoader__.load({
|
|
|
3857
4239
|
console.warn('[dsh-memory] 记忆审计视图注册失败:', error?.message)
|
|
3858
4240
|
}
|
|
3859
4241
|
try {
|
|
3860
|
-
slots.inject('
|
|
3861
|
-
name: '
|
|
3862
|
-
id: 'memory-audit',
|
|
3863
|
-
order:
|
|
3864
|
-
|
|
3865
|
-
inject: (sessionId) => ({ sessionId }),
|
|
3866
|
-
}, MemoryHeaderAction))
|
|
4242
|
+
slots.inject('shell.overlay', () => slots.register({
|
|
4243
|
+
name: 'shell.overlay',
|
|
4244
|
+
id: 'memory-audit-marks',
|
|
4245
|
+
order: 59,
|
|
4246
|
+
}, () => React.createElement(TrajectoryMemoryMarks)))
|
|
3867
4247
|
} catch (error) {
|
|
3868
|
-
console.warn('[dsh-memory]
|
|
4248
|
+
console.warn('[dsh-memory] 轨迹行记忆标记注册失败:', error?.message)
|
|
3869
4249
|
}
|
|
3870
4250
|
try {
|
|
3871
4251
|
slots.inject('shell.overlay', () => slots.register({
|
|
@@ -3876,6 +4256,15 @@ window.__ModuleLoader__.load({
|
|
|
3876
4256
|
} catch (error) {
|
|
3877
4257
|
console.warn('[dsh-memory] 轨迹记忆徽标注册失败:', error?.message)
|
|
3878
4258
|
}
|
|
4259
|
+
try {
|
|
4260
|
+
slots.inject('shell.overlay', () => slots.register({
|
|
4261
|
+
name: 'shell.overlay',
|
|
4262
|
+
id: 'memory-audit-detail',
|
|
4263
|
+
order: 61,
|
|
4264
|
+
}, () => React.createElement(TrajectoryDetailAudit)))
|
|
4265
|
+
} catch (error) {
|
|
4266
|
+
console.warn('[dsh-memory] 轨迹详情记忆页签注册失败:', error?.message)
|
|
4267
|
+
}
|
|
3879
4268
|
} catch (error) {
|
|
3880
4269
|
console.error('[dsh-memory] client apply 失败(已吞掉):', error?.message)
|
|
3881
4270
|
}
|
|
@@ -4003,8 +4392,9 @@ window.__ModuleLoader__.load({
|
|
|
4003
4392
|
paintNavIcon: paintNavIcon,
|
|
4004
4393
|
// 审计 ↔ 轨迹桥(测试只覆盖纯解析/焦点总线,不碰宿主 slot 实例)
|
|
4005
4394
|
MemoryAuditView: MemoryAuditView,
|
|
4006
|
-
MemoryHeaderAction: MemoryHeaderAction,
|
|
4007
4395
|
TrajectoryMemoryBadge: TrajectoryMemoryBadge,
|
|
4396
|
+
TrajectoryMemoryMarks: TrajectoryMemoryMarks,
|
|
4397
|
+
TrajectoryDetailAudit: TrajectoryDetailAudit,
|
|
4008
4398
|
auditEntryCallId: auditEntryCallId,
|
|
4009
4399
|
trajectoryRowCallId: trajectoryRowCallId,
|
|
4010
4400
|
requestAuditFocus: requestAuditFocus,
|