import { runPostToolUseHooks } from "./tool-hook-runner.js";
import { persistToolOutput } from "./tool-result-persistence.js";
export async function finalizeExecutedToolResult(input) {
    const postHook = await runPostToolUseHooks({
        output: input.output,
        persistTerminalToolFailure: input.persistTerminalToolFailure,
        preparedToolResumeContext: input.preparedToolResumeContext,
        profile: input.profile,
        runtime: input.runtime,
        shellDebugBase: input.shellDebugBase,
        toolCallId: input.toolCallId,
        toolInput: input.prepared.normalizedInput,
        toolName: input.toolName,
        toolStartedAt: input.toolStartedAt,
        turn: input.turn,
    });
    if (postHook.failureOutput !== undefined) {
        return postHook.failureOutput;
    }
    await persistToolOutput({
        debugEventPrefix: "shell.result_persist",
        output: postHook.output,
        resultMetadata: input.resultMetadata,
        resumeContext: {
            ...input.preparedToolResumeContext,
            toolCallId: input.toolCallId,
        },
        runtime: input.runtime,
        shellDebugBase: input.shellDebugBase,
        toolCallId: input.toolCallId,
        toolInput: input.prepared.normalizedInput,
        toolName: input.toolName,
        turn: input.turn,
    });
    return postHook.output;
}
//# sourceMappingURL=tool-execution-finalizer.js.map