Repository navigation
fix(ai-chat-turbo): take over long pastes and clear the tray after a send - #266
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked Issue
Closes #265
Change summary
pastelistener and the page-lifecycle observers are now bound at the end ofinitializeEngine()(document-start), ahead of the host editor's own registration. Every handler still short-circuits onisEngineDormant(), so login routes stay untouched.beforeinputfallback forinsertFromPaste/insertFromPasteAsQuotation: if the site swallowspaste, the browser still emits a cancelablebeforeinput, which the engine now cancels and turns into a virtual file when the target is inside the editor and the payload reaches the threshold.tray-send-trackerwatches 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 whenisTrayVisible()and no part sequence is running.send-plan.tssplits line-first (surrogate-safe) into at mostMAX_SEND_PARTS = 12parts, reservingPART_HEADER_BUDGET = 48characters 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.waitForPartSentthenwaitForComposerReady), keep the remainder as aremaining_textvirtual file if a part is not confirmed, and abort the sequence on route swap or engine dormancy so a foreign composer is never clicked.insertTextAtomic:execCommand("insertText")with a readback check, theninsertHTML, then apre-wraptextContentfallback; addisStopControl()to avoid clicking the site's "stop generating" button.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 typecheckpasses.pnpm vitest run tests/ai-chat-turbo-passes: 16 files / 351 tests.pnpm testpasses: 59 files / 915 tests.pnpm buildwritesdist/ai-chat-turbo-engine.user.js, and the ScriptCat check reportsok dist\ai-chat-turbo-engine.user.js(exit 0).inputTypepass-through, out-of-editor targets, dormant-engine gating; send-confirmed tray dismissal, rebuilt-transcript dismissal, re-offer suppression, and theinsertTextAtomic/isStopControlpaths; 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.exceptions: [],pasteTakesOver: true,beforeInputTakesOver: true,singleSendClearsTray: true,oversizeSplits: true(two sends, both ≤ 50000), andrefuseKeepsTray: true.Review conclusion
writeNextPartnow returns whether the sequence is still owned andwaitForComposerReadybails on dormancy. A P4 comment-consistency nit was also addressed.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.