Skip to content

Commit 75397fe

Browse files
committed
feat: Enhance documentation and type definitions across CommandKit and related plugins
- Added detailed JSDoc comments to various classes and methods in CommandKitPluginRuntime and CompilerPluginRuntime for better clarity and understanding. - Introduced new interfaces and types to improve type safety and documentation in the i18n package. - Enhanced the legacy commands and validations with comprehensive comments to clarify their purpose and usage. - Removed unused utility functions and improved existing ones with better documentation. - Updated Redis plugin to include documentation for the creation of new instances. - Overall improvements to the structure and readability of the codebase through consistent documentation practices.
1 parent 326743b commit 75397fe

File tree

107 files changed

+2452
-68
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+2452
-68
lines changed

packages/ai/src/ai-context-worker.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { AiContext } from './context';
44

55
const worker = new AsyncLocalStorage<{ message: Message; ctx: AiContext }>();
66

7+
/**
8+
* @private
9+
*/
710
export function getAiWorkerContext(): { message: Message; ctx: AiContext } {
811
const ctx = worker.getStore();
912

@@ -16,6 +19,9 @@ export function getAiWorkerContext(): { message: Message; ctx: AiContext } {
1619
return ctx;
1720
}
1821

22+
/**
23+
* @private
24+
*/
1925
export function runInAiWorkerContext<R, F extends (...args: any[]) => R>(
2026
ctx: AiContext,
2127
message: Message,

packages/ai/src/context.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,46 @@ export interface AiContextOptions<
99
commandkit: CommandKit;
1010
}
1111

12+
/**
13+
* Represents the context in which an AI command is executed.
14+
* This includes the parameters passed to the command, the message that triggered it,
15+
* and the CommandKit instance associated with the command.
16+
*/
1217
export class AiContext<
1318
T extends Record<string, unknown> = Record<string, unknown>,
1419
> {
20+
/**
21+
* The parameters passed to the AI command.
22+
*/
1523
public params!: T;
24+
/**
25+
* The message that triggered the AI command.
26+
*/
1627
public message!: Message;
28+
/**
29+
* The client instance associated with the AI command.
30+
*/
1731
public client!: Client;
32+
/**
33+
* The CommandKit instance associated with the AI command.
34+
*/
1835
public commandkit!: CommandKit;
1936

37+
/**
38+
* Creates a new instance of AiContext.
39+
* @param options - The options for the AI context, including the message, parameters, and CommandKit instance.
40+
*/
2041
public constructor(options: AiContextOptions<T>) {
2142
this.params = options.params;
2243
this.message = options.message;
2344
this.commandkit = options.commandkit;
2445
this.client = options.commandkit.client;
2546
}
2647

48+
/**
49+
* Sets the parameters for the AI context.
50+
* @param params - The parameters to set.
51+
*/
2752
public setParams(params: T): void {
2853
this.params = params;
2954
}

packages/ai/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { AiPlugin } from './plugin';
22
import { AiPluginOptions } from './types';
33

4+
/**
5+
* Defines the AI plugin for the application.
6+
* @param options The options for the AI plugin
7+
* @returns The AI plugin instance
8+
*/
49
export function ai(options?: AiPluginOptions) {
510
return new AiPlugin(options ?? {});
611
}

packages/ai/src/plugin.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,51 @@ type WithAI<T extends LoadedCommand> = T & {
1616
tool: Tool;
1717
};
1818

19+
/**
20+
* Represents the configuration options for the AI plugin scoped to a specific command.
21+
*/
1922
export interface AiConfig {
23+
/**
24+
* A description of the AI functionality provided by this command. If not given, the command's description will be used.
25+
*/
2026
description?: string;
27+
/**
28+
* A zod schema defining the parameters that the AI command accepts.
29+
*/
2130
parameters: any;
2231
}
2332

2433
let messageFilter: MessageFilter | null = null;
2534
let selectAiModel: SelectAiModel | null = null;
2635
let generateSystemPrompt: ((message: Message) => Promise<string>) | undefined;
2736

37+
/**
38+
* Represents the configuration options for the AI model.
39+
*/
2840
export interface ConfigureAI {
41+
/**
42+
* A filter function that determines whether a message should be processed by the AI.
43+
* CommandKit invokes this function before processing the message.
44+
*/
2945
messageFilter?: MessageFilter;
46+
/**
47+
* A function that selects the AI model to use based on the message.
48+
* This function should return a promise that resolves to an object containing the model and options.
49+
*/
3050
selectAiModel?: SelectAiModel;
51+
/**
52+
* A function that generates a system prompt based on the message.
53+
* This function should return a promise that resolves to a string containing the system prompt.
54+
* If not provided, a default system prompt will be used.
55+
*/
3156
systemPrompt?: (message: Message) => Promise<string>;
3257
}
3358

59+
/**
60+
* Configures the AI plugin with the provided options.
61+
* This function allows you to set a message filter, select an AI model, and generate a system prompt.
62+
* @param config The configuration options for the AI plugin.
63+
*/
3464
export function configureAI(config: ConfigureAI): void {
3565
if (config.messageFilter) {
3666
messageFilter = config.messageFilter;

packages/ai/src/types.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,41 @@ import { LanguageModelV1, ProviderMetadata } from 'ai';
22
import { Message } from 'discord.js';
33
import { AiContext } from './context';
44

5+
/**
6+
* Function type for filtering commands based on their name.
7+
* @param commandName - The name of the command to filter.
8+
* @returns A boolean indicating whether the command should be included in the filter.
9+
*/
510
export type CommandFilterFunction = (commandName: string) => boolean;
611

12+
/**
13+
* Function type for filtering messages before they are processed by the AI.
14+
* @param message - The message to filter.
15+
* @returns A promise that resolves to a boolean indicating whether the message should be processed.
16+
*/
717
export type MessageFilter = (message: Message) => Promise<boolean>;
818

19+
/**
20+
* Function type for selecting an AI model based on the message.
21+
* @param message - The message to base the model selection on.
22+
* @returns A promise that resolves to an object containing the selected model and optional metadata.
23+
*/
924
export type SelectAiModel = (message: Message) => Promise<{
1025
model: LanguageModelV1;
1126
options?: ProviderMetadata;
1227
objectMode?: boolean;
1328
}>;
1429

30+
/**
31+
* Options for the AI plugin.
32+
*/
1533
export interface AiPluginOptions {}
1634

35+
/**
36+
* Represents a command that can be executed by the AI.
37+
* @param T - The type of parameters that the command accepts.
38+
* @param ctx - The AI context in which the command is executed, including the message and parameters.
39+
*/
1740
export type AiCommand<T extends Record<string, unknown>> = (
1841
ctx: AiContext<T>,
1942
) => Promise<unknown> | unknown;

packages/analytics/src/posthog/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { PostHogPlugin, PostHogPluginOptions } from './plugin';
22

3+
/**
4+
* Defines the PostHog plugin for the application.
5+
* @param options The options for the PostHog plugin
6+
* @returns The PostHog plugin instance
7+
*/
38
export function posthog(options: PostHogPluginOptions) {
49
return new PostHogPlugin(options);
510
}

packages/analytics/src/posthog/plugin.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@ import { CommandKitPluginRuntime, RuntimePlugin } from 'commandkit/plugin';
22
import { PostHog, PostHogOptions } from 'posthog-node';
33
import { PostHogProvider } from './provider';
44

5+
/**
6+
* Options for the PostHog plugin.
7+
*/
58
export interface PostHogPluginOptions {
9+
/**
10+
* The PostHog API key and options.
11+
*/
612
posthogOptions: {
13+
/**
14+
* The PostHog API key.
15+
*/
716
apiKey: string;
17+
/**
18+
* Additional options for the PostHog client.
19+
*/
820
options?: PostHogOptions;
921
};
1022
}

packages/analytics/src/posthog/provider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import {
66
IdentifyEvent,
77
} from 'commandkit/analytics';
88

9+
/**
10+
* PostHog analytics provider for CommandKit.
11+
* This provider allows you to track events and identify users using PostHog.
12+
*/
913
export class PostHogProvider implements AnalyticsProvider {
1014
public readonly name = 'PostHog';
1115
public constructor(public readonly posthog: PostHog) {}

packages/analytics/src/umami/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { UmamiPlugin, UmamiPluginOptions } from './plugin';
22

3+
/**
4+
* Defines the Umami plugin for the application.
5+
* @param options The options for the Umami plugin
6+
* @returns The Umami plugin instance
7+
*/
38
export function umami(options: UmamiPluginOptions) {
49
return new UmamiPlugin(options);
510
}

packages/analytics/src/umami/plugin.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { UmamiOptions, Umami } from '@umami/node';
22
import { CommandKitPluginRuntime, RuntimePlugin } from 'commandkit/plugin';
33
import { UmamiProvider } from './provider';
44

5+
/**
6+
* Options for the Umami plugin.
7+
*/
58
export interface UmamiPluginOptions {
9+
/**
10+
* The Umami API options.
11+
*/
612
umamiOptions: UmamiOptions;
713
}
814

0 commit comments

Comments
 (0)