- Session click opens edit form (name, description, image, agent) instead of chat
- Chat is now a separate route (#chat/{id}), opened via button
- Sessions created on save, not on click
- Soft-delete for sessions (is_deleted flag)
- Delete button in session form
- Removed title double-click editing from chat
- Card images now square (aspect-ratio: 1)
- New Session as placeholder card
106 lines
2.7 KiB
JavaScript
106 lines
2.7 KiB
JavaScript
// ── API Calls ──
|
|
|
|
async function apiChat(messages, systemPrompt, sessionId) {
|
|
return fetch('/api/chat', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ messages, systemPrompt, sessionId })
|
|
});
|
|
}
|
|
|
|
// ── Agent API ──
|
|
|
|
async function apiGetAgents() {
|
|
const resp = await fetch('/api/agents');
|
|
return resp.json();
|
|
}
|
|
|
|
async function apiGetAgent(agentId) {
|
|
const resp = await fetch(`/api/agents/${agentId}`);
|
|
if (!resp.ok) return null;
|
|
return resp.json();
|
|
}
|
|
|
|
async function apiCreateAgent(data) {
|
|
const resp = await fetch('/api/agents', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(data)
|
|
});
|
|
return resp.json();
|
|
}
|
|
|
|
async function apiUpdateAgent(agentId, data) {
|
|
const resp = await fetch(`/api/agents/${agentId}`, {
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(data)
|
|
});
|
|
return resp.json();
|
|
}
|
|
|
|
async function apiDeleteAgent(agentId) {
|
|
return fetch(`/api/agents/${agentId}`, { method: 'DELETE' });
|
|
}
|
|
|
|
async function apiHistory(sessionId) {
|
|
const resp = await fetch(`/api/history?sessionId=${sessionId}`);
|
|
return resp.json();
|
|
}
|
|
|
|
async function apiHistoryPoll(sessionId, afterId) {
|
|
const resp = await fetch(`/api/history/poll?sessionId=${sessionId}&afterId=${afterId}`);
|
|
return resp.json();
|
|
}
|
|
|
|
async function apiArchive(sessionId) {
|
|
const resp = await fetch(`/api/archive?sessionId=${sessionId}`, { method: 'POST' });
|
|
if (resp.status === 204) return null;
|
|
return resp.json();
|
|
}
|
|
|
|
async function apiListArchives(sessionId) {
|
|
const resp = await fetch(`/api/archives?sessionId=${sessionId}`);
|
|
return resp.json();
|
|
}
|
|
|
|
async function apiGetArchive(archiveId) {
|
|
const resp = await fetch(`/api/archive/${archiveId}`);
|
|
return resp.json();
|
|
}
|
|
|
|
// ── Session API ──
|
|
|
|
async function apiGetSessions() {
|
|
const resp = await fetch('/api/sessions');
|
|
return resp.json();
|
|
}
|
|
|
|
async function apiCreateSession(data = {}) {
|
|
const resp = await fetch('/api/sessions', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(data)
|
|
});
|
|
return resp.json();
|
|
}
|
|
|
|
async function apiGetSession(sessionId) {
|
|
const resp = await fetch(`/api/sessions/${sessionId}`);
|
|
if (!resp.ok) return null;
|
|
return resp.json();
|
|
}
|
|
|
|
async function apiDeleteSession(sessionId) {
|
|
return fetch(`/api/sessions/${sessionId}`, { method: 'DELETE' });
|
|
}
|
|
|
|
async function apiUpdateSession(sessionId, data) {
|
|
const resp = await fetch(`/api/sessions/${sessionId}`, {
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(data)
|
|
});
|
|
return resp.json();
|
|
}
|