import { s as normalizeOptionalLowercaseString } from "./string-coerce-mnp54Vah.js";
//#region src/agents/tool-result-error.ts
function readToolResultDetails(result) {
	if (!result || typeof result !== "object") return;
	const record = result;
	return record.details && typeof record.details === "object" && !Array.isArray(record.details) ? record.details : void 0;
}
function readToolResultStatus(result) {
	return normalizeOptionalLowercaseString(readToolResultDetails(result)?.status);
}
function isToolResultError(result) {
	const details = readToolResultDetails(result);
	const normalized = readToolResultStatus(result);
	const explicitlySuccessful = details?.ok === true || details?.success === true;
	if (details?.ok === false || details?.success === false) return true;
	if ((normalized === "error" || normalized === "failed" || normalized === "failure" || normalized === "timeout" || normalized === "timed_out" || normalized === "blocked" || normalized === "denied" || normalized === "forbidden" || normalized === "unavailable" || normalized === "approval-unavailable" || normalized === "disabled" || normalized === "aborted" || normalized === "cancelled" || normalized === "canceled" || normalized === "killed" || normalized === "invalid") && !explicitlySuccessful) return true;
	if (details?.timedOut === true || Boolean(details?.error)) return true;
	const exitCode = details?.exitCode;
	return typeof exitCode === "number" && Number.isFinite(exitCode) && exitCode !== 0;
}
//#endregion
export { readToolResultDetails as n, readToolResultStatus as r, isToolResultError as t };
