From 38b0d91407aea8558d104d5cd0b4431bb3bc84f3 Mon Sep 17 00:00:00 2001 From: iven Date: Mon, 18 May 2026 09:35:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(mp):=20AI=20=E8=81=8A=E5=A4=A9=E4=BC=A0?= =?UTF-8?q?=E9=80=92=20patient=5Fid=20=E6=94=AF=E6=8C=81=E4=BD=93=E5=BE=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2=20Tool=20Call?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ai-chat service: sendAiMessage 新增 patientId 可选参数 - messages 页面: 从 authStore 获取 currentPatient.id 传入 Co-Authored-By: Claude Opus 4.7 --- apps/miniprogram/src/pages/messages/index.tsx | 3 ++- apps/miniprogram/src/services/ai-chat.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/miniprogram/src/pages/messages/index.tsx b/apps/miniprogram/src/pages/messages/index.tsx index d1e596e..2fc8ad9 100644 --- a/apps/miniprogram/src/pages/messages/index.tsx +++ b/apps/miniprogram/src/pages/messages/index.tsx @@ -26,6 +26,7 @@ function genId(): string { export default function Messages() { const user = useAuthStore((s) => s.user); + const currentPatient = useAuthStore((s) => s.currentPatient); const modeClass = useElderClass(); const [messages, setMessages] = useState([]); const [inputText, setInputText] = useState(''); @@ -70,7 +71,7 @@ export default function Messages() { scrollToBottom(next); try { - const resp = await sendAiMessage(content, next); + const resp = await sendAiMessage(content, next, currentPatient?.id); const aiMsg: AiChatMessage = { id: resp.message_id || genId(), role: 'assistant', diff --git a/apps/miniprogram/src/services/ai-chat.ts b/apps/miniprogram/src/services/ai-chat.ts index c516364..44a88f9 100644 --- a/apps/miniprogram/src/services/ai-chat.ts +++ b/apps/miniprogram/src/services/ai-chat.ts @@ -16,11 +16,16 @@ export interface AiChatResponse { export async function sendAiMessage( message: string, history?: AiChatMessage[], + patientId?: string, ): Promise { - const resp = await api.post('/ai/chat', { + const body: Record = { message, history: history?.slice(-10), - }); + }; + if (patientId) { + body.patient_id = patientId; + } + const resp = await api.post('/ai/chat', body); return resp; }