feat(file-check): 增加文件检核进度展示功能及相关配置
This commit is contained in:
1 parent
d3cfd24d6f
commit
9b36ced288
11 files changed
+361
-13
No files matched your search
@@ -12,12 +12,14 @@ import { Bot, Plus, Trash2, Users } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import AgentPermissionModal from './components/AgentPermissionModal.vue';
|
||||
import AgentTestModal from './components/AgentTestModal.vue';
|
||||
import AgentToolRunProgressConfig from './components/AgentToolRunProgressConfig.vue';
|
||||
import { useAgentsAdmin } from './composables/useAgentsAdmin';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const {
|
||||
agents,
|
||||
scheduleTasks,
|
||||
activeUsers,
|
||||
isLoading,
|
||||
isSaving,
|
||||
@@ -195,6 +197,12 @@ onMounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AgentToolRunProgressConfig
|
||||
v-if="form.type === 'api' && form.dify_app_type !== 'workflow'"
|
||||
:form="form"
|
||||
:schedule-tasks="scheduleTasks"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex justify-end">
|
||||
<button type="button" class="btn-primary btn-lg" @click="submitAgent">
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* features/admin/modules/agents/components/AgentToolRunProgressConfig.vue
|
||||
* 用途:应用管理表单中的 tool_run_progress 能力配置区块。
|
||||
* 依赖:agent.types AgentFormState、schedule.types ScheduleTask、vue-i18n。
|
||||
* 逻辑:AgentsPage 在 API 集成类型下挂载本组件;schedule_task_id 写入 extra_config.tool_run_progress。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import type { AgentFormState } from '@/features/admin/types/agent.types';
|
||||
import type { ScheduleTask } from '@/shared/types/schedule.types';
|
||||
|
||||
defineProps<{
|
||||
form: AgentFormState;
|
||||
scheduleTasks: ScheduleTask[];
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="col-span-1 md:col-span-2 rounded-2xl border border-default bg-surface-soft/40 p-5 space-y-4">
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div>
|
||||
<h4 class="text-sm font-semibold text-primary">{{ $t('admin.agent.toolRunProgress.title') }}</h4>
|
||||
<p class="mt-1 text-xs text-muted">{{ $t('admin.agent.toolRunProgress.subtitle') }}</p>
|
||||
</div>
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary shrink-0">
|
||||
<input v-model="form.tool_run_progress_enabled" type="checkbox" class="admin-checkbox" />
|
||||
<span>{{ $t('admin.agent.toolRunProgress.enable') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<template v-if="form.tool_run_progress_enabled">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">
|
||||
{{ $t('admin.agent.toolRunProgress.scheduleTaskId') }}
|
||||
</label>
|
||||
<select
|
||||
v-model="form.schedule_task_id"
|
||||
class="w-full input-field text-sm"
|
||||
:disabled="scheduleTasks.length === 0"
|
||||
>
|
||||
<option :value="null">
|
||||
{{ scheduleTasks.length === 0
|
||||
? $t('admin.agent.toolRunProgress.noScheduleTasks')
|
||||
: $t('admin.agent.toolRunProgress.selectScheduleTask') }}
|
||||
</option>
|
||||
<option v-for="task in scheduleTasks" :key="task.id" :value="task.id">
|
||||
{{ task.name }}
|
||||
</option>
|
||||
</select>
|
||||
<p class="text-xs text-muted">{{ $t('admin.agent.toolRunProgress.scheduleTaskHint') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">
|
||||
{{ $t('admin.agent.toolRunProgress.pollInterval') }}
|
||||
</label>
|
||||
<input
|
||||
v-model.number="form.poll_interval_seconds"
|
||||
type="number"
|
||||
min="1"
|
||||
max="30"
|
||||
class="w-full input-field text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary">
|
||||
<input v-model="form.lock_input_when_running" type="checkbox" class="admin-checkbox" />
|
||||
<span>{{ $t('admin.agent.toolRunProgress.lockInput') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -16,10 +16,12 @@ import {
|
||||
testAdminAgent,
|
||||
updateAdminAgent,
|
||||
} from '@/features/admin/api/admin.api';
|
||||
import { listAdminSchedules } from '@/features/admin/api/schedule.api';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import type { AdminUserRow } from '@/features/admin/types/admin.types';
|
||||
import type { AgentFormState, AgentRow, AgentSuggestedQuestionItem, AgentTestResult } from '@/features/admin/types/agent.types';
|
||||
import { createEmptyAgentForm } from '@/features/admin/types/agent.types';
|
||||
import type { ScheduleTask } from '@/shared/types/schedule.types';
|
||||
|
||||
const normalizeSuggestedQuestions = (value: unknown): AgentSuggestedQuestionItem[] => {
|
||||
if (!Array.isArray(value)) return [];
|
||||
@@ -37,12 +39,65 @@ const normalizeSuggestedQuestions = (value: unknown): AgentSuggestedQuestionItem
|
||||
.filter((item): item is AgentSuggestedQuestionItem => !!item);
|
||||
};
|
||||
|
||||
/**
|
||||
* 从 Agent extra_config 解析 tool_run_progress 表单字段。
|
||||
* 核心逻辑:capabilities 含 tool_run_progress 时视为启用;task_id 与 schedule_task_id 等价。
|
||||
*/
|
||||
const parseToolRunProgressFromExtra = (extra: Record<string, unknown> | undefined) => {
|
||||
const capabilities = Array.isArray(extra?.capabilities)
|
||||
? extra.capabilities.map((item) => String(item))
|
||||
: [];
|
||||
const enabled = capabilities.includes('tool_run_progress');
|
||||
const cfg = extra?.tool_run_progress && typeof extra.tool_run_progress === 'object'
|
||||
? (extra.tool_run_progress as Record<string, unknown>)
|
||||
: {};
|
||||
const rawTaskId = cfg.schedule_task_id ?? cfg.task_id;
|
||||
const parsedTaskId = rawTaskId != null && rawTaskId !== '' ? Number(rawTaskId) : null;
|
||||
const pollRaw = Number(cfg.poll_interval_seconds);
|
||||
return {
|
||||
tool_run_progress_enabled: enabled,
|
||||
schedule_task_id: Number.isFinite(parsedTaskId) && parsedTaskId! > 0 ? parsedTaskId : null,
|
||||
poll_interval_seconds: Number.isFinite(pollRaw) && pollRaw > 0 ? Math.min(pollRaw, 30) : 2,
|
||||
lock_input_when_running: cfg.lock_input_when_running !== false,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* 将表单中的 tool_run_progress 字段写入 extra_config。
|
||||
* 核心逻辑:启用时追加 capabilities 并写入 schedule_task_id;禁用时移除能力声明。
|
||||
*/
|
||||
const applyToolRunProgressToExtra = (extraConfig: Record<string, unknown>, form: AgentFormState): void => {
|
||||
const capabilities = Array.isArray(extraConfig.capabilities)
|
||||
? extraConfig.capabilities.map((item) => String(item)).filter((item) => item !== 'tool_run_progress')
|
||||
: [];
|
||||
|
||||
if (form.tool_run_progress_enabled) {
|
||||
capabilities.push('tool_run_progress');
|
||||
extraConfig.capabilities = capabilities;
|
||||
extraConfig.tool_run_progress = {
|
||||
type: 'file_check',
|
||||
schedule_task_id: form.schedule_task_id,
|
||||
poll_interval_seconds: form.poll_interval_seconds,
|
||||
lock_input_when_running: form.lock_input_when_running,
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
if (capabilities.length) {
|
||||
extraConfig.capabilities = capabilities;
|
||||
} else {
|
||||
delete extraConfig.capabilities;
|
||||
}
|
||||
delete extraConfig.tool_run_progress;
|
||||
};
|
||||
|
||||
export function useAgentsAdmin() {
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
|
||||
const agents = ref<AgentRow[]>([]);
|
||||
const users = ref<AdminUserRow[]>([]);
|
||||
const scheduleTasks = ref<ScheduleTask[]>([]);
|
||||
const isLoading = ref(true);
|
||||
const isSaving = ref(false);
|
||||
const isEditing = ref(false);
|
||||
@@ -82,9 +137,18 @@ export function useAgentsAdmin() {
|
||||
}
|
||||
};
|
||||
|
||||
const loadScheduleTasks = async (): Promise<void> => {
|
||||
try {
|
||||
scheduleTasks.value = await listAdminSchedules();
|
||||
} catch (e) {
|
||||
console.error('Error loading schedule tasks:', e);
|
||||
scheduleTasks.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const loadAll = async (): Promise<void> => {
|
||||
isLoading.value = true;
|
||||
await Promise.all([loadAgents(), loadUsers()]);
|
||||
await Promise.all([loadAgents(), loadUsers(), loadScheduleTasks()]);
|
||||
isLoading.value = false;
|
||||
};
|
||||
|
||||
@@ -95,6 +159,10 @@ export function useAgentsAdmin() {
|
||||
};
|
||||
|
||||
const selectAgent = (agent: AgentRow): void => {
|
||||
const extra = (agent.extra_config && typeof agent.extra_config === 'object')
|
||||
? agent.extra_config
|
||||
: {};
|
||||
const toolRunProgress = parseToolRunProgressFromExtra(extra);
|
||||
selectedAgentId.value = agent.id;
|
||||
form.value = {
|
||||
id: agent.id,
|
||||
@@ -109,6 +177,7 @@ export function useAgentsAdmin() {
|
||||
suggested_questions_style: agent.extra_config?.suggested_questions_style === 'styled' ? 'styled' : 'plain',
|
||||
suggested_questions: normalizeSuggestedQuestions(agent.extra_config?.suggested_questions),
|
||||
is_active: agent.is_active,
|
||||
...toolRunProgress,
|
||||
};
|
||||
isEditing.value = true;
|
||||
};
|
||||
@@ -141,14 +210,30 @@ export function useAgentsAdmin() {
|
||||
msg.warning(t('admin.dept.msg.nameRequired'));
|
||||
return;
|
||||
}
|
||||
const supportsToolRunProgress = form.value.type === 'api' && form.value.dify_app_type !== 'workflow';
|
||||
if (supportsToolRunProgress && form.value.tool_run_progress_enabled && !form.value.schedule_task_id) {
|
||||
msg.warning(t('admin.agent.toolRunProgress.scheduleTaskRequired'));
|
||||
return;
|
||||
}
|
||||
|
||||
isSaving.value = true;
|
||||
const extra_config: Record<string, unknown> = {};
|
||||
const editingAgent = isEditing.value
|
||||
? agents.value.find((agent) => agent.id === form.value.id)
|
||||
: null;
|
||||
const extra_config: Record<string, unknown> = {
|
||||
...(editingAgent?.extra_config && typeof editingAgent.extra_config === 'object'
|
||||
? editingAgent.extra_config
|
||||
: {}),
|
||||
};
|
||||
if (form.value.type === 'iframe' && form.value.iframe_url) {
|
||||
extra_config.iframe_url = form.value.iframe_url;
|
||||
} else {
|
||||
delete extra_config.iframe_url;
|
||||
}
|
||||
if (form.value.type === 'api') {
|
||||
extra_config.dify_app_type = form.value.dify_app_type === 'workflow' ? 'workflow' : 'chatflow';
|
||||
} else {
|
||||
delete extra_config.dify_app_type;
|
||||
}
|
||||
extra_config.suggested_questions_style = form.value.suggested_questions_style === 'styled' ? 'styled' : 'plain';
|
||||
extra_config.suggested_questions = form.value.suggested_questions
|
||||
@@ -157,6 +242,11 @@ export function useAgentsAdmin() {
|
||||
group: String(item.group || '').trim(),
|
||||
}))
|
||||
.filter((item) => item.question);
|
||||
if (supportsToolRunProgress) {
|
||||
applyToolRunProgressToExtra(extra_config, form.value);
|
||||
} else {
|
||||
applyToolRunProgressToExtra(extra_config, { ...form.value, tool_run_progress_enabled: false });
|
||||
}
|
||||
|
||||
try {
|
||||
const editingId = isEditing.value ? Number(form.value.id) : null;
|
||||
@@ -310,6 +400,7 @@ export function useAgentsAdmin() {
|
||||
return {
|
||||
agents,
|
||||
users,
|
||||
scheduleTasks,
|
||||
activeUsers,
|
||||
isLoading,
|
||||
isSaving,
|
||||
|
||||
Reference in new issue
Block a user