@@ -81,9 +81,10 @@ export class Muppet<E extends Env = BlankEnv> {
8181
8282 #errorHandler: ErrorHandler < E > = ( err : Error , ctx ) => {
8383 ctx . error = {
84- code : "code" in err && Number . isSafeInteger ( err . code )
85- ? Number ( err . code )
86- : ErrorCode . InternalError ,
84+ code :
85+ "code" in err && Number . isSafeInteger ( err . code )
86+ ? Number ( err . code )
87+ : ErrorCode . InternalError ,
8788 message : err . message ?? "Internal error" ,
8889 data : "data" in err ? err . data : undefined ,
8990 } ;
@@ -126,10 +127,11 @@ export class Muppet<E extends Env = BlankEnv> {
126127 ...args : ( ToolHandler < E , I , O > | ToolMiddlewareHandler < E , I , O > ) [ ]
127128 ) {
128129 if ( typeof args1 === "object" && ! Array . isArray ( args1 ) ) {
129- this . #id = ` ${ this . prefix } ${ args1 . name } ` ;
130+ this . #id = args1 . name ;
130131 this . routes . push ( {
131132 type : "tool" ,
132133 ...args1 ,
134+ name : `${ this . prefix } ${ args1 . name } ` ,
133135 } ) ;
134136 } else {
135137 this . routes . push ( {
@@ -165,12 +167,13 @@ export class Muppet<E extends Env = BlankEnv> {
165167 ...args : ( PromptHandler < E , I > | PromptMiddlewareHandler < E , I > ) [ ]
166168 ) {
167169 if ( typeof args1 === "object" && ! Array . isArray ( args1 ) ) {
168- this . #id = ` ${ this . prefix } ${ args1 . name } ` ;
170+ this . #id = args1 . name ;
169171 this . routes . push (
170172 // @ts -expect-error
171173 {
172174 type : "prompt" ,
173175 ...args1 ,
176+ name : `${ this . prefix } ${ args1 . name } ` ,
174177 } ,
175178 ) ;
176179 } else {
@@ -207,14 +210,15 @@ export class Muppet<E extends Env = BlankEnv> {
207210 ...args : ( ResourceHandler < E > | ResourceMiddlewareHandler < E > ) [ ]
208211 ) {
209212 if ( typeof args1 === "object" && ! Array . isArray ( args1 ) ) {
210- this . #id = ` ${ this . prefix } ${ args1 . name } ` ;
213+ this . #id = args1 . name ;
211214 const type = "uriTemplate" in args1 ? "resource-template" : "resource" ;
212215
213216 this . routes . push (
214217 // @ts -expect-error
215218 {
216219 ...args1 ,
217220 type,
221+ name : `${ this . prefix } ${ args1 . name } `
218222 } ,
219223 ) ;
220224 } else {
@@ -589,7 +593,7 @@ export class Muppet<E extends Env = BlankEnv> {
589593 route . type === "resource" && route . uri === message . params . uri ,
590594 ) ;
591595
592- let middlewares : MiddlewareOptions [ "handler" ] [ ] = [ ] ;
596+ const middlewares : MiddlewareOptions [ "handler" ] [ ] = [ ] ;
593597 let variables : Record < string , unknown > = { } ;
594598
595599 if ( resource ) {
@@ -639,11 +643,9 @@ export class Muppet<E extends Env = BlankEnv> {
639643 variables = { ...match } ;
640644
641645 if ( resourceTemplate . arguments ) {
642- for (
643- const [ key , value ] of Object . entries (
644- resourceTemplate . arguments ,
645- )
646- ) {
646+ for ( const [ key , value ] of Object . entries (
647+ resourceTemplate . arguments ,
648+ ) ) {
647649 const validationResponse = await value . validation [
648650 "~standard"
649651 ] . validate ( variables [ key ] ) ;
@@ -723,9 +725,9 @@ export class Muppet<E extends Env = BlankEnv> {
723725 ) ;
724726
725727 if ( promptOptions ?. type === "prompt" ) {
726- completionFn = promptOptions . arguments
727- ?. [ message . params . argument . name ]
728- ?. completion ;
728+ completionFn =
729+ promptOptions . arguments ?. [ message . params . argument . name ]
730+ ?. completion ;
729731 }
730732 } else if ( message . params . ref . type === "ref/resource" ) {
731733 const resourceURI = message . params . ref . uri ;
@@ -737,17 +739,16 @@ export class Muppet<E extends Env = BlankEnv> {
737739 ) ;
738740
739741 if ( resourceOptions ?. type === "resource-template" ) {
740- completionFn = resourceOptions . arguments
741- ?. [ message . params . argument . name ]
742- ?. completion ;
742+ completionFn =
743+ resourceOptions . arguments ?. [ message . params . argument . name ]
744+ ?. completion ;
743745 }
744746 }
745747
746748 if ( ! completionFn ) {
747749 options . context . error = {
748750 code : ErrorCode . InvalidParams ,
749- message :
750- `No completion function found for ${ message . params . ref . type } ` ,
751+ message : `No completion function found for ${ message . params . ref . type } ` ,
751752 } ;
752753
753754 return ;
0 commit comments