Skip to content

Allow aiConfig inference for AI-powered commands #374

@twlite

Description

@twlite

Currently, we have to manually export aiConfig for AI command parameters. We could make this optional by providing a way to automatically infer AI config from command definition.

Before

// command definition
export const command: CommandData = {
  name: 'remind',
  description: 'remind about something after the specified duration',
  options: [
    {
      name: 'time',
      description: 'The time to remind after. Eg: 6h, 10m, 1d',
      type: ApplicationCommandOptionType.String,
      required: true,
    },
    {
      name: 'message',
      description: 'The message to remind about.',
      type: ApplicationCommandOptionType.String,
      required: true,
    },
  ],
};

export const aiConfig = {
  description: 'remind about something after the specified duration',
  parameters: z.object({
    time: z.string().describe('The time to remind after. Eg: 6h, 10m, 1d'),
    message: z.string().describe('The message to remind about')
  })
} satisfies AiConfig;

New

// command definition
export const command = {
  name: 'remind',
  description: 'remind about something after the specified duration',
  options: [
    {
      name: 'time',
      description: 'The time to remind after. Eg: 6h, 10m, 1d',
      type: ApplicationCommandOptionType.String,
      required: true,
    },
    {
      name: 'message',
      description: 'The message to remind about.',
      type: ApplicationCommandOptionType.String,
      required: true,
    },
  ],
// use satisfies to preserve object shape
} satisfies CommandData;

// implicit inference: this means `aiConfig` is automatically set without declaration. We could do this but it makes type safety non-existing.
// explicit inference:
export const aiConfig = inferConfig<typeof command>(command)

Feel free to suggest ideas if you have any

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions