feat: add outbound attachment support with media.send tool

Introduces OutboundAttachment type on OutboundMessage, an
OutboundAttachmentCollector (push/drain pattern), and a media.send
tool that queues files for outbound delivery. Each channel adapter
(Telegram, Discord, Slack, WhatsApp) sends attachments after the
text reply. Includes 15 tests for collector and tool.
This commit is contained in:
William Valentin
2026-02-07 09:09:00 -08:00
parent 1e6f6bb5a4
commit b9bfee9c5b
15 changed files with 576 additions and 21 deletions
+13
View File
@@ -6,6 +6,7 @@ import type { ToolExecutor } from '../../tools/executor.js';
import type { ToolResult } from '../../tools/types.js';
import type { ToolPolicyContext } from '../../tools/policy.js';
import type { Attachment } from '../../channels/types.js';
import type { OutboundAttachmentCollector } from './attachments.js';
import { buildUserMessage, getMessageText } from '../../models/media.js';
export interface ToolUseEvent {
@@ -25,6 +26,8 @@ export interface NativeAgentConfig {
onToolUse?: (event: ToolUseEvent) => void;
/** Policy context for tool filtering (agent tier, provider). */
toolPolicyContext?: ToolPolicyContext;
/** Collector for outbound attachments queued by tools (e.g. media.send). */
attachmentCollector?: OutboundAttachmentCollector;
}
// Internal message type for the tool loop — supports both text and structured content blocks.
@@ -47,6 +50,7 @@ export class NativeAgent {
private _totalUsage: TokenUsage = { inputTokens: 0, outputTokens: 0 };
private _callCount: number = 0;
private _toolPolicyContext?: ToolPolicyContext;
private _attachmentCollector?: OutboundAttachmentCollector;
constructor(config: NativeAgentConfig) {
this.modelClient = config.modelClient;
@@ -57,6 +61,7 @@ export class NativeAgent {
this.maxIterations = config.maxIterations ?? 10;
this.onToolUse = config.onToolUse;
this._toolPolicyContext = config.toolPolicyContext;
this._attachmentCollector = config.attachmentCollector;
}
private get history(): Message[] {
@@ -241,4 +246,12 @@ export class NativeAgent {
getToolPolicyContext(): ToolPolicyContext | undefined {
return this._toolPolicyContext;
}
setAttachmentCollector(collector: OutboundAttachmentCollector | undefined): void {
this._attachmentCollector = collector;
}
getAttachmentCollector(): OutboundAttachmentCollector | undefined {
return this._attachmentCollector;
}
}