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

+10 -6
View File
@@ -1,9 +1,10 @@
import type { SessionMention } from "./types";
import { isLocalAttachment, type LocalAttachment } from "../../../packages/client-events/attachments";
/** Files stay in memory, including unfinished attachments. */
/** Ordered attachments retain browser Files in memory and persist local references. */
export interface ComposerDraft {
text: string;
files: File[];
attachments: Array<File | LocalAttachment>;
sessionMentions: SessionMention[];
quotedContext: string | null;
}
@@ -34,7 +35,9 @@ function readDraft(raw: string): ComposerDraft | undefined {
? { id: item.id } : {}),
}];
});
return { text: value.text, quotedContext: value.quotedContext, sessionMentions, files: [] };
const rawAttachments = Array.isArray(value.attachments) ? value.attachments : value.localAttachments;
const attachments = Array.isArray(rawAttachments) ? rawAttachments.filter(isLocalAttachment) : [];
return { text: value.text, quotedContext: value.quotedContext, sessionMentions, attachments };
}
function removeStoredDraft(key: string): void {
@@ -69,14 +72,14 @@ export class ComposerDraftStore extends Map<string, ComposerDraft> {
const unchanged = previous
&& previous.text === draft.text
&& previous.quotedContext === draft.quotedContext
&& previous.files.length === draft.files.length
&& previous.files.every((file, index) => file === draft.files[index])
&& previous.attachments.length === draft.attachments.length
&& previous.attachments.every((attachment, index) => attachment === draft.attachments[index])
&& previous.sessionMentions.length === draft.sessionMentions.length
&& previous.sessionMentions.every((mention, index) => mention === draft.sessionMentions[index]);
// Restoring a composer is not an edit. Pending sends retain this identity across mounts.
super.set(key, unchanged ? previous : draft);
if (!persist) return this;
if (!draft.text && !draft.quotedContext) {
if (!draft.text && !draft.quotedContext && !draft.attachments.some(isLocalAttachment)) {
removeStoredDraft(key);
return this;
}
@@ -85,6 +88,7 @@ export class ComposerDraftStore extends Map<string, ComposerDraft> {
text: draft.text,
quotedContext: draft.quotedContext,
sessionMentions: draft.sessionMentions,
attachments: draft.attachments.filter(isLocalAttachment),
});
if (raw.length <= MAX_STORED_CHARS) localStorage.setItem(STORAGE_PREFIX + key, raw);
else removeStoredDraft(key);
+5 -7
View File
@@ -1488,11 +1488,12 @@ export type InboundEvent =
event: "message_accepted";
chat_id: string;
turn_id: string;
media_urls?: UIMediaAttachment[];
starts_turn?: boolean;
active_turn_id?: string;
started_at?: number;
}
| {
| ({
event: "user_message";
chat_id: string;
text: string;
@@ -1506,14 +1507,14 @@ export type InboundEvent =
mcp_presets?: UIMcpPresetAttachment[];
session_mentions?: SessionMention[];
provenance?: { session_message?: UISessionMessage };
}
} & InboundTurnMetadata)
| ({
event: "message";
chat_id: string;
text: string;
reply_to?: string;
media?: string[];
media_urls?: Array<{ url: string; name?: string }>;
media_urls?: Array<{ url: string; name?: string; kind?: UIMediaKind }>;
tool_events?: ToolProgressEvent[];
/** Oversized persisted activity detail, fetched only when the trace is expanded. */
trace_detail?: UITraceDetail;
@@ -1677,10 +1678,7 @@ export type ThreadProjectionEvent = Extract<
* surface. ``name`` is advisory and is surfaced as the placeholder label when
* the session is replayed.
*/
export interface OutboundMedia {
data_url: string;
name?: string;
}
export type OutboundMedia = import("../../../packages/client-events/attachments").DraftAttachment;
export interface OutboundCliAppMention {
name: string;