Skip to content

Commit 6b5e0e4

Browse files
committed
fix: ai plugin enhancements
1 parent 2dd8ea0 commit 6b5e0e4

35 files changed

+1575
-2344
lines changed

apps/test-bot/src/app/commands/(interactions)/confirmation.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import {
44
ChatInputCommandContext,
55
CommandData,
66
OnButtonKitClick,
7-
MessageCommandContext,
87
} from 'commandkit';
98
import { ButtonStyle, MessageFlags } from 'discord.js';
10-
import { AiConfig, AiContext } from '@commandkit/ai';
9+
import { AiConfig, AiCommand } from '@commandkit/ai';
1110
import { z } from 'zod';
1211

1312
export const command: CommandData = {
@@ -60,8 +59,8 @@ export async function chatInput({ interaction }: ChatInputCommandContext) {
6059
});
6160
}
6261

63-
export async function ai(ctx: MessageCommandContext) {
64-
const message = ctx.ai?.params?.message as string;
62+
export const ai: AiCommand<typeof aiConfig> = async (ctx) => {
63+
const message = ctx.ai.params.message;
6564

6665
const buttons = (
6766
<ActionRow>
@@ -78,4 +77,4 @@ export async function ai(ctx: MessageCommandContext) {
7877
content: message || 'There was no confirmation message provided.',
7978
components: [buttons],
8079
});
81-
}
80+
};

apps/test-bot/src/app/commands/(leveling)/xp.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from 'commandkit';
66
import { database } from '@/database/store.ts';
77
import { cacheTag } from '@commandkit/cache';
8-
import { AiConfig } from '@commandkit/ai';
8+
import { AiCommand, AiConfig } from '@commandkit/ai';
99
import { z } from 'zod';
1010

1111
export const command: CommandData = {
@@ -54,7 +54,7 @@ export async function chatInput({ interaction }: ChatInputCommandContext) {
5454
});
5555
}
5656

57-
export async function ai(ctx: MessageCommandContext) {
57+
export const ai: AiCommand<typeof aiConfig> = async (ctx) => {
5858
const message = ctx.message;
5959

6060
if (!message.inGuild()) {
@@ -63,9 +63,7 @@ export async function ai(ctx: MessageCommandContext) {
6363
};
6464
}
6565

66-
const { guildId, userId } = ctx.ai?.params as z.infer<
67-
(typeof aiConfig)['parameters']
68-
>;
66+
const { guildId, userId } = ctx.ai.params;
6967

7068
const xp = await getUserXP(guildId, userId);
7169

@@ -74,4 +72,4 @@ export async function ai(ctx: MessageCommandContext) {
7472
guildId,
7573
xp,
7674
};
77-
}
75+
};

apps/website/docs/api-reference/ai/functions/configure-ai.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
1313

1414
## configureAI
1515

16-
<GenerationInfo sourceFile="packages/ai/src/configure.ts" sourceLine="128" packageName="@commandkit/ai" />
16+
<GenerationInfo sourceFile="packages/ai/src/configure.ts" sourceLine="170" packageName="@commandkit/ai" />
1717

1818
Configures the AI plugin with the provided options.
1919
This function allows you to set a message filter, select an AI model, and generate a system prompt.

apps/website/docs/api-reference/ai/functions/get-aiconfig.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
1313

1414
## getAIConfig
1515

16-
<GenerationInfo sourceFile="packages/ai/src/configure.ts" sourceLine="119" packageName="@commandkit/ai" />
16+
<GenerationInfo sourceFile="packages/ai/src/configure.ts" sourceLine="161" packageName="@commandkit/ai" />
1717

1818
Retrieves the current AI configuration.
1919

apps/website/docs/api-reference/ai/interfaces/ai-plugin-options.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
1313

1414
## AiPluginOptions
1515

16-
<GenerationInfo sourceFile="packages/ai/src/types.ts" sourceLine="43" packageName="@commandkit/ai" />
16+
<GenerationInfo sourceFile="packages/ai/src/types.ts" sourceLine="45" packageName="@commandkit/ai" />
1717

1818
Options for the AI plugin.
1919

apps/website/docs/api-reference/ai/interfaces/configure-ai.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
1313

1414
## ConfigureAI
1515

16-
<GenerationInfo sourceFile="packages/ai/src/configure.ts" sourceLine="13" packageName="@commandkit/ai" />
16+
<GenerationInfo sourceFile="packages/ai/src/configure.ts" sourceLine="16" packageName="@commandkit/ai" />
1717

1818
Represents the configuration options for the AI model.
1919

@@ -23,7 +23,10 @@ interface ConfigureAI {
2323
messageFilter?: MessageFilter;
2424
selectAiModel: SelectAiModel;
2525
prepareSystemPrompt?: (ctx: AiContext, message: Message) => Promise<string>;
26-
preparePrompt?: (ctx: AiContext, message: Message) => Promise<string>;
26+
preparePrompt?: (
27+
ctx: AiContext,
28+
message: Message,
29+
) => Promise<string | AiMessage>;
2730
onProcessingStart?: (ctx: AiContext, message: Message) => Promise<void>;
2831
onProcessingFinish?: (ctx: AiContext, message: Message) => Promise<void>;
2932
onResult?: (
@@ -63,7 +66,7 @@ This function should return a promise that resolves to a string containing the s
6366
If not provided, a default system prompt will be used.
6467
### preparePrompt
6568

66-
<MemberInfo kind="property" type={`(ctx: <a href='/docs/next/api-reference/ai/classes/ai-context#aicontext'>AiContext</a>, message: Message) =&#62; Promise&#60;string&#62;`} />
69+
<MemberInfo kind="property" type={`( ctx: <a href='/docs/next/api-reference/ai/classes/ai-context#aicontext'>AiContext</a>, message: Message, ) =&#62; Promise&#60;string | <a href='/docs/next/api-reference/ai/types/ai-message#aimessage'>AiMessage</a>&#62;`} />
6770

6871
A function that prepares the prompt for the AI model.
6972
### onProcessingStart
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: "AiCommandContext"
3+
isDefaultIndex: false
4+
generated: true
5+
---
6+
7+
import MemberInfo from '@site/src/components/MemberInfo';
8+
import GenerationInfo from '@site/src/components/GenerationInfo';
9+
import MemberDescription from '@site/src/components/MemberDescription';
10+
11+
<!-- This file was generated from the CommandKit source. Do not modify. Instead, re-run the "docgen" script -->
12+
13+
14+
## AiCommandContext
15+
16+
<GenerationInfo sourceFile="packages/ai/src/types.ts" sourceLine="58" packageName="@commandkit/ai" />
17+
18+
Represents the context in which an AI command is executed.
19+
It extends the MessageCommandContext to include AI-specific properties.
20+
21+
```ts title="Signature"
22+
type AiCommandContext<T extends Record<string, unknown>> = MessageCommandContext & { ai: AiContext<ExtractAiConfig<T>> }
23+
```

apps/website/docs/api-reference/ai/types/ai-command.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ import MemberDescription from '@site/src/components/MemberDescription';
1313

1414
## AiCommand
1515

16-
<GenerationInfo sourceFile="packages/ai/src/types.ts" sourceLine="50" packageName="@commandkit/ai" />
16+
<GenerationInfo sourceFile="packages/ai/src/types.ts" sourceLine="66" packageName="@commandkit/ai" />
1717

1818
Represents a command that can be executed by the AI.
1919

2020
```ts title="Signature"
21-
type AiCommand<T extends Record<string, unknown>> = (
22-
ctx: AiContext<T>,
23-
) => Promise<unknown> | unknown
21+
type AiCommand<T extends Record<string, unknown> = Record<string, unknown>> = (ctx: AiCommandContext<ExtractAiConfig<T>>) => Promise<unknown> | unknown
2422
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: "AiMessage"
3+
isDefaultIndex: false
4+
generated: true
5+
---
6+
7+
import MemberInfo from '@site/src/components/MemberInfo';
8+
import GenerationInfo from '@site/src/components/GenerationInfo';
9+
import MemberDescription from '@site/src/components/MemberDescription';
10+
11+
<!-- This file was generated from the CommandKit source. Do not modify. Instead, re-run the "docgen" script -->
12+
13+
14+
## AiMessage
15+
16+
<GenerationInfo sourceFile="packages/ai/src/configure.ts" sourceLine="9" packageName="@commandkit/ai" />
17+
18+
19+
20+
```ts title="Signature"
21+
type AiMessage = Parameters<typeof generateText>[0]['messages'] & {}
22+
```

apps/website/docs/api-reference/ai/types/aigenerate-result.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
1313

1414
## AIGenerateResult
1515

16-
<GenerationInfo sourceFile="packages/ai/src/types.ts" sourceLine="9" packageName="@commandkit/ai" />
16+
<GenerationInfo sourceFile="packages/ai/src/types.ts" sourceLine="11" packageName="@commandkit/ai" />
1717

1818
Represents the result of an AI text generation operation.
1919

0 commit comments

Comments
 (0)