feat(attachments): support local files and video attachments (#6321)

* feat(attachments): support local files and video attachments

Share gateway inspection and send validation for borrowed local paths while preserving binary uploads, original-file ownership, and existing limits.

Related to NAN-284. Native provider video input remains outside this change.

* test: make cross-platform verification fixtures self-contained

* test(webui): align typed fixtures with runtime contracts

* fix(webui): preserve uploaded video playback during history sync

* test(tui): preserve local attachment drafts across resizes

* perf(attachments): preserve upload caches and release video previews

* docs(webui): keep attachment guidance user-focused

* chore: remove redundant dependency comment

* test(providers): make stream idle renewal timing deterministic

* fix(attachments): keep upload byte limits out of local references

Validate common format/count rules separately from upload byte budgets. Keep local inspection and send-time checks metadata-only, and exclude local references from composer and pending-upload totals. Explain upload size rejections with actual size and maximum in all ten locales. Related to NAN-284.

* fix(attachments): retain image references and draft order

* fix(attachments): close local reference UX and authorization gaps

* fix(attachments): preserve focus during asynchronous path confirmation
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-22 18:32:18 +08:00
1 parent 7dfeff9ddf
commit 254f94b068
65 files changed
+1816 -292

No files matched your search

+18 -3
View File
@@ -1,4 +1,5 @@
import type { OutboundMedia } from "../client"
import type { LocalAttachment } from "../../../packages/client-events/attachments"
const LARGE_PASTE_CHARS = 1_000
const LARGE_PASTE_LINES = 10
@@ -31,7 +32,7 @@ interface DraftImage {
/** Keeps large pasted text and image payloads out of the editable composer surface. */
export class ComposerDraft {
private readonly pastes = new Map<string, string>()
private readonly images = new Map<string, OutboundMedia>()
private readonly images = new Map<string, OutboundMedia & { kind: LocalAttachment["kind"] }>()
get imageCount(): number {
return this.images.size
@@ -67,16 +68,30 @@ export class ComposerDraft {
}
image(image: DraftImage, visible = ""): PasteInsertion | null {
if (this.images.size >= MAX_DRAFT_IMAGES) return null
if ([...this.images.values()].filter((item) => item.kind !== "video").length >= MAX_DRAFT_IMAGES) return null
const index = this.nextImageIndex(visible)
const label = `[Image #${index}]`
this.images.set(label, {
kind: "image",
data_url: image.dataUrl,
name: `clipboard-image-${index}.${IMAGE_EXTENSIONS[image.mimeType]}`,
})
return { text: `${label} `, compacted: true, description: label.slice(1, -1) }
}
localFile(file: LocalAttachment, visible = ""): PasteInsertion | null {
const current = [...this.images.values()]
if (file.kind === "video"
? current.some((item) => item.kind === "video")
: current.filter((item) => item.kind !== "video").length >= MAX_DRAFT_IMAGES) return null
const prefix = file.kind === "video" ? "Video" : file.kind === "image" ? "Image" : "File"
let index = 1
let label = `[${prefix} #${index}: ${file.name}]`
while (this.imageLabelInUse(label, visible)) label = `[${prefix} #${++index}: ${file.name}]`
this.images.set(label, { kind: file.kind, path: file.path, name: file.name })
return { text: `${label} `, compacted: true, description: label.slice(1, -1) }
}
private expandPastes(visible: string): string {
let expanded = visible
for (const [label, content] of this.pastes) expanded = expanded.split(label).join(content)
@@ -180,7 +195,7 @@ export class ComposerDraft {
return [...this.images]
.filter(([label]) => visible.includes(label))
.sort(([left], [right]) => visible.indexOf(left) - visible.indexOf(right))
.map(([, media]) => media)
.map(([, { kind: _kind, ...media }]) => media)
}
prune(visible: string): void {