feat(mp): Day 10 — 小程序会话 API 封装
- sendAiMessage 支持 sessionId 参数 - 新增 createSession / listSessions / renameSession / closeSession - AiChatSession 接口定义
This commit is contained in:
@@ -28,6 +28,7 @@ export async function sendAiMessage(
|
|||||||
message: string,
|
message: string,
|
||||||
history?: AiChatMessage[],
|
history?: AiChatMessage[],
|
||||||
patientId?: string,
|
patientId?: string,
|
||||||
|
sessionId?: string,
|
||||||
): Promise<AiChatResponse> {
|
): Promise<AiChatResponse> {
|
||||||
const body: Record<string, unknown> = {
|
const body: Record<string, unknown> = {
|
||||||
message,
|
message,
|
||||||
@@ -36,10 +37,43 @@ export async function sendAiMessage(
|
|||||||
if (patientId) {
|
if (patientId) {
|
||||||
body.patient_id = patientId;
|
body.patient_id = patientId;
|
||||||
}
|
}
|
||||||
|
if (sessionId) {
|
||||||
|
body.session_id = sessionId;
|
||||||
|
}
|
||||||
const resp = await api.post<AiChatResponse>('/ai/chat', body);
|
const resp = await api.post<AiChatResponse>('/ai/chat', body);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// === 会话 API ===
|
||||||
|
|
||||||
|
export interface AiChatSession {
|
||||||
|
id: string;
|
||||||
|
title: string | null;
|
||||||
|
patient_id: string | null;
|
||||||
|
status: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createSession(patientId?: string, title?: string): Promise<AiChatSession> {
|
||||||
|
const body: Record<string, unknown> = {};
|
||||||
|
if (patientId) body.patient_id = patientId;
|
||||||
|
if (title) body.title = title;
|
||||||
|
return api.post<AiChatSession>('/ai/chat/sessions', body);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listSessions(): Promise<AiChatSession[]> {
|
||||||
|
return api.get<AiChatSession[]>('/ai/chat/sessions');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function renameSession(sessionId: string, title: string): Promise<void> {
|
||||||
|
await api.put(`/ai/chat/sessions/${sessionId}/rename`, { title });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function closeSession(sessionId: string): Promise<void> {
|
||||||
|
await api.post(`/ai/chat/sessions/${sessionId}/close`, {});
|
||||||
|
}
|
||||||
|
|
||||||
/** 获取聊天历史(本地缓存) */
|
/** 获取聊天历史(本地缓存) */
|
||||||
export function getLocalHistory(): AiChatMessage[] {
|
export function getLocalHistory(): AiChatMessage[] {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user