@effect/ai-amazon-bedrock 0.16.1 → 4.1.4

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 (186) hide show
  1. package/AGENTS.md +434 -0
  2. package/CLAUDE.md +434 -0
  3. package/README.md +76 -3
  4. package/ai-docs/README.md +44 -0
  5. package/ai-docs/package.json +36 -0
  6. package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
  7. package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +52 -0
  8. package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
  9. package/ai-docs/src/01_effect/01_basics/index.md +7 -0
  10. package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
  11. package/ai-docs/src/01_effect/02_schema/index.md +7 -0
  12. package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
  13. package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
  14. package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
  15. package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
  16. package/ai-docs/src/01_effect/03_services/index.md +5 -0
  17. package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
  18. package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
  19. package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
  20. package/ai-docs/src/01_effect/04_errors/index.md +1 -0
  21. package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
  22. package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
  23. package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
  24. package/ai-docs/src/01_effect/05_resources/index.md +3 -0
  25. package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
  26. package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
  27. package/ai-docs/src/01_effect/06_running/index.md +1 -0
  28. package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
  29. package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
  30. package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
  31. package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
  32. package/ai-docs/src/03_stream/30_encoding.ts +163 -0
  33. package/ai-docs/src/03_stream/index.md +4 -0
  34. package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
  35. package/ai-docs/src/04_integration/index.md +5 -0
  36. package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
  37. package/ai-docs/src/05_batching/index.md +3 -0
  38. package/ai-docs/src/06_schedule/10_schedules.ts +111 -0
  39. package/ai-docs/src/06_schedule/index.md +3 -0
  40. package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
  41. package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
  42. package/ai-docs/src/07_datetime/index.md +5 -0
  43. package/ai-docs/src/08_observability/10_logging.ts +66 -0
  44. package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
  45. package/ai-docs/src/08_observability/index.md +7 -0
  46. package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
  47. package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
  48. package/ai-docs/src/09_testing/index.md +1 -0
  49. package/ai-docs/src/10_predicate/01_basics.ts +14 -0
  50. package/ai-docs/src/10_predicate/index.md +9 -0
  51. package/ai-docs/src/40_sql/10_basics.ts +175 -0
  52. package/ai-docs/src/40_sql/index.md +6 -0
  53. package/ai-docs/src/50_http-client/10_basics.ts +102 -0
  54. package/ai-docs/src/50_http-client/index.md +3 -0
  55. package/ai-docs/src/51_http-server/10_basics.ts +118 -0
  56. package/ai-docs/src/51_http-server/20_testing.ts +100 -0
  57. package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
  58. package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
  59. package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
  60. package/ai-docs/src/51_http-server/fixtures/api/Users.ts +107 -0
  61. package/ai-docs/src/51_http-server/fixtures/domain/User.ts +21 -0
  62. package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
  63. package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +37 -0
  64. package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +80 -0
  65. package/ai-docs/src/51_http-server/fixtures/server/Users.ts +183 -0
  66. package/ai-docs/src/51_http-server/index.md +3 -0
  67. package/ai-docs/src/52_graphql/10_basics.ts +117 -0
  68. package/ai-docs/src/52_graphql/20_testing.ts +45 -0
  69. package/ai-docs/src/52_graphql/30_batching.ts +118 -0
  70. package/ai-docs/src/52_graphql/40_aliased-batching.ts +124 -0
  71. package/ai-docs/src/52_graphql/50_errors-and-retries.ts +74 -0
  72. package/ai-docs/src/52_graphql/index.md +6 -0
  73. package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
  74. package/ai-docs/src/60_child-process/index.md +3 -0
  75. package/ai-docs/src/70_cli/10_basics.ts +162 -0
  76. package/ai-docs/src/70_cli/index.md +5 -0
  77. package/ai-docs/src/71_ai/10_language-model.ts +156 -0
  78. package/ai-docs/src/71_ai/20_tools.ts +226 -0
  79. package/ai-docs/src/71_ai/30_chat.ts +158 -0
  80. package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
  81. package/ai-docs/src/71_ai/index.md +5 -0
  82. package/ai-docs/src/80_cluster/10_entities.ts +97 -0
  83. package/ai-docs/src/80_cluster/index.md +4 -0
  84. package/ai-docs/src/index.md +10 -0
  85. package/ai-docs/tsconfig.json +28 -0
  86. package/dist/AmazonBedrockClient.d.ts +227 -0
  87. package/dist/AmazonBedrockClient.d.ts.map +1 -0
  88. package/dist/AmazonBedrockClient.js +281 -0
  89. package/dist/AmazonBedrockClient.js.map +1 -0
  90. package/dist/AmazonBedrockConfig.d.ts +76 -0
  91. package/dist/AmazonBedrockConfig.d.ts.map +1 -0
  92. package/dist/AmazonBedrockConfig.js +41 -0
  93. package/dist/AmazonBedrockConfig.js.map +1 -0
  94. package/dist/AmazonBedrockLanguageModel.d.ts +315 -0
  95. package/dist/AmazonBedrockLanguageModel.d.ts.map +1 -0
  96. package/dist/AmazonBedrockLanguageModel.js +991 -0
  97. package/dist/AmazonBedrockLanguageModel.js.map +1 -0
  98. package/dist/AmazonBedrockSchema.d.ts +918 -0
  99. package/dist/AmazonBedrockSchema.d.ts.map +1 -0
  100. package/dist/AmazonBedrockSchema.js +536 -0
  101. package/dist/AmazonBedrockSchema.js.map +1 -0
  102. package/dist/index.d.ts +25 -0
  103. package/dist/index.d.ts.map +1 -0
  104. package/dist/{esm/index.js → index.js} +13 -12
  105. package/dist/index.js.map +1 -0
  106. package/dist/internal/errors.d.ts +2 -0
  107. package/dist/internal/errors.d.ts.map +1 -0
  108. package/dist/internal/errors.js +185 -0
  109. package/dist/internal/errors.js.map +1 -0
  110. package/dist/internal/eventStream.d.ts +2 -0
  111. package/dist/internal/eventStream.d.ts.map +1 -0
  112. package/dist/internal/eventStream.js +180 -0
  113. package/dist/internal/eventStream.js.map +1 -0
  114. package/dist/internal/sigv4.d.ts +2 -0
  115. package/dist/internal/sigv4.d.ts.map +1 -0
  116. package/dist/internal/sigv4.js +115 -0
  117. package/dist/internal/sigv4.js.map +1 -0
  118. package/dist/{dts/internal → internal}/utilities.d.ts.map +1 -1
  119. package/dist/internal/utilities.js +17 -0
  120. package/dist/internal/utilities.js.map +1 -0
  121. package/package.json +45 -84
  122. package/src/AmazonBedrockClient.ts +447 -263
  123. package/src/AmazonBedrockConfig.ts +55 -40
  124. package/src/AmazonBedrockLanguageModel.ts +950 -929
  125. package/src/AmazonBedrockSchema.ts +526 -970
  126. package/src/index.ts +15 -14
  127. package/src/internal/errors.ts +207 -0
  128. package/src/internal/eventStream.ts +208 -0
  129. package/src/internal/sigv4.ts +154 -0
  130. package/src/internal/utilities.ts +15 -17
  131. package/AmazonBedrockClient/package.json +0 -6
  132. package/AmazonBedrockConfig/package.json +0 -6
  133. package/AmazonBedrockLanguageModel/package.json +0 -6
  134. package/AmazonBedrockSchema/package.json +0 -6
  135. package/AmazonBedrockTool/package.json +0 -6
  136. package/EventStreamEncoding/package.json +0 -6
  137. package/dist/cjs/AmazonBedrockClient.js +0 -191
  138. package/dist/cjs/AmazonBedrockClient.js.map +0 -1
  139. package/dist/cjs/AmazonBedrockConfig.js +0 -30
  140. package/dist/cjs/AmazonBedrockConfig.js.map +0 -1
  141. package/dist/cjs/AmazonBedrockLanguageModel.js +0 -1051
  142. package/dist/cjs/AmazonBedrockLanguageModel.js.map +0 -1
  143. package/dist/cjs/AmazonBedrockSchema.js +0 -800
  144. package/dist/cjs/AmazonBedrockSchema.js.map +0 -1
  145. package/dist/cjs/AmazonBedrockTool.js +0 -53
  146. package/dist/cjs/AmazonBedrockTool.js.map +0 -1
  147. package/dist/cjs/EventStreamEncoding.js +0 -86
  148. package/dist/cjs/EventStreamEncoding.js.map +0 -1
  149. package/dist/cjs/index.js +0 -20
  150. package/dist/cjs/index.js.map +0 -1
  151. package/dist/cjs/internal/utilities.js +0 -27
  152. package/dist/cjs/internal/utilities.js.map +0 -1
  153. package/dist/dts/AmazonBedrockClient.d.ts +0 -95
  154. package/dist/dts/AmazonBedrockClient.d.ts.map +0 -1
  155. package/dist/dts/AmazonBedrockConfig.d.ts +0 -47
  156. package/dist/dts/AmazonBedrockConfig.d.ts.map +0 -1
  157. package/dist/dts/AmazonBedrockLanguageModel.d.ts +0 -147
  158. package/dist/dts/AmazonBedrockLanguageModel.d.ts.map +0 -1
  159. package/dist/dts/AmazonBedrockSchema.d.ts +0 -1875
  160. package/dist/dts/AmazonBedrockSchema.d.ts.map +0 -1
  161. package/dist/dts/AmazonBedrockTool.d.ts +0 -206
  162. package/dist/dts/AmazonBedrockTool.d.ts.map +0 -1
  163. package/dist/dts/EventStreamEncoding.d.ts +0 -16
  164. package/dist/dts/EventStreamEncoding.d.ts.map +0 -1
  165. package/dist/dts/index.d.ts +0 -25
  166. package/dist/dts/index.d.ts.map +0 -1
  167. package/dist/esm/AmazonBedrockClient.js +0 -179
  168. package/dist/esm/AmazonBedrockClient.js.map +0 -1
  169. package/dist/esm/AmazonBedrockConfig.js +0 -22
  170. package/dist/esm/AmazonBedrockConfig.js.map +0 -1
  171. package/dist/esm/AmazonBedrockLanguageModel.js +0 -1040
  172. package/dist/esm/AmazonBedrockLanguageModel.js.map +0 -1
  173. package/dist/esm/AmazonBedrockSchema.js +0 -731
  174. package/dist/esm/AmazonBedrockSchema.js.map +0 -1
  175. package/dist/esm/AmazonBedrockTool.js +0 -45
  176. package/dist/esm/AmazonBedrockTool.js.map +0 -1
  177. package/dist/esm/EventStreamEncoding.js +0 -78
  178. package/dist/esm/EventStreamEncoding.js.map +0 -1
  179. package/dist/esm/index.js.map +0 -1
  180. package/dist/esm/internal/utilities.js +0 -19
  181. package/dist/esm/internal/utilities.js.map +0 -1
  182. package/dist/esm/package.json +0 -4
  183. package/index/package.json +0 -6
  184. package/src/AmazonBedrockTool.ts +0 -273
  185. package/src/EventStreamEncoding.ts +0 -118
  186. /package/dist/{dts/internal → internal}/utilities.d.ts +0 -0
