feat(shipping-notice): 添加订单抽取功能,支持异步运行和管理,优化相关数据模型和处理逻辑
This commit is contained in:
1 parent
34d489a2d1
commit
ce26d6d0c4
144 files changed
+12241
-4233
No files matched your search
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* features/chat/page/useChatPageLocalMessage.spec.ts
|
||||
* 用途:验证非 SSE 本地消息的 ID 和持久化结果契约。
|
||||
* 依赖:Vitest、useChatPageLocalMessage、chat.api mock。
|
||||
* 逻辑:成功回写会话/日志并返回 true,且工厂始终返回可调用 helpers。
|
||||
*/
|
||||
import { computed, ref } from 'vue';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
|
||||
const api = vi.hoisted(() => ({ saveLocalChatMessage: vi.fn() }));
|
||||
vi.mock('../api/chat.api', () => ({ saveLocalChatMessage: api.saveLocalChatMessage }));
|
||||
|
||||
import { createChatPageLocalMessageApi } from './useChatPageLocalMessage';
|
||||
|
||||
describe('createChatPageLocalMessageApi', () => {
|
||||
beforeEach(() => api.saveLocalChatMessage.mockReset());
|
||||
|
||||
it('returns helpers and reports a successful persisted message', async () => {
|
||||
const conversationId = ref<string | null>(null);
|
||||
api.saveLocalChatMessage.mockResolvedValue({ conversation_id: 'conv-local', chat_log_id: 42 });
|
||||
const helpers = createChatPageLocalMessageApi({ conversationId, currentAgentId: computed(() => 7) });
|
||||
const message: ChatMessage = { role: 'assistant', type: 'text', content: 'done' };
|
||||
|
||||
expect(helpers.newLocalMessageId('local')).toContain('local-');
|
||||
expect(await helpers.saveLocalMessageToBackend(message)).toBe(true);
|
||||
expect(conversationId.value).toBe('conv-local');
|
||||
expect(message.chat_log_id).toBe(42);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,8 @@
|
||||
/**
|
||||
* 对话页:本地消息落库(请假/出货等不经过 SSE 的消息)。
|
||||
* features/chat/page/useChatPageLocalMessage.ts
|
||||
* 用途:持久化请假、出货等不经过 SSE 的本地聊天消息。
|
||||
* 依赖:chat.api.saveLocalChatMessage、ChatMessage、Vue refs。
|
||||
* 逻辑:各业务 composable 传入本地消息;本模块绑定当前会话并返回明确保存结果。
|
||||
*/
|
||||
import { saveLocalChatMessage } from '../api/chat.api';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
@@ -13,12 +16,19 @@ export interface ChatPageLocalMessageContext {
|
||||
export function createChatPageLocalMessageApi(ctx: ChatPageLocalMessageContext) {
|
||||
let localMessageCounter = 0;
|
||||
|
||||
const newLocalMessageId = (prefix: string) => {
|
||||
/** 生成组件实例内唯一的本地消息 ID,用于前端渲染和提交前关联。 */
|
||||
const newLocalMessageId = (prefix: string): string => {
|
||||
localMessageCounter += 1;
|
||||
return `${prefix}-${Date.now()}-${localMessageCounter}`;
|
||||
};
|
||||
|
||||
const saveLocalMessageToBackend = async (localMsg: ChatMessage, userQuery: string = '') => {
|
||||
/**
|
||||
* 保存一条本地消息,并把服务端会话与日志主键回写到前端对象。
|
||||
* @param localMsg - 待保存的用户或助手消息。
|
||||
* @param userQuery - 用户消息展示文本;助手消息必须为空。
|
||||
* @returns 服务端确认提交时为 true;网络或业务失败时为 false。
|
||||
*/
|
||||
const saveLocalMessageToBackend = async (localMsg: ChatMessage, userQuery: string = ''): Promise<boolean> => {
|
||||
try {
|
||||
const data = await saveLocalChatMessage({
|
||||
conversation_id: ctx.conversationId.value,
|
||||
@@ -35,8 +45,9 @@ export function createChatPageLocalMessageApi(ctx: ChatPageLocalMessageContext)
|
||||
if (data.chat_log_id) {
|
||||
localMsg.chat_log_id = data.chat_log_id;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to save local message', e);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ export interface ChatPageSendContext {
|
||||
agentId: number,
|
||||
kb: string,
|
||||
files: ChatUploadFileSpec[],
|
||||
context?: { task_id?: string; batch_no?: string; shipping_intake_nos?: string[]; shipping_temporary_inventory_asset_no?: string; shipping_temporary_inventory_session_no?: string; display_query?: string },
|
||||
context?: { task_id?: string; batch_no?: string; shipping_temporary_inventory_asset_no?: string; shipping_temporary_inventory_session_no?: string; display_query?: string },
|
||||
hooks?: SendMessageLifecycleHooks,
|
||||
) => Promise<ChatMessageSendResult>;
|
||||
refreshHistoryAfterSend: () => Promise<void>;
|
||||
@@ -75,7 +75,7 @@ export interface ChatPageSendContext {
|
||||
msg: { warning: (text: string) => void; info: (text: string) => void };
|
||||
t: (key: string) => string;
|
||||
copiedIndex: Ref<number | null>;
|
||||
getChatContext?: () => { task_id?: string; batch_no?: string; shipping_intake_nos?: string[]; shipping_temporary_inventory_asset_no?: string; shipping_temporary_inventory_session_no?: string; display_query?: string };
|
||||
getChatContext?: () => { task_id?: string; batch_no?: string; shipping_temporary_inventory_asset_no?: string; shipping_temporary_inventory_session_no?: string; display_query?: string };
|
||||
onAssistantMessageFinished?: (message: ChatMessage, runMessages: ChatMessage[]) => void | Promise<void>;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user