|
1 | 1 | import type { ActorDefinition } from 'apify-client'; |
2 | 2 |
|
3 | | -import { ApifyClient } from '../apify-client.js'; |
| 3 | +import { ApifyClient, getApifyAPIBaseUrl } from '../apify-client.js'; |
4 | 4 |
|
5 | 5 | export async function isActorMCPServer(actorID: string, apifyToken: string): Promise<boolean> { |
6 | 6 | const mcpPath = await getActorsMCPServerPath(actorID, apifyToken); |
@@ -63,18 +63,25 @@ export async function getActorDefinition(actorID: string, apifyToken: string): P |
63 | 63 | if (!info) { |
64 | 64 | throw new Error(`Actor ${actorID} not found`); |
65 | 65 | } |
66 | | - const latestBuildID = info.taggedBuilds?.latest?.buildId; |
67 | | - if (!latestBuildID) { |
68 | | - throw new Error(`Actor ${actorID} does not have a latest build`); |
| 66 | + |
| 67 | + const actorObjID = info.id; |
| 68 | + const res = await fetch(`${getApifyAPIBaseUrl()}/v2/acts/${actorObjID}/builds/default`, { |
| 69 | + headers: { |
| 70 | + // This is done so tests can pass with public Actors without token |
| 71 | + ...(apifyToken ? { Authorization: `Bearer ${apifyToken}` } : {}), |
| 72 | + }, |
| 73 | + }); |
| 74 | + if (!res.ok) { |
| 75 | + throw new Error(`Failed to fetch default build for actor ${actorID}: ${res.statusText}`); |
69 | 76 | } |
70 | | - const build = apifyClient.build(latestBuildID); |
71 | | - const buildInfo = await build.get(); |
| 77 | + const json = await res.json() as any; // eslint-disable-line @typescript-eslint/no-explicit-any |
| 78 | + const buildInfo = json.data; |
72 | 79 | if (!buildInfo) { |
73 | | - throw new Error(`Build ${latestBuildID} not found`); |
| 80 | + throw new Error(`Default build for Actor ${actorID} not found`); |
74 | 81 | } |
75 | 82 | const { actorDefinition } = buildInfo; |
76 | 83 | if (!actorDefinition) { |
77 | | - throw new Error(`Build ${latestBuildID} does not have an actor definition`); |
| 84 | + throw new Error(`Actor default build ${actorID} does not have Actor definition`); |
78 | 85 | } |
79 | 86 |
|
80 | 87 | return actorDefinition; |
|
0 commit comments