@aws/nx-plugin 1.0.15 → 1.1.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.
- package/README.md +1 -0
- package/generators.json +8 -0
- package/migrations.json +1 -1
- package/package.json +1 -1
- package/src/internal/test-matrix/generator.js +6 -1
- package/src/internal/test-matrix/generator.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +2 -0
- package/src/sdk/ts.d.ts +2 -0
- package/src/sdk/ts.js +2 -0
- package/src/sdk/ts.js.map +1 -1
- package/src/ts/agent/guardrails/__snapshots__/generator.spec.ts.snap +1625 -0
- package/src/ts/agent/guardrails/files/agent/guardrail.json.template +16 -0
- package/src/ts/agent/guardrails/files/agent/guardrail.ts.template +86 -0
- package/src/ts/agent/guardrails/generator.d.ts +10 -0
- package/src/ts/agent/guardrails/generator.js +111 -0
- package/src/ts/agent/guardrails/generator.js.map +1 -0
- package/src/ts/agent/guardrails/schema.d.js +6 -0
- package/src/ts/agent/guardrails/schema.d.js.map +1 -0
- package/src/ts/agent/guardrails/schema.d.ts +9 -0
- package/src/ts/agent/guardrails/schema.json +25 -0
- package/src/utils/guardrail-constructs/files/cdk/app/guardrails/__nameKebabCase__/__nameKebabCase__-guardrail.ts.template +128 -0
- package/src/utils/guardrail-constructs/files/terraform/app/guardrails/__nameKebabCase__/__nameKebabCase__-guardrail.tf.template +108 -0
- package/src/utils/guardrail-constructs/guardrail-constructs.d.ts +29 -0
- package/src/utils/guardrail-constructs/guardrail-constructs.js +52 -0
- package/src/utils/guardrail-constructs/guardrail-constructs.js.map +1 -0
- package/src/utils/guardrail-constructs/guardrail-wiring.d.ts +35 -0
- package/src/utils/guardrail-constructs/guardrail-wiring.js +61 -0
- package/src/utils/guardrail-constructs/guardrail-wiring.js.map +1 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import type { Iac } from '../iac.js';
|
|
6
|
+
export interface GuardrailWiringOptions {
|
|
7
|
+
iac: Iac;
|
|
8
|
+
/** Class name of the guarded agent, eg `MyAgent`. */
|
|
9
|
+
nameClassName: string;
|
|
10
|
+
/** Kebab-case name of the guarded agent, eg `my-agent`. */
|
|
11
|
+
nameKebabCase: string;
|
|
12
|
+
/** npm scope of the workspace without the `@`, eg `my-scope`. */
|
|
13
|
+
npmScope: string;
|
|
14
|
+
}
|
|
15
|
+
/** The ts#agent guide section that shows how to deploy the agent's Terraform module. */
|
|
16
|
+
export declare const TS_AGENT_TERRAFORM_DEPLOY_GUIDE_URL = "https://awslabs.github.io/nx-plugin-for-aws/en/guides/ts-agent/#infrastructure-as-code";
|
|
17
|
+
/**
|
|
18
|
+
* The code a user adds to their CDK stack to guard the agent.
|
|
19
|
+
* The guide shows the same code for `my-agent` in scope `my-scope`, which
|
|
20
|
+
* generator.spec.ts checks.
|
|
21
|
+
*/
|
|
22
|
+
export declare const cdkGuardrailWiring: ({ nameClassName, npmScope, }: Pick<GuardrailWiringOptions, "nameClassName" | "npmScope">) => string;
|
|
23
|
+
/**
|
|
24
|
+
* The code a user adds to their root Terraform module to grant the agent the
|
|
25
|
+
* guardrail and deploy its runtime-config entry, relative to
|
|
26
|
+
* `packages/infra/src`. The guide shows the same code for `my-agent`, which
|
|
27
|
+
* generator.spec.ts checks.
|
|
28
|
+
*/
|
|
29
|
+
export declare const terraformGuardrailWiring: ({ nameKebabCase, }: Pick<GuardrailWiringOptions, "nameKebabCase">) => string;
|
|
30
|
+
/**
|
|
31
|
+
* The message the generator prints after it adds the guardrail
|
|
32
|
+
* infrastructure. The generator does not edit the user's stack or root
|
|
33
|
+
* module, so this tells the user what to add there.
|
|
34
|
+
*/
|
|
35
|
+
export declare const guardrailWiringMessage: (options: GuardrailWiringOptions) => string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/ import { snakeCase } from "../names.js";
|
|
5
|
+
import { SHARED_CONSTRUCTS_NAME } from "../shared-constructs-constants.js";
|
|
6
|
+
/** The ts#agent guide section that shows how to deploy the agent's Terraform module. */ export const TS_AGENT_TERRAFORM_DEPLOY_GUIDE_URL = 'https://awslabs.github.io/nx-plugin-for-aws/en/guides/ts-agent/#infrastructure-as-code';
|
|
7
|
+
/**
|
|
8
|
+
* The code a user adds to their CDK stack to guard the agent.
|
|
9
|
+
* The guide shows the same code for `my-agent` in scope `my-scope`, which
|
|
10
|
+
* generator.spec.ts checks.
|
|
11
|
+
*/ export const cdkGuardrailWiring = ({ nameClassName, npmScope })=>`import { ${nameClassName}, ${nameClassName}Guardrail } from '@${npmScope}/${SHARED_CONSTRUCTS_NAME}';
|
|
12
|
+
|
|
13
|
+
const agent = new ${nameClassName}(this, '${nameClassName}');
|
|
14
|
+
new ${nameClassName}Guardrail(this, '${nameClassName}Guardrail', { agent });`;
|
|
15
|
+
/**
|
|
16
|
+
* The code a user adds to their root Terraform module to grant the agent the
|
|
17
|
+
* guardrail and deploy its runtime-config entry, relative to
|
|
18
|
+
* `packages/infra/src`. The guide shows the same code for `my-agent`, which
|
|
19
|
+
* generator.spec.ts checks.
|
|
20
|
+
*/ export const terraformGuardrailWiring = ({ nameKebabCase })=>{
|
|
21
|
+
const agentModule = snakeCase(nameKebabCase);
|
|
22
|
+
const guardrailModule = `${agentModule}_guardrail`;
|
|
23
|
+
return `module "${guardrailModule}" {
|
|
24
|
+
source = "../../common/terraform/src/app/guardrails/${nameKebabCase}"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module "${agentModule}" {
|
|
28
|
+
source = "../../common/terraform/src/app/agents/${nameKebabCase}"
|
|
29
|
+
# ...existing arguments...
|
|
30
|
+
additional_iam_policy_statements = module.${guardrailModule}.iam_policy_statements
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module "runtime_config_appconfig_deployment" {
|
|
34
|
+
# ...existing arguments...
|
|
35
|
+
depends_on = [
|
|
36
|
+
# ...existing modules...
|
|
37
|
+
module.${guardrailModule},
|
|
38
|
+
]
|
|
39
|
+
}`;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* How to add the printed Terraform code. `ts#agent` does not add the agent to
|
|
43
|
+
* the root module, so its `module` block may not exist yet.
|
|
44
|
+
*/ const terraformSteps = (nameKebabCase)=>{
|
|
45
|
+
const agentModule = snakeCase(nameKebabCase);
|
|
46
|
+
return `Add the module "${agentModule}_guardrail" block as printed below. Add its additional_iam_policy_statements line to your existing module "${agentModule}" block, and add module.${agentModule}_guardrail to the depends_on list of your runtime_config_appconfig_deployment module. If your root module does not deploy the agent yet, add the agent's module first, as described in ${TS_AGENT_TERRAFORM_DEPLOY_GUIDE_URL}.`;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The message the generator prints after it adds the guardrail
|
|
50
|
+
* infrastructure. The generator does not edit the user's stack or root
|
|
51
|
+
* module, so this tells the user what to add there.
|
|
52
|
+
*/ export const guardrailWiringMessage = (options)=>{
|
|
53
|
+
const missing = `Until you add it, the deployed agent fails on its first request, because runtime config has no guardrail at agentcore.guardrails.${options.nameClassName}.`;
|
|
54
|
+
return options.iac === 'cdk' ? `Add the guardrail to your agent in your stack, for example packages/infra/src/stacks/application-stack.ts. ${missing}
|
|
55
|
+
|
|
56
|
+
${cdkGuardrailWiring(options)}` : `Add the guardrail to your agent in the root Terraform module where you deploy the agent, for example packages/infra/src/main.tf. ${missing} ${terraformSteps(options.nameKebabCase)}
|
|
57
|
+
|
|
58
|
+
${terraformGuardrailWiring(options)}`;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=guardrail-wiring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/guardrail-constructs/guardrail-wiring.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { Iac } from '../iac.js';\nimport { snakeCase } from '../names.js';\nimport { SHARED_CONSTRUCTS_NAME } from '../shared-constructs-constants.js';\n\nexport interface GuardrailWiringOptions {\n iac: Iac;\n /** Class name of the guarded agent, eg `MyAgent`. */\n nameClassName: string;\n /** Kebab-case name of the guarded agent, eg `my-agent`. */\n nameKebabCase: string;\n /** npm scope of the workspace without the `@`, eg `my-scope`. */\n npmScope: string;\n}\n\n/** The ts#agent guide section that shows how to deploy the agent's Terraform module. */\nexport const TS_AGENT_TERRAFORM_DEPLOY_GUIDE_URL =\n 'https://awslabs.github.io/nx-plugin-for-aws/en/guides/ts-agent/#infrastructure-as-code';\n\n/**\n * The code a user adds to their CDK stack to guard the agent.\n * The guide shows the same code for `my-agent` in scope `my-scope`, which\n * generator.spec.ts checks.\n */\nexport const cdkGuardrailWiring = ({\n nameClassName,\n npmScope,\n}: Pick<GuardrailWiringOptions, 'nameClassName' | 'npmScope'>): string =>\n `import { ${nameClassName}, ${nameClassName}Guardrail } from '@${npmScope}/${SHARED_CONSTRUCTS_NAME}';\n\nconst agent = new ${nameClassName}(this, '${nameClassName}');\nnew ${nameClassName}Guardrail(this, '${nameClassName}Guardrail', { agent });`;\n\n/**\n * The code a user adds to their root Terraform module to grant the agent the\n * guardrail and deploy its runtime-config entry, relative to\n * `packages/infra/src`. The guide shows the same code for `my-agent`, which\n * generator.spec.ts checks.\n */\nexport const terraformGuardrailWiring = ({\n nameKebabCase,\n}: Pick<GuardrailWiringOptions, 'nameKebabCase'>): string => {\n const agentModule = snakeCase(nameKebabCase);\n const guardrailModule = `${agentModule}_guardrail`;\n return `module \"${guardrailModule}\" {\n source = \"../../common/terraform/src/app/guardrails/${nameKebabCase}\"\n}\n\nmodule \"${agentModule}\" {\n source = \"../../common/terraform/src/app/agents/${nameKebabCase}\"\n # ...existing arguments...\n additional_iam_policy_statements = module.${guardrailModule}.iam_policy_statements\n}\n\nmodule \"runtime_config_appconfig_deployment\" {\n # ...existing arguments...\n depends_on = [\n # ...existing modules...\n module.${guardrailModule},\n ]\n}`;\n};\n\n/**\n * How to add the printed Terraform code. `ts#agent` does not add the agent to\n * the root module, so its `module` block may not exist yet.\n */\nconst terraformSteps = (nameKebabCase: string): string => {\n const agentModule = snakeCase(nameKebabCase);\n return `Add the module \"${agentModule}_guardrail\" block as printed below. Add its additional_iam_policy_statements line to your existing module \"${agentModule}\" block, and add module.${agentModule}_guardrail to the depends_on list of your runtime_config_appconfig_deployment module. If your root module does not deploy the agent yet, add the agent's module first, as described in ${TS_AGENT_TERRAFORM_DEPLOY_GUIDE_URL}.`;\n};\n\n/**\n * The message the generator prints after it adds the guardrail\n * infrastructure. The generator does not edit the user's stack or root\n * module, so this tells the user what to add there.\n */\nexport const guardrailWiringMessage = (\n options: GuardrailWiringOptions,\n): string => {\n const missing = `Until you add it, the deployed agent fails on its first request, because runtime config has no guardrail at agentcore.guardrails.${options.nameClassName}.`;\n return options.iac === 'cdk'\n ? `Add the guardrail to your agent in your stack, for example packages/infra/src/stacks/application-stack.ts. ${missing}\n\n${cdkGuardrailWiring(options)}`\n : `Add the guardrail to your agent in the root Terraform module where you deploy the agent, for example packages/infra/src/main.tf. ${missing} ${terraformSteps(options.nameKebabCase)}\n\n${terraformGuardrailWiring(options)}`;\n};\n"],"names":["snakeCase","SHARED_CONSTRUCTS_NAME","TS_AGENT_TERRAFORM_DEPLOY_GUIDE_URL","cdkGuardrailWiring","nameClassName","npmScope","terraformGuardrailWiring","nameKebabCase","agentModule","guardrailModule","terraformSteps","guardrailWiringMessage","options","missing","iac"],"mappings":"AAAA;;;CAGC,GAED,SAASA,SAAS,QAAQ,cAAc;AACxC,SAASC,sBAAsB,QAAQ,oCAAoC;AAY3E,sFAAsF,GACtF,OAAO,MAAMC,sCACX,yFAAyF;AAE3F;;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