Feature 1 — Tab close menu (pure local pane state, no API):
- ChatTabBar context menu: Rename / sep / Close / Close others / Close to right / Close all
- Workspace bulk-tab primitives: closeOtherTabs, closeTabsToRight, closeAllTabs (manipulate panes[].chatIds, no fetch)
- Drop in-bar Delete; landing card's name-typed Delete is the canonical destructive path
Feature 2 — Chat archive + delete:
- chats.status vocabulary aligned with projects ('open' | 'archived'); DROP old inline CHECK, UPDATE 'closed' → 'archived', ADD new named chats_status_chk
- POST /api/chats/:id/archive (204) + POST /api/chats/:id/unarchive (200) + GET /api/sessions/:id/chats?status=archived; DELETE publishes chat_deleted; PATCH simplified to name-only
- 3 new WS frames: chat_archived, chat_unarchived, chat_deleted (renamed from chat_closed)
- Same dedup discipline: server-only publish, no local sessionEvents.emit in client
- SessionLandingPage: right-click ContextMenu (Open / Rename / Archive / sep / Delete-destructive), inline rename, archive confirm dialog, delete dialog with name-typed Input gated until typed text === chat.name, Archived chats collapsible section with Restore
- Card-level Archive + Delete icon buttons reusing the same dialog state setters; stopPropagation on both so card click still opens the chat; archived cards keep only Restore
UX — chat content width cap:
- ChatPane content (MessageList, queue chips, stop button, ChatInput) wrapped in inner max-w-[1000px] mx-auto w-full so messages center; outer border-t / scroll containers stay full-width so pane chrome and backgrounds remain edge-to-edge
- No new deps, no media queries (narrow viewports collapse to width naturally)
186 lines
6.1 KiB
TypeScript
186 lines
6.1 KiB
TypeScript
import type {
|
|
Project,
|
|
AvailableProject,
|
|
Session,
|
|
Chat,
|
|
Message,
|
|
ModelInfo,
|
|
SidebarResponse,
|
|
ListDirResult,
|
|
ViewFileResult,
|
|
} from './types';
|
|
|
|
export class ApiError extends Error {
|
|
constructor(
|
|
public status: number,
|
|
public body: unknown
|
|
) {
|
|
super(typeof body === 'object' && body && 'error' in body ? String((body as { error: unknown }).error) : `HTTP ${status}`);
|
|
}
|
|
}
|
|
|
|
async function request<T>(
|
|
path: string,
|
|
init: RequestInit = {}
|
|
): Promise<T> {
|
|
const res = await fetch(path, {
|
|
...init,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...(init.headers ?? {}),
|
|
},
|
|
});
|
|
if (res.status === 204) return undefined as T;
|
|
const text = await res.text();
|
|
const data = text ? JSON.parse(text) : undefined;
|
|
if (!res.ok) throw new ApiError(res.status, data);
|
|
return data as T;
|
|
}
|
|
|
|
export const api = {
|
|
health: () => request<{ status: string; db: boolean }>('/api/health'),
|
|
|
|
projects: {
|
|
list: (params?: { status?: 'open' | 'archived' }) =>
|
|
request<Project[]>(`/api/projects${params?.status ? `?status=${params.status}` : ''}`),
|
|
available: () => request<AvailableProject[]>('/api/projects/available'),
|
|
add: (body: { path: string; name?: string }) =>
|
|
request<Project>('/api/projects', {
|
|
method: 'POST',
|
|
body: JSON.stringify(body),
|
|
}),
|
|
update: (id: string, body: { name: string }) =>
|
|
request<Project>(`/api/projects/${id}`, {
|
|
method: 'PATCH',
|
|
body: JSON.stringify(body),
|
|
}),
|
|
archive: (id: string) =>
|
|
request<void>(`/api/projects/${id}/archive`, { method: 'POST' }),
|
|
unarchive: (id: string) =>
|
|
request<Project>(`/api/projects/${id}/unarchive`, { method: 'POST' }),
|
|
create: (body: {
|
|
name: string;
|
|
commit_message?: string;
|
|
visibility?: 'private' | 'public';
|
|
create_gitea_remote?: boolean;
|
|
}) =>
|
|
request<{
|
|
project: Project;
|
|
bootstrap: {
|
|
folder_created: boolean;
|
|
git_initialized: boolean;
|
|
first_commit: boolean;
|
|
gitea_remote_created: boolean;
|
|
gitea_pushed: boolean;
|
|
warnings: string[];
|
|
};
|
|
}>(`/api/projects/create`, {
|
|
method: 'POST',
|
|
body: JSON.stringify(body),
|
|
}),
|
|
remove: (id: string) =>
|
|
request<void>(`/api/projects/${id}`, { method: 'DELETE' }),
|
|
listDir: (id: string, path: string) =>
|
|
request<ListDirResult>(`/api/projects/${id}/list_dir?path=${encodeURIComponent(path)}`),
|
|
viewFile: (id: string, path: string) =>
|
|
request<ViewFileResult>(`/api/projects/${id}/view_file?path=${encodeURIComponent(path)}`),
|
|
files: (id: string) =>
|
|
request<{ files: string[] }>(`/api/projects/${id}/files`),
|
|
},
|
|
|
|
sessions: {
|
|
listForProject: (projectId: string, status?: 'open' | 'archived') =>
|
|
request<Session[]>(`/api/projects/${projectId}/sessions${status ? `?status=${status}` : ''}`),
|
|
create: (
|
|
projectId: string,
|
|
body: { name?: string; model?: string; system_prompt?: string }
|
|
) =>
|
|
request<Session>(`/api/projects/${projectId}/sessions`, {
|
|
method: 'POST',
|
|
body: JSON.stringify(body),
|
|
}),
|
|
get: (id: string) => request<Session>(`/api/sessions/${id}`),
|
|
update: (
|
|
id: string,
|
|
body: Partial<Pick<Session, 'name' | 'model' | 'system_prompt'>>
|
|
) =>
|
|
request<Session>(`/api/sessions/${id}`, {
|
|
method: 'PATCH',
|
|
body: JSON.stringify(body),
|
|
}),
|
|
remove: (id: string) =>
|
|
request<void>(`/api/sessions/${id}`, { method: 'DELETE' }),
|
|
archive: (id: string) =>
|
|
request<void>(`/api/sessions/${id}/archive`, { method: 'POST' }),
|
|
unarchive: (id: string) =>
|
|
request<Session>(`/api/sessions/${id}/unarchive`, { method: 'POST' }),
|
|
},
|
|
|
|
chats: {
|
|
listForSession: (sessionId: string, params?: { status?: 'open' | 'archived' }) =>
|
|
request<Chat[]>(
|
|
`/api/sessions/${sessionId}/chats${params?.status ? `?status=${params.status}` : ''}`
|
|
),
|
|
create: (sessionId: string, body?: { name?: string }) =>
|
|
request<Chat>(`/api/sessions/${sessionId}/chats`, {
|
|
method: 'POST',
|
|
body: JSON.stringify(body ?? {}),
|
|
}),
|
|
update: (chatId: string, body: { name: string }) =>
|
|
request<Chat>(`/api/chats/${chatId}`, {
|
|
method: 'PATCH',
|
|
body: JSON.stringify(body),
|
|
}),
|
|
archive: (chatId: string) =>
|
|
request<void>(`/api/chats/${chatId}/archive`, { method: 'POST' }),
|
|
unarchive: (chatId: string) =>
|
|
request<Chat>(`/api/chats/${chatId}/unarchive`, { method: 'POST' }),
|
|
remove: (chatId: string) =>
|
|
request<void>(`/api/chats/${chatId}`, { method: 'DELETE' }),
|
|
messages: (chatId: string) =>
|
|
request<Message[]>(`/api/chats/${chatId}/messages`),
|
|
compact: (chatId: string) =>
|
|
request<{ compact_message_id: string }>(`/api/chats/${chatId}/compact`, { method: 'POST' }),
|
|
stop: (chatId: string) =>
|
|
request<{ stopped: boolean }>(`/api/chats/${chatId}/stop`, { method: 'POST' }),
|
|
forceSend: (chatId: string, content: string) =>
|
|
request<{ user_message_id: string; assistant_message_id: string }>(
|
|
`/api/chats/${chatId}/force_send`,
|
|
{ method: 'POST', body: JSON.stringify({ content }) }
|
|
),
|
|
},
|
|
|
|
messages: {
|
|
list: (sessionId: string) =>
|
|
request<Message[]>(`/api/sessions/${sessionId}/messages`),
|
|
send: (chatId: string, content: string) =>
|
|
request<{ user_message_id: string; assistant_message_id: string }>(
|
|
`/api/chats/${chatId}/messages`,
|
|
{
|
|
method: 'POST',
|
|
body: JSON.stringify({ content }),
|
|
}
|
|
),
|
|
regenerate: (chatId: string, messageId: string) =>
|
|
request<{ assistant_message_id: string }>(
|
|
`/api/chats/${chatId}/messages/${messageId}/regenerate`,
|
|
{ method: 'POST' }
|
|
),
|
|
},
|
|
|
|
models: () => request<ModelInfo[]>('/api/models'),
|
|
|
|
settings: {
|
|
get: () => request<Record<string, unknown>>('/api/settings'),
|
|
patch: (body: Record<string, unknown>) =>
|
|
request<Record<string, unknown>>('/api/settings', {
|
|
method: 'PATCH',
|
|
body: JSON.stringify(body),
|
|
}),
|
|
},
|
|
|
|
sidebar: {
|
|
get: () => request<SidebarResponse>('/api/sidebar'),
|
|
},
|
|
};
|