@@ -69,19 +69,26 @@ export const searchActorsArgsSchema = z.object({
6969} ) ;
7070
7171/**
72- * Filters out actors with the 'FLAT_PRICE_PER_MONTH' pricing model (rental actors)..
72+ * Filters out actors with the 'FLAT_PRICE_PER_MONTH' pricing model (rental actors),
73+ * unless the actor's ID is present in the user's rented actor IDs list.
7374 *
74- * Returns new array of Actors excluding those with 'FLAT_PRICE_PER_MONTH' pricing model .
75+ * This is necessary because the Store list API does not support filtering by multiple pricing models at once .
7576 *
7677 * @param actors - Array of ActorStorePruned objects to filter.
77- * @returns Array of actors excluding those with 'FLAT_PRICE_PER_MONTH' pricing model.
78+ * @param userRentedActorIds - Array of actor IDs that the user has rented.
79+ * @returns Array of actors excluding those with 'FLAT_PRICE_PER_MONTH' pricing model,
80+ * except for actors that the user has rented (whose IDs are in userRentedActorIds).
7881 */
7982function filterRentalActors (
8083 actors : ActorStorePruned [ ] ,
84+ userRentedActorIds : string [ ] ,
8185) : ActorStorePruned [ ] {
8286 // Store list API does not support filtering by two pricing models at once,
8387 // so we filter the results manually after fetching them.
84- return actors . filter ( ( actor ) => ( actor . currentPricingInfo . pricingModel as ActorPricingModel ) !== 'FLAT_PRICE_PER_MONTH' ) ;
88+ return actors . filter ( ( actor ) => (
89+ actor . currentPricingInfo . pricingModel as ActorPricingModel ) !== 'FLAT_PRICE_PER_MONTH'
90+ || userRentedActorIds . includes ( actor . id ) ,
91+ ) ;
8592}
8693
8794/**
@@ -102,15 +109,15 @@ export const searchActors: ToolEntry = {
102109 inputSchema : zodToJsonSchema ( searchActorsArgsSchema ) ,
103110 ajvValidate : ajv . compile ( zodToJsonSchema ( searchActorsArgsSchema ) ) ,
104111 call : async ( toolArgs ) => {
105- const { args, apifyToken } = toolArgs ;
112+ const { args, apifyToken, userRentedActorIds } = toolArgs ;
106113 const parsed = searchActorsArgsSchema . parse ( args ) ;
107114 let actors = await searchActorsByKeywords (
108115 parsed . search ,
109116 apifyToken ,
110117 parsed . limit + ACTOR_SEARCH_ABOVE_LIMIT ,
111118 parsed . offset ,
112119 ) ;
113- actors = filterRentalActors ( actors || [ ] ) . slice ( 0 , parsed . limit ) ;
120+ actors = filterRentalActors ( actors || [ ] , userRentedActorIds || [ ] ) . slice ( 0 , parsed . limit ) ;
114121
115122 return { content : actors ?. map ( ( item ) => ( { type : 'text' , text : JSON . stringify ( item ) } ) ) } ;
116123 } ,
0 commit comments