Merge 3f9889923a into 28f8d00e9f
This commit is contained in:
commit
5cb086c5be
@ -1,6 +1,6 @@
|
|||||||
import type { ChannelId } from "../channels/plugins/types.js";
|
import type { ChannelId } from "../channels/plugins/types.js";
|
||||||
import { normalizeChannelId } from "../channels/plugins/index.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 {
|
function resolveAutoDefault(providerId?: ChannelId): boolean {
|
||||||
const id = normalizeChannelId(providerId);
|
const id = normalizeChannelId(providerId);
|
||||||
@ -22,6 +22,22 @@ export function resolveNativeSkillsEnabled(params: {
|
|||||||
return resolveAutoDefault(providerId);
|
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: {
|
export function resolveNativeCommandsEnabled(params: {
|
||||||
providerId: ChannelId;
|
providerId: ChannelId;
|
||||||
providerSetting?: NativeCommandsSetting;
|
providerSetting?: NativeCommandsSetting;
|
||||||
|
|||||||
@ -87,12 +87,13 @@ export type MessagesConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type NativeCommandsSetting = boolean | "auto";
|
export type NativeCommandsSetting = boolean | "auto";
|
||||||
|
export type NativeSkillsSetting = boolean | "auto" | string[];
|
||||||
|
|
||||||
export type CommandsConfig = {
|
export type CommandsConfig = {
|
||||||
/** Enable native command registration when supported (default: "auto"). */
|
/** Enable native command registration when supported (default: "auto"). */
|
||||||
native?: NativeCommandsSetting;
|
native?: NativeCommandsSetting;
|
||||||
/** Enable native skill command registration when supported (default: "auto"). */
|
/** Enable native skill command registration when supported (default: "auto"). */
|
||||||
nativeSkills?: NativeCommandsSetting;
|
nativeSkills?: NativeSkillsSetting;
|
||||||
/** Enable text command parsing (default: true). */
|
/** Enable text command parsing (default: true). */
|
||||||
text?: boolean;
|
text?: boolean;
|
||||||
/** Allow bash chat command (`!`; `/bash` alias) (default: false). */
|
/** 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"). */
|
/** Override native command registration for this provider (bool or "auto"). */
|
||||||
native?: NativeCommandsSetting;
|
native?: NativeCommandsSetting;
|
||||||
/** Override native skill command registration for this provider (bool or "auto"). */
|
/** 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")]);
|
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
|
export const ProviderCommandsSchema = z
|
||||||
.object({
|
.object({
|
||||||
native: NativeCommandsSettingSchema.optional(),
|
native: NativeCommandsSettingSchema.optional(),
|
||||||
nativeSkills: NativeCommandsSettingSchema.optional(),
|
nativeSkills: NativeSkillsSettingSchema.optional(),
|
||||||
})
|
})
|
||||||
.strict()
|
.strict()
|
||||||
.optional();
|
.optional();
|
||||||
|
|||||||
@ -78,7 +78,7 @@ type RegisterTelegramNativeCommandsParams = {
|
|||||||
textLimit: number;
|
textLimit: number;
|
||||||
useAccessGroups: boolean;
|
useAccessGroups: boolean;
|
||||||
nativeEnabled: boolean;
|
nativeEnabled: boolean;
|
||||||
nativeSkillsEnabled: boolean;
|
nativeSkillsEnabled: boolean | string[];
|
||||||
nativeDisabledExplicit: boolean;
|
nativeDisabledExplicit: boolean;
|
||||||
resolveGroupPolicy: (chatId: string | number) => ChannelGroupPolicy;
|
resolveGroupPolicy: (chatId: string | number) => ChannelGroupPolicy;
|
||||||
resolveTelegramGroupConfig: (
|
resolveTelegramGroupConfig: (
|
||||||
@ -258,7 +258,13 @@ export const registerTelegramNativeCommands = ({
|
|||||||
opts,
|
opts,
|
||||||
}: RegisterTelegramNativeCommandsParams) => {
|
}: RegisterTelegramNativeCommandsParams) => {
|
||||||
const skillCommands =
|
const skillCommands =
|
||||||
nativeEnabled && nativeSkillsEnabled ? listSkillCommandsForAgents({ cfg }) : [];
|
nativeEnabled && nativeSkillsEnabled
|
||||||
|
? Array.isArray(nativeSkillsEnabled)
|
||||||
|
? listSkillCommandsForAgents({ cfg }).filter((s) =>
|
||||||
|
nativeSkillsEnabled.includes(s.skillName),
|
||||||
|
)
|
||||||
|
: listSkillCommandsForAgents({ cfg })
|
||||||
|
: [];
|
||||||
const nativeCommands = nativeEnabled
|
const nativeCommands = nativeEnabled
|
||||||
? listNativeCommandSpecsForConfig(cfg, { skillCommands, provider: "telegram" })
|
? listNativeCommandSpecsForConfig(cfg, { skillCommands, provider: "telegram" })
|
||||||
: [];
|
: [];
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import {
|
|||||||
isNativeCommandsExplicitlyDisabled,
|
isNativeCommandsExplicitlyDisabled,
|
||||||
resolveNativeCommandsEnabled,
|
resolveNativeCommandsEnabled,
|
||||||
resolveNativeSkillsEnabled,
|
resolveNativeSkillsEnabled,
|
||||||
|
resolveNativeSkillsSetting,
|
||||||
} from "../config/commands.js";
|
} from "../config/commands.js";
|
||||||
import type { OpenClawConfig, ReplyToMode } from "../config/config.js";
|
import type { OpenClawConfig, ReplyToMode } from "../config/config.js";
|
||||||
import { loadConfig } from "../config/config.js";
|
import { loadConfig } from "../config/config.js";
|
||||||
@ -241,7 +242,7 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
|||||||
providerSetting: telegramCfg.commands?.native,
|
providerSetting: telegramCfg.commands?.native,
|
||||||
globalSetting: cfg.commands?.native,
|
globalSetting: cfg.commands?.native,
|
||||||
});
|
});
|
||||||
const nativeSkillsEnabled = resolveNativeSkillsEnabled({
|
const nativeSkillsEnabled = resolveNativeSkillsSetting({
|
||||||
providerId: "telegram",
|
providerId: "telegram",
|
||||||
providerSetting: telegramCfg.commands?.nativeSkills,
|
providerSetting: telegramCfg.commands?.nativeSkills,
|
||||||
globalSetting: cfg.commands?.nativeSkills,
|
globalSetting: cfg.commands?.nativeSkills,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user