Merge 3f9889923a into 28f8d00e9f
This commit is contained in:
commit
5cb086c5be
@ -1,6 +1,6 @@
|
||||
import type { ChannelId } from "../channels/plugins/types.js";
|
||||
import { normalizeChannelId } from "../channels/plugins/index.js";
|
||||
import type { NativeCommandsSetting } from "./types.js";
|
||||
import type { NativeCommandsSetting, NativeSkillsSetting } from "./types.js";
|
||||
|
||||
function resolveAutoDefault(providerId?: ChannelId): boolean {
|
||||
const id = normalizeChannelId(providerId);
|
||||
@ -22,6 +22,22 @@ export function resolveNativeSkillsEnabled(params: {
|
||||
return resolveAutoDefault(providerId);
|
||||
}
|
||||
|
||||
// Returns boolean (enable all/none) or string[] (whitelist of skill names)
|
||||
export function resolveNativeSkillsSetting(params: {
|
||||
providerId: ChannelId;
|
||||
providerSetting?: NativeSkillsSetting;
|
||||
globalSetting?: NativeSkillsSetting;
|
||||
}): boolean | string[] {
|
||||
const { providerId, providerSetting, globalSetting } = params;
|
||||
const setting = providerSetting === undefined ? globalSetting : providerSetting;
|
||||
// If it is an array, return the whitelist
|
||||
if (Array.isArray(setting)) return setting;
|
||||
// Otherwise resolve as boolean
|
||||
if (setting === true) return true;
|
||||
if (setting === false) return false;
|
||||
return resolveAutoDefault(providerId);
|
||||
}
|
||||
|
||||
export function resolveNativeCommandsEnabled(params: {
|
||||
providerId: ChannelId;
|
||||
providerSetting?: NativeCommandsSetting;
|
||||
|
||||
@ -87,12 +87,13 @@ export type MessagesConfig = {
|
||||
};
|
||||
|
||||
export type NativeCommandsSetting = boolean | "auto";
|
||||
export type NativeSkillsSetting = boolean | "auto" | string[];
|
||||
|
||||
export type CommandsConfig = {
|
||||
/** Enable native command registration when supported (default: "auto"). */
|
||||
native?: NativeCommandsSetting;
|
||||
/** Enable native skill command registration when supported (default: "auto"). */
|
||||
nativeSkills?: NativeCommandsSetting;
|
||||
nativeSkills?: NativeSkillsSetting;
|
||||
/** Enable text command parsing (default: true). */
|
||||
text?: boolean;
|
||||
/** Allow bash chat command (`!`; `/bash` alias) (default: false). */
|
||||
@ -113,5 +114,5 @@ export type ProviderCommandsConfig = {
|
||||
/** Override native command registration for this provider (bool or "auto"). */
|
||||
native?: NativeCommandsSetting;
|
||||
/** Override native skill command registration for this provider (bool or "auto"). */
|
||||
nativeSkills?: NativeCommandsSetting;
|
||||
nativeSkills?: NativeSkillsSetting;
|
||||
};
|
||||
|
||||
@ -493,10 +493,17 @@ export const ToolsLinksSchema = z
|
||||
|
||||
export const NativeCommandsSettingSchema = z.union([z.boolean(), z.literal("auto")]);
|
||||
|
||||
// nativeSkills can be boolean/auto OR an array of skill names to whitelist
|
||||
export const NativeSkillsSettingSchema = z.union([
|
||||
z.boolean(),
|
||||
z.literal("auto"),
|
||||
z.array(z.string()).describe("Whitelist of skill names to register as native commands"),
|
||||
]);
|
||||
|
||||
export const ProviderCommandsSchema = z
|
||||
.object({
|
||||
native: NativeCommandsSettingSchema.optional(),
|
||||
nativeSkills: NativeCommandsSettingSchema.optional(),
|
||||
nativeSkills: NativeSkillsSettingSchema.optional(),
|
||||
})
|
||||
.strict()
|
||||
.optional();
|
||||
|
||||
@ -78,7 +78,7 @@ type RegisterTelegramNativeCommandsParams = {
|
||||
textLimit: number;
|
||||
useAccessGroups: boolean;
|
||||
nativeEnabled: boolean;
|
||||
nativeSkillsEnabled: boolean;
|
||||
nativeSkillsEnabled: boolean | string[];
|
||||
nativeDisabledExplicit: boolean;
|
||||
resolveGroupPolicy: (chatId: string | number) => ChannelGroupPolicy;
|
||||
resolveTelegramGroupConfig: (
|
||||
@ -258,7 +258,13 @@ export const registerTelegramNativeCommands = ({
|
||||
opts,
|
||||
}: RegisterTelegramNativeCommandsParams) => {
|
||||
const skillCommands =
|
||||
nativeEnabled && nativeSkillsEnabled ? listSkillCommandsForAgents({ cfg }) : [];
|
||||
nativeEnabled && nativeSkillsEnabled
|
||||
? Array.isArray(nativeSkillsEnabled)
|
||||
? listSkillCommandsForAgents({ cfg }).filter((s) =>
|
||||
nativeSkillsEnabled.includes(s.skillName),
|
||||
)
|
||||
: listSkillCommandsForAgents({ cfg })
|
||||
: [];
|
||||
const nativeCommands = nativeEnabled
|
||||
? listNativeCommandSpecsForConfig(cfg, { skillCommands, provider: "telegram" })
|
||||
: [];
|
||||
|
||||
@ -11,6 +11,7 @@ import {
|
||||
isNativeCommandsExplicitlyDisabled,
|
||||
resolveNativeCommandsEnabled,
|
||||
resolveNativeSkillsEnabled,
|
||||
resolveNativeSkillsSetting,
|
||||
} from "../config/commands.js";
|
||||
import type { OpenClawConfig, ReplyToMode } from "../config/config.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
@ -241,7 +242,7 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
||||
providerSetting: telegramCfg.commands?.native,
|
||||
globalSetting: cfg.commands?.native,
|
||||
});
|
||||
const nativeSkillsEnabled = resolveNativeSkillsEnabled({
|
||||
const nativeSkillsEnabled = resolveNativeSkillsSetting({
|
||||
providerId: "telegram",
|
||||
providerSetting: telegramCfg.commands?.nativeSkills,
|
||||
globalSetting: cfg.commands?.nativeSkills,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user