@wmaurer/effect-ai-amazon-bedrock 0.3.0 → 0.4.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.
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../../src/internal/errors.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,mBAAmB;AAE5C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,SAAS,IAAI,QAAQ,iBAAiB;AAItC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAAK,UAAU,MAAM,mBAAmB;AAC/C,OAAO,KAAK,MAAM,MAAM,eAAe;AAGvC;AACA;AACA;AAEA;AACA,OAAO,MAAM,cAAc,gBAAG,IAAI,CAGhC,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KACjB,OAAO,CAAC,IAAI,CAAC;EACX,MAAM,EAAE,qBAAqB;EAC7B,MAAM;EACN,MAAM,EAAE,OAAO,CAAC,kBAAkB,CAAC,eAAe,CAAC,KAAK;CACzD,CAAC,CAAC;AAEL;AACA,OAAO,MAAM,mBAAmB,gBAAG,IAAI,CAGrC,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KACjB,OAAO,CAAC,IAAI,CAAC;EACX,MAAM,EAAE,qBAAqB;EAC7B,MAAM;EACN,MAAM,EAAE,IAAI,OAAO,CAAC,qBAAqB,CAAC;IACxC,WAAW,EAAE,2BAA2B,KAAK,CAAC,IAAI,GAAG,KAAK,KAAK,CAAC,IAAI,GAAG,GAAG,EAAE,KAC1E,KAAK,CAAC,OAAO,IAAI,2BACnB;GACD;CACF,CAAC,CAAC;AAEL;AACA,OAAO,MAAM,kBAAkB,gBAAG,IAAI,CAGpC,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAI;EACrB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM;EAC3B,QAAQ,M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yB,CAAC;QAChE,WAAW,EAAE,OAAO;QACpB;OACD,CAAC;IACJ,KAAK,GAAG;MACN;MACA,OAAO,IAAI,OAAO,CAAC,qBAAqB,CAAC;QACvC,WAAW,EAAE,OAAO,IAAI,eAAe;QACvC;OACD,CAAC;IACJ,KAAK,GAAG;MACN;MACA,OAAO,IAAI,OAAO,CAAC,qBAAqB,CAAC;QACvC,WAAW,EAAE,OAAO,IAAI,aAAa;QACrC;OACD,CAAC;IACJ,KAAK,GAAG;MACN,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC;QAChC;OACD,CAAC;IACJ;MACE,IAAI,MAAM,IAAI,GAAG,EAAE;QACjB,OAAO,IAAI,OAAO,CAAC,qBAAqB,CAAC;UACvC,WAAW,EAAE,OAAO,IAAI,cAAc;UACtC;SACD,CAAC;MACJ;MACA,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC;QAC9B,WAAW,EAAE,OAAO;QACpB;OACD,CAAC;EACN;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ import type * as Schema from "effect/Schema";
2
+ import type { FinishMetadata, GuardrailOutcome } from "../AmazonBedrockLanguageModel.ts";
3
+ /** @internal */
4
+ export declare const guardrailOutcome: (trace: Schema.MutableJson | undefined) => GuardrailOutcome | null;
5
+ /** @internal */
6
+ export declare const finishMetadata: (stopReason: string | null, trace: Schema.MutableJson | undefined) => FinishMetadata;
7
+ /**
8
+ * Bedrock stops with `guardrail_intervened` both when a guardrail blocks,
9
+ * replacing the text with the guardrail's blocked message, and when it masks,
10
+ * leaving the object JSON.
11
+ *
12
+ * @internal
13
+ */
14
+ export declare const blocksObject: (stopReason: string, text: string) => boolean;
15
+ //# sourceMappingURL=guardrails.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrails.d.ts","sourceRoot":"","sources":["../../src/internal/guardrails.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAmB,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;AA8CzG,gBAAgB;AAChB,eAAO,MAAM,gBAAgB,UAAW,MAAM,CAAC,WAAW,GAAG,SAAS,KAAG,gBAAgB,GAAG,IAgB3F,CAAA;AAED,gBAAgB;AAChB,eAAO,MAAM,cAAc,eAAgB,MAAM,GAAG,IAAI,SAAS,MAAM,CAAC,WAAW,GAAG,SAAS,KAAG,cAIhG,CAAA;AAWF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,QAAQ,MAAM,KAAG,OACR,CAAA"}
@@ -0,0 +1,77 @@
1
+ const strength = {
2
+ none: 0,
3
+ masked: 1,
4
+ blocked: 2
5
+ };
6
+ const stronger = (a, b) => strength[b] > strength[a] ? b : a;
7
+ const isObject = value => typeof value === "object" && value !== null && !Array.isArray(value);
8
+ const actionOf = value => value === "BLOCKED" ? "blocked" : value === "ANONYMIZED" ? "masked" : "none";
9
+ const strongestAction = value => {
10
+ let action = "none";
11
+ if (Array.isArray(value)) {
12
+ for (const item of value) {
13
+ action = stronger(action, strongestAction(item));
14
+ }
15
+ } else if (isObject(value)) {
16
+ for (const [key, member] of Object.entries(value)) {
17
+ action = stronger(action, key === "action" && typeof member === "string" ? actionOf(member) : strongestAction(member));
18
+ }
19
+ }
20
+ return action;
21
+ };
22
+ const assessSide = (assessments, policies) => {
23
+ let side = "none";
24
+ for (const assessment of assessments) {
25
+ if (!isObject(assessment)) {
26
+ continue;
27
+ }
28
+ for (const [policy, member] of Object.entries(assessment)) {
29
+ const action = strongestAction(member);
30
+ if (action !== "none" && !policies.includes(policy)) {
31
+ policies.push(policy);
32
+ }
33
+ side = stronger(side, action);
34
+ }
35
+ }
36
+ return side;
37
+ };
38
+ /** @internal */
39
+ export const guardrailOutcome = trace => {
40
+ const guardrail = isObject(trace) ? trace.guardrail : undefined;
41
+ if (!isObject(guardrail)) {
42
+ return null;
43
+ }
44
+ const inputAssessment = guardrail.inputAssessment;
45
+ const outputAssessments = guardrail.outputAssessments;
46
+ const policies = [];
47
+ const input = assessSide(isObject(inputAssessment) ? Object.values(inputAssessment) : [], policies);
48
+ const output = assessSide(isObject(outputAssessments) ? Object.values(outputAssessments).flatMap(chunks => Array.isArray(chunks) ? chunks : []) : [], policies);
49
+ return {
50
+ input,
51
+ output,
52
+ policies
53
+ };
54
+ };
55
+ /** @internal */
56
+ export const finishMetadata = (stopReason, trace) => ({
57
+ stopReason,
58
+ guardrail: guardrailOutcome(trace),
59
+ trace: trace ?? null
60
+ });
61
+ const isJson = text => {
62
+ try {
63
+ JSON.parse(text);
64
+ return true;
65
+ } catch {
66
+ return false;
67
+ }
68
+ };
69
+ /**
70
+ * Bedrock stops with `guardrail_intervened` both when a guardrail blocks,
71
+ * replacing the text with the guardrail's blocked message, and when it masks,
72
+ * leaving the object JSON.
73
+ *
74
+ * @internal
75
+ */
76
+ export const blocksObject = (stopReason, text) => stopReason === "guardrail_intervened" && !isJson(text);
77
+ //# sourceMappingURL=guardrails.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrails.js","names":[],"sources":["../../src/internal/guardrails.ts"],"sourcesContent":[null],"mappings":"AAGA,MAAM,QAAQ,GAAoC;EAAE,IAAI,EAAE,CAAC;EAAE,MAAM,EAAE,CAAC;EAAE,OAAO,EAAE;AAAC,CAAE;AAEpF,MAAM,QAAQ,GAAG,CAAC,CAAkB,EAAE,CAAkB,KAAsB,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;AAE/G,MAAM,QAAQ,GAAI,KAAc,IAC9B,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;AAEtE,MAAM,QAAQ,GAAI,KAAa,IAC7B,KAAK,KAAK,SAAS,GAAG,SAAS,GAAG,KAAK,KAAK,YAAY,GAAG,QAAQ,GAAG,MAAM;AAE9E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ock",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Wayne Maurer",
@@ -31,7 +31,7 @@ import type * as Redacted from "effect/Redacted"
31
31
  import * as Stream from "effect/Stream"
