@@ -18,7 +18,6 @@ import { Loop } from '../mcp/sdk/bundle';
1818
1919import type z from 'zod' ;
2020import type { Client } from '@modelcontextprotocol/sdk/client/index.js' ;
21- import type { Tool } from '@modelcontextprotocol/sdk/types.js' ;
2221import type * as tinyLoop from 'tiny-loop' ;
2322
2423type Logger = ( category : string , text : string , details ?: string ) => void ;
@@ -33,14 +32,18 @@ export type AgentSpec = {
3332 examples : string [ ] ;
3433} ;
3534
35+ type LoopOptions = ConstructorParameters < typeof tinyLoop . Loop > [ 1 ] & {
36+ loopName : 'copilot' | 'claude' | 'openai' ;
37+ } ;
38+
3639export class Agent < T extends z . ZodSchema < any > > {
3740 readonly loop : tinyLoop . Loop ;
3841 readonly spec : AgentSpec ;
3942 readonly clients : Map < string , Client > ;
40- readonly resultSchema : Tool [ 'inputSchema' ] ;
43+ readonly resultSchema : tinyLoop . Schema ;
4144
42- constructor ( loopName : 'copilot' | 'claude' | 'openai' , spec : AgentSpec , clients : Map < string , Client > , resultSchema : Tool [ 'inputSchema' ] ) {
43- this . loop = new Loop ( loopName ) ;
45+ constructor ( loopOptions : LoopOptions , spec : AgentSpec , clients : Map < string , Client > , resultSchema : tinyLoop . Schema ) {
46+ this . loop = new Loop ( loopOptions . loopName , loopOptions ) ;
4447 this . spec = spec ;
4548 this . clients = clients ;
4649 this . resultSchema = resultSchema ;
@@ -52,9 +55,8 @@ export class Agent<T extends z.ZodSchema<any>> {
5255 try {
5356 return await this . loop . run < z . output < T > > ( `${ prompt } \n\nTask:\n${ task } \n\nParams:\n${ JSON . stringify ( params , null , 2 ) } ` , {
5457 ...options ,
55- // TODO: fix types in tiny-loop
56- tools : tools as any ,
57- callTool : callTool as any ,
58+ tools,
59+ callTool,
5860 resultSchema : this . resultSchema
5961 } ) ;
6062 } finally {
@@ -65,15 +67,15 @@ export class Agent<T extends z.ZodSchema<any>> {
6567 private async _initClients ( ) {
6668 const clients : Record < string , Client > = { } ;
6769 const agentToolNames = new Set < string > ( this . spec . tools ) ;
68- const tools : Tool [ ] = [ ] ;
70+ const tools : tinyLoop . Tool [ ] = [ ] ;
6971
7072 for ( const [ name , client ] of this . clients . entries ( ) ) {
7173 const list = await client . listTools ( ) ;
7274 for ( const tool of list . tools ) {
7375 if ( ! agentToolNames . has ( name + '/' + tool . name ) )
7476 continue ;
7577 agentToolNames . delete ( name + '/' + tool . name ) ;
76- tools . push ( { ...tool , name : name + '__' + tool . name } ) ;
78+ tools . push ( { ...tool as tinyLoop . Tool , name : name + '__' + tool . name } ) ;
7779 }
7880 clients [ name ] = client ;
7981 }
0 commit comments