dsh-team-bots 0.3.12 → 0.3.64
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/NOTICE +3 -4
- package/README.md +2 -2
- package/docs/README.zh.md +2 -2
- package/docs/assets/global-config.png +0 -0
- package/docs/assets/global-config.zh.png +0 -0
- package/docs/assets/tasks.png +0 -0
- package/docs/assets/tasks.zh.png +0 -0
- package/docs/assets/usage.png +0 -0
- package/docs/assets/usage.zh.png +0 -0
- package/package.json +8 -2
- package/src/api.js +10 -1
- package/src/config.js +180 -2
- package/src/db-migrations.js +53 -4
- package/src/db.js +28 -3
- package/src/http.js +20 -1
- package/src/runtime.js +16 -1
- package/src/seed-bots.js +4 -0
- package/src/service.js +21 -2
- package/src/services/approvals.js +276 -8
- package/src/services/core.js +31 -2
- package/src/services/memory.js +24 -8
- package/src/services/projects.js +12 -1
- package/src/services/run-finish.js +11 -0
- package/src/services/runtime/session.js +87 -25
- package/src/services/scheduler.js +20 -0
- package/src/services/system.js +162 -10
- package/src/services/task-review.js +90 -55
- package/src/services/tasks.js +5 -2
- package/ui/app.js +7 -10
- package/ui/i18n/en/chat.js +2 -0
- package/ui/i18n/en/common.js +10 -0
- package/ui/i18n/en/settings.js +75 -1
- package/ui/i18n/en/tasks.js +3 -0
- package/ui/i18n/zh/chat.js +2 -0
- package/ui/i18n/zh/common.js +10 -0
- package/ui/i18n/zh/settings.js +75 -1
- package/ui/i18n/zh/tasks.js +3 -0
- package/ui/modules/api.js +9 -1
- package/ui/modules/cards.js +6 -3
- package/ui/modules/chat.js +1 -1
- package/ui/modules/composer.js +6 -1
- package/ui/modules/events-board.js +48 -0
- package/ui/modules/events-misc.js +43 -0
- package/ui/modules/events-submit.js +20 -0
- package/ui/modules/form-validation.js +204 -0
- package/ui/modules/global-pages.js +8 -5
- package/ui/modules/modal-forms.js +1 -1
- package/ui/modules/modal-layer.js +4 -1
- package/ui/modules/page-shell.js +10 -7
- package/ui/modules/permissions.js +99 -0
- package/ui/modules/settings.js +103 -21
- package/ui/modules/state.js +10 -0
- package/ui/modules/task-menu.js +147 -0
- package/ui/modules/tasks.js +9 -8
- package/ui/modules/util.js +43 -6
- package/ui/styles/a11y.css +13 -0
- package/ui/styles/base.css +57 -11
- package/ui/styles/buttons.css +46 -6
- package/ui/styles/cards.css +90 -0
- package/ui/styles/chat.css +23 -2
- package/ui/styles/global-config.css +7 -4
- package/ui/styles/modal.css +28 -0
- package/ui/styles/settings.css +23 -1
- package/ui/styles/tasks.css +51 -1
- package/ui/styles/toast.css +18 -11
- package/ui/styles/usage.css +2 -0
- package/ui/styles/wide.css +5 -0
- package/docs/assets/channel-redesign.png +0 -0
- package/docs/assets/global-config-dark.png +0 -0
- package/docs/assets/global-config-light.png +0 -0
- package/docs/assets/global-config-light.zh.png +0 -0
- package/docs/assets/global-config-redesign.png +0 -0
- package/docs/assets/secrets-redesign.png +0 -0
- package/docs/assets/usage-redesign-global.png +0 -0
package/ui/modules/cards.js
CHANGED
|
@@ -116,9 +116,12 @@ function approvalCardMarkup(approval, deciding = false, showSource = false) {
|
|
|
116
116
|
const percent = pending ? Math.round(approvalProgressRatio(approval.remainingMs, windowMs) * 100) : 0
|
|
117
117
|
const urgent = approvalUrgent(approval.remainingMs)
|
|
118
118
|
const target = approvalTargetChip(approval, summary)
|
|
119
|
+
const decidedBy = String(approval.decided_by ?? '')
|
|
120
|
+
// 免审回显(DSHBOTS-365):auto:rule:* 前缀区分自动/人工放行,decided_by 进 pill title 可溯源。
|
|
121
|
+
const autoAllowed = status === 'allowed' && decidedBy.startsWith('auto:')
|
|
119
122
|
const pillTone = status === 'allowed' ? 'is-allowed' : status === 'rejected' ? 'is-rejected' : 'is-muted'
|
|
120
123
|
const pillText = status === 'allowed' && approval.decided_at
|
|
121
|
-
? `${APPROVAL_STATUS.allowed} ${formatTime(approval.decided_at)}`
|
|
124
|
+
? `${autoAllowed ? t("规则自动放行") : APPROVAL_STATUS.allowed} ${formatTime(approval.decided_at)}`
|
|
122
125
|
: (APPROVAL_STATUS[status] ?? status)
|
|
123
126
|
return `<div class="message-row">
|
|
124
127
|
<div class="message-body-wrap approval-card" data-approval-status="${attr(approval.status)}" data-approval-id="${attr(approval.id)}">
|
|
@@ -138,7 +141,7 @@ function approvalCardMarkup(approval, deciding = false, showSource = false) {
|
|
|
138
141
|
<button class="btn small primary" data-action="approval-decide" data-approval-id="${attr(approval.id)}" data-decision="allow"${deciding ? ' disabled' : ''}>${t("允许一次")}</button>
|
|
139
142
|
<button class="btn small danger" data-action="approval-decide" data-approval-id="${attr(approval.id)}" data-decision="reject"${deciding ? ' disabled' : ''}>${t("拒绝")}</button>
|
|
140
143
|
</div>`
|
|
141
|
-
: `<div class="approval-foot"><span class="approval-pill ${pillTone}"${approval.decided_at ? ` title="${attr(formatTime(approval.decided_at))}"` : ''}>${esc(pillText)}</span></div>`}
|
|
144
|
+
: `<div class="approval-foot"><span class="approval-pill ${pillTone}"${approval.decided_at ? ` title="${attr(decidedBy ? `${formatTime(approval.decided_at)} · ${decidedBy}` : formatTime(approval.decided_at))}"` : ''}>${esc(pillText)}</span></div>`}
|
|
142
145
|
</div>
|
|
143
146
|
</div>`
|
|
144
147
|
}
|
|
@@ -520,7 +523,7 @@ function renderMessage(message) {
|
|
|
520
523
|
return `<div class="message-row ${isUser ? 'user' : ''}">
|
|
521
524
|
${isUser ? '' : avatar(bot ?? { name: message.senderName, color: 'gray' })}
|
|
522
525
|
<div class="message-body-wrap">
|
|
523
|
-
<div class="message-meta"><strong>${esc(message.senderName)}</strong><span>${esc(formatTime(message.created_at))}</span>${quoteBtn}${copyBtn}</div>
|
|
526
|
+
<div class="message-meta"><strong title="${attr(message.senderName)}">${esc(message.senderName)}</strong><span>${esc(formatTime(message.created_at))}</span>${quoteBtn}${copyBtn}</div>
|
|
524
527
|
${bubbleHtml}
|
|
525
528
|
${renderMessageImages(message.images)}
|
|
526
529
|
${chipsLine}
|
package/ui/modules/chat.js
CHANGED
|
@@ -278,7 +278,7 @@ function renderChat() {
|
|
|
278
278
|
${open.length === 0 ? `<div class="faint">${t('card.noActiveTasks')}</div>` : `<div class="side-list">
|
|
279
279
|
${open.map(task => {
|
|
280
280
|
const bot = botById(task.assignee_bot_id)
|
|
281
|
-
return `<div class="side-row" data-action="open-task" data-task-id="${attr(task.id)}" style="cursor:pointer">
|
|
281
|
+
return `<div class="side-row" role="button" tabindex="0" data-action="open-task" data-task-id="${attr(task.id)}" style="cursor:pointer">
|
|
282
282
|
${sideRowStatusHtml(task.status)}
|
|
283
283
|
<strong>${esc(task.identifier)}</strong>
|
|
284
284
|
<span class="side-row-title">${esc(task.title)}</span>
|
package/ui/modules/composer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { state } from './state.js'
|
|
2
2
|
import { icon } from './icons.js'
|
|
3
|
-
import { activeProject, attr, avatar, botById, esc, toast } from './util.js'
|
|
3
|
+
import { activeProject, attr, avatar, botById, esc, overlayInertState, setAppInert, toast } from './util.js'
|
|
4
4
|
import { api, loadState } from './api.js'
|
|
5
5
|
import { applyOptimisticTyping } from './typing-linger.js'
|
|
6
6
|
import { t } from './i18n.js'
|
|
@@ -479,6 +479,8 @@ async function openMessageImage(imageId) {
|
|
|
479
479
|
const nameEl = document.getElementById('image-viewer-name')
|
|
480
480
|
const sizeEl = document.getElementById('image-viewer-size')
|
|
481
481
|
viewer.hidden = false
|
|
482
|
+
// 查看器也是遮罩:背景 #app 置 inert(DSHBOTS-367)。
|
|
483
|
+
setAppInert(overlayInertState())
|
|
482
484
|
body.textContent = t("图片加载中…")
|
|
483
485
|
if (nameEl) nameEl.textContent = ''
|
|
484
486
|
if (sizeEl) sizeEl.textContent = ''
|
|
@@ -506,6 +508,8 @@ function closeImageViewer() {
|
|
|
506
508
|
img.removeAttribute('src')
|
|
507
509
|
}
|
|
508
510
|
viewer.hidden = true
|
|
511
|
+
// 查看器关闭:背景解锁(弹窗仍开着时保持 inert)。
|
|
512
|
+
setAppInert(overlayInertState())
|
|
509
513
|
// 遮罩关闭:补上查看器开着期间被跳过的 #app 渲染(DSHBOTS-98)。
|
|
510
514
|
flushAppRender()
|
|
511
515
|
}
|
|
@@ -529,6 +533,7 @@ function openInlineImage(img) {
|
|
|
529
533
|
document.getElementById('image-viewer-name').textContent = name
|
|
530
534
|
document.getElementById('image-viewer-size').textContent = ''
|
|
531
535
|
viewer.hidden = false
|
|
536
|
+
setAppInert(overlayInertState())
|
|
532
537
|
body.textContent = ''
|
|
533
538
|
const view = document.createElement('img')
|
|
534
539
|
view.className = 'image-viewer-img'
|
|
@@ -113,6 +113,12 @@ export async function handleBoardAction(action, target) {
|
|
|
113
113
|
render()
|
|
114
114
|
break
|
|
115
115
|
}
|
|
116
|
+
// 控制台页 tab 分页容器:切换激活分组,只重渲染当前页。
|
|
117
|
+
case 'page-tab': {
|
|
118
|
+
state.pageTab = target.dataset.tab || null
|
|
119
|
+
render()
|
|
120
|
+
break
|
|
121
|
+
}
|
|
116
122
|
case 'set-color-scheme': {
|
|
117
123
|
// 明暗三档:跟随宿主/系统、日间、夜间;手动档压过自动判定,落盘后即时生效。
|
|
118
124
|
const pref = setColorSchemePreference(target.dataset.colorScheme)
|
|
@@ -153,6 +159,21 @@ export async function handleBoardAction(action, target) {
|
|
|
153
159
|
toast(t('toast.uiLanguageSaved'), 'success')
|
|
154
160
|
break
|
|
155
161
|
}
|
|
162
|
+
// 运行参数(全局设置「运行参数」卡):整卡收集 data-runtime-setting 元素按 key 提交。
|
|
163
|
+
// 空值语义由后端定义:空串 = 清除保存值回默认(bool 下拉有显式「跟随默认」空项)。
|
|
164
|
+
case 'save-runtime-settings': {
|
|
165
|
+
const patch = {}
|
|
166
|
+
for (const el of document.querySelectorAll ('[data-runtime-setting]')) {
|
|
167
|
+
const key = el.dataset.runtimeSetting
|
|
168
|
+
if (key) patch[key] = el.value
|
|
169
|
+
}
|
|
170
|
+
const payload = { patch }
|
|
171
|
+
if (Number.isFinite(Number(state.data?.settingsRevision))) payload.revision = state.data?.settingsRevision
|
|
172
|
+
await api('update_settings', payload)
|
|
173
|
+
await loadState(state.projectId)
|
|
174
|
+
toast(t('运行参数已保存,即时生效(env 显式设置仍优先)'), 'success')
|
|
175
|
+
break
|
|
176
|
+
}
|
|
156
177
|
case 'save-run-limits': {
|
|
157
178
|
await saveSettingsWithMerge(
|
|
158
179
|
{
|
|
@@ -180,6 +201,33 @@ export async function handleBoardAction(action, target) {
|
|
|
180
201
|
toast(t("已恢复默认指令"), 'success')
|
|
181
202
|
break
|
|
182
203
|
}
|
|
204
|
+
// 审批免审规则(DSHBOTS-365):服务端权威整表替换——保存 = 存量行 + 新增行全量收集;
|
|
205
|
+
// 删除 = 去掉该行后整表提交。校验在后端(主维度必填一项等),失败经 api 报错 toast。
|
|
206
|
+
case 'save-approval-rules':
|
|
207
|
+
case 'approval-rule-delete': {
|
|
208
|
+
const removeId = action === 'approval-rule-delete' ? target.dataset.ruleId : null
|
|
209
|
+
const readRow = (row ) => {
|
|
210
|
+
if (!row) return null
|
|
211
|
+
const value = (name ) => (row.querySelector(`[data-field="${name}"]`) )?.value ?? ''
|
|
212
|
+
const item = {
|
|
213
|
+
path_prefix: value('path_prefix'), command: value('command'), bot_id: value('bot_id'),
|
|
214
|
+
tool_name: value('tool_name'), sandbox: value('sandbox'), note: value('note'),
|
|
215
|
+
}
|
|
216
|
+
return item.path_prefix.trim() || item.command.trim() ? item : null
|
|
217
|
+
}
|
|
218
|
+
const rules = []
|
|
219
|
+
for (const row of document.querySelectorAll ('[data-approval-rule-id]')) {
|
|
220
|
+
if (removeId && row.dataset.approvalRuleId === removeId) continue
|
|
221
|
+
const item = readRow(row)
|
|
222
|
+
if (item) rules.push({ ...item, id: row.dataset.approvalRuleId })
|
|
223
|
+
}
|
|
224
|
+
const fresh = readRow(document.getElementById('approval-rule-new'))
|
|
225
|
+
if (fresh) rules.push(fresh)
|
|
226
|
+
await api('update_approval_rules', { rules })
|
|
227
|
+
await loadState(state.projectId)
|
|
228
|
+
toast(action === 'approval-rule-delete' ? t("规则已删除") : t("审批免审规则已保存"), 'success')
|
|
229
|
+
break
|
|
230
|
+
}
|
|
183
231
|
case 'reconcile-usage': {
|
|
184
232
|
const result = await api('reconcile_usage', {})
|
|
185
233
|
const reconciliation = result?.reconciliation ?? {}
|
|
@@ -6,6 +6,7 @@ import { COMPOSER_AUTO_MAX_PX, addPendingImages, applyAutocomplete, applyCompose
|
|
|
6
6
|
import { questionDraftOf } from './cards.js'
|
|
7
7
|
import { searchMemories } from './tasks.js'
|
|
8
8
|
import { closeModal, trapModalFocus, updateEffortOptions, updateFallbackEffortOptions } from './modal-forms.js'
|
|
9
|
+
import { openTaskMenuForElement } from './task-menu.js'
|
|
9
10
|
import { UI_SCALE_KEY, renderShell, renderKeepingChatScroll, panelKey, applyPanelToggle, nextChatAtBottom, render, refresh } from '../app.js'
|
|
10
11
|
import { t } from './i18n.js'
|
|
11
12
|
|
|
@@ -67,11 +68,53 @@ document.addEventListener('change', (event) => {
|
|
|
67
68
|
}
|
|
68
69
|
})
|
|
69
70
|
|
|
71
|
+
// ===== keyboard-activation:start —— 纯逻辑标记块(tests/task-a11y.test.js 抽取断言)=====
|
|
72
|
+
// 原生自带键盘激活的标签:这些元素上的 Enter/Space 交给浏览器,不重复派发。
|
|
73
|
+
const NATIVE_ACTIVATION_TAGS = ['BUTTON', 'A', 'INPUT', 'SELECT', 'TEXTAREA', 'SUMMARY']
|
|
74
|
+
// 纯判定:给定按键、载体标签、以及事件目标到载体之间的标签链,
|
|
75
|
+
// 判断这次 keydown 是否该由「非 button 载体」(任务卡 article、侧栏行 div)自行激活。
|
|
76
|
+
// repeat:长按不放时 keydown 会连发,卡片会被反复打开——按住时只认第一次。
|
|
77
|
+
function activationDecision({ key, carrierTag, chainTags, repeat }) {
|
|
78
|
+
if (key !== 'Enter' && key !== ' ' && key !== 'Spacebar') return false
|
|
79
|
+
if (repeat) return false
|
|
80
|
+
if (!carrierTag) return false
|
|
81
|
+
if (NATIVE_ACTIVATION_TAGS.includes(carrierTag)) return false
|
|
82
|
+
return !(chainTags ?? []).some(tag => NATIVE_ACTIVATION_TAGS.includes(tag))
|
|
83
|
+
}
|
|
84
|
+
// ===== keyboard-activation:end =====
|
|
85
|
+
|
|
86
|
+
// 定位本次 keydown 的动作载体:最近的 [data-action],以及目标到载体之间的标签链。
|
|
87
|
+
function activationCarrier(target) {
|
|
88
|
+
const el = target
|
|
89
|
+
const carrier = el?.closest?.('[data-action]')
|
|
90
|
+
// 遮罩本身也是 [data-action](点击遮罩关弹窗),但它不是键盘动作载体:
|
|
91
|
+
// 弹窗内无可聚焦元素时焦点会落在 .modal 上,此时 Space 不该顺手关掉弹窗。
|
|
92
|
+
if (!carrier || carrier.classList?.contains('modal-backdrop')) return { carrier: null, chain: [] }
|
|
93
|
+
const chain = []
|
|
94
|
+
for (let node = el; node && node !== carrier; node = node.parentElement) chain.push(node.tagName)
|
|
95
|
+
return { carrier, chain }
|
|
96
|
+
}
|
|
97
|
+
|
|
70
98
|
document.addEventListener('keydown', (event) => {
|
|
71
99
|
if (event.key === 'Tab' && state.modal) {
|
|
72
100
|
trapModalFocus(event)
|
|
73
101
|
return
|
|
74
102
|
}
|
|
103
|
+
// 通用键盘激活(DSHBOTS-367):任务卡(article)与侧栏行(div)不是原生可激活元素,
|
|
104
|
+
// Enter/Space 由这里代为派发 click;原生按钮/链接不在此重复触发。
|
|
105
|
+
const { carrier, chain } = activationCarrier(event.target)
|
|
106
|
+
if (activationDecision({ key: event.key, carrierTag: carrier?.tagName, chainTags: chain, repeat: event.repeat })) {
|
|
107
|
+
event.preventDefault()
|
|
108
|
+
carrier?.click()
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
// 菜单键 / Shift+F10:开任务卡上下文菜单——键盘跨列移动的入口。
|
|
112
|
+
if (event.key === 'ContextMenu' || (event.key === 'F10' && event.shiftKey)) {
|
|
113
|
+
if (openTaskMenuForElement(event.target )) {
|
|
114
|
+
event.preventDefault()
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
}
|
|
75
118
|
const tab = (event.target ).closest?.('[role="tab"]')
|
|
76
119
|
if (tab && ['ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(event.key)) {
|
|
77
120
|
event.preventDefault()
|
|
@@ -3,6 +3,7 @@ import { activeProject, toast } from './util.js'
|
|
|
3
3
|
import { api, loadState } from './api.js'
|
|
4
4
|
import { closeModal, normalizeTimeBudgetMinutes, openTask, parseFallbackFields, reloadTaskModal } from './modal-forms.js'
|
|
5
5
|
import { saveTaskFromForm } from './composer.js'
|
|
6
|
+
import { validateForm } from './form-validation.js'
|
|
6
7
|
import { loadSoloDetail } from './chat.js'
|
|
7
8
|
import { refresh, startTerminalPoll, render, formPayload } from '../app.js'
|
|
8
9
|
import { t } from './i18n.js'
|
|
@@ -11,8 +12,20 @@ document.addEventListener('submit', async (event) => {
|
|
|
11
12
|
const form = (event.target ).closest('form[data-form]')
|
|
12
13
|
if (!form) return
|
|
13
14
|
event.preventDefault()
|
|
15
|
+
// 表单内联校验(DSHBOTS-367):非法字段就地报错并把焦点交给第一个非法字段,
|
|
16
|
+
// 校验不过就不进后端。原生约束校验的即时错误由 form-validation 模块接管。
|
|
17
|
+
if (!validateForm(form)) return
|
|
14
18
|
const type = form.dataset.form
|
|
15
19
|
const payload = formPayload(form)
|
|
20
|
+
// 提交在途时按钮出 spinner 并播报 aria-busy。只接这一处中央路径,全部表单类型自动
|
|
21
|
+
// 生效。弹窗的提交按钮靠 form= 挂在 .modal-foot 里、并不在 form 子树内,只有
|
|
22
|
+
// SubmitEvent.submitter 能拿到真正触发提交的那一个。
|
|
23
|
+
const submitter = (event ).submitter
|
|
24
|
+
const wasDisabled = submitter?.disabled ?? false
|
|
25
|
+
if (submitter) {
|
|
26
|
+
submitter.setAttribute('aria-busy', 'true')
|
|
27
|
+
submitter.disabled = true
|
|
28
|
+
}
|
|
16
29
|
try {
|
|
17
30
|
if (type === 'create-project') {
|
|
18
31
|
const result = await api('create_project', {
|
|
@@ -251,6 +264,13 @@ document.addEventListener('submit', async (event) => {
|
|
|
251
264
|
}
|
|
252
265
|
} catch (error ) {
|
|
253
266
|
toast(error.message || String(error), 'error')
|
|
267
|
+
} finally {
|
|
268
|
+
// 成功路径常已 closeModal()/refresh() 把按钮换成新节点,这里恢复的是旧引用,
|
|
269
|
+
// 对已脱离文档的节点写属性无副作用;失败路径按钮还在,必须收回忙态让用户能重试。
|
|
270
|
+
if (submitter) {
|
|
271
|
+
submitter.removeAttribute('aria-busy')
|
|
272
|
+
submitter.disabled = wasDisabled
|
|
273
|
+
}
|
|
254
274
|
}
|
|
255
275
|
})
|
|
256
276
|
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// ui/modules/form-validation.ts —— 集中式表单内联校验(DSHBOTS-367)。
|
|
2
|
+
// 口径:视觉状态用原生 :user-invalid,程序化状态用 aria-invalid + aria-describedby,
|
|
3
|
+
// 两者同一时刻切换——错误文案只在字段确实非法时挂进 aria-describedby,
|
|
4
|
+
// 文案走应用内词典(随界面语言),不依赖浏览器原生气泡。
|
|
5
|
+
import { t } from './i18n.js'
|
|
6
|
+
|
|
7
|
+
const FIELD_SELECTOR = 'input, select, textarea'
|
|
8
|
+
|
|
9
|
+
// ===== form-validation:start —— 纯逻辑标记块(tests/task-a11y.test.js 抽取断言)=====
|
|
10
|
+
// 约束类型 → 错误文案键。顺序即优先级:缺失 > 类型 > 模式 > 长度 > 数值范围 > 步长。
|
|
11
|
+
const CONSTRAINT_KEYS = {
|
|
12
|
+
valueMissing: 'form.errorRequired',
|
|
13
|
+
typeMismatch: 'form.errorTypeMismatch',
|
|
14
|
+
patternMismatch: 'form.errorPatternMismatch',
|
|
15
|
+
tooShort: 'form.errorTooShort',
|
|
16
|
+
tooLong: 'form.errorTooLong',
|
|
17
|
+
rangeUnderflow: 'form.errorRangeUnderflow',
|
|
18
|
+
rangeOverflow: 'form.errorRangeOverflow',
|
|
19
|
+
stepMismatch: 'form.errorStepMismatch',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 取第一个命中的约束名;全部合法返回空串。
|
|
23
|
+
function constraintOf(validity) {
|
|
24
|
+
if (!validity) return ''
|
|
25
|
+
for (const name of Object.keys(CONSTRAINT_KEYS)) {
|
|
26
|
+
if (validity[name]) return name
|
|
27
|
+
}
|
|
28
|
+
return ''
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 约束名 → i18n 键;未知约束返回空串(不渲染错误)。
|
|
32
|
+
function errorKeyOf(constraint) {
|
|
33
|
+
return Object.prototype.hasOwnProperty.call(CONSTRAINT_KEYS, constraint) ? CONSTRAINT_KEYS[constraint] : ''
|
|
34
|
+
}
|
|
35
|
+
// ===== form-validation:end =====
|
|
36
|
+
|
|
37
|
+
// 不参与校验的控件:隐藏域、禁用域、只读域。
|
|
38
|
+
function skippable(field) {
|
|
39
|
+
return field.type === 'hidden' || field.disabled || field.readOnly
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 字段可访问名:优先 label 文本,其次 name,最后 id。
|
|
43
|
+
function fieldLabel(field) {
|
|
44
|
+
const labels = field.labels
|
|
45
|
+
const el = labels && labels.length ? labels[0] : null
|
|
46
|
+
const text = el ? String(el.textContent ?? '').trim() : ''
|
|
47
|
+
return text || field.getAttribute('name') || field.id || t('form.thisField')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 错误文案:按约束类型取词典条目,缺省参数填字段名与阈值。
|
|
51
|
+
function messageFor(field) {
|
|
52
|
+
const key = errorKeyOf(constraintOf(field.validity))
|
|
53
|
+
if (!key) return ''
|
|
54
|
+
const params = { label: fieldLabel(field) }
|
|
55
|
+
if (Number(field.minLength) > 0) params.min = field.minLength
|
|
56
|
+
if (Number(field.maxLength) > 0) params.max = field.maxLength
|
|
57
|
+
if (field.min !== '' && field.min !== undefined) params.min = field.min
|
|
58
|
+
if (field.max !== '' && field.max !== undefined) params.max = field.max
|
|
59
|
+
if (field.step) params.step = field.step
|
|
60
|
+
return t(key, params)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 错误节点:始终留在 DOM 里(隐藏),只在非法时被 aria-describedby 引用。
|
|
64
|
+
function errorNode(field) {
|
|
65
|
+
const id = field.dataset.error || `${field.id || field.getAttribute('name') || 'field'}-error`
|
|
66
|
+
field.dataset.error = id
|
|
67
|
+
let node = document.getElementById(id)
|
|
68
|
+
if (!node) {
|
|
69
|
+
node = document.createElement('div')
|
|
70
|
+
node.className = 'field-error'
|
|
71
|
+
node.id = id
|
|
72
|
+
const holder = field.closest('.field') || field.parentElement
|
|
73
|
+
if (holder) holder.appendChild(node)
|
|
74
|
+
else field.insertAdjacentElement('afterend', node)
|
|
75
|
+
}
|
|
76
|
+
return node
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 错误 id 只在显示期间进 aria-describedby——隐藏文本被引用也会被读屏念出来。
|
|
80
|
+
function linkError(field, shown) {
|
|
81
|
+
const id = field.dataset.error
|
|
82
|
+
if (!id) return
|
|
83
|
+
const ids = (field.getAttribute('aria-describedby') || '').split(/\s+/).filter(token => token && token !== id)
|
|
84
|
+
if (shown) ids.push(id)
|
|
85
|
+
if (ids.length) field.setAttribute('aria-describedby', ids.join(' '))
|
|
86
|
+
else field.removeAttribute('aria-describedby')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function showError(field) {
|
|
90
|
+
const node = errorNode(field)
|
|
91
|
+
node.textContent = messageFor(field)
|
|
92
|
+
node.classList.add('is-visible')
|
|
93
|
+
field.setAttribute('aria-invalid', 'true')
|
|
94
|
+
linkError(field, true)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function clearError(field) {
|
|
98
|
+
const id = field.dataset.error
|
|
99
|
+
if (id) {
|
|
100
|
+
const node = document.getElementById(id)
|
|
101
|
+
if (node) {
|
|
102
|
+
node.textContent = ''
|
|
103
|
+
node.classList.remove('is-visible')
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
field.setAttribute('aria-invalid', 'false')
|
|
107
|
+
linkError(field, false)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// :user-invalid 的降级判定:极老浏览器不支持该伪类时退回 validity。
|
|
111
|
+
function isUserInvalid(field) {
|
|
112
|
+
try {
|
|
113
|
+
return field.matches(':user-invalid')
|
|
114
|
+
} catch {
|
|
115
|
+
return field.validity ? !field.validity.valid : false
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 单字段同步:视觉(错误节点 is-visible)与程序化(aria-invalid/aria-describedby)同步。
|
|
120
|
+
export function syncFieldValidity(field) {
|
|
121
|
+
if (!field || !field.matches?.(FIELD_SELECTOR) || skippable(field)) return true
|
|
122
|
+
const invalid = isUserInvalid(field)
|
|
123
|
+
if (invalid) showError(field)
|
|
124
|
+
else clearError(field)
|
|
125
|
+
return !invalid
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 提交失败后聚焦第一个非法字段——读屏会在焦点落位时念出该字段的错误。
|
|
129
|
+
export function reportInvalid(field) {
|
|
130
|
+
showError(field)
|
|
131
|
+
const form = field.closest?.('form')
|
|
132
|
+
if (!form) return
|
|
133
|
+
const fields = Array.from(form.querySelectorAll(FIELD_SELECTOR))
|
|
134
|
+
const first = fields.find(el => !skippable(el) && !el.validity.valid)
|
|
135
|
+
if (first !== field) return
|
|
136
|
+
try { first.focus() } catch {}
|
|
137
|
+
announce(messageFor(field))
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// 表单级校验:同步所有字段的非法态;返回 true 表示可以继续提交。
|
|
141
|
+
export function validateForm(form) {
|
|
142
|
+
if (!form) return true
|
|
143
|
+
const fields = Array.from(form.querySelectorAll(FIELD_SELECTOR))
|
|
144
|
+
let firstInvalid = null
|
|
145
|
+
for (const field of fields) {
|
|
146
|
+
if (skippable(field)) continue
|
|
147
|
+
if (!syncFieldValidity(field) && !firstInvalid) firstInvalid = field
|
|
148
|
+
}
|
|
149
|
+
// 用户没碰过的必填项在提交瞬间才被判非法:此时 :user-invalid 尚未匹配,按 validity 兜底。
|
|
150
|
+
if (!firstInvalid) {
|
|
151
|
+
for (const field of fields) {
|
|
152
|
+
if (skippable(field)) continue
|
|
153
|
+
if (!field.validity.valid) {
|
|
154
|
+
showError(field)
|
|
155
|
+
if (!firstInvalid) firstInvalid = field
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (firstInvalid) {
|
|
160
|
+
try { firstInvalid.focus() } catch {}
|
|
161
|
+
announce(messageFor(firstInvalid))
|
|
162
|
+
return false
|
|
163
|
+
}
|
|
164
|
+
return true
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// 一个页面一个礼貌播报区:错误出现时念一次(错误节点本身不做 live region)。
|
|
168
|
+
let announcer = null
|
|
169
|
+
function announce(text) {
|
|
170
|
+
if (!text) return
|
|
171
|
+
if (!announcer) {
|
|
172
|
+
announcer = document.createElement('div')
|
|
173
|
+
announcer.className = 'visually-hidden'
|
|
174
|
+
announcer.setAttribute('aria-live', 'polite')
|
|
175
|
+
document.body.appendChild(announcer)
|
|
176
|
+
}
|
|
177
|
+
announcer.textContent = text
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// 原生约束校验:捕获阶段拦下浏览器自带的浮动气泡,改用应用内内联错误。
|
|
181
|
+
document.addEventListener('invalid', event => {
|
|
182
|
+
const field = event.target
|
|
183
|
+
if (!field?.matches?.(FIELD_SELECTOR)) return
|
|
184
|
+
if (!field.closest?.('form[data-form]')) return
|
|
185
|
+
event.preventDefault()
|
|
186
|
+
reportInvalid(field)
|
|
187
|
+
}, true)
|
|
188
|
+
|
|
189
|
+
// 离开字段时按 :user-invalid 同步:非法才显示错误并播报文案。
|
|
190
|
+
document.addEventListener('blur', event => {
|
|
191
|
+
const field = event.target
|
|
192
|
+
if (!field?.matches?.(FIELD_SELECTOR)) return
|
|
193
|
+
if (!field.closest?.('form[data-form]')) return
|
|
194
|
+
if (!syncFieldValidity(field)) announce(messageFor(field))
|
|
195
|
+
}, true)
|
|
196
|
+
|
|
197
|
+
// 输入中:已经被标记为非法的字段,若内容已合法就撤掉错误,否则只更新文案。
|
|
198
|
+
document.addEventListener('input', event => {
|
|
199
|
+
const field = event.target
|
|
200
|
+
if (!field?.matches?.(FIELD_SELECTOR)) return
|
|
201
|
+
if (field.getAttribute('aria-invalid') !== 'true') return
|
|
202
|
+
if (field.validity.valid) clearError(field)
|
|
203
|
+
else showError(field)
|
|
204
|
+
})
|
|
@@ -202,13 +202,15 @@ export function renderSecretsPage() {
|
|
|
202
202
|
const secrets = state.data?.secrets ?? []
|
|
203
203
|
const requests = state.data?.secretRequests ?? []
|
|
204
204
|
const projects = (state.data?.projects ?? []).filter(project => project.status === 'active')
|
|
205
|
+
const navItems = [
|
|
206
|
+
{ id: 's-requests', label: t('secrets.sectionRequests') },
|
|
207
|
+
{ id: 's-list', label: t('secrets.sectionList') },
|
|
208
|
+
{ id: 's-add', label: t('secrets.sectionAdd') },
|
|
209
|
+
]
|
|
210
|
+
const active = navItems.some(item => item.id === state.pageTab) ? state.pageTab : navItems[0].id
|
|
205
211
|
return pageShell(
|
|
206
212
|
pageHead('SECRETS', t('viewTitle.secrets'), t('secrets.desc'), refreshAction()),
|
|
207
|
-
pageNav(
|
|
208
|
-
{ id: 's-requests', label: t('secrets.sectionRequests') },
|
|
209
|
-
{ id: 's-list', label: t('secrets.sectionList') },
|
|
210
|
-
{ id: 's-add', label: t('secrets.sectionAdd') },
|
|
211
|
-
], t('secrets.navLabel')),
|
|
213
|
+
pageNav(navItems, t('secrets.navLabel'), active),
|
|
212
214
|
[
|
|
213
215
|
pageSection({
|
|
214
216
|
index: '01', id: 's-requests', title: t('secrets.sectionRequests'), desc: t('secrets.sectionRequestsDesc'),
|
|
@@ -225,6 +227,7 @@ export function renderSecretsPage() {
|
|
|
225
227
|
body: slot('full', secretAddCard(projects)),
|
|
226
228
|
}),
|
|
227
229
|
],
|
|
230
|
+
active,
|
|
228
231
|
)
|
|
229
232
|
}
|
|
230
233
|
|
|
@@ -496,7 +496,7 @@ function modalTask(task) {
|
|
|
496
496
|
${(task.dependencies ?? []).length ? `<div class="divider"></div><div class="eyebrow" style="margin-bottom:7px">${t("依赖")}</div>${task.dependencies.map(dep => `<div class="kv"><span>${esc(dep.title)}</span><strong>${esc(STATUS[dep.status] ?? dep.status)}</strong></div>`).join('')}` : ''}
|
|
497
497
|
</aside>
|
|
498
498
|
</div>`,
|
|
499
|
-
footer: `<button class="btn" data-action="close-modal">${t("关闭")}</button>${['done', 'canceled'].includes(task.status) ? `<button class="btn danger" type="button" data-action="reject-task" data-task-id="${attr(task.id)}" title="${t('task.rejectTitle')}">${icon('reply')}${t('task.rejectAction')}</button>` : ''}<button class="btn" type="button" data-action="derive-subtask" data-task-id="${attr(task.id)}" title="${t("以本任务为父任务新建子任务")}">${icon('branch')}${t("派生子任务")}</button>${task.status === 'in_review' ? `<button class="btn" type="button" data-action="review-delegate" data-task-id="${attr(task.id)}" title="${t("
|
|
499
|
+
footer: `<button class="btn" data-action="close-modal">${t("关闭")}</button>${['done', 'canceled'].includes(task.status) ? `<button class="btn danger" type="button" data-action="reject-task" data-task-id="${attr(task.id)}" title="${t('task.rejectTitle')}">${icon('reply')}${t('task.rejectAction')}</button>` : ''}<button class="btn" type="button" data-action="derive-subtask" data-task-id="${attr(task.id)}" title="${t("以本任务为父任务新建子任务")}">${icon('branch')}${t("派生子任务")}</button>${task.status === 'in_review' ? `<button class="btn" type="button" data-action="review-delegate" data-task-id="${attr(task.id)}" title="${t("委派子代理并行核验交付(优先 reviewer,无则总监兜底),结论写回任务评论,裁决仍由您执行")}">${icon('spark')}${t("子代理核验")}</button>` : ''}<button class="btn" type="button" data-action="run-task" data-task-id="${attr(task.id)}">${icon('play')}${t("保存并运行")}</button><button class="btn primary" type="submit" form="task-form">${icon('check')}${t("保存")}</button>`,
|
|
500
500
|
})
|
|
501
501
|
}
|
|
502
502
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { state } from './state.js'
|
|
2
|
-
import { attr, esc } from './util.js'
|
|
2
|
+
import { attr, esc, overlayInertState, setAppInert } from './util.js'
|
|
3
3
|
import { render, updateRunClocks } from '../app.js'
|
|
4
4
|
import { modalNewProject, modalRemoveTracking, modalRemoveBotTracking, modalBot, modalInviteMember, modalNewTask, modalTask, modalSkill, modalMemory, modalProposal, modalPrice, modalTrajectory } from './modal-forms.js'
|
|
5
5
|
import { modalFilePreview } from './file-preview.js'
|
|
@@ -109,6 +109,9 @@ function ensureModalRoot(doc = document) {
|
|
|
109
109
|
function renderModalLayer() {
|
|
110
110
|
const root = ensureModalRoot()
|
|
111
111
|
const html = renderModal()
|
|
112
|
+
// 遮罩开合即背景可达性的开关(DSHBOTS-367):#app 置 inert,关闭时还原。
|
|
113
|
+
// typeof 守卫同 updateRunClocks:本块会被测试整段抽出求值,符号不在场时跳过。
|
|
114
|
+
if (typeof setAppInert === 'function') setAppInert(overlayInertState())
|
|
112
115
|
if (html === lastModalHtml) return
|
|
113
116
|
// 滚动守卫闸门(DSHBOTS-154):同一弹窗的刷新在 modal-body 滚动进行中延后——延后期间
|
|
114
117
|
// lastModalHtml 不更新,滚动停止后 scheduleModalPatch 重入时仍能识别「内容变了」并补拍。
|
package/ui/modules/page-shell.js
CHANGED
|
@@ -24,10 +24,11 @@ export function refreshAction() {
|
|
|
24
24
|
return `<button class="btn icon" data-action="refresh" title="${label}" aria-label="${label}">${icon('refresh')}</button>`
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
// 分组导航(tab 分页容器):仅当页面有 2 个及以上分组时出现;
|
|
28
|
+
// 同一时刻只渲染激活分组,长页由此拆成等高的分页(任务看板除外,不经过本壳)。
|
|
29
|
+
export function pageNav(items, label, activeId) {
|
|
30
|
+
return `<nav class="global-nav" role="tablist" aria-label="${label}">
|
|
31
|
+
${items.map(item => `<button type="button" role="tab" class="global-nav-item${item.id === activeId ? ' active' : ''}" data-action="page-tab" data-tab="${item.id}" aria-selected="${item.id === activeId}">${item.label}</button>`).join('')}
|
|
31
32
|
</nav>`
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -47,12 +48,14 @@ export function pageSection(section) {
|
|
|
47
48
|
</section>`
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
// 页面壳:页头 + 导航 + 分组。sections 为 pageSection 的markup
|
|
51
|
-
|
|
51
|
+
// 页面壳:页头 + 导航 + 分组。sections 为 pageSection 的markup 数组;
|
|
52
|
+
// activeTab 非空时只保留该分组(tab 分页),为空时全量渲染。
|
|
53
|
+
export function pageShell(head, nav, sections, activeTab = '') {
|
|
54
|
+
const visible = activeTab ? sections.filter(markup => markup.includes(`id="${activeTab}"`)) : sections
|
|
52
55
|
return `<div class="global-page">
|
|
53
56
|
${head}
|
|
54
57
|
${nav ?? ''}
|
|
55
|
-
${
|
|
58
|
+
${visible.join('')}
|
|
56
59
|
</div>`
|
|
57
60
|
}
|
|
58
61
|
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { state } from './state.js'
|
|
2
|
+
import { t } from './i18n.js'
|
|
3
|
+
import { icon } from './icons.js'
|
|
4
|
+
import { attr, botById, esc } from './util.js'
|
|
5
|
+
import { panelAttrs } from '../app.js'
|
|
6
|
+
|
|
7
|
+
// 免审权限卡(DSHBOTS-365 编辑面在总览 bots 页):每条规则只露两件事——路径 glob 与命令 glob,
|
|
8
|
+
// 其余条件收进「更多条件」里,折叠态一行 chip 摘要占位。
|
|
9
|
+
// 服务端权威不变:保存 = 全量收集行 → update_approval_rules 整表替换;删除 = 去行后整表提交;
|
|
10
|
+
// 改规则即时生效,每次调用一放行一结。
|
|
11
|
+
const APPROVAL_RULE_SANDBOXES = ['', 'workspace-write', 'danger-full-access']
|
|
12
|
+
|
|
13
|
+
function approvalRuleFields(rule ) {
|
|
14
|
+
const bots = (state.data?.bots ?? [])
|
|
15
|
+
const hasMore = Boolean(rule.bot_id || rule.tool_name || rule.sandbox || rule.note)
|
|
16
|
+
return `
|
|
17
|
+
<div class="field-row">
|
|
18
|
+
<div class="field">
|
|
19
|
+
<span class="field-label">${t('global.approvalRulePath')}</span>
|
|
20
|
+
<input class="input mono" data-field="path_prefix" value="${attr(rule.path_prefix ?? '')}" placeholder="${attr(t('global.approvalRulePathExample'))}" maxlength="500">
|
|
21
|
+
<div class="hint">${t('global.approvalRulePathHint')}</div>
|
|
22
|
+
</div>
|
|
23
|
+
<div class="field">
|
|
24
|
+
<span class="field-label">${t('global.approvalRuleCommand')}</span>
|
|
25
|
+
<input class="input mono" data-field="command" value="${attr(rule.command ?? '')}" placeholder="${attr(t('global.approvalRuleCommandExample'))}" maxlength="200">
|
|
26
|
+
<div class="hint">${t('global.approvalRuleCommandHint')}</div>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
<details class="perm-more"${hasMore ? ' open' : ''}>
|
|
30
|
+
<summary class="perm-more-head">${t('global.approvalRuleMore')}</summary>
|
|
31
|
+
<div class="field-row">
|
|
32
|
+
<div class="field">
|
|
33
|
+
<span class="field-label">${t('global.approvalRuleBot')}</span>
|
|
34
|
+
<select class="select" data-field="bot_id"><option value="">${t('global.approvalRuleAny')}</option>${bots.map(bot => `<option value="${attr(bot.id)}" ${bot.id === (rule.bot_id ?? '') ? 'selected' : ''}>${esc(bot.name)}</option>`).join('')}</select>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="field">
|
|
37
|
+
<span class="field-label">${t('global.approvalRuleTool')}</span>
|
|
38
|
+
<input class="input mono" data-field="tool_name" value="${attr(rule.tool_name ?? '')}" placeholder="bash" maxlength="100">
|
|
39
|
+
</div>
|
|
40
|
+
<div class="field">
|
|
41
|
+
<span class="field-label">${t('global.approvalRuleSandbox')}</span>
|
|
42
|
+
<select class="select" data-field="sandbox">${APPROVAL_RULE_SANDBOXES.map(tier => `<option value="${tier}" ${tier === (rule.sandbox ?? '') ? 'selected' : ''}>${tier === '' ? t('global.approvalRuleAny') : tier}</option>`).join('')}</select>
|
|
43
|
+
</div>
|
|
44
|
+
<div class="field">
|
|
45
|
+
<span class="field-label">${t('global.approvalRuleNote')}</span>
|
|
46
|
+
<input class="input" data-field="note" value="${attr(rule.note ?? '')}" maxlength="200">
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
</details>`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 摘要行:只显示已设的条件,标签带在 chip 里,不让占位文案看起来像真值。
|
|
53
|
+
function approvalRuleChips(rule ) {
|
|
54
|
+
const chip = (labelKey , value ) => `<span class="approval-chip mono">${t(labelKey)} ${esc(value)}</span>`
|
|
55
|
+
const chips = []
|
|
56
|
+
if (rule.path_prefix) chips.push(chip('global.approvalRuleChipPath', rule.path_prefix))
|
|
57
|
+
if (rule.command) chips.push(chip('global.approvalRuleChipCommand', rule.command))
|
|
58
|
+
if (rule.bot_id) chips.push(chip('global.approvalRuleChipBot', botById(rule.bot_id)?.name ?? rule.bot_id))
|
|
59
|
+
if (rule.tool_name) chips.push(chip('global.approvalRuleChipTool', rule.tool_name))
|
|
60
|
+
if (rule.sandbox) chips.push(chip('global.approvalRuleChipSandbox', rule.sandbox))
|
|
61
|
+
if (rule.note) chips.push(chip('global.approvalRuleChipNote', rule.note))
|
|
62
|
+
return chips.join('')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function renderApprovalPermissionsCard() {
|
|
66
|
+
const rules = (state.data?.approvalRules ?? [])
|
|
67
|
+
const ruleBody = (rule , removeId ) => `
|
|
68
|
+
<div class="perm-rule-body">
|
|
69
|
+
${approvalRuleFields(rule)}
|
|
70
|
+
<div class="btn-row">
|
|
71
|
+
${removeId ? `<button class="btn small danger" type="button" data-action="approval-rule-delete" data-rule-id="${attr(removeId)}">${t('global.approvalRuleDelete')}</button>` : ''}
|
|
72
|
+
<button class="btn small primary" type="button" data-action="save-approval-rules">${t('global.saveApprovalRules')}</button>
|
|
73
|
+
</div>
|
|
74
|
+
</div>`
|
|
75
|
+
return `
|
|
76
|
+
<section class="perm-section">
|
|
77
|
+
<div class="section-head">
|
|
78
|
+
<h3>${t('global.approvalPermissionsTitle')}</h3>
|
|
79
|
+
<span class="meta">${t('global.approvalRulesMeta', { count: rules.length })}</span>
|
|
80
|
+
</div>
|
|
81
|
+
<div class="card perm-card">
|
|
82
|
+
${rules.length === 0 ? `<div class="faint perm-empty">${t('global.approvalRulesEmpty')}</div>` : ''}
|
|
83
|
+
${rules.map(rule => `
|
|
84
|
+
<details class="perm-rule" data-approval-rule-id="${attr(rule.id)}"${panelAttrs(state, `approval-rule:${rule.id}`)}>
|
|
85
|
+
<summary class="perm-rule-head">
|
|
86
|
+
${approvalRuleChips(rule)}
|
|
87
|
+
${icon('chevron', 'perm-chev')}
|
|
88
|
+
</summary>${ruleBody(rule, rule.id)}
|
|
89
|
+
</details>`).join('')}
|
|
90
|
+
<details class="perm-rule perm-rule-new" id="approval-rule-new"${panelAttrs(state, 'approval-rule:new')}>
|
|
91
|
+
<summary class="perm-rule-head"><span class="perm-add">${icon('plus')}${t('global.approvalRuleAdd')}</span></summary>
|
|
92
|
+
${ruleBody({ path_prefix: '', command: '', bot_id: '', tool_name: '', sandbox: '', note: '' }, '')}
|
|
93
|
+
</details>
|
|
94
|
+
<div class="hint">${t('global.approvalRulesHint')}</div>
|
|
95
|
+
</div>
|
|
96
|
+
</section>`
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { renderApprovalPermissionsCard }
|