From cc89e155c35b728e53a57ccfd075b2821aaa1866 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 22 Jun 2026 13:55:36 +0800 Subject: [PATCH] refactor(imessage): share direct chat normalization --- extensions/imessage/src/actions.runtime.ts | 18 +++++------------- extensions/imessage/src/monitor-reply-cache.ts | 2 +- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/extensions/imessage/src/actions.runtime.ts b/extensions/imessage/src/actions.runtime.ts index 02d9ae798333..a5743323fecc 100644 --- a/extensions/imessage/src/actions.runtime.ts +++ b/extensions/imessage/src/actions.runtime.ts @@ -12,7 +12,10 @@ import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path"; import { appendIMessageCliStderrTail, appendIMessageCliStdout } from "./cli-output.js"; import { createIMessageRpcClient } from "./client.js"; import { extractMarkdownFormatRuns } from "./markdown-format.js"; -import { resolveIMessageMessageId as resolveIMessageMessageIdImpl } from "./monitor-reply-cache.js"; +import { + normalizeDirectChatIdentifier, + resolveIMessageMessageId as resolveIMessageMessageIdImpl, +} from "./monitor-reply-cache.js"; import type { IMessageTarget } from "./targets.js"; type CliRunOptions = { @@ -115,7 +118,7 @@ function chatListCacheSet( * forms — the action surface synthesizes `iMessage;-;` from a * handle target, while imsg's chats.list returns `identifier: ` * and `guid: any;-;`. Comparing the raw strings would falsely - * miss the match. Mirror of the same helper in monitor-reply-cache.ts. + * miss the match. */ export function normalizeDirectChatIdentifierForTest(raw: string): string { return normalizeDirectChatIdentifier(raw); @@ -128,17 +131,6 @@ export function findChatGuidForTest( return findChatGuid(chats, target); } -function normalizeDirectChatIdentifier(raw: string): string { - const trimmed = raw.trim(); - const lowered = trimmed.toLowerCase(); - for (const prefix of ["imessage;-;", "sms;-;", "any;-;"]) { - if (lowered.startsWith(prefix)) { - return trimmed.slice(prefix.length); - } - } - return trimmed; -} - function findChatGuid( chats: readonly Record[], target: Extract, diff --git a/extensions/imessage/src/monitor-reply-cache.ts b/extensions/imessage/src/monitor-reply-cache.ts index 4fee594126ed..78ae44a422f8 100644 --- a/extensions/imessage/src/monitor-reply-cache.ts +++ b/extensions/imessage/src/monitor-reply-cache.ts @@ -256,7 +256,7 @@ function hasChatScope(ctx?: IMessageChatContext): boolean { * so comparing the raw strings would falsely flag the same chat as a * cross-chat target. Normalize both sides to the bare suffix. */ -function normalizeDirectChatIdentifier(raw: string): string { +export function normalizeDirectChatIdentifier(raw: string): string { const trimmed = raw.trim(); const lowered = trimmed.toLowerCase(); for (const prefix of ["imessage;-;", "sms;-;", "any;-;"]) {