@composurecdk/bedrock 0.10.1 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +110 -17
  2. package/dist/commonjs/alarm-definition.d.ts +29 -0
  3. package/dist/commonjs/alarm-definition.d.ts.map +1 -0
  4. package/dist/commonjs/alarm-definition.js +53 -0
  5. package/dist/commonjs/alarm-definition.js.map +1 -0
  6. package/dist/commonjs/application-inference-profile-builder.d.ts +44 -0
  7. package/dist/commonjs/application-inference-profile-builder.d.ts.map +1 -0
  8. package/dist/commonjs/application-inference-profile-builder.js +51 -0
  9. package/dist/commonjs/application-inference-profile-builder.js.map +1 -0
  10. package/dist/commonjs/grants.d.ts +25 -1
  11. package/dist/commonjs/grants.d.ts.map +1 -1
  12. package/dist/commonjs/grants.js +57 -6
  13. package/dist/commonjs/grants.js.map +1 -1
  14. package/dist/commonjs/guardrail-alarms.d.ts +40 -0
  15. package/dist/commonjs/guardrail-alarms.d.ts.map +1 -0
  16. package/dist/commonjs/guardrail-alarms.js +41 -0
  17. package/dist/commonjs/guardrail-alarms.js.map +1 -0
  18. package/dist/commonjs/guardrail-builder.d.ts +70 -0
  19. package/dist/commonjs/guardrail-builder.d.ts.map +1 -0
  20. package/dist/commonjs/guardrail-builder.js +78 -0
  21. package/dist/commonjs/guardrail-builder.js.map +1 -0
  22. package/dist/commonjs/guardrail-defaults.d.ts +25 -0
  23. package/dist/commonjs/guardrail-defaults.d.ts.map +1 -0
  24. package/dist/commonjs/guardrail-defaults.js +30 -0
  25. package/dist/commonjs/guardrail-defaults.js.map +1 -0
  26. package/dist/commonjs/index.d.ts +8 -2
  27. package/dist/commonjs/index.d.ts.map +1 -1
  28. package/dist/commonjs/index.js +15 -1
  29. package/dist/commonjs/index.js.map +1 -1
  30. package/dist/commonjs/inference-profile.d.ts +19 -0
  31. package/dist/commonjs/inference-profile.d.ts.map +1 -1
  32. package/dist/commonjs/inference-profile.js.map +1 -1
  33. package/dist/commonjs/inference-target.d.ts +14 -7
  34. package/dist/commonjs/inference-target.d.ts.map +1 -1
  35. package/dist/commonjs/inference-target.js +63 -35
  36. package/dist/commonjs/inference-target.js.map +1 -1
  37. package/dist/commonjs/model-alarm-defaults.d.ts.map +1 -1
  38. package/dist/commonjs/model-alarm-defaults.js +5 -14
  39. package/dist/commonjs/model-alarm-defaults.js.map +1 -1
  40. package/dist/commonjs/model-alarms.d.ts +2 -2
  41. package/dist/commonjs/model-alarms.d.ts.map +1 -1
  42. package/dist/commonjs/model-alarms.js +35 -58
  43. package/dist/commonjs/model-alarms.js.map +1 -1
  44. package/dist/commonjs/model-invocation-logging-alarms.d.ts +42 -0
  45. package/dist/commonjs/model-invocation-logging-alarms.d.ts.map +1 -0
  46. package/dist/commonjs/model-invocation-logging-alarms.js +59 -0
  47. package/dist/commonjs/model-invocation-logging-alarms.js.map +1 -0
  48. package/dist/commonjs/model-invocation-logging-builder.d.ts +84 -0
  49. package/dist/commonjs/model-invocation-logging-builder.d.ts.map +1 -0
  50. package/dist/commonjs/model-invocation-logging-builder.js +135 -0
  51. package/dist/commonjs/model-invocation-logging-builder.js.map +1 -0
  52. package/dist/esm/alarm-definition.d.ts +29 -0
  53. package/dist/esm/alarm-definition.d.ts.map +1 -0
  54. package/dist/esm/alarm-definition.js +48 -0
  55. package/dist/esm/alarm-definition.js.map +1 -0
  56. package/dist/esm/application-inference-profile-builder.d.ts +44 -0
  57. package/dist/esm/application-inference-profile-builder.d.ts.map +1 -0
  58. package/dist/esm/application-inference-profile-builder.js +48 -0
  59. package/dist/esm/application-inference-profile-builder.js.map +1 -0
  60. package/dist/esm/grants.d.ts +25 -1
  61. package/dist/esm/grants.d.ts.map +1 -1
  62. package/dist/esm/grants.js +58 -7
  63. package/dist/esm/grants.js.map +1 -1
  64. package/dist/esm/guardrail-alarms.d.ts +40 -0
  65. package/dist/esm/guardrail-alarms.d.ts.map +1 -0
  66. package/dist/esm/guardrail-alarms.js +37 -0
  67. package/dist/esm/guardrail-alarms.js.map +1 -0
  68. package/dist/esm/guardrail-builder.d.ts +70 -0
  69. package/dist/esm/guardrail-builder.d.ts.map +1 -0
  70. package/dist/esm/guardrail-builder.js +75 -0
  71. package/dist/esm/guardrail-builder.js.map +1 -0
  72. package/dist/esm/guardrail-defaults.d.ts +25 -0
  73. package/dist/esm/guardrail-defaults.d.ts.map +1 -0
  74. package/dist/esm/guardrail-defaults.js +27 -0
  75. package/dist/esm/guardrail-defaults.js.map +1 -0
  76. package/dist/esm/index.d.ts +8 -2
  77. package/dist/esm/index.d.ts.map +1 -1
  78. package/dist/esm/index.js +7 -1
  79. package/dist/esm/index.js.map +1 -1
  80. package/dist/esm/inference-profile.d.ts +19 -0
  81. package/dist/esm/inference-profile.d.ts.map +1 -1
  82. package/dist/esm/inference-profile.js.map +1 -1
  83. package/dist/esm/inference-target.d.ts +14 -7
  84. package/dist/esm/inference-target.d.ts.map +1 -1
  85. package/dist/esm/inference-target.js +62 -35
  86. package/dist/esm/inference-target.js.map +1 -1
  87. package/dist/esm/model-alarm-defaults.d.ts.map +1 -1
  88. package/dist/esm/model-alarm-defaults.js +1 -10
  89. package/dist/esm/model-alarm-defaults.js.map +1 -1
  90. package/dist/esm/model-alarms.d.ts +2 -2
  91. package/dist/esm/model-alarms.d.ts.map +1 -1
  92. package/dist/esm/model-alarms.js +35 -58
  93. package/dist/esm/model-alarms.js.map +1 -1
  94. package/dist/esm/model-invocation-logging-alarms.d.ts +42 -0
  95. package/dist/esm/model-invocation-logging-alarms.d.ts.map +1 -0
  96. package/dist/esm/model-invocation-logging-alarms.js +55 -0
  97. package/dist/esm/model-invocation-logging-alarms.js.map +1 -0
  98. package/dist/esm/model-invocation-logging-builder.d.ts +84 -0
  99. package/dist/esm/model-invocation-logging-builder.d.ts.map +1 -0
  100. package/dist/esm/model-invocation-logging-builder.js +131 -0
  101. package/dist/esm/model-invocation-logging-builder.js.map +1 -0
  102. package/package.json +5 -11
