mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 10:41:25 +00:00
feat: enhance BlueBubbles message actions with support for message editing, reply metadata, and improved effect handling
This commit is contained in:
committed by
Peter Steinberger
parent
2e6c58bf75
commit
574b848863
@@ -1,6 +1,9 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { MessageActionRunResult } from "../../infra/outbound/message-action-runner.js";
|
||||
import { setActivePluginRegistry } from "../../plugins/runtime.js";
|
||||
import type { ChannelPlugin } from "../../channels/plugins/types.js";
|
||||
import { createTestRegistry } from "../../test-utils/channel-plugins.js";
|
||||
import { createMessageTool } from "./message-tool.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
@@ -82,3 +85,59 @@ describe("message tool mirroring", () => {
|
||||
expect(mocks.appendAssistantMessageToSessionTranscript).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("message tool description", () => {
|
||||
const bluebubblesPlugin: ChannelPlugin = {
|
||||
id: "bluebubbles",
|
||||
meta: {
|
||||
id: "bluebubbles",
|
||||
label: "BlueBubbles",
|
||||
selectionLabel: "BlueBubbles",
|
||||
docsPath: "/channels/bluebubbles",
|
||||
blurb: "BlueBubbles test plugin.",
|
||||
},
|
||||
capabilities: { chatTypes: ["direct", "group"], media: true },
|
||||
config: {
|
||||
listAccountIds: () => ["default"],
|
||||
resolveAccount: () => ({}),
|
||||
},
|
||||
messaging: {
|
||||
normalizeTarget: (raw) => {
|
||||
const trimmed = raw.trim().replace(/^bluebubbles:/i, "");
|
||||
const lower = trimmed.toLowerCase();
|
||||
if (lower.startsWith("chat_guid:")) {
|
||||
const guid = trimmed.slice("chat_guid:".length);
|
||||
const parts = guid.split(";");
|
||||
if (parts.length === 3 && parts[1] === "-") {
|
||||
return parts[2]?.trim() || trimmed;
|
||||
}
|
||||
return `chat_guid:${guid}`;
|
||||
}
|
||||
return trimmed;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
listActions: () =>
|
||||
["react", "renameGroup", "addParticipant", "removeParticipant", "leaveGroup"] as const,
|
||||
},
|
||||
};
|
||||
|
||||
it("hides BlueBubbles group actions for DM targets", () => {
|
||||
setActivePluginRegistry(
|
||||
createTestRegistry([{ pluginId: "bluebubbles", source: "test", plugin: bluebubblesPlugin }]),
|
||||
);
|
||||
|
||||
const tool = createMessageTool({
|
||||
config: {} as never,
|
||||
currentChannelProvider: "bluebubbles",
|
||||
currentChannelId: "bluebubbles:chat_guid:iMessage;-;+15551234567",
|
||||
});
|
||||
|
||||
expect(tool.description).not.toContain("renameGroup");
|
||||
expect(tool.description).not.toContain("addParticipant");
|
||||
expect(tool.description).not.toContain("removeParticipant");
|
||||
expect(tool.description).not.toContain("leaveGroup");
|
||||
|
||||
setActivePluginRegistry(createTestRegistry([]));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,15 +14,23 @@ import {
|
||||
resolveMirroredTranscriptText,
|
||||
} from "../../config/sessions.js";
|
||||
import { GATEWAY_CLIENT_IDS, GATEWAY_CLIENT_MODES } from "../../gateway/protocol/client-info.js";
|
||||
import { normalizeTargetForProvider } from "../../infra/outbound/target-normalization.js";
|
||||
import { getToolResult, runMessageAction } from "../../infra/outbound/message-action-runner.js";
|
||||
import { resolveSessionAgentId } from "../agent-scope.js";
|
||||
import { normalizeAccountId } from "../../routing/session-key.js";
|
||||
import { channelTargetSchema, channelTargetsSchema, stringEnum } from "../schema/typebox.js";
|
||||
import { listChannelSupportedActions } from "../channel-tools.js";
|
||||
import { normalizeMessageChannel } from "../../utils/message-channel.js";
|
||||
import type { AnyAgentTool } from "./common.js";
|
||||
import { jsonResult, readNumberParam, readStringParam } from "./common.js";
|
||||
|
||||
const AllMessageActions = CHANNEL_MESSAGE_ACTION_NAMES;
|
||||
const BLUEBUBBLES_GROUP_ACTIONS = new Set<ChannelMessageActionName>([
|
||||
"renameGroup",
|
||||
"addParticipant",
|
||||
"removeParticipant",
|
||||
"leaveGroup",
|
||||
]);
|
||||
|
||||
function buildRoutingSchema() {
|
||||
return {
|
||||
@@ -37,7 +45,26 @@ function buildRoutingSchema() {
|
||||
function buildSendSchema(options: { includeButtons: boolean }) {
|
||||
const props: Record<string, unknown> = {
|
||||
message: Type.Optional(Type.String()),
|
||||
effectId: Type.Optional(
|
||||
Type.String({
|
||||
description: "Message effect name/id for sendWithEffect (e.g., invisible ink).",
|
||||
}),
|
||||
),
|
||||
effect: Type.Optional(
|
||||
Type.String({ description: "Alias for effectId (e.g., invisible-ink, balloons)." }),
|
||||
),
|
||||
media: Type.Optional(Type.String()),
|
||||
filename: Type.Optional(Type.String()),
|
||||
buffer: Type.Optional(
|
||||
Type.String({
|
||||
description: "Base64 payload for attachments (optionally a data: URL).",
|
||||
}),
|
||||
),
|
||||
contentType: Type.Optional(Type.String()),
|
||||
mimeType: Type.Optional(Type.String()),
|
||||
caption: Type.Optional(Type.String()),
|
||||
path: Type.Optional(Type.String()),
|
||||
filePath: Type.Optional(Type.String()),
|
||||
replyTo: Type.Optional(Type.String()),
|
||||
threadId: Type.Optional(Type.String()),
|
||||
asVoice: Type.Optional(Type.Boolean()),
|
||||
@@ -228,17 +255,43 @@ function resolveAgentAccountId(value?: string): string | undefined {
|
||||
return normalizeAccountId(trimmed);
|
||||
}
|
||||
|
||||
function filterActionsForContext(params: {
|
||||
actions: ChannelMessageActionName[];
|
||||
channel?: string;
|
||||
currentChannelId?: string;
|
||||
}): ChannelMessageActionName[] {
|
||||
const channel = normalizeMessageChannel(params.channel);
|
||||
if (!channel || channel !== "bluebubbles") return params.actions;
|
||||
const currentChannelId = params.currentChannelId?.trim();
|
||||
if (!currentChannelId) return params.actions;
|
||||
const normalizedTarget =
|
||||
normalizeTargetForProvider(channel, currentChannelId) ?? currentChannelId;
|
||||
const lowered = normalizedTarget.trim().toLowerCase();
|
||||
const isGroupTarget =
|
||||
lowered.startsWith("chat_guid:") ||
|
||||
lowered.startsWith("chat_id:") ||
|
||||
lowered.startsWith("chat_identifier:") ||
|
||||
lowered.startsWith("group:");
|
||||
if (isGroupTarget) return params.actions;
|
||||
return params.actions.filter((action) => !BLUEBUBBLES_GROUP_ACTIONS.has(action));
|
||||
}
|
||||
|
||||
function buildMessageToolDescription(options?: {
|
||||
config?: ClawdbotConfig;
|
||||
currentChannel?: string;
|
||||
currentChannelId?: string;
|
||||
}): string {
|
||||
const baseDescription = "Send, delete, and manage messages via channel plugins.";
|
||||
|
||||
// If we have a current channel, show only its supported actions
|
||||
if (options?.currentChannel) {
|
||||
const channelActions = listChannelSupportedActions({
|
||||
cfg: options.config,
|
||||
const channelActions = filterActionsForContext({
|
||||
actions: listChannelSupportedActions({
|
||||
cfg: options.config,
|
||||
channel: options.currentChannel,
|
||||
}),
|
||||
channel: options.currentChannel,
|
||||
currentChannelId: options.currentChannelId,
|
||||
});
|
||||
if (channelActions.length > 0) {
|
||||
// Always include "send" as a base action
|
||||
@@ -265,6 +318,7 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
|
||||
const description = buildMessageToolDescription({
|
||||
config: options?.config,
|
||||
currentChannel: options?.currentChannelProvider,
|
||||
currentChannelId: options?.currentChannelId,
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user