
!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]="091a7faa-7ea2-5a27-b5cd-5d9af2942e64")}catch(e){}}();
import { createApifyClientWithSkyfireSupport } from '../../apify_client.js';
import { TOOL_STATUS } from '../../const.js';
import { getWidgetConfig, WIDGET_URIS } from '../../resources/widgets.js';
import { logHttpError } from '../../utils/logging.js';
import { buildMCPResponse, buildUsageMeta } from '../../utils/mcp.js';
import { fetchActorRunData, getActorRunArgs, getActorRunMetadata, } from '../core/get_actor_run_common.js';
/**
 * OpenAI mode get-actor-run tool.
 * Returns abbreviated text with widget metadata for interactive progress display.
 */
export const openaiGetActorRun = Object.freeze({
    ...getActorRunMetadata,
    call: async (toolArgs) => {
        const { args, apifyToken, apifyMcpServer, mcpSessionId } = toolArgs;
        const parsed = getActorRunArgs.parse(args);
        const client = createApifyClientWithSkyfireSupport(apifyMcpServer, args, apifyToken);
        try {
            const fetchResult = await fetchActorRunData({
                runId: parsed.runId,
                client,
                mcpSessionId,
            });
            if ('error' in fetchResult) {
                return fetchResult.error;
            }
            const { run, structuredContent } = fetchResult.result;
            const statusText = run.status === 'SUCCEEDED' && structuredContent.dataset
                ? `Actor run ${parsed.runId} completed successfully with ${structuredContent.dataset.totalItemCount} items. A widget has been rendered with the details.`
                : `Actor run ${parsed.runId} status: ${run.status}. A progress widget has been rendered.`;
            const widgetConfig = getWidgetConfig(WIDGET_URIS.ACTOR_RUN);
            const usageMeta = buildUsageMeta(run);
            return buildMCPResponse({
                texts: [statusText],
                structuredContent,
                // Response-level meta; only returned in openai mode (this handler is openai-only)
                _meta: {
                    ...widgetConfig === null || widgetConfig === void 0 ? void 0 : widgetConfig.meta,
                    ...usageMeta,
                },
            });
        }
        catch (error) {
            logHttpError(error, 'Failed to get Actor run', { runId: parsed.runId });
            return buildMCPResponse({
                texts: [`Failed to get Actor run '${parsed.runId}': ${error instanceof Error ? error.message : String(error)}.
Please verify the run ID and ensure that the run exists.`],
                isError: true,
                toolStatus: TOOL_STATUS.SOFT_FAIL,
            });
        }
    },
});
//# sourceMappingURL=get_actor_run.js.map
//# debugId=091a7faa-7ea2-5a27-b5cd-5d9af2942e64