@@ -1,1126 +1,682 @@
1
1
  /**
2
- * @since 1.0.0
3
- */
4
- import * as Schema from "effect/Schema"
5
-
6
- const prefix = "@effect/ai-amazon-bedrock"
7
-
8
- const makeIdentifier = (name: string) => `${prefix}/${name}`
9
-
10
- /**
11
- * The foundation models supported by Amazon Bedrock.
2
+ * The `AmazonBedrockSchema` module defines handwritten schemas for the subset
3
+ * of the Amazon Bedrock Converse API that this provider uses: the Converse
4
+ * request and response, and the ConverseStream events.
12
5
  *
13
- * An up-to-date list can be generated with the following command:
6
+ * **Details**
14
7
  *
15
- * ```sh
16
- * aws bedrock list-foundation-models --output json | jq '[.modelSummaries[].modelId]'
17
- * ```
8
+ * The Smithy model of the Converse API expresses most content as unions. A
9
+ * union is modelled here as a struct whose members are all optional. Every
10
+ * struct that Bedrock sends back keeps the fields this provider does not
11
+ * model, so a new union member or field reaches a low-level consumer instead
12
+ * of failing the whole response or being dropped. Blobs travel as base64
13
+ * strings, as in the JSON protocol.
18
14
  *
19
- * @since 1.0.0
20
- * @category Schemas
21
- */
22
- export class BedrockFoundationModelId extends Schema.Literal(
23
- "amazon.titan-tg1-large",
24
- "amazon.titan-image-generator-v1:0",
25
- "amazon.titan-image-generator-v1",
26
- "amazon.titan-image-generator-v2:0",
27
- "amazon.nova-premier-v1:0:8k",
28
- "amazon.nova-premier-v1:0:20k",
29
- "amazon.nova-premier-v1:0:1000k",
30
- "amazon.nova-premier-v1:0:mm",
31
- "amazon.nova-premier-v1:0",
32
- "amazon.titan-text-premier-v1:0",
33
- "amazon.nova-pro-v1:0:24k",
34
- "amazon.nova-pro-v1:0:300k",
35
- "amazon.nova-pro-v1:0",
36
- "amazon.nova-lite-v1:0:24k",
37
- "amazon.nova-lite-v1:0:300k",
38
- "amazon.nova-lite-v1:0",
39
- "amazon.nova-canvas-v1:0",
40
- "amazon.nova-reel-v1:0",
41
- "amazon.nova-reel-v1:1",
42
- "amazon.nova-micro-v1:0:24k",
43
- "amazon.nova-micro-v1:0:128k",
44
- "amazon.nova-micro-v1:0",
45
- "amazon.nova-sonic-v1:0",
46
- "amazon.titan-embed-g1-text-02",
47
- "amazon.titan-text-lite-v1:0:4k",
48
- "amazon.titan-text-lite-v1",
49
- "amazon.titan-text-express-v1:0:8k",
50
- "amazon.titan-text-express-v1",
51
- "amazon.titan-embed-text-v1:2:8k",
52
- "amazon.titan-embed-text-v1",
53
- "amazon.titan-embed-text-v2:0:8k",
54
- "amazon.titan-embed-text-v2:0",
55
- "amazon.titan-embed-image-v1:0",
56
- "amazon.titan-embed-image-v1",
57
- "stability.stable-diffusion-xl-v1:0",
58
- "stability.stable-diffusion-xl-v1",
59
- "ai21.jamba-instruct-v1:0",
60
- "ai21.jamba-1-5-large-v1:0",
61
- "ai21.jamba-1-5-mini-v1:0",
62
- "anthropic.claude-instant-v1:2:100k",
63
- "anthropic.claude-instant-v1",
64
- "anthropic.claude-v2:0:18k",
65
- "anthropic.claude-v2:0:100k",
66
- "anthropic.claude-v2:1:18k",
67
- "anthropic.claude-v2:1:200k",
68
- "anthropic.claude-v2:1",
69
- "anthropic.claude-v2",
70
- "anthropic.claude-3-sonnet-20240229-v1:0:28k",
71
- "anthropic.claude-3-sonnet-20240229-v1:0:200k",
72
- "anthropic.claude-3-sonnet-20240229-v1:0",
73
- "anthropic.claude-3-haiku-20240307-v1:0:48k",
74
- "anthropic.claude-3-haiku-20240307-v1:0:200k",
75
- "anthropic.claude-3-haiku-20240307-v1:0",
76
- "anthropic.claude-3-opus-20240229-v1:0:12k",
77
- "anthropic.claude-3-opus-20240229-v1:0:28k",
78
- "anthropic.claude-3-opus-20240229-v1:0:200k",
79
- "anthropic.claude-3-opus-20240229-v1:0",
80
- "anthropic.claude-3-5-sonnet-20240620-v1:0",
81
- "anthropic.claude-3-5-sonnet-20241022-v2:0",
82
- "anthropic.claude-3-7-sonnet-20250219-v1:0",
83
- "anthropic.claude-3-5-haiku-20241022-v1:0",
84
- "anthropic.claude-opus-4-20250514-v1:0",
85
- "anthropic.claude-sonnet-4-20250514-v1:0",
86
- "cohere.command-text-v14:7:4k",
87
- "cohere.command-text-v14",
88
- "cohere.command-r-v1:0",
89
- "cohere.command-r-plus-v1:0",
90
- "cohere.command-light-text-v14:7:4k",
91
- "cohere.command-light-text-v14",
92
- "cohere.embed-english-v3:0:512",
93
- "cohere.embed-english-v3",
94
- "cohere.embed-multilingual-v3:0:512",
95
- "cohere.embed-multilingual-v3",
96
- "deepseek.r1-v1:0",
97
- "meta.llama3-8b-instruct-v1:0",
98
- "meta.llama3-70b-instruct-v1:0",
99
- "meta.llama3-1-8b-instruct-v1:0",
100
- "meta.llama3-1-70b-instruct-v1:0",
101
- "meta.llama3-2-11b-instruct-v1:0",
102
- "meta.llama3-2-90b-instruct-v1:0",
103
- "meta.llama3-2-1b-instruct-v1:0",
104
- "meta.llama3-2-3b-instruct-v1:0",
105
- "meta.llama3-3-70b-instruct-v1:0",
106
- "meta.llama4-scout-17b-instruct-v1:0",
107
- "meta.llama4-maverick-17b-instruct-v1:0",
108
- "mistral.mistral-7b-instruct-v0:2",
109
- "mistral.mixtral-8x7b-instruct-v0:1",
110
- "mistral.mistral-large-2402-v1:0",
111
- "mistral.mistral-small-2402-v1:0",
112
- "mistral.pixtral-large-2502-v1:0"
113
- ) {}
114
-
115
- /**
116
- * @since 1.0.0
117
- * @category Schemas
118
- */
119
- export class CachePointBlock extends Schema.Class<CachePointBlock>(makeIdentifier("CachePointBlock"))({
120
- type: Schema.Literal("default")
121
- }) {}
122
-
123
- /**
124
- * @since 1.0.0
125
- * @category Schemas
126
- */
127
- export const DocumentFormat = Schema.Literal(
128
- "csv",
129
- "doc",
130
- "docx",
131
- "html",
132
- "md",
133
- "pdf",
134
- "txt",
135
- "xls",
136
- "xlsx"
137
- )
138
- /**
139
- * @since 1.0.0
140
- * @category Schemas
15
+ * @stability unstable
16
+ * @since 4.0.0
141
17
  */
