import { appendRuntimeObservation } from "./runtime-observation.js";
export async function runReplayRepairDecision(input) {
    const repairMessages = appendRuntimeObservation(input.baseMessages, input.repairObservation);
    const correctionTrace = input.runtime.buildCorrectionTrace({
        code: input.repairCode,
        messages: input.baseMessages,
        operation: input.correctionOperation,
        phaseResultPhaseName: input.phaseResultPhaseName,
        systemPrompt: input.traceSystemPrompt ?? input.systemPrompt,
        tools: input.toolsForTrace,
    });
    const decision = await input.runtime.provider.decide(input.turn.threadId, input.turn.id, {
        allowPhaseResult: input.allowPhaseResult,
        allowPlanUpdate: input.allowPlanUpdate,
        ...(input.actionPolicy ? { actionPolicy: input.actionPolicy } : {}),
        cacheControl: input.cacheControl,
        messages: repairMessages,
        ...(input.phaseResultPhaseName ? { phaseResultPhaseName: input.phaseResultPhaseName } : {}),
        systemPrompt: input.systemPrompt,
        tools: input.visibleTools,
    }, "repair", {
        ...input.providerContext,
        correctionTrace,
    });
    const repairedText = await input.runtime.resolveProviderDecision({
        turn: input.turn,
        messages: repairMessages,
        systemPrompt: input.systemPrompt,
        decision,
        availableTools: input.availableTools,
        visibleTools: input.visibleTools,
        cacheControl: input.cacheControl,
        controls: input.controls,
        invokeContext: {
            ...input.resolveContext,
            correctionTrace,
        },
        operation: "repair",
        objective: input.objective,
        repairAttempt: 0,
        requiredToolConstraint: input.requiredToolConstraint,
        responseRepairDeliverableFailures: input.responseRepairDeliverableFailures,
        toolStepCount: input.toolStepCount,
        actionPolicyOverride: input.actionPolicy,
    });
    if (input.assertArtifacts) {
        await input.runtime.assertArtifactObligationsSatisfied(input.turn, input.artifactObligations);
    }
    return input.assertTerminal === false
        ? repairedText
        : input.runtime.assertValidTerminalAssistantTextOrFallback(input.turn, repairedText);
}
//# sourceMappingURL=provider-replay-decision-runner.js.map