feat: enhance BlueBubbles group message handling by adding account-specific logging and improving typing signal conditions
This commit is contained in:
committed by
Peter Steinberger
parent
d9a2ac7e72
commit
199fef2a5e
@@ -116,7 +116,6 @@ export function createFollowupRunner(params: {
|
||||
};
|
||||
|
||||
return async (queued: FollowupRun) => {
|
||||
await typingSignals.signalRunStart();
|
||||
try {
|
||||
const runId = crypto.randomUUID();
|
||||
if (queued.run.sessionKey) {
|
||||
|
||||
@@ -456,10 +456,6 @@ export async function runPreparedReply(
|
||||
},
|
||||
};
|
||||
|
||||
if (typingSignals.shouldStartImmediately) {
|
||||
await typingSignals.signalRunStart();
|
||||
}
|
||||
|
||||
return runReplyAgent({
|
||||
commandBody: prefixedCommandBody,
|
||||
followupRun,
|
||||
|
||||
@@ -106,8 +106,9 @@ describe("createTypingSignaler", () => {
|
||||
|
||||
await signaler.signalMessageStart();
|
||||
|
||||
expect(typing.startTypingLoop).toHaveBeenCalled();
|
||||
expect(typing.startTypingOnText).not.toHaveBeenCalled();
|
||||
expect(typing.startTypingLoop).not.toHaveBeenCalled();
|
||||
await signaler.signalTextDelta("hello");
|
||||
expect(typing.startTypingOnText).toHaveBeenCalledWith("hello");
|
||||
});
|
||||
|
||||
it("signals on reasoning for thinking mode", async () => {
|
||||
@@ -119,7 +120,8 @@ describe("createTypingSignaler", () => {
|
||||
});
|
||||
|
||||
await signaler.signalReasoningDelta();
|
||||
|
||||
expect(typing.startTypingLoop).not.toHaveBeenCalled();
|
||||
await signaler.signalTextDelta("hi");
|
||||
expect(typing.startTypingLoop).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -133,11 +135,12 @@ describe("createTypingSignaler", () => {
|
||||
|
||||
await signaler.signalTextDelta("hi");
|
||||
|
||||
expect(typing.startTypingLoop).toHaveBeenCalled();
|
||||
expect(typing.refreshTypingTtl).toHaveBeenCalled();
|
||||
expect(typing.startTypingOnText).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("starts typing on tool start when inactive", async () => {
|
||||
it("does not start typing on tool start before text", async () => {
|
||||
const typing = createMockTypingController();
|
||||
const signaler = createTypingSignaler({
|
||||
typing,
|
||||
@@ -147,11 +150,11 @@ describe("createTypingSignaler", () => {
|
||||
|
||||
await signaler.signalToolStart();
|
||||
|
||||
expect(typing.startTypingLoop).toHaveBeenCalled();
|
||||
expect(typing.refreshTypingTtl).toHaveBeenCalled();
|
||||
expect(typing.startTypingLoop).not.toHaveBeenCalled();
|
||||
expect(typing.refreshTypingTtl).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("refreshes ttl on tool start when active", async () => {
|
||||
it("refreshes ttl on tool start when active after text", async () => {
|
||||
const typing = createMockTypingController({
|
||||
isActive: vi.fn(() => true),
|
||||
});
|
||||
@@ -161,6 +164,10 @@ describe("createTypingSignaler", () => {
|
||||
isHeartbeat: false,
|
||||
});
|
||||
|
||||
await signaler.signalTextDelta("hello");
|
||||
typing.startTypingLoop.mockClear();
|
||||
typing.startTypingOnText.mockClear();
|
||||
typing.refreshTypingTtl.mockClear();
|
||||
await signaler.signalToolStart();
|
||||
|
||||
expect(typing.refreshTypingTtl).toHaveBeenCalled();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { TypingMode } from "../../config/types.js";
|
||||
import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../tokens.js";
|
||||
import type { TypingController } from "./typing.js";
|
||||
|
||||
export type TypingModeContext = {
|
||||
@@ -46,6 +47,13 @@ export function createTypingSignaler(params: {
|
||||
const shouldStartOnText = mode === "message" || mode === "instant";
|
||||
const shouldStartOnReasoning = mode === "thinking";
|
||||
const disabled = isHeartbeat || mode === "never";
|
||||
let hasRenderableText = false;
|
||||
|
||||
const isRenderableText = (text?: string): boolean => {
|
||||
const trimmed = text?.trim();
|
||||
if (!trimmed) return false;
|
||||
return !isSilentReplyText(trimmed, SILENT_REPLY_TOKEN);
|
||||
};
|
||||
|
||||
const signalRunStart = async () => {
|
||||
if (disabled || !shouldStartImmediately) return;
|
||||
@@ -54,28 +62,40 @@ export function createTypingSignaler(params: {
|
||||
|
||||
const signalMessageStart = async () => {
|
||||
if (disabled || !shouldStartOnMessageStart) return;
|
||||
if (!hasRenderableText) return;
|
||||
await typing.startTypingLoop();
|
||||
};
|
||||
|
||||
const signalTextDelta = async (text?: string) => {
|
||||
if (disabled) return;
|
||||
const renderable = isRenderableText(text);
|
||||
if (renderable) {
|
||||
hasRenderableText = true;
|
||||
} else if (text?.trim()) {
|
||||
return;
|
||||
}
|
||||
if (shouldStartOnText) {
|
||||
await typing.startTypingOnText(text);
|
||||
return;
|
||||
}
|
||||
if (shouldStartOnReasoning) {
|
||||
if (!typing.isActive()) {
|
||||
await typing.startTypingLoop();
|
||||
}
|
||||
typing.refreshTypingTtl();
|
||||
}
|
||||
};
|
||||
|
||||
const signalReasoningDelta = async () => {
|
||||
if (disabled || !shouldStartOnReasoning) return;
|
||||
if (!hasRenderableText) return;
|
||||
await typing.startTypingLoop();
|
||||
typing.refreshTypingTtl();
|
||||
};
|
||||
|
||||
const signalToolStart = async () => {
|
||||
if (disabled) return;
|
||||
if (!hasRenderableText) return;
|
||||
if (!typing.isActive()) {
|
||||
await typing.startTypingLoop();
|
||||
typing.refreshTypingTtl();
|
||||
|
||||
Reference in New Issue
Block a user