From d9c891eb90aebb845949045a1cb25427c61fea95 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 18:30:34 +0000 Subject: [PATCH] refactor(channels): share threading tool context --- src/channels/dock.ts | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/channels/dock.ts b/src/channels/dock.ts index e0aec226964..fa872a21620 100644 --- a/src/channels/dock.ts +++ b/src/channels/dock.ts @@ -8,7 +8,9 @@ import type { ChannelAgentPromptAdapter, ChannelMentionAdapter, ChannelPlugin, + ChannelThreadingContext, ChannelThreadingAdapter, + ChannelThreadingToolContext, } from "./plugins/types.js"; import { resolveChannelGroupRequireMention, @@ -79,6 +81,21 @@ const formatLower = (allowFrom: Array) => .map((entry) => String(entry).trim()) .filter(Boolean) .map((entry) => entry.toLowerCase()); + +function buildDirectOrGroupThreadToolContext(params: { + context: ChannelThreadingContext; + hasRepliedRef: ChannelThreadingToolContext["hasRepliedRef"]; +}): ChannelThreadingToolContext { + const isDirect = params.context.ChatType?.toLowerCase() === "direct"; + const channelId = + (isDirect ? (params.context.From ?? params.context.To) : params.context.To)?.trim() || + undefined; + return { + currentChannelId: channelId, + currentThreadTs: params.context.ReplyToId, + hasRepliedRef: params.hasRepliedRef, + }; +} // Channel docks: lightweight channel metadata/behavior for shared code paths. // // Rules: @@ -404,16 +421,8 @@ const DOCKS: Record = { .filter(Boolean), }, threading: { - buildToolContext: ({ context, hasRepliedRef }) => { - const isDirect = context.ChatType?.toLowerCase() === "direct"; - const channelId = - (isDirect ? (context.From ?? context.To) : context.To)?.trim() || undefined; - return { - currentChannelId: channelId, - currentThreadTs: context.ReplyToId, - hasRepliedRef, - }; - }, + buildToolContext: ({ context, hasRepliedRef }) => + buildDirectOrGroupThreadToolContext({ context, hasRepliedRef }), }, }, imessage: { @@ -437,16 +446,8 @@ const DOCKS: Record = { resolveToolPolicy: resolveIMessageGroupToolPolicy, }, threading: { - buildToolContext: ({ context, hasRepliedRef }) => { - const isDirect = context.ChatType?.toLowerCase() === "direct"; - const channelId = - (isDirect ? (context.From ?? context.To) : context.To)?.trim() || undefined; - return { - currentChannelId: channelId, - currentThreadTs: context.ReplyToId, - hasRepliedRef, - }; - }, + buildToolContext: ({ context, hasRepliedRef }) => + buildDirectOrGroupThreadToolContext({ context, hasRepliedRef }), }, }, };