mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-26 16:41:49 +00:00
67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
|
import { normalizeLowercaseStringOrEmpty } from "../../shared/string-coerce.js";
|
|
import {
|
|
authorizeConfigWriteShared,
|
|
canBypassConfigWritePolicyShared,
|
|
formatConfigWriteDeniedMessageShared,
|
|
resolveChannelConfigWritesShared,
|
|
resolveConfigWriteTargetFromPathShared,
|
|
resolveExplicitConfigWriteTargetShared,
|
|
type ConfigWriteAuthorizationResultLike,
|
|
type ConfigWriteScopeLike,
|
|
type ConfigWriteTargetLike,
|
|
} from "./config-write-policy-shared.js";
|
|
import type { ChannelId } from "./types.core.js";
|
|
export type ConfigWriteScope = ConfigWriteScopeLike;
|
|
export type ConfigWriteTarget = ConfigWriteTargetLike;
|
|
export type ConfigWriteAuthorizationResult = ConfigWriteAuthorizationResultLike;
|
|
|
|
function isInternalConfigWriteMessageChannel(channel?: string | null): boolean {
|
|
return normalizeLowercaseStringOrEmpty(channel) === "webchat";
|
|
}
|
|
|
|
export function resolveChannelConfigWrites(params: {
|
|
cfg: OpenClawConfig;
|
|
channelId?: ChannelId | null;
|
|
accountId?: string | null;
|
|
}): boolean {
|
|
return resolveChannelConfigWritesShared(params);
|
|
}
|
|
|
|
export function authorizeConfigWrite(params: {
|
|
cfg: OpenClawConfig;
|
|
origin?: ConfigWriteScope;
|
|
target?: ConfigWriteTarget;
|
|
allowBypass?: boolean;
|
|
}): ConfigWriteAuthorizationResult {
|
|
return authorizeConfigWriteShared(params);
|
|
}
|
|
|
|
export function resolveExplicitConfigWriteTarget(scope: ConfigWriteScope): ConfigWriteTarget {
|
|
return resolveExplicitConfigWriteTargetShared(scope);
|
|
}
|
|
|
|
export function resolveConfigWriteTargetFromPath(path: string[]): ConfigWriteTarget {
|
|
return resolveConfigWriteTargetFromPathShared({
|
|
path,
|
|
normalizeChannelId: (raw) => normalizeLowercaseStringOrEmpty(raw) as ChannelId,
|
|
});
|
|
}
|
|
|
|
export function canBypassConfigWritePolicy(params: {
|
|
channel?: string | null;
|
|
gatewayClientScopes?: string[] | null;
|
|
}): boolean {
|
|
return canBypassConfigWritePolicyShared({
|
|
...params,
|
|
isInternalMessageChannel: isInternalConfigWriteMessageChannel,
|
|
});
|
|
}
|
|
|
|
export function formatConfigWriteDeniedMessage(params: {
|
|
result: Exclude<ConfigWriteAuthorizationResult, { allowed: true }>;
|
|
fallbackChannelId?: ChannelId | null;
|
|
}): string {
|
|
return formatConfigWriteDeniedMessageShared(params);
|
|
}
|