Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

feat(ui): paste files into the composer to upload them (#540)

Call Whitecd4cc71542f1
diff --git a/ui/src/components/workbench/Composer.tsx b/ui/src/components/workbench/Composer.tsx
index ebd0ee7cc..c4d4ca973 100644
--- a/ui/src/components/workbench/Composer.tsx
+++ b/ui/src/components/workbench/Composer.tsx
@@ -563,6 +563,10 @@ export const Composer = forwardRef<ComposerHandle, ComposerProps>(function Compo
initialText={initialDraft}
onSearchAgents={onSearchAgents!}
onSearchSessions={onSearchSessions!}
+ // Paste-to-upload: only when this composer has an upload target
+ // (a session), mirroring the picker + drag-drop. uploadFiles itself
+ // no-ops without a session, so this gate is also defense in depth.
+ onPasteFiles={mediaEnabled ? (files) => void uploadFiles(files) : undefined}
onChange={(text, references) => {
setValue(text);
referencesRef.current = references;
diff --git a/ui/src/components/workbench/MentionEditor.tsx b/ui/src/components/workbench/MentionEditor.tsx
index 7f1914291..83709276a 100644
--- a/ui/src/components/workbench/MentionEditor.tsx
+++ b/ui/src/components/workbench/MentionEditor.tsx
@@ -22,6 +22,7 @@ import {
$isTextNode,
COMMAND_PRIORITY_HIGH,
KEY_ENTER_COMMAND,
+ PASTE_COMMAND,
type EditorState,
type LexicalNode,
} from 'lexical';
@@ -34,6 +35,7 @@ import {
type BeautifulMentionsMenuItemProps,
} from 'lexical-beautiful-mentions';
+import { filesFromClipboard } from '../../lib/clipboardFiles';
import { isSoftKeyboardOpen, isTouchCapableDevice } from '../../lib/softKeyboard';
import { cn } from '../../lib/utils';
import { dedupeReferences, type MentionReference } from '../../lib/mentions';
@@ -66,6 +68,10 @@ export interface MentionEditorProps {
onSubmit: () => void;
onSearchAgents: (query: string) => Promise<AgentSearchResult[]>;
onSearchSessions: (query: string) => Promise<SessionSearchResult[]>;
+ /** Pasting a file into the editor (clipboard screenshot or OS-copied file)
+ * hands it here instead of pasting as text. Unset → paste behaves as plain
+ * text (e.g. when the composer has no upload target). */
+ onPasteFiles?: (files: File[]) => void;
}
// Per-trigger chip classes — styled in index.css to read like a Badge
@@ -165,6 +171,41 @@ function EditablePlugin({ disabled }: { disabled: boolean }) {
return null;
}
+// Intercept a paste that carries files (a clipboard screenshot, or a file copied
+// in the OS file manager) and hand it to the composer's uploader instead of
+// letting Lexical insert it as text — the editor sibling of the `+` picker and
+// chat-page drag-drop. Registered at HIGH priority so it runs before Lexical's
+// own (LOW/EDITOR) paste handling: a files paste is consumed here (return true),
+// while a plain text / rich-text paste carries no files and falls through
+// (return false) to normal text pasting. Reads the callback through a ref so the
+// command registers once per editor and never churns on the composer's renders.
+function PasteFilesPlugin({ onPasteFiles }: { onPasteFiles?: (files: File[]) => void }) {
+ const [editor] = useLexicalComposerContext();
+ const handlerRef = useRef(onPasteFiles);
+ handlerRef.current = onPasteFiles;
+ useEffect(
+ () =>
+ editor.registerCommand(
+ PASTE_COMMAND,
+ (event) => {
+ const handler = handlerRef.current;
+ if (!handler) return false;
+ // PASTE_COMMAND can also fire for non-clipboard (input/keyboard) paste
+ // triggers; only a ClipboardEvent carries files.
+ const clipboardData = event instanceof ClipboardEvent ? event.clipboardData : null;
+ const files = filesFromClipboard(clipboardData);
+ if (files.length === 0) return false;
+ event.preventDefault();
+ handler(files);
+ return true;
+ },
+ COMMAND_PRIORITY_HIGH,
+ ),
+ [editor],
+ );
+ return null;
+}
+
function BootstrapPlugin({
autoFocus,
initialText,
@@ -325,6 +366,7 @@ export const MentionEditor = forwardRef<MentionEditorHandle, MentionEditorProps>
onSubmit,
onSearchAgents,
onSearchSessions,
+ onPasteFiles,
},
ref,
) {
@@ -418,6 +460,7 @@ export const MentionEditor = forwardRef<MentionEditorHandle, MentionEditorProps>
/>
<EnterSubmitPlugin onSubmit={onSubmit} menuOpenRef={menuOpenRef} />
<EditablePlugin disabled={disabled} />
+ <PasteFilesPlugin onPasteFiles={onPasteFiles} />
<BootstrapPlugin autoFocus={autoFocus} initialText={initialText} bridgeRef={ref} />
<MentionCaretFixPlugin />
</LexicalComposer>
diff --git a/ui/src/lib/clipboardFiles.ts b/ui/src/lib/clipboardFiles.ts
new file mode 100644
index 000000000..ceba4aa9f
--- /dev/null
+++ b/ui/src/lib/clipboardFiles.ts
@@ -0,0 +1,28 @@
+// Pull file blobs out of a clipboard paste, shared by every composer input that
+// supports paste-to-upload. A pasted screenshot rides in ``items`` as a ``file``
+// entry (and usually in ``files`` too); a file copied in the OS file manager
+// lands in ``files`` directly. A plain text / rich-text paste carries no files
+// and returns ``[]`` so the editor handles it as normal text.
+//
+// Pasted screenshots can arrive without a filename, so synthesize a readable,
+// collision-free one: the timestamp separates one paste from the next, the index
+// separates files staged within the same paste (same millisecond). The upload
+// path keys files by their unique on-disk path, so the synthesized name is only
+// ever a display label.
+export function filesFromClipboard(data: DataTransfer | null): File[] {
+ if (!data) return [];
+ const direct = Array.from(data.files ?? []);
+ const files =
+ direct.length > 0
+ ? direct
+ : Array.from(data.items ?? [])
+ .filter((it) => it.kind === 'file')
+ .map((it) => it.getAsFile())
+ .filter((f): f is File => f != null);
+ return files.map((file, i) => {
+ if (file.name) return file;
+ const ext = file.type.split('/')[1] || 'dat';
+ const base = file.type.startsWith('image/') ? 'pasted-image' : 'pasted-file';
+ return new File([file], `${base}-${Date.now().toString(36)}-${i}.${ext}`, { type: file.type });
+ });
+}