mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-17 19:55:44 +00:00
fix(imessage): align monitor retry types
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { monitorIMessageProvider } from "./monitor.js";
|
||||
|
||||
const waitForTransportReadyMock = vi.hoisted(() => vi.fn(async () => {}));
|
||||
const createIMessageRpcClientMock = vi.hoisted(() => vi.fn());
|
||||
const attachIMessageMonitorAbortHandlerMock = vi.hoisted(() => vi.fn(() => () => {}));
|
||||
const waitForTransportReadyMock = vi.hoisted(() =>
|
||||
vi.fn<(...args: unknown[]) => Promise<void>>(async () => {}),
|
||||
);
|
||||
const createIMessageRpcClientMock = vi.hoisted(() => vi.fn<(...args: unknown[]) => unknown>());
|
||||
const attachIMessageMonitorAbortHandlerMock = vi.hoisted(() =>
|
||||
vi.fn<(...args: unknown[]) => () => void>(() => () => {}),
|
||||
);
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/infra-runtime", () => ({
|
||||
waitForTransportReady: (...args: unknown[]) => waitForTransportReadyMock(...args),
|
||||
|
||||
@@ -234,6 +234,15 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
|
||||
},
|
||||
});
|
||||
|
||||
let client: IMessageRpcClient | undefined;
|
||||
let detachAbortHandler = () => {};
|
||||
const getActiveClient = () => {
|
||||
if (!client) {
|
||||
throw new Error("imessage monitor client not initialized");
|
||||
}
|
||||
return client;
|
||||
};
|
||||
|
||||
async function handleMessageNow(message: IMessagePayload) {
|
||||
const messageText = (message.text ?? "").trim();
|
||||
|
||||
@@ -343,7 +352,7 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
|
||||
},
|
||||
sendPairingReply: async (text) => {
|
||||
await sendMessageIMessage(sender, text, {
|
||||
client,
|
||||
client: getActiveClient(),
|
||||
maxBytes: mediaMaxBytes,
|
||||
accountId: accountInfo.accountId,
|
||||
...(chatId ? { chatId } : {}),
|
||||
@@ -443,7 +452,7 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
|
||||
await deliverReplies({
|
||||
replies: [payload],
|
||||
target,
|
||||
client,
|
||||
client: getActiveClient(),
|
||||
accountId: accountInfo.accountId,
|
||||
runtime,
|
||||
maxBytes: mediaMaxBytes,
|
||||
@@ -539,14 +548,11 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
|
||||
},
|
||||
});
|
||||
|
||||
let client: IMessageRpcClient | null = null;
|
||||
let detachAbortHandler = () => {};
|
||||
|
||||
for (let attempt = 1; attempt <= WATCH_SUBSCRIBE_MAX_ATTEMPTS; attempt++) {
|
||||
if (abort?.aborted) {
|
||||
return;
|
||||
}
|
||||
let attemptClient: IMessageRpcClient | null = null;
|
||||
let attemptClient: IMessageRpcClient | undefined;
|
||||
let attemptDetachAbortHandler = () => {};
|
||||
let keepAttemptClient = false;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user