ultron1 / website /src /lib /api.js
ghostdrive1's picture
v26: complete website β€” Projects live, Sentinel live topology, 4 new components, CF Worker updated, api.js complete
37f231b
Raw
History Blame Contribute Delete
1.54 kB
// website/src/lib/api.js
// All Brain calls go through the CF Worker (ultron-api) which proxies to Brain.
// Worker adds X-Ultron-Token from its own secret β€” website never holds the token.
const BASE = import.meta.env.VITE_API_URL || 'https://ultron-api.ghostdriveg1.workers.dev';
async function req(path, opts = {}) {
const res = await fetch(`${BASE}${path}`, {
...opts,
headers: { 'Content-Type': 'application/json', ...opts.headers },
});
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
return res.json();
}
export const api = {
// GET /api/health β†’ Brain /health
health: () => req('/api/health'),
// POST /api/infer β†’ Brain /infer
infer: (payload) => req('/api/infer', { method: 'POST', body: JSON.stringify(payload) }),
// GET /api/keys β†’ Brain /keys
keys: {
list: () => req('/api/keys'),
},
// Sentinel
sentinel: {
trigger: (type) =>
req('/api/sentinel/event', {
method: 'POST',
body: JSON.stringify({ event_type: type, payload: { source: 'website' } }),
}),
reports: () => req('/api/sentinel/reports'),
},
// Memory
memory: {
stm: (channelId) => req(`/api/memory/stm/${channelId}`),
},
// R&D loop history
rd: {
history: (userId, limit = 20) => req(`/api/rd/history/${userId}?limit=${limit}`),
},
// Infrastructure β€” SpacePromoter topology + infra event log
infra: {
promoterStatus: () => req('/api/health').then((d) => d.promoter ?? null),
events: () => req('/api/infra/events'),
},
};