@@ -118,10 +118,7 @@ export class ExperimentalServerTasks {
118118 options ?: RequestOptions
119119 ) : AsyncGenerator < ResponseMessage < CreateMessageResult > , void , void > {
120120 // Access client capabilities via the server
121- type ServerWithCapabilities = {
122- getClientCapabilities ( ) : { sampling ?: { tools ?: boolean } } | undefined ;
123- } ;
124- const clientCapabilities = ( this . _server as unknown as ServerWithCapabilities ) . getClientCapabilities ( ) ;
121+ const clientCapabilities = this . _server . getClientCapabilities ( ) ;
125122
126123 // Capability check - only required when tools/toolChoice are provided
127124 if ( ( params . tools || params . toolChoice ) && ! clientCapabilities ?. sampling ?. tools ) {
@@ -153,23 +150,22 @@ export class ExperimentalServerTasks {
153150 }
154151 }
155152 if ( hasPreviousToolUse ) {
156- type ToolUseContent = { type : 'tool_use' ; id : string } ;
157- type ToolResultContent = { type : 'tool_result' ; toolUseId : string } ;
158- const toolUseIds = new Set ( previousContent . filter ( c => c . type === 'tool_use' ) . map ( c => ( c as ToolUseContent ) . id ) ) ;
159- const toolResultIds = new Set (
160- lastContent . filter ( c => c . type === 'tool_result' ) . map ( c => ( c as ToolResultContent ) . toolUseId )
161- ) ;
153+ const toolUseIds = new Set ( previousContent . filter ( c => c . type === 'tool_use' ) . map ( c => c . id ) ) ;
154+ const toolResultIds = new Set ( lastContent . filter ( c => c . type === 'tool_result' ) . map ( c => c . toolUseId ) ) ;
162155 if ( toolUseIds . size !== toolResultIds . size || ! [ ...toolUseIds ] . every ( id => toolResultIds . has ( id ) ) ) {
163156 throw new Error ( 'ids of tool_result blocks and tool_use blocks from previous message do not match' ) ;
164157 }
165158 }
166159 }
167160
168- const request = {
169- method : 'sampling/createMessage' as const ,
170- params
171- } ;
172- return this . requestStream ( request , CreateMessageResultSchema , options ) ;
161+ return this . requestStream (
162+ {
163+ method : 'sampling/createMessage' ,
164+ params
165+ } ,
166+ CreateMessageResultSchema ,
167+ options
168+ ) ;
173169 }
174170
175171 /**
@@ -219,12 +215,8 @@ export class ExperimentalServerTasks {
219215 options ?: RequestOptions
220216 ) : AsyncGenerator < ResponseMessage < ElicitResult > , void , void > {
221217 // Access client capabilities via the server
222- type ServerWithCapabilities = {
223- getClientCapabilities ( ) : { elicitation ?: { form ?: boolean ; url ?: boolean } } | undefined ;
224- } ;
225- const clientCapabilities = ( this . _server as unknown as ServerWithCapabilities ) . getClientCapabilities ( ) ;
226-
227- const mode = ( params . mode ?? 'form' ) as 'form' | 'url' ;
218+ const clientCapabilities = this . _server . getClientCapabilities ( ) ;
219+ const mode = params . mode ?? 'form' ;
228220
229221 // Capability check based on mode
230222 switch ( mode ) {
@@ -243,14 +235,15 @@ export class ExperimentalServerTasks {
243235 }
244236
245237 // Normalize params to ensure mode is set
246- const normalizedParams =
247- mode === 'form' && params . mode !== 'form' ? { ...( params as ElicitRequestFormParams ) , mode : 'form' as const } : params ;
248-
249- const request = {
250- method : 'elicitation/create' as const ,
251- params : normalizedParams
252- } ;
253- return this . requestStream ( request , ElicitResultSchema , options ) ;
238+ const normalizedParams = mode === 'form' && params . mode !== 'form' ? { ...params , mode : 'form' } : params ;
239+ return this . requestStream (
240+ {
241+ method : 'elicitation/create' ,
242+ params : normalizedParams
243+ } ,
244+ ElicitResultSchema ,
245+ options
246+ ) ;
254247 }
255248
256249 /**
0 commit comments