
!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]="1ba5de13-4721-5b94-96aa-2d5822d4f2e1")}catch(e){}}();
import log from '@apify/log';
import { HelperTools } from '../../const.js';
import { getWidgetConfig, WIDGET_URIS } from '../../resources/widgets.js';
/**
 * OpenAI actor executor for UI mode.
 * Runs actors asynchronously — starts the run and returns immediately with widget metadata.
 * The widget automatically tracks progress and updates the UI.
 */
export const openaiActorExecutor = {
    async executeActorTool(params) {
        var _a, _b;
        if ((_a = params.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) {
            return null;
        }
        const actorClient = params.apifyClient.actor(params.actorFullName);
        const actorRun = await actorClient.start(params.input, params.callOptions);
        log.debug('Started Actor run (async, direct actor tool)', {
            actorName: params.actorFullName,
            runId: actorRun.id,
            mcpSessionId: params.mcpSessionId,
        });
        const structuredContent = {
            runId: actorRun.id,
            actorName: params.actorFullName,
            status: actorRun.status,
            startedAt: ((_b = actorRun.startedAt) === null || _b === void 0 ? void 0 : _b.toISOString()) || '',
            input: params.input,
        };
        const responseText = `Started Actor "${params.actorFullName}" (Run ID: ${actorRun.id}).

A live progress widget has been rendered that automatically tracks this run and refreshes status every few seconds until completion.

The widget will update the context with run status and datasetId when the run completes. Once complete (or if the user requests results), use ${HelperTools.ACTOR_OUTPUT_GET} with the datasetId to retrieve the output.

Do NOT proactively poll using ${HelperTools.ACTOR_RUNS_GET}. Wait for the widget state update or user instructions. Ask the user what they would like to do next.`;
        // _meta carries widget rendering config (not usage meta — the run is still in progress)
        const widgetConfig = getWidgetConfig(WIDGET_URIS.ACTOR_RUN);
        return {
            content: [{ type: 'text', text: responseText }],
            structuredContent,
            // Response-level meta; only returned in openai mode (this executor is openai-only)
            _meta: {
                ...widgetConfig === null || widgetConfig === void 0 ? void 0 : widgetConfig.meta,
                'openai/widgetDescription': `Actor run progress for ${params.actorFullName}`,
            },
        };
    },
};
//# sourceMappingURL=actor_executor.js.map
//# debugId=1ba5de13-4721-5b94-96aa-2d5822d4f2e1
