refactor(shipping-notice): 统一料号字段,移除过时的 SKU 相关字段,更新相关逻辑以支持新字段命名
This commit is contained in:
1 parent
dde25344ca
commit
46eb63f5bb
111 files changed
+3116
-1250
No files matched your search
@@ -17,6 +17,7 @@ import type {
|
||||
ShippingOrderExtractionStatus,
|
||||
} from '../types/chat.types';
|
||||
import type { ShippingBatchUiState, ShippingTaskUiState } from '../types/shipping.api.types';
|
||||
import type { ChatMessageSendResult } from '../types/chat-turn.types';
|
||||
import { createStartChatTurn } from './useChatTurn';
|
||||
|
||||
export interface SendMessageLifecycleHooks {
|
||||
@@ -533,7 +534,7 @@ export function useChat() {
|
||||
>,
|
||||
context?: { task_id?: string; batch_no?: string; shipping_intake_nos?: string[]; display_query?: string },
|
||||
hooks?: SendMessageLifecycleHooks,
|
||||
) => {
|
||||
): Promise<ChatMessageSendResult> => {
|
||||
const displayQuery = String(
|
||||
context && Object.prototype.hasOwnProperty.call(context, 'display_query')
|
||||
? context.display_query ?? ''
|
||||
@@ -565,10 +566,12 @@ export function useChat() {
|
||||
if (runs.value.length > 30) runs.value = runs.value.slice(0, 30);
|
||||
activeRunId.value = run.runId;
|
||||
|
||||
runMessages.push(createUserChatMessage(displayQuery, hooks?.userAttachments));
|
||||
const userMessageIndex = runMessages.push(createUserChatMessage(displayQuery, hooks?.userAttachments)) - 1;
|
||||
let botMsgIndex: number | null = null;
|
||||
let hasAssistantContent = false;
|
||||
let hasTerminalEvent = false;
|
||||
let requestAccepted = false;
|
||||
let chatLogId: number | undefined;
|
||||
let ignoreFurtherStreamEvents = false;
|
||||
const ensureBotMessage = () => {
|
||||
if (botMsgIndex === null) {
|
||||
@@ -609,6 +612,7 @@ export function useChat() {
|
||||
const err = await response.json().catch(() => ({}));
|
||||
throw new Error((err as { error?: string }).error || `Request failed with status ${response.status}`);
|
||||
}
|
||||
requestAccepted = true;
|
||||
|
||||
const reader = response.body?.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
@@ -655,6 +659,10 @@ export function useChat() {
|
||||
}
|
||||
|
||||
const eventName = String(data.event || '');
|
||||
const eventChatLogId = Number(data.chat_log_id || 0);
|
||||
if (Number.isInteger(eventChatLogId) && eventChatLogId > 0) {
|
||||
chatLogId = eventChatLogId;
|
||||
}
|
||||
if (ignoreFurtherStreamEvents && !isAllowedAfterStreamTerminal(eventName)) {
|
||||
continue;
|
||||
}
|
||||
@@ -791,11 +799,24 @@ export function useChat() {
|
||||
if (run.status === 'done' && botMsgIndex !== null) {
|
||||
const botMsg = runMessages[botMsgIndex];
|
||||
if (botMsg) {
|
||||
await hooks?.onAssistantMessageFinished?.(botMsg, runMessages);
|
||||
try {
|
||||
await hooks?.onAssistantMessageFinished?.(botMsg, runMessages);
|
||||
} catch (error) {
|
||||
// 助手完成后的领域刷新属于附加动作,失败不能反向改变已被服务端接受的消息结果。
|
||||
console.error('[chat] onAssistantMessageFinished failed', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!requestAccepted) {
|
||||
const removeCount = botMsgIndex === null ? 1 : Math.max(botMsgIndex - userMessageIndex + 1, 1);
|
||||
runMessages.splice(userMessageIndex, removeCount);
|
||||
}
|
||||
}
|
||||
return run.status === 'done';
|
||||
return {
|
||||
accepted: requestAccepted,
|
||||
completed: requestAccepted && run.status === 'done',
|
||||
...(chatLogId ? { chatLogId } : {}),
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user