@effect/ai-amazon-bedrock 0.6.2 → 0.7.0

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 (48) hide show
  1. package/AmazonBedrockTool/package.json +6 -0
  2. package/dist/cjs/AmazonBedrockClient.js +71 -145
  3. package/dist/cjs/AmazonBedrockClient.js.map +1 -1
  4. package/dist/cjs/AmazonBedrockLanguageModel.js +833 -337
  5. package/dist/cjs/AmazonBedrockLanguageModel.js.map +1 -1
  6. package/dist/cjs/AmazonBedrockSchema.js +94 -39
  7. package/dist/cjs/AmazonBedrockSchema.js.map +1 -1
  8. package/dist/cjs/AmazonBedrockTool.js +53 -0
  9. package/dist/cjs/AmazonBedrockTool.js.map +1 -0
  10. package/dist/cjs/EventStreamEncoding.js +5 -4
  11. package/dist/cjs/EventStreamEncoding.js.map +1 -1
  12. package/dist/cjs/index.js +3 -1
  13. package/dist/cjs/internal/utilities.js +3 -1
  14. package/dist/cjs/internal/utilities.js.map +1 -1
  15. package/dist/dts/AmazonBedrockClient.d.ts +34 -34
  16. package/dist/dts/AmazonBedrockClient.d.ts.map +1 -1
  17. package/dist/dts/AmazonBedrockLanguageModel.d.ts +72 -20
  18. package/dist/dts/AmazonBedrockLanguageModel.d.ts.map +1 -1
  19. package/dist/dts/AmazonBedrockSchema.d.ts +543 -102
  20. package/dist/dts/AmazonBedrockSchema.d.ts.map +1 -1
  21. package/dist/dts/AmazonBedrockTool.d.ts +184 -0
  22. package/dist/dts/AmazonBedrockTool.d.ts.map +1 -0
  23. package/dist/dts/EventStreamEncoding.d.ts +2 -2
  24. package/dist/dts/EventStreamEncoding.d.ts.map +1 -1
  25. package/dist/dts/index.d.ts +4 -0
  26. package/dist/dts/index.d.ts.map +1 -1
  27. package/dist/esm/AmazonBedrockClient.js +71 -144
  28. package/dist/esm/AmazonBedrockClient.js.map +1 -1
  29. package/dist/esm/AmazonBedrockLanguageModel.js +830 -333
  30. package/dist/esm/AmazonBedrockLanguageModel.js.map +1 -1
  31. package/dist/esm/AmazonBedrockSchema.js +93 -37
  32. package/dist/esm/AmazonBedrockSchema.js.map +1 -1
  33. package/dist/esm/AmazonBedrockTool.js +45 -0
  34. package/dist/esm/AmazonBedrockTool.js.map +1 -0
  35. package/dist/esm/EventStreamEncoding.js +5 -3
  36. package/dist/esm/EventStreamEncoding.js.map +1 -1
  37. package/dist/esm/index.js +4 -0
  38. package/dist/esm/index.js.map +1 -1
  39. package/dist/esm/internal/utilities.js +2 -0
  40. package/dist/esm/internal/utilities.js.map +1 -1
  41. package/package.json +13 -4
  42. package/src/AmazonBedrockClient.ts +144 -241
  43. package/src/AmazonBedrockLanguageModel.ts +962 -372
  44. package/src/AmazonBedrockSchema.ts +134 -46
  45. package/src/AmazonBedrockTool.ts +251 -0
  46. package/src/EventStreamEncoding.ts +80 -73
  47. package/src/index.ts +5 -0
  48. package/src/internal/utilities.ts +6 -3
@@ -230,8 +230,16 @@ export class ReasoningContentBlock extends Schema.Union(
230
230
  text: Schema.String,
231
231
  signature: Schema.optional(Schema.String)
232
232
  })
233
- }),
234
- Schema.Struct({ redactedContent: Schema.Uint8ArrayFromBase64 })
233
+ }).pipe(
234
+ Schema.attachPropertySignature("type", "reasoning"),
235
+ Schema.annotations({ identifier: "ReasoningTextContentBlock" })
236
+ ),
237
+ Schema.Struct({
238
+ redactedContent: Schema.String
239
+ }).pipe(
240
+ Schema.attachPropertySignature("type", "redacted-reasoning"),
241
+ Schema.annotations({ identifier: "RedactedReasoningContentBlock" })
242
+ )
235
243
  ) {}
