mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
refactor(channels): share threading tool context
This commit is contained in:
@@ -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<string | number>) =>
|
||||
.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<ChatChannelId, ChannelDock> = {
|
||||
.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<ChatChannelId, ChannelDock> = {
|
||||
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 }),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user