dsh-team-bots 0.3.64 → 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/docs/README.zh.md +1 -1
- package/package.json +1 -1
- package/src/db-migrations.js +2 -0
- package/src/db.js +2 -0
- package/src/http.js +1 -0
- package/src/services/approvals.js +30 -5
- package/src/services/bots.js +12 -3
- package/src/services/runtime/session.js +29 -7
- package/src/services/system.js +2 -0
- package/ui/i18n/en/common.js +4 -0
- package/ui/i18n/en/settings.js +8 -2
- package/ui/i18n/zh/common.js +4 -0
- package/ui/i18n/zh/settings.js +8 -2
- package/ui/modules/approval-rule-modal.js +31 -0
- package/ui/modules/chat.js +2 -1
- package/ui/modules/events-board.js +20 -22
- package/ui/modules/events-submit.js +25 -0
- package/ui/modules/modal-forms.js +2 -1
- package/ui/modules/modal-layer.js +2 -0
- package/ui/modules/permissions.js +21 -64
- package/ui/modules/util.js +15 -0
- package/ui/styles/cards.css +32 -68
- package/ui/styles/wide.css +2 -3
package/docs/README.zh.md
CHANGED
|
@@ -87,7 +87,7 @@ Bot 要工具审批、要密钥或要人回答时,工作台在聊天里出一
|
|
|
87
87
|
| `DSH_TEAM_WORKSPACE` | `~/.dsh/workspace/team-bots` | 团队工作区根目录 |
|
|
88
88
|
| `DSH_TEAM_DATA` | `<workspace>/.data` | 数据库与运行记录 |
|
|
89
89
|
|
|
90
|
-
其余变量的默认值与解析顺序(显式环境变量 > 页面上保存的值 > 代码默认值)都写在 `src/config.ts`,常用项见 `.env.example`。除引导期变量(工作区/数据目录/首次种子)与通道凭据(微信/飞书在各自通道页)外,**全部运行期 `DSH_TEAM_*` 变量都可在工作台「全局配置 → 运行与预算 →
|
|
90
|
+
其余变量的默认值与解析顺序(显式环境变量 > 页面上保存的值 > 代码默认值)都写在 `src/config.ts`,常用项见 `.env.example`。除引导期变量(工作区/数据目录/首次种子)与通道凭据(微信/飞书在各自通道页)外,**全部运行期 `DSH_TEAM_*` 变量都可在工作台「全局配置 → 运行与预算 → 运行参数(环境变量)」卡里直接配置**:保存即生效(进行中的运行与已建会话不追溯),显式环境变量仍最高优先。Agent 预设还支持 **Bot 级覆盖**:Bot 配置弹窗的「Agent 预设」下拉逐个设置,留空跟随全局。不要在仓库根目录放 `.env`,否则 `DSH_*` 会泄进 `npm test` 和 `npm run dev`。
|
|
91
91
|
|
|
92
92
|
`DSH_TEAM_DATA` 下有 `team.sqlite`、`wechat-channel.sqlite`、`secret.key`、`memory/`、`messages/` 与 `secrets-runtime/`。备份时把 `secret.key` 和数据一起带走——没有它,已存的密文解不开。
|
|
93
93
|
|
package/package.json
CHANGED
package/src/db-migrations.js
CHANGED
|
@@ -188,6 +188,8 @@ function migrateBots(db) {
|
|
|
188
188
|
addColumn(db, 'bots', 'fallback_provider', 'TEXT')
|
|
189
189
|
addColumn(db, 'bots', 'fallback_model', 'TEXT')
|
|
190
190
|
addColumn(db, 'bots', 'fallback_effort', 'TEXT')
|
|
191
|
+
// Bot 级 agent preset 覆盖:空 = 跟随全局(DSH_TEAM_WORKER_PRESET 生效链)。
|
|
192
|
+
addColumn(db, 'bots', 'agent_preset', "TEXT NOT NULL DEFAULT ''")
|
|
191
193
|
// bots.avatar_seed:像素块头像(identicon)种子;NULL = 首字母/首字头像,非空 = 像素块头像。
|
|
192
194
|
addColumn(db, 'bots', 'avatar_seed', 'TEXT')
|
|
193
195
|
}
|
package/src/db.js
CHANGED
|
@@ -39,6 +39,8 @@ CREATE TABLE IF NOT EXISTS bots (
|
|
|
39
39
|
fallback_model TEXT,
|
|
40
40
|
fallback_effort TEXT,
|
|
41
41
|
file_policy TEXT NOT NULL DEFAULT 'workspace-write',
|
|
42
|
+
-- Bot 级 agent preset 覆盖(空 = 跟随全局 workerPreset 生效链),见 defaultAgentPreset。
|
|
43
|
+
agent_preset TEXT NOT NULL DEFAULT '',
|
|
42
44
|
solo_dir TEXT UNIQUE,
|
|
43
45
|
status TEXT NOT NULL DEFAULT 'active',
|
|
44
46
|
current_revision INTEGER NOT NULL DEFAULT 0,
|
package/src/http.js
CHANGED
|
@@ -181,6 +181,7 @@ export function installHttp(ctx, service, logger = console) {
|
|
|
181
181
|
route('/api/dsh-team/modules/file-preview.js', ['GET'], moduleScript('file-preview.js'))
|
|
182
182
|
route('/api/dsh-team/modules/dom-morph.js', ['GET'], moduleScript('dom-morph.js'))
|
|
183
183
|
route('/api/dsh-team/modules/modal-forms.js', ['GET'], moduleScript('modal-forms.js'))
|
|
184
|
+
route('/api/dsh-team/modules/approval-rule-modal.js', ['GET'], moduleScript('approval-rule-modal.js'))
|
|
184
185
|
route('/api/dsh-team/modules/bot-quota.js', ['GET'], moduleScript('bot-quota.js'))
|
|
185
186
|
route('/api/dsh-team/modules/chat.js', ['GET'], moduleScript('chat.js'))
|
|
186
187
|
route('/api/dsh-team/modules/solo-archive.js', ['GET'], moduleScript('solo-archive.js'))
|
|
@@ -90,14 +90,18 @@ export function ensureApprovalSchema(store) {
|
|
|
90
90
|
// 目标提取(纯函数):按参数形状判别,不按工具名——宿主工具族会扩展,形状更稳。
|
|
91
91
|
// bash 类取 command 首行(超长截 120 字符,chip 只需要可辨认的意图);
|
|
92
92
|
// edit/write/read 类取 file_path 原样(绝对路径入库,展示层再收成工作区相对形)。
|
|
93
|
+
// 路径位参数名按常见形状收口:file_path 优先,path/target_dir/dir/directory/cwd/workdir 兜底
|
|
94
|
+
// (免审不因工具换了参数名就永远提不到目标 → 永远落卡)。
|
|
95
|
+
const TOOL_TARGET_PATH_KEYS = ['file_path', 'path', 'target_dir', 'dir', 'directory', 'cwd', 'workdir']
|
|
93
96
|
export function toolTargetOf(arguments_) {
|
|
94
97
|
if (!arguments_ || typeof arguments_ !== 'object') return null
|
|
95
98
|
if (typeof arguments_.command === 'string') {
|
|
96
99
|
const firstLine = arguments_.command.trim().split('\n')[0].trim()
|
|
97
100
|
return firstLine ? firstLine.slice(0, 120) : null
|
|
98
101
|
}
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
for (const key of TOOL_TARGET_PATH_KEYS) {
|
|
103
|
+
const value = arguments_[key]
|
|
104
|
+
if (typeof value === 'string' && value.trim()) return value.trim()
|
|
101
105
|
}
|
|
102
106
|
return null
|
|
103
107
|
}
|
|
@@ -234,7 +238,12 @@ export function approvalRuleMatches(rule, { botId, toolName, target, sandbox })
|
|
|
234
238
|
}
|
|
235
239
|
|
|
236
240
|
// 含通配符 → glob;不含通配符 → 存量前缀语义(路径按目录边界、命令按词边界)。
|
|
241
|
+
// 路径维度支持 ~ 开头:~ 与 ~/… 在匹配时展开为当前用户家目录(规则按字面存储,跨机器可移植)。
|
|
237
242
|
function matchesRulePattern(pattern, value, dimension) {
|
|
243
|
+
if (dimension === 'path' && (pattern === '~' || pattern.startsWith('~/'))) {
|
|
244
|
+
const home = homedir().replace(/[/\\]+$/, '')
|
|
245
|
+
pattern = pattern === '~' ? home : `${home}${pattern.slice(1)}`
|
|
246
|
+
}
|
|
238
247
|
if (/[*?]/.test(pattern)) return approvalGlobMatch(pattern, value)
|
|
239
248
|
if (dimension === 'path') return value === pattern || value.startsWith(`${pattern}/`)
|
|
240
249
|
return value === pattern || value.startsWith(`${pattern} `)
|
|
@@ -486,9 +495,10 @@ export const approvalsMethods = {
|
|
|
486
495
|
const pathPrefix = String(item.path_prefix ?? '').trim().replace(/\/+$/, '')
|
|
487
496
|
const command = String(item.command ?? '').trim().split('\n')[0].trim().slice(0, 200)
|
|
488
497
|
if (!pathPrefix && !command) throw badRequest(`${label}缺少路径规则或命令规则(至少填一项)`)
|
|
489
|
-
//
|
|
490
|
-
|
|
491
|
-
|
|
498
|
+
// 路径规则:绝对路径、~ 开头的家目录路径(~/…,匹配时展开),或含通配符的 glob
|
|
499
|
+
// (关键词规则如 **/tmp/** 不必是绝对路径)。
|
|
500
|
+
if (pathPrefix && !pathPrefix.startsWith('/') && !pathPrefix.startsWith('~') && !/[*?]/.test(pathPrefix)) {
|
|
501
|
+
throw badRequest(`${label}路径规则必须是以 / 开头的绝对路径、~ 开头的家目录路径或含通配符的 glob`)
|
|
492
502
|
}
|
|
493
503
|
if (pathPrefix.length > 500) throw badRequest(`${label}路径规则超长(上限 500 字符)`)
|
|
494
504
|
const botId = String(item.bot_id ?? '').trim()
|
|
@@ -513,6 +523,21 @@ export const approvalsMethods = {
|
|
|
513
523
|
}
|
|
514
524
|
})
|
|
515
525
|
this.store.setSetting(APPROVAL_RULES_SETTING, JSON.stringify(rules))
|
|
526
|
+
// 推进 settings_revision:免审规则存 settings 表但不进 stateVersion 签名的任何表列,
|
|
527
|
+
// 不 bump 的话保存后客户端轮询命中 unchanged 短路,规则列表最长 60s 才刷出来。
|
|
528
|
+
this.store.setSetting('settings_revision', String(this.settingsRevision() + 1))
|
|
529
|
+
// 追溯放行:发起时未命中而落卡的 pending 审批,保存规则后立刻重判一遍——命中即按同口径
|
|
530
|
+
// allowed-once 放行并留痕,「先见卡、后补规则」不再要求重跑流程。沙箱档不入 approvals 表,
|
|
531
|
+
// 限档规则(sandbox 非空)拿空档冒充命中不稳,不参与追溯。
|
|
532
|
+
const pendingRows = this.store.all("SELECT id, bot_id, tool_name, tool_target FROM approvals WHERE status = 'pending'") ?? []
|
|
533
|
+
for (const pendingRow of pendingRows) {
|
|
534
|
+
const hit = this.matchApprovalAutoRule({ botId: pendingRow.bot_id, toolName: pendingRow.tool_name, target: pendingRow.tool_target, sandbox: '' })
|
|
535
|
+
if (!hit) continue
|
|
536
|
+
this.settleApproval(pendingRow.id, 'allowed', 'allowed-once', `auto:rule:${hit.id}`)
|
|
537
|
+
this.audit(actor, 'approval.auto_allow', 'approval', pendingRow.id, {
|
|
538
|
+
ruleId: hit.id, retroactive: true, toolName: pendingRow.tool_name, botId: pendingRow.bot_id, target: pendingRow.tool_target,
|
|
539
|
+
})
|
|
540
|
+
}
|
|
516
541
|
this.audit(actor, 'approval_rules.update', 'settings', APPROVAL_RULES_SETTING, {
|
|
517
542
|
count: rules.length,
|
|
518
543
|
rules: rules.map(rule => ({ id: rule.id, path_prefix: rule.path_prefix, command: rule.command, sandbox: rule.sandbox })),
|
package/src/services/bots.js
CHANGED
|
@@ -58,6 +58,9 @@ export const botsMethods = {
|
|
|
58
58
|
const instructions = text(input.instructions, 12_000)
|
|
59
59
|
const color = COLORS.includes(input.color) ? input.color : 'blue'
|
|
60
60
|
const filePolicy = normalizeFilePolicy(input.filePolicy)
|
|
61
|
+
// Bot 级 agent preset 覆盖:空 = 跟随全局(DSH_TEAM_WORKER_PRESET 生效链);
|
|
62
|
+
// 自由短串,不在此校验存在性——宿主侧 defaultAgentPreset 只选可用 preset,写错回落 standard。
|
|
63
|
+
const agentPreset = input.agentPreset !== undefined ? text(input.agentPreset, 80) : ''
|
|
61
64
|
// 先建目录再建号:目录建不出来就别留下一个单聊必然失败的 bot 行。
|
|
62
65
|
// 这里预建的是占位候选;并发同名时权威 solo_dir 在事务内重算,输家目录提交后补建。
|
|
63
66
|
const placeholder = this.soloDirFor(name, botId)
|
|
@@ -75,11 +78,11 @@ export const botsMethods = {
|
|
|
75
78
|
try {
|
|
76
79
|
this.store.run(
|
|
77
80
|
`INSERT INTO bots(id, name, role, instructions, color, provider, model, effort,
|
|
78
|
-
fallback_provider, fallback_model, fallback_effort, file_policy, solo_dir,
|
|
81
|
+
fallback_provider, fallback_model, fallback_effort, file_policy, agent_preset, solo_dir,
|
|
79
82
|
status, current_revision, created_at, updated_at)
|
|
80
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', 1, ?, ?)`,
|
|
83
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', 1, ?, ?)`,
|
|
81
84
|
botId, name, role, instructions, color, provider, model, effort,
|
|
82
|
-
fallbackProvider, fallbackModel, fallbackEffort, filePolicy, soloDir, createdAt, createdAt,
|
|
85
|
+
fallbackProvider, fallbackModel, fallbackEffort, filePolicy, agentPreset, soloDir, createdAt, createdAt,
|
|
83
86
|
)
|
|
84
87
|
break
|
|
85
88
|
} catch (error ) {
|
|
@@ -232,6 +235,11 @@ export const botsMethods = {
|
|
|
232
235
|
const filePolicy = normalizeFilePolicy(patch.filePolicy)
|
|
233
236
|
if (filePolicy !== bot.file_policy) changes.file_policy = filePolicy
|
|
234
237
|
}
|
|
238
|
+
// Bot 级 agent preset 覆盖(空 = 跟随全局):自由短串,不校验存在性(宿主侧安全回落)。
|
|
239
|
+
if (patch.agentPreset !== undefined) {
|
|
240
|
+
const agentPreset = text(patch.agentPreset, 80)
|
|
241
|
+
if (agentPreset !== (bot.agent_preset ?? '')) changes.agent_preset = agentPreset
|
|
242
|
+
}
|
|
235
243
|
if (patch.status !== undefined) {
|
|
236
244
|
if (!['active', 'paused', 'archived'].includes(patch.status)) throw badRequest('Bot 状态无效')
|
|
237
245
|
changes.status = patch.status
|
|
@@ -362,6 +370,7 @@ export const botsMethods = {
|
|
|
362
370
|
)
|
|
363
371
|
return {
|
|
364
372
|
...bot,
|
|
373
|
+
agentPreset: bot.agent_preset ?? '',
|
|
365
374
|
modelRef: bot.provider && bot.model ? `${bot.provider}/${bot.model}` : null,
|
|
366
375
|
fallbackModelRef: bot.fallback_provider && bot.fallback_model ? `${bot.fallback_provider}/${bot.fallback_model}` : null,
|
|
367
376
|
fallbackConfigured: Boolean(bot.fallback_provider && bot.fallback_model),
|
|
@@ -233,10 +233,15 @@ export const sessionMethods = {
|
|
|
233
233
|
this.selecting = run.catch(() => {})
|
|
234
234
|
return run
|
|
235
235
|
},
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
236
|
+
// kind 'task' = 任务 worker 会话(全局链走 workerPreset);其余 = 控制面/单聊/核验会话
|
|
237
|
+
//(全局链走 routerPreset)。bot.agent_preset 非空时逐 bot 覆盖,两级都留空时 kind
|
|
238
|
+
// 决定用哪个全局链。可选 preset 只从宿主 roster 里实际可用(非 broken)的里挑。
|
|
239
|
+
async defaultAgentPreset(kind, bot = null) {
|
|
240
|
+
const botPreset = String(bot?.agent_preset ?? '').trim()
|
|
241
|
+
const wanted = botPreset
|
|
242
|
+
|| (kind === 'task'
|
|
243
|
+
? (this.config.workerPreset ?? '')
|
|
244
|
+
: (this.config.routerPreset ?? ''))
|
|
240
245
|
try {
|
|
241
246
|
const presets = this.ctx.get?.('agentPresets')
|
|
242
247
|
if (!presets) return {}
|
|
@@ -249,6 +254,23 @@ export const sessionMethods = {
|
|
|
249
254
|
return {}
|
|
250
255
|
}
|
|
251
256
|
},
|
|
257
|
+
// 宿主可用 agent preset 清单(Bot 配置下拉数据源):只列 roster 里非 broken 的,
|
|
258
|
+
// 附宿主默认 id(用户「设为新任务默认」),供 UI 标注「跟随全局」的当前生效值。
|
|
259
|
+
// 宿主无 agentPresets 服务(或调用失败)返回 null,UI 下拉退化为自由文本。
|
|
260
|
+
async agentPresetsRoster() {
|
|
261
|
+
try {
|
|
262
|
+
const presets = this.ctx.get?.('agentPresets')
|
|
263
|
+
if (!presets) return null
|
|
264
|
+
const list = await presets.list()
|
|
265
|
+
return {
|
|
266
|
+
presets: (list ?? []).filter(preset => preset.broken === undefined)
|
|
267
|
+
.map(preset => ({ id: preset.id, name: preset.name ?? preset.id })),
|
|
268
|
+
defaultId: (() => { try { return String(presets.defaultId ?? '') } catch { return '' } })(),
|
|
269
|
+
}
|
|
270
|
+
} catch {
|
|
271
|
+
return null
|
|
272
|
+
}
|
|
273
|
+
},
|
|
252
274
|
// 会话当前上下文体积估计(单轮上下文治理 P2):该会话最近一次模型调用的
|
|
253
275
|
// input+cache_read 即当前历史整体规模——usage_events 按调用记账、runs.session_id 归属。
|
|
254
276
|
// 无记录(新会话/尚未有成功调用)返回 0,两个消费点(压缩下限/结转上限)都判 >=,
|
|
@@ -577,7 +599,7 @@ export const sessionMethods = {
|
|
|
577
599
|
const cwd = await resolveSessionCwd(this.config, { solo: false, bot, project })
|
|
578
600
|
const created = await this.ctx.sessionController.create({
|
|
579
601
|
cwd,
|
|
580
|
-
...(await this.defaultAgentPreset('project')),
|
|
602
|
+
...(await this.defaultAgentPreset('project', bot)),
|
|
581
603
|
})
|
|
582
604
|
const sessionId = created.sessionId
|
|
583
605
|
const agent = await this.ctx.sessionController.resolveAgent(sessionId)
|
|
@@ -645,7 +667,7 @@ export const sessionMethods = {
|
|
|
645
667
|
const cwd = await resolveSessionCwd(this.config, { solo: !project, bot, project })
|
|
646
668
|
const created = await this.ctx.sessionController.create({
|
|
647
669
|
cwd,
|
|
648
|
-
...(await this.defaultAgentPreset('project')),
|
|
670
|
+
...(await this.defaultAgentPreset('project', bot)),
|
|
649
671
|
})
|
|
650
672
|
const sessionId = created.sessionId
|
|
651
673
|
const agent = await this.ctx.sessionController.resolveAgent(sessionId)
|
|
@@ -733,7 +755,7 @@ export const sessionMethods = {
|
|
|
733
755
|
const cwd = await resolveSessionCwd(this.config, { solo, bot, project })
|
|
734
756
|
const created = await this.ctx.sessionController.create({
|
|
735
757
|
cwd,
|
|
736
|
-
...(await this.defaultAgentPreset('project')),
|
|
758
|
+
...(await this.defaultAgentPreset('project', bot)),
|
|
737
759
|
})
|
|
738
760
|
const sessionId = created.sessionId
|
|
739
761
|
const agent = await this.ctx.sessionController.resolveAgent(sessionId)
|
package/src/services/system.js
CHANGED
|
@@ -188,6 +188,8 @@ const systemMethodsBase = {
|
|
|
188
188
|
// 审批免审规则(DSHBOTS-365):总览 bots 页「免审权限」卡唯一真值,规则量小随行下发。
|
|
189
189
|
approvalRules: this.approvalRulesView(),
|
|
190
190
|
runLimits: this.runLimitsView(),
|
|
191
|
+
// Bot 配置页 preset 下拉数据源:宿主可用清单 + 默认值;无宿主服务时 null(UI 退化)。
|
|
192
|
+
agentPresets: await (this.runtime?.agentPresetsRoster?.() ?? null),
|
|
191
193
|
// 运行参数目录(全局设置「运行参数」卡):全部 DSH_TEAM_* 运行期变量的可配置视图。
|
|
192
194
|
runtimeSettings: this.runtimeSettingsView(),
|
|
193
195
|
// 侧栏状态行全局口径(DSHBOTS-77):全库活跃运行(含 queued),不随群聊/单聊上下文收敛。
|
package/ui/i18n/en/common.js
CHANGED
|
@@ -182,4 +182,8 @@ export default {
|
|
|
182
182
|
"form.errorRangeUnderflow": "${label} must be at least ${min}",
|
|
183
183
|
"form.errorRangeOverflow": "${label} must be at most ${max}",
|
|
184
184
|
"form.errorStepMismatch": "${label} must be a multiple of ${step}",
|
|
185
|
+
"bots.agentPreset": "Agent preset",
|
|
186
|
+
"bots.presetFollow": "Follow global",
|
|
187
|
+
"bots.agentPresetTitle": "Agent preset for this bot's sessions; empty = follow global (effective DSH_TEAM_WORKER_PRESET chain), applies to newly created sessions",
|
|
188
|
+
"bots.agentPresetHint": "Empty follows the global value; selecting one applies to this bot's new sessions only.",
|
|
185
189
|
}
|
package/ui/i18n/en/settings.js
CHANGED
|
@@ -44,14 +44,17 @@ export default {
|
|
|
44
44
|
"global.approvalRuleCommand": "Command glob",
|
|
45
45
|
"global.approvalRulePathExample": "e.g. **/tmp/**",
|
|
46
46
|
"global.approvalRuleCommandExample": "e.g. git push*",
|
|
47
|
-
"global.approvalRulePathHint": "Matches the operation target path: * stays in one segment, ** crosses directories.",
|
|
47
|
+
"global.approvalRulePathHint": "Matches the operation target path: * stays in one segment, ** crosses directories; a leading ~ expands to the home directory.",
|
|
48
48
|
"global.approvalRuleCommandHint": "Matches the first line of the command: * stays in one segment, ** crosses directories.",
|
|
49
49
|
"global.approvalRuleBot": "Bot filter",
|
|
50
50
|
"global.approvalRuleTool": "Tool filter",
|
|
51
|
+
"global.approvalRuleToolPlaceholder": "e.g. bash",
|
|
52
|
+
"global.approvalRuleToolHint": "Empty = any tool; a value must exactly match the escalating tool name (e.g. bash, edit).",
|
|
51
53
|
"global.approvalRuleSandbox": "Sandbox tier",
|
|
52
54
|
"global.approvalRuleNote": "Note",
|
|
53
55
|
"global.approvalRuleAny": "Any",
|
|
54
56
|
"global.approvalRuleDelete": "Delete",
|
|
57
|
+
"global.approvalRuleEdit": "Edit",
|
|
55
58
|
"global.approvalRuleAdd": "Add rule",
|
|
56
59
|
"global.approvalRuleMore": "More conditions (bot / tool / sandbox / note)",
|
|
57
60
|
"global.approvalRuleChipPath": "Path",
|
|
@@ -63,6 +66,9 @@ export default {
|
|
|
63
66
|
"global.saveApprovalRules": "Save auto-allow rules",
|
|
64
67
|
"global.approvalRulesHint": "Matching escalation requests skip the approval card: the plugin answers allowed-once immediately and leaves an audit trail (decided_by=auto:rule:*). Path and command rules match the target as globs (* stays in one segment, ** crosses directories); legacy rules without wildcards keep prefix matching, so existing entries stay effective. The system temp directory ($TMPDIR) is allowed out of the box. Each call is allowed once per match; rule changes take effect immediately. Only the workbench owner can edit rules.",
|
|
65
68
|
"审批免审规则已保存": "Approval auto-allow rules saved",
|
|
69
|
+
"新增免审规则": "Add auto-allow rule",
|
|
70
|
+
"编辑免审规则": "Edit auto-allow rule",
|
|
71
|
+
"保存规则": "Save rule",
|
|
66
72
|
"规则已删除": "Rule deleted",
|
|
67
73
|
"团队指令已保存,新会话生效": "Team instructions saved; applies to new sessions",
|
|
68
74
|
"已恢复默认指令": "Restored to default",
|
|
@@ -110,7 +116,7 @@ export default {
|
|
|
110
116
|
"global.rsGroupReview": "Review",
|
|
111
117
|
"global.rsGroupModels": "Derived model proxies",
|
|
112
118
|
"global.rsFollowDefault": "Follow default",
|
|
113
|
-
"global.rsEffective": "Effective {value} (default {def})",
|
|
119
|
+
"global.rsEffective": "Effective ${value} (default ${def})",
|
|
114
120
|
"global.rsSave": "Save runtime parameters",
|
|
115
121
|
"运行参数已保存,即时生效(env 显式设置仍优先)": "Runtime parameters saved, effective immediately (explicit env vars still take priority)",
|
|
116
122
|
"global.rs.max_concurrent_runs": "Max concurrent runs",
|
package/ui/i18n/zh/common.js
CHANGED
|
@@ -182,4 +182,8 @@ export default {
|
|
|
182
182
|
"form.errorRangeUnderflow": "${label}不能小于 ${min}",
|
|
183
183
|
"form.errorRangeOverflow": "${label}不能大于 ${max}",
|
|
184
184
|
"form.errorStepMismatch": "${label}必须是 ${step} 的整数倍",
|
|
185
|
+
"bots.agentPreset": "Agent 预设",
|
|
186
|
+
"bots.presetFollow": "跟随全局",
|
|
187
|
+
"bots.agentPresetTitle": "Bot 会话使用的 agent preset;留空 = 跟随全局(DSH_TEAM_WORKER_PRESET 生效链),下次新建会话生效",
|
|
188
|
+
"bots.agentPresetHint": "留空跟随全局;选择后仅该 Bot 的新建会话使用所选预设。",
|
|
185
189
|
}
|
package/ui/i18n/zh/settings.js
CHANGED
|
@@ -44,14 +44,17 @@ export default {
|
|
|
44
44
|
"global.approvalRuleCommand": "命令 glob",
|
|
45
45
|
"global.approvalRulePathExample": "例:**/tmp/**",
|
|
46
46
|
"global.approvalRuleCommandExample": "例:git push*",
|
|
47
|
-
"global.approvalRulePathHint": "匹配操作目标路径:* 不跨目录,**
|
|
47
|
+
"global.approvalRulePathHint": "匹配操作目标路径:* 不跨目录,** 跨目录;~ 开头按家目录展开。",
|
|
48
48
|
"global.approvalRuleCommandHint": "匹配命令首行:* 不跨目录,** 跨目录。",
|
|
49
49
|
"global.approvalRuleBot": "限 Bot",
|
|
50
50
|
"global.approvalRuleTool": "限工具",
|
|
51
|
+
"global.approvalRuleToolPlaceholder": "如:bash",
|
|
52
|
+
"global.approvalRuleToolHint": "留空 = 任意工具;填了则须与提权工具名完全一致(如 bash、edit)。",
|
|
51
53
|
"global.approvalRuleSandbox": "限沙箱档",
|
|
52
54
|
"global.approvalRuleNote": "备注",
|
|
53
55
|
"global.approvalRuleAny": "任意",
|
|
54
56
|
"global.approvalRuleDelete": "删除",
|
|
57
|
+
"global.approvalRuleEdit": "编辑",
|
|
55
58
|
"global.approvalRuleAdd": "新增规则",
|
|
56
59
|
"global.approvalRuleMore": "更多条件(Bot / 工具 / 沙箱档 / 备注)",
|
|
57
60
|
"global.approvalRuleChipPath": "路径",
|
|
@@ -63,6 +66,9 @@ export default {
|
|
|
63
66
|
"global.saveApprovalRules": "保存免审规则",
|
|
64
67
|
"global.approvalRulesHint": "命中的提权请求不落审批卡:插件即时按 allowed-once 放行,并在审批记录与审计里留痕(decided_by=auto:rule:*)。路径与命令规则都用 glob 匹配目标(* 不跨目录,** 跨目录);不含通配符的旧规则按前缀匹配,存量不失效。系统临时目录($TMPDIR)随预置一并放行。每次调用一放行一结,改规则即时生效;仅工作台 owner 可修改。",
|
|
65
68
|
"审批免审规则已保存": "审批免审规则已保存",
|
|
69
|
+
"新增免审规则": "新增免审规则",
|
|
70
|
+
"编辑免审规则": "编辑免审规则",
|
|
71
|
+
"保存规则": "保存规则",
|
|
66
72
|
"规则已删除": "规则已删除",
|
|
67
73
|
"团队指令已保存,新会话生效": "团队指令已保存,新会话生效",
|
|
68
74
|
"已恢复默认指令": "已恢复默认指令",
|
|
@@ -110,7 +116,7 @@ export default {
|
|
|
110
116
|
"global.rsGroupReview": "验收",
|
|
111
117
|
"global.rsGroupModels": "派生模型代理",
|
|
112
118
|
"global.rsFollowDefault": "跟随默认",
|
|
113
|
-
"global.rsEffective": "生效 {value}(默认 {def})",
|
|
119
|
+
"global.rsEffective": "生效 ${value}(默认 ${def})",
|
|
114
120
|
"global.rsSave": "保存运行参数",
|
|
115
121
|
"运行参数已保存,即时生效(env 显式设置仍优先)": "运行参数已保存,即时生效(env 显式设置仍优先)",
|
|
116
122
|
"global.rs.max_concurrent_runs": "最大并发运行",
|
|
@@ -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/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'
|
|
@@ -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>
|
|
@@ -201,31 +201,29 @@ export async function handleBoardAction(action, target) {
|
|
|
201
201
|
toast(t("已恢复默认指令"), 'success')
|
|
202
202
|
break
|
|
203
203
|
}
|
|
204
|
-
// 审批免审规则(DSHBOTS-365
|
|
205
|
-
//
|
|
206
|
-
|
|
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
|
+
}
|
|
207
216
|
case 'approval-rule-delete': {
|
|
208
|
-
const removeId =
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
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)
|
|
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 }))
|
|
226
221
|
await api('update_approval_rules', { rules })
|
|
227
222
|
await loadState(state.projectId)
|
|
228
|
-
|
|
223
|
+
// loadState 只更新 state.data 不重渲染,且下一次轮询因 since=新版本返回 unchanged,
|
|
224
|
+
// 不主动 render 页面会一直停留在旧规则列表。
|
|
225
|
+
render()
|
|
226
|
+
toast(t("规则已删除"), 'success')
|
|
229
227
|
break
|
|
230
228
|
}
|
|
231
229
|
case 'reconcile-usage': {
|
|
@@ -76,6 +76,7 @@ document.addEventListener('submit', async (event) => {
|
|
|
76
76
|
model,
|
|
77
77
|
effort: payload.effort || null,
|
|
78
78
|
filePolicy: payload.filePolicy || undefined,
|
|
79
|
+
agentPreset: payload.agentPreset ?? '',
|
|
79
80
|
fallbackProvider: fallback.fallbackProvider,
|
|
80
81
|
fallbackModel: fallback.fallbackModel,
|
|
81
82
|
fallbackEffort: fallback.fallbackEffort,
|
|
@@ -168,6 +169,30 @@ document.addEventListener('submit', async (event) => {
|
|
|
168
169
|
toast(t("记忆已更新"), 'success')
|
|
169
170
|
return
|
|
170
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
|
+
}
|
|
171
196
|
if (type === 'create-proposal') {
|
|
172
197
|
const kind = payload.kind
|
|
173
198
|
const proposal = await api('create_proposal', {
|
|
@@ -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>
|
|
@@ -3,6 +3,7 @@ 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)
|
|
@@ -2,76 +2,28 @@ import { state } from './state.js'
|
|
|
2
2
|
import { t } from './i18n.js'
|
|
3
3
|
import { icon } from './icons.js'
|
|
4
4
|
import { attr, botById, esc } from './util.js'
|
|
5
|
-
import { panelAttrs } from '../app.js'
|
|
6
5
|
|
|
7
|
-
// 免审权限卡(DSHBOTS-365 编辑面在总览 bots
|
|
8
|
-
//
|
|
9
|
-
// 服务端权威不变:保存 =
|
|
6
|
+
// 免审权限卡(DSHBOTS-365 编辑面在总览 bots 页):每条规则一张独立卡片,只读展示 chip 摘要;
|
|
7
|
+
// 新增/编辑一律拉起 modal(modal-forms 的 approval-rule 弹窗)。
|
|
8
|
+
// 服务端权威不变:保存 = 弹窗整行提交 → update_approval_rules 整表替换;删除 = 去行后整表提交;
|
|
10
9
|
// 改规则即时生效,每次调用一放行一结。
|
|
11
10
|
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
|
-
}
|
|
11
|
+
export { APPROVAL_RULE_SANDBOXES }
|
|
51
12
|
|
|
52
13
|
// 摘要行:只显示已设的条件,标签带在 chip 里,不让占位文案看起来像真值。
|
|
53
14
|
function approvalRuleChips(rule ) {
|
|
54
|
-
const chip = (labelKey , value ) => `<span class="approval-chip mono">${t(labelKey)} ${esc(value)}</span>`
|
|
15
|
+
const chip = (labelKey , value ) => `<span class="approval-chip mono" title="${attr(value)}">${t(labelKey)} ${esc(value)}</span>`
|
|
55
16
|
const chips = []
|
|
56
17
|
if (rule.path_prefix) chips.push(chip('global.approvalRuleChipPath', rule.path_prefix))
|
|
57
18
|
if (rule.command) chips.push(chip('global.approvalRuleChipCommand', rule.command))
|
|
58
19
|
if (rule.bot_id) chips.push(chip('global.approvalRuleChipBot', botById(rule.bot_id)?.name ?? rule.bot_id))
|
|
59
20
|
if (rule.tool_name) chips.push(chip('global.approvalRuleChipTool', rule.tool_name))
|
|
60
21
|
if (rule.sandbox) chips.push(chip('global.approvalRuleChipSandbox', rule.sandbox))
|
|
61
|
-
if (rule.note) chips.push(chip('global.approvalRuleChipNote', rule.note))
|
|
62
22
|
return chips.join('')
|
|
63
23
|
}
|
|
64
24
|
|
|
65
25
|
function renderApprovalPermissionsCard() {
|
|
66
26
|
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
27
|
return `
|
|
76
28
|
<section class="perm-section">
|
|
77
29
|
<div class="section-head">
|
|
@@ -80,17 +32,22 @@ function renderApprovalPermissionsCard() {
|
|
|
80
32
|
</div>
|
|
81
33
|
<div class="card perm-card">
|
|
82
34
|
${rules.length === 0 ? `<div class="faint perm-empty">${t('global.approvalRulesEmpty')}</div>` : ''}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
35
|
+
<div class="perm-rule-grid">
|
|
36
|
+
${rules.map(rule => `
|
|
37
|
+
<div class="perm-rule-card" data-approval-rule-id="${attr(rule.id)}">
|
|
38
|
+
<div class="perm-rule-card-main">
|
|
39
|
+
<div class="perm-rule-chips">${approvalRuleChips(rule) || `<span class="faint">${t('global.approvalRuleAny')}</span>`}</div>
|
|
40
|
+
${rule.note ? `<div class="perm-note" title="${attr(rule.note)}">${esc(rule.note)}</div>` : ''}
|
|
41
|
+
</div>
|
|
42
|
+
<div class="perm-rule-actions">
|
|
43
|
+
<button class="btn small" type="button" data-action="approval-rule-edit" data-rule-id="${attr(rule.id)}">${icon('edit')}${t('global.approvalRuleEdit')}</button>
|
|
44
|
+
<button class="btn small danger" type="button" data-action="approval-rule-delete" data-rule-id="${attr(rule.id)}">${t('global.approvalRuleDelete')}</button>
|
|
45
|
+
</div>
|
|
46
|
+
</div>`).join('')}
|
|
47
|
+
</div>
|
|
48
|
+
<div class="btn-row perm-add-row">
|
|
49
|
+
<button class="btn small primary" type="button" data-action="approval-rule-new">${icon('plus')}${t('global.approvalRuleAdd')}</button>
|
|
50
|
+
</div>
|
|
94
51
|
<div class="hint">${t('global.approvalRulesHint')}</div>
|
|
95
52
|
</div>
|
|
96
53
|
</section>`
|
package/ui/modules/util.js
CHANGED
|
@@ -330,3 +330,18 @@ export function overlayInertState() {
|
|
|
330
330
|
const viewer = document.getElementById('image-viewer')
|
|
331
331
|
return backgroundInert(Boolean(state?.modal), Boolean(viewer && !viewer.hidden))
|
|
332
332
|
}
|
|
333
|
+
|
|
334
|
+
// Agent 预设下拉(Bot 级覆盖,空 = 跟随全局):
|
|
335
|
+
// 数据源 state.data.agentPresets(宿主 roster);缺宿主服务时退化显示为全局链文本提示。
|
|
336
|
+
export function agentPresetOptions(bot ) {
|
|
337
|
+
const roster = state.data?.agentPresets
|
|
338
|
+
const presets = roster?.presets ?? []
|
|
339
|
+
const current = String(bot?.agent_preset ?? bot?.agentPreset ?? '')
|
|
340
|
+
const follow = t('bots.presetFollow')
|
|
341
|
+
const rows = presets.map(preset => {
|
|
342
|
+
const selected = current === preset.id ? ' selected' : ''
|
|
343
|
+
const label = preset.name && preset.name !== preset.id ? `${preset.name} (${preset.id})` : preset.id
|
|
344
|
+
return `<option value="${attr(preset.id)}"${selected}>${esc(label)}</option>`
|
|
345
|
+
})
|
|
346
|
+
return `<option value=""${current ? '' : ' selected'}>${esc(follow)}</option>${rows.join('')}`
|
|
347
|
+
}
|
package/ui/styles/cards.css
CHANGED
|
@@ -329,93 +329,57 @@
|
|
|
329
329
|
margin-top: 10px;
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
/* 免审权限卡(总览 bots 页「全部 Bots
|
|
333
|
-
|
|
332
|
+
/* 免审权限卡(总览 bots 页「全部 Bots」下方):每条规则一张独立只读卡片(chip 摘要 +
|
|
333
|
+
编辑/删除),新增与编辑都拉起 modal,卡内不再内联编辑。 */
|
|
334
334
|
.perm-section {
|
|
335
335
|
margin-top: 26px;
|
|
336
336
|
}
|
|
337
337
|
.perm-card {
|
|
338
|
-
padding:
|
|
338
|
+
padding: 14px 16px;
|
|
339
339
|
}
|
|
340
340
|
.perm-empty {
|
|
341
|
-
padding:
|
|
341
|
+
padding: 4px 0 10px;
|
|
342
342
|
}
|
|
343
|
-
.perm-rule {
|
|
344
|
-
|
|
343
|
+
.perm-rule-grid {
|
|
344
|
+
display: grid;
|
|
345
|
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
|
346
|
+
gap: 10px;
|
|
347
|
+
}
|
|
348
|
+
.perm-rule-card {
|
|
349
|
+
display: flex;
|
|
350
|
+
flex-direction: column;
|
|
351
|
+
gap: 10px;
|
|
352
|
+
border: 1px solid var(--line);
|
|
353
|
+
border-radius: 10px;
|
|
354
|
+
padding: 12px;
|
|
355
|
+
background: var(--bg-2, transparent);
|
|
356
|
+
}
|
|
357
|
+
.perm-rule-card-main {
|
|
358
|
+
flex: 1;
|
|
345
359
|
}
|
|
346
|
-
.perm-rule
|
|
360
|
+
.perm-rule-chips {
|
|
347
361
|
display: flex;
|
|
348
362
|
align-items: center;
|
|
349
363
|
gap: 6px;
|
|
350
364
|
flex-wrap: wrap;
|
|
351
|
-
padding: 10px 0;
|
|
352
|
-
cursor: pointer;
|
|
353
|
-
list-style: none;
|
|
354
365
|
}
|
|
355
|
-
.perm-rule
|
|
356
|
-
|
|
366
|
+
.perm-rule-chips .approval-chip {
|
|
367
|
+
max-width: 100%;
|
|
357
368
|
}
|
|
358
|
-
.perm-rule-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
.perm-chev {
|
|
362
|
-
margin-left: auto;
|
|
363
|
-
width: 14px;
|
|
364
|
-
height: 14px;
|
|
365
|
-
color: var(--ink-3);
|
|
366
|
-
flex: 0 0 auto;
|
|
367
|
-
}
|
|
368
|
-
.perm-rule[open] > summary .perm-chev {
|
|
369
|
-
transform: rotate(90deg);
|
|
370
|
-
}
|
|
371
|
-
.perm-rule-body {
|
|
372
|
-
padding-bottom: 12px;
|
|
373
|
-
}
|
|
374
|
-
.perm-rule-body .field-row {
|
|
375
|
-
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
376
|
-
}
|
|
377
|
-
.perm-rule-body .field {
|
|
378
|
-
margin-bottom: 10px;
|
|
379
|
-
}
|
|
380
|
-
.perm-rule-body .btn-row {
|
|
369
|
+
.perm-rule-actions {
|
|
370
|
+
display: flex;
|
|
381
371
|
justify-content: flex-end;
|
|
382
|
-
|
|
383
|
-
/* 更多条件:默认收起,展开后四列排条件位 */
|
|
384
|
-
.perm-more {
|
|
385
|
-
margin-top: 4px;
|
|
386
|
-
}
|
|
387
|
-
.perm-more > summary.perm-more-head {
|
|
388
|
-
cursor: pointer;
|
|
389
|
-
color: var(--ink-3);
|
|
390
|
-
font-size: var(--fs-small);
|
|
391
|
-
list-style: none;
|
|
392
|
-
}
|
|
393
|
-
.perm-more > summary.perm-more-head::-webkit-details-marker {
|
|
394
|
-
display: none;
|
|
395
|
-
}
|
|
396
|
-
.perm-more > summary.perm-more-head::before {
|
|
397
|
-
content: "▸ ";
|
|
398
|
-
color: var(--ink-3);
|
|
399
|
-
}
|
|
400
|
-
.perm-more[open] > summary.perm-more-head::before {
|
|
401
|
-
content: "▾ ";
|
|
402
|
-
}
|
|
403
|
-
.perm-more .field-row {
|
|
404
|
-
grid-template-columns: repeat(4, minmax(0, 1fr));
|
|
405
|
-
margin-top: 10px;
|
|
372
|
+
gap: 8px;
|
|
406
373
|
}
|
|
407
374
|
.perm-note {
|
|
375
|
+
margin-top: 8px;
|
|
408
376
|
color: var(--ink-3);
|
|
409
377
|
font-size: var(--fs-small);
|
|
378
|
+
overflow: hidden;
|
|
379
|
+
text-overflow: ellipsis;
|
|
380
|
+
white-space: nowrap;
|
|
410
381
|
}
|
|
411
|
-
.perm-add {
|
|
412
|
-
|
|
413
|
-
align-items: center;
|
|
414
|
-
gap: 6px;
|
|
415
|
-
color: var(--ink-2);
|
|
416
|
-
}
|
|
417
|
-
.perm-add svg {
|
|
418
|
-
width: 14px;
|
|
419
|
-
height: 14px;
|
|
382
|
+
.perm-add-row {
|
|
383
|
+
margin-top: 12px;
|
|
420
384
|
}
|
|
421
385
|
|
package/ui/styles/wide.css
CHANGED
|
@@ -181,9 +181,8 @@
|
|
|
181
181
|
.field-row {
|
|
182
182
|
grid-template-columns: 1fr;
|
|
183
183
|
}
|
|
184
|
-
/*
|
|
185
|
-
.perm-rule-
|
|
186
|
-
.perm-more .field-row {
|
|
184
|
+
/* 免审规则卡片栅格窄屏单列 */
|
|
185
|
+
.perm-rule-grid {
|
|
187
186
|
grid-template-columns: 1fr;
|
|
188
187
|
}
|
|
189
188
|
.metric-grid {
|