Skip to content

fix(ai-chat-turbo): take over long pastes and clear the tray after a send - #266

Merged
CYoJkoY merged 1 commit into
mainfrom
issue-265-ai-chat-turbo-long-text-split
Nov 28, 2026
Merged

CYoJkoY merged 1 commit into
mainfrom
issue-265-ai-chat-turbo-long-text-split

Conversation

@CYoJkoY

@CYoJkoY CYoJkoY commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Linked Issue

Closes #265

Change summary

  • Take over long pastes on Yuanbao before the site can reject them. The capture-phase paste listener and the page-lifecycle observers are now bound at the end of initializeEngine() (document-start), ahead of the host editor's own registration. Every handler still short-circuits on isEngineDormant(), so login routes stay untouched.
  • Add a beforeinput fallback for insertFromPaste / insertFromPasteAsQuotation: if the site swallows paste, the browser still emits a cancelable beforeinput, which the engine now cancels and turns into a virtual file when the target is inside the editor and the payload reaches the threshold.
  • Make the virtual-file tray disappear after a send. A new tray-send-tracker watches the transcript turns and confirms a send when a user turn is appended after the anchor, or when the transcript is rebuilt with more user turns; the confirmed send dismisses the tray only when isTrayVisible() and no part sequence is running.
  • Add multi-part sending for payloads over the platform cap: send-plan.ts splits line-first (surrogate-safe) into at most MAX_SEND_PARTS = 12 parts, reserving PART_HEADER_BUDGET = 48 characters on every part so a full part never trips the measured 50,000-character Yuanbao limit. Later parts carry a 【第 i/N 段 · 接上文】 header; an over-12-part payload is refused and the tray keeps the content.
  • Wait for the site between parts (waitForPartSent then waitForComposerReady), keep the remainder as a remaining_text virtual file if a part is not confirmed, and abort the sequence on route swap or engine dormancy so a foreign composer is never clicked.
  • Replace the merged-send editor write with insertTextAtomic: execCommand("insertText") with a readback check, then insertHTML, then a pre-wrap textContent fallback; add isStopControl() to avoid clicking the site's "stop generating" button.
  • Point the Yuanbao platform config at the real editor and send control (enterToSend: true, composerTextLimit: 50000, .ql-editor[contenteditable="true"], #yuanbao-send-btn, human/ai turn selectors), bump ai-chat-turbo-engine to 0.23.15, and document the paste takeover, tray lifecycle, and multi-part design.

Verification & Dependencies

  • pnpm typecheck passes.
  • pnpm vitest run tests/ai-chat-turbo- passes: 16 files / 351 tests.
  • pnpm test passes: 59 files / 915 tests.
  • pnpm build writes dist/ai-chat-turbo-engine.user.js, and the ScriptCat check reports ok dist\ai-chat-turbo-engine.user.js (exit 0).
  • New regression cases cover document-start paste takeover, short-paste pass-through, non-paste inputType pass-through, out-of-editor targets, dormant-engine gating; send-confirmed tray dismissal, rebuilt-transcript dismissal, re-offer suppression, and the insertTextAtomic / isStopControl paths; plus the send plan (single part, no cap, line split, surrogate pairs, header-budget margin, over-part refusal, fused format), the part sequence, over-cap refusal, partial-send remainder retention, and the "stop a part sequence when the composer is no longer owned" guard.
  • Synthetic Yuanbao harness (headless Edge + CDP running the real compiled bundle) reports PASS with exceptions: [], pasteTakesOver: true, beforeInputTakesOver: true, singleSendClearsTray: true, oversizeSplits: true (two sends, both ≤ 50000), and refuseKeepsTray: true.
  • No new runtime dependencies and no new network endpoints.

Review conclusion

  • Reviewed head: 81c5161.
  • Single-agent source review: PASS, calculated score 4.85/5.00. No unresolved P0, P1, P2, P3, or P4 findings. This is not an independent review attestation.
  • Two findings were raised and resolved during review: (1) the first part was counted one character higher than written because the editor block adds a trailing newline, so a 50000-character part tripped the cap — every part now reserves the same 48-character header budget; (2) the part loop could click send on a foreign composer after a route swap — writeNextPart now returns whether the sequence is still owned and waitForComposerReady bails on dormancy. A P4 comment-consistency nit was also addressed.
  • C1: explicit element and text guards; C2: spaces only; C3: new control flow stays within two levels; C4: early exits on empty text and dormant engine; C5: existing observers and tracking loop reused; C6: focused helpers with narrow parameters; C7: existing typed config reused, with no new tunable business data.

Permission Notice

This change is limited to the ai-chat-turbo-engine paste takeover, virtual-file tray lifecycle, and multi-part send path. It adds no grants, network endpoints, telemetry, or outgoing message writes beyond the user's own send action. No user content is collected or transmitted.

…send

Register paste/beforeinput capture listeners at document start so the engine
sees long pastes before the host cancels them, and stage over-threshold text
as a virtual file. Clear the tray from a transcript-level send signal instead
of the optimistic click path, and resume observers between multi-part sends.

Split over-limit payloads into at most 12 line-first, surrogate-safe parts
under the measured 50000-char Yuanbao cap, reserving a small margin on every
part because the editor's block element adds a trailing newline to the text
the host counts. Return any remainder to the tray when a sequence is cut
short, and stop the loop instead of clicking send once the composer no longer
belongs to the sequence.

Refs: #265
@CYoJkoY
CYoJkoY merged commit 068bf53 into main Nov 28, 2026
1 check passed
@CYoJkoY
CYoJkoY deleted the issue-265-ai-chat-turbo-long-text-split branch November 28, 2026 18:34
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.

fix(ai-chat-turbo): take over long pastes and clear the tray after a send

1 participant