commit 2fbed24b337ddbe1e43e3c275557a7bcd612a7aa Author: fullsizemalt <106900403+fullsizemalt@users.noreply.github.com> Date: Sat Dec 27 12:13:08 2025 -0800 feat: initial commit for backup diff --git a/client/src/api.ts b/client/src/api.ts new file mode 100644 index 0000000..946af6d --- /dev/null +++ b/client/src/api.ts @@ -0,0 +1,82 @@ +import axios from 'axios'; + +// Use environment variable for API URL if available (for Web), otherwise fallback (for Desktop dev) +// The backend is now at kites.runfoo.run (Next.js app) +const API_URL = import.meta.env.VITE_API_URL || 'https://kites.runfoo.run/api/v1'; + +// Hardcoded API Key for MVP Desktop Client +const API_KEY = 'kites-desktop-secret-key'; + +export interface Item { + id: string; + content: string; + title?: string; + syntax?: string; + tags?: string[]; + createdAt: string; + sessionId?: string; + visibility: string; +} + +export interface Session { + id: string; + title: string; + agentName?: string; + createdAt: string; + items?: Item[]; + _count?: { + items: number; + }; +} + +const client = axios.create({ + baseURL: API_URL, + headers: { + 'x-api-key': API_KEY, + 'Content-Type': 'application/json' + } +}); + +export const api = { + health: async () => { + // Next.js app doesn't have explicit health endpoint at /api/health usually, + // but we can check root or just assume it works if pastes load. + return client.get('/pastes?limit=1'); + }, + + getItems: async (search?: string) => { + const params = search ? { q: search } : {}; + // Kites API uses /pastes + return client.get('/pastes', { params }); + }, + + createItem: async (content: string, tags: string[] = [], sessionId?: string) => { + return client.post('/pastes', { + content, + tags, + sessionId, + visibility: 'private', // Default to private for desktop sync + title: content.substring(0, 50) + (content.length > 50 ? '...' : ''), + contentType: 'text/plain' + }); + }, + + getSessions: async () => { + return client.get('/sessions'); + }, + + createSession: async (title: string, agentName?: string) => { + return client.post('/sessions', { + title, + agentName + }); + }, + + getSession: async (id: string) => { + // Next.js Kites API structure for getting session might differ, + // but assuming standard REST based on my route.ts read. + // Actually I didn't verify GET /sessions/:id returns items in the Next.js app. + // Let's assume list for now. + return client.get(`/sessions/${id}`); + } +};