2026-10-11 11:49:32 +08:00
|
|
|
|
<script setup lang="ts">
|
2026-11-07 16:27:38 +08:00
|
|
|
|
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref } from 'vue';
|
2026-10-11 11:49:32 +08:00
|
|
|
|
import axios from 'axios';
|
2026-11-07 16:27:38 +08:00
|
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
|
|
|
|
|
import { PageHeader } from '@classhelper/ui';
|
2026-10-11 11:49:32 +08:00
|
|
|
|
import {
|
2026-11-07 16:27:38 +08:00
|
|
|
|
COURSEWARE_MAX_BYTES,
|
|
|
|
|
|
type AiAttachment,
|
|
|
|
|
|
type AiCapability,
|
|
|
|
|
|
type AiConversationResult,
|
|
|
|
|
|
type AiPlanStep,
|
2026-10-11 11:49:32 +08:00
|
|
|
|
type ClassDto,
|
2026-10-11 16:21:38 +08:00
|
|
|
|
type ClassPeriod,
|
2026-10-11 11:49:32 +08:00
|
|
|
|
} from '@classhelper/shared';
|
2026-11-07 16:27:38 +08:00
|
|
|
|
import { aiApi, classApi } from '@/api';
|
|
|
|
|
|
import { api } from '@/api/http';
|
2026-10-11 11:49:32 +08:00
|
|
|
|
import { useAuthStore } from '@/stores/auth';
|
2026-11-07 16:27:38 +08:00
|
|
|
|
import { hashAttachment, importFileBase64 } from '@/composables/assistantFiles';
|
2026-10-11 16:21:38 +08:00
|
|
|
|
import { findClassInSession } from '@/composables/useClassInSession';
|
2026-11-07 16:27:38 +08:00
|
|
|
|
import AssistantData from '@/components/AssistantData.vue';
|
2026-10-11 16:21:38 +08:00
|
|
|
|
import UrgentClassWarning from '@/components/UrgentClassWarning.vue';
|
2026-11-07 16:27:38 +08:00
|
|
|
|
interface ChatMessage {
|
|
|
|
|
|
role: 'user' | 'assistant';
|
|
|
|
|
|
content: string;
|
|
|
|
|
|
result?: AiConversationResult;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
const auth = useAuthStore();
|
|
|
|
|
|
const text = ref(''),
|
|
|
|
|
|
classId = ref(''),
|
|
|
|
|
|
classes = ref<ClassDto[]>([]),
|
|
|
|
|
|
capabilities = ref<AiCapability[]>([]);
|
|
|
|
|
|
const messages = ref<ChatMessage[]>([]),
|
|
|
|
|
|
attachments = ref<AiAttachment[]>([]);
|
|
|
|
|
|
const files = new Map<string, File>();
|
|
|
|
|
|
const input = ref<HTMLInputElement>(),
|
|
|
|
|
|
conversation = ref<HTMLElement>();
|
|
|
|
|
|
const busy = ref(false),
|
|
|
|
|
|
hashing = ref(false),
|
|
|
|
|
|
executing = ref(false),
|
|
|
|
|
|
progress = ref(0),
|
|
|
|
|
|
error = ref('');
|
|
|
|
|
|
const disabled = ref(false),
|
|
|
|
|
|
dragging = ref(false),
|
|
|
|
|
|
active = ref<AiConversationResult>();
|
|
|
|
|
|
const credentials = reactive<Record<string, Record<string, string>>>({});
|
|
|
|
|
|
const urgent = reactive({ visible: false, period: null as ClassPeriod | null, title: '' });
|
|
|
|
|
|
let resolveUrgent: ((confirmed: boolean) => void) | undefined;
|
|
|
|
|
|
let controller: AbortController | undefined;
|
|
|
|
|
|
let disposed = false;
|
|
|
|
|
|
const pending = computed(
|
|
|
|
|
|
() => active.value?.steps.some((step) => !['succeeded', 'blocked'].includes(step.status)) ?? false,
|
|
|
|
|
|
);
|
|
|
|
|
|
const ready = computed(
|
|
|
|
|
|
() =>
|
|
|
|
|
|
pending.value &&
|
|
|
|
|
|
active.value!.steps.every((step) =>
|
|
|
|
|
|
['prepared', 'confirmed', 'failed', 'succeeded'].includes(step.status),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
const statusLabels: Record<string, string> = {
|
|
|
|
|
|
draft: '准备附件',
|
|
|
|
|
|
prepared: '待确认',
|
|
|
|
|
|
confirmed: '已确认',
|
|
|
|
|
|
running: '执行中',
|
|
|
|
|
|
succeeded: '已完成',
|
|
|
|
|
|
failed: '失败',
|
|
|
|
|
|
blocked: '已停止,请核对',
|
|
|
|
|
|
};
|
|
|
|
|
|
function failure(e: unknown): string {
|
|
|
|
|
|
return axios.isAxiosError(e)
|
|
|
|
|
|
? (e.response?.data?.message ?? e.message)
|
|
|
|
|
|
: e instanceof Error
|
|
|
|
|
|
? e.message
|
|
|
|
|
|
: '操作失败';
|
|
|
|
|
|
}
|
|
|
|
|
|
function clearCredentials(): void {
|
|
|
|
|
|
for (const key of Object.keys(credentials)) delete credentials[key];
|
|
|
|
|
|
for (const step of active.value?.steps ?? []) credentials[step.id] = {};
|
|
|
|
|
|
}
|
|
|
|
|
|
async function scroll(): Promise<void> {
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
conversation.value?.scrollTo({ top: conversation.value.scrollHeight, behavior: 'smooth' });
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
async function selectFiles(selected: FileList | File[]): Promise<void> {
|
|
|
|
|
|
if (busy.value || executing.value || hashing.value || pending.value) return;
|
|
|
|
|
|
hashing.value = true;
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
controller = new AbortController();
|
2026-10-11 11:49:32 +08:00
|
|
|
|
try {
|
2026-11-07 16:27:38 +08:00
|
|
|
|
for (const file of [...selected]) {
|
|
|
|
|
|
if (!file.size || file.size > COURSEWARE_MAX_BYTES)
|
|
|
|
|
|
throw new Error('文件大小须在 1 字节到 512 MB 之间');
|
|
|
|
|
|
if (attachments.value.length >= 8) throw new Error('一次最多添加 8 个文件');
|
|
|
|
|
|
const attachment = await hashAttachment(file, controller.signal);
|
|
|
|
|
|
if (disposed) return;
|
|
|
|
|
|
if (
|
|
|
|
|
|
attachments.value.some((item) => item.sha256 === attachment.sha256 && item.name === attachment.name)
|
|
|
|
|
|
)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
files.set(attachment.id, file);
|
|
|
|
|
|
attachments.value.push(attachment);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
if (!disposed && !axios.isCancel(e) && !(e instanceof DOMException && e.name === 'AbortError'))
|
|
|
|
|
|
error.value = failure(e);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
hashing.value = false;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
function choose(event: Event): void {
|
|
|
|
|
|
const target = event.target as HTMLInputElement;
|
|
|
|
|
|
if (target.files) void selectFiles(target.files);
|
|
|
|
|
|
target.value = '';
|
|
|
|
|
|
}
|
|
|
|
|
|
function drop(event: DragEvent): void {
|
|
|
|
|
|
dragging.value = false;
|
|
|
|
|
|
if (event.dataTransfer?.files) void selectFiles(event.dataTransfer.files);
|
|
|
|
|
|
}
|
|
|
|
|
|
function removeFile(id: string): void {
|
|
|
|
|
|
files.delete(id);
|
|
|
|
|
|
attachments.value = attachments.value.filter((item) => item.id !== id);
|
|
|
|
|
|
}
|
|
|
|
|
|
async function prepare(result: AiConversationResult): Promise<void> {
|
|
|
|
|
|
if (!result.planId || !result.steps.some((step) => step.status === 'draft')) return;
|
|
|
|
|
|
const payload: Record<string, { contentBase64: string }> = {};
|
|
|
|
|
|
for (const step of result.steps.filter((item) => item.status === 'draft')) {
|
|
|
|
|
|
const id = step.attachmentId!,
|
|
|
|
|
|
file = files.get(id);
|
|
|
|
|
|
if (!file) throw new Error('请重新选择原附件');
|
|
|
|
|
|
if (!payload[id]) payload[id] = { contentBase64: await importFileBase64(file) };
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
for (const [id, file] of Object.entries(payload))
|
|
|
|
|
|
result.steps = await aiApi.prepare(result.planId, { [id]: file });
|
|
|
|
|
|
}
|
|
|
|
|
|
async function retryTask(): Promise<void> {
|
|
|
|
|
|
const last = [...messages.value].reverse().find((message) => message.role === 'user');
|
|
|
|
|
|
if (last) {
|
|
|
|
|
|
text.value = last.content;
|
|
|
|
|
|
await send();
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
async function send(): Promise<void> {
|
|
|
|
|
|
if (!text.value.trim() || busy.value || executing.value || hashing.value) return;
|
|
|
|
|
|
busy.value = true;
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
controller = new AbortController();
|
2026-10-11 11:49:32 +08:00
|
|
|
|
try {
|
2026-11-07 16:27:38 +08:00
|
|
|
|
if (active.value?.planId && pending.value) await aiApi.discard(active.value.planId);
|
|
|
|
|
|
clearCredentials();
|
|
|
|
|
|
active.value = undefined;
|
|
|
|
|
|
const content = text.value.trim(),
|
|
|
|
|
|
history = messages.value.slice(-18).map(({ role, content }) => ({ role, content }));
|
|
|
|
|
|
messages.value.push({ role: 'user', content });
|
|
|
|
|
|
text.value = '';
|
|
|
|
|
|
await scroll();
|
|
|
|
|
|
const result = reactive(
|
|
|
|
|
|
await aiApi.interpret(
|
|
|
|
|
|
{
|
|
|
|
|
|
text: content,
|
|
|
|
|
|
classId: classId.value || undefined,
|
|
|
|
|
|
messages: history,
|
|
|
|
|
|
attachments: attachments.value,
|
|
|
|
|
|
},
|
|
|
|
|
|
controller.signal,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
if (disposed) return;
|
|
|
|
|
|
active.value = result;
|
|
|
|
|
|
const message = reactive<ChatMessage>({ role: 'assistant', content: result.message, result });
|
|
|
|
|
|
messages.value.push(message);
|
|
|
|
|
|
try {
|
|
|
|
|
|
await prepare(result);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
message.result = result;
|
|
|
|
|
|
}
|
|
|
|
|
|
for (const step of result.steps) credentials[step.id] = {};
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
if (!disposed && !axios.isCancel(e)) {
|
|
|
|
|
|
error.value = failure(e);
|
|
|
|
|
|
if (axios.isAxiosError(e) && e.response?.data?.code === 'AI_NOT_CONFIGURED') disabled.value = true;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
2026-11-07 16:27:38 +08:00
|
|
|
|
busy.value = false;
|
|
|
|
|
|
await scroll();
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
async function urgentConfirmation(period: ClassPeriod | null, title: string): Promise<boolean> {
|
|
|
|
|
|
urgent.period = period;
|
|
|
|
|
|
urgent.title = title;
|
|
|
|
|
|
urgent.visible = true;
|
|
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
|
|
resolveUrgent = resolve;
|
|
|
|
|
|
});
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
function finishUrgent(value: boolean): void {
|
|
|
|
|
|
urgent.visible = false;
|
|
|
|
|
|
resolveUrgent?.(value);
|
|
|
|
|
|
resolveUrgent = undefined;
|
2026-10-11 16:21:38 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
async function refreshPlan(result: AiConversationResult): Promise<void> {
|
|
|
|
|
|
if (result.planId) result.steps = await aiApi.plan(result.planId);
|
|
|
|
|
|
}
|
|
|
|
|
|
function tablePreview(
|
|
|
|
|
|
step: AiPlanStep,
|
|
|
|
|
|
): { columns: string[]; fields: { key: string; label: string; required: boolean }[] } | null {
|
|
|
|
|
|
const value = step.preview as
|
|
|
|
|
|
{ columns?: string[]; fields?: { key: string; label: string; required: boolean }[] } | undefined;
|
|
|
|
|
|
return value?.columns && value.fields ? { columns: value.columns, fields: value.fields } : null;
|
|
|
|
|
|
}
|
|
|
|
|
|
function mapping(step: AiPlanStep): Record<string, string> {
|
|
|
|
|
|
return (step.params?.mapping as Record<string, string>) ?? {};
|
|
|
|
|
|
}
|
|
|
|
|
|
async function updateMapping(step: AiPlanStep, key: string, value: string): Promise<void> {
|
|
|
|
|
|
if (!active.value?.planId) return;
|
|
|
|
|
|
busy.value = true;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
try {
|
2026-11-07 16:27:38 +08:00
|
|
|
|
active.value.steps = await aiApi.prepare(
|
|
|
|
|
|
active.value.planId,
|
|
|
|
|
|
{},
|
|
|
|
|
|
{ [step.id]: { ...mapping(step), [key]: value } },
|
|
|
|
|
|
);
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
error.value = failure(e);
|
2026-10-11 11:49:32 +08:00
|
|
|
|
} finally {
|
2026-11-07 16:27:38 +08:00
|
|
|
|
busy.value = false;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
async function execute(urgentConfirmed = false): Promise<void> {
|
|
|
|
|
|
const result = active.value;
|
|
|
|
|
|
if (!result?.planId || !ready.value || executing.value) return;
|
|
|
|
|
|
executing.value = true;
|
|
|
|
|
|
error.value = '';
|
|
|
|
|
|
progress.value = 0;
|
|
|
|
|
|
controller = new AbortController();
|
|
|
|
|
|
try {
|
|
|
|
|
|
const danger = result.steps.filter((step) => step.dangerous && step.status !== 'succeeded');
|
|
|
|
|
|
if (danger.length)
|
|
|
|
|
|
await ElMessageBox.confirm(danger.map((step) => step.summary).join(';'), '确认执行这些操作', {
|
|
|
|
|
|
type: 'warning',
|
|
|
|
|
|
confirmButtonText: '确认执行',
|
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
|
});
|
|
|
|
|
|
for (const step of result.steps)
|
|
|
|
|
|
if (
|
|
|
|
|
|
step.action.startsWith('notifications.') &&
|
|
|
|
|
|
step.params?.priority === 'URGENT' &&
|
|
|
|
|
|
step.status !== 'succeeded' &&
|
|
|
|
|
|
!urgentConfirmed
|
|
|
|
|
|
) {
|
|
|
|
|
|
const ids = step.params.classId
|
|
|
|
|
|
? [String(step.params.classId)]
|
|
|
|
|
|
: ((step.params.classIds as string[]) ?? []),
|
|
|
|
|
|
hit = await findClassInSession(ids);
|
|
|
|
|
|
if (hit) {
|
|
|
|
|
|
if (!(await urgentConfirmation(hit.period, String(step.params.title ?? '')))) return;
|
|
|
|
|
|
urgentConfirmed = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
result.steps = await aiApi.confirm(result.planId, {
|
|
|
|
|
|
confirmed: true,
|
|
|
|
|
|
extraConfirmed: danger.length > 0,
|
|
|
|
|
|
urgentConfirmed,
|
|
|
|
|
|
secrets: { ...credentials },
|
2026-10-11 11:49:32 +08:00
|
|
|
|
});
|
2026-11-07 16:27:38 +08:00
|
|
|
|
clearCredentials();
|
|
|
|
|
|
for (const step of result.steps) {
|
|
|
|
|
|
if (step.status === 'succeeded') continue;
|
|
|
|
|
|
if (!step.request) throw new Error('计划未确认,请刷新后重试');
|
|
|
|
|
|
const file = step.request.attachmentId ? files.get(step.request.attachmentId) : undefined;
|
|
|
|
|
|
if (step.request.attachmentId && !file) throw new Error('原附件已移除,请重新生成计划');
|
|
|
|
|
|
step.status = 'running';
|
|
|
|
|
|
try {
|
|
|
|
|
|
step.result = await api.executeAi(step.id, step.request, file, controller.signal, (value) => {
|
|
|
|
|
|
progress.value = value;
|
|
|
|
|
|
});
|
|
|
|
|
|
step.status = 'succeeded';
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
const refreshed = await refreshPlan(result)
|
|
|
|
|
|
.then(() => true)
|
|
|
|
|
|
.catch(() => false);
|
|
|
|
|
|
if (!refreshed) {
|
|
|
|
|
|
step.status = axios.isAxiosError(e) && e.response && e.response.status < 500 ? 'failed' : 'blocked';
|
|
|
|
|
|
step.error = failure(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (
|
|
|
|
|
|
axios.isAxiosError(e) &&
|
|
|
|
|
|
e.response?.data?.code === 'URGENT_DURING_CLASS' &&
|
|
|
|
|
|
(await urgentConfirmation(
|
|
|
|
|
|
e.response.data.details?.period ?? null,
|
|
|
|
|
|
String(step.params?.title ?? ''),
|
|
|
|
|
|
))
|
|
|
|
|
|
) {
|
|
|
|
|
|
executing.value = false;
|
|
|
|
|
|
await execute(true);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
throw e;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
await refreshPlan(result);
|
|
|
|
|
|
messages.value.push({
|
|
|
|
|
|
role: 'assistant',
|
|
|
|
|
|
content: `已完成 ${result.steps.filter((step) => step.status === 'succeeded').length} 项操作。`,
|
2026-10-11 11:49:32 +08:00
|
|
|
|
});
|
2026-11-07 16:27:38 +08:00
|
|
|
|
ElMessage.success('操作已完成');
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
if (e !== 'cancel' && e !== 'close') error.value = failure(e);
|
|
|
|
|
|
await refreshPlan(result).catch(() => undefined);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
executing.value = false;
|
|
|
|
|
|
await scroll();
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
async function cancelPlan(): Promise<void> {
|
|
|
|
|
|
if (executing.value) {
|
|
|
|
|
|
controller?.abort();
|
2026-10-11 11:49:32 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
if (active.value?.planId) {
|
|
|
|
|
|
await aiApi.discard(active.value.planId);
|
|
|
|
|
|
await refreshPlan(active.value);
|
|
|
|
|
|
}
|
|
|
|
|
|
clearCredentials();
|
|
|
|
|
|
}
|
|
|
|
|
|
function size(value: number): string {
|
|
|
|
|
|
return value < 1024 * 1024 ? `${Math.ceil(value / 1024)} KB` : `${(value / 1024 / 1024).toFixed(1)} MB`;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
onMounted(async () => {
|
2026-11-07 16:27:38 +08:00
|
|
|
|
try {
|
|
|
|
|
|
[capabilities.value, classes.value] = await Promise.all([
|
|
|
|
|
|
aiApi.capabilities(),
|
|
|
|
|
|
classApi.list().catch(() => []),
|
|
|
|
|
|
]);
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
error.value = failure(e);
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-11-07 16:27:38 +08:00
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
|
|
disposed = true;
|
|
|
|
|
|
controller?.abort();
|
|
|
|
|
|
finishUrgent(false);
|
|
|
|
|
|
clearCredentials();
|
|
|
|
|
|
files.clear();
|
|
|
|
|
|
});
|
2026-10-11 11:49:32 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2026-11-07 16:27:38 +08:00
|
|
|
|
<div
|
|
|
|
|
|
class="page assistant-page"
|
|
|
|
|
|
:class="{ 'is-dragging': dragging }"
|
|
|
|
|
|
@dragover.prevent="dragging = true"
|
|
|
|
|
|
@dragleave.prevent="dragging = false"
|
|
|
|
|
|
@drop.prevent="drop"
|
|
|
|
|
|
>
|
|
|
|
|
|
<PageHeader title="AI 助手">
|
|
|
|
|
|
<el-select v-model="classId" clearable filterable placeholder="目标班级" :disabled="busy || executing">
|
|
|
|
|
|
<el-option v-for="item in classes" :key="item.id" :value="item.id" :label="item.name" />
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
<el-button v-if="auth.can('ai:manage')" @click="$router.push('/ai-settings')">模型设置</el-button>
|
|
|
|
|
|
</PageHeader>
|
|
|
|
|
|
<div ref="conversation" class="assistant-conversation" aria-live="polite" :aria-busy="busy || executing">
|
|
|
|
|
|
<div v-if="!messages.length" class="assistant-welcome">
|
|
|
|
|
|
<h2>今天需要处理什么?</h2>
|
|
|
|
|
|
<div class="assistant-examples">
|
|
|
|
|
|
<el-button @click="text = '查看本班今天的作业'">查看作业</el-button>
|
|
|
|
|
|
<el-button @click="text = '将附件推送到所选班级'">推送文件</el-button>
|
|
|
|
|
|
<el-button @click="text = '调整所选班级的时间表'">调整时间表</el-button>
|
2026-10-11 11:49:32 +08:00
|
|
|
|
</div>
|
2026-11-07 16:27:38 +08:00
|
|
|
|
<details>
|
|
|
|
|
|
<summary>可用功能</summary>
|
|
|
|
|
|
<div class="assistant-capabilities">
|
|
|
|
|
|
<el-tag v-for="item in capabilities" :key="`${item.kind}:${item.action}`" effect="plain">
|
|
|
|
|
|
{{ item.label }}
|
|
|
|
|
|
</el-tag>
|
2026-10-11 11:49:32 +08:00
|
|
|
|
</div>
|
2026-11-07 16:27:38 +08:00
|
|
|
|
</details>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<article
|
|
|
|
|
|
v-for="(message, index) in messages"
|
|
|
|
|
|
:key="index"
|
|
|
|
|
|
class="assistant-message"
|
|
|
|
|
|
:class="message.role"
|
|
|
|
|
|
>
|
|
|
|
|
|
<span class="assistant-role">{{ message.role === 'user' ? '你' : '助手' }}</span>
|
|
|
|
|
|
<p>{{ message.content }}</p>
|
|
|
|
|
|
<el-card v-for="(item, n) in message.result?.results" :key="n" shadow="never">
|
|
|
|
|
|
<template #header>{{ item.label }}</template>
|
|
|
|
|
|
<AssistantData :value="item.data" />
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
</article>
|
|
|
|
|
|
<section v-if="active?.steps.length" class="assistant-plan" aria-label="待确认操作计划">
|
|
|
|
|
|
<el-card v-for="(step, n) in active.steps" :key="step.id" shadow="never" class="assistant-step">
|
|
|
|
|
|
<template #header>
|
|
|
|
|
|
<div class="assistant-step-head">
|
|
|
|
|
|
<strong>{{ n + 1 }}. {{ step.summary }}</strong>
|
|
|
|
|
|
<el-tag
|
|
|
|
|
|
:type="
|
|
|
|
|
|
step.status === 'succeeded'
|
|
|
|
|
|
? 'success'
|
|
|
|
|
|
: ['blocked', 'failed'].includes(step.status)
|
|
|
|
|
|
? 'danger'
|
|
|
|
|
|
: 'info'
|
|
|
|
|
|
"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ statusLabels[step.status] }}
|
|
|
|
|
|
</el-tag>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<p v-if="step.attachmentId">
|
|
|
|
|
|
{{ attachments.find((file) => file.id === step.attachmentId)?.name }}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<AssistantData v-if="!step.preview" :value="step.params" />
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-if="!step.preview && step.before && (!Array.isArray(step.before) || step.before.length)"
|
|
|
|
|
|
class="assistant-diff"
|
2026-10-11 11:49:32 +08:00
|
|
|
|
>
|
2026-11-07 16:27:38 +08:00
|
|
|
|
<details>
|
|
|
|
|
|
<summary>修改前</summary>
|
|
|
|
|
|
<AssistantData :value="step.before" />
|
|
|
|
|
|
</details>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-form v-if="tablePreview(step) && step.status === 'prepared'" label-position="top">
|
|
|
|
|
|
<el-form-item
|
|
|
|
|
|
v-for="field in tablePreview(step)!.fields"
|
|
|
|
|
|
:key="field.key"
|
|
|
|
|
|
:label="field.label"
|
|
|
|
|
|
:required="field.required"
|
|
|
|
|
|
>
|
2026-10-11 11:49:32 +08:00
|
|
|
|
<el-select
|
2026-11-07 16:27:38 +08:00
|
|
|
|
:model-value="mapping(step)[field.key]"
|
|
|
|
|
|
clearable
|
|
|
|
|
|
placeholder="选择文件中的列"
|
|
|
|
|
|
:disabled="busy || executing"
|
|
|
|
|
|
@change="(value: string) => updateMapping(step, field.key, value)"
|
2026-10-11 11:49:32 +08:00
|
|
|
|
>
|
2026-11-07 16:27:38 +08:00
|
|
|
|
<el-option
|
|
|
|
|
|
v-for="column in tablePreview(step)!.columns"
|
|
|
|
|
|
:key="column"
|
|
|
|
|
|
:value="column"
|
|
|
|
|
|
:label="column"
|
|
|
|
|
|
/>
|
2026-10-11 11:49:32 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
2026-11-07 16:27:38 +08:00
|
|
|
|
<details v-if="step.preview" open>
|
|
|
|
|
|
<summary>变更预览</summary>
|
|
|
|
|
|
<AssistantData :value="step.preview" />
|
|
|
|
|
|
</details>
|
|
|
|
|
|
<el-form v-if="step.sensitiveFields.length && step.status !== 'succeeded'" label-position="top">
|
|
|
|
|
|
<el-form-item
|
|
|
|
|
|
v-for="key in step.sensitiveFields"
|
|
|
|
|
|
:key="key"
|
|
|
|
|
|
:label="key === 'currentPassword' ? '当前密码' : '新密码'"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
v-if="credentials[step.id]"
|
|
|
|
|
|
v-model="credentials[step.id]![key]"
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
show-password
|
|
|
|
|
|
autocomplete="new-password"
|
|
|
|
|
|
placeholder="仅用于本次确认,不发送给模型"
|
|
|
|
|
|
:disabled="executing"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
<el-alert v-if="step.error" :title="step.error" type="error" :closable="false" show-icon />
|
|
|
|
|
|
<AssistantData v-if="step.status === 'succeeded' && step.result" :value="step.result" />
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
<div class="assistant-plan-actions">
|
|
|
|
|
|
<el-button type="primary" :disabled="!ready || busy" :loading="executing" @click="execute()">
|
|
|
|
|
|
{{ active.steps.some((step) => step.status === 'succeeded') ? '重试未完成步骤' : '确认执行' }}
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
<el-button :disabled="busy" @click="cancelPlan">
|
|
|
|
|
|
{{ executing ? '停止等待' : '取消计划' }}
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
<el-button
|
|
|
|
|
|
v-if="active.steps.some((step) => step.status === 'draft')"
|
|
|
|
|
|
:disabled="busy || executing"
|
|
|
|
|
|
@click="prepare(active).catch((e) => (error = failure(e)))"
|
|
|
|
|
|
>
|
|
|
|
|
|
重试附件预览
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-progress v-if="executing && progress > 0" :percentage="progress" />
|
|
|
|
|
|
</section>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-alert v-if="error" :title="error" type="error" :closable="true" show-icon @close="error = ''" />
|
|
|
|
|
|
<el-button v-if="error && !active?.steps.length && !busy && !executing" @click="retryTask">
|
|
|
|
|
|
重试上次任务
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
<div class="assistant-composer">
|
|
|
|
|
|
<div v-if="attachments.length" class="assistant-attachments">
|
|
|
|
|
|
<el-tag
|
|
|
|
|
|
v-for="file in attachments"
|
|
|
|
|
|
:key="file.id"
|
|
|
|
|
|
:closable="!pending && !executing"
|
|
|
|
|
|
@close="removeFile(file.id)"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ file.name }} · {{ size(file.size) }}
|
|
|
|
|
|
</el-tag>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="text"
|
|
|
|
|
|
type="textarea"
|
|
|
|
|
|
:autosize="{ minRows: 2, maxRows: 6 }"
|
|
|
|
|
|
maxlength="8000"
|
|
|
|
|
|
placeholder="描述任务,也可以拖入文件"
|
|
|
|
|
|
:disabled="busy || executing || disabled"
|
|
|
|
|
|
@keydown.ctrl.enter.prevent="send"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<div class="assistant-composer-actions">
|
|
|
|
|
|
<input ref="input" type="file" multiple hidden @change="choose" />
|
|
|
|
|
|
<el-button :loading="hashing" :disabled="busy || executing || pending" @click="input?.click()">
|
|
|
|
|
|
添加文件
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
<span class="text-muted">所有更改先确认</span>
|
|
|
|
|
|
<el-button v-if="busy || hashing" @click="controller?.abort()">取消</el-button>
|
|
|
|
|
|
<el-button
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
:loading="busy"
|
|
|
|
|
|
:disabled="!text.trim() || hashing || executing || disabled"
|
|
|
|
|
|
@click="send"
|
|
|
|
|
|
>
|
|
|
|
|
|
发送
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-10-11 16:21:38 +08:00
|
|
|
|
<UrgentClassWarning
|
2026-11-07 16:27:38 +08:00
|
|
|
|
:visible="urgent.visible"
|
|
|
|
|
|
:period="urgent.period"
|
|
|
|
|
|
:pending-title="urgent.title"
|
|
|
|
|
|
@confirm="finishUrgent(true)"
|
|
|
|
|
|
@cancel="finishUrgent(false)"
|
2026-10-11 16:21:38 +08:00
|
|
|
|
/>
|
2026-10-11 11:49:32 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-page {
|
|
|
|
|
|
max-width: 1120px;
|
|
|
|
|
|
margin: auto;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
display: flex;
|
2026-11-07 16:27:38 +08:00
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
height: calc(100dvh - 110px);
|
|
|
|
|
|
min-height: 0;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
box-sizing: border-box;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-conversation {
|
2026-10-11 11:49:32 +08:00
|
|
|
|
flex: 1;
|
2026-11-07 16:27:38 +08:00
|
|
|
|
min-height: 240px;
|
|
|
|
|
|
max-height: calc(100dvh - 380px);
|
|
|
|
|
|
overflow: auto;
|
|
|
|
|
|
padding: 8px 2px 24px;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-welcome {
|
|
|
|
|
|
padding: clamp(20px, 4vw, 56px) 0;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-welcome h2 {
|
|
|
|
|
|
font-size: 28px;
|
|
|
|
|
|
font-weight: 600;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-examples,
|
|
|
|
|
|
.assistant-capabilities,
|
|
|
|
|
|
.assistant-attachments,
|
|
|
|
|
|
.assistant-composer-actions,
|
|
|
|
|
|
.assistant-plan-actions {
|
2026-10-11 11:49:32 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 8px;
|
2026-11-07 16:27:38 +08:00
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
align-items: center;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-examples {
|
|
|
|
|
|
margin: 24px 0;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-capabilities {
|
|
|
|
|
|
margin-top: 16px;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-message {
|
|
|
|
|
|
margin: 0 0 24px;
|
|
|
|
|
|
padding: 16px 20px;
|
|
|
|
|
|
border: 1px solid var(--ch-ui-border);
|
|
|
|
|
|
border-radius: var(--ch-ui-radius);
|
|
|
|
|
|
background: var(--ch-ui-surface);
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-message.user {
|
|
|
|
|
|
margin-left: 15%;
|
|
|
|
|
|
background: var(--el-color-primary-light-9);
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-message p {
|
|
|
|
|
|
white-space: pre-wrap;
|
|
|
|
|
|
overflow-wrap: anywhere;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
margin: 8px 0 0;
|
2026-11-07 16:27:38 +08:00
|
|
|
|
line-height: 1.7;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-role {
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
color: var(--ch-ui-muted);
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-message .el-card {
|
|
|
|
|
|
margin-top: 16px;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-step {
|
|
|
|
|
|
margin-bottom: 12px;
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
2026-11-07 16:27:38 +08:00
|
|
|
|
.assistant-step-head {
|
2026-10-11 11:49:32 +08:00
|
|
|
|
display: flex;
|
2026-11-07 16:27:38 +08:00
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.assistant-step-head strong {
|
|
|
|
|
|
min-width: 0;
|
|
|
|
|
|
overflow-wrap: anywhere;
|
|
|
|
|
|
}
|
|
|
|
|
|
.assistant-step-head .el-tag {
|
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
.assistant-diff {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
grid-template-columns: 1fr 1fr;
|
|
|
|
|
|
gap: 16px;
|
|
|
|
|
|
margin: 16px 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
.assistant-plan-actions {
|
|
|
|
|
|
margin: 16px 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
.assistant-composer {
|
|
|
|
|
|
margin-top: 16px;
|
|
|
|
|
|
padding: 16px;
|
|
|
|
|
|
border: 1px solid var(--ch-ui-border);
|
|
|
|
|
|
border-radius: var(--ch-ui-radius);
|
|
|
|
|
|
background: var(--ch-ui-surface);
|
|
|
|
|
|
}
|
|
|
|
|
|
.assistant-composer-actions {
|
|
|
|
|
|
margin-top: 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.assistant-composer-actions .text-muted {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.assistant-attachments {
|
|
|
|
|
|
margin-bottom: 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.is-dragging {
|
|
|
|
|
|
outline: 2px dashed var(--el-color-primary);
|
|
|
|
|
|
outline-offset: -8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
details > summary {
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
color: var(--ch-ui-muted);
|
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
|
}
|
|
|
|
|
|
@media (max-width: 720px) {
|
|
|
|
|
|
.assistant-page {
|
|
|
|
|
|
height: auto;
|
|
|
|
|
|
overflow: visible;
|
|
|
|
|
|
}
|
|
|
|
|
|
.assistant-diff {
|
|
|
|
|
|
grid-template-columns: 1fr;
|
|
|
|
|
|
}
|
|
|
|
|
|
.assistant-message.user {
|
|
|
|
|
|
margin-left: 8%;
|
|
|
|
|
|
}
|
|
|
|
|
|
.assistant-conversation {
|
|
|
|
|
|
max-height: none;
|
|
|
|
|
|
}
|
2026-10-11 11:49:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|