import { fetchJSON, jsonBody } from './index'; export type BotData = { id: string; platform: string; name: string; workspace: string; model_id: string; token_masked: string; allowed_senders: string[]; is_active: boolean; is_running: boolean; meta: Record | null; created_at: number; updated_at: number; }; export type BotForm = { platform: string; name: string; workspace: string; model_id: string; token: string; allowed_senders?: string[]; is_active?: boolean; }; export type BotUpdate = { name?: string; workspace?: string; model_id?: string; token?: string; allowed_senders?: string[]; is_active?: boolean; }; export async function listBots(): Promise { return fetchJSON('/api/admin/bots'); } export async function createBot(form: BotForm): Promise { return fetchJSON('/api/admin/bots', jsonBody(form)); } export async function updateBot(id: string, form: BotUpdate): Promise { return fetchJSON(`/api/admin/bots/${id}`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(form) }); } export async function deleteBot(id: string): Promise<{ ok: boolean }> { return fetchJSON(`/api/admin/bots/${id}`, { method: 'DELETE' }); } export async function startBot(id: string): Promise<{ ok: boolean; is_running: boolean }> { return fetchJSON(`/api/admin/bots/${id}/start`, { method: 'POST' }); } export async function stopBot(id: string): Promise<{ ok: boolean; is_running: boolean }> { return fetchJSON(`/api/admin/bots/${id}/stop`, { method: 'POST' }); } export async function verifyBotToken( platform: string, token: string ): Promise<{ ok: boolean; info?: { username: string; id: string }; error?: string }> { return fetchJSON('/api/admin/bots/verify', jsonBody({ platform, token })); }