feat: 同步管理端、用户端与后端业务,并接通线上 Web 接口
补齐平台订阅、外部登录、CRM 同步与用户端页面;Nginx 转发用户端接口,登录页使用 Google 与 Apple 标志。 Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
@@ -17,10 +17,24 @@ const AI_CHAT_UTS = path.resolve(
|
||||
);
|
||||
|
||||
type AiChatRole = 'user' | 'assistant' | 'system';
|
||||
type ChatMessageType = 'text' | 'lead_card';
|
||||
|
||||
type ChatLeadPayload = {
|
||||
title: string;
|
||||
description: string;
|
||||
name: string;
|
||||
contact: string;
|
||||
submitted: boolean;
|
||||
submitting: boolean;
|
||||
successMessage?: string;
|
||||
errorMessage?: string;
|
||||
};
|
||||
|
||||
type AiChatMessage = {
|
||||
role: AiChatRole;
|
||||
content: string;
|
||||
type?: ChatMessageType;
|
||||
cardPayload?: ChatLeadPayload;
|
||||
};
|
||||
|
||||
type AiChatRequest = {
|
||||
@@ -54,6 +68,30 @@ type SendChatResult = {
|
||||
leadHint: string;
|
||||
};
|
||||
|
||||
type AiChatState = {
|
||||
cardId: string;
|
||||
locale: string;
|
||||
draft: string;
|
||||
sending: boolean;
|
||||
messages: AiChatMessage[];
|
||||
showLeadHint: boolean;
|
||||
leadHint: string;
|
||||
errorMessage: string;
|
||||
};
|
||||
|
||||
type SubmitLeadParams = {
|
||||
cardId: string | number;
|
||||
name: string;
|
||||
phone?: string;
|
||||
email?: string;
|
||||
source?: string;
|
||||
notes?: string;
|
||||
};
|
||||
|
||||
type SubmitLeadApi = {
|
||||
submitLead: (params: SubmitLeadParams) => Promise<unknown>;
|
||||
};
|
||||
|
||||
type UseAiChatModule = {
|
||||
buildUserMessage: (text: string) => AiChatMessage;
|
||||
appendTurn: (
|
||||
@@ -62,6 +100,21 @@ type UseAiChatModule = {
|
||||
reply: AiChatReply
|
||||
) => AiChatMessage[];
|
||||
sendChat: (input: SendChatInput, api?: SendChatApi) => Promise<SendChatResult>;
|
||||
hasLeadIntent: (text: string) => boolean;
|
||||
createAiChatState: () => AiChatState;
|
||||
createLeadCardPayload: (locale?: string) => ChatLeadPayload;
|
||||
createLeadCardMessage: (locale?: string) => AiChatMessage;
|
||||
sendStreamChat: (
|
||||
state: AiChatState,
|
||||
text?: string,
|
||||
options?: { intervalMs?: number }
|
||||
) => Promise<boolean>;
|
||||
submitLeadCard: (
|
||||
cardId: string | number,
|
||||
payload: ChatLeadPayload,
|
||||
api?: SubmitLeadApi
|
||||
) => Promise<boolean>;
|
||||
resolveAiChatText: (key: string) => string;
|
||||
};
|
||||
|
||||
const EMOJI_RE = /[\u{1F300}-\u{1FAFF}\u{2600}-\u{27BF}]/u;
|
||||
@@ -200,6 +253,119 @@ describe('OmniCard AI 门户顾问对话业务逻辑测试 (useAiChat.uts)', ()
|
||||
expect(result.messages[result.messages.length - 1].role).toBe('assistant');
|
||||
});
|
||||
});
|
||||
|
||||
describe('4. P49 留资意向判定 hasLeadIntent', () => {
|
||||
it('4.1 命中价格/报价/合作/buy/quote/price 等关键词为真', () => {
|
||||
const { hasLeadIntent } = loadUseAiChat();
|
||||
|
||||
expect(hasLeadIntent('请问标准版价格多少')).toBe(true);
|
||||
expect(hasLeadIntent('发一份报价')).toBe(true);
|
||||
expect(hasLeadIntent('希望商务合作')).toBe(true);
|
||||
expect(hasLeadIntent('I want to buy')).toBe(true);
|
||||
expect(hasLeadIntent('Can you quote pricing?')).toBe(true);
|
||||
expect(hasLeadIntent('What is the PRICE')).toBe(true);
|
||||
});
|
||||
|
||||
it('4.2 普通闲聊与空文本不为真', () => {
|
||||
const { hasLeadIntent } = loadUseAiChat();
|
||||
|
||||
expect(hasLeadIntent('你好')).toBe(false);
|
||||
expect(hasLeadIntent('介绍一下服务')).toBe(false);
|
||||
expect(hasLeadIntent('Good morning')).toBe(false);
|
||||
expect(hasLeadIntent('')).toBe(false);
|
||||
expect(hasLeadIntent(' ')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('5. P49 sendStreamChat 按意向弹留资卡', () => {
|
||||
it('5.1 有意向时追加 lead_card,姓名为空且未提交', async () => {
|
||||
const { createAiChatState, sendStreamChat } = loadUseAiChat();
|
||||
const state = createAiChatState();
|
||||
state.cardId = 'card-p49';
|
||||
state.draft = '请问方案报价多少?';
|
||||
|
||||
const ok = await sendStreamChat(state, undefined, { intervalMs: 0 });
|
||||
expect(ok).toBe(true);
|
||||
expect(state.messages.length).toBe(3);
|
||||
|
||||
const cardMsg = state.messages[2];
|
||||
expect(cardMsg.type).toBe('lead_card');
|
||||
expect(cardMsg.cardPayload).toBeDefined();
|
||||
expect(cardMsg.cardPayload?.name).toBe('');
|
||||
expect(cardMsg.cardPayload?.contact).toBe('');
|
||||
expect(cardMsg.cardPayload?.submitted).toBe(false);
|
||||
expect(state.showLeadHint).toBe(true);
|
||||
});
|
||||
|
||||
it('5.2 无意向时不追加留资卡', async () => {
|
||||
const { createAiChatState, sendStreamChat } = loadUseAiChat();
|
||||
const state = createAiChatState();
|
||||
state.cardId = 'card-p49';
|
||||
state.draft = '名片支持哪些展示模块?';
|
||||
|
||||
const ok = await sendStreamChat(state, undefined, { intervalMs: 0 });
|
||||
expect(ok).toBe(true);
|
||||
expect(state.messages.length).toBe(2);
|
||||
expect(state.messages.some((m) => m.type === 'lead_card')).toBe(false);
|
||||
expect(state.showLeadHint).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('6. P49 submitLeadCard 走真实线索接口契约', () => {
|
||||
it('6.1 成功提交时调用 submitLead 并标记 submitted', async () => {
|
||||
const { createLeadCardPayload, submitLeadCard } = loadUseAiChat();
|
||||
const payload = createLeadCardPayload('zh-CN');
|
||||
payload.name = 'Alex Wang';
|
||||
payload.contact = 'alex@example.com';
|
||||
|
||||
const submitLead = jest
|
||||
.fn<Promise<unknown>, [SubmitLeadParams]>()
|
||||
.mockResolvedValue({ id: 'lead-1' });
|
||||
|
||||
const ok = await submitLeadCard('card-p49', payload, { submitLead });
|
||||
expect(ok).toBe(true);
|
||||
expect(submitLead).toHaveBeenCalledTimes(1);
|
||||
const params = submitLead.mock.calls[0][0];
|
||||
expect(params.cardId).toBe('card-p49');
|
||||
expect(params.name).toBe('Alex Wang');
|
||||
expect(params.email).toBe('alex@example.com');
|
||||
expect(params.source).toBe('ai_chat');
|
||||
expect(payload.submitted).toBe(true);
|
||||
expect(payload.submitting).toBe(false);
|
||||
expect(payload.errorMessage).toBe('');
|
||||
});
|
||||
|
||||
it('6.2 接口失败显示错误且不把卡片标成已提交', async () => {
|
||||
const { createLeadCardPayload, submitLeadCard, resolveAiChatText } =
|
||||
loadUseAiChat();
|
||||
const payload = createLeadCardPayload('en-US');
|
||||
payload.name = 'Jordan Lee';
|
||||
payload.contact = '+15551234567';
|
||||
|
||||
const submitLead = jest
|
||||
.fn<Promise<unknown>, [SubmitLeadParams]>()
|
||||
.mockRejectedValue(new Error('network'));
|
||||
|
||||
const ok = await submitLeadCard('card-p49', payload, { submitLead });
|
||||
expect(ok).toBe(false);
|
||||
expect(payload.submitted).toBe(false);
|
||||
expect(payload.submitting).toBe(false);
|
||||
expect(payload.errorMessage).toBe(resolveAiChatText('submitFailed'));
|
||||
expect(payload.errorMessage.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('6.3 留资卡初始不造假客户姓名', () => {
|
||||
const { createLeadCardPayload, createLeadCardMessage } = loadUseAiChat();
|
||||
const payload = createLeadCardPayload('zh-CN');
|
||||
expect(payload.name).toBe('');
|
||||
expect(payload.contact).toBe('');
|
||||
expect(payload.submitted).toBe(false);
|
||||
|
||||
const msg = createLeadCardMessage('en-US');
|
||||
expect(msg.type).toBe('lead_card');
|
||||
expect(msg.cardPayload?.name).toBe('');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('OmniCard AI 门户顾问对话页契约 (ai-chat.uvue)', () => {
|
||||
@@ -225,6 +391,34 @@ describe('OmniCard AI 门户顾问对话页契约 (ai-chat.uvue)', () => {
|
||||
expect(pageSource.includes('askAiChat') || logicSource.includes('askAiChat')).toBe(true);
|
||||
});
|
||||
|
||||
it('P49 留资卡按 type===lead_card 渲染,提交走 submitLead,失败展示 errorMessage', () => {
|
||||
const pageSource = fs.readFileSync(AI_CHAT_PAGE, 'utf8');
|
||||
const logicSource = fs.readFileSync(AI_CHAT_UTS, 'utf8');
|
||||
|
||||
expect(pageSource.includes("item.type === 'lead_card'")).toBe(true);
|
||||
expect(pageSource.includes('ai-lead-card')).toBe(true);
|
||||
expect(pageSource.includes('cardPayload.errorMessage')).toBe(true);
|
||||
expect(pageSource.includes('submitLeadCard')).toBe(true);
|
||||
expect(pageSource.includes('handleSubmitCard')).toBe(true);
|
||||
|
||||
expect(logicSource.includes('hasLeadIntent')).toBe(true);
|
||||
expect(logicSource.includes('createLeadCardMessage')).toBe(true);
|
||||
expect(logicSource.includes('submitLead')).toBe(true);
|
||||
expect(logicSource.includes("source: 'ai_chat'")).toBe(true);
|
||||
expect(logicSource.includes("payload.errorMessage = resolveAiChatText('submitFailed')")).toBe(
|
||||
true
|
||||
);
|
||||
|
||||
const submitFnStart = logicSource.indexOf('export async function submitLeadCard');
|
||||
expect(submitFnStart).toBeGreaterThanOrEqual(0);
|
||||
const submitFnBody = logicSource.slice(submitFnStart);
|
||||
const catchIdx = submitFnBody.indexOf('} catch (_e) {');
|
||||
expect(catchIdx).toBeGreaterThan(0);
|
||||
const failCatch = submitFnBody.slice(catchIdx, catchIdx + 220);
|
||||
expect(failCatch.includes('payload.submitted = true')).toBe(false);
|
||||
expect(failCatch.includes("resolveAiChatText('submitFailed')")).toBe(true);
|
||||
});
|
||||
|
||||
it('无 emoji、无 any,对话不用 view v-for,无自动播放声音', () => {
|
||||
const pageSource = fs.readFileSync(AI_CHAT_PAGE, 'utf8');
|
||||
const logicSource = fs.readFileSync(AI_CHAT_UTS, 'utf8');
|
||||
|
||||
在新工单中引用
屏蔽一个用户