@@ -9,6 +9,8 @@ import type { ToolWrap } from '../types.js';
99import { addTool , getActorsAsTools , removeTool } from '../tools/index.js' ;
1010import { Input } from "../types.js" ;
1111import { APIFY_USERNAME } from "../const.js" ;
12+ import { ActorDefinition } from "apify-client" ;
13+ import { ApifyClient } from "../apify-client.js" ;
1214
1315/**
1416 * Generates a unique server ID based on the provided URL.
@@ -81,3 +83,28 @@ export function getActorStandbyURL(actorID: string, standbyBaseUrl = 'apify.acto
8183
8284 return `https://${ prefix } ${ actorName } .${ standbyBaseUrl } ` ;
8385}
86+
87+ export async function getActorDefinition ( actorID : string , apifyToken : string ) : Promise < ActorDefinition > {
88+ const apifyClient = new ApifyClient ( { token : apifyToken
89+ } )
90+ const actor = apifyClient . actor ( actorID ) ;
91+ const info = await actor . get ( ) ;
92+ if ( ! info ) {
93+ throw new Error ( `Actor ${ actorID } not found` ) ;
94+ }
95+ const latestBuildID = info . taggedBuilds ?. [ 'latest' ] ?. buildId ;
96+ if ( ! latestBuildID ) {
97+ throw new Error ( `Actor ${ actorID } does not have a latest build` ) ;
98+ }
99+ const build = apifyClient . build ( latestBuildID ) ;
100+ const buildInfo = await build . get ( ) ;
101+ if ( ! buildInfo ) {
102+ throw new Error ( `Build ${ latestBuildID } not found` ) ;
103+ }
104+ const actorDefinition = buildInfo . actorDefinition ;
105+ if ( ! actorDefinition ) {
106+ throw new Error ( `Build ${ latestBuildID } does not have an actor definition` ) ;
107+ }
108+
109+ return actorDefinition ;
110+ }
0 commit comments