The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): dragging a link from a browser attaches an @url chip
teknium12179a279ae04
diff --git a/apps/desktop/src/app/chat/composer/inline-refs.ts b/apps/desktop/src/app/chat/composer/inline-refs.tsindex a50d389e806..4d9eb69edf7 100644--- a/apps/desktop/src/app/chat/composer/inline-refs.ts+++ b/apps/desktop/src/app/chat/composer/inline-refs.ts@@ -38,11 +38,15 @@ export function dragHasAttachments(transfer: DataTransfer | null, pathsMime: strreturn false}- if (Array.from(transfer.types || []).includes(pathsMime)) {+ const types = Array.from(transfer.types || [])++ // A browser link drag carries `text/uri-list` (on Windows also a virtual+ // shortcut File); accept it so the link lands as an `@url:` chip.+ if (types.includes(pathsMime) || types.includes('text/uri-list')) {return true}- if (Array.from(transfer.types || []).includes('Files')) {+ if (types.includes('Files')) {return true}@@ -50,6 +54,10 @@ export function dragHasAttachments(transfer: DataTransfer | null, pathsMime: str}export function droppedFileInlineRef(candidate: DroppedFile, cwd: string | null | undefined) {+ if (candidate.url) {+ return `@url:${formatRefValue(candidate.url)}`+ }+if (!candidate.path) {return null}diff --git a/apps/desktop/src/app/chat/hooks/use-composer-actions.test.ts b/apps/desktop/src/app/chat/hooks/use-composer-actions.test.tsindex ce1c2df44c6..f34d041df01 100644--- a/apps/desktop/src/app/chat/hooks/use-composer-actions.test.ts+++ b/apps/desktop/src/app/chat/hooks/use-composer-actions.test.ts@@ -4,6 +4,8 @@ import { afterEach, describe, expect, it, vi } from 'vitest'import { $composerAttachments, type ComposerAttachment, updateComposerAttachment } from '@/store/composer'import { $connection } from '@/store/session'+import { droppedFileInlineRefs } from '../composer/inline-refs'+import {attachmentPreviewDataUrl,type DroppedFile,@@ -87,9 +89,14 @@ interface StubEntry {isDirectory: boolean}-function stubTransfer(entries: StubEntry[], internalRaw = ''): DataTransfer & { _pathByFile: Map<File, string> } {+function stubTransfer(+ entries: StubEntry[],+ internalRaw = '',+ uriList = ''+): DataTransfer & { _pathByFile: Map<File, string> } {const files = entries.map(entry => new File(['x'], entry.path.split('/').pop() || 'f'))- const pathByFile = new Map(files.map((file, i) => [file, entries[i].path]))+ // A virtual shortcut File (browser link drag on Windows) has a name but no path.+ const pathByFile = new Map(files.map((file, i) => [file, entries[i].path.includes('/') ? entries[i].path : '']))const items: Record<number | string, unknown> = { length: entries.length }entries.forEach((entry, i) => {@@ -101,7 +108,7 @@ function stubTransfer(entries: StubEntry[], internalRaw = ''): DataTransfer & {})return {- getData: (mime: string) => (mime === HERMES_PATHS_MIME ? internalRaw : ''),+ getData: (mime: string) => (mime === HERMES_PATHS_MIME ? internalRaw : mime === 'text/uri-list' ? uriList : ''),files: {length: files.length,item: (i: number) => files[i] ?? null@@ -174,6 +181,41 @@ describe('extractDroppedFiles', () => {expect(osDrops.map(entry => entry.path)).toEqual(['/abs/notes.txt'])})+ it('turns a browser link drag into an @url chip instead of failing on the virtual .url stub', () => {+ // Dragging a link out of a browser on Windows lands as `text/uri-list` plus a+ // path-less `<title>.url` shortcut File. That stub used to reach the upload+ // pipeline and toast "Could not attach agent-wiki.url".+ const transfer = stubTransfer(+ [{ path: 'agent-wiki.url', isDirectory: false }],+ '',+ 'https://example.com/wiki/agent?x=1\r\n'+ ) as DataTransfer & { _pathByFile: Map<File, string> }++ stubBridge(transfer)++ const result = extractDroppedFiles(transfer)++ expect(result).toEqual([{ path: '', url: 'https://example.com/wiki/agent?x=1' }])+ expect(partitionDroppedFiles(result).osDrops).toEqual([])+ expect(droppedFileInlineRefs(result, '/w')).toEqual(['@url:https://example.com/wiki/agent?x=1'])+ })++ it('keeps a path-less image dragged off a web page as an upload, not a link chip', () => {+ const transfer = stubTransfer(+ [{ path: 'logo.png', isDirectory: false }],+ '',+ 'https://example.com/logo.png'+ ) as DataTransfer & { _pathByFile: Map<File, string> }++ stubBridge(transfer)++ const result = extractDroppedFiles(transfer)++ expect(result).toHaveLength(1)+ expect(result[0]?.file).toBeInstanceOf(File)+ expect(result[0]?.url).toBeUndefined()+ })+it('does not duplicate a folder that appears in both items and files', () => {// Chromium lists a dropped folder in transfer.files too (as a size-0 File);// the items pass claims its path first so the files fallback skips it.diff --git a/apps/desktop/src/app/chat/hooks/use-composer-actions.ts b/apps/desktop/src/app/chat/hooks/use-composer-actions.tsindex c964c515530..157c2082eaf 100644--- a/apps/desktop/src/app/chat/hooks/use-composer-actions.ts+++ b/apps/desktop/src/app/chat/hooks/use-composer-actions.ts@@ -90,6 +90,8 @@ export interface DroppedFile {line?: number/** Last line number for line-range drags (`line..lineEnd` inclusive). */lineEnd?: number+ /** A link dragged out of a browser (`text/uri-list`). Path-less; becomes an `@url:` chip. */+ url?: string}/** MIME emitted by in-app drag sources (project tree, gutter line numbers).@@ -110,6 +112,7 @@ export function extractDroppedFiles(transfer: DataTransfer): DroppedFile[] {const seenPaths = new Set<string>()const seenFiles = new Set<File>()const getPath = window.hermesDesktop?.getPathForFile+ const urls = droppedLinkUrls(transfer)// In-app drags first — they carry richer metadata (isDirectory) than the// File-based fallback can provide, and produce no overlapping native files.@@ -169,6 +172,20 @@ export function extractDroppedFiles(transfer: DataTransfer): DroppedFile[] {}}+ // A link dragged out of a browser rides along as a virtual shortcut File+ // (`<title>.url` on Windows, `.webloc` on macOS) with no on-disk path. It+ // is the same link `text/uri-list` already carries, so drop the stub and+ // let the URL become a chip instead of toasting "Could not attach X.url".+ // A path-less *image* (dragged off a web page) keeps its bytes and wins+ // over the link to its own src.+ if (!path && urls.length) {+ if (isImagePath(file.name) || file.type.startsWith('image/')) {+ urls.length = 0+ } else {+ return+ }+ }+if (path && seenPaths.has(path)) {return}@@ -238,9 +255,37 @@ export function extractDroppedFiles(transfer: DataTransfer): DroppedFile[] {}}+ for (const url of urls) {+ result.push({ path: '', url })+ }+return result}+/** `http(s)` links from a `text/uri-list` payload (one per line, `#` comments+ * skipped), deduped. Empty when the drag carried none. */+function droppedLinkUrls(transfer: DataTransfer): string[] {+ let raw = ''++ try {+ raw = transfer.getData('text/uri-list') || ''+ } catch {+ return []+ }++ const urls: string[] = []++ for (const line of raw.split(/\r?\n/)) {+ const url = line.trim()++ if (/^https?:\/\/[^/\s]/i.test(url) && !urls.includes(url)) {+ urls.push(url)+ }+ }++ return urls+}+/*** Split dropped entries by origin. OS/Finder drops carry a native `File`* handle; in-app drags (project tree, gutter line refs) are path-only.