142
- export type DocumentFormat = typeof DocumentFormat.Type
143
-
144
- /**
145
- * @since 1.0.0
146
- * @category Schemas
147
- */
148
- export class DocumentBlock extends Schema.Class<DocumentBlock>(makeIdentifier("DocumentBlock"))({
149
- name: Schema.String.pipe(
150
- Schema.pattern(/^[a-zA-Z0-9()[\]-]+(?: [a-zA-Z0-9()[\]-]+)*$/),
151
- Schema.minLength(1),
152
- Schema.maxLength(200)
153
- ),
154
- format: DocumentFormat,
155
- source: Schema.Struct({
156
- bytes: Schema.NonEmptyString
157
- })
158
- }) {}
159
-
160
- /**
161
- * @since 1.0.0
162
- * @category Schemas
163
- */
164
- export class GuardrailConverseImageBlock extends Schema.Class<GuardrailConverseImageBlock>(
165
- makeIdentifier("GuardrailConverseImageBlock")
166
- )({
167
- format: Schema.Literal("png", "jpg"),
168
- source: Schema.Struct({
169
- bytes: Schema.NonEmptyString
170
- })
171
- }) {}
172
-
173
- /**
174
- * @since 1.0.0
175
- * @category Schemas
176
- */
177
- export class GuardrailConverseTextBlock extends Schema.Class<GuardrailConverseTextBlock>(
178
- makeIdentifier("GuardrailConverseTextBlock")
179
- )({
180
- text: Schema.String,
181
- qualifiers: Schema.optional(Schema.Array(Schema.Literal("guard_content", "grounding_source", "query")))
182
- }) {}
183
-
184
- /**
185
- * @since 1.0.0
186
- * @category Schemas
187
- */
188
- export class GuardrailConverseContentBlock extends Schema.Union(
189
- GuardrailConverseImageBlock,
190
- GuardrailConverseTextBlock
191
- ) {}
192
-
193
- /**
194
- * @since 1.0.0
195
- * @category Schemas
196
- */
197
- export const ImageFormat = Schema.Literal("gif", "jpeg", "png", "webp")
198
- /**
199
- * @since 1.0.0
200
- * @category Schemas
201
- */
202
- export type ImageFormat = typeof ImageFormat.Type
203
-
204
- /**
205
- * @since 1.0.0
206
- * @category Schemas
207
- */
208
- export class ImageBlock extends Schema.Class<ImageBlock>(makeIdentifier("ImageBlock"))({
209
- format: ImageFormat,
210
- source: Schema.Struct({
211
- bytes: Schema.NonEmptyString
212
- })
213
- }) {}
214
-
215
- /**
216
- * @since 1.0.0
217
- * @category Schemas
218
- */
219
- export class JsonBlock extends Schema.Class<JsonBlock>(makeIdentifier("JsonBlock"))({
220
- json: Schema.Unknown
221
- }) {}
18
+ import type * as Brand from "effect/Brand"
19
+ import * as Predicate from "effect/Predicate"
20
+ import * as Schema from "effect/Schema"
222
21
 
223
22
  /**
224
- * @since 1.0.0
225
- * @category Schemas
23
+ * The rest of every response struct: fields this provider does not model are
24
+ * decoded as they are, so a low-level consumer can read them.
226
25
  */
227
- export class ReasoningContentBlock extends Schema.Union(
228
- Schema.Struct({
229
- reasoningText: Schema.Struct({
230
- text: Schema.String,
231
- signature: Schema.optional(Schema.String)
232
- })
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
- )
243
- ) {}
26
+ const UnknownRecord = Schema.Record(Schema.String, Schema.Unknown)
244
27
 
245
28
  /**
246
- * @since 1.0.0
247
- * @category Schemas
29
+ * A struct that Bedrock can send back, with {@link UnknownRecord} as its rest.
248
30
  */
249
- export class VideoBlock extends Schema.Class<VideoBlock>(makeIdentifier("VideoBlock"))({
250
- format: Schema.Literal("flv", "mkv", "mov", "mp4", "mpg", "mpeg", "three_gp", "webm"),
251
- source: Schema.Union(
252
- Schema.Struct({
253
- bytes: Schema.NonEmptyString
254
- }),
255
- Schema.Struct({
256
- s3Location: Schema.Struct({
257
- uri: Schema.String.pipe(
258
- Schema.pattern(/^s3:\/\/[a-z0-9][.\-a-z0-9]{1,61}[a-z0-9](\/.*)?$/),
259
- Schema.minLength(1),
260
- Schema.maxLength(1024)
261
- ),
262
- bucketOwner: Schema.String.pipe(
263
- Schema.pattern(/^[0-9]{12}$/),
264
- Schema.optional
265
- )
266
- })
267
- })
268
- )
269
- }) {}
31
+ const ResponseStruct = <const Fields extends Schema.Struct.Fields>(fields: Fields) =>
32
+ Schema.StructWithRest(Schema.Struct(fields), [UnknownRecord])
270
33
 
271
- /**
272
- * @since 1.0.0
273
- * @category Schemas
274
- */
275
- export class ToolResultBlock extends Schema.Class<ToolResultBlock>(makeIdentifier("ToolResultBlock"))({
276
- content: Schema.Array(Schema.Union(
277
- Schema.Struct({ document: DocumentBlock }),
278
- Schema.Struct({ image: ImageBlock }),
279
- Schema.Struct({ text: Schema.String }),
280
- Schema.Struct({ json: JsonBlock }),
281
- Schema.Struct({ video: VideoBlock })
282
- )),
283
- toolUseId: Schema.String.pipe(
284
- Schema.pattern(/^[a-zA-Z0-9_-]+$/),
285
- Schema.minLength(1),
286
- Schema.maxLength(64)
287
- ),
288
- status: Schema.optional(Schema.Literal("success", "error"))
289
- }) {}
34
+ // =============================================================================
35
+ // Common
36
+ // =============================================================================
290
37
 
291
38
  /**
292
- * @since 1.0.0
293
- * @category Schemas
39
+ * The stop reasons that the Smithy model of the Converse API names.
40
+ *
41
+ * @stability unstable
42
+ * @category schemas
43
+ * @since 4.0.0
294
44
  */
295
- export class ToolUseBlock extends Schema.Class<ToolUseBlock>(makeIdentifier("ToolUseBlock"))({
296
- name: Schema.String.pipe(
297
- Schema.pattern(/^[a-zA-Z0-9_-]+$/),
298
- Schema.minLength(1),
299
- Schema.maxLength(64)
300
- ),
301
- input: Schema.Unknown,
302
- toolUseId: Schema.String.pipe(
303
- Schema.pattern(/^[a-zA-Z0-9_-]+$/),
304
- Schema.minLength(1),
305
- Schema.maxLength(64)
306
- )
307
- }) {}
45
+ export const KnownStopReason = Schema.Literals([
46
+ "end_turn",
47
+ "tool_use",
48
+ "max_tokens",
49
+ "stop_sequence",
50
+ "guardrail_intervened",
51
+ "content_filtered",
52
+ "malformed_model_output",
53
+ "malformed_tool_use",
54
+ "model_context_window_exceeded"
55
+ ])
308
56
 
309
57
  /**
310
- * @since 1.0.0
311
- * @category Schemas
58
+ * The type of {@link KnownStopReason}.
59
+ *
60
+ * @stability unstable
61
+ * @category schemas
62
+ * @since 4.0.0
312
63
  */
313
- export class ContentBlock extends Schema.Union(
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
- )
350
- ) {}
64
+ export type KnownStopReason = typeof KnownStopReason.Type
351
65
 
352
66
  /**
353
- * @since 1.0.0
354
- * @category Schemas
67
+ * The reason the model stopped generating a response. Any string decodes, so a
68
+ * reason that Bedrock adds later does not fail the response.
69
+ *
70
+ * @stability unstable
71
+ * @category schemas
72
+ * @since 4.0.0
355
73
  */
356
- export class Message extends Schema.Class<Message>(makeIdentifier("Message"))({
357
- role: Schema.Literal("user", "assistant"),
358
- content: Schema.Array(ContentBlock)
359
- }) {}
74
+ export const StopReason = Schema.Union([KnownStopReason, Schema.StringForLiteralAutocomplete])
360
75
 
361
76
  /**
362
- * @since 1.0.0
363
- * @category Schemas
77
+ * The type of {@link StopReason}.
78
+ *
79
+ * @stability unstable
80
+ * @category schemas
81
+ * @since 4.0.0
364
82
  */
365
- export class ConverseOutput extends Schema.Class<ConverseOutput>(makeIdentifier("ConverseOutput"))({
366
- message: Message
367
- }) {}
83
+ export type StopReason = typeof StopReason.Type
368
84
 
369
85
  /**
370
- * @since 1.0.0
371
- * @category Schemas
86
+ * Token usage statistics returned by the Converse API.
87
+ *
88
+ * @stability unstable
89
+ * @category schemas
90
+ * @since 4.0.0
372
91
  */
373
- export class ConverseMetrics extends Schema.Class<ConverseMetrics>(makeIdentifier("ConverseMetrics"))({
374
- latencyMs: Schema.DurationFromMillis
375
- }) {}
92
+ export const TokenUsage = ResponseStruct({
93
+ inputTokens: Schema.Int,
94
+ outputTokens: Schema.Int,
95
+ totalTokens: Schema.Int,
96
+ cacheReadInputTokens: Schema.optional(Schema.Int),
97
+ cacheWriteInputTokens: Schema.optional(Schema.Int)
98
+ })
376
99
 
377
100
  /**
378
- * @since 1.0.0
379
- * @category Schemas
101
+ * The type of {@link TokenUsage}.
102
+ *
103
+ * @stability unstable
104
+ * @category schemas
105
+ * @since 4.0.0
380
106
  */
381
- export class GuardrailContentFilter extends Schema.Class<GuardrailContentFilter>(
382
- makeIdentifier("GuardrailContentFilter")
383
- )({
384
- type: Schema.Literal("HATE", "INSULTS", "MISCONDUCT", "PROMPT_ATTACK", "SEXUAL", "VIOLENCE"),
385
- action: Schema.Literal("BLOCKED", "NONE"),
386
- confidence: Schema.Literal("NONE", "LOW", "MEDIUM", "HIGH"),
387
- detected: Schema.optional(Schema.Boolean),
388
- filterStrength: Schema.optional(Schema.Literal("NONE", "LOW", "MEDIUM", "HIGH"))
389
- }) {}
107
+ export type TokenUsage = typeof TokenUsage.Type
390
108
 
391
- /**
392
- * @since 1.0.0
393
- * @category Schemas
394
- */
395
- export class GuardrailContentPolicyAssessment extends Schema.Class<GuardrailContentPolicyAssessment>(
396
- makeIdentifier("GuardrailContentPolicyAssessment")
397
- )({
398
- filters: Schema.Array(GuardrailContentFilter)
399
- }) {}
109
+ // =============================================================================
110
+ // Content Blocks
111
+ // =============================================================================
400
112
 
401
113
  /**
402
- * @since 1.0.0
403
- * @category Schemas
114
+ * A tool-use content block: the model's request to invoke a tool.
115
+ *
116
+ * @stability unstable
117
+ * @category schemas
118
+ * @since 4.0.0
404
119
  */
405
- export class GuardrailContextualGroundingFilter extends Schema.Class<GuardrailContextualGroundingFilter>(
406
- makeIdentifier("GuardrailContextualGroundingFilter")
407
- )({
408
- type: Schema.Literal("GROUNDING", "RELEVANCE"),
409
- action: Schema.Literal("BLOCKED", "NONE"),
410
- score: Schema.Number.pipe(Schema.between(0, 1)),
411
- threshold: Schema.Number.pipe(Schema.between(0, 1)),
412
- detected: Schema.optional(Schema.Boolean)
413
- }) {}
120
+ export const ToolUseBlock = ResponseStruct({
121
+ toolUseId: Schema.String,
122
+ name: Schema.String,
123
+ input: Schema.Unknown
124
+ })
414
125
 
415
126
  /**
416
- * @since 1.0.0
417
- * @category Schemas
127
+ * One piece of the content of a tool result: text or a JSON document.
128
+ *
129
+ * @stability unstable
130
+ * @category schemas
131
+ * @since 4.0.0
418
132
  */
419
- export class GuardrailContextualGroundingPolicyAssessment
420
- extends Schema.Class<GuardrailContextualGroundingPolicyAssessment>(
421
- makeIdentifier("GuardrailContextualGroundingPolicyAssessment")
422
- )({
423
- filters: Schema.optional(Schema.Array(GuardrailContextualGroundingFilter))
424
- })
425
- {}
133
+ export const ToolResultContentBlock = ResponseStruct({
134
+ text: Schema.optional(Schema.String),
135
+ json: Schema.optional(Schema.Unknown)
136
+ })
426
137
 
427
138
  /**
428
- * @since 1.0.0
429
- * @category Schemas
139
+ * A tool-result content block: the outcome of a tool invocation fed back to
140
+ * the model.
141
+ *
142
+ * @stability unstable
143
+ * @category schemas
144
+ * @since 4.0.0
430
145
  */
431
- export class GuardrailImageCoverage extends Schema.Class<GuardrailImageCoverage>(
432
- makeIdentifier("GuardrailImageCoverage")
433
- )({
434
- guarded: Schema.optional(Schema.Int),
435
- total: Schema.optional(Schema.Int)
436
- }) {}
146
+ export const ToolResultBlock = ResponseStruct({
147
+ toolUseId: Schema.String,
148
+ content: Schema.Array(ToolResultContentBlock),
149
+ status: Schema.optional(Schema.Literals(["success", "error"]))
150
+ })
437
151
 
438
152
  /**
439
- * @since 1.0.0
440
- * @category Schemas
153
+ * The reasoning text produced by a model, with the signature that verifies
154
+ * the model generated it. The signature must be echoed back unmodified when
155
+ * the block is sent in a later turn.
156
+ *
157
+ * @stability unstable
158
+ * @category schemas
159
+ * @since 4.0.0
441
160
  */
442
- export class GuardrailTextCharactersCoverage extends Schema.Class<GuardrailTextCharactersCoverage>(
443
- makeIdentifier("GuardrailTextCharactersCoverage")
444
- )({
445
- guarded: Schema.optional(Schema.Int),
446
- total: Schema.optional(Schema.Int)
447
- }) {}
161
+ export const ReasoningTextBlock = ResponseStruct({
162
+ text: Schema.String,
163
+ signature: Schema.optional(Schema.String)
164
+ })
448
165
 
449
166
  /**
450
- * @since 1.0.0
451
- * @category Schemas
167
+ * A reasoning content block: either reasoning text or reasoning that the
168
+ * model provider redacted, as a base64 string.
169
+ *
170
+ * @stability unstable
171
+ * @category schemas
172
+ * @since 4.0.0
452
173
  */
453
- export class GuardrailCoverage extends Schema.Class<GuardrailCoverage>(makeIdentifier("GuardrailCoverage"))({
454
- images: Schema.optional(GuardrailImageCoverage),
455
- textCharacters: Schema.optional(GuardrailTextCharactersCoverage)
456
- }) {}
174
+ export const ReasoningContentBlock = ResponseStruct({
175
+ reasoningText: Schema.optional(ReasoningTextBlock),
176
+ redactedContent: Schema.optional(Schema.String)
177
+ })
457
178
 
458
179
  /**
459
- * @since 1.0.0
460
- * @category Schemas
180
+ * A cache point marking the end of a reusable prefix of a request.
181
+ *
182
+ * **Details**
183
+ *
184
+ * Converse caches everything preceding the block, so a cache point is its own
185
+ * content block appended after the content it should cover. `ttl` opts into
186
+ * extended caching; when omitted Bedrock uses the default lifetime.
187
+ * Bedrock does not send cache points back, so unlike the response structs
188
+ * this one keeps no unmodelled fields and stays exact as a request option.
189
+ *
190
+ * @stability unstable
191
+ * @category schemas
192
+ * @since 4.0.0
461
193
  */
462
- export class GuardrailUsage extends Schema.Class<GuardrailUsage>(makeIdentifier("GuardrailUsage"))({
463
- contentPolicyUnits: Schema.Int,
464
- contextualGroundingPolicyUnits: Schema.Int,
465
- sensitiveInformationPolicyFreeUnits: Schema.Int,
466
- sensitiveInformationPolicyUnits: Schema.Int,
467
- topicPolicyUnits: Schema.Int,
468
- wordPolicyUnits: Schema.Int,
469
- contentPolicyImageUnits: Schema.optional(Schema.Int)
470
- }) {}
194
+ export const CachePointBlock = Schema.Struct({
195
+ type: Schema.Literal("default"),
196
+ ttl: Schema.optionalKey(Schema.Literals(["5m", "1h"]))
197
+ })
471
198
 
472
199
  /**
473
- * @since 1.0.0
474
- * @category Schemas
200
+ * The type of {@link CachePointBlock}.
201
+ *
202
+ * @stability unstable
203
+ * @category schemas
204
+ * @since 4.0.0
475
205
  */
476
- export class GuardrailInvocationMetrics extends Schema.Class<GuardrailInvocationMetrics>(
477
- makeIdentifier("GuardrailInvocationMetrics")
478
- )({
479
- guardrailCoverage: Schema.optional(GuardrailCoverage),
480
- guardrailProcessingLatency: Schema.optional(Schema.Number),
481
- usage: Schema.optional(GuardrailUsage)
482
- }) {}
206
+ export type CachePointBlock = typeof CachePointBlock.Type
483
207
 
484
208
  /**
485
- * @since 1.0.0
486
- * @category Schemas
209
+ * The image formats the Converse API accepts.
210
+ *
211
+ * @stability unstable
212
+ * @category schemas
213
+ * @since 4.0.0
487
214
  */
488
- export class GuardrailPiiEntityFilter extends Schema.Class<GuardrailPiiEntityFilter>(
489
- makeIdentifier("GuardrailPiiEntityFilter")
490
- )({
491
- type: Schema.Literal(
492
- "ADDRESS",
493
- "AGE",
494
- "AWS_ACCESS_KEY",
495
- "AWS_SECRET_KEY",
496
- "CA_HEALTH_NUMBER",
497
- "CA_SOCIAL_INSURANCE_NUMBER",
498
- "CREDIT_DEBIT_CARD_CVV",
499
- "CREDIT_DEBIT_CARD_EXPIRY",
500
- "CREDIT_DEBIT_CARD_NUMBER",
501
- "DRIVER_ID",
502
- "EMAIL",
503
- "INTERNATIONAL_BANK_ACCOUNT_NUMBER",
504
- "IP_ADDRESS",
505
- "LICENSE_PLATE",
506
- "MAC_ADDRESS",
507
- "NAME",
508
- "PASSWORD",
509
- "PHONE",
510
- "PIN",
511
- "SWIFT_CODE",
512
- "UK_NATIONAL_HEALTH_SERVICE_NUMBER",
513
- "UK_NATIONAL_INSURANCE_NUMBER",
514
- "UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER",
515
- "URL",
516
- "USERNAME",
517
- "US_BANK_ACCOUNT_NUMBER",
518
- "US_BANK_ROUTING_NUMBER",
519
- "US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER",
520
- "US_PASSPORT_NUMBER",
521
- "US_SOCIAL_SECURITY_NUMBER",
522
- "VEHICLE_IDENTIFICATION_NUMBER"
523
- ),
524
- action: Schema.Literal("ANONYMIZED", "BLOCKED", "NONE"),
525
- match: Schema.String,
526
- detected: Schema.optional(Schema.Boolean)
527
- }) {}
215
+ export const ImageFormat = Schema.Literals(["png", "jpeg", "gif", "webp"])
528
216
 
529
217
  /**
530
- * @since 1.0.0
531
- * @category Schemas
218
+ * An image content block. The image is sent as base64 bytes.
219
+ *
220
+ * @stability unstable
221
+ * @category schemas
222
+ * @since 4.0.0
532
223
  */
533
- export class GuardrailRegexFilter extends Schema.Class<GuardrailRegexFilter>(
534
- makeIdentifier("GuardrailRegexFilter")
535
- )({
536
- action: Schema.Literal("ANONYMIZED", "BLOCKED", "NONE"),
537
- name: Schema.optional(Schema.String),
538
- match: Schema.optional(Schema.String),
539
- regex: Schema.optional(Schema.String),
540
- detected: Schema.optional(Schema.Boolean)
541
- }) {}
224
+ export const ImageBlock = ResponseStruct({
225
+ format: ImageFormat,
226
+ source: ResponseStruct({ bytes: Schema.String })
227
+ })
542
228
 
543
229
  /**
544
- * @since 1.0.0
545
- * @category Schemas
230
+ * The document formats the Converse API accepts.
231
+ *
232
+ * @stability unstable
233
+ * @category schemas
234
+ * @since 4.0.0
546
235
  */
547
- export class GuardrailSensitiveInformationPolicyAssessment
548
- extends Schema.Class<GuardrailSensitiveInformationPolicyAssessment>(
549
- makeIdentifier("GuardrailSensitiveInformationPolicyAssessment")
550
- )({
551
- piiEntities: Schema.Array(GuardrailPiiEntityFilter),
552
- regexes: Schema.Array(GuardrailRegexFilter)
553
- })
554
- {}
236
+ export const DocumentFormat = Schema.Literals(["pdf", "csv", "doc", "docx", "xls", "xlsx", "html", "txt", "md"])
555
237
 
556
238
  /**
557
- * @since 1.0.0
558
- * @category Schemas
239
+ * A document content block. Bedrock restricts `name` to alphanumerics, single
240
+ * runs of whitespace, hyphens, parentheses and square brackets.
241
+ *
242
+ * @stability unstable
243
+ * @category schemas
244
+ * @since 4.0.0
559
245
  */
560
- export class GuardrailTopic extends Schema.Class<GuardrailTopic>(makeIdentifier("GuardrailTopic"))({
561
- action: Schema.Literal("BLOCKED", "NONE"),
246
+ export const DocumentBlock = ResponseStruct({
247
+ format: DocumentFormat,
562
248
  name: Schema.String,
563
- type: Schema.Literal("DENY"),
564
- detected: Schema.optional(Schema.Boolean)
565
- }) {}
566
-
567
- /**
568
- * @since 1.0.0
569
- * @category Schemas
570
- */
571
- export class GuardrailTopicPolicyAssessment extends Schema.Class<GuardrailTopicPolicyAssessment>(
572
- makeIdentifier("GuardrailTopicPolicyAssessment")
573
- )({
574
- topics: Schema.Array(GuardrailTopic)
575
- }) {}
576
-
577
- /**
578
- * @since 1.0.0
579
- * @category Schemas
580
- */
581
- export class GuardrailCustomWord extends Schema.Class<GuardrailCustomWord>(
582
- makeIdentifier("GuardrailCustomWord")
583
- )({
584
- action: Schema.Literal("BLOCKED", "NONE"),
585
- match: Schema.String,
586
- detected: Schema.optional(Schema.Boolean)
587
- }) {}
588
-
589
- /**
590
- * @since 1.0.0
591
- * @category Schemas
592
- */
593
- export class GuardrailManagedWord extends Schema.Class<GuardrailManagedWord>(
594
- makeIdentifier("GuardrailManagedWord")
595
- )({
596
- action: Schema.Literal("BLOCKED", "NONE"),
597
- match: Schema.String,
598
- type: Schema.Literal("PROFANITY"),
599
- detected: Schema.optional(Schema.Boolean)
600
- }) {}
601
-
602
- /**
603
- * @since 1.0.0
604
- * @category Schemas
605
- */
606
- export class GuardrailWordPolicyAssessment extends Schema.Class<GuardrailWordPolicyAssessment>(
607
- makeIdentifier("GuardrailWordPolicyAssessment")
608
- )({
609
- customWords: GuardrailCustomWord,
610
- managedWordLists: GuardrailManagedWord
611
- }) {}
612
-
613
- /**
614
- * @since 1.0.0
615
- * @category Schemas
616
- */
617
- export class GuardrailAssessment extends Schema.Class<GuardrailAssessment>(makeIdentifier("GuardrailAssessment"))({
618
- contentPolicy: Schema.optional(GuardrailContentPolicyAssessment),
619
- contextualGroundingPolicy: Schema.optional(GuardrailContextualGroundingPolicyAssessment),
620
- invocationMetrics: Schema.optional(GuardrailInvocationMetrics),
621
- sensitiveInformationPolicy: Schema.optional(GuardrailSensitiveInformationPolicyAssessment),
622
- topicPolicy: Schema.optional(GuardrailTopicPolicyAssessment),
623
- wordPolicy: Schema.optional(GuardrailWordPolicyAssessment)
624
- }) {}
249
+ source: ResponseStruct({ bytes: Schema.String })
250
+ })
625
251
 
626
252
  /**
627
- * @since 1.0.0
628
- * @category Schemas
253
+ * A content block within a Converse message. A block member this provider
254
+ * does not model, such as `citationsContent`, is kept as it was sent.
255
+ *
256
+ * @stability unstable
257
+ * @category schemas
258
+ * @since 4.0.0
259
+ */
260
+ export const ContentBlock = ResponseStruct({
261
+ text: Schema.optional(Schema.String),
262
+ toolUse: Schema.optional(ToolUseBlock),
263
+ toolResult: Schema.optional(ToolResultBlock),
264
+ reasoningContent: Schema.optional(ReasoningContentBlock),
265
+ image: Schema.optional(ImageBlock),
266
+ document: Schema.optional(DocumentBlock),
267
+ cachePoint: Schema.optional(CachePointBlock)
268
+ })
269
+
270
+ /**
271
+ * A message within a Converse conversation.
272
+ *
273
+ * @stability unstable
274
+ * @category schemas
275
+ * @since 4.0.0
629
276
  */
630
- export class GuardrailTraceAssessment extends Schema.Class<GuardrailTraceAssessment>(
631
- makeIdentifier("GuardrailTraceAssessment")
632
- )({
633
- actionReason: Schema.optional(Schema.String),
634
- inputAssessment: Schema.optional(Schema.Record({
635
- key: Schema.String,
636
- value: GuardrailAssessment
637
- })),
638
- modelOutput: Schema.optional(Schema.Array(Schema.String)),
639
- outputAssessments: Schema.optional(Schema.Record({
640
- key: Schema.String,
641
- value: GuardrailAssessment
642
- }))
643
- }) {}
277
+ export const Message = ResponseStruct({
278
+ role: Schema.Literals(["user", "assistant"]),
279
+ content: Schema.Array(ContentBlock)
280
+ })
644
281
 
645
282
  /**
646
- * @since 1.0.0
647
- * @category Schemas
283
+ * A system content block: system text or a cache point.
284
+ *
285
+ * @stability unstable
286
+ * @category schemas
287
+ * @since 4.0.0
648
288
  */
649
- export class PromptRouterTrace extends Schema.Class<PromptRouterTrace>(makeIdentifier("PromptRouterTrace"))({
650
- invokedModelId: Schema.String.pipe(
651
- Schema.pattern(
652
- /^(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}::foundation-model\/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([a-z0-9-]{1,63}[.]){0,2}[a-z0-9-]{1,63}([:][a-z0-9-]{1,63}){0,2})|(arn:aws(|-us-gov|-cn|-iso|-iso-b):bedrock:(|[0-9a-z-]{1,20}):(|[0-9]{12}):inference-profile\/[a-zA-Z0-9-:.]+)$/
653
- ),
654
- Schema.optional
655
- )
656
- }) {}
289
+ export const SystemContentBlock = Schema.Struct({
290
+ text: Schema.optional(Schema.String),
291
+ cachePoint: Schema.optional(CachePointBlock)
292
+ })
657
293
 
