mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 01:18:28 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -38,7 +38,9 @@ export function createTypingController(params: {
|
||||
const typingIntervalMs = typingIntervalSeconds * 1000;
|
||||
|
||||
const formatTypingTtl = (ms: number) => {
|
||||
if (ms % 60_000 === 0) return `${ms / 60_000}m`;
|
||||
if (ms % 60_000 === 0) {
|
||||
return `${ms / 60_000}m`;
|
||||
}
|
||||
return `${Math.round(ms / 1000)}s`;
|
||||
};
|
||||
|
||||
@@ -50,7 +52,9 @@ export function createTypingController(params: {
|
||||
};
|
||||
|
||||
const cleanup = () => {
|
||||
if (sealed) return;
|
||||
if (sealed) {
|
||||
return;
|
||||
}
|
||||
if (typingTtlTimer) {
|
||||
clearTimeout(typingTtlTimer);
|
||||
typingTtlTimer = undefined;
|
||||
@@ -64,14 +68,22 @@ export function createTypingController(params: {
|
||||
};
|
||||
|
||||
const refreshTypingTtl = () => {
|
||||
if (sealed) return;
|
||||
if (!typingIntervalMs || typingIntervalMs <= 0) return;
|
||||
if (typingTtlMs <= 0) return;
|
||||
if (sealed) {
|
||||
return;
|
||||
}
|
||||
if (!typingIntervalMs || typingIntervalMs <= 0) {
|
||||
return;
|
||||
}
|
||||
if (typingTtlMs <= 0) {
|
||||
return;
|
||||
}
|
||||
if (typingTtlTimer) {
|
||||
clearTimeout(typingTtlTimer);
|
||||
}
|
||||
typingTtlTimer = setTimeout(() => {
|
||||
if (!typingTimer) return;
|
||||
if (!typingTimer) {
|
||||
return;
|
||||
}
|
||||
log?.(`typing TTL reached (${formatTypingTtl(typingTtlMs)}); stopping typing indicator`);
|
||||
cleanup();
|
||||
}, typingTtlMs);
|
||||
@@ -80,37 +92,59 @@ export function createTypingController(params: {
|
||||
const isActive = () => active && !sealed;
|
||||
|
||||
const triggerTyping = async () => {
|
||||
if (sealed) return;
|
||||
if (sealed) {
|
||||
return;
|
||||
}
|
||||
await onReplyStart?.();
|
||||
};
|
||||
|
||||
const ensureStart = async () => {
|
||||
if (sealed) return;
|
||||
if (sealed) {
|
||||
return;
|
||||
}
|
||||
// Late callbacks after a run completed should never restart typing.
|
||||
if (runComplete) return;
|
||||
if (runComplete) {
|
||||
return;
|
||||
}
|
||||
if (!active) {
|
||||
active = true;
|
||||
}
|
||||
if (started) return;
|
||||
if (started) {
|
||||
return;
|
||||
}
|
||||
started = true;
|
||||
await triggerTyping();
|
||||
};
|
||||
|
||||
const maybeStopOnIdle = () => {
|
||||
if (!active) return;
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
// Stop only when the model run is done and the dispatcher queue is empty.
|
||||
if (runComplete && dispatchIdle) cleanup();
|
||||
if (runComplete && dispatchIdle) {
|
||||
cleanup();
|
||||
}
|
||||
};
|
||||
|
||||
const startTypingLoop = async () => {
|
||||
if (sealed) return;
|
||||
if (runComplete) return;
|
||||
if (sealed) {
|
||||
return;
|
||||
}
|
||||
if (runComplete) {
|
||||
return;
|
||||
}
|
||||
// Always refresh TTL when called, even if loop already running.
|
||||
// This keeps typing alive during long tool executions.
|
||||
refreshTypingTtl();
|
||||
if (!onReplyStart) return;
|
||||
if (typingIntervalMs <= 0) return;
|
||||
if (typingTimer) return;
|
||||
if (!onReplyStart) {
|
||||
return;
|
||||
}
|
||||
if (typingIntervalMs <= 0) {
|
||||
return;
|
||||
}
|
||||
if (typingTimer) {
|
||||
return;
|
||||
}
|
||||
await ensureStart();
|
||||
typingTimer = setInterval(() => {
|
||||
void triggerTyping();
|
||||
@@ -118,10 +152,16 @@ export function createTypingController(params: {
|
||||
};
|
||||
|
||||
const startTypingOnText = async (text?: string) => {
|
||||
if (sealed) return;
|
||||
if (sealed) {
|
||||
return;
|
||||
}
|
||||
const trimmed = text?.trim();
|
||||
if (!trimmed) return;
|
||||
if (silentToken && isSilentReplyText(trimmed, silentToken)) return;
|
||||
if (!trimmed) {
|
||||
return;
|
||||
}
|
||||
if (silentToken && isSilentReplyText(trimmed, silentToken)) {
|
||||
return;
|
||||
}
|
||||
refreshTypingTtl();
|
||||
await startTypingLoop();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user