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;
+}