/**
 * OMK Provider Runner — Advisory execution wrappers
 * Extracted from provider-task-runner.ts to break God Module coupling
 */
import { providerModelEnv } from "./env.js";
import { providerExceptionResult, summarizeAdvisory, summarizeFailures } from "./results.js";
export async function runGenericProviderAdvisory(options) {
    let result;
    try {
        result = await options.runner.run(options.node, {
            ...options.env,
            ...options.traceEnv,
            ...providerModelEnv(options.modelRef),
            OMK_PROVIDER: options.modelRef?.provider ?? "external",
            OMK_PROVIDER_REQUESTED: options.modelRef?.provider ?? "external",
            OMK_PROVIDER_FALLBACK: options.authorityProvider,
            OMK_PROVIDER_ROUTE_REASON: options.routeReason,
            OMK_PROVIDER_AUTHORITY: "advisory",
        }, options.signal, options.context);
    }
    catch (error) {
        result = providerExceptionResult(error);
    }
    const success = result.success;
    const summary = success ? summarizeAdvisory(result.stdout) : "";
    const failureReason = success ? undefined : summarizeFailures([result]);
    return {
        success,
        result,
        summary,
        failureReason,
        metadata: {
            provider: options.modelRef?.provider ?? "external",
            model: options.modelRef?.model,
            participation: "advisory",
            invocationKey: options.invocationKey,
            success,
            summary,
            failureReason,
        },
    };
}