32
32
  import { AmazonBedrockConfig } from "./AmazonBedrockConfig.ts"
33
33
  import * as EventStream from "./AmazonBedrockEventStream.ts"
34
- import type { ConverseRequest } from "./AmazonBedrockSchema.ts"
34
+ import type { ConverseRequest, ConverseStreamRequest } from "./AmazonBedrockSchema.ts"
35
35
  import { ConverseResponse, ConverseResponseStreamEvent } from "./AmazonBedrockSchema.ts"
36
36
  import * as Authentication from "./internal/credentials.ts"
37
37
  import * as Errors from "./internal/errors.ts"
@@ -62,7 +62,7 @@ export interface Service {
62
62
  * all errors to the unified `AiError` type.
63
63
  */
64
64
  readonly converseStream: (options: {
65
- readonly payload: typeof ConverseRequest.Encoded
65
+ readonly payload: typeof ConverseStreamRequest.Encoded
66
66
  }) => Stream.Stream<ConverseResponseStreamEvent, AiError.AiError>
67
67
  }
68
68
 
@@ -20,7 +20,11 @@
20
20
  * loudly with `AiError.InvalidUserInputError` rather than silently dropping
21
21
  * content. Prompt caching is opt-in per message or per part via provider
22
22
  * options. Citations are opt-in per document, and the citation blocks and