@@ -0,0 +1,44 @@
1
+ import { CfnApplicationInferenceProfile, type CfnApplicationInferenceProfileProps } from "aws-cdk-lib/aws-bedrock";
2
+ import type { IConstruct } from "constructs";
3
+ import { type Lifecycle, type Resolvable } from "@composurecdk/core";
4
+ import { type ITaggedBuilder } from "@composurecdk/cloudformation";
5
+ import type { ApplicationInferenceProfile } from "./inference-profile.js";
6
+ /** Configuration properties for {@link createApplicationInferenceProfileBuilder}. */
7
+ export interface ApplicationInferenceProfileBuilderProps extends Omit<CfnApplicationInferenceProfileProps, "modelSource" | "tags"> {
8
+ /** The foundation model or system-defined profile to route to. Required. */
9
+ source: Resolvable<ApplicationInferenceProfile["source"]>;
10
+ }
11
+ /** The build output of an {@link IApplicationInferenceProfileBuilder}. */
12
+ export interface ApplicationInferenceProfileBuilderResult {
13
+ applicationInferenceProfile: CfnApplicationInferenceProfile;
14
+ /** The profile as an invocation target, for grants and callers. */
15
+ profile: ApplicationInferenceProfile;
16
+ }
17
+ /**
18
+ * A fluent builder for an Amazon Bedrock application inference profile.
19
+ *
20
+ * @see {@link createApplicationInferenceProfileBuilder}
21
+ */
22
+ export type IApplicationInferenceProfileBuilder = ITaggedBuilder<ApplicationInferenceProfileBuilderProps, ApplicationInferenceProfileBuilder>;
23
+ declare class ApplicationInferenceProfileBuilder implements Lifecycle<ApplicationInferenceProfileBuilderResult> {
24
+ props: Partial<ApplicationInferenceProfileBuilderProps>;
25
+ build(scope: IConstruct, id: string, context?: Record<string, object>): ApplicationInferenceProfileBuilderResult;
26
+ }
27
+ /**
28
+ * Creates a builder for an {@link ApplicationInferenceProfile}, which carries
29
+ * the builder's tags. Pass the result's `profile` to `modelGrants.invoke`, and
30
+ * its `profileArn` to callers as the model id.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * createApplicationInferenceProfileBuilder()
35
+ * .inferenceProfileName("support-assistant")
36
+ * .source(haiku)
37
+ * .tag("CostCentre", "support");
38
+ * ```
39
+ *
40
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-create.html
41
+ */
42
+ export declare function createApplicationInferenceProfileBuilder(): IApplicationInferenceProfileBuilder;
43
+ export {};
44
+ //# sourceMappingURL=application-inference-profile-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-inference-profile-builder.d.ts","sourceRoot":"","sources":["../../src/application-inference-profile-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,KAAK,mCAAmC,EACzC,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,KAAK,SAAS,EAAW,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,8BAA8B,CAAC;AAClF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAG1E,qFAAqF;AACrF,MAAM,WAAW,uCAAwC,SAAQ,IAAI,CACnE,mCAAmC,EACnC,aAAa,GAAG,MAAM,CACvB;IACC,4EAA4E;IAC5E,MAAM,EAAE,UAAU,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC,CAAC;CAC3D;AAED,0EAA0E;AAC1E,MAAM,WAAW,wCAAwC;IACvD,2BAA2B,EAAE,8BAA8B,CAAC;IAC5D,mEAAmE;IACnE,OAAO,EAAE,2BAA2B,CAAC;CACtC;AAED;;;;GAIG;AACH,MAAM,MAAM,mCAAmC,GAAG,cAAc,CAC9D,uCAAuC,EACvC,kCAAkC,CACnC,CAAC;AAEF,cAAM,kCAAmC,YAAW,SAAS,CAAC,wCAAwC,CAAC;IACrG,KAAK,EAAE,OAAO,CAAC,uCAAuC,CAAC,CAAM;IAE7D,KAAK,CACH,KAAK,EAAE,UAAU,EACjB,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,wCAAwC;CAwB5C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wCAAwC,IAAI,mCAAmC,CAI9F"}
@@ -0,0 +1,48 @@
1
+ import { CfnApplicationInferenceProfile, } from "aws-cdk-lib/aws-bedrock";
2
+ import { resolve } from "@composurecdk/core";
3
+ import { taggedBuilder } from "@composurecdk/cloudformation";
4
+ import { sourceArn } from "./inference-target.js";
5
+ class ApplicationInferenceProfileBuilder {
6
+ props = {};
7
+ build(scope, id, context = {}) {
8
+ const { source: sourceRef, inferenceProfileName, ...rest } = this.props;
9
+ if (!inferenceProfileName || sourceRef === undefined) {
10
+ throw new Error(`ApplicationInferenceProfileBuilder "${id}" requires an inferenceProfileName and a ` +
11
+ `source. Call .inferenceProfileName() and .source().`);
12
+ }
13
+ const source = resolve(sourceRef, context);
14
+ const applicationInferenceProfile = new CfnApplicationInferenceProfile(scope, id, {
15
+ ...rest,
16
+ inferenceProfileName,
17
+ modelSource: { copyFrom: sourceArn(source, scope) },
18
+ });
19
+ return {
20
+ applicationInferenceProfile,
21
+ profile: {
22
+ kind: "application",
23
+ profileArn: applicationInferenceProfile.attrInferenceProfileArn,
24
+ profileId: applicationInferenceProfile.attrInferenceProfileId,
25
+ source,
26
+ },
27
+ };
28
+ }
29
+ }
30
+ /**
31
+ * Creates a builder for an {@link ApplicationInferenceProfile}, which carries
32
+ * the builder's tags. Pass the result's `profile` to `modelGrants.invoke`, and
33
+ * its `profileArn` to callers as the model id.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * createApplicationInferenceProfileBuilder()
38
+ * .inferenceProfileName("support-assistant")
39
+ * .source(haiku)
40
+ * .tag("CostCentre", "support");
41
+ * ```
42
+ *
43
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-create.html
44
+ */
45
+ export function createApplicationInferenceProfileBuilder() {
46
+ return taggedBuilder(ApplicationInferenceProfileBuilder);
47
+ }
48
+ //# sourceMappingURL=application-inference-profile-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-inference-profile-builder.js","sourceRoot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rantable } from "aws-cdk-lib/aws-iam";
2
2
  import { type Grant, type Resolvable } from "@composurecdk/core";
