11import { config } from "dotenv" ;
22import type { ModelName } from "./providers" ;
33import type { ProviderConfig } from "./providers/types" ;
4- import type {
5- AgentResponse ,
6- AgentsExecutionResult ,
7- ToolCall ,
8- ToolCallStats ,
9- } from "./chunks/types" ;
4+ import type { AgentResponse , AgentsExecutionResult , ToolCall , ToolCallStats } from "./chunks/types" ;
105import { createProvider } from "./providers" ;
116
127config ( ) ;
@@ -31,7 +26,6 @@ export {
3126 * @template T - The type of model names to use
3227 * @param mcpServer - The MCP server configuration
3328 * @param models - Array of model names to execute
34- * @param scorers - Array of scorers to score the output of the tools
3529 * @param config - Optional provider configuration (API keys, silent mode, etc.)
3630 * @returns A configured AgentsClient instance
3731 *
@@ -53,13 +47,8 @@ export {
5347 * ```
5448 */
5549
56- export function client < T extends ModelName > (
57- mcpServer : McpServer ,
58- models : T [ ] ,
59- scorers ?: Scorer [ ] ,
60- config : ProviderConfig = { } ,
61- ) : AgentsClient < T > {
62- return new AgentsClient ( mcpServer , models , scorers , config ) ;
50+ export function client < T extends ModelName > ( mcpServer : McpServer , models : T [ ] , config : ProviderConfig = { } ) : AgentsClient < T > {
51+ return new AgentsClient ( mcpServer , models , config ) ;
6352}
6453
6554/**
@@ -86,15 +75,7 @@ export class Scorer {
8675 public scorer : ( toolResponse : any ) => number ;
8776 public tool : string ;
8877
89- constructor ( {
90- name,
91- scorer,
92- tool,
93- } : {
94- name : string ;
95- scorer : ( toolResponse : any ) => number ;
96- tool : string ;
97- } ) {
78+ constructor ( { name, scorer, tool } : { name : string ; scorer : ( toolResponse : any ) => number ; tool : string } ) {
9879 this . name = name ;
9980 this . scorer = scorer ;
10081 this . tool = tool ;
@@ -107,17 +88,7 @@ export class McpServer {
10788 public name : string ;
10889 public type : string ;
10990
110- constructor ( {
111- url,
112- authorizationToken,
113- name,
114- type,
115- } : {
116- url : string ;
117- authorizationToken : string ;
118- name : string ;
119- type : string ;
120- } ) {
91+ constructor ( { url, authorizationToken, name, type } : { url : string ; authorizationToken : string ; name : string ; type : string } ) {
12192 this . url = url ;
12293 this . authorizationToken = authorizationToken ;
12394 this . name = name ;
@@ -139,7 +110,7 @@ export class AgentsResult<T extends ModelName = ModelName> {
139110 endTime : number ,
140111 models : T [ ] ,
141112 agentsInstance ?: AgentsClient < T > ,
142- scorers ?: Scorer [ ] ,
113+ scorers ?: Scorer [ ]
143114 ) {
144115 this . responses = responses ;
145116 this . executionStartTime = startTime ;
@@ -189,15 +160,13 @@ export class AgentsResult<T extends ModelName = ModelName> {
189160 const successfulExecutions = Object . keys ( this . responses ) . length ;
190161 const failedExecutions = this . models . length - successfulExecutions ;
191162
192- const allTools = ( Object . values ( this . responses ) as AgentResponse [ ] ) . flatMap (
193- ( r ) => r . usedTools ,
194- ) ;
163+ const allTools = ( Object . values ( this . responses ) as AgentResponse [ ] ) . flatMap ( ( r ) => r . usedTools ) ;
195164 const toolCounts = allTools . reduce (
196165 ( acc , tool ) => {
197166 acc [ tool ] = ( acc [ tool ] || 0 ) + 1 ;
198167 return acc ;
199168 } ,
200- { } as Record < string , number > ,
169+ { } as Record < string , number >
201170 ) ;
202171
203172 const commonTools = Object . entries ( toolCounts )
@@ -231,18 +200,13 @@ export class AgentsResult<T extends ModelName = ModelName> {
231200 }
232201
233202 stats [ toolName ] . callCount += ( calls as any [ ] ) . length ;
234- stats [ toolName ] . lastCalled = Math . max (
235- stats [ toolName ] . lastCalled || 0 ,
236- response . metadata ?. timestamp || 0 ,
237- ) ;
203+ stats [ toolName ] . lastCalled = Math . max ( stats [ toolName ] . lastCalled || 0 , response . metadata ?. timestamp || 0 ) ;
238204 } ) ;
239205 } ) ;
240206
241207 return Object . values ( stats ) . map ( ( stat ) => ( {
242208 ...stat ,
243- averageDuration : stat . totalDuration
244- ? stat . totalDuration / stat . callCount
245- : undefined ,
209+ averageDuration : stat . totalDuration ? stat . totalDuration / stat . callCount : undefined ,
246210 } ) ) ;
247211 }
248212
@@ -286,15 +250,10 @@ export class AgentsClient<T extends ModelName = ModelName> {
286250 private config : ProviderConfig ;
287251 private _scorers : Scorer [ ] = [ ] ;
288252
289- constructor (
290- mcpServer : McpServer ,
291- models : T [ ] ,
292- scorers ?: Scorer [ ] ,
293- config : ProviderConfig = { } ,
294- ) {
253+ constructor ( mcpServer : McpServer , models : T [ ] , config : ProviderConfig = { } ) {
295254 this . models = models ;
296255 this . mcpServer = mcpServer ;
297- this . _scorers = scorers || [ ] ;
256+ this . _scorers = config . scorers || [ ] ;
298257 this . config = { silent : true , ...config } ;
299258 }
300259
@@ -313,26 +272,21 @@ export class AgentsClient<T extends ModelName = ModelName> {
313272 name : string ;
314273 tool : string ;
315274 scorer : ( toolResponse : any ) => number ;
316- } > ,
275+ } >
317276 ) : this {
318277 this . _scorers = scorers . map ( ( s ) => new Scorer ( s ) ) ;
319278 return this ;
320279 }
321280
322- async execute ( ) : Promise < AgentsResult < T > > {
281+ private async execute ( ) : Promise < AgentsResult < T > > {
323282 if ( ! this . mcpServer ) {
324283 throw new Error ( "MCP server not set" ) ;
325284 }
326285
327286 const executionStartTime = Date . now ( ) ;
328287
329288 this . executionPromises = this . models . map ( async ( model ) => {
330- const provider = createProvider (
331- model ,
332- this . mcpServer ! ,
333- this . promptText ,
334- this . config ,
335- ) ;
289+ const provider = createProvider ( model , this . mcpServer ! , this . promptText , this . config ) ;
336290 const result = await provider . stream ( model ) ;
337291
338292 this . usedTools [ model ] = result . usedTools ;
@@ -358,16 +312,9 @@ export class AgentsClient<T extends ModelName = ModelName> {
358312 acc [ response . model as T ] = response ;
359313 return acc ;
360314 } ,
361- { } as Record < T , AgentResponse > ,
315+ { } as Record < T , AgentResponse >
362316 ) ;
363317
364- return new AgentsResult (
365- responsesMap ,
366- executionStartTime ,
367- executionEndTime ,
368- this . models ,
369- this ,
370- this . _scorers ,
371- ) ;
318+ return new AgentsResult ( responsesMap , executionStartTime , executionEndTime , this . models , this , this . _scorers ) ;
372319 }
373320}
0 commit comments