fix(conflicts): 解决冲突及功能迁移
This commit is contained in:
commit
e827c5dc38
208 files changed
+15526
-12088
No files matched your search
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* 对话页:加载历史会话、新建对话、切换 Agent 时重置状态。
|
||||
*/
|
||||
import type { RouteLocationNormalizedLoaded, Router } from 'vue-router';
|
||||
import { listChatMessages } from '../api/chat.api';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
import type { ComputedRef, Ref } from 'vue';
|
||||
|
||||
export interface ChatPageConversationContext {
|
||||
deps: { t: (key: string) => string; msg: { warning: (text: string) => void } };
|
||||
route: RouteLocationNormalizedLoaded;
|
||||
router: Router;
|
||||
currentAgentId: ComputedRef<number>;
|
||||
conversationId: Ref<string | null>;
|
||||
activeRunId: Ref<number | null>;
|
||||
messages: Ref<ChatMessage[]>;
|
||||
isThinking: Ref<boolean>;
|
||||
loadConversationState: (id: string, loaded: ChatMessage[]) => void;
|
||||
createNewChatView: () => void;
|
||||
onConversationIdChanging: (nextId: string, prevId: string | null | undefined) => void;
|
||||
onConversationLoadedEmpty: () => Promise<void>;
|
||||
onConversationLoadFailed: () => Promise<void>;
|
||||
isShippingNoticeAgent: ComputedRef<boolean>;
|
||||
shippingTaskIdFromQuery: ComputedRef<string>;
|
||||
clearHistory: () => void;
|
||||
clearAttachments: () => void;
|
||||
input: Ref<string>;
|
||||
resetCurrentAgent: () => void;
|
||||
copiedIndex: Ref<number | null>;
|
||||
resetPeripheralState: () => void;
|
||||
filePreviewVisible: Ref<boolean>;
|
||||
previewFile: Ref<unknown>;
|
||||
}
|
||||
|
||||
export function createChatPageConversationApi(ctx: ChatPageConversationContext) {
|
||||
const loadConversation = async (id: string, options?: { force?: boolean }) => {
|
||||
const force = options?.force ?? false;
|
||||
if (!force && ctx.conversationId.value === id && !ctx.activeRunId.value && ctx.messages.value.length > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const prevConversationId = ctx.conversationId.value;
|
||||
try {
|
||||
ctx.onConversationIdChanging(id, prevConversationId);
|
||||
const loaded = await listChatMessages(id, ctx.currentAgentId.value);
|
||||
ctx.loadConversationState(id, Array.isArray(loaded) ? loaded : []);
|
||||
if (!loaded?.length) {
|
||||
await ctx.onConversationLoadedEmpty();
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load conversation', e);
|
||||
await ctx.onConversationLoadFailed();
|
||||
if (ctx.isShippingNoticeAgent.value && ctx.shippingTaskIdFromQuery.value && !ctx.isThinking.value) {
|
||||
return;
|
||||
}
|
||||
ctx.deps.msg.warning(ctx.deps.t('chat.historyLoadFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
const startNewChat = () => {
|
||||
ctx.createNewChatView();
|
||||
void ctx.router.replace({ path: ctx.route.path, query: {} });
|
||||
};
|
||||
|
||||
const resetChatStateForAgentChange = () => {
|
||||
ctx.createNewChatView();
|
||||
ctx.clearHistory();
|
||||
ctx.clearAttachments();
|
||||
ctx.input.value = '';
|
||||
ctx.resetCurrentAgent();
|
||||
ctx.copiedIndex.value = null;
|
||||
ctx.resetPeripheralState();
|
||||
ctx.filePreviewVisible.value = false;
|
||||
ctx.previewFile.value = null;
|
||||
};
|
||||
|
||||
return { loadConversation, startNewChat, resetChatStateForAgentChange };
|
||||
}
|
||||
Reference in new issue
Block a user