Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
chat: a PDF is added to the chat folder and named in the next message; the file dialog lists PDFs and text on Linux (#3838)
Niko1221353c9f2556d3
diff --git a/apps/host/src/components/ComposerControls.tsx b/apps/host/src/components/ComposerControls.tsxindex 4dab29925..7156199b0 100644--- a/apps/host/src/components/ComposerControls.tsx+++ b/apps/host/src/components/ComposerControls.tsx@@ -5,10 +5,11 @@ import { FloatingMenu } from './FloatingMenu';import { DictationControl } from './DictationControl';import { Btn, Dialog, Icon, ErrorNotice } from './ui';import { MOD } from '../lib/commands';-import { setChatPreferences, useStore } from '../lib/store';+import { pushToast, setChatPreferences, useStore } from '../lib/store';import { artifactFromUrl, type PreviewArtifact } from '../lib/artifacts';import type { ChatMode, Session } from '../lib/types';import { attachChatPhoto } from '../lib/chat-photos';+import { uploadChatFile, FILE_ACCEPT } from '../lib/chat-attach-file';import { useNative } from '../lib/native';import { pictureStatus } from '../lib/pictures';const modes: {@@ -91,6 +92,12 @@ export function ComposerControls({ session, onPreview, onAttach, onError, onSlasawait attachChatPhoto(file, session?.id);continue;}+ if (!directory && session?.id && /\.pdf$/i.test(file.name) && file.size <= 12 * 1024 * 1024) {+ // A PDF goes to the chat's folder and is named in the next message; "Open a file" still previews it.+ const saved = await uploadChatFile(file, session.id);+ pushToast('success', 'PDF added', `${saved.name} is in this chat. Ask about it in your next message.`);+ continue;+ }if (!directory && (photoTypes.test(file.name) || /\.pdf$/i.test(file.name))) {await openFile(file);if (photoTypes.test(file.name))@@ -157,7 +164,7 @@ export function ComposerControls({ session, onPreview, onAttach, onError, onSlasreturn <>{tr(!remoteModel && nativeModel?.metrics?.mcp?.servers?.length ? <button className="composer-choice" aria-label={tr("Use connected MCP tools")} aria-pressed={session?.preferences?.useTools === true} onClick={() => session?.preferences?.useTools ? setChatPreferences(session.id, { useTools: false }) : setToolsOpen(true)}><Icon name="skills" size={16}/>{tr("Tools")}{tr(session?.preferences?.useTools ? ' on' : '')}</button> : null)}<Dialog open={toolsOpen} compact title={tr("Enable connected tools?")} onClose={() => setToolsOpen(false)} actions={<><Btn onClick={() => setToolsOpen(false)}>{tr("Keep tools off")}</Btn><Btn variant="primary" onClick={() => { setChatPreferences(session?.id, { useTools: true, mode: 'bypass' }); setToolsOpen(false); }}>{tr("Enable tools")}</Btn></>}><p>{tr("Connected servers can act on the resources you configured. Calls run automatically when the model chooses them, and their results appear in chat.")}</p><p className="small muted">{tr("This switches this conversation to Bypass permissions. Servers: ")}{tr((nativeModel?.metrics?.mcp?.servers ?? []).map((s: any) => s.name).join(', '))}.</p></Dialog>- <input ref={files} type="file" multiple hidden accept="image/*,.pdf,.txt,.md,.markdown,.csv,.ts,.tsx,.js,.jsx,.py,.json,.css,.rs,.go,.sh,.html,.htm,.yaml,.yml,.toml,.xml,.log" onChange={e => { void addFiles(Array.from(e.target.files ?? [])); e.target.value = ''; }}/>+ <input ref={files} type="file" multiple hidden accept={FILE_ACCEPT} onChange={e => { void addFiles(Array.from(e.target.files ?? [])); e.target.value = ''; }}/><input ref={folder} type="file" multiple hidden onChange={e => { void addFiles(Array.from(e.target.files ?? []), true); e.target.value = ''; }}/><input ref={previewFile} type="file" hidden onChange={e => { void openFile(e.target.files?.[0]); e.target.value = ''; }}/><button ref={trigger} className="composer-add" aria-label={tr("Add or open")} title={tr("Add or open")} disabled={reading || streaming} aria-haspopup="menu" aria-expanded={menu} onClick={() => { setPreferences(null); setMenu(v => !v); }}><Icon name="plus" size={22}/></button>diff --git a/apps/host/src/lib/chat-attach-file.ts b/apps/host/src/lib/chat-attach-file.tsnew file mode 100644index 000000000..e3e24d791--- /dev/null+++ b/apps/host/src/lib/chat-attach-file.ts@@ -0,0 +1,11 @@+/** 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). */+export async function uploadChatFile(file: File, sessionId: string, fetchFn: typeof fetch = fetch): Promise<{ name: string }> {+ const host = (globalThis as { __STRATA_HOST__?: string }).__STRATA_HOST__ ?? '';+ 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 });+ const data = await res.json().catch(() => ({})) as { files?: { name: string; attached?: boolean }[]; error?: string };+ if (!res.ok) throw new Error(data.error || 'The file could not be added. Try again.');+ return { name: data.files?.find(f => f.attached)?.name ?? file.name };+}++/** Types the Linux file dialog needs next to the extensions (WebKitGTK reads only the type part of `accept`). */+export 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';diff --git a/apps/host/tests/chat-attach-file.test.mjs b/apps/host/tests/chat-attach-file.test.mjsnew file mode 100644index 000000000..3a8af9cba--- /dev/null+++ b/apps/host/tests/chat-attach-file.test.mjs@@ -0,0 +1,22 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import { readFile } from 'node:fs/promises';+import { transform } from 'esbuild';++const { code } = await transform(await readFile(new URL('../src/lib/chat-attach-file.ts', import.meta.url), 'utf8'), { loader: 'ts', format: 'esm' });+const { uploadChatFile, FILE_ACCEPT } = await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);++test('the file dialog lists PDFs and text on Linux: the types sit next to the extensions (#3838)', () => {+ for (const t of ['image/*', 'application/pdf', 'text/*', '.pdf', '.md']) assert.ok(FILE_ACCEPT.split(',').includes(t), t);+});+test('a PDF is sent to the chat folder through the upload route and named back', async () => {+ let seen;+ const fake = async (url, init) => { seen = { url, init }; return { ok: true, json: async () => ({ files: [{ name: 'report-2.pdf', attached: true }] }) }; };+ const out = await uploadChatFile(new File(['%PDF-1.4'], 'report.pdf', { type: 'application/pdf' }), 's 1', fake);+ assert.equal(out.name, 'report-2.pdf');+ assert.match(seen.url, /\/api\/chat\/upload\?sessionId=s%201&name=report\.pdf$/);+ assert.equal(seen.init.method, 'POST'); assert.equal(seen.init.headers['content-type'], 'application/pdf');+});+test('a refused upload says why', async () => {+ await assert.rejects(uploadChatFile(new File(['x'], 'a.pdf'), 's', async () => ({ ok: false, json: async () => ({ error: '"a.pdf" is bigger than 12 MB.' }) })), /bigger than 12 MB/);+});