fix: propagate agent run context for subagent announce
This commit is contained in:
18
src/commands/agent/run-context.ts
Normal file
18
src/commands/agent/run-context.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { normalizeAccountId } from "../../utils/account-id.js";
|
||||
import { resolveMessageChannel } from "../../utils/message-channel.js";
|
||||
import type { AgentCommandOpts, AgentRunContext } from "./types.js";
|
||||
|
||||
export function resolveAgentRunContext(opts: AgentCommandOpts): AgentRunContext {
|
||||
const merged: AgentRunContext = opts.runContext ? { ...opts.runContext } : {};
|
||||
|
||||
const normalizedChannel = resolveMessageChannel(
|
||||
merged.messageChannel ?? opts.messageChannel,
|
||||
opts.replyChannel ?? opts.channel,
|
||||
);
|
||||
if (normalizedChannel) merged.messageChannel = normalizedChannel;
|
||||
|
||||
const normalizedAccountId = normalizeAccountId(merged.accountId ?? opts.accountId);
|
||||
if (normalizedAccountId) merged.accountId = normalizedAccountId;
|
||||
|
||||
return merged;
|
||||
}
|
||||
@@ -7,6 +7,15 @@ export type ImageContent = {
|
||||
mimeType: string;
|
||||
};
|
||||
|
||||
export type AgentRunContext = {
|
||||
messageChannel?: string;
|
||||
accountId?: string;
|
||||
currentChannelId?: string;
|
||||
currentThreadTs?: string;
|
||||
replyToMode?: "off" | "first" | "all";
|
||||
hasRepliedRef?: { value: boolean };
|
||||
};
|
||||
|
||||
export type AgentCommandOpts = {
|
||||
message: string;
|
||||
/** Optional image attachments for multimodal messages. */
|
||||
@@ -33,6 +42,8 @@ export type AgentCommandOpts = {
|
||||
channel?: string; // delivery channel (whatsapp|telegram|...)
|
||||
/** Account ID for multi-account channel routing (e.g., WhatsApp account). */
|
||||
accountId?: string;
|
||||
/** Context for embedded run routing (channel/account/thread). */
|
||||
runContext?: AgentRunContext;
|
||||
deliveryTargetMode?: ChannelOutboundTargetMode;
|
||||
bestEffortDeliver?: boolean;
|
||||
abortSignal?: AbortSignal;
|
||||
|
||||
Reference in New Issue
Block a user