feat: initial commit for backup
This commit is contained in:
commit
2fbed24b33
1 changed files with 82 additions and 0 deletions
82
client/src/api.ts
Normal file
82
client/src/api.ts
Normal file
|
|
@ -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<Item[]>('/pastes', { params });
|
||||||
|
},
|
||||||
|
|
||||||
|
createItem: async (content: string, tags: string[] = [], sessionId?: string) => {
|
||||||
|
return client.post<Item>('/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<Session[]>('/sessions');
|
||||||
|
},
|
||||||
|
|
||||||
|
createSession: async (title: string, agentName?: string) => {
|
||||||
|
return client.post<Session>('/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<Session>(`/sessions/${id}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Add table
Reference in a new issue