@restregular/dsh-memory 0.23.0 → 0.24.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 +26 -0
- package/README.md +52 -5
- package/lib/client.js +77 -38
- package/lib/inject/apply.js +1 -1
- package/lib/inject/policy.js +7 -1
- package/lib/panel.js +16 -2
- package/lib/provider/apply.js +50 -0
- package/lib/provider/approval-audit.js +77 -0
- package/lib/provider/authorize.js +114 -0
- package/lib/provider/grants.js +245 -0
- package/lib/provider/index.js +601 -53
- package/lib/provider/scope-meta.js +215 -0
- package/lib/provider/store.js +6 -0
- package/lib/tools/apply.js +6 -1
- package/lib/tools/index.js +390 -30
- package/lib/tools/render.js +72 -1
- package/package.json +1 -1
package/lib/tools/render.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* 写进渲染文本。
|
|
10
10
|
* 0.23.0:绝对限制与「不可读」开关也会被说明(不再假装"不存在"),并提示怎么调整。
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
|
|
14
14
|
/** 把 scope 键渲染成展示文案(宿主能查到会话标题时用它,否则用短 id)。 */
|
|
15
15
|
|
|
@@ -51,6 +51,8 @@ export function renderWithheldNote(withheld ) {
|
|
|
51
51
|
return `另有 ${count} 条记忆在本会话的可见域外,当前限制等级为「绝对限制」,不会发起审批,未返回。如确实是本次任务需要的内容,请让用户调整「记忆范围」后重试。`
|
|
52
52
|
case 'read-disabled':
|
|
53
53
|
return `另有 ${count} 条记忆所在的作用域在本会话记忆范围里被标记为「不可读」(可读/可写按钮),未返回。如确实需要,请让用户打开该作用域的「可读」状态后重试。`
|
|
54
|
+
case 'scope-disabled':
|
|
55
|
+
return `另有 ${count} 条记忆所在的作用域已被配置关闭(global / project / session / custom 开关),未返回。如确实需要,请让用户打开对应类型的作用域。`
|
|
54
56
|
default:
|
|
55
57
|
return ''
|
|
56
58
|
}
|
|
@@ -102,6 +104,74 @@ export function renderListResult(value , label ) {
|
|
|
102
104
|
return tail === '' ? body : `${body}\n\n${tail}`
|
|
103
105
|
}
|
|
104
106
|
|
|
107
|
+
/**
|
|
108
|
+
* memory_scopes 的渲染:list 只讲“有什么、干什么、能不能碰”;request 讲每个
|
|
109
|
+
* scope + 权限的申请结局。两者共用同一个工具入口,但文案完全分开。
|
|
110
|
+
*/
|
|
111
|
+
export function renderScopesResult(value , label ) {
|
|
112
|
+
if ('results' in value) {
|
|
113
|
+
if (value.results.length === 0) return '没有需要申请的作用域权限。'
|
|
114
|
+
const statusText = (status ) => {
|
|
115
|
+
switch (status) {
|
|
116
|
+
case 'granted': return '已授予(本会话)'
|
|
117
|
+
case 'already-allowed': return '本来就允许'
|
|
118
|
+
case 'already-granted': return '已有本会话授权'
|
|
119
|
+
case 'not-requestable': return '不可申请'
|
|
120
|
+
case 'unavailable': return '作用域不可用'
|
|
121
|
+
case 'denied': return '用户拒绝'
|
|
122
|
+
case 'timeout': return '审批超时'
|
|
123
|
+
case 'approval-unavailable': return '当前环境无法审批'
|
|
124
|
+
default: return status
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const reasonText = (reason ) => {
|
|
128
|
+
switch (reason) {
|
|
129
|
+
case 'ABSOLUTE_ISOLATION': return '(绝对限制)'
|
|
130
|
+
case 'SCOPE_DISABLED': return '(作用域已关闭)'
|
|
131
|
+
case 'READ_DISABLED': return '(用户已关闭可读)'
|
|
132
|
+
case 'WRITE_DISABLED': return '(用户已关闭可写)'
|
|
133
|
+
default: return ''
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const body = value.results.map((item) =>
|
|
137
|
+
`- ${label(item.scope)}:${item.permission === 'read' ? '只读' : '写入 / 删除'} → ${statusText(item.status)}${reasonText(item.reason)}`,
|
|
138
|
+
).join('\n')
|
|
139
|
+
return `作用域权限申请结果:\n${body}`
|
|
140
|
+
}
|
|
141
|
+
if (value.scopes.length === 0) return '当前没有可列出的作用域。'
|
|
142
|
+
const body = value.scopes.map((item) => {
|
|
143
|
+
const name = item.name !== undefined && item.name !== '' ? item.name : label(item.scope)
|
|
144
|
+
const description = item.description !== undefined && item.description.trim() !== ''
|
|
145
|
+
? item.description.trim()
|
|
146
|
+
: '(未填写用途)'
|
|
147
|
+
const meta = []
|
|
148
|
+
if (item.records !== undefined) meta.push(`${item.records} 条`)
|
|
149
|
+
if (item.inScope) {
|
|
150
|
+
meta.push(item.accessStatus === 'default'
|
|
151
|
+
? '范围内'
|
|
152
|
+
: item.accessStatus === 'read-only'
|
|
153
|
+
? '范围内 · 只读'
|
|
154
|
+
: item.accessStatus === 'read-write'
|
|
155
|
+
? '范围内 · 读写'
|
|
156
|
+
: '范围内 · 受限')
|
|
157
|
+
} else if (item.readable || item.writable) {
|
|
158
|
+
meta.push(`范围外 · 已授权${item.readable && item.writable ? '读写' : item.readable ? '只读' : '可写'}`)
|
|
159
|
+
} else {
|
|
160
|
+
const canRead = item.canRequestRead
|
|
161
|
+
const canWrite = item.canRequestWrite
|
|
162
|
+
meta.push(canRead || canWrite
|
|
163
|
+
? `范围外 · 可申请${canRead ? '只读' : ''}${canWrite ? (canRead ? '/读写' : '读写') : ''}`
|
|
164
|
+
: '范围外 · 不可申请')
|
|
165
|
+
}
|
|
166
|
+
const initial = Array.isArray(item.initialRecords) && item.initialRecords.length > 0
|
|
167
|
+
? `\n 初始记录:${item.initialRecords.map((record) => `[${record.kind}] ${record.content}`).join(' / ')}`
|
|
168
|
+
: ''
|
|
169
|
+
return `- ${name}(${item.scope}):${description}(${meta.join(' · ')})${initial}`
|
|
170
|
+
}).join('\n')
|
|
171
|
+
const tail = value.omitted > 0 ? `\n…另有 ${value.omitted} 个作用域未列出,可调整 limit。` : ''
|
|
172
|
+
return `作用域目录(共 ${value.total} 个):\n${body}${tail}`
|
|
173
|
+
}
|
|
174
|
+
|
|
105
175
|
/**
|
|
106
176
|
* memory_get 的渲染:
|
|
107
177
|
* - 元数据按 fields 拼在首行括号里;
|
|
@@ -141,6 +211,7 @@ export function renderGetResult(value , label ) {
|
|
|
141
211
|
if (fields.has('supersedes') && typeof record.supersedes === 'string' && record.supersedes !== '') {
|
|
142
212
|
meta.push(`修正 ${shortId(record.supersedes)}`)
|
|
143
213
|
}
|
|
214
|
+
if (fields.has('initial') && record.initial === true) meta.push('初始记录')
|
|
144
215
|
const head = `[${record.id}]${meta.length > 0 ? ` (${meta.join(' · ')})` : ''}`
|
|
145
216
|
const content = typeof record.content === 'string' ? record.content : undefined
|
|
146
217
|
const summary = typeof record.summary === 'string' ? record.summary : undefined
|