okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-0243-guifix into f-0243-rel9caf39495

main
1.2 KiB11 linesraw
1/** A file that is not a picture or plain text (a PDF) is saved by the host in the chat's folder and named in the next message, so the assistant can open it (#3838). */
2export async function uploadChatFile(file: File, sessionId: string, fetchFn: typeof fetch = fetch): Promise<{ name: string }> {
3  const host = (globalThis as { __STRATA_HOST__?: string }).__STRATA_HOST__ ?? '';
4  const res = await fetchFn(`${host}/api/chat/upload?sessionId=${encodeURIComponent(sessionId)}&name=${encodeURIComponent(file.name)}`, { method: 'POST', headers: { 'content-type': file.type || 'application/octet-stream' }, body: file });
5  const data = await res.json().catch(() => ({})) as { files?: { name: string; attached?: boolean }[]; error?: string };
6  if (!res.ok) throw new Error(data.error || 'The file could not be added. Try again.');
7  return { name: data.files?.find(f => f.attached)?.name ?? file.name };
8}
9
10/** Types the Linux file dialog needs next to the extensions (WebKitGTK reads only the type part of `accept`). */
11export const FILE_ACCEPT = 'image/*,application/pdf,text/*,application/json,application/xml,.pdf,.txt,.md,.markdown,.csv,.ts,.tsx,.js,.jsx,.py,.json,.css,.rs,.go,.sh,.html,.htm,.yaml,.yml,.toml,.xml,.log';