
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a493f85b-e828-5a85-8c6c-c866a1bbbf7b")}catch(e){}}();
import { ApifyClient } from '../apify_client.js';
import { MCP_STREAMABLE_ENDPOINT } from '../const.js';
import { parseCommaSeparatedList } from '../utils/generic.js';
/**
 * Returns the MCP server path for the given Actor ID.
 * Prioritizes the streamable transport path if available.
 * The `webServerMcpPath` is a string containing MCP endpoint or endpoints separated by commas.
 */
export function getActorMCPServerPath(actorDefinition) {
    if ('webServerMcpPath' in actorDefinition && typeof actorDefinition.webServerMcpPath === 'string') {
        const webServerMcpPath = actorDefinition.webServerMcpPath.trim();
        const paths = parseCommaSeparatedList(webServerMcpPath);
        // If there is only one path, return it directly
        if (paths.length === 1) {
            return paths[0];
        }
        // If there are multiple paths, prioritize the streamable transport path
        // otherwise return the first one.
        const streamablePath = paths.find((path) => path === MCP_STREAMABLE_ENDPOINT);
        if (streamablePath) {
            return streamablePath;
        }
        // Otherwise, return the first path
        return paths[0];
    }
    return null;
}
/**
 * Returns the MCP server URL for the given Actor ID.
 */
export async function getActorMCPServerURL(realActorId, mcpServerPath) {
    // TODO: get from API instead
    const standbyBaseUrl = process.env.HOSTNAME === 'mcp-securitybyobscurity.apify.com'
        ? 'securitybyobscurity.apify.actor' : 'apify.actor';
    const standbyUrl = await getActorStandbyURL(realActorId, standbyBaseUrl);
    return `${standbyUrl}${mcpServerPath}`;
}
/**
* Gets Actor ID from the Actor object.
*/
export async function getRealActorID(actorIdOrName, apifyToken) {
    const apifyClient = new ApifyClient({ token: apifyToken });
    const actor = apifyClient.actor(actorIdOrName);
    const info = await actor.get();
    if (!info) {
        throw new Error(`Actor ${actorIdOrName} not found`);
    }
    return info.id;
}
/**
* Returns standby URL for given Actor ID.
*/
export async function getActorStandbyURL(realActorId, standbyBaseUrl = 'apify.actor') {
    return `https://${realActorId}.${standbyBaseUrl}`;
}
//# sourceMappingURL=actors.js.map
//# debugId=a493f85b-e828-5a85-8c6c-c866a1bbbf7b
