@@ -19,6 +19,7 @@ import { actorDefinitionPrunedCache } from '../state.js';
1919import type { ActorDefinitionStorage , ActorInfo , InternalTool , ToolEntry } from '../types.js' ;
2020import { getActorDefinitionStorageFieldNames } from '../utils/actor.js' ;
2121import { getValuesByDotKeys } from '../utils/generic.js' ;
22+ import type { ProgressTracker } from '../utils/progress.js' ;
2223import { getActorDefinition } from './build.js' ;
2324import {
2425 actorNameToToolName ,
@@ -50,6 +51,7 @@ export type CallActorGetDatasetResult = {
5051 * @param {ActorCallOptions } callOptions - The options to pass to the actor.
5152 * @param {unknown } input - The input to pass to the actor.
5253 * @param {string } apifyToken - The Apify token to use for authentication.
54+ * @param {ProgressTracker } progressTracker - Optional progress tracker for real-time updates.
5355 * @returns {Promise<{ actorRun: any, items: object[] }> } - A promise that resolves to an object containing the actor run and dataset items.
5456 * @throws {Error } - Throws an error if the `APIFY_TOKEN` is not set
5557 */
@@ -58,16 +60,26 @@ export async function callActorGetDataset(
5860 input : unknown ,
5961 apifyToken : string ,
6062 callOptions : ActorCallOptions | undefined = undefined ,
63+ progressTracker ?: ProgressTracker | null ,
6164) : Promise < CallActorGetDatasetResult > {
6265 try {
6366 log . info ( `Calling Actor ${ actorName } with input: ${ JSON . stringify ( input ) } ` ) ;
6467
6568 const client = new ApifyClient ( { token : apifyToken } ) ;
6669 const actorClient = client . actor ( actorName ) ;
6770
68- const actorRun : ActorRun = await actorClient . call ( input , callOptions ) ;
69- const dataset = client . dataset ( actorRun . defaultDatasetId ) ;
70- // const dataset = client.dataset('Ehtn0Y4wIKviFT2WB');
71+ // Start the actor run but don't wait for completion
72+ const actorRun : ActorRun = await actorClient . start ( input , callOptions ) ;
73+
74+ // Start progress tracking if tracker is provided
75+ if ( progressTracker ) {
76+ progressTracker . startActorRunUpdates ( actorRun . id , apifyToken , actorName ) ;
77+ }
78+
79+ // Wait for the actor to complete
80+ const completedRun = await client . run ( actorRun . id ) . waitForFinish ( ) ;
81+
82+ const dataset = client . dataset ( completedRun . defaultDatasetId ) ;
7183 const [ items , defaultBuild ] = await Promise . all ( [
7284 dataset . listItems ( ) ,
7385 ( await actorClient . defaultBuild ( ) ) . get ( ) ,
@@ -301,7 +313,7 @@ export const callActor: ToolEntry = {
301313 inputSchema : zodToJsonSchema ( callActorArgs ) ,
302314 ajvValidate : ajv . compile ( zodToJsonSchema ( callActorArgs ) ) ,
303315 call : async ( toolArgs ) => {
304- const { apifyMcpServer, args, apifyToken } = toolArgs ;
316+ const { apifyMcpServer, args, apifyToken, progressTracker } = toolArgs ;
305317 const { actor : actorName , input, callOptions } = callActorArgs . parse ( args ) ;
306318
307319 const actors = apifyMcpServer . listActorToolNames ( ) ;
@@ -356,6 +368,7 @@ You can only use actors that are included in the list; actors not in the list ca
356368 input ,
357369 apifyToken ,
358370 callOptions ,
371+ progressTracker ,
359372 ) ;
360373
361374 return {
0 commit comments