23
- * deltas Converse returns are surfaced as document source parts.
23
+ * deltas Converse returns are surfaced as document source parts. A guardrail
24
+ * applies through `Config.guardrailConfig`, and `guardContent` options on text
25
+ * parts, png and jpeg file parts, and system messages choose what it
26
+ * evaluates. Every finish part reports the raw stop reason and, when the trace
27
+ * is enabled, what the guardrail did.
24
28
  *
25
29
  * @stability unstable
26
30
  * @since 0.1.0
@@ -54,8 +58,13 @@ import type {
54
58
  ConverseRequest,
55
59
  ConverseResponse,
56
60
  ConverseResponseStreamEvent,
61
+ ConverseStreamRequest,
57
62
  DocumentBlock,
58
63
  DocumentSource,
64
+ GuardrailConverseContentBlock,
65
+ GuardrailConverseContentQualifier,
66
+ GuardrailConverseImageBlock,
67
+ GuardrailStreamConfiguration,
59
68
  ImageBlock,
60
69
  MediaSource,
61
70
  Message,
@@ -65,6 +74,7 @@ import type {
65
74
  ToolChoice,
66
75
  ToolConfiguration
67
76
  } from "./AmazonBedrockSchema.ts"
77
+ import * as InternalGuardrails from "./internal/guardrails.ts"
68
78
  import * as InternalUtilities from "./internal/utilities.ts"
69
79
 
70
80
  /**
@@ -149,15 +159,6 @@ interface CachePointOptions {
149
159
  }
150
160
 
151
161
  declare module "effect/ai/Prompt" {
152
- /**
153
- * Amazon Bedrock options for system messages.
154
- *
155
- * @stability unstable
156
- * @category models
157
- * @since 0.1.0
158
- */
159
- export interface SystemMessageOptions extends CachePointOptions {}
160
-
161
162
  /**
162
163
  * Amazon Bedrock options for user messages.
163
164
  *
@@ -185,15 +186,6 @@ declare module "effect/ai/Prompt" {
185
186
  */
186
187
  export interface ToolMessageOptions extends CachePointOptions {}
187
188
 
188
- /**
189
- * Amazon Bedrock options for text prompt parts.
190
- *
191
- * @stability unstable
192
- * @category models
193
- * @since 0.1.0
194
- */
195
- export interface TextPartOptions extends CachePointOptions {}
196
-
197
189
  /**
198
190
  * Amazon Bedrock options for tool call prompt parts.
199
191
  *
@@ -274,6 +266,13 @@ interface FileOptions {
274
266
  * Converse cannot cite.
275
267
  */
276
268
  readonly citations?: Citations | null
269
+ /**
270
+ * Sends the image as a `guardContent` image block, for the guardrail to
271
+ * evaluate. Only an `image/png` or `image/jpeg` part whose data is bytes
272
+ * or base64 can be guarded. Any other file part with this option fails
273
+ * the request with `InvalidUserInputError`.
274
+ */
275
+ readonly guardContent?: true | null
277
276
  } | null
