|
|
|
|
@ -4,6 +4,7 @@ import type { OpenClawConfig } from "../config/config.js";
|
|
|
|
|
import type { MsgContext } from "./templating.js";
|
|
|
|
|
import { getChannelDock, listChannelDocks } from "../channels/dock.js";
|
|
|
|
|
import { normalizeAnyChannelId } from "../channels/registry.js";
|
|
|
|
|
import { INTERNAL_MESSAGE_CHANNEL, normalizeMessageChannel } from "../utils/message-channel.js";
|
|
|
|
|
|
|
|
|
|
export type CommandAuthorization = {
|
|
|
|
|
providerId?: ChannelId;
|
|
|
|
|
@ -16,7 +17,15 @@ export type CommandAuthorization = {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function resolveProviderFromContext(ctx: MsgContext, cfg: OpenClawConfig): ChannelId | undefined {
|
|
|
|
|
const explicitMessageChannel =
|
|
|
|
|
normalizeMessageChannel(ctx.Provider) ??
|
|
|
|
|
normalizeMessageChannel(ctx.Surface) ??
|
|
|
|
|
normalizeMessageChannel(ctx.OriginatingChannel);
|
|
|
|
|
if (explicitMessageChannel === INTERNAL_MESSAGE_CHANNEL) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
const direct =
|
|
|
|
|
normalizeAnyChannelId(explicitMessageChannel ?? undefined) ??
|
|
|
|
|
normalizeAnyChannelId(ctx.Provider) ??
|
|
|
|
|
normalizeAnyChannelId(ctx.Surface) ??
|
|
|
|
|
normalizeAnyChannelId(ctx.OriginatingChannel);
|
|
|
|
|
@ -27,7 +36,13 @@ function resolveProviderFromContext(ctx: MsgContext, cfg: OpenClawConfig): Chann
|
|
|
|
|
.filter((value): value is string => Boolean(value?.trim()))
|
|
|
|
|
.flatMap((value) => value.split(":").map((part) => part.trim()));
|
|
|
|
|
for (const candidate of candidates) {
|
|
|
|
|
const normalized = normalizeAnyChannelId(candidate);
|
|
|
|
|
const normalizedCandidateChannel = normalizeMessageChannel(candidate);
|
|
|
|
|
if (normalizedCandidateChannel === INTERNAL_MESSAGE_CHANNEL) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
const normalized =
|
|
|
|
|
normalizeAnyChannelId(normalizedCandidateChannel ?? undefined) ??
|
|
|
|
|
normalizeAnyChannelId(candidate);
|
|
|
|
|
if (normalized) {
|
|
|
|
|
return normalized;
|
|
|
|
|
}
|
|
|
|
|
|