@restregular/dsh-memory 0.25.3 → 0.25.5
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 +14 -0
- package/README.md +2 -2
- package/lib/client.js +88 -33
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
本项目的版本记录。安装 id 与 npm 版本一一对应。
|
|
4
4
|
|
|
5
|
+
## 0.25.5 — AI 授权行用自己的样式;按钮数字与「已选」都把授权算进去
|
|
6
|
+
|
|
7
|
+
- **视觉区分**:AI 授权勾上的行不再套用用户选中行的实心蓝底 + 蓝边 —— 行用虚线边框 + 中性底色(`.mem-scope-item.ai`),勾选框用虚线描边、透明底、蓝色对勾(`.mem-scope-check.on.ai .box`),一眼能看出「这条是 AI 申请来的」而不是你自己勾的。
|
|
8
|
+
- **计数口径**:输入框按钮上的数字改为「可见范围 ∪ AI 授权」的作用域数(`accessibleCount`),按钮 `title` 同步;弹窗头部「已选」也改成当前勾选数(含 AI 授权,标「待撤销」的不算)。上一版把 AI 授权排除在计数外,和实际可读作用域不一致。
|
|
9
|
+
- 测试:用例断言有 AI 授权时按钮数字为 2、已选为 2、AI 行带 `ai` class;新增 CSS 断言(虚线边框 / 中性底 / 描边勾选框)。全套 494 tests / 493 pass / 1 skipped。
|
|
10
|
+
|
|
11
|
+
## 0.25.4 — 授权撤销与列表重排都改到「保存」之后;已选计数只算可见范围
|
|
12
|
+
|
|
13
|
+
- **取消勾选只是草稿**:勾选 AI 授权的行后取消勾选,不再立刻调用 `POST /memory/api/grants`;改成标记「AI·待撤销」气泡,点「保存」时才先撤销授权、再保存可见范围。再勾回去会恢复原状。
|
|
14
|
+
- **保存后才重排**:列表的「已勾选在上」按**保存过的状态**排序,草稿勾选 / 取消勾选期间顺序不动,保存后(重开面板)才按新状态重排。
|
|
15
|
+
- **计数口径**:面板头部的「已选」只统计你自己勾选的可见范围(与输入框按钮的范围数字同口径),AI 授权不算进去;授权只以勾选 + 气泡体现。
|
|
16
|
+
- **取消全选**:把可撤销的授权标记为待撤销,不立即撤销;继承自父会话的授权给出提示。
|
|
17
|
+
- 测试:改写两个面板用例——取消勾选不触发 `/grants`、气泡变「AI·待撤销」、顺序与计数不变;点保存后才 `POST /grants` + `POST /visibility`,且重开后按新状态重排;全套 494 tests / 493 pass / 1 skipped。
|
|
18
|
+
|
|
5
19
|
## 0.25.3 — Agent 授权改用「勾选 + AI 气泡」呈现,取消勾选即撤销
|
|
6
20
|
|
|
7
21
|
- **授权结果 = 勾选**:作用域被 Agent 申请并审批通过后,该作用域直接显示为**已勾选**(即使它不在你设置的可见范围内),列表里同样排在已勾选分组。浮窗打开期间每 3 秒刷新授权,Agent 刚拿到的权限不用重开面板就能看到。
|
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ JSONL 落盘 · 本机向量检索 · 五个模型工具 · 自动召回 · 硬
|
|
|
47
47
|
| **自动召回** | 每轮按用户问题召回;新会话第一步注入项目 / global 摘要;发布、部署、工具失败等行为按标签触发定向召回 |
|
|
48
48
|
| **印象形态** | 每轮只给每条记忆的短摘要;模型判断相关但需要细节时再 `memory_get` 取全文,省 token 也不丢信息 |
|
|
49
49
|
| **硬性规则** | `kind: rule` 进系统提示常驻段;行首带 8 位 id,注入的是摘要,需要全文时用 `memory_get`;旧会话会收到新增 / 编辑提醒;超预算有明确警告,不静默丢弃 |
|
|
50
|
-
| **记忆权限** | 输入框旁的「记忆权限」按钮设置本会话可读的作用域 + 限制等级(绝对 / 普通 / 无限制);每个作用域一行就是一条设置:**勾选**表示本会话可访问,行内**【绑定】/【可读】/【可写】**控制工作区默认可见与读写权限——绑定到当前工作区后新会话默认可见,可读 / 可写独立影响工具读写;Agent 通过 `memory_scopes request` 申请到的范围外授权**也用勾选呈现**(名称右边挂一个「AI
|
|
50
|
+
| **记忆权限** | 输入框旁的「记忆权限」按钮设置本会话可读的作用域 + 限制等级(绝对 / 普通 / 无限制);每个作用域一行就是一条设置:**勾选**表示本会话可访问,行内**【绑定】/【可读】/【可写】**控制工作区默认可见与读写权限——绑定到当前工作区后新会话默认可见,可读 / 可写独立影响工具读写;Agent 通过 `memory_scopes request` 申请到的范围外授权**也用勾选呈现**(名称右边挂一个「AI」气泡,样式与你自己勾选的行区分开),取消勾选只是草稿,**点「保存」才真正撤销**(0.25.4 起),且按钮数字 / 「已选」都把 AI 授权算进去(0.25.5 起);Agent 及其子 Agent 都按它检索、注入与 `memory_get` |
|
|
51
51
|
| **修正版编辑** | 面板里编辑一条记忆 = 新建一条修正版并通过 `supersedes` 指向旧记录,旧记录不原地修改;记录页「是否被修正」筛选默认隐藏旧版本,可切到全部 / 只看已修正 |
|
|
52
52
|
| **范围外审批** | 普通限制下,工具命中可见域外的记忆时会在**对应会话的输入框上方**出现审批卡(样式与系统权限审批一致):展示工具、Agent 说明、查询关键词与范围外记忆摘要,支持逐条勾选 / 全选 / 取消全选(「允许选中的 N 条」或整单「允许一次」)或「拒绝」;点记忆 ID 直接跳到面板「记录」页并展开该条 |
|
|
53
53
|
| **上下文去重** | `memory_search` / `memory_list` 返回过的条目记进会话上下文状态;同一版本再次命中只回记忆 ID(`memory_search` 的裸 ID 与带摘要条目之间空一行),并提示用 `memory_get` 取全文(内容更新后重新给摘要) |
|
|
@@ -97,7 +97,7 @@ JSONL 落盘 · 本机向量检索 · 五个模型工具 · 自动召回 · 硬
|
|
|
97
97
|
- **绝对限制**:可见域外的读取 / 写入 / 删除一律不执行;命中被挡住时会明确告诉 Agent 是「绝对限制」以及怎么调整(不再假装记忆不存在)。
|
|
98
98
|
- **普通限制**(默认):可见域内正常返回;命中范围外记忆时,工具会暂停并在**该会话**的输入框上方显示审批卡,展示 Agent 的查询关键词与范围外记忆摘要;读审批可以逐条勾选,只允许其中一条或多条。用户拒绝 / 5 分钟未回答时,工具结果里会明确写出真实原因(「用户拒绝了本次访问」/「审批超时」),模型不会误以为记忆不存在。范围外写入 / 删除同样走审批。
|
|
99
99
|
- **无限制**:不启用范围白名单,可以读写任意作用域(选择仍会保存,供下次切换)。
|
|
100
|
-
- **Agent 授权 = 勾选 + 「AI」气泡(0.25.3)**:作用域行就是「勾选该作用域 + 【绑定】/【可读】/【可写】」这一组控件,不再有独立的「Agent 授权」行与浮窗上方的解释文本。Agent 通过 `memory_scopes request`
|
|
100
|
+
- **Agent 授权 = 勾选 + 「AI」气泡(0.25.3 – 0.25.5)**:作用域行就是「勾选该作用域 + 【绑定】/【可读】/【可写】」这一组控件,不再有独立的「Agent 授权」行与浮窗上方的解释文本。Agent 通过 `memory_scopes request` 审批得到的授权直接体现为该作用域的**勾选**,名称右边挂「AI」气泡(`title` 写明只读 / 可写);**AI 授权的行用自己的样式**——虚线边框 + 中性底色,勾选框是虚线描边(透明底、蓝勾),不会和你自己勾选的实心蓝底行混淆。**取消勾选只是草稿**——气泡改标「AI·待撤销」,**点「保存」才真正撤销**(保存时先 `POST /grants` 撤销,再保存可见范围),Agent 下一次 pre-step 收到「记忆权限已更新」。**计数**:输入框按钮上的数字与弹窗头部「已选」都是「可见范围 ∪ AI 授权」的作用域数,AI 授权算进去。继承自父会话的授权标「AI·继承」,本会话取消勾选会被拒绝并提示到父会话操作;「取消全选」只是把可撤销的授权标记为待撤销。目录里已不可见的作用域仍占一行(标「目录中已不可见」)。列表里**已勾选(按保存过的状态)的排在上面、未勾选的排在下面**,组内按名称字母排序;**保存后才按新状态重排**。
|
|
101
101
|
- **不再按记忆类型收窄**:0.19.1 起只按作用域限制;旧配置里的 `kinds` 会被忽略,同一作用域下的事实 / 规则 / 流程等都可读。
|
|
102
102
|
- **审批卡(0.21.0 / 0.22.x)**:注册在会话内的 `conversation.input.dock`,**只在发起审批的那个会话里显示**,切到别的会话看不到;视觉与系统自带的权限审批弹窗一致(警告色 strip、卡片、右对齐动作行,同一批主题 token)。按动作分为「记忆读取 / 写入 / 删除审批」。读审批默认全部勾选:可逐条取消、用「全选 / 取消全选」批量操作,**点条目任意位置即可切换选中**,再点「允许选中的 N 条」,工具只放行勾选的 id、其余写入 `withheld.reason='partial'`;全选时等价于原来的「允许一次」。strip 右侧可**折叠 / 展开**详情,折叠后仍保留「拒绝 / 允许」动作。写 / 删审批是单条,隐藏勾选框。**0.22.0 起**卡片展示工具调用的 `description`(普通限制下工具层强制模型提供),点记忆 ID 会打开记忆面板的「记录」标签页、选中并滚动到该条、自动展开;**0.22.2 起**查询与说明固定显示在条目列表上方,条目再多也不会被列表挤没(两行锁 `flex:none`,只有列表滚动);**0.22.3 起**审批卡高度只受 composer 文本区上限约束(与宿主审批卡同口径),矮窗口下列表也有空间。拒绝、超时或无法发起审批都会把原因告诉模型。Enter = 允许、Esc = 拒绝(焦点在卡片内时)。
|
|
103
103
|
- 子 Agent 自动继承父会话 / 根会话的设置;在子 Agent 自己的会话里再设置,只影响那一个会话。
|
package/lib/client.js
CHANGED
|
@@ -522,10 +522,16 @@ window.__ModuleLoader__.load({
|
|
|
522
522
|
'.mem-scope-item{display:flex;flex-direction:column;gap:4px;padding:5px 6px;border:1px solid transparent;border-radius:10px}',
|
|
523
523
|
'.mem-scope-item:hover{background:var(--dsw-alias-interactive-bg-hover)}',
|
|
524
524
|
'.mem-scope-item.on{border-color:color-mix(in srgb,var(--dsw-alias-state-business-primary) 38%,var(--dsw-alias-border-l1));background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 8%,transparent)}',
|
|
525
|
+
// 0.25.5:AI 授权的勾选与用户自己勾选要能一眼分开 —— 行用虚线边框 + 中性底,
|
|
526
|
+
// 勾选框用描边(虚线、透明底、蓝勾),不再套用用户选中的实心蓝底。
|
|
527
|
+
'.mem-scope-item.ai{border-style:dashed;border-color:color-mix(in srgb,var(--dsw-alias-state-business-primary,#4176e6) 32%,var(--dsw-alias-border-l1));background:color-mix(in srgb,var(--dsw-alias-label-primary) 3%,transparent)}',
|
|
528
|
+
'.mem-scope-item.ai:hover{background:var(--dsw-alias-interactive-bg-hover)}',
|
|
529
|
+
'.mem-scope-check.ai .box{background:transparent}',
|
|
525
530
|
'.mem-scope-row{display:flex;align-items:center;gap:8px}',
|
|
526
531
|
'.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}',
|
|
527
532
|
'.mem-scope-check .box{display:flex;align-items:center;justify-content:center;width:16px;height:16px;border:1.5px solid color-mix(in srgb,var(--dsw-alias-label-secondary) 52%,var(--dsw-alias-border-l1));border-radius:5px;background:color-mix(in srgb,var(--dsw-alias-label-primary) 5%,transparent);color:var(--dsw-alias-label-primary-foreground);transition:background .12s ease,border-color .12s ease}',
|
|
528
533
|
'.mem-scope-check.on .box{background:var(--dsw-alias-state-business-primary);border-color:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-label-primary-foreground)}',
|
|
534
|
+
'.mem-scope-check.on.ai .box{background:transparent;border-style:dashed;border-color:color-mix(in srgb,var(--dsw-alias-state-business-primary,#4176e6) 72%,var(--dsw-alias-border-l1));color:var(--dsw-alias-state-business-primary,#4176e6)}',
|
|
529
535
|
'.mem-scope-check:focus-visible{outline:1px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}',
|
|
530
536
|
'.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}',
|
|
531
537
|
'.mem-scope-label:hover{color:var(--dsw-alias-brand-primary);border:none}',
|
|
@@ -543,6 +549,7 @@ window.__ModuleLoader__.load({
|
|
|
543
549
|
// 0.25.3:Agent 授权用「勾选 + AI 气泡」呈现,气泡挂在作用域名称右边。
|
|
544
550
|
'.mem-scope-ai{flex:none;font-size:9.5px;line-height:1.7;padding:0 6px;border-radius:999px;border:1px solid color-mix(in srgb,var(--dsw-alias-state-business-primary,#4176e6) 45%,var(--dsw-alias-border-l1));background:color-mix(in srgb,var(--dsw-alias-state-business-primary,#4176e6) 12%,transparent);color:color-mix(in srgb,var(--dsw-alias-state-business-primary,#4176e6) 78%,var(--dsw-alias-label-primary));white-space:nowrap;cursor:help}',
|
|
545
551
|
'.mem-scope-ai.inherited{border-style:dashed;background:transparent;color:var(--dsw-alias-label-secondary)}',
|
|
552
|
+
'.mem-scope-ai.pending{opacity:.62;border-style:dashed;text-decoration:line-through}',
|
|
546
553
|
'.mem-scope-foot{display:flex;align-items:center;gap:8px}',
|
|
547
554
|
'.mem-scope-foot .spacer{flex:1}',
|
|
548
555
|
'.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}',
|
|
@@ -4574,6 +4581,8 @@ window.__ModuleLoader__.load({
|
|
|
4574
4581
|
const [data, setData] = React.useState(null)
|
|
4575
4582
|
const [level, setLevel] = React.useState('normal')
|
|
4576
4583
|
const [entries, setEntries] = React.useState({})
|
|
4584
|
+
const [savedEntries, setSavedEntries] = React.useState({})
|
|
4585
|
+
const [pendingRevoke, setPendingRevoke] = React.useState({})
|
|
4577
4586
|
const [perms, setPerms] = React.useState({})
|
|
4578
4587
|
const [bound, setBound] = React.useState({})
|
|
4579
4588
|
const [defaultBound, setDefaultBound] = React.useState({})
|
|
@@ -4679,6 +4688,8 @@ window.__ModuleLoader__.load({
|
|
|
4679
4688
|
}
|
|
4680
4689
|
setCatalog(nextCatalog)
|
|
4681
4690
|
setEntries(nextEntries)
|
|
4691
|
+
// 保存过的勾选基线:排序与「已选」都以它为准,草稿改动不立刻重排。
|
|
4692
|
+
setSavedEntries({ ...nextEntries })
|
|
4682
4693
|
setPerms(nextPerms)
|
|
4683
4694
|
setBound(nextBound)
|
|
4684
4695
|
setDefaultBound(nextDefaultBound)
|
|
@@ -4754,20 +4765,30 @@ window.__ModuleLoader__.load({
|
|
|
4754
4765
|
.finally(() => setGrantBusy(''))
|
|
4755
4766
|
}
|
|
4756
4767
|
|
|
4768
|
+
/**
|
|
4769
|
+
* 勾选 / 取消勾选作用域 —— 都是草稿状态,点「保存」才生效。
|
|
4770
|
+
* 取消勾选一条 AI 授权的行 = 标记为「待撤销」,保存时才真正撤销授权。
|
|
4771
|
+
*/
|
|
4757
4772
|
const toggleScope = (scope) => {
|
|
4758
4773
|
const grant = grantsByScope.get(scope)
|
|
4759
4774
|
if (!grant) {
|
|
4760
4775
|
setEntries((prev) => ({ ...prev, [scope]: !prev[scope] }))
|
|
4761
4776
|
return
|
|
4762
4777
|
}
|
|
4763
|
-
// 勾选里有 Agent 授权:取消勾选 = 撤销授权(撤销后「AI」气泡一起消失)。
|
|
4764
4778
|
if (grant.inherited === true) {
|
|
4765
4779
|
setEntries((prev) => ({ ...prev, [scope]: true }))
|
|
4766
4780
|
setGrantError('继承自父会话的授权需要到父会话撤销')
|
|
4767
4781
|
return
|
|
4768
4782
|
}
|
|
4769
|
-
|
|
4770
|
-
|
|
4783
|
+
const pending = Boolean(pendingRevoke[scope])
|
|
4784
|
+
setPendingRevoke((prev) => {
|
|
4785
|
+
const next = { ...prev }
|
|
4786
|
+
if (pending) delete next[scope]
|
|
4787
|
+
else next[scope] = true
|
|
4788
|
+
return next
|
|
4789
|
+
})
|
|
4790
|
+
// 取消勾选先清掉草稿里的范围勾选;再勾回来时恢复到保存时的勾选状态。
|
|
4791
|
+
setEntries((prev) => ({ ...prev, [scope]: pending ? Boolean(savedEntries[scope]) : false }))
|
|
4771
4792
|
}
|
|
4772
4793
|
|
|
4773
4794
|
/** 切换某个作用域的可读 / 可写状态(会话级)。 */
|
|
@@ -4789,6 +4810,8 @@ window.__ModuleLoader__.load({
|
|
|
4789
4810
|
for (const key of Object.keys(next)) next[key] = true
|
|
4790
4811
|
return next
|
|
4791
4812
|
})
|
|
4813
|
+
// 全选 = 不再撤销任何授权(草稿里取消的重新勾回来)。
|
|
4814
|
+
setPendingRevoke({})
|
|
4792
4815
|
}
|
|
4793
4816
|
|
|
4794
4817
|
const clearAll = () => {
|
|
@@ -4797,29 +4820,36 @@ window.__ModuleLoader__.load({
|
|
|
4797
4820
|
for (const key of Object.keys(next)) next[key] = false
|
|
4798
4821
|
return next
|
|
4799
4822
|
})
|
|
4800
|
-
//
|
|
4823
|
+
// 取消全选也是草稿:AI 授权只标记「待撤销」,点保存才真正撤销;
|
|
4801
4824
|
// 继承自父会话的授权撤销不了,只提示去父会话操作。
|
|
4825
|
+
const next = {}
|
|
4802
4826
|
let inherited = 0
|
|
4803
|
-
let chain = Promise.resolve()
|
|
4804
4827
|
for (const grant of Array.isArray(grants) ? grants : []) {
|
|
4805
4828
|
if (!grant || typeof grant.scope !== 'string' || grant.scope === '') continue
|
|
4806
4829
|
if (grant.inherited === true) { inherited += 1; continue }
|
|
4807
|
-
|
|
4830
|
+
next[grant.scope] = true
|
|
4808
4831
|
}
|
|
4832
|
+
setPendingRevoke(next)
|
|
4809
4833
|
if (inherited > 0) setGrantError('继承自父会话的授权需要到父会话撤销')
|
|
4810
|
-
chain.catch(() => { /* revokeGrant 自己会记录错误 */ })
|
|
4811
4834
|
}
|
|
4812
4835
|
|
|
4813
|
-
const save = (config) => {
|
|
4836
|
+
const save = (config, revokeFirst) => {
|
|
4814
4837
|
setBusy(true)
|
|
4815
4838
|
setError('')
|
|
4816
4839
|
// 只提交**额外**绑定:默认范围自带的会话 / 项目 / global 不需要也不允许写入。
|
|
4817
4840
|
const bindings = catalog
|
|
4818
4841
|
.filter((item) => bound[item.scope] && !defaultBound[item.scope] && !String(item.scope).startsWith('session:'))
|
|
4819
4842
|
.map((item) => item.scope)
|
|
4820
|
-
|
|
4843
|
+
// 保存时先撤销草稿里取消勾选的 AI 授权,再写可见范围。
|
|
4844
|
+
let chain = Promise.resolve()
|
|
4845
|
+
for (const grant of Array.isArray(revokeFirst) ? revokeFirst : []) {
|
|
4846
|
+
chain = chain.then(() => revokeGrant(grant))
|
|
4847
|
+
}
|
|
4848
|
+
chain
|
|
4849
|
+
.then(() => api('visibility', { session: sessionId, visibility: config, bindings }))
|
|
4821
4850
|
.then((value) => {
|
|
4822
4851
|
applyPayload(value)
|
|
4852
|
+
setPendingRevoke({})
|
|
4823
4853
|
setOpen(false)
|
|
4824
4854
|
})
|
|
4825
4855
|
.catch((e) => setError(String((e && e.message) || e)))
|
|
@@ -4833,7 +4863,11 @@ window.__ModuleLoader__.load({
|
|
|
4833
4863
|
write: perms[item.scope]?.write !== false,
|
|
4834
4864
|
}))
|
|
4835
4865
|
if (scopes.length === 0) { setError('至少选择一个可见范围'); return }
|
|
4836
|
-
|
|
4866
|
+
const pendingGrants = Object.keys(pendingRevoke)
|
|
4867
|
+
.filter((scope) => pendingRevoke[scope])
|
|
4868
|
+
.map((scope) => grantsByScope.get(scope))
|
|
4869
|
+
.filter(Boolean)
|
|
4870
|
+
save({ scopes, level }, pendingGrants)
|
|
4837
4871
|
}
|
|
4838
4872
|
|
|
4839
4873
|
if (typeof sessionId !== 'string' || sessionId === '') return null
|
|
@@ -4844,20 +4878,22 @@ window.__ModuleLoader__.load({
|
|
|
4844
4878
|
const hasOverride = override !== null
|
|
4845
4879
|
const effectiveConfig = override
|
|
4846
4880
|
?? (data && data.effective && typeof data.effective === 'object' && !Array.isArray(data.effective) ? data.effective : null)
|
|
4847
|
-
const effectiveCount = effectiveConfig && Array.isArray(effectiveConfig.scopes)
|
|
4848
|
-
? effectiveConfig.scopes.length
|
|
4849
|
-
: (data && Array.isArray(data.defaults) ? data.defaults.length : 0)
|
|
4850
4881
|
const selectedCount = catalog.filter((item) => entries[item.scope]).length
|
|
4851
4882
|
const needle = search.trim().toLowerCase()
|
|
4852
|
-
// 0.25.
|
|
4853
|
-
// 在名称右边挂一个「AI
|
|
4883
|
+
// 0.25.4:Agent 授权的结果用勾选呈现 —— 勾选 = 本会话可访问,授权来的作用域
|
|
4884
|
+
// 在名称右边挂一个「AI」气泡。取消勾选只是草稿(标「待撤销」),点「保存」才撤销;
|
|
4885
|
+
// 列表顺序按**已保存**的勾选排序,保存后才重排。
|
|
4854
4886
|
const grantList = Array.isArray(grants) ? grants : []
|
|
4855
4887
|
const grantsByScope = new Map()
|
|
4856
4888
|
for (const grant of grantList) {
|
|
4857
4889
|
if (!grant || typeof grant.scope !== 'string' || grant.scope === '') continue
|
|
4858
4890
|
if (!grantsByScope.has(grant.scope)) grantsByScope.set(grant.scope, grant)
|
|
4859
4891
|
}
|
|
4860
|
-
|
|
4892
|
+
/** 当前草稿里的勾选状态(取消勾选的 AI 授权算未勾选)。 */
|
|
4893
|
+
const isChecked = (scope) => Boolean(entries[scope])
|
|
4894
|
+
|| (grantsByScope.has(scope) && !pendingRevoke[scope])
|
|
4895
|
+
/** 已保存状态的勾选(排序只看它,草稿改动不立刻重排)。 */
|
|
4896
|
+
const savedChecked = (scope) => Boolean(savedEntries[scope]) || grantsByScope.has(scope)
|
|
4861
4897
|
const matches = (label, scope) => !needle
|
|
4862
4898
|
|| String(label || scope).toLowerCase().includes(needle) || String(scope).toLowerCase().includes(needle)
|
|
4863
4899
|
const visibleScopes = catalog.filter((item) => matches(item.label || item.scope, item.scope))
|
|
@@ -4865,24 +4901,26 @@ window.__ModuleLoader__.load({
|
|
|
4865
4901
|
const catalogScopes = new Set(catalog.map((item) => item.scope))
|
|
4866
4902
|
const orphanGrants = grantList.filter((grant) => grant && typeof grant.scope === 'string' && grant.scope !== ''
|
|
4867
4903
|
&& !catalogScopes.has(grant.scope) && matches(grant.label || grant.scope, grant.scope))
|
|
4868
|
-
|
|
4869
|
-
&& grant.scope !== '' && !catalogScopes.has(grant.scope)).length
|
|
4870
|
-
const checkedCount = catalog.filter((item) => isChecked(item.scope)).length + orphanCount
|
|
4871
|
-
// 已勾选的排上面、未勾选的排下面,组内按名称字母排序(授权行同样算已勾选)。
|
|
4904
|
+
// 已勾选的排上面、未勾选的排下面,组内按名称字母排序;顺序以保存过的状态为准。
|
|
4872
4905
|
const rows = [
|
|
4873
4906
|
...visibleScopes.map((item) => ({ scope: item.scope, name: String(item.label || item.scope), item })),
|
|
4874
4907
|
...orphanGrants.map((grant) => ({ scope: grant.scope, name: String(grant.label || grant.scope), grant })),
|
|
4875
4908
|
]
|
|
4876
|
-
rows.sort((a, b) => (Number(
|
|
4909
|
+
rows.sort((a, b) => (Number(savedChecked(b.scope)) - Number(savedChecked(a.scope)))
|
|
4877
4910
|
|| a.name.localeCompare(b.name, 'zh-Hans-CN', { sensitivity: 'base', numeric: true })
|
|
4878
4911
|
|| a.scope.localeCompare(b.scope))
|
|
4879
4912
|
/** 作用域名称右边的「AI」气泡:表示这条勾选来自 Agent 申请的授权。 */
|
|
4880
|
-
const grantTag = (grant) =>
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
:
|
|
4885
|
-
|
|
4913
|
+
const grantTag = (grant, scope) => {
|
|
4914
|
+
const pending = Boolean(pendingRevoke[scope])
|
|
4915
|
+
return h('span', {
|
|
4916
|
+
className: `mem-scope-ai${grant.inherited === true ? ' inherited' : ''}${pending ? ' pending' : ''}`,
|
|
4917
|
+
title: pending
|
|
4918
|
+
? `Agent 申请的范围外授权(${grantPermissionText(grant.permissions)});点「保存」后撤销`
|
|
4919
|
+
: (grant.inherited === true
|
|
4920
|
+
? `Agent 申请的范围外授权(${grantPermissionText(grant.permissions)})· 继承自父会话,要到父会话撤销`
|
|
4921
|
+
: `Agent 申请的范围外授权(${grantPermissionText(grant.permissions)});取消勾选后点「保存」即撤销`),
|
|
4922
|
+
}, pending ? 'AI·待撤销' : (grant.inherited === true ? 'AI·继承' : 'AI'))
|
|
4923
|
+
}
|
|
4886
4924
|
let popStyle = {}
|
|
4887
4925
|
if (anchor) {
|
|
4888
4926
|
const width = 340
|
|
@@ -4908,7 +4946,22 @@ window.__ModuleLoader__.load({
|
|
|
4908
4946
|
const sourceText = data && data.source === 'inherited'
|
|
4909
4947
|
? '继承自父会话'
|
|
4910
4948
|
: hasOverride ? '本会话已设置' : '本会话使用默认'
|
|
4911
|
-
|
|
4949
|
+
// 0.25.5:按钮数字 = 可见范围 ∪ AI 授权(AI 授权也是本会话能读的作用域,算进去)。
|
|
4950
|
+
const effectiveScopeKeys = effectiveConfig && Array.isArray(effectiveConfig.scopes)
|
|
4951
|
+
? effectiveConfig.scopes
|
|
4952
|
+
.map((rule) => (typeof rule === 'string' ? rule : rule && typeof rule.scope === 'string' ? rule.scope : ''))
|
|
4953
|
+
.filter((scope) => scope !== '')
|
|
4954
|
+
: (data && Array.isArray(data.defaults) ? data.defaults.filter((scope) => typeof scope === 'string') : [])
|
|
4955
|
+
const accessibleCount = new Set([
|
|
4956
|
+
...effectiveScopeKeys,
|
|
4957
|
+
...grantList.filter((grant) => grant && typeof grant.scope === 'string' && grant.scope !== '')
|
|
4958
|
+
.map((grant) => grant.scope),
|
|
4959
|
+
]).size
|
|
4960
|
+
// 弹窗头部的「已选」= 当前勾选数(含 AI 授权的勾选;标了待撤销的不算)。
|
|
4961
|
+
const orphanChecked = grantList.filter((grant) => grant && typeof grant.scope === 'string'
|
|
4962
|
+
&& grant.scope !== '' && !catalogScopes.has(grant.scope) && !pendingRevoke[grant.scope]).length
|
|
4963
|
+
const checkedCount = catalog.filter((item) => isChecked(item.scope)).length + orphanChecked
|
|
4964
|
+
const scopeCountText = `${accessibleCount} 个作用域`
|
|
4912
4965
|
return h('span', { className: 'mem-scope-wrap', ref: wrapRef },
|
|
4913
4966
|
h('button', {
|
|
4914
4967
|
type: 'button',
|
|
@@ -4920,7 +4973,7 @@ window.__ModuleLoader__.load({
|
|
|
4920
4973
|
onClick: toggle,
|
|
4921
4974
|
},
|
|
4922
4975
|
h(NavLineIcon, { size: 14 }),
|
|
4923
|
-
data === null ? null : h('span', null, String(
|
|
4976
|
+
data === null ? null : h('span', null, String(accessibleCount)),
|
|
4924
4977
|
),
|
|
4925
4978
|
open ? h('div', { className: 'mem-scope-pop', style: popStyle, role: 'dialog', 'aria-label': '记忆权限' },
|
|
4926
4979
|
h('div', { className: 'mem-scope-head' },
|
|
@@ -4965,19 +5018,21 @@ window.__ModuleLoader__.load({
|
|
|
4965
5018
|
const item = row.item
|
|
4966
5019
|
const grant = item ? grantsByScope.get(row.scope) : row.grant
|
|
4967
5020
|
const checked = isChecked(row.scope)
|
|
4968
|
-
|
|
5021
|
+
// 只靠 AI 授权才勾上的行加 .ai:样式与用户自己勾选的行区分开。
|
|
5022
|
+
const aiOnly = Boolean(grant) && !entries[row.scope]
|
|
5023
|
+
return h('div', { className: `mem-scope-item${checked ? ' on' : ''}${aiOnly ? ' ai' : ''}`, key: row.scope },
|
|
4969
5024
|
h('div', { className: 'mem-scope-row' },
|
|
4970
5025
|
h('button', {
|
|
4971
5026
|
type: 'button',
|
|
4972
5027
|
role: 'checkbox',
|
|
4973
5028
|
'aria-checked': checked,
|
|
4974
|
-
className: `mem-scope-check${checked ? ' on' : ''}`,
|
|
5029
|
+
className: `mem-scope-check${checked ? ' on' : ''}${aiOnly ? ' ai' : ''}`,
|
|
4975
5030
|
onClick: () => toggleScope(row.scope),
|
|
4976
5031
|
'aria-label': checked ? '取消选择' : '选择',
|
|
4977
5032
|
title: grant
|
|
4978
5033
|
? (grant.inherited === true
|
|
4979
5034
|
? 'AI 申请的授权(继承自父会话,要到父会话撤销)'
|
|
4980
|
-
: '
|
|
5035
|
+
: (pendingRevoke[row.scope] ? '已标记撤销,点「保存」生效' : '取消勾选后点「保存」撤销 AI 申请的这条授权'))
|
|
4981
5036
|
: null,
|
|
4982
5037
|
}, h('span', { className: 'box' }, checked ? 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)),
|
|
4983
5038
|
h('button', {
|
|
@@ -4986,7 +5041,7 @@ window.__ModuleLoader__.load({
|
|
|
4986
5041
|
title: item ? row.scope : `${row.scope}(目录中已不可见)`,
|
|
4987
5042
|
onClick: () => toggleScope(row.scope),
|
|
4988
5043
|
}, item ? (item.label || item.scope) : (row.grant.label || row.grant.scope)),
|
|
4989
|
-
grant ? grantTag(grant) : null,
|
|
5044
|
+
grant ? grantTag(grant, row.scope) : null,
|
|
4990
5045
|
h('span', { className: 'cnt' }, item ? `${item.records ?? 0}` : '目录中已不可见'),
|
|
4991
5046
|
),
|
|
4992
5047
|
item
|