@aws/nx-plugin 1.0.0-rc.58 → 1.0.0-rc.59

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 (96) hide show
  1. package/generators.json +17 -1
  2. package/migrations.json +12 -7
  3. package/package.json +1 -1
  4. package/src/agentcore-gateway/__snapshots__/generator.spec.ts.snap +273 -0
  5. package/src/agentcore-gateway/agent-connection/generator.d.ts +19 -0
  6. package/src/agentcore-gateway/agent-connection/generator.js +90 -0
  7. package/src/agentcore-gateway/agent-connection/generator.js.map +1 -0
  8. package/src/agentcore-gateway/agent-connection/schema.d.js +6 -0
  9. package/src/agentcore-gateway/agent-connection/schema.d.js.map +1 -0
  10. package/src/agentcore-gateway/agent-connection/schema.d.ts +13 -0
  11. package/src/agentcore-gateway/agent-connection/schema.json +31 -0
  12. package/src/agentcore-gateway/attach-upstream.d.ts +16 -0
  13. package/src/agentcore-gateway/attach-upstream.js +32 -11
  14. package/src/agentcore-gateway/attach-upstream.js.map +1 -1
  15. package/src/agentcore-gateway/files/project/http/local-dev.ts.template +77 -0
  16. package/src/agentcore-gateway/generator.d.ts +1 -0
  17. package/src/agentcore-gateway/generator.js +22 -10
  18. package/src/agentcore-gateway/generator.js.map +1 -1
  19. package/src/agentcore-gateway/react-connection/__snapshots__/generator.spec.ts.snap +68 -0
  20. package/src/agentcore-gateway/react-connection/generator.d.ts +19 -0
  21. package/src/agentcore-gateway/react-connection/generator.js +119 -0
  22. package/src/agentcore-gateway/react-connection/generator.js.map +1 -0
  23. package/src/agentcore-gateway/react-connection/schema.d.js +6 -0
  24. package/src/agentcore-gateway/react-connection/schema.d.js.map +1 -0
  25. package/src/agentcore-gateway/react-connection/schema.d.ts +13 -0
  26. package/src/agentcore-gateway/react-connection/schema.json +31 -0
  27. package/src/agentcore-gateway/schema.d.js.map +1 -1
  28. package/src/agentcore-gateway/schema.d.ts +1 -1
  29. package/src/agentcore-gateway/schema.json +2 -2
  30. package/src/connection/agent-local-dev.d.ts +16 -0
  31. package/src/connection/agent-local-dev.js +44 -2
  32. package/src/connection/agent-local-dev.js.map +1 -1
  33. package/src/connection/gateway-runtime-config.d.ts +19 -0
  34. package/src/connection/gateway-runtime-config.js +47 -0
  35. package/src/connection/gateway-runtime-config.js.map +1 -0
  36. package/src/connection/generator.js +5 -0
  37. package/src/connection/generator.js.map +1 -1
  38. package/src/connection/scaffold-catalog.d.ts +107 -0
  39. package/src/connection/scaffold-catalog.js +140 -0
  40. package/src/connection/scaffold-catalog.js.map +1 -1
  41. package/src/connection/supported-connections.d.ts +9 -0
  42. package/src/connection/supported-connections.js +12 -0
  43. package/src/connection/supported-connections.js.map +1 -1
  44. package/src/internal/test-matrix/generator.js +39 -1
  45. package/src/internal/test-matrix/generator.js.map +1 -1
  46. package/src/migrations/latest/gateway-agent-targets/__snapshots__/migration.spec.ts.snap +223 -0
  47. package/src/migrations/latest/gateway-agent-targets/metadata.json +3 -0
  48. package/src/migrations/latest/gateway-agent-targets/migration.d.ts +6 -0
  49. package/src/migrations/latest/gateway-agent-targets/migration.js +217 -0
  50. package/src/migrations/latest/gateway-agent-targets/migration.js.map +1 -0
  51. package/src/migrations/latest/smithy-ssdk-bundle-pins/metadata.json +3 -0
  52. package/src/migrations/v1.0.0-rc.50/modernize-function-props-cast/metadata.json +3 -0
  53. package/src/migrations/v1.0.0-rc.50/restrict-cors-to-custom-domains/metadata.json +3 -0
  54. package/src/migrations/v1.0.0-rc.50/terraform-bootstrap-adopt-existing-bucket/metadata.json +3 -0
  55. package/src/migrations/v1.0.0-rc.52/user-identity-waf-allow-localhost-callback/metadata.json +3 -0
  56. package/src/migrations/v1.0.0-rc.54/order-access-log-delivery-after-bucket-policy/metadata.json +3 -0
  57. package/src/migrations/v1.0.0-rc.55/backfill-generator-metadata/metadata.json +3 -0
  58. package/src/migrations/v1.0.0-rc.56/dynamodb-local-remove-optimize-flag/metadata.json +3 -0
  59. package/src/migrations/v1.0.0-rc.57/ts-agent-session-management-support/metadata.json +3 -0
  60. package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +2 -0
  61. package/src/py/agent/react-connection/generator.d.ts +4 -1
  62. package/src/py/agent/react-connection/generator.js +35 -14
  63. package/src/py/agent/react-connection/generator.js.map +1 -1
  64. package/src/ts/agent/__snapshots__/generator.spec.ts.snap +4 -0
  65. package/src/ts/agent/react-connection/generator.d.ts +16 -1
  66. package/src/ts/agent/react-connection/generator.js +21 -8
  67. package/src/ts/agent/react-connection/generator.js.map +1 -1
  68. package/src/ts/nx-migration/generator.js +40 -27
  69. package/src/ts/nx-migration/generator.js.map +1 -1
  70. package/src/ts/react-website/agui/files/common/src/hooks/useAgui__agentNameClassName__.tsx.template +16 -0
  71. package/src/ts/react-website/agui/generator.d.ts +11 -0
  72. package/src/ts/react-website/agui/generator.js +11 -7
  73. package/src/ts/react-website/agui/generator.js.map +1 -1
  74. package/src/utils/agent-core-constructs/agent-core-constructs.d.ts +5 -0
  75. package/src/utils/agent-core-constructs/agent-core-constructs.js +2 -0
  76. package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
  77. package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +3 -0
  78. package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +6 -4
  79. package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +119 -3
  80. package/src/utils/agent-core-constructs/files/terraform/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.tf.template +17 -0
  81. package/src/utils/config/utils.d.ts +5 -0
  82. package/src/utils/config/utils.js +7 -1
  83. package/src/utils/config/utils.js.map +1 -1
  84. package/src/utils/connection/open-api/files/components/__apiNameClassName__Provider.tsx.template +13 -2
  85. package/src/utils/connection/open-api/react.d.ts +10 -1
  86. package/src/utils/connection/open-api/react.js +3 -2
  87. package/src/utils/connection/open-api/react.js.map +1 -1
  88. package/src/utils/migration-manifest.d.ts +58 -0
  89. package/src/utils/migration-manifest.js +76 -0
  90. package/src/utils/migration-manifest.js.map +1 -0
  91. package/src/utils/migration-versions.d.ts +2 -0
  92. package/src/utils/migration-versions.js.map +1 -1
  93. package/src/utils/version-upgrade-migration/register.d.ts +4 -2
  94. package/src/utils/version-upgrade-migration/register.js +13 -13
  95. package/src/utils/version-upgrade-migration/register.js.map +1 -1
  96. /package/src/agentcore-gateway/files/project/{local-dev.ts.template → mcp/local-dev.ts.template} +0 -0