658
- /**
659
- * @since 1.0.0
660
- * @category Schemas
661
- */
662
- export class ConverseTrace extends Schema.Class<ConverseTrace>(makeIdentifier("ConverseTrace"))({
663
- guardrail: Schema.optional(GuardrailTraceAssessment),
664
- promptRouter: Schema.optional(PromptRouterTrace)
665
- }) {}
294
+ // =============================================================================
295
+ // Request
296
+ // =============================================================================
666
297
 
667
298
  /**
668
- * @since 1.0.0
669
- * @category Schemas
299
+ * Base inference parameters to pass to a model in a Converse call.
300
+ *
301
+ * @stability unstable
302
+ * @category schemas
303
+ * @since 4.0.0
670
304
  */
671
- export const IntZeroOrGreater = Schema.Int.pipe(Schema.greaterThanOrEqualTo(0))
305
+ export const InferenceConfiguration = Schema.Struct({
306
+ maxTokens: Schema.optional(Schema.Int),
307
+ stopSequences: Schema.optional(Schema.Array(Schema.String)),
308
+ temperature: Schema.optional(Schema.Number),
309
+ topP: Schema.optional(Schema.Number)
310
+ })
672
311
 
673
312
  /**
674
- * @since 1.0.0
675
- * @category Schemas
313
+ * The JSON Schema specification of a tool the model may call.
314
+ *
315
+ * @stability unstable
316
+ * @category schemas
317
+ * @since 4.0.0
676
318
  */
677
- export class TokenUsage extends Schema.Class<TokenUsage>(makeIdentifier("TokenUsage"))({
678
- inputTokens: IntZeroOrGreater,
679
- outputTokens: IntZeroOrGreater,
680
- totalTokens: IntZeroOrGreater,
681
- cacheReadInputTokens: Schema.optional(IntZeroOrGreater),
682
- cacheWriteInputTokens: Schema.optional(IntZeroOrGreater)
683
- }) {}
319
+ export const ToolSpecification = Schema.Struct({
320
+ name: Schema.String,
321
+ description: Schema.optionalKey(Schema.String),
322
+ inputSchema: Schema.Struct({
323
+ json: Schema.Record(Schema.String, Schema.Unknown)
324
+ })
325
+ })
684
326
 
685
327
  /**
686
- * @since 1.0.0
687
- * @category Schemas
328
+ * A tool entry within a {@link ToolConfiguration}: a tool specification, or a
329
+ * cache point marking the end of the cacheable prefix of the tool list.
330
+ *
331
+ * @stability unstable
332
+ * @category schemas
333
+ * @since 4.0.0
688
334
  */
689
- export class SystemContentBlock extends Schema.Union(
690
- Schema.Struct({ cachePoint: CachePointBlock }),
691
- Schema.Struct({ guardContent: GuardrailConverseContentBlock }),
692
- Schema.Struct({ text: Schema.String.pipe(Schema.minLength(1)) })
693
- ) {}
335
+ export const Tool = Schema.Struct({
336
+ toolSpec: Schema.optional(ToolSpecification),
337
+ cachePoint: Schema.optional(CachePointBlock)
338
+ })
694
339
 
695
340
  /**
696
- * @since 1.0.0
697
- * @category Schemas
341
+ * Controls how the model selects a tool: let it decide (`auto`), force any
342
+ * tool (`any`), or force a specific tool (`tool`).
343
+ *
344
+ * @stability unstable
345
+ * @category schemas
346
+ * @since 4.0.0
698
347
  */
699
- export class GuardrailConfiguration extends Schema.Class<GuardrailConfiguration>(
700
- makeIdentifier("GuardrailConfiguration")
701
- )({
702
- guardrailIdentifier: Schema.String.pipe(
703
- Schema.minLength(0),
704
- Schema.maxLength(2048),
705
- Schema.pattern(/^(([a-z0-9]+)|(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:[0-9]{12}:guardrail\/[a-z0-9]+))$/)
706
- ),
707
- guardrailVersion: Schema.String.pipe(
708
- Schema.pattern(/^(([1-9][0-9]{0,7})|(DRAFT))$/)
709
- ),
710
- trace: Schema.optional(Schema.Literal("enabled", "disabled", "enabled_full"))
711
- }) {}
348
+ export const ToolChoice = Schema.Union([
349
+ Schema.Struct({ auto: Schema.Struct({}) }),
350
+ Schema.Struct({ any: Schema.Struct({}) }),
351
+ Schema.Struct({ tool: Schema.Struct({ name: Schema.String }) })
352
+ ])
712
353
 
713
354
  /**
714
- * @since 1.0.0
715
- * @category Schemas
355
+ * The type of {@link ToolChoice}.
356
+ *
357
+ * @stability unstable
358
+ * @category schemas
359
+ * @since 4.0.0
716
360
  */
717
- export class InferenceConfiguration extends Schema.Class<InferenceConfiguration>(
718
- makeIdentifier("InferenceConfiguration")
719
- )({
720
- maxTokens: Schema.optional(Schema.Int.pipe(Schema.greaterThanOrEqualTo(1))),
721
- stopSequences: Schema.optional(
722
- Schema.Array(Schema.String.pipe(
723
- Schema.minLength(1)
724
- )).pipe(
725
- Schema.maxItems(4)
726
- )
727
- ),
728
- temperature: Schema.optional(Schema.Number.pipe(Schema.between(0, 1))),
729
- topP: Schema.optional(Schema.Number.pipe(Schema.between(0, 1)))
730
- }) {}
361
+ export type ToolChoice = typeof ToolChoice.Type
731
362
 
732
363
  /**
733
- * @since 1.0.0
734
- * @category Schemas
364
+ * The tool configuration for a Converse request.
365
+ *
366
+ * @stability unstable
367
+ * @category schemas
368
+ * @since 4.0.0
735
369
  */
736
- export class PerformanceConfiguration extends Schema.Class<PerformanceConfiguration>(
737
- makeIdentifier("PerformanceConfiguration")
738
- )({
739
- latency: Schema.optional(Schema.Literal("standard", "optimized"))
740
- }) {}
370
+ export const ToolConfiguration = Schema.Struct({
371
+ tools: Schema.Array(Tool),
372
+ toolChoice: Schema.optionalKey(ToolChoice)
373
+ })
741
374
 
742
375
  /**
743
- * @since 1.0.0
744
- * @category Schemas
376
+ * A JSON Schema the model's output must conform to. `schema` is the JSON
377
+ * Schema serialized to a string, as Converse requires.
378
+ *
379
+ * @stability unstable
380
+ * @category schemas
381
+ * @since 4.0.0
745
382
  */
746
- export class ToolSpecification extends Schema.Class<ToolSpecification>(
747
- makeIdentifier("ToolSpecification")
748
- )({
749
- name: Schema.String.pipe(
750
- Schema.minLength(1),
751
- Schema.maxLength(64),
752
- Schema.pattern(/^[a-zA-Z0-9_-]+$/)
753
- ),
754
- inputSchema: Schema.Struct({
755
- json: Schema.Record({
756
- key: Schema.String,
757
- value: Schema.Unknown
758
- })
759
- }),
760
- description: Schema.optional(Schema.String.pipe(
761
- Schema.minLength(1)
762
- ))
763
- }) {}
383
+ export const JsonSchemaDefinition = Schema.Struct({
384
+ schema: Schema.String,
385
+ name: Schema.optionalKey(Schema.String),
386
+ description: Schema.optionalKey(Schema.String)
387
+ })
764
388
 
765
389
  /**
766
- * @since 1.0.0
767
- * @category Schemas
390
+ * Structured output parameters for a Converse request.
391
+ *
392
+ * @stability unstable
393
+ * @category schemas
394
+ * @since 4.0.0
768
395
  */
769
- export class Tool extends Schema.Class<Tool>(
770
- makeIdentifier("Tool")
771
- )({
772
- cachePoint: Schema.optional(CachePointBlock),
773
- toolSpec: Schema.optional(ToolSpecification)
774
- }) {}
396
+ export const OutputFormat = Schema.Struct({
397
+ type: Schema.Literal("json_schema"),
398
+ structure: Schema.Struct({ jsonSchema: JsonSchemaDefinition })
399
+ })
775
400
 
776
401
  /**
777
- * @since 1.0.0
778
- * @category Schemas
402
+ * Output configuration for a Converse request: native structured output
403
+ * (`textFormat`) and the model's effort level (`effort`, on the models that
404
+ * accept it).
405
+ *
406
+ * @stability unstable
407
+ * @category schemas
408
+ * @since 4.0.0
779
409
  */
780
- export class ToolChoice extends Schema.Union(
781
- Schema.Struct({ any: Schema.Struct({}) }),
782
- Schema.Struct({ auto: Schema.Struct({}) }),
783
- Schema.Struct({
784
- tool: Schema.Struct({
785
- name: Schema.String.pipe(
786
- Schema.minLength(1),
787
- Schema.maxLength(64),
788
- Schema.pattern(/^[a-zA-Z0-9_-]+$/)
789
- )
790
- })
791
- })
792
- ) {}
410
+ export const OutputConfig = Schema.Struct({
411
+ textFormat: Schema.optionalKey(OutputFormat),
412
+ effort: Schema.optionalKey(Schema.String)
413
+ })
793
414
 
