@restregular/dsh-memory 0.17.1 → 0.19.0
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 +37 -0
- package/README.md +29 -2
- package/lib/client.js +663 -0
- package/lib/inject/apply.js +92 -9
- package/lib/inject/inject.js +25 -6
- package/lib/inject/rules.js +8 -3
- package/lib/panel.js +153 -2
- package/lib/provider/apply.js +64 -0
- package/lib/provider/index.js +374 -4
- package/lib/provider/session-visibility.js +206 -0
- package/lib/tools/index.js +271 -20
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -485,6 +485,74 @@ window.__ModuleLoader__.load({
|
|
|
485
485
|
'.mem-traj-mark:focus-visible{outline:1px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}',
|
|
486
486
|
'@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}}',
|
|
487
487
|
'@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)}}',
|
|
488
|
+
'.mem-scope-wrap{display:inline-flex;min-width:0}',
|
|
489
|
+
'.mem-scope-btn{display:inline-flex;align-items:center;gap:5px;height:28px;padding:0 9px;border:1px solid var(--dsw-alias-border-l1);border-radius:9px;background:color-mix(in srgb,var(--dsw-alias-bg-layer-1) 55%,transparent);color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1;cursor:pointer;flex:none;transition:border-color .12s ease,color .12s ease,background .12s ease}',
|
|
490
|
+
'.mem-scope-btn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}',
|
|
491
|
+
'.mem-scope-btn.on{color:var(--dsw-alias-brand-primary);border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 45%,var(--dsw-alias-border-l1));background:color-mix(in srgb,var(--dsw-alias-brand-primary) 9%,transparent)}',
|
|
492
|
+
'.mem-scope-btn svg{flex:none}',
|
|
493
|
+
// 毛玻璃浮窗:半透明 + backdrop blur;不支持 backdrop-filter 时退回实心底。
|
|
494
|
+
'.mem-scope-pop{position:fixed;z-index:80;width:360px;max-height:min(620px,80vh);display:flex;flex-direction:column;gap:9px;padding:14px;border:1px solid color-mix(in srgb,var(--dsw-alias-border-l2,var(--dsw-alias-border-l1)) 70%,transparent);border-radius:16px;background:color-mix(in srgb,var(--dsw-alias-bg-layer-1) 66%,transparent);-webkit-backdrop-filter:blur(20px) saturate(1.4);backdrop-filter:blur(20px) saturate(1.4);box-shadow:0 22px 60px rgba(0,0,0,.34),inset 0 1px 0 rgba(255,255,255,.08);color:var(--dsw-alias-label-primary);font-size:13px;overflow:hidden}',
|
|
495
|
+
'@supports not ((backdrop-filter:blur(1px)) or (-webkit-backdrop-filter:blur(1px))){.mem-scope-pop{background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-1))}}',
|
|
496
|
+
'.mem-scope-head{display:flex;align-items:center;gap:8px}',
|
|
497
|
+
'.mem-scope-head h4{margin:0;font-size:13px;font-weight:600;line-height:1.4}',
|
|
498
|
+
'.mem-scope-head .spacer{flex:1}',
|
|
499
|
+
'.mem-scope-count{flex:none;padding:1px 8px;border:1px solid var(--dsw-alias-border-l1);border-radius:999px;color:var(--dsw-alias-label-secondary);font-size:10.5px;line-height:1.7}',
|
|
500
|
+
'.mem-scope-pop .hint{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.55}',
|
|
501
|
+
'.mem-scope-level{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:5px}',
|
|
502
|
+
'.mem-scope-level-btn{display:flex;flex-direction:column;align-items:flex-start;gap:1px;padding:7px 8px;border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:transparent;color:var(--dsw-alias-label-secondary);font-size:11px;text-align:left;cursor:pointer;transition:border-color .12s ease,background .12s ease}',
|
|
503
|
+
'.mem-scope-level-btn b{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary)}',
|
|
504
|
+
'.mem-scope-level-btn span{font-size:9.5px;line-height:1.4;color:var(--dsw-alias-label-secondary)}',
|
|
505
|
+
'.mem-scope-level-btn:hover{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 40%,var(--dsw-alias-border-l1))}',
|
|
506
|
+
'.mem-scope-level-btn.on{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 55%,var(--dsw-alias-border-l1));background:color-mix(in srgb,var(--dsw-alias-brand-primary) 11%,transparent)}',
|
|
507
|
+
'.mem-scope-level-btn.on b,.mem-scope-level-btn.on span{color:var(--dsw-alias-brand-primary)}',
|
|
508
|
+
'.mem-scope-note{padding:5px 8px;border-radius:8px;background:color-mix(in srgb,var(--dsw-alias-state-warn-primary,#d9a23b) 10%,transparent);color:var(--dsw-alias-label-secondary);font-size:11px;line-height:1.5}',
|
|
509
|
+
'.mem-scope-search{display:flex;align-items:center;gap:6px}',
|
|
510
|
+
'.mem-scope-search input[type=search]{flex:1;min-width:0;padding:5px 9px;font-size:12px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;background:color-mix(in srgb,var(--dsw-alias-bg-layer-1) 78%,transparent);color:var(--dsw-alias-label-primary);outline:none}',
|
|
511
|
+
'.mem-scope-search input[type=search]:focus{border-color:var(--dsw-alias-brand-primary)}',
|
|
512
|
+
'.mem-scope-search .linkbtn{white-space:nowrap;padding:2px 3px;border:none;background:none;color:var(--dsw-alias-label-secondary);font-size:11px;cursor:pointer}',
|
|
513
|
+
'.mem-scope-search .linkbtn:hover{color:var(--dsw-alias-brand-primary);border:none}',
|
|
514
|
+
'.mem-scope-list{display:flex;flex-direction:column;gap:3px;overflow:auto;min-height:0;max-height:min(300px,40vh);padding:2px 2px 2px 0;scrollbar-width:thin}',
|
|
515
|
+
'.mem-scope-list::-webkit-scrollbar{width:8px}',
|
|
516
|
+
'.mem-scope-list::-webkit-scrollbar-thumb{background:color-mix(in srgb,var(--dsw-alias-label-secondary) 35%,transparent);border-radius:999px;border:2px solid transparent;background-clip:padding-box}',
|
|
517
|
+
'.mem-scope-item{display:flex;flex-direction:column;gap:4px;padding:5px 6px;border:1px solid transparent;border-radius:10px}',
|
|
518
|
+
'.mem-scope-item:hover{background:var(--dsw-alias-interactive-bg-hover)}',
|
|
519
|
+
'.mem-scope-item.on{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 24%,var(--dsw-alias-border-l1));background:color-mix(in srgb,var(--dsw-alias-brand-primary) 7%,transparent)}',
|
|
520
|
+
'.mem-scope-row{display:flex;align-items:center;gap:8px}',
|
|
521
|
+
'.mem-scope-check{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;padding:0;border:none;background:transparent;flex:none;cursor:pointer}',
|
|
522
|
+
'.mem-scope-check .box{display:flex;align-items:center;justify-content:center;width:16px;height:16px;border:1.5px solid var(--dsw-alias-border-l2,var(--dsw-alias-border-l1));border-radius:5px;background:transparent;color:var(--dsw-alias-label-on-brand,#fff);transition:background .12s ease,border-color .12s ease}',
|
|
523
|
+
'.mem-scope-check.on .box{background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary)}',
|
|
524
|
+
'.mem-scope-check:focus-visible{outline:1px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}',
|
|
525
|
+
'.mem-scope-label{flex:1;min-width:0;padding:0;border:none;background:transparent;color:var(--dsw-alias-label-primary);font-size:12.5px;text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:pointer}',
|
|
526
|
+
'.mem-scope-label:hover{color:var(--dsw-alias-brand-primary);border:none}',
|
|
527
|
+
'.mem-scope-row .cnt{flex:none;color:var(--dsw-alias-label-secondary);font-size:10.5px}',
|
|
528
|
+
'.mem-kind-row{display:flex;flex-wrap:wrap;gap:4px;padding-left:24px}',
|
|
529
|
+
'.mem-kind-chip{display:inline-flex;align-items:center;gap:3px;padding:1px 7px;border:1px solid var(--dsw-alias-border-l1);border-radius:999px;background:transparent;color:var(--dsw-alias-label-secondary);font-size:10.5px;line-height:1.7;cursor:pointer}',
|
|
530
|
+
'.mem-kind-chip:hover{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 50%,var(--dsw-alias-border-l1));color:var(--dsw-alias-label-primary)}',
|
|
531
|
+
'.mem-kind-chip.on{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 55%,var(--dsw-alias-border-l1));color:var(--dsw-alias-brand-primary);background:color-mix(in srgb,var(--dsw-alias-brand-primary) 10%,transparent)}',
|
|
532
|
+
'.mem-kind-chip i{font-style:normal;opacity:.65;font-size:9px}',
|
|
533
|
+
'.mem-scope-foot{display:flex;align-items:center;gap:8px}',
|
|
534
|
+
'.mem-scope-foot .spacer{flex:1}',
|
|
535
|
+
'.mem-scope-reset{padding:6px 13px;border:1px solid var(--dsw-alias-border-l1);border-radius:9px;background:transparent;color:var(--dsw-alias-label-secondary);font-size:12px;cursor:pointer;transition:border-color .12s ease,color .12s ease}',
|
|
536
|
+
'.mem-scope-reset:hover:not(:disabled){border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 55%,var(--dsw-alias-border-l1));color:var(--dsw-alias-brand-primary)}',
|
|
537
|
+
'.mem-scope-save{padding:6px 16px;border:1px solid var(--dsw-alias-brand-primary);border-radius:9px;background:linear-gradient(180deg,color-mix(in srgb,var(--dsw-alias-brand-primary) 92%,white 8%),var(--dsw-alias-brand-primary));color:var(--dsw-alias-label-on-brand,#fff);font-size:12px;font-weight:600;cursor:pointer;box-shadow:0 4px 14px color-mix(in srgb,var(--dsw-alias-brand-primary) 30%,transparent);transition:filter .12s ease}',
|
|
538
|
+
'.mem-scope-save:hover:not(:disabled){filter:brightness(1.06)}',
|
|
539
|
+
'.mem-scope-reset:disabled,.mem-scope-save:disabled{opacity:.5;cursor:default;filter:none}',
|
|
540
|
+
'.mem-scope-err{padding:5px 8px;border-radius:8px;background:color-mix(in srgb,var(--dsw-alias-state-error-primary,#d33) 10%,transparent);color:var(--dsw-alias-state-error-primary,#d33);font-size:12px;line-height:1.5}',
|
|
541
|
+
// 范围外访问审批浮层(全局 fixed;根节点带 .memp 以复用审计 hover 浮窗样式)
|
|
542
|
+
'.mem-approval{position:fixed;left:50%;bottom:18px;transform:translateX(-50%);z-index:90;width:min(520px,calc(100vw - 24px));max-height:min(70vh,620px);display:flex;flex-direction:column;pointer-events:none;padding:0;font-size:13px;color:var(--dsw-alias-label-primary)}',
|
|
543
|
+
'.mem-approval-card{pointer-events:auto;display:flex;flex-direction:column;gap:8px;padding:14px;border:1px solid color-mix(in srgb,var(--dsw-alias-state-warn-primary,#d9a23b) 42%,var(--dsw-alias-border-l1));border-radius:16px;background:color-mix(in srgb,var(--dsw-alias-bg-layer-1) 72%,transparent);-webkit-backdrop-filter:blur(20px) saturate(1.35);backdrop-filter:blur(20px) saturate(1.35);box-shadow:0 22px 60px rgba(0,0,0,.36),inset 0 1px 0 rgba(255,255,255,.08);overflow:hidden}',
|
|
544
|
+
'@supports not ((backdrop-filter:blur(1px)) or (-webkit-backdrop-filter:blur(1px))){.mem-approval-card{background:var(--dsw-alias-bg-layer-1)}}',
|
|
545
|
+
'.mem-approval-head{display:flex;align-items:center;gap:7px}',
|
|
546
|
+
'.mem-approval-head b{font-size:13px;font-weight:600}',
|
|
547
|
+
'.mem-approval-head .spacer{flex:1}',
|
|
548
|
+
'.mem-approval-dot{width:8px;height:8px;border-radius:50%;flex:none;background:var(--dsw-alias-state-warn-primary,#d9a23b);box-shadow:0 0 0 3px color-mix(in srgb,var(--dsw-alias-state-warn-primary,#d9a23b) 18%,transparent)}',
|
|
549
|
+
'.mem-approval-query{padding:6px 9px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;background:color-mix(in srgb,var(--dsw-alias-bg-layer-2) 55%,transparent);color:var(--dsw-alias-label-secondary);font-size:11.5px;line-height:1.5;white-space:pre-wrap;word-break:break-word;max-height:80px;overflow:auto}',
|
|
550
|
+
'.mem-approval-list{display:flex;flex-direction:column;gap:6px;overflow:auto;min-height:0;max-height:min(300px,38vh)}',
|
|
551
|
+
'.mem-approval-item{display:flex;flex-direction:column;gap:4px;padding:7px 8px;border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:color-mix(in srgb,var(--dsw-alias-bg-layer-1) 55%,transparent)}',
|
|
552
|
+
'.mem-approval-row{display:flex;align-items:center;gap:6px;flex-wrap:wrap}',
|
|
553
|
+
'.mem-approval-summary{color:var(--dsw-alias-label-secondary);font-size:11.5px;line-height:1.5;word-break:break-word}',
|
|
554
|
+
'.mem-approval-foot{display:flex;align-items:center;gap:8px}',
|
|
555
|
+
'.mem-approval .spacer{flex:1}',
|
|
488
556
|
].join('')
|
|
489
557
|
|
|
490
558
|
async function api(method, body) {
|
|
@@ -2457,6 +2525,53 @@ window.__ModuleLoader__.load({
|
|
|
2457
2525
|
return target
|
|
2458
2526
|
}
|
|
2459
2527
|
|
|
2528
|
+
// ===== 记录焦点总线:审批浮层里的记忆 ID → 面板「记录」页并展开卡片 =====
|
|
2529
|
+
const RECORD_FOCUS_EVENT = 'dsh-memory:record-focus'
|
|
2530
|
+
let pendingRecordFocus = null
|
|
2531
|
+
|
|
2532
|
+
function requestRecordFocus(target) {
|
|
2533
|
+
pendingRecordFocus = target && typeof target === 'object' ? { ...target, at: Date.now() } : null
|
|
2534
|
+
try {
|
|
2535
|
+
if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof CustomEvent === 'function') {
|
|
2536
|
+
window.dispatchEvent(new CustomEvent(RECORD_FOCUS_EVENT, { detail: pendingRecordFocus }))
|
|
2537
|
+
}
|
|
2538
|
+
} catch { /* 没有 CustomEvent 时靠面板挂载时取一次 */ }
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2541
|
+
function takeRecordFocus() {
|
|
2542
|
+
const target = pendingRecordFocus
|
|
2543
|
+
if (!target) return null
|
|
2544
|
+
pendingRecordFocus = null
|
|
2545
|
+
return target
|
|
2546
|
+
}
|
|
2547
|
+
|
|
2548
|
+
function peekRecordFocus() {
|
|
2549
|
+
return pendingRecordFocus
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
/**
|
|
2553
|
+
* 打开记忆面板并定位到某条记录(审批浮层 hover 的点击动作)。
|
|
2554
|
+
* 优先侧栏主面板;没有侧栏入口时打开设置页。目标由面板挂载/事件消费。
|
|
2555
|
+
*/
|
|
2556
|
+
function openMemoryRecordPanel(id, scope, record) {
|
|
2557
|
+
if (typeof id !== 'string' || id === '') return 'none'
|
|
2558
|
+
requestRecordFocus({ id, scope: typeof scope === 'string' ? scope : '', record: record || null })
|
|
2559
|
+
try {
|
|
2560
|
+
const main = safeSlots()?.entries?.('main') ?? []
|
|
2561
|
+
if (main.some((entry) => entry?.options?.key === 'memory')) {
|
|
2562
|
+
try { clientCtx?.get?.('layout')?.selectPanel?.('memory') } catch { /* 交给挂载消费 */ }
|
|
2563
|
+
return 'panel'
|
|
2564
|
+
}
|
|
2565
|
+
} catch { /* fallthrough */ }
|
|
2566
|
+
try {
|
|
2567
|
+
const settings = clientCtx?.get?.('settings')
|
|
2568
|
+
const openSection = settings?.store?.actions?.openSection ?? settings?.actions?.openSection ?? settings?.openSection
|
|
2569
|
+
if (typeof openSection === 'function') { openSection('memory'); return 'settings' }
|
|
2570
|
+
} catch { /* fallthrough */ }
|
|
2571
|
+
try { clientCtx?.get?.('layout')?.selectPanel?.('settings') } catch { /* 无布局服务 */ }
|
|
2572
|
+
return 'settings'
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2460
2575
|
/**
|
|
2461
2576
|
* 从轨迹/头部入口打开记忆审计:优先主面板;没有侧栏入口时切到会话内的
|
|
2462
2577
|
* 「记忆」视图;两者都不可用时至少打开设置页(面板挂载后会消费 pending)。
|
|
@@ -3340,6 +3455,18 @@ window.__ModuleLoader__.load({
|
|
|
3340
3455
|
setScopeFilter(nextScope)
|
|
3341
3456
|
load('', nextScope, false)
|
|
3342
3457
|
}
|
|
3458
|
+
// 审批浮层 / 其它入口点击记忆 ID:挂载时消费一次 pending,之后靠同一事件。
|
|
3459
|
+
React.useEffect(() => {
|
|
3460
|
+
const applyFocus = () => {
|
|
3461
|
+
const target = takeRecordFocus()
|
|
3462
|
+
if (!target || typeof target.id !== 'string' || target.id === '') return
|
|
3463
|
+
openRecord(target.id, target.scope, target.record || null)
|
|
3464
|
+
}
|
|
3465
|
+
applyFocus()
|
|
3466
|
+
if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') return undefined
|
|
3467
|
+
window.addEventListener(RECORD_FOCUS_EVENT, applyFocus)
|
|
3468
|
+
return () => window.removeEventListener(RECORD_FOCUS_EVENT, applyFocus)
|
|
3469
|
+
}, [])
|
|
3343
3470
|
// 导入完成后从设置页切换回记录页时,列表要能看到新数据(事件由设置页发出)。
|
|
3344
3471
|
React.useEffect(() => {
|
|
3345
3472
|
if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') return undefined
|
|
@@ -4311,6 +4438,515 @@ window.__ModuleLoader__.load({
|
|
|
4311
4438
|
)
|
|
4312
4439
|
}
|
|
4313
4440
|
|
|
4441
|
+
/**
|
|
4442
|
+
* 输入框里的「记忆可见范围」按钮。
|
|
4443
|
+
*
|
|
4444
|
+
* 宿主 `conversation.input.right` 是 session 作用域的 list 槽,owner 会把
|
|
4445
|
+
* `sessionId` 作为标准 prop 传进来,所以这里不需要 register 的 inject。
|
|
4446
|
+
*
|
|
4447
|
+
* 读写走 /memory/api/visibility:
|
|
4448
|
+
* GET ?session=<id> → { override, effective, inherited, scopes }
|
|
4449
|
+
* POST { session, scopes: string[] | null } → 同上
|
|
4450
|
+
* `override === null` = 使用默认三路集合;子 Agent 会话会继承父会话的 override。
|
|
4451
|
+
*
|
|
4452
|
+
* 弹层用 fixed 定位(按按钮 rect 往上开),避免被 composer 的 overflow 裁掉。
|
|
4453
|
+
*/
|
|
4454
|
+
/**
|
|
4455
|
+
* 输入框里的「记忆可见域」按钮 + 浮窗。
|
|
4456
|
+
*
|
|
4457
|
+
* 宿主 `conversation.input.right` 是 session 作用域的 list 槽,owner 会把
|
|
4458
|
+
* `sessionId` 作为标准 prop 传进来,所以这里不需要 register 的 inject。
|
|
4459
|
+
*
|
|
4460
|
+
* 读写走 /memory/api/visibility:
|
|
4461
|
+
* GET ?session=<id> → { override, effective, inherited, scopes, kinds }
|
|
4462
|
+
* POST { session, visibility: { scopes: [{ scope, kinds? }], level } | null } → 同上
|
|
4463
|
+
* `override === null` = 使用默认三路集合;子 Agent 会话会继承父会话的 override。
|
|
4464
|
+
*
|
|
4465
|
+
* 弹层用 fixed 定位(按按钮 rect 往上开),避免被 composer 的 overflow 裁掉。
|
|
4466
|
+
* 视觉:毛玻璃背景 + 自定义勾选 + 类型 chips + 三档限制等级。
|
|
4467
|
+
*/
|
|
4468
|
+
function MemoryVisibilityButton({ sessionId } = {}) {
|
|
4469
|
+
const [open, setOpen] = React.useState(false)
|
|
4470
|
+
const [loading, setLoading] = React.useState(false)
|
|
4471
|
+
const [busy, setBusy] = React.useState(false)
|
|
4472
|
+
const [error, setError] = React.useState('')
|
|
4473
|
+
const [data, setData] = React.useState(null)
|
|
4474
|
+
const [level, setLevel] = React.useState('normal')
|
|
4475
|
+
const [entries, setEntries] = React.useState({})
|
|
4476
|
+
const [search, setSearch] = React.useState('')
|
|
4477
|
+
const [anchor, setAnchor] = React.useState(null)
|
|
4478
|
+
const wrapRef = React.useRef(null)
|
|
4479
|
+
|
|
4480
|
+
React.useEffect(() => {
|
|
4481
|
+
if (!open) return undefined
|
|
4482
|
+
if (typeof document === 'undefined' || typeof document.addEventListener !== 'function') return undefined
|
|
4483
|
+
const onDown = (event) => {
|
|
4484
|
+
try {
|
|
4485
|
+
const node = wrapRef.current
|
|
4486
|
+
if (node && typeof node.contains === 'function' && !node.contains(event.target)) setOpen(false)
|
|
4487
|
+
} catch { /* 关闭失败不影响页面 */ }
|
|
4488
|
+
}
|
|
4489
|
+
const onKey = (event) => { if (event && event.key === 'Escape') setOpen(false) }
|
|
4490
|
+
document.addEventListener('mousedown', onDown)
|
|
4491
|
+
document.addEventListener('keydown', onKey)
|
|
4492
|
+
return () => {
|
|
4493
|
+
try {
|
|
4494
|
+
document.removeEventListener('mousedown', onDown)
|
|
4495
|
+
document.removeEventListener('keydown', onKey)
|
|
4496
|
+
} catch { /* 宿主卸载时 document 可能已不可用 */ }
|
|
4497
|
+
}
|
|
4498
|
+
}, [open])
|
|
4499
|
+
|
|
4500
|
+
if (typeof sessionId !== 'string' || sessionId === '') return null
|
|
4501
|
+
|
|
4502
|
+
const allKindsOf = (value) => {
|
|
4503
|
+
const list = value && Array.isArray(value.kinds) ? value.kinds.filter((kind) => typeof kind === 'string') : []
|
|
4504
|
+
return list.length > 0 ? list : Object.keys(KIND_META)
|
|
4505
|
+
}
|
|
4506
|
+
|
|
4507
|
+
const applyPayload = (value) => {
|
|
4508
|
+
if (!value || typeof value !== 'object') return
|
|
4509
|
+
setData(value)
|
|
4510
|
+
const config = value.override || value.effective || (Array.isArray(value.defaults) && value.defaults.length > 0
|
|
4511
|
+
? { level: 'normal', scopes: value.defaults.map((scope) => ({ scope })) }
|
|
4512
|
+
: null)
|
|
4513
|
+
const selected = config && Array.isArray(config.scopes) ? config.scopes.filter((rule) => rule && typeof rule.scope === 'string') : []
|
|
4514
|
+
setLevel(config && (config.level === 'absolute' || config.level === 'none') ? config.level : 'normal')
|
|
4515
|
+
const kindsAll = allKindsOf(value)
|
|
4516
|
+
const scopes = []
|
|
4517
|
+
const catalog = Array.isArray(value.scopes) ? value.scopes : []
|
|
4518
|
+
for (const item of catalog) {
|
|
4519
|
+
if (item && typeof item.scope === 'string' && !scopes.includes(item.scope)) scopes.push(item.scope)
|
|
4520
|
+
}
|
|
4521
|
+
for (const rule of selected) {
|
|
4522
|
+
if (!scopes.includes(rule.scope)) scopes.push(rule.scope)
|
|
4523
|
+
}
|
|
4524
|
+
const next = {}
|
|
4525
|
+
for (const scope of scopes) {
|
|
4526
|
+
const rule = selected.find((item) => item.scope === scope)
|
|
4527
|
+
const kinds = rule && Array.isArray(rule.kinds) && rule.kinds.length > 0 ? rule.kinds.filter((kind) => kindsAll.includes(kind)) : [...kindsAll]
|
|
4528
|
+
next[scope] = { enabled: rule !== undefined, kinds }
|
|
4529
|
+
}
|
|
4530
|
+
setEntries(next)
|
|
4531
|
+
}
|
|
4532
|
+
|
|
4533
|
+
const load = () => {
|
|
4534
|
+
setLoading(true)
|
|
4535
|
+
setError('')
|
|
4536
|
+
api(`visibility?session=${encodeURIComponent(sessionId)}`)
|
|
4537
|
+
.then(applyPayload)
|
|
4538
|
+
.catch((e) => setError(String((e && e.message) || e)))
|
|
4539
|
+
.finally(() => setLoading(false))
|
|
4540
|
+
}
|
|
4541
|
+
|
|
4542
|
+
const toggle = (event) => {
|
|
4543
|
+
if (open) { setOpen(false); return }
|
|
4544
|
+
let nextAnchor = null
|
|
4545
|
+
try {
|
|
4546
|
+
const rect = event && event.currentTarget && event.currentTarget.getBoundingClientRect
|
|
4547
|
+
? event.currentTarget.getBoundingClientRect()
|
|
4548
|
+
: null
|
|
4549
|
+
if (rect) nextAnchor = { left: rect.left, top: rect.top }
|
|
4550
|
+
} catch { nextAnchor = null }
|
|
4551
|
+
setAnchor(nextAnchor)
|
|
4552
|
+
setSearch('')
|
|
4553
|
+
setOpen(true)
|
|
4554
|
+
load()
|
|
4555
|
+
}
|
|
4556
|
+
|
|
4557
|
+
const toggleScope = (scope) => {
|
|
4558
|
+
const kindsAll = allKindsOf(data)
|
|
4559
|
+
setEntries((prev) => {
|
|
4560
|
+
const current = prev[scope]
|
|
4561
|
+
return { ...prev, [scope]: { enabled: !(current && current.enabled), kinds: current && current.kinds.length > 0 ? current.kinds : [...kindsAll] } }
|
|
4562
|
+
})
|
|
4563
|
+
}
|
|
4564
|
+
|
|
4565
|
+
const toggleKind = (scope, kind) => {
|
|
4566
|
+
setEntries((prev) => {
|
|
4567
|
+
const current = prev[scope]
|
|
4568
|
+
if (!current) return prev
|
|
4569
|
+
const has = current.kinds.includes(kind)
|
|
4570
|
+
if (has && current.kinds.length === 1) return prev // 至少保留一种类型;全部用「全部」按钮
|
|
4571
|
+
const kinds = has ? current.kinds.filter((item) => item !== kind) : [...current.kinds, kind]
|
|
4572
|
+
return { ...prev, [scope]: { ...current, kinds } }
|
|
4573
|
+
})
|
|
4574
|
+
}
|
|
4575
|
+
|
|
4576
|
+
const setAllKinds = (scope) => {
|
|
4577
|
+
const kindsAll = allKindsOf(data)
|
|
4578
|
+
setEntries((prev) => {
|
|
4579
|
+
const current = prev[scope]
|
|
4580
|
+
if (!current) return prev
|
|
4581
|
+
return { ...prev, [scope]: { ...current, kinds: [...kindsAll] } }
|
|
4582
|
+
})
|
|
4583
|
+
}
|
|
4584
|
+
|
|
4585
|
+
const selectAll = () => {
|
|
4586
|
+
const kindsAll = allKindsOf(data)
|
|
4587
|
+
setEntries((prev) => {
|
|
4588
|
+
const next = { ...prev }
|
|
4589
|
+
for (const scope of Object.keys(next)) next[scope] = { enabled: true, kinds: next[scope].kinds.length > 0 ? next[scope].kinds : [...kindsAll] }
|
|
4590
|
+
return next
|
|
4591
|
+
})
|
|
4592
|
+
}
|
|
4593
|
+
|
|
4594
|
+
const clearAll = () => {
|
|
4595
|
+
setEntries((prev) => {
|
|
4596
|
+
const next = { ...prev }
|
|
4597
|
+
for (const scope of Object.keys(next)) next[scope] = { ...next[scope], enabled: false }
|
|
4598
|
+
return next
|
|
4599
|
+
})
|
|
4600
|
+
}
|
|
4601
|
+
|
|
4602
|
+
const save = (config) => {
|
|
4603
|
+
setBusy(true)
|
|
4604
|
+
setError('')
|
|
4605
|
+
api('visibility', { session: sessionId, visibility: config })
|
|
4606
|
+
.then((value) => {
|
|
4607
|
+
applyPayload(value)
|
|
4608
|
+
setOpen(false)
|
|
4609
|
+
})
|
|
4610
|
+
.catch((e) => setError(String((e && e.message) || e)))
|
|
4611
|
+
.finally(() => setBusy(false))
|
|
4612
|
+
}
|
|
4613
|
+
|
|
4614
|
+
const saveDraft = () => {
|
|
4615
|
+
const scopes = Object.entries(entries)
|
|
4616
|
+
.filter(([, entry]) => entry && entry.enabled)
|
|
4617
|
+
.map(([scope, entry]) => ({ scope, kinds: [...entry.kinds] }))
|
|
4618
|
+
if (scopes.length === 0) { setError('至少选择一个可见范围'); return }
|
|
4619
|
+
save({ scopes, level })
|
|
4620
|
+
}
|
|
4621
|
+
|
|
4622
|
+
const scopes = data && Array.isArray(data.scopes) ? data.scopes : []
|
|
4623
|
+
const override = data && data.override && Array.isArray(data.override.scopes) ? data.override : null
|
|
4624
|
+
const hasOverride = override !== null
|
|
4625
|
+
const overrideCount = hasOverride ? override.scopes.length : 0
|
|
4626
|
+
const selectedCount = Object.values(entries).filter((entry) => entry && entry.enabled).length
|
|
4627
|
+
const kindsAll = allKindsOf(data)
|
|
4628
|
+
const needle = search.trim().toLowerCase()
|
|
4629
|
+
const visibleScopes = scopes.filter((item) => {
|
|
4630
|
+
if (!needle) return true
|
|
4631
|
+
return String(item.label || item.scope).toLowerCase().includes(needle) || String(item.scope).toLowerCase().includes(needle)
|
|
4632
|
+
})
|
|
4633
|
+
let popStyle = {}
|
|
4634
|
+
if (anchor) {
|
|
4635
|
+
const width = 360
|
|
4636
|
+
const margin = 8
|
|
4637
|
+
const viewportW = (typeof window !== 'undefined' && Number(window.innerWidth)) || 1024
|
|
4638
|
+
const viewportH = (typeof window !== 'undefined' && Number(window.innerHeight)) || 768
|
|
4639
|
+
popStyle = {
|
|
4640
|
+
left: Math.min(Math.max(margin, anchor.left), Math.max(margin, viewportW - width - margin)),
|
|
4641
|
+
bottom: Math.max(margin, viewportH - anchor.top + 8),
|
|
4642
|
+
}
|
|
4643
|
+
}
|
|
4644
|
+
|
|
4645
|
+
const levelMeta = [
|
|
4646
|
+
{ value: 'absolute', label: '绝对限制', hint: '范围外一律查不到' },
|
|
4647
|
+
{ value: 'normal', label: '普通限制', hint: '范围外需审批' },
|
|
4648
|
+
{ value: 'none', label: '无限制', hint: '不限制读取' },
|
|
4649
|
+
]
|
|
4650
|
+
|
|
4651
|
+
return h('span', { className: 'mem-scope-wrap', ref: wrapRef },
|
|
4652
|
+
h('button', {
|
|
4653
|
+
type: 'button',
|
|
4654
|
+
className: `mem-scope-btn${hasOverride ? ' on' : ''}`,
|
|
4655
|
+
title: '记忆可见域(本会话及子 Agent)',
|
|
4656
|
+
'aria-label': '记忆可见域',
|
|
4657
|
+
'aria-expanded': open,
|
|
4658
|
+
onMouseDown: (event) => { try { event.preventDefault() } catch { /* keepFocus */ } },
|
|
4659
|
+
onClick: toggle,
|
|
4660
|
+
},
|
|
4661
|
+
h(NavLineIcon, { size: 14 }),
|
|
4662
|
+
h('span', null, hasOverride ? `记忆可见域 ${overrideCount}` : '记忆范围'),
|
|
4663
|
+
),
|
|
4664
|
+
open ? h('div', { className: 'mem-scope-pop', style: popStyle, role: 'dialog', 'aria-label': '记忆可见域' },
|
|
4665
|
+
h('div', { className: 'mem-scope-head' },
|
|
4666
|
+
h('h4', null, '记忆可见域'),
|
|
4667
|
+
h('span', { className: 'spacer' }),
|
|
4668
|
+
h('span', { className: 'mem-scope-count' }, `已选 ${selectedCount}`),
|
|
4669
|
+
),
|
|
4670
|
+
h('div', { className: 'hint' },
|
|
4671
|
+
'Agent 默认只能检索和读取勾选的作用域与类型;限制等级决定范围外怎么处理。'),
|
|
4672
|
+
data && data.inherited
|
|
4673
|
+
? h('div', { className: 'hint' }, '当前继承自父会话;保存后在本会话独立生效。')
|
|
4674
|
+
: null,
|
|
4675
|
+
h('div', { className: 'mem-scope-level', role: 'radiogroup', 'aria-label': '限制等级' },
|
|
4676
|
+
levelMeta.map((item) => h('button', {
|
|
4677
|
+
key: item.value,
|
|
4678
|
+
type: 'button',
|
|
4679
|
+
role: 'radio',
|
|
4680
|
+
'aria-checked': level === item.value,
|
|
4681
|
+
className: `mem-scope-level-btn${level === item.value ? ' on' : ''}`,
|
|
4682
|
+
onClick: () => setLevel(item.value),
|
|
4683
|
+
title: item.hint,
|
|
4684
|
+
}, h('b', null, item.label), h('span', null, item.hint))),
|
|
4685
|
+
),
|
|
4686
|
+
level === 'none'
|
|
4687
|
+
? h('div', { className: 'mem-scope-note' }, '无限制:范围选择会保存,但暂不参与读取限制。')
|
|
4688
|
+
: null,
|
|
4689
|
+
h('div', { className: 'mem-scope-search' },
|
|
4690
|
+
h('input', {
|
|
4691
|
+
type: 'search',
|
|
4692
|
+
placeholder: '搜索作用域…',
|
|
4693
|
+
value: search,
|
|
4694
|
+
'aria-label': '搜索作用域',
|
|
4695
|
+
onChange: (event) => setSearch(event.target.value),
|
|
4696
|
+
}),
|
|
4697
|
+
h('button', { type: 'button', className: 'linkbtn', onClick: selectAll }, '全选'),
|
|
4698
|
+
h('button', { type: 'button', className: 'linkbtn', onClick: clearAll }, '取消全选'),
|
|
4699
|
+
),
|
|
4700
|
+
loading
|
|
4701
|
+
? h('div', { className: 'hint' }, '读取中…')
|
|
4702
|
+
: h('div', { className: 'mem-scope-list' },
|
|
4703
|
+
visibleScopes.length === 0
|
|
4704
|
+
? h('div', { className: 'hint' }, needle ? '没有匹配的作用域。' : '还没有可选的范围。')
|
|
4705
|
+
: visibleScopes.map((item) => {
|
|
4706
|
+
const entry = entries[item.scope] || { enabled: false, kinds: [...kindsAll] }
|
|
4707
|
+
const kindCounts = new Map()
|
|
4708
|
+
for (const kind of Array.isArray(item.kinds) ? item.kinds : []) {
|
|
4709
|
+
if (kind && typeof kind.kind === 'string') kindCounts.set(kind.kind, Number(kind.records) || 0)
|
|
4710
|
+
}
|
|
4711
|
+
return h('div', { className: `mem-scope-item${entry.enabled ? ' on' : ''}`, key: item.scope },
|
|
4712
|
+
h('div', { className: 'mem-scope-row' },
|
|
4713
|
+
h('button', {
|
|
4714
|
+
type: 'button',
|
|
4715
|
+
role: 'checkbox',
|
|
4716
|
+
'aria-checked': entry.enabled,
|
|
4717
|
+
className: `mem-scope-check${entry.enabled ? ' on' : ''}`,
|
|
4718
|
+
onClick: () => toggleScope(item.scope),
|
|
4719
|
+
'aria-label': entry.enabled ? '取消选择' : '选择',
|
|
4720
|
+
}, h('span', { className: 'box' }, entry.enabled ? h('svg', { width: 11, height: 11, viewBox: '0 0 12 12', 'aria-hidden': 'true' }, h('path', { d: 'M2 6.2 4.7 9 10 3.4', fill: 'none', stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round' })) : null)),
|
|
4721
|
+
h('button', {
|
|
4722
|
+
type: 'button',
|
|
4723
|
+
className: 'mem-scope-label',
|
|
4724
|
+
title: item.scope,
|
|
4725
|
+
onClick: () => toggleScope(item.scope),
|
|
4726
|
+
}, item.label || item.scope),
|
|
4727
|
+
h('span', { className: 'cnt' }, `${item.records ?? 0}`),
|
|
4728
|
+
),
|
|
4729
|
+
entry.enabled
|
|
4730
|
+
? h('div', { className: 'mem-kind-row' },
|
|
4731
|
+
h('button', {
|
|
4732
|
+
type: 'button',
|
|
4733
|
+
className: `mem-kind-chip${entry.kinds.length >= kindsAll.length ? ' on' : ''}`,
|
|
4734
|
+
onClick: () => setAllKinds(item.scope),
|
|
4735
|
+
title: '允许该作用域下所有类型',
|
|
4736
|
+
}, '全部'),
|
|
4737
|
+
kindsAll.map((kind) => {
|
|
4738
|
+
const on = entry.kinds.includes(kind)
|
|
4739
|
+
const label = kindMeta(kind).label
|
|
4740
|
+
const count = kindCounts.get(kind)
|
|
4741
|
+
return h('button', {
|
|
4742
|
+
key: kind,
|
|
4743
|
+
type: 'button',
|
|
4744
|
+
className: `mem-kind-chip${on ? ' on' : ''}`,
|
|
4745
|
+
'aria-pressed': on,
|
|
4746
|
+
onClick: () => toggleKind(item.scope, kind),
|
|
4747
|
+
title: `${label}${count === undefined ? '' : ` · ${count} 条`}`,
|
|
4748
|
+
}, label, count === undefined ? null : h('i', null, count))
|
|
4749
|
+
}),
|
|
4750
|
+
)
|
|
4751
|
+
: null,
|
|
4752
|
+
)
|
|
4753
|
+
}),
|
|
4754
|
+
),
|
|
4755
|
+
error ? h('div', { className: 'mem-scope-err' }, error) : null,
|
|
4756
|
+
h('div', { className: 'mem-scope-foot' },
|
|
4757
|
+
h('button', {
|
|
4758
|
+
type: 'button',
|
|
4759
|
+
className: 'mem-scope-reset',
|
|
4760
|
+
disabled: busy || !data || data.override === null,
|
|
4761
|
+
onClick: () => save(null),
|
|
4762
|
+
}, '恢复默认'),
|
|
4763
|
+
h('span', { className: 'spacer' }),
|
|
4764
|
+
h('button', {
|
|
4765
|
+
type: 'button',
|
|
4766
|
+
className: 'mem-scope-save',
|
|
4767
|
+
disabled: busy || selectedCount === 0,
|
|
4768
|
+
onClick: saveDraft,
|
|
4769
|
+
}, busy ? '保存中…' : '保存'),
|
|
4770
|
+
),
|
|
4771
|
+
) : null,
|
|
4772
|
+
)
|
|
4773
|
+
}
|
|
4774
|
+
/**
|
|
4775
|
+
* 普通限制下的「范围外记忆访问审批」浮层。
|
|
4776
|
+
*
|
|
4777
|
+
* 工具在 memory_search / memory_get / memory_list 命中可见域外的记录时会在
|
|
4778
|
+
* provider 里挂起一个 Promise,这里轮询 /memory/api/approvals 把它显示给用户。
|
|
4779
|
+
* 用户点「拒绝 / 允许一次」→ POST /memory/api/approvals → 工具拿到结果继续。
|
|
4780
|
+
*
|
|
4781
|
+
* 视觉沿用审计详情里的 hover 浮窗(.audit-tip / .audit-id / .audit-pill):
|
|
4782
|
+
* 把根节点标成 .memp,这些样式就会按同一套 token 生效。
|
|
4783
|
+
*/
|
|
4784
|
+
function MemoryApprovalOverlay() {
|
|
4785
|
+
const [approvals, setApprovals] = React.useState([])
|
|
4786
|
+
const [busy, setBusy] = React.useState('')
|
|
4787
|
+
const [error, setError] = React.useState('')
|
|
4788
|
+
const [tip, setTip] = React.useState(null)
|
|
4789
|
+
const tipTimer = React.useRef(null)
|
|
4790
|
+
const hideTimer = React.useRef(null)
|
|
4791
|
+
const activeRef = React.useRef(true)
|
|
4792
|
+
|
|
4793
|
+
const clearTimers = () => {
|
|
4794
|
+
if (tipTimer.current !== null) { clearTimeout(tipTimer.current); tipTimer.current = null }
|
|
4795
|
+
if (hideTimer.current !== null) { clearTimeout(hideTimer.current); hideTimer.current = null }
|
|
4796
|
+
}
|
|
4797
|
+
|
|
4798
|
+
React.useEffect(() => {
|
|
4799
|
+
activeRef.current = true
|
|
4800
|
+
return () => {
|
|
4801
|
+
activeRef.current = false
|
|
4802
|
+
clearTimers()
|
|
4803
|
+
}
|
|
4804
|
+
}, [])
|
|
4805
|
+
|
|
4806
|
+
const refresh = () => {
|
|
4807
|
+
api('approvals')
|
|
4808
|
+
.then((value) => {
|
|
4809
|
+
if (!activeRef.current) return
|
|
4810
|
+
setApprovals(Array.isArray(value.approvals) ? value.approvals : [])
|
|
4811
|
+
})
|
|
4812
|
+
.catch(() => { /* 轮询失败静默重试 */ })
|
|
4813
|
+
}
|
|
4814
|
+
|
|
4815
|
+
React.useEffect(() => {
|
|
4816
|
+
refresh()
|
|
4817
|
+
if (typeof setInterval !== 'function') return undefined
|
|
4818
|
+
const timer = setInterval(() => {
|
|
4819
|
+
if (typeof document !== 'undefined' && document.hidden) return
|
|
4820
|
+
refresh()
|
|
4821
|
+
}, 1500)
|
|
4822
|
+
return () => clearInterval(timer)
|
|
4823
|
+
}, [])
|
|
4824
|
+
|
|
4825
|
+
const answer = (id, outcome) => {
|
|
4826
|
+
setBusy(id)
|
|
4827
|
+
setError('')
|
|
4828
|
+
api('approvals', { id, outcome })
|
|
4829
|
+
.then(() => {
|
|
4830
|
+
setApprovals((prev) => prev.filter((item) => item.id !== id))
|
|
4831
|
+
hideTip()
|
|
4832
|
+
})
|
|
4833
|
+
.catch((e) => setError(String((e && e.message) || e)))
|
|
4834
|
+
.finally(() => setBusy(''))
|
|
4835
|
+
}
|
|
4836
|
+
|
|
4837
|
+
const hideTip = () => { clearTimers(); setTip(null) }
|
|
4838
|
+
const cancelHideTip = () => {
|
|
4839
|
+
if (hideTimer.current !== null) { clearTimeout(hideTimer.current); hideTimer.current = null }
|
|
4840
|
+
}
|
|
4841
|
+
const scheduleHideTip = () => {
|
|
4842
|
+
if (tipTimer.current !== null) { clearTimeout(tipTimer.current); tipTimer.current = null }
|
|
4843
|
+
cancelHideTip()
|
|
4844
|
+
hideTimer.current = setTimeout(() => { hideTimer.current = null; setTip(null) }, 220)
|
|
4845
|
+
}
|
|
4846
|
+
const positionFor = (element) => {
|
|
4847
|
+
const width = typeof window !== 'undefined' ? window.innerWidth : 1200
|
|
4848
|
+
const height = typeof window !== 'undefined' ? window.innerHeight : 800
|
|
4849
|
+
const rect = element && typeof element.getBoundingClientRect === 'function' ? element.getBoundingClientRect() : null
|
|
4850
|
+
if (rect === null) return { x: 12, y: 12 }
|
|
4851
|
+
const tipWidth = Math.min(380, width - 24)
|
|
4852
|
+
const tipHeight = 260
|
|
4853
|
+
const x = Math.max(12, Math.min(rect.left, width - tipWidth - 12))
|
|
4854
|
+
let y = rect.bottom + 8
|
|
4855
|
+
if (y + tipHeight > height - 12) y = Math.max(12, rect.top - tipHeight - 8)
|
|
4856
|
+
return { x, y }
|
|
4857
|
+
}
|
|
4858
|
+
const fetchRecord = (id) => {
|
|
4859
|
+
api(`records?id=${encodeURIComponent(id)}`)
|
|
4860
|
+
.then((value) => {
|
|
4861
|
+
const record = Array.isArray(value.records) ? value.records[0] : undefined
|
|
4862
|
+
if (!record || !activeRef.current) return
|
|
4863
|
+
setTip((prev) => prev !== null && prev.item && prev.item.id === id
|
|
4864
|
+
? { ...prev, item: { ...prev.item, content: record.content, tags: Array.isArray(record.tags) ? record.tags : prev.item.tags, scope: record.scope, kind: record.kind, importance: record.importance } }
|
|
4865
|
+
: prev)
|
|
4866
|
+
})
|
|
4867
|
+
.catch(() => { /* 悬浮详情是增强,失败就展示轮询里的摘要 */ })
|
|
4868
|
+
}
|
|
4869
|
+
const showTip = (item, element) => {
|
|
4870
|
+
clearTimers()
|
|
4871
|
+
tipTimer.current = setTimeout(() => {
|
|
4872
|
+
tipTimer.current = null
|
|
4873
|
+
setTip({ item, ...positionFor(element) })
|
|
4874
|
+
fetchRecord(item.id)
|
|
4875
|
+
}, 350)
|
|
4876
|
+
}
|
|
4877
|
+
|
|
4878
|
+
const pending = approvals.length > 0 ? approvals[0] : null
|
|
4879
|
+
const tipNode = tip === null ? null : (() => {
|
|
4880
|
+
const item = tip.item || {}
|
|
4881
|
+
return h('div', { className: 'audit-tip', style: { left: tip.x, top: tip.y }, onMouseEnter: cancelHideTip, onMouseLeave: hideTip, onClick: () => openMemoryRecordPanel(item.id, item.scope, item) },
|
|
4882
|
+
h('div', { className: 'audit-tip-head' }, h('span', null, '记忆'), h('span', { className: 'audit-tip-title' }, item.id || '未知')),
|
|
4883
|
+
h('div', { className: 'audit-tip-meta' },
|
|
4884
|
+
auditPill(item.kind ? kindMeta(item.kind).label : '未知', 'mute'),
|
|
4885
|
+
auditPill(item.scope || '', 'mute'),
|
|
4886
|
+
auditPill(`重要度 ${Number(item.importance ?? 0).toFixed(2)}`, 'mute'),
|
|
4887
|
+
),
|
|
4888
|
+
item.tags && item.tags.length > 0
|
|
4889
|
+
? h('div', { className: 'audit-flat' }, item.tags.map((tag) => h('span', { className: 'tag', key: tag }, tag)))
|
|
4890
|
+
: null,
|
|
4891
|
+
h('div', { className: 'audit-tip-content' }, String(item.content || '')),
|
|
4892
|
+
h('div', { className: 'audit-tip-foot' }, '点击跳转到「记录」页并展开'),
|
|
4893
|
+
)
|
|
4894
|
+
})()
|
|
4895
|
+
|
|
4896
|
+
if (pending === null) return null
|
|
4897
|
+
|
|
4898
|
+
return h('div', { className: 'memp mem-approval' },
|
|
4899
|
+
h('div', { className: 'mem-approval-card', role: 'dialog', 'aria-label': '记忆访问审批' },
|
|
4900
|
+
h('div', { className: 'mem-approval-head' },
|
|
4901
|
+
h('span', { className: 'mem-approval-dot' }),
|
|
4902
|
+
h('b', null, '记忆访问审批'),
|
|
4903
|
+
h('span', { className: 'muted' }, pending.tool || 'memory'),
|
|
4904
|
+
h('span', { className: 'spacer' }),
|
|
4905
|
+
approvals.length > 1 ? h('span', { className: 'muted' }, `还有 ${approvals.length - 1} 个待审批`) : null,
|
|
4906
|
+
),
|
|
4907
|
+
h('div', { className: 'mem-approval-query' }, `Agent 查询:${pending.query || '(未提供)'}`),
|
|
4908
|
+
h('div', { className: 'hint' }, '以下记忆不在本会话的可见域内。允许一次只对本次调用生效,拒绝则工具拿不到这些内容。'),
|
|
4909
|
+
h('div', { className: 'mem-approval-list' },
|
|
4910
|
+
pending.items.map((item) => h('div', { className: 'mem-approval-item', key: item.id },
|
|
4911
|
+
h('div', { className: 'mem-approval-row' },
|
|
4912
|
+
h('button', {
|
|
4913
|
+
type: 'button',
|
|
4914
|
+
className: 'audit-id',
|
|
4915
|
+
'aria-label': item.id,
|
|
4916
|
+
onMouseEnter: (event) => showTip(item, event.currentTarget),
|
|
4917
|
+
onMouseLeave: scheduleHideTip,
|
|
4918
|
+
onClick: () => openMemoryRecordPanel(item.id, item.scope, item),
|
|
4919
|
+
}, String(item.id).length > 12 ? `${item.id.slice(0, 8)}…${item.id.slice(-4)}` : item.id),
|
|
4920
|
+
h('span', { className: 'audit-pill mute' }, item.scope),
|
|
4921
|
+
h('span', { className: 'audit-pill mute' }, item.kind ? kindMeta(item.kind).label : '未知'),
|
|
4922
|
+
item.reason === 'kind'
|
|
4923
|
+
? h('span', { className: 'audit-pill warn' }, '类型受限')
|
|
4924
|
+
: h('span', { className: 'audit-pill warn' }, '范围外'),
|
|
4925
|
+
),
|
|
4926
|
+
h('div', { className: 'mem-approval-summary' }, String(item.content || '').replace(/\s+/g, ' ').slice(0, 180)),
|
|
4927
|
+
)),
|
|
4928
|
+
),
|
|
4929
|
+
error ? h('div', { className: 'mem-scope-err' }, error) : null,
|
|
4930
|
+
h('div', { className: 'mem-approval-foot' },
|
|
4931
|
+
h('button', {
|
|
4932
|
+
type: 'button',
|
|
4933
|
+
className: 'mem-scope-reset',
|
|
4934
|
+
disabled: busy === pending.id,
|
|
4935
|
+
onClick: () => answer(pending.id, 'rejected'),
|
|
4936
|
+
}, '拒绝'),
|
|
4937
|
+
h('span', { className: 'spacer' }),
|
|
4938
|
+
h('button', {
|
|
4939
|
+
type: 'button',
|
|
4940
|
+
className: 'mem-scope-save',
|
|
4941
|
+
disabled: busy === pending.id,
|
|
4942
|
+
onClick: () => answer(pending.id, 'allowed-once'),
|
|
4943
|
+
}, busy === pending.id ? '处理中…' : '允许一次'),
|
|
4944
|
+
),
|
|
4945
|
+
),
|
|
4946
|
+
tipNode,
|
|
4947
|
+
)
|
|
4948
|
+
}
|
|
4949
|
+
|
|
4314
4950
|
function apply(ctx) {
|
|
4315
4951
|
try {
|
|
4316
4952
|
const styleEl = document.createElement('style')
|
|
@@ -4414,6 +5050,18 @@ window.__ModuleLoader__.load({
|
|
|
4414
5050
|
} catch (error) {
|
|
4415
5051
|
console.warn('[dsh-memory] 记忆审计视图注册失败:', error?.message)
|
|
4416
5052
|
}
|
|
5053
|
+
// 输入框工具行右侧:本会话「记忆可见范围」按钮。session 作用域的 list 槽,
|
|
5054
|
+
// owner 会把 sessionId 作为标准 prop 传进来;旧宿主没有这个槽时只少一个入口。
|
|
5055
|
+
try {
|
|
5056
|
+
slots.inject('conversation.input.right', () => slots.register({
|
|
5057
|
+
name: 'conversation.input.right',
|
|
5058
|
+
id: 'memory-visibility',
|
|
5059
|
+
order: 30,
|
|
5060
|
+
label: () => '记忆可见域',
|
|
5061
|
+
}, MemoryVisibilityButton))
|
|
5062
|
+
} catch (error) {
|
|
5063
|
+
console.warn('[dsh-memory] 记忆可见范围按钮注册失败:', error?.message)
|
|
5064
|
+
}
|
|
4417
5065
|
try {
|
|
4418
5066
|
slots.inject('shell.overlay', () => slots.register({
|
|
4419
5067
|
name: 'shell.overlay',
|
|
@@ -4441,6 +5089,16 @@ window.__ModuleLoader__.load({
|
|
|
4441
5089
|
} catch (error) {
|
|
4442
5090
|
console.warn('[dsh-memory] 轨迹详情记忆页签注册失败:', error?.message)
|
|
4443
5091
|
}
|
|
5092
|
+
// 普通限制下的范围外访问审批浮层:全局 fixed,自己轮询待审批。
|
|
5093
|
+
try {
|
|
5094
|
+
slots.inject('shell.overlay', () => slots.register({
|
|
5095
|
+
name: 'shell.overlay',
|
|
5096
|
+
id: 'memory-access-approval',
|
|
5097
|
+
order: 62,
|
|
5098
|
+
}, () => React.createElement(MemoryApprovalOverlay)))
|
|
5099
|
+
} catch (error) {
|
|
5100
|
+
console.warn('[dsh-memory] 记忆访问审批浮层注册失败:', error?.message)
|
|
5101
|
+
}
|
|
4444
5102
|
} catch (error) {
|
|
4445
5103
|
console.error('[dsh-memory] client apply 失败(已吞掉):', error?.message)
|
|
4446
5104
|
}
|
|
@@ -4558,6 +5216,11 @@ window.__ModuleLoader__.load({
|
|
|
4558
5216
|
MemoryTreeTab: MemoryTreeTab,
|
|
4559
5217
|
SettingsTab: SettingsTab,
|
|
4560
5218
|
AuditTab: AuditTab,
|
|
5219
|
+
MemoryVisibilityButton: MemoryVisibilityButton,
|
|
5220
|
+
MemoryApprovalOverlay: MemoryApprovalOverlay,
|
|
5221
|
+
openMemoryRecordPanel: openMemoryRecordPanel,
|
|
5222
|
+
requestRecordFocus: requestRecordFocus,
|
|
5223
|
+
takeRecordFocus: takeRecordFocus,
|
|
4561
5224
|
buildMemoryTree: buildMemoryTree,
|
|
4562
5225
|
KIND_META: KIND_META,
|
|
4563
5226
|
CSS: CSS,
|