@aws/nx-plugin 1.0.0-rc.72 → 1.0.0-rc.73
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 +210 -730
- package/migrations.json +34 -24
- package/package.json +4 -4
- package/src/agentcore-gateway/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +3 -3
- package/src/license/config.d.ts +9 -0
- package/src/license/config.js +28 -0
- package/src/license/config.js.map +1 -1
- package/src/license/dependency-check/collectors/collector.js.map +1 -1
- package/src/license/generator.js +3 -17
- package/src/license/generator.js.map +1 -1
- package/src/license/known-exceptions.d.ts +0 -1
- package/src/license/known-exceptions.js +1 -23
- package/src/license/known-exceptions.js.map +1 -1
- package/src/migrations/latest/apt-security-updates-in-container-images/__snapshots__/migration.spec.ts.snap +90 -0
- package/src/migrations/latest/apt-security-updates-in-container-images/metadata.json +3 -0
- package/src/migrations/latest/apt-security-updates-in-container-images/migration.js +90 -0
- package/src/migrations/latest/apt-security-updates-in-container-images/migration.js.map +1 -0
- package/src/migrations/latest/remove-mcp-inspector-license-exceptions/metadata.json +3 -0
- package/src/migrations/latest/remove-mcp-inspector-license-exceptions/migration.d.ts +6 -0
- package/src/migrations/latest/remove-mcp-inspector-license-exceptions/migration.js +38 -0
- package/src/migrations/latest/remove-mcp-inspector-license-exceptions/migration.js.map +1 -0
- package/src/migrations/v1.0.0-rc.67/0001-smithy-server-package-rename/migration.js.map +1 -0
- package/src/migrations/v1.0.0-rc.68/0001-translate-script-whole-file-writes/migration.js.map +1 -0
- package/src/migrations/{latest/py-agent-a2a-lifespan-construction → v1.0.0-rc.70/0001-py-agent-a2a-lifespan-construction}/migration.js +14 -2
- package/src/migrations/v1.0.0-rc.70/0001-py-agent-a2a-lifespan-construction/migration.js.map +1 -0
- package/src/migrations/v1.0.0-rc.71/0001-py-agent-a2a-httpx-client-per-call/migration.d.ts +6 -0
- package/src/migrations/v1.0.0-rc.71/0001-py-agent-a2a-httpx-client-per-call/migration.js.map +1 -0
- package/src/migrations/v1.0.0-rc.72/0001-py-agent-session-management-support/migration.js.map +1 -0
- package/src/preset/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +11 -4
- package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +8 -8
- package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +2 -2
- package/src/py/agent/a2a-connection/generator.js +5 -11
- package/src/py/agent/a2a-connection/generator.js.map +1 -1
- package/src/py/agent/files/deploy/Dockerfile.template +7 -0
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +5 -5
- package/src/py/mcp-server/files/deploy/Dockerfile.template +7 -0
- package/src/py/mcp-server/generator.js +8 -3
- package/src/py/mcp-server/generator.js.map +1 -1
- package/src/py/rdb/__snapshots__/generator.spec.ts.snap +7 -5
- package/src/py/rdb/generator.js +36 -2
- package/src/py/rdb/generator.js.map +1 -1
- package/src/smithy/project/__snapshots__/generator.spec.ts.snap +14 -14
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +9 -2
- package/src/ts/agent/a2a-connection/generator.js +4 -2
- package/src/ts/agent/a2a-connection/generator.js.map +1 -1
- package/src/ts/agent/files/deploy/Dockerfile.template +7 -0
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/mcp-server/files/Dockerfile.template +7 -0
- package/src/ts/mcp-server/generator.js +8 -3
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +8 -6
- package/src/ts/rdb/generator.js +29 -2
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +15 -15
- package/src/ts/react-website/app/generator.js +4 -2
- package/src/ts/react-website/app/generator.js.map +1 -1
- package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +1 -1
- package/src/utils/agent-connection/agent-connection.js +5 -9
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/ast.d.ts +29 -0
- package/src/utils/ast.js +31 -0
- package/src/utils/ast.js.map +1 -1
- package/src/utils/metrics.js +2 -2
- package/src/utils/metrics.js.map +1 -1
- package/src/utils/versions.d.ts +73 -73
- package/src/utils/versions.js +70 -70
- package/src/utils/versions.js.map +1 -1
- package/src/migrations/latest/py-agent-a2a-httpx-client-per-call/migration.js.map +0 -1
- package/src/migrations/latest/py-agent-a2a-lifespan-construction/migration.js.map +0 -1
- package/src/migrations/latest/py-agent-session-management-support/migration.js.map +0 -1
- package/src/migrations/latest/smithy-server-package-rename/migration.js.map +0 -1
- package/src/migrations/latest/translate-script-whole-file-writes/migration.js.map +0 -1
- package/src/py/rdb/files/__name__/__init__.py.template +0 -3
- package/src/py/rdb/files/config.json.template +0 -14
- package/src/ts/rdb/files/config.json.template +0 -14
- package/src/ts/rdb/files/src/index.ts.template +0 -1
- /package/src/migrations/latest/{py-agent-a2a-httpx-client-per-call → apt-security-updates-in-container-images}/migration.d.ts +0 -0
- /package/src/migrations/{latest/smithy-server-package-rename → v1.0.0-rc.67/0001-smithy-server-package-rename}/metadata.json +0 -0
- /package/src/migrations/{latest/py-agent-a2a-lifespan-construction → v1.0.0-rc.67/0001-smithy-server-package-rename}/migration.d.ts +0 -0
- /package/src/migrations/{latest/smithy-server-package-rename → v1.0.0-rc.67/0001-smithy-server-package-rename}/migration.js +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/files/build-system-prompt.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/files/build-user-prompt.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/files/config-path.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/files/file-to-translate.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/files/get-files-to-translate.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/files/header.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/files/log.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/files/main-call.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/files/main.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/files/project-root.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/files/run-with-concurrency.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/files/scripts-dir.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/files/translate-file-for-language.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/grit/already-migrated.grit +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/grit/build-system-prompt.grit +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/grit/build-user-prompt.grit +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/grit/config-path.grit +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/grit/file-to-translate.grit +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/grit/get-files-to-translate.grit +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/grit/log.grit +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/grit/main-call.grit +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/grit/main.grit +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/grit/project-root.grit +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/grit/run-with-concurrency.grit +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/grit/translate-file-for-language.grit +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/metadata.json +0 -0
- /package/src/migrations/{latest/py-agent-session-management-support → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/migration.d.ts +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/migration.js +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/test-fixtures/released-script-first.ts.fixture +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.68/0001-translate-script-whole-file-writes}/test-fixtures/released-script.ts.fixture +0 -0
- /package/src/migrations/{latest/py-agent-a2a-lifespan-construction → v1.0.0-rc.70/0001-py-agent-a2a-lifespan-construction}/metadata.json +0 -0
- /package/src/migrations/{latest/smithy-server-package-rename → v1.0.0-rc.70/0001-py-agent-a2a-lifespan-construction}/migration.d.ts +0 -0
- /package/src/migrations/{latest/py-agent-a2a-httpx-client-per-call → v1.0.0-rc.71/0001-py-agent-a2a-httpx-client-per-call}/metadata.json +0 -0
- /package/src/migrations/{latest/py-agent-a2a-httpx-client-per-call → v1.0.0-rc.71/0001-py-agent-a2a-httpx-client-per-call}/migration.js +0 -0
- /package/src/migrations/{latest/py-agent-session-management-support → v1.0.0-rc.72/0001-py-agent-session-management-support}/metadata.json +0 -0
- /package/src/migrations/{latest/translate-script-whole-file-writes → v1.0.0-rc.72/0001-py-agent-session-management-support}/migration.d.ts +0 -0
- /package/src/migrations/{latest/py-agent-session-management-support → v1.0.0-rc.72/0001-py-agent-session-management-support}/migration.js +0 -0
|
@@ -42,7 +42,7 @@ exports[`smithyProjectGenerator > shape libraries > should generate a shape libr
|
|
|
42
42
|
"rimraf dist/{projectRoot}/build",
|
|
43
43
|
"rimraf dist/{projectRoot}/smithy",
|
|
44
44
|
"make-dir dist/{projectRoot}/build",
|
|
45
|
-
"npx -y mise@2026.8.
|
|
45
|
+
"npx -y mise@2026.8.6 exec smithy@1.73.0 -- smithy build -c {projectRoot}/smithy-build.json --output dist/{projectRoot}/smithy",
|
|
46
46
|
"ncp dist/{projectRoot}/smithy/source/model/model.json dist/{projectRoot}/build/model.json"
|
|
47
47
|
],
|
|
48
48
|
"parallel": false,
|
|
@@ -59,7 +59,7 @@ exports[`smithyProjectGenerator > shape libraries > should generate a shape libr
|
|
|
59
59
|
"version": "1.0",
|
|
60
60
|
"sources": ["src/"],
|
|
61
61
|
"maven": {
|
|
62
|
-
"dependencies": ["software.amazon.smithy:smithy-model:1.
|
|
62
|
+
"dependencies": ["software.amazon.smithy:smithy-model:1.73.0"]
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
"
|
|
@@ -116,7 +116,7 @@ exports[`smithyProjectGenerator > should generate smithy project with all custom
|
|
|
116
116
|
"rimraf dist/{projectRoot}/build",
|
|
117
117
|
"rimraf dist/{projectRoot}/smithy",
|
|
118
118
|
"make-dir dist/{projectRoot}/build",
|
|
119
|
-
"npx -y mise@2026.8.
|
|
119
|
+
"npx -y mise@2026.8.6 exec smithy@1.73.0 -- smithy build -c {projectRoot}/smithy-build.json --output dist/{projectRoot}/smithy",
|
|
120
120
|
"cpy \\"dist/{projectRoot}/smithy/source/openapi/*.openapi.json\\" dist/{projectRoot}/build/openapi --flat --rename=openapi.json"
|
|
121
121
|
],
|
|
122
122
|
"parallel": false,
|
|
@@ -170,7 +170,7 @@ exports[`smithyProjectGenerator > should generate smithy project with custom dir
|
|
|
170
170
|
"rimraf dist/{projectRoot}/build",
|
|
171
171
|
"rimraf dist/{projectRoot}/smithy",
|
|
172
172
|
"make-dir dist/{projectRoot}/build",
|
|
173
|
-
"npx -y mise@2026.8.
|
|
173
|
+
"npx -y mise@2026.8.6 exec smithy@1.73.0 -- smithy build -c {projectRoot}/smithy-build.json --output dist/{projectRoot}/smithy",
|
|
174
174
|
"cpy \\"dist/{projectRoot}/smithy/source/openapi/*.openapi.json\\" dist/{projectRoot}/build/openapi --flat --rename=openapi.json"
|
|
175
175
|
],
|
|
176
176
|
"parallel": false,
|
|
@@ -316,7 +316,7 @@ exports[`smithyProjectGenerator > should generate smithy project with default op
|
|
|
316
316
|
"rimraf dist/{projectRoot}/build",
|
|
317
317
|
"rimraf dist/{projectRoot}/smithy",
|
|
318
318
|
"make-dir dist/{projectRoot}/build",
|
|
319
|
-
"npx -y mise@2026.8.
|
|
319
|
+
"npx -y mise@2026.8.6 exec smithy@1.73.0 -- smithy build -c {projectRoot}/smithy-build.json --output dist/{projectRoot}/smithy",
|
|
320
320
|
"cpy \\"dist/{projectRoot}/smithy/source/openapi/*.openapi.json\\" dist/{projectRoot}/build/openapi --flat --rename=openapi.json"
|
|
321
321
|
],
|
|
322
322
|
"parallel": false,
|
|
@@ -360,10 +360,10 @@ exports[`smithyProjectGenerator > should generate smithy project with default op
|
|
|
360
360
|
},
|
|
361
361
|
"maven": {
|
|
362
362
|
"dependencies": [
|
|
363
|
-
"software.amazon.smithy:smithy-model:1.
|
|
364
|
-
"software.amazon.smithy:smithy-aws-traits:1.
|
|
365
|
-
"software.amazon.smithy:smithy-validation-model:1.
|
|
366
|
-
"software.amazon.smithy:smithy-openapi:1.
|
|
363
|
+
"software.amazon.smithy:smithy-model:1.73.0",
|
|
364
|
+
"software.amazon.smithy:smithy-aws-traits:1.73.0",
|
|
365
|
+
"software.amazon.smithy:smithy-validation-model:1.73.0",
|
|
366
|
+
"software.amazon.smithy:smithy-openapi:1.73.0",
|
|
367
367
|
"software.amazon.smithy.typescript:smithy-aws-typescript-codegen:0.52.0"
|
|
368
368
|
]
|
|
369
369
|
}
|
|
@@ -456,7 +456,7 @@ exports[`smithyProjectGenerator > should generate smithy project with subdirecto
|
|
|
456
456
|
"rimraf dist/{projectRoot}/build",
|
|
457
457
|
"rimraf dist/{projectRoot}/smithy",
|
|
458
458
|
"make-dir dist/{projectRoot}/build",
|
|
459
|
-
"npx -y mise@2026.8.
|
|
459
|
+
"npx -y mise@2026.8.6 exec smithy@1.73.0 -- smithy build -c {projectRoot}/smithy-build.json --output dist/{projectRoot}/smithy",
|
|
460
460
|
"cpy \\"dist/{projectRoot}/smithy/source/openapi/*.openapi.json\\" dist/{projectRoot}/build/openapi --flat --rename=openapi.json"
|
|
461
461
|
],
|
|
462
462
|
"parallel": false,
|
|
@@ -546,10 +546,10 @@ exports[`smithyProjectGenerator > should handle kebab-case conversion for servic
|
|
|
546
546
|
},
|
|
547
547
|
"maven": {
|
|
548
548
|
"dependencies": [
|
|
549
|
-
"software.amazon.smithy:smithy-model:1.
|
|
550
|
-
"software.amazon.smithy:smithy-aws-traits:1.
|
|
551
|
-
"software.amazon.smithy:smithy-validation-model:1.
|
|
552
|
-
"software.amazon.smithy:smithy-openapi:1.
|
|
549
|
+
"software.amazon.smithy:smithy-model:1.73.0",
|
|
550
|
+
"software.amazon.smithy:smithy-aws-traits:1.73.0",
|
|
551
|
+
"software.amazon.smithy:smithy-validation-model:1.73.0",
|
|
552
|
+
"software.amazon.smithy:smithy-openapi:1.73.0",
|
|
553
553
|
"software.amazon.smithy.typescript:smithy-aws-typescript-codegen:0.52.0"
|
|
554
554
|
]
|
|
555
555
|
}
|
|
@@ -1765,7 +1765,7 @@ exports[`tsSmithyApiGenerator > should generate smithy ts api with default optio
|
|
|
1765
1765
|
"rimraf dist/{projectRoot}/build",
|
|
1766
1766
|
"rimraf dist/{projectRoot}/smithy",
|
|
1767
1767
|
"make-dir dist/{projectRoot}/build",
|
|
1768
|
-
"npx -y mise@2026.8.
|
|
1768
|
+
"npx -y mise@2026.8.6 exec smithy@1.73.0 -- smithy build -c {projectRoot}/smithy-build.json --output dist/{projectRoot}/smithy",
|
|
1769
1769
|
"cpy \\"dist/{projectRoot}/smithy/source/openapi/*.openapi.json\\" dist/{projectRoot}/build/openapi --flat --rename=openapi.json"
|
|
1770
1770
|
],
|
|
1771
1771
|
"parallel": false,
|
|
@@ -642,6 +642,13 @@ export const getSessionManager = async (): Promise<SessionManager> => {
|
|
|
642
642
|
exports[`ts#agent generator > should match snapshot for BedrockAgentCoreRuntime generated constructs files > agent-Dockerfile 1`] = `
|
|
643
643
|
"FROM public.ecr.aws/docker/library/node:lts-slim
|
|
644
644
|
|
|
645
|
+
# Apply the distribution's security updates: base image tags lag behind the
|
|
646
|
+
# security suite, so its OS packages carry fixed HIGH/CRITICAL vulnerabilities
|
|
647
|
+
# flagged by the image scan.
|
|
648
|
+
RUN apt-get update && \\
|
|
649
|
+
apt-get upgrade -y --no-install-recommends && \\
|
|
650
|
+
rm -rf /var/lib/apt/lists/*
|
|
651
|
+
|
|
645
652
|
# Upgrade npm to a version free of known HIGH/CRITICAL vulnerabilities
|
|
646
653
|
RUN npm install -g npm@12.0.2
|
|
647
654
|
|
|
@@ -1288,7 +1295,7 @@ exports[`ts#agent generator > should match snapshot for Terraform generated file
|
|
|
1288
1295
|
}
|
|
1289
1296
|
null = {
|
|
1290
1297
|
source = "hashicorp/null"
|
|
1291
|
-
version = "3.3.
|
|
1298
|
+
version = "3.3.1"
|
|
1292
1299
|
}
|
|
1293
1300
|
random = {
|
|
1294
1301
|
source = "hashicorp/random"
|
|
@@ -1700,7 +1707,7 @@ resource "null_resource" "runtime_ready" {
|
|
|
1700
1707
|
|
|
1701
1708
|
provisioner "local-exec" {
|
|
1702
1709
|
command = <<-EOT
|
|
1703
|
-
uv run --with boto3==1.43.
|
|
1710
|
+
uv run --with boto3==1.43.72 python -c "
|
|
1704
1711
|
import boto3
|
|
1705
1712
|
import json
|
|
1706
1713
|
import os
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/ import { generateFiles, joinPathFragments, OverwriteStrategy, updateProjectConfiguration } from "@nx/devkit";
|
|
5
5
|
import { addTsDependencies } from "../../../utils/add-dependencies.js";
|
|
6
6
|
import { AGENT_CONNECTION_DEPENDENCIES, AGENT_CONNECTION_PROJECT_DIR, addTypeScriptCoreClient, ensureTypeScriptAgentConnectionProject } from "../../../utils/agent-connection/agent-connection.js";
|
|
7
|
-
import { addDestructuredImport, addStarExport, applyGritQL } from "../../../utils/ast.js";
|
|
7
|
+
import { addDestructuredImport, addStarExport, appendToArrayViaGritQL, applyGritQL } from "../../../utils/ast.js";
|
|
8
8
|
import { declareDependencies, ownedElsewhere } from "../../../utils/declared-dependencies.js";
|
|
9
9
|
import { formatFilesInSubtree } from "../../../utils/format.js";
|
|
10
10
|
import { installDependencies } from "../../../utils/install.js";
|
|
@@ -123,7 +123,9 @@ export const tsAgentA2aConnectionGenerator = async (tree, options)=>{
|
|
|
123
123
|
$body
|
|
124
124
|
}\` where { $body <: contains \`new Agent($_)\`, $program <: not contains \`${clientClassName}.create\` } }`);
|
|
125
125
|
// Append the tool to the tools array (after existing items)
|
|
126
|
-
await
|
|
126
|
+
await appendToArrayViaGritQL(tree, agentFilePath, 'tools:', toolVarName, {
|
|
127
|
+
scope: 'new Agent($_)'
|
|
128
|
+
});
|
|
127
129
|
}
|
|
128
130
|
// 4. Set up dev target — depend on the target agent's dev
|
|
129
131
|
// so running the host's dev also spins up the remote A2A agent.
|
|
@@ -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 type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../../../utils/add-dependencies';\nimport {\n AGENT_CONNECTION_DEPENDENCIES,\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 {\n declareDependencies,\n ownedElsewhere,\n} from '../../../utils/declared-dependencies';\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 addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { toProjectRelativePath } from '../../../utils/paths';\nimport type { TsAgentA2aConnectionGeneratorSchema } from './schema';\n\n// The A2A core client + vended client need these whatever the connection's\n// options, so no entry is conditional.\n// The A2A client the generated agent code imports, plus the AppConfig lookup and\n// sigv4 signing it resolves the remote agent with. Added to the workspace root,\n// where this connection has always put them.\nexport const DEPENDENCIES = declareDependencies()({\n ts: [\n { name: '@a2a-js/sdk', root: true },\n { name: '@strands-agents/sdk', root: true },\n { name: '@aws-lambda-powertools/parameters', root: true },\n { name: '@aws-sdk/client-appconfigdata', root: true },\n { name: 'aws4fetch', root: true },\n { name: '@aws-sdk/credential-providers', root: true },\n { name: 'zod', root: true },\n ...ownedElsewhere(AGENT_CONNECTION_DEPENDENCIES),\n ],\n});\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, DEPENDENCIES);\n await addTypeScriptCoreClient(tree, 'a2a', DEPENDENCIES);\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 to the workspace root manifest\n addTsDependencies(tree, DEPENDENCIES);\n\n // Recorded so the version sync knows this connection's dependencies are ours.\n addComponentGeneratorMetadata(\n tree,\n sourceProject.name,\n TS_AGENT_A2A_CONNECTION_GENERATOR_INFO,\n toProjectRelativePath(sourceProject, agentFilePath),\n targetAgentClassName,\n // The source component this connection is made from, so the pair is\n // identifiable rather than just the two projects.\n { sourcePath: options.sourceComponent?.path },\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":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addTsDependencies","AGENT_CONNECTION_DEPENDENCIES","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","applyGritQL","declareDependencies","ownedElsewhere","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","getNpmScope","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","toProjectRelativePath","DEPENDENCIES","ts","name","root","TS_AGENT_A2A_CONNECTION_GENERATOR_INFO","filename","tsAgentA2aConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","targetAgentComponent","targetComponent","Error","protocol","toLowerCase","auth","targetAgentComponentName","targetAgentClassName","rc","targetAgentKebabCase","targetAgentPort","port","npmScope","dirname","overwriteStrategy","KeepExisting","agentSourceDir","path","agentFilePath","exists","clientClassName","clientVarName","charAt","slice","toolName","toolVarName","toolCreationBlock","agentName","devTargetName","targetDevTargetName","targets","projects","target","sourcePath","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,qCAAkC;AACpE,SACEC,6BAA6B,EAC7BC,4BAA4B,EAC5BC,uBAAuB,EACvBC,sCAAsC,QACjC,sDAAmD;AAC1D,SACEC,qBAAqB,EACrBC,aAAa,EACbC,WAAW,QACN,wBAAqB;AAC5B,SACEC,mBAAmB,EACnBC,cAAc,QACT,0CAAuC;AAC9C,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,6BAA6B,EAC7BC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,uBAAoB;AAC3B,SAASC,qBAAqB,QAAQ,0BAA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"}
|
|
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 type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../../../utils/add-dependencies';\nimport {\n AGENT_CONNECTION_DEPENDENCIES,\n AGENT_CONNECTION_PROJECT_DIR,\n addTypeScriptCoreClient,\n ensureTypeScriptAgentConnectionProject,\n} from '../../../utils/agent-connection/agent-connection';\nimport {\n addDestructuredImport,\n addStarExport,\n appendToArrayViaGritQL,\n applyGritQL,\n} from '../../../utils/ast';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../../utils/declared-dependencies';\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 addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { toProjectRelativePath } from '../../../utils/paths';\nimport type { TsAgentA2aConnectionGeneratorSchema } from './schema';\n\n// The A2A core client + vended client need these whatever the connection's\n// options, so no entry is conditional.\n// The A2A client the generated agent code imports, plus the AppConfig lookup and\n// sigv4 signing it resolves the remote agent with. Added to the workspace root,\n// where this connection has always put them.\nexport const DEPENDENCIES = declareDependencies()({\n ts: [\n { name: '@a2a-js/sdk', root: true },\n { name: '@strands-agents/sdk', root: true },\n { name: '@aws-lambda-powertools/parameters', root: true },\n { name: '@aws-sdk/client-appconfigdata', root: true },\n { name: 'aws4fetch', root: true },\n { name: '@aws-sdk/credential-providers', root: true },\n { name: 'zod', root: true },\n ...ownedElsewhere(AGENT_CONNECTION_DEPENDENCIES),\n ],\n});\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, DEPENDENCIES);\n await addTypeScriptCoreClient(tree, 'a2a', DEPENDENCIES);\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 appendToArrayViaGritQL(tree, agentFilePath, 'tools:', toolVarName, {\n scope: 'new Agent($_)',\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 to the workspace root manifest\n addTsDependencies(tree, DEPENDENCIES);\n\n // Recorded so the version sync knows this connection's dependencies are ours.\n addComponentGeneratorMetadata(\n tree,\n sourceProject.name,\n TS_AGENT_A2A_CONNECTION_GENERATOR_INFO,\n toProjectRelativePath(sourceProject, agentFilePath),\n targetAgentClassName,\n // The source component this connection is made from, so the pair is\n // identifiable rather than just the two projects.\n { sourcePath: options.sourceComponent?.path },\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":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addTsDependencies","AGENT_CONNECTION_DEPENDENCIES","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","appendToArrayViaGritQL","applyGritQL","declareDependencies","ownedElsewhere","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","getNpmScope","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","toProjectRelativePath","DEPENDENCIES","ts","name","root","TS_AGENT_A2A_CONNECTION_GENERATOR_INFO","filename","tsAgentA2aConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","targetAgentComponent","targetComponent","Error","protocol","toLowerCase","auth","targetAgentComponentName","targetAgentClassName","rc","targetAgentKebabCase","targetAgentPort","port","npmScope","dirname","overwriteStrategy","KeepExisting","agentSourceDir","path","agentFilePath","exists","clientClassName","clientVarName","charAt","slice","toolName","toolVarName","toolCreationBlock","scope","agentName","devTargetName","targetDevTargetName","targets","projects","target","sourcePath","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,qCAAkC;AACpE,SACEC,6BAA6B,EAC7BC,4BAA4B,EAC5BC,uBAAuB,EACvBC,sCAAsC,QACjC,sDAAmD;AAC1D,SACEC,qBAAqB,EACrBC,aAAa,EACbC,sBAAsB,EACtBC,WAAW,QACN,wBAAqB;AAC5B,SACEC,mBAAmB,EACnBC,cAAc,QACT,0CAAuC;AAC9C,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,6BAA6B,EAC7BC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,uBAAoB;AAC3B,SAASC,qBAAqB,QAAQ,0BAAuB;AAG7D,2EAA2E;AAC3E,uCAAuC;AACvC,iFAAiF;AACjF,gFAAgF;AAChF,6CAA6C;AAC7C,OAAO,MAAMC,eAAeb,sBAAsB;IAChDc,IAAI;QACF;YAAEC,MAAM;YAAeC,MAAM;QAAK;QAClC;YAAED,MAAM;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ACjE,gDAAgD;QAChD,MAAMhD,YACJqB,MACAwB,eACA,CAAC;EACL,EAAEQ,kBAAkB;;uCAEiB,EAAEN,gBAAgB;EACvD,EAAEM,kBAAkB;;4EAEsD,EAAEN,gBAAgB,aAAa,CAAC;QAGxG,4DAA4D;QAC5D,MAAMhD,uBAAuBsB,MAAMwB,eAAe,UAAUO,aAAa;YACvEE,OAAO;QACT;IACF;IAEA,0DAA0D;IAC1D,mEAAmE;IACnE,MAAMC,YAAY9B,eAAeT,IAAI,IAAI;IACzC,MAAMwC,gBAAgB,GAAGD,UAAU,IAAI,CAAC;IACxC,MAAME,sBAAsB,GAAGxB,yBAAyB,IAAI,CAAC;IAE7D,IAAIV,cAAcmC,OAAO,EAAE,CAACF,cAAc,EAAE;QAC1C9C,kCAAkCa,eAAeiC,eAAe;YAC9DG,UAAU;gBAACnC,cAAcR,IAAI;aAAC;YAC9B4C,QAAQH;QACV;QACAlE,2BAA2B8B,MAAME,cAAcP,IAAI,EAAEO;IACvD;IAEA,qDAAqD;IACrD/B,kBAAkB6B,MAAMP;IAExB,8EAA8E;IAC9EL,8BACEY,MACAE,cAAcP,IAAI,EAClBE,wCACAL,sBAAsBU,eAAesB,gBACrCX,sBACA,oEAAoE;IACpE,kDAAkD;IAClD;QAAE2B,YAAYvC,QAAQI,eAAe,EAAEkB;IAAK;IAG9C,MAAMvC,gCAAgCgB,MAAM;QAC1CH;KACD;IAED,MAAMf,qBAAqBkB;IAC3B,OAAO,IACLjB,oBAAoBiB,MAAMC,QAAQwC,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe3C,8BAA8B"}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
FROM <%- nodeBaseImage %>
|
|
2
2
|
|
|
3
|
+
# Apply the distribution's security updates: base image tags lag behind the
|
|
4
|
+
# security suite, so its OS packages carry fixed HIGH/CRITICAL vulnerabilities
|
|
5
|
+
# flagged by the image scan.
|
|
6
|
+
RUN apt-get update && \
|
|
7
|
+
apt-get upgrade -y --no-install-recommends && \
|
|
8
|
+
rm -rf /var/lib/apt/lists/*
|
|
9
|
+
|
|
3
10
|
# Upgrade npm to a version free of known HIGH/CRITICAL vulnerabilities
|
|
4
11
|
RUN npm install -g npm@<%- npmVersion %>
|
|
5
12
|
|
|
@@ -159,7 +159,7 @@ exports[`ts#mcp-server generator > should match snapshot for Terraform generated
|
|
|
159
159
|
}
|
|
160
160
|
null = {
|
|
161
161
|
source = "hashicorp/null"
|
|
162
|
-
version = "3.3.
|
|
162
|
+
version = "3.3.1"
|
|
163
163
|
}
|
|
164
164
|
random = {
|
|
165
165
|
source = "hashicorp/random"
|
|
@@ -571,7 +571,7 @@ resource "null_resource" "runtime_ready" {
|
|
|
571
571
|
|
|
572
572
|
provisioner "local-exec" {
|
|
573
573
|
command = <<-EOT
|
|
574
|
-
uv run --with boto3==1.43.
|
|
574
|
+
uv run --with boto3==1.43.72 python -c "
|
|
575
575
|
import boto3
|
|
576
576
|
import json
|
|
577
577
|
import os
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
FROM <%- nodeBaseImage %>
|
|
2
2
|
|
|
3
|
+
# Apply the distribution's security updates: base image tags lag behind the
|
|
4
|
+
# security suite, so its OS packages carry fixed HIGH/CRITICAL vulnerabilities
|
|
5
|
+
# flagged by the image scan.
|
|
6
|
+
RUN apt-get update && \
|
|
7
|
+
apt-get upgrade -y --no-install-recommends && \
|
|
8
|
+
rm -rf /var/lib/apt/lists/*
|
|
9
|
+
|
|
3
10
|
# Upgrade npm to a version free of known HIGH/CRITICAL vulnerabilities
|
|
4
11
|
RUN npm install -g npm@<%- npmVersion %>
|
|
5
12
|
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/ import { detectPackageManager, generateFiles, joinPathFragments, OverwriteStrategy, readJson, updateJson, updateProjectConfiguration } from "@nx/devkit";
|
|
5
|
-
import { ensureLicenseExceptions } from "../../license/config.js";
|
|
6
|
-
import { MCP_INSPECTOR_EXCEPTIONS } from "../../license/known-exceptions.js";
|
|
7
5
|
import { addTsDependencies } from "../../utils/add-dependencies.js";
|
|
8
6
|
import { AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES, addMcpServerInfra } from "../../utils/agent-core-constructs/agent-core-constructs.js";
|
|
9
7
|
import { addTypeScriptBundleTarget, BUNDLE_DEPENDENCIES } from "../../utils/bundle/bundle.js";
|
|
@@ -20,6 +18,7 @@ import { kebabCase, toClassName } from "../../utils/names.js";
|
|
|
20
18
|
import { getNpmScope } from "../../utils/npm-scope.js";
|
|
21
19
|
import { addComponentDevTarget, addComponentGeneratorMetadata, addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
|
|
22
20
|
import { sortObjectKeys } from "../../utils/object.js";
|
|
21
|
+
import { registerPnpmBuiltDependencies } from "../../utils/pnpm-workspace.js";
|
|
23
22
|
import { assignPort } from "../../utils/port.js";
|
|
24
23
|
import { SHARED_CONSTRUCTS_DEPENDENCIES, sharedConstructsGenerator } from "../../utils/shared-constructs.js";
|
|
25
24
|
import { BASE_IMAGES, TS_VERSIONS } from "../../utils/versions.js";
|
|
@@ -197,6 +196,13 @@ export const tsMcpServerGenerator = async (tree, options)=>{
|
|
|
197
196
|
iac
|
|
198
197
|
} : {}
|
|
199
198
|
};
|
|
199
|
+
// The MCP inspector has a postinstall script that cascades installs into its
|
|
200
|
+
// client packages, which no-ops when the package is installed as a dependency.
|
|
201
|
+
// Register it as an explicitly-rejected build so pnpm 11's default
|
|
202
|
+
// `strictDepBuilds=true` skips it instead of failing the install.
|
|
203
|
+
registerPnpmBuiltDependencies(tree, {
|
|
204
|
+
'@modelcontextprotocol/inspector': false
|
|
205
|
+
});
|
|
200
206
|
addTsDependencies(tree, DEPENDENCIES, {
|
|
201
207
|
metadata,
|
|
202
208
|
projectRoot: project.root
|
|
@@ -280,7 +286,6 @@ export const tsMcpServerGenerator = async (tree, options)=>{
|
|
|
280
286
|
await addGeneratorMetricsIfApplicable(tree, [
|
|
281
287
|
TS_MCP_SERVER_GENERATOR_INFO
|
|
282
288
|
]);
|
|
283
|
-
await ensureLicenseExceptions(tree, MCP_INSPECTOR_EXCEPTIONS);
|
|
284
289
|
await formatFilesInSubtree(tree);
|
|
285
290
|
return ()=>installDependencies(tree, options.preferInstallDependencies, {
|
|
286
291
|
languages: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/mcp-server/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n detectPackageManager,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readJson,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { ensureLicenseExceptions } from '../../license/config';\nimport { MCP_INSPECTOR_EXCEPTIONS } from '../../license/known-exceptions';\nimport { addTsDependencies } from '../../utils/add-dependencies';\nimport {\n AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES,\n addMcpServerInfra,\n} from '../../utils/agent-core-constructs/agent-core-constructs';\nimport {\n addTypeScriptBundleTarget,\n BUNDLE_DEPENDENCIES,\n} from '../../utils/bundle/bundle';\nimport { resolveContainers } from '../../utils/containers';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies';\nimport {\n ADOT_IMAGE_DEPENDENCIES,\n addDockerScanTarget,\n DOCKER_DEPENDENCIES,\n NODE_IMAGE_DEPENDENCIES,\n nodeImageVersions,\n} from '../../utils/docker';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FS_DEPENDENCIES, FsCommands } from '../../utils/fs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { isEsmWorkspace } 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 {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs';\nimport type { IacMetadata } from '../../utils/shared-constructs-constants';\nimport { BASE_IMAGES, TS_VERSIONS } from '../../utils/versions';\nimport type { TsMcpServerGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface TsMcpServerMetadata extends IacMetadata {\n readonly port: number;\n readonly rc: string;\n readonly auth: string;\n}\n\nexport const DEPENDENCIES = declareDependencies<TsMcpServerMetadata>()({\n ts: [\n { name: '@modelcontextprotocol/sdk' },\n { name: 'zod' },\n { name: 'express' },\n { name: '@aws-lambda-powertools/parameters' },\n { name: '@aws-sdk/client-appconfigdata' },\n { name: '@types/express', dev: true },\n // tsx (local dev) and the MCP inspector are shared tooling.\n { name: 'tsx', dev: true, root: true },\n { name: '@modelcontextprotocol/inspector', dev: true, root: true },\n ...ownedElsewhere(FS_DEPENDENCIES),\n ...ownedElsewhere(BUNDLE_DEPENDENCIES),\n ...ownedElsewhere(DOCKER_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(NODE_IMAGE_DEPENDENCIES),\n ...ownedElsewhere(ADOT_IMAGE_DEPENDENCIES),\n ],\n py: ownedElsewhere(AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES),\n});\n\nexport const TS_MCP_SERVER_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsMcpServerGenerator = async (\n tree: Tree,\n options: TsMcpServerGeneratorSchema,\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())}-mcp-server`;\n const name = kebabCase(options.name || defaultName);\n const mcpServerNameClassName = toClassName(name);\n const mcpTargetPrefix = options.name ? name : 'mcp-server';\n const targetSourceDirRelativeToProjectRoot = joinPathFragments(\n 'src',\n mcpTargetPrefix,\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\n // Recorded in the metadata below so the version sync can tell a CDK\n // project from a Terraform one; undefined when no infrastructure was\n // generated, in which case neither provider's packages were added.\n const iac =\n infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\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 const projectPackageJsonPath = joinPathFragments(\n project.root,\n 'package.json',\n );\n\n // Generate esm if the project's package.json is `type: module`, falling\n // back to the workspace format when the project has no manifest.\n const esm = tree.exists(projectPackageJsonPath)\n ? readJson(tree, projectPackageJsonPath).type === 'module'\n : isEsmWorkspace(tree);\n\n // Generate example server\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n targetSourceDir,\n {\n name,\n esm,\n distDir,\n adotVersion:\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],\n jaegerVersion: TS_VERSIONS['@opentelemetry/propagator-jaeger'],\n nodeBaseImage: BASE_IMAGES.node,\n ...nodeImageVersions(),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add hosting based on infra\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(\n tree,\n project,\n {\n targetFilePath: `${targetSourceDirRelativeToProjectRoot}/http.ts`,\n bundleOutputDir: joinPathFragments('mcp', name),\n },\n DEPENDENCIES,\n );\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'bundle',\n 'mcp',\n name,\n );\n const dockerTargetName = `${mcpTargetPrefix}-docker`;\n\n const fs = new FsCommands(tree, DEPENDENCIES);\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 addDockerScanTarget(\n tree,\n {\n project,\n containerEngine: containers,\n trivyTargetName: `${mcpTargetPrefix}-trivy`,\n dockerTargetName,\n imageTags: [dockerImageTag],\n },\n DEPENDENCIES,\n );\n\n // Add shared constructs\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n\n // Add the construct to deploy the mcp server\n await addMcpServerInfra(tree, {\n mcpServerNameKebabCase: name,\n mcpServerNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n containers,\n });\n } else {\n // No Dockerfile needed for non-hosted MCP\n tree.delete(joinPathFragments(targetSourceDir, 'Dockerfile'));\n }\n\n // @modelcontextprotocol/sdk declares zod as a peer dependency with a wide range\n // (^3.25 || ^4.0). Yarn does not dedupe the peer to the workspace's pinned zod, so\n // without a resolution it installs a separate zod under the SDK's own node_modules.\n // The two zod copies have structurally incompatible types, which breaks type\n // inference for registerTool inputSchema. Scope the resolution to the SDK so\n // other consumers (e.g. @tanstack/router-generator pinning zod@3) are unaffected.\n // Classic yarn only honours the `**/`-prefixed descriptor in a workspace, and\n // berry only the bare one — it deletes a glob descriptor on install — so\n // declare both.\n if (detectPackageManager() === 'yarn') {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.resolutions = {\n ...packageJson.resolutions,\n '**/@modelcontextprotocol/sdk/zod': TS_VERSIONS['zod'],\n '@modelcontextprotocol/sdk/zod': TS_VERSIONS['zod'],\n };\n return packageJson;\n });\n }\n\n const localDevPort = assignPort(tree, project, 8000, {\n component: { info: TS_MCP_SERVER_GENERATOR_INFO, name: mcpTargetPrefix },\n });\n\n // Recorded below and read by the declaration's predicates, so the packages\n // added here are exactly the ones the version sync will own.\n const metadata: TsMcpServerMetadata = {\n port: localDevPort,\n rc: mcpServerNameClassName,\n auth,\n ...(iac ? { iac } : {}),\n };\n\n addTsDependencies(tree, DEPENDENCIES, {\n metadata,\n projectRoot: project.root,\n });\n\n const mcpTargets = {\n ...project.targets,\n // Add targets for running the MCP server\n [`${mcpTargetPrefix}-serve-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/stdio.ts`],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/http.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${mcpTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/http.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${mcpTargetPrefix}-inspect`]: {\n executor: 'nx:run-commands',\n continuous: true,\n // Launch the inspector against the locally served HTTP server. The dev\n // target starts the server and any connected dependencies (e.g. a local\n // database).\n dependsOn: [`${mcpTargetPrefix}-dev`],\n options: {\n commands: [\n `mcp-inspector --transport http --server-url http://localhost:${localDevPort}/mcp`,\n ],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-inspect-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `mcp-inspector -- tsx --watch ${relativeSourceDir}/stdio.ts`,\n ],\n cwd: '{projectRoot}',\n },\n },\n };\n\n // Aggregate `<mcp>-dev` under the project-level `dev` target.\n addComponentDevTarget(mcpTargets, `${mcpTargetPrefix}-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(mcpTargets),\n });\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n TS_MCP_SERVER_GENERATOR_INFO,\n targetSourceDirRelativeToProjectRoot,\n mcpTargetPrefix,\n metadata,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_MCP_SERVER_GENERATOR_INFO]);\n\n await ensureLicenseExceptions(tree, MCP_INSPECTOR_EXCEPTIONS);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsMcpServerGenerator;\n"],"names":["detectPackageManager","generateFiles","joinPathFragments","OverwriteStrategy","readJson","updateJson","updateProjectConfiguration","ensureLicenseExceptions","MCP_INSPECTOR_EXCEPTIONS","addTsDependencies","AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES","addMcpServerInfra","addTypeScriptBundleTarget","BUNDLE_DEPENDENCIES","resolveContainers","declareDependencies","ownedElsewhere","ADOT_IMAGE_DEPENDENCIES","addDockerScanTarget","DOCKER_DEPENDENCIES","NODE_IMAGE_DEPENDENCIES","nodeImageVersions","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","kebabCase","toClassName","getNpmScope","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","assignPort","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","BASE_IMAGES","TS_VERSIONS","DEPENDENCIES","ts","name","dev","root","py","TS_MCP_SERVER_GENERATOR_INFO","filename","tsMcpServerGenerator","tree","options","project","exists","Error","defaultName","split","pop","mcpServerNameClassName","mcpTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","iac","undefined","auth","console","warn","projectPackageJsonPath","esm","type","dirname","adotVersion","jaegerVersion","nodeBaseImage","node","overwriteStrategy","KeepExisting","containers","dockerImageTag","targetFilePath","bundleOutputDir","dockerOutputDir","dockerTargetName","fs","targets","cache","outputs","executor","commands","cp","parallel","dependsOn","containerEngine","trivyTargetName","imageTags","mcpServerNameKebabCase","projectName","delete","packageJson","resolutions","localDevPort","component","info","metadata","port","rc","projectRoot","mcpTargets","continuous","cwd","env","PORT","LOCAL_DEV","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,oBAAoB,EAEpBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,QAAQ,EAERC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,uBAAuB,QAAQ,0BAAuB;AAC/D,SAASC,wBAAwB,QAAQ,oCAAiC;AAC1E,SAASC,iBAAiB,QAAQ,kCAA+B;AACjE,SACEC,qCAAqC,EACrCC,iBAAiB,QACZ,6DAA0D;AACjE,SACEC,yBAAyB,EACzBC,mBAAmB,QACd,+BAA4B;AACnC,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAoC;AAC3C,SACEC,uBAAu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ACZI,8BACAa,sCACAD,iBACAgD;IAGF,MAAMlF,gCAAgCyB,MAAM;QAACH;KAA6B;IAE1E,MAAM1C,wBAAwB6C,MAAM5C;IAEpC,MAAMc,qBAAqB8B;IAC3B,OAAO,IACL1B,oBAAoB0B,MAAMC,QAAQkE,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAerE,qBAAqB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/mcp-server/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n detectPackageManager,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readJson,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../../utils/add-dependencies';\nimport {\n AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES,\n addMcpServerInfra,\n} from '../../utils/agent-core-constructs/agent-core-constructs';\nimport {\n addTypeScriptBundleTarget,\n BUNDLE_DEPENDENCIES,\n} from '../../utils/bundle/bundle';\nimport { resolveContainers } from '../../utils/containers';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies';\nimport {\n ADOT_IMAGE_DEPENDENCIES,\n addDockerScanTarget,\n DOCKER_DEPENDENCIES,\n NODE_IMAGE_DEPENDENCIES,\n nodeImageVersions,\n} from '../../utils/docker';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FS_DEPENDENCIES, FsCommands } from '../../utils/fs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { isEsmWorkspace } 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 { registerPnpmBuiltDependencies } from '../../utils/pnpm-workspace';\nimport { assignPort } from '../../utils/port';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs';\nimport type { IacMetadata } from '../../utils/shared-constructs-constants';\nimport { BASE_IMAGES, TS_VERSIONS } from '../../utils/versions';\nimport type { TsMcpServerGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface TsMcpServerMetadata extends IacMetadata {\n readonly port: number;\n readonly rc: string;\n readonly auth: string;\n}\n\nexport const DEPENDENCIES = declareDependencies<TsMcpServerMetadata>()({\n ts: [\n { name: '@modelcontextprotocol/sdk' },\n { name: 'zod' },\n { name: 'express' },\n { name: '@aws-lambda-powertools/parameters' },\n { name: '@aws-sdk/client-appconfigdata' },\n { name: '@types/express', dev: true },\n // tsx (local dev) and the MCP inspector are shared tooling.\n { name: 'tsx', dev: true, root: true },\n { name: '@modelcontextprotocol/inspector', dev: true, root: true },\n ...ownedElsewhere(FS_DEPENDENCIES),\n ...ownedElsewhere(BUNDLE_DEPENDENCIES),\n ...ownedElsewhere(DOCKER_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(NODE_IMAGE_DEPENDENCIES),\n ...ownedElsewhere(ADOT_IMAGE_DEPENDENCIES),\n ],\n py: ownedElsewhere(AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES),\n});\n\nexport const TS_MCP_SERVER_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsMcpServerGenerator = async (\n tree: Tree,\n options: TsMcpServerGeneratorSchema,\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())}-mcp-server`;\n const name = kebabCase(options.name || defaultName);\n const mcpServerNameClassName = toClassName(name);\n const mcpTargetPrefix = options.name ? name : 'mcp-server';\n const targetSourceDirRelativeToProjectRoot = joinPathFragments(\n 'src',\n mcpTargetPrefix,\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\n // Recorded in the metadata below so the version sync can tell a CDK\n // project from a Terraform one; undefined when no infrastructure was\n // generated, in which case neither provider's packages were added.\n const iac =\n infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\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 const projectPackageJsonPath = joinPathFragments(\n project.root,\n 'package.json',\n );\n\n // Generate esm if the project's package.json is `type: module`, falling\n // back to the workspace format when the project has no manifest.\n const esm = tree.exists(projectPackageJsonPath)\n ? readJson(tree, projectPackageJsonPath).type === 'module'\n : isEsmWorkspace(tree);\n\n // Generate example server\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n targetSourceDir,\n {\n name,\n esm,\n distDir,\n adotVersion:\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],\n jaegerVersion: TS_VERSIONS['@opentelemetry/propagator-jaeger'],\n nodeBaseImage: BASE_IMAGES.node,\n ...nodeImageVersions(),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add hosting based on infra\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(\n tree,\n project,\n {\n targetFilePath: `${targetSourceDirRelativeToProjectRoot}/http.ts`,\n bundleOutputDir: joinPathFragments('mcp', name),\n },\n DEPENDENCIES,\n );\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'bundle',\n 'mcp',\n name,\n );\n const dockerTargetName = `${mcpTargetPrefix}-docker`;\n\n const fs = new FsCommands(tree, DEPENDENCIES);\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 addDockerScanTarget(\n tree,\n {\n project,\n containerEngine: containers,\n trivyTargetName: `${mcpTargetPrefix}-trivy`,\n dockerTargetName,\n imageTags: [dockerImageTag],\n },\n DEPENDENCIES,\n );\n\n // Add shared constructs\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n\n // Add the construct to deploy the mcp server\n await addMcpServerInfra(tree, {\n mcpServerNameKebabCase: name,\n mcpServerNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n containers,\n });\n } else {\n // No Dockerfile needed for non-hosted MCP\n tree.delete(joinPathFragments(targetSourceDir, 'Dockerfile'));\n }\n\n // @modelcontextprotocol/sdk declares zod as a peer dependency with a wide range\n // (^3.25 || ^4.0). Yarn does not dedupe the peer to the workspace's pinned zod, so\n // without a resolution it installs a separate zod under the SDK's own node_modules.\n // The two zod copies have structurally incompatible types, which breaks type\n // inference for registerTool inputSchema. Scope the resolution to the SDK so\n // other consumers (e.g. @tanstack/router-generator pinning zod@3) are unaffected.\n // Classic yarn only honours the `**/`-prefixed descriptor in a workspace, and\n // berry only the bare one — it deletes a glob descriptor on install — so\n // declare both.\n if (detectPackageManager() === 'yarn') {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.resolutions = {\n ...packageJson.resolutions,\n '**/@modelcontextprotocol/sdk/zod': TS_VERSIONS['zod'],\n '@modelcontextprotocol/sdk/zod': TS_VERSIONS['zod'],\n };\n return packageJson;\n });\n }\n\n const localDevPort = assignPort(tree, project, 8000, {\n component: { info: TS_MCP_SERVER_GENERATOR_INFO, name: mcpTargetPrefix },\n });\n\n // Recorded below and read by the declaration's predicates, so the packages\n // added here are exactly the ones the version sync will own.\n const metadata: TsMcpServerMetadata = {\n port: localDevPort,\n rc: mcpServerNameClassName,\n auth,\n ...(iac ? { iac } : {}),\n };\n\n // The MCP inspector has a postinstall script that cascades installs into its\n // client packages, which no-ops when the package is installed as a dependency.\n // Register it as an explicitly-rejected build so pnpm 11's default\n // `strictDepBuilds=true` skips it instead of failing the install.\n registerPnpmBuiltDependencies(tree, {\n '@modelcontextprotocol/inspector': false,\n });\n\n addTsDependencies(tree, DEPENDENCIES, {\n metadata,\n projectRoot: project.root,\n });\n\n const mcpTargets = {\n ...project.targets,\n // Add targets for running the MCP server\n [`${mcpTargetPrefix}-serve-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/stdio.ts`],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/http.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${mcpTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/http.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${mcpTargetPrefix}-inspect`]: {\n executor: 'nx:run-commands',\n continuous: true,\n // Launch the inspector against the locally served HTTP server. The dev\n // target starts the server and any connected dependencies (e.g. a local\n // database).\n dependsOn: [`${mcpTargetPrefix}-dev`],\n options: {\n commands: [\n `mcp-inspector --transport http --server-url http://localhost:${localDevPort}/mcp`,\n ],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-inspect-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `mcp-inspector -- tsx --watch ${relativeSourceDir}/stdio.ts`,\n ],\n cwd: '{projectRoot}',\n },\n },\n };\n\n // Aggregate `<mcp>-dev` under the project-level `dev` target.\n addComponentDevTarget(mcpTargets, `${mcpTargetPrefix}-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(mcpTargets),\n });\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n TS_MCP_SERVER_GENERATOR_INFO,\n targetSourceDirRelativeToProjectRoot,\n mcpTargetPrefix,\n metadata,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_MCP_SERVER_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsMcpServerGenerator;\n"],"names":["detectPackageManager","generateFiles","joinPathFragments","OverwriteStrategy","readJson","updateJson","updateProjectConfiguration","addTsDependencies","AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES","addMcpServerInfra","addTypeScriptBundleTarget","BUNDLE_DEPENDENCIES","resolveContainers","declareDependencies","ownedElsewhere","ADOT_IMAGE_DEPENDENCIES","addDockerScanTarget","DOCKER_DEPENDENCIES","NODE_IMAGE_DEPENDENCIES","nodeImageVersions","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","kebabCase","toClassName","getNpmScope","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","registerPnpmBuiltDependencies","assignPort","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","BASE_IMAGES","TS_VERSIONS","DEPENDENCIES","ts","name","dev","root","py","TS_MCP_SERVER_GENERATOR_INFO","filename","tsMcpServerGenerator","tree","options","project","exists","Error","defaultName","split","pop","mcpServerNameClassName","mcpTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","iac","undefined","auth","console","warn","projectPackageJsonPath","esm","type","dirname","adotVersion","jaegerVersion","nodeBaseImage","node","overwriteStrategy","KeepExisting","containers","dockerImageTag","targetFilePath","bundleOutputDir","dockerOutputDir","dockerTargetName","fs","targets","cache","outputs","executor","commands","cp","parallel","dependsOn","containerEngine","trivyTargetName","imageTags","mcpServerNameKebabCase","projectName","delete","packageJson","resolutions","localDevPort","component","info","metadata","port","rc","projectRoot","mcpTargets","continuous","cwd","env","PORT","LOCAL_DEV","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,oBAAoB,EAEpBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,QAAQ,EAERC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,kCAA+B;AACjE,SACEC,qCAAqC,EACrCC,iBAAiB,QACZ,6DAA0D;AACjE,SACEC,yBAAyB,EACzBC,mBAAmB,QACd,+BAA4B;AACnC,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAoC;AAC3C,SACEC,uBAAuB,EACvBC,mBAAmB,EACnBC,mBAAmB,EACnBC,uBAAuB,EACvBC,iBAAiB,QACZ,wBAAqB;AAC5B,SAAS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StD,eAAe6E;IAC1B;IAEAjF,8BACEoB,MACAE,QAAQT,IAAI,EACZI,8BACAa,sCACAD,iBACAgD;IAGF,MAAMnF,gCAAgC0B,MAAM;QAACH;KAA6B;IAE1E,MAAM5B,qBAAqB+B;IAC3B,OAAO,IACL3B,oBAAoB2B,MAAMC,QAAQkE,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAerE,qBAAqB"}
|
|
@@ -99,7 +99,8 @@ export const handler = async (
|
|
|
99
99
|
`;
|
|
100
100
|
|
|
101
101
|
exports[`ts#rdb generator > should add mysql prisma dependencies when engine is MySQL > packages/db/src/index.ts 1`] = `
|
|
102
|
-
"export
|
|
102
|
+
"export * from './prisma.js';
|
|
103
|
+
// Export your library code here
|
|
103
104
|
"
|
|
104
105
|
`;
|
|
105
106
|
|
|
@@ -803,7 +804,7 @@ terraform {
|
|
|
803
804
|
}
|
|
804
805
|
null = {
|
|
805
806
|
source = "hashicorp/null"
|
|
806
|
-
version = "3.3.
|
|
807
|
+
version = "3.3.1"
|
|
807
808
|
}
|
|
808
809
|
random = {
|
|
809
810
|
source = "hashicorp/random"
|
|
@@ -1557,7 +1558,7 @@ exports[`ts#rdb generator > should generate terraform modules when iac is Terraf
|
|
|
1557
1558
|
}
|
|
1558
1559
|
null = {
|
|
1559
1560
|
source = "hashicorp/null"
|
|
1560
|
-
version = "3.3.
|
|
1561
|
+
version = "3.3.1"
|
|
1561
1562
|
}
|
|
1562
1563
|
random = {
|
|
1563
1564
|
source = "hashicorp/random"
|
|
@@ -2289,7 +2290,7 @@ terraform {
|
|
|
2289
2290
|
}
|
|
2290
2291
|
null = {
|
|
2291
2292
|
source = "hashicorp/null"
|
|
2292
|
-
version = "3.3.
|
|
2293
|
+
version = "3.3.1"
|
|
2293
2294
|
}
|
|
2294
2295
|
random = {
|
|
2295
2296
|
source = "hashicorp/random"
|
|
@@ -3043,7 +3044,7 @@ exports[`ts#rdb generator > should generate terraform modules with MySQL engine
|
|
|
3043
3044
|
}
|
|
3044
3045
|
null = {
|
|
3045
3046
|
source = "hashicorp/null"
|
|
3046
|
-
version = "3.3.
|
|
3047
|
+
version = "3.3.1"
|
|
3047
3048
|
}
|
|
3048
3049
|
random = {
|
|
3049
3050
|
source = "hashicorp/random"
|
|
@@ -3878,7 +3879,8 @@ export const handler = async (
|
|
|
3878
3879
|
`;
|
|
3879
3880
|
|
|
3880
3881
|
exports[`ts#rdb generator > should generate the aurora shared construct > packages/db/src/index.ts 1`] = `
|
|
3881
|
-
"export
|
|
3882
|
+
"export * from './prisma.js';
|
|
3883
|
+
// Export your library code here
|
|
3882
3884
|
"
|
|
3883
3885
|
`;
|
|
3884
3886
|
|
package/src/ts/rdb/generator.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/ import { relative } from "node:path";
|
|
5
|
-
import { detectPackageManager, generateFiles, joinPathFragments, readProjectConfiguration, updateJson, updateProjectConfiguration } from "@nx/devkit";
|
|
5
|
+
import { detectPackageManager, generateFiles, joinPathFragments, OverwriteStrategy, readProjectConfiguration, updateJson, updateProjectConfiguration, writeJson } from "@nx/devkit";
|
|
6
6
|
import { addTsDependencies } from "../../utils/add-dependencies.js";
|
|
7
|
+
import { addStarExport } from "../../utils/ast.js";
|
|
7
8
|
import { addTypeScriptBundleTarget, BUNDLE_DEPENDENCIES } from "../../utils/bundle/bundle.js";
|
|
8
9
|
import { resolveContainers } from "../../utils/containers.js";
|
|
9
10
|
import { declareDependencies, ownedElsewhere } from "../../utils/declared-dependencies.js";
|
|
@@ -149,7 +150,33 @@ export const tsRdbGenerator = async (tree, options)=>{
|
|
|
149
150
|
dockerImage,
|
|
150
151
|
...esmVars(tree)
|
|
151
152
|
};
|
|
152
|
-
|
|
153
|
+
// The Prisma schema and models, the handlers and the prisma client module are
|
|
154
|
+
// all user-editable, so a re-run (to add infrastructure, or after a failed
|
|
155
|
+
// run) must not clobber the user's schema and edits.
|
|
156
|
+
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files'), dir, templateOptions, {
|
|
157
|
+
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
158
|
+
});
|
|
159
|
+
// The barrel re-exports prisma.ts. `tsProjectGenerator` writes a stub index.ts
|
|
160
|
+
// when it creates the project, so the re-export is added to whatever is there
|
|
161
|
+
// rather than replacing it — which also leaves a user's own additions to the
|
|
162
|
+
// barrel alone on a re-run.
|
|
163
|
+
await addStarExport(tree, joinPathFragments(dir, 'src', 'index.ts'), './prisma.js');
|
|
164
|
+
// config.json is framework-owned: it carries values derived from the
|
|
165
|
+
// generator's options, so it converges on a re-run with changed options.
|
|
166
|
+
writeJson(tree, joinPathFragments(dir, 'config.json'), {
|
|
167
|
+
runtimeConfigKey: nameClassName,
|
|
168
|
+
localDev: {
|
|
169
|
+
containerEngine,
|
|
170
|
+
containerName,
|
|
171
|
+
image: dockerImage,
|
|
172
|
+
port: localDbPort,
|
|
173
|
+
host: localDbHost,
|
|
174
|
+
dbName: databaseName,
|
|
175
|
+
dbUser: localDbUser,
|
|
176
|
+
dbPassword: localDbPassword,
|
|
177
|
+
dbEngine: options.engine
|
|
178
|
+
}
|
|
179
|
+
});
|
|
153
180
|
updateGitIgnore(tree, dir, (patterns)=>[
|
|
154
181
|
...patterns,
|
|
155
182
|
'generated/prisma'
|