794
415
  /**
795
- * @since 1.0.0
796
- * @category Schemas
416
+ * The guardrail of a Converse request. `streamProcessingMode` applies to
417
+ * ConverseStream only and is removed from Converse requests.
418
+ *
419
+ * @stability unstable
420
+ * @category schemas
421
+ * @since 4.0.0
797
422
  */
798
- export class ToolConfiguration extends Schema.Class<ToolConfiguration>(
799
- makeIdentifier("ToolConfiguration")
800
- )({
801
- tools: Schema.Array(Tool).pipe(Schema.minItems(1)),
802
- toolChoice: Schema.optional(ToolChoice)
803
- }) {}
423
+ export const GuardrailConfiguration = Schema.Struct({
424
+ guardrailIdentifier: Schema.String,
425
+ guardrailVersion: Schema.String,
426
+ trace: Schema.optionalKey(Schema.Literals(["enabled", "disabled", "enabled_full"])),
427
+ streamProcessingMode: Schema.optionalKey(Schema.Literals(["sync", "async"]))
428
+ })
804
429
 
805
430
  /**
806
- * @since 1.0.0
807
- * @category Schemas
431
+ * The request payload for the Converse and ConverseStream operations.
432
+ *
433
+ * **Details**
434
+ *
435
+ * `modelId` travels in the URL, not in the body. `additionalModelRequestFields`
436
+ * carries inference parameters specific to the target model; extended
437
+ * thinking on an Anthropic model is enabled through it.
438
+ *
439
+ * @stability unstable
440
+ * @category schemas
441
+ * @since 4.0.0
808
442
  */
