dsh-team-bots 0.3.12 → 0.3.70
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 +55 -4
- package/src/db.js +30 -3
- package/src/http.js +21 -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 +303 -10
- package/src/services/bots.js +12 -3
- 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 +116 -32
- package/src/services/scheduler.js +20 -0
- package/src/services/system.js +164 -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 +14 -0
- package/ui/i18n/en/settings.js +81 -1
- package/ui/i18n/en/tasks.js +3 -0
- package/ui/i18n/zh/chat.js +2 -0
- package/ui/i18n/zh/common.js +14 -0
- package/ui/i18n/zh/settings.js +81 -1
- package/ui/i18n/zh/tasks.js +3 -0
- package/ui/modules/api.js +9 -1
- package/ui/modules/approval-rule-modal.js +31 -0
- package/ui/modules/cards.js +6 -3
- package/ui/modules/chat.js +3 -2
- package/ui/modules/composer.js +6 -1
- package/ui/modules/events-board.js +46 -0
- package/ui/modules/events-misc.js +43 -0
- package/ui/modules/events-submit.js +45 -0
- package/ui/modules/form-validation.js +204 -0
- package/ui/modules/global-pages.js +8 -5
- package/ui/modules/modal-forms.js +3 -2
- package/ui/modules/modal-layer.js +6 -1
- package/ui/modules/page-shell.js +10 -7
- package/ui/modules/permissions.js +56 -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 +58 -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 +54 -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 +4 -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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { state } from './state.js'
|
|
2
|
+
import { t } from './i18n.js'
|
|
3
|
+
import { icon } from './icons.js'
|
|
4
|
+
import { attr, esc } from './util.js'
|
|
5
|
+
import { modalShell } from './modal-layer.js'
|
|
6
|
+
import { APPROVAL_RULE_SANDBOXES } from './permissions.js'
|
|
7
|
+
|
|
8
|
+
// 免审规则新增/编辑弹窗:rule 为 null 即新增。保存走整表替换(events-submit 的
|
|
9
|
+
// save-approval-rule):编辑保 id、新增不带 id 由后端发 arul_*。
|
|
10
|
+
export function modalApprovalRule(rule = null) {
|
|
11
|
+
const bots = (state.data?.bots ?? [])
|
|
12
|
+
const value = (key ) => attr(String(rule?.[key] ?? ''))
|
|
13
|
+
return modalShell({
|
|
14
|
+
title: rule ? t("编辑免审规则") : t("新增免审规则"),
|
|
15
|
+
badge: '',
|
|
16
|
+
body: `<form data-form="save-approval-rule" id="modal-form">
|
|
17
|
+
<input type="hidden" name="ruleId" value="${value('id')}">
|
|
18
|
+
<div class="field-row">
|
|
19
|
+
<div class="field"><label id="approval-rule-path-label" for="approval-rule-path">${t('global.approvalRulePath')}</label><input class="input mono" style="width:100%" id="approval-rule-path" name="path_prefix" value="${value('path_prefix')}" placeholder="${attr(t('global.approvalRulePathExample'))}" maxlength="500"><div class="hint">${t('global.approvalRulePathHint')}</div></div>
|
|
20
|
+
<div class="field"><label id="approval-rule-command-label" for="approval-rule-command">${t('global.approvalRuleCommand')}</label><input class="input mono" style="width:100%" id="approval-rule-command" name="command" value="${value('command')}" placeholder="${attr(t('global.approvalRuleCommandExample'))}" maxlength="200"><div class="hint">${t('global.approvalRuleCommandHint')}</div></div>
|
|
21
|
+
</div>
|
|
22
|
+
<div class="field-row">
|
|
23
|
+
<div class="field"><label id="approval-rule-bot-label" for="approval-rule-bot">${t('global.approvalRuleBot')}</label><select class="select" style="width:100%" id="approval-rule-bot" name="bot_id"><option value="">${t('global.approvalRuleAny')}</option>${bots.map(bot => `<option value="${attr(bot.id)}" ${bot.id === String(rule?.bot_id ?? '') ? 'selected' : ''}>${esc(bot.name)}</option>`).join('')}</select></div>
|
|
24
|
+
<div class="field"><label id="approval-rule-tool-label" for="approval-rule-tool">${t('global.approvalRuleTool')}</label><input class="input mono" style="width:100%" id="approval-rule-tool" name="tool_name" value="${value('tool_name')}" placeholder="${attr(t('global.approvalRuleToolPlaceholder'))}" maxlength="100"><div class="hint">${t('global.approvalRuleToolHint')}</div></div>
|
|
25
|
+
<div class="field"><label id="approval-rule-sandbox-label" for="approval-rule-sandbox">${t('global.approvalRuleSandbox')}</label><select class="select" style="width:100%" id="approval-rule-sandbox" name="sandbox">${APPROVAL_RULE_SANDBOXES.map(tier => `<option value="${tier}" ${tier === String(rule?.sandbox ?? '') ? 'selected' : ''}>${tier === '' ? t('global.approvalRuleAny') : tier}</option>`).join('')}</select></div>
|
|
26
|
+
</div>
|
|
27
|
+
<div class="field"><label id="approval-rule-note-label" for="approval-rule-note">${t('global.approvalRuleNote')}</label><input class="input" style="width:100%" id="approval-rule-note" name="note" value="${value('note')}" maxlength="200"></div>
|
|
28
|
+
</form>`,
|
|
29
|
+
footer: `<button class="btn" data-action="close-modal">${t("取消")}</button><button class="btn primary" type="submit" form="modal-form">${icon('check')}${t("保存规则")}</button>`,
|
|
30
|
+
})
|
|
31
|
+
}
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { state, BOT_STATUS, CHAT_ACTIVE_TASK_LIMIT, CHAT_PAGE_SIZE, COLORS, COLOR_NAMES } from './state.js'
|
|
2
2
|
import { icon } from './icons.js'
|
|
3
|
-
import { activeProject, attr, avatar, botById, duration, esc, filePolicyOptions, formatTime, memberRunDot, pathCode, runDotHtml, tildePath, timeAgo, toast } from './util.js'
|
|
3
|
+
import { activeProject, agentPresetOptions, attr, avatar, botById, duration, esc, filePolicyOptions, formatTime, memberRunDot, pathCode, runDotHtml, tildePath, timeAgo, toast } from './util.js'
|
|
4
4
|
import { mdPlainSummary } from './markdown.js'
|
|
5
5
|
import { t } from './i18n.js'
|
|
6
6
|
import { api } from './api.js'
|
|
@@ -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>
|
|
@@ -465,6 +465,7 @@ function renderSoloConfig() {
|
|
|
465
465
|
<div class="field"><label for="solo-bot-model">${t("模型")}</label><select class="select" style="width:100%" id="solo-bot-model" name="modelRef" data-model-select>${modelOptions(bot.provider, bot.model)}</select></div>
|
|
466
466
|
<div class="field"><label for="solo-bot-effort">${t("推理强度")}</label><select class="select" style="width:100%" id="solo-bot-effort" name="effort" data-effort-select>${effortOptions(bot.modelRef ?? '', bot.effort)}</select></div>
|
|
467
467
|
<div class="field"><label for="solo-bot-file-policy">${t("文件权限")}</label><select class="select" style="width:100%" id="solo-bot-file-policy" name="filePolicy" title="Bot ${t("会话内文件操作的沙箱边界,下次运行生效")}">${filePolicyOptions(bot.file_policy)}</select></div>
|
|
468
|
+
<div class="field"><label for="solo-bot-agent-preset">${t("bots.agentPreset")}</label><select class="select" style="width:100%" id="solo-bot-agent-preset" name="agentPreset" title="${t("bots.agentPresetTitle")}">${agentPresetOptions(bot)}</select><div class="hint">${t("bots.agentPresetHint")}</div></div>
|
|
468
469
|
</div>
|
|
469
470
|
<div class="field-row">
|
|
470
471
|
<div class="field"><label for="solo-bot-fallback-model">${t("备用模型")}</label><select class="select" style="width:100%" id="solo-bot-fallback-model" name="fallbackModelRef" data-fallback-model-select title="${t("主模型不可用时自动接手的备用模型,留空")} = ${t("不启用")}">${fallbackModelOptions(bot.fallbackModelRef ?? '')}</select></div>
|
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,31 @@ export async function handleBoardAction(action, target) {
|
|
|
180
201
|
toast(t("已恢复默认指令"), 'success')
|
|
181
202
|
break
|
|
182
203
|
}
|
|
204
|
+
// 审批免审规则(DSHBOTS-365):服务端权威整表替换。新增/编辑拉起 approval-rule 弹窗
|
|
205
|
+
// (表单提交走 events-submit 的 save-approval-rule);删除 = 从 state 规则表去行后整表提交。
|
|
206
|
+
// 校验在后端(主维度必填一项等),失败经 api 报错 toast。
|
|
207
|
+
case 'approval-rule-new':
|
|
208
|
+
case 'approval-rule-edit': {
|
|
209
|
+
const ruleId = action === 'approval-rule-edit' ? target.dataset.ruleId : null
|
|
210
|
+
const rule = ruleId
|
|
211
|
+
? ((state.data?.approvalRules ?? []) ).find(item => item.id === ruleId)
|
|
212
|
+
: null
|
|
213
|
+
openModal({ type: 'approval-rule', rule: rule ? { ...rule } : null })
|
|
214
|
+
break
|
|
215
|
+
}
|
|
216
|
+
case 'approval-rule-delete': {
|
|
217
|
+
const removeId = target.dataset.ruleId
|
|
218
|
+
const rules = ((state.data?.approvalRules ?? []) )
|
|
219
|
+
.filter(item => item.id !== removeId)
|
|
220
|
+
.map(({ id, path_prefix, command, bot_id, tool_name, sandbox, note }) => ({ id, path_prefix, command, bot_id, tool_name, sandbox, note }))
|
|
221
|
+
await api('update_approval_rules', { rules })
|
|
222
|
+
await loadState(state.projectId)
|
|
223
|
+
// loadState 只更新 state.data 不重渲染,且下一次轮询因 since=新版本返回 unchanged,
|
|
224
|
+
// 不主动 render 页面会一直停留在旧规则列表。
|
|
225
|
+
render()
|
|
226
|
+
toast(t("规则已删除"), 'success')
|
|
227
|
+
break
|
|
228
|
+
}
|
|
183
229
|
case 'reconcile-usage': {
|
|
184
230
|
const result = await api('reconcile_usage', {})
|
|
185
231
|
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', {
|
|
@@ -63,6 +76,7 @@ document.addEventListener('submit', async (event) => {
|
|
|
63
76
|
model,
|
|
64
77
|
effort: payload.effort || null,
|
|
65
78
|
filePolicy: payload.filePolicy || undefined,
|
|
79
|
+
agentPreset: payload.agentPreset ?? '',
|
|
66
80
|
fallbackProvider: fallback.fallbackProvider,
|
|
67
81
|
fallbackModel: fallback.fallbackModel,
|
|
68
82
|
fallbackEffort: fallback.fallbackEffort,
|
|
@@ -155,6 +169,30 @@ document.addEventListener('submit', async (event) => {
|
|
|
155
169
|
toast(t("记忆已更新"), 'success')
|
|
156
170
|
return
|
|
157
171
|
}
|
|
172
|
+
if (type === 'save-approval-rule') {
|
|
173
|
+
// 免审规则整表替换:编辑保 id 原位换行,新增不带 id 追加到表尾。
|
|
174
|
+
const ruleId = String(payload.ruleId || '')
|
|
175
|
+
const incoming = {
|
|
176
|
+
path_prefix: String(payload.path_prefix ?? ''),
|
|
177
|
+
command: String(payload.command ?? ''),
|
|
178
|
+
bot_id: String(payload.bot_id ?? ''),
|
|
179
|
+
tool_name: String(payload.tool_name ?? ''),
|
|
180
|
+
sandbox: String(payload.sandbox ?? ''),
|
|
181
|
+
note: String(payload.note ?? ''),
|
|
182
|
+
...(ruleId ? { id: ruleId } : {}),
|
|
183
|
+
}
|
|
184
|
+
const existing = (state.data?.approvalRules ?? [])
|
|
185
|
+
const index = ruleId ? existing.findIndex(item => item.id === ruleId) : -1
|
|
186
|
+
const rules = existing.map(item => ({ id: item.id, path_prefix: item.path_prefix, command: item.command, bot_id: item.bot_id, tool_name: item.tool_name, sandbox: item.sandbox, note: item.note }))
|
|
187
|
+
if (index >= 0) rules[index] = { ...rules[index], ...incoming }
|
|
188
|
+
else rules.push(incoming)
|
|
189
|
+
await api('update_approval_rules', { rules })
|
|
190
|
+
closeModal()
|
|
191
|
+
await loadState(state.projectId, { quiet: true })
|
|
192
|
+
render()
|
|
193
|
+
toast(t("审批免审规则已保存"), 'success')
|
|
194
|
+
return
|
|
195
|
+
}
|
|
158
196
|
if (type === 'create-proposal') {
|
|
159
197
|
const kind = payload.kind
|
|
160
198
|
const proposal = await api('create_proposal', {
|
|
@@ -251,6 +289,13 @@ document.addEventListener('submit', async (event) => {
|
|
|
251
289
|
}
|
|
252
290
|
} catch (error ) {
|
|
253
291
|
toast(error.message || String(error), 'error')
|
|
292
|
+
} finally {
|
|
293
|
+
// 成功路径常已 closeModal()/refresh() 把按钮换成新节点,这里恢复的是旧引用,
|
|
294
|
+
// 对已脱离文档的节点写属性无副作用;失败路径按钮还在,必须收回忙态让用户能重试。
|
|
295
|
+
if (submitter) {
|
|
296
|
+
submitter.removeAttribute('aria-busy')
|
|
297
|
+
submitter.disabled = wasDisabled
|
|
298
|
+
}
|
|
254
299
|
}
|
|
255
300
|
})
|
|
256
301
|
|
|
@@ -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
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { state, STATUS, STATUS_ORDER, PRIORITY, BOT_STATUS, SKILL_STATUS, RUN_STATUS, CREATOR_TYPE, EFFORT, COLORS, COLOR_NAMES, stageLabelText } from './state.js'
|
|
2
2
|
import { icon } from './icons.js'
|
|
3
|
-
import { activeBots, activeProject, attr, avatar, botById, duration, esc, filePolicyOptions, formatCost, formatNumber, formatTime, inSoloContext, pageProject, runDot, sandboxPill, timeAgo, tildePath, toast } from './util.js'
|
|
3
|
+
import { activeBots, activeProject, attr, avatar, botById, duration, esc, filePolicyOptions, agentPresetOptions, formatCost, formatNumber, formatTime, inSoloContext, pageProject, runDot, sandboxPill, timeAgo, tildePath, toast } from './util.js'
|
|
4
4
|
import { api } from './api.js'
|
|
5
5
|
import { mdChatScope, richText } from './markdown.js'
|
|
6
6
|
import { t, tMaybe } from './i18n.js'
|
|
@@ -221,6 +221,7 @@ function modalBot(detail) {
|
|
|
221
221
|
<div class="field"><label id="bot-model-label" for="bot-model">${t("模型")}</label><select class="select" style="width:100%" id="bot-model" name="modelRef" data-model-select>${modelOptions(bot?.provider, bot?.model)}</select></div>
|
|
222
222
|
<div class="field"><label id="bot-effort-label" for="bot-effort">${t("推理强度")}</label><select class="select" style="width:100%" id="bot-effort" name="effort" data-effort-select>${effortOptions(modelRef, bot?.effort)}</select></div>
|
|
223
223
|
<div class="field"><label id="bot-file-policy-label" for="bot-file-policy">${t("文件权限")}</label><select class="select" style="width:100%" id="bot-file-policy" name="filePolicy" title="Bot ${t("会话内文件操作的沙箱边界,下次运行生效")}">${filePolicyOptions(bot?.file_policy)}</select></div>
|
|
224
|
+
<div class="field"><label id="bot-agent-preset-label" for="bot-agent-preset">${t("bots.agentPreset")}</label><select class="select" style="width:100%" id="bot-agent-preset" name="agentPreset" title="${t("bots.agentPresetTitle")}">${agentPresetOptions(bot)}</select><div class="hint">${t("bots.agentPresetHint")}</div></div>
|
|
224
225
|
</div>
|
|
225
226
|
<div class="field-row">
|
|
226
227
|
<div class="field"><label id="bot-fallback-model-label" for="bot-fallback-model">${t("备用模型")}</label><select class="select" style="width:100%" id="bot-fallback-model" name="fallbackModelRef" data-fallback-model-select title="${t("主模型不可用时自动接手的备用模型,留空")} = ${t("不启用")}">${fallbackModelOptions(bot?.fallbackModelRef ?? '')}</select></div>
|
|
@@ -496,7 +497,7 @@ function modalTask(task) {
|
|
|
496
497
|
${(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
498
|
</aside>
|
|
498
499
|
</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("
|
|
500
|
+
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
501
|
})
|
|
501
502
|
}
|
|
502
503
|
|
|
@@ -1,8 +1,9 @@
|
|
|
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'
|
|
6
|
+
import { modalApprovalRule } from './approval-rule-modal.js'
|
|
6
7
|
import { t } from './i18n.js'
|
|
7
8
|
|
|
8
9
|
function modalShell({ title, subtitle = '', body = '', footer = '', size = '', badge = '' }) {
|
|
@@ -42,6 +43,7 @@ function renderModal() {
|
|
|
42
43
|
case 'task': return modalTask(modal.detail)
|
|
43
44
|
case 'skill-detail': return modalSkill(modal.detail)
|
|
44
45
|
case 'memory': return modalMemory(modal.memory)
|
|
46
|
+
case 'approval-rule': return modalApprovalRule(modal.rule)
|
|
45
47
|
case 'proposal': return modalProposal(modal.kind)
|
|
46
48
|
case 'price': return modalPrice(modal.price ?? {})
|
|
47
49
|
case 'trajectory': return modalTrajectory(modal.detail, modal.runId)
|
|
@@ -109,6 +111,9 @@ function ensureModalRoot(doc = document) {
|
|
|
109
111
|
function renderModalLayer() {
|
|
110
112
|
const root = ensureModalRoot()
|
|
111
113
|
const html = renderModal()
|
|
114
|
+
// 遮罩开合即背景可达性的开关(DSHBOTS-367):#app 置 inert,关闭时还原。
|
|
115
|
+
// typeof 守卫同 updateRunClocks:本块会被测试整段抽出求值,符号不在场时跳过。
|
|
116
|
+
if (typeof setAppInert === 'function') setAppInert(overlayInertState())
|
|
112
117
|
if (html === lastModalHtml) return
|
|
113
118
|
// 滚动守卫闸门(DSHBOTS-154):同一弹窗的刷新在 modal-body 滚动进行中延后——延后期间
|
|
114
119
|
// lastModalHtml 不更新,滚动停止后 scheduleModalPatch 重入时仍能识别「内容变了」并补拍。
|