MCPcopy
hub / github.com/Effect-TS/effect / make

Function make

packages/ai/amazon-bedrock/src/AmazonBedrockClient.ts:63–196  ·  view source on GitHub ↗
(options: {
  readonly apiUrl?: string | undefined
  readonly accessKeyId: string
  readonly secretAccessKey: Redacted.Redacted<string>
  readonly sessionToken?: Redacted.Redacted<string> | undefined
  readonly region?: string | undefined
  readonly transformClient?: (
    client: HttpClient.HttpClient
  ) => HttpClient.HttpClient
})

Source from the content-addressed store, hash-verified

61 * @category Constructors
62 */
63export const make = (options: {
64 readonly apiUrl?: string | undefined
65 readonly accessKeyId: string
66 readonly secretAccessKey: Redacted.Redacted<string>
67 readonly sessionToken?: Redacted.Redacted<string> | undefined
68 readonly region?: string | undefined
69 readonly transformClient?: (
70 client: HttpClient.HttpClient
71 ) => HttpClient.HttpClient
72}) =>
73 Effect.gen(function*() {
74 const region = options.region ?? "us-east-1"
75
76 const redactedHeaders = ["X-Amz-Security-Token"]
77
78 yield* Effect.locallyScopedWith(Headers.currentRedactedNames, Arr.appendAll(redactedHeaders))
79
80 const httpClient = (yield* HttpClient.HttpClient).pipe(
81 HttpClient.mapRequest((request) =>
82 request.pipe(
83 HttpClientRequest.prependUrl(options.apiUrl ?? `https://bedrock-runtime.${region}.amazonaws.com`),
84 HttpClientRequest.acceptJson
85 )
86 ),
87 HttpClient.mapRequestEffect(Effect.fnUntraced(function*(request) {
88 const originalHeaders = request.headers
89 const signer = new AwsV4Signer({
90 service: "bedrock",
91 url: request.url,
92 method: request.method,
93 headers: Object.entries(originalHeaders),
94 body: prepareBody(request.body),
95 region,
96 accessKeyId: options.accessKeyId,
97 secretAccessKey: Redacted.value(options.secretAccessKey),
98 ...(options.sessionToken ? { sessionToken: Redacted.value(options.sessionToken) } : {})
99 })
100 const { headers: signedHeaders } = yield* Effect.promise(() => signer.sign())
101 const headers = Headers.merge(originalHeaders, Headers.fromInput(signedHeaders))
102 return HttpClientRequest.setHeaders(request, headers)
103 })),
104 options.transformClient ? options.transformClient : identity
105 )
106
107 const httpClientOk = HttpClient.filterStatusOk(httpClient)
108
109 const client = makeClient(httpClient, {
110 transformClient: (client) =>
111 AmazonBedrockConfig.getOrUndefined.pipe(
112 Effect.map((config) => config?.transformClient ? config.transformClient(client) : client)
113 )
114 })
115
116 const converse: (options: {
117 readonly params?: { "anthropic-beta"?: string | undefined } | undefined
118 readonly payload: typeof ConverseRequest.Encoded
119 }) => Effect.Effect<ConverseResponse, AiError.AiError> = Effect.fnUntraced(
120 function*(request) {

Callers 3

layerFunction · 0.70
layerFunction · 0.70
layerConfigFunction · 0.70

Calls 12

prepareBodyFunction · 0.85
entriesMethod · 0.80
mergeMethod · 0.80
setHeadersMethod · 0.80
fromRequestErrorMethod · 0.80
fromResponseErrorMethod · 0.80
makeClientFunction · 0.70
pipeMethod · 0.65
mapMethod · 0.65
ofMethod · 0.65
valueMethod · 0.45
fromParseErrorMethod · 0.45

Tested by

no test coverage detected