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

+43
View File
@@ -2899,6 +2899,49 @@ describe("useNanobotStream", () => {
);
});
it("uses the accepted upload URL instead of retaining an encoded video in message state", () => {
const fake = fakeClient();
const { result } = renderHook(() => useNanobotStream("uploaded-video", EMPTY_MESSAGES), {
wrapper: wrap(fake.client),
});
act(() => {
result.current.send("watch", [{
media: { data_url: "data:video/webm;base64,AAAA", name: "clip.webm" },
preview: { kind: "video", url: "data:video/webm;base64,AAAA", name: "clip.webm" },
}]);
});
const optimistic = result.current.messages[0];
expect(optimistic.media).toEqual([{ kind: "video", name: "clip.webm" }]);
const media = [{ kind: "video" as const, url: "/api/media/sig/upload", name: "clip.webm" }];
act(() => fake.emit("uploaded-video", {
event: "message_accepted", chat_id: "uploaded-video",
turn_id: optimistic.turnId!, starts_turn: true, media_urls: media,
}));
expect(result.current.messages).toHaveLength(1);
expect(result.current.messages[0]).toMatchObject({ id: optimistic.id, media, deliveryStatus: "accepted" });
});
it("replaces a local reference's optimistic preview with the gateway's session URL", () => {
const fake = fakeClient();
const { result } = renderHook(() => useNanobotStream("local-video", EMPTY_MESSAGES), {
wrapper: wrap(fake.client),
});
act(() => {
result.current.send("watch", [{
media: { path: "/project/video.mp4", name: "video.mp4" },
preview: { kind: "video", url: "", name: "video.mp4" },
}]);
});
const optimistic = result.current.messages[0];
const media = [{ kind: "video" as const, url: "/api/media/sig/local-video", name: "video.mp4" }];
act(() => fake.emit("local-video", {
event: "user_message", chat_id: "local-video", text: "watch",
turn_id: optimistic.turnId!, starts_turn: true, media_urls: media,
}));
expect(result.current.messages).toHaveLength(1);
expect(result.current.messages[0]).toMatchObject({ id: optimistic.id, media, deliveryStatus: "accepted" });
});
it("inlines quoted context into the optimistic and outbound user message", () => {
const fake = fakeClient();
const { result } = renderHook(() => useNanobotStream("chat-quote", EMPTY_MESSAGES), {