3
+ import type { GuardrailReference } from "./guardrail-builder.js";
3
4
  import { type InferenceTarget } from "./inference-target.js";
5
+ /** Options for {@link modelGrants.invoke}. */
6
+ export interface ModelInvokeGrantOptions {
7
+ /**
8
+ * Requires every invocation to apply this guardrail version. The allow is
9
+ * conditioned on `bedrock:GuardrailIdentifier`, an explicit deny refuses
10
+ * calls without it, and the grantee may apply the guardrail.
11
+ *
12
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-permissions-id.html
13
+ */
14
+ requireGuardrail?: Resolvable<GuardrailReference>;
15
+ }
4
16
  /**
5
17
  * Consumer-side grant helpers for invoking Amazon Bedrock models. Pass one to
6
18
  * a grantee builder's `grant(...)` — e.g.
@@ -22,6 +34,18 @@ export declare const modelGrants: {
22
34
  *
23
35
  * @see https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp01.html
24
36
  */
25
- invoke: (target: Resolvable<InferenceTarget>) => Grant<IGrantable>;
37
+ invoke: (target: Resolvable<InferenceTarget>, { requireGuardrail }?: ModelInvokeGrantOptions) => Grant<IGrantable>;
38
+ };
39
+ /**
40
+ * Consumer-side grant helpers for Amazon Bedrock guardrails.
41
+ *
42
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-permissions-id.html
43
+ */
44
+ export declare const guardrailGrants: {
45
+ /**
46
+ * Apply the guardrail (`bedrock:ApplyGuardrail`), through the
47
+ * `ApplyGuardrail` API or a model invocation that names it.
48
+ */
49
+ apply: (guardrail: Resolvable<GuardrailReference>) => Grant<IGrantable>;
26
50
  };
27
51
  //# sourceMappingURL=grants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../../src/grants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,KAAK,KAAK,EAAY,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,KAAK,eAAe,EAAiC,MAAM,uBAAuB,CAAC;AAU5F;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;;;;;OAUG;qBACc,UAAU,CAAC,eAAe,CAAC,KAAG,KAAK,CAAC,UAAU,CAAC;CAOjE,CAAC"}
1
+ {"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../../src/grants.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,UAAU,EAAmB,MAAM,qBAAqB,CAAC;AAClG,OAAO,EAAW,KAAK,KAAK,EAAY,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,KAAK,eAAe,EAAiC,MAAM,uBAAuB,CAAC;AAU5F,8CAA8C;AAC9C,MAAM,WAAW,uBAAuB;IACtC;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC;CACnD;AAmDD;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;;;;;OAUG;qBAEO,UAAU,CAAC,eAAe,CAAC,yBACb,uBAAuB,KAC5C,KAAK,CAAC,UAAU,CAAC;CAOrB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe;IAC1B;;;OAGG;uBACgB,UAAU,CAAC,kBAAkB,CAAC,KAAG,KAAK,CAAC,UAAU,CAAC;CAItE,CAAC"}
@@ -1,5 +1,5 @@
1
- import { Grant as IamGrant } from "aws-cdk-lib/aws-iam";
2
- import { grantVia } from "@composurecdk/core";
1
+ import { Effect, Grant as IamGrant, PolicyStatement } from "aws-cdk-lib/aws-iam";
2
+ import { combine, grantVia } from "@composurecdk/core";
3
3
  import { invocationStatements, scopeOf } from "./inference-target.js";
4
4
  /**
5
5
  * Streaming operations (`InvokeModelWithResponseStream`, `ConverseStream`)
@@ -8,6 +8,46 @@ import { invocationStatements, scopeOf } from "./inference-target.js";
8
8
  * @see https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrock.html
9
9
  */
10
10
  const INVOKE_ACTIONS = ["bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream"];
