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:
1 parent
7dfeff9ddf
commit
254f94b068
65 files changed
+1816
-292
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { afterEach, expect, test } from "bun:test"
|
||||
import { pastedFilePath, uploadAttachments } from "../../../packages/client-events/attachments"
|
||||
|
||||
const originalFetch = globalThis.fetch
|
||||
afterEach(() => { globalThis.fetch = originalFetch })
|
||||
|
||||
test("recognizes whole paths across native platforms without consuming prose, code, URLs or fakepath", () => {
|
||||
for (const [text, path] of [
|
||||
['"C:\\project\\my clip.mp4"', "C:\\project\\my clip.mp4"],
|
||||
["'./clips/my clip.webm'", "./clips/my clip.webm"],
|
||||
["/tmp/my clip.mov", "/tmp/my clip.mov"], ["clips/clip.mp4", "clips/clip.mp4"],
|
||||
["clip.mp4", "clip.mp4"],
|
||||
['"C:\\project\\O\'Reilly.png"', "C:\\project\\O'Reilly.png"],
|
||||
["/tmp/O'Reilly.png", "/tmp/O'Reilly.png"],
|
||||
['"O\'Reilly notes.pdf"', "O'Reilly notes.pdf"],
|
||||
]) expect(pastedFilePath(text!)).toBe(path!)
|
||||
for (const text of ["please read ./file.txt", "const p = './file.txt'", "https://host/clip.mp4",
|
||||
"C:\\fakepath\\clip.mp4", "line\n./clip.mp4", "`./clip.mp4`"]) expect(pastedFilePath(text)).toBeNull()
|
||||
})
|
||||
|
||||
test("local paths send zero HTTP bodies; mixed batches upload only the required bytes", async () => {
|
||||
const requests: { url: string; body: Blob }[] = []
|
||||
globalThis.fetch = (async (url, init) => {
|
||||
requests.push({ url: String(url), body: init?.body as Blob })
|
||||
return Response.json({ reference: "upload-token" })
|
||||
}) as typeof fetch
|
||||
const local = { path: "/workspace/original.mp4", name: "original.mp4" }
|
||||
expect(await uploadAttachments([local], null, "ws://unused", () => true)).toEqual([local])
|
||||
expect(requests).toHaveLength(0)
|
||||
expect(await uploadAttachments([local, { data_url: "data:video/webm;base64,eA==", name: "upload.webm" }],
|
||||
{ path: "/api/attachments", token: "private-capability" }, "ws://localhost:1234", () => true))
|
||||
.toEqual([local, { reference: "upload-token", name: "upload.webm" }])
|
||||
expect(requests).toHaveLength(1)
|
||||
expect(requests[0]?.url).toBe("http://localhost:1234/api/attachments")
|
||||
expect(await requests[0]?.body.text()).toBe("x")
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
import { uploadAttachments, uploadCapability, type AttachmentReference, type UploadCapability } from "../../../packages/client-events/attachments"
|
||||
import { uploadAttachments, uploadCapability, isLocalAttachment, type AttachmentReference, type UploadCapability } from "../../../packages/client-events/attachments"
|
||||
import { DeliveryReceipts } from "../../../packages/client-events/delivery"
|
||||
import { isRecoveryState } from "../../../packages/client-events/notifications"
|
||||
|
||||
@@ -249,6 +249,17 @@ export class NanobotClient {
|
||||
})
|
||||
}
|
||||
|
||||
inspectAttachment(path: string): Promise<import("../../../packages/client-events/attachments").LocalAttachment> {
|
||||
if (!this.chatId) return Promise.reject(new Error("chat is not ready"))
|
||||
return this.requestMutation<unknown>("attachment.inspect", {
|
||||
chat_id: this.chatId, path,
|
||||
...(this.workspaceScope ? { workspace_scope: this.workspaceScope } : {}),
|
||||
}).then((result) => {
|
||||
if (!isLocalAttachment(result)) throw new Error("Invalid attachment metadata")
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
private requestMutation<T>(
|
||||
action: string,
|
||||
payload: Record<string, unknown> = {},
|
||||
|
||||
@@ -71,10 +71,7 @@ export interface MediaAttachment {
|
||||
name?: string
|
||||
}
|
||||
|
||||
export interface OutboundMedia {
|
||||
data_url: string
|
||||
name?: string
|
||||
}
|
||||
export type OutboundMedia = import("../../../packages/client-events/attachments").DraftAttachment
|
||||
|
||||
export interface WorkspaceScopePayload {
|
||||
project_path: string
|
||||
|
||||
Reference in new issue
Block a user