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

+40
View File
@@ -1049,6 +1049,23 @@ describe("MessageBubble", () => {
expect(content.querySelectorAll("li")).toHaveLength(1000);
});
it("retries a failed video locally without replacing a healthy player on history updates", () => {
const message: UIMessage = { id: "retry-video", role: "user", content: "watch", createdAt: 0,
media: [{ kind: "video", name: "clip.webm", url: "/api/media/sig/clip" }] };
const { container, rerender } = render(<MessageBubble message={message} />);
const original = container.querySelector("video")!;
fireEvent.error(original);
expect(container.querySelector("video")).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Retry" }));
const retried = container.querySelector("video")!;
expect(retried).toHaveAttribute("src", "/api/media/sig/clip");
expect(retried).not.toBe(original);
rerender(<MessageBubble message={{ ...message, media: [...message.media!] }} />);
expect(container.querySelector("video")).toBe(retried);
fireEvent.error(retried);
expect(screen.getByRole("button", { name: "Retry" })).toBeVisible();
});
it("renders video media as an inline player", () => {
const message: UIMessage = {
id: "a1",
@@ -1076,6 +1093,29 @@ describe("MessageBubble", () => {
expect(screen.queryByText("Code")).not.toBeInTheDocument();
});
it("starts an uploaded player from its accepted URL and preserves it through hydration", () => {
const message: UIMessage = {
id: "optimistic-user", role: "user", content: "Watch this", createdAt: 1,
turnId: "video-turn", turnPhase: "user", deliveryStatus: "sending",
media: [{ kind: "video", name: "clip.webm" }],
};
const accepted: UIMessage = {
...message, deliveryStatus: "accepted",
media: [{ kind: "video", name: "clip.webm", url: "/api/media/sig/clip" }],
};
const { rerender, unmount } = render(<ThreadMessages messages={[message]} />);
expect(screen.queryByLabelText(/video attachment/i)?.tagName).not.toBe("VIDEO");
expect(screen.queryByText(/attachment unavailable/i)).not.toBeInTheDocument();
rerender(<ThreadMessages messages={[accepted]} />);
const video = screen.getByLabelText(/video attachment/i);
rerender(<ThreadMessages messages={[{ ...accepted, id: "history-user" }]} />);
expect(screen.getByLabelText(/video attachment/i)).toBe(video);
expect(video).toHaveAttribute("src", "/api/media/sig/clip");
unmount();
render(<ThreadMessages messages={[accepted]} />);
expect(screen.getByLabelText(/video attachment/i)).toHaveAttribute("src", "/api/media/sig/clip");
});
it("renders streaming reasoning as one compact activity line", () => {
const message: UIMessage = {
id: "a-reasoning-streaming",