11
+ /** The versioned identifier `bedrock:GuardrailIdentifier` carries. */
12
+ function identifierOf(guardrail) {
13
+ return `${guardrail.guardrailArn}:${guardrail.version}`;
14
+ }
15
+ function grantInvoke(target, grantee, guardrail) {
16
+ const statements = invocationStatements(target, scopeOf(grantee.grantPrincipal));
17
+ const identifier = guardrail && identifierOf(guardrail);
18
+ for (const { resourceArns, conditions } of statements) {
19
+ IamGrant.addToPrincipal({
20
+ grantee,
21
+ actions: INVOKE_ACTIONS,
22
+ resourceArns,
23
+ conditions: identifier
24
+ ? {
25
+ ...conditions,
26
+ StringEquals: {
27
+ ...conditions?.StringEquals,
28
+ "bedrock:GuardrailIdentifier": identifier,
29
+ },
30
+ }
31
+ : conditions,
32
+ });
33
+ }
34
+ if (!guardrail)
35
+ return;
36
+ grantee.grantPrincipal.addToPrincipalPolicy(new PolicyStatement({
37
+ effect: Effect.DENY,
38
+ actions: INVOKE_ACTIONS,
39
+ resources: statements.flatMap((s) => s.resourceArns),
40
+ conditions: { StringNotEquals: { "bedrock:GuardrailIdentifier": identifierOf(guardrail) } },
41
+ }));
42
+ grantApply(guardrail, grantee);
43
+ }
44
+ function grantApply(guardrail, grantee) {
45
+ IamGrant.addToPrincipal({
46
+ grantee,
47
+ actions: ["bedrock:ApplyGuardrail"],
48
+ resourceArns: [guardrail.guardrailArn],
49
+ });
50
+ }
11
51
  /**
12
52
  * Consumer-side grant helpers for invoking Amazon Bedrock models. Pass one to
13
53
  * a grantee builder's `grant(...)` — e.g.
@@ -29,11 +69,22 @@ export const modelGrants = {
29
69
  *
30
70
  * @see https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec01-bp01.html
31
71
  */
