Files
post-hub-platform-k7m2xq9wnp/devops-view/src/services/api.ts
2026-03-20 19:31:54 +01:00

30 lines
902 B
TypeScript

import type { Chat, CreateEntryResponse } from "../types";
const BASE = "/api/rag";
export async function createChat(token: string): Promise<Chat> {
const res = await fetch(`${BASE}/chat/new?title=DevOps%20Chat`, {
method: "POST",
headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) throw new Error(`Failed to create chat: ${res.status}`);
return res.json() as Promise<Chat>;
}
export async function sendMessage(
token: string,
chatId: number,
content: string
): Promise<CreateEntryResponse> {
const res = await fetch(`${BASE}/entry/${chatId}`, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ content, onlyContext: true }),
});
if (!res.ok) throw new Error(`Failed to send message: ${res.status}`);
return res.json() as Promise<CreateEntryResponse>;
}