@restregular/dsh-memory 0.14.0 → 0.14.1
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 +6 -0
- package/README.md +3 -2
- package/lib/client.js +294 -43
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
本项目的版本记录。安装 id 与 npm 版本一一对应。
|
|
4
4
|
|
|
5
|
+
## 0.14.1 — 移除头部入口,记忆视图内滚,轨迹详情加审计页签
|
|
6
|
+
|
|
7
|
+
- **移除会话头部的「记忆审计」按钮**:入口收敛到会话内的「记忆」视图和轨迹详情页签,不再占用标题行。
|
|
8
|
+
- **记忆视图不再撑高外层**:视图声明 `data-conversation-composer-overlay`,与 Trajectory 用同一套壳层机制把 viewArea 压成固定高度;审计列表在自己的滚动容器里滚动,外层会话界面不需要跟着滚。底部为浮动 composer 预留高度。
|
|
9
|
+
- **轨迹详情新增「记忆审计」页签**:Trajectory 没有页签级 slot,所以页签按钮和面板放在 `shell.overlay` 里,用 fixed 定位贴着右侧详情面板(页签行预留 96px,不改 React 管理的 DOM)。点击后展示该记录的 callId 对应审计事件,底部按钮跳到本会话记忆审计面板;没有 callId 的记录明确提示无法精确过滤。选择器用 CSS Modules 稳定后缀(`_details` / `_detailTabs` / `_detailBody`),失配时静默隐藏。
|
|
10
|
+
|
|
5
11
|
## 0.14.0 — 记忆审计与会话轨迹互相精准跳转
|
|
6
12
|
|
|
7
13
|
- **审计可定位到轨迹**:审计详情新增「在轨迹中定位」。条目上的 `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 的选中行带有稳定的 `data-trajectory-row-key`(工具行是 `kind\0call\0<callId>`)。一个 `shell.overlay` 徽标只读观察选中行,按 callId 查审计,在行右侧浮出「记忆 N」。点击后打开记忆面板的「审计」页,并按 `op:<callId>`
|
|
378
|
+
- **轨迹 → 记忆审计**:Trajectory 的选中行带有稳定的 `data-trajectory-row-key`(工具行是 `kind\0call\0<callId>`)。一个 `shell.overlay` 徽标只读观察选中行,按 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,11 +445,34 @@ 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))}',
|
|
@@ -2147,17 +2170,6 @@ window.__ModuleLoader__.load({
|
|
|
2147
2170
|
}
|
|
2148
2171
|
}
|
|
2149
2172
|
|
|
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)
|
|
2156
|
-
} catch {
|
|
2157
|
-
return undefined
|
|
2158
|
-
}
|
|
2159
|
-
}
|
|
2160
|
-
|
|
2161
2173
|
/**
|
|
2162
2174
|
* `conversation.session` 注册时把 per-session store 交给 slot 服务;服务把实例
|
|
2163
2175
|
* 放在 `_stores` 的 handle 记录里,按 session id 解析。这是主面板唯一能拿到
|
|
@@ -3577,7 +3589,12 @@ window.__ModuleLoader__.load({
|
|
|
3577
3589
|
if (typeof openView === 'function') openView('trajectory', focus)
|
|
3578
3590
|
} catch { /* 视图不可用时保持在本页 */ }
|
|
3579
3591
|
}
|
|
3580
|
-
return h('div', {
|
|
3592
|
+
return h('div', {
|
|
3593
|
+
className: 'memp mem-view',
|
|
3594
|
+
// 让宿主把 composer 浮起来、把 viewArea 压成固定高度(与 Trajectory 同一机制),
|
|
3595
|
+
// 否则外层 scrollBody 会滚动,审计列表拿不到自己的滚动视口。
|
|
3596
|
+
'data-conversation-composer-overlay': '',
|
|
3597
|
+
},
|
|
3581
3598
|
h('div', { className: 'mem-view-head' },
|
|
3582
3599
|
h('b', null, '记忆审计'),
|
|
3583
3600
|
h('span', { className: 'muted' }, '本会话的注入评估、投递与记忆工具调用;选中一条可在轨迹里精确定位。'),
|
|
@@ -3600,21 +3617,6 @@ window.__ModuleLoader__.load({
|
|
|
3600
3617
|
)
|
|
3601
3618
|
}
|
|
3602
3619
|
|
|
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
3620
|
/**
|
|
3619
3621
|
* Trajectory 行上的记忆徽标。
|
|
3620
3622
|
*
|
|
@@ -3713,6 +3715,257 @@ window.__ModuleLoader__.load({
|
|
|
3713
3715
|
}, h('span', { className: 'dot' }), `记忆 ${badge.entries.length}`)
|
|
3714
3716
|
}
|
|
3715
3717
|
|
|
3718
|
+
/**
|
|
3719
|
+
* 轨迹详情面板里的「记忆审计」页签。
|
|
3720
|
+
*
|
|
3721
|
+
* Trajectory 的详情页签是包内私有的 `detailTabs` 数组,没有给插件留 slot。
|
|
3722
|
+
* 这里不在 React 管理的 `<div data-slot>` 里插节点(会被重渲染清掉),而是:
|
|
3723
|
+
* 1. 给详情页签行加 `padding-right` 预留 96px;
|
|
3724
|
+
* 2. 在 `shell.overlay` 里用 fixed 定位渲染一个页签按钮,贴在保留区;
|
|
3725
|
+
* 3. 点开后用 fixed 覆盖详情正文区域,展示这条记录的审计;
|
|
3726
|
+
* 4. 页签/面板的位置随滚动、resize、详情切换重新测量。
|
|
3727
|
+
* 选择器全部用 CSS Modules 的稳定后缀(`_details` / `_detailTabs` / `_detailBody`),
|
|
3728
|
+
* 失配时什么都不显示,不影响轨迹本身。
|
|
3729
|
+
*/
|
|
3730
|
+
function TrajectoryDetailAudit() {
|
|
3731
|
+
const [layout, setLayout] = React.useState({
|
|
3732
|
+
visible: false, tabTop: 0, tabLeft: 0, tabWidth: 88, paneTop: 0, paneLeft: 0, paneWidth: 0, paneHeight: 0,
|
|
3733
|
+
})
|
|
3734
|
+
const [open, setOpen] = React.useState(false)
|
|
3735
|
+
const [callId, setCallId] = React.useState(undefined)
|
|
3736
|
+
const [sessionId, setSessionId] = React.useState(undefined)
|
|
3737
|
+
const [entries, setEntries] = React.useState([])
|
|
3738
|
+
const [loading, setLoading] = React.useState(false)
|
|
3739
|
+
const [error, setError] = React.useState('')
|
|
3740
|
+
const layoutRef = React.useRef(layout)
|
|
3741
|
+
const openRef = React.useRef(false)
|
|
3742
|
+
const keyRef = React.useRef('')
|
|
3743
|
+
const cacheRef = React.useRef(new Map())
|
|
3744
|
+
const setOpenBoth = (value) => { openRef.current = value; setOpen(value) }
|
|
3745
|
+
|
|
3746
|
+
const loadAudit = (sid, cid) => {
|
|
3747
|
+
const key = `${sid}|${cid}`
|
|
3748
|
+
const cached = cacheRef.current.get(key)
|
|
3749
|
+
if (cached && cached.pending === true) return
|
|
3750
|
+
if (cached && Date.now() - cached.at < 4000) {
|
|
3751
|
+
setEntries(cached.entries)
|
|
3752
|
+
setLoading(false)
|
|
3753
|
+
setError('')
|
|
3754
|
+
return
|
|
3755
|
+
}
|
|
3756
|
+
cacheRef.current.set(key, { at: Date.now(), pending: true, entries: [] })
|
|
3757
|
+
setLoading(true)
|
|
3758
|
+
setError('')
|
|
3759
|
+
api(`audit?session=${encodeURIComponent(sid)}&operation=${encodeURIComponent(cid)}&limit=50`)
|
|
3760
|
+
.then((value) => {
|
|
3761
|
+
const list = value && Array.isArray(value.entries) ? value.entries : []
|
|
3762
|
+
cacheRef.current.set(key, { at: Date.now(), pending: false, entries: list })
|
|
3763
|
+
if (keyRef.current === key) { setEntries(list); setLoading(false) }
|
|
3764
|
+
})
|
|
3765
|
+
.catch((reason) => {
|
|
3766
|
+
cacheRef.current.set(key, { at: Date.now(), pending: false, entries: [] })
|
|
3767
|
+
if (keyRef.current === key) { setEntries([]); setLoading(false); setError(String(reason?.message || reason)) }
|
|
3768
|
+
})
|
|
3769
|
+
}
|
|
3770
|
+
|
|
3771
|
+
React.useEffect(() => {
|
|
3772
|
+
let disposed = false
|
|
3773
|
+
let raf = 0
|
|
3774
|
+
const rafFn = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : ((fn) => setTimeout(fn, 16))
|
|
3775
|
+
const cancelFn = typeof cancelAnimationFrame === 'function' ? cancelAnimationFrame : ((id) => clearTimeout(id))
|
|
3776
|
+
const apply = (next) => {
|
|
3777
|
+
const prev = layoutRef.current
|
|
3778
|
+
if (prev.visible === next.visible
|
|
3779
|
+
&& Math.abs(prev.tabTop - next.tabTop) < 1
|
|
3780
|
+
&& Math.abs(prev.tabLeft - next.tabLeft) < 1
|
|
3781
|
+
&& Math.abs(prev.paneTop - next.paneTop) < 1
|
|
3782
|
+
&& Math.abs(prev.paneLeft - next.paneLeft) < 1
|
|
3783
|
+
&& Math.abs(prev.paneWidth - next.paneWidth) < 1
|
|
3784
|
+
&& Math.abs(prev.paneHeight - next.paneHeight) < 1) return
|
|
3785
|
+
layoutRef.current = next
|
|
3786
|
+
setLayout(next)
|
|
3787
|
+
}
|
|
3788
|
+
const hide = () => {
|
|
3789
|
+
apply({ visible: false, tabTop: 0, tabLeft: 0, tabWidth: 88, paneTop: 0, paneLeft: 0, paneWidth: 0, paneHeight: 0 })
|
|
3790
|
+
keyRef.current = ''
|
|
3791
|
+
}
|
|
3792
|
+
const tick = () => {
|
|
3793
|
+
try {
|
|
3794
|
+
if (disposed || typeof document === 'undefined' || typeof window === 'undefined') return
|
|
3795
|
+
const details = document.querySelector('[class*="_details"]')
|
|
3796
|
+
if (details === null) { hide(); return }
|
|
3797
|
+
const tabs = details.querySelector('[class*="_detailTabs"]')
|
|
3798
|
+
const body = details.querySelector('[class*="_detailBody"]')
|
|
3799
|
+
const row = document.querySelector('tr[data-selected="true"][data-trajectory-row-key]')
|
|
3800
|
+
if (tabs === null || body === null || row === null) { hide(); return }
|
|
3801
|
+
const detailsRect = details.getBoundingClientRect()
|
|
3802
|
+
const tabsRect = tabs.getBoundingClientRect()
|
|
3803
|
+
if (detailsRect.width < 220 || detailsRect.height < 120 || tabsRect.height === 0) { hide(); return }
|
|
3804
|
+
const sid = currentSessionId()
|
|
3805
|
+
if (sid === undefined) { hide(); return }
|
|
3806
|
+
// 给受 React 管理的 tabs 行留出右侧空位;只改 style,不动 DOM 结构。
|
|
3807
|
+
if (tabs.style.paddingRight !== '96px') tabs.style.paddingRight = '96px'
|
|
3808
|
+
const cid = trajectoryRowCallId(row)
|
|
3809
|
+
const key = `${sid}|${cid ?? ''}`
|
|
3810
|
+
if (key !== keyRef.current) {
|
|
3811
|
+
keyRef.current = key
|
|
3812
|
+
setCallId(cid)
|
|
3813
|
+
setSessionId(sid)
|
|
3814
|
+
setOpenBoth(false)
|
|
3815
|
+
if (cid === undefined) {
|
|
3816
|
+
setEntries([])
|
|
3817
|
+
setLoading(false)
|
|
3818
|
+
setError('')
|
|
3819
|
+
} else {
|
|
3820
|
+
loadAudit(sid, cid)
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
const tabWidth = 88
|
|
3824
|
+
const tabTop = tabsRect.top + 4
|
|
3825
|
+
const tabLeft = Math.max(0, tabsRect.right - tabWidth - 4)
|
|
3826
|
+
const paneTop = tabsRect.bottom
|
|
3827
|
+
const paneLeft = detailsRect.left
|
|
3828
|
+
const paneWidth = detailsRect.width
|
|
3829
|
+
// 轨迹会把 composer 浮在面板底部;审计面板停在 composer 上沿,
|
|
3830
|
+
// 避免把输入框盖住(composer 不存在/隐藏时退回面板底边)。
|
|
3831
|
+
const composerSeat = document.querySelector('[class*="_composerSeat"]')
|
|
3832
|
+
const composerRect = composerSeat ? composerSeat.getBoundingClientRect() : null
|
|
3833
|
+
const paneBottom = composerRect !== null && composerRect.height > 0
|
|
3834
|
+
? Math.min(detailsRect.bottom, composerRect.top)
|
|
3835
|
+
: detailsRect.bottom
|
|
3836
|
+
const paneHeight = Math.max(0, paneBottom - tabsRect.bottom)
|
|
3837
|
+
apply({ visible: true, tabTop, tabLeft, tabWidth, paneTop, paneLeft, paneWidth, paneHeight })
|
|
3838
|
+
} catch { /* 观察失败:保持现状 */ }
|
|
3839
|
+
}
|
|
3840
|
+
const schedule = () => {
|
|
3841
|
+
if (disposed || raf !== 0) return
|
|
3842
|
+
raf = rafFn(() => { raf = 0; tick() })
|
|
3843
|
+
}
|
|
3844
|
+
let observer = null
|
|
3845
|
+
try {
|
|
3846
|
+
observer = new MutationObserver(schedule)
|
|
3847
|
+
observer.observe(document.body, {
|
|
3848
|
+
childList: true,
|
|
3849
|
+
subtree: true,
|
|
3850
|
+
attributes: true,
|
|
3851
|
+
attributeFilter: ['data-selected', 'class', 'style'],
|
|
3852
|
+
})
|
|
3853
|
+
} catch { observer = null }
|
|
3854
|
+
const onScroll = () => schedule()
|
|
3855
|
+
let timer = null
|
|
3856
|
+
try {
|
|
3857
|
+
window.addEventListener('scroll', onScroll, true)
|
|
3858
|
+
window.addEventListener('resize', onScroll)
|
|
3859
|
+
timer = setInterval(tick, 700)
|
|
3860
|
+
} catch { /* 非浏览器环境 */ }
|
|
3861
|
+
const onDocClick = (event) => {
|
|
3862
|
+
try {
|
|
3863
|
+
const target = event.target
|
|
3864
|
+
if (!target || typeof target.closest !== 'function') return
|
|
3865
|
+
if (target.closest('.mem-traj-audit-tab') || target.closest('.mem-traj-audit-pane')) return
|
|
3866
|
+
if (target.closest('[class*="_detailTab"]')) setOpenBoth(false)
|
|
3867
|
+
} catch { /* 忽略 */ }
|
|
3868
|
+
}
|
|
3869
|
+
try { document.addEventListener('click', onDocClick, true) } catch { /* 忽略 */ }
|
|
3870
|
+
schedule()
|
|
3871
|
+
return () => {
|
|
3872
|
+
disposed = true
|
|
3873
|
+
if (raf !== 0) cancelFn(raf)
|
|
3874
|
+
if (timer !== null) clearInterval(timer)
|
|
3875
|
+
try { observer?.disconnect() } catch { /* 已断开 */ }
|
|
3876
|
+
try {
|
|
3877
|
+
window.removeEventListener('scroll', onScroll, true)
|
|
3878
|
+
window.removeEventListener('resize', onScroll)
|
|
3879
|
+
document.removeEventListener('click', onDocClick, true)
|
|
3880
|
+
} catch { /* 非浏览器环境 */ }
|
|
3881
|
+
}
|
|
3882
|
+
}, [])
|
|
3883
|
+
|
|
3884
|
+
if (!layout.visible) return null
|
|
3885
|
+
const toggle = () => setOpenBoth(!openRef.current)
|
|
3886
|
+
const close = () => setOpenBoth(false)
|
|
3887
|
+
const openInPanel = (entryId) => {
|
|
3888
|
+
openMemoryAuditPanel({
|
|
3889
|
+
sessionId,
|
|
3890
|
+
...(callId !== undefined ? { callId } : {}),
|
|
3891
|
+
...(entryId !== undefined ? { entryId } : {}),
|
|
3892
|
+
})
|
|
3893
|
+
}
|
|
3894
|
+
const rowView = (entry) => {
|
|
3895
|
+
const ids = entry.selected && Array.isArray(entry.selected.contentIds) ? entry.selected.contentIds : []
|
|
3896
|
+
const outcome = auditOutcomeMeta(entry.outcome)
|
|
3897
|
+
return h('button', {
|
|
3898
|
+
key: entry.id,
|
|
3899
|
+
className: 'mem-traj-audit-row',
|
|
3900
|
+
title: `${fmtTime(entry.at)} · ${entry.trigger || entry.stage || ''}`,
|
|
3901
|
+
onClick: () => openInPanel(entry.id),
|
|
3902
|
+
},
|
|
3903
|
+
h('div', { className: 'mem-traj-audit-row-top' },
|
|
3904
|
+
h('span', { className: 't' }, shortTime(entry.at)),
|
|
3905
|
+
h('span', { className: 'ch' }, `${auditChannelLabel(entry.channel)} · ${entry.kind || 'event'}`),
|
|
3906
|
+
h('span', { className: 'spacer' }),
|
|
3907
|
+
h('span', { className: `audit-pill ${outcome.tone}` }, outcome.label),
|
|
3908
|
+
),
|
|
3909
|
+
h('div', { className: 'mem-traj-audit-row-meta' },
|
|
3910
|
+
`${entry.trigger || '—'}${entry.stage ? ` / ${entry.stage}` : ''}`
|
|
3911
|
+
+ (entry.delivery ? ` · ${auditDeliveryMeta(entry).label}` : '')
|
|
3912
|
+
+ (entry.candidates !== undefined ? ` · 候选 ${entry.candidates}` : '')
|
|
3913
|
+
+ (entry.selected && entry.selected.count !== undefined ? ` · 选中 ${entry.selected.count}` : ''),
|
|
3914
|
+
),
|
|
3915
|
+
ids.length > 0
|
|
3916
|
+
? h('div', { className: 'mem-traj-audit-row-ids' },
|
|
3917
|
+
ids.slice(0, 4).map((id) => h('span', { className: 'audit-id', key: id }, String(id).length > 14 ? `${String(id).slice(0, 10)}…` : String(id))),
|
|
3918
|
+
ids.length > 4 ? h('span', { className: 'audit-id-sub' }, `+${ids.length - 4}`) : null,
|
|
3919
|
+
)
|
|
3920
|
+
: null,
|
|
3921
|
+
)
|
|
3922
|
+
}
|
|
3923
|
+
return h(React.Fragment, null,
|
|
3924
|
+
h('button', {
|
|
3925
|
+
className: 'mem-traj-audit-tab' + (open ? ' on' : ''),
|
|
3926
|
+
style: { top: layout.tabTop, left: layout.tabLeft, width: layout.tabWidth },
|
|
3927
|
+
title: callId === undefined ? '这条记录没有 callId 锚点,可打开本会话记忆审计' : `查看这次调用的记忆审计(${callId})`,
|
|
3928
|
+
onClick: toggle,
|
|
3929
|
+
}, `记忆审计${entries.length > 0 ? ` ${entries.length}` : ''}`),
|
|
3930
|
+
open
|
|
3931
|
+
? h('div', {
|
|
3932
|
+
className: 'memp mem-traj-audit-pane',
|
|
3933
|
+
style: {
|
|
3934
|
+
top: layout.paneTop,
|
|
3935
|
+
left: layout.paneLeft,
|
|
3936
|
+
width: layout.paneWidth,
|
|
3937
|
+
height: layout.paneHeight,
|
|
3938
|
+
},
|
|
3939
|
+
},
|
|
3940
|
+
h('div', { className: 'mem-traj-audit-pane-head' },
|
|
3941
|
+
h('b', null, '记忆审计'),
|
|
3942
|
+
callId !== undefined ? h('span', { className: 'mono', title: callId }, callId.length > 20 ? `${callId.slice(0, 18)}…` : callId) : null,
|
|
3943
|
+
h('span', { className: 'spacer' }),
|
|
3944
|
+
h('button', { className: 'linkbtn', onClick: close }, '返回轨迹'),
|
|
3945
|
+
),
|
|
3946
|
+
h('div', { className: 'mem-traj-audit-pane-body' },
|
|
3947
|
+
loading
|
|
3948
|
+
? h('div', { className: 'mem-traj-audit-empty' }, '加载审计…')
|
|
3949
|
+
: error
|
|
3950
|
+
? h('div', { className: 'mem-traj-audit-empty' }, `加载失败:${error}`)
|
|
3951
|
+
: entries.length === 0
|
|
3952
|
+
? h('div', { className: 'mem-traj-audit-empty' },
|
|
3953
|
+
callId === undefined
|
|
3954
|
+
? '这条轨迹记录没有 callId 锚点,无法精确过滤;可以打开本会话记忆审计,按轮次/步骤查找。'
|
|
3955
|
+
: '这次调用没有记忆审计记录(可能发生在审计开启前,或已被容量策略淘汰)。',
|
|
3956
|
+
)
|
|
3957
|
+
: entries.map(rowView),
|
|
3958
|
+
),
|
|
3959
|
+
h('div', { className: 'mem-traj-audit-pane-foot' },
|
|
3960
|
+
h('span', { className: 'muted' }, entries.length > 0 ? `${entries.length} 条` : ''),
|
|
3961
|
+
h('span', { className: 'spacer' }),
|
|
3962
|
+
h('button', { onClick: () => openInPanel(entries[0]?.id) }, '打开本会话记忆审计'),
|
|
3963
|
+
),
|
|
3964
|
+
)
|
|
3965
|
+
: null,
|
|
3966
|
+
)
|
|
3967
|
+
}
|
|
3968
|
+
|
|
3716
3969
|
const inject = ['slots']
|
|
3717
3970
|
|
|
3718
3971
|
/** 侧栏入口打开的主界面页面(整块可滚动,内容就是面板本体)。 */
|
|
@@ -3856,17 +4109,6 @@ window.__ModuleLoader__.load({
|
|
|
3856
4109
|
} catch (error) {
|
|
3857
4110
|
console.warn('[dsh-memory] 记忆审计视图注册失败:', error?.message)
|
|
3858
4111
|
}
|
|
3859
|
-
try {
|
|
3860
|
-
slots.inject('conversation.session.header.actions', () => slots.register({
|
|
3861
|
-
name: 'conversation.session.header.actions',
|
|
3862
|
-
id: 'memory-audit',
|
|
3863
|
-
order: 20,
|
|
3864
|
-
label: () => '记忆审计',
|
|
3865
|
-
inject: (sessionId) => ({ sessionId }),
|
|
3866
|
-
}, MemoryHeaderAction))
|
|
3867
|
-
} catch (error) {
|
|
3868
|
-
console.warn('[dsh-memory] 会话头部记忆入口注册失败:', error?.message)
|
|
3869
|
-
}
|
|
3870
4112
|
try {
|
|
3871
4113
|
slots.inject('shell.overlay', () => slots.register({
|
|
3872
4114
|
name: 'shell.overlay',
|
|
@@ -3876,6 +4118,15 @@ window.__ModuleLoader__.load({
|
|
|
3876
4118
|
} catch (error) {
|
|
3877
4119
|
console.warn('[dsh-memory] 轨迹记忆徽标注册失败:', error?.message)
|
|
3878
4120
|
}
|
|
4121
|
+
try {
|
|
4122
|
+
slots.inject('shell.overlay', () => slots.register({
|
|
4123
|
+
name: 'shell.overlay',
|
|
4124
|
+
id: 'memory-audit-detail',
|
|
4125
|
+
order: 61,
|
|
4126
|
+
}, () => React.createElement(TrajectoryDetailAudit)))
|
|
4127
|
+
} catch (error) {
|
|
4128
|
+
console.warn('[dsh-memory] 轨迹详情记忆页签注册失败:', error?.message)
|
|
4129
|
+
}
|
|
3879
4130
|
} catch (error) {
|
|
3880
4131
|
console.error('[dsh-memory] client apply 失败(已吞掉):', error?.message)
|
|
3881
4132
|
}
|
|
@@ -4003,8 +4254,8 @@ window.__ModuleLoader__.load({
|
|
|
4003
4254
|
paintNavIcon: paintNavIcon,
|
|
4004
4255
|
// 审计 ↔ 轨迹桥(测试只覆盖纯解析/焦点总线,不碰宿主 slot 实例)
|
|
4005
4256
|
MemoryAuditView: MemoryAuditView,
|
|
4006
|
-
MemoryHeaderAction: MemoryHeaderAction,
|
|
4007
4257
|
TrajectoryMemoryBadge: TrajectoryMemoryBadge,
|
|
4258
|
+
TrajectoryDetailAudit: TrajectoryDetailAudit,
|
|
4008
4259
|
auditEntryCallId: auditEntryCallId,
|
|
4009
4260
|
trajectoryRowCallId: trajectoryRowCallId,
|
|
4010
4261
|
requestAuditFocus: requestAuditFocus,
|