refactor: unify typing dispatch lifecycle and policy boundaries

This commit is contained in:
Peter Steinberger
2026-02-26 17:36:09 +01:00
parent 6fd9ec97de
commit 273973d374
19 changed files with 420 additions and 164 deletions

View File

@@ -1,4 +1,5 @@
import { createTypingKeepaliveLoop } from "../../channels/typing-lifecycle.js";
import { createTypingStartGuard } from "../../channels/typing-start-guard.js";
import { isSilentReplyPrefixText, isSilentReplyText, SILENT_REPLY_TOKEN } from "../tokens.js";
export type TypingController = {
@@ -99,15 +100,16 @@ export function createTypingController(params: {
const isActive = () => active && !sealed;
const startGuard = createTypingStartGuard({
isSealed: () => sealed,
shouldBlock: () => runComplete,
rethrowOnError: true,
});
const triggerTyping = async () => {
if (sealed) {
return;
}
// Late callbacks after a run completed should never restart typing.
if (runComplete) {
return;
}
await onReplyStart?.();
await startGuard.run(async () => {
await onReplyStart?.();
});
};
const typingLoop = createTypingKeepaliveLoop({