278
277
  }
279
278
 
@@ -489,6 +488,190 @@ const reasoningTextInfo = (signature: string | undefined): ReasoningInfo => ({
489
488
  signature: signature ?? null
490
489
  })
491
490
 
491
+ /**
492
+ * A guardrail to apply to every request, set as `Config.guardrailConfig`.
493
+ *
494
+ * **Details**
495
+ *
496
+ * `generateText` and `generateObject` send it to Converse without
497
+ * `streamProcessingMode`, which Converse does not have. `streamText` sends it
498
+ * to ConverseStream as given.
499
+ *
500
+ * Without `guardContent` on any part, the guardrail evaluates every message
501
+ * and not the system prompt. Set `trace` to `"enabled"` to learn from the
502
+ * finish part whether the guardrail blocked or masked. The trace holds the
503
+ * matched text unmasked.
504
+ *
505
+ * @stability unstable
506
+ * @category models
507
+ * @since 0.4.0
508
+ */
509
+ export type GuardrailConfig = typeof GuardrailStreamConfiguration.Encoded
510
+
511
+ /**
512
+ * The role a guarded text part plays in a contextual grounding check.
513
+ *
514
+ * @stability unstable
515
+ * @category models
516
+ * @since 0.4.0
517
+ */
518
+ export type GuardContentQualifier = typeof GuardrailConverseContentQualifier.Type
519
+
520
+ /**
521
+ * Marks a text part or a system message for the guardrail to evaluate.
522
+ *
523
+ * **Details**
524
+ *
525
+ * `true` guards the text. `qualifiers` names its role in a contextual
526
+ * grounding check: the source documents are `grounding_source`, and the
527
+ * question is `query`. Once any part of a request is guarded, the guardrail
528
+ * evaluates only the guarded parts. The model still reads every part.
529
+ *
530
+ * The option stays on the part, so in a chat a guarded turn is evaluated
531
+ * again on every later turn.
532
+ *
533
+ * @stability unstable
534
+ * @category models
535
+ * @since 0.4.0
536
+ */
537
+ export type GuardContent = true | {
538
+ readonly qualifiers: ReadonlyArray<GuardContentQualifier>
539
+ }
540
+
541
+ interface GuardableOptions {
542
+ readonly amazonBedrock?: {
543
+ /**
544
+ * Marks the end of the reusable prefix of the request. The cache point is
545
+ * emitted after the content this is attached to.
546
+ */
547
+ readonly cachePoint?: CachePoint | null
548
+ /**
549
+ * Sends the text as a `guardContent` block, for the guardrail to evaluate.
550
+ * Honoured on user text parts and system messages. On an assistant text
551
+ * part it fails the request with `InvalidUserInputError`.
552
+ */
553
+ readonly guardContent?: GuardContent | null
554
+ } | null
555
+ }
556
+
557
+ declare module "effect/ai/Prompt" {
558
+ /**
559
+ * Amazon Bedrock options for system messages.
560
+ *
561
+ * @stability unstable
562
+ * @category models
563
+ * @since 0.1.0
564
+ */
565
+ export interface SystemMessageOptions extends GuardableOptions {}
566
+
567
+ /**
568
+ * Amazon Bedrock options for text prompt parts.
569
+ *
570
+ * @stability unstable
571
+ * @category models
572
+ * @since 0.1.0
573
+ */
574
+ export interface TextPartOptions extends GuardableOptions {}
575
+ }
576
+
577
+ const textBlock = (
578
+ text: string,
579
+ options: GuardableOptions
580
+ ): { readonly text: string } | { readonly guardContent: typeof GuardrailConverseContentBlock.Encoded } => {
581
+ const guard = options.amazonBedrock?.guardContent
582
+ if (Predicate.isNullish(guard)) {
583
+ return { text }
584
+ }
585
+ return { guardContent: { text: guard === true ? { text } : { text, qualifiers: guard.qualifiers } } }
586
+ }
587
+
588
+ /**
589
+ * What a guardrail did to one side of the exchange.
590
+ *
591
+ * @stability unstable
592
+ * @category models
593
+ * @since 0.4.0
594
+ */
595
+ export type GuardrailAction = "blocked" | "masked" | "none"
596
+
597
+ /**
598
+ * What the guardrails did, read from the trace.
599
+ *
600
+ * **Details**
601
+ *
602
+ * `input` and `output` are the strongest action that any guardrail took on
603
+ * that side, `blocked` over `masked` over `none`, across every guardrail in
604
+ * the trace, enforced guardrails included. `policies` lists the trace keys of
605
+ * the policies that blocked or masked, such as `wordPolicy` or
606
+ * `sensitiveInformationPolicy`, each once, in the order the trace names them.
607
+ *
608
+ * @stability unstable
609
+ * @category models
610
+ * @since 0.4.0
611
+ */
612
+ export type GuardrailOutcome = {
613
+ readonly input: GuardrailAction
614
+ readonly output: GuardrailAction
615
+ // Mutable, because the same type rides on ContentPolicyError, whose
616
+ // metadata must be MutableJson.
617
+ readonly policies: Array<string>
618
+ }
619
+
620
+ /**
621
+ * The Amazon Bedrock metadata on every finish part.
622
+ *
623
+ * **Details**
624
+ *
625
+ * `stopReason` is the raw Converse stop reason. It tells
626
+ * `guardrail_intervened` from `content_filtered`, which both finish with
627
+ * `"content-filter"`, and `max_tokens` from `model_context_window_exceeded`,
628
+ * which both finish with `"length"`. It is `null` only when a stream ended
629
+ * without a `messageStop` event.
630
+ *
631
+ * `guardrail` is `null` when the response carried no guardrail trace, which
632
+ * is the case unless `trace` is enabled in the guardrail config. A trace in
633
+ * which nothing acted gives `{ input: "none", output: "none", policies: [] }`.
634
+ * `trace` is the Converse trace as Bedrock sent it, or `null`. It holds the
635
+ * text that a policy matched, unmasked.
636
+ *
637
+ * @stability unstable
638
+ * @category models
639
+ * @since 0.4.0
640
+ */
641
+ export type FinishMetadata = {
642
+ readonly stopReason: string | null
643
+ readonly guardrail: GuardrailOutcome | null
644
+ readonly trace: Schema.MutableJson | null
645
+ }
646
+
647
+ declare module "effect/ai/AiError" {
648
+ /**
649
+ * Amazon Bedrock metadata on the `ContentPolicyError` that `generateObject`
650
+ * fails with when a guardrail blocked the exchange. It is the metadata of
651
+ * the response's finish part.
652
+ *
653
+ * @stability unstable
654
+ * @category models
655
+ * @since 0.4.0
656
+ */
657
+ export interface ContentPolicyErrorMetadata extends ProviderMetadata {
658
+ readonly amazonBedrock?: FinishMetadata | null
659
+ }
660
+ }
661
+
662
+ declare module "effect/ai/Response" {
663
+ /**
664
+ * Amazon Bedrock metadata on the finish part.
665
+ *
666
+ * @stability unstable
667
+ * @category models
668
+ * @since 0.4.0
669
+ */
670
+ export interface FinishPartMetadata extends ProviderMetadata {
671
+ readonly amazonBedrock?: FinishMetadata | null
672
+ }
673
+ }
674
+
492
675
  // =============================================================================
