openclaw-vainplex/src/agents/tools
Tyler Yust 0f662c2935
fix(bluebubbles): route phone-number targets to direct chats; prevent internal IDs leaking in cross-context prefix (#1751)
* fix(bluebubbles): prefer DM resolution + hide routing markers

* fix(bluebubbles): prevent message routing to group chats when targeting phone numbers

When sending a message to a phone number like +12622102921, the
resolveChatGuidForTarget function was finding and returning a GROUP
CHAT containing that phone number instead of a direct DM chat.

The bug was in the participantMatch fallback logic which matched ANY
chat containing the phone number as a participant, including groups.

This fix adds a check to ensure participantMatch only considers DM
chats (identified by ';-;' separator in the chat GUID). Group chats
(identified by ';+;' separator) are now explicitly excluded from
handle-based matching.

If a phone number only exists in a group chat (no direct DM exists),
the function now correctly returns null, which causes the send to
fail with a clear error rather than accidentally messaging a group.

Added test case to verify this behavior.

* feat(bluebubbles): auto-create new DM chats when sending to unknown phone numbers

When sending to a phone number that doesn't have an existing chat,
instead of failing with 'chatGuid not found', now automatically creates
a new chat using the /api/v1/chat/new endpoint.

- Added createNewChatWithMessage() helper function
- When resolveChatGuidForTarget returns null for a handle target,
  uses the new chat endpoint with addresses array and message
- Includes helpful error message if Private API isn't enabled
- Only applies to handle targets (phone numbers), not group chats

* fix(bluebubbles): hide internal routing metadata in cross-context markers

When sending cross-context messages via BlueBubbles, the origin marker was
exposing internal chat_guid routing info like '[from bluebubbles:chat_guid:any;-;+19257864429]'.

This adds a formatTargetDisplay() function to the BlueBubbles plugin that:
- Extracts phone numbers from chat_guid formats (iMessage;-;+1234567890 -> +1234567890)
- Normalizes handles for clean display
- Avoids returning raw chat_guid formats containing internal routing metadata

Now cross-context markers show clean identifiers like '[from +19257864429]' instead
of exposing internal routing details to recipients.

* fix: prevent cross-context decoration on direct message tool sends

Two fixes:

1. Cross-context decoration (e.g., '[from +19257864429]' prefix) was being
   added to ALL messages sent to a different target, even when the agent
   was just composing a new message via the message tool. This decoration
   should only be applied when forwarding/relaying messages between chats.

   Fix: Added skipCrossContextDecoration flag to ChannelThreadingToolContext.
   The message tool now sets this flag to true, so direct sends don't get
   decorated. The buildCrossContextDecoration function checks this flag
   and returns null when set.

2. Aborted requests were still completing because the abort signal wasn't
   being passed through the message tool execution chain.

   Fix: Added abortSignal propagation from message tool → runMessageAction →
   executeSendAction → sendMessage → deliverOutboundPayloads. Added abort
   checks at key points in the chain to fail fast when aborted.

Files changed:
- src/channels/plugins/types.core.ts: Added skipCrossContextDecoration field
- src/infra/outbound/outbound-policy.ts: Check skip flag before decorating
- src/agents/tools/message-tool.ts: Set skip flag, accept and pass abort signal
- src/infra/outbound/message-action-runner.ts: Pass abort signal through
- src/infra/outbound/outbound-send-service.ts: Check and pass abort signal
- src/infra/outbound/message.ts: Pass abort signal to delivery

* fix(bluebubbles): preserve friendly display names in formatTargetDisplay
2026-01-25 10:03:08 +00:00
..
agent-step.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
agents-list-tool.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
browser-tool.schema.ts feat: add node browser proxy routing 2026-01-24 04:21:47 +00:00
browser-tool.test.ts feat: add node browser proxy routing 2026-01-24 04:21:47 +00:00
browser-tool.ts feat: add node browser proxy routing 2026-01-24 04:21:47 +00:00
canvas-tool.ts style: run oxfmt 2026-01-16 21:11:55 +00:00
common.test.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
common.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
cron-tool.test.ts Merge origin/main into fix-discord-accountId 2026-01-23 09:15:44 +00:00
cron-tool.ts fix: honor accountId in message actions 2026-01-23 09:06:04 +00:00
discord-actions-guild.ts fix: honor accountId in message actions 2026-01-23 09:06:04 +00:00
discord-actions-messaging.ts fix: honor accountId in message actions 2026-01-23 09:06:04 +00:00
discord-actions-moderation.ts fix: honor accountId in message actions 2026-01-23 09:06:04 +00:00
discord-actions.test.ts fix: stabilize ci tests 2026-01-23 09:52:22 +00:00
discord-actions.ts refactor!: rename chat providers to channels 2026-01-13 08:40:39 +00:00
gateway-tool.ts fix: follow up config.patch restarts/docs/tests (#1653) 2026-01-24 23:33:13 +00:00
gateway.test.ts chore: changelog for #293 2026-01-06 15:32:06 +01:00
gateway.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
image-tool.helpers.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
image-tool.test.ts fix: resolve ci failures 2026-01-18 08:45:29 +00:00
image-tool.ts refactor: add aws-sdk auth mode and tighten provider auth 2026-01-20 08:28:40 +00:00
memory-tool.does-not-crash-on-errors.test.ts style: oxfmt 2026-01-17 10:26:08 +00:00
memory-tool.ts feat: add experimental session memory source 2026-01-17 18:53:52 +00:00
message-tool.test.ts fix: normalize session keys and outbound mirroring 2026-01-24 11:57:11 +00:00
message-tool.ts fix(bluebubbles): route phone-number targets to direct chats; prevent internal IDs leaking in cross-context prefix (#1751) 2026-01-25 10:03:08 +00:00
nodes-tool.ts fix: add node tool failure context 2026-01-21 09:55:10 +00:00
nodes-utils.ts feat: add node core/ui versions in bridge 2026-01-18 15:59:54 +00:00
session-status-tool.ts fix: resolve session ids in session tools 2026-01-24 11:09:11 +00:00
sessions-announce-target.test.ts refactor: route channel runtime via plugin api 2026-01-18 11:01:16 +00:00
sessions-announce-target.ts fix: normalize delivery routing context 2026-01-17 06:38:33 +00:00
sessions-helpers.test.ts fix: sanitize assistant session text (#1456) (thanks @zerone0x) 2026-01-23 07:05:31 +00:00
sessions-helpers.ts fix: resolve session ids in session tools 2026-01-24 11:09:11 +00:00
sessions-history-tool.ts fix: resolve session ids in session tools 2026-01-24 11:09:11 +00:00
sessions-list-tool.gating.test.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
sessions-list-tool.ts fix: resolve session ids in session tools 2026-01-24 11:09:11 +00:00
sessions-send-helpers.ts style: format code 2026-01-18 19:36:46 +00:00
sessions-send-tool.a2a.ts refactor(logging): split config + subsystem imports 2026-01-19 00:15:44 +00:00
sessions-send-tool.gating.test.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
sessions-send-tool.ts fix: resolve session ids in session tools 2026-01-24 11:09:11 +00:00
sessions-spawn-tool.ts fix: enforce group tool policy inheritance for subagents (#1557) (thanks @adam91holt) 2026-01-24 05:49:39 +00:00
slack-actions.test.ts fix: read Slack thread replies for message reads (#1450) (#1450) 2026-01-23 04:17:45 +00:00
slack-actions.ts fix: read Slack thread replies for message reads (#1450) (#1450) 2026-01-23 04:17:45 +00:00
telegram-actions.test.ts test: cover tg/group/topic inline button targets (#1072) — thanks @danielz1z 2026-01-17 08:00:16 +00:00
telegram-actions.ts feat(telegram): support sending audio as native voice notes via asVoice param in message tool 2026-01-17 17:32:50 +00:00
tts-tool.ts feat: move TTS into core (#1559) (thanks @Glucksberg) 2026-01-24 08:00:44 +00:00
web-fetch-utils.ts fix: add readability fallback extraction 2026-01-24 02:15:13 +00:00
web-fetch.ssrf.test.ts fix: harden web fetch SSRF and redirects 2026-01-21 02:54:14 +00:00
web-fetch.ts fix: harden web fetch SSRF and redirects 2026-01-21 02:54:14 +00:00
web-search.test.ts fix: validate web_search freshness (#1688) (thanks @JonUleis) 2026-01-25 04:23:25 +00:00
web-search.ts fix: validate web_search freshness (#1688) (thanks @JonUleis) 2026-01-25 04:23:25 +00:00
web-shared.ts style: apply oxfmt 2026-01-18 02:19:35 +00:00
web-tools.enabled-defaults.test.ts fix: validate web_search freshness (#1688) (thanks @JonUleis) 2026-01-25 04:23:25 +00:00
web-tools.fetch.test.ts Web: trim HTML error bodies in web_fetch (#1193) 2026-01-19 00:24:16 +00:00
web-tools.readability.test.ts feat: improve web_fetch readability extraction 2026-01-16 23:18:01 +00:00
web-tools.ts refactor: split web tools and docs 2026-01-18 01:42:54 +00:00
whatsapp-actions.test.ts refactor: route channel runtime via plugin api 2026-01-18 11:01:16 +00:00
whatsapp-actions.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00