import { runReplayGenerateRepair } from "./provider-replay-generate-repair-runner.js";
import { requireReplayRepairProfile } from "./provider-replay-profile.js";
import { replayTurnContext } from "./provider-replay-repair-decision-runner.js";
import { buildTerminalOutputInvalidRepair } from "./provider-terminal-output-handler.js";
export async function repairReplayGenerateTerminalOutput(input) {
    const { payload, replayContextAvailableTools, replayProfile, replayProfileName, replayProviderTurnBudget, replayRouteConfig, runtime, turn, } = input.state;
    const terminalRepair = buildTerminalOutputInvalidRepair({
        baseActionPolicy: {
            allowedActions: ["respond"],
            directResponseAllowed: true,
        },
        classificationToolNames: (replayContextAvailableTools ?? []).map((tool) => tool.name),
        deliverableFailures: [],
        text: input.responseText,
        visibleTools: [],
    });
    const request = payload.request;
    const { profile, profileName } = replayProfile && replayProfileName
        ? { profile: replayProfile, profileName: replayProfileName }
        : requireReplayRepairProfile({
            missingProfileMessage: "Provider request checkpoint is missing the profile needed to repair replayed generate terminal output.",
            profileName: payload.replayContext?.profileName,
            runtime,
        });
    return runReplayGenerateRepair({
        availableTools: replayContextAvailableTools ?? [],
        baseMessages: request.messages,
        correctionOperation: payload.operation,
        objective: payload.replayContext?.objective,
        providerContext: replayTurnContext({
            availableTools: replayContextAvailableTools,
            payload,
            profile,
            profileName,
            replayProviderTurnBudget,
            replayRouteConfig,
        }),
        repairCode: "TERMINAL_OUTPUT_INVALID",
        repairObservation: terminalRepair.observation,
        request,
        runtime,
        systemPrompt: request.systemPrompt,
        traceSystemPrompt: request.systemPrompt,
        turn,
    });
}
//# sourceMappingURL=provider-replay-generate-repair.js.map