Skip to content

fix(deepseek): fix send button detection and file upload#1166

Merged
jackwener merged 2 commits intojackwener:mainfrom
Benjamin-eecs:fix/deepseek-send-file
Apr 28, 2026
Merged

fix(deepseek): fix send button detection and file upload#1166
jackwener merged 2 commits intojackwener:mainfrom
Benjamin-eecs:fix/deepseek-send-file

Conversation

@Benjamin-eecs
Copy link
Copy Markdown
Contributor

@Benjamin-eecs Benjamin-eecs commented Apr 24, 2026

Description

Three bugs in sendMessage and sendWithFile that caused --file upload to silently fail:

1. sendMessage button detection always failed. The selector btn.closest('div')?.querySelector('textarea') always returned null because the button itself is a <div>, so closest('div') returns the button, which has no textarea inside. This caused every send to use the Enter key fallback, and when the send button was disabled (during file upload), it would click the attachment button instead.

Fix: walk up from the textarea to find the input container, then click only the last non-toggle button (the actual send button).

2. sendWithFile sent the message before the file upload finished. DeepSeek shows the file preview chip immediately (optimistic UI), but the send button stays aria-disabled="true" until the PoW challenge + server upload completes (~2s). The old code sent the message as soon as the preview appeared, before the upload was done.

Fix: after waitForFilePreview, poll until the send button becomes enabled (up to 15s).

3. DataTransfer ownership bug. inp.files = dt.files transfers the FileList and empties dt.files. The old code then passed the now-empty dt.files to React's onChange.

Fix: pass inp.files instead of dt.files to onChange.

Fixes #1167

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🌐 New site adapter
  • 📝 Documentation
  • ♻️ Refactor
  • 🔧 CI / build / tooling

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Documentation (if adding/modifying an adapter)

N/A

Screenshots / Output

File upload now works:

$ echo "The answer is 42." > /tmp/test.txt
$ opencli deepseek ask "what number is in this file" --new --file /tmp/test.txt
- response: The number in the file is 42.

All commands tested:

ask (instant)      OK
ask --think        OK
ask --model expert OK
ask --file         OK
ask --search       OK
history            OK
status             OK
new                OK
read               OK

Copilot AI review requested due to automatic review settings April 24, 2026 04:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes DeepSeek adapter message sending by correctly identifying and clicking the actual send button in sendMessage() instead of always falling back to an Enter keypress.

Changes:

  • Replaces global button scanning with DOM traversal from the textarea to its input container.
  • Selects the last enabled non-toggle SVG button in that container and clicks it, preserving Enter fallback if no button is found.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread clis/deepseek/utils.js Outdated
if (btns[i].getAttribute('aria-disabled') === 'false'
&& btns[i].querySelectorAll('svg').length > 0) {
btns[i].click();
return { ok: true };
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The success return shape is inconsistent: the click path returns { ok: true } while the Enter fallback returns { ok: true, method: 'enter' }. This makes it harder for callers/logging to reliably understand how the message was sent. Consider returning a consistent shape for both paths (e.g., include method: 'click' on the click path).

Suggested change
return { ok: true };
return { ok: true, method: 'click' };

Copilot uses AI. Check for mistakes.
Comment thread clis/deepseek/utils.js Outdated
Comment on lines 77 to 90
// Find the send button inside the textarea's input container.
// Walk up from the textarea until we reach a parent with buttons.
var container = box.parentElement;
while (container && !container.querySelector('div[role="button"]')) {
container = container.parentElement;
}
if (container) {
var btns = container.querySelectorAll('div[role="button"]:not(.ds-toggle-button)');
for (var i = btns.length - 1; i >= 0; i--) {
if (btns[i].getAttribute('aria-disabled') === 'false'
&& btns[i].querySelectorAll('svg').length > 0) {
btns[i].click();
return { ok: true };
}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new DOM-walking/button-selection logic is untested. Since this package already has unit tests for utils.js, add coverage for sendMessage() to validate that it finds the correct enabled SVG button in the textarea container and avoids falling back to the Enter key path.

Copilot uses AI. Check for mistakes.
Comment thread clis/deepseek/utils.js Outdated
var btns = container.querySelectorAll('div[role="button"]:not(.ds-toggle-button)');
for (var i = btns.length - 1; i >= 0; i--) {
if (btns[i].getAttribute('aria-disabled') === 'false'
&& btns[i].querySelectorAll('svg').length > 0) {
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor performance/clarity: btns[i].querySelectorAll('svg').length > 0 allocates a NodeList each iteration just to check existence. Using a single-element query (e.g., querySelector('svg')) avoids that overhead and reads more directly as an existence check.

Suggested change
&& btns[i].querySelectorAll('svg').length > 0) {
&& btns[i].querySelector('svg')) {

Copilot uses AI. Check for mistakes.
@Benjamin-eecs Benjamin-eecs force-pushed the fix/deepseek-send-file branch 2 times, most recently from 3f9f17e to 0e2b9eb Compare April 24, 2026 05:34
@Benjamin-eecs Benjamin-eecs changed the title fix(deepseek): fix send button detection in sendMessage fix(deepseek): fix send button detection and file upload Apr 24, 2026
@Benjamin-eecs Benjamin-eecs force-pushed the fix/deepseek-send-file branch 8 times, most recently from 2b8b1f6 to b5a13d3 Compare April 27, 2026 07:42
The previous selector `btn.closest('div')?.querySelector('textarea')`
always returned null because the button itself is a div, so
closest('div') returns the button, which has no textarea inside.
This caused every send to fall through to the Enter key fallback.

Walk up from the textarea to find the input container, then select
the last enabled non-toggle button with an SVG icon (the send
button). Excludes `.ds-toggle-button` elements (DeepThink / Search
toggles) so only the actual send button is clicked.
@Benjamin-eecs Benjamin-eecs force-pushed the fix/deepseek-send-file branch from b5a13d3 to 24606bd Compare April 27, 2026 10:20
@jackwener jackwener merged commit 08a2428 into jackwener:main Apr 28, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: deepseek --file upload fails silently

3 participants