@@ -28,7 +28,7 @@ import type { ProgressTracker } from '../utils/progress.js';
2828import type { JsonSchemaProperty } from '../utils/schema-generation.js' ;
2929import { generateSchemaFromItems } from '../utils/schema-generation.js' ;
3030import { getActorDefinition } from './build.js' ;
31- import { actorNameToToolName , buildActorInputSchema , fixedAjvCompile } from './utils.js' ;
31+ import { actorNameToToolName , buildActorInputSchema , fixedAjvCompile , isActorInfoMcpServer } from './utils.js' ;
3232
3333// Define a named return type for callActorGetDataset
3434export type CallActorGetDatasetResult = {
@@ -150,7 +150,7 @@ export async function callActorGetDataset(
150150 * 4. Properties are shortened using shortenProperties()
151151 * 5. Enums are added to descriptions with examples using addEnumsToDescriptionsWithExamples()
152152 *
153- * @param {ActorInfo[] } actorsInfo - An array of ActorInfo objects with webServerMcpPath and actorDefinitionPruned .
153+ * @param {ActorInfo[] } actorsInfo - An array of ActorInfo objects with webServerMcpPath, definition, and Actor .
154154 * @returns {Promise<ToolEntry[]> } - A promise that resolves to an array of MCP tools.
155155 */
156156export async function getNormalActorsAsTools (
@@ -159,22 +159,22 @@ export async function getNormalActorsAsTools(
159159 const tools : ToolEntry [ ] = [ ] ;
160160
161161 for ( const actorInfo of actorsInfo ) {
162- const { actorDefinitionPruned } = actorInfo ;
162+ const { definition } = actorInfo ;
163163
164- if ( ! actorDefinitionPruned ) continue ;
164+ if ( ! definition ) continue ;
165165
166- const isRag = actorDefinitionPruned . actorFullName === RAG_WEB_BROWSER ;
167- const { inputSchema } = buildActorInputSchema ( actorDefinitionPruned . actorFullName , actorDefinitionPruned . input , isRag ) ;
166+ const isRag = definition . actorFullName === RAG_WEB_BROWSER ;
167+ const { inputSchema } = buildActorInputSchema ( definition . actorFullName , definition . input , isRag ) ;
168168
169- let description = `This tool calls the Actor "${ actorDefinitionPruned . actorFullName } " and retrieves its output results.
169+ let description = `This tool calls the Actor "${ definition . actorFullName } " and retrieves its output results.
170170Use this tool instead of the "${ HelperTools . ACTOR_CALL } " if user requests this specific Actor.
171- Actor description: ${ actorDefinitionPruned . description } ` ;
171+ Actor description: ${ definition . description } ` ;
172172 if ( isRag ) {
173173 description += RAG_WEB_BROWSER_ADDITIONAL_DESC ;
174174 }
175175
176176 const memoryMbytes = Math . min (
177- actorDefinitionPruned . defaultRunOptions ?. memoryMbytes || ACTOR_MAX_MEMORY_MBYTES ,
177+ definition . defaultRunOptions ?. memoryMbytes || ACTOR_MAX_MEMORY_MBYTES ,
178178 ACTOR_MAX_MEMORY_MBYTES ,
179179 ) ;
180180
@@ -183,25 +183,25 @@ Actor description: ${actorDefinitionPruned.description}`;
183183 ajvValidate = fixedAjvCompile ( ajv , { ...inputSchema , additionalProperties : true } ) ;
184184 } catch ( e ) {
185185 log . error ( 'Failed to compile schema' , {
186- actorName : actorDefinitionPruned . actorFullName ,
186+ actorName : definition . actorFullName ,
187187 error : e ,
188188 } ) ;
189189 continue ;
190190 }
191191
192192 tools . push ( {
193193 type : 'actor' ,
194- name : actorNameToToolName ( actorDefinitionPruned . actorFullName ) ,
195- actorFullName : actorDefinitionPruned . actorFullName ,
194+ name : actorNameToToolName ( definition . actorFullName ) ,
195+ actorFullName : definition . actorFullName ,
196196 description,
197197 inputSchema : inputSchema as ToolInputSchema ,
198198 ajvValidate,
199199 memoryMbytes,
200- icons : actorDefinitionPruned . pictureUrl
201- ? [ { src : actorDefinitionPruned . pictureUrl , mimeType : 'image/png' } ]
200+ icons : definition . pictureUrl
201+ ? [ { src : definition . pictureUrl , mimeType : 'image/png' } ]
202202 : undefined ,
203203 annotations : {
204- title : actorDefinitionPruned . actorFullName ,
204+ title : definition . actorFullName ,
205205 openWorldHint : true ,
206206 } ,
207207 // Allow long running tasks for Actor tools, make it optional for now
@@ -227,21 +227,21 @@ async function getMCPServersAsTools(
227227
228228 // Process all actors in parallel
229229 const actorToolPromises = actorsInfo . map ( async ( actorInfo ) => {
230- const actorId = actorInfo . actorDefinitionPruned . id ;
230+ const actorId = actorInfo . definition . id ;
231231 if ( ! actorInfo . webServerMcpPath ) {
232232 log . warning ( 'Actor does not have a web server MCP path, skipping' , {
233- actorFullName : actorInfo . actorDefinitionPruned . actorFullName ,
233+ actorFullName : actorInfo . definition . actorFullName ,
234234 actorId,
235235 } ) ;
236236 return [ ] ;
237237 }
238238
239239 const mcpServerUrl = await getActorMCPServerURL (
240- actorInfo . actorDefinitionPruned . id , // Real ID of the Actor
240+ actorInfo . definition . id , // Real ID of the Actor
241241 actorInfo . webServerMcpPath ,
242242 ) ;
243243 log . debug ( 'Retrieved MCP server URL for Actor' , {
244- actorFullName : actorInfo . actorDefinitionPruned . actorFullName ,
244+ actorFullName : actorInfo . definition . actorFullName ,
245245 actorId,
246246 mcpServerUrl,
247247 } ) ;
@@ -256,7 +256,7 @@ async function getMCPServersAsTools(
256256 return await getMCPServerTools ( actorId , client , mcpServerUrl ) ;
257257 } catch ( error ) {
258258 logHttpError ( error , 'Failed to connect to MCP server' , {
259- actorFullName : actorInfo . actorDefinitionPruned . actorFullName ,
259+ actorFullName : actorInfo . definition . actorFullName ,
260260 actorId,
261261 } ) ;
262262 return [ ] ;
@@ -280,26 +280,28 @@ export async function getActorsAsTools(
280280
281281 const actorsInfo : ( ActorInfo | null ) [ ] = await Promise . all (
282282 actorIdsOrNames . map ( async ( actorIdOrName ) => {
283- const actorDefinitionPrunedCached = actorDefinitionPrunedCache . get ( actorIdOrName ) ;
284- if ( actorDefinitionPrunedCached ) {
283+ const actorDefinitionWithInfoCached = actorDefinitionPrunedCache . get ( actorIdOrName ) ;
284+ if ( actorDefinitionWithInfoCached ) {
285285 return {
286- actorDefinitionPruned : actorDefinitionPrunedCached ,
287- webServerMcpPath : getActorMCPServerPath ( actorDefinitionPrunedCached ) ,
286+ definition : actorDefinitionWithInfoCached . definition ,
287+ actor : actorDefinitionWithInfoCached . info ,
288+ webServerMcpPath : getActorMCPServerPath ( actorDefinitionWithInfoCached . definition ) ,
288289
289290 } as ActorInfo ;
290291 }
291292
292293 try {
293- const actorDefinitionPruned = await getActorDefinition ( actorIdOrName , apifyClient ) ;
294- if ( ! actorDefinitionPruned ) {
294+ const actorDefinitionWithInfo = await getActorDefinition ( actorIdOrName , apifyClient ) ;
295+ if ( ! actorDefinitionWithInfo ) {
295296 log . softFail ( 'Actor not found or definition is not available' , { actorName : actorIdOrName , statusCode : 404 } ) ;
296297 return null ;
297298 }
298- // Cache the pruned Actor definition
299- actorDefinitionPrunedCache . set ( actorIdOrName , actorDefinitionPruned ) ;
299+ // Cache the Actor definition with info
300+ actorDefinitionPrunedCache . set ( actorIdOrName , actorDefinitionWithInfo ) ;
300301 return {
301- actorDefinitionPruned,
302- webServerMcpPath : getActorMCPServerPath ( actorDefinitionPruned ) ,
302+ definition : actorDefinitionWithInfo . definition ,
303+ actor : actorDefinitionWithInfo . info ,
304+ webServerMcpPath : getActorMCPServerPath ( actorDefinitionWithInfo . definition ) ,
303305 } as ActorInfo ;
304306 } catch ( error ) {
305307 logHttpError ( error , 'Failed to fetch Actor definition' , {
@@ -312,9 +314,14 @@ export async function getActorsAsTools(
312314
313315 const clonedActors = structuredClone ( actorsInfo ) ;
314316
315- // Filter out nulls and separate Actors with MCP servers and normal Actors
316- const actorMCPServersInfo = clonedActors . filter ( ( actorInfo ) => actorInfo && actorInfo . webServerMcpPath ) as ActorInfo [ ] ;
317- const normalActorsInfo = clonedActors . filter ( ( actorInfo ) => actorInfo && ! actorInfo . webServerMcpPath ) as ActorInfo [ ] ;
317+ // Filter out nulls - actorInfo can be null if the Actor was not found or an error occurred
318+ const nonNullActors = clonedActors . filter ( ( actorInfo ) : actorInfo is ActorInfo => Boolean ( actorInfo ) ) ;
319+
320+ // Separate Actors with MCP servers and normal Actors
321+ // for MCP servers if mcp path is configured and also if the Actor standby mode is enabled
322+ const actorMCPServersInfo = nonNullActors . filter ( ( actorInfo ) => isActorInfoMcpServer ( actorInfo ) ) ;
323+ // all others
324+ const normalActorsInfo = nonNullActors . filter ( ( actorInfo ) => ! isActorInfoMcpServer ( actorInfo ) ) ;
318325
319326 const [ normalTools , mcpServerTools ] = await Promise . all ( [
320327 getNormalActorsAsTools ( normalActorsInfo ) ,
0 commit comments