Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
fix(desktop): attach copied files and images pasted into the message box
leepokai6dcee39da4e4
diff --git a/apps/desktop/src/main/files.ts b/apps/desktop/src/main/files.tsindex 8a76e48b..0a9647d7 100644--- a/apps/desktop/src/main/files.ts+++ b/apps/desktop/src/main/files.ts@@ -13,7 +13,8 @@ export async function readFiles(paths: string[]) {return out}-const fileURLFormat = process.platform === 'darwin' ? 'electron application/osclipboard;format="public.file-url"' : 'text/uri-list'+// Copied files on every platform (macOS's `public.file-url` included): `clipboard.read()` never lists the raw type.+const fileURLFormat = 'text/uri-list'/** ⌘V with a copied file or image: the files it holds (the text field alone would paste a name). */export async function readClipboardFiles() {diff --git a/apps/desktop/src/renderer/views/thread/Composer.tsx b/apps/desktop/src/renderer/views/thread/Composer.tsxindex 1af21540..b3280971 100644--- a/apps/desktop/src/renderer/views/thread/Composer.tsx+++ b/apps/desktop/src/renderer/views/thread/Composer.tsx@@ -15,6 +15,7 @@ import { useTr } from '../../lib/use-language'import { useStore } from '../../store/context'import { MAX_FILE_SIZE, type OutgoingFile } from '../../store/bot-store'import { pluginsFor } from '../marketplace/plugins'+import { pastedFiles, readPicked, type PickedFile } from './composer-files'import { composerEnter } from './composer-keyboard'import { CommandMenu, useCommandMenu } from './CommandMenu'import { ComposerAttachment } from './ComposerAttachment'@@ -151,7 +152,7 @@ function DestinationComposer({ botId, reply, about, cancelReply, onCall, onInter}const menu = useCommandMenu(draft, commands, run)- const append = (incoming: { name: string; data: Uint8Array }[]) => {+ const append = (incoming: PickedFile[]) => {if (!canAttach) returnconst accepted: OutgoingFile[] = []for (const f of incoming) {@@ -208,7 +209,7 @@ function DestinationComposer({ botId, reply, about, cancelReply, onCall, onInteronDrop={(e) => {if (!canAttach) returne.preventDefault()- void Promise.all([...e.dataTransfer.files].map(async (f) => ({ name: f.name, data: new Uint8Array(await f.arrayBuffer()) }))).then(append)+ void readPicked([...e.dataTransfer.files]).then(append)}}><div className="composer-surface">@@ -276,10 +277,7 @@ function DestinationComposer({ botId, reply, about, cancelReply, onCall, onInterif (!canAttach) returnif (!hasFiles || (types.includes('text/plain') && !e.clipboardData.files.length)) returne.preventDefault()- void window.codync.app.readClipboardFiles().then((picked) => {- if (picked.length) return append(picked)- return Promise.all([...e.clipboardData.files].map(async (f) => ({ name: f.name || `pasted-${Date.now()}.png`, data: new Uint8Array(await f.arrayBuffer()) }))).then(append)- })+ void pastedFiles(window.codync.app.readClipboardFiles, [...e.clipboardData.files]).then(append)}}/></div>diff --git a/apps/desktop/src/renderer/views/thread/composer-files.test.ts b/apps/desktop/src/renderer/views/thread/composer-files.test.tsnew file mode 100644index 00000000..597df3ad--- /dev/null+++ b/apps/desktop/src/renderer/views/thread/composer-files.test.ts@@ -0,0 +1,25 @@+import assert from 'node:assert/strict'+import { test } from 'node:test'+import { pastedFiles, readPicked } from './composer-files.ts'++const png = new File([new Uint8Array([1, 2, 3])], 'shot.png', { type: 'image/png' })+const folder = { name: 'folder', arrayBuffer: () => Promise.reject(new Error('NotFoundError')) } as unknown as File++test('a paste the computer reads keeps its own names and contents', async () => {+ const own = [{ name: 'report.pdf', data: new Uint8Array([9]) }]+ assert.deepEqual(await pastedFiles(async () => own, [png]), own)+})++test('a paste the computer finds nothing in, or fails to read, attaches the files the event held', async () => {+ for (const fromComputer of [async () => [], () => Promise.reject(new Error('clipboard'))]) {+ const files = await pastedFiles(fromComputer, [png])+ assert.deepEqual(files.map((f) => [f.name, [...f.data]]), [['shot.png', [1, 2, 3]]])+ }+})++test('an unreadable item (a folder) is left out and an unnamed image gets a name', async () => {+ const unnamed = new File([new Uint8Array([4])], '', { type: 'image/png' })+ const files = await readPicked([folder, unnamed])+ assert.equal(files.length, 1)+ assert.match(files[0].name, /^pasted-\d+\.png$/)+})diff --git a/apps/desktop/src/renderer/views/thread/composer-files.ts b/apps/desktop/src/renderer/views/thread/composer-files.tsnew file mode 100644index 00000000..6ad85d1b--- /dev/null+++ b/apps/desktop/src/renderer/views/thread/composer-files.ts@@ -0,0 +1,19 @@+/** A dropped, pasted or picked file, read for the draft. */+export type PickedFile = { name: string; data: Uint8Array }++/** The files' contents; one that can't be read (a copied folder) is left out instead of failing the rest. */+export async function readPicked(files: File[]): Promise<PickedFile[]> {+ const read = await Promise.all(+ files.map((f) => f.arrayBuffer().then((b) => ({ name: f.name || `pasted-${Date.now()}.png`, data: new Uint8Array(b) }), () => null)),+ )+ return read.filter((f) => f !== null)+}++/**+ * ⌘V with files: the computer's own clipboard (real names and contents) when it has them, else the files the+ * paste event held. `held` must be taken while the event runs: its clipboard data is empty once it ends.+ */+export async function pastedFiles(fromComputer: () => Promise<PickedFile[]>, held: File[]): Promise<PickedFile[]> {+ const picked = await fromComputer().catch(() => [])+ return picked.length ? picked : readPicked(held)+}