Agents: honor message channel for tool dedupe
This commit is contained in:
parent
026cf1130e
commit
2ee54fee41
30
src/agents/pi-embedded-subscribe.tools.test.ts
Normal file
30
src/agents/pi-embedded-subscribe.tools.test.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { extractMessagingToolSend } from "./pi-embedded-subscribe.tools.js";
|
||||||
|
|
||||||
|
describe("extractMessagingToolSend", () => {
|
||||||
|
it("uses channel as provider for message tool", () => {
|
||||||
|
const result = extractMessagingToolSend("message", {
|
||||||
|
action: "send",
|
||||||
|
channel: "telegram",
|
||||||
|
to: "123",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result?.tool).toBe("message");
|
||||||
|
expect(result?.provider).toBe("telegram");
|
||||||
|
expect(result?.to).toBe("telegram:123");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prefers provider when both provider and channel are set", () => {
|
||||||
|
const result = extractMessagingToolSend("message", {
|
||||||
|
action: "send",
|
||||||
|
provider: "slack",
|
||||||
|
channel: "telegram",
|
||||||
|
to: "channel:C1",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result?.tool).toBe("message");
|
||||||
|
expect(result?.provider).toBe("slack");
|
||||||
|
expect(result?.to).toBe("channel:c1");
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -57,8 +57,10 @@ export function extractMessagingToolSend(
|
|||||||
const toRaw = typeof args.to === "string" ? args.to : undefined;
|
const toRaw = typeof args.to === "string" ? args.to : undefined;
|
||||||
if (!toRaw) return undefined;
|
if (!toRaw) return undefined;
|
||||||
const providerRaw = typeof args.provider === "string" ? args.provider.trim() : "";
|
const providerRaw = typeof args.provider === "string" ? args.provider.trim() : "";
|
||||||
const providerId = providerRaw ? normalizeChannelId(providerRaw) : null;
|
const channelRaw = typeof args.channel === "string" ? args.channel.trim() : "";
|
||||||
const provider = providerId ?? (providerRaw ? providerRaw.toLowerCase() : "message");
|
const providerHint = providerRaw || channelRaw;
|
||||||
|
const providerId = providerHint ? normalizeChannelId(providerHint) : null;
|
||||||
|
const provider = providerId ?? (providerHint ? providerHint.toLowerCase() : "message");
|
||||||
const to = normalizeTargetForProvider(provider, toRaw);
|
const to = normalizeTargetForProvider(provider, toRaw);
|
||||||
return to ? { tool: toolName, provider, accountId, to } : undefined;
|
return to ? { tool: toolName, provider, accountId, to } : undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user