@@ -3,15 +3,16 @@ import { AiPluginOptions, CommandTool } from './types';
33import CommandKit , { getCommandKit , Logger } from 'commandkit' ;
44import { AiContext } from './context' ;
55import { Collection , Events , Message } from 'discord.js' ;
6- import { tool , Tool , generateText } from 'ai' ;
6+ import { tool , Tool , generateText , stepCountIs , ModelMessage } from 'ai' ;
77import { getAiWorkerContext , runInAiWorkerContext } from './ai-context-worker' ;
88import { getAvailableCommands } from './tools/get-available-commands' ;
99import { getChannelById } from './tools/get-channel-by-id' ;
1010import { getCurrentClientInfo } from './tools/get-current-client-info' ;
1111import { getGuildById } from './tools/get-guild-by-id' ;
1212import { getUserById } from './tools/get-user-by-id' ;
13- import { AiMessage , getAIConfig } from './configure' ;
13+ import { getAIConfig } from './configure' ;
1414import { augmentCommandKit } from './augmentation' ;
15+ import { ToolParameterType } from './tools/common' ;
1516
1617/**
1718 * Represents the configuration options for the AI plugin scoped to a specific command.
@@ -24,7 +25,7 @@ export interface AiConfig {
2425 /**
2526 * A zod schema defining the parameters that the AI command accepts.
2627 */
27- parameters : any ;
28+ inputSchema : ToolParameterType ;
2829}
2930
3031const defaultTools : Record < string , Tool > = {
@@ -99,11 +100,19 @@ export class AiPlugin extends RuntimePlugin<AiPluginOptions> {
99100 await runInAiWorkerContext ( ctx , message , async ( ) => {
100101 const systemPrompt = await prepareSystemPrompt ( ctx , message ) ;
101102 const prompt = await preparePrompt ( ctx , message ) ;
102- const { model, abortSignal, maxSteps, ...modelOptions } =
103- await selectAiModel ( ctx , message ) ;
104-
105- const promptOrMessage =
106- typeof prompt === 'string' ? { prompt } : { messages : prompt } ;
103+ const {
104+ model,
105+ abortSignal,
106+ stopWhen,
107+ prompt : _prompt ,
108+ ...modelOptions
109+ } = await selectAiModel ( ctx , message ) ;
110+
111+ const promptOrMessage = (
112+ typeof prompt === 'string' ? { prompt } : { messages : prompt }
113+ ) as
114+ | { prompt : string ; messages : never }
115+ | { messages : ModelMessage [ ] ; prompt : never } ;
107116
108117 await onProcessingStart ( ctx , message ) ;
109118
@@ -112,7 +121,7 @@ export class AiPlugin extends RuntimePlugin<AiPluginOptions> {
112121 model,
113122 abortSignal : abortSignal ?? AbortSignal . timeout ( 60_000 ) ,
114123 system : systemPrompt ,
115- maxSteps : maxSteps ?? 5 ,
124+ stopWhen : stopWhen ?? stepCountIs ( 5 ) ,
116125 ...modelOptions ,
117126 tools : {
118127 // Include built-in least significant tools if not disabled
@@ -181,12 +190,12 @@ export class AiPlugin extends RuntimePlugin<AiPluginOptions> {
181190
182191 const cmdTool = tool ( {
183192 description,
184- parameters : cmd . data . aiConfig . parameters ,
193+ inputSchema : cmd . data . aiConfig . inputSchema ,
185194 async execute ( params ) {
186195 const config = getAIConfig ( ) ;
187196 const ctx = getAiWorkerContext ( ) ;
188197
189- ctx . ctx . setParams ( params ) ;
198+ ctx . ctx . setParams ( params as Record < string , unknown > ) ;
190199
191200 try {
192201 const target = await commandkit . commandHandler . prepareCommandRun (
0 commit comments