refactor(channels): share threading tool context

This commit is contained in:
Peter Steinberger
2026-02-15 18:30:34 +00:00
parent b2d8b95906
commit d9c891eb90

View File

@@ -8,7 +8,9 @@ import type {
ChannelAgentPromptAdapter, ChannelAgentPromptAdapter,
ChannelMentionAdapter, ChannelMentionAdapter,
ChannelPlugin, ChannelPlugin,
ChannelThreadingContext,
ChannelThreadingAdapter, ChannelThreadingAdapter,
ChannelThreadingToolContext,
} from "./plugins/types.js"; } from "./plugins/types.js";
import { import {
resolveChannelGroupRequireMention, resolveChannelGroupRequireMention,
@@ -79,6 +81,21 @@ const formatLower = (allowFrom: Array<string | number>) =>
.map((entry) => String(entry).trim()) .map((entry) => String(entry).trim())
.filter(Boolean) .filter(Boolean)
.map((entry) => entry.toLowerCase()); .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. // Channel docks: lightweight channel metadata/behavior for shared code paths.
// //
// Rules: // Rules:
@@ -404,16 +421,8 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
.filter(Boolean), .filter(Boolean),
}, },
threading: { threading: {
buildToolContext: ({ context, hasRepliedRef }) => { buildToolContext: ({ context, hasRepliedRef }) =>
const isDirect = context.ChatType?.toLowerCase() === "direct"; buildDirectOrGroupThreadToolContext({ context, hasRepliedRef }),
const channelId =
(isDirect ? (context.From ?? context.To) : context.To)?.trim() || undefined;
return {
currentChannelId: channelId,
currentThreadTs: context.ReplyToId,
hasRepliedRef,
};
},
}, },
}, },
imessage: { imessage: {
@@ -437,16 +446,8 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
resolveToolPolicy: resolveIMessageGroupToolPolicy, resolveToolPolicy: resolveIMessageGroupToolPolicy,
}, },
threading: { threading: {
buildToolContext: ({ context, hasRepliedRef }) => { buildToolContext: ({ context, hasRepliedRef }) =>
const isDirect = context.ChatType?.toLowerCase() === "direct"; buildDirectOrGroupThreadToolContext({ context, hasRepliedRef }),
const channelId =
(isDirect ? (context.From ?? context.To) : context.To)?.trim() || undefined;
return {
currentChannelId: channelId,
currentThreadTs: context.ReplyToId,
hasRepliedRef,
};
},
}, },
}, },
}; };