@@ -261,3 +261,79 @@ export const getActor: ToolEntry = {
261261 } ,
262262 } as InternalTool ,
263263} ;
264+
265+ const callActorArgs = z . object ( {
266+ actorName : z . string ( )
267+ . describe ( 'The name of the Actor to call.' ) ,
268+ input : z . any ( )
269+ . describe ( 'The input to pass to the Actor.' ) ,
270+ callOptions : z . object ( {
271+ memory : z . number ( ) . optional ( ) ,
272+ timeout : z . number ( ) . optional ( ) ,
273+ } ) . optional ( )
274+ . describe ( 'Optional call options for the Actor.' ) ,
275+ } ) ;
276+
277+ export const callActor : ToolEntry = {
278+ type : 'internal' ,
279+ tool : {
280+ name : HelperTools . ACTOR_CALL ,
281+ actorFullName : HelperTools . ACTOR_CALL ,
282+ description : 'Call Actor and get dataset id. Call without input and result response with requred input properties.' ,
283+ inputSchema : zodToJsonSchema ( callActorArgs ) ,
284+ ajvValidate : ajv . compile ( zodToJsonSchema ( callActorArgs ) ) ,
285+ call : async ( toolArgs ) => {
286+ const { args, apifyToken } = toolArgs ;
287+ const { actorName, input, callOptions } = callActorArgs . parse ( args ) ;
288+ if ( ! apifyToken ) {
289+ throw new Error ( 'APIFY_TOKEN environment variable is not set.' ) ;
290+ }
291+ try {
292+ // FIXME: Bug, every call add "**REQUIRED**" to the description of the input properties
293+ const [ actor ] = await getActorsAsTools ( [ actorName ] , apifyToken ) ;
294+
295+ if ( ! actor ) {
296+ return {
297+ content : [
298+ { type : 'text' , text : `Actor '${ actorName } ' not found.` } ,
299+ ] ,
300+ } ;
301+ }
302+
303+ if ( ! actor . tool . ajvValidate ( input ) ) {
304+ const { errors } = actor . tool . ajvValidate ;
305+ if ( errors && errors . length > 0 ) {
306+ return {
307+ content : [
308+ { type : 'text' , text : `Input validation failed for Actor '${ actorName } ': ${ errors . map ( ( e ) => e . message ) . join ( ', ' ) } ` } ,
309+ { type : 'json' , json : actor . tool . inputSchema } ,
310+ ] ,
311+ } ;
312+ }
313+ }
314+
315+ const { actorRun, datasetInfo, items } = await callActorGetDataset (
316+ actorName ,
317+ input ,
318+ apifyToken ,
319+ callOptions ,
320+ ) ;
321+
322+ return {
323+ content : [
324+ { type : 'text' , text : `Actor run ID: ${ actorRun . id } ` } ,
325+ { type : 'text' , text : `Dataset ID: ${ datasetInfo ?. id } ` } ,
326+ { type : 'text' , text : `Items count: ${ items . total } ` } ,
327+ ] ,
328+ } ;
329+ } catch ( error ) {
330+ console . error ( `Error calling Actor: ${ error } ` ) ;
331+ return {
332+ content : [
333+ { type : 'text' , text : `Error calling Actor: ${ error instanceof Error ? error . message : String ( error ) } ` } ,
334+ ] ,
335+ } ;
336+ }
337+ } ,
338+ } ,
339+ } ;
0 commit comments