@@ -11,6 +11,15 @@ interface SpotifyCheckFollowingResponse extends ToolResponse {
1111 output : { results : boolean [ ] }
1212}
1313
14+ /** The library URI type for `type`, rejecting anything other than `artist` or `user`. */
15+ function followType ( type : string ) : 'artist' | 'user' {
16+ const normalized = String ( type ?? '' )
17+ . trim ( )
18+ . toLowerCase ( )
19+ if ( normalized === 'artist' || normalized === 'user' ) return normalized
20+ throw new Error ( 'Type must be "artist" or "user"' )
21+ }
22+
1423export const spotifyCheckFollowingTool : ToolConfig <
1524 SpotifyCheckFollowingParams ,
1625 SpotifyCheckFollowingResponse
@@ -43,7 +52,7 @@ export const spotifyCheckFollowingTool: ToolConfig<
4352
4453 request : {
4554 url : ( params ) =>
46- spotifyLibraryUrl ( params . ids , params . type === 'user' ? 'user' : 'artist' , {
55+ spotifyLibraryUrl ( params . ids , followType ( params . type ) , {
4756 contains : true ,
4857 maxIds : 50 ,
4958 } ) ,
@@ -53,16 +62,17 @@ export const spotifyCheckFollowingTool: ToolConfig<
5362 } ) ,
5463 } ,
5564
56- transformResponse : async ( response , params ) : Promise < SpotifyCheckFollowingResponse > => {
65+ transformResponse : async ( response , params , context ) : Promise < SpotifyCheckFollowingResponse > => {
5766 const results : boolean [ ] = [
5867 ...( await response . json ( ) ) ,
5968 ...( params
6069 ? await sendRemainingSpotifyLibraryChunks (
6170 params ,
6271 params . ids ,
63- params . type === 'user' ? 'user' : 'artist' ,
72+ followType ( params . type ) ,
6473 'GET' ,
65- { contains : true , maxIds : 50 }
74+ { contains : true , maxIds : 50 } ,
75+ context ?. signal
6676 )
6777 : [ ] ) ,
6878 ]
0 commit comments