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,
|
||||
|
||||
@@ -46,6 +46,12 @@ export interface AgentFormState {
|
||||
suggested_questions_style: 'plain' | 'styled';
|
||||
suggested_questions: AgentSuggestedQuestionItem[];
|
||||
is_active: boolean;
|
||||
/** 是否启用 extra_config.capabilities 中的 tool_run_progress */
|
||||
tool_run_progress_enabled: boolean;
|
||||
/** 对应 ScheduleTask.id,写入 extra_config.tool_run_progress.schedule_task_id */
|
||||
schedule_task_id: number | null;
|
||||
poll_interval_seconds: number;
|
||||
lock_input_when_running: boolean;
|
||||
}
|
||||
|
||||
export const createEmptyAgentForm = (): AgentFormState => ({
|
||||
@@ -60,4 +66,8 @@ export const createEmptyAgentForm = (): AgentFormState => ({
|
||||
suggested_questions_style: 'plain',
|
||||
suggested_questions: [],
|
||||
is_active: true,
|
||||
tool_run_progress_enabled: false,
|
||||
schedule_task_id: null,
|
||||
poll_interval_seconds: 2,
|
||||
lock_input_when_running: true,
|
||||
});
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
* 依赖:useToolRunProgress、toolRunProgressConfig、ChatMessage。
|
||||
|
||||
* 逻辑:按助手消息 ChatLog.run_id 展示进度,每轮问答独立绑定;无 run_id 时不展示进度卡片。
|
||||
* 逻辑:仅当 chat_logs.run_id 已绑定(消息含 run_id 或 for-log 已解析到批次)时展示进度卡片;未绑定时不展示等待条,后台仍轮询 for-log。
|
||||
|
||||
*/
|
||||
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
isRunningToolRunStatus,
|
||||
resolveScheduleTaskId,
|
||||
resolveMessageAnchorKey,
|
||||
resolveToolRunProgressOptions,
|
||||
} from '../utils/toolRunProgressConfig';
|
||||
|
||||
|
||||
@@ -62,6 +63,8 @@ export function useChatPageToolRun(ctx: ChatPageToolRunContext) {
|
||||
|
||||
const pollingChatLogIds = ref<number[]>([]);
|
||||
|
||||
const emptyPollCounts = ref<Record<number, number>>({});
|
||||
|
||||
let pollTimer: number | undefined;
|
||||
|
||||
|
||||
@@ -108,6 +111,8 @@ export function useChatPageToolRun(ctx: ChatPageToolRunContext) {
|
||||
|
||||
const boundScheduleTaskId = computed(() => resolveScheduleTaskId(rawToolRunConfig.value));
|
||||
|
||||
const progressPollOptions = computed(() => resolveToolRunProgressOptions(rawToolRunConfig.value));
|
||||
|
||||
|
||||
|
||||
const clearPollTimer = () => {
|
||||
@@ -246,6 +251,12 @@ export function useChatPageToolRun(ctx: ChatPageToolRunContext) {
|
||||
|
||||
storeRunPayload(payload.run, chatLogId);
|
||||
|
||||
const nextEmptyCounts = { ...emptyPollCounts.value };
|
||||
|
||||
delete nextEmptyCounts[chatLogId];
|
||||
|
||||
emptyPollCounts.value = nextEmptyCounts;
|
||||
|
||||
const msg = ctx.messages.value[messageIndex];
|
||||
|
||||
if (msg && !getRunIdFromMessage(msg)) {
|
||||
@@ -254,6 +265,32 @@ export function useChatPageToolRun(ctx: ChatPageToolRunContext) {
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
const nextCount = (emptyPollCounts.value[chatLogId] || 0) + 1;
|
||||
|
||||
emptyPollCounts.value = {
|
||||
|
||||
...emptyPollCounts.value,
|
||||
|
||||
[chatLogId]: nextCount,
|
||||
|
||||
};
|
||||
|
||||
const emptyPollMax = progressPollOptions.value.empty_poll_max;
|
||||
|
||||
if (nextCount >= emptyPollMax) {
|
||||
|
||||
chatLogErrors.value = {
|
||||
|
||||
...chatLogErrors.value,
|
||||
|
||||
[chatLogId]: '暂未找到关联的检核任务,请稍后刷新或查看排程执行记录',
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const nextErrors = { ...chatLogErrors.value };
|
||||
@@ -314,6 +351,8 @@ export function useChatPageToolRun(ctx: ChatPageToolRunContext) {
|
||||
|
||||
pollingChatLogIds.value = [];
|
||||
|
||||
emptyPollCounts.value = {};
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
@@ -398,7 +437,19 @@ export function useChatPageToolRun(ctx: ChatPageToolRunContext) {
|
||||
|
||||
const hasRunning = Object.values(nextRuns).some((run) => isRunningToolRunStatus(run.status));
|
||||
|
||||
if (hasRunning) schedulePoll();
|
||||
const emptyPollMax = progressPollOptions.value.empty_poll_max;
|
||||
|
||||
const hasPendingChatLogs = chatLogIds.some((chatLogId) => {
|
||||
|
||||
if (chatLogRunMap.value[chatLogId]) return false;
|
||||
|
||||
if (chatLogErrors.value[chatLogId]) return false;
|
||||
|
||||
return (emptyPollCounts.value[chatLogId] || 0) < emptyPollMax;
|
||||
|
||||
});
|
||||
|
||||
if (hasRunning || hasPendingChatLogs) schedulePoll();
|
||||
|
||||
};
|
||||
|
||||
@@ -424,6 +475,8 @@ export function useChatPageToolRun(ctx: ChatPageToolRunContext) {
|
||||
|
||||
clearPollTimer();
|
||||
|
||||
emptyPollCounts.value = {};
|
||||
|
||||
},
|
||||
|
||||
);
|
||||
@@ -532,7 +585,7 @@ export function useChatPageToolRun(ctx: ChatPageToolRunContext) {
|
||||
|
||||
* 判断是否在该助手消息后展示进度卡片。
|
||||
|
||||
* 核心逻辑:已解析到 run_id 时展示;执行中、已完成、加载中或查询报错均保留卡片,无 run_id 不展示。
|
||||
* 核心逻辑:chat_logs.run_id 未绑定时不展示;已解析到 run_id 后展示进度/加载/报错状态。
|
||||
|
||||
*/
|
||||
|
||||
|
||||
Reference in new issue
Block a user