mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 18:28:26 +00:00
refactor: consolidate typing lifecycle and queue policy
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { createTypingKeepaliveLoop } from "../../channels/typing-lifecycle.js";
|
||||
import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../tokens.js";
|
||||
|
||||
export type TypingController = {
|
||||
@@ -35,7 +36,6 @@ export function createTypingController(params: {
|
||||
// especially when upstream event emitters don't await async listeners.
|
||||
// Once we stop typing, we "seal" the controller so late events can't restart typing forever.
|
||||
let sealed = false;
|
||||
let typingTimer: NodeJS.Timeout | undefined;
|
||||
let typingTtlTimer: NodeJS.Timeout | undefined;
|
||||
const typingIntervalMs = typingIntervalSeconds * 1000;
|
||||
|
||||
@@ -61,10 +61,7 @@ export function createTypingController(params: {
|
||||
clearTimeout(typingTtlTimer);
|
||||
typingTtlTimer = undefined;
|
||||
}
|
||||
if (typingTimer) {
|
||||
clearInterval(typingTimer);
|
||||
typingTimer = undefined;
|
||||
}
|
||||
typingLoop.stop();
|
||||
// Notify the channel to stop its typing indicator (e.g., on NO_REPLY).
|
||||
// This fires only once (sealed prevents re-entry).
|
||||
if (active) {
|
||||
@@ -88,7 +85,7 @@ export function createTypingController(params: {
|
||||
clearTimeout(typingTtlTimer);
|
||||
}
|
||||
typingTtlTimer = setTimeout(() => {
|
||||
if (!typingTimer) {
|
||||
if (!typingLoop.isRunning()) {
|
||||
return;
|
||||
}
|
||||
log?.(`typing TTL reached (${formatTypingTtl(typingTtlMs)}); stopping typing indicator`);
|
||||
@@ -105,6 +102,11 @@ export function createTypingController(params: {
|
||||
await onReplyStart?.();
|
||||
};
|
||||
|
||||
const typingLoop = createTypingKeepaliveLoop({
|
||||
intervalMs: typingIntervalMs,
|
||||
onTick: triggerTyping,
|
||||
});
|
||||
|
||||
const ensureStart = async () => {
|
||||
if (sealed) {
|
||||
return;
|
||||
@@ -146,16 +148,11 @@ export function createTypingController(params: {
|
||||
if (!onReplyStart) {
|
||||
return;
|
||||
}
|
||||
if (typingIntervalMs <= 0) {
|
||||
return;
|
||||
}
|
||||
if (typingTimer) {
|
||||
if (typingLoop.isRunning()) {
|
||||
return;
|
||||
}
|
||||
await ensureStart();
|
||||
typingTimer = setInterval(() => {
|
||||
void triggerTyping();
|
||||
}, typingIntervalMs);
|
||||
typingLoop.start();
|
||||
};
|
||||
|
||||
const startTypingOnText = async (text?: string) => {
|
||||
|
||||
Reference in New Issue
Block a user