32
- invoke: (target) => grantVia(target, (resolved, grantee) => {
33
- const statements = invocationStatements(resolved, scopeOf(grantee.grantPrincipal));
34
- for (const { resourceArns, conditions } of statements) {
35
- IamGrant.addToPrincipal({ grantee, actions: INVOKE_ACTIONS, resourceArns, conditions });
36
- }
72
+ invoke: (target, { requireGuardrail } = {}) => grantVia(combine({ target, guardrail: requireGuardrail }), ({ target: resolved, guardrail }, grantee) => {
73
+ grantInvoke(resolved, grantee, guardrail);
74
+ }),
75
+ };
76
+ /**
77
+ * Consumer-side grant helpers for Amazon Bedrock guardrails.
78
+ *
79
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-permissions-id.html
80
+ */
81
+ export const guardrailGrants = {
82
+ /**
83
+ * Apply the guardrail (`bedrock:ApplyGuardrail`), through the
84
+ * `ApplyGuardrail` API or a model invocation that names it.
85
+ */
86
+ apply: (guardrail) => grantVia(guardrail, (resolved, grantee) => {
87
+ grantApply(resolved, grantee);
37
88
  }),
38
89
  };
39
90
  //# sourceMappingURL=grants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"grants.js","sourceRoot":"","sources":["../../src/grants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAmB,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAc,QAAQ,EAAmB,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAwB,oBAAoB,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAE5F;;;;;GAKG;AACH,MAAM,cAAc,GAAG,CAAC,qBAAqB,EAAE,uCAAuC,CAAC,CAAC;AAExF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB;;;;;;;;;;OAUG;IACH,MAAM,EAAE,CAAC,MAAmC,EAAqB,EAAE,CACjE,QAAQ,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,OAAmB,EAAE,EAAE;QACjD,MAAM,UAAU,GAAG,oBAAoB,CAAC,QAAQ,EAAE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AK,EAAE,CAAC,SAAyC,EAAqB,EAAE,CACtE,QAAQ,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,OAAmB,EAAE,EAAE;QACpD,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC,CAAC;CACL,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { Metric, type MetricOptions } from "aws-cdk-lib/aws-cloudwatch";
2
+ import type { AlarmConfig, AlarmDefinition } from "@composurecdk/cloudwatch";
3
+ import type { GuardrailReference } from "./guardrail-builder.js";
4
+ /** `AWS/Bedrock/Guardrails` metrics for one guardrail version. */
5
+ export interface GuardrailMetrics {
6
+ /** A metric dimensioned by the guardrail's ARN and version. */
7
+ metric(metricName: string, options?: MetricOptions): Metric;
8
+ }
9
+ /** Returns the `AWS/Bedrock/Guardrails` metrics for `guardrail`. */
10
+ export declare function guardrailMetrics(guardrail: GuardrailReference): GuardrailMetrics;
11
+ /**
12
+ * Controls the recommended alarms for a guardrail. Both are opt-in and need a
13
+ * threshold: what counts as normal depends on the workload.
14
+ *
15
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/monitoring-guardrails-cw-metrics.html
16
+ */
17
+ export interface GuardrailAlarmConfig {
18
+ /**
19
+ * Master switch: set to `false` to disable all recommended alarms.
20
+ * @default true
21
+ */
22
+ enabled?: boolean;
23
+ /**
24
+ * Alarm when the guardrail intervenes more often than the threshold, e.g.
25
+ * a spike in prompt attacks or a filter set too strictly.
26
+ *
27
+ * Metric: `InvocationsIntervened`, statistic Sum. Opt-in; threshold required.
28
+ */
29
+ invocationsIntervened?: AlarmConfig | false;
30
+ /**
31
+ * Alarm when evaluating the guardrail takes longer than the threshold, in
32
+ * milliseconds.
33
+ *
34
+ * Metric: `InvocationLatency`, statistic p90. Opt-in; threshold required.
35
+ */
36
+ invocationLatency?: AlarmConfig | false;
37
+ }
38
+ /** Resolves the recommended guardrail alarms. */
39
+ export declare function resolveGuardrailAlarmDefinitions(metrics: GuardrailMetrics, config: GuardrailAlarmConfig | false | undefined): AlarmDefinition[];
40
+ //# sourceMappingURL=guardrail-alarms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrail-alarms.d.ts","sourceRoot":"","sources":["../../src/guardrail-alarms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE7E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,kEAAkE;AAClE,MAAM,WAAW,gBAAgB;IAC/B,+DAA+D;IAC/D,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;CAC7D;AAED,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,kBAAkB,GAAG,gBAAgB,CAchF;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAE5C;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;CACzC;AAkBD,iDAAiD;AACjD,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,oBAAoB,GAAG,KAAK,GAAG,SAAS,GAC/C,eAAe,EAAE,CAKnB"}
@@ -0,0 +1,37 @@
1
+ import { Duration } from "aws-cdk-lib";
2
+ import { Metric } from "aws-cdk-lib/aws-cloudwatch";
3
+ import { resolveThresholdAlarms } from "./alarm-definition.js";
4
+ /** Returns the `AWS/Bedrock/Guardrails` metrics for `guardrail`. */
5
+ export function guardrailMetrics(guardrail) {
6
+ return {
7
+ metric: (metricName, options) => new Metric({
8
+ namespace: "AWS/Bedrock/Guardrails",
9
+ metricName,
10
+ dimensionsMap: {
11
+ GuardrailArn: guardrail.guardrailArn,
12
+ GuardrailVersion: guardrail.version,
13
+ },
14
+ period: Duration.minutes(1),
15
+ ...options,
16
+ }),
17
+ };
18
+ }
19
+ const GUARDRAIL_ALARMS = {
20
+ invocationsIntervened: {
21
+ metricName: "InvocationsIntervened",
22
+ statistic: "Sum",
23
+ describe: (t) => `The guardrail is intervening more than ${String(t)} times a minute.`,
24
+ },
25
+ invocationLatency: {
26
+ metricName: "InvocationLatency",
27
+ statistic: "p90",
28
+ describe: (t) => `p90 guardrail evaluation latency exceeds ${String(t)} ms.`,
29
+ },
30
+ };
31
+ /** Resolves the recommended guardrail alarms. */
32
+ export function resolveGuardrailAlarmDefinitions(metrics, config) {
33
+ if (config === false || config?.enabled === false)
34
+ return [];
35
+ return resolveThresholdAlarms(GUARDRAIL_ALARMS, config, (metricName, statistic) => metrics.metric(metricName, { statistic }));
36
+ }
37
+ //# sourceMappingURL=guardrail-alarms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrail-alarms.js","sourceRoot":"","sources":["../../src/guardrail-alarms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,MAAM,EAAsB,MAAM,4BAA4B,CAAC;AAExE,OAAO,EAAE,sBAAsB,EAA2B,MAAM,uBAAuB,CAAC;AASxF,oEAAoE;AACpE,MAAM,UAAU,gBAAgB,CAAC,SAA6B;IAC5D,OAAO;QACL,MAAM,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,CAC9B,IAAI,MAAM,CAAC;YACT,SAAS,EAAE,wBAAwB;YACnC,UAAU;YACV,aAAa,EAAE;gBACb,YAAY,EAAE,SAAS,CAAC,YAAY;gBACpC,gBAAgB,EAAE,SAAS,CAAC,OAAO;aACpC;YACD,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;YAC3B,GAAG,OAAO;SACX,CAAC;KACL,CAAC;AACJ,CAAC;AAgCD,MAAM,gBAAgB,GAGlB;IACF,qBAAqB,EAAE;QACrB,UAAU,EAAE,uBAAuB;QACnC,SAAS,EAAE,KAAK;QAChB,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,0CAA0C,MAAM,CAAC,CAAC,CAAC,kBAAkB;KACvF;IACD,iBAAiB,EAAE;QACjB,UAAU,EAAE,mBAAmB;QAC/B,SAAS,EAAE,KAAK;QAChB,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,4CAA4C,MAAM,CAAC,CAAC,CAAC,MAAM;KAC7E;CACF,CAAC;AAEF,iDAAiD;AACjD,MAAM,UAAU,gCAAgC,CAC9C,OAAyB,EACzB,MAAgD;IAEhD,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,EAAE,OAAO,KAAK,KAAK;QAAE,OAAO,EAAE,CAAC;IAC7D,OAAO,sBAAsB,CAAC,gBAAgB,EAAE,MAAM,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE,CAChF,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,CAAC,CAC1C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { CfnGuardrail, type CfnGuardrailProps, CfnGuardrailVersion } from "aws-cdk-lib/aws-bedrock";
2
+ import type { Alarm } from "aws-cdk-lib/aws-cloudwatch";
3
+ import type { IConstruct } from "constructs";
4
+ import { COPY_STATE, type Lifecycle, type Resolvable } from "@composurecdk/core";
5
+ import { type ITaggedBuilder } from "@composurecdk/cloudformation";
6
+ import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
7
+ import { type GuardrailAlarmConfig, type GuardrailMetrics } from "./guardrail-alarms.js";
8
+ /** A guardrail's ARN and published version. */
9
+ export interface GuardrailReference {
10
+ /** The guardrail's ARN, without a version. */
11
+ readonly guardrailArn: string;
12
+ /** The published version, e.g. `"1"`. */
13
+ readonly version: string;
14
+ }
15
+ /** Configuration properties for {@link createGuardrailBuilder}. */
16
+ export interface GuardrailBuilderProps extends Omit<CfnGuardrailProps, "tags" | "kmsKeyArn"> {
17
+ /** A customer managed key to encrypt the guardrail with. */
18
+ kmsKeyArn?: Resolvable<NonNullable<CfnGuardrailProps["kmsKeyArn"]>>;
19
+ /**
20
+ * Configuration for the recommended alarms, which are all opt-in. Set to
21
+ * `false` to disable them; alarms added with `addAlarm()` are unaffected.
22
+ */
23
+ recommendedAlarms?: GuardrailAlarmConfig | false;
24
+ }
25
+ /** The build output of an {@link IGuardrailBuilder}. */
26
+ export interface GuardrailBuilderResult {
27
+ guardrail: CfnGuardrail;
28
+ /** The published version callers should use, rather than the working draft. */
29
+ version: CfnGuardrailVersion;
30
+ /** The guardrail's ARN and published version, for grants and invocations. */
31
+ reference: GuardrailReference;
32
+ /** The CloudWatch alarms created, keyed by alarm key. */
33
+ alarms: Record<string, Alarm>;
34
+ }
35
+ /**
36
+ * A fluent builder for an Amazon Bedrock guardrail.
37
+ *
38
+ * @see {@link createGuardrailBuilder}
39
+ */
40
+ export type IGuardrailBuilder = ITaggedBuilder<GuardrailBuilderProps, GuardrailBuilder>;
41
+ declare class GuardrailBuilder implements Lifecycle<GuardrailBuilderResult> {
42
+ #private;
43
+ props: Partial<GuardrailBuilderProps>;
44
+ /**
45
+ * Adds a custom alarm. The metric factory receives the guardrail version's
46
+ * {@link GuardrailMetrics}.
47
+ */
48
+ addAlarm(key: string, configure: (alarm: AlarmDefinitionBuilder<GuardrailMetrics>) => AlarmDefinitionBuilder<GuardrailMetrics>): this;
49
+ /** @internal — see ADR-0005. */
50
+ [COPY_STATE](target: GuardrailBuilder): void;
51
+ build(scope: IConstruct, id: string, context?: Record<string, object>): GuardrailBuilderResult;
52
+ }
53
+ /**
54
+ * Creates a builder for an Amazon Bedrock guardrail and a published version
55
+ * of it ([GENSEC02-BP01](https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec02-bp01.html)).
56
+ *
57
+ * By default it filters every harmful-content category and prompt attacks at
58
+ * `HIGH` ({@link GUARDRAIL_DEFAULTS}). Pass its `reference` to
59
+ * `modelGrants.invoke(target, { requireGuardrail })` to make callers use it.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * createGuardrailBuilder()
64
+ * .name("support-assistant")
65
+ * .topicPolicyConfig({ topicsConfig: [{ name: "Legal", definition: "Legal advice.", type: "DENY" }] });
66
+ * ```
67
+ */
68
+ export declare function createGuardrailBuilder(): IGuardrailBuilder;
69
+ export {};
70
+ //# sourceMappingURL=guardrail-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrail-builder.d.ts","sourceRoot":"","sources":["../../src/guardrail-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACpG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,KAAK,SAAS,EAAW,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAgB,MAAM,0BAA0B,CAAC;AAChF,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EAGtB,MAAM,uBAAuB,CAAC;AAG/B,+CAA+C;AAC/C,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,yCAAyC;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,mEAAmE;AACnE,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,WAAW,CAAC;IAC1F,4DAA4D;IAC5D,SAAS,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAEpE;;;OAGG;IACH,iBAAiB,CAAC,EAAE,oBAAoB,GAAG,KAAK,CAAC;CAClD;AAED,wDAAwD;AACxD,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,YAAY,CAAC;IACxB,+EAA+E;IAC/E,OAAO,EAAE,mBAAmB,CAAC;IAC7B,6EAA6E;IAC7E,SAAS,EAAE,kBAAkB,CAAC;IAC9B,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CAC/B;AAED;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,cAAc,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;AAWxF,cAAM,gBAAiB,YAAW,SAAS,CAAC,sBAAsB,CAAC;;IACjE,KAAK,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAM;IAG3C;;;OAGG;IACH,QAAQ,CACN,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,CACT,KAAK,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,KAC5C,sBAAsB,CAAC,gBAAgB,CAAC,GAC5C,IAAI;IAKP,gCAAgC;IAChC,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI;IAI5C,KAAK,CACH,KAAK,EAAE,UAAU,EACjB,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,sBAAsB;CA4B1B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,IAAI,iBAAiB,CAE1D"}
@@ -0,0 +1,75 @@
1
+ import { Stack } from "aws-cdk-lib";
2
+ import { CfnGuardrail, CfnGuardrailVersion } from "aws-cdk-lib/aws-bedrock";
3
+ import { COPY_STATE, resolve } from "@composurecdk/core";
4
+ import { taggedBuilder } from "@composurecdk/cloudformation";
5
+ import { AlarmDefinitionBuilder, createAlarms } from "@composurecdk/cloudwatch";
6
+ import { guardrailMetrics, resolveGuardrailAlarmDefinitions, } from "./guardrail-alarms.js";
7
+ import { GUARDRAIL_DEFAULTS } from "./guardrail-defaults.js";
8
+ /** 32-bit FNV-1a, as 8 hex digits. */
9
+ function fnv1a(value) {
10
+ let hash = 0x811c9dc5;
11
+ for (let i = 0; i < value.length; i++) {
12
+ hash = Math.imul(hash ^ value.charCodeAt(i), 0x01000193) >>> 0;
13
+ }
14
+ return hash.toString(16).padStart(8, "0");
15
+ }
16
+ class GuardrailBuilder {
17
+ props = {};
18
+ #customAlarms = [];
19
+ /**
20
+ * Adds a custom alarm. The metric factory receives the guardrail version's
21
+ * {@link GuardrailMetrics}.
22
+ */
23
+ addAlarm(key, configure) {
24
+ this.#customAlarms.push(configure(new AlarmDefinitionBuilder(key)));
25
+ return this;
26
+ }
27
+ /** @internal — see ADR-0005. */
28
+ [COPY_STATE](target) {
29
+ target.#customAlarms.push(...this.#customAlarms);
30
+ }
31
+ build(scope, id, context = {}) {
32
+ const { kmsKeyArn, recommendedAlarms, ...rest } = this.props;
33
+ if (!rest.name) {
34
+ throw new Error(`GuardrailBuilder "${id}" requires a name. Call .name().`);
35
+ }
36
+ const props = {
37
+ ...GUARDRAIL_DEFAULTS,
38
+ ...rest,
39
+ name: rest.name,
40
+ ...(kmsKeyArn !== undefined && { kmsKeyArn: resolve(kmsKeyArn, context) }),
41
+ };
42
+ const guardrail = new CfnGuardrail(scope, id, props);
43
+ // A version is a snapshot, so a configuration change publishes a new one.
44
+ const fingerprint = fnv1a(JSON.stringify(Stack.of(scope).resolve(props)));
45
+ const version = new CfnGuardrailVersion(scope, `${id}Version${fingerprint}`, {
46
+ guardrailIdentifier: guardrail.attrGuardrailId,
47
+ });
48
+ const reference = { guardrailArn: guardrail.attrGuardrailArn, version: version.attrVersion };
49
+ const metrics = guardrailMetrics(reference);
50
+ const alarms = createAlarms(scope, id, [
51
+ ...resolveGuardrailAlarmDefinitions(metrics, recommendedAlarms),
52
+ ...this.#customAlarms.map((b) => b.resolve(metrics)),
53
+ ]);
54
+ return { guardrail, version, reference, alarms };
55
+ }
56
+ }
57
+ /**
58
+ * Creates a builder for an Amazon Bedrock guardrail and a published version
59
+ * of it ([GENSEC02-BP01](https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec02-bp01.html)).
60
+ *
61
+ * By default it filters every harmful-content category and prompt attacks at
62
+ * `HIGH` ({@link GUARDRAIL_DEFAULTS}). Pass its `reference` to
63
+ * `modelGrants.invoke(target, { requireGuardrail })` to make callers use it.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * createGuardrailBuilder()
68
+ * .name("support-assistant")
69
+ * .topicPolicyConfig({ topicsConfig: [{ name: "Legal", definition: "Legal advice.", type: "DENY" }] });
70
+ * ```
71
+ */
72
+ export function createGuardrailBuilder() {
73
+ return taggedBuilder(GuardrailBuilder);
74
+ }
75
+ //# sourceMappingURL=guardrail-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrail-builder.js","sourceRoot":"","sources":["../../src/guardrail-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,YAAY,EAA0B,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAGpG,OAAO,EAAE,UAAU,EAAkB,OAAO,EAAmB,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAuB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAGL,gBAAgB,EAChB,gCAAgC,GACjC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAwC7D,sCAAsC;AACtC,SAAS,KAAK,CAAC,KAAa;IAC1B,IAAI,IAAI,GAAG,UAAU,CAAC;IACtB,KAAK,IAAI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E,CAAC;QACF,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;QAErD,0EAA0E;QAC1E,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC1E,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,KAAK,EAAE,GAAG,EAAE,UAAU,WAAW,EAAE,EAAE;YAC3E,mBAAmB,EAAE,SAAS,CAAC,eAAe;SAC/C,CAAC,CAAC;QAEH,MAAM,SAAS,GAAG,EAAE,YAAY,EAAE,SAAS,CAAC,gBAAgB,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;QAC7F,MAAM,OAAO,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAC5C,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,EAAE,EAAE,EAAE;YACrC,GAAG,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,CAAC;YAC/D,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;SACrD,CAAC,CAAC;QAEH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IACnD,CAAC;CACF;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO,aAAa,CAA0C,gBAAgB,CAAC,CAAC;AAClF,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Defaults for {@link createGuardrailBuilder}.
3
+ *
4
+ * @see https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec02-bp01.html
5
+ */
6
+ export declare const GUARDRAIL_DEFAULTS: {
7
+ blockedInputMessaging: string;
8
+ blockedOutputsMessaging: string;
9
+ /**
10
+ * Every harmful-content category and prompt attacks, at `HIGH`. AWS
11
+ * recommends no strengths; `HIGH` blocks the most, and a category that
12
+ * blocks legitimate content can be lowered. Prompt attacks only apply to
13
+ * input, so their output strength must be `NONE`.
14
+ *
15
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-content-filters.html
16
+ */
17
+ contentPolicyConfig: {
18
+ filtersConfig: {
19
+ type: string;
20
+ inputStrength: string;
21
+ outputStrength: string;
22
+ }[];
23
+ };
24
+ };
25
+ //# sourceMappingURL=guardrail-defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrail-defaults.d.ts","sourceRoot":"","sources":["../../src/guardrail-defaults.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,eAAO,MAAM,kBAAkB;;;IAI7B;;;;;;;OAOG;;;;;;;;CAOiC,CAAC"}
@@ -0,0 +1,27 @@
1
+ const HARMFUL_CONTENT = ["SEXUAL", "VIOLENCE", "HATE", "INSULTS", "MISCONDUCT"];
2
+ /** The Bedrock console's default message for a blocked prompt or response. */
3
+ const BLOCKED_MESSAGE = "Sorry, the model cannot answer this question.";
4
+ /**
5
+ * Defaults for {@link createGuardrailBuilder}.
6
+ *
7
+ * @see https://docs.aws.amazon.com/wellarchitected/latest/generative-ai-lens/gensec02-bp01.html
8
+ */
9
+ export const GUARDRAIL_DEFAULTS = {
10
+ blockedInputMessaging: BLOCKED_MESSAGE,
11
+ blockedOutputsMessaging: BLOCKED_MESSAGE,
12
+ /**
13
+ * Every harmful-content category and prompt attacks, at `HIGH`. AWS
14
+ * recommends no strengths; `HIGH` blocks the most, and a category that
15
+ * blocks legitimate content can be lowered. Prompt attacks only apply to
16
+ * input, so their output strength must be `NONE`.
17
+ *
18
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-content-filters.html
19
+ */
20
+ contentPolicyConfig: {
21
+ filtersConfig: [
22
+ ...HARMFUL_CONTENT.map((type) => ({ type, inputStrength: "HIGH", outputStrength: "HIGH" })),
23
+ { type: "PROMPT_ATTACK", inputStrength: "HIGH", outputStrength: "NONE" },
24
+ ],
25
+ },
26
+ };
27
+ //# sourceMappingURL=guardrail-defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrail-defaults.js","sourceRoot":"","sources":["../../src/guardrail-defaults.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;AAEhF,8EAA8E;AAC9E,MAAM,eAAe,GAAG,+CAA+C,CAAC;AAExE;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,qBAAqB,EAAE,eAAe;IACtC,uBAAuB,EAAE,eAAe;IAExC;;;;;;;OAOG;IACH,mBAAmB,EAAE;QACnB,aAAa,EAAE;YACb,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC;YAC3F,EAAE,IAAI,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE;SACzE;KACF;CACmC,CAAC"}
@@ -1,8 +1,14 @@
1
- export { foundationModelFor, type GeographicInferenceProfile, type GeographicInferenceProfileOptions, type GlobalInferenceProfile, INFERENCE_PROFILE_GEOGRAPHIES, type InferenceProfile, type InferenceProfileGeography, inferenceProfile, } from "./inference-profile.js";
1
+ export { type ApplicationInferenceProfileBuilderProps, type ApplicationInferenceProfileBuilderResult, createApplicationInferenceProfileBuilder, type IApplicationInferenceProfileBuilder, } from "./application-inference-profile-builder.js";
2
+ export { type ApplicationInferenceProfile, foundationModelFor, type GeographicInferenceProfile, type GeographicInferenceProfileOptions, type GlobalInferenceProfile, INFERENCE_PROFILE_GEOGRAPHIES, type InferenceProfile, type InferenceProfileGeography, inferenceProfile, } from "./inference-profile.js";
2
3
  export { type InferenceTarget, invocationArns } from "./inference-target.js";
3
- export { modelGrants } from "./grants.js";
4
+ export { guardrailGrants, type ModelInvokeGrantOptions, modelGrants } from "./grants.js";
5
+ export { createGuardrailBuilder, type GuardrailBuilderProps, type GuardrailBuilderResult, type GuardrailReference, type IGuardrailBuilder, } from "./guardrail-builder.js";
6
+ export { GUARDRAIL_DEFAULTS } from "./guardrail-defaults.js";
7
+ export { type GuardrailAlarmConfig, type GuardrailMetrics, guardrailMetrics, } from "./guardrail-alarms.js";
4
8
  export { createModelAlarmBuilder, type IModelAlarmBuilder, type ModelAlarmBuilderProps, type ModelAlarmBuilderResult, } from "./model-alarm-builder.js";
5
9
  export { type ModelAlarmConfig, type QuotaAlarmConfig } from "./model-alarm-config.js";
6
10
  export { MODEL_ALARM_DEFAULTS } from "./model-alarm-defaults.js";
7
11
  export { type ModelAlarmTarget, type ModelMetrics, modelMetrics } from "./model-alarms.js";
12
+ export { createModelInvocationLoggingBuilder, type IModelInvocationLoggingBuilder, MODEL_INVOCATION_LOGGING_DEFAULTS, type ModelInvocationLoggingBuilderProps, type ModelInvocationLoggingBuilderResult, type ModelInvocationLoggingModalities, } from "./model-invocation-logging-builder.js";
13
+ export { MODEL_INVOCATION_LOGGING_ALARM_DEFAULTS, type ModelInvocationLoggingAlarmConfig, } from "./model-invocation-logging-alarms.js";
8
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,KAAK,0BAA0B,EAC/B,KAAK,iCAAiC,EACtC,KAAK,sBAAsB,EAC3B,6BAA6B,EAC7B,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7E,O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ACvB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,GAC7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC3F,OAAO,EACL,mCAAmC,EACnC,KAAK,8BAA8B,EACnC,iCAAiC,EACjC,KAAK,kCAAkC,EACvC,KAAK,mCAAmC,EACxC,KAAK,gCAAgC,GACtC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,uCAAuC,EACvC,KAAK,iCAAiC,GACvC,MAAM,sCAAsC,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,7 +1,13 @@
1
+ export { createApplicationInferenceProfileBuilder, } from "./application-inference-profile-builder.js";
1
2
  export { foundationModelFor, INFERENCE_PROFILE_GEOGRAPHIES, inferenceProfile, } from "./inference-profile.js";
2
3
  export { invocationArns } from "./inference-target.js";
3
- export { modelGrants } from "./grants.js";
4
+ export { guardrailGrants, modelGrants } from "./grants.js";
5
+ export { createGuardrailBuilder, } from "./guardrail-builder.js";
6
+ export { GUARDRAIL_DEFAULTS } from "./guardrail-defaults.js";
7
+ export { guardrailMetrics, } from "./guardrail-alarms.js";
4
8
  export { createModelAlarmBuilder, } from "./model-alarm-builder.js";
5
9
  export { MODEL_ALARM_DEFAULTS } from "./model-alarm-defaults.js";
6
10
  export { modelMetrics } from "./model-alarms.js";
11
+ export { createModelInvocationLoggingBuilder, MODEL_INVOCATION_LOGGING_DEFAULTS, } from "./model-invocation-logging-builder.js";
12
+ export { MODEL_INVOCATION_LOGGING_ALARM_DEFAULTS, } from "./model-invocation-logging-alarms.js";
7
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAIlB,6BAA6B,EAG7B,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAwB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EACL,uBAAuB,GAIxB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAA4C,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,wCAAwC,GAEzC,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAEL,kBAAkB,EAIlB,6BAA6B,EAG7B,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAwB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAgC,WAAW,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EACL,sBAAsB,GAKvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAGL,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,uBAAuB,GAIxB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAA4C,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC3F,OAAO,EACL,mCAAmC,EAEnC,iCAAiC,GAIlC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,uCAAuC,GAExC,MAAM,sCAAsC,CAAC"}
@@ -47,6 +47,25 @@ export interface GlobalInferenceProfile {
47
47
  }
48
48
  /** A system-defined cross-Region inference profile. */
49
49
  export type InferenceProfile = GeographicInferenceProfile | GlobalInferenceProfile;
50
+ /**
51
+ * An application inference profile: an account-owned profile, tagged for
52
+ * cost allocation, that routes to a foundation model or a system-defined
53
+ * profile. Build one with `createApplicationInferenceProfileBuilder()`.
54
+ *
55
+ * @see https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-create.html
56
+ */
57
+ export interface ApplicationInferenceProfile {
58
+ readonly kind: "application";
59
+ /** The profile's ARN, which callers pass as the model id. */
60
+ readonly profileArn: string;
61
+ /**
62
+ * The profile's id, the last segment of {@link profileArn}: the `ModelId`
63
+ * its invocation metrics are reported under.
64
+ */
65
+ readonly profileId: string;
66
+ /** What the profile routes to. */
67
+ readonly source: FoundationModelIdentifier | InferenceProfile;
68
+ }
50
69
  /** Options for {@link inferenceProfile.geographic}. */
51
70
  export type GeographicInferenceProfileOptions = Pick<GeographicInferenceProfile, "model" | "geography" | "routingRegions">;
52
71
  declare function geographic(options: GeographicInferenceProfileOptions): GeographicInferenceProfile;