Existing ASP.NET API with vanilla JS SPA, WindowWatcher, Chrome extension, and MCP server. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
49 lines
2.1 KiB
JavaScript
49 lines
2.1 KiB
JavaScript
const BASE = '/api';
|
|
|
|
async function request(path, options = {}) {
|
|
const res = await fetch(`${BASE}${path}`, {
|
|
headers: { 'Content-Type': 'application/json', ...options.headers },
|
|
...options,
|
|
});
|
|
const json = await res.json();
|
|
if (!json.success) throw new Error(json.error || 'Request failed');
|
|
return json.data;
|
|
}
|
|
|
|
export const tasks = {
|
|
list: (status, { parentId, includeSubTasks } = {}) => {
|
|
const params = new URLSearchParams();
|
|
if (status) params.set('status', status);
|
|
if (parentId != null) params.set('parentId', parentId);
|
|
if (includeSubTasks) params.set('includeSubTasks', 'true');
|
|
const qs = params.toString();
|
|
return request(`/tasks${qs ? `?${qs}` : ''}`);
|
|
},
|
|
subtasks: (parentId) => request(`/tasks?parentId=${parentId}`),
|
|
active: () => request('/tasks/active'),
|
|
get: (id) => request(`/tasks/${id}`),
|
|
create: (body) => request('/tasks', { method: 'POST', body: JSON.stringify(body) }),
|
|
start: (id) => request(`/tasks/${id}/start`, { method: 'PUT' }),
|
|
pause: (id, note) => request(`/tasks/${id}/pause`, { method: 'PUT', body: JSON.stringify({ note }) }),
|
|
resume: (id, note) => request(`/tasks/${id}/resume`, { method: 'PUT', body: JSON.stringify({ note }) }),
|
|
complete: (id) => request(`/tasks/${id}/complete`, { method: 'PUT' }),
|
|
abandon: (id) => request(`/tasks/${id}`, { method: 'DELETE' }),
|
|
};
|
|
|
|
export const notes = {
|
|
list: (taskId) => request(`/tasks/${taskId}/notes`),
|
|
create: (taskId, body) => request(`/tasks/${taskId}/notes`, { method: 'POST', body: JSON.stringify(body) }),
|
|
};
|
|
|
|
export const context = {
|
|
recent: (minutes = 30) => request(`/context/recent?minutes=${minutes}`),
|
|
summary: () => request('/context/summary'),
|
|
};
|
|
|
|
export const mappings = {
|
|
list: () => request('/mappings'),
|
|
create: (body) => request('/mappings', { method: 'POST', body: JSON.stringify(body) }),
|
|
update: (id, body) => request(`/mappings/${id}`, { method: 'PUT', body: JSON.stringify(body) }),
|
|
remove: (id) => request(`/mappings/${id}`, { method: 'DELETE' }),
|
|
};
|