refactor: AI session managed server-side, sessionId returned from API

This commit is contained in:
2026-06-15 11:23:14 +08:00
parent 33357650c7
commit 0aac429908
4 changed files with 42 additions and 25 deletions

View File

@@ -1,8 +1,8 @@
export async function sendAIRequest(sessionId: string, userMessage: string, mode: string, apiKey: string): Promise<{ result: string }> {
export async function sendAIRequest(userMessage: string, mode: string, apiKey: string, sessionId?: string): Promise<{ result: string; sessionId: string }> {
const resp = await fetch('/api/ai', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sessionId, userMessage, apiKey, mode }),
body: JSON.stringify({ userMessage, apiKey, mode, ...(sessionId ? { sessionId } : {}) }),
})
if (!resp.ok) {
const err = await resp.json().catch(() => ({ error: 'request failed' }))