fix: address review comments
- Use optional timeoutMs parameter (undefined = use config/default) - Extract DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS to shared constants.ts - Import constant in client.ts instead of hardcoding - Re-export constant from probe.ts for backwards compatibilitymain
parent
78f8a29071
commit
f633a8cb22
|
|
@ -2,6 +2,7 @@ import { type ChildProcessWithoutNullStreams, spawn } from "node:child_process";
|
||||||
import { createInterface, type Interface } from "node:readline";
|
import { createInterface, type Interface } from "node:readline";
|
||||||
import type { RuntimeEnv } from "../runtime.js";
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
import { resolveUserPath } from "../utils.js";
|
import { resolveUserPath } from "../utils.js";
|
||||||
|
import { DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS } from "./constants.js";
|
||||||
|
|
||||||
export type IMessageRpcError = {
|
export type IMessageRpcError = {
|
||||||
code?: number;
|
code?: number;
|
||||||
|
|
@ -149,8 +150,7 @@ export class IMessageRpcClient {
|
||||||
params: params ?? {},
|
params: params ?? {},
|
||||||
};
|
};
|
||||||
const line = `${JSON.stringify(payload)}\n`;
|
const line = `${JSON.stringify(payload)}\n`;
|
||||||
// Default timeout matches DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS from probe.ts
|
const timeoutMs = opts?.timeoutMs ?? DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS;
|
||||||
const timeoutMs = opts?.timeoutMs ?? 10_000;
|
|
||||||
|
|
||||||
const response = new Promise<T>((resolve, reject) => {
|
const response = new Promise<T>((resolve, reject) => {
|
||||||
const key = String(id);
|
const key = String(id);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
/** Default timeout for iMessage probe/RPC operations (10 seconds). */
|
||||||
|
export const DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS = 10_000;
|
||||||
|
|
@ -45,7 +45,8 @@ import { resolveAgentRoute } from "../../routing/resolve-route.js";
|
||||||
import { truncateUtf16Safe } from "../../utils.js";
|
import { truncateUtf16Safe } from "../../utils.js";
|
||||||
import { resolveIMessageAccount } from "../accounts.js";
|
import { resolveIMessageAccount } from "../accounts.js";
|
||||||
import { createIMessageRpcClient } from "../client.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 { sendMessageIMessage } from "../send.js";
|
||||||
import {
|
import {
|
||||||
formatIMessageChatTarget,
|
formatIMessageChatTarget,
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ import { detectBinary } from "../commands/onboard-helpers.js";
|
||||||
import { loadConfig } from "../config/config.js";
|
import { loadConfig } from "../config/config.js";
|
||||||
import { runCommandWithTimeout } from "../process/exec.js";
|
import { runCommandWithTimeout } from "../process/exec.js";
|
||||||
import { createIMessageRpcClient } from "./client.js";
|
import { createIMessageRpcClient } from "./client.js";
|
||||||
|
import { DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS } from "./constants.js";
|
||||||
|
|
||||||
/** Default timeout for iMessage probe operations (10 seconds). */
|
// Re-export for backwards compatibility
|
||||||
export const DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS = 10_000;
|
export { DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS } from "./constants.js";
|
||||||
|
|
||||||
export type IMessageProbe = {
|
export type IMessageProbe = {
|
||||||
ok: boolean;
|
ok: boolean;
|
||||||
|
|
@ -59,18 +60,21 @@ async function probeRpcSupport(cliPath: string, timeoutMs: number): Promise<RpcS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Probe iMessage RPC availability.
|
||||||
|
* @param timeoutMs - Explicit timeout in ms. If undefined, uses config or default.
|
||||||
|
* @param opts - Additional options (cliPath, dbPath, runtime).
|
||||||
|
*/
|
||||||
export async function probeIMessage(
|
export async function probeIMessage(
|
||||||
timeoutMs = DEFAULT_IMESSAGE_PROBE_TIMEOUT_MS,
|
timeoutMs?: number,
|
||||||
opts: IMessageProbeOptions = {},
|
opts: IMessageProbeOptions = {},
|
||||||
): Promise<IMessageProbe> {
|
): Promise<IMessageProbe> {
|
||||||
const cfg = opts.cliPath || opts.dbPath ? undefined : loadConfig();
|
const cfg = opts.cliPath || opts.dbPath ? undefined : loadConfig();
|
||||||
const cliPath = opts.cliPath?.trim() || cfg?.channels?.imessage?.cliPath?.trim() || "imsg";
|
const cliPath = opts.cliPath?.trim() || cfg?.channels?.imessage?.cliPath?.trim() || "imsg";
|
||||||
const dbPath = opts.dbPath?.trim() || cfg?.channels?.imessage?.dbPath?.trim();
|
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 =
|
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);
|
const detected = await detectBinary(cliPath);
|
||||||
if (!detected) {
|
if (!detected) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue