/**
 * Shared catch-block helper for host-tool handlers.
 *
 * Every handler's error path follows the same shape: branch on
 * `signal.aborted` to pick Cancelled vs Failed and write a `userMessage` on
 * the top-level result. The synthesized failure carries no typed `details` —
 * the tool's success-shape payload is, by definition, not produced on the
 * failure path.
 */
import { errorToMessage, HostToolResultStatus } from './host-tool.js';
/**
 * Build a Cancelled-or-Failed `HostToolResult` from a thrown error.
 *
 * Returns Cancelled when `signal.aborted === true`, Failed otherwise. The
 * top-level `userMessage` carries the cancelled message when aborted, or the
 * coerced error string when failed.
 */
export function createCancelOrFailResult(options) {
    const cancelled = options.signal?.aborted === true;
    return {
        kind: options.contract.kind,
        requestId: options.request.requestId,
        status: cancelled ? HostToolResultStatus.Cancelled : HostToolResultStatus.Failed,
        userMessage: cancelled ? options.cancelledMessage : errorToMessage(options.error)
    };
}
//# sourceMappingURL=cancel-or-fail.js.map