package/generators.json CHANGED
@@ -30,6 +30,20 @@
30
30
  "metric": "g65",
31
31
  "hidden": true
32
32
  },
33
+ "agentcore-gateway#agent-connection": {
34
+ "factory": "./src/agentcore-gateway/agent-connection/generator",
35
+ "schema": "./src/agentcore-gateway/agent-connection/schema.json",
36
+ "description": "Connect an AgentCore Gateway to an agent, adding the agent as a gateway target",
37
+ "metric": "g69",
38
+ "hidden": true
39
+ },
40
+ "agentcore-gateway#react-connection": {
41
+ "factory": "./src/agentcore-gateway/react-connection/generator",
42
+ "schema": "./src/agentcore-gateway/react-connection/schema.json",
43
+ "description": "Connect a React website to an AgentCore Gateway fronting agents",
44
+ "metric": "g70",
45
+ "hidden": true
46
+ },
33
47
  "connection": {
34
48
  "factory": "./src/connection/generator",
35
49
  "schema": "./src/connection/schema.json",
@@ -54,7 +68,9 @@
54
68
  "connection/ts-agent-gateway",
55
69
  "connection/py-agent-gateway",
56
70
  "connection/agentcore-gateway-mcp",
57
- "connection/agentcore-gateway-gateway"
71
+ "connection/agentcore-gateway-gateway",
72
+ "connection/agentcore-gateway-agent",
73
+ "connection/react-agentcore-gateway"
58
74
  ]
59
75
  },
