mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 00:58:28 +00:00
refactor(channels): share native command session targets
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveDiscordNativeCommandSessionTargets } from "./native-command-session-targets.js";
|
||||
|
||||
describe("resolveDiscordNativeCommandSessionTargets", () => {
|
||||
it("uses the bound session for both targets when present", () => {
|
||||
expect(
|
||||
resolveDiscordNativeCommandSessionTargets({
|
||||
boundSessionKey: "agent:codex:acp:binding:discord:default:seed",
|
||||
effectiveRoute: {
|
||||
agentId: "codex",
|
||||
sessionKey: "agent:codex:discord:channel:chan-1",
|
||||
},
|
||||
sessionPrefix: "discord:slash",
|
||||
userId: "user-1",
|
||||
}),
|
||||
).toEqual({
|
||||
sessionKey: "agent:codex:acp:binding:discord:default:seed",
|
||||
commandTargetSessionKey: "agent:codex:acp:binding:discord:default:seed",
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to the routed slash and command target session keys", () => {
|
||||
expect(
|
||||
resolveDiscordNativeCommandSessionTargets({
|
||||
effectiveRoute: {
|
||||
agentId: "qwen",
|
||||
sessionKey: "agent:qwen:discord:channel:chan-1",
|
||||
},
|
||||
sessionPrefix: "discord:slash",
|
||||
userId: "user-1",
|
||||
}),
|
||||
).toEqual({
|
||||
sessionKey: "agent:qwen:discord:slash:user-1",
|
||||
commandTargetSessionKey: "agent:qwen:discord:channel:chan-1",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,22 +0,0 @@
|
||||
export type ResolveDiscordNativeCommandSessionTargetsParams = {
|
||||
boundSessionKey?: string;
|
||||
effectiveRoute: {
|
||||
agentId: string;
|
||||
sessionKey: string;
|
||||
};
|
||||
sessionPrefix: string;
|
||||
userId: string;
|
||||
};
|
||||
|
||||
export function resolveDiscordNativeCommandSessionTargets(
|
||||
params: ResolveDiscordNativeCommandSessionTargetsParams,
|
||||
) {
|
||||
const sessionKey =
|
||||
params.boundSessionKey ??
|
||||
`agent:${params.effectiveRoute.agentId}:${params.sessionPrefix}:${params.userId}`;
|
||||
const commandTargetSessionKey = params.boundSessionKey ?? params.effectiveRoute.sessionKey;
|
||||
return {
|
||||
sessionKey,
|
||||
commandTargetSessionKey,
|
||||
};
|
||||
}
|
||||
@@ -41,6 +41,7 @@ import { resolveStoredModelOverride } from "../../auto-reply/reply/model-selecti
|
||||
import { dispatchReplyWithDispatcher } from "../../auto-reply/reply/provider-dispatcher.js";
|
||||
import type { ReplyPayload } from "../../auto-reply/types.js";
|
||||
import { resolveCommandAuthorizedFromAuthorizers } from "../../channels/command-gating.js";
|
||||
import { resolveNativeCommandSessionTargets } from "../../channels/native-command-session-targets.js";
|
||||
import { createReplyPrefixOptions } from "../../channels/reply-prefix.js";
|
||||
import type { OpenClawConfig, loadConfig } from "../../config/config.js";
|
||||
import { isDangerousNameMatchingEnabled } from "../../config/dangerous-name-matching.js";
|
||||
@@ -83,7 +84,6 @@ import {
|
||||
type DiscordModelPickerCommandContext,
|
||||
} from "./model-picker.js";
|
||||
import { buildDiscordNativeCommandContext } from "./native-command-context.js";
|
||||
import { resolveDiscordNativeCommandSessionTargets } from "./native-command-session-targets.js";
|
||||
import {
|
||||
resolveDiscordBoundConversationRoute,
|
||||
resolveDiscordEffectiveRoute,
|
||||
@@ -1645,11 +1645,12 @@ async function dispatchDiscordCommandInteraction(params: {
|
||||
configuredRoute,
|
||||
matchedBy: configuredBinding ? "binding.channel" : undefined,
|
||||
});
|
||||
const { sessionKey, commandTargetSessionKey } = resolveDiscordNativeCommandSessionTargets({
|
||||
boundSessionKey,
|
||||
effectiveRoute,
|
||||
const { sessionKey, commandTargetSessionKey } = resolveNativeCommandSessionTargets({
|
||||
agentId: effectiveRoute.agentId,
|
||||
sessionPrefix,
|
||||
userId: user.id,
|
||||
targetSessionKey: effectiveRoute.sessionKey,
|
||||
boundSessionKey,
|
||||
});
|
||||
const ctxPayload = buildDiscordNativeCommandContext({
|
||||
prompt,
|
||||
|
||||
Reference in New Issue
Block a user