fix(discord): add media dedup production code for messaging tool pipeline

Wire media URL tracking through the embedded agent pipeline so that
media already sent via messaging tools is not delivered again by the
reply dispatcher.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Yaroslav Boiko
2026-02-16 20:41:41 +01:00
committed by Peter Steinberger
parent c7681c3cff
commit 838259331f
14 changed files with 244 additions and 4 deletions

View File

@@ -70,9 +70,11 @@ export type EmbeddedPiSubscribeState = {
messagingToolSentTexts: string[];
messagingToolSentTextsNormalized: string[];
messagingToolSentTargets: MessagingToolSend[];
messagingToolSentMediaUrls: string[];
pendingMessagingTexts: Map<string, string>;
pendingMessagingTargets: Map<string, MessagingToolSend>;
successfulCronAdds: number;
pendingMessagingMediaUrls: Map<string, string>;
lastAssistant?: AgentMessage;
};
@@ -122,6 +124,44 @@ export type EmbeddedPiSubscribeContext = {
getCompactionCount: () => number;
};
/**
* Minimal context type for tool execution handlers. Allows
* tests provide only the fields they exercise
* without needing the full `EmbeddedPiSubscribeContext`.
*/
export type ToolHandlerParams = Pick<
SubscribeEmbeddedPiSessionParams,
"runId" | "onBlockReplyFlush" | "onAgentEvent" | "onToolResult"
>;
export type ToolHandlerState = Pick<
EmbeddedPiSubscribeState,
| "toolMetaById"
| "toolMetas"
| "toolSummaryById"
| "lastToolError"
| "pendingMessagingTargets"
| "pendingMessagingTexts"
| "pendingMessagingMediaUrls"
| "messagingToolSentTexts"
| "messagingToolSentTextsNormalized"
| "messagingToolSentMediaUrls"
| "messagingToolSentTargets"
>;
export type ToolHandlerContext = {
params: ToolHandlerParams;
state: ToolHandlerState;
log: EmbeddedSubscribeLogger;
hookRunner?: HookRunner;
flushBlockReplyBuffer: () => void;
shouldEmitToolResult: () => boolean;
shouldEmitToolOutput: () => boolean;
emitToolSummary: (toolName?: string, meta?: string) => void;
emitToolOutput: (toolName?: string, meta?: string, output?: string) => void;
trimMessagingToolSent: () => void;
};
export type EmbeddedPiSubscribeEvent =
| AgentEvent
| { type: string; [k: string]: unknown }