@restregular/dsh-memory 0.25.1 → 0.25.3
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 +17 -0
- package/README.md +3 -3
- package/lib/client.js +144 -129
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
本项目的版本记录。安装 id 与 npm 版本一一对应。
|
|
4
4
|
|
|
5
|
+
## 0.25.3 — Agent 授权改用「勾选 + AI 气泡」呈现,取消勾选即撤销
|
|
6
|
+
|
|
7
|
+
- **授权结果 = 勾选**:作用域被 Agent 申请并审批通过后,该作用域直接显示为**已勾选**(即使它不在你设置的可见范围内),列表里同样排在已勾选分组。浮窗打开期间每 3 秒刷新授权,Agent 刚拿到的权限不用重开面板就能看到。
|
|
8
|
+
- **「AI」气泡**:授权来的作用域在名称右边挂一个「AI」气泡,`title` 写明只读 / 可写;继承自父会话的标「AI·继承」。
|
|
9
|
+
- **取消勾选 = 撤销**:用户取消该作用域的勾选时,面板调用 `POST /memory/api/grants` 撤销这条授权,勾选与气泡一起消失,Agent 下一次 pre-step 收到「记忆权限已更新」。「取消全选」会一并撤销可撤销的授权;继承的授权撤销不了,会明确提示到父会话操作。
|
|
10
|
+
- **目录里已不可见的作用域**仍保留一行(「目录中已不可见」),取消勾选即可撤销对应授权。
|
|
11
|
+
- **保留 0.25.2 的收敛**:仍没有独立的「Agent 授权」行与浮窗上方解释文本;勾选、`可读 / 可写`(自己勾选的作用域才可调)与授权气泡并列在同一行。
|
|
12
|
+
- 测试:新增用例断言授权行显示为勾选 + AI 气泡、title 含权限文案、授权行参与「已勾选在上」排序,取消勾选走 `POST /grants` 且气泡消失;全套 494 tests / 493 pass / 1 skipped。
|
|
13
|
+
|
|
14
|
+
## 0.25.2 — 记忆权限浮窗只留「勾选作用域 + 可读 / 可写」,列表按勾选与字母排序
|
|
15
|
+
|
|
16
|
+
- **移除 Agent 授权 UI**:「记忆权限」浮窗不再显示「Agent 授权:只读 / 可写」行,作用域行只剩勾选 + 【绑定】/【可读】/【可写】;继承标记、「到父会话撤销」与「目录中已不可见」的保留授权行一并去掉。
|
|
17
|
+
- **移除多余解释文本**:删掉浮窗上方「勾选作用域 +『可读 / 可写』= …;行内『Agent 授权』= …」那段说明。
|
|
18
|
+
- **列表排序**:已勾选的作用域排在列表上方、未勾选的排在下面,组内按名称字母排序(中英文走同一份 key,用 `localeCompare` + 数字比较);勾选 / 取消勾选后立即重排。
|
|
19
|
+
- **客户端减负**:面板不再请求 / 轮询 `GET /memory/api/grants`,也不再提供撤销入口,相关状态、定时器与样式全部删除;服务端 `GET/POST /memory/api/grants`、`grants/<session>.json` 与审批授予逻辑保持不变,授权仍按会话(含子 Agent 继承)生效并注入告知。
|
|
20
|
+
- 测试:client 浮窗断言不再出现「Agent 授权」「范围外例外」等文本、不请求 `/grants`,作用域行仍有勾选框 + 绑定 / 可读 / 可写三个状态按钮;新增排序用例(勾选的在上一组、组内字母序、取消勾选后沉下去)。全套 493 tests / 492 pass / 1 skipped。
|
|
21
|
+
|
|
5
22
|
## 0.25.1 — Agent 授权不再单列,直接标在作用域行内
|
|
6
23
|
|
|
7
24
|
- **复用同一条作用域记录**:去掉「记忆权限」浮窗里独立的「Agent 会话授权」区块。同一作用域只有一条,Agent 授权直接显示在对应作用域行的下方(`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
|
-
| **记忆权限** | 输入框旁的「记忆权限」按钮设置本会话可读的作用域 + 限制等级(绝对 / 普通 /
|
|
50
|
+
| **记忆权限** | 输入框旁的「记忆权限」按钮设置本会话可读的作用域 + 限制等级(绝对 / 普通 / 无限制);每个作用域一行就是一条设置:**勾选**表示本会话可访问,行内**【绑定】/【可读】/【可写】**控制工作区默认可见与读写权限——绑定到当前工作区后新会话默认可见,可读 / 可写独立影响工具读写;Agent 通过 `memory_scopes request` 申请到的范围外授权**也用勾选呈现**(名称右边挂一个「AI」气泡),**取消勾选即撤销**,撤销后气泡自动消失(0.25.3 起);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,11 +97,11 @@ JSONL 落盘 · 本机向量检索 · 五个模型工具 · 自动召回 · 硬
|
|
|
97
97
|
- **绝对限制**:可见域外的读取 / 写入 / 删除一律不执行;命中被挡住时会明确告诉 Agent 是「绝对限制」以及怎么调整(不再假装记忆不存在)。
|
|
98
98
|
- **普通限制**(默认):可见域内正常返回;命中范围外记忆时,工具会暂停并在**该会话**的输入框上方显示审批卡,展示 Agent 的查询关键词与范围外记忆摘要;读审批可以逐条勾选,只允许其中一条或多条。用户拒绝 / 5 分钟未回答时,工具结果里会明确写出真实原因(「用户拒绝了本次访问」/「审批超时」),模型不会误以为记忆不存在。范围外写入 / 删除同样走审批。
|
|
99
99
|
- **无限制**:不启用范围白名单,可以读写任意作用域(选择仍会保存,供下次切换)。
|
|
100
|
-
- **Agent
|
|
100
|
+
- **Agent 授权 = 勾选 + 「AI」气泡(0.25.3)**:作用域行就是「勾选该作用域 + 【绑定】/【可读】/【可写】」这一组控件,不再有独立的「Agent 授权」行与浮窗上方的解释文本。Agent 通过 `memory_scopes request` 审批得到的授权,直接体现为该作用域的**勾选**,并在名称右边挂一个「AI」气泡(`title` 写明只读 / 可写);**用户取消勾选 = 撤销授权**,撤销后气泡与勾选一起消失,Agent 下一次 pre-step 收到「记忆权限已更新」。继承自父会话的授权标「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 自己的会话里再设置,只影响那一个会话。
|
|
104
|
-
- 保存后,下一次 Agent 步骤会通过注入的上下文消息收到「记忆权限已更新」通知(可见范围 + 限制等级 + 本次授权变更 +
|
|
104
|
+
- 保存后,下一次 Agent 步骤会通过注入的上下文消息收到「记忆权限已更新」通知(可见范围 + 限制等级 + 本次授权变更 + 当前会话授权);授权变化走同一条注入,不需要重启会话。
|
|
105
105
|
- 「恢复默认」清除覆盖,回到默认设置(会话 + 项目 + global + 已绑定的作用域 + 普通限制)。
|
|
106
106
|
- 覆盖按会话落盘在 `<storeDir>/visibility/<session>.json`,浏览器刷新 / 插件重载后仍在;0.18 的旧文件按「绝对限制」兼容读取。
|
|
107
107
|
- 浮窗与审批卡的半透明背景、边框、文字颜色全部走宿主主题 token;勾选框选中态、保存按钮、限制等级选中态使用 `--dsw-alias-state-business-primary` + `--dsw-alias-label-primary-foreground`,深色模式下不会出现白底白勾 / 白底白字;按钮三档边框用 `state-warn-primary`(橙黄)/ `state-business-primary`(蓝)/ 虚线灰;阴影已收敛为小范围投影,滚动列表高度收紧到 `min(220px, 32vh)`。
|
package/lib/client.js
CHANGED
|
@@ -540,6 +540,9 @@ window.__ModuleLoader__.load({
|
|
|
540
540
|
'.mem-scope-state:disabled{opacity:.42;cursor:default}',
|
|
541
541
|
'.mem-scope-state:focus-visible{outline:1px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}',
|
|
542
542
|
'.mem-scope-sep{width:1px;height:12px;margin:0 1px;background:var(--dsw-alias-border-l1);flex:none}',
|
|
543
|
+
// 0.25.3:Agent 授权用「勾选 + AI 气泡」呈现,气泡挂在作用域名称右边。
|
|
544
|
+
'.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
|
+
'.mem-scope-ai.inherited{border-style:dashed;background:transparent;color:var(--dsw-alias-label-secondary)}',
|
|
543
546
|
'.mem-scope-foot{display:flex;align-items:center;gap:8px}',
|
|
544
547
|
'.mem-scope-foot .spacer{flex:1}',
|
|
545
548
|
'.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}',
|
|
@@ -549,15 +552,6 @@ window.__ModuleLoader__.load({
|
|
|
549
552
|
'.mem-scope-reset:disabled,.mem-scope-save:disabled{opacity:.5;cursor:default;filter:none}',
|
|
550
553
|
'.mem-scope-save:disabled{color:var(--dsw-alias-label-primary-foreground)}',
|
|
551
554
|
'.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}',
|
|
552
|
-
// 0.25.x:Agent 授权直接标在对应作用域行内,不再单独开一块列表
|
|
553
|
-
// (与上面的「勾选 + 可读/可写」是同一条作用域记录,分两块会看起来重复)。
|
|
554
|
-
'.mem-scope-grant-row{display:flex;align-items:center;gap:6px;min-width:0;padding-left:26px;font-size:10.5px;color:var(--dsw-alias-label-secondary)}',
|
|
555
|
-
'.mem-scope-grant-row .spacer{flex:1}',
|
|
556
|
-
'.mem-scope-grant{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:color-mix(in srgb,var(--dsw-alias-state-business-primary) 78%,var(--dsw-alias-label-primary));border:1px dashed color-mix(in srgb,var(--dsw-alias-state-business-primary) 45%,var(--dsw-alias-border-l1));border-radius:999px;padding:0 7px;line-height:1.8}',
|
|
557
|
-
'.mem-grant-pill{flex:none;font-size:9.5px;color:var(--dsw-alias-label-secondary);border:1px dashed var(--dsw-alias-border-l1);border-radius:999px;padding:0 6px;line-height:1.7;white-space:nowrap}',
|
|
558
|
-
'.mem-grant-revoke{flex:none;padding:0 7px;border:1px solid color-mix(in srgb,var(--dsw-alias-state-error-primary,#d33) 45%,var(--dsw-alias-border-l1));border-radius:6px;background:transparent;color:color-mix(in srgb,var(--dsw-alias-state-error-primary,#d33) 78%,var(--dsw-alias-label-primary));font-size:10px;line-height:1.7;cursor:pointer}',
|
|
559
|
-
'.mem-grant-revoke:hover:not(:disabled){border-color:var(--dsw-alias-state-error-primary,#d33);color:var(--dsw-alias-state-error-primary,#d33)}',
|
|
560
|
-
'.mem-grant-revoke:disabled{opacity:.45;cursor:default}',
|
|
561
555
|
// 范围外访问审批卡(0.21.0):注册在 conversation.input.dock,只在所属会话里显示。
|
|
562
556
|
// 版式照抄宿主 dsh-client-ui-approval 的审批卡(strip + body + 右对齐动作行),
|
|
563
557
|
// 尺寸/圆角/底色/阴影全走同一批主题 token;缺少 composer 变量时给出同样的回退值。
|
|
@@ -4699,10 +4693,31 @@ window.__ModuleLoader__.load({
|
|
|
4699
4693
|
.finally(() => setLoading(false))
|
|
4700
4694
|
}
|
|
4701
4695
|
|
|
4696
|
+
// 打开会话就加载一次:按钮上的数字来自这个会话的设置,不需要用户先点按钮。
|
|
4697
|
+
React.useEffect(() => {
|
|
4698
|
+
if (typeof sessionId !== 'string' || sessionId === '') return
|
|
4699
|
+
load()
|
|
4700
|
+
}, [sessionId])
|
|
4701
|
+
|
|
4702
|
+
const toggle = (event) => {
|
|
4703
|
+
if (open) { setOpen(false); return }
|
|
4704
|
+
let nextAnchor = null
|
|
4705
|
+
try {
|
|
4706
|
+
const rect = event && event.currentTarget && event.currentTarget.getBoundingClientRect
|
|
4707
|
+
? event.currentTarget.getBoundingClientRect()
|
|
4708
|
+
: null
|
|
4709
|
+
if (rect) nextAnchor = { left: rect.left, top: rect.top }
|
|
4710
|
+
} catch { nextAnchor = null }
|
|
4711
|
+
setAnchor(nextAnchor)
|
|
4712
|
+
setSearch('')
|
|
4713
|
+
setOpen(true)
|
|
4714
|
+
load()
|
|
4715
|
+
}
|
|
4716
|
+
|
|
4702
4717
|
/**
|
|
4703
|
-
* 0.25.
|
|
4704
|
-
*
|
|
4705
|
-
*
|
|
4718
|
+
* 0.25.3:本会话的 Agent 授权(grants)。
|
|
4719
|
+
* 授权结果直接体现在作用域行的勾选上(外加「AI」气泡),所以浮窗打开期间
|
|
4720
|
+
* 按 3 秒轮询:Agent 刚审批到的授权不用重开面板就能看到勾选与气泡。
|
|
4706
4721
|
*/
|
|
4707
4722
|
const loadGrants = () => {
|
|
4708
4723
|
if (typeof sessionId !== 'string' || sessionId === '') return
|
|
@@ -4727,41 +4742,32 @@ window.__ModuleLoader__.load({
|
|
|
4727
4742
|
|
|
4728
4743
|
/** 撤销一条本会话授权(继承自父会话的授权只能到父会话撤销)。 */
|
|
4729
4744
|
const revokeGrant = (grant) => {
|
|
4730
|
-
if (!grant || grant.inherited === true) return
|
|
4745
|
+
if (!grant || grant.inherited === true) return Promise.resolve()
|
|
4731
4746
|
const id = typeof grant.id === 'string' ? grant.id : ''
|
|
4732
|
-
if (id === '') return
|
|
4747
|
+
if (id === '') return Promise.resolve()
|
|
4733
4748
|
const owner = typeof grant.ownerSession === 'string' && grant.ownerSession !== '' ? grant.ownerSession : sessionId
|
|
4734
4749
|
setGrantBusy(id)
|
|
4735
4750
|
setGrantError('')
|
|
4736
|
-
api('grants', { session: owner, id, view: sessionId })
|
|
4751
|
+
return api('grants', { session: owner, id, view: sessionId })
|
|
4737
4752
|
.then((value) => setGrants(Array.isArray(value.grants) ? value.grants : []))
|
|
4738
4753
|
.catch((e) => setGrantError(String((e && e.message) || e)))
|
|
4739
4754
|
.finally(() => setGrantBusy(''))
|
|
4740
4755
|
}
|
|
4741
4756
|
|
|
4742
|
-
// 打开会话就加载一次:按钮上的数字来自这个会话的设置,不需要用户先点按钮。
|
|
4743
|
-
React.useEffect(() => {
|
|
4744
|
-
if (typeof sessionId !== 'string' || sessionId === '') return
|
|
4745
|
-
load()
|
|
4746
|
-
}, [sessionId])
|
|
4747
|
-
|
|
4748
|
-
const toggle = (event) => {
|
|
4749
|
-
if (open) { setOpen(false); return }
|
|
4750
|
-
let nextAnchor = null
|
|
4751
|
-
try {
|
|
4752
|
-
const rect = event && event.currentTarget && event.currentTarget.getBoundingClientRect
|
|
4753
|
-
? event.currentTarget.getBoundingClientRect()
|
|
4754
|
-
: null
|
|
4755
|
-
if (rect) nextAnchor = { left: rect.left, top: rect.top }
|
|
4756
|
-
} catch { nextAnchor = null }
|
|
4757
|
-
setAnchor(nextAnchor)
|
|
4758
|
-
setSearch('')
|
|
4759
|
-
setOpen(true)
|
|
4760
|
-
load()
|
|
4761
|
-
}
|
|
4762
|
-
|
|
4763
4757
|
const toggleScope = (scope) => {
|
|
4764
|
-
|
|
4758
|
+
const grant = grantsByScope.get(scope)
|
|
4759
|
+
if (!grant) {
|
|
4760
|
+
setEntries((prev) => ({ ...prev, [scope]: !prev[scope] }))
|
|
4761
|
+
return
|
|
4762
|
+
}
|
|
4763
|
+
// 勾选里有 Agent 授权:取消勾选 = 撤销授权(撤销后「AI」气泡一起消失)。
|
|
4764
|
+
if (grant.inherited === true) {
|
|
4765
|
+
setEntries((prev) => ({ ...prev, [scope]: true }))
|
|
4766
|
+
setGrantError('继承自父会话的授权需要到父会话撤销')
|
|
4767
|
+
return
|
|
4768
|
+
}
|
|
4769
|
+
setEntries((prev) => ({ ...prev, [scope]: false }))
|
|
4770
|
+
revokeGrant(grant)
|
|
4765
4771
|
}
|
|
4766
4772
|
|
|
4767
4773
|
/** 切换某个作用域的可读 / 可写状态(会话级)。 */
|
|
@@ -4791,6 +4797,17 @@ window.__ModuleLoader__.load({
|
|
|
4791
4797
|
for (const key of Object.keys(next)) next[key] = false
|
|
4792
4798
|
return next
|
|
4793
4799
|
})
|
|
4800
|
+
// 取消全选 = 把这些作用域全部取消勾选,所以 Agent 授权也一并撤销;
|
|
4801
|
+
// 继承自父会话的授权撤销不了,只提示去父会话操作。
|
|
4802
|
+
let inherited = 0
|
|
4803
|
+
let chain = Promise.resolve()
|
|
4804
|
+
for (const grant of Array.isArray(grants) ? grants : []) {
|
|
4805
|
+
if (!grant || typeof grant.scope !== 'string' || grant.scope === '') continue
|
|
4806
|
+
if (grant.inherited === true) { inherited += 1; continue }
|
|
4807
|
+
chain = chain.then(() => revokeGrant(grant))
|
|
4808
|
+
}
|
|
4809
|
+
if (inherited > 0) setGrantError('继承自父会话的授权需要到父会话撤销')
|
|
4810
|
+
chain.catch(() => { /* revokeGrant 自己会记录错误 */ })
|
|
4794
4811
|
}
|
|
4795
4812
|
|
|
4796
4813
|
const save = (config) => {
|
|
@@ -4832,23 +4849,40 @@ window.__ModuleLoader__.load({
|
|
|
4832
4849
|
: (data && Array.isArray(data.defaults) ? data.defaults.length : 0)
|
|
4833
4850
|
const selectedCount = catalog.filter((item) => entries[item.scope]).length
|
|
4834
4851
|
const needle = search.trim().toLowerCase()
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
})
|
|
4839
|
-
// 0.25.x:授权按 scope 合并到作用域行内(同一作用域只有一条 grant)。
|
|
4852
|
+
// 0.25.3:Agent 授权的结果也用勾选呈现 —— 勾选 = 本会话可访问,授权来的作用域
|
|
4853
|
+
// 在名称右边挂一个「AI」气泡;取消勾选即撤销,撤销后气泡自动消失。
|
|
4854
|
+
const grantList = Array.isArray(grants) ? grants : []
|
|
4840
4855
|
const grantsByScope = new Map()
|
|
4841
|
-
for (const grant of
|
|
4856
|
+
for (const grant of grantList) {
|
|
4842
4857
|
if (!grant || typeof grant.scope !== 'string' || grant.scope === '') continue
|
|
4843
4858
|
if (!grantsByScope.has(grant.scope)) grantsByScope.set(grant.scope, grant)
|
|
4844
4859
|
}
|
|
4845
|
-
|
|
4860
|
+
const isChecked = (scope) => Boolean(entries[scope]) || grantsByScope.has(scope)
|
|
4861
|
+
const matches = (label, scope) => !needle
|
|
4862
|
+
|| String(label || scope).toLowerCase().includes(needle) || String(scope).toLowerCase().includes(needle)
|
|
4863
|
+
const visibleScopes = catalog.filter((item) => matches(item.label || item.scope, item.scope))
|
|
4864
|
+
// 目录里已经看不到的作用域(记录删光 / 元数据没了)仍占一行,方便取消勾选撤销授权。
|
|
4846
4865
|
const catalogScopes = new Set(catalog.map((item) => item.scope))
|
|
4847
|
-
const orphanGrants =
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4866
|
+
const orphanGrants = grantList.filter((grant) => grant && typeof grant.scope === 'string' && grant.scope !== ''
|
|
4867
|
+
&& !catalogScopes.has(grant.scope) && matches(grant.label || grant.scope, grant.scope))
|
|
4868
|
+
const orphanCount = grantList.filter((grant) => grant && typeof grant.scope === 'string'
|
|
4869
|
+
&& grant.scope !== '' && !catalogScopes.has(grant.scope)).length
|
|
4870
|
+
const checkedCount = catalog.filter((item) => isChecked(item.scope)).length + orphanCount
|
|
4871
|
+
// 已勾选的排上面、未勾选的排下面,组内按名称字母排序(授权行同样算已勾选)。
|
|
4872
|
+
const rows = [
|
|
4873
|
+
...visibleScopes.map((item) => ({ scope: item.scope, name: String(item.label || item.scope), item })),
|
|
4874
|
+
...orphanGrants.map((grant) => ({ scope: grant.scope, name: String(grant.label || grant.scope), grant })),
|
|
4875
|
+
]
|
|
4876
|
+
rows.sort((a, b) => (Number(isChecked(b.scope)) - Number(isChecked(a.scope)))
|
|
4877
|
+
|| a.name.localeCompare(b.name, 'zh-Hans-CN', { sensitivity: 'base', numeric: true })
|
|
4878
|
+
|| a.scope.localeCompare(b.scope))
|
|
4879
|
+
/** 作用域名称右边的「AI」气泡:表示这条勾选来自 Agent 申请的授权。 */
|
|
4880
|
+
const grantTag = (grant) => h('span', {
|
|
4881
|
+
className: `mem-scope-ai${grant.inherited === true ? ' inherited' : ''}`,
|
|
4882
|
+
title: grant.inherited === true
|
|
4883
|
+
? `Agent 申请的范围外授权(${grantPermissionText(grant.permissions)})· 继承自父会话,要到父会话撤销`
|
|
4884
|
+
: `Agent 申请的范围外授权(${grantPermissionText(grant.permissions)});取消勾选即撤销`,
|
|
4885
|
+
}, grant.inherited === true ? 'AI·继承' : 'AI')
|
|
4852
4886
|
let popStyle = {}
|
|
4853
4887
|
if (anchor) {
|
|
4854
4888
|
const width = 340
|
|
@@ -4875,25 +4909,6 @@ window.__ModuleLoader__.load({
|
|
|
4875
4909
|
? '继承自父会话'
|
|
4876
4910
|
: hasOverride ? '本会话已设置' : '本会话使用默认'
|
|
4877
4911
|
const scopeCountText = `${effectiveCount} 个作用域`
|
|
4878
|
-
/** 作用域行内的「Agent 授权」:只读 / 可写 + 撤销(继承的只能到父会话撤销)。 */
|
|
4879
|
-
const grantRow = (grant) => h('div', { className: 'mem-scope-grant-row' },
|
|
4880
|
-
h('span', {
|
|
4881
|
-
className: 'mem-scope-grant',
|
|
4882
|
-
title: `${grant.scope}${grant.grantedAt ? ` · 授予于 ${fmtTime(grant.grantedAt)}` : ''}(范围外例外,不影响上面的勾选)`,
|
|
4883
|
-
}, `Agent 授权:${grantPermissionText(grant.permissions)}`),
|
|
4884
|
-
grant.inherited === true ? h('span', { className: 'mem-grant-pill' }, '继承') : null,
|
|
4885
|
-
h('span', { className: 'spacer' }),
|
|
4886
|
-
grant.inherited === true
|
|
4887
|
-
? h('span', { className: 'muted' }, '到父会话撤销')
|
|
4888
|
-
: h('button', {
|
|
4889
|
-
type: 'button',
|
|
4890
|
-
className: 'mem-grant-revoke',
|
|
4891
|
-
disabled: grantBusy === grant.id,
|
|
4892
|
-
title: '撤销这条授权(不影响上面的勾选;Agent 需要重新申请)',
|
|
4893
|
-
onClick: () => revokeGrant(grant),
|
|
4894
|
-
}, grantBusy === grant.id ? '撤销中…' : '撤销'),
|
|
4895
|
-
)
|
|
4896
|
-
|
|
4897
4912
|
return h('span', { className: 'mem-scope-wrap', ref: wrapRef },
|
|
4898
4913
|
h('button', {
|
|
4899
4914
|
type: 'button',
|
|
@@ -4911,10 +4926,8 @@ window.__ModuleLoader__.load({
|
|
|
4911
4926
|
h('div', { className: 'mem-scope-head' },
|
|
4912
4927
|
h('h4', null, '记忆权限'),
|
|
4913
4928
|
h('span', { className: 'spacer' }),
|
|
4914
|
-
h('span', { className: 'mem-scope-count' }, `已选 ${
|
|
4929
|
+
h('span', { className: 'mem-scope-count' }, `已选 ${checkedCount}`),
|
|
4915
4930
|
),
|
|
4916
|
-
h('div', { className: 'hint' },
|
|
4917
|
-
'勾选作用域 +「可读 / 可写」= 你为本会话设置的可见范围;行内「Agent 授权」= Agent 主动申请、你审批过的范围外例外(仅本会话,可单独撤销,不影响勾选)。限制等级决定范围外怎么处理。'),
|
|
4918
4931
|
data && data.inherited
|
|
4919
4932
|
? h('div', { className: 'hint' }, '当前继承自父会话;保存后在本会话独立生效。')
|
|
4920
4933
|
: null,
|
|
@@ -4946,73 +4959,75 @@ window.__ModuleLoader__.load({
|
|
|
4946
4959
|
loading && data === null
|
|
4947
4960
|
? h('div', { className: 'hint' }, '读取中…')
|
|
4948
4961
|
: h('div', { className: 'mem-scope-list' },
|
|
4949
|
-
|
|
4962
|
+
rows.length === 0
|
|
4950
4963
|
? h('div', { className: 'hint' }, needle ? '没有匹配的作用域。' : '还没有可选的范围。')
|
|
4951
|
-
:
|
|
4952
|
-
|
|
4964
|
+
: rows.map((row) => {
|
|
4965
|
+
const item = row.item
|
|
4966
|
+
const grant = item ? grantsByScope.get(row.scope) : row.grant
|
|
4967
|
+
const checked = isChecked(row.scope)
|
|
4968
|
+
return h('div', { className: `mem-scope-item${checked ? ' on' : ''}`, key: row.scope },
|
|
4953
4969
|
h('div', { className: 'mem-scope-row' },
|
|
4954
4970
|
h('button', {
|
|
4955
4971
|
type: 'button',
|
|
4956
4972
|
role: 'checkbox',
|
|
4957
|
-
'aria-checked':
|
|
4958
|
-
className: `mem-scope-check${
|
|
4959
|
-
onClick: () => toggleScope(
|
|
4960
|
-
'aria-label':
|
|
4961
|
-
|
|
4973
|
+
'aria-checked': checked,
|
|
4974
|
+
className: `mem-scope-check${checked ? ' on' : ''}`,
|
|
4975
|
+
onClick: () => toggleScope(row.scope),
|
|
4976
|
+
'aria-label': checked ? '取消选择' : '选择',
|
|
4977
|
+
title: grant
|
|
4978
|
+
? (grant.inherited === true
|
|
4979
|
+
? 'AI 申请的授权(继承自父会话,要到父会话撤销)'
|
|
4980
|
+
: '取消勾选会撤销 AI 申请的这条授权')
|
|
4981
|
+
: null,
|
|
4982
|
+
}, 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)),
|
|
4962
4983
|
h('button', {
|
|
4963
4984
|
type: 'button',
|
|
4964
4985
|
className: 'mem-scope-label',
|
|
4965
|
-
title: item.scope
|
|
4966
|
-
onClick: () => toggleScope(
|
|
4967
|
-
}, item.label || item.scope),
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
// 0.23.0:状态按钮 —— 绑定(工作区级) / 可读 | 可写(会话级)。
|
|
4971
|
-
h('div', { className: 'mem-scope-state-row' },
|
|
4972
|
-
h('button', {
|
|
4973
|
-
type: 'button',
|
|
4974
|
-
className: `mem-scope-state bind${defaultBound[item.scope] || bound[item.scope] ? ' on' : ''}${defaultBound[item.scope] ? ' locked' : ''}`,
|
|
4975
|
-
'aria-pressed': Boolean(defaultBound[item.scope] || bound[item.scope]),
|
|
4976
|
-
disabled: Boolean(defaultBound[item.scope]),
|
|
4977
|
-
title: defaultBound[item.scope]
|
|
4978
|
-
? '默认可见范围已包含(会话 + 项目 + global 默认绑定),无需再绑定'
|
|
4979
|
-
: (bound[item.scope]
|
|
4980
|
-
? '已绑定到当前工作区:本工作区新会话的默认可见范围会包含它'
|
|
4981
|
-
: '绑定到当前工作区:本工作区新会话的默认可见范围会包含它'),
|
|
4982
|
-
onClick: () => { if (!defaultBound[item.scope]) toggleBound(item.scope) },
|
|
4983
|
-
}, '绑定'),
|
|
4984
|
-
h('span', { className: 'mem-scope-sep', 'aria-hidden': 'true' }),
|
|
4985
|
-
h('button', {
|
|
4986
|
-
type: 'button',
|
|
4987
|
-
className: `mem-scope-state read${perms[item.scope]?.read !== false ? ' on' : ''}`,
|
|
4988
|
-
'aria-pressed': perms[item.scope]?.read !== false,
|
|
4989
|
-
disabled: !entries[item.scope],
|
|
4990
|
-
title: entries[item.scope]
|
|
4991
|
-
? (perms[item.scope]?.read !== false ? '可读:搜索 / 读取会命中该作用域' : '不可读:搜索 / 读取会跳过该作用域')
|
|
4992
|
-
: '先勾选该作用域再调整可读 / 可写',
|
|
4993
|
-
onClick: () => togglePerm(item.scope, 'read'),
|
|
4994
|
-
}, '可读'),
|
|
4995
|
-
h('button', {
|
|
4996
|
-
type: 'button',
|
|
4997
|
-
className: `mem-scope-state write${perms[item.scope]?.write !== false ? ' on' : ''}`,
|
|
4998
|
-
'aria-pressed': perms[item.scope]?.write !== false,
|
|
4999
|
-
disabled: !entries[item.scope],
|
|
5000
|
-
title: entries[item.scope]
|
|
5001
|
-
? (perms[item.scope]?.write !== false ? '可写:保存 / 删除会作用到该作用域' : '不可写:保存 / 删除会被拒绝并告知原因')
|
|
5002
|
-
: '先勾选该作用域再调整可读 / 可写',
|
|
5003
|
-
onClick: () => togglePerm(item.scope, 'write'),
|
|
5004
|
-
}, '可写'),
|
|
4986
|
+
title: item ? row.scope : `${row.scope}(目录中已不可见)`,
|
|
4987
|
+
onClick: () => toggleScope(row.scope),
|
|
4988
|
+
}, item ? (item.label || item.scope) : (row.grant.label || row.grant.scope)),
|
|
4989
|
+
grant ? grantTag(grant) : null,
|
|
4990
|
+
h('span', { className: 'cnt' }, item ? `${item.records ?? 0}` : '目录中已不可见'),
|
|
5005
4991
|
),
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
4992
|
+
item
|
|
4993
|
+
? h('div', { className: 'mem-scope-state-row' },
|
|
4994
|
+
h('button', {
|
|
4995
|
+
type: 'button',
|
|
4996
|
+
className: `mem-scope-state bind${defaultBound[item.scope] || bound[item.scope] ? ' on' : ''}${defaultBound[item.scope] ? ' locked' : ''}`,
|
|
4997
|
+
'aria-pressed': Boolean(defaultBound[item.scope] || bound[item.scope]),
|
|
4998
|
+
disabled: Boolean(defaultBound[item.scope]),
|
|
4999
|
+
title: defaultBound[item.scope]
|
|
5000
|
+
? '默认可见范围已包含(会话 + 项目 + global 默认绑定),无需再绑定'
|
|
5001
|
+
: (bound[item.scope]
|
|
5002
|
+
? '已绑定到当前工作区:本工作区新会话的默认可见范围会包含它'
|
|
5003
|
+
: '绑定到当前工作区:本工作区新会话的默认可见范围会包含它'),
|
|
5004
|
+
onClick: () => { if (!defaultBound[item.scope]) toggleBound(item.scope) },
|
|
5005
|
+
}, '绑定'),
|
|
5006
|
+
h('span', { className: 'mem-scope-sep', 'aria-hidden': 'true' }),
|
|
5007
|
+
h('button', {
|
|
5008
|
+
type: 'button',
|
|
5009
|
+
className: `mem-scope-state read${perms[item.scope]?.read !== false ? ' on' : ''}`,
|
|
5010
|
+
'aria-pressed': perms[item.scope]?.read !== false,
|
|
5011
|
+
disabled: !entries[item.scope],
|
|
5012
|
+
title: entries[item.scope]
|
|
5013
|
+
? (perms[item.scope]?.read !== false ? '可读:搜索 / 读取会命中该作用域' : '不可读:搜索 / 读取会跳过该作用域')
|
|
5014
|
+
: (grant ? '这条勾选来自 AI 授权,权限由审批决定;你自己勾选后可改' : '先勾选该作用域再调整可读 / 可写'),
|
|
5015
|
+
onClick: () => togglePerm(item.scope, 'read'),
|
|
5016
|
+
}, '可读'),
|
|
5017
|
+
h('button', {
|
|
5018
|
+
type: 'button',
|
|
5019
|
+
className: `mem-scope-state write${perms[item.scope]?.write !== false ? ' on' : ''}`,
|
|
5020
|
+
'aria-pressed': perms[item.scope]?.write !== false,
|
|
5021
|
+
disabled: !entries[item.scope],
|
|
5022
|
+
title: entries[item.scope]
|
|
5023
|
+
? (perms[item.scope]?.write !== false ? '可写:保存 / 删除会作用到该作用域' : '不可写:保存 / 删除会被拒绝并告知原因')
|
|
5024
|
+
: (grant ? '这条勾选来自 AI 授权,权限由审批决定;你自己勾选后可改' : '先勾选该作用域再调整可读 / 可写'),
|
|
5025
|
+
onClick: () => togglePerm(item.scope, 'write'),
|
|
5026
|
+
}, '可写'),
|
|
5027
|
+
)
|
|
5028
|
+
: null,
|
|
5029
|
+
)
|
|
5030
|
+
}),
|
|
5016
5031
|
),
|
|
5017
5032
|
grantError ? h('div', { className: 'mem-scope-err' }, grantError) : null,
|
|
5018
5033
|
error ? h('div', { className: 'mem-scope-err' }, error) : null,
|