Skip to content

Commit 928b593

Browse files
committed
fix(agents): track normalized message target evidence
1 parent 77a682c commit 928b593

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

src/agents/embedded-agent-subscribe.tools.extract.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,32 @@ describe("extractMessagingToolSend", () => {
248248
expect(result?.to).toBe("telegram:123");
249249
});
250250

251+
it("accepts channelId alias when earlier target aliases are blank", () => {
252+
const result = extractMessagingToolSend("message", {
253+
action: "send",
254+
channel: "telegram",
255+
target: " ",
256+
to: "",
257+
channelId: "123",
258+
});
259+
260+
expect(result?.tool).toBe("message");
261+
expect(result?.provider).toBe("telegram");
262+
expect(result?.to).toBe("telegram:123");
263+
});
264+
265+
it("prefers canonical target over legacy target aliases", () => {
266+
const result = extractMessagingToolSend("message", {
267+
action: "send",
268+
channel: "telegram",
269+
target: "123",
270+
to: "456",
271+
channelId: "789",
272+
});
273+
274+
expect(result?.to).toBe("telegram:123");
275+
});
276+
251277
it("recognizes attachment-style message tool sends", () => {
252278
const upload = extractMessagingToolSend("message", {
253279
action: "upload-file",

src/agents/embedded-agent-subscribe.tools.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -633,11 +633,11 @@ export function extractToolErrorMessage(result: unknown): string | undefined {
633633
}
634634

635635
function resolveMessageToolTarget(args: Record<string, unknown>): string | undefined {
636-
const toRaw = readStringValue(args.to);
637-
if (toRaw) {
638-
return toRaw;
639-
}
640-
return readStringValue(args.target);
636+
return (
637+
normalizeOptionalString(args.target) ??
638+
normalizeOptionalString(args.to) ??
639+
normalizeOptionalString(args.channelId)
640+
);
641641
}
642642

643643
function resolveMessagingToolThreadEvidence(params: {
@@ -744,7 +744,7 @@ export function extractMessagingToolSend(
744744
const providerId = providerHint ? normalizeChannelId(providerHint) : null;
745745
const provider = providerId ?? normalizeOptionalLowercaseString(providerHint) ?? "message";
746746
const to = normalizeTargetForProvider(provider, toRaw);
747-
const pluginExtractionArgs = readStringValue(args.to) ? args : { ...args, to: toRaw };
747+
const pluginExtractionArgs = { ...args, to: toRaw };
748748
const pluginExtracted = providerId
749749
? getChannelPlugin(providerId)?.actions?.extractToolSend?.({ args: pluginExtractionArgs })
750750
: null;

0 commit comments

Comments
 (0)