feat(rohs-check): 新增 RoHS 对话轮次注册与检核批次绑定功能
This commit is contained in:
1 parent
9cba517bff
commit
fa0cdee8df
20 files changed
+1050
-201
No files matched your search
+6
-98
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
import { ChevronDown, ChevronUp, Plus } from 'lucide-vue-next';
|
||||
import { useSchedulesAdminContext } from '../composables/schedules.context';
|
||||
import ScheduleCronDesigner from './ScheduleCronDesigner.vue';
|
||||
|
||||
const admin = useSchedulesAdminContext();
|
||||
</script>
|
||||
@@ -344,103 +345,10 @@ const admin = useSchedulesAdminContext();
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<div class="rounded-2xl border border-default bg-surface-soft/40 p-4">
|
||||
<div class="mb-3">
|
||||
<h4 class="text-base font-bold text-primary">{{ $t('admin.schedule.form.cronTitle') }}</h4>
|
||||
<p class="text-sm text-muted">{{ $t('admin.schedule.form.cronHint') }}</p>
|
||||
</div>
|
||||
<div
|
||||
class="segment-control segment-control--cols-4 segment-control--sm"
|
||||
role="radiogroup"
|
||||
:aria-label="$t('admin.schedule.form.cronTitle')"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="admin.scheduleCronDesigner.mode === 'every_minutes'"
|
||||
class="segment-item"
|
||||
:class="admin.scheduleCronDesigner.mode === 'every_minutes' ? 'segment-item--active' : ''"
|
||||
@click="admin.scheduleCronDesigner.mode = 'every_minutes'"
|
||||
>
|
||||
{{ $t('admin.schedule.form.everyMinutes') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="admin.scheduleCronDesigner.mode === 'hourly'"
|
||||
class="segment-item"
|
||||
:class="admin.scheduleCronDesigner.mode === 'hourly' ? 'segment-item--active' : ''"
|
||||
@click="admin.scheduleCronDesigner.mode = 'hourly'"
|
||||
>
|
||||
{{ $t('admin.schedule.form.hourly') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="admin.scheduleCronDesigner.mode === 'daily'"
|
||||
class="segment-item"
|
||||
:class="admin.scheduleCronDesigner.mode === 'daily' ? 'segment-item--active' : ''"
|
||||
@click="admin.scheduleCronDesigner.mode = 'daily'"
|
||||
>
|
||||
{{ $t('admin.schedule.form.daily') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="admin.scheduleCronDesigner.mode === 'weekly'"
|
||||
class="segment-item"
|
||||
:class="admin.scheduleCronDesigner.mode === 'weekly' ? 'segment-item--active' : ''"
|
||||
@click="admin.scheduleCronDesigner.mode = 'weekly'"
|
||||
>
|
||||
{{ $t('admin.schedule.form.weekly') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid grid-cols-1 gap-3 md:grid-cols-3">
|
||||
<template v-if="admin.scheduleCronDesigner.mode === 'every_minutes'">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.minuteInterval') }}</label>
|
||||
<input v-model.number="admin.scheduleCronDesigner.every_minutes" type="number" min="1" max="59" class="input-field !text-sm !leading-5" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="admin.scheduleCronDesigner.mode === 'hourly'">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.minuteOfHour') }}</label>
|
||||
<input v-model.number="admin.scheduleCronDesigner.hourly_minute" type="number" min="0" max="59" class="input-field !text-sm !leading-5" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="admin.scheduleCronDesigner.mode === 'daily'">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.hour') }}</label>
|
||||
<input v-model.number="admin.scheduleCronDesigner.daily_hour" type="number" min="0" max="23" class="input-field !text-sm !leading-5" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.minute') }}</label>
|
||||
<input v-model.number="admin.scheduleCronDesigner.daily_minute" type="number" min="0" max="59" class="input-field !text-sm !leading-5" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.weekday') }}</label>
|
||||
<select v-model.number="admin.scheduleCronDesigner.weekly_day" class="input-field !text-sm !leading-5">
|
||||
<option v-for="d in admin.weeklyDayOptions" :key="d.value" :value="d.value">{{ d.label }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.hour') }}</label>
|
||||
<input v-model.number="admin.scheduleCronDesigner.weekly_hour" type="number" min="0" max="23" class="input-field !text-sm !leading-5" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.minute') }}</label>
|
||||
<input v-model.number="admin.scheduleCronDesigner.weekly_minute" type="number" min="0" max="59" class="input-field !text-sm !leading-5" />
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="mt-4 rounded-xl border border-dashed border-default bg-surface-soft px-4 py-3 text-xs text-secondary">
|
||||
{{ $t('admin.schedule.form.cronPreview') }}:<span class="font-mono text-primary">{{ admin.scheduleCronPreview }}</span>
|
||||
<span v-if="admin.scheduleNextRunPreview" class="ml-4">{{ $t('admin.schedule.form.nextRun') }}:<span class="font-medium text-primary">{{ admin.formatDateTime(admin.scheduleNextRunPreview.toISOString()) }}</span></span>
|
||||
</div>
|
||||
</div>
|
||||
<ScheduleCronDesigner
|
||||
:designer="admin.cronDesigner"
|
||||
:format-date-time="admin.formatDateTime"
|
||||
/>
|
||||
|
||||
<div class="input-field px-3 py-2.5">
|
||||
<div class="flex flex-col gap-2 md:flex-row md:items-center">
|
||||
@@ -522,7 +430,7 @@ const admin = useSchedulesAdminContext();
|
||||
<button
|
||||
type="button"
|
||||
class="btn-primary inline-flex items-center gap-2 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="admin.scheduleCreateSaving || !admin.scheduleCreateForm.name || !admin.scheduleCreateForm.owner_user_id"
|
||||
:disabled="admin.scheduleCreateSaving || !admin.scheduleCreateForm.name || !admin.scheduleCreateForm.owner_user_id || !admin.cronDesigner.isValid"
|
||||
@click="admin.createSchedule"
|
||||
>
|
||||
<Plus class="h-4 w-4 shrink-0" />
|
||||
|
||||
-3
@@ -7,7 +7,6 @@ import type { ScheduleRun, ScheduleTask, TestScheduleRunResult } from '@/feature
|
||||
import type { AdminAgentOption, AdminUserRow } from '@/features/admin/types/admin.types';
|
||||
import type { KbGroup } from '@/features/kb/api/kb.api';
|
||||
import {
|
||||
createDefaultCronDesigner,
|
||||
createDefaultScheduleCreateForm,
|
||||
createDefaultScheduleSqlEditForm,
|
||||
} from '../../types/schedule-admin.types';
|
||||
@@ -79,7 +78,6 @@ export function createScheduleAdminState() {
|
||||
const scheduleEditingId = ref<number | null>(null);
|
||||
const scheduleCreateForm = ref(createDefaultScheduleCreateForm());
|
||||
const scheduleConfigCollapsed = ref(true);
|
||||
const scheduleCronDesigner = ref(createDefaultCronDesigner());
|
||||
|
||||
const expandedScheduleRunId = ref<number | null>(null);
|
||||
|
||||
@@ -132,7 +130,6 @@ export function createScheduleAdminState() {
|
||||
scheduleEditingId,
|
||||
scheduleCreateForm,
|
||||
scheduleConfigCollapsed,
|
||||
scheduleCronDesigner,
|
||||
expandedScheduleRunId,
|
||||
showTestRunDialog,
|
||||
testRunSchedule,
|
||||
|
||||
+12
-27
@@ -2,7 +2,7 @@
|
||||
* features/admin/modules/schedules/composables/schedule-admin/useScheduleAdminForm.ts
|
||||
* 创建/编辑弹窗:Cron 设计器、负责人/通知人、SQL 配置与提交。
|
||||
*/
|
||||
import { computed, watch } from 'vue';
|
||||
import { computed, markRaw, watch } from 'vue';
|
||||
import type { ComposerTranslation } from 'vue-i18n';
|
||||
import {
|
||||
createAdminSchedule,
|
||||
@@ -14,16 +14,11 @@ import {
|
||||
import type { AdminUserRow } from '@/features/admin/types/admin.types';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
createDefaultCronDesigner,
|
||||
createDefaultScheduleCreateForm,
|
||||
createDefaultScheduleSqlEditForm,
|
||||
} from '../../types/schedule-admin.types';
|
||||
import { buildScheduleConfigPayload } from '../../utils/schedule-form-payload.utils';
|
||||
import {
|
||||
buildCronExprFromDesigner,
|
||||
computeNextRunPreview,
|
||||
parseCronExprToDesigner,
|
||||
} from '../../utils/schedule-cron.utils';
|
||||
import { useScheduleCronDesigner } from '../useScheduleCronDesigner';
|
||||
import type { ScheduleAdminState } from './schedule-admin.state';
|
||||
import type { ScheduleAdminLookups } from './useScheduleAdminLookups';
|
||||
import type { ScheduleAdminList } from './useScheduleAdminList';
|
||||
@@ -37,6 +32,8 @@ export function useScheduleAdminForm(
|
||||
t: ComposerTranslation,
|
||||
) {
|
||||
const msg = useMessage();
|
||||
/** markRaw 避免 SchedulesPage reactive() 深度代理破坏内部 Ref */
|
||||
const cronDesigner = markRaw(useScheduleCronDesigner());
|
||||
const {
|
||||
users,
|
||||
showScheduleCreateModal,
|
||||
@@ -44,7 +41,6 @@ export function useScheduleAdminForm(
|
||||
scheduleEditingId,
|
||||
scheduleCreateForm,
|
||||
scheduleConfigCollapsed,
|
||||
scheduleCronDesigner,
|
||||
scheduleSqlEditForm,
|
||||
scheduleTestLoading,
|
||||
scheduleTestResult,
|
||||
@@ -57,19 +53,6 @@ export function useScheduleAdminForm(
|
||||
let scheduleNotifyCloseTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
let scheduleOwnerCloseTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const weeklyDayOptions = computed(() => [
|
||||
{ value: 1, label: t('admin.schedule.weekday.mon') },
|
||||
{ value: 2, label: t('admin.schedule.weekday.tue') },
|
||||
{ value: 3, label: t('admin.schedule.weekday.wed') },
|
||||
{ value: 4, label: t('admin.schedule.weekday.thu') },
|
||||
{ value: 5, label: t('admin.schedule.weekday.fri') },
|
||||
{ value: 6, label: t('admin.schedule.weekday.sat') },
|
||||
{ value: 0, label: t('admin.schedule.weekday.sun') },
|
||||
]);
|
||||
|
||||
const scheduleCronPreview = computed(() => buildCronExprFromDesigner(scheduleCronDesigner.value));
|
||||
const scheduleNextRunPreview = computed(() => computeNextRunPreview(scheduleCronPreview.value));
|
||||
|
||||
const formatUserOptionLabel = (u: AdminUserRow) =>
|
||||
`${u.real_name || u.username}${u.employee_id ? `(${u.employee_id})` : ''}`;
|
||||
|
||||
@@ -112,7 +95,7 @@ export function useScheduleAdminForm(
|
||||
scheduleNotifyDropdownOpen.value = false;
|
||||
scheduleOwnerQuery.value = '';
|
||||
scheduleOwnerDropdownOpen.value = false;
|
||||
scheduleCronDesigner.value = createDefaultCronDesigner();
|
||||
cronDesigner.reset();
|
||||
};
|
||||
|
||||
const openScheduleCreateModal = async () => {
|
||||
@@ -180,7 +163,7 @@ export function useScheduleAdminForm(
|
||||
}
|
||||
|
||||
scheduleTestResult.value = null;
|
||||
scheduleCronDesigner.value = parseCronExprToDesigner(task.cron_expr);
|
||||
cronDesigner.loadFromExpr(task.cron_expr);
|
||||
syncScheduleOwnerQuery();
|
||||
showScheduleCreateModal.value = true;
|
||||
};
|
||||
@@ -264,6 +247,10 @@ export function useScheduleAdminForm(
|
||||
|
||||
const createSchedule = async () => {
|
||||
if (!scheduleCreateForm.value.name || !scheduleCreateForm.value.owner_user_id) return;
|
||||
if (!cronDesigner.isValid.value) {
|
||||
msg.error(t('admin.schedule.form.cronInvalid'));
|
||||
return;
|
||||
}
|
||||
|
||||
const dst = scheduleCreateForm.value.data_source_type;
|
||||
const hasAgent = !!scheduleCreateForm.value.dify_agent_id;
|
||||
@@ -305,7 +292,7 @@ export function useScheduleAdminForm(
|
||||
name: scheduleCreateForm.value.name,
|
||||
schedule_type: 'platform_app',
|
||||
owner_user_id: scheduleCreateForm.value.owner_user_id,
|
||||
cron_expr: scheduleCronPreview.value,
|
||||
cron_expr: cronDesigner.cronExpr.value,
|
||||
wait_seconds: Math.max(0, Number(scheduleCreateForm.value.wait_seconds || 0)),
|
||||
dify_agent_id: scheduleCreateForm.value.dify_agent_id || undefined,
|
||||
notify_user_ids_json: scheduleCreateForm.value.notify_enabled ? scheduleCreateForm.value.notify_user_ids_json : [],
|
||||
@@ -337,9 +324,7 @@ export function useScheduleAdminForm(
|
||||
};
|
||||
|
||||
return {
|
||||
weeklyDayOptions,
|
||||
scheduleCronPreview,
|
||||
scheduleNextRunPreview,
|
||||
cronDesigner,
|
||||
filteredNotifyUsers,
|
||||
filteredOwnerUsers,
|
||||
openScheduleCreateModal,
|
||||
|
||||
@@ -17,8 +17,6 @@ import {
|
||||
Send,
|
||||
X,
|
||||
} from 'lucide-vue-next';
|
||||
import ToolRunProgressCard from './ToolRunProgressCard.vue';
|
||||
import type { ToolRunProgress } from '../api/toolRunProgress.api';
|
||||
import type { PendingAttachment } from '../types/shipping.types';
|
||||
|
||||
export interface ChatInputAttachmentPolicy {
|
||||
|
||||
@@ -11,7 +11,7 @@ import ToolRunProgressCard from './ToolRunProgressCard.vue';
|
||||
import type { LeaveMessageHandlers } from './messages/LeaveMessageBlock.vue';
|
||||
import type { ShippingMappingHandlers } from './messages/ShippingInventoryMappingMessage.vue';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
import type { ToolRunProgress } from '@/api/toolRunProgress';
|
||||
import type { ToolRunProgress } from '../api/toolRunProgress.api';
|
||||
|
||||
const {
|
||||
messages,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { computed, onBeforeUnmount, ref, type Ref, watch } from 'vue';
|
||||
import { buildLogProgressUrl } from '../utils/toolRunProgressConfig';
|
||||
import { getToolRunProgress, type ToolRunProgress } from '../api/toolRunProgress.api';
|
||||
import type { ToolRunProgressMatchSource } from '../types/tool-run-progress.types';
|
||||
|
||||
export interface ToolRunProgressConfig {
|
||||
type?: string;
|
||||
|
||||
@@ -1,231 +1,685 @@
|
||||
/**
|
||||
|
||||
* 对话页:Agent tool_run_progress 能力轮询(RoHS 等异步任务进度卡片)。
|
||||
|
||||
* 依赖:useToolRunProgress、toolRunProgressConfig、ChatMessage。
|
||||
* 逻辑:按助手消息 ChatLog.run_id 展示进度,每轮问答独立绑定。
|
||||
|
||||
* 逻辑:按助手消息 ChatLog.run_id 展示进度,每轮问答独立绑定;无 run_id 时不展示进度卡片。
|
||||
|
||||
*/
|
||||
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
import type { ToolRunProgress } from '@/api/toolRunProgress';
|
||||
import { getToolRunProgress } from '@/api/toolRunProgress';
|
||||
|
||||
import type { ToolRunProgress } from '../api/toolRunProgress.api';
|
||||
|
||||
import { getToolRunProgress } from '../api/toolRunProgress.api';
|
||||
|
||||
import type { ToolRunProgressConfig } from '../composables/useToolRunProgress';
|
||||
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
|
||||
import type { Ref } from 'vue';
|
||||
|
||||
import {
|
||||
|
||||
assistantMessageHasError,
|
||||
collectAssistantRunIds,
|
||||
|
||||
buildLogProgressUrl,
|
||||
|
||||
collectAssistantProgressTargets,
|
||||
|
||||
getChatLogIdFromMessage,
|
||||
|
||||
getRunIdFromMessage,
|
||||
|
||||
isRunningToolRunStatus,
|
||||
|
||||
resolveLogProgressBaseUrl,
|
||||
|
||||
resolveScheduleTaskId,
|
||||
|
||||
resolveMessageAnchorKey,
|
||||
|
||||
} from '../utils/toolRunProgressConfig';
|
||||
|
||||
|
||||
|
||||
export interface ChatPageToolRunContext {
|
||||
|
||||
currentAgent: Ref<{ id?: number; extra_config?: Record<string, unknown> } | null>;
|
||||
|
||||
conversationId: Ref<string | null>;
|
||||
|
||||
messages: Ref<ChatMessage[]>;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function useChatPageToolRun(ctx: ChatPageToolRunContext) {
|
||||
|
||||
const runsById = ref<Record<number, ToolRunProgress>>({});
|
||||
|
||||
const runErrors = ref<Record<number, string>>({});
|
||||
|
||||
const chatLogRunMap = ref<Record<number, number>>({});
|
||||
|
||||
const chatLogErrors = ref<Record<number, string>>({});
|
||||
|
||||
const pollingRunIds = ref<number[]>([]);
|
||||
|
||||
const pollingChatLogIds = ref<number[]>([]);
|
||||
|
||||
let pollTimer: number | undefined;
|
||||
|
||||
|
||||
|
||||
const rawToolRunConfig = computed(() => {
|
||||
|
||||
const extra = ctx.currentAgent.value?.extra_config || {};
|
||||
|
||||
const raw = extra.tool_run_progress;
|
||||
|
||||
return raw && typeof raw === 'object' ? (raw as ToolRunProgressConfig) : null;
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
const toolRunProgressConfig = computed<ToolRunProgressConfig | null>(() => {
|
||||
|
||||
const extra = ctx.currentAgent.value?.extra_config || {};
|
||||
|
||||
const capabilities = Array.isArray(extra.capabilities)
|
||||
|
||||
? extra.capabilities.map((item: unknown) => String(item))
|
||||
|
||||
: [];
|
||||
|
||||
if (!capabilities.includes('tool_run_progress')) return null;
|
||||
|
||||
const cfg = rawToolRunConfig.value;
|
||||
|
||||
if (!cfg) return null;
|
||||
|
||||
return {
|
||||
|
||||
...cfg,
|
||||
|
||||
schedule_task_id: resolveScheduleTaskId(cfg),
|
||||
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
const boundScheduleTaskId = computed(() => resolveScheduleTaskId(rawToolRunConfig.value));
|
||||
|
||||
|
||||
|
||||
const clearPollTimer = () => {
|
||||
|
||||
if (pollTimer !== undefined) {
|
||||
|
||||
window.clearTimeout(pollTimer);
|
||||
|
||||
pollTimer = undefined;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const resolveDetailUrl = (runId: number) => {
|
||||
|
||||
const template = String(rawToolRunConfig.value?.detail_url_template || '').trim();
|
||||
|
||||
if (!template) return '';
|
||||
|
||||
return template.replace('{run_id}', encodeURIComponent(String(runId)));
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const resolveForLogUrl = (chatLogId: number) => {
|
||||
|
||||
const taskId = boundScheduleTaskId.value;
|
||||
|
||||
if (!taskId) return '';
|
||||
|
||||
const base = resolveLogProgressBaseUrl(rawToolRunConfig.value || {});
|
||||
|
||||
return buildLogProgressUrl(base, taskId, chatLogId);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 解析消息对应的检核批次 ID(消息 run_id 优先,其次 for-log 映射)。
|
||||
|
||||
*/
|
||||
|
||||
const resolveMessageRunId = (msg: ChatMessage): number | null => {
|
||||
|
||||
const direct = getRunIdFromMessage(msg);
|
||||
|
||||
if (direct) return direct;
|
||||
|
||||
const chatLogId = getChatLogIdFromMessage(msg);
|
||||
|
||||
if (!chatLogId) return null;
|
||||
|
||||
const mapped = chatLogRunMap.value[chatLogId];
|
||||
|
||||
return mapped && mapped > 0 ? mapped : null;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const storeRunPayload = (run: ToolRunProgress, chatLogId?: number | null) => {
|
||||
|
||||
const runId = Number(run.run_id);
|
||||
|
||||
if (!Number.isFinite(runId) || runId <= 0) return;
|
||||
|
||||
runsById.value = { ...runsById.value, [runId]: run };
|
||||
|
||||
const nextErrors = { ...runErrors.value };
|
||||
|
||||
delete nextErrors[runId];
|
||||
|
||||
runErrors.value = nextErrors;
|
||||
|
||||
if (chatLogId && chatLogId > 0) {
|
||||
|
||||
chatLogRunMap.value = { ...chatLogRunMap.value, [chatLogId]: runId };
|
||||
|
||||
const nextChatLogErrors = { ...chatLogErrors.value };
|
||||
|
||||
delete nextChatLogErrors[chatLogId];
|
||||
|
||||
chatLogErrors.value = nextChatLogErrors;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const refreshRun = async (runId: number) => {
|
||||
|
||||
const url = resolveDetailUrl(runId);
|
||||
|
||||
if (!url) return;
|
||||
|
||||
try {
|
||||
|
||||
const payload = await getToolRunProgress(url);
|
||||
|
||||
if (payload.run) {
|
||||
runsById.value = { ...runsById.value, [runId]: payload.run };
|
||||
|
||||
storeRunPayload(payload.run);
|
||||
|
||||
}
|
||||
|
||||
const nextErrors = { ...runErrors.value };
|
||||
|
||||
delete nextErrors[runId];
|
||||
|
||||
runErrors.value = nextErrors;
|
||||
|
||||
} catch (e: unknown) {
|
||||
|
||||
runErrors.value = {
|
||||
|
||||
...runErrors.value,
|
||||
|
||||
[runId]: e instanceof Error ? e.message : '任务进度查询失败',
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 按 chat_log_id 走 for-log 解析批次;成功时回写消息 run_id 供后续 detail 轮询。
|
||||
|
||||
*/
|
||||
|
||||
const refreshRunByChatLog = async (chatLogId: number, messageIndex: number) => {
|
||||
|
||||
const url = resolveForLogUrl(chatLogId);
|
||||
|
||||
if (!url) return;
|
||||
|
||||
try {
|
||||
|
||||
const payload = await getToolRunProgress(url);
|
||||
|
||||
if (payload.run) {
|
||||
|
||||
storeRunPayload(payload.run, chatLogId);
|
||||
|
||||
const msg = ctx.messages.value[messageIndex];
|
||||
|
||||
if (msg && !getRunIdFromMessage(msg)) {
|
||||
|
||||
msg.run_id = Number(payload.run.run_id);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const nextErrors = { ...chatLogErrors.value };
|
||||
|
||||
delete nextErrors[chatLogId];
|
||||
|
||||
chatLogErrors.value = nextErrors;
|
||||
|
||||
} catch (e: unknown) {
|
||||
|
||||
chatLogErrors.value = {
|
||||
|
||||
...chatLogErrors.value,
|
||||
|
||||
[chatLogId]: e instanceof Error ? e.message : '任务进度查询失败',
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const schedulePoll = () => {
|
||||
|
||||
clearPollTimer();
|
||||
|
||||
const intervalSec = Number(rawToolRunConfig.value?.poll_interval_seconds);
|
||||
|
||||
const intervalMs = Math.max(1, Math.min(Number.isFinite(intervalSec) ? intervalSec : 2, 30)) * 1000;
|
||||
|
||||
pollTimer = window.setTimeout(() => {
|
||||
|
||||
void syncProgressState();
|
||||
|
||||
}, intervalMs);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const syncProgressState = async () => {
|
||||
|
||||
clearPollTimer();
|
||||
|
||||
if (!toolRunProgressConfig.value) {
|
||||
|
||||
runsById.value = {};
|
||||
|
||||
runErrors.value = {};
|
||||
|
||||
chatLogRunMap.value = {};
|
||||
|
||||
chatLogErrors.value = {};
|
||||
|
||||
pollingRunIds.value = [];
|
||||
|
||||
pollingChatLogIds.value = [];
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
const runIds = collectAssistantRunIds(ctx.messages.value);
|
||||
|
||||
|
||||
const targets = collectAssistantProgressTargets(ctx.messages.value);
|
||||
|
||||
const runIds = [...new Set(targets.map((item) => item.runId).filter((id): id is number => !!id))];
|
||||
|
||||
const chatLogIds = [...new Set(
|
||||
|
||||
targets
|
||||
|
||||
.filter((item) => !item.runId && item.chatLogId)
|
||||
|
||||
.map((item) => item.chatLogId as number),
|
||||
|
||||
)];
|
||||
|
||||
pollingRunIds.value = runIds;
|
||||
if (!runIds.length) {
|
||||
|
||||
pollingChatLogIds.value = chatLogIds;
|
||||
|
||||
|
||||
|
||||
if (!targets.length) {
|
||||
|
||||
runsById.value = {};
|
||||
|
||||
runErrors.value = {};
|
||||
|
||||
chatLogRunMap.value = {};
|
||||
|
||||
chatLogErrors.value = {};
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
await Promise.all(runIds.map((runId) => refreshRun(runId)));
|
||||
|
||||
|
||||
await Promise.all([
|
||||
|
||||
...runIds.map((runId) => refreshRun(runId)),
|
||||
|
||||
...targets
|
||||
|
||||
.filter((item) => !item.runId && item.chatLogId)
|
||||
|
||||
.map((item) => refreshRunByChatLog(item.chatLogId as number, item.messageIndex)),
|
||||
|
||||
]);
|
||||
|
||||
|
||||
|
||||
const activeRunIds = new Set<number>();
|
||||
|
||||
for (const target of targets) {
|
||||
|
||||
const runId = resolveMessageRunId(target.message);
|
||||
|
||||
if (runId) activeRunIds.add(runId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
const nextRuns: Record<number, ToolRunProgress> = {};
|
||||
for (const runId of runIds) {
|
||||
|
||||
for (const runId of activeRunIds) {
|
||||
|
||||
const run = runsById.value[runId];
|
||||
|
||||
if (run) nextRuns[runId] = run;
|
||||
|
||||
}
|
||||
|
||||
runsById.value = nextRuns;
|
||||
|
||||
|
||||
|
||||
const hasRunning = Object.values(nextRuns).some((run) => isRunningToolRunStatus(run.status));
|
||||
|
||||
if (hasRunning) schedulePoll();
|
||||
|
||||
};
|
||||
|
||||
watch(
|
||||
() => [ctx.currentAgent.value?.id, ctx.conversationId.value] as const,
|
||||
() => {
|
||||
runsById.value = {};
|
||||
runErrors.value = {};
|
||||
pollingRunIds.value = [];
|
||||
clearPollTimer();
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
watch(
|
||||
() => ctx.messages.value.map((msg, index) => (
|
||||
msg?.role === 'assistant'
|
||||
? `${resolveMessageAnchorKey(msg, index)}:${getRunIdFromMessage(msg) ?? ''}`
|
||||
: ''
|
||||
)).join('|'),
|
||||
async () => {
|
||||
await nextTick();
|
||||
await syncProgressState();
|
||||
|
||||
() => [ctx.currentAgent.value?.id, ctx.conversationId.value] as const,
|
||||
|
||||
() => {
|
||||
|
||||
runsById.value = {};
|
||||
|
||||
runErrors.value = {};
|
||||
|
||||
chatLogRunMap.value = {};
|
||||
|
||||
chatLogErrors.value = {};
|
||||
|
||||
pollingRunIds.value = [];
|
||||
|
||||
pollingChatLogIds.value = [];
|
||||
|
||||
clearPollTimer();
|
||||
|
||||
},
|
||||
{ immediate: true },
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
||||
watch(
|
||||
|
||||
() => ctx.messages.value.map((msg, index) => (
|
||||
|
||||
msg?.role === 'assistant'
|
||||
|
||||
? `${resolveMessageAnchorKey(msg, index)}:${getRunIdFromMessage(msg) ?? ''}:${getChatLogIdFromMessage(msg) ?? ''}`
|
||||
|
||||
: ''
|
||||
|
||||
)).join('|'),
|
||||
|
||||
async () => {
|
||||
|
||||
await nextTick();
|
||||
|
||||
await syncProgressState();
|
||||
|
||||
},
|
||||
|
||||
{ immediate: true },
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
||||
const refreshToolRunProgressAfterSend = async () => {
|
||||
|
||||
await nextTick();
|
||||
|
||||
await syncProgressState();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const prepareToolRunProgressBeforeSend = async () => {
|
||||
|
||||
// 按轮 bind:发送前无需 session 级快照。
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const matchesBoundScheduleTask = (taskId: unknown): boolean => {
|
||||
|
||||
const expected = boundScheduleTaskId.value;
|
||||
|
||||
if (!expected) return true;
|
||||
|
||||
const actual = Number(taskId);
|
||||
|
||||
return Number.isFinite(actual) && actual === expected;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const getMessageRunProgress = (msg: ChatMessage) => {
|
||||
const runId = getRunIdFromMessage(msg);
|
||||
|
||||
const runId = resolveMessageRunId(msg);
|
||||
|
||||
if (!runId) return null;
|
||||
|
||||
return runsById.value[runId] ?? null;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const getMessageRunProgressError = (msg: ChatMessage) => {
|
||||
const runId = getRunIdFromMessage(msg);
|
||||
if (!runId) return '';
|
||||
return runErrors.value[runId] || '';
|
||||
|
||||
const runId = resolveMessageRunId(msg);
|
||||
|
||||
if (runId && runErrors.value[runId]) return runErrors.value[runId];
|
||||
|
||||
const chatLogId = getChatLogIdFromMessage(msg);
|
||||
|
||||
if (chatLogId && chatLogErrors.value[chatLogId]) return chatLogErrors.value[chatLogId];
|
||||
|
||||
return '';
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const isMessageRunProgressLoading = (msg: ChatMessage) => {
|
||||
const runId = getRunIdFromMessage(msg);
|
||||
|
||||
const runId = resolveMessageRunId(msg);
|
||||
|
||||
if (!runId) return false;
|
||||
|
||||
return !runsById.value[runId] && !runErrors.value[runId];
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 判断是否在该助手消息后展示进度卡片。
|
||||
|
||||
* 核心逻辑:已解析到 run_id 时展示;执行中、已完成、加载中或查询报错均保留卡片,无 run_id 不展示。
|
||||
|
||||
*/
|
||||
|
||||
const shouldShowToolRunProgressAfterMessage = (msg: ChatMessage, _index: number) => {
|
||||
|
||||
if (msg?.role !== 'assistant') return false;
|
||||
|
||||
if (!toolRunProgressConfig.value) return false;
|
||||
|
||||
if (assistantMessageHasError(msg)) return false;
|
||||
const runId = getRunIdFromMessage(msg);
|
||||
|
||||
const runId = resolveMessageRunId(msg);
|
||||
|
||||
if (!runId) return false;
|
||||
|
||||
|
||||
|
||||
const error = getMessageRunProgressError(msg);
|
||||
|
||||
if (error) return true;
|
||||
|
||||
|
||||
|
||||
const loading = isMessageRunProgressLoading(msg);
|
||||
|
||||
if (loading) return true;
|
||||
|
||||
|
||||
|
||||
const run = getMessageRunProgress(msg);
|
||||
if (!run || !isRunningToolRunStatus(run.status)) return false;
|
||||
if (!matchesBoundScheduleTask(run.task_id)) return false;
|
||||
return true;
|
||||
|
||||
if (!run) return false;
|
||||
|
||||
return matchesBoundScheduleTask(run.task_id);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const toolRunProgress = computed(() => {
|
||||
|
||||
for (let i = ctx.messages.value.length - 1; i >= 0; i -= 1) {
|
||||
|
||||
const msg = ctx.messages.value[i];
|
||||
|
||||
if (!msg || !shouldShowToolRunProgressAfterMessage(msg, i)) continue;
|
||||
|
||||
return getMessageRunProgress(msg);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
});
|
||||
|
||||
const toolRunProgressLoading = computed(() => pollingRunIds.value.length > 0 && !toolRunProgress.value);
|
||||
const toolRunProgressError = computed(() => {
|
||||
const ids = pollingRunIds.value;
|
||||
for (const runId of ids) {
|
||||
const err = runErrors.value[runId];
|
||||
if (err) return err;
|
||||
}
|
||||
return '';
|
||||
|
||||
|
||||
const toolRunProgressLoading = computed(() => {
|
||||
|
||||
if (toolRunProgress.value) return false;
|
||||
|
||||
return pollingRunIds.value.length > 0 || pollingChatLogIds.value.length > 0;
|
||||
|
||||
});
|
||||
|
||||
const toolRunProgressError = computed(() => {
|
||||
|
||||
for (const runId of pollingRunIds.value) {
|
||||
|
||||
const err = runErrors.value[runId];
|
||||
|
||||
if (err) return err;
|
||||
|
||||
}
|
||||
|
||||
for (const chatLogId of pollingChatLogIds.value) {
|
||||
|
||||
const err = chatLogErrors.value[chatLogId];
|
||||
|
||||
if (err) return err;
|
||||
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
});
|
||||
|
||||
const toolRunProgressTitle = computed(() => toolRunProgressConfig.value?.title ?? '');
|
||||
|
||||
const isToolRunProgressWaiting = computed(() => false);
|
||||
|
||||
|
||||
|
||||
return {
|
||||
|
||||
toolRunProgressConfig,
|
||||
|
||||
toolRunProgress,
|
||||
|
||||
toolRunProgressLoading,
|
||||
|
||||
toolRunProgressError,
|
||||
|
||||
toolRunProgressTitle,
|
||||
|
||||
isToolRunProgressWaiting,
|
||||
|
||||
shouldShowToolRunProgressAfterMessage,
|
||||
|
||||
getMessageRunProgress,
|
||||
|
||||
getMessageRunProgressError,
|
||||
|
||||
isMessageRunProgressLoading,
|
||||
|
||||
prepareToolRunProgressBeforeSend,
|
||||
|
||||
refreshToolRunProgressAfterSend,
|
||||
|
||||
syncProgressForCurrentConversation: syncProgressState,
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* features/chat/utils/toolRunProgressConfig.ts
|
||||
* 用途:解析 Agent tool_run_progress 配置;构建 for-log / detail 轮询 URL。
|
||||
* 依赖:ToolRunProgressConfig、ChatMessage。
|
||||
* 逻辑:进度卡片由 ChatLog.run_id(按轮问答)驱动。
|
||||
* 逻辑:进度卡片由 ChatLog.run_id(按轮问答)驱动;执行中与已完成批次均展示。
|
||||
*/
|
||||
import type { ToolRunProgressConfig } from '../composables/useToolRunProgress';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
@@ -77,6 +77,16 @@ export function isRunningToolRunStatus(status?: string | null): boolean {
|
||||
return String(status || '').toLowerCase() === 'running';
|
||||
}
|
||||
|
||||
const TERMINAL_TOOL_RUN_STATUSES = new Set(['success', 'partial_failed', 'failed', 'cancelled', 'canceled']);
|
||||
|
||||
/**
|
||||
* 判断检核批次是否已进入终态(成功/失败/取消等)。
|
||||
* 核心逻辑:与 useToolRunProgress 轮询终止条件保持一致,供进度卡片展示判断复用。
|
||||
*/
|
||||
export function isTerminalToolRunStatus(status?: string | null): boolean {
|
||||
return TERMINAL_TOOL_RUN_STATUSES.has(String(status || '').toLowerCase());
|
||||
}
|
||||
|
||||
export function collectAssistantRunIds(messages: ChatMessage[]): number[] {
|
||||
const ids = new Set<number>();
|
||||
for (const msg of messages) {
|
||||
@@ -86,3 +96,32 @@ export function collectAssistantRunIds(messages: ChatMessage[]): number[] {
|
||||
}
|
||||
return [...ids];
|
||||
}
|
||||
|
||||
export interface AssistantProgressTarget {
|
||||
message: ChatMessage;
|
||||
messageIndex: number;
|
||||
runId: number | null;
|
||||
chatLogId: number | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集助手消息上的进度轮询目标:优先 run_id,否则用 chat_log_id 走 for-log 兜底。
|
||||
* 核心逻辑:run_id 未从 SSE 回写时,仍可通过 chat_log_id 解析已绑定的检核批次。
|
||||
*/
|
||||
export function collectAssistantProgressTargets(messages: ChatMessage[]): AssistantProgressTarget[] {
|
||||
const targets: AssistantProgressTarget[] = [];
|
||||
messages.forEach((msg, messageIndex) => {
|
||||
if (msg?.role !== 'assistant') return;
|
||||
const runId = getRunIdFromMessage(msg);
|
||||
const chatLogIdRaw = Number(msg.chat_log_id);
|
||||
const chatLogId = Number.isFinite(chatLogIdRaw) && chatLogIdRaw > 0 ? chatLogIdRaw : null;
|
||||
if (!runId && !chatLogId) return;
|
||||
targets.push({ message: msg, messageIndex, runId, chatLogId });
|
||||
});
|
||||
return targets;
|
||||
}
|
||||
|
||||
export function getChatLogIdFromMessage(msg: ChatMessage | null | undefined): number | null {
|
||||
const chatLogId = Number(msg?.chat_log_id);
|
||||
return Number.isFinite(chatLogId) && chatLogId > 0 ? chatLogId : null;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
return workflow.upload.code !== 'success';
|
||||
}
|
||||
if (filter === 'clean') {
|
||||
return ['pending', 'running', 'failed'].includes(workflow.clean.code);
|
||||
return ['pending', 'queued', 'running', 'failed'].includes(workflow.clean.code);
|
||||
}
|
||||
return ['pending', 'running', 'failed'].includes(workflow.sync.code);
|
||||
};
|
||||
@@ -172,7 +172,7 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
selectedDocuments.value.filter((doc) => {
|
||||
if (!doc.latest_version) return false;
|
||||
const workflow = resolveWorkflowState(doc);
|
||||
return ['failed', 'pending', 'idle'].includes(workflow.clean.code);
|
||||
return ['failed', 'pending', 'queued', 'idle'].includes(workflow.clean.code);
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ export type KbFeedbackType = 'success' | 'error' | '';
|
||||
|
||||
/** 上传 → 清洗 → 同步 各阶段展示状态 */
|
||||
export type WorkflowStageState = {
|
||||
code: 'pending' | 'running' | 'success' | 'failed' | 'idle';
|
||||
code: 'pending' | 'queued' | 'running' | 'success' | 'failed' | 'idle';
|
||||
label: string;
|
||||
className: string;
|
||||
errorMessage?: string | null;
|
||||
|
||||
@@ -101,11 +101,17 @@ export const getDocumentWorkflowState = (
|
||||
};
|
||||
} else if (['cleaned', 'ready', 'syncing', 'synced'].includes(latestStatus)) {
|
||||
cleanStage = { code: 'success', label: t('kbWorkspace.status.done'), className: getStatusBadgeClass('success') };
|
||||
} else if (['running', 'queued'].includes(String(cleanJob?.status || '').toLowerCase()) || latestStatus === 'processing') {
|
||||
} else if (String(cleanJob?.status || '').toLowerCase() === 'queued') {
|
||||
cleanStage = {
|
||||
code: 'queued',
|
||||
label: t('kbWorkspace.status.queued'),
|
||||
className: getStatusBadgeClass('queued'),
|
||||
};
|
||||
} else if (String(cleanJob?.status || '').toLowerCase() === 'running' || latestStatus === 'processing') {
|
||||
cleanStage = {
|
||||
code: 'running',
|
||||
label: latestStatus === 'processing' ? t('kbWorkspace.status.cleaning') : t('kbWorkspace.status.pendingClean'),
|
||||
className: getStatusBadgeClass(latestStatus === 'processing' ? 'processing' : 'uploaded'),
|
||||
label: t('kbWorkspace.status.cleaning'),
|
||||
className: getStatusBadgeClass('processing'),
|
||||
};
|
||||
} else if (latestStatus === 'uploaded') {
|
||||
cleanStage = { code: 'pending', label: t('kbWorkspace.status.pendingClean'), className: getStatusBadgeClass('uploaded') };
|
||||
|
||||
Reference in new issue
Block a user