60
76
  "license": {
package/migrations.json CHANGED
@@ -2,6 +2,16 @@
2
2
  "$schema": "http://json-schema.org/schema",
3
3
  "name": "@aws/nx-plugin",
4
4
  "generators": {
5
+ "latest-gateway-agent-targets": {
6
+ "version": "1.0.0-rc.59",
7
+ "description": "Add agent runtime target support to the vended AgentCoreGateway construct and an agentName member to vended agent constructs",
8
+ "implementation": "./src/migrations/latest/gateway-agent-targets/migration"
9
+ },
10
+ "latest-smithy-ssdk-bundle-pins": {
11
+ "version": "1.0.0-rc.58",
12
+ "description": "Bump the rolldown and dts plugin pins in the Smithy build.Dockerfile so the bundled SSDK type declaration resolves",
13
+ "implementation": "./src/migrations/latest/smithy-ssdk-bundle-pins/migration"
14
+ },
5
15
  "v1.0.0-rc.50-modernize-function-props-cast": {
6
16
  "version": "1.0.0-rc.50",
7
17
  "description": "Replace the legacy angle-bracket FunctionProps type assertion with the modern as syntax in generated API constructs",
@@ -42,20 +52,15 @@
42
52
  "description": "Add session management support to ts#agent",
43
53
  "implementation": "./src/migrations/v1.0.0-rc.57/ts-agent-session-management-support/migration"
44
54
  },
45
- "latest-smithy-ssdk-bundle-pins": {
46
- "version": "1.0.0-rc.58",
47
- "description": "Bump the rolldown and dts plugin pins in the Smithy build.Dockerfile so the bundled SSDK type declaration resolves",
48
- "implementation": "./src/migrations/latest/smithy-ssdk-bundle-pins/migration"
49
- },
50
55
  "sync-vended-versions": {
51
- "version": "1.0.0-rc.58",
56
+ "version": "1.0.0-rc.59",
52
57
  "description": "Sync vended dependency versions and the tracked plugin version to those vended by this release",
53
58
  "implementation": "./src/utils/version-upgrade-migration/migration"
54
59
  }
55
60
  },
56
61
  "packageJsonUpdates": {
57
62
  "nx-23.1.1-nx-packages": {
58
- "version": "1.0.0-rc.58",
63
+ "version": "1.0.0-rc.59",
59
64
  "packages": {
60
65
  "nx": {
61
66
  "version": "23.1.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws/nx-plugin",
3
- "version": "1.0.0-rc.58",
3
+ "version": "1.0.0-rc.59",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/awslabs/nx-plugin-for-aws.git",
@@ -0,0 +1,273 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`agentcore-gateway generator > protocol: http > omits protocol_type from the Terraform gateway > my-gateway.tf 1`] = `
4
+ "terraform {
5
+ required_version = ">= 1.0"
6
+
7
+ required_providers {
8
+ aws = {
9
+ source = "hashicorp/aws"
10
+ version = "6.57.1"
11
+ }
12
+ random = {
13
+ source = "hashicorp/random"
14
+ version = "3.9.0"
15
+ }
16
+ }
17
+ }
18
+
19
+ variable "additional_iam_policy_statements" {
20
+ description = "Additional IAM policy statements to attach to the gateway service role. Connection generators (e.g. agentcore-gateway#mcp-connection) append \`InvokeAgentRuntime*\` entries here."
21
+ type = list(object({
22
+ Effect = string
23
+ Action = list(string)
24
+ Resource = list(string)
25
+ }))
26
+ default = []
27
+ }
28
+
29
+
30
+ variable "enable_waf" {
31
+ description = "Associate a regional WAFv2 web ACL (default AWS managed rule groups) with the gateway to inspect inbound requests."
32
+ type = bool
33
+ default = true
34
+ }
35
+
36
+ data "aws_caller_identity" "current" {}
37
+ data "aws_region" "current" {}
38
+
39
+ locals {
40
+ aws_account_id = data.aws_caller_identity.current.account_id
41
+ aws_region = data.aws_region.current.id
42
+ }
43
+
44
+ resource "random_id" "unique_suffix" {
45
+ byte_length = 4
46
+ }
47
+
48
+ # IAM role for the gateway service
49
+ resource "aws_iam_role" "gateway_role" {
50
+ name = "MyGateway-GatewayRole-\${random_id.unique_suffix.hex}"
51
+
52
+ assume_role_policy = jsonencode({
53
+ Version = "2012-10-17"
54
+ Statement = [
55
+ {
56
+ Sid = "AgentCoreGatewayAssumeRolePolicy"
57
+ Effect = "Allow"
58
+ Principal = {
59
+ Service = "bedrock-agentcore.amazonaws.com"
60
+ }
61
+ Action = "sts:AssumeRole"
62
+ Condition = {
63
+ StringEquals = {
64
+ "aws:SourceAccount" = local.aws_account_id
65
+ }
66
+ ArnLike = {
67
+ "aws:SourceArn" = "arn:aws:bedrock-agentcore:\${local.aws_region}:\${local.aws_account_id}:*"
68
+ }
69
+ }
70
+ }
71
+ ]
72
+ })
73
+ }
74
+
75
+ # Inline policy for statements appended by connection generators
76
+ # (e.g. InvokeAgentRuntime*)
77
+ resource "aws_iam_role_policy" "gateway_role_policy" {
78
+ count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
79
+ name = "MyGateway-GatewayPolicy"
80
+ role = aws_iam_role.gateway_role.id
81
+
82
+ policy = jsonencode({
83
+ Version = "2012-10-17"
84
+ Statement = var.additional_iam_policy_statements
85
+ })
86
+ }
87
+
88
+ resource "aws_bedrockagentcore_gateway" "this" {
89
+ # Cap the name so the 11-char service suffix keeps the gateway id within its
90
+ # 50-char limit (30 prefix + "-<8 hex>" + 11 = 50).
91
+ name = "\${substr("MyGateway", 0, 30)}-\${random_id.unique_suffix.hex}"
92
+ description = "AgentCore Gateway for MyGateway"
93
+ role_arn = aws_iam_role.gateway_role.arn
94
+
95
+ # No protocol type: AgentCore Runtime targets require a gateway without one.
96
+ # The gateway proxies requests to its runtime targets via path-based routing
97
+ # (\`/<targetName>/invocations\`).
98
+
99
+ authorizer_type = "AWS_IAM"
100
+ }
101
+
102
+ # WAFv2 protection for the gateway. AgentCore Gateway requires a REGIONAL web
103
+ # ACL; CloudFront (global) is not supported.
104
+ resource "aws_wafv2_web_acl" "gateway_waf" {
105
+ #checkov:skip=CKV2_AWS_31:Logging configuration is defined below in aws_wafv2_web_acl_logging_configuration.gateway_waf_logging; Checkov does not resolve the separate resource
106
+ count = var.enable_waf ? 1 : 0
107
+
108
+ name = "MyGateway-waf-\${random_id.unique_suffix.hex}"
109
+ scope = "REGIONAL"
110
+
111
+ default_action {
112
+ allow {}
113
+ }
114
+
115
+ rule {
116
+ name = "CRSRule"
117
+ priority = 0
118
+
119
+ override_action {
120
+ none {}
121
+ }
122
+
123
+ statement {
124
+ managed_rule_group_statement {
125
+ name = "AWSManagedRulesCommonRuleSet"
126
+ vendor_name = "AWS"
127
+
128
+ # Count instead of Block: the CRS 8 KB body limit is too restrictive
129
+ # for typical MCP tool payloads.
130
+ rule_action_override {
131
+ name = "SizeRestrictions_BODY"
132
+ action_to_use {
133
+ count {}
134
+ }
135
+ }
136
+ }
137
+ }
138
+
139
+ visibility_config {
140
+ cloudwatch_metrics_enabled = true
141
+ metric_name = "MyGatewayWebAcl-CRS"
142
+ sampled_requests_enabled = true
143
+ }
144
+ }
145
+
146
+ rule {
147
+ name = "KnownBadInputsRule"
148
+ priority = 1
149
+
150
+ override_action {
151
+ none {}
152
+ }
153
+
154
+ statement {
155
+ managed_rule_group_statement {
156
+ name = "AWSManagedRulesKnownBadInputsRuleSet"
157
+ vendor_name = "AWS"
158
+ }
159
+ }
160
+
161
+ visibility_config {
162
+ cloudwatch_metrics_enabled = true
163
+ metric_name = "MyGatewayWebAcl-KnownBadInputs"
164
+ sampled_requests_enabled = true
165
+ }
166
+ }
167
+
168
+ visibility_config {
169
+ cloudwatch_metrics_enabled = true
170
+ metric_name = "MyGatewayWebAcl"
171
+ sampled_requests_enabled = true
172
+ }
173
+
174
+ lifecycle {
175
+ create_before_destroy = true
176
+ }
177
+ }
178
+
179
+ resource "aws_wafv2_web_acl_association" "gateway_waf" {
180
+ count = var.enable_waf ? 1 : 0
181
+
182
+ resource_arn = aws_bedrockagentcore_gateway.this.gateway_arn
183
+ web_acl_arn = aws_wafv2_web_acl.gateway_waf[0].arn
184
+ }
185
+
186
+ # WAF request logs. WAFv2 requires the \`aws-waf-logs-\` name prefix.
187
+ resource "aws_cloudwatch_log_group" "gateway_waf_logs" {
188
+ #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
189
+ #checkov:skip=CKV_AWS_338:Log retention set to one year which is sufficient for WAF logs
190
+ count = var.enable_waf ? 1 : 0
191
+
192
+ name = "aws-waf-logs-my-gateway-\${random_id.unique_suffix.hex}"
193
+ retention_in_days = 365
194
+ }
195
+
196
+ resource "aws_wafv2_web_acl_logging_configuration" "gateway_waf_logging" {
197
+ count = var.enable_waf ? 1 : 0
198
+
199
+ log_destination_configs = [aws_cloudwatch_log_group.gateway_waf_logs[0].arn]
200
+ resource_arn = aws_wafv2_web_acl.gateway_waf[0].arn
201
+ }
202
+
203
+
204
+ # Add gateway URL to runtime config
205
+ module "add_gateway_url_to_runtime_config" {
206
+ source = "../../../core/runtime-config/entry"
207
+
208
+ namespace = "agentcore"
209
+ key = "gateways"
210
+ value = { "MyGateway" = aws_bedrockagentcore_gateway.this.gateway_url }
211
+
212
+ depends_on = [aws_bedrockagentcore_gateway.this]
213
+ }
214
+
215
+ output "gateway_id" {
216
+ description = "ID of the Bedrock AgentCore Gateway"
217
+ value = aws_bedrockagentcore_gateway.this.gateway_id
218
+ }
219
+
220
+ output "gateway_arn" {
221
+ description = "ARN of the Bedrock AgentCore Gateway"
222
+ value = aws_bedrockagentcore_gateway.this.gateway_arn
223
+ }
224
+
225
+ output "gateway_url" {
226
+ description = "Endpoint URL of the Bedrock AgentCore Gateway. Runtime targets are served under \`<gateway_url minus /mcp>/<targetName>/invocations\`."
227
+ value = aws_bedrockagentcore_gateway.this.gateway_url
228
+ }
229
+
230
+ output "gateway_role_arn" {
231
+ description = "ARN of the IAM role assumed by the gateway service"
232
+ value = aws_iam_role.gateway_role.arn
233
+ }
234
+
235
+ output "waf_web_acl_arn" {
236
+ description = "ARN of the WAFv2 web ACL associated with the gateway, or null if WAF is disabled"
237
+ value = var.enable_waf ? aws_wafv2_web_acl.gateway_waf[0].arn : null
238
+ }
239
+ "
240
+ `;
241
+
242
+ exports[`agentcore-gateway generator > protocol: http > wires the CDK construct with the http protocol > my-gateway.ts 1`] = `
243
+ "import { Construct } from 'constructs';
244
+ import {
245
+ AgentCoreGateway,
246
+ AgentCoreGatewayProps,
247
+ } from '../../../core/agentcore-gateway/agentcore-gateway.js';
248
+ import { RuntimeConfig } from '../../../core/runtime-config.js';
249
+
250
+ export type MyGatewayProps = Omit<AgentCoreGatewayProps, 'protocol'>;
251
+
252
+ /**
253
+ * AgentCore Gateway wired for HTTP proxying of agent runtime targets with IAM inbound auth.
254
+ */
255
+ export class MyGateway extends AgentCoreGateway {
256
+ /** Default Gateway target name when added to another Gateway. */
257
+ public readonly gatewayName = 'my-gateway';
258
+
259
+ constructor(scope: Construct, id: string, props?: MyGatewayProps) {
260
+ super(scope, id, {
261
+ protocol: 'http',
262
+ ...props,
263
+ });
264
+
265
+ const rc = RuntimeConfig.ensure(this);
266
+ rc.set('agentcore', 'gateways', {
267
+ ...rc.get('agentcore').gateways,
268
+ MyGateway: this.gateway.gatewayUrl,
269
+ });
270
+ }
271
+ }
272
+ "
273
+ `;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import type { GeneratorCallback, Tree } from '@nx/devkit';
6
+ import { type NxGeneratorInfo } from '../../utils/nx';
7
+ import type { AgentcoreGatewayAgentConnectionGeneratorSchema } from './schema';
8
+ export declare const AGENTCORE_GATEWAY_AGENT_CONNECTION_GENERATOR_INFO: NxGeneratorInfo;
9
+ /**
10
+ * Connect an AgentCore Gateway to an agent, so the agent is added as a
11
+ * gateway target and served under `<gatewayUrl>/<targetName>/invocations`.
12
+ *
13
+ * Chains the gateway's dev target to the agent's dev target, and registers
14
+ * the agent in the gateway's local-dev.ts so the local gateway proxies to it.
15
+ * Users must still call `gateway.addAgent(...)` in their application stack to
16
+ * create the actual CDK/Terraform resource.
17
+ */
18
+ export declare const agentcoreGatewayAgentConnectionGenerator: (tree: Tree, options: AgentcoreGatewayAgentConnectionGeneratorSchema) => Promise<GeneratorCallback>;
19
+ export default agentcoreGatewayAgentConnectionGenerator;
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */ import { formatFilesInSubtree } from "../../utils/format.js";
5
+ import { installDependencies } from "../../utils/install.js";
6
+ import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
7
+ import { kebabCase, toClassName } from "../../utils/names.js";
8
+ import { addComponentGeneratorMetadata, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
9
+ import { attachAgentToLocalGateway } from "../attach-upstream.js";
10
+ import { readAgentCoreGatewayMetadata } from "../generator.js";
11
+ export const AGENTCORE_GATEWAY_AGENT_CONNECTION_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
12
+ /**
13
+ * The agent protocols an http gateway can front, by agent language. The
14
+ * gateway proxies plain HTTP request/response and SSE streams:
15
+ *
16
+ * - `ag-ui` (ts + py) and `http` (py) serve POST /invocations with streamed
17
+ * responses, which proxy cleanly.
18
+ * - `a2a` (ts + py) is JSON-RPC over POST, which AgentCore applies a default
19
+ * schema for.
20
+ * - `http` (ts) is tRPC over WebSocket, and the gateway does not support
21
+ * WebSocket / bidirectional streaming, so it cannot sit behind one.
22
+ */ const SUPPORTED_AGENT_PROTOCOLS = {
23
+ 'ts#agent': [
24
+ 'ag-ui',
25
+ 'a2a'
26
+ ],
27
+ 'py#agent': [
28
+ 'ag-ui',
29
+ 'http',
30
+ 'a2a'
31
+ ]
32
+ };
33
+ /**
34
+ * Connect an AgentCore Gateway to an agent, so the agent is added as a
35
+ * gateway target and served under `<gatewayUrl>/<targetName>/invocations`.
36
+ *
37
+ * Chains the gateway's dev target to the agent's dev target, and registers
38
+ * the agent in the gateway's local-dev.ts so the local gateway proxies to it.
39
+ * Users must still call `gateway.addAgent(...)` in their application stack to
40
+ * create the actual CDK/Terraform resource.
41
+ */ export const agentcoreGatewayAgentConnectionGenerator = async (tree, options)=>{
42
+ const sourceProject = readProjectConfigurationUnqualified(tree, options.sourceProject);
43
+ const targetProject = readProjectConfigurationUnqualified(tree, options.targetProject);
44
+ const gateway = readAgentCoreGatewayMetadata(sourceProject);
45
+ const agentComponent = options.targetComponent;
46
+ if (!agentComponent) {
47
+ throw new Error(`Target project '${options.targetProject}' has no agent component metadata. Did you run the 'ts#agent' or 'py#agent' generator?`);
48
+ }
49
+ if (gateway.protocol !== 'http') {
50
+ throw new Error(`Gateway '${gateway.name}' has protocol='${gateway.protocol}'. Agent targets can only be attached to http-protocol gateways — generate one with the 'agentcore-gateway' generator and --protocol=http.`);
51
+ }
52
+ const agentGenerator = agentComponent.generator ?? 'ts#agent';
53
+ const agentProtocol = (agentComponent.protocol ?? 'http').toLowerCase();
54
+ const supportedProtocols = SUPPORTED_AGENT_PROTOCOLS[agentGenerator] ?? [];
55
+ if (!supportedProtocols.includes(agentProtocol)) {
56
+ throw new Error(`Agent '${agentComponent.name}' uses protocol='${agentProtocol}', which cannot be fronted by a gateway` + (agentGenerator === 'ts#agent' && agentProtocol === 'http' ? ` — a TypeScript HTTP agent serves tRPC over WebSocket, and AgentCore Gateway does not support WebSocket streaming. Consider the ag-ui protocol instead.` : `. Supported protocols: ${supportedProtocols.join(', ')}.`));
57
+ }
58
+ if (agentComponent.auth && agentComponent.auth !== 'iam') {
59
+ throw new Error(`Agent '${agentComponent.name}' uses auth='${agentComponent.auth}'. Gateway->agent connections currently require the agent to use IAM authentication.`);
60
+ }
61
+ // The target name must match what the deployed Gateway uses (`agentName` on
62
+ // the agent construct, derived from the project's class name) so the
63
+ // `/<target>/invocations` path resolves identically locally and deployed.
64
+ const agentComponentName = agentComponent.name ?? 'agent';
65
+ const agentTargetName = kebabCase(agentComponent.rc ?? toClassName(agentComponentName));
66
+ await attachAgentToLocalGateway(tree, sourceProject, 'dev', {
67
+ targetName: agentTargetName,
68
+ port: agentComponent.port ?? 8081,
69
+ upstreamProjectName: targetProject.name,
70
+ upstreamDevTargetName: `${agentComponentName}-dev`,
71
+ // The deployed gateway maps an A2A target's `/invocations/...` paths onto
72
+ // the agent container's root; HTTP and AG-UI agents serve /invocations
73
+ // themselves.
74
+ stripInvocations: agentProtocol === 'a2a'
75
+ });
76
+ // Recorded so the version sync can identify this connection.
77
+ addComponentGeneratorMetadata(tree, sourceProject.name, AGENTCORE_GATEWAY_AGENT_CONNECTION_GENERATOR_INFO, targetProject.root, agentTargetName);
78
+ await addGeneratorMetricsIfApplicable(tree, [
79
+ AGENTCORE_GATEWAY_AGENT_CONNECTION_GENERATOR_INFO
80
+ ]);
81
+ await formatFilesInSubtree(tree);
82
+ return ()=>installDependencies(tree, options.preferInstallDependencies, {
83
+ languages: [
84
+ 'typescript'
85
+ ]
86
+ });
87
+ };
88
+ export default agentcoreGatewayAgentConnectionGenerator;
89
+
90
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/agentcore-gateway/agent-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { GeneratorCallback, Tree } from '@nx/devkit';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport {\n addComponentGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { attachAgentToLocalGateway } from '../attach-upstream';\nimport { readAgentCoreGatewayMetadata } from '../generator';\nimport type { AgentcoreGatewayAgentConnectionGeneratorSchema } from './schema';\n\nexport const AGENTCORE_GATEWAY_AGENT_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\n/**\n * The agent protocols an http gateway can front, by agent language. The\n * gateway proxies plain HTTP request/response and SSE streams:\n *\n * - `ag-ui` (ts + py) and `http` (py) serve POST /invocations with streamed\n * responses, which proxy cleanly.\n * - `a2a` (ts + py) is JSON-RPC over POST, which AgentCore applies a default\n * schema for.\n * - `http` (ts) is tRPC over WebSocket, and the gateway does not support\n * WebSocket / bidirectional streaming, so it cannot sit behind one.\n */\nconst SUPPORTED_AGENT_PROTOCOLS: Record<string, string[]> = {\n 'ts#agent': ['ag-ui', 'a2a'],\n 'py#agent': ['ag-ui', 'http', 'a2a'],\n};\n\n/**\n * Connect an AgentCore Gateway to an agent, so the agent is added as a\n * gateway target and served under `<gatewayUrl>/<targetName>/invocations`.\n *\n * Chains the gateway's dev target to the agent's dev target, and registers\n * the agent in the gateway's local-dev.ts so the local gateway proxies to it.\n * Users must still call `gateway.addAgent(...)` in their application stack to\n * create the actual CDK/Terraform resource.\n */\nexport const agentcoreGatewayAgentConnectionGenerator = async (\n tree: Tree,\n options: AgentcoreGatewayAgentConnectionGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const sourceProject = readProjectConfigurationUnqualified(\n tree,\n options.sourceProject,\n );\n const targetProject = readProjectConfigurationUnqualified(\n tree,\n options.targetProject,\n );\n\n const gateway = readAgentCoreGatewayMetadata(sourceProject);\n const agentComponent = options.targetComponent;\n\n if (!agentComponent) {\n throw new Error(\n `Target project '${options.targetProject}' has no agent component metadata. Did you run the 'ts#agent' or 'py#agent' generator?`,\n );\n }\n\n if (gateway.protocol !== 'http') {\n throw new Error(\n `Gateway '${gateway.name}' has protocol='${gateway.protocol}'. Agent targets can only be attached to http-protocol gateways — generate one with the 'agentcore-gateway' generator and --protocol=http.`,\n );\n }\n\n const agentGenerator = agentComponent.generator ?? 'ts#agent';\n const agentProtocol = (\n (agentComponent.protocol as string | undefined) ?? 'http'\n ).toLowerCase();\n const supportedProtocols = SUPPORTED_AGENT_PROTOCOLS[agentGenerator] ?? [];\n if (!supportedProtocols.includes(agentProtocol)) {\n throw new Error(\n `Agent '${agentComponent.name}' uses protocol='${agentProtocol}', which cannot be fronted by a gateway` +\n (agentGenerator === 'ts#agent' && agentProtocol === 'http'\n ? ` — a TypeScript HTTP agent serves tRPC over WebSocket, and AgentCore Gateway does not support WebSocket streaming. Consider the ag-ui protocol instead.`\n : `. Supported protocols: ${supportedProtocols.join(', ')}.`),\n );\n }\n if (agentComponent.auth && agentComponent.auth !== 'iam') {\n throw new Error(\n `Agent '${agentComponent.name}' uses auth='${agentComponent.auth}'. Gateway->agent connections currently require the agent to use IAM authentication.`,\n );\n }\n\n // The target name must match what the deployed Gateway uses (`agentName` on\n // the agent construct, derived from the project's class name) so the\n // `/<target>/invocations` path resolves identically locally and deployed.\n const agentComponentName = agentComponent.name ?? 'agent';\n const agentTargetName = kebabCase(\n (agentComponent.rc as string | undefined) ??\n toClassName(agentComponentName),\n );\n\n await attachAgentToLocalGateway(tree, sourceProject, 'dev', {\n targetName: agentTargetName,\n port: (agentComponent.port as number | undefined) ?? 8081,\n upstreamProjectName: targetProject.name,\n upstreamDevTargetName: `${agentComponentName}-dev`,\n // The deployed gateway maps an A2A target's `/invocations/...` paths onto\n // the agent container's root; HTTP and AG-UI agents serve /invocations\n // themselves.\n stripInvocations: agentProtocol === 'a2a',\n });\n\n // Recorded so the version sync can identify this connection.\n addComponentGeneratorMetadata(\n tree,\n sourceProject.name,\n AGENTCORE_GATEWAY_AGENT_CONNECTION_GENERATOR_INFO,\n targetProject.root,\n agentTargetName,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n AGENTCORE_GATEWAY_AGENT_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default agentcoreGatewayAgentConnectionGenerator;\n"],"names":["formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","addComponentGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","attachAgentToLocalGateway","readAgentCoreGatewayMetadata","AGENTCORE_GATEWAY_AGENT_CONNECTION_GENERATOR_INFO","filename","SUPPORTED_AGENT_PROTOCOLS","agentcoreGatewayAgentConnectionGenerator","tree","options","sourceProject","targetProject","gateway","agentComponent","targetComponent","Error","protocol","name","agentGenerator","generator","agentProtocol","toLowerCase","supportedProtocols","includes","join","auth","agentComponentName","agentTargetName","rc","targetName","port","upstreamProjectName","upstreamDevTargetName","stripInvocations","root","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GAED,SAASA,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,SAAS,EAAEC,WAAW,QAAQ,uBAAoB;AAC3D,SACEC,6BAA6B,EAC7BC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,yBAAyB,QAAQ,wBAAqB;AAC/D,SAASC,4BAA4B,QAAQ,kBAAe;AAG5D,OAAO,MAAMC,oDACXJ,iBAAiB,YAAYK,QAAQ,EAAE;AAEzC;;;;;;;;;;CAUC,GACD,MAAMC,4BAAsD;IAC1D,YAAY;QAAC;QAAS;KAAM;IAC5B,YAAY;QAAC;QAAS;QAAQ;KAAM;AACtC;AAEA;;;;;;;;CAQC,GACD,OAAO,MAAMC,2CAA2C,OACtDC,MACAC;IAEA,MAAMC,gBAAgBT,oCACpBO,MACAC,QAAQC,aAAa;IAEvB,MAAMC,gBAAgBV,oCACpBO,MACAC,QAAQE,aAAa;IAGvB,MAAMC,UAAUT,6BAA6BO;IAC7C,MAAMG,iBAAiBJ,QAAQK,eAAe;IAE9C,IAAI,CAACD,gBAAgB;QACnB,MAAM,IAAIE,MACR,CAAC,gBAAgB,EAAEN,QAAQE,aAAa,CAAC,sFAAsF,CAAC;IAEpI;IAEA,IAAIC,QAAQI,QAAQ,KAAK,QAAQ;QAC/B,MAAM,IAAID,MACR,CAAC,SAAS,EAAEH,QAAQK,IAAI,CAAC,gBAAgB,EAAEL,QAAQI,QAAQ,CAAC,0IAA0I,CAAC;IAE3M;IAEA,MAAME,iBAAiBL,eAAeM,SAAS,IAAI;IACnD,MAAMC,gBAAgB,AACpB,CAAA,AAACP,eAAeG,QAAQ,IAA2B,MAAK,EACxDK,WAAW;IACb,MAAMC,qBAAqBhB,yBAAyB,CAACY,eAAe,IAAI,EAAE;IAC1E,IAAI,CAACI,mBAAmBC,QAAQ,CAACH,gBAAgB;QAC/C,MAAM,IAAIL,MACR,CAAC,OAAO,EAAEF,eAAeI,IAAI,CAAC,iBAAiB,EAAEG,cAAc,uCAAuC,CAAC,GACpGF,CAAAA,mBAAmB,cAAcE,kBAAkB,SAChD,CAAC,uJAAuJ,CAAC,GACzJ,CAAC,uBAAuB,EAAEE,mBAAmBE,IAAI,CAAC,MAAM,CAAC,CAAC,AAAD;IAEnE;IACA,IAAIX,eAAeY,IAAI,IAAIZ,eAAeY,IAAI,KAAK,OAAO;QACxD,MAAM,IAAIV,MACR,CAAC,OAAO,EAAEF,eAAeI,IAAI,CAAC,aAAa,EAAEJ,eAAeY,IAAI,CAAC,oFAAoF,CAAC;IAE1J;IAEA,4EAA4E;IAC5E,qEAAqE;IACrE,0EAA0E;IAC1E,MAAMC,qBAAqBb,eAAeI,IAAI,IAAI;IAClD,MAAMU,kBAAkB9B,UACtB,AAACgB,eAAee,EAAE,IAChB9B,YAAY4B;IAGhB,MAAMxB,0BAA0BM,MAAME,eAAe,OAAO;QAC1DmB,YAAYF;QACZG,MAAM,AAACjB,eAAeiB,IAAI,IAA2B;QACrDC,qBAAqBpB,cAAcM,IAAI;QACvCe,uBAAuB,GAAGN,mBAAmB,IAAI,CAAC;QAClD,0EAA0E;QAC1E,uEAAuE;QACvE,cAAc;QACdO,kBAAkBb,kBAAkB;IACtC;IAEA,6DAA6D;IAC7DrB,8BACES,MACAE,cAAcO,IAAI,EAClBb,mDACAO,cAAcuB,IAAI,EAClBP;IAGF,MAAM/B,gCAAgCY,MAAM;QAC1CJ;KACD;IAED,MAAMV,qBAAqBc;IAE3B,OAAO,IACLb,oBAAoBa,MAAMC,QAAQ0B,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe7B,yCAAyC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */ export { };
5
+
6
+ //# sourceMappingURL=schema.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/agentcore-gateway/agent-connection/schema.d.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { ComponentMetadata } from '../../utils/nx';\n\nexport interface AgentcoreGatewayAgentConnectionGeneratorSchema {\n sourceProject: string;\n targetProject: string;\n sourceComponent?: ComponentMetadata;\n targetComponent?: ComponentMetadata;\n preferInstallDependencies?: boolean;\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GAGD,WAMC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import type { ComponentMetadata } from '../../utils/nx';
6
+
7
+ export interface AgentcoreGatewayAgentConnectionGeneratorSchema {
8
+ sourceProject: string;
9
+ targetProject: string;
10
+ sourceComponent?: ComponentMetadata;
11
+ targetComponent?: ComponentMetadata;
12
+ preferInstallDependencies?: boolean;
13
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "agentcore-gateway#agent-connection",
4
+ "title": "agentcore-gateway#agent-connection",
5
+ "description": "Connect an AgentCore Gateway to an agent, adding the agent as a gateway target",
6
+ "type": "object",
7
+ "properties": {
8
+ "sourceProject": {
9
+ "type": "string",
10
+ "description": "The gateway project"
11
+ },
12
+ "targetProject": {
13
+ "type": "string",
14
+ "description": "The agent project"
15
+ },
16
+ "sourceComponent": {
17
+ "type": "string",
18
+ "description": "The gateway component in the source project"
19
+ },
20
+ "targetComponent": {
21
+ "type": "string",
22
+ "description": "The agent component in the target project"
23
+ },
24
+ "preferInstallDependencies": {
25
+ "type": "boolean",
26
+ "description": "Whether to prefer installing dependencies after the generator runs. Set to false to defer installing when batching multiple generators (an install still runs if needed so subsequent generators can compute the Nx project graph); install once at the end.",
27
+ "default": true
28
+ }
29
+ },
30
+ "required": ["sourceProject", "targetProject"]
31
+ }
@@ -31,3 +31,19 @@ export interface LocalGatewayUpstream {
31
31
  * aggregates its tools.
32
32
  */
33
33
  export declare const attachUpstreamToLocalGateway: (tree: Tree, gatewayProject: ProjectConfiguration, gatewayDevTargetName: string, upstream: LocalGatewayUpstream) => Promise<void>;
34
+ /**
35
+ * Attach an upstream agent to an http gateway's local gateway.
36
+ *
37
+ * Chains the gateway's dev target onto the agent's dev target, and registers
38
+ * the agent in the gateway's local-dev.ts so the local gateway proxies
39
+ * `/<targetName>/...` to it.
40
+ */
41
+ export declare const attachAgentToLocalGateway: (tree: Tree, gatewayProject: ProjectConfiguration, gatewayDevTargetName: string, upstream: LocalGatewayUpstream & {
42
+ /**
43
+ * Whether to strip the `/invocations` path prefix when proxying. The
44
+ * deployed gateway maps an A2A target's `/invocations/...` paths onto the
45
+ * agent container's root, so the local proxy does the same; HTTP and
46
+ * AG-UI agents serve `/invocations` themselves.
47
+ */
48
+ stripInvocations: boolean;
49
+ }) => Promise<void>;
@@ -12,17 +12,8 @@ import { addDependencyToTargetIfNotPresent } from "../utils/nx.js";
12
12
  * registers the upstream in the gateway's local-dev.ts so the local gateway
13
13
  * aggregates its tools.
14
14
  */ export const attachUpstreamToLocalGateway = async (tree, gatewayProject, gatewayDevTargetName, upstream)=>{
15
- // 1. Wire dev chain
16
- if (gatewayProject.targets?.[gatewayDevTargetName]) {
17
- addDependencyToTargetIfNotPresent(gatewayProject, gatewayDevTargetName, {
18
- projects: [
19
- upstream.upstreamProjectName
20
- ],
21
- target: upstream.upstreamDevTargetName
22
- });
23
- updateProjectConfiguration(tree, gatewayProject.name, gatewayProject);
24
- }
25
- // 2. Register the upstream in the gateway's local local-dev.ts
15
+ chainGatewayDevTarget(tree, gatewayProject, gatewayDevTargetName, upstream);
16
+ // Register the upstream in the gateway's local local-dev.ts
26
17
  const serveTsPath = joinPathFragments(gatewayProject.root, 'local-dev.ts');
27
18
  if (tree.exists(serveTsPath)) {
28
19
  const entry = `{ name: '${upstream.targetName}', url: 'http://localhost:${upstream.port}/mcp' }`;
@@ -34,5 +25,35 @@ import { addDependencyToTargetIfNotPresent } from "../utils/nx.js";
34
25
  }`);
35
26
  }
36
27
  };
28
+ /**
29
+ * Attach an upstream agent to an http gateway's local gateway.
30
+ *
31
+ * Chains the gateway's dev target onto the agent's dev target, and registers
32
+ * the agent in the gateway's local-dev.ts so the local gateway proxies
33
+ * `/<targetName>/...` to it.
34
+ */ export const attachAgentToLocalGateway = async (tree, gatewayProject, gatewayDevTargetName, upstream)=>{
35
+ chainGatewayDevTarget(tree, gatewayProject, gatewayDevTargetName, upstream);
36
+ const serveTsPath = joinPathFragments(gatewayProject.root, 'local-dev.ts');
37
+ if (tree.exists(serveTsPath)) {
38
+ const entry = `{ name: '${upstream.targetName}', url: 'http://localhost:${upstream.port}', stripInvocations: ${upstream.stripInvocations} }`;
39
+ await applyGritQL(tree, serveTsPath, `or {
40
+ \`const ATTACHED_AGENTS: AttachedAgent[] = []\` => \`const ATTACHED_AGENTS: AttachedAgent[] = [${entry}]\`,
41
+ \`const ATTACHED_AGENTS: AttachedAgent[] = [$items]\` => \`const ATTACHED_AGENTS: AttachedAgent[] = [${entry}, $items]\` where {
42
+ $items <: not contains \`'${upstream.targetName}'\`
43
+ }
44
+ }`);
45
+ }
46
+ };
47
+ /** Chain the gateway's dev target onto the upstream's dev target. */ const chainGatewayDevTarget = (tree, gatewayProject, gatewayDevTargetName, upstream)=>{
48
+ if (gatewayProject.targets?.[gatewayDevTargetName]) {
49
+ addDependencyToTargetIfNotPresent(gatewayProject, gatewayDevTargetName, {
50
+ projects: [
51
+ upstream.upstreamProjectName
52
+ ],
53
+ target: upstream.upstreamDevTargetName
54
+ });
55
+ updateProjectConfiguration(tree, gatewayProject.name, gatewayProject);
56
+ }
57
+ };
37
58
 
38
59
  //# sourceMappingURL=attach-upstream.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../packages/nx-plugin/src/agentcore-gateway/attach-upstream.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n joinPathFragments,\n type ProjectConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { applyGritQL } from '../utils/ast';\nimport { addDependencyToTargetIfNotPresent } from '../utils/nx';\n\nexport interface LocalGatewayUpstream {\n /**\n * Gateway target name for the upstream — prefixes its tools as\n * `<targetName>___<toolName>` both locally and deployed.\n */\n targetName: string;\n /**\n * Local port the upstream MCP endpoint listens on.\n */\n port: number;\n /**\n * Project providing the upstream's dev target.\n */\n upstreamProjectName: string;\n /**\n * Name of the upstream's dev target.\n */\n upstreamDevTargetName: string;\n}\n\n/**\n * Attach an upstream MCP endpoint (an MCP server or another gateway's local\n * gateway) to a gateway's local gateway.\n *\n * Chains the gateway's dev target onto the upstream's dev target, and\n * registers the upstream in the gateway's local-dev.ts so the local gateway\n * aggregates its tools.\n */\nexport const attachUpstreamToLocalGateway = async (\n tree: Tree,\n gatewayProject: ProjectConfiguration,\n gatewayDevTargetName: string,\n upstream: LocalGatewayUpstream,\n): Promise<void> => {\n // 1. Wire dev chain\n if (gatewayProject.targets?.[gatewayDevTargetName]) {\n addDependencyToTargetIfNotPresent(gatewayProject, gatewayDevTargetName, {\n projects: [upstream.upstreamProjectName],\n target: upstream.upstreamDevTargetName,\n });\n updateProjectConfiguration(tree, gatewayProject.name, gatewayProject);\n }\n\n // 2. Register the upstream in the gateway's local local-dev.ts\n const serveTsPath = joinPathFragments(gatewayProject.root, 'local-dev.ts');\n if (tree.exists(serveTsPath)) {\n const entry = `{ name: '${upstream.targetName}', url: 'http://localhost:${upstream.port}/mcp' }`;\n await applyGritQL(\n tree,\n serveTsPath,\n `or {\n \\`const ATTACHED_MCP_SERVERS: AttachedMcpServer[] = []\\` => \\`const ATTACHED_MCP_SERVERS: AttachedMcpServer[] = [${entry}]\\`,\n \\`const ATTACHED_MCP_SERVERS: AttachedMcpServer[] = [$items]\\` => \\`const ATTACHED_MCP_SERVERS: AttachedMcpServer[] = [${entry}, $items]\\` where {\n $items <: not contains \\`'${upstream.targetName}'\\`\n }\n}`,\n );\n }\n};\n"],"names":["joinPathFragments","updateProjectConfiguration","applyGritQL","addDependencyToTargetIfNotPresent","attachUpstreamToLocalGateway","tree","gatewayProject","gatewayDevTargetName","upstream","targets","projects","upstreamProjectName","target","upstreamDevTargetName","name","serveTsPath","root","exists","entry","targetName","port"],"mappings":"AAAA;;;CAGC,GACD,SACEA,iBAAiB,EAGjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,WAAW,QAAQ,kBAAe;AAC3C,SAASC,iCAAiC,QAAQ,iBAAc;AAsBhE;;;;;;;CAOC,GACD,OAAO,MAAMC,+BAA+B,OAC1CC,MACAC,gBACAC,sBACAC;IAEA,oBAAoB;IACpB,IAAIF,eAAeG,OAAO,EAAE,CAACF,qBAAqB,EAAE;QAClDJ,kCAAkCG,gBAAgBC,sBAAsB;YACtEG,UAAU;gBAACF,SAASG,mBAAmB;aAAC;YACxCC,QAAQJ,SAASK,qBAAqB;QACxC;QACAZ,2BAA2BI,MAAMC,eAAeQ,IAAI,EAAER;IACxD;IAEA,+DAA+D;IAC/D,MAAMS,cAAcf,kBAAkBM,eAAeU,IAAI,EAAE;IAC3D,IAAIX,KAAKY,MAAM,CAACF,cAAc;QAC5B,MAAMG,QAAQ,CAAC,SAAS,EAAEV,SAASW,UAAU,CAAC,0BAA0B,EAAEX,SAASY,IAAI,CAAC,OAAO,CAAC;QAChG,MAAMlB,YACJG,MACAU,aACA,CAAC;mHAC4G,EAAEG,MAAM;yHACF,EAAEA,MAAM;8BACnG,EAAEV,SAASW,UAAU,CAAC;;CAEnD,CAAC;IAEA;AACF,EAAE"}
1
+ {"version":3,"sources":["../../../../../packages/nx-plugin/src/agentcore-gateway/attach-upstream.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n joinPathFragments,\n type ProjectConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { applyGritQL } from '../utils/ast';\nimport { addDependencyToTargetIfNotPresent } from '../utils/nx';\n\nexport interface LocalGatewayUpstream {\n /**\n * Gateway target name for the upstream — prefixes its tools as\n * `<targetName>___<toolName>` both locally and deployed.\n */\n targetName: string;\n /**\n * Local port the upstream MCP endpoint listens on.\n */\n port: number;\n /**\n * Project providing the upstream's dev target.\n */\n upstreamProjectName: string;\n /**\n * Name of the upstream's dev target.\n */\n upstreamDevTargetName: string;\n}\n\n/**\n * Attach an upstream MCP endpoint (an MCP server or another gateway's local\n * gateway) to a gateway's local gateway.\n *\n * Chains the gateway's dev target onto the upstream's dev target, and\n * registers the upstream in the gateway's local-dev.ts so the local gateway\n * aggregates its tools.\n */\nexport const attachUpstreamToLocalGateway = async (\n tree: Tree,\n gatewayProject: ProjectConfiguration,\n gatewayDevTargetName: string,\n upstream: LocalGatewayUpstream,\n): Promise<void> => {\n chainGatewayDevTarget(tree, gatewayProject, gatewayDevTargetName, upstream);\n\n // Register the upstream in the gateway's local local-dev.ts\n const serveTsPath = joinPathFragments(gatewayProject.root, 'local-dev.ts');\n if (tree.exists(serveTsPath)) {\n const entry = `{ name: '${upstream.targetName}', url: 'http://localhost:${upstream.port}/mcp' }`;\n await applyGritQL(\n tree,\n serveTsPath,\n `or {\n \\`const ATTACHED_MCP_SERVERS: AttachedMcpServer[] = []\\` => \\`const ATTACHED_MCP_SERVERS: AttachedMcpServer[] = [${entry}]\\`,\n \\`const ATTACHED_MCP_SERVERS: AttachedMcpServer[] = [$items]\\` => \\`const ATTACHED_MCP_SERVERS: AttachedMcpServer[] = [${entry}, $items]\\` where {\n $items <: not contains \\`'${upstream.targetName}'\\`\n }\n}`,\n );\n }\n};\n\n/**\n * Attach an upstream agent to an http gateway's local gateway.\n *\n * Chains the gateway's dev target onto the agent's dev target, and registers\n * the agent in the gateway's local-dev.ts so the local gateway proxies\n * `/<targetName>/...` to it.\n */\nexport const attachAgentToLocalGateway = async (\n tree: Tree,\n gatewayProject: ProjectConfiguration,\n gatewayDevTargetName: string,\n upstream: LocalGatewayUpstream & {\n /**\n * Whether to strip the `/invocations` path prefix when proxying. The\n * deployed gateway maps an A2A target's `/invocations/...` paths onto the\n * agent container's root, so the local proxy does the same; HTTP and\n * AG-UI agents serve `/invocations` themselves.\n */\n stripInvocations: boolean;\n },\n): Promise<void> => {\n chainGatewayDevTarget(tree, gatewayProject, gatewayDevTargetName, upstream);\n\n const serveTsPath = joinPathFragments(gatewayProject.root, 'local-dev.ts');\n if (tree.exists(serveTsPath)) {\n const entry = `{ name: '${upstream.targetName}', url: 'http://localhost:${upstream.port}', stripInvocations: ${upstream.stripInvocations} }`;\n await applyGritQL(\n tree,\n serveTsPath,\n `or {\n \\`const ATTACHED_AGENTS: AttachedAgent[] = []\\` => \\`const ATTACHED_AGENTS: AttachedAgent[] = [${entry}]\\`,\n \\`const ATTACHED_AGENTS: AttachedAgent[] = [$items]\\` => \\`const ATTACHED_AGENTS: AttachedAgent[] = [${entry}, $items]\\` where {\n $items <: not contains \\`'${upstream.targetName}'\\`\n }\n}`,\n );\n }\n};\n\n/** Chain the gateway's dev target onto the upstream's dev target. */\nconst chainGatewayDevTarget = (\n tree: Tree,\n gatewayProject: ProjectConfiguration,\n gatewayDevTargetName: string,\n upstream: LocalGatewayUpstream,\n): void => {\n if (gatewayProject.targets?.[gatewayDevTargetName]) {\n addDependencyToTargetIfNotPresent(gatewayProject, gatewayDevTargetName, {\n projects: [upstream.upstreamProjectName],\n target: upstream.upstreamDevTargetName,\n });\n updateProjectConfiguration(tree, gatewayProject.name, gatewayProject);\n }\n};\n"],"names":["joinPathFragments","updateProjectConfiguration","applyGritQL","addDependencyToTargetIfNotPresent","attachUpstreamToLocalGateway","tree","gatewayProject","gatewayDevTargetName","upstream","chainGatewayDevTarget","serveTsPath","root","exists","entry","targetName","port","attachAgentToLocalGateway","stripInvocations","targets","projects","upstreamProjectName","target","upstreamDevTargetName","name"],"mappings":"AAAA;;;CAGC,GACD,SACEA,iBAAiB,EAGjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,WAAW,QAAQ,kBAAe;AAC3C,SAASC,iCAAiC,QAAQ,iBAAc;AAsBhE;;;;;;;CAOC,GACD,OAAO,MAAMC,+BAA+B,OAC1CC,MACAC,gBACAC,sBACAC;IAEAC,sBAAsBJ,MAAMC,gBAAgBC,sBAAsBC;IAElE,4DAA4D;IAC5D,MAAME,cAAcV,kBAAkBM,eAAeK,IAAI,EAAE;IAC3D,IAAIN,KAAKO,MAAM,CAACF,cAAc;QAC5B,MAAMG,QAAQ,CAAC,SAAS,EAAEL,SAASM,UAAU,CAAC,0BAA0B,EAAEN,SAASO,IAAI,CAAC,OAAO,CAAC;QAChG,MAAMb,YACJG,MACAK,aACA,CAAC;mHAC4G,EAAEG,MAAM;yHACF,EAAEA,MAAM;8BACnG,EAAEL,SAASM,UAAU,CAAC;;CAEnD,CAAC;IAEA;AACF,EAAE;AAEF;;;;;;CAMC,GACD,OAAO,MAAME,4BAA4B,OACvCX,MACAC,gBACAC,sBACAC;IAUAC,sBAAsBJ,MAAMC,gBAAgBC,sBAAsBC;IAElE,MAAME,cAAcV,kBAAkBM,eAAeK,IAAI,EAAE;IAC3D,IAAIN,KAAKO,MAAM,CAACF,cAAc;QAC5B,MAAMG,QAAQ,CAAC,SAAS,EAAEL,SAASM,UAAU,CAAC,0BAA0B,EAAEN,SAASO,IAAI,CAAC,qBAAqB,EAAEP,SAASS,gBAAgB,CAAC,EAAE,CAAC;QAC5I,MAAMf,YACJG,MACAK,aACA,CAAC;iGAC0F,EAAEG,MAAM;uGACF,EAAEA,MAAM;8BACjF,EAAEL,SAASM,UAAU,CAAC;;CAEnD,CAAC;IAEA;AACF,EAAE;AAEF,mEAAmE,GACnE,MAAML,wBAAwB,CAC5BJ,MACAC,gBACAC,sBACAC;IAEA,IAAIF,eAAeY,OAAO,EAAE,CAACX,qBAAqB,EAAE;QAClDJ,kCAAkCG,gBAAgBC,sBAAsB;YACtEY,UAAU;gBAACX,SAASY,mBAAmB;aAAC;YACxCC,QAAQb,SAASc,qBAAqB;QACxC;QACArB,2BAA2BI,MAAMC,eAAeiB,IAAI,EAAEjB;IACxD;AACF"}