@aws/nx-plugin 1.0.0-rc.32 → 1.0.0-rc.33
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/LICENSE-THIRD-PARTY +72 -70
- package/package.json +5 -5
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +15 -15
- package/src/infra/app/files/app/src/main.ts.template +1 -1
- package/src/infra/app/files/app/src/stages/application-stage.ts.template +1 -1
- package/src/infra/app/generator.js +3 -1
- package/src/infra/app/generator.js.map +1 -1
- package/src/open-api/ts-client/files/client.gen.ts.template +1 -1
- package/src/open-api/ts-client/generator.js +5 -1
- package/src/open-api/ts-client/generator.js.map +1 -1
- package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +2 -2
- package/src/open-api/ts-hooks/generator.js +5 -1
- package/src/open-api/ts-hooks/generator.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/preset/generator.d.ts +1 -1
- package/src/preset/generator.js +5 -2
- package/src/preset/generator.js.map +1 -1
- package/src/preset/schema.d.js.map +1 -1
- package/src/preset/schema.d.ts +2 -0
- package/src/preset/schema.json +6 -0
- package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +7 -7
- package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +8 -8
- package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +89 -3
- package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/py/fast-api/__snapshots__/generator.terraform.spec.ts.snap +12 -12
- package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +91 -5
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +7 -7
- package/src/smithy/ts/api/files/handler.ts.template +2 -2
- package/src/smithy/ts/api/files/local-server.ts.template +2 -2
- package/src/smithy/ts/api/files/operations/echo.ts.template +2 -2
- package/src/smithy/ts/api/files/service.ts.template +3 -3
- package/src/smithy/ts/api/generator.js +3 -1
- package/src/smithy/ts/api/generator.js.map +1 -1
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +12 -12
- package/src/trpc/backend/files/src/client/index.ts.template +1 -1
- package/src/trpc/backend/files/src/handler.ts.template +1 -1
- package/src/trpc/backend/files/src/index.ts.template +5 -5
- package/src/trpc/backend/files/src/init.ts.template +1 -1
- package/src/trpc/backend/files/src/local-server.ts.template +1 -1
- package/src/trpc/backend/files/src/middleware/index.ts.template +7 -7
- package/src/trpc/backend/files/src/procedures/echo.ts.template +2 -2
- package/src/trpc/backend/files/src/router.ts.template +2 -2
- package/src/trpc/backend/files/src/schema/index.ts.template +1 -1
- package/src/trpc/backend/generator.js +3 -1
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +89 -3
- package/src/ts/agent/a2a-connection/files/agent-connection/app/__targetAgentKebabCase__-client-strands.ts.template +2 -2
- package/src/ts/agent/a2a-connection/generator.js +3 -1
- package/src/ts/agent/a2a-connection/generator.js.map +1 -1
- package/src/ts/agent/files/a2a/index.ts.template +1 -1
- package/src/ts/agent/files/ag-ui/index.ts.template +1 -1
- package/src/ts/agent/files/http/client.ts.template +2 -2
- package/src/ts/agent/files/http/index.ts.template +2 -2
- package/src/ts/agent/files/http/router.ts.template +3 -3
- package/src/ts/agent/gateway-connection/files/agent-connection/app/__gatewayKebabCase__-client-strands.ts.template +2 -2
- package/src/ts/agent/gateway-connection/generator.js +3 -1
- package/src/ts/agent/gateway-connection/generator.js.map +1 -1
- package/src/ts/agent/generator.js +5 -2
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/agent/mcp-connection/files/agent-connection/app/__mcpServerKebabCase__-client-strands.ts.template +2 -2
- package/src/ts/agent/mcp-connection/generator.js +3 -1
- package/src/ts/agent/mcp-connection/generator.js.map +1 -1
- package/src/ts/astro-docs/files/translation/scripts/translate.ts.template +3 -2
- package/src/ts/astro-docs/generator.js +2 -0
- package/src/ts/astro-docs/generator.js.map +1 -1
- package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/dynamodb/files/src/client.ts.template +5 -2
- package/src/ts/dynamodb/files/src/entities/example.ts.template +1 -1
- package/src/ts/dynamodb/files/src/entities/index.ts.template +1 -1
- package/src/ts/dynamodb/files/src/index.ts.template +2 -2
- package/src/ts/dynamodb/generator.js +3 -1
- package/src/ts/dynamodb/generator.js.map +1 -1
- package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/lib/generator.js +7 -1
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/ts-project-utils.js +19 -4
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/lib/types.d.ts +6 -0
- package/src/ts/lib/types.js.map +1 -1
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +94 -8
- package/src/ts/mcp-server/generator.js +3 -2
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/nx-generator/files/local/generator.ts.template +2 -2
- package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +2 -2
- package/src/ts/nx-generator/generator.js +5 -2
- package/src/ts/nx-generator/generator.js.map +1 -1
- package/src/ts/nx-plugin/files/mcp-server/server.ts.template +5 -5
- package/src/ts/nx-plugin/files/mcp-server/tools/create-workspace-command.ts.template +2 -2
- package/src/ts/nx-plugin/files/mcp-server/tools/general-guidance.ts.template +1 -1
- package/src/ts/nx-plugin/files/mcp-server/tools/generator-guide.ts.template +2 -2
- package/src/ts/nx-plugin/files/mcp-server/tools/list-generators.ts.template +2 -2
- package/src/ts/nx-plugin/files/mcp-server/utils.ts.template +3 -3
- package/src/ts/nx-plugin/generator.js +3 -1
- package/src/ts/nx-plugin/generator.js.map +1 -1
- package/src/ts/nx-plugin/utils.js +7 -4
- package/src/ts/nx-plugin/utils.js.map +1 -1
- package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +4 -4
- package/src/ts/rdb/files/src/create-db-user-handler.ts.template +2 -2
- package/src/ts/rdb/files/src/index.ts.template +1 -1
- package/src/ts/rdb/files/src/migration-handler.ts.template +1 -1
- package/src/ts/rdb/files/src/prisma.ts.template +7 -4
- package/src/ts/rdb/generator.js +3 -1
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +35 -35
- package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +2 -2
- package/src/utils/agent-chat/agent-chat.js +3 -1
- package/src/utils/agent-chat/agent-chat.js.map +1 -1
- package/src/utils/agent-chat/files/a2a/chat.ts.template +1 -1
- package/src/utils/agent-chat/files/ag-ui/chat.ts.template +1 -1
- package/src/utils/agent-chat/files/http-py/chat.ts.template +2 -2
- package/src/utils/agent-chat/files/http-ts/chat.ts.template +1 -1
- package/src/utils/agent-connection/agent-connection.js +4 -1
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client-config.ts.template +2 -2
- package/src/utils/agent-connection/files/core-auth/agentcore-fetch.ts.template +1 -1
- package/src/utils/agent-connection/files/core-gateway/agentcore-gateway-mcp-transport.ts.template +2 -2
- package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-transport.ts.template +2 -2
- package/src/utils/agent-connection/files/core-shared/agentcore-transport.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/a2a/agentcore-a2a-client-strands.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/base/with-session-id-strands.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/gateway/agentcore-gateway-mcp-client-strands.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/mcp/agentcore-mcp-client-strands.ts.template +1 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.js +10 -3
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +3 -3
- package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +4 -4
- package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +1 -1
- package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +27 -0
- package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +60 -1
- package/src/utils/api-constructs/api-constructs.js +8 -2
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +8 -8
- package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +8 -8
- package/src/utils/api-constructs/files/cdk/core/api/http/http-api.ts.template +3 -3
- package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account/index.js.template +32 -20
- package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account.ts.template +1 -1
- package/src/utils/api-constructs/files/cdk/core/api/rest/rest-api.ts.template +4 -4
- package/src/utils/api-constructs/files/cdk/core/api/trpc/trpc-utils.ts.template +1 -1
- package/src/utils/ast.js +16 -0
- package/src/utils/ast.js.map +1 -1
- package/src/utils/commands.d.ts +1 -1
- package/src/utils/commands.js +4 -1
- package/src/utils/commands.js.map +1 -1
- package/src/utils/dynamodb-constructs/dynamodb-constructs.js +9 -2
- package/src/utils/dynamodb-constructs/dynamodb-constructs.js.map +1 -1
- package/src/utils/dynamodb-constructs/files/cdk/app/dynamodb/__nameKebabCase__.ts.template +3 -3
- package/src/utils/dynamodb-constructs/files/cdk/core/dynamodb.ts.template +1 -1
- package/src/utils/files/common/constructs/src/core/index.ts.template +4 -4
- package/src/utils/files/common/constructs/src/index.ts.template +2 -2
- package/src/utils/files/common/infra-config/src/index.ts.template +3 -3
- package/src/utils/files/common/infra-config/src/resolve-stage.ts.template +2 -2
- package/src/utils/files/common/infra-config/src/stages.config.ts.template +1 -1
- package/src/utils/files/common/scripts/src/infra/infra-deploy.ts.template +1 -1
- package/src/utils/files/common/scripts/src/infra/infra-destroy.ts.template +1 -1
- package/src/utils/files/common/scripts/src/infra/stage-credentials/run.ts.template +3 -3
- package/src/utils/files/common/shadcn/src/index.ts.template +2 -2
- package/src/utils/function-constructs/files/cdk/app/lambda-functions/__nameKebabCase__.ts.template +1 -1
- package/src/utils/function-constructs/function-constructs.js +3 -1
- package/src/utils/function-constructs/function-constructs.js.map +1 -1
- package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +2 -2
- package/src/utils/identity-constructs/identity-constructs.js +5 -1
- package/src/utils/identity-constructs/identity-constructs.js.map +1 -1
- package/src/utils/module-format.d.ts +28 -0
- package/src/utils/module-format.js +28 -0
- package/src/utils/module-format.js.map +1 -0
- package/src/utils/rdb-constructs/files/cdk/app/dbs/__nameKebabCase__.ts.template +5 -5
- package/src/utils/rdb-constructs/files/cdk/core/rdb/aurora.ts.template +1 -1
- package/src/utils/rdb-constructs/rdb-constructs.js +9 -2
- package/src/utils/rdb-constructs/rdb-constructs.js.map +1 -1
- package/src/utils/shared-constructs.js +3 -1
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/shared-infra-config.js +3 -1
- package/src/utils/shared-infra-config.js.map +1 -1
- package/src/utils/shared-infra-scripts.js +3 -1
- package/src/utils/shared-infra-scripts.js.map +1 -1
- package/src/utils/shared-shadcn.js +3 -1
- package/src/utils/shared-shadcn.js.map +1 -1
- package/src/utils/test.d.ts +2 -0
- package/src/utils/test.js +7 -1
- package/src/utils/test.js.map +1 -1
- package/src/utils/versions.d.ts +58 -58
- package/src/utils/versions.js +56 -56
- package/src/utils/versions.js.map +1 -1
- package/src/utils/website-constructs/files/cdk/app/static-websites/__websiteNameKebabCase__.ts.template +2 -2
- package/src/utils/website-constructs/files/cdk/core/static-website.ts.template +2 -2
- package/src/utils/website-constructs/website-constructs.js +9 -2
- package/src/utils/website-constructs/website-constructs.js.map +1 -1
|
@@ -748,6 +748,25 @@ variable "tags" {
|
|
|
748
748
|
default = {}
|
|
749
749
|
}
|
|
750
750
|
|
|
751
|
+
# VPC Configuration (optional)
|
|
752
|
+
variable "enable_vpc" {
|
|
753
|
+
description = "Run the agent core runtime inside a VPC. Set alongside vpc_id/subnet_ids."
|
|
754
|
+
type = bool
|
|
755
|
+
default = false
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
variable "vpc_id" {
|
|
759
|
+
description = "VPC ID to run the agent core runtime in. Required when enable_vpc is true."
|
|
760
|
+
type = string
|
|
761
|
+
default = null
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
variable "subnet_ids" {
|
|
765
|
+
description = "Subnet IDs to run the agent core runtime in. Required when enable_vpc is true."
|
|
766
|
+
type = list(string)
|
|
767
|
+
default = null
|
|
768
|
+
}
|
|
769
|
+
|
|
751
770
|
variable "appconfig_application_id" {
|
|
752
771
|
description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). The agent reads its runtime configuration from this application."
|
|
753
772
|
type = string
|
|
@@ -763,6 +782,9 @@ module "agent_core_runtime" {
|
|
|
763
782
|
agent_runtime_name = "TerraformSnapshotAgent"
|
|
764
783
|
docker_image_tag = "proj-terraform-snapshot-agent:latest"
|
|
765
784
|
server_protocol = "HTTP"
|
|
785
|
+
enable_vpc = var.enable_vpc
|
|
786
|
+
vpc_id = var.vpc_id
|
|
787
|
+
subnet_ids = var.subnet_ids
|
|
766
788
|
|
|
767
789
|
env = merge({
|
|
768
790
|
RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
|
|
@@ -817,6 +839,11 @@ output "appconfig_application_id" {
|
|
|
817
839
|
description = "AppConfig Application ID for runtime config (passthrough of the shared \`appconfig_application_id\` input)."
|
|
818
840
|
value = var.appconfig_application_id
|
|
819
841
|
}
|
|
842
|
+
|
|
843
|
+
output "security_group_id" {
|
|
844
|
+
description = "Security group ID of the agent core runtime, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
|
|
845
|
+
value = module.agent_core_runtime.security_group_id
|
|
846
|
+
}
|
|
820
847
|
"
|
|
821
848
|
`;
|
|
822
849
|
|
|
@@ -827,7 +854,7 @@ exports[`ts#agent generator > should match snapshot for Terraform generated file
|
|
|
827
854
|
required_providers {
|
|
828
855
|
aws = {
|
|
829
856
|
source = "hashicorp/aws"
|
|
830
|
-
version = "6.
|
|
857
|
+
version = "6.54.0"
|
|
831
858
|
}
|
|
832
859
|
null = {
|
|
833
860
|
source = "hashicorp/null"
|
|
@@ -893,6 +920,30 @@ variable "additional_iam_policy_statements" {
|
|
|
893
920
|
default = []
|
|
894
921
|
}
|
|
895
922
|
|
|
923
|
+
# VPC Configuration (optional)
|
|
924
|
+
variable "enable_vpc" {
|
|
925
|
+
description = "Run the agent core runtime inside a VPC. Set alongside vpc_id/subnet_ids."
|
|
926
|
+
type = bool
|
|
927
|
+
default = false
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
variable "vpc_id" {
|
|
931
|
+
description = "VPC ID to run the agent core runtime in. Required when enable_vpc is true."
|
|
932
|
+
type = string
|
|
933
|
+
default = null
|
|
934
|
+
|
|
935
|
+
validation {
|
|
936
|
+
condition = !var.enable_vpc || (var.vpc_id != null && var.subnet_ids != null)
|
|
937
|
+
error_message = "vpc_id and subnet_ids must be set when enable_vpc is true."
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
variable "subnet_ids" {
|
|
942
|
+
description = "Subnet IDs to run the agent core runtime in. Required when enable_vpc is true."
|
|
943
|
+
type = list(string)
|
|
944
|
+
default = null
|
|
945
|
+
}
|
|
946
|
+
|
|
896
947
|
variable "tags" {
|
|
897
948
|
description = "Tags to apply to resources"
|
|
898
949
|
type = map(string)
|
|
@@ -1128,6 +1179,28 @@ resource "null_resource" "docker_publish" {
|
|
|
1128
1179
|
depends_on = [aws_ecr_repository_policy.agent_core_ecr_policy]
|
|
1129
1180
|
}
|
|
1130
1181
|
|
|
1182
|
+
# Security group for the agent core runtime, used when running inside a VPC
|
|
1183
|
+
resource "aws_security_group" "agent_core_runtime" {
|
|
1184
|
+
count = var.enable_vpc ? 1 : 0
|
|
1185
|
+
|
|
1186
|
+
#checkov:skip=CKV2_AWS_5:Attached to the runtime via network_configuration; Checkov cannot resolve this reference
|
|
1187
|
+
name_prefix = "\${var.agent_runtime_name}-runtime-"
|
|
1188
|
+
description = "Security group for the \${var.agent_runtime_name} agent core runtime"
|
|
1189
|
+
vpc_id = var.vpc_id
|
|
1190
|
+
tags = var.tags
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
resource "aws_vpc_security_group_egress_rule" "agent_core_runtime_https" {
|
|
1194
|
+
count = var.enable_vpc ? 1 : 0
|
|
1195
|
+
|
|
1196
|
+
security_group_id = aws_security_group.agent_core_runtime[0].id
|
|
1197
|
+
cidr_ipv4 = "0.0.0.0/0"
|
|
1198
|
+
from_port = 443
|
|
1199
|
+
to_port = 443
|
|
1200
|
+
ip_protocol = "tcp"
|
|
1201
|
+
description = "Allow outbound HTTPS to AWS service endpoints"
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1131
1204
|
# Bedrock AgentCore Agent Runtime
|
|
1132
1205
|
resource "aws_bedrockagentcore_agent_runtime" "agent_runtime" {
|
|
1133
1206
|
agent_runtime_name = "\${var.agent_runtime_name}_\${random_id.unique_suffix.hex}"
|
|
@@ -1154,7 +1227,15 @@ resource "aws_bedrockagentcore_agent_runtime" "agent_runtime" {
|
|
|
1154
1227
|
}
|
|
1155
1228
|
|
|
1156
1229
|
network_configuration {
|
|
1157
|
-
network_mode = "PUBLIC"
|
|
1230
|
+
network_mode = var.enable_vpc ? "VPC" : "PUBLIC"
|
|
1231
|
+
|
|
1232
|
+
dynamic "network_mode_config" {
|
|
1233
|
+
for_each = var.enable_vpc ? [1] : []
|
|
1234
|
+
content {
|
|
1235
|
+
security_groups = [aws_security_group.agent_core_runtime[0].id]
|
|
1236
|
+
subnets = var.subnet_ids
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1158
1239
|
}
|
|
1159
1240
|
|
|
1160
1241
|
protocol_configuration {
|
|
@@ -1181,7 +1262,7 @@ resource "null_resource" "runtime_ready" {
|
|
|
1181
1262
|
|
|
1182
1263
|
provisioner "local-exec" {
|
|
1183
1264
|
command = <<-EOT
|
|
1184
|
-
uv run --with boto3==1.43.
|
|
1265
|
+
uv run --with boto3==1.43.46 python -c "
|
|
1185
1266
|
import boto3
|
|
1186
1267
|
import json
|
|
1187
1268
|
import os
|
|
@@ -1256,6 +1337,11 @@ output "agent_runtime_version" {
|
|
|
1256
1337
|
description = "Version of the Bedrock Agent Core runtime"
|
|
1257
1338
|
value = aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_version
|
|
1258
1339
|
}
|
|
1340
|
+
|
|
1341
|
+
output "security_group_id" {
|
|
1342
|
+
description = "Security group ID of the agent core runtime, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
|
|
1343
|
+
value = var.enable_vpc ? aws_security_group.agent_core_runtime[0].id : null
|
|
1344
|
+
}
|
|
1259
1345
|
"
|
|
1260
1346
|
`;
|
|
1261
1347
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { A2AAgent } from '@strands-agents/sdk/a2a';
|
|
2
|
-
import { AgentCoreA2aClientStrands } from '../core/agentcore-a2a-client-strands
|
|
3
|
-
import { getAgentCoreRuntimeConfig } from '../core/runtime-config
|
|
2
|
+
import { AgentCoreA2aClientStrands } from '../core/agentcore-a2a-client-strands<% if (esm) { %>.js<% } %>';
|
|
3
|
+
import { getAgentCoreRuntimeConfig } from '../core/runtime-config<% if (esm) { %>.js<% } %>';
|
|
4
4
|
|
|
5
5
|
/** Strands client for the <%- targetAgentClassName %> A2A agent. */
|
|
6
6
|
export class <%- targetAgentClassName %>ClientStrands {
|
|
@@ -7,6 +7,7 @@ import { addDestructuredImport, addStarExport, applyGritQL } from "../../../util
|
|
|
7
7
|
import { formatFilesInSubtree } from "../../../utils/format.js";
|
|
8
8
|
import { installDependencies } from "../../../utils/install.js";
|
|
9
9
|
import { addGeneratorMetricsIfApplicable } from "../../../utils/metrics.js";
|
|
10
|
+
import { esmVars } from "../../../utils/module-format.js";
|
|
10
11
|
import { kebabCase } from "../../../utils/names.js";
|
|
11
12
|
import { getNpmScope } from "../../../utils/npm-scope.js";
|
|
12
13
|
import { addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../../utils/nx.js";
|
|
@@ -38,7 +39,8 @@ export const tsAgentA2aConnectionGenerator = async (tree, options)=>{
|
|
|
38
39
|
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'), joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'), {
|
|
39
40
|
targetAgentKebabCase,
|
|
40
41
|
targetAgentClassName,
|
|
41
|
-
targetAgentPort
|
|
42
|
+
targetAgentPort,
|
|
43
|
+
...esmVars(tree)
|
|
42
44
|
}, {
|
|
43
45
|
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
44
46
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/ts/agent/a2a-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport {\n AGENT_CONNECTION_PROJECT_DIR,\n addTypeScriptCoreClient,\n ensureTypeScriptAgentConnectionProject,\n} from '../../../utils/agent-connection/agent-connection';\nimport {\n addDestructuredImport,\n addStarExport,\n applyGritQL,\n} from '../../../utils/ast';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { kebabCase } from '../../../utils/names';\nimport { getNpmScope } from '../../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { withVersions } from '../../../utils/versions';\nimport type { TsAgentA2aConnectionGeneratorSchema } from './schema';\n\nexport const TS_AGENT_A2A_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const tsAgentA2aConnectionGenerator = async (\n tree: Tree,\n options: TsAgentA2aConnectionGeneratorSchema,\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 agentComponent = options.sourceComponent;\n const targetAgentComponent = options.targetComponent;\n\n if (!agentComponent || !targetAgentComponent) {\n throw new Error(\n 'Both sourceComponent and targetComponent must be provided for ts#agent -> a2a connections',\n );\n }\n\n if ((targetAgentComponent.protocol ?? '').toLowerCase() !== 'a2a') {\n throw new Error(\n `Target agent '${targetAgentComponent.name}' uses the ${targetAgentComponent.protocol ?? 'http'} protocol — only A2A agents can be connected as tools.`,\n );\n }\n\n if (\n targetAgentComponent.auth &&\n targetAgentComponent.auth.toLowerCase() !== 'iam'\n ) {\n throw new Error(\n `A2A agent connection currently only supports IAM authentication, but '${targetAgentComponent.name}' uses '${targetAgentComponent.auth}' authentication.`,\n );\n }\n\n const targetAgentComponentName = targetAgentComponent.name ?? 'agent';\n const targetAgentClassName = targetAgentComponent.rc as string;\n const targetAgentKebabCase = kebabCase(targetAgentClassName);\n const targetAgentPort = targetAgentComponent.port ?? 9000;\n\n const npmScope = getNpmScope(tree);\n\n // 1. Ensure the shared agent-connection project exists + has the A2A core client\n await ensureTypeScriptAgentConnectionProject(tree);\n await addTypeScriptCoreClient(tree, 'a2a');\n\n // 2. Generate the per-connection <Name>Client into app/\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'),\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'),\n {\n targetAgentKebabCase,\n targetAgentClassName,\n targetAgentPort,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add re-export to index.ts\n await addStarExport(\n tree,\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'index.ts'),\n `./app/${targetAgentKebabCase}-client-strands.js`,\n );\n\n // 3. AST transform agent.ts to add the remote A2A agent as a tool\n const agentSourceDir = joinPathFragments(\n sourceProject.root,\n agentComponent.path ?? 'src',\n );\n const agentFilePath = joinPathFragments(agentSourceDir, 'agent.ts');\n\n if (tree.exists(agentFilePath)) {\n const clientClassName = `${targetAgentClassName}ClientStrands`;\n const clientVarName =\n targetAgentClassName.charAt(0).toLowerCase() +\n targetAgentClassName.slice(1);\n const toolName = `ask${targetAgentClassName}`;\n const toolVarName = `${clientVarName}Tool`;\n\n // Ensure tool + z imports are available\n await addDestructuredImport(\n tree,\n agentFilePath,\n ['tool'],\n '@strands-agents/sdk',\n );\n await addDestructuredImport(tree, agentFilePath, ['z'], 'zod');\n await addDestructuredImport(\n tree,\n agentFilePath,\n [clientClassName],\n `:${npmScope}/agent-connection`,\n );\n\n // Build the tool creation + Agent wiring.\n const toolCreationBlock = `const ${clientVarName} = await ${clientClassName}.create();\n const ${toolVarName} = tool({\n name: '${toolName}',\n description: 'Delegate a question to the remote ${targetAgentClassName} A2A agent and return its reply.',\n inputSchema: z.object({ prompt: z.string() }),\n callback: async ({ prompt }) => (await ${clientVarName}.invoke(prompt)).toString(),\n });`;\n\n // Transform the arrow function that contains `new Agent`:\n // - Expression body: wrap in block with tool creation and return\n // - Block body: prepend tool creation statement\n await applyGritQL(\n tree,\n agentFilePath,\n `or { \\`async ($p) => new Agent($args)\\` => raw\\`async ($p) => {\n ${toolCreationBlock}\n return new Agent($args);\n}\\` where { $program <: not contains \\`${clientClassName}.create\\` }, \\`async ($p) => { $body }\\` => raw\\`async ($p) => {\n ${toolCreationBlock}\n $body\n}\\` where { $body <: contains \\`new Agent($_)\\`, $program <: not contains \\`${clientClassName}.create\\` } }`,\n );\n\n // Append the tool to the tools array (after existing items)\n await applyGritQL(\n tree,\n agentFilePath,\n `\\`tools: [$items]\\` => \\`tools: [$items, ${toolVarName}]\\` where { $items <: within \\`new Agent($_)\\`, $items <: not contains \\`${toolVarName}\\` }`,\n );\n }\n\n // 4. Set up dev target — depend on the target agent's dev\n // so running the host's dev also spins up the remote A2A agent.\n const agentName = agentComponent.name ?? 'agent';\n const devTargetName = `${agentName}-dev`;\n const targetDevTargetName = `${targetAgentComponentName}-dev`;\n\n if (sourceProject.targets?.[devTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, devTargetName, {\n projects: [targetProject.name],\n target: targetDevTargetName,\n });\n updateProjectConfiguration(tree, sourceProject.name, sourceProject);\n }\n\n // 5. Add dependencies\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@a2a-js/sdk',\n '@strands-agents/sdk',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n 'zod',\n ]),\n {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n TS_AGENT_A2A_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentA2aConnectionGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","applyGritQL","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","getNpmScope","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","withVersions","TS_AGENT_A2A_CONNECTION_GENERATOR_INFO","filename","tsAgentA2aConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","targetAgentComponent","targetComponent","Error","protocol","toLowerCase","name","auth","targetAgentComponentName","targetAgentClassName","rc","targetAgentKebabCase","targetAgentPort","port","npmScope","dirname","overwriteStrategy","KeepExisting","agentSourceDir","root","path","agentFilePath","exists","clientClassName","clientVarName","charAt","slice","toolName","toolVarName","toolCreationBlock","agentName","devTargetName","targetDevTargetName","targets","projects","target","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SACEC,4BAA4B,EAC5BC,uBAAuB,EACvBC,sCAAsC,QACjC,sDAAmD;AAC1D,SACEC,qBAAqB,EACrBC,aAAa,EACbC,WAAW,QACN,wBAAqB;AAC5B,SAASC,oBAAoB,QAAQ,2BAAwB;AAC7D,SAASC,mBAAmB,QAAQ,4BAAyB;AAC7D,SAASC,+BAA+B,QAAQ,4BAAyB;AACzE,SAASC,SAAS,QAAQ,0BAAuB;AACjD,SAASC,WAAW,QAAQ,8BAA2B;AACvD,SACEC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,uBAAoB;AAC3B,SAASC,YAAY,QAAQ,6BAA0B;AAGvD,OAAO,MAAMC,yCACXH,iBAAiB,YAAYI,QAAQ,EAAE;AAEzC,OAAO,MAAMC,gCAAgC,OAC3CC,MACAC;IAEA,MAAMC,gBAAgBP,oCACpBK,MACAC,QAAQC,aAAa;IAEvB,MAAMC,gBAAgBR,oCACpBK,MACAC,QAAQE,aAAa;IAGvB,MAAMC,iBAAiBH,QAAQI,eAAe;IAC9C,MAAMC,uBAAuBL,QAAQM,eAAe;IAEpD,IAAI,CAACH,kBAAkB,CAACE,sBAAsB;QAC5C,MAAM,IAAIE,MACR;IAEJ;IAEA,IAAI,AAACF,CAAAA,qBAAqB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J,aAAa;QACX;QACA;QACA;QACA;QACA;QACA;QACA;KACD,GACD,CAAC;IAGH,MAAMN,gCAAgCU,MAAM;QAC1CH;KACD;IAED,MAAMT,qBAAqBY;IAC3B,OAAO,IACLX,oBAAoBW,MAAMC,QAAQwC,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe3C,8BAA8B"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/ts/agent/a2a-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport {\n AGENT_CONNECTION_PROJECT_DIR,\n addTypeScriptCoreClient,\n ensureTypeScriptAgentConnectionProject,\n} from '../../../utils/agent-connection/agent-connection';\nimport {\n addDestructuredImport,\n addStarExport,\n applyGritQL,\n} from '../../../utils/ast';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { esmVars } from '../../../utils/module-format';\nimport { kebabCase } from '../../../utils/names';\nimport { getNpmScope } from '../../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { withVersions } from '../../../utils/versions';\nimport type { TsAgentA2aConnectionGeneratorSchema } from './schema';\n\nexport const TS_AGENT_A2A_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const tsAgentA2aConnectionGenerator = async (\n tree: Tree,\n options: TsAgentA2aConnectionGeneratorSchema,\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 agentComponent = options.sourceComponent;\n const targetAgentComponent = options.targetComponent;\n\n if (!agentComponent || !targetAgentComponent) {\n throw new Error(\n 'Both sourceComponent and targetComponent must be provided for ts#agent -> a2a connections',\n );\n }\n\n if ((targetAgentComponent.protocol ?? '').toLowerCase() !== 'a2a') {\n throw new Error(\n `Target agent '${targetAgentComponent.name}' uses the ${targetAgentComponent.protocol ?? 'http'} protocol — only A2A agents can be connected as tools.`,\n );\n }\n\n if (\n targetAgentComponent.auth &&\n targetAgentComponent.auth.toLowerCase() !== 'iam'\n ) {\n throw new Error(\n `A2A agent connection currently only supports IAM authentication, but '${targetAgentComponent.name}' uses '${targetAgentComponent.auth}' authentication.`,\n );\n }\n\n const targetAgentComponentName = targetAgentComponent.name ?? 'agent';\n const targetAgentClassName = targetAgentComponent.rc as string;\n const targetAgentKebabCase = kebabCase(targetAgentClassName);\n const targetAgentPort = targetAgentComponent.port ?? 9000;\n\n const npmScope = getNpmScope(tree);\n\n // 1. Ensure the shared agent-connection project exists + has the A2A core client\n await ensureTypeScriptAgentConnectionProject(tree);\n await addTypeScriptCoreClient(tree, 'a2a');\n\n // 2. Generate the per-connection <Name>Client into app/\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'),\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'),\n {\n targetAgentKebabCase,\n targetAgentClassName,\n targetAgentPort,\n ...esmVars(tree),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add re-export to index.ts\n await addStarExport(\n tree,\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'index.ts'),\n `./app/${targetAgentKebabCase}-client-strands.js`,\n );\n\n // 3. AST transform agent.ts to add the remote A2A agent as a tool\n const agentSourceDir = joinPathFragments(\n sourceProject.root,\n agentComponent.path ?? 'src',\n );\n const agentFilePath = joinPathFragments(agentSourceDir, 'agent.ts');\n\n if (tree.exists(agentFilePath)) {\n const clientClassName = `${targetAgentClassName}ClientStrands`;\n const clientVarName =\n targetAgentClassName.charAt(0).toLowerCase() +\n targetAgentClassName.slice(1);\n const toolName = `ask${targetAgentClassName}`;\n const toolVarName = `${clientVarName}Tool`;\n\n // Ensure tool + z imports are available\n await addDestructuredImport(\n tree,\n agentFilePath,\n ['tool'],\n '@strands-agents/sdk',\n );\n await addDestructuredImport(tree, agentFilePath, ['z'], 'zod');\n await addDestructuredImport(\n tree,\n agentFilePath,\n [clientClassName],\n `:${npmScope}/agent-connection`,\n );\n\n // Build the tool creation + Agent wiring.\n const toolCreationBlock = `const ${clientVarName} = await ${clientClassName}.create();\n const ${toolVarName} = tool({\n name: '${toolName}',\n description: 'Delegate a question to the remote ${targetAgentClassName} A2A agent and return its reply.',\n inputSchema: z.object({ prompt: z.string() }),\n callback: async ({ prompt }) => (await ${clientVarName}.invoke(prompt)).toString(),\n });`;\n\n // Transform the arrow function that contains `new Agent`:\n // - Expression body: wrap in block with tool creation and return\n // - Block body: prepend tool creation statement\n await applyGritQL(\n tree,\n agentFilePath,\n `or { \\`async ($p) => new Agent($args)\\` => raw\\`async ($p) => {\n ${toolCreationBlock}\n return new Agent($args);\n}\\` where { $program <: not contains \\`${clientClassName}.create\\` }, \\`async ($p) => { $body }\\` => raw\\`async ($p) => {\n ${toolCreationBlock}\n $body\n}\\` where { $body <: contains \\`new Agent($_)\\`, $program <: not contains \\`${clientClassName}.create\\` } }`,\n );\n\n // Append the tool to the tools array (after existing items)\n await applyGritQL(\n tree,\n agentFilePath,\n `\\`tools: [$items]\\` => \\`tools: [$items, ${toolVarName}]\\` where { $items <: within \\`new Agent($_)\\`, $items <: not contains \\`${toolVarName}\\` }`,\n );\n }\n\n // 4. Set up dev target — depend on the target agent's dev\n // so running the host's dev also spins up the remote A2A agent.\n const agentName = agentComponent.name ?? 'agent';\n const devTargetName = `${agentName}-dev`;\n const targetDevTargetName = `${targetAgentComponentName}-dev`;\n\n if (sourceProject.targets?.[devTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, devTargetName, {\n projects: [targetProject.name],\n target: targetDevTargetName,\n });\n updateProjectConfiguration(tree, sourceProject.name, sourceProject);\n }\n\n // 5. Add dependencies\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@a2a-js/sdk',\n '@strands-agents/sdk',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n 'zod',\n ]),\n {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n TS_AGENT_A2A_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentA2aConnectionGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","applyGritQL","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","getNpmScope","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","withVersions","TS_AGENT_A2A_CONNECTION_GENERATOR_INFO","filename","tsAgentA2aConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","targetAgentComponent","targetComponent","Error","protocol","toLowerCase","name","auth","targetAgentComponentName","targetAgentClassName","rc","targetAgentKebabCase","targetAgentPort","port","npmScope","dirname","overwriteStrategy","KeepExisting","agentSourceDir","root","path","agentFilePath","exists","clientClassName","clientVarName","charAt","slice","toolName","toolVarName","toolCreationBlock","agentName","devTargetName","targetDevTargetName","targets","projects","target","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,E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2
|
import express, { type Request, type Response, type NextFunction } from 'express';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
import { runWithSessionId, withSessionId } from '<%- agentConnectionImport %>';
|
|
5
|
-
import { getAgent } from './agent
|
|
5
|
+
import { getAgent } from './agent<% if (esm) { %>.js<% } %>';
|
|
6
6
|
|
|
7
7
|
const PORT = parseInt(process.env.PORT || '9000');
|
|
8
8
|
const HOST = '0.0.0.0';
|
|
@@ -3,7 +3,7 @@ import { createStrandsApp } from '@ag-ui/aws-strands/server';
|
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
import type { Request, Response, NextFunction } from 'express';
|
|
5
5
|
import { runWithSessionId } from '<%- agentConnectionImport %>';
|
|
6
|
-
import { getAgent } from './agent
|
|
6
|
+
import { getAgent } from './agent<% if (esm) { %>.js<% } %>';
|
|
7
7
|
|
|
8
8
|
const PORT = parseInt(process.env.PORT || '8080');
|
|
9
9
|
const HOST = '0.0.0.0';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AppRouter } from './router
|
|
2
|
-
import { AgentCoreTrpcClient, WebSocketTrpcClient } from './agent-core-trpc-client
|
|
1
|
+
import { AppRouter } from './router<% if (esm) { %>.js<% } %>';
|
|
2
|
+
import { AgentCoreTrpcClient, WebSocketTrpcClient } from './agent-core-trpc-client<% if (esm) { %>.js<% } %>';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Client for connecting to <%- agentNameClassName %> on Bedrock AgentCore Runtime via WebSocket from a NodeJS environment
|
|
@@ -4,14 +4,14 @@ import {
|
|
|
4
4
|
CreateHTTPContextOptions,
|
|
5
5
|
createHTTPHandler,
|
|
6
6
|
} from '@trpc/server/adapters/standalone';
|
|
7
|
-
import { appRouter, AppRouter } from './router
|
|
7
|
+
import { appRouter, AppRouter } from './router<% if (esm) { %>.js<% } %>';
|
|
8
8
|
import { WebSocketServer } from 'ws';
|
|
9
9
|
import cors from 'cors';
|
|
10
10
|
import {
|
|
11
11
|
CreateWSSContextFnOptions,
|
|
12
12
|
applyWSSHandler,
|
|
13
13
|
} from '@trpc/server/adapters/ws';
|
|
14
|
-
import { Context } from './init
|
|
14
|
+
import { Context } from './init<% if (esm) { %>.js<% } %>';
|
|
15
15
|
|
|
16
16
|
const PORT = parseInt(process.env.PORT || '8080');
|
|
17
17
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { publicProcedure, t } from './init
|
|
1
|
+
import { publicProcedure, t } from './init<% if (esm) { %>.js<% } %>';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { zAsyncIterable } from './schema/z-async-iterable
|
|
3
|
+
import { zAsyncIterable } from './schema/z-async-iterable<% if (esm) { %>.js<% } %>';
|
|
4
4
|
import { enterSessionContext, withSessionId } from '<%- agentConnectionImport %>';
|
|
5
|
-
import { getAgent } from './agent
|
|
5
|
+
import { getAgent } from './agent<% if (esm) { %>.js<% } %>';
|
|
6
6
|
|
|
7
7
|
export const router = t.router;
|
|
8
8
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { McpClient } from '@strands-agents/sdk';
|
|
2
|
-
import { AgentCoreGatewayMcpClientStrands } from '../core/agentcore-gateway-mcp-client-strands
|
|
3
|
-
import { getAgentCoreRuntimeConfig } from '../core/runtime-config
|
|
2
|
+
import { AgentCoreGatewayMcpClientStrands } from '../core/agentcore-gateway-mcp-client-strands<% if (esm) { %>.js<% } %>';
|
|
3
|
+
import { getAgentCoreRuntimeConfig } from '../core/runtime-config<% if (esm) { %>.js<% } %>';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Strands client for the <%- gatewayClassName %> AgentCore Gateway.
|
|
@@ -8,6 +8,7 @@ import { addDestructuredImport, addStarExport } from "../../../utils/ast.js";
|
|
|
8
8
|
import { formatFilesInSubtree } from "../../../utils/format.js";
|
|
9
9
|
import { installDependencies } from "../../../utils/install.js";
|
|
10
10
|
import { addGeneratorMetricsIfApplicable } from "../../../utils/metrics.js";
|
|
11
|
+
import { esmVars } from "../../../utils/module-format.js";
|
|
11
12
|
import { kebabCase } from "../../../utils/names.js";
|
|
12
13
|
import { getNpmScope } from "../../../utils/npm-scope.js";
|
|
13
14
|
import { addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../../utils/nx.js";
|
|
@@ -45,7 +46,8 @@ export const tsAgentGatewayConnectionGenerator = async (tree, options)=>{
|
|
|
45
46
|
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'), joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'), {
|
|
46
47
|
gatewayKebabCase,
|
|
47
48
|
gatewayClassName,
|
|
48
|
-
gatewayPort: gateway.port
|
|
49
|
+
gatewayPort: gateway.port,
|
|
50
|
+
...esmVars(tree)
|
|
49
51
|
}, {
|
|
50
52
|
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
51
53
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/ts/agent/gateway-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { readAgentCoreGatewayMetadata } from '../../../agentcore-gateway/generator';\nimport {\n AGENT_CONNECTION_PROJECT_DIR,\n addTypeScriptClientToAgent,\n addTypeScriptCoreClient,\n ensureTypeScriptAgentConnectionProject,\n} from '../../../utils/agent-connection/agent-connection';\nimport { addDestructuredImport, addStarExport } from '../../../utils/ast';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { kebabCase } from '../../../utils/names';\nimport { getNpmScope } from '../../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { withVersions } from '../../../utils/versions';\nimport type { TsAgentGatewayConnectionGeneratorSchema } from './schema';\n\nexport const TS_AGENT_GATEWAY_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const tsAgentGatewayConnectionGenerator = async (\n tree: Tree,\n options: TsAgentGatewayConnectionGeneratorSchema,\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 agentComponent = options.sourceComponent;\n if (!agentComponent) {\n throw new Error(\n 'sourceComponent must be provided for ts#agent -> agentcore-gateway connections',\n );\n }\n const gateway = readAgentCoreGatewayMetadata(targetProject);\n\n if (gateway.protocol !== 'mcp') {\n throw new Error(\n `Gateway '${gateway.name}' has protocol='${gateway.protocol}'. Only MCP-protocol gateways are supported.`,\n );\n }\n if (gateway.auth !== 'iam') {\n throw new Error(\n `Gateway '${gateway.name}' uses auth='${gateway.auth}'. Only IAM-authenticated gateways are supported in v1.`,\n );\n }\n if (agentComponent.auth && agentComponent.auth !== 'iam') {\n throw new Error(\n `Agent '${agentComponent.name}' uses auth='${agentComponent.auth}'. Only IAM-authenticated agents can connect to IAM gateways.`,\n );\n }\n\n const gatewayClassName = gateway.rc;\n const gatewayKebabCase = kebabCase(gatewayClassName);\n // A gateway is its own standalone project, so it exposes plain serve / dev.\n const gatewayServeTargetName = 'serve';\n const gatewayDevTargetName = 'dev';\n\n const npmScope = getNpmScope(tree);\n\n // 1. Ensure the shared agent-connection project exists + has the gateway\n // core client template.\n await ensureTypeScriptAgentConnectionProject(tree);\n await addTypeScriptCoreClient(tree, 'gateway');\n\n // 2. Generate the per-connection <Gateway>Client into app/. Local mode\n // points at the gateway project's local gateway port.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'),\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'),\n {\n gatewayKebabCase,\n gatewayClassName,\n gatewayPort: gateway.port,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Re-export from the agent-connection index\n await addStarExport(\n tree,\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'index.ts'),\n `./app/${gatewayKebabCase}-client-strands.js`,\n );\n\n // 3. AST-transform agent.ts to add the gateway client (an McpClient in\n // both deployed and local modes) to the agent's tools.\n const agentSourceDir = joinPathFragments(\n sourceProject.root,\n agentComponent.path ?? 'src',\n );\n const agentFilePath = joinPathFragments(agentSourceDir, 'agent.ts');\n\n if (tree.exists(agentFilePath)) {\n const clientClassName = `${gatewayClassName}ClientStrands`;\n const clientVarName =\n gatewayClassName.charAt(0).toLowerCase() + gatewayClassName.slice(1);\n\n await addDestructuredImport(\n tree,\n agentFilePath,\n [clientClassName],\n `:${npmScope}/agent-connection`,\n );\n await addTypeScriptClientToAgent(\n tree,\n agentFilePath,\n clientClassName,\n clientVarName,\n );\n }\n\n // 4. Wire dev chain — agent's dev depends on gateway's\n // aggregator target, which transitively starts each attached MCP server.\n const agentName = agentComponent.name ?? 'agent';\n const serveTargetName = `${agentName}-serve`;\n const devTargetName = `${agentName}-dev`;\n let projectConfigChanged = false;\n if (sourceProject.targets?.[serveTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, serveTargetName, {\n projects: [targetProject.name],\n target: gatewayServeTargetName,\n });\n projectConfigChanged = true;\n }\n if (sourceProject.targets?.[devTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, devTargetName, {\n projects: [targetProject.name],\n target: gatewayDevTargetName,\n });\n projectConfigChanged = true;\n }\n if (projectConfigChanged) {\n updateProjectConfiguration(tree, sourceProject.name, sourceProject);\n }\n\n // 5. Dependencies\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@modelcontextprotocol/sdk',\n '@strands-agents/sdk',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n ]),\n {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n TS_AGENT_GATEWAY_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentGatewayConnectionGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","readAgentCoreGatewayMetadata","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptClientToAgent","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","getNpmScope","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","withVersions","TS_AGENT_GATEWAY_CONNECTION_GENERATOR_INFO","filename","tsAgentGatewayConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","Error","gateway","protocol","name","auth","gatewayClassName","rc","gatewayKebabCase","gatewayServeTargetName","gatewayDevTargetName","npmScope","dirname","gatewayPort","port","overwriteStrategy","KeepExisting","agentSourceDir","root","path","agentFilePath","exists","clientClassName","clientVarName","charAt","toLowerCase","slice","agentName","serveTargetName","devTargetName","projectConfigChanged","targets","projects","target","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,4BAA4B,QAAQ,0CAAuC;AACpF,SACEC,4BAA4B,EAC5BC,0BAA0B,EAC1BC,uBAAuB,EACvBC,sCAAsC,QACjC,sDAAmD;AAC1D,SAASC,qBAAqB,EAAEC,aAAa,QAAQ,wBAAq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ChEI,UAAU;gBAAClC,cAAcM,IAAI;aAAC;YAC9B6B,QAAQxB;QACV;QACAqB,uBAAuB;IACzB;IACA,IAAIjC,cAAckC,OAAO,EAAE,CAACF,cAAc,EAAE;QAC1CzC,kCAAkCS,eAAegC,eAAe;YAC9DG,UAAU;gBAAClC,cAAcM,IAAI;aAAC;YAC9B6B,QAAQvB;QACV;QACAoB,uBAAuB;IACzB;IACA,IAAIA,sBAAsB;QACxBvD,2BAA2BoB,MAAME,cAAcO,IAAI,EAAEP;IACvD;IAEA,kBAAkB;IAClB1B,6BACEwB,MACAJ,aAAa;QACX;QACA;QACA;QACA;QACA;QACA;KACD,GACD,CAAC;IAGH,MAAMN,gCAAgCU,MAAM;QAC1CH;KACD;IAED,MAAMT,qBAAqBY;IAC3B,OAAO,IACLX,oBAAoBW,MAAMC,QAAQsC,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAezC,kCAAkC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/ts/agent/gateway-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { readAgentCoreGatewayMetadata } from '../../../agentcore-gateway/generator';\nimport {\n AGENT_CONNECTION_PROJECT_DIR,\n addTypeScriptClientToAgent,\n addTypeScriptCoreClient,\n ensureTypeScriptAgentConnectionProject,\n} from '../../../utils/agent-connection/agent-connection';\nimport { addDestructuredImport, addStarExport } from '../../../utils/ast';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { esmVars } from '../../../utils/module-format';\nimport { kebabCase } from '../../../utils/names';\nimport { getNpmScope } from '../../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { withVersions } from '../../../utils/versions';\nimport type { TsAgentGatewayConnectionGeneratorSchema } from './schema';\n\nexport const TS_AGENT_GATEWAY_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const tsAgentGatewayConnectionGenerator = async (\n tree: Tree,\n options: TsAgentGatewayConnectionGeneratorSchema,\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 agentComponent = options.sourceComponent;\n if (!agentComponent) {\n throw new Error(\n 'sourceComponent must be provided for ts#agent -> agentcore-gateway connections',\n );\n }\n const gateway = readAgentCoreGatewayMetadata(targetProject);\n\n if (gateway.protocol !== 'mcp') {\n throw new Error(\n `Gateway '${gateway.name}' has protocol='${gateway.protocol}'. Only MCP-protocol gateways are supported.`,\n );\n }\n if (gateway.auth !== 'iam') {\n throw new Error(\n `Gateway '${gateway.name}' uses auth='${gateway.auth}'. Only IAM-authenticated gateways are supported in v1.`,\n );\n }\n if (agentComponent.auth && agentComponent.auth !== 'iam') {\n throw new Error(\n `Agent '${agentComponent.name}' uses auth='${agentComponent.auth}'. Only IAM-authenticated agents can connect to IAM gateways.`,\n );\n }\n\n const gatewayClassName = gateway.rc;\n const gatewayKebabCase = kebabCase(gatewayClassName);\n // A gateway is its own standalone project, so it exposes plain serve / dev.\n const gatewayServeTargetName = 'serve';\n const gatewayDevTargetName = 'dev';\n\n const npmScope = getNpmScope(tree);\n\n // 1. Ensure the shared agent-connection project exists + has the gateway\n // core client template.\n await ensureTypeScriptAgentConnectionProject(tree);\n await addTypeScriptCoreClient(tree, 'gateway');\n\n // 2. Generate the per-connection <Gateway>Client into app/. Local mode\n // points at the gateway project's local gateway port.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'),\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'),\n {\n gatewayKebabCase,\n gatewayClassName,\n gatewayPort: gateway.port,\n ...esmVars(tree),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Re-export from the agent-connection index\n await addStarExport(\n tree,\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'index.ts'),\n `./app/${gatewayKebabCase}-client-strands.js`,\n );\n\n // 3. AST-transform agent.ts to add the gateway client (an McpClient in\n // both deployed and local modes) to the agent's tools.\n const agentSourceDir = joinPathFragments(\n sourceProject.root,\n agentComponent.path ?? 'src',\n );\n const agentFilePath = joinPathFragments(agentSourceDir, 'agent.ts');\n\n if (tree.exists(agentFilePath)) {\n const clientClassName = `${gatewayClassName}ClientStrands`;\n const clientVarName =\n gatewayClassName.charAt(0).toLowerCase() + gatewayClassName.slice(1);\n\n await addDestructuredImport(\n tree,\n agentFilePath,\n [clientClassName],\n `:${npmScope}/agent-connection`,\n );\n await addTypeScriptClientToAgent(\n tree,\n agentFilePath,\n clientClassName,\n clientVarName,\n );\n }\n\n // 4. Wire dev chain — agent's dev depends on gateway's\n // aggregator target, which transitively starts each attached MCP server.\n const agentName = agentComponent.name ?? 'agent';\n const serveTargetName = `${agentName}-serve`;\n const devTargetName = `${agentName}-dev`;\n let projectConfigChanged = false;\n if (sourceProject.targets?.[serveTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, serveTargetName, {\n projects: [targetProject.name],\n target: gatewayServeTargetName,\n });\n projectConfigChanged = true;\n }\n if (sourceProject.targets?.[devTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, devTargetName, {\n projects: [targetProject.name],\n target: gatewayDevTargetName,\n });\n projectConfigChanged = true;\n }\n if (projectConfigChanged) {\n updateProjectConfiguration(tree, sourceProject.name, sourceProject);\n }\n\n // 5. Dependencies\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@modelcontextprotocol/sdk',\n '@strands-agents/sdk',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n ]),\n {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n TS_AGENT_GATEWAY_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentGatewayConnectionGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","readAgentCoreGatewayMetadata","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptClientToAgent","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","getNpmScope","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","withVersions","TS_AGENT_GATEWAY_CONNECTION_GENERATOR_INFO","filename","tsAgentGatewayConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","Error","gateway","protocol","name","auth","gatewayClassName","rc","gatewayKebabCase","gatewayServeTargetName","gatewayDevTargetName","npmScope","dirname","gatewayPort","port","overwriteStrategy","KeepExisting","agentSourceDir","root","path","agentFilePath","exists","clientClassName","clientVarName","charAt","toLowerCase","slice","agentName","serveTargetName","devTargetName","projectConfigChanged","targets","projects","target","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,4BAA4B,QAAQ,0CAAuC;AACpF,SACEC,4BAA4B,EAC5BC,0BAA0B,EAC1BC,uBAAuB,EACvBC,sCAAsC,QACjC,sDA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ACxC,IAAIG,uBAAuB;IAC3B,IAAIjC,cAAckC,OAAO,EAAE,CAACH,gBAAgB,EAAE;QAC5CxC,kCAAkCS,eAAe+B,iBAAiB;YAChEI,UAAU;gBAAClC,cAAcM,IAAI;aAAC;YAC9B6B,QAAQxB;QACV;QACAqB,uBAAuB;IACzB;IACA,IAAIjC,cAAckC,OAAO,EAAE,CAACF,cAAc,EAAE;QAC1CzC,kCAAkCS,eAAegC,eAAe;YAC9DG,UAAU;gBAAClC,cAAcM,IAAI;aAAC;YAC9B6B,QAAQvB;QACV;QACAoB,uBAAuB;IACzB;IACA,IAAIA,sBAAsB;QACxBxD,2BAA2BqB,MAAME,cAAcO,IAAI,EAAEP;IACvD;IAEA,kBAAkB;IAClB3B,6BACEyB,MACAJ,aAAa;QACX;QACA;QACA;QACA;QACA;QACA;KACD,GACD,CAAC;IAGH,MAAMP,gCAAgCW,MAAM;QAC1CH;KACD;IAED,MAAMV,qBAAqBa;IAC3B,OAAO,IACLZ,oBAAoBY,MAAMC,QAAQsC,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAezC,kCAAkC"}
|
|
@@ -12,6 +12,7 @@ import { FsCommands } from "../../utils/fs.js";
|
|
|
12
12
|
import { resolveIac } from "../../utils/iac.js";
|
|
13
13
|
import { installDependencies } from "../../utils/install.js";
|
|
14
14
|
import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
|
|
15
|
+
import { esmVars } from "../../utils/module-format.js";
|
|
15
16
|
import { kebabCase, toClassName } from "../../utils/names.js";
|
|
16
17
|
import { getNpmScope } from "../../utils/npm-scope.js";
|
|
17
18
|
import { addComponentDevTarget, addComponentGeneratorMetadata, addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
|
|
@@ -51,7 +52,8 @@ export const tsAgentGenerator = async (tree, options)=>{
|
|
|
51
52
|
name,
|
|
52
53
|
agentNameClassName,
|
|
53
54
|
distDir,
|
|
54
|
-
agentConnectionImport: `:${getNpmScope(tree)}/agent-connection
|
|
55
|
+
agentConnectionImport: `:${getNpmScope(tree)}/agent-connection`,
|
|
56
|
+
...esmVars(tree)
|
|
55
57
|
};
|
|
56
58
|
// Generate common files shared by both protocols
|
|
57
59
|
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'common'), targetSourceDir, templateContext, {
|
|
@@ -74,7 +76,8 @@ export const tsAgentGenerator = async (tree, options)=>{
|
|
|
74
76
|
distDir,
|
|
75
77
|
name,
|
|
76
78
|
protocol,
|
|
77
|
-
adotVersion: TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation']
|
|
79
|
+
adotVersion: TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],
|
|
80
|
+
...esmVars(tree)
|
|
78
81
|
}, {
|
|
79
82
|
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
80
83
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/agent/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addAgentChatScripts } from '../../utils/agent-chat/agent-chat';\nimport {\n addTypeScriptFrameworkBase,\n ensureTypeScriptAgentConnectionProject,\n} from '../../utils/agent-connection/agent-connection';\nimport { addAgentInfra } from '../../utils/agent-core-constructs/agent-core-constructs';\nimport { addTypeScriptBundleTarget } from '../../utils/bundle/bundle';\nimport { resolveContainers } from '../../utils/containers';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FsCommands } from '../../utils/fs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addComponentDevTarget,\n addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { assignPort } from '../../utils/port';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport { TS_VERSIONS, withVersions } from '../../utils/versions';\nimport type { TsAgentGeneratorSchema } from './schema';\n\nexport const TS_AGENT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsAgentGenerator = async (\n tree: Tree,\n options: TsAgentGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const project = readProjectConfigurationUnqualified(tree, options.project);\n\n if (!tree.exists(joinPathFragments(project.root, 'tsconfig.json'))) {\n throw new Error(\n `Unsupported project ${options.project}. Expected a TypeScript project (with a tsconfig.json)`,\n );\n }\n\n const defaultName = `${kebabCase(project.name.split('/').pop())}-agent`;\n const name = kebabCase(options.name || defaultName);\n const agentNameClassName = toClassName(name);\n const agentTargetPrefix = options.name ? name : 'agent';\n const targetSourceDirRelativeToProjectRoot = joinPathFragments(\n 'src',\n agentTargetPrefix,\n );\n const targetSourceDir = joinPathFragments(\n project.root,\n targetSourceDirRelativeToProjectRoot,\n );\n const relativeSourceDir = targetSourceDir.replace(project.root + '/', './');\n const distDir = joinPathFragments('dist', project.root);\n\n const infra = options.infra ?? 'agentcore';\n const protocol = options.protocol ?? 'http';\n\n if (infra === 'none' && options.auth && options.auth !== 'iam') {\n console.warn(\n 'Warning: auth is ignored when no infrastructure is configured (no infrastructure is generated)',\n );\n }\n\n const auth = options.auth ?? 'iam';\n\n // Ensure the shared agent-connection project exists so the server entry\n // point can import `runWithSessionId` and propagate the AgentCore session\n // ID to any downstream MCP / A2A clients a later connection generator\n // wires into this agent.\n await ensureTypeScriptAgentConnectionProject(tree);\n // The agent server imports the framework base helpers (session cache + model\n // error logging) regardless of whether a connection client is wired in.\n await addTypeScriptFrameworkBase(tree);\n\n const templateContext = {\n name,\n agentNameClassName,\n distDir,\n agentConnectionImport: `:${getNpmScope(tree)}/agent-connection`,\n };\n\n // Generate common files shared by both protocols\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'common'),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Generate protocol-specific files\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', protocol.toLowerCase()),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n if (infra === 'agentcore') {\n const containers = await resolveContainers(tree, 'inherit');\n const dockerImageTag = `${getNpmScope(tree)}-${name}:latest`;\n\n // Add bundle target\n await addTypeScriptBundleTarget(tree, project, {\n targetFilePath: `${targetSourceDirRelativeToProjectRoot}/index.ts`,\n bundleOutputDir: joinPathFragments('agent', name),\n });\n\n // Add the Dockerfile\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'deploy'),\n targetSourceDir,\n {\n distDir,\n name,\n protocol,\n adotVersion:\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'bundle',\n 'agent',\n name,\n );\n const dockerTargetName = `${agentTargetPrefix}-docker`;\n\n const fs = new FsCommands(tree);\n project.targets[dockerTargetName] = {\n cache: true,\n outputs: [`{workspaceRoot}/${dockerOutputDir}/Dockerfile`],\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.cp(\n `${targetSourceDir}/Dockerfile`,\n `${dockerOutputDir}/Dockerfile`,\n ),\n `${containers} build --platform linux/arm64 -t ${dockerImageTag} ${dockerOutputDir}`,\n ],\n parallel: false,\n },\n dependsOn: ['bundle'],\n };\n\n addDependencyToTargetIfNotPresent(project, 'docker', dockerTargetName);\n addDependencyToTargetIfNotPresent(project, 'build', 'docker');\n\n // Add shared constructs\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, { iac });\n\n // AG-UI uses HTTP as the AgentCore protocol type (AG-UI is HTTP-based with SSE over POST).\n const infraProtocol: 'http' | 'a2a' =\n protocol === 'ag-ui' ? 'http' : (protocol as 'http' | 'a2a');\n\n await addAgentInfra(tree, {\n agentNameKebabCase: name,\n agentNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n serverProtocol: infraProtocol,\n containers,\n });\n }\n\n // Add dependencies\n addDependenciesToPackageJson(\n tree,\n withVersions([\n 'zod',\n '@strands-agents/sdk',\n '@aws-sdk/credential-providers',\n '@aws-sdk/client-appconfigdata',\n '@aws-lambda-powertools/parameters',\n '@modelcontextprotocol/sdk',\n ...(protocol === 'a2a'\n ? (['express', '@a2a-js/sdk'] as const)\n : protocol === 'ag-ui'\n ? ([\n '@ag-ui/aws-strands',\n '@ag-ui/core',\n '@ag-ui/encoder',\n 'express',\n 'cors',\n ] as const)\n : ([\n '@trpc/server',\n '@trpc/client',\n 'ws',\n 'cors',\n 'aws4fetch',\n ] as const)),\n ]),\n withVersions([\n // The chat CLI runs standalone via tsx for every protocol, and resolves\n // the deployed agent from AppConfig when `RUNTIME_CONFIG_APP_ID` is set.\n 'tsx',\n '@types/node',\n 'agent-chat-cli',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n ...(auth === 'iam'\n ? (['aws4fetch', '@aws-sdk/credential-providers'] as const)\n : ([] as const)),\n // A2A chat builds a signed @a2a-js client factory for the deployed agent.\n ...(protocol === 'a2a' ? (['@a2a-js/sdk'] as const) : ([] as const)),\n ...(protocol === 'a2a' || protocol === 'ag-ui'\n ? (['@types/express', '@types/cors'] as const)\n : (['@types/ws', '@types/cors'] as const)),\n ]),\n );\n\n // A2A servers use port 9000 as per the Strands A2A SDK default and AgentCore A2A contract.\n // HTTP and AG-UI agents use port 8081+ to avoid conflict with VS Code server on 8080.\n const localDevPortStart = protocol === 'a2a' ? 9000 : 8081;\n const localDevPort = assignPort(tree, project, localDevPortStart, {\n component: { info: TS_AGENT_GENERATOR_INFO, name: agentTargetPrefix },\n });\n\n // Every protocol gets a standalone `chat.ts`. It connects to the local\n // `dev` server by default, or to the deployed agent (with the\n // appropriate auth) when `RUNTIME_CONFIG_APP_ID` is set.\n const scriptsDir = joinPathFragments(\n project.root,\n 'scripts',\n agentTargetPrefix,\n );\n addAgentChatScripts(tree, {\n scriptsDir,\n protocol,\n language: 'ts',\n agentNameClassName,\n auth,\n relativeAgentImport: `../../${targetSourceDirRelativeToProjectRoot}`,\n });\n\n const chatUrl =\n protocol === 'http'\n ? `ws://localhost:${localDevPort}/ws`\n : protocol === 'ag-ui'\n ? `http://localhost:${localDevPort}/invocations`\n : `http://localhost:${localDevPort}`;\n const chatCommand = `tsx ./scripts/${agentTargetPrefix}/chat.ts`;\n\n const agentTargets = {\n ...project.targets,\n [`${agentTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/index.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${agentTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/index.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${agentTargetPrefix}-chat`]: {\n executor: 'nx:run-commands',\n options: {\n commands: [chatCommand],\n cwd: '{projectRoot}',\n env: {\n URL: chatUrl,\n },\n },\n },\n };\n\n // Aggregate `<agent>-dev` under the project-level `dev` target.\n addComponentDevTarget(agentTargets, `${agentTargetPrefix}-dev`);\n\n updateProjectConfiguration(tree, project.name, {\n ...project,\n // Sort targets so their order is stable regardless of insertion order on\n // first run vs re-run.\n targets: sortObjectKeys(agentTargets),\n });\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n TS_AGENT_GENERATOR_INFO,\n targetSourceDirRelativeToProjectRoot,\n agentTargetPrefix,\n { port: localDevPort, rc: agentNameClassName, auth, protocol },\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_AGENT_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addAgentChatScripts","addTypeScriptFrameworkBase","ensureTypeScriptAgentConnectionProject","addAgentInfra","addTypeScriptBundleTarget","resolveContainers","formatFilesInSubtree","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","getNpmScope","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","assignPort","sharedConstructsGenerator","TS_VERSIONS","withVersions","TS_AGENT_GENERATOR_INFO","filename","tsAgentGenerator","tree","options","project","exists","root","Error","defaultName","name","split","pop","agentNameClassName","agentTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","protocol","auth","console","warn","templateContext","agentConnectionImport","dirname","overwriteStrategy","KeepExisting","toLowerCase","containers","dockerImageTag","targetFilePath","bundleOutputDir","adotVersion","dockerOutputDir","dockerTargetName","fs","targets","cache","outputs","executor","commands","cp","parallel","dependsOn","iac","infraProtocol","agentNameKebabCase","projectName","serverProtocol","localDevPortStart","localDevPort","component","info","scriptsDir","language","relativeAgentImport","chatUrl","chatCommand","agentTargets","continuous","cwd","env","PORT","LOCAL_DEV","URL","port","rc","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC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;YACZ1D,SAAS;gBACPuC,UAAU;oBAAC,CAAC,YAAY,EAAE1B,kBAAkB,SAAS,CAAC;iBAAC;gBACvD8C,KAAK;gBACLC,KAAK;oBACHC,MAAM,GAAGZ,cAAc;gBACzB;YACF;QACF;QACA,CAAC,GAAGvC,kBAAkB,IAAI,CAAC,CAAC,EAAE;YAC5B4B,UAAU;YACVoB,YAAY;YACZ1D,SAAS;gBACPuC,UAAU;oBAAC,CAAC,YAAY,EAAE1B,kBAAkB,SAAS,CAAC;iBAAC;gBACvD8C,KAAK;gBACLC,KAAK;oBACHC,MAAM,GAAGZ,cAAc;oBACvBa,WAAW;gBACb;YACF;QACF;QACA,CAAC,GAAGpD,kBAAkB,KAAK,CAAC,CAAC,EAAE;YAC7B4B,UAAU;YACVtC,SAAS;gBACPuC,UAAU;oBAACiB;iBAAY;gBACvBG,KAAK;gBACLC,KAAK;oBACHG,KAAKR;gBACP;YACF;QACF;IACF;IAEA,gEAAgE;IAChErE,sBAAsBuE,cAAc,GAAG/C,kBAAkB,IAAI,CAAC;IAE9DvC,2BAA2B4B,MAAME,QAAQK,IAAI,EAAE;QAC7C,GAAGL,OAAO;QACV,yEAAyE;QACzE,uBAAuB;QACvBkC,SAAS5C,eAAekE;IAC1B;IAEAtE,8BACEY,MACAE,QAAQK,IAAI,EACZV,yBACAe,sCACAD,mBACA;QAAEsD,MAAMf;QAAcgB,IAAIxD;QAAoBS;QAAMD;IAAS;IAG/D,MAAMnC,gCAAgCiB,MAAM;QAACH;KAAwB;IAErE,MAAMlB,qBAAqBqB;IAC3B,OAAO,IACLlB,oBAAoBkB,MAAMC,QAAQkE,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAerE,iBAAiB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/agent/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addAgentChatScripts } from '../../utils/agent-chat/agent-chat';\nimport {\n addTypeScriptFrameworkBase,\n ensureTypeScriptAgentConnectionProject,\n} from '../../utils/agent-connection/agent-connection';\nimport { addAgentInfra } from '../../utils/agent-core-constructs/agent-core-constructs';\nimport { addTypeScriptBundleTarget } from '../../utils/bundle/bundle';\nimport { resolveContainers } from '../../utils/containers';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FsCommands } from '../../utils/fs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { esmVars } from '../../utils/module-format';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addComponentDevTarget,\n addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { assignPort } from '../../utils/port';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport { TS_VERSIONS, withVersions } from '../../utils/versions';\nimport type { TsAgentGeneratorSchema } from './schema';\n\nexport const TS_AGENT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsAgentGenerator = async (\n tree: Tree,\n options: TsAgentGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const project = readProjectConfigurationUnqualified(tree, options.project);\n\n if (!tree.exists(joinPathFragments(project.root, 'tsconfig.json'))) {\n throw new Error(\n `Unsupported project ${options.project}. Expected a TypeScript project (with a tsconfig.json)`,\n );\n }\n\n const defaultName = `${kebabCase(project.name.split('/').pop())}-agent`;\n const name = kebabCase(options.name || defaultName);\n const agentNameClassName = toClassName(name);\n const agentTargetPrefix = options.name ? name : 'agent';\n const targetSourceDirRelativeToProjectRoot = joinPathFragments(\n 'src',\n agentTargetPrefix,\n );\n const targetSourceDir = joinPathFragments(\n project.root,\n targetSourceDirRelativeToProjectRoot,\n );\n const relativeSourceDir = targetSourceDir.replace(project.root + '/', './');\n const distDir = joinPathFragments('dist', project.root);\n\n const infra = options.infra ?? 'agentcore';\n const protocol = options.protocol ?? 'http';\n\n if (infra === 'none' && options.auth && options.auth !== 'iam') {\n console.warn(\n 'Warning: auth is ignored when no infrastructure is configured (no infrastructure is generated)',\n );\n }\n\n const auth = options.auth ?? 'iam';\n\n // Ensure the shared agent-connection project exists so the server entry\n // point can import `runWithSessionId` and propagate the AgentCore session\n // ID to any downstream MCP / A2A clients a later connection generator\n // wires into this agent.\n await ensureTypeScriptAgentConnectionProject(tree);\n // The agent server imports the framework base helpers (session cache + model\n // error logging) regardless of whether a connection client is wired in.\n await addTypeScriptFrameworkBase(tree);\n\n const templateContext = {\n name,\n agentNameClassName,\n distDir,\n agentConnectionImport: `:${getNpmScope(tree)}/agent-connection`,\n ...esmVars(tree),\n };\n\n // Generate common files shared by both protocols\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'common'),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Generate protocol-specific files\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', protocol.toLowerCase()),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n if (infra === 'agentcore') {\n const containers = await resolveContainers(tree, 'inherit');\n const dockerImageTag = `${getNpmScope(tree)}-${name}:latest`;\n\n // Add bundle target\n await addTypeScriptBundleTarget(tree, project, {\n targetFilePath: `${targetSourceDirRelativeToProjectRoot}/index.ts`,\n bundleOutputDir: joinPathFragments('agent', name),\n });\n\n // Add the Dockerfile\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'deploy'),\n targetSourceDir,\n {\n distDir,\n name,\n protocol,\n adotVersion:\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],\n ...esmVars(tree),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'bundle',\n 'agent',\n name,\n );\n const dockerTargetName = `${agentTargetPrefix}-docker`;\n\n const fs = new FsCommands(tree);\n project.targets[dockerTargetName] = {\n cache: true,\n outputs: [`{workspaceRoot}/${dockerOutputDir}/Dockerfile`],\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.cp(\n `${targetSourceDir}/Dockerfile`,\n `${dockerOutputDir}/Dockerfile`,\n ),\n `${containers} build --platform linux/arm64 -t ${dockerImageTag} ${dockerOutputDir}`,\n ],\n parallel: false,\n },\n dependsOn: ['bundle'],\n };\n\n addDependencyToTargetIfNotPresent(project, 'docker', dockerTargetName);\n addDependencyToTargetIfNotPresent(project, 'build', 'docker');\n\n // Add shared constructs\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, { iac });\n\n // AG-UI uses HTTP as the AgentCore protocol type (AG-UI is HTTP-based with SSE over POST).\n const infraProtocol: 'http' | 'a2a' =\n protocol === 'ag-ui' ? 'http' : (protocol as 'http' | 'a2a');\n\n await addAgentInfra(tree, {\n agentNameKebabCase: name,\n agentNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n serverProtocol: infraProtocol,\n containers,\n });\n }\n\n // Add dependencies\n addDependenciesToPackageJson(\n tree,\n withVersions([\n 'zod',\n '@strands-agents/sdk',\n '@aws-sdk/credential-providers',\n '@aws-sdk/client-appconfigdata',\n '@aws-lambda-powertools/parameters',\n '@modelcontextprotocol/sdk',\n ...(protocol === 'a2a'\n ? (['express', '@a2a-js/sdk'] as const)\n : protocol === 'ag-ui'\n ? ([\n '@ag-ui/aws-strands',\n '@ag-ui/core',\n '@ag-ui/encoder',\n 'express',\n 'cors',\n ] as const)\n : ([\n '@trpc/server',\n '@trpc/client',\n 'ws',\n 'cors',\n 'aws4fetch',\n ] as const)),\n ]),\n withVersions([\n // The chat CLI runs standalone via tsx for every protocol, and resolves\n // the deployed agent from AppConfig when `RUNTIME_CONFIG_APP_ID` is set.\n 'tsx',\n '@types/node',\n 'agent-chat-cli',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n ...(auth === 'iam'\n ? (['aws4fetch', '@aws-sdk/credential-providers'] as const)\n : ([] as const)),\n // A2A chat builds a signed @a2a-js client factory for the deployed agent.\n ...(protocol === 'a2a' ? (['@a2a-js/sdk'] as const) : ([] as const)),\n ...(protocol === 'a2a' || protocol === 'ag-ui'\n ? (['@types/express', '@types/cors'] as const)\n : (['@types/ws', '@types/cors'] as const)),\n ]),\n );\n\n // A2A servers use port 9000 as per the Strands A2A SDK default and AgentCore A2A contract.\n // HTTP and AG-UI agents use port 8081+ to avoid conflict with VS Code server on 8080.\n const localDevPortStart = protocol === 'a2a' ? 9000 : 8081;\n const localDevPort = assignPort(tree, project, localDevPortStart, {\n component: { info: TS_AGENT_GENERATOR_INFO, name: agentTargetPrefix },\n });\n\n // Every protocol gets a standalone `chat.ts`. It connects to the local\n // `dev` server by default, or to the deployed agent (with the\n // appropriate auth) when `RUNTIME_CONFIG_APP_ID` is set.\n const scriptsDir = joinPathFragments(\n project.root,\n 'scripts',\n agentTargetPrefix,\n );\n addAgentChatScripts(tree, {\n scriptsDir,\n protocol,\n language: 'ts',\n agentNameClassName,\n auth,\n relativeAgentImport: `../../${targetSourceDirRelativeToProjectRoot}`,\n });\n\n const chatUrl =\n protocol === 'http'\n ? `ws://localhost:${localDevPort}/ws`\n : protocol === 'ag-ui'\n ? `http://localhost:${localDevPort}/invocations`\n : `http://localhost:${localDevPort}`;\n const chatCommand = `tsx ./scripts/${agentTargetPrefix}/chat.ts`;\n\n const agentTargets = {\n ...project.targets,\n [`${agentTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/index.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${agentTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/index.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${agentTargetPrefix}-chat`]: {\n executor: 'nx:run-commands',\n options: {\n commands: [chatCommand],\n cwd: '{projectRoot}',\n env: {\n URL: chatUrl,\n },\n },\n },\n };\n\n // Aggregate `<agent>-dev` under the project-level `dev` target.\n addComponentDevTarget(agentTargets, `${agentTargetPrefix}-dev`);\n\n updateProjectConfiguration(tree, project.name, {\n ...project,\n // Sort targets so their order is stable regardless of insertion order on\n // first run vs re-run.\n targets: sortObjectKeys(agentTargets),\n });\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n TS_AGENT_GENERATOR_INFO,\n targetSourceDirRelativeToProjectRoot,\n agentTargetPrefix,\n { port: localDevPort, rc: agentNameClassName, auth, protocol },\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_AGENT_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addAgentChatScripts","addTypeScriptFrameworkBase","ensureTypeScriptAgentConnectionProject","addAgentInfra","addTypeScriptBundleTarget","resolveContainers","formatFilesInSubtree","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","toClassName","getNpmScope","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","assignPort","sharedConstructsGenerator","TS_VERSIONS","withVersions","TS_AGENT_GENERATOR_INFO","filename","tsAgentGenerator","tree","options","project","exists","root","Error","defaultName","name","split","pop","agentNameClassName","agentTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","protocol","auth","console","warn","templateContext","agentConnectionImport","dirname","overwriteStrategy","KeepExisting","toLowerCase","containers","dockerImageTag","targetFilePath","bundleOutputDir","adotVersion","dockerOutputDir","dockerTargetName","fs","targets","cache","outputs","executor","commands","cp","parallel","dependsOn","iac","infraProtocol","agentNameKebabCase","projectName","serverProtocol","localDevPortStart","localDevPort","component","info","scriptsDir","language","relativeAgentImport","chatUrl","chatCommand","agentTargets","continuous","cwd","env","PORT","LOCAL_DEV","URL","port","rc","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,mBAAmB,QAAQ,uCAAoC;AACxE,SACEC,0BAA0B,EAC1BC,sCAAsC,QACjC,mDAAgD;AACvD,SAASC,aAAa,QAAQ,6DAA0D;AACxF,SAASC,yBAAyB,QAAQ,+BAA4B;AACtE,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,oBAAiB;AAC5C,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,OAAO,QAAQ,+BAA4B;AACpD,SAASC,SAAS,EAAEC,WAAW,QAAQ,uBAAoB;AAC3D,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,qBAAqB,EACrBC,6BAA6B,EAC7BC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,cAAc,QAAQ,w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AAgE;IAChErE,sBAAsBuE,cAAc,GAAG/C,kBAAkB,IAAI,CAAC;IAE9DxC,2BAA2B6B,MAAME,QAAQK,IAAI,EAAE;QAC7C,GAAGL,OAAO;QACV,yEAAyE;QACzE,uBAAuB;QACvBkC,SAAS5C,eAAekE;IAC1B;IAEAtE,8BACEY,MACAE,QAAQK,IAAI,EACZV,yBACAe,sCACAD,mBACA;QAAEsD,MAAMf;QAAcgB,IAAIxD;QAAoBS;QAAMD;IAAS;IAG/D,MAAMpC,gCAAgCkB,MAAM;QAACH;KAAwB;IAErE,MAAMnB,qBAAqBsB;IAC3B,OAAO,IACLnB,oBAAoBmB,MAAMC,QAAQkE,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAerE,iBAAiB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { McpClient } from '@strands-agents/sdk';
|
|
2
|
-
import { AgentCoreMcpClientStrands } from '../core/agentcore-mcp-client-strands
|
|
3
|
-
import { getAgentCoreRuntimeConfig } from '../core/runtime-config
|
|
2
|
+
import { AgentCoreMcpClientStrands } from '../core/agentcore-mcp-client-strands<% if (esm) { %>.js<% } %>';
|
|
3
|
+
import { getAgentCoreRuntimeConfig } from '../core/runtime-config<% if (esm) { %>.js<% } %>';
|
|
4
4
|
|
|
5
5
|
/** Strands client for the <%- mcpServerClassName %> MCP server. */
|
|
6
6
|
export class <%- mcpServerClassName %>ClientStrands {
|
|
@@ -7,6 +7,7 @@ import { addDestructuredImport, addStarExport } from "../../../utils/ast.js";
|
|
|
7
7
|
import { formatFilesInSubtree } from "../../../utils/format.js";
|
|
8
8
|
import { installDependencies } from "../../../utils/install.js";
|
|
9
9
|
import { addGeneratorMetricsIfApplicable } from "../../../utils/metrics.js";
|
|
10
|
+
import { esmVars } from "../../../utils/module-format.js";
|
|
10
11
|
import { kebabCase } from "../../../utils/names.js";
|
|
11
12
|
import { getNpmScope } from "../../../utils/npm-scope.js";
|
|
12
13
|
import { addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../../utils/nx.js";
|
|
@@ -35,7 +36,8 @@ export const tsAgentMcpConnectionGenerator = async (tree, options)=>{
|
|
|
35
36
|
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'), joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'), {
|
|
36
37
|
mcpServerKebabCase,
|
|
37
38
|
mcpServerClassName,
|
|
38
|
-
mcpServerPort
|
|
39
|
+
mcpServerPort,
|
|
40
|
+
...esmVars(tree)
|
|
39
41
|
}, {
|
|
40
42
|
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
41
43
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/ts/agent/mcp-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport {\n AGENT_CONNECTION_PROJECT_DIR,\n addTypeScriptClientToAgent,\n addTypeScriptCoreClient,\n ensureTypeScriptAgentConnectionProject,\n} from '../../../utils/agent-connection/agent-connection';\nimport { addDestructuredImport, addStarExport } from '../../../utils/ast';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { kebabCase } from '../../../utils/names';\nimport { getNpmScope } from '../../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { withVersions } from '../../../utils/versions';\nimport type { TsAgentMcpConnectionGeneratorSchema } from './schema';\n\nexport const TS_AGENT_MCP_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const tsAgentMcpConnectionGenerator = async (\n tree: Tree,\n options: TsAgentMcpConnectionGeneratorSchema,\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 agentComponent = options.sourceComponent;\n const mcpComponent = options.targetComponent;\n\n if (!agentComponent || !mcpComponent) {\n throw new Error(\n 'Both sourceComponent and targetComponent must be provided for ts#agent -> mcp connections',\n );\n }\n\n if (mcpComponent.auth && mcpComponent.auth.toLowerCase() !== 'iam') {\n throw new Error(\n `MCP server connection currently only supports IAM authentication, but '${mcpComponent.name}' uses '${mcpComponent.auth}' authentication.`,\n );\n }\n\n const mcpComponentName = mcpComponent.name ?? 'mcp-server';\n const mcpServerClassName = mcpComponent.rc as string;\n const mcpServerKebabCase = kebabCase(mcpServerClassName);\n const mcpServerPort = mcpComponent.port ?? 8000;\n\n const npmScope = getNpmScope(tree);\n\n // 1. Ensure the shared agent-connection project exists + has the MCP core client\n await ensureTypeScriptAgentConnectionProject(tree);\n await addTypeScriptCoreClient(tree, 'mcp');\n\n // 2. Generate the per-connection <Name>Client into app/\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'),\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'),\n {\n mcpServerKebabCase,\n mcpServerClassName,\n mcpServerPort,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add re-export to index.ts\n await addStarExport(\n tree,\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'index.ts'),\n `./app/${mcpServerKebabCase}-client-strands.js`,\n );\n\n // 3. AST transform agent.ts to add MCP tools\n const agentSourceDir = joinPathFragments(\n sourceProject.root,\n agentComponent.path ?? 'src',\n );\n const agentFilePath = joinPathFragments(agentSourceDir, 'agent.ts');\n\n if (tree.exists(agentFilePath)) {\n const clientClassName = `${mcpServerClassName}ClientStrands`;\n const clientVarName =\n mcpServerClassName.charAt(0).toLowerCase() + mcpServerClassName.slice(1);\n\n // Add import for the client\n await addDestructuredImport(\n tree,\n agentFilePath,\n [clientClassName],\n `:${npmScope}/agent-connection`,\n );\n\n await addTypeScriptClientToAgent(\n tree,\n agentFilePath,\n clientClassName,\n clientVarName,\n );\n }\n\n // 4. Set up dev target\n const agentName = agentComponent.name ?? 'agent';\n const devTargetName = `${agentName}-dev`;\n const mcpDevTargetName = `${mcpComponentName}-dev`;\n\n if (sourceProject.targets?.[devTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, devTargetName, {\n projects: [targetProject.name],\n target: mcpDevTargetName,\n });\n updateProjectConfiguration(tree, sourceProject.name, sourceProject);\n }\n\n // 5. Add dependencies required by the MCP core client + vended client\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@modelcontextprotocol/sdk',\n '@strands-agents/sdk',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n ]),\n {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n TS_AGENT_MCP_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentMcpConnectionGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptClientToAgent","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","getNpmScope","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","withVersions","TS_AGENT_MCP_CONNECTION_GENERATOR_INFO","filename","tsAgentMcpConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","mcpComponent","targetComponent","Error","auth","toLowerCase","name","mcpComponentName","mcpServerClassName","rc","mcpServerKebabCase","mcpServerPort","port","npmScope","dirname","overwriteStrategy","KeepExisting","agentSourceDir","root","path","agentFilePath","exists","clientClassName","clientVarName","charAt","slice","agentName","devTargetName","mcpDevTargetName","targets","projects","target","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SACEC,4BAA4B,EAC5BC,0BAA0B,EAC1BC,uBAAuB,EACvBC,sCAAsC,QACjC,sDAAmD;AAC1D,SAASC,qBAAqB,EAAEC,aAAa,QAAQ,wBAAqB;AAC1E,SAASC,oBAAoB,QAAQ,2BAAwB;AAC7D,SAASC,mBAAmB,QAAQ,4BAAyB;AAC7D,SAASC,+BAA+B,QAAQ,4BAAyB;AACzE,SAASC,SAAS,QAAQ,0BAAuB;AACjD,SAASC,WAAW,QAAQ,8BAA2B;AACvD,SACEC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,uBAAoB;AAC3B,SAASC,YAAY,QAAQ,6BAA0B;AAGvD,OAAO,MAAMC,yCACXH,iBAAiB,YAAYI,QAAQ,EAAE;AAEzC,OAAO,MAAMC,gCAAgC,OAC3CC,MACAC;IAEA,MAAMC,gBAAgBP,oCACpBK,MACAC,QAAQC,aAAa;IAEvB,MAAMC,gBAAgBR,oCACpBK,MACAC,QAAQE,aAAa;IAGvB,MAAMC,iBAAiBH,QAAQI,eAAe;IAC9C,MAAMC,eAAeL,QAAQM,eAAe;IAE5C,IAAI,CAACH,kBAAkB,CAACE,cAAc;QACpC,MAAM,IAAIE,MACR;IAEJ;IAEA,IAAIF,aAAaG,IAAI,IAAIH,aAAaG,IAAI,CAACC,WAAW,OAAO,OAAO;QAClE,MAAM,IAAIF,MACR,CAAC,uEAAuE,EAAEF,aAAaK,IAAI,CAAC,QAAQ,EAAEL,aAAaG,IAAI,CAAC,iBAAiB,CAAC;IAE9I;IAEA,MAAMG,mBAAmBN,aAAaK,IAAI,IAAI;IAC9C,MAAME,qBAAqBP,aAAaQ,EAAE;IAC1C,MAAMC,qBAAqBxB,UAAUsB;IACrC,MAAMG,gBAAgBV,aAAaW,IAAI,IAAI;IAE3C,MAAMC,WAAW1B,YAAYQ;IAE7B,iFAAiF;IACjF,
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/ts/agent/mcp-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport {\n AGENT_CONNECTION_PROJECT_DIR,\n addTypeScriptClientToAgent,\n addTypeScriptCoreClient,\n ensureTypeScriptAgentConnectionProject,\n} from '../../../utils/agent-connection/agent-connection';\nimport { addDestructuredImport, addStarExport } from '../../../utils/ast';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { esmVars } from '../../../utils/module-format';\nimport { kebabCase } from '../../../utils/names';\nimport { getNpmScope } from '../../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { withVersions } from '../../../utils/versions';\nimport type { TsAgentMcpConnectionGeneratorSchema } from './schema';\n\nexport const TS_AGENT_MCP_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const tsAgentMcpConnectionGenerator = async (\n tree: Tree,\n options: TsAgentMcpConnectionGeneratorSchema,\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 agentComponent = options.sourceComponent;\n const mcpComponent = options.targetComponent;\n\n if (!agentComponent || !mcpComponent) {\n throw new Error(\n 'Both sourceComponent and targetComponent must be provided for ts#agent -> mcp connections',\n );\n }\n\n if (mcpComponent.auth && mcpComponent.auth.toLowerCase() !== 'iam') {\n throw new Error(\n `MCP server connection currently only supports IAM authentication, but '${mcpComponent.name}' uses '${mcpComponent.auth}' authentication.`,\n );\n }\n\n const mcpComponentName = mcpComponent.name ?? 'mcp-server';\n const mcpServerClassName = mcpComponent.rc as string;\n const mcpServerKebabCase = kebabCase(mcpServerClassName);\n const mcpServerPort = mcpComponent.port ?? 8000;\n\n const npmScope = getNpmScope(tree);\n\n // 1. Ensure the shared agent-connection project exists + has the MCP core client\n await ensureTypeScriptAgentConnectionProject(tree);\n await addTypeScriptCoreClient(tree, 'mcp');\n\n // 2. Generate the per-connection <Name>Client into app/\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'),\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'),\n {\n mcpServerKebabCase,\n mcpServerClassName,\n mcpServerPort,\n ...esmVars(tree),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add re-export to index.ts\n await addStarExport(\n tree,\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'index.ts'),\n `./app/${mcpServerKebabCase}-client-strands.js`,\n );\n\n // 3. AST transform agent.ts to add MCP tools\n const agentSourceDir = joinPathFragments(\n sourceProject.root,\n agentComponent.path ?? 'src',\n );\n const agentFilePath = joinPathFragments(agentSourceDir, 'agent.ts');\n\n if (tree.exists(agentFilePath)) {\n const clientClassName = `${mcpServerClassName}ClientStrands`;\n const clientVarName =\n mcpServerClassName.charAt(0).toLowerCase() + mcpServerClassName.slice(1);\n\n // Add import for the client\n await addDestructuredImport(\n tree,\n agentFilePath,\n [clientClassName],\n `:${npmScope}/agent-connection`,\n );\n\n await addTypeScriptClientToAgent(\n tree,\n agentFilePath,\n clientClassName,\n clientVarName,\n );\n }\n\n // 4. Set up dev target\n const agentName = agentComponent.name ?? 'agent';\n const devTargetName = `${agentName}-dev`;\n const mcpDevTargetName = `${mcpComponentName}-dev`;\n\n if (sourceProject.targets?.[devTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, devTargetName, {\n projects: [targetProject.name],\n target: mcpDevTargetName,\n });\n updateProjectConfiguration(tree, sourceProject.name, sourceProject);\n }\n\n // 5. Add dependencies required by the MCP core client + vended client\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@modelcontextprotocol/sdk',\n '@strands-agents/sdk',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n ]),\n {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n TS_AGENT_MCP_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentMcpConnectionGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptClientToAgent","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","getNpmScope","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","withVersions","TS_AGENT_MCP_CONNECTION_GENERATOR_INFO","filename","tsAgentMcpConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","mcpComponent","targetComponent","Error","auth","toLowerCase","name","mcpComponentName","mcpServerClassName","rc","mcpServerKebabCase","mcpServerPort","port","npmScope","dirname","overwriteStrategy","KeepExisting","agentSourceDir","root","path","agentFilePath","exists","clientClassName","clientVarName","charAt","slice","agentName","devTargetName","mcpDevTargetName","targets","projects","target","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SACEC,4BAA4B,EAC5BC,0BAA0B,EAC1BC,uBAAuB,EACvBC,sCAAsC,QACjC,sDAAmD;AAC1D,SAASC,qBAAqB,EAAEC,aAAa,QAAQ,wBAAqB;AAC1E,SAASC,oBAAoB,QAAQ,2BAAwB;AAC7D,SAASC,mBAAmB,QAAQ,4BAAyB;AAC7D,SAASC,+BAA+B,QAAQ,4BAAyB;AACzE,SAASC,OAAO,QAAQ,kCAA+B;AACvD,SAASC,SAAS,QAAQ,0BAAuB;AACjD,SAASC,WAAW,QAAQ,8BAA2B;AACvD,SACEC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,uBAAoB;AAC3B,SAASC,YAAY,QAAQ,6BAA0B;AAGvD,OAAO,MAAMC,yCACXH,iBAAiB,YAAYI,QAAQ,EAAE;AAEzC,OAAO,MAAMC,gCAAgC,OAC3CC,MACAC;IAEA,MAAMC,gBAAgBP,oCACpBK,MACAC,QAAQC,aAAa;IAEvB,MAAMC,gBAAgBR,oCACpBK,MACAC,QAAQE,aAAa;IAGvB,MAAMC,iBAAiBH,QAAQI,eAAe;IAC9C,MAAMC,eAAeL,QAAQM,eAAe;IAE5C,IAAI,CAACH,kBAAkB,CAACE,cAAc;QACpC,MAAM,IAAIE,MACR;IAEJ;IAEA,IAAIF,aAAaG,IAAI,IAAIH,aAAaG,IAAI,CAACC,WAAW,OAAO,OAAO;QAClE,MAAM,IAAIF,MACR,CAAC,uEAAuE,EAAEF,aAAaK,IAAI,CAAC,QAAQ,EAAEL,aAA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mB,GAAGrB,iBAAiB,IAAI,CAAC;IAElD,IAAIV,cAAcgC,OAAO,EAAE,CAACF,cAAc,EAAE;QAC1CvC,kCAAkCS,eAAe8B,eAAe;YAC9DG,UAAU;gBAAChC,cAAcQ,IAAI;aAAC;YAC9ByB,QAAQH;QACV;QACArD,2BAA2BoB,MAAME,cAAcS,IAAI,EAAET;IACvD;IAEA,sEAAsE;IACtE1B,6BACEwB,MACAJ,aAAa;QACX;QACA;QACA;QACA;QACA;QACA;KACD,GACD,CAAC;IAGH,MAAMP,gCAAgCW,MAAM;QAC1CH;KACD;IAED,MAAMV,qBAAqBa;IAC3B,OAAO,IACLZ,oBAAoBY,MAAMC,QAAQoC,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAevC,8BAA8B"}
|
|
@@ -44,8 +44,9 @@ interface TranslateConfig {
|
|
|
44
44
|
translationCommitMessage?: string;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
const
|
|
48
|
-
const
|
|
47
|
+
const SCRIPTS_DIR = <% if (esm) { %>import.meta.dirname<% } else { %>__dirname<% } %>;
|
|
48
|
+
const PROJECT_ROOT = path.resolve(SCRIPTS_DIR, '..');
|
|
49
|
+
const CONFIG_PATH = path.resolve(SCRIPTS_DIR, 'translate.config.json');
|
|
49
50
|
const config: TranslateConfig = JSON.parse(
|
|
50
51
|
fs.readFileSync(CONFIG_PATH, 'utf-8'),
|
|
51
52
|
);
|