19 lines
648 B
TypeScript
19 lines
648 B
TypeScript
export async function sendAIRequest(sessionId: string, userMessage: string, mode: string, apiKey: string): Promise<{ result: string }> {
|
|
const resp = await fetch('/api/ai', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ sessionId, userMessage, apiKey, mode }),
|
|
})
|
|
if (!resp.ok) {
|
|
const err = await resp.json().catch(() => ({ error: 'request failed' }))
|
|
throw new Error(err.error || 'request failed')
|
|
}
|
|
return resp.json()
|
|
}
|
|
|
|
export async function listSessions(): Promise<any[]> {
|
|
const resp = await fetch('/api/ai/sessions')
|
|
if (!resp.ok) return []
|
|
return resp.json()
|
|
}
|