mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 17:24:58 +00:00
refactor(channels): share threading tool context
This commit is contained in:
@@ -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,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user