feat(agent): 增强 Agent 配置,新增结构化字段与聊天功能支持

This commit is contained in:
hugo committed 2026-07-07 11:10:32 +08:00
1 parent ac4262cd75
commit c8ce77199e
183 files changed
+11690 -2300

No files matched your search

@@ -8,6 +8,7 @@ import { getAuthHeaders } from '@/shared/utils/auth';
import { applyStreamErrorToMessage, type StreamErrorLabels } from '../utils/streamErrorMessage';
import type { ChatMessage, ChatRun, RetrieverResource } from '../types/chat.types';
import type { ShippingBatchUiState, ShippingTaskUiState } from '../types/shipping.api.types';
import { createStartChatTurn } from './useChatTurn';
export interface SendMessageLifecycleHooks {
onAssistantMessageFinished?: (message: ChatMessage, runMessages: ChatMessage[]) => void | Promise<void>;
@@ -300,9 +301,14 @@ export function useChat() {
activeRunId.value = runId;
};
/**
* 打开空白新会话视图:仅脱离当前流与视图绑定,不 abort 后台 SSE。
*
* 核心逻辑:与 loadConversationState 一致;旧 run 继续在 runs 中更新,并在侧栏显示为「生成中」。
*/
const createNewChatView = () => {
clearLikelyCompletedStreamTimer();
cancelActiveStream();
detachActiveStreamFromView();
viewId.value += 1;
messages.value = [];
conversationId.value = null;
@@ -310,6 +316,25 @@ export function useChat() {
activeRunId.value = null;
};
/**
* 用户显式点击「停止生成」时中止当前可见 run 的流式请求。
*
* 核心逻辑:优先 abort 活动视图绑定的 controller;若已 detach,则回退到 run 上保存的 controller。
*/
const stopActiveGeneration = () => {
clearLikelyCompletedStreamTimer();
const run = activeRunId.value != null
? runs.value.find((r) => r.runId === activeRunId.value)
: undefined;
const controller = activeStreamController.value ?? run?.abortController ?? null;
if (!controller) return;
controller.abort();
activeStreamController.value = null;
if (run && messages.value === run.messages) {
isThinking.value = false;
}
};
const loadConversationState = (id: string, nextMessages: ChatMessage[]) => {
clearLikelyCompletedStreamTimer();
detachActiveStreamFromView();
@@ -388,6 +413,18 @@ export function useChat() {
generic: t('chat.streamError.generic'),
});
const { startChatTurn } = createStartChatTurn({
messages,
isThinking,
conversationId,
viewId,
runs,
activeRunId,
activeStreamController,
streamErrorLabels,
formatStreamError,
});
const sendMessage = async (
query: string,
agentId: number,
@@ -420,6 +457,7 @@ export function useChat() {
conversationId: conversationId.value,
status: 'running',
createdAt: new Date().toISOString(),
abortController: controller,
};
runs.value.unshift(run);
if (runs.value.length > 30) runs.value = runs.value.slice(0, 30);
@@ -634,6 +672,9 @@ export function useChat() {
if (activeStreamController.value === controller) {
activeStreamController.value = null;
}
if (run.abortController === controller) {
delete run.abortController;
}
if (messages.value === runMessages) {
isThinking.value = false;
}
@@ -657,5 +698,7 @@ export function useChat() {
createNewChatView,
loadConversationState,
sendMessage,
startChatTurn,
stopActiveGeneration,
};
}