diff --git a/src/imessage/client.ts b/src/imessage/client.ts index 070765e3b..1a47f1726 100644 --- a/src/imessage/client.ts +++ b/src/imessage/client.ts @@ -2,6 +2,7 @@ import { type ChildProcessWithoutNullStreams, spawn } from "node:child_process"; import { createInterface, type Interface } from "node:readline"; import type { RuntimeEnv } from "../runtime.js"; import { resolveUserPath } from "../utils.js"; +import { DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS } from "./constants.js"; export type IMessageRpcError = { code?: number; @@ -149,8 +150,7 @@ export class IMessageRpcClient { params: params ?? {}, }; const line = `${JSON.stringify(payload)}\n`; - // Default timeout matches DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS from probe.ts - const timeoutMs = opts?.timeoutMs ?? 10_000; + const timeoutMs = opts?.timeoutMs ?? DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS; const response = new Promise((resolve, reject) => { const key = String(id); diff --git a/src/imessage/constants.ts b/src/imessage/constants.ts new file mode 100644 index 000000000..d82eaa502 --- /dev/null +++ b/src/imessage/constants.ts @@ -0,0 +1,2 @@ +/** Default timeout for iMessage probe/RPC operations (10 seconds). */ +export const DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS = 10_000; diff --git a/src/imessage/monitor/monitor-provider.ts b/src/imessage/monitor/monitor-provider.ts index 1f6c457f3..9044f221b 100644 --- a/src/imessage/monitor/monitor-provider.ts +++ b/src/imessage/monitor/monitor-provider.ts @@ -45,7 +45,8 @@ import { resolveAgentRoute } from "../../routing/resolve-route.js"; import { truncateUtf16Safe } from "../../utils.js"; import { resolveIMessageAccount } from "../accounts.js"; import { createIMessageRpcClient } from "../client.js"; -import { DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS, probeIMessage } from "../probe.js"; +import { DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS } from "../constants.js"; +import { probeIMessage } from "../probe.js"; import { sendMessageIMessage } from "../send.js"; import { formatIMessageChatTarget, diff --git a/src/imessage/probe.ts b/src/imessage/probe.ts index 5df7c667d..9226d48b1 100644 --- a/src/imessage/probe.ts +++ b/src/imessage/probe.ts @@ -3,9 +3,10 @@ import { detectBinary } from "../commands/onboard-helpers.js"; import { loadConfig } from "../config/config.js"; import { runCommandWithTimeout } from "../process/exec.js"; import { createIMessageRpcClient } from "./client.js"; +import { DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS } from "./constants.js"; -/** Default timeout for iMessage probe operations (10 seconds). */ -export const DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS = 10_000; +// Re-export for backwards compatibility +export { DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS } from "./constants.js"; export type IMessageProbe = { ok: boolean; @@ -59,18 +60,21 @@ async function probeRpcSupport(cliPath: string, timeoutMs: number): Promise { const cfg = opts.cliPath || opts.dbPath ? undefined : loadConfig(); const cliPath = opts.cliPath?.trim() || cfg?.channels?.imessage?.cliPath?.trim() || "imsg"; const dbPath = opts.dbPath?.trim() || cfg?.channels?.imessage?.dbPath?.trim(); - // Read probeTimeoutMs from config if not explicitly provided + // Use explicit timeout if provided, otherwise fall back to config, then default const effectiveTimeout = - timeoutMs !== DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS - ? timeoutMs - : cfg?.channels?.imessage?.probeTimeoutMs ?? DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS; + timeoutMs ?? cfg?.channels?.imessage?.probeTimeoutMs ?? DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS; const detected = await detectBinary(cliPath); if (!detected) {