493
676
  // Configuration
494
677
  // =============================================================================
@@ -498,12 +681,17 @@ const reasoningTextInfo = (signature: string | undefined): ReasoningInfo => ({
498
681
  *
499
682
  * **Details**
500
683
  *
501
- * Derived from `ConverseRequest`, minus the fields built from the prompt, so
502
- * every Converse request parameter is settable per request. That includes
503
- * `additionalModelRequestFields`, which carries inference parameters specific
504
- * to the target model — among them extended thinking on Anthropic models. The
505
- * thinking budget is drawn from the same ceiling as the visible answer, so
506
- * `inferenceConfig.maxTokens` must exceed `budget_tokens`.
684
+ * Derived from `ConverseStreamRequest`, minus the fields built from the
685
+ * prompt, so every Converse request parameter is settable per request. That
686
+ * includes `additionalModelRequestFields`, which carries inference parameters
687
+ * specific to the target model — among them extended thinking on Anthropic
688
+ * models. The thinking budget is drawn from the same ceiling as the visible
689
+ * answer, so `inferenceConfig.maxTokens` must exceed `budget_tokens`.
690
+ *
691
+ * It also includes `guardrailConfig` (see {@link GuardrailConfig}). An
692
+ * override replaces the whole object, and `guardrailConfig: undefined` turns
693
+ * off a layer's guardrail for one request. `generateText` does not send
694
+ * `streamProcessingMode`.
507
695
  *
508
696
  * **Example** (Enabling extended thinking for one request)
509
697
  *
@@ -532,7 +720,7 @@ export class Config extends Context.Service<
532
720
  Simplify<
533
721
  & Partial<
534
722
  Omit<
535
- typeof ConverseRequest.Encoded,
723
+ typeof ConverseStreamRequest.Encoded,
536
724
  "messages" | "system" | "outputConfig"
537
725
  >
538
726
  >
@@ -635,7 +823,7 @@ export const make = Effect.fnUntraced(function*({ config: providerConfig, model
635
823
  function*(
636
824
  options: LanguageModel.ProviderOptions
637
825
  ): Effect.fn.Return<{
638
- readonly request: typeof ConverseRequest.Encoded
826
+ readonly request: typeof ConverseStreamRequest.Encoded
639
827
  readonly nameMapper: Tool.NameMapper<ReadonlyArray<Tool.Any>>
640
828
  readonly documents: ReadonlyArray<CitedDocument>
641
829
  }, AiError.AiError> {
@@ -708,7 +896,7 @@ export const make = Effect.fnUntraced(function*({ config: providerConfig, model
708
896
  }
709
897
  }
710
898
 
711
- const request: typeof ConverseRequest.Encoded = {
899
+ const request: typeof ConverseStreamRequest.Encoded = {
712
900
  ...config,
713
901
  modelId,
714
902
  system,
@@ -736,7 +924,8 @@ export const make = Effect.fnUntraced(function*({ config: providerConfig, model
736
924
  return yield* LanguageModel.make({
737
925
  codecTransformer: toCodecAnthropic,
738
926
  generateText: Effect.fnUntraced(function*(options) {
739
- const { documents, nameMapper, request } = yield* makeRequest(options)
927
+ const { documents, nameMapper, request: streamRequest } = yield* makeRequest(options)
928
+ const request = toConverseRequest(streamRequest)
740
929
  const rawResponse = yield* client.converse({ payload: request })
741
930
  return yield* makeResponse(request, rawResponse, options, nameMapper, documents)
742
931
  }),
@@ -748,6 +937,17 @@ export const make = Effect.fnUntraced(function*({ config: providerConfig, model
748
937
  })
749
938
  })
750
939
 
940
+ const toConverseRequest = (
941
+ request: typeof ConverseStreamRequest.Encoded
942
+ ): typeof ConverseRequest.Encoded => {
943
+ const { guardrailConfig, ...rest } = request
944
+ if (Predicate.isUndefined(guardrailConfig)) {
945
+ return rest
946
+ }
947
+ const { streamProcessingMode: _, ...converseGuardrail } = guardrailConfig
948
+ return { ...rest, guardrailConfig: converseGuardrail }
949
+ }
950
+
751
951
  /**
752
952
  * Creates a layer for the Amazon Bedrock language model.
753
953
  *
@@ -902,6 +1102,45 @@ const documentName = (fileName: string | undefined, position: number): string =>
902
1102
  return `document ${position}`
903
1103
  }
904
1104
 
1105
+ const guardedImageFormats: Record<string, typeof GuardrailConverseImageBlock.Encoded["format"]> = {
1106
+ "image/jpeg": "jpeg",
1107
+ "image/png": "png"
1108
+ }
1109
+
1110
+ const guardedImage: (
1111
+ part: Prompt.FilePart
1112
+ ) => Effect.Effect<typeof GuardrailConverseImageBlock.Encoded, AiError.AiError> = Effect.fnUntraced(
1113
+ function*(part) {
1114
+ const format = guardedImageFormats[part.mediaType]
1115
+ if (Predicate.isUndefined(format)) {
1116
+ const reason = part.mediaType === "image/*"
1117
+ ? "its format is unknown, and a guarded image must be image/png or image/jpeg"
1118
+ : part.mediaType.startsWith("image/")
1119
+ ? "a guarded image must be image/png or image/jpeg"
1120
+ : "only text parts and png or jpeg images can be guarded"
1121
+ return yield* AiError.make({
1122
+ module: "AmazonBedrockLanguageModel",
1123
+ method: "prepareMessages",
1124
+ reason: new AiError.InvalidUserInputError({
1125
+ description: `Unsupported guardContent on a file part of media type '${part.mediaType}' - ${reason}`
1126
+ })
1127
+ })
1128
+ }
1129
+ const source = yield* fileSource(part.data)
1130
+ if (Predicate.isUndefined(source.bytes)) {
1131
+ return yield* AiError.make({
1132
+ module: "AmazonBedrockLanguageModel",
1133
+ method: "prepareMessages",
1134
+ reason: new AiError.InvalidUserInputError({
1135
+ description: `Unsupported guardContent on an image at '${source.s3Location?.uri}' - a guarded image ` +
1136
+ "must be sent as bytes or base64, not as an s3:// location"
1137
+ })
1138
+ })
1139
+ }
1140
+ return { format, source: { bytes: source.bytes } }
1141
+ }
1142
+ )
1143
+
905
1144
  const prepareMessages: (options: LanguageModel.ProviderOptions) => Effect.Effect<{
906
1145
  readonly system: ReadonlyArray<typeof SystemContentBlock.Encoded>
907
1146
  readonly messages: ReadonlyArray<typeof Message.Encoded>
@@ -933,7 +1172,7 @@ const prepareMessages: (options: LanguageModel.ProviderOptions) => Effect.Effect
933
1172
  })
934
1173
  }
935
1174
  for (const message of group.messages) {
936
- system.push({ text: message.content })
1175
+ system.push(textBlock(message.content, message.options))
937
1176
  const cachePoint = getCachePoint(message)
938
1177
  if (Predicate.isNotNull(cachePoint)) {
939
1178
  system.push({ cachePoint })
@@ -950,9 +1189,14 @@ const prepareMessages: (options: LanguageModel.ProviderOptions) => Effect.Effect
950
1189
  case "user": {
951
1190
  for (const part of message.content) {
952
1191
  if (part.type === "text") {
953
- content.push({ text: part.text })
1192
+ content.push(textBlock(part.text, part.options))
954
1193
  pushCachePoint(content, part)
955
1194
  } else if (part.type === "file") {
1195
+ if (part.options.amazonBedrock?.guardContent === true) {
1196
+ content.push({ guardContent: { image: yield* guardedImage(part) } })
1197
+ pushCachePoint(content, part)
1198
+ continue
1199
+ }
956
1200
  const imageFormat = imageFormats[part.mediaType]
957
1201
  if (Predicate.isNotUndefined(imageFormat)) {
958
1202
  content.push({ image: { format: imageFormat, source: yield* fileSource(part.data) } })
@@ -1048,6 +1292,16 @@ const prepareMessages: (options: LanguageModel.ProviderOptions) => Effect.Effect
1048
1292
  const isLastPart = k === message.content.length - 1
1049
1293
 
1050
1294
  if (part.type === "text") {
1295
+ if (!Predicate.isNullish(part.options.amazonBedrock?.guardContent)) {
1296
+ return yield* AiError.make({
1297
+ module: "AmazonBedrockLanguageModel",
1298
+ method: "prepareMessages",
1299
+ reason: new AiError.InvalidUserInputError({
1300
+ description: "Unsupported guardContent on an assistant text part - this provider guards only " +
1301
+ "user text parts, user png and jpeg images, and system messages"
1302
+ })
1303
+ })
1304
+ }
1051
1305
  // Skip empty text blocks
1052
1306
  if (part.text.trim().length === 0) {
1053
1307
  continue
@@ -1326,7 +1580,7 @@ const makeResponse: (
1326
1580
  documents: ReadonlyArray<CitedDocument>
1327
1581
  ) => Effect.Effect<
1328
1582
  Array<Response.PartEncoded>,
1329
- never,
1583
+ AiError.AiError,
1330
1584
  IdGenerator.IdGenerator
1331
1585
  > = Effect.fnUntraced(function*(request, response, options, nameMapper, documents) {
1332
1586
  const idGenerator = yield* IdGenerator.IdGenerator
@@ -1434,6 +1688,22 @@ const makeResponse: (
1434
1688
  : InternalUtilities.resolveFinishReason(response.stopReason)
1435
1689
  const cacheReadTokens = response.usage.cacheReadInputTokens ?? 0
1436
1690
  const cacheWriteTokens = response.usage.cacheWriteInputTokens ?? 0
1691
+ const metadata = InternalGuardrails.finishMetadata(response.stopReason, response.trace)
1692
+
1693
+ if (options.responseFormat.type === "json") {
1694
+ const text = parts.flatMap((part) => part.type === "text" ? [part.text] : []).join("")
1695
+ if (InternalGuardrails.blocksObject(response.stopReason, text)) {
1696
+ return yield* AiError.make({
1697
+ module: "AmazonBedrockLanguageModel",
1698
+ method: "generateObject",
1699
+ reason: new AiError.ContentPolicyError({
1700
+ description: "An Amazon Bedrock guardrail intervened, and the response holds no JSON object. " +
1701
+ `Bedrock answered: ${truncate(text, 200)}`,
1702
+ metadata: { amazonBedrock: metadata }
1703
+ })
1704
+ })
1705
+ }
1706
+ }
1437
1707
 
1438
1708
  parts.push({
1439
1709
  type: "finish",
@@ -1453,14 +1723,15 @@ const makeResponse: (
1453
1723
  },
1454
1724
  // `Response.FinishPart` models `response` with `Schema.UndefinedOr`, which
1455
1725
  // requires the key; HTTP response details are not surfaced by the client.
1456
- response: undefined
1726
+ response: undefined,
1727
+ metadata: { amazonBedrock: metadata }
1457
1728
  })
1458
1729
 
1459
1730
  return parts
1460
1731
  })
1461
1732
 
1462
1733
  const makeStreamResponse: (
1463
- request: typeof ConverseRequest.Encoded,
1734
+ request: typeof ConverseStreamRequest.Encoded,
1464
1735
  stream: Stream.Stream<ConverseResponseStreamEvent, AiError.AiError>,
1465
1736
  nameMapper: Tool.NameMapper<ReadonlyArray<Tool.Any>>,
1466
1737
  documents: ReadonlyArray<CitedDocument>
@@ -1503,6 +1774,7 @@ const makeStreamResponse: (
1503
1774
  // (which AWS sends AFTER messageStop and which carries the usage), so finish
1504
1775
  // reports the real token counts rather than the pre-metadata zeros.
1505
1776
  let finishReason: Response.FinishReason = "unknown"
1777
+ let stopReason: string | null = null
1506
1778
 
1507
1779
  return stream.pipe(
1508
1780
  Stream.mapEffect(Effect.fnUntraced(function*(event) {
@@ -1682,6 +1954,7 @@ const makeStreamResponse: (
1682
1954
  // Defer the `finish` part to the trailing `metadata` event (usage
1683
1955
  // is still zero here — metadata has not arrived yet).
1684
1956
  finishReason = InternalUtilities.resolveFinishReason(event.messageStop.stopReason)
1957
+ stopReason = event.messageStop.stopReason
1685
1958
  break
1686
1959
  }
1687
1960
 
@@ -1710,7 +1983,8 @@ const makeStreamResponse: (
1710
1983
  }
1711
1984
  },
1712
1985
  // See `makeResponse`: the key is required (`Schema.UndefinedOr`).
1713
- response: undefined
1986
+ response: undefined,
1987
+ metadata: { amazonBedrock: InternalGuardrails.finishMetadata(stopReason, event.metadata.trace) }
1714
1988
  })
1715
1989
  break
1716
1990
  }