import * as HttpClient from "effect/unstable/http/HttpClient";
import * as redacted from "effect/Redacted";
import * as S from "effect/Schema";
import * as stream from "effect/Stream";
import * as API from "../client/api.js";
import * as T from "../traits.js";
import * as C from "../category.js";
import { SensitiveBlob } from "../sensitive.js";
const svc = T.AwsApiService({
    sdkId: "SageMaker Runtime HTTP2",
    serviceShapeName: "AmazonSageMakerRuntimeHttp2",
});
const auth = T.AwsAuthSigv4({ name: "sagemaker" });
const ver = T.ServiceVersion("2025-10-01");
const proto = T.AwsProtocolsRestJson1();
const rules = T.EndpointResolver((p, _) => {
    const { UseDualStack = false, UseFIPS = false, Endpoint, Region } = p;
    const e = (u, p = {}, h = {}) => ({
        type: "endpoint",
        endpoint: { url: u, properties: p, headers: h },
    });
    const err = (m) => ({
        type: "error",
        message: m,
    });
    if (Endpoint != null) {
        if (UseFIPS === true) {
            return err("Invalid Configuration: FIPS and custom endpoint are not supported");
        }
        if (UseDualStack === true) {
            return err("Invalid Configuration: Dualstack and custom endpoint are not supported");
        }
        return e(Endpoint);
    }
    if (Region != null) {
        {
            const PartitionResult = _.partition(Region);
            if (PartitionResult != null && PartitionResult !== false) {
                if (_.getAttr(PartitionResult, "name") === "aws" &&
                    UseFIPS === false &&
                    UseDualStack === false) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws" &&
                    UseFIPS === false &&
                    UseDualStack === true) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws" &&
                    UseFIPS === true &&
                    UseDualStack === false) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws" &&
                    UseFIPS === true &&
                    UseDualStack === true) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-cn" &&
                    UseFIPS === false &&
                    UseDualStack === false) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-cn" &&
                    UseFIPS === false &&
                    UseDualStack === true) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-cn" &&
                    UseFIPS === true &&
                    UseDualStack === false) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-cn" &&
                    UseFIPS === true &&
                    UseDualStack === true) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-us-gov" &&
                    UseFIPS === false &&
                    UseDualStack === false) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-us-gov" &&
                    UseFIPS === false &&
                    UseDualStack === true) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-us-gov" &&
                    UseFIPS === true &&
                    UseDualStack === false) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-us-gov" &&
                    UseFIPS === true &&
                    UseDualStack === true) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso" &&
                    UseFIPS === false &&
                    UseDualStack === false) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso" &&
                    UseFIPS === false &&
                    UseDualStack === true) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso" &&
                    UseFIPS === true &&
                    UseDualStack === false) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso" &&
                    UseFIPS === true &&
                    UseDualStack === true) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso-b" &&
                    UseFIPS === false &&
                    UseDualStack === false) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso-b" &&
                    UseFIPS === false &&
                    UseDualStack === true) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso-b" &&
                    UseFIPS === true &&
                    UseDualStack === false) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso-b" &&
                    UseFIPS === true &&
                    UseDualStack === true) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso-f" &&
                    UseFIPS === false &&
                    UseDualStack === false) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso-f" &&
                    UseFIPS === false &&
                    UseDualStack === true) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso-f" &&
                    UseFIPS === true &&
                    UseDualStack === false) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-iso-f" &&
                    UseFIPS === true &&
                    UseDualStack === true) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-eusc" &&
                    UseFIPS === false &&
                    UseDualStack === false) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-eusc" &&
                    UseFIPS === false &&
                    UseDualStack === true) {
                    return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-eusc" &&
                    UseFIPS === true &&
                    UseDualStack === false) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}:8443`);
                }
                if (_.getAttr(PartitionResult, "name") === "aws-eusc" &&
                    UseFIPS === true &&
                    UseDualStack === true) {
                    return e(`https://runtime-fips.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}:8443`);
                }
                if (UseFIPS === true && UseDualStack === true) {
                    if (true === _.getAttr(PartitionResult, "supportsFIPS") &&
                        true === _.getAttr(PartitionResult, "supportsDualStack")) {
                        return e(`https://runtime.sagemaker-fips.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}`);
                    }
                    return err("FIPS and DualStack are enabled, but this partition does not support one or both");
                }
                if (UseFIPS === true && UseDualStack === false) {
                    if (_.getAttr(PartitionResult, "supportsFIPS") === true) {
                        return e(`https://runtime.sagemaker-fips.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}`);
                    }
                    return err("FIPS is enabled but this partition does not support FIPS");
                }
                if (UseFIPS === false && UseDualStack === true) {
                    if (true === _.getAttr(PartitionResult, "supportsDualStack")) {
                        return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dualStackDnsSuffix")}`);
                    }
                    return err("DualStack is enabled but this partition does not support DualStack");
                }
                return e(`https://runtime.sagemaker.${Region}.${_.getAttr(PartitionResult, "dnsSuffix")}`);
            }
        }
    }
    return err("Invalid Configuration: Missing Region");
});
export const RequestPayloadPart = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Bytes: S.optional(SensitiveBlob).pipe(T.EventPayload()),
    DataType: S.optional(S.String).pipe(T.EventHeader()),
    CompletionState: S.optional(S.String).pipe(T.EventHeader()),
    P: S.optional(S.String).pipe(T.EventHeader()),
})).annotate({
    identifier: "RequestPayloadPart",
});
export const RequestStreamEvent = 
/*@__PURE__*/ /*#__PURE__*/ T.InputEventStream(S.Union([S.Struct({ PayloadPart: RequestPayloadPart })]));
export const InvokeEndpointWithBidirectionalStreamInput = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    EndpointName: S.String.pipe(T.HttpLabel("EndpointName")),
    Body: RequestStreamEvent.pipe(T.HttpPayload()),
    TargetVariant: S.optional(S.String).pipe(T.HttpHeader("X-Amzn-SageMaker-Target-Variant")),
    ModelInvocationPath: S.optional(S.String).pipe(T.HttpHeader("X-Amzn-SageMaker-Model-Invocation-Path")),
    ModelQueryString: S.optional(S.String).pipe(T.HttpHeader("X-Amzn-SageMaker-Model-Query-String")),
}).pipe(T.all(T.Http({
    method: "POST",
    uri: "/endpoints/{EndpointName}/invocations-bidirectional-stream",
}), svc, auth, proto, ver, rules))).annotate({
    identifier: "InvokeEndpointWithBidirectionalStreamInput",
});
export const ResponsePayloadPart = /*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Bytes: S.optional(SensitiveBlob).pipe(T.EventPayload()),
    DataType: S.optional(S.String).pipe(T.EventHeader()),
    CompletionState: S.optional(S.String).pipe(T.EventHeader()),
    P: S.optional(S.String).pipe(T.EventHeader()),
})).annotate({
    identifier: "ResponsePayloadPart",
});
export const ResponseStreamEvent = /*@__PURE__*/ /*#__PURE__*/ T.EventStream(S.Union([
    S.Struct({ PayloadPart: ResponsePayloadPart }),
    S.Struct({
        ModelStreamError: S.suspend(() => ModelStreamError).annotate({
            identifier: "ModelStreamError",
        }),
    }),
    S.Struct({
        InternalStreamFailure: S.suspend(() => InternalStreamFailure).annotate({
            identifier: "InternalStreamFailure",
        }),
    }),
]));
export const InvokeEndpointWithBidirectionalStreamOutput = 
/*@__PURE__*/ /*#__PURE__*/ S.suspend(() => S.Struct({
    Body: ResponseStreamEvent.pipe(T.HttpPayload()),
    InvokedProductionVariant: S.optional(S.String).pipe(T.HttpHeader("X-Amzn-Invoked-Production-Variant")),
})).annotate({
    identifier: "InvokeEndpointWithBidirectionalStreamOutput",
});
//# Errors
export class InputValidationError extends S.TaggedErrorClass()("InputValidationError", { Message: S.optional(S.String), ErrorCode: S.optional(S.String) }).pipe(C.withBadRequestError) {
}
export class InternalServerError extends S.TaggedErrorClass()("InternalServerError", { Message: S.optional(S.String), ErrorCode: S.optional(S.String) }).pipe(C.withServerError) {
}
export class InternalStreamFailure extends S.TaggedErrorClass()("InternalStreamFailure", { Message: S.optional(S.String) }) {
}
export class ModelError extends S.TaggedErrorClass()("ModelError", {
    Message: S.optional(S.String),
    OriginalStatusCode: S.optional(S.Number),
    OriginalMessage: S.optional(S.String),
    LogStreamArn: S.optional(S.String),
    ErrorCode: S.optional(S.String),
}) {
}
export class ModelStreamError extends S.TaggedErrorClass()("ModelStreamError", { Message: S.optional(S.String), ErrorCode: S.optional(S.String) }) {
}
export class ServiceUnavailableError extends S.TaggedErrorClass()("ServiceUnavailableError", { Message: S.optional(S.String), ErrorCode: S.optional(S.String) }).pipe(C.withServerError) {
}
/**
 * Invokes a model endpoint with bidirectional streaming capabilities. This operation establishes a persistent connection that allows you to send multiple requests and receive streaming responses from the model in real-time.
 *
 * Bidirectional streaming is useful for interactive applications such as chatbots, real-time translation, or any scenario where you need to maintain a conversation-like interaction with the model. The connection remains open, allowing you to send additional input and receive responses without establishing a new connection for each request.
 *
 * For an overview of Amazon SageMaker AI, see How It Works.
 *
 * Amazon SageMaker AI strips all POST headers except those supported by the API. Amazon SageMaker AI might add additional headers. You should not rely on the behavior of headers outside those enumerated in the request syntax.
 *
 * Calls to `InvokeEndpointWithBidirectionalStream` are authenticated by using Amazon Web Services Signature Version 4. For information, see Authenticating Requests (Amazon Web Services Signature Version 4) in the *Amazon S3 API Reference*.
 *
 * The bidirectional stream maintains the connection until either the client closes it or the model indicates completion. Each request and response in the stream is sent as an event with optional headers for data type and completion state.
 *
 * Endpoints are scoped to an individual account, and are not public. The URL does not contain the account ID, but Amazon SageMaker AI determines the account ID from the authentication token that is supplied by the caller.
 */
export const invokeEndpointWithBidirectionalStream = /*@__PURE__*/ /*#__PURE__*/ API.make(() => ({
    input: InvokeEndpointWithBidirectionalStreamInput,
    output: InvokeEndpointWithBidirectionalStreamOutput,
    errors: [
        InputValidationError,
        InternalServerError,
        InternalStreamFailure,
        ModelError,
        ModelStreamError,
        ServiceUnavailableError,
    ],
}));
//# sourceMappingURL=sagemaker-runtime-http2.js.map