fix(webui): preserve pasted paths when attachment detection fails (#6610)
This commit is contained in:
1 parent
82cc42aee7
commit
bbbc5329bb
2 files changed
+45
-20
No files matched your search
@@ -1323,13 +1323,12 @@ export function ThreadComposer({
|
|||||||
void onInspectAttachment(path).then((attachment) => {
|
void onInspectAttachment(path).then((attachment) => {
|
||||||
if (generation !== pathCheckGeneration.current) return;
|
if (generation !== pathCheckGeneration.current) return;
|
||||||
setPathInspection((current) => current?.generation === generation ? { ...current, attachment } : current);
|
setPathInspection((current) => current?.generation === generation ? { ...current, attachment } : current);
|
||||||
}).catch((error: unknown) => {
|
}).catch(() => {
|
||||||
if (generation !== pathCheckGeneration.current || pathCheckScope.current !== scopeIdentity) return;
|
if (generation !== pathCheckGeneration.current || pathCheckScope.current !== scopeIdentity) return;
|
||||||
|
// Attachment recognition is optional; the pasted text is already in the draft.
|
||||||
setPathInspection(null);
|
setPathInspection(null);
|
||||||
if (error instanceof Error && "status" in error && error.status === 404) return;
|
|
||||||
setInlineError(error instanceof Error ? error.message : t("message.attachmentUnavailable"));
|
|
||||||
});
|
});
|
||||||
}, [interactionDisabled, isUserShell, onAttachmentPaste, onInspectAttachment, rawSelection, replaceMentionInput, scopeIdentity, t, value]);
|
}, [interactionDisabled, isUserShell, onAttachmentPaste, onInspectAttachment, rawSelection, replaceMentionInput, scopeIdentity, value]);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (!pathInspection) return;
|
if (!pathInspection) return;
|
||||||
@@ -1341,16 +1340,12 @@ export function ThreadComposer({
|
|||||||
// Let the native IME commit before removing the confirmed path from its text.
|
// Let the native IME commit before removing the confirmed path from its text.
|
||||||
if (!pathInspection.attachment || mentionInput.isComposing) return;
|
if (!pathInspection.attachment || mentionInput.isComposing) return;
|
||||||
const edited = pathInspection.range.replace("", rawSelection().start);
|
const edited = pathInspection.range.replace("", rawSelection().start);
|
||||||
if (edited) {
|
if (edited && !addLocal(pathInspection.attachment)) {
|
||||||
const rejection = addLocal(pathInspection.attachment);
|
replaceMentionInput(edited.value, edited.cursor, { preserveFocus: true });
|
||||||
if (rejection) setInlineError(formatRejection(rejection));
|
setInlineError(null);
|
||||||
else {
|
|
||||||
replaceMentionInput(edited.value, edited.cursor, { preserveFocus: true });
|
|
||||||
setInlineError(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setPathInspection(null);
|
setPathInspection(null);
|
||||||
}, [addLocal, formatRejection, isUserShell, mentionInput.isComposing, pathInspection, rawSelection, replaceMentionInput, scopeIdentity, value]);
|
}, [addLocal, isUserShell, mentionInput.isComposing, pathInspection, rawSelection, replaceMentionInput, scopeIdentity, value]);
|
||||||
|
|
||||||
const draftText = composerMentionText(mentionInput.segments).raw;
|
const draftText = composerMentionText(mentionInput.segments).raw;
|
||||||
const sessionDragInsertion = sessionDragPreview
|
const sessionDragInsertion = sessionDragPreview
|
||||||
|
|||||||
@@ -586,17 +586,29 @@ describe("local attachment paths and video ingress", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
|
[400, "Unsupported attachment MIME"],
|
||||||
[404, "file not found"],
|
[404, "file not found"],
|
||||||
[403, "file is outside the current workspace"],
|
[403, "file is outside the current workspace"],
|
||||||
] as const)("retains pasted text on %s, showing only actionable errors", async (status, message) => {
|
[null, "gateway request timed out"],
|
||||||
const inspect = vi.fn().mockRejectedValue(Object.assign(new Error(message), { status }));
|
] as const)("silently retains pasted text when inspection fails (%s)", async (status, message) => {
|
||||||
render(<ThreadComposer onSend={vi.fn()} onInspectAttachment={inspect} />);
|
let reject!: (error: Error) => void;
|
||||||
const input = screen.getByLabelText(/message input/i);
|
const inspect = vi.fn(() => new Promise<typeof local>((_, fail) => { reject = fail; }));
|
||||||
fireEvent.paste(input, { clipboardData: { items: [], getData: () => "./missing.mp4" } });
|
const onSend = vi.fn();
|
||||||
|
const path = "C:\\project\\example.py";
|
||||||
|
render(<ThreadComposer onSend={onSend} onInspectAttachment={inspect} />);
|
||||||
|
const input = screen.getByLabelText(/message input/i) as HTMLTextAreaElement;
|
||||||
|
fireEvent.change(input, { target: { value: "Read OLD, please" } });
|
||||||
|
input.setSelectionRange(5, 8);
|
||||||
|
fireEvent.paste(input, { clipboardData: { items: [], getData: () => path } });
|
||||||
|
expect(inspect).toHaveBeenCalledWith(path);
|
||||||
|
expect(input).toHaveValue(`Read ${path}, please`);
|
||||||
|
fireEvent.change(input, { target: { value: `Read ${path}, please quickly` } });
|
||||||
|
await act(async () => reject(Object.assign(new Error(message), { status })));
|
||||||
await waitFor(() => expect(screen.getByRole("button", { name: /send message/i })).toBeEnabled());
|
await waitFor(() => expect(screen.getByRole("button", { name: /send message/i })).toBeEnabled());
|
||||||
expect(input).toHaveValue("./missing.mp4");
|
expect(input).toHaveValue(`Read ${path}, please quickly`);
|
||||||
if (status === 404) expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
||||||
else expect(screen.getByRole("alert")).toHaveTextContent(message);
|
fireEvent.keyDown(input, { key: "Enter" });
|
||||||
|
expect(onSend).toHaveBeenCalledWith(`Read ${path}, please quickly`, undefined, undefined);
|
||||||
for (const text of ["some pasted text", "look at ./missing.mp4 please", "https://host/clip.mp4", "const path = './clip.mp4'", "line one\n./clip.mp4"]) {
|
for (const text of ["some pasted text", "look at ./missing.mp4 please", "https://host/clip.mp4", "const path = './clip.mp4'", "line one\n./clip.mp4"]) {
|
||||||
fireEvent.paste(input, {
|
fireEvent.paste(input, {
|
||||||
clipboardData: {
|
clipboardData: {
|
||||||
@@ -618,6 +630,24 @@ describe("local attachment paths and video ingress", () => {
|
|||||||
expect(encodeImage).not.toHaveBeenCalled();
|
expect(encodeImage).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("keeps the path as text when the local attachment quota is full", async () => {
|
||||||
|
const second = { ...local, path: "C:\\project\\second.mp4", name: "second.mp4" };
|
||||||
|
const inspect = vi.fn().mockResolvedValueOnce(local).mockResolvedValueOnce(second);
|
||||||
|
const onSend = vi.fn();
|
||||||
|
render(<ThreadComposer onSend={onSend} onInspectAttachment={inspect} />);
|
||||||
|
const input = screen.getByLabelText(/message input/i);
|
||||||
|
fireEvent.paste(input, { clipboardData: { items: [], getData: () => local.path } });
|
||||||
|
await screen.findByRole("button", { name: local.name });
|
||||||
|
fireEvent.paste(input, { clipboardData: { items: [], getData: () => second.path } });
|
||||||
|
await waitFor(() => expect(screen.getByRole("button", { name: /send message/i })).toBeEnabled());
|
||||||
|
expect(input).toHaveValue(second.path);
|
||||||
|
expect(screen.getAllByTestId("composer-chip")).toHaveLength(1);
|
||||||
|
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
||||||
|
fireEvent.keyDown(input, { key: "Enter" });
|
||||||
|
expect(onSend.mock.calls[0][0]).toBe(second.path);
|
||||||
|
expect(onSend.mock.calls[0][1][0].media).toEqual({ path: local.path, name: local.name });
|
||||||
|
});
|
||||||
|
|
||||||
it("does not charge large local documents against a picked document's upload budget", async () => {
|
it("does not charge large local documents against a picked document's upload budget", async () => {
|
||||||
const onSend = vi.fn();
|
const onSend = vi.fn();
|
||||||
const document = { ...local, path: "C:\\project\\large.pdf", name: "large.pdf", mime: "application/pdf", kind: "file" as const, size: 64 * 1024 * 1024 + 1 };
|
const document = { ...local, path: "C:\\project\\large.pdf", name: "large.pdf", mime: "application/pdf", kind: "file" as const, size: 64 * 1024 * 1024 + 1 };
|
||||||
|
|||||||
Reference in new issue
Block a user