236
244
 
237
245
  /**
@@ -303,15 +311,42 @@ export class ToolUseBlock extends Schema.Class<ToolUseBlock>(makeIdentifier("Too
303
311
  * @category Schemas
304
312
  */
305
313
  export class ContentBlock extends Schema.Union(
306
- Schema.Struct({ cachePoint: CachePointBlock }),
307
- Schema.Struct({ document: DocumentBlock }),
308
- Schema.Struct({ guardContent: GuardrailConverseContentBlock }),
309
- Schema.Struct({ image: ImageBlock }),
310
- Schema.Struct({ reasoningContent: ReasoningContentBlock }),
311
- Schema.Struct({ text: Schema.String }),
312
- Schema.Struct({ toolResult: ToolResultBlock }),
313
- Schema.Struct({ toolUse: ToolUseBlock }),
314
- Schema.Struct({ video: VideoBlock })
314
+ Schema.Struct({ cachePoint: CachePointBlock }).pipe(
315
+ Schema.attachPropertySignature("type", "cachePoint"),
316
+ Schema.annotations({ identifier: "CachePointContentBlock" })
317
+ ),
318
+ Schema.Struct({ document: DocumentBlock }).pipe(
319
+ Schema.attachPropertySignature("type", "document"),
320
+ Schema.annotations({ identifier: "DocumentContentBlock" })
321
+ ),
322
+ Schema.Struct({ guardContent: GuardrailConverseContentBlock }).pipe(
323
+ Schema.attachPropertySignature("type", "guardContent"),
324
+ Schema.annotations({ identifier: "GuardrailContentBlock" })
325
+ ),
326
+ Schema.Struct({ image: ImageBlock }).pipe(
327
+ Schema.attachPropertySignature("type", "image"),
328
+ Schema.annotations({ identifier: "ImageContentBlock" })
329
+ ),
330
+ Schema.Struct({ reasoningContent: ReasoningContentBlock }).pipe(
331
+ Schema.attachPropertySignature("type", "reasoningContent"),
332
+ Schema.annotations({ identifier: "ResponseContentBlock" })
333
+ ),
334
+ Schema.Struct({ text: Schema.String }).pipe(
335
+ Schema.attachPropertySignature("type", "text"),
336
+ Schema.annotations({ identifier: "TextContentBlock" })
337
+ ),
338
+ Schema.Struct({ toolResult: ToolResultBlock }).pipe(
339
+ Schema.attachPropertySignature("type", "toolResult"),
340
+ Schema.annotations({ identifier: "ToolResultContentBlock" })
341
+ ),
342
+ Schema.Struct({ toolUse: ToolUseBlock }).pipe(
343
+ Schema.attachPropertySignature("type", "toolUse"),
344
+ Schema.annotations({ identifier: "ToolUseContentBlock" })
345
+ ),
346
+ Schema.Struct({ video: VideoBlock }).pipe(
347
+ Schema.attachPropertySignature("type", "video"),
348
+ Schema.annotations({ identifier: "VideoContentBlock" })
349
+ )
315
350
  ) {}
316
351
 
317
352
  /**
@@ -840,7 +875,7 @@ export class ConverseResponse extends Schema.Class<ConverseResponse>(makeIdentif
840
875
  * @category Schemas
841
876
  */
842
877
  export class ReasoningContentBlockDelta extends Schema.Union(
843
- Schema.Struct({ redactedContent: Schema.Uint8ArrayFromBase64 }),
878
+ Schema.Struct({ redactedContent: Schema.String }),
844
879
  Schema.Struct({ signature: Schema.String }),
845
880
  Schema.Struct({ text: Schema.String })
846
881
  ) {}
@@ -871,7 +906,7 @@ export class ToolUseBlockStart extends Schema.Class<ToolUseBlockStart>(
871
906
  export class ContentBlockStart extends Schema.Class<ContentBlockStart>(
872
907
  makeIdentifier("ContentBlockStart")
873
908
  )({
874
- toolUse: ToolUseBlockStart
909
+ toolUse: Schema.optional(ToolUseBlockStart)
875
910
  }) {}
876
911
 
877
912
  /**
@@ -910,9 +945,15 @@ export class ToolUseBlockDelta extends Schema.Class<ToolUseBlockDelta>(
910
945
  * @category Schemas
911
946
  */
912
947
  export class ContentBlockDelta extends Schema.Union(
913
- Schema.Struct({ reasoningContent: ReasoningContentBlockDelta }),
914
- Schema.Struct({ text: Schema.String }),
915
- Schema.Struct({ toolUse: ToolUseBlockDelta })
948
+ Schema.Struct({ reasoningContent: ReasoningContentBlockDelta }).pipe(
949
+ Schema.attachPropertySignature("type", "reasoningContent")
950
+ ),
951
+ Schema.Struct({ text: Schema.String }).pipe(
952
+ Schema.attachPropertySignature("type", "text")
953
+ ),
954
+ Schema.Struct({ toolUse: ToolUseBlockDelta }).pipe(
955
+ Schema.attachPropertySignature("type", "toolUse")
956
+ )
916
957
  ) {}
917
958
 
918
959
  /**
@@ -1006,33 +1047,80 @@ export class ConverseStreamMetadataEvent extends Schema.Class<ConverseStreamMeta
1006
1047
  * @since 1.0.0
1007
1048
  * @category Schemas
1008
1049
  */
1009
- export class ConverseStreamResponse extends Schema.Class<ConverseStreamResponse>(
1010
- makeIdentifier("ConverseStreamResponse")
1011
- )({
1012
- contentBlockStart: Schema.optional(ContentBlockStartEvent),
1013
- contentBlockStop: Schema.optional(ContentBlockStopEvent),
1014
- contentBlockDelta: Schema.optional(ContentBlockDeltaEvent),
1015
- messageStart: Schema.optional(MessageStartEvent),
1016
- messageStop: Schema.optional(MessageStopEvent),
1017
- metadata: Schema.optional(ConverseStreamMetadataEvent),
1018
- internalServerException: Schema.optional(Schema.Record({
1019
- key: Schema.String,
1020
- value: Schema.Unknown
1021
- })),
1022
- modelStreamErrorException: Schema.optional(Schema.Record({
1023
- key: Schema.String,
1024
- value: Schema.Unknown
1025
- })),
1026
- serviceUnavailableException: Schema.optional(Schema.Record({
1027
- key: Schema.String,
1028
- value: Schema.Unknown
1029
- })),
1030
- throttlingException: Schema.optional(Schema.Record({
1031
- key: Schema.String,
1032
- value: Schema.Unknown
1033
- })),
1034
- validationException: Schema.optional(Schema.Record({
1035
- key: Schema.String,
1036
- value: Schema.Unknown
1037
- }))
1038
- }) {}
1050
+ export const ConverseResponseStreamEvent = Schema.Union(
1051
+ Schema.Struct({ messageStart: MessageStartEvent }).pipe(
1052
+ Schema.attachPropertySignature("type", "messageStart"),
1053
+ Schema.annotations({ identifier: "MessageStartEvent" })
1054
+ ),
1055
+ Schema.Struct({ messageStop: MessageStopEvent }).pipe(
1056
+ Schema.attachPropertySignature("type", "messageStop"),
1057
+ Schema.annotations({ identifier: "MessageStopEvent" })
1058
+ ),
1059
+ Schema.Struct({ contentBlockStart: ContentBlockStartEvent }).pipe(
1060
+ Schema.attachPropertySignature("type", "contentBlockStart"),
1061
+ Schema.annotations({ identifier: "ContentBlockStartEvent" })
1062
+ ),
1063
+ Schema.Struct({ contentBlockDelta: ContentBlockDeltaEvent }).pipe(
1064
+ Schema.attachPropertySignature("type", "contentBlockDelta"),
1065
+ Schema.annotations({ identifier: "ContentBlockDeltaEvent" })
1066
+ ),
1067
+ Schema.Struct({ contentBlockStop: ContentBlockStopEvent }).pipe(
1068
+ Schema.attachPropertySignature("type", "contentBlockStop"),
1069
+ Schema.annotations({ identifier: "ContentBlockDeltaEvent" })
1070
+ ),
1071
+ Schema.Struct({ metadata: ConverseStreamMetadataEvent }).pipe(
1072
+ Schema.attachPropertySignature("type", "metadata"),
1073
+ Schema.annotations({ identifier: "ConverseStreamMetadataEvent" })
1074
+ ),
1075
+ Schema.Struct({
1076
+ internalServerException: Schema.Record({
1077
+ key: Schema.String,
1078
+ value: Schema.Unknown
1079
+ })
1080
+ }).pipe(
1081
+ Schema.attachPropertySignature("type", "internalServerException"),
1082
+ Schema.annotations({ identifier: "InternalServerException" })
1083
+ ),
1084
+ Schema.Struct({
1085
+ modelStreamErrorException: Schema.Record({
1086
+ key: Schema.String,
1087
+ value: Schema.Unknown
1088
+ })
1089
+ }).pipe(
1090
+ Schema.attachPropertySignature("type", "modelStreamErrorException"),
1091
+ Schema.annotations({ identifier: "ModelStreamErrorException" })
1092
+ ),
1093
+ Schema.Struct({
1094
+ serviceUnavailableException: Schema.Record({
1095
+ key: Schema.String,
1096
+ value: Schema.Unknown
1097
+ })
1098
+ }).pipe(
1099
+ Schema.attachPropertySignature("type", "serviceUnavailableException"),
1100
+ Schema.annotations({ identifier: "ServiceUnavailableException" })
1101
+ ),
1102
+ Schema.Struct({
1103
+ throttlingException: Schema.Record({
1104
+ key: Schema.String,
1105
+ value: Schema.Unknown
1106
+ })
1107
+ }).pipe(
1108
+ Schema.attachPropertySignature("type", "throttlingException"),
1109
+ Schema.annotations({ identifier: "ThrottlingException" })
1110
+ ),
1111
+ Schema.Struct({
1112
+ validationException: Schema.Record({
1113
+ key: Schema.String,
1114
+ value: Schema.Unknown
1115
+ })
1116
+ }).pipe(
1117
+ Schema.attachPropertySignature("type", "validationException"),
1118
+ Schema.annotations({ identifier: "ValidationException" })
1119
+ )
1120
+ ).pipe(Schema.asSchema).annotations({ identifier: "ConverseResponseStreamEvent" })
1121
+
1122
+ /**
1123
+ * @since 1.0.0
1124
+ * @category Models
1125
+ */
1126
+ export type ConverseResponseStreamEvent = typeof ConverseResponseStreamEvent.Type
@@ -0,0 +1,251 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as AnthropicTool from "@effect/ai-anthropic/AnthropicTool"
5
+ import type * as Generated from "@effect/ai-anthropic/Generated"
6
+ import type * as Tool from "@effect/ai/Tool"
7
+ import type * as Schema from "effect/Schema"
8
+
9
+ /**
10
+ * @since 1.0.0
11
+ * @catgory Tools
12
+ */
13
+ export const AnthropicBash_20241022: (
14
+ args: {}
15
+ ) => Tool.ProviderDefined<
16
+ "AnthropicBash",
17
+ {
18
+ readonly args: Schema.Struct<{}>
19
+ readonly parameters: Schema.Struct<
20
+ { command: typeof Schema.NonEmptyString; restart: Schema.optional<typeof Schema.Boolean> }
21
+ >
22
+ readonly success: typeof Schema.String
23
+ readonly failure: typeof Schema.Never
24
+ },
25
+ true
26
+ > = AnthropicTool.Bash_20241022
27
+
28
+ /**
29
+ * @since 1.0.0
30
+ * @catgory Tools
31
+ */
32
+ export const AnthropicBash_20250124: (
33
+ args: {}
34
+ ) => Tool.ProviderDefined<
35
+ "AnthropicBash",
36
+ {
37
+ readonly args: Schema.Struct<{}>
38
+ readonly parameters: Schema.Struct<
39
+ { command: typeof Schema.NonEmptyString; restart: Schema.optional<typeof Schema.Boolean> }
40
+ >
41
+ readonly success: typeof Schema.String
42
+ readonly failure: typeof Schema.Never
43
+ },
44
+ true
45
+ > = AnthropicTool.Bash_20250124
46
+
47
+ /**
48
+ * @since 1.0.0
49
+ * @catgory Tools
50
+ */
51
+ export const AnthropicComputerUse_20241022: (
52
+ args: {
53
+ readonly display_height_px: number
54
+ readonly display_width_px: number
55
+ readonly cache_control?:
56
+ | { readonly type: "ephemeral"; readonly ttl?: "5m" | "1h" | null | undefined }
57
+ | null
58
+ | undefined
59
+ readonly display_number?: number | null | undefined
60
+ }
61
+ ) => Tool.ProviderDefined<
62
+ "AnthropicComputerUse",
63
+ {
64
+ readonly args: Schema.Struct<
65
+ {
66
+ readonly cache_control: Schema.optionalWith<typeof Generated.BetaCacheControlEphemeral, { nullable: true }>
67
+ readonly display_height_px: Schema.filter<typeof Schema.Int>
68
+ readonly display_number: Schema.optionalWith<Schema.filter<typeof Schema.Int>, { nullable: true }>
69
+ readonly display_width_px: Schema.filter<typeof Schema.Int>
70
+ }
71
+ >
72
+ readonly parameters: Schema.Struct<
73
+ {
74
+ action: Schema.Literal<["screenshot", "left_click", "type", "key", "mouse_move"]>
75
+ coordinate: Schema.optional<Schema.Tuple2<typeof Schema.Number, typeof Schema.Number>>
76
+ text: Schema.optional<typeof Schema.String>
77
+ }
78
+ >
79
+ readonly success: typeof Schema.String
80
+ readonly failure: typeof Schema.Never
81
+ },
82
+ true
83
+ > = AnthropicTool.ComputerUse_20241022
84
+
85
+ /**
86
+ * @since 1.0.0
87
+ * @catgory Tools
88
+ */
89
+ export const AnthropicComputerUse_20250124: (
90
+ args: {
91
+ readonly display_height_px: number
92
+ readonly display_width_px: number
93
+ readonly cache_control?:
94
+ | { readonly type: "ephemeral"; readonly ttl?: "5m" | "1h" | null | undefined }
95
+ | null
96
+ | undefined
97
+ readonly display_number?: number | null | undefined
98
+ }
99
+ ) => Tool.ProviderDefined<
100
+ "AnthropicComputerUse",
101
+ {
102
+ readonly args: Schema.Struct<
103
+ {
104
+ readonly cache_control: Schema.optionalWith<typeof Generated.BetaCacheControlEphemeral, { nullable: true }>
105
+ readonly display_height_px: Schema.filter<typeof Schema.Int>
106
+ readonly display_number: Schema.optionalWith<Schema.filter<typeof Schema.Int>, { nullable: true }>
107
+ readonly display_width_px: Schema.filter<typeof Schema.Int>
108
+ }
109
+ >
110
+ readonly parameters: Schema.Struct<
111
+ {
112
+ action: Schema.Literal<
113
+ [
114
+ "screenshot",
115
+ "left_click",
116
+ "type",
117
+ "key",
118
+ "mouse_move",
119
+ "scroll",
120
+ "left_click_drag",
121
+ "middle_click",
122
+ "right_click",
123
+ "double_click",
124
+ "triple_click",
125
+ "left_mouse_down",
126
+ "left_mouse_up",
127
+ "hold_key",
128
+ "wait"
129
+ ]
130
+ >
131
+ coordinate: Schema.optional<Schema.Tuple2<typeof Schema.Number, typeof Schema.Number>>
132
+ start_coordinate: Schema.optional<Schema.Tuple2<typeof Schema.Number, typeof Schema.Number>>
133
+ text: Schema.optional<typeof Schema.String>
134
+ scroll_direction: Schema.optional<Schema.Literal<["up", "down", "left", "right"]>>
135
+ scroll_amount: Schema.optional<typeof Schema.Number>
136
+ duration: Schema.optional<typeof Schema.Number>
137
+ }
138
+ >
139
+ readonly success: typeof Schema.String
140
+ readonly failure: typeof Schema.Never
141
+ },
142
+ true
143
+ > = AnthropicTool.ComputerUse_20250124
144
+
145
+ /**
146
+ * @since 1.0.0
147
+ * @catgory Tools
148
+ */
149
+ export const AnthropicTextEditor_20241022: (
150
+ args: {}
151
+ ) => Tool.ProviderDefined<
152
+ "AnthropicTextEditor",
153
+ {
154
+ readonly args: Schema.Struct<{}>
155
+ readonly parameters: Schema.Struct<
156
+ {
157
+ command: Schema.Literal<["view", "create", "str_replace", "insert", "undo_edit"]>
158
+ path: typeof Schema.String
159
+ file_text: Schema.optional<typeof Schema.String>
160
+ insert_line: Schema.optional<typeof Schema.Number>
161
+ new_str: Schema.optional<typeof Schema.String>
162
+ old_str: Schema.optional<typeof Schema.String>
163
+ view_range: Schema.optional<Schema.Array$<typeof Schema.Number>>
164
+ }
165
+ >
166
+ readonly success: typeof Schema.Void
167
+ readonly failure: typeof Schema.Never
168
+ },
169
+ true
170
+ > = AnthropicTool.TextEditor_20241022
171
+
172
+ /**
173
+ * @since 1.0.0
174
+ * @catgory Tools
175
+ */
176
+ export const AnthropicTextEditor_20250124: (
177
+ args: {}
178
+ ) => Tool.ProviderDefined<
179
+ "AnthropicTextEditor",
180
+ {
181
+ readonly args: Schema.Struct<{}>
182
+ readonly parameters: Schema.Struct<
183
+ {
184
+ command: Schema.Literal<["view", "create", "str_replace", "insert", "undo_edit"]>
185
+ path: typeof Schema.String
186
+ file_text: Schema.optional<typeof Schema.String>
187
+ insert_line: Schema.optional<typeof Schema.Number>
188
+ new_str: Schema.optional<typeof Schema.String>
189
+ old_str: Schema.optional<typeof Schema.String>
190
+ view_range: Schema.optional<Schema.Array$<typeof Schema.Number>>
191
+ }
192
+ >
193
+ readonly success: typeof Schema.Void
194
+ readonly failure: typeof Schema.Never
195
+ },
196
+ true
197
+ > = AnthropicTool.TextEditor_20250124
198
+
199
+ /**
200
+ * @since 1.0.0
201
+ * @catgory Tools
202
+ */
203
+ export const AnthropicTextEditor_20250429: (
204
+ args: {}
205
+ ) => Tool.ProviderDefined<
206
+ "AnthropicTextEditor",
207
+ {
208
+ readonly args: Schema.Struct<{}>
209
+ readonly parameters: Schema.Struct<
210
+ {
211
+ command: Schema.Literal<["view", "create", "str_replace", "insert"]>
212
+ path: typeof Schema.String
213
+ file_text: Schema.optional<typeof Schema.String>
214
+ insert_line: Schema.optional<typeof Schema.Number>
215
+ new_str: Schema.optional<typeof Schema.String>
216
+ old_str: Schema.optional<typeof Schema.String>
217
+ view_range: Schema.optional<Schema.Array$<typeof Schema.Number>>
218
+ }
219
+ >
220
+ readonly success: typeof Schema.Void
221
+ readonly failure: typeof Schema.Never
222
+ },
223
+ true
224
+ > = AnthropicTool.TextEditor_20250429
225
+
226
+ /**
227
+ * @since 1.0.0
228
+ * @catgory Tools
229
+ */
230
+ export const AnthropicTextEditor_20250728: (
231
+ args: {}
232
+ ) => Tool.ProviderDefined<
233
+ "AnthropicTextEditor",
234
+ {
235
+ readonly args: Schema.Struct<{}>
236
+ readonly parameters: Schema.Struct<
237
+ {
238
+ command: Schema.Literal<["view", "create", "str_replace", "insert"]>
239
+ path: typeof Schema.String
240
+ file_text: Schema.optional<typeof Schema.String>
241
+ insert_line: Schema.optional<typeof Schema.Number>
242
+ new_str: Schema.optional<typeof Schema.String>
243
+ old_str: Schema.optional<typeof Schema.String>
244
+ view_range: Schema.optional<Schema.Array$<typeof Schema.Number>>
245
+ }
246
+ >
247
+ readonly success: typeof Schema.Void
248
+ readonly failure: typeof Schema.Never
249
+ },
250
+ true
251
+ > = AnthropicTool.TextEditor_20250728
@@ -19,93 +19,100 @@ import type * as AsyncInput from "effect/SingleProducerAsyncInput"
19
19
  *
20
20
  * @since 1.0.0
21
21
  */
22
- export const makeChannel = <A, I, IE, Done>(schema: Schema.Schema<A, I>, options?: {
22
+ export const makeChannel: <A, I, R, IE, Done>(schema: Schema.Schema<A, I, R>, options?: {
23
23
  readonly bufferSize?: number
24
- }): Channel.Channel<
24
+ }) => Channel.Channel<
25
25
  Chunk.Chunk<A>,
26
26
  Chunk.Chunk<Uint8Array<ArrayBufferLike>>,
27
27
  IE | ParseError,
28
28
  IE,
29
29
  void,
30
30
  Done,
31
- never
32
- > =>
33
- Mailbox.make<A, IE | ParseError>(options?.bufferSize ?? 16).pipe(
34
- Effect.map((mailbox) => {
35
- const codec = new EventStreamCodec(toUtf8, fromUtf8)
36
- const decodeMessage = Schema.decodeUnknown(schema, {
37
- onExcessProperty: "ignore"
38
- })
39
- const textDecoder = new TextDecoder()
31
+ R
32
+ > = Effect.fnUntraced(
33
+ function*<A, I, R, IE, Done>(schema: Schema.Schema<A, I, R>, options?: {
34
+ readonly bufferSize?: number
35
+ }) {
36
+ const context = yield* Effect.context<R>()
40
37
 
41
- let messages: Array<A> = []
42
- let buffer = new Uint8Array(0)
43
- const input: AsyncInput.AsyncInputProducer<
44
- IE | ParseError,
45
- Chunk.Chunk<Uint8Array>,
46
- Done
47
- > = {
48
- awaitRead() {
49
- return Effect.void
50
- },
51
- emit(chunks) {
52
- return Effect.forEach(
53
- chunks,
54
- Effect.fnUntraced(function*(chunk) {
55
- // Append new chunk to buffer
56
- const newBuffer = new Uint8Array(buffer.length + chunk.length)
57
- newBuffer.set(buffer)
58
- newBuffer.set(chunk, buffer.length)
59
- buffer = newBuffer
38
+ const mailbox = yield* Mailbox.make<A, IE | ParseError>(options?.bufferSize ?? 16)
60
39
 
61
- // Try to decode messages from the buffer
62
- while (buffer.length >= 4) {
63
- // The first four bytes are the total length of the message (big-endian)
64
- const totalLength = new DataView(
65
- buffer.buffer,
66
- buffer.byteOffset,
67
- buffer.byteLength
68
- ).getUint32(0, false)
40
+ const codec = new EventStreamCodec(toUtf8, fromUtf8)
41
+ const decodeMessage = Schema.decodeUnknown(schema, {
42
+ onExcessProperty: "ignore"
43
+ })
44
+ const textDecoder = new TextDecoder()
69
45
 
70
- // If we don't have the full message yet, keep looping
71
- if (buffer.length < totalLength) {
72
- break
73
- }
46
+ let messages: Array<A> = []
47
+ let buffer = new Uint8Array(0)
74
48
 
75
- // Decode exactly the sub-slice for this event
76
- const subView = buffer.subarray(0, totalLength)
77
- const decoded = codec.decode(subView)
49
+ const input: AsyncInput.AsyncInputProducer<
50
+ IE | ParseError,
51
+ Chunk.Chunk<Uint8Array>,
52
+ Done
53
+ > = {
54
+ awaitRead() {
55
+ return Effect.void
56
+ },
57
+ emit(chunks) {
58
+ return Effect.forEach(
59
+ chunks,
60
+ Effect.fnUntraced(function*(chunk) {
61
+ // Append new chunk to buffer
62
+ const newBuffer = new Uint8Array(buffer.length + chunk.length)
63
+ newBuffer.set(buffer)
64
+ newBuffer.set(chunk, buffer.length)
65
+ buffer = newBuffer
78
66
 
79
- // Slice the used bytes off the buffer, removing this message
80
- buffer = buffer.slice(totalLength)
67
+ // Try to decode messages from the buffer
68
+ while (buffer.length >= 4) {
69
+ // The first four bytes are the total length of the message (big-endian)
70
+ const totalLength = new DataView(
71
+ buffer.buffer,
72
+ buffer.byteOffset,
73
+ buffer.byteLength
74
+ ).getUint32(0, false)
81
75
 
82
- // Process the message
83
- if (decoded.headers[":message-type"]?.value === "event") {
84
- const data = textDecoder.decode(decoded.body)
76
+ // If we don't have the full message yet, keep looping
77
+ if (buffer.length < totalLength) {
78
+ break
79
+ }
80
+
81
+ // Decode exactly the sub-slice for this event
82
+ const subView = buffer.subarray(0, totalLength)
83
+ const decoded = codec.decode(subView)
84
+
85
+ // Slice the used bytes off the buffer, removing this message
86
+ buffer = buffer.slice(totalLength)
85
87
 
86
- // Wrap the data in the `":event-type"` field to match the
87
- // expected schema
88
- const message = yield* decodeMessage({
89
- [decoded.headers[":event-type"]?.value as string]: JSON.parse(data)
90
- })
88
+ // Process the message
89
+ if (decoded.headers[":message-type"]?.value === "event") {
90
+ const data = textDecoder.decode(decoded.body)
91
91
 
92
- messages.push(message)
93
- }
92
+ // Wrap the data in the `":event-type"` field to match the
93
+ // expected schema
94
+ const message = yield* decodeMessage({
95
+ [decoded.headers[":event-type"]?.value as string]: JSON.parse(data)
96
+ }).pipe(Effect.provide(context))
97
+
98
+ messages.push(message)
94
99
  }
95
- yield* mailbox.offerAll(messages)
96
- messages = []
97
- }),
98
- { discard: true }
99
- ).pipe(Effect.catchAll((error) => mailbox.fail(error)))
100
- },
101
- error(cause) {
102
- return mailbox.failCause(cause)
103
- },
104
- done() {
105
- return mailbox.end
106
- }
100
+ }
101
+ yield* mailbox.offerAll(messages)
102
+ messages = []
103
+ }),
104
+ { discard: true }
105
+ ).pipe(Effect.catchAll((error) => mailbox.fail(error)))
106
+ },
107
+ error(cause) {
108
+ return mailbox.failCause(cause)
109
+ },
110
+ done() {
111
+ return mailbox.end
107
112
  }
108
- return Channel.embedInput(Mailbox.toChannel(mailbox), input)
109
- }),
110
- Channel.unwrap
111
- )
113
+ }
114
+
115
+ return Channel.embedInput(Mailbox.toChannel(mailbox), input)
116
+ },
117
+ Channel.unwrap
118
+ ) as any
package/src/index.ts CHANGED
@@ -18,6 +18,11 @@ export * as AmazonBedrockLanguageModel from "./AmazonBedrockLanguageModel.js"
18
18
  */
19
19
  export * as AmazonBedrockSchema from "./AmazonBedrockSchema.js"
20
20
 
21
+ /**
22
+ * @since 1.0.0
23
+ */
24
+ export * as AmazonBedrockTool from "./AmazonBedrockTool.js"
25
+
21
26
  /**
22
27
  * @since 1.0.0
23
28
  */
@@ -1,11 +1,14 @@
1
- import type * as AiResponse from "@effect/ai/AiResponse"
1
+ import type * as Response from "@effect/ai/Response"
2
2
  import * as Predicate from "effect/Predicate"
3
3
  import type { StopReason } from "../AmazonBedrockSchema.js"
4
4
 
5
+ /** @internal */
6
+ export const ProviderOptionsKey = "@effect/ai-amazon-bedrock/AmazonBedrockLanguageModel/ProviderOptions"
7
+
5
8
  /** @internal */
6
9
  export const ProviderMetadataKey = "@effect/ai-amazon-bedrock/AmazonBedrockLanguageModel/ProviderMetadata"
7
10
 
8
- const finishReasonMap: Record<StopReason, AiResponse.FinishReason> = {
11
+ const finishReasonMap: Record<StopReason, Response.FinishReason> = {
9
12
  content_filtered: "content-filter",
10
13
  end_turn: "stop",
11
14
  guardrail_intervened: "content-filter",
@@ -15,7 +18,7 @@ const finishReasonMap: Record<StopReason, AiResponse.FinishReason> = {
15
18
  }
16
19
 
17
20
  /** @internal */
18
- export const resolveFinishReason = (stopReason: StopReason): AiResponse.FinishReason => {
21
+ export const resolveFinishReason = (stopReason: StopReason): Response.FinishReason => {
19
22
  const reason = finishReasonMap[stopReason]
20
23
  return Predicate.isUndefined(reason) ? "unknown" : reason
21
24
  }