dsh-team-bots 0.2.465 → 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 +5 -0
- package/README.md +8 -2
- package/docs/README.zh.md +8 -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 +16 -2
- package/src/config.js +193 -8
- package/src/db-migrations.js +53 -4
- package/src/db.js +37 -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/bot-quota.js +54 -0
- package/src/services/bots.js +8 -0
- package/src/services/chat.js +54 -5
- package/src/services/core.js +31 -2
- package/src/services/memory.js +112 -25
- package/src/services/model-fallback.js +55 -15
- package/src/services/projects.js +13 -2
- package/src/services/run-finish.js +44 -11
- package/src/services/runs.js +15 -7
- package/src/services/runtime/prompt.js +31 -6
- package/src/services/runtime/session.js +87 -25
- package/src/services/scheduler.js +26 -5
- package/src/services/system.js +162 -10
- package/src/services/task-dispatch.js +24 -0
- package/src/services/task-notify.js +18 -0
- package/src/services/task-review.js +102 -23
- package/src/services/task-runs.js +31 -3
- package/src/services/tasks.js +91 -3
- package/src/tools.js +20 -14
- 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 +76 -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 +76 -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 +4 -4
- 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 +108 -26
- package/ui/modules/state.js +10 -0
- package/ui/modules/task-menu.js +147 -0
- package/ui/modules/tasks.js +11 -10
- 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
|
@@ -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, toast } from './util.js'
|
|
3
|
+
import { activeBots, activeProject, attr, avatar, botById, duration, esc, filePolicyOptions, 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'
|
|
@@ -147,7 +147,7 @@ async function renderDirPicker(inputId, path) {
|
|
|
147
147
|
error = err?.message || String(err)
|
|
148
148
|
}
|
|
149
149
|
const current = data?.path ?? path ?? ''
|
|
150
|
-
const head = `\n <div style="display:flex;gap:6px;align-items:center;margin-bottom:6px">\n <button class="btn small" type="button" data-action="pick-dir-up" data-picker-for="${attr(inputId)}" data-path="${attr(current)}" title="${t("上一级")}">↑</button>\n <button class="btn small" type="button" data-action="pick-dir-home" data-picker-for="${attr(inputId)}">${t("主目录")}</button>\n <span class="mono" style="flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="${attr(current)}">${esc(current)}</span>\n <button class="btn primary small" type="button" data-action="pick-dir-choose" data-picker-for="${attr(inputId)}" data-path="${attr(current)}">${t("选定此目录")}</button>\n <button class="btn small" type="button" data-action="pick-dir-close" data-picker-for="${attr(inputId)}" title="${t("关闭")}">✕</button>\n </div>`
|
|
150
|
+
const head = `\n <div style="display:flex;gap:6px;align-items:center;margin-bottom:6px">\n <button class="btn small" type="button" data-action="pick-dir-up" data-picker-for="${attr(inputId)}" data-path="${attr(current)}" title="${t("上一级")}">↑</button>\n <button class="btn small" type="button" data-action="pick-dir-home" data-picker-for="${attr(inputId)}">${t("主目录")}</button>\n <span class="mono" style="flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="${attr(current)}">${esc(tildePath(current))}</span>\n <button class="btn primary small" type="button" data-action="pick-dir-choose" data-picker-for="${attr(inputId)}" data-path="${attr(current)}">${t("选定此目录")}</button>\n <button class="btn small" type="button" data-action="pick-dir-close" data-picker-for="${attr(inputId)}" title="${t("关闭")}">✕</button>\n </div>`
|
|
151
151
|
if (error) {
|
|
152
152
|
box.innerHTML = `${head}<div class="hint" style="color:#c0392b">${esc(error)}</div>`
|
|
153
153
|
return
|
|
@@ -311,7 +311,7 @@ function modalSkill(detail) {
|
|
|
311
311
|
<div><div class="eyebrow">${t("本项目")}</div><div>${off ? `<span class="pill">${t("已停用")}</span>` : `<span class="pill green">${t("可用")}</span>`}</div></div>
|
|
312
312
|
</div>
|
|
313
313
|
<div class="detail-block"><div class="eyebrow">${t("描述")}</div><div>${esc(detail.description || t("无描述"))}</div></div>
|
|
314
|
-
<div class="detail-block"><div class="eyebrow">${t("文件")}</div><code class="mono detail-path">${esc(detail.path || detail.sharedPath || '')}</code></div>
|
|
314
|
+
<div class="detail-block"><div class="eyebrow">${t("文件")}</div><code class="mono detail-path">${esc(tildePath(detail.path || detail.sharedPath || ''))}</code></div>
|
|
315
315
|
<div class="divider"></div>
|
|
316
316
|
<div class="eyebrow">SKILL.md ${t("全文")}</div>
|
|
317
317
|
${detail.readable ? `<pre class="detail-pre">${esc(detail.content)}</pre>` : `<div class="note">${t("技能文件当前不可读(可能已被移动或删除),可尝试重新扫描。")}</div>`}
|
|
@@ -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 }
|