feat: add batch task approval settings and fix modal dropdown scrolling

This commit is contained in:
Ed1s0nZ
2026-09-13 18:02:43 +08:00
parent c563567502
commit ac101d8476
13 changed files with 387 additions and 32 deletions
-6
View File
@@ -38272,12 +38272,6 @@ html[data-theme="dark"] #agent-md-modal .modal-footer {
white-space: nowrap;
}
#batch-import-modal .modal-content:has(.batch-form-select-ui.open),
#batch-import-modal .modal-body:has(.batch-form-select-ui.open),
#batch-queue-detail-modal .modal-content:has(.batch-form-select-ui.open),
#batch-queue-detail-modal .modal-body:has(.batch-form-select-ui.open) {
overflow: visible;
}
.bq-inline-edit-controls .batch-form-native-select {
position: absolute;
+9
View File
@@ -3457,6 +3457,15 @@
"deleteConversation": "Delete conversation"
},
"batchImportModal": {
"hitlInherit": "Use global settings",
"hitlOff": "Approval off",
"hitlHuman": "Human approval",
"hitlAgent": "Agent approval",
"hitlReviewEdit": "Agent review and edit",
"hitlPolicy": "Tool approval",
"hitlHint": "Applies to all tasks in this queue, including tasks added later. Uses the global whitelist, audit strategy and timeout.",
"hitlSubtaskHint": "New tasks use the queues tool approval setting. Change it in queue details.",
"title": "New task",
"queueTitle": "Queue title",
"queueTitlePlaceholder": "Enter queue title (optional, for identification and filtering)",
+9
View File
@@ -3445,6 +3445,15 @@
"deleteConversation": "删除此对话"
},
"batchImportModal": {
"hitlInherit": "沿用全局设置",
"hitlOff": "关闭审批",
"hitlHuman": "人工审批",
"hitlAgent": "Agent 审批",
"hitlReviewEdit": "Agent 审查编辑",
"hitlPolicy": "工具审批",
"hitlHint": "队列内所有任务(含后续添加的任务)使用此设置;白名单、审计策略和等待时限沿用全局配置。",
"hitlSubtaskHint": "新增任务沿用队列的工具审批设置,可在队列详情中修改。",
"title": "新建任务",
"queueTitle": "任务标题",
"queueTitlePlaceholder": "请输入任务标题(可选,用于标识和筛选)",
+72
View File
@@ -894,6 +894,8 @@ async function showBatchImportModal() {
if (titleInput) {
titleInput.value = '';
}
const hitlSelect = document.getElementById('batch-queue-hitl-policy');
if (hitlSelect) hitlSelect.value = '';
// 重置角色选择为默认
if (roleSelect) {
roleSelect.value = '';
@@ -1059,6 +1061,7 @@ async function createBatchQueue() {
tasks,
role,
agentMode,
hitlPolicy: document.getElementById('batch-queue-hitl-policy')?.value || '',
scheduleMode,
cronExpr,
executeNow,
@@ -1318,6 +1321,7 @@ const BATCH_IMPORT_FORM_SELECT_IDS = [
'batch-queue-role',
'batch-queue-project-id',
'batch-queue-agent-mode',
'batch-queue-hitl-policy',
'batch-queue-schedule-mode',
];
const batchFormSelectMap = {};
@@ -1333,6 +1337,21 @@ function closeAllBatchFormSelects() {
});
}
// Keep the menu inside the modal scrollport without changing the modal's overflow.
function positionBatchFormDropdown(wrapper, trigger, dropdown) {
const body = wrapper.closest('.modal-body');
const bounds = body ? body.getBoundingClientRect() : { top: 0, bottom: window.innerHeight };
const rect = trigger.getBoundingClientRect();
const above = Math.max(0, rect.top - Math.max(0, bounds.top) - 8);
const below = Math.max(0, Math.min(window.innerHeight, bounds.bottom) - rect.bottom - 8);
const desired = Math.min(280, dropdown.scrollHeight + 2);
const openAbove = below < desired && above > below;
dropdown.style.top = openAbove ? 'auto' : 'calc(100% + 4px)';
dropdown.style.bottom = openAbove ? 'calc(100% + 4px)' : 'auto';
dropdown.style.maxHeight = Math.min(280, openAbove ? above : below) + 'px';
dropdown.style.boxSizing = 'border-box';
}
function syncBatchFormSelect(selectId) {
const reg = batchFormSelectMap[selectId];
if (!reg) return;
@@ -1457,6 +1476,7 @@ function enhanceBatchFormSelect(selectId, options) {
if (!open) {
wrapper.classList.add('open');
trigger.setAttribute('aria-expanded', 'true');
positionBatchFormDropdown(wrapper, trigger, dropdown);
}
});
@@ -1857,6 +1877,7 @@ async function showBatchQueueDetail(queueId) {
<div class="bq-kv"><span class="bq-kv__k">${escapeHtml(_t('batchQueueDetailModal.queueTitle'))}</span><span class="bq-kv__v" id="bq-title-val">${allowSubtaskMutation ? `<span class="bq-inline-editable" onclick="startInlineEditTitle()" title="${escapeHtml(_t('common.edit'))}">${escapeHtml(queue.title || _t('tasks.batchQueueUntitled'))}</span>` : escapeHtml(queue.title || _t('tasks.batchQueueUntitled'))}</span></div>
<div class="bq-kv"><span class="bq-kv__k">${escapeHtml(_t('batchQueueDetailModal.role'))}</span><span class="bq-kv__v" id="bq-role-val">${allowSubtaskMutation ? `<span class="bq-inline-editable" onclick="startInlineEditRole()" title="${escapeHtml(_t('common.edit'))}">${roleLineVal}</span>` : roleLineVal}</span></div>
<div class="bq-kv"><span class="bq-kv__k">${escapeHtml(_t('batchImportModal.agentMode'))}</span><span class="bq-kv__v" id="bq-agentmode-val">${allowSubtaskMutation ? `<span class="bq-inline-editable" onclick="startInlineEditAgentMode()" title="${escapeHtml(_t('common.edit'))}">${escapeHtml(agentModeText)}</span>` : escapeHtml(agentModeText)}</span></div>
<div class="bq-kv"><span class="bq-kv__k">${escapeHtml(_t('batchImportModal.hitlPolicy'))}</span><span class="bq-kv__v" id="bq-hitl-val">${allowSubtaskMutation ? `<button type="button" class="btn-link" onclick="startInlineEditHITLPolicy()" title="${escapeAttr(_t('common.edit'))}">${escapeHtml(batchHITLPolicyLabel(queue.hitlPolicy))}</button>` : escapeHtml(batchHITLPolicyLabel(queue.hitlPolicy))}</span></div>
<div class="bq-kv"><span class="bq-kv__k">${escapeHtml(_t('batchImportModal.scheduleMode'))}</span><span class="bq-kv__v" id="bq-schedule-val">${allowSubtaskMutation ? `<span class="bq-inline-editable" onclick="startInlineEditSchedule()" title="${escapeHtml(_t('common.edit'))}">${scheduleDetail}</span>` : scheduleDetail}</span></div>
<div class="bq-kv"><span class="bq-kv__k">${escapeHtml(_t('batchQueueDetailModal.concurrency'))}</span><span class="bq-kv__v" id="bq-concurrency-val">${allowSubtaskMutation ? `<span class="bq-inline-editable" onclick="startInlineEditConcurrency()" title="${escapeHtml(_t('common.edit'))}">${escapeHtml(String(queue.concurrency && queue.concurrency > 0 ? queue.concurrency : 1))}</span>` : escapeHtml(String(queue.concurrency && queue.concurrency > 0 ? queue.concurrency : 1))}</span></div>
<div class="bq-kv"><span class="bq-kv__k">${escapeHtml(_t('batchQueueDetailModal.taskTotal'))}</span><span class="bq-kv__v">${queue.tasks.length}</span></div>
@@ -2920,3 +2941,54 @@ document.addEventListener('DOMContentLoaded', function () {
initBatchQueuesFilterSelects();
initBatchFormSelects();
});
const BATCH_HITL_POLICIES = {
'': 'hitlInherit', off: 'hitlOff', human: 'hitlHuman',
audit_agent: 'hitlAgent', review_edit: 'hitlReviewEdit'
};
function batchHITLPolicyLabel(policy) {
return _t('batchImportModal.' + (BATCH_HITL_POLICIES[policy || ''] || 'hitlInherit'));
}
async function startInlineEditHITLPolicy() {
if (typeof requirePermission === 'function' && !requirePermission('tasks:write')) return;
const queueId = batchQueuesState.currentQueueId;
const container = document.getElementById('bq-hitl-val');
if (!queueId || !container) return;
try {
const response = await apiFetch(`/api/batch-tasks/${queueId}`);
if (!response.ok) throw new Error(_t('tasks.loadTaskListFailed'));
const { queue } = await response.json();
if (batchQueuesState.currentQueueId !== queueId || !batchQueueAllowsSubtaskMutation(queue)) return;
container.innerHTML = `<select id="bq-edit-hitl" aria-label="${escapeAttr(_t('batchImportModal.hitlPolicy'))}">${Object.keys(BATCH_HITL_POLICIES).map(policy => `<option value="${policy}" ${policy === (queue.hitlPolicy || '') ? 'selected' : ''}>${escapeHtml(batchHITLPolicyLabel(policy))}</option>`).join('')}</select>`;
const select = document.getElementById('bq-edit-hitl');
select.focus();
select.addEventListener('keydown', e => {
if (e.key === 'Escape') showBatchQueueDetail(queueId);
});
select.addEventListener('change', async () => {
select.disabled = true;
try {
const result = await apiFetch(`/api/batch-tasks/${queueId}/metadata`, {
method: 'PUT', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
title: queue.title || '', role: queue.role || '',
hitlPolicy: select.value
})
});
if (!result.ok) {
const error = await result.json().catch(() => ({}));
throw new Error(error.error || _t('tasks.updateTaskFailed'));
}
if (batchQueuesState.currentQueueId === queueId) showBatchQueueDetail(queueId);
refreshBatchQueues();
} catch (error) {
select.disabled = false;
alert(error.message);
}
});
} catch (error) { alert(error.message); }
}
window.startInlineEditHITLPolicy = startInlineEditHITLPolicy;
+12
View File
@@ -6125,6 +6125,17 @@
</select>
<div class="form-hint" style="margin-top: 4px;" data-i18n="batchImportModal.agentModeHint">与对话页一致:Eino 单代理(ADK),或 Deep / Plan-Execute / Supervisor(后三种需已启用多代理)。</div>
</div>
<div class="form-group">
<label for="batch-queue-hitl-policy" data-i18n="batchImportModal.hitlPolicy">工具审批</label>
<select id="batch-queue-hitl-policy">
<option value="" data-i18n="batchImportModal.hitlInherit">沿用全局设置</option>
<option value="off" data-i18n="batchImportModal.hitlOff">关闭审批</option>
<option value="human" data-i18n="batchImportModal.hitlHuman">人工审批</option>
<option value="audit_agent" data-i18n="batchImportModal.hitlAgent">Agent 审批</option>
<option value="review_edit" data-i18n="batchImportModal.hitlReviewEdit">Agent 审查编辑</option>
</select>
<div class="form-hint" data-i18n="batchImportModal.hitlHint">队列内所有任务(含后续添加的任务)使用此设置;白名单、审计策略和等待时限沿用全局配置。</div>
</div>
<div class="form-group">
<label for="batch-queue-concurrency" data-i18n="batchImportModal.concurrency">并发数</label>
<input type="number" id="batch-queue-concurrency" min="1" max="8" value="1" style="width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px; font-size: 0.875rem;" />
@@ -6197,6 +6208,7 @@
</div>
<div class="modal-body">
<div class="form-group">
<p class="form-hint" data-i18n="batchImportModal.hitlSubtaskHint">新增任务沿用队列的工具审批设置,可在队列详情中修改。</p>
<label for="add-task-message" data-i18n="addBatchTaskModal.taskMessage">任务消息</label>
<textarea id="add-task-message" class="form-control" rows="5" data-i18n="addBatchTaskModal.taskMessagePlaceholder" data-i18n-attr="placeholder" placeholder="请输入任务消息"></textarea>
</div>