feat(shipping-notice): 新增货代客户管理功能,支持客户导入、识别证据管理与客户确认
This commit is contained in:
1 parent
b595e157e9
commit
4fbaed2b4c
176 files changed
+14011
-994
No files matched your search
@@ -1,6 +1,8 @@
|
||||
/**
|
||||
* features/chat/api/chat.api.ts
|
||||
* 聊天域 HTTP API:会话、消息、源文件、附件上传。
|
||||
* 用途:封装聊天会话、消息、源文件与附件上传 HTTP API,并恢复结构化历史消息状态。
|
||||
* 依赖:shared/api/client、鉴权工具、chat.types。
|
||||
* 逻辑:页面 composable 调用本模块;历史消息响应在返回前将 ChatLog.payload 中的领域状态投影到 ChatMessage。
|
||||
*/
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
@@ -14,6 +16,7 @@ import type {
|
||||
ChatSourceFileResult,
|
||||
ChatUploadResult,
|
||||
OaEmployeesResponse,
|
||||
ShippingOrderExtractionState,
|
||||
} from '../types/chat.types';
|
||||
|
||||
const auth = () => ({ headers: getAuthHeaders() });
|
||||
@@ -28,10 +31,30 @@ export const deleteAllChatSessions = (agentId: number) =>
|
||||
export const deleteChatSession = (conversationId: string, agentId: number) =>
|
||||
requestJson(`/api/chat/sessions/${conversationId}?agent_id=${agentId}`, { method: 'DELETE', ...auth() });
|
||||
|
||||
/**
|
||||
* 从 ChatLog.payload 恢复订单识别终态,保证刷新会话后与实时 SSE 消息形状一致。
|
||||
* 核心逻辑:仅接受带合法 status 的对象;服务端仍是终态事实源,本函数不推导或改写计数。
|
||||
* @param message - 历史接口返回的单条消息。
|
||||
* @returns 原消息或已补充 shipping_order_extraction_state 的消息。
|
||||
*/
|
||||
export const hydrateShippingOrderExtractionState = (message: ChatMessage): ChatMessage => {
|
||||
const payload = message.payload && typeof message.payload === 'object'
|
||||
? message.payload as Record<string, unknown>
|
||||
: {};
|
||||
const state = payload.shipping_order_extraction_state;
|
||||
if (!state || typeof state !== 'object') return message;
|
||||
const status = String((state as Record<string, unknown>).status || '');
|
||||
if (!['extracting', 'completed', 'partially_completed', 'failed'].includes(status)) return message;
|
||||
message.shipping_order_extraction_state = state as ShippingOrderExtractionState;
|
||||
return message;
|
||||
};
|
||||
|
||||
export const listChatMessages = async (conversationId: string, agentId: number) => {
|
||||
const messages = await requestJson<ChatMessage[]>(`/api/chat/messages?conversation_id=${conversationId}&agent_id=${agentId}`, auth());
|
||||
return Array.isArray(messages)
|
||||
? messages.filter((message) => message?.type !== 'shipping-parse-review')
|
||||
? messages
|
||||
.filter((message) => message?.type !== 'shipping-parse-review')
|
||||
.map(hydrateShippingOrderExtractionState)
|
||||
: messages;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user