This commit is contained in:
2026-05-14 19:24:50 +00:00
parent af0628867f
commit a7f218e182
63 changed files with 10539 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
import { useCallback, useEffect, useState } from 'react';
import { api } from '@/api/client';
import type { Session } from '@/api/types';
export function useSessions(projectId: string | undefined) {
const [sessions, setSessions] = useState<Session[] | null>(null);
const [error, setError] = useState<string | null>(null);
const refresh = useCallback(async () => {
if (!projectId) {
setSessions(null);
return;
}
try {
const list = await api.sessions.listForProject(projectId);
setSessions(list);
setError(null);
} catch (err) {
setError(err instanceof Error ? err.message : 'failed to load sessions');
}
}, [projectId]);
useEffect(() => {
void refresh();
}, [refresh]);
const create = useCallback(
async (body: { name?: string; model?: string; system_prompt?: string }) => {
if (!projectId) throw new Error('no project');
const created = await api.sessions.create(projectId, body);
await refresh();
return created;
},
[projectId, refresh]
);
const remove = useCallback(
async (id: string) => {
await api.sessions.remove(id);
await refresh();
},
[refresh]
);
return { sessions, error, refresh, create, remove };
}