diff --git a/apps/website/docs/api-reference/ai/classes/ai-plugin.mdx b/apps/website/docs/api-reference/ai/classes/ai-plugin.mdx index 46946f3e..eb4b533e 100644 --- a/apps/website/docs/api-reference/ai/classes/ai-plugin.mdx +++ b/apps/website/docs/api-reference/ai/classes/ai-plugin.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## AiPlugin - + diff --git a/apps/website/docs/api-reference/ai/functions/experimental_create-config.mdx b/apps/website/docs/api-reference/ai/functions/experimental_create-config.mdx new file mode 100644 index 00000000..f3179586 --- /dev/null +++ b/apps/website/docs/api-reference/ai/functions/experimental_create-config.mdx @@ -0,0 +1,28 @@ +--- +title: "Experimental_createConfig" +isDefaultIndex: false +generated: true +--- + +import MemberInfo from '@site/src/components/MemberInfo'; +import GenerationInfo from '@site/src/components/GenerationInfo'; +import MemberDescription from '@site/src/components/MemberDescription'; + + + + +## experimental_createConfig + + + +Generates AI config from a CommandKit command data. + +```ts title="Signature" +function experimental_createConfig(command: CommandData): AiConfig +``` +Parameters + +### command + +CommandData`} /> + diff --git a/apps/website/docs/api-reference/ai/interfaces/ai-config.mdx b/apps/website/docs/api-reference/ai/interfaces/ai-config.mdx index fc7b33ed..0d88018b 100644 --- a/apps/website/docs/api-reference/ai/interfaces/ai-config.mdx +++ b/apps/website/docs/api-reference/ai/interfaces/ai-config.mdx @@ -13,14 +13,14 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## AiConfig - + Represents the configuration options for the AI plugin scoped to a specific command. ```ts title="Signature" -interface AiConfig { +interface AiConfig { description?: string; - parameters: any; + inputSchema: T; } ``` @@ -31,9 +31,9 @@ interface AiConfig { A description of the AI functionality provided by this command. If not given, the command's description will be used. -### parameters +### inputSchema - + A zod schema defining the parameters that the AI command accepts. diff --git a/apps/website/docs/api-reference/ai/interfaces/ai-plugin-options.mdx b/apps/website/docs/api-reference/ai/interfaces/ai-plugin-options.mdx index 384df4d0..b4bf4cb2 100644 --- a/apps/website/docs/api-reference/ai/interfaces/ai-plugin-options.mdx +++ b/apps/website/docs/api-reference/ai/interfaces/ai-plugin-options.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## AiPluginOptions - + Options for the AI plugin. diff --git a/apps/website/docs/api-reference/ai/interfaces/configure-ai.mdx b/apps/website/docs/api-reference/ai/interfaces/configure-ai.mdx index 23d77e27..1f31e2d9 100644 --- a/apps/website/docs/api-reference/ai/interfaces/configure-ai.mdx +++ b/apps/website/docs/api-reference/ai/interfaces/configure-ai.mdx @@ -23,16 +23,16 @@ interface ConfigureAI { messageFilter?: MessageFilter; selectAiModel: SelectAiModel; prepareSystemPrompt?: (ctx: AiContext, message: Message) => Promise; - preparePrompt?: ( - ctx: AiContext, - message: Message, + preparePrompt?: ( + ctx: AiContext, + message: Message, ) => Promise; onProcessingStart?: (ctx: AiContext, message: Message) => Promise; onProcessingFinish?: (ctx: AiContext, message: Message) => Promise; - onResult?: ( - ctx: AiContext, - message: Message, - result: AIGenerateResult, + onResult?: ( + ctx: AiContext, + message: Message, + result: AIGenerateResult, ) => Promise; onError?: (ctx: AiContext, message: Message, error: Error) => Promise; } @@ -49,24 +49,24 @@ Whether to disable the built-in tools. Default is false. MessageFilter`} /> -A filter function that determines whether a message should be processed by the AI. +A filter function that determines whether a message should be processed by the AI. CommandKit invokes this function before processing the message. ### selectAiModel SelectAiModel`} /> -A function that selects the AI model to use based on the message. +A function that selects the AI model to use based on the message. This function should return a promise that resolves to an object containing the model and options. ### prepareSystemPrompt AiContext, message: Message) => Promise<string>`} /> -A function that generates a system prompt based on the message. -This function should return a promise that resolves to a string containing the system prompt. +A function that generates a system prompt based on the message. +This function should return a promise that resolves to a string containing the system prompt. If not provided, a default system prompt will be used. ### preparePrompt -AiContext, message: Message, ) => Promise<string | AiMessage>`} /> +AiContext, message: Message, ) => Promise<string | AiMessage>`} /> A function that prepares the prompt for the AI model. ### onProcessingStart @@ -81,7 +81,7 @@ A function that gets called when the AI starts processing a message. A function that gets called when the AI finishes processing a message. ### onResult -AiContext, message: Message, result: AIGenerateResult, ) => Promise<void>`} /> +AiContext, message: Message, result: AIGenerateResult, ) => Promise<void>`} /> A function that gets called upon receiving the result from the AI model. ### onError diff --git a/apps/website/docs/api-reference/ai/interfaces/create-tool-options.mdx b/apps/website/docs/api-reference/ai/interfaces/create-tool-options.mdx index d124f2bd..95530697 100644 --- a/apps/website/docs/api-reference/ai/interfaces/create-tool-options.mdx +++ b/apps/website/docs/api-reference/ai/interfaces/create-tool-options.mdx @@ -21,7 +21,7 @@ Configuration options for creating an AI tool. interface CreateToolOptions { name: string; description: string; - parameters: T; + inputSchema: T; execute: ToolExecuteFunction; } ``` @@ -38,7 +38,7 @@ The unique name identifier for the tool A human-readable description of what the tool does -### parameters +### inputSchema diff --git a/apps/website/docs/api-reference/ai/types/ai-command-context.mdx b/apps/website/docs/api-reference/ai/types/ai-command-context.mdx index 87844eed..1654e40c 100644 --- a/apps/website/docs/api-reference/ai/types/ai-command-context.mdx +++ b/apps/website/docs/api-reference/ai/types/ai-command-context.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## AiCommandContext - + Represents the context in which an AI command is executed. It extends the MessageCommandContext to include AI-specific properties. diff --git a/apps/website/docs/api-reference/ai/types/ai-command.mdx b/apps/website/docs/api-reference/ai/types/ai-command.mdx index 8cf5e524..cf882701 100644 --- a/apps/website/docs/api-reference/ai/types/ai-command.mdx +++ b/apps/website/docs/api-reference/ai/types/ai-command.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## AiCommand - + Represents a command that can be executed by the AI. diff --git a/apps/website/docs/api-reference/ai/types/command-tool.mdx b/apps/website/docs/api-reference/ai/types/command-tool.mdx index a53cef50..e2072047 100644 --- a/apps/website/docs/api-reference/ai/types/command-tool.mdx +++ b/apps/website/docs/api-reference/ai/types/command-tool.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## CommandTool - + diff --git a/apps/website/docs/api-reference/ai/types/extract-ai-config.mdx b/apps/website/docs/api-reference/ai/types/extract-ai-config.mdx index e3a9928d..36657d13 100644 --- a/apps/website/docs/api-reference/ai/types/extract-ai-config.mdx +++ b/apps/website/docs/api-reference/ai/types/extract-ai-config.mdx @@ -13,10 +13,10 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## ExtractAiConfig - + Extracts the AI configuration params. ```ts title="Signature" -type ExtractAiConfig> = T extends AiConfig ? InferParameters : T +type ExtractAiConfig> = T extends AiConfig ? InferParameters : T ``` diff --git a/apps/website/docs/api-reference/ai/types/select-ai-model-result.mdx b/apps/website/docs/api-reference/ai/types/select-ai-model-result.mdx index fe11ed5a..8d2e5cc2 100644 --- a/apps/website/docs/api-reference/ai/types/select-ai-model-result.mdx +++ b/apps/website/docs/api-reference/ai/types/select-ai-model-result.mdx @@ -18,5 +18,8 @@ import MemberDescription from '@site/src/components/MemberDescription'; ```ts title="Signature" -type SelectAiModelResult = Parameters[0] +type SelectAiModelResult = Omit< + Parameters[0], + 'messages' | 'prompt' +> ``` diff --git a/apps/website/docs/api-reference/ai/types/tool-execute-function.mdx b/apps/website/docs/api-reference/ai/types/tool-execute-function.mdx index 2e1ee291..18fbe1eb 100644 --- a/apps/website/docs/api-reference/ai/types/tool-execute-function.mdx +++ b/apps/website/docs/api-reference/ai/types/tool-execute-function.mdx @@ -20,6 +20,6 @@ Type definition for a tool's execute function. ```ts title="Signature" type ToolExecuteFunction = ( ctx: AiContext, - parameters: InferParameters, + inputSchema: InferParameters, ) => Awaitable ``` diff --git a/apps/website/docs/api-reference/ai/types/tool-parameter-type.mdx b/apps/website/docs/api-reference/ai/types/tool-parameter-type.mdx index b8cdad97..3668869c 100644 --- a/apps/website/docs/api-reference/ai/types/tool-parameter-type.mdx +++ b/apps/website/docs/api-reference/ai/types/tool-parameter-type.mdx @@ -19,5 +19,5 @@ Type representing the parameters schema for AI tools. Extracted from the first parameter of the `tool` function from the 'ai' library. ```ts title="Signature" -type ToolParameterType = Parameters[0]['parameters'] +type ToolParameterType = z.ZodType | Schema ``` diff --git a/apps/website/docs/api-reference/cache/interfaces/cache-context.mdx b/apps/website/docs/api-reference/cache/interfaces/cache-context.mdx index 163da3c7..8d8c21e9 100644 --- a/apps/website/docs/api-reference/cache/interfaces/cache-context.mdx +++ b/apps/website/docs/api-reference/cache/interfaces/cache-context.mdx @@ -19,12 +19,12 @@ Context for managing cache operations within an async scope ```ts title="Signature" interface CacheContext { - params: { - /** Custom name for the cache entry */ - name?: string; - /** Time-to-live in milliseconds */ - ttl?: number | null; - tags: Set; + params: { + /** Custom name for the cache entry */ + name?: string; + /** Time-to-live in milliseconds */ + ttl?: number | null; + tags: Set; }; } ``` @@ -33,7 +33,7 @@ interface CacheContext { ### params -cache entry */ name?: string; /** Time-to-live in milliseconds */ ttl?: number | null; tags: Set<string>; }`} /> +cache entry */ name?: string; /** Time-to-live in milliseconds */ ttl?: number | null; tags: Set<string>; }`} /> diff --git a/apps/website/docs/api-reference/commandkit/classes/app-command-handler.mdx b/apps/website/docs/api-reference/commandkit/classes/app-command-handler.mdx index edcffda6..679d703a 100644 --- a/apps/website/docs/api-reference/commandkit/classes/app-command-handler.mdx +++ b/apps/website/docs/api-reference/commandkit/classes/app-command-handler.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## AppCommandHandler - + Handles application commands for CommandKit, including loading, registration, and execution. Manages both slash commands and message commands with middleware support. @@ -35,6 +35,7 @@ class AppCommandHandler { registerExternalLoadedMiddleware(data: LoadedMiddleware[]) => ; registerExternalLoadedCommands(data: LoadedCommand[]) => ; loadCommands() => ; + getMetadataFor(command: string) => CommandMetadata | null; } ``` @@ -115,6 +116,11 @@ Registers externally loaded commands. `} /> Loads all commands and middleware from the router. +### getMetadataFor + + CommandMetadata | null`} /> + +Gets the metadata for a command. diff --git a/apps/website/docs/api-reference/commandkit/classes/command-registrar.mdx b/apps/website/docs/api-reference/commandkit/classes/command-registrar.mdx index 426ec3cd..7427f1b2 100644 --- a/apps/website/docs/api-reference/commandkit/classes/command-registrar.mdx +++ b/apps/website/docs/api-reference/commandkit/classes/command-registrar.mdx @@ -20,10 +20,10 @@ Handles registration of Discord application commands (slash commands, context me ```ts title="Signature" class CommandRegistrar { constructor(commandkit: CommandKit) - getCommandsData() => CommandData[]; + getCommandsData() => (CommandData & { __metadata?: CommandMetadata })[]; register() => ; - updateGlobalCommands(commands: CommandData[]) => ; - updateGuildCommands(commands: CommandData[]) => ; + updateGlobalCommands(commands: (CommandData & { __metadata?: CommandMetadata })[]) => ; + updateGuildCommands(commands: (CommandData & { __metadata?: CommandMetadata })[]) => ; } ``` @@ -36,7 +36,7 @@ class CommandRegistrar { Creates an instance of CommandRegistrar. ### getCommandsData - CommandData[]`} /> + (CommandData & { __metadata?: CommandMetadata })[]`} /> Gets the commands data. ### register @@ -46,12 +46,12 @@ Gets the commands data. Registers loaded commands. ### updateGlobalCommands -CommandData[]) => `} /> +CommandData & { __metadata?: CommandMetadata })[]) => `} /> Updates the global commands. ### updateGuildCommands -CommandData[]) => `} /> +CommandData & { __metadata?: CommandMetadata })[]) => `} /> Updates the guild commands. diff --git a/apps/website/docs/api-reference/commandkit/interfaces/app-command-native.mdx b/apps/website/docs/api-reference/commandkit/interfaces/app-command-native.mdx index 36106df2..fed296b5 100644 --- a/apps/website/docs/api-reference/commandkit/interfaces/app-command-native.mdx +++ b/apps/website/docs/api-reference/commandkit/interfaces/app-command-native.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## AppCommandNative - + Represents a native command structure used in CommandKit. This structure includes the command definition and various handlers for different interaction types. @@ -22,6 +22,8 @@ It can be used to define slash commands, context menu commands, and message comm ```ts title="Signature" interface AppCommandNative { command: CommandData | Record; + generateMetadata?: CommandMetadataFunction; + metadata?: CommandMetadata; chatInput?: (ctx: Context) => Awaitable; autocomplete?: (ctx: Context) => Awaitable; message?: (ctx: Context) => Awaitable; @@ -37,6 +39,16 @@ interface AppCommandNative { CommandData | Record<string, any>`} /> +### generateMetadata + +CommandMetadataFunction`} /> + + +### metadata + +CommandMetadata`} /> + + ### chatInput Context) => Awaitable<unknown>`} /> diff --git a/apps/website/docs/api-reference/commandkit/interfaces/command-context.mdx b/apps/website/docs/api-reference/commandkit/interfaces/command-context.mdx index 5d8b439c..dc5f1a4a 100644 --- a/apps/website/docs/api-reference/commandkit/interfaces/command-context.mdx +++ b/apps/website/docs/api-reference/commandkit/interfaces/command-context.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## CommandContext - + Represents a command context. diff --git a/apps/website/docs/api-reference/commandkit/interfaces/command-flag-context.mdx b/apps/website/docs/api-reference/commandkit/interfaces/command-flag-context.mdx index 5af9d70a..2fec6a23 100644 --- a/apps/website/docs/api-reference/commandkit/interfaces/command-flag-context.mdx +++ b/apps/website/docs/api-reference/commandkit/interfaces/command-flag-context.mdx @@ -21,34 +21,34 @@ Context for evaluating command flags in CommandKit. interface CommandFlagContext { client: Client; commandkit: CommandKit; - command: { - /** - * The interaction object if the command was invoked via an interaction. - * This can be a ChatInputCommandInteraction, AutocompleteInteraction, or ContextMenuCommandInteraction. - */ - interaction?: - | ChatInputCommandInteraction - | AutocompleteInteraction - | ContextMenuCommandInteraction; - /** - * The message object if the command was invoked via a message. - */ - message?: Message; - /** - * The guild where the command was invoked, if applicable. - * This will be null for commands invoked in DMs. - */ - guild: Guild | null; - /** - * The channel where the command was invoked. - * This can be a text channel, DM channel, or any other type of text-based channel. - */ - channel: TextBasedChannel | null; - /** - * The loaded command instance that is being executed. - * This contains the command's metadata and logic. - */ - command: LoadedCommand; + command: { + /** + * The interaction object if the command was invoked via an interaction. + * This can be a ChatInputCommandInteraction, AutocompleteInteraction, or ContextMenuCommandInteraction. + */ + interaction?: + | ChatInputCommandInteraction + | AutocompleteInteraction + | ContextMenuCommandInteraction; + /** + * The message object if the command was invoked via a message. + */ + message?: Message; + /** + * The guild where the command was invoked, if applicable. + * This will be null for commands invoked in DMs. + */ + guild: Guild | null; + /** + * The channel where the command was invoked. + * This can be a text channel, DM channel, or any other type of text-based channel. + */ + channel: TextBasedChannel | null; + /** + * The loaded command instance that is being executed. + * This contains the command's metadata and logic. + */ + command: LoadedCommand; }; event: null; } @@ -60,25 +60,25 @@ interface CommandFlagContext { -The Discord client instance. +The Discord client instance. This is the main entry point for interacting with the Discord API. ### commandkit CommandKit`} /> -The CommandKit instance, which provides access to the command framework. +The CommandKit instance, which provides access to the command framework. This includes commands, events, and other features of CommandKit. ### command -LoadedCommand; }`} /> +LoadedCommand; }`} /> -The command context, which includes information about the command being executed. +The command context, which includes information about the command being executed. This can include the interaction, message, guild, channel, and the loaded command. ### event -The event context is null for command flags, as they are not tied to a specific event. +The event context is null for command flags, as they are not tied to a specific event. This is used to differentiate between command and event flags. diff --git a/apps/website/docs/api-reference/commandkit/interfaces/command-kit-compiler-options.mdx b/apps/website/docs/api-reference/commandkit/interfaces/command-kit-compiler-options.mdx index aa470f85..eecc428b 100644 --- a/apps/website/docs/api-reference/commandkit/interfaces/command-kit-compiler-options.mdx +++ b/apps/website/docs/api-reference/commandkit/interfaces/command-kit-compiler-options.mdx @@ -19,12 +19,12 @@ import MemberDescription from '@site/src/components/MemberDescription'; ```ts title="Signature" interface CommandKitCompilerOptions { - macro?: { - /** - * Whether to enable macro function compilation in development mode. - * @default false - */ - development?: boolean; + macro?: { + /** + * Whether to enable macro function compilation in development mode. + * @default false + */ + development?: boolean; }; tsdown?: Partial; disableChunking?: boolean; @@ -35,14 +35,14 @@ interface CommandKitCompilerOptions { ### macro - + The macro compiler options to use with CommandKit. ### tsdown -The tsdown compiler options to use with CommandKit. +The tsdown compiler options to use with CommandKit. **DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING** as it alters the behavior of the build process. ### disableChunking diff --git a/apps/website/docs/api-reference/commandkit/interfaces/command-kit-config.mdx b/apps/website/docs/api-reference/commandkit/interfaces/command-kit-config.mdx index 45fda999..faec8f8d 100644 --- a/apps/website/docs/api-reference/commandkit/interfaces/command-kit-config.mdx +++ b/apps/website/docs/api-reference/commandkit/interfaces/command-kit-config.mdx @@ -23,39 +23,40 @@ interface CommandKitConfig { rolldownPlugins?: any[]; entrypoints?: string[]; compilerOptions?: CommandKitCompilerOptions; - typescript?: { - /** - * Whether to ignore type checking during builds. - */ - ignoreBuildErrors?: boolean; + typescript?: { + /** + * Whether to ignore type checking during builds. + */ + ignoreBuildErrors?: boolean; }; static?: boolean; env?: Record; distDir?: string; - antiCrashScript?: { - /** - * Whether to enable the anti-crash script in development mode. - * @default true - */ - development?: boolean; - /** - * Whether to enable the anti-crash script in production mode. Usually, you should use other means to handle errors. - * @default false - */ - production?: boolean; + antiCrashScript?: { + /** + * Whether to enable the anti-crash script in development mode. + * @default true + */ + development?: boolean; + /** + * Whether to enable the anti-crash script in production mode. Usually, you should use other means to handle errors. + * @default false + */ + production?: boolean; }; - sourceMap?: { - /** - * Whether to enable source map generation in development mode. - */ - development?: boolean; - /** - * Whether to enable source map generation in production mode. - */ - production?: boolean; + sourceMap?: { + /** + * Whether to enable source map generation in development mode. + */ + development?: boolean; + /** + * Whether to enable source map generation in production mode. + */ + production?: boolean; }; typedCommands?: boolean; disablePrefixCommands?: boolean; + disablePermissionsMiddleware?: boolean; showUnknownPrefixCommandsWarning?: boolean; } ``` @@ -66,7 +67,7 @@ interface CommandKitConfig { MaybeArray<CommandKitPlugin>[] | Array<CommandKitPlugin>`} /> -The plugins to use with CommandKit. +The plugins to use with CommandKit. Can be a single plugin, an array of plugins, or a nested array of plugins. ### rolldownPlugins @@ -77,7 +78,7 @@ The rolldown plugins to use with CommandKit. -The list of additional entrypoints to compile. Eg, `dir` or `dir/index.ts` or `dir/*.ts`, etc. +The list of additional entrypoints to compile. Eg, `dir` or `dir/index.ts` or `dir/*.ts`, etc. Similarly, negative patterns can be used to exclude files. Eg, `!dir/index.ts` or `!dir/*.ts`, etc. ### compilerOptions @@ -86,7 +87,7 @@ Similarly, negative patterns can be used to exclude files. Eg, `!dir/index.ts` o The compiler options to use with CommandKit. ### typescript - + The typescript configuration to use with CommandKit. ### static @@ -106,12 +107,12 @@ Statically define the environment variables to use. The custom build directory name to use. ### antiCrashScript - + The anti-crash script configuration. ### sourceMap - + Whether or not to enable the source map generation. ### typedCommands @@ -124,6 +125,11 @@ Whether or not to enable the typed commands. Whether or not to disable the prefix commands. +### disablePermissionsMiddleware + + + +Whether or not to disable the built-in permissions middleware. This only affects `botPermissions` and `userPermissions` in the command metadata. ### showUnknownPrefixCommandsWarning diff --git a/apps/website/docs/api-reference/commandkit/interfaces/command-kit-options.mdx b/apps/website/docs/api-reference/commandkit/interfaces/command-kit-options.mdx index b7ba311d..0e2f31c6 100644 --- a/apps/website/docs/api-reference/commandkit/interfaces/command-kit-options.mdx +++ b/apps/website/docs/api-reference/commandkit/interfaces/command-kit-options.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## CommandKitOptions - + Options for instantiating a CommandKit handler. diff --git a/apps/website/docs/api-reference/commandkit/interfaces/command-metadata.mdx b/apps/website/docs/api-reference/commandkit/interfaces/command-metadata.mdx new file mode 100644 index 00000000..d16ccf89 --- /dev/null +++ b/apps/website/docs/api-reference/commandkit/interfaces/command-metadata.mdx @@ -0,0 +1,53 @@ +--- +title: "CommandMetadata" +isDefaultIndex: false +generated: true +--- + +import MemberInfo from '@site/src/components/MemberInfo'; +import GenerationInfo from '@site/src/components/GenerationInfo'; +import MemberDescription from '@site/src/components/MemberDescription'; + + + + +## CommandMetadata + + + +Represents the command metadata. + +```ts title="Signature" +interface CommandMetadata { + guilds?: string[]; + aliases?: string[]; + userPermissions?: PermissionsString | PermissionsString[]; + botPermissions?: PermissionsString | PermissionsString[]; +} +``` + +
+ +### guilds + + + +The guilds that the command is available in. +### aliases + + + +The aliases of the command. +### userPermissions + + + +The user permissions required to execute the command. +### botPermissions + + + +The bot permissions required to execute the command. + + +
diff --git a/apps/website/docs/api-reference/commandkit/interfaces/context-parameters.mdx b/apps/website/docs/api-reference/commandkit/interfaces/context-parameters.mdx index d5c2939f..055f9c5a 100644 --- a/apps/website/docs/api-reference/commandkit/interfaces/context-parameters.mdx +++ b/apps/website/docs/api-reference/commandkit/interfaces/context-parameters.mdx @@ -22,14 +22,14 @@ interface ContextParameters + ### message diff --git a/apps/website/docs/api-reference/commandkit/interfaces/custom-app-command-props.mdx b/apps/website/docs/api-reference/commandkit/interfaces/custom-app-command-props.mdx index 13705da7..1490ec86 100644 --- a/apps/website/docs/api-reference/commandkit/interfaces/custom-app-command-props.mdx +++ b/apps/website/docs/api-reference/commandkit/interfaces/custom-app-command-props.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## CustomAppCommandProps - + Custom properties that can be added to an AppCommand. This allows for additional metadata or configuration to be associated with a command. diff --git a/apps/website/docs/api-reference/commandkit/interfaces/event-flag-context.mdx b/apps/website/docs/api-reference/commandkit/interfaces/event-flag-context.mdx index 11b19d7e..be20fb31 100644 --- a/apps/website/docs/api-reference/commandkit/interfaces/event-flag-context.mdx +++ b/apps/website/docs/api-reference/commandkit/interfaces/event-flag-context.mdx @@ -21,35 +21,35 @@ Context for evaluating event flags in CommandKit. interface EventFlagContext { client: Client; commandkit: CommandKit; - event: { - /** - * The parsed event data, which contains the raw data from the event. - * This can include information like user IDs, channel IDs, and other relevant data. - */ - data: ParsedEvent; - /** - * The name of the event being processed. - * This is the string identifier for the event, such as 'messageCreate' or 'guildMemberAdd'. - */ - event: string; - /** - * The namespace of the event, if applicable. - * This can be used to group related events or commands together. - * It is null if the event does not belong to a specific namespace. - */ - namespace: string | null; - /** - * The arguments passed to the event handler. - * This is an array of arguments that were passed when the event was triggered. - * It can be used to access specific data related to the event. - */ - arguments: any[]; - /** - * A function to retrieve the arguments for a specific event type. - * This allows for type-safe access to the arguments based on the event name. - * @param event - The name of the event to retrieve arguments for. - */ - argumentsAs(event: E): ClientEvents[E]; + event: { + /** + * The parsed event data, which contains the raw data from the event. + * This can include information like user IDs, channel IDs, and other relevant data. + */ + data: ParsedEvent; + /** + * The name of the event being processed. + * This is the string identifier for the event, such as 'messageCreate' or 'guildMemberAdd'. + */ + event: string; + /** + * The namespace of the event, if applicable. + * This can be used to group related events or commands together. + * It is null if the event does not belong to a specific namespace. + */ + namespace: string | null; + /** + * The arguments passed to the event handler. + * This is an array of arguments that were passed when the event was triggered. + * It can be used to access specific data related to the event. + */ + arguments: any[]; + /** + * A function to retrieve the arguments for a specific event type. + * This allows for type-safe access to the arguments based on the event name. + * @param event - The name of the event to retrieve arguments for. + */ + argumentsAs(event: E): ClientEvents[E]; }; command: null; } @@ -61,25 +61,25 @@ interface EventFlagContext { -The Discord client instance. +The Discord client instance. This is the main entry point for interacting with the Discord API. ### commandkit CommandKit`} /> -The CommandKit instance, which provides access to the command framework. +The CommandKit instance, which provides access to the command framework. This includes commands, events, and other features of CommandKit. ### event -ParsedEvent; /** * The name of the event being processed. * This is the string identifier for the event, such as 'messageCreate' or 'guildMemberAdd'. */ event: string; /** * The namespace of the event, if applicable. * This can be used to group related events or commands together. * It is null if the event does not belong to a specific namespace. */ namespace: string | null; /** * The arguments passed to the event handler. * This is an array of arguments that were passed when the event was triggered. * It can be used to access specific data related to the event. */ arguments: any[]; /** * A function to retrieve the arguments for a specific event type. * This allows for type-safe access to the arguments based on the event name. * @param event - The name of the event to retrieve arguments for. */ argumentsAs<E extends keyof ClientEvents>(event: E): ClientEvents[E]; }`} /> +ParsedEvent; /** * The name of the event being processed. * This is the string identifier for the event, such as 'messageCreate' or 'guildMemberAdd'. */ event: string; /** * The namespace of the event, if applicable. * This can be used to group related events or commands together. * It is null if the event does not belong to a specific namespace. */ namespace: string | null; /** * The arguments passed to the event handler. * This is an array of arguments that were passed when the event was triggered. * It can be used to access specific data related to the event. */ arguments: any[]; /** * A function to retrieve the arguments for a specific event type. * This allows for type-safe access to the arguments based on the event name. * @param event - The name of the event to retrieve arguments for. */ argumentsAs<E extends keyof ClientEvents>(event: E): ClientEvents[E]; }`} /> -The event context, which includes information about the event being processed. +The event context, which includes information about the event being processed. This can include the parsed event data, the event name, and the namespace if applicable. ### command -The command context is null for event flags, as they are not tied to a specific command. +The command context is null for event flags, as they are not tied to a specific command. This is used to differentiate between command and event flags. diff --git a/apps/website/docs/api-reference/commandkit/interfaces/legacy-command-metadata.mdx b/apps/website/docs/api-reference/commandkit/interfaces/legacy-command-metadata.mdx new file mode 100644 index 00000000..6af246a2 --- /dev/null +++ b/apps/website/docs/api-reference/commandkit/interfaces/legacy-command-metadata.mdx @@ -0,0 +1,41 @@ +--- +title: "LegacyCommandMetadata" +isDefaultIndex: false +generated: true +--- + +import MemberInfo from '@site/src/components/MemberInfo'; +import GenerationInfo from '@site/src/components/GenerationInfo'; +import MemberDescription from '@site/src/components/MemberDescription'; + + + + +## LegacyCommandMetadata + + + + + +```ts title="Signature" +interface LegacyCommandMetadata { + aliases?: string[]; + guilds?: string[]; +} +``` + +
+ +### aliases + + + +The aliases of the command. +### guilds + + + +The guilds that the command is available in. + + +
diff --git a/apps/website/docs/api-reference/commandkit/interfaces/loaded-command.mdx b/apps/website/docs/api-reference/commandkit/interfaces/loaded-command.mdx index 998315f2..08af0497 100644 --- a/apps/website/docs/api-reference/commandkit/interfaces/loaded-command.mdx +++ b/apps/website/docs/api-reference/commandkit/interfaces/loaded-command.mdx @@ -13,15 +13,15 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## LoadedCommand - + Represents a loaded command with its metadata and configuration. ```ts title="Signature" interface LoadedCommand { command: Command; + metadata: CommandMetadata; data: AppCommand; - guilds?: string[]; } ``` @@ -32,14 +32,14 @@ interface LoadedCommand { Command`} /> -### data +### metadata -AppCommand`} /> +CommandMetadata`} /> -### guilds +### data - +AppCommand`} /> diff --git a/apps/website/docs/api-reference/commandkit/interfaces/prepared-app-command-execution.mdx b/apps/website/docs/api-reference/commandkit/interfaces/prepared-app-command-execution.mdx index 31c33be2..205e4491 100644 --- a/apps/website/docs/api-reference/commandkit/interfaces/prepared-app-command-execution.mdx +++ b/apps/website/docs/api-reference/commandkit/interfaces/prepared-app-command-execution.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## PreparedAppCommandExecution - + Represents a prepared command execution with all necessary data and middleware. diff --git a/apps/website/docs/api-reference/commandkit/types/app-command.mdx b/apps/website/docs/api-reference/commandkit/types/app-command.mdx index 6c08f161..59c97e40 100644 --- a/apps/website/docs/api-reference/commandkit/types/app-command.mdx +++ b/apps/website/docs/api-reference/commandkit/types/app-command.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## AppCommand - + Represents a command in the CommandKit application, including its metadata and handlers. This type extends the native command structure with additional properties. diff --git a/apps/website/docs/api-reference/commandkit/types/command-builder-like.mdx b/apps/website/docs/api-reference/commandkit/types/command-builder-like.mdx index 30c3ed1f..3ff95616 100644 --- a/apps/website/docs/api-reference/commandkit/types/command-builder-like.mdx +++ b/apps/website/docs/api-reference/commandkit/types/command-builder-like.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## CommandBuilderLike - + Type representing command builder objects supported by CommandKit. diff --git a/apps/website/docs/api-reference/commandkit/types/command-data-schema-value.mdx b/apps/website/docs/api-reference/commandkit/types/command-data-schema-value.mdx deleted file mode 100644 index 196a32fc..00000000 --- a/apps/website/docs/api-reference/commandkit/types/command-data-schema-value.mdx +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: "CommandDataSchemaValue" -isDefaultIndex: false -generated: true ---- - -import MemberInfo from '@site/src/components/MemberInfo'; -import GenerationInfo from '@site/src/components/GenerationInfo'; -import MemberDescription from '@site/src/components/MemberDescription'; - - - - -## CommandDataSchemaValue - - - - - -```ts title="Signature" -type CommandDataSchemaValue = CommandDataSchema[CommandDataSchemaKey] -``` diff --git a/apps/website/docs/api-reference/commandkit/types/command-data.mdx b/apps/website/docs/api-reference/commandkit/types/command-data.mdx index 8faa1350..d308cfe6 100644 --- a/apps/website/docs/api-reference/commandkit/types/command-data.mdx +++ b/apps/website/docs/api-reference/commandkit/types/command-data.mdx @@ -13,16 +13,17 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## CommandData - + Represents a command that can be executed by CommandKit. ```ts title="Signature" type CommandData = Prettify< Omit & { + /** + * The description of the command. + */ description?: string; - guilds?: string[]; - aliases?: string[]; - } + } & LegacyCommandMetadata > ``` diff --git a/apps/website/docs/api-reference/commandkit/types/command-data-schema-key.mdx b/apps/website/docs/api-reference/commandkit/types/command-metadata-function.mdx similarity index 57% rename from apps/website/docs/api-reference/commandkit/types/command-data-schema-key.mdx rename to apps/website/docs/api-reference/commandkit/types/command-metadata-function.mdx index d5fe2e01..e5c2ec46 100644 --- a/apps/website/docs/api-reference/commandkit/types/command-data-schema-key.mdx +++ b/apps/website/docs/api-reference/commandkit/types/command-metadata-function.mdx @@ -1,5 +1,5 @@ --- -title: "CommandDataSchemaKey" +title: "CommandMetadataFunction" isDefaultIndex: false generated: true --- @@ -11,12 +11,14 @@ import MemberDescription from '@site/src/components/MemberDescription'; -## CommandDataSchemaKey - - +## CommandMetadataFunction + +The command metadata function ```ts title="Signature" -type CommandDataSchemaKey = keyof CommandDataSchema +type CommandMetadataFunction = () => + | Promise + | CommandMetadata ``` diff --git a/apps/website/docs/api-reference/commandkit/types/command-type-data.mdx b/apps/website/docs/api-reference/commandkit/types/command-type-data.mdx index b2a06c35..d92c72fd 100644 --- a/apps/website/docs/api-reference/commandkit/types/command-type-data.mdx +++ b/apps/website/docs/api-reference/commandkit/types/command-type-data.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## CommandTypeData - + Type representing command data identifier. diff --git a/apps/website/docs/api-reference/commandkit/types/event-handler.mdx b/apps/website/docs/api-reference/commandkit/types/event-handler.mdx index 258bbde0..741a8488 100644 --- a/apps/website/docs/api-reference/commandkit/types/event-handler.mdx +++ b/apps/website/docs/api-reference/commandkit/types/event-handler.mdx @@ -13,12 +13,12 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## EventHandler - + Represents an event handler for a specific event. ```ts title="Signature" type EventHandler = ( - ...args: ClientEvents[K] + ...args: [...ClientEvents[K], Client, CommandKit] ) => void | Promise ``` diff --git a/apps/website/docs/api-reference/commandkit/types/resolvable-command.mdx b/apps/website/docs/api-reference/commandkit/types/resolvable-command.mdx index be379f6b..c1004c47 100644 --- a/apps/website/docs/api-reference/commandkit/types/resolvable-command.mdx +++ b/apps/website/docs/api-reference/commandkit/types/resolvable-command.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## ResolvableCommand - + Type for commands that can be resolved by the handler. diff --git a/apps/website/docs/api-reference/commandkit/types/run-command.mdx b/apps/website/docs/api-reference/commandkit/types/run-command.mdx index f2817cc8..1877338d 100644 --- a/apps/website/docs/api-reference/commandkit/types/run-command.mdx +++ b/apps/website/docs/api-reference/commandkit/types/run-command.mdx @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription'; ## RunCommand - + Function type for wrapping command execution with custom logic. diff --git a/apps/website/docs/api-reference/commandkit/types/command-data-schema.mdx b/apps/website/docs/api-reference/commandkit/variables/middleware-id.mdx similarity index 58% rename from apps/website/docs/api-reference/commandkit/types/command-data-schema.mdx rename to apps/website/docs/api-reference/commandkit/variables/middleware-id.mdx index e4284f18..90b18e61 100644 --- a/apps/website/docs/api-reference/commandkit/types/command-data-schema.mdx +++ b/apps/website/docs/api-reference/commandkit/variables/middleware-id.mdx @@ -1,5 +1,5 @@ --- -title: "CommandDataSchema" +title: "MiddlewareId" isDefaultIndex: false generated: true --- @@ -11,12 +11,9 @@ import MemberDescription from '@site/src/components/MemberDescription'; -## CommandDataSchema +## middlewareId - + -```ts title="Signature" -type CommandDataSchema = typeof commandDataSchema -``` diff --git a/apps/website/docs/api-reference/redis/classes/redis-mutex-storage.mdx b/apps/website/docs/api-reference/redis/classes/redis-mutex-storage.mdx index 16bdfec6..b2b3cb06 100644 --- a/apps/website/docs/api-reference/redis/classes/redis-mutex-storage.mdx +++ b/apps/website/docs/api-reference/redis/classes/redis-mutex-storage.mdx @@ -23,10 +23,10 @@ class RedisMutexStorage implements MutexStorage { acquire(key: string, timeout: number = this.defaultTimeout, signal?: AbortSignal) => Promise; release(key: string) => Promise; isLocked(key: string) => Promise; - getLockInfo(key: string) => Promise<{ - locked: boolean; - ttl: number; - value?: string; + getLockInfo(key: string) => Promise<{ + locked: boolean; + ttl: number; + value?: string; }>; forceRelease(key: string) => Promise; extendLock(key: string, additionalTime: number) => Promise; @@ -60,7 +60,7 @@ class RedisMutexStorage implements MutexStorage { ### getLockInfo - Promise<{ locked: boolean; ttl: number; value?: string; }>`} /> + Promise<{ locked: boolean; ttl: number; value?: string; }>`} /> Gets information about a lock including its TTL ### forceRelease diff --git a/apps/website/docs/api-reference/redis/classes/redis-semaphore-storage.mdx b/apps/website/docs/api-reference/redis/classes/redis-semaphore-storage.mdx index 19c1cac3..a73880b0 100644 --- a/apps/website/docs/api-reference/redis/classes/redis-semaphore-storage.mdx +++ b/apps/website/docs/api-reference/redis/classes/redis-semaphore-storage.mdx @@ -25,11 +25,11 @@ class RedisSemaphoreStorage implements SemaphoreStorage { getAvailablePermits(key: string) => Promise; getTotalPermits(key: string) => Promise; initialize(key: string, permits: number) => Promise; - getSemaphoreInfo(key: string) => Promise<{ - total: number; - available: number; - acquired: number; - initialized: boolean; + getSemaphoreInfo(key: string) => Promise<{ + total: number; + available: number; + acquired: number; + initialized: boolean; }>; reset(key: string, permits?: number) => Promise; increasePermits(key: string, additionalPermits: number) => Promise; @@ -75,7 +75,7 @@ class RedisSemaphoreStorage implements SemaphoreStorage { Initializes a semaphore with the specified number of permits ### getSemaphoreInfo - Promise<{ total: number; available: number; acquired: number; initialized: boolean; }>`} /> + Promise<{ total: number; available: number; acquired: number; initialized: boolean; }>`} /> Gets detailed information about a semaphore ### reset diff --git a/package.json b/package.json index 25b59dcd..3a160eff 100644 --- a/package.json +++ b/package.json @@ -80,4 +80,4 @@ "typescript": "catalog:build", "yaml": "^2.8.0" } -} \ No newline at end of file +} diff --git a/packages/ai/src/index.ts b/packages/ai/src/index.ts index dd432023..7fb2c259 100644 --- a/packages/ai/src/index.ts +++ b/packages/ai/src/index.ts @@ -60,3 +60,4 @@ export * from './configure'; export * from './types'; export * from './system-prompt'; export * from './tools/common/index'; +export { experimental_createConfig } from './utils'; diff --git a/packages/ai/src/plugin.ts b/packages/ai/src/plugin.ts index 37a9f8c2..09e5331b 100644 --- a/packages/ai/src/plugin.ts +++ b/packages/ai/src/plugin.ts @@ -17,7 +17,7 @@ import { ToolParameterType } from './tools/common'; /** * Represents the configuration options for the AI plugin scoped to a specific command. */ -export interface AiConfig { +export interface AiConfig { /** * A description of the AI functionality provided by this command. If not given, the command's description will be used. */ @@ -25,7 +25,7 @@ export interface AiConfig { /** * A zod schema defining the parameters that the AI command accepts. */ - inputSchema: ToolParameterType; + inputSchema: T; } const defaultTools: Record = { @@ -100,13 +100,8 @@ export class AiPlugin extends RuntimePlugin { await runInAiWorkerContext(ctx, message, async () => { const systemPrompt = await prepareSystemPrompt(ctx, message); const prompt = await preparePrompt(ctx, message); - const { - model, - abortSignal, - stopWhen, - prompt: _prompt, - ...modelOptions - } = await selectAiModel(ctx, message); + const { model, abortSignal, stopWhen, ...modelOptions } = + await selectAiModel(ctx, message); const promptOrMessage = ( typeof prompt === 'string' ? { prompt } : { messages: prompt } diff --git a/packages/ai/src/types.ts b/packages/ai/src/types.ts index 85cb361f..a44f2219 100644 --- a/packages/ai/src/types.ts +++ b/packages/ai/src/types.ts @@ -30,7 +30,10 @@ export type SelectAiModel = ( message: Message, ) => Promise; -export type SelectAiModelResult = Parameters[0]; +export type SelectAiModelResult = Omit< + Parameters[0], + 'messages' | 'prompt' +>; export type CommandTool = LoadedCommand & { tool: Tool; diff --git a/packages/ai/src/utils.ts b/packages/ai/src/utils.ts index ae85c8c0..ab3aff48 100644 --- a/packages/ai/src/utils.ts +++ b/packages/ai/src/utils.ts @@ -1,4 +1,7 @@ -import { TextBasedChannel } from 'discord.js'; +import { ApplicationCommandOptionType, TextBasedChannel } from 'discord.js'; +import { AiConfig } from './plugin'; +import { CommandData } from 'commandkit'; +import z from 'zod'; /** * @private @@ -26,3 +29,46 @@ export async function createTypingIndicator( clearInterval(typingInterval); }; } + +/** + * Generates AI config from a CommandKit command data. + * @experimental + */ +export function experimental_createConfig(command: CommandData): AiConfig { + const inputSchema = z.object({ + ...Object.fromEntries( + command.options?.map((option) => [ + option.name, + (() => { + const { type, required, description } = option; + + const t = (() => { + switch (type) { + case ApplicationCommandOptionType.String: + return z.string(); + case ApplicationCommandOptionType.Number: + return z.number(); + case ApplicationCommandOptionType.Boolean: + return z.boolean(); + case ApplicationCommandOptionType.Integer: + return z.int(); + default: + throw new Error(`Unsupported option type: ${type}`); + } + })().describe(description); + + if (!required) { + return t.optional(); + } + + return t; + })(), + ]) ?? [], + ), + }); + + return { + description: command.description ?? `${command.name} command tool`, + inputSchema, + } satisfies AiConfig; +}