/**
 * LAFS (LLM-Agent-First Schema) unified envelope types.
 *
 * Protocol-level types (`LAFSEnvelope`, `LAFSMeta`, `LAFSError`,
 * `LAFSErrorCategory`, `LAFSTransport`, `LAFSPage*`, `MVILevel`, `Warning`)
 * are owned by `@cleocode/lafs` (ADR-039) and re-exported here so that
 * downstream consumers can import from a single well-known contracts path.
 *
 * Contracts-specific types (`LafsEnvelope`, `LafsSuccess`, `LafsError`,
 * `LafsErrorDetail`, `LafsAlternative`, `GatewayMeta`, `GatewayEnvelope`,
 * `CleoResponse`) are defined here because they represent CLEO's CLI-layer
 * and gateway-layer response contracts that depend on the protocol types but
 * are not part of the LAFS SDK itself.
 *
 * @epic T4654
 * @task T1706
 */
// ---------------------------------------------------------------------------
// Type guards
// ---------------------------------------------------------------------------
/**
 * Type guard for success responses.
 *
 * @typeParam T - The data payload type of the envelope.
 * @param envelope - The envelope to check.
 * @returns `true` if the envelope represents a successful operation.
 *
 * @remarks
 * Narrows a {@link LafsEnvelope} to {@link LafsSuccess} so that `envelope.data`
 * is accessible without additional type assertions.
 *
 * @example
 * ```ts
 * const result: LafsEnvelope<Task[]> = await fetchTasks();
 * if (isLafsSuccess(result)) {
 *   console.log(result.data); // Task[]
 * }
 * ```
 */
export function isLafsSuccess(envelope) {
    return envelope.success === true;
}
/**
 * Type guard for error responses.
 *
 * @typeParam T - The data payload type of the envelope.
 * @param envelope - The envelope to check.
 * @returns `true` if the envelope represents a failed operation.
 *
 * @remarks
 * Narrows a {@link LafsEnvelope} to {@link LafsError} so that `envelope.error`
 * is accessible without additional type assertions.
 *
 * @example
 * ```ts
 * const result: LafsEnvelope<Task[]> = await fetchTasks();
 * if (isLafsError(result)) {
 *   console.error(result.error.message);
 * }
 * ```
 */
export function isLafsError(envelope) {
    return envelope.success === false;
}
/**
 * Type guard for gateway responses (has _meta).
 *
 * @typeParam T - The data payload type of the envelope.
 * @param envelope - The response to check.
 * @returns `true` if the response includes gateway metadata.
 *
 * @remarks
 * Distinguishes gateway responses from plain CLI responses by checking for the
 * presence of the `_meta` field, which carries gateway-specific routing and timing data.
 *
 * @example
 * ```ts
 * const response: CleoResponse<Task> = await handleRequest();
 * if (isGatewayEnvelope(response)) {
 *   console.log(response._meta.gateway);
 * }
 * ```
 */
export function isGatewayEnvelope(envelope) {
    return '_meta' in envelope && envelope._meta !== undefined;
}
//# sourceMappingURL=lafs.js.map