809
- export class ConverseRequest extends Schema.Class<ConverseRequest>(makeIdentifier("ConverseRequest"))({
443
+ export const ConverseRequest = Schema.Struct({
810
444
  modelId: Schema.String,
811
445
  messages: Schema.Array(Message),
812
446
  system: Schema.optional(Schema.Array(SystemContentBlock)),
813
- toolConfig: Schema.optional(ToolConfiguration),
814
- guardrailConfig: Schema.optional(GuardrailConfiguration),
447
+ toolConfig: Schema.optionalKey(ToolConfiguration),
815
448
  inferenceConfig: Schema.optional(InferenceConfiguration),
816
- performanceConfig: Schema.optional(PerformanceConfiguration),
817
- promptVariables: Schema.optional(Schema.Record({
818
- key: Schema.String,
819
- value: Schema.Struct({ text: Schema.String })
820
- })),
821
- requestMetadata: Schema.optional(Schema.Record({
822
- key: Schema.String.pipe(
823
- Schema.minLength(1),
824
- Schema.maxLength(256),
825
- Schema.pattern(/^[a-zA-Z0-9\s:_@$#=/+,-.]{1,256}$/)
826
- ),
827
- value: Schema.String.pipe(
828
- Schema.minLength(0),
829
- Schema.maxLength(256),
830
- Schema.pattern(/^[a-zA-Z0-9\s:_@$#=/+,-.]{0,256}$/)
831
- )
832
- })),
833
- additionalModelRequestFields: Schema.optional(Schema.Record({
834
- key: Schema.String,
835
- value: Schema.Unknown
836
- })),
837
- additionalModelResponseFieldPaths: Schema.optional(
838
- Schema.Array(Schema.String.pipe(
839
- Schema.minLength(1),
840
- Schema.maxLength(256)
841
- )).pipe(
842
- Schema.maxItems(10)
843
- )
844
- )
845
- }) {}
449
+ outputConfig: Schema.optionalKey(OutputConfig),
450
+ additionalModelRequestFields: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
451
+ guardrailConfig: Schema.optional(GuardrailConfiguration)
452
+ })
846
453
 
847
454
  /**
848
- * @since 1.0.0
849
- * @category Schemas
455
+ * The type of {@link ConverseRequest}.
456
+ *
457
+ * @stability unstable
458
+ * @category schemas
459
+ * @since 4.0.0
850
460
  */
851
- export class ConverseResponse extends Schema.Class<ConverseResponse>(makeIdentifier("ConverseResponse"))({
852
- output: ConverseOutput,
853
- metrics: ConverseMetrics,
854
- usage: TokenUsage,
855
- stopReason: Schema.Literal(
856
- "content_filtered",
857
- "end_turn",
858
- "tool_use",
859
- "max_tokens",
860
- "stop_sequence",
861
- "guardrail_intervened"
862
- ),
863
- trace: Schema.optional(ConverseTrace),
864
- performanceConfig: Schema.optional(Schema.Struct({
865
- latency: Schema.Literal("standard", "optimized")
866
- })),
867
- additionalModelResponseFields: Schema.optional(Schema.Record({
868
- key: Schema.String,
869
- value: Schema.Unknown
870
- }))
871
- }) {}
461
+ export type ConverseRequest = typeof ConverseRequest.Type
872
462
 
873
- /**
874
- * @since 1.0.0
875
- * @category Schemas
876
- */
877
- export class ReasoningContentBlockDelta extends Schema.Union(
878
- Schema.Struct({ redactedContent: Schema.String }),
879
- Schema.Struct({ signature: Schema.String }),
880
- Schema.Struct({ text: Schema.String })
881
- ) {}
463
+ // =============================================================================
464
+ // Response
465
+ // =============================================================================
882
466
 
883
467
  /**
884
- * @since 1.0.0
885
- * @category Schemas
468
+ * Metrics about a Converse call.
469
+ *
470
+ * @stability unstable
471
+ * @category schemas
472
+ * @since 4.0.0
886
473
  */
887
- export class ToolUseBlockStart extends Schema.Class<ToolUseBlockStart>(
888
- makeIdentifier("ToolUseBlockStart")
889
- )({
890
- name: Schema.String.pipe(
891
- Schema.minLength(1),
892
- Schema.maxLength(64),
893
- Schema.pattern(/^[a-zA-Z0-9_-]+$/)
894
- ),
895
- toolUseId: Schema.String.pipe(
896
- Schema.minLength(1),
897
- Schema.maxLength(64),
898
- Schema.pattern(/^[a-zA-Z0-9_-]+$/)
899
- )
900
- }) {}
474
+ export const ConverseMetrics = ResponseStruct({
475
+ latencyMs: Schema.Number
476
+ })
901
477
 
902
478
  /**
903
- * @since 1.0.0
904
- * @category Schemas
479
+ * The response from a successful Converse call. `trace` and any field this
480
+ * provider does not model, such as `additionalModelResponseFields`, are kept
481
+ * as Bedrock sent them.
482
+ *
483
+ * @stability unstable
484
+ * @category schemas
485
+ * @since 4.0.0
905
486
  */
906
- export class ContentBlockStart extends Schema.Class<ContentBlockStart>(
907
- makeIdentifier("ContentBlockStart")
908
- )({
909
- toolUse: Schema.optional(ToolUseBlockStart)
910
- }) {}
487
+ export const ConverseResponse = ResponseStruct({
488
+ output: ResponseStruct({ message: Message }),
489
+ usage: TokenUsage,
490
+ stopReason: StopReason,
491
+ metrics: Schema.optional(ConverseMetrics),
492
+ trace: Schema.optional(Schema.Unknown)
493
+ })
911
494
 
912
495
  /**
913
- * @since 1.0.0
914
- * @category Schemas
496
+ * The type of {@link ConverseResponse}.
497
+ *
498
+ * @stability unstable
499
+ * @category schemas
500
+ * @since 4.0.0
915
501
  */
916
- export class ContentBlockStartEvent extends Schema.Class<ContentBlockStartEvent>(
917
- makeIdentifier("ContentBlockStartEvent")
918
- )({
919
- contentBlockIndex: Schema.Int.pipe(Schema.greaterThanOrEqualTo(0)),
920
- start: ContentBlockStart
921
- }) {}
502
+ export type ConverseResponse = typeof ConverseResponse.Type
503
+
504
+ // =============================================================================
505
+ // Stream Events
506
+ // =============================================================================
922
507
 
923
508
  /**
924
- * @since 1.0.0
925
- * @category Schemas
509
+ * The start of a streamed message.
510
+ *
511
+ * @stability unstable
512
+ * @category schemas
513
+ * @since 4.0.0
926
514
  */
927
- export class ContentBlockStopEvent extends Schema.Class<ContentBlockStopEvent>(
928
- makeIdentifier("ContentBlockStopEvent")
929
- )({
930
- contentBlockIndex: Schema.Int.pipe(Schema.greaterThanOrEqualTo(0))
931
- }) {}
515
+ export const MessageStartEvent = ResponseStruct({
516
+ role: Schema.Literals(["user", "assistant"])
517
+ })
932
518
 
933
519
  /**
934
- * @since 1.0.0
935
- * @category Schemas
936
- */
937
- export class ToolUseBlockDelta extends Schema.Class<ToolUseBlockDelta>(
938
- makeIdentifier("ToolUseBlockDelta")
939
- )({
940
- input: Schema.String
941
- }) {}
520
+ * The start of a streamed content block. Tool-use blocks announce their id and
521
+ * name here; text and reasoning blocks start directly with deltas.
522
+ *
523
+ * @stability unstable
524
+ * @category schemas
525
+ * @since 4.0.0
526
+ */
527
+ export const ContentBlockStartEvent = ResponseStruct({
528
+ contentBlockIndex: Schema.Int,
529
+ start: Schema.optional(ResponseStruct({
530
+ toolUse: Schema.optional(ResponseStruct({ toolUseId: Schema.String, name: Schema.String }))
531
+ }))
532
+ })
942
533
 
943
534
  /**
944
- * @since 1.0.0
945
- * @category Schemas
946
- */
947
- export class ContentBlockDelta extends Schema.Union(
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
- )
957
- ) {}
535
+ * A delta within a streamed content block: text, a fragment of tool input
536
+ * JSON, or reasoning text, signature or redacted content. A delta member this
537
+ * provider does not model, such as `citation`, is kept as it was sent.
538
+ *
539
+ * @stability unstable
540
+ * @category schemas
541
+ * @since 4.0.0
542
+ */
543
+ export const ContentBlockDelta = ResponseStruct({
544
+ text: Schema.optional(Schema.String),
545
+ toolUse: Schema.optional(ResponseStruct({ input: Schema.String })),
546
+ reasoningContent: Schema.optional(ResponseStruct({
547
+ text: Schema.optional(Schema.String),
548
+ signature: Schema.optional(Schema.String),
549
+ redactedContent: Schema.optional(Schema.String)
550
+ }))
551
+ })
958
552
 
959
553
  /**
960
- * @since 1.0.0
961
- * @category Schemas
554
+ * A streamed delta event for a content block.
555
+ *
556
+ * @stability unstable
557
+ * @category schemas
558
+ * @since 4.0.0
962
559
  */
963
- export class ContentBlockDeltaEvent extends Schema.Class<ContentBlockDeltaEvent>(
964
- makeIdentifier("ContentBlockDeltaEvent")
965
- )({
966
- contentBlockIndex: Schema.Int.pipe(Schema.greaterThanOrEqualTo(0)),
560
+ export const ContentBlockDeltaEvent = ResponseStruct({
561
+ contentBlockIndex: Schema.Int,
967
562
  delta: ContentBlockDelta
968
- }) {}
563
+ })
969
564
 
970
565
  /**
971
- * @since 1.0.0
972
- * @category Schemas
566
+ * A streamed stop event for a content block.
567
+ *
568
+ * @stability unstable
569
+ * @category schemas
570
+ * @since 4.0.0
973
571
  */
974
- export class MessageStartEvent extends Schema.Class<MessageStartEvent>(
975
- makeIdentifier("MessageStartEvent")
976
- )({
977
- role: Schema.Literal("user", "assistant")
978
- }) {}
572
+ export const ContentBlockStopEvent = ResponseStruct({
573
+ contentBlockIndex: Schema.Int
574
+ })
979
575
 
980
576
  /**
981
- * @since 1.0.0
982
- * @category Schemas
983
- */
984
- export const StopReason = Schema.Literal(
985
- "end_turn",
986
- "tool_use",
987
- "max_tokens",
988
- "stop_sequence",
989
- "guardrail_intervened",
990
- "content_filtered"
991
- )
992
- /**
993
- * @since 1.0.0
994
- * @category Schemas
577
+ * The stop event for a streamed message.
578
+ *
579
+ * @stability unstable
580
+ * @category schemas
581
+ * @since 4.0.0
995
582
  */
996
- export type StopReason = typeof StopReason.Type
583
+ export const MessageStopEvent = ResponseStruct({
584
+ stopReason: StopReason
585
+ })
997
586
 
998
587
  /**
999
- * @since 1.0.0
1000
- * @category Schemas
588
+ * The trailing metadata event of a stream, carrying usage and metrics. Bedrock
589
+ * sends it after `messageStop`.
590
+ *
591
+ * @stability unstable
592
+ * @category schemas
593
+ * @since 4.0.0
1001
594
  */
1002
- export class MessageStopEvent extends Schema.Class<MessageStopEvent>(
1003
- makeIdentifier("MessageStopEvent")
1004
- )({
1005
- stopReason: StopReason,
1006
- additionalModelResponseFields: Schema.optional(Schema.Record({
1007
- key: Schema.String,
1008
- value: Schema.Unknown
1009
- }))
1010
- }) {}
595
+ export const ConverseStreamMetadataEvent = ResponseStruct({
596
+ usage: TokenUsage,
597
+ metrics: Schema.optional(ConverseMetrics),
598
+ trace: Schema.optional(Schema.Unknown)
599
+ })
600
+
601
+ const KnownConverseStreamEvent = Schema.Union([
602
+ Schema.Struct({ messageStart: MessageStartEvent }),
603
+ Schema.Struct({ contentBlockStart: ContentBlockStartEvent }),
604
+ Schema.Struct({ contentBlockDelta: ContentBlockDeltaEvent }),
605
+ Schema.Struct({ contentBlockStop: ContentBlockStopEvent }),
606
+ Schema.Struct({ messageStop: MessageStopEvent }),
607
+ Schema.Struct({ metadata: ConverseStreamMetadataEvent })
608
+ ])
609
+
610
+ const knownStreamEventTypes = new Set(
611
+ KnownConverseStreamEvent.members.flatMap((member) => Object.keys(member.fields))
612
+ )
1011
613
 
1012
614
  /**
1013
- * @since 1.0.0
1014
- * @category Schemas
615
+ * A ConverseStream event this provider does not model, keyed by its
616
+ * event-stream `:event-type` like every other event: `{ [eventType]: payload }`.
617
+ *
618
+ * **Details**
619
+ *
620
+ * The type declares no index signature, so an `in` check on a
621
+ * {@link ConverseStreamEvent} still narrows to the known event, and the brand
622
+ * keeps this member apart from them. Read the payload with `Object.entries`.
623
+ *
624
+ * @stability unstable
625
+ * @category models
626
+ * @since 4.0.0
1015
627
  */
1016
- export class ConverseStreamMetrics extends Schema.Class<ConverseStreamMetrics>(
1017
- makeIdentifier("ConverseStreamMetrics")
1018
- )({
1019
- latencyMs: Schema.DurationFromMillis
1020
- }) {}
628
+ export type UnknownConverseStreamEvent = Brand.Branded<object, "UnknownConverseStreamEvent">
1021
629
 
1022
630
  /**
1023
- * @since 1.0.0
1024
- * @category Schemas
1025
- */
1026
- export class ConverseStreamTrace extends Schema.Class<ConverseStreamTrace>(
1027
- makeIdentifier("ConverseStreamTrace")
1028
- )({
1029
- guardrail: Schema.optional(GuardrailTraceAssessment),
1030
- promptRouter: Schema.optional(PromptRouterTrace)
1031
- }) {}
631
+ * Fallback schema for a ConverseStream event this provider does not model.
632
+ *
633
+ * @stability unstable
634
+ * @category schemas
635
+ * @since 4.0.0
636
+ */
637
+ export const UnknownConverseStreamEvent = Schema.declare<UnknownConverseStreamEvent>(
638
+ (value): value is UnknownConverseStreamEvent => {
639
+ if (!Predicate.isObject(value)) {
640
+ return false
641
+ }
642
+ const keys = Object.keys(value)
643
+ return keys.length === 1 && !knownStreamEventTypes.has(keys[0])
644
+ },
645
+ {
646
+ identifier: "UnknownConverseStreamEvent",
647
+ description: "Fallback for unknown future stream events"
648
+ }
649
+ )
1032
650
 
1033
651
  /**
1034
- * @since 1.0.0
1035
- * @category Schemas
652
+ * A ConverseStream event, keyed by its event-stream `:event-type`, as the AWS
653
+ * SDK shapes it: `{ messageStart: ... }`, `{ contentBlockDelta: ... }` and so
654
+ * on. An event type this provider does not model decodes through
655
+ * {@link UnknownConverseStreamEvent}; a malformed known event still fails.
656
+ *
657
+ * @stability unstable
658
+ * @category schemas
659
+ * @since 4.0.0
1036
660
  */
1037
- export class ConverseStreamMetadataEvent extends Schema.Class<ConverseStreamMetadataEvent>(
1038
- makeIdentifier("ConverseStreamMetadataEvent")
1039
- )({
1040
- metrics: ConverseStreamMetrics,
1041
- usage: TokenUsage,
1042
- performanceConfig: Schema.optional(PerformanceConfiguration),
1043
- trace: Schema.optional(ConverseStreamTrace)
1044
- }) {}
661
+ export const ConverseStreamEvent = Schema.Union([...KnownConverseStreamEvent.members, UnknownConverseStreamEvent])
1045
662
 
1046
663
  /**
1047
- * @since 1.0.0
1048
- * @category Schemas
664
+ * The type of {@link ConverseStreamEvent}.
665
+ *
666
+ * @stability unstable
667
+ * @category schemas
668
+ * @since 4.0.0
1049
669
  */
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" })
670
+ export type ConverseStreamEvent = typeof ConverseStreamEvent.Type
1121
671
 
1122
672
  /**
1123
- * @since 1.0.0
1124
- * @category Models
673
+ * The body of an exception frame in a ConverseStream response, such as a
674
+ * `throttlingException`.
675
+ *
676
+ * @stability unstable
677
+ * @category schemas
678
+ * @since 4.0.0
1125
679
  */
1126
- export type ConverseResponseStreamEvent = typeof ConverseResponseStreamEvent.Type
680
+ export const ConverseStreamException = ResponseStruct({
681
+ message: Schema.optional(Schema.String)
682
+ })