@effect-aws/client-bedrock-runtime 1.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/BedrockRuntimeClientInstance/package.json +6 -0
  2. package/BedrockRuntimeService/package.json +6 -0
  3. package/BedrockRuntimeServiceConfig/package.json +6 -0
  4. package/Errors/package.json +6 -0
  5. package/LICENSE +19 -0
  6. package/README.md +58 -0
  7. package/dist/cjs/BedrockRuntimeClientInstance.d.ts +24 -0
  8. package/dist/cjs/BedrockRuntimeClientInstance.d.ts.map +1 -0
  9. package/dist/cjs/BedrockRuntimeClientInstance.js +50 -0
  10. package/dist/cjs/BedrockRuntimeClientInstance.js.map +1 -0
  11. package/dist/cjs/BedrockRuntimeService.d.ts +73 -0
  12. package/dist/cjs/BedrockRuntimeService.d.ts.map +1 -0
  13. package/dist/cjs/BedrockRuntimeService.js +64 -0
  14. package/dist/cjs/BedrockRuntimeService.js.map +1 -0
  15. package/dist/cjs/BedrockRuntimeServiceConfig.d.ts +25 -0
  16. package/dist/cjs/BedrockRuntimeServiceConfig.d.ts.map +1 -0
  17. package/dist/cjs/BedrockRuntimeServiceConfig.js +35 -0
  18. package/dist/cjs/BedrockRuntimeServiceConfig.js.map +1 -0
  19. package/dist/cjs/Errors.d.ts +19 -0
  20. package/dist/cjs/Errors.d.ts.map +1 -0
  21. package/dist/cjs/Errors.js +20 -0
  22. package/dist/cjs/Errors.js.map +1 -0
  23. package/dist/cjs/index.d.ts +39 -0
  24. package/dist/cjs/index.d.ts.map +1 -0
  25. package/dist/cjs/index.js +56 -0
  26. package/dist/cjs/index.js.map +1 -0
  27. package/dist/dts/BedrockRuntimeClientInstance.d.ts +24 -0
  28. package/dist/dts/BedrockRuntimeClientInstance.d.ts.map +1 -0
  29. package/dist/dts/BedrockRuntimeService.d.ts +73 -0
  30. package/dist/dts/BedrockRuntimeService.d.ts.map +1 -0
  31. package/dist/dts/BedrockRuntimeServiceConfig.d.ts +25 -0
  32. package/dist/dts/BedrockRuntimeServiceConfig.d.ts.map +1 -0
  33. package/dist/dts/Errors.d.ts +19 -0
  34. package/dist/dts/Errors.d.ts.map +1 -0
  35. package/dist/dts/index.d.ts +39 -0
  36. package/dist/dts/index.d.ts.map +1 -0
  37. package/dist/esm/BedrockRuntimeClientInstance.js +23 -0
  38. package/dist/esm/BedrockRuntimeClientInstance.js.map +1 -0
  39. package/dist/esm/BedrockRuntimeService.js +37 -0
  40. package/dist/esm/BedrockRuntimeService.js.map +1 -0
  41. package/dist/esm/BedrockRuntimeServiceConfig.js +31 -0
  42. package/dist/esm/BedrockRuntimeServiceConfig.js.map +1 -0
  43. package/dist/esm/Errors.js +17 -0
  44. package/dist/esm/Errors.js.map +1 -0
  45. package/dist/esm/index.js +27 -0
  46. package/dist/esm/index.js.map +1 -0
  47. package/dist/esm/package.json +4 -0
  48. package/package.json +71 -0
  49. package/src/BedrockRuntimeClientInstance.ts +33 -0
  50. package/src/BedrockRuntimeService.ts +256 -0
  51. package/src/BedrockRuntimeServiceConfig.ts +52 -0
  52. package/src/Errors.ts +47 -0
  53. package/src/index.ts +44 -0
@@ -0,0 +1,256 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import {
5
+ ApplyGuardrailCommand,
6
+ type ApplyGuardrailCommandInput,
7
+ type ApplyGuardrailCommandOutput,
8
+ type BedrockRuntimeClient,
9
+ type BedrockRuntimeClientConfig,
10
+ ConverseCommand,
11
+ type ConverseCommandInput,
12
+ type ConverseCommandOutput,
13
+ ConverseStreamCommand,
14
+ type ConverseStreamCommandInput,
15
+ type ConverseStreamCommandOutput,
16
+ GetAsyncInvokeCommand,
17
+ type GetAsyncInvokeCommandInput,
18
+ type GetAsyncInvokeCommandOutput,
19
+ InvokeModelCommand,
20
+ type InvokeModelCommandInput,
21
+ type InvokeModelCommandOutput,
22
+ InvokeModelWithResponseStreamCommand,
23
+ type InvokeModelWithResponseStreamCommandInput,
24
+ type InvokeModelWithResponseStreamCommandOutput,
25
+ ListAsyncInvokesCommand,
26
+ type ListAsyncInvokesCommandInput,
27
+ type ListAsyncInvokesCommandOutput,
28
+ StartAsyncInvokeCommand,
29
+ type StartAsyncInvokeCommandInput,
30
+ type StartAsyncInvokeCommandOutput,
31
+ } from "@aws-sdk/client-bedrock-runtime";
32
+ import type { HttpHandlerOptions, SdkError, ServiceLogger } from "@effect-aws/commons";
33
+ import { Service } from "@effect-aws/commons";
34
+ import { Effect, Layer } from "effect";
35
+ import * as Instance from "./BedrockRuntimeClientInstance.js";
36
+ import * as BedrockRuntimeServiceConfig from "./BedrockRuntimeServiceConfig.js";
37
+ import type {
38
+ AccessDeniedError,
39
+ ConflictError,
40
+ InternalServerError,
41
+ ModelError,
42
+ ModelNotReadyError,
43
+ ModelStreamError,
44
+ ModelTimeoutError,
45
+ ResourceNotFoundError,
46
+ ServiceQuotaExceededError,
47
+ ServiceUnavailableError,
48
+ ThrottlingError,
49
+ ValidationError,
50
+ } from "./Errors.js";
51
+ import { AllServiceErrors } from "./Errors.js";
52
+
53
+ const commands = {
54
+ ApplyGuardrailCommand,
55
+ ConverseCommand,
56
+ ConverseStreamCommand,
57
+ GetAsyncInvokeCommand,
58
+ InvokeModelCommand,
59
+ InvokeModelWithResponseStreamCommand,
60
+ ListAsyncInvokesCommand,
61
+ StartAsyncInvokeCommand,
62
+ };
63
+
64
+ interface BedrockRuntimeService$ {
65
+ readonly _: unique symbol;
66
+
67
+ /**
68
+ * @see {@link ApplyGuardrailCommand}
69
+ */
70
+ applyGuardrail(
71
+ args: ApplyGuardrailCommandInput,
72
+ options?: HttpHandlerOptions,
73
+ ): Effect.Effect<
74
+ ApplyGuardrailCommandOutput,
75
+ | SdkError
76
+ | AccessDeniedError
77
+ | InternalServerError
78
+ | ResourceNotFoundError
79
+ | ServiceQuotaExceededError
80
+ | ThrottlingError
81
+ | ValidationError
82
+ >;
83
+
84
+ /**
85
+ * @see {@link ConverseCommand}
86
+ */
87
+ converse(
88
+ args: ConverseCommandInput,
89
+ options?: HttpHandlerOptions,
90
+ ): Effect.Effect<
91
+ ConverseCommandOutput,
92
+ | SdkError
93
+ | AccessDeniedError
94
+ | InternalServerError
95
+ | ModelError
96
+ | ModelNotReadyError
97
+ | ModelTimeoutError
98
+ | ResourceNotFoundError
99
+ | ServiceUnavailableError
100
+ | ThrottlingError
101
+ | ValidationError
102
+ >;
103
+
104
+ /**
105
+ * @see {@link ConverseStreamCommand}
106
+ */
107
+ converseStream(
108
+ args: ConverseStreamCommandInput,
109
+ options?: HttpHandlerOptions,
110
+ ): Effect.Effect<
111
+ ConverseStreamCommandOutput,
112
+ | SdkError
113
+ | AccessDeniedError
114
+ | InternalServerError
115
+ | ModelError
116
+ | ModelNotReadyError
117
+ | ModelTimeoutError
118
+ | ResourceNotFoundError
119
+ | ServiceUnavailableError
120
+ | ThrottlingError
121
+ | ValidationError
122
+ >;
123
+
124
+ /**
125
+ * @see {@link GetAsyncInvokeCommand}
126
+ */
127
+ getAsyncInvoke(
128
+ args: GetAsyncInvokeCommandInput,
129
+ options?: HttpHandlerOptions,
130
+ ): Effect.Effect<
131
+ GetAsyncInvokeCommandOutput,
132
+ SdkError | AccessDeniedError | InternalServerError | ThrottlingError | ValidationError
133
+ >;
134
+
135
+ /**
136
+ * @see {@link InvokeModelCommand}
137
+ */
138
+ invokeModel(
139
+ args: InvokeModelCommandInput,
140
+ options?: HttpHandlerOptions,
141
+ ): Effect.Effect<
142
+ InvokeModelCommandOutput,
143
+ | SdkError
144
+ | AccessDeniedError
145
+ | InternalServerError
146
+ | ModelError
147
+ | ModelNotReadyError
148
+ | ModelTimeoutError
149
+ | ResourceNotFoundError
150
+ | ServiceQuotaExceededError
151
+ | ServiceUnavailableError
152
+ | ThrottlingError
153
+ | ValidationError
154
+ >;
155
+
156
+ /**
157
+ * @see {@link InvokeModelWithResponseStreamCommand}
158
+ */
159
+ invokeModelWithResponseStream(
160
+ args: InvokeModelWithResponseStreamCommandInput,
161
+ options?: HttpHandlerOptions,
162
+ ): Effect.Effect<
163
+ InvokeModelWithResponseStreamCommandOutput,
164
+ | SdkError
165
+ | AccessDeniedError
166
+ | InternalServerError
167
+ | ModelError
168
+ | ModelNotReadyError
169
+ | ModelStreamError
170
+ | ModelTimeoutError
171
+ | ResourceNotFoundError
172
+ | ServiceQuotaExceededError
173
+ | ServiceUnavailableError
174
+ | ThrottlingError
175
+ | ValidationError
176
+ >;
177
+
178
+ /**
179
+ * @see {@link ListAsyncInvokesCommand}
180
+ */
181
+ listAsyncInvokes(
182
+ args: ListAsyncInvokesCommandInput,
183
+ options?: HttpHandlerOptions,
184
+ ): Effect.Effect<
185
+ ListAsyncInvokesCommandOutput,
186
+ SdkError | AccessDeniedError | InternalServerError | ThrottlingError | ValidationError
187
+ >;
188
+
189
+ /**
190
+ * @see {@link StartAsyncInvokeCommand}
191
+ */
192
+ startAsyncInvoke(
193
+ args: StartAsyncInvokeCommandInput,
194
+ options?: HttpHandlerOptions,
195
+ ): Effect.Effect<
196
+ StartAsyncInvokeCommandOutput,
197
+ | SdkError
198
+ | AccessDeniedError
199
+ | ConflictError
200
+ | InternalServerError
201
+ | ResourceNotFoundError
202
+ | ServiceQuotaExceededError
203
+ | ServiceUnavailableError
204
+ | ThrottlingError
205
+ | ValidationError
206
+ >;
207
+ }
208
+
209
+ /**
210
+ * @since 1.0.0
211
+ * @category constructors
212
+ */
213
+ export const makeBedrockRuntimeService = Effect.gen(function*() {
214
+ const client = yield* Instance.BedrockRuntimeClientInstance;
215
+
216
+ return Service.fromClientAndCommands<BedrockRuntimeService$>(client, commands, AllServiceErrors);
217
+ });
218
+
219
+ /**
220
+ * @since 1.0.0
221
+ * @category models
222
+ */
223
+ export class BedrockRuntimeService extends Effect.Tag("@effect-aws/client-bedrock-runtime/BedrockRuntimeService")<
224
+ BedrockRuntimeService,
225
+ BedrockRuntimeService$
226
+ >() {
227
+ static readonly defaultLayer = Layer.effect(this, makeBedrockRuntimeService).pipe(Layer.provide(Instance.layer));
228
+ static readonly layer = (config: BedrockRuntimeService.Config) =>
229
+ Layer.effect(this, makeBedrockRuntimeService).pipe(
230
+ Layer.provide(Instance.layer),
231
+ Layer.provide(BedrockRuntimeServiceConfig.setBedrockRuntimeServiceConfig(config)),
232
+ );
233
+ static readonly baseLayer = (
234
+ evaluate: (defaultConfig: BedrockRuntimeClientConfig) => BedrockRuntimeClient,
235
+ ) =>
236
+ Layer.effect(this, makeBedrockRuntimeService).pipe(
237
+ Layer.provide(
238
+ Layer.effect(
239
+ Instance.BedrockRuntimeClientInstance,
240
+ Effect.map(BedrockRuntimeServiceConfig.toBedrockRuntimeClientConfig, evaluate),
241
+ ),
242
+ ),
243
+ );
244
+ }
245
+
246
+ /**
247
+ * @since 1.0.0
248
+ */
249
+ export declare namespace BedrockRuntimeService {
250
+ /**
251
+ * @since 1.0.0
252
+ */
253
+ export interface Config extends Omit<BedrockRuntimeClientConfig, "logger"> {
254
+ readonly logger?: ServiceLogger.ServiceLoggerConstructorProps | true;
255
+ }
256
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import type { BedrockRuntimeClientConfig } from "@aws-sdk/client-bedrock-runtime";
5
+ import { ServiceLogger } from "@effect-aws/commons";
6
+ import { Effect, FiberRef, Layer } from "effect";
7
+ import { dual } from "effect/Function";
8
+ import { globalValue } from "effect/GlobalValue";
9
+ import type { BedrockRuntimeService } from "./BedrockRuntimeService.js";
10
+
11
+ /**
12
+ * @since 1.0.0
13
+ * @category bedrock-runtime service config
14
+ */
15
+ const currentBedrockRuntimeServiceConfig = globalValue(
16
+ "@effect-aws/client-bedrock-runtime/currentBedrockRuntimeServiceConfig",
17
+ () => FiberRef.unsafeMake<BedrockRuntimeService.Config>({}),
18
+ );
19
+
20
+ /**
21
+ * @since 1.0.0
22
+ * @category bedrock-runtime service config
23
+ */
24
+ export const withBedrockRuntimeServiceConfig: {
25
+ (config: BedrockRuntimeService.Config): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
26
+ <A, E, R>(effect: Effect.Effect<A, E, R>, config: BedrockRuntimeService.Config): Effect.Effect<A, E, R>;
27
+ } = dual(
28
+ 2,
29
+ <A, E, R>(effect: Effect.Effect<A, E, R>, config: BedrockRuntimeService.Config): Effect.Effect<A, E, R> =>
30
+ Effect.locally(effect, currentBedrockRuntimeServiceConfig, config),
31
+ );
32
+
33
+ /**
34
+ * @since 1.0.0
35
+ * @category bedrock-runtime service config
36
+ */
37
+ export const setBedrockRuntimeServiceConfig = (config: BedrockRuntimeService.Config) =>
38
+ Layer.locallyScoped(currentBedrockRuntimeServiceConfig, config);
39
+
40
+ /**
41
+ * @since 1.0.0
42
+ * @category adapters
43
+ */
44
+ export const toBedrockRuntimeClientConfig: Effect.Effect<BedrockRuntimeClientConfig> = Effect.gen(function*() {
45
+ const { logger: serviceLogger, ...config } = yield* FiberRef.get(currentBedrockRuntimeServiceConfig);
46
+
47
+ const logger = serviceLogger === true
48
+ ? yield* ServiceLogger.toClientLogger(ServiceLogger.defaultServiceLogger)
49
+ : (serviceLogger ? yield* ServiceLogger.toClientLogger(ServiceLogger.make(serviceLogger)) : undefined);
50
+
51
+ return { logger, ...config };
52
+ });
package/src/Errors.ts ADDED
@@ -0,0 +1,47 @@
1
+ import type {
2
+ AccessDeniedException,
3
+ ConflictException,
4
+ InternalServerException,
5
+ ModelErrorException,
6
+ ModelNotReadyException,
7
+ ModelStreamErrorException,
8
+ ModelTimeoutException,
9
+ ResourceNotFoundException,
10
+ ServiceQuotaExceededException,
11
+ ServiceUnavailableException,
12
+ ThrottlingException,
13
+ ValidationException,
14
+ } from "@aws-sdk/client-bedrock-runtime";
15
+ import type { TaggedException } from "@effect-aws/commons";
16
+ import { SdkError as CommonSdkError } from "@effect-aws/commons";
17
+
18
+ export const AllServiceErrors = [
19
+ "AccessDeniedException",
20
+ "ConflictException",
21
+ "InternalServerException",
22
+ "ModelErrorException",
23
+ "ModelNotReadyException",
24
+ "ModelStreamErrorException",
25
+ "ModelTimeoutException",
26
+ "ResourceNotFoundException",
27
+ "ServiceQuotaExceededException",
28
+ "ServiceUnavailableException",
29
+ "ThrottlingException",
30
+ "ValidationException",
31
+ ] as const;
32
+
33
+ export type AccessDeniedError = TaggedException<AccessDeniedException>;
34
+ export type ConflictError = TaggedException<ConflictException>;
35
+ export type InternalServerError = TaggedException<InternalServerException>;
36
+ export type ModelError = TaggedException<ModelErrorException>;
37
+ export type ModelNotReadyError = TaggedException<ModelNotReadyException>;
38
+ export type ModelStreamError = TaggedException<ModelStreamErrorException>;
39
+ export type ModelTimeoutError = TaggedException<ModelTimeoutException>;
40
+ export type ResourceNotFoundError = TaggedException<ResourceNotFoundException>;
41
+ export type ServiceQuotaExceededError = TaggedException<ServiceQuotaExceededException>;
42
+ export type ServiceUnavailableError = TaggedException<ServiceUnavailableException>;
43
+ export type ThrottlingError = TaggedException<ThrottlingException>;
44
+ export type ValidationError = TaggedException<ValidationException>;
45
+
46
+ export type SdkError = CommonSdkError;
47
+ export const SdkError = CommonSdkError;
package/src/index.ts ADDED
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import { BedrockRuntimeService } from "./BedrockRuntimeService.js";
5
+
6
+ /**
7
+ * @since 1.0.0
8
+ */
9
+ export * from "./Errors.js";
10
+
11
+ /**
12
+ * @since 1.0.0
13
+ */
14
+ export * as BedrockRuntimeClientInstance from "./BedrockRuntimeClientInstance.js";
15
+
16
+ /**
17
+ * @since 1.0.0
18
+ */
19
+ export * as BedrockRuntimeServiceConfig from "./BedrockRuntimeServiceConfig.js";
20
+
21
+ /**
22
+ * @since 1.0.0
23
+ */
24
+ export * from "./BedrockRuntimeService.js";
25
+
26
+ /**
27
+ * @since 1.0.0
28
+ * @category exports
29
+ * @alias BedrockRuntimeService
30
+ */
31
+ export declare namespace BedrockRuntime {
32
+ /**
33
+ * @since 1.0.0
34
+ * @alias BedrockRuntimeService.Config
35
+ */
36
+ export type Config = BedrockRuntimeService.Config;
37
+ }
38
+
39
+ /**
40
+ * @since 1.0.0
41
+ * @category exports
42
+ * @alias BedrockRuntimeService
43
+ */
44
+ export const BedrockRuntime